2 * Common functions for CAM "type" (peripheral) drivers.
4 * Copyright (c) 1997, 1998 Justin T. Gibbs.
5 * Copyright (c) 1997, 1998, 1999, 2000 Kenneth D. Merry.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions, and the following disclaimer,
13 * without modification, immediately at the beginning of the file.
14 * 2. The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
21 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 #include <sys/cdefs.h>
31 __FBSDID("$FreeBSD$");
33 #include <sys/param.h>
34 #include <sys/systm.h>
35 #include <sys/types.h>
36 #include <sys/malloc.h>
37 #include <sys/kernel.h>
38 #include <sys/linker_set.h>
41 #include <sys/mutex.h>
44 #include <sys/devicestat.h>
47 #include <vm/vm_extern.h>
50 #include <cam/cam_ccb.h>
51 #include <cam/cam_queue.h>
52 #include <cam/cam_xpt_periph.h>
53 #include <cam/cam_periph.h>
54 #include <cam/cam_debug.h>
55 #include <cam/cam_sim.h>
57 #include <cam/scsi/scsi_all.h>
58 #include <cam/scsi/scsi_message.h>
59 #include <cam/scsi/scsi_pass.h>
61 static u_int camperiphnextunit(struct periph_driver *p_drv,
62 u_int newunit, int wired,
63 path_id_t pathid, target_id_t target,
65 static u_int camperiphunit(struct periph_driver *p_drv,
66 path_id_t pathid, target_id_t target,
68 static void camperiphdone(struct cam_periph *periph,
70 static void camperiphfree(struct cam_periph *periph);
71 static int camperiphscsistatuserror(union ccb *ccb,
73 u_int32_t sense_flags,
75 u_int32_t *relsim_flags,
77 const char **action_string);
78 static int camperiphscsisenseerror(union ccb *ccb,
80 u_int32_t sense_flags,
82 u_int32_t *relsim_flags,
84 const char **action_string);
86 static int nperiph_drivers;
87 static int initialized = 0;
88 struct periph_driver **periph_drivers;
90 MALLOC_DEFINE(M_CAMPERIPH, "CAM periph", "CAM peripheral buffers");
92 static int periph_selto_delay = 1000;
93 TUNABLE_INT("kern.cam.periph_selto_delay", &periph_selto_delay);
94 static int periph_noresrc_delay = 500;
95 TUNABLE_INT("kern.cam.periph_noresrc_delay", &periph_noresrc_delay);
96 static int periph_busy_delay = 500;
97 TUNABLE_INT("kern.cam.periph_busy_delay", &periph_busy_delay);
101 periphdriver_register(void *data)
103 struct periph_driver *drv = (struct periph_driver *)data;
104 struct periph_driver **newdrivers, **old;
107 ndrivers = nperiph_drivers + 2;
108 newdrivers = malloc(sizeof(*newdrivers) * ndrivers, M_CAMPERIPH,
111 bcopy(periph_drivers, newdrivers,
112 sizeof(*newdrivers) * nperiph_drivers);
113 newdrivers[nperiph_drivers] = drv;
114 newdrivers[nperiph_drivers + 1] = NULL;
115 old = periph_drivers;
116 periph_drivers = newdrivers;
118 free(old, M_CAMPERIPH);
120 /* If driver marked as early or it is late now, initialize it. */
121 if (((drv->flags & CAM_PERIPH_DRV_EARLY) != 0 && initialized > 0) ||
127 periphdriver_init(int level)
131 initialized = max(initialized, level);
132 for (i = 0; periph_drivers[i] != NULL; i++) {
133 early = (periph_drivers[i]->flags & CAM_PERIPH_DRV_EARLY) ? 1 : 2;
134 if (early == initialized)
135 (*periph_drivers[i]->init)();
140 cam_periph_alloc(periph_ctor_t *periph_ctor,
141 periph_oninv_t *periph_oninvalidate,
142 periph_dtor_t *periph_dtor, periph_start_t *periph_start,
143 char *name, cam_periph_type type, struct cam_path *path,
144 ac_callback_t *ac_callback, ac_code code, void *arg)
146 struct periph_driver **p_drv;
148 struct cam_periph *periph;
149 struct cam_periph *cur_periph;
151 target_id_t target_id;
158 * Handle Hot-Plug scenarios. If there is already a peripheral
159 * of our type assigned to this path, we are likely waiting for
160 * final close on an old, invalidated, peripheral. If this is
161 * the case, queue up a deferred call to the peripheral's async
162 * handler. If it looks like a mistaken re-allocation, complain.
164 if ((periph = cam_periph_find(path, name)) != NULL) {
166 if ((periph->flags & CAM_PERIPH_INVALID) != 0
167 && (periph->flags & CAM_PERIPH_NEW_DEV_FOUND) == 0) {
168 periph->flags |= CAM_PERIPH_NEW_DEV_FOUND;
169 periph->deferred_callback = ac_callback;
170 periph->deferred_ac = code;
171 return (CAM_REQ_INPROG);
173 printf("cam_periph_alloc: attempt to re-allocate "
174 "valid device %s%d rejected\n",
175 periph->periph_name, periph->unit_number);
177 return (CAM_REQ_INVALID);
180 periph = (struct cam_periph *)malloc(sizeof(*periph), M_CAMPERIPH,
184 return (CAM_RESRC_UNAVAIL);
189 sim = xpt_path_sim(path);
190 path_id = xpt_path_path_id(path);
191 target_id = xpt_path_target_id(path);
192 lun_id = xpt_path_lun_id(path);
193 bzero(periph, sizeof(*periph));
194 cam_init_pinfo(&periph->pinfo);
195 periph->periph_start = periph_start;
196 periph->periph_dtor = periph_dtor;
197 periph->periph_oninval = periph_oninvalidate;
199 periph->periph_name = name;
200 periph->immediate_priority = CAM_PRIORITY_NONE;
201 periph->refcount = 0;
203 SLIST_INIT(&periph->ccb_list);
204 status = xpt_create_path(&path, periph, path_id, target_id, lun_id);
205 if (status != CAM_REQ_CMP)
210 for (p_drv = periph_drivers; *p_drv != NULL; p_drv++) {
211 if (strcmp((*p_drv)->driver_name, name) == 0)
214 if (*p_drv == NULL) {
215 printf("cam_periph_alloc: invalid periph name '%s'\n", name);
216 xpt_free_path(periph->path);
217 free(periph, M_CAMPERIPH);
219 return (CAM_REQ_INVALID);
221 periph->unit_number = camperiphunit(*p_drv, path_id, target_id, lun_id);
222 cur_periph = TAILQ_FIRST(&(*p_drv)->units);
223 while (cur_periph != NULL
224 && cur_periph->unit_number < periph->unit_number)
225 cur_periph = TAILQ_NEXT(cur_periph, unit_links);
226 if (cur_periph != NULL) {
227 KASSERT(cur_periph->unit_number != periph->unit_number, ("duplicate units on periph list"));
228 TAILQ_INSERT_BEFORE(cur_periph, periph, unit_links);
230 TAILQ_INSERT_TAIL(&(*p_drv)->units, periph, unit_links);
231 (*p_drv)->generation++;
237 status = xpt_add_periph(periph);
238 if (status != CAM_REQ_CMP)
243 status = periph_ctor(periph, arg);
245 if (status == CAM_REQ_CMP)
249 switch (init_level) {
251 /* Initialized successfully */
254 xpt_remove_periph(periph);
258 TAILQ_REMOVE(&(*p_drv)->units, periph, unit_links);
260 xpt_free_path(periph->path);
263 free(periph, M_CAMPERIPH);
266 /* No cleanup to perform. */
269 panic("cam_periph_alloc: Unkown init level");
275 * Find a peripheral structure with the specified path, target, lun,
276 * and (optionally) type. If the name is NULL, this function will return
277 * the first peripheral driver that matches the specified path.
280 cam_periph_find(struct cam_path *path, char *name)
282 struct periph_driver **p_drv;
283 struct cam_periph *periph;
286 for (p_drv = periph_drivers; *p_drv != NULL; p_drv++) {
288 if (name != NULL && (strcmp((*p_drv)->driver_name, name) != 0))
291 TAILQ_FOREACH(periph, &(*p_drv)->units, unit_links) {
292 if (xpt_path_comp(periph->path, path) == 0) {
294 mtx_assert(periph->sim->mtx, MA_OWNED);
308 cam_periph_acquire(struct cam_periph *periph)
312 return(CAM_REQ_CMP_ERR);
322 cam_periph_release_locked(struct cam_periph *periph)
329 if (periph->refcount != 0) {
332 xpt_print(periph->path, "%s: release %p when refcount is zero\n ", __func__, periph);
334 if (periph->refcount == 0
335 && (periph->flags & CAM_PERIPH_INVALID)) {
336 camperiphfree(periph);
342 cam_periph_release(struct cam_periph *periph)
350 mtx_assert(sim->mtx, MA_NOTOWNED);
352 cam_periph_release_locked(periph);
353 mtx_unlock(sim->mtx);
357 cam_periph_hold(struct cam_periph *periph, int priority)
362 * Increment the reference count on the peripheral
363 * while we wait for our lock attempt to succeed
364 * to ensure the peripheral doesn't disappear out
365 * from user us while we sleep.
368 if (cam_periph_acquire(periph) != CAM_REQ_CMP)
371 mtx_assert(periph->sim->mtx, MA_OWNED);
372 while ((periph->flags & CAM_PERIPH_LOCKED) != 0) {
373 periph->flags |= CAM_PERIPH_LOCK_WANTED;
374 if ((error = mtx_sleep(periph, periph->sim->mtx, priority,
375 "caplck", 0)) != 0) {
376 cam_periph_release_locked(periph);
381 periph->flags |= CAM_PERIPH_LOCKED;
386 cam_periph_unhold(struct cam_periph *periph)
389 mtx_assert(periph->sim->mtx, MA_OWNED);
391 periph->flags &= ~CAM_PERIPH_LOCKED;
392 if ((periph->flags & CAM_PERIPH_LOCK_WANTED) != 0) {
393 periph->flags &= ~CAM_PERIPH_LOCK_WANTED;
397 cam_periph_release_locked(periph);
401 * Look for the next unit number that is not currently in use for this
402 * peripheral type starting at "newunit". Also exclude unit numbers that
403 * are reserved by for future "hardwiring" unless we already know that this
404 * is a potential wired device. Only assume that the device is "wired" the
405 * first time through the loop since after that we'll be looking at unit
406 * numbers that did not match a wiring entry.
409 camperiphnextunit(struct periph_driver *p_drv, u_int newunit, int wired,
410 path_id_t pathid, target_id_t target, lun_id_t lun)
412 struct cam_periph *periph;
414 int i, val, dunit, r;
415 const char *dname, *strval;
417 periph_name = p_drv->driver_name;
420 for (periph = TAILQ_FIRST(&p_drv->units);
421 periph != NULL && periph->unit_number != newunit;
422 periph = TAILQ_NEXT(periph, unit_links))
425 if (periph != NULL && periph->unit_number == newunit) {
427 xpt_print(periph->path, "Duplicate Wired "
429 xpt_print(periph->path, "Second device (%s "
430 "device at scbus%d target %d lun %d) will "
431 "not be wired\n", periph_name, pathid,
441 * Don't match entries like "da 4" as a wired down
442 * device, but do match entries like "da 4 target 5"
443 * or even "da 4 scbus 1".
448 r = resource_find_dev(&i, dname, &dunit, NULL, NULL);
451 /* if no "target" and no specific scbus, skip */
452 if (resource_int_value(dname, dunit, "target", &val) &&
453 (resource_string_value(dname, dunit, "at",&strval)||
454 strcmp(strval, "scbus") == 0))
456 if (newunit == dunit)
466 camperiphunit(struct periph_driver *p_drv, path_id_t pathid,
467 target_id_t target, lun_id_t lun)
470 int wired, i, val, dunit;
471 const char *dname, *strval;
472 char pathbuf[32], *periph_name;
474 periph_name = p_drv->driver_name;
475 snprintf(pathbuf, sizeof(pathbuf), "scbus%d", pathid);
479 for (wired = 0; resource_find_dev(&i, dname, &dunit, NULL, NULL) == 0;
481 if (resource_string_value(dname, dunit, "at", &strval) == 0) {
482 if (strcmp(strval, pathbuf) != 0)
486 if (resource_int_value(dname, dunit, "target", &val) == 0) {
491 if (resource_int_value(dname, dunit, "lun", &val) == 0) {
503 * Either start from 0 looking for the next unit or from
504 * the unit number given in the resource config. This way,
505 * if we have wildcard matches, we don't return the same
508 unit = camperiphnextunit(p_drv, unit, wired, pathid, target, lun);
514 cam_periph_invalidate(struct cam_periph *periph)
518 * We only call this routine the first time a peripheral is
521 if (((periph->flags & CAM_PERIPH_INVALID) == 0)
522 && (periph->periph_oninval != NULL))
523 periph->periph_oninval(periph);
525 periph->flags |= CAM_PERIPH_INVALID;
526 periph->flags &= ~CAM_PERIPH_NEW_DEV_FOUND;
529 if (periph->refcount == 0)
530 camperiphfree(periph);
531 else if (periph->refcount < 0)
532 printf("cam_invalidate_periph: refcount < 0!!\n");
537 camperiphfree(struct cam_periph *periph)
539 struct periph_driver **p_drv;
541 for (p_drv = periph_drivers; *p_drv != NULL; p_drv++) {
542 if (strcmp((*p_drv)->driver_name, periph->periph_name) == 0)
545 if (*p_drv == NULL) {
546 printf("camperiphfree: attempt to free non-existant periph\n");
550 TAILQ_REMOVE(&(*p_drv)->units, periph, unit_links);
551 (*p_drv)->generation++;
554 if (periph->periph_dtor != NULL)
555 periph->periph_dtor(periph);
556 xpt_remove_periph(periph);
558 if (periph->flags & CAM_PERIPH_NEW_DEV_FOUND) {
562 switch (periph->deferred_ac) {
563 case AC_FOUND_DEVICE:
564 ccb.ccb_h.func_code = XPT_GDEV_TYPE;
565 xpt_setup_ccb(&ccb.ccb_h, periph->path, CAM_PRIORITY_NORMAL);
569 case AC_PATH_REGISTERED:
570 ccb.ccb_h.func_code = XPT_PATH_INQ;
571 xpt_setup_ccb(&ccb.ccb_h, periph->path, CAM_PRIORITY_NORMAL);
579 periph->deferred_callback(NULL, periph->deferred_ac,
582 xpt_free_path(periph->path);
583 free(periph, M_CAMPERIPH);
588 * Map user virtual pointers into kernel virtual address space, so we can
589 * access the memory. This won't work on physical pointers, for now it's
590 * up to the caller to check for that. (XXX KDM -- should we do that here
591 * instead?) This also only works for up to MAXPHYS memory. Since we use
592 * buffers to map stuff in and out, we're limited to the buffer size.
595 cam_periph_mapmem(union ccb *ccb, struct cam_periph_map_info *mapinfo)
598 int flags[CAM_PERIPH_MAXMAPS];
599 u_int8_t **data_ptrs[CAM_PERIPH_MAXMAPS];
600 u_int32_t lengths[CAM_PERIPH_MAXMAPS];
601 u_int32_t dirs[CAM_PERIPH_MAXMAPS];
602 /* Some controllers may not be able to handle more data. */
603 size_t maxmap = DFLTPHYS;
605 switch(ccb->ccb_h.func_code) {
607 if (ccb->cdm.match_buf_len == 0) {
608 printf("cam_periph_mapmem: invalid match buffer "
612 if (ccb->cdm.pattern_buf_len > 0) {
613 data_ptrs[0] = (u_int8_t **)&ccb->cdm.patterns;
614 lengths[0] = ccb->cdm.pattern_buf_len;
615 dirs[0] = CAM_DIR_OUT;
616 data_ptrs[1] = (u_int8_t **)&ccb->cdm.matches;
617 lengths[1] = ccb->cdm.match_buf_len;
618 dirs[1] = CAM_DIR_IN;
621 data_ptrs[0] = (u_int8_t **)&ccb->cdm.matches;
622 lengths[0] = ccb->cdm.match_buf_len;
623 dirs[0] = CAM_DIR_IN;
627 * This request will not go to the hardware, no reason
628 * to be so strict. vmapbuf() is able to map up to MAXPHYS.
633 case XPT_CONT_TARGET_IO:
634 if ((ccb->ccb_h.flags & CAM_DIR_MASK) == CAM_DIR_NONE)
637 data_ptrs[0] = &ccb->csio.data_ptr;
638 lengths[0] = ccb->csio.dxfer_len;
639 dirs[0] = ccb->ccb_h.flags & CAM_DIR_MASK;
643 if ((ccb->ccb_h.flags & CAM_DIR_MASK) == CAM_DIR_NONE)
646 data_ptrs[0] = &ccb->ataio.data_ptr;
647 lengths[0] = ccb->ataio.dxfer_len;
648 dirs[0] = ccb->ccb_h.flags & CAM_DIR_MASK;
653 break; /* NOTREACHED */
657 * Check the transfer length and permissions first, so we don't
658 * have to unmap any previously mapped buffers.
660 for (i = 0; i < numbufs; i++) {
665 * The userland data pointer passed in may not be page
666 * aligned. vmapbuf() truncates the address to a page
667 * boundary, so if the address isn't page aligned, we'll
668 * need enough space for the given transfer length, plus
669 * whatever extra space is necessary to make it to the page
673 (((vm_offset_t)(*data_ptrs[i])) & PAGE_MASK)) > maxmap){
674 printf("cam_periph_mapmem: attempt to map %lu bytes, "
675 "which is greater than %lu\n",
677 (((vm_offset_t)(*data_ptrs[i])) & PAGE_MASK)),
682 if (dirs[i] & CAM_DIR_OUT) {
683 flags[i] = BIO_WRITE;
686 if (dirs[i] & CAM_DIR_IN) {
692 /* this keeps the current process from getting swapped */
694 * XXX KDM should I use P_NOSWAP instead?
698 for (i = 0; i < numbufs; i++) {
702 mapinfo->bp[i] = getpbuf(NULL);
704 /* save the buffer's data address */
705 mapinfo->bp[i]->b_saveaddr = mapinfo->bp[i]->b_data;
707 /* put our pointer in the data slot */
708 mapinfo->bp[i]->b_data = *data_ptrs[i];
710 /* set the transfer length, we know it's < MAXPHYS */
711 mapinfo->bp[i]->b_bufsize = lengths[i];
713 /* set the direction */
714 mapinfo->bp[i]->b_iocmd = flags[i];
717 * Map the buffer into kernel memory.
719 * Note that useracc() alone is not a sufficient test.
720 * vmapbuf() can still fail due to a smaller file mapped
721 * into a larger area of VM, or if userland races against
722 * vmapbuf() after the useracc() check.
724 if (vmapbuf(mapinfo->bp[i]) < 0) {
725 for (j = 0; j < i; ++j) {
726 *data_ptrs[j] = mapinfo->bp[j]->b_saveaddr;
727 vunmapbuf(mapinfo->bp[j]);
728 relpbuf(mapinfo->bp[j], NULL);
730 relpbuf(mapinfo->bp[i], NULL);
735 /* set our pointer to the new mapped area */
736 *data_ptrs[i] = mapinfo->bp[i]->b_data;
738 mapinfo->num_bufs_used++;
742 * Now that we've gotten this far, change ownership to the kernel
743 * of the buffers so that we don't run afoul of returning to user
744 * space with locks (on the buffer) held.
746 for (i = 0; i < numbufs; i++) {
747 BUF_KERNPROC(mapinfo->bp[i]);
755 * Unmap memory segments mapped into kernel virtual address space by
756 * cam_periph_mapmem().
759 cam_periph_unmapmem(union ccb *ccb, struct cam_periph_map_info *mapinfo)
762 u_int8_t **data_ptrs[CAM_PERIPH_MAXMAPS];
764 if (mapinfo->num_bufs_used <= 0) {
765 /* allow ourselves to be swapped once again */
770 switch (ccb->ccb_h.func_code) {
772 numbufs = min(mapinfo->num_bufs_used, 2);
775 data_ptrs[0] = (u_int8_t **)&ccb->cdm.matches;
777 data_ptrs[0] = (u_int8_t **)&ccb->cdm.patterns;
778 data_ptrs[1] = (u_int8_t **)&ccb->cdm.matches;
782 case XPT_CONT_TARGET_IO:
783 data_ptrs[0] = &ccb->csio.data_ptr;
784 numbufs = min(mapinfo->num_bufs_used, 1);
787 data_ptrs[0] = &ccb->ataio.data_ptr;
788 numbufs = min(mapinfo->num_bufs_used, 1);
791 /* allow ourselves to be swapped once again */
794 break; /* NOTREACHED */
797 for (i = 0; i < numbufs; i++) {
798 /* Set the user's pointer back to the original value */
799 *data_ptrs[i] = mapinfo->bp[i]->b_saveaddr;
801 /* unmap the buffer */
802 vunmapbuf(mapinfo->bp[i]);
804 /* release the buffer */
805 relpbuf(mapinfo->bp[i], NULL);
808 /* allow ourselves to be swapped once again */
813 cam_periph_getccb(struct cam_periph *periph, u_int32_t priority)
815 struct ccb_hdr *ccb_h;
817 mtx_assert(periph->sim->mtx, MA_OWNED);
818 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("entering cdgetccb\n"));
820 while (SLIST_FIRST(&periph->ccb_list) == NULL) {
821 if (periph->immediate_priority > priority)
822 periph->immediate_priority = priority;
823 xpt_schedule(periph, priority);
824 if ((SLIST_FIRST(&periph->ccb_list) != NULL)
825 && (SLIST_FIRST(&periph->ccb_list)->pinfo.priority == priority))
827 mtx_assert(periph->sim->mtx, MA_OWNED);
828 mtx_sleep(&periph->ccb_list, periph->sim->mtx, PRIBIO, "cgticb",
832 ccb_h = SLIST_FIRST(&periph->ccb_list);
833 SLIST_REMOVE_HEAD(&periph->ccb_list, periph_links.sle);
834 return ((union ccb *)ccb_h);
838 cam_periph_ccbwait(union ccb *ccb)
842 sim = xpt_path_sim(ccb->ccb_h.path);
843 if ((ccb->ccb_h.pinfo.index != CAM_UNQUEUED_INDEX)
844 || ((ccb->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_INPROG))
845 mtx_sleep(&ccb->ccb_h.cbfcnp, sim->mtx, PRIBIO, "cbwait", 0);
849 cam_periph_ioctl(struct cam_periph *periph, u_long cmd, caddr_t addr,
850 int (*error_routine)(union ccb *ccb,
852 u_int32_t sense_flags))
862 ccb = cam_periph_getccb(periph, CAM_PRIORITY_NORMAL);
863 xpt_setup_ccb(&ccb->ccb_h,
865 CAM_PRIORITY_NORMAL);
866 ccb->ccb_h.func_code = XPT_GDEVLIST;
869 * Basically, the point of this is that we go through
870 * getting the list of devices, until we find a passthrough
871 * device. In the current version of the CAM code, the
872 * only way to determine what type of device we're dealing
873 * with is by its name.
877 ccb->cgdl.status = CAM_GDEVLIST_MORE_DEVS;
878 while (ccb->cgdl.status == CAM_GDEVLIST_MORE_DEVS) {
880 /* we want the next device in the list */
882 if (strncmp(ccb->cgdl.periph_name,
888 if ((ccb->cgdl.status == CAM_GDEVLIST_LAST_DEVICE) &&
890 ccb->cgdl.periph_name[0] = '\0';
891 ccb->cgdl.unit_number = 0;
896 /* copy the result back out */
897 bcopy(ccb, addr, sizeof(union ccb));
899 /* and release the ccb */
900 xpt_release_ccb(ccb);
911 cam_periph_runccb(union ccb *ccb,
912 int (*error_routine)(union ccb *ccb,
914 u_int32_t sense_flags),
915 cam_flags camflags, u_int32_t sense_flags,
922 sim = xpt_path_sim(ccb->ccb_h.path);
923 mtx_assert(sim->mtx, MA_OWNED);
926 * If the user has supplied a stats structure, and if we understand
927 * this particular type of ccb, record the transaction start.
929 if ((ds != NULL) && (ccb->ccb_h.func_code == XPT_SCSI_IO ||
930 ccb->ccb_h.func_code == XPT_ATA_IO))
931 devstat_start_transaction(ds, NULL);
936 cam_periph_ccbwait(ccb);
937 if ((ccb->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP)
939 else if (error_routine != NULL)
940 error = (*error_routine)(ccb, camflags, sense_flags);
944 } while (error == ERESTART);
946 if ((ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
947 cam_release_devq(ccb->ccb_h.path,
951 /* getcount_only */ FALSE);
952 ccb->ccb_h.status &= ~CAM_DEV_QFRZN;
956 if (ccb->ccb_h.func_code == XPT_SCSI_IO) {
957 devstat_end_transaction(ds,
959 ccb->csio.tag_action & 0x3,
960 ((ccb->ccb_h.flags & CAM_DIR_MASK) ==
961 CAM_DIR_NONE) ? DEVSTAT_NO_DATA :
962 (ccb->ccb_h.flags & CAM_DIR_OUT) ?
964 DEVSTAT_READ, NULL, NULL);
965 } else if (ccb->ccb_h.func_code == XPT_ATA_IO) {
966 devstat_end_transaction(ds,
967 ccb->ataio.dxfer_len,
968 ccb->ataio.tag_action & 0x3,
969 ((ccb->ccb_h.flags & CAM_DIR_MASK) ==
970 CAM_DIR_NONE) ? DEVSTAT_NO_DATA :
971 (ccb->ccb_h.flags & CAM_DIR_OUT) ?
973 DEVSTAT_READ, NULL, NULL);
981 cam_freeze_devq(struct cam_path *path)
984 cam_freeze_devq_arg(path, 0, 0);
988 cam_freeze_devq_arg(struct cam_path *path, uint32_t flags, uint32_t arg)
990 struct ccb_relsim crs;
992 xpt_setup_ccb(&crs.ccb_h, path, CAM_PRIORITY_NONE);
993 crs.ccb_h.func_code = XPT_FREEZE_QUEUE;
994 crs.release_flags = flags;
996 crs.release_timeout = arg;
997 xpt_action((union ccb *)&crs);
1001 cam_release_devq(struct cam_path *path, u_int32_t relsim_flags,
1002 u_int32_t openings, u_int32_t arg,
1005 struct ccb_relsim crs;
1007 xpt_setup_ccb(&crs.ccb_h, path, CAM_PRIORITY_NORMAL);
1008 crs.ccb_h.func_code = XPT_REL_SIMQ;
1009 crs.ccb_h.flags = getcount_only ? CAM_DEV_QFREEZE : 0;
1010 crs.release_flags = relsim_flags;
1011 crs.openings = openings;
1012 crs.release_timeout = arg;
1013 xpt_action((union ccb *)&crs);
1014 return (crs.qfrozen_cnt);
1017 #define saved_ccb_ptr ppriv_ptr0
1018 #define recovery_depth ppriv_field1
1020 camperiphsensedone(struct cam_periph *periph, union ccb *done_ccb)
1022 union ccb *saved_ccb = (union ccb *)done_ccb->ccb_h.saved_ccb_ptr;
1026 int depth = done_ccb->ccb_h.recovery_depth;
1028 status = done_ccb->ccb_h.status;
1029 if (status & CAM_DEV_QFRZN) {
1032 * Clear freeze flag now for case of retry,
1033 * freeze will be dropped later.
1035 done_ccb->ccb_h.status &= ~CAM_DEV_QFRZN;
1037 status &= CAM_STATUS_MASK;
1042 * If we manually retrieved sense into a CCB and got
1043 * something other than "NO SENSE" send the updated CCB
1044 * back to the client via xpt_done() to be processed via
1045 * the error recovery code again.
1047 sense_key = saved_ccb->csio.sense_data.flags;
1048 sense_key &= SSD_KEY;
1049 if (sense_key != SSD_KEY_NO_SENSE) {
1050 saved_ccb->ccb_h.status |=
1053 saved_ccb->ccb_h.status &=
1055 saved_ccb->ccb_h.status |=
1058 bcopy(saved_ccb, done_ccb, sizeof(union ccb));
1059 xpt_free_ccb(saved_ccb);
1063 bcopy(saved_ccb, done_ccb, sizeof(union ccb));
1064 xpt_free_ccb(saved_ccb);
1065 done_ccb->ccb_h.status &= ~CAM_STATUS_MASK;
1066 done_ccb->ccb_h.status |= CAM_AUTOSENSE_FAIL;
1069 periph->flags &= ~CAM_PERIPH_SENSE_INPROG;
1071 * If it is the end of recovery, drop freeze, taken due to
1072 * CAM_DEV_QFREEZE flag, set on recovery request.
1075 cam_release_devq(done_ccb->ccb_h.path,
1079 /*getcount_only*/0);
1082 * Copy frozen flag from recovery request if it is set there
1086 done_ccb->ccb_h.status |= CAM_DEV_QFRZN;
1087 (*done_ccb->ccb_h.cbfcnp)(periph, done_ccb);
1091 camperiphdone(struct cam_periph *periph, union ccb *done_ccb)
1093 union ccb *saved_ccb, *save_ccb;
1096 struct scsi_start_stop_unit *scsi_cmd;
1097 u_int32_t relsim_flags, timeout;
1099 status = done_ccb->ccb_h.status;
1100 if (status & CAM_DEV_QFRZN) {
1103 * Clear freeze flag now for case of retry,
1104 * freeze will be dropped later.
1106 done_ccb->ccb_h.status &= ~CAM_DEV_QFRZN;
1111 saved_ccb = (union ccb *)done_ccb->ccb_h.saved_ccb_ptr;
1113 switch (status & CAM_STATUS_MASK) {
1117 * If we have successfully taken a device from the not
1118 * ready to ready state, re-scan the device and re-get
1119 * the inquiry information. Many devices (mostly disks)
1120 * don't properly report their inquiry information unless
1123 scsi_cmd = (struct scsi_start_stop_unit *)
1124 &done_ccb->csio.cdb_io.cdb_bytes;
1126 if (scsi_cmd->opcode == START_STOP_UNIT)
1127 xpt_async(AC_INQ_CHANGED,
1128 done_ccb->ccb_h.path, NULL);
1131 case CAM_SCSI_STATUS_ERROR:
1132 scsi_cmd = (struct scsi_start_stop_unit *)
1133 &done_ccb->csio.cdb_io.cdb_bytes;
1134 if (status & CAM_AUTOSNS_VALID) {
1135 struct ccb_getdev cgd;
1136 struct scsi_sense_data *sense;
1137 int error_code, sense_key, asc, ascq;
1138 scsi_sense_action err_action;
1140 sense = &done_ccb->csio.sense_data;
1141 scsi_extract_sense(sense, &error_code,
1142 &sense_key, &asc, &ascq);
1144 * Grab the inquiry data for this device.
1146 xpt_setup_ccb(&cgd.ccb_h, done_ccb->ccb_h.path,
1147 CAM_PRIORITY_NORMAL);
1148 cgd.ccb_h.func_code = XPT_GDEV_TYPE;
1149 xpt_action((union ccb *)&cgd);
1150 err_action = scsi_error_action(&done_ccb->csio,
1153 * If the error is "invalid field in CDB",
1154 * and the load/eject flag is set, turn the
1155 * flag off and try again. This is just in
1156 * case the drive in question barfs on the
1157 * load eject flag. The CAM code should set
1158 * the load/eject flag by default for
1162 * Should we check to see what the specific
1163 * scsi status is?? Or does it not matter
1164 * since we already know that there was an
1165 * error, and we know what the specific
1166 * error code was, and we know what the
1169 if ((scsi_cmd->opcode == START_STOP_UNIT) &&
1170 ((scsi_cmd->how & SSS_LOEJ) != 0) &&
1171 (asc == 0x24) && (ascq == 0x00) &&
1172 (done_ccb->ccb_h.retry_count > 0)) {
1174 scsi_cmd->how &= ~SSS_LOEJ;
1175 xpt_action(done_ccb);
1176 } else if ((done_ccb->ccb_h.retry_count > 1)
1177 && ((err_action & SS_MASK) != SS_FAIL)) {
1180 * In this case, the error recovery
1181 * command failed, but we've got
1182 * some retries left on it. Give
1183 * it another try unless this is an
1184 * unretryable error.
1186 /* set the timeout to .5 sec */
1188 RELSIM_RELEASE_AFTER_TIMEOUT;
1190 xpt_action(done_ccb);
1194 * Perform the final retry with the original
1195 * CCB so that final error processing is
1196 * performed by the owner of the CCB.
1201 save_ccb = xpt_alloc_ccb_nowait();
1202 if (save_ccb == NULL)
1204 bcopy(done_ccb, save_ccb, sizeof(*save_ccb));
1205 periph->flags |= CAM_PERIPH_SENSE_INPROG;
1207 * Send a Request Sense to the device. We
1208 * assume that we are in a contingent allegiance
1209 * condition so we do not tag this request.
1211 scsi_request_sense(&done_ccb->csio, /*retries*/1,
1213 &save_ccb->csio.sense_data,
1214 sizeof(save_ccb->csio.sense_data),
1215 CAM_TAG_ACTION_NONE,
1216 /*sense_len*/SSD_FULL_SIZE,
1218 done_ccb->ccb_h.pinfo.priority--;
1219 done_ccb->ccb_h.flags |= CAM_DEV_QFREEZE;
1220 done_ccb->ccb_h.saved_ccb_ptr = save_ccb;
1221 done_ccb->ccb_h.recovery_depth++;
1222 xpt_action(done_ccb);
1227 bcopy(saved_ccb, done_ccb, sizeof(*done_ccb));
1228 xpt_free_ccb(saved_ccb);
1229 periph->flags &= ~CAM_PERIPH_RECOVERY_INPROG;
1230 xpt_action(done_ccb);
1234 /* decrement the retry count */
1236 * XXX This isn't appropriate in all cases. Restructure,
1237 * so that the retry count is only decremented on an
1238 * actual retry. Remeber that the orignal ccb had its
1239 * retry count dropped before entering recovery, so
1240 * doing it again is a bug.
1242 if (done_ccb->ccb_h.retry_count > 0)
1243 done_ccb->ccb_h.retry_count--;
1245 * Drop freeze taken due to CAM_DEV_QFREEZE flag set on recovery
1248 cam_release_devq(done_ccb->ccb_h.path,
1249 /*relsim_flags*/relsim_flags,
1252 /*getcount_only*/0);
1253 /* Drop freeze taken, if this recovery request got error. */
1255 cam_release_devq(done_ccb->ccb_h.path,
1259 /*getcount_only*/0);
1264 * Generic Async Event handler. Peripheral drivers usually
1265 * filter out the events that require personal attention,
1266 * and leave the rest to this function.
1269 cam_periph_async(struct cam_periph *periph, u_int32_t code,
1270 struct cam_path *path, void *arg)
1273 case AC_LOST_DEVICE:
1274 cam_periph_invalidate(periph);
1282 cam_periph_bus_settle(struct cam_periph *periph, u_int bus_settle)
1284 struct ccb_getdevstats cgds;
1286 xpt_setup_ccb(&cgds.ccb_h, periph->path, CAM_PRIORITY_NORMAL);
1287 cgds.ccb_h.func_code = XPT_GDEV_STATS;
1288 xpt_action((union ccb *)&cgds);
1289 cam_periph_freeze_after_event(periph, &cgds.last_reset, bus_settle);
1293 cam_periph_freeze_after_event(struct cam_periph *periph,
1294 struct timeval* event_time, u_int duration_ms)
1296 struct timeval delta;
1297 struct timeval duration_tv;
1300 timevalsub(&delta, event_time);
1301 duration_tv.tv_sec = duration_ms / 1000;
1302 duration_tv.tv_usec = (duration_ms % 1000) * 1000;
1303 if (timevalcmp(&delta, &duration_tv, <)) {
1304 timevalsub(&duration_tv, &delta);
1306 duration_ms = duration_tv.tv_sec * 1000;
1307 duration_ms += duration_tv.tv_usec / 1000;
1308 cam_freeze_devq(periph->path);
1309 cam_release_devq(periph->path,
1310 RELSIM_RELEASE_AFTER_TIMEOUT,
1312 /*timeout*/duration_ms,
1313 /*getcount_only*/0);
1319 camperiphscsistatuserror(union ccb *ccb, cam_flags camflags,
1320 u_int32_t sense_flags,
1321 int *openings, u_int32_t *relsim_flags,
1322 u_int32_t *timeout, const char **action_string)
1326 switch (ccb->csio.scsi_status) {
1327 case SCSI_STATUS_OK:
1328 case SCSI_STATUS_COND_MET:
1329 case SCSI_STATUS_INTERMED:
1330 case SCSI_STATUS_INTERMED_COND_MET:
1333 case SCSI_STATUS_CMD_TERMINATED:
1334 case SCSI_STATUS_CHECK_COND:
1336 xpt_print(ccb->ccb_h.path, "SCSI status error\n");
1337 error = camperiphscsisenseerror(ccb,
1345 case SCSI_STATUS_QUEUE_FULL:
1348 struct ccb_getdevstats cgds;
1351 * First off, find out what the current
1352 * transaction counts are.
1354 xpt_setup_ccb(&cgds.ccb_h,
1356 CAM_PRIORITY_NORMAL);
1357 cgds.ccb_h.func_code = XPT_GDEV_STATS;
1358 xpt_action((union ccb *)&cgds);
1361 * If we were the only transaction active, treat
1362 * the QUEUE FULL as if it were a BUSY condition.
1364 if (cgds.dev_active != 0) {
1368 * Reduce the number of openings to
1369 * be 1 less than the amount it took
1370 * to get a queue full bounded by the
1371 * minimum allowed tag count for this
1374 total_openings = cgds.dev_active + cgds.dev_openings;
1375 *openings = cgds.dev_active;
1376 if (*openings < cgds.mintags)
1377 *openings = cgds.mintags;
1378 if (*openings < total_openings)
1379 *relsim_flags = RELSIM_ADJUST_OPENINGS;
1382 * Some devices report queue full for
1383 * temporary resource shortages. For
1384 * this reason, we allow a minimum
1385 * tag count to be entered via a
1386 * quirk entry to prevent the queue
1387 * count on these devices from falling
1388 * to a pessimisticly low value. We
1389 * still wait for the next successful
1390 * completion, however, before queueing
1391 * more transactions to the device.
1393 *relsim_flags = RELSIM_RELEASE_AFTER_CMDCMPLT;
1398 xpt_print(ccb->ccb_h.path, "Queue full\n");
1404 case SCSI_STATUS_BUSY:
1406 * Restart the queue after either another
1407 * command completes or a 1 second timeout.
1410 xpt_print(ccb->ccb_h.path, "Device busy\n");
1412 if (ccb->ccb_h.retry_count > 0) {
1413 ccb->ccb_h.retry_count--;
1415 *relsim_flags = RELSIM_RELEASE_AFTER_TIMEOUT
1416 | RELSIM_RELEASE_AFTER_CMDCMPLT;
1422 case SCSI_STATUS_RESERV_CONFLICT:
1423 xpt_print(ccb->ccb_h.path, "Reservation conflict\n");
1427 xpt_print(ccb->ccb_h.path, "SCSI status 0x%x\n",
1428 ccb->csio.scsi_status);
1436 camperiphscsisenseerror(union ccb *ccb, cam_flags camflags,
1437 u_int32_t sense_flags,
1438 int *openings, u_int32_t *relsim_flags,
1439 u_int32_t *timeout, const char **action_string)
1441 struct cam_periph *periph;
1442 union ccb *orig_ccb = ccb;
1445 periph = xpt_path_periph(ccb->ccb_h.path);
1447 (CAM_PERIPH_RECOVERY_INPROG | CAM_PERIPH_SENSE_INPROG)) {
1449 * If error recovery is already in progress, don't attempt
1450 * to process this error, but requeue it unconditionally
1451 * and attempt to process it once error recovery has
1452 * completed. This failed command is probably related to
1453 * the error that caused the currently active error recovery
1454 * action so our current recovery efforts should also
1455 * address this command. Be aware that the error recovery
1456 * code assumes that only one recovery action is in progress
1457 * on a particular peripheral instance at any given time
1458 * (e.g. only one saved CCB for error recovery) so it is
1459 * imperitive that we don't violate this assumption.
1463 scsi_sense_action err_action;
1464 struct ccb_getdev cgd;
1467 * Grab the inquiry data for this device.
1469 xpt_setup_ccb(&cgd.ccb_h, ccb->ccb_h.path, CAM_PRIORITY_NORMAL);
1470 cgd.ccb_h.func_code = XPT_GDEV_TYPE;
1471 xpt_action((union ccb *)&cgd);
1473 if ((ccb->ccb_h.status & CAM_AUTOSNS_VALID) != 0)
1474 err_action = scsi_error_action(&ccb->csio,
1477 else if ((ccb->ccb_h.flags & CAM_DIS_AUTOSENSE) == 0)
1478 err_action = SS_REQSENSE;
1480 err_action = SS_RETRY|SSQ_DECREMENT_COUNT|EIO;
1482 error = err_action & SS_ERRMASK;
1485 * If the recovery action will consume a retry,
1486 * make sure we actually have retries available.
1488 if ((err_action & SSQ_DECREMENT_COUNT) != 0) {
1489 if (ccb->ccb_h.retry_count > 0)
1490 ccb->ccb_h.retry_count--;
1492 *action_string = "Retries exhausted";
1493 goto sense_error_done;
1497 if ((err_action & SS_MASK) >= SS_START) {
1499 * Do common portions of commands that
1500 * use recovery CCBs.
1502 orig_ccb = xpt_alloc_ccb_nowait();
1503 if (orig_ccb == NULL) {
1504 *action_string = "Can't allocate recovery CCB";
1505 goto sense_error_done;
1508 * Clear freeze flag for original request here, as
1509 * this freeze will be dropped as part of ERESTART.
1511 ccb->ccb_h.status &= ~CAM_DEV_QFRZN;
1512 bcopy(ccb, orig_ccb, sizeof(*orig_ccb));
1515 switch (err_action & SS_MASK) {
1517 *action_string = "No recovery action needed";
1521 *action_string = "Retrying command (per sense data)";
1525 *action_string = "Unretryable error";
1532 * Send a start unit command to the device, and
1533 * then retry the command.
1535 *action_string = "Attempting to start unit";
1536 periph->flags |= CAM_PERIPH_RECOVERY_INPROG;
1539 * Check for removable media and set
1540 * load/eject flag appropriately.
1542 if (SID_IS_REMOVABLE(&cgd.inq_data))
1547 scsi_start_stop(&ccb->csio,
1561 * Send a Test Unit Ready to the device.
1562 * If the 'many' flag is set, we send 120
1563 * test unit ready commands, one every half
1564 * second. Otherwise, we just send one TUR.
1565 * We only want to do this if the retry
1566 * count has not been exhausted.
1570 if ((err_action & SSQ_MANY) != 0) {
1571 *action_string = "Polling device for readiness";
1574 *action_string = "Testing device for readiness";
1577 periph->flags |= CAM_PERIPH_RECOVERY_INPROG;
1578 scsi_test_unit_ready(&ccb->csio,
1586 * Accomplish our 500ms delay by deferring
1587 * the release of our device queue appropriately.
1589 *relsim_flags = RELSIM_RELEASE_AFTER_TIMEOUT;
1595 *action_string = "Requesting SCSI sense data";
1596 periph->flags |= CAM_PERIPH_SENSE_INPROG;
1598 * Send a Request Sense to the device. We
1599 * assume that we are in a contingent allegiance
1600 * condition so we do not tag this request.
1602 scsi_request_sense(&ccb->csio, /*retries*/1,
1604 &orig_ccb->csio.sense_data,
1605 sizeof(orig_ccb->csio.sense_data),
1606 CAM_TAG_ACTION_NONE,
1607 /*sense_len*/SSD_FULL_SIZE,
1612 panic("Unhandled error action %x", err_action);
1615 if ((err_action & SS_MASK) >= SS_START) {
1617 * Drop the priority, so that the recovery
1618 * CCB is the first to execute. Freeze the queue
1619 * after this command is sent so that we can
1620 * restore the old csio and have it queued in
1621 * the proper order before we release normal
1622 * transactions to the device.
1624 ccb->ccb_h.pinfo.priority--;
1625 ccb->ccb_h.flags |= CAM_DEV_QFREEZE;
1626 ccb->ccb_h.saved_ccb_ptr = orig_ccb;
1627 ccb->ccb_h.recovery_depth = 0;
1632 if ((err_action & SSQ_PRINT_SENSE) != 0
1633 && (ccb->ccb_h.status & CAM_AUTOSNS_VALID) != 0)
1634 cam_error_print(orig_ccb, CAM_ESF_ALL, CAM_EPF_ALL);
1640 * Generic error handler. Peripheral drivers usually filter
1641 * out the errors that they handle in a unique mannor, then
1642 * call this function.
1645 cam_periph_error(union ccb *ccb, cam_flags camflags,
1646 u_int32_t sense_flags, union ccb *save_ccb)
1648 const char *action_string;
1651 int error, printed = 0;
1653 u_int32_t relsim_flags;
1654 u_int32_t timeout = 0;
1656 action_string = NULL;
1657 status = ccb->ccb_h.status;
1658 frozen = (status & CAM_DEV_QFRZN) != 0;
1659 status &= CAM_STATUS_MASK;
1660 openings = relsim_flags = 0;
1666 case CAM_SCSI_STATUS_ERROR:
1667 error = camperiphscsistatuserror(ccb,
1675 case CAM_AUTOSENSE_FAIL:
1676 xpt_print(ccb->ccb_h.path, "AutoSense failed\n");
1677 error = EIO; /* we have to kill the command */
1679 case CAM_ATA_STATUS_ERROR:
1680 if (bootverbose && printed == 0) {
1681 xpt_print(ccb->ccb_h.path, "ATA status error\n");
1682 cam_error_print(ccb, CAM_ESF_ALL, CAM_EPF_ALL);
1686 case CAM_REQ_CMP_ERR:
1687 if (bootverbose && printed == 0) {
1688 xpt_print(ccb->ccb_h.path,
1689 "Request completed with CAM_REQ_CMP_ERR\n");
1693 case CAM_CMD_TIMEOUT:
1694 if (bootverbose && printed == 0) {
1695 xpt_print(ccb->ccb_h.path, "Command timed out\n");
1699 case CAM_UNEXP_BUSFREE:
1700 if (bootverbose && printed == 0) {
1701 xpt_print(ccb->ccb_h.path, "Unexpected Bus Free\n");
1705 case CAM_UNCOR_PARITY:
1706 if (bootverbose && printed == 0) {
1707 xpt_print(ccb->ccb_h.path,
1708 "Uncorrected parity error\n");
1712 case CAM_DATA_RUN_ERR:
1713 if (bootverbose && printed == 0) {
1714 xpt_print(ccb->ccb_h.path, "Data overrun\n");
1717 error = EIO; /* we have to kill the command */
1718 /* decrement the number of retries */
1719 if (ccb->ccb_h.retry_count > 0) {
1720 ccb->ccb_h.retry_count--;
1723 action_string = "Retries exhausted";
1729 case CAM_MSG_REJECT_REC:
1730 /* XXX Don't know that these are correct */
1733 case CAM_SEL_TIMEOUT:
1735 struct cam_path *newpath;
1737 if ((camflags & CAM_RETRY_SELTO) != 0) {
1738 if (ccb->ccb_h.retry_count > 0) {
1740 ccb->ccb_h.retry_count--;
1742 if (bootverbose && printed == 0) {
1743 xpt_print(ccb->ccb_h.path,
1744 "Selection timeout\n");
1749 * Wait a bit to give the device
1750 * time to recover before we try again.
1752 relsim_flags = RELSIM_RELEASE_AFTER_TIMEOUT;
1753 timeout = periph_selto_delay;
1758 /* Should we do more if we can't create the path?? */
1759 if (xpt_create_path(&newpath, xpt_path_periph(ccb->ccb_h.path),
1760 xpt_path_path_id(ccb->ccb_h.path),
1761 xpt_path_target_id(ccb->ccb_h.path),
1762 CAM_LUN_WILDCARD) != CAM_REQ_CMP)
1766 * Let peripheral drivers know that this device has gone
1769 xpt_async(AC_LOST_DEVICE, newpath, NULL);
1770 xpt_free_path(newpath);
1773 case CAM_REQ_INVALID:
1774 case CAM_PATH_INVALID:
1775 case CAM_DEV_NOT_THERE:
1777 case CAM_PROVIDE_FAIL:
1778 case CAM_REQ_TOO_BIG:
1779 case CAM_LUN_INVALID:
1780 case CAM_TID_INVALID:
1783 case CAM_SCSI_BUS_RESET:
1786 * Commands that repeatedly timeout and cause these
1787 * kinds of error recovery actions, should return
1788 * CAM_CMD_TIMEOUT, which allows us to safely assume
1789 * that this command was an innocent bystander to
1790 * these events and should be unconditionally
1793 if (bootverbose && printed == 0) {
1794 xpt_print_path(ccb->ccb_h.path);
1795 if (status == CAM_BDR_SENT)
1796 printf("Bus Device Reset sent\n");
1798 printf("Bus Reset issued\n");
1802 case CAM_REQUEUE_REQ:
1803 /* Unconditional requeue */
1805 if (bootverbose && printed == 0) {
1806 xpt_print(ccb->ccb_h.path, "Request requeued\n");
1810 case CAM_RESRC_UNAVAIL:
1811 /* Wait a bit for the resource shortage to abate. */
1812 timeout = periph_noresrc_delay;
1816 /* Wait a bit for the busy condition to abate. */
1817 timeout = periph_busy_delay;
1819 relsim_flags = RELSIM_RELEASE_AFTER_TIMEOUT;
1822 /* decrement the number of retries */
1823 if (ccb->ccb_h.retry_count > 0) {
1824 ccb->ccb_h.retry_count--;
1826 if (bootverbose && printed == 0) {
1827 xpt_print(ccb->ccb_h.path, "CAM status 0x%x\n",
1833 action_string = "Retries exhausted";
1839 * If we have and error and are booting verbosely, whine
1840 * *unless* this was a non-retryable selection timeout.
1842 if (error != 0 && bootverbose &&
1843 !(status == CAM_SEL_TIMEOUT && (camflags & CAM_RETRY_SELTO) == 0)) {
1844 if (error != ERESTART) {
1845 if (action_string == NULL)
1846 action_string = "Unretryable error";
1847 xpt_print(ccb->ccb_h.path, "Error %d, %s\n",
1848 error, action_string);
1849 } else if (action_string != NULL)
1850 xpt_print(ccb->ccb_h.path, "%s\n", action_string);
1852 xpt_print(ccb->ccb_h.path, "Retrying command\n");
1855 /* Attempt a retry */
1856 if (error == ERESTART || error == 0) {
1858 ccb->ccb_h.status &= ~CAM_DEV_QFRZN;
1859 if (error == ERESTART)
1862 cam_release_devq(ccb->ccb_h.path,
1866 /*getcount_only*/0);