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
29 * $FreeBSD: src/sys/cam/cam_periph.c,v 1.70 2008/02/12 11:07:33 raj Exp $
30 * $DragonFly: src/sys/bus/cam/cam_periph.c,v 1.40.2.1 2008/07/18 00:08:22 dillon Exp $
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>
41 #include <sys/devicestat.h>
44 #include <vm/vm_extern.h>
46 #include <sys/thread2.h>
50 #include "cam_xpt_periph.h"
51 #include "cam_periph.h"
52 #include "cam_debug.h"
55 #include <bus/cam/scsi/scsi_all.h>
56 #include <bus/cam/scsi/scsi_message.h>
57 #include <bus/cam/scsi/scsi_pass.h>
59 static u_int
camperiphnextunit(struct periph_driver
*p_drv
,
60 u_int newunit
, int wired
,
61 path_id_t pathid
, target_id_t target
,
63 static u_int
camperiphunit(struct periph_driver
*p_drv
,
64 path_id_t pathid
, target_id_t target
,
66 static void camperiphdone(struct cam_periph
*periph
,
68 static void camperiphfree(struct cam_periph
*periph
);
69 static int camperiphscsistatuserror(union ccb
*ccb
,
71 u_int32_t sense_flags
,
74 u_int32_t
*relsim_flags
,
76 static int camperiphscsisenseerror(union ccb
*ccb
,
78 u_int32_t sense_flags
,
81 u_int32_t
*relsim_flags
,
84 static int nperiph_drivers
;
85 struct periph_driver
**periph_drivers
;
87 MALLOC_DEFINE(M_CAMPERIPH
, "CAM periph", "CAM peripheral buffers");
89 static int periph_selto_delay
= 1000;
90 TUNABLE_INT("kern.cam.periph_selto_delay", &periph_selto_delay
);
91 static int periph_noresrc_delay
= 500;
92 TUNABLE_INT("kern.cam.periph_noresrc_delay", &periph_noresrc_delay
);
93 static int periph_busy_delay
= 500;
94 TUNABLE_INT("kern.cam.periph_busy_delay", &periph_busy_delay
);
98 periphdriver_register(void *data
)
100 struct periph_driver
**newdrivers
, **old
;
103 ndrivers
= nperiph_drivers
+ 2;
104 newdrivers
= kmalloc(sizeof(*newdrivers
) * ndrivers
, M_CAMPERIPH
,
107 bcopy(periph_drivers
, newdrivers
,
108 sizeof(*newdrivers
) * nperiph_drivers
);
109 newdrivers
[nperiph_drivers
] = (struct periph_driver
*)data
;
110 newdrivers
[nperiph_drivers
+ 1] = NULL
;
111 old
= periph_drivers
;
112 periph_drivers
= newdrivers
;
114 kfree(old
, M_CAMPERIPH
);
119 cam_periph_alloc(periph_ctor_t
*periph_ctor
,
120 periph_oninv_t
*periph_oninvalidate
,
121 periph_dtor_t
*periph_dtor
, periph_start_t
*periph_start
,
122 char *name
, cam_periph_type type
, struct cam_path
*path
,
123 ac_callback_t
*ac_callback
, ac_code code
, void *arg
)
125 struct periph_driver
**p_drv
;
127 struct cam_periph
*periph
;
128 struct cam_periph
*cur_periph
;
130 target_id_t target_id
;
137 * Handle Hot-Plug scenarios. If there is already a peripheral
138 * of our type assigned to this path, we are likely waiting for
139 * final close on an old, invalidated, peripheral. If this is
140 * the case, queue up a deferred call to the peripheral's async
141 * handler. If it looks like a mistaken re-allocation, complain.
143 if ((periph
= cam_periph_find(path
, name
)) != NULL
) {
145 if ((periph
->flags
& CAM_PERIPH_INVALID
) != 0
146 && (periph
->flags
& CAM_PERIPH_NEW_DEV_FOUND
) == 0) {
147 periph
->flags
|= CAM_PERIPH_NEW_DEV_FOUND
;
148 periph
->deferred_callback
= ac_callback
;
149 periph
->deferred_ac
= code
;
150 return (CAM_REQ_INPROG
);
152 kprintf("cam_periph_alloc: attempt to re-allocate "
153 "valid device %s%d rejected\n",
154 periph
->periph_name
, periph
->unit_number
);
156 return (CAM_REQ_INVALID
);
159 periph
= kmalloc(sizeof(*periph
), M_CAMPERIPH
, M_INTWAIT
| M_ZERO
);
164 for (p_drv
= periph_drivers
; *p_drv
!= NULL
; p_drv
++) {
165 if (strcmp((*p_drv
)->driver_name
, name
) == 0)
170 sim
= xpt_path_sim(path
);
171 path_id
= xpt_path_path_id(path
);
172 target_id
= xpt_path_target_id(path
);
173 lun_id
= xpt_path_lun_id(path
);
174 cam_init_pinfo(&periph
->pinfo
);
175 periph
->periph_start
= periph_start
;
176 periph
->periph_dtor
= periph_dtor
;
177 periph
->periph_oninval
= periph_oninvalidate
;
179 periph
->periph_name
= name
;
180 periph
->unit_number
= camperiphunit(*p_drv
, path_id
, target_id
, lun_id
);
181 periph
->immediate_priority
= CAM_PRIORITY_NONE
;
182 periph
->refcount
= 0;
184 SLIST_INIT(&periph
->ccb_list
);
185 status
= xpt_create_path(&path
, periph
, path_id
, target_id
, lun_id
);
186 if (status
!= CAM_REQ_CMP
)
192 status
= xpt_add_periph(periph
);
194 if (status
!= CAM_REQ_CMP
)
197 cur_periph
= TAILQ_FIRST(&(*p_drv
)->units
);
198 while (cur_periph
!= NULL
199 && cur_periph
->unit_number
< periph
->unit_number
)
200 cur_periph
= TAILQ_NEXT(cur_periph
, unit_links
);
202 if (cur_periph
!= NULL
)
203 TAILQ_INSERT_BEFORE(cur_periph
, periph
, unit_links
);
205 TAILQ_INSERT_TAIL(&(*p_drv
)->units
, periph
, unit_links
);
206 (*p_drv
)->generation
++;
211 status
= periph_ctor(periph
, arg
);
213 if (status
== CAM_REQ_CMP
)
217 switch (init_level
) {
219 /* Initialized successfully */
222 TAILQ_REMOVE(&(*p_drv
)->units
, periph
, unit_links
);
223 xpt_remove_periph(periph
);
226 xpt_free_path(periph
->path
);
229 kfree(periph
, M_CAMPERIPH
);
232 /* No cleanup to perform. */
235 panic("cam_periph_alloc: Unknown init level");
241 * Find a peripheral structure with the specified path, target, lun,
242 * and (optionally) type. If the name is NULL, this function will return
243 * the first peripheral driver that matches the specified path.
246 cam_periph_find(struct cam_path
*path
, char *name
)
248 struct periph_driver
**p_drv
;
249 struct cam_periph
*periph
;
252 for (p_drv
= periph_drivers
; *p_drv
!= NULL
; p_drv
++) {
253 if (name
!= NULL
&& (strcmp((*p_drv
)->driver_name
, name
) != 0))
256 TAILQ_FOREACH(periph
, &(*p_drv
)->units
, unit_links
) {
257 if (xpt_path_comp(periph
->path
, path
) == 0) {
272 cam_periph_acquire(struct cam_periph
*periph
)
275 return(CAM_REQ_CMP_ERR
);
285 cam_periph_release(struct cam_periph
*periph
)
292 if ((--periph
->refcount
== 0)
293 && (periph
->flags
& CAM_PERIPH_INVALID
)) {
294 camperiphfree(periph
);
301 cam_periph_hold(struct cam_periph
*periph
, int flags
)
305 sim_lock_assert_owned(periph
->sim
->lock
);
308 * Increment the reference count on the peripheral
309 * while we wait for our lock attempt to succeed
310 * to ensure the peripheral doesn't disappear out
311 * from user us while we sleep.
314 if (cam_periph_acquire(periph
) != CAM_REQ_CMP
)
317 while ((periph
->flags
& CAM_PERIPH_LOCKED
) != 0) {
318 periph
->flags
|= CAM_PERIPH_LOCK_WANTED
;
319 if ((error
= sim_lock_sleep(periph
, flags
, "caplck", 0,
320 periph
->sim
->lock
)) != 0) {
321 cam_periph_release(periph
);
326 periph
->flags
|= CAM_PERIPH_LOCKED
;
331 cam_periph_unhold(struct cam_periph
*periph
, int unlock
)
335 sim_lock_assert_owned(periph
->sim
->lock
);
336 periph
->flags
&= ~CAM_PERIPH_LOCKED
;
337 if ((periph
->flags
& CAM_PERIPH_LOCK_WANTED
) != 0) {
338 periph
->flags
&= ~CAM_PERIPH_LOCK_WANTED
;
343 cam_periph_release(periph
);
344 /* periph may be garbage now */
347 cam_periph_release(periph
);
352 * Look for the next unit number that is not currently in use for this
353 * peripheral type starting at "newunit". Also exclude unit numbers that
354 * are reserved by for future "hardwiring" unless we already know that this
355 * is a potential wired device. Only assume that the device is "wired" the
356 * first time through the loop since after that we'll be looking at unit
357 * numbers that did not match a wiring entry.
360 camperiphnextunit(struct periph_driver
*p_drv
, u_int newunit
, int wired
,
361 path_id_t pathid
, target_id_t target
, lun_id_t lun
)
363 struct cam_periph
*periph
;
364 char *periph_name
, *strval
;
368 periph_name
= p_drv
->driver_name
;
371 for (periph
= TAILQ_FIRST(&p_drv
->units
);
372 periph
!= NULL
&& periph
->unit_number
!= newunit
;
373 periph
= TAILQ_NEXT(periph
, unit_links
))
376 if (periph
!= NULL
&& periph
->unit_number
== newunit
) {
378 xpt_print(periph
->path
, "Duplicate Wired "
380 xpt_print(periph
->path
, "Second device (%s "
381 "device at scbus%d target %d lun %d) will "
382 "not be wired\n", periph_name
, pathid
,
392 * Don't match entries like "da 4" as a wired down
393 * device, but do match entries like "da 4 target 5"
394 * or even "da 4 scbus 1".
397 while ((i
= resource_locate(i
, periph_name
)) != -1) {
398 dname
= resource_query_name(i
);
399 dunit
= resource_query_unit(i
);
400 /* if no "target" and no specific scbus, skip */
401 if (resource_int_value(dname
, dunit
, "target", &val
) &&
402 (resource_string_value(dname
, dunit
, "at",&strval
)||
403 strcmp(strval
, "scbus") == 0))
405 if (newunit
== dunit
)
415 camperiphunit(struct periph_driver
*p_drv
, path_id_t pathid
,
416 target_id_t target
, lun_id_t lun
)
419 int hit
, i
, val
, dunit
;
421 char pathbuf
[32], *strval
, *periph_name
;
425 periph_name
= p_drv
->driver_name
;
426 ksnprintf(pathbuf
, sizeof(pathbuf
), "scbus%d", pathid
);
428 for (hit
= 0; (i
= resource_locate(i
, periph_name
)) != -1; hit
= 0) {
429 dname
= resource_query_name(i
);
430 dunit
= resource_query_unit(i
);
431 if (resource_string_value(dname
, dunit
, "at", &strval
) == 0) {
432 if (strcmp(strval
, pathbuf
) != 0)
436 if (resource_int_value(dname
, dunit
, "target", &val
) == 0) {
441 if (resource_int_value(dname
, dunit
, "lun", &val
) == 0) {
453 * Either start from 0 looking for the next unit or from
454 * the unit number given in the resource config. This way,
455 * if we have wildcard matches, we don't return the same
458 unit
= camperiphnextunit(p_drv
, unit
, /*wired*/hit
, pathid
,
465 cam_periph_invalidate(struct cam_periph
*periph
)
468 * We only call this routine the first time a peripheral is
471 if (((periph
->flags
& CAM_PERIPH_INVALID
) == 0)
472 && (periph
->periph_oninval
!= NULL
))
473 periph
->periph_oninval(periph
);
475 periph
->flags
|= CAM_PERIPH_INVALID
;
476 periph
->flags
&= ~CAM_PERIPH_NEW_DEV_FOUND
;
479 if (periph
->refcount
== 0)
480 camperiphfree(periph
);
481 else if (periph
->refcount
< 0)
482 kprintf("cam_invalidate_periph: refcount < 0!!\n");
487 camperiphfree(struct cam_periph
*periph
)
489 struct periph_driver
**p_drv
;
491 for (p_drv
= periph_drivers
; *p_drv
!= NULL
; p_drv
++) {
492 if (strcmp((*p_drv
)->driver_name
, periph
->periph_name
) == 0)
496 if (*p_drv
== NULL
) {
497 kprintf("camperiphfree: attempt to free non-existent periph\n");
501 TAILQ_REMOVE(&(*p_drv
)->units
, periph
, unit_links
);
502 (*p_drv
)->generation
++;
505 if (periph
->periph_dtor
!= NULL
)
506 periph
->periph_dtor(periph
);
507 xpt_remove_periph(periph
);
509 if (periph
->flags
& CAM_PERIPH_NEW_DEV_FOUND
) {
513 switch (periph
->deferred_ac
) {
514 case AC_FOUND_DEVICE
:
515 ccb
.ccb_h
.func_code
= XPT_GDEV_TYPE
;
516 xpt_setup_ccb(&ccb
.ccb_h
, periph
->path
, /*priority*/ 1);
520 case AC_PATH_REGISTERED
:
521 ccb
.ccb_h
.func_code
= XPT_PATH_INQ
;
522 xpt_setup_ccb(&ccb
.ccb_h
, periph
->path
, /*priority*/ 1);
530 periph
->deferred_callback(NULL
, periph
->deferred_ac
,
533 xpt_free_path(periph
->path
);
534 kfree(periph
, M_CAMPERIPH
);
539 * Map user virtual pointers into kernel virtual address space, so we can
540 * access the memory. This won't work on physical pointers, for now it's
541 * up to the caller to check for that. (XXX KDM -- should we do that here
542 * instead?) This also only works for up to MAXPHYS memory. Since we use
543 * buffers to map stuff in and out, we're limited to the buffer size.
546 cam_periph_mapmem(union ccb
*ccb
, struct cam_periph_map_info
*mapinfo
)
549 buf_cmd_t cmd
[CAM_PERIPH_MAXMAPS
];
550 u_int8_t
**data_ptrs
[CAM_PERIPH_MAXMAPS
];
551 u_int32_t lengths
[CAM_PERIPH_MAXMAPS
];
552 u_int32_t dirs
[CAM_PERIPH_MAXMAPS
];
554 switch(ccb
->ccb_h
.func_code
) {
556 if (ccb
->cdm
.match_buf_len
== 0) {
557 kprintf("cam_periph_mapmem: invalid match buffer "
561 if (ccb
->cdm
.pattern_buf_len
> 0) {
562 data_ptrs
[0] = (u_int8_t
**)&ccb
->cdm
.patterns
;
563 lengths
[0] = ccb
->cdm
.pattern_buf_len
;
564 dirs
[0] = CAM_DIR_OUT
;
565 data_ptrs
[1] = (u_int8_t
**)&ccb
->cdm
.matches
;
566 lengths
[1] = ccb
->cdm
.match_buf_len
;
567 dirs
[1] = CAM_DIR_IN
;
570 data_ptrs
[0] = (u_int8_t
**)&ccb
->cdm
.matches
;
571 lengths
[0] = ccb
->cdm
.match_buf_len
;
572 dirs
[0] = CAM_DIR_IN
;
577 case XPT_CONT_TARGET_IO
:
578 if ((ccb
->ccb_h
.flags
& CAM_DIR_MASK
) == CAM_DIR_NONE
)
581 data_ptrs
[0] = &ccb
->csio
.data_ptr
;
582 lengths
[0] = ccb
->csio
.dxfer_len
;
583 dirs
[0] = ccb
->ccb_h
.flags
& CAM_DIR_MASK
;
588 break; /* NOTREACHED */
592 * Check the transfer length and permissions first, so we don't
593 * have to unmap any previously mapped buffers.
595 for (i
= 0; i
< numbufs
; i
++) {
597 * Its kinda bogus, we need a R+W command. For now the
598 * buffer needs some sort of command. Use BUF_CMD_WRITE
599 * to indicate a write and BUF_CMD_READ to indicate R+W.
601 cmd
[i
] = BUF_CMD_WRITE
;
604 * The userland data pointer passed in may not be page
605 * aligned. vmapbuf() truncates the address to a page
606 * boundary, so if the address isn't page aligned, we'll
607 * need enough space for the given transfer length, plus
608 * whatever extra space is necessary to make it to the page
612 (((vm_offset_t
)(*data_ptrs
[i
])) & PAGE_MASK
)) > DFLTPHYS
){
613 kprintf("cam_periph_mapmem: attempt to map %lu bytes, "
614 "which is greater than DFLTPHYS(%d)\n",
616 (((vm_offset_t
)(*data_ptrs
[i
])) & PAGE_MASK
)),
621 if (dirs
[i
] & CAM_DIR_OUT
) {
622 if (!useracc(*data_ptrs
[i
], lengths
[i
],
624 kprintf("cam_periph_mapmem: error, "
625 "address %p, length %lu isn't "
626 "user accessible for READ\n",
627 (void *)*data_ptrs
[i
],
633 if (dirs
[i
] & CAM_DIR_IN
) {
634 cmd
[i
] = BUF_CMD_READ
;
635 if (!useracc(*data_ptrs
[i
], lengths
[i
],
637 kprintf("cam_periph_mapmem: error, "
638 "address %p, length %lu isn't "
639 "user accessible for WRITE\n",
640 (void *)*data_ptrs
[i
],
649 for (i
= 0; i
< numbufs
; i
++) {
653 mapinfo
->bp
[i
] = getpbuf(NULL
);
655 /* save the original user pointer */
656 mapinfo
->saved_ptrs
[i
] = *data_ptrs
[i
];
659 mapinfo
->bp
[i
]->b_cmd
= cmd
[i
];
661 /* map the user buffer into kernel memory */
662 if (vmapbuf(mapinfo
->bp
[i
], *data_ptrs
[i
], lengths
[i
]) < 0) {
663 kprintf("cam_periph_mapmem: error, "
664 "address %p, length %lu isn't "
665 "user accessible any more\n",
666 (void *)*data_ptrs
[i
],
668 for (j
= 0; j
< i
; ++j
) {
669 *data_ptrs
[j
] = mapinfo
->saved_ptrs
[j
];
670 vunmapbuf(mapinfo
->bp
[j
]);
671 relpbuf(mapinfo
->bp
[j
], NULL
);
673 mapinfo
->num_bufs_used
-= i
;
677 /* set our pointer to the new mapped area */
678 *data_ptrs
[i
] = mapinfo
->bp
[i
]->b_data
;
680 mapinfo
->num_bufs_used
++;
687 * Unmap memory segments mapped into kernel virtual address space by
688 * cam_periph_mapmem().
691 cam_periph_unmapmem(union ccb
*ccb
, struct cam_periph_map_info
*mapinfo
)
694 u_int8_t
**data_ptrs
[CAM_PERIPH_MAXMAPS
];
696 if (mapinfo
->num_bufs_used
<= 0) {
697 /* allow ourselves to be swapped once again */
701 switch (ccb
->ccb_h
.func_code
) {
703 numbufs
= min(mapinfo
->num_bufs_used
, 2);
706 data_ptrs
[0] = (u_int8_t
**)&ccb
->cdm
.matches
;
708 data_ptrs
[0] = (u_int8_t
**)&ccb
->cdm
.patterns
;
709 data_ptrs
[1] = (u_int8_t
**)&ccb
->cdm
.matches
;
713 case XPT_CONT_TARGET_IO
:
714 data_ptrs
[0] = &ccb
->csio
.data_ptr
;
715 numbufs
= min(mapinfo
->num_bufs_used
, 1);
718 /* allow ourselves to be swapped once again */
720 break; /* NOTREACHED */
723 for (i
= 0; i
< numbufs
; i
++) {
724 /* Set the user's pointer back to the original value */
725 *data_ptrs
[i
] = mapinfo
->saved_ptrs
[i
];
727 /* unmap the buffer */
728 vunmapbuf(mapinfo
->bp
[i
]);
730 /* release the buffer */
731 relpbuf(mapinfo
->bp
[i
], NULL
);
734 /* allow ourselves to be swapped once again */
738 cam_periph_getccb(struct cam_periph
*periph
, u_int32_t priority
)
740 struct ccb_hdr
*ccb_h
;
742 sim_lock_assert_owned(periph
->sim
->lock
);
743 CAM_DEBUG(periph
->path
, CAM_DEBUG_TRACE
, ("entering cdgetccb\n"));
745 while (SLIST_FIRST(&periph
->ccb_list
) == NULL
) {
746 if (periph
->immediate_priority
> priority
)
747 periph
->immediate_priority
= priority
;
748 xpt_schedule(periph
, priority
);
749 if ((SLIST_FIRST(&periph
->ccb_list
) != NULL
)
750 && (SLIST_FIRST(&periph
->ccb_list
)->pinfo
.priority
== priority
))
752 sim_lock_sleep(&periph
->ccb_list
, 0, "cgticb", 0,
756 ccb_h
= SLIST_FIRST(&periph
->ccb_list
);
757 SLIST_REMOVE_HEAD(&periph
->ccb_list
, periph_links
.sle
);
758 return ((union ccb
*)ccb_h
);
762 cam_periph_ccbwait(union ccb
*ccb
)
766 sim
= xpt_path_sim(ccb
->ccb_h
.path
);
767 while ((ccb
->ccb_h
.pinfo
.index
!= CAM_UNQUEUED_INDEX
)
768 || ((ccb
->ccb_h
.status
& CAM_STATUS_MASK
) == CAM_REQ_INPROG
)) {
769 sim_lock_sleep(&ccb
->ccb_h
.cbfcnp
, 0, "cbwait", 0, sim
->lock
);
774 cam_periph_ioctl(struct cam_periph
*periph
, int cmd
, caddr_t addr
,
775 int (*error_routine
)(union ccb
*ccb
,
777 u_int32_t sense_flags
))
787 ccb
= cam_periph_getccb(periph
, /* priority */ 1);
788 xpt_setup_ccb(&ccb
->ccb_h
,
791 ccb
->ccb_h
.func_code
= XPT_GDEVLIST
;
794 * Basically, the point of this is that we go through
795 * getting the list of devices, until we find a passthrough
796 * device. In the current version of the CAM code, the
797 * only way to determine what type of device we're dealing
798 * with is by its name.
802 ccb
->cgdl
.status
= CAM_GDEVLIST_MORE_DEVS
;
803 while (ccb
->cgdl
.status
== CAM_GDEVLIST_MORE_DEVS
) {
805 /* we want the next device in the list */
807 if (strncmp(ccb
->cgdl
.periph_name
,
813 if ((ccb
->cgdl
.status
== CAM_GDEVLIST_LAST_DEVICE
) &&
815 ccb
->cgdl
.periph_name
[0] = '\0';
816 ccb
->cgdl
.unit_number
= 0;
821 /* copy the result back out */
822 bcopy(ccb
, addr
, sizeof(union ccb
));
824 /* and release the ccb */
825 xpt_release_ccb(ccb
);
836 cam_periph_runccb(union ccb
*ccb
,
837 int (*error_routine
)(union ccb
*ccb
,
839 u_int32_t sense_flags
),
840 cam_flags camflags
, u_int32_t sense_flags
,
847 sim
= xpt_path_sim(ccb
->ccb_h
.path
);
848 sim_lock_assert_owned(sim
->lock
);
851 * If the user has supplied a stats structure, and if we understand
852 * this particular type of ccb, record the transaction start.
854 if ((ds
!= NULL
) && (ccb
->ccb_h
.func_code
== XPT_SCSI_IO
))
855 devstat_start_transaction(ds
);
860 cam_periph_ccbwait(ccb
);
861 if ((ccb
->ccb_h
.status
& CAM_STATUS_MASK
) == CAM_REQ_CMP
)
863 else if (error_routine
!= NULL
)
864 error
= (*error_routine
)(ccb
, camflags
, sense_flags
);
868 } while (error
== ERESTART
);
870 if ((ccb
->ccb_h
.status
& CAM_DEV_QFRZN
) != 0)
871 cam_release_devq(ccb
->ccb_h
.path
,
875 /* getcount_only */ FALSE
);
877 if ((ds
!= NULL
) && (ccb
->ccb_h
.func_code
== XPT_SCSI_IO
))
878 devstat_end_transaction(ds
,
880 ccb
->csio
.tag_action
& 0xf,
881 ((ccb
->ccb_h
.flags
& CAM_DIR_MASK
) ==
882 CAM_DIR_NONE
) ? DEVSTAT_NO_DATA
:
883 (ccb
->ccb_h
.flags
& CAM_DIR_OUT
) ?
891 cam_freeze_devq(struct cam_path
*path
)
893 struct ccb_hdr ccb_h
;
895 xpt_setup_ccb(&ccb_h
, path
, /*priority*/1);
896 ccb_h
.func_code
= XPT_NOOP
;
897 ccb_h
.flags
= CAM_DEV_QFREEZE
;
898 xpt_action((union ccb
*)&ccb_h
);
902 cam_release_devq(struct cam_path
*path
, u_int32_t relsim_flags
,
903 u_int32_t openings
, u_int32_t timeout
,
906 struct ccb_relsim crs
;
908 xpt_setup_ccb(&crs
.ccb_h
, path
,
910 crs
.ccb_h
.func_code
= XPT_REL_SIMQ
;
911 crs
.ccb_h
.flags
= getcount_only
? CAM_DEV_QFREEZE
: 0;
912 crs
.release_flags
= relsim_flags
;
913 crs
.openings
= openings
;
914 crs
.release_timeout
= timeout
;
915 xpt_action((union ccb
*)&crs
);
916 return (crs
.qfrozen_cnt
);
919 #define saved_ccb_ptr ppriv_ptr0
921 camperiphdone(struct cam_periph
*periph
, union ccb
*done_ccb
)
923 union ccb
*saved_ccb
;
927 struct scsi_start_stop_unit
*scsi_cmd
;
928 u_int32_t relsim_flags
, timeout
;
929 u_int32_t qfrozen_cnt
;
932 xpt_done_ccb
= FALSE
;
933 status
= done_ccb
->ccb_h
.status
;
934 frozen
= (status
& CAM_DEV_QFRZN
) != 0;
935 sense
= (status
& CAM_AUTOSNS_VALID
) != 0;
936 status
&= CAM_STATUS_MASK
;
940 saved_ccb
= (union ccb
*)done_ccb
->ccb_h
.saved_ccb_ptr
;
943 * Unfreeze the queue once if it is already frozen..
946 qfrozen_cnt
= cam_release_devq(done_ccb
->ccb_h
.path
,
957 * If we have successfully taken a device from the not
958 * ready to ready state, re-scan the device and re-get
959 * the inquiry information. Many devices (mostly disks)
960 * don't properly report their inquiry information unless
963 * If we manually retrieved sense into a CCB and got
964 * something other than "NO SENSE" send the updated CCB
965 * back to the client via xpt_done() to be processed via
966 * the error recovery code again.
968 if (done_ccb
->ccb_h
.func_code
== XPT_SCSI_IO
) {
969 scsi_cmd
= (struct scsi_start_stop_unit
*)
970 &done_ccb
->csio
.cdb_io
.cdb_bytes
;
972 if (scsi_cmd
->opcode
== START_STOP_UNIT
)
973 xpt_async(AC_INQ_CHANGED
,
974 done_ccb
->ccb_h
.path
, NULL
);
975 if (scsi_cmd
->opcode
== REQUEST_SENSE
) {
978 sense_key
= saved_ccb
->csio
.sense_data
.flags
;
979 sense_key
&= SSD_KEY
;
980 if (sense_key
!= SSD_KEY_NO_SENSE
) {
981 saved_ccb
->ccb_h
.status
|=
984 xpt_print(saved_ccb
->ccb_h
.path
,
985 "Recovered Sense\n");
986 scsi_sense_print(&saved_ccb
->csio
);
987 cam_error_print(saved_ccb
, CAM_ESF_ALL
,
994 bcopy(done_ccb
->ccb_h
.saved_ccb_ptr
, done_ccb
,
997 periph
->flags
&= ~CAM_PERIPH_RECOVERY_INPROG
;
999 if (xpt_done_ccb
== FALSE
)
1000 xpt_action(done_ccb
);
1004 case CAM_SCSI_STATUS_ERROR
:
1005 scsi_cmd
= (struct scsi_start_stop_unit
*)
1006 &done_ccb
->csio
.cdb_io
.cdb_bytes
;
1008 struct ccb_getdev cgd
;
1009 struct scsi_sense_data
*sense
;
1010 int error_code
, sense_key
, asc
, ascq
;
1011 scsi_sense_action err_action
;
1013 sense
= &done_ccb
->csio
.sense_data
;
1014 scsi_extract_sense(sense
, &error_code
,
1015 &sense_key
, &asc
, &ascq
);
1018 * Grab the inquiry data for this device.
1020 xpt_setup_ccb(&cgd
.ccb_h
, done_ccb
->ccb_h
.path
,
1022 cgd
.ccb_h
.func_code
= XPT_GDEV_TYPE
;
1023 xpt_action((union ccb
*)&cgd
);
1024 err_action
= scsi_error_action(&done_ccb
->csio
,
1028 * If the error is "invalid field in CDB",
1029 * and the load/eject flag is set, turn the
1030 * flag off and try again. This is just in
1031 * case the drive in question barfs on the
1032 * load eject flag. The CAM code should set
1033 * the load/eject flag by default for
1038 * Should we check to see what the specific
1039 * scsi status is?? Or does it not matter
1040 * since we already know that there was an
1041 * error, and we know what the specific
1042 * error code was, and we know what the
1045 if ((scsi_cmd
->opcode
== START_STOP_UNIT
) &&
1046 ((scsi_cmd
->how
& SSS_LOEJ
) != 0) &&
1047 (asc
== 0x24) && (ascq
== 0x00) &&
1048 (done_ccb
->ccb_h
.retry_count
> 0)) {
1050 scsi_cmd
->how
&= ~SSS_LOEJ
;
1052 xpt_action(done_ccb
);
1054 } else if ((done_ccb
->ccb_h
.retry_count
> 1)
1055 && ((err_action
& SS_MASK
) != SS_FAIL
)) {
1058 * In this case, the error recovery
1059 * command failed, but we've got
1060 * some retries left on it. Give
1061 * it another try unless this is an
1062 * unretryable error.
1065 /* set the timeout to .5 sec */
1067 RELSIM_RELEASE_AFTER_TIMEOUT
;
1070 xpt_action(done_ccb
);
1076 * Perform the final retry with the original
1077 * CCB so that final error processing is
1078 * performed by the owner of the CCB.
1080 bcopy(done_ccb
->ccb_h
.saved_ccb_ptr
,
1081 done_ccb
, sizeof(union ccb
));
1083 periph
->flags
&= ~CAM_PERIPH_RECOVERY_INPROG
;
1085 xpt_action(done_ccb
);
1089 * Eh?? The command failed, but we don't
1090 * have any sense. What's up with that?
1091 * Fire the CCB again to return it to the
1094 bcopy(done_ccb
->ccb_h
.saved_ccb_ptr
,
1095 done_ccb
, sizeof(union ccb
));
1097 periph
->flags
&= ~CAM_PERIPH_RECOVERY_INPROG
;
1099 xpt_action(done_ccb
);
1104 bcopy(done_ccb
->ccb_h
.saved_ccb_ptr
, done_ccb
,
1107 periph
->flags
&= ~CAM_PERIPH_RECOVERY_INPROG
;
1109 xpt_action(done_ccb
);
1114 /* decrement the retry count */
1116 * XXX This isn't appropriate in all cases. Restructure,
1117 * so that the retry count is only decremented on an
1118 * actual retry. Remeber that the orignal ccb had its
1119 * retry count dropped before entering recovery, so
1120 * doing it again is a bug.
1122 if (done_ccb
->ccb_h
.retry_count
> 0)
1123 done_ccb
->ccb_h
.retry_count
--;
1125 qfrozen_cnt
= cam_release_devq(done_ccb
->ccb_h
.path
,
1126 /*relsim_flags*/relsim_flags
,
1129 /*getcount_only*/0);
1130 if (xpt_done_ccb
== TRUE
)
1131 (*done_ccb
->ccb_h
.cbfcnp
)(periph
, done_ccb
);
1135 * Generic Async Event handler. Peripheral drivers usually
1136 * filter out the events that require personal attention,
1137 * and leave the rest to this function.
1140 cam_periph_async(struct cam_periph
*periph
, u_int32_t code
,
1141 struct cam_path
*path
, void *arg
)
1144 case AC_LOST_DEVICE
:
1145 cam_periph_invalidate(periph
);
1150 cam_periph_bus_settle(periph
, scsi_delay
);
1159 cam_periph_bus_settle(struct cam_periph
*periph
, u_int bus_settle
)
1161 struct ccb_getdevstats cgds
;
1163 xpt_setup_ccb(&cgds
.ccb_h
, periph
->path
, /*priority*/1);
1164 cgds
.ccb_h
.func_code
= XPT_GDEV_STATS
;
1165 xpt_action((union ccb
*)&cgds
);
1166 cam_periph_freeze_after_event(periph
, &cgds
.last_reset
, bus_settle
);
1170 cam_periph_freeze_after_event(struct cam_periph
*periph
,
1171 struct timeval
* event_time
, u_int duration_ms
)
1173 struct timeval delta
;
1174 struct timeval duration_tv
;
1176 microuptime(&delta
);
1177 timevalsub(&delta
, event_time
);
1178 duration_tv
.tv_sec
= duration_ms
/ 1000;
1179 duration_tv
.tv_usec
= (duration_ms
% 1000) * 1000;
1180 if (timevalcmp(&delta
, &duration_tv
, <)) {
1181 timevalsub(&duration_tv
, &delta
);
1183 duration_ms
= duration_tv
.tv_sec
* 1000;
1184 duration_ms
+= duration_tv
.tv_usec
/ 1000;
1185 cam_freeze_devq(periph
->path
);
1186 cam_release_devq(periph
->path
,
1187 RELSIM_RELEASE_AFTER_TIMEOUT
,
1189 /*timeout*/duration_ms
,
1190 /*getcount_only*/0);
1196 camperiphscsistatuserror(union ccb
*ccb
, cam_flags camflags
,
1197 u_int32_t sense_flags
, union ccb
*save_ccb
,
1198 int *openings
, u_int32_t
*relsim_flags
,
1203 switch (ccb
->csio
.scsi_status
) {
1204 case SCSI_STATUS_OK
:
1205 case SCSI_STATUS_COND_MET
:
1206 case SCSI_STATUS_INTERMED
:
1207 case SCSI_STATUS_INTERMED_COND_MET
:
1210 case SCSI_STATUS_CMD_TERMINATED
:
1211 case SCSI_STATUS_CHECK_COND
:
1212 error
= camperiphscsisenseerror(ccb
,
1220 case SCSI_STATUS_QUEUE_FULL
:
1223 struct ccb_getdevstats cgds
;
1226 * First off, find out what the current
1227 * transaction counts are.
1229 xpt_setup_ccb(&cgds
.ccb_h
,
1232 cgds
.ccb_h
.func_code
= XPT_GDEV_STATS
;
1233 xpt_action((union ccb
*)&cgds
);
1236 * If we were the only transaction active, treat
1237 * the QUEUE FULL as if it were a BUSY condition.
1239 if (cgds
.dev_active
!= 0) {
1243 * Reduce the number of openings to
1244 * be 1 less than the amount it took
1245 * to get a queue full bounded by the
1246 * minimum allowed tag count for this
1249 total_openings
= cgds
.dev_active
+ cgds
.dev_openings
;
1250 *openings
= cgds
.dev_active
;
1251 if (*openings
< cgds
.mintags
)
1252 *openings
= cgds
.mintags
;
1253 if (*openings
< total_openings
)
1254 *relsim_flags
= RELSIM_ADJUST_OPENINGS
;
1257 * Some devices report queue full for
1258 * temporary resource shortages. For
1259 * this reason, we allow a minimum
1260 * tag count to be entered via a
1261 * quirk entry to prevent the queue
1262 * count on these devices from falling
1263 * to a pessimisticly low value. We
1264 * still wait for the next successful
1265 * completion, however, before queueing
1266 * more transactions to the device.
1268 *relsim_flags
= RELSIM_RELEASE_AFTER_CMDCMPLT
;
1273 xpt_print(ccb
->ccb_h
.path
, "Queue Full\n");
1279 case SCSI_STATUS_BUSY
:
1281 * Restart the queue after either another
1282 * command completes or a 1 second timeout.
1285 xpt_print(ccb
->ccb_h
.path
, "Device Busy\n");
1287 if (ccb
->ccb_h
.retry_count
> 0) {
1288 ccb
->ccb_h
.retry_count
--;
1290 *relsim_flags
= RELSIM_RELEASE_AFTER_TIMEOUT
1291 | RELSIM_RELEASE_AFTER_CMDCMPLT
;
1297 case SCSI_STATUS_RESERV_CONFLICT
:
1298 xpt_print(ccb
->ccb_h
.path
, "Reservation Conflict\n");
1302 xpt_print(ccb
->ccb_h
.path
, "SCSI Status 0x%x\n",
1303 ccb
->csio
.scsi_status
);
1311 camperiphscsisenseerror(union ccb
*ccb
, cam_flags camflags
,
1312 u_int32_t sense_flags
, union ccb
*save_ccb
,
1313 int *openings
, u_int32_t
*relsim_flags
,
1316 struct cam_periph
*periph
;
1319 periph
= xpt_path_periph(ccb
->ccb_h
.path
);
1320 if (periph
->flags
& CAM_PERIPH_RECOVERY_INPROG
) {
1323 * If error recovery is already in progress, don't attempt
1324 * to process this error, but requeue it unconditionally
1325 * and attempt to process it once error recovery has
1326 * completed. This failed command is probably related to
1327 * the error that caused the currently active error recovery
1328 * action so our current recovery efforts should also
1329 * address this command. Be aware that the error recovery
1330 * code assumes that only one recovery action is in progress
1331 * on a particular peripheral instance at any given time
1332 * (e.g. only one saved CCB for error recovery) so it is
1333 * imperitive that we don't violate this assumption.
1337 scsi_sense_action err_action
;
1338 struct ccb_getdev cgd
;
1339 const char *action_string
;
1340 union ccb
* print_ccb
;
1342 /* A description of the error recovery action performed */
1343 action_string
= NULL
;
1346 * The location of the orignal ccb
1347 * for sense printing purposes.
1352 * Grab the inquiry data for this device.
1354 xpt_setup_ccb(&cgd
.ccb_h
, ccb
->ccb_h
.path
, /*priority*/ 1);
1355 cgd
.ccb_h
.func_code
= XPT_GDEV_TYPE
;
1356 xpt_action((union ccb
*)&cgd
);
1358 if ((ccb
->ccb_h
.status
& CAM_AUTOSNS_VALID
) != 0)
1359 err_action
= scsi_error_action(&ccb
->csio
,
1362 else if ((ccb
->ccb_h
.flags
& CAM_DIS_AUTOSENSE
) == 0)
1363 err_action
= SS_REQSENSE
;
1365 err_action
= SS_RETRY
|SSQ_DECREMENT_COUNT
|EIO
;
1367 error
= err_action
& SS_ERRMASK
;
1370 * If the recovery action will consume a retry,
1371 * make sure we actually have retries available.
1373 if ((err_action
& SSQ_DECREMENT_COUNT
) != 0) {
1374 if (ccb
->ccb_h
.retry_count
> 0)
1375 ccb
->ccb_h
.retry_count
--;
1377 action_string
= "Retries Exhausted";
1378 goto sense_error_done
;
1382 if ((err_action
& SS_MASK
) >= SS_START
) {
1384 * Do common portions of commands that
1385 * use recovery CCBs.
1387 if (save_ccb
== NULL
) {
1388 action_string
= "No recovery CCB supplied";
1389 goto sense_error_done
;
1391 bcopy(ccb
, save_ccb
, sizeof(*save_ccb
));
1392 print_ccb
= save_ccb
;
1393 periph
->flags
|= CAM_PERIPH_RECOVERY_INPROG
;
1396 switch (err_action
& SS_MASK
) {
1398 action_string
= "No Recovery Action Needed";
1402 action_string
= "Retrying Command (per Sense Data)";
1406 action_string
= "Unretryable error";
1413 * Send a start unit command to the device, and
1414 * then retry the command.
1416 action_string
= "Attempting to Start Unit";
1419 * Check for removable media and set
1420 * load/eject flag appropriately.
1422 if (SID_IS_REMOVABLE(&cgd
.inq_data
))
1427 scsi_start_stop(&ccb
->csio
,
1441 * Send a Test Unit Ready to the device.
1442 * If the 'many' flag is set, we send 120
1443 * test unit ready commands, one every half
1444 * second. Otherwise, we just send one TUR.
1445 * We only want to do this if the retry
1446 * count has not been exhausted.
1450 if ((err_action
& SSQ_MANY
) != 0) {
1451 action_string
= "Polling device for readiness";
1454 action_string
= "Testing device for readiness";
1457 scsi_test_unit_ready(&ccb
->csio
,
1465 * Accomplish our 500ms delay by deferring
1466 * the release of our device queue appropriately.
1468 *relsim_flags
= RELSIM_RELEASE_AFTER_TIMEOUT
;
1475 * Send a Request Sense to the device. We
1476 * assume that we are in a contingent allegiance
1477 * condition so we do not tag this request.
1479 scsi_request_sense(&ccb
->csio
, /*retries*/1,
1481 &save_ccb
->csio
.sense_data
,
1482 sizeof(save_ccb
->csio
.sense_data
),
1483 CAM_TAG_ACTION_NONE
,
1484 /*sense_len*/SSD_FULL_SIZE
,
1489 panic("Unhandled error action %x", err_action
);
1492 if ((err_action
& SS_MASK
) >= SS_START
) {
1494 * Drop the priority to 0 so that the recovery
1495 * CCB is the first to execute. Freeze the queue
1496 * after this command is sent so that we can
1497 * restore the old csio and have it queued in
1498 * the proper order before we release normal
1499 * transactions to the device.
1501 ccb
->ccb_h
.pinfo
.priority
= 0;
1502 ccb
->ccb_h
.flags
|= CAM_DEV_QFREEZE
;
1503 ccb
->ccb_h
.saved_ccb_ptr
= save_ccb
;
1508 if ((err_action
& SSQ_PRINT_SENSE
) != 0
1509 && (ccb
->ccb_h
.status
& CAM_AUTOSNS_VALID
) != 0) {
1510 cam_error_print(print_ccb
, CAM_ESF_ALL
, CAM_EPF_ALL
);
1511 xpt_print_path(ccb
->ccb_h
.path
);
1513 scsi_sense_print(&print_ccb
->csio
);
1514 kprintf("%s\n", action_string
);
1521 * Generic error handler. Peripheral drivers usually filter
1522 * out the errors that they handle in a unique mannor, then
1523 * call this function.
1526 cam_periph_error(union ccb
*ccb
, cam_flags camflags
,
1527 u_int32_t sense_flags
, union ccb
*save_ccb
)
1529 const char *action_string
;
1532 int error
, printed
= 0;
1534 u_int32_t relsim_flags
;
1535 u_int32_t timeout
= 0;
1537 action_string
= NULL
;
1538 status
= ccb
->ccb_h
.status
;
1539 frozen
= (status
& CAM_DEV_QFRZN
) != 0;
1540 status
&= CAM_STATUS_MASK
;
1541 openings
= relsim_flags
= 0;
1547 case CAM_SCSI_STATUS_ERROR
:
1548 error
= camperiphscsistatuserror(ccb
,
1556 case CAM_AUTOSENSE_FAIL
:
1557 xpt_print(ccb
->ccb_h
.path
, "AutoSense Failed\n");
1558 error
= EIO
; /* we have to kill the command */
1560 case CAM_REQ_CMP_ERR
:
1561 if (bootverbose
&& printed
== 0) {
1562 xpt_print(ccb
->ccb_h
.path
,
1563 "Request completed with CAM_REQ_CMP_ERR\n");
1567 case CAM_CMD_TIMEOUT
:
1568 if (bootverbose
&& printed
== 0) {
1569 xpt_print(ccb
->ccb_h
.path
, "Command timed out\n");
1573 case CAM_UNEXP_BUSFREE
:
1574 if (bootverbose
&& printed
== 0) {
1575 xpt_print(ccb
->ccb_h
.path
, "Unexpected Bus Free\n");
1579 case CAM_UNCOR_PARITY
:
1580 if (bootverbose
&& printed
== 0) {
1581 xpt_print(ccb
->ccb_h
.path
,
1582 "Uncorrected Parity Error\n");
1586 case CAM_DATA_RUN_ERR
:
1587 if (bootverbose
&& printed
== 0) {
1588 xpt_print(ccb
->ccb_h
.path
, "Data Overrun\n");
1591 error
= EIO
; /* we have to kill the command */
1592 /* decrement the number of retries */
1593 if (ccb
->ccb_h
.retry_count
> 0) {
1594 ccb
->ccb_h
.retry_count
--;
1597 action_string
= "Retries Exhausted";
1603 case CAM_MSG_REJECT_REC
:
1604 /* XXX Don't know that these are correct */
1607 case CAM_SEL_TIMEOUT
:
1609 struct cam_path
*newpath
;
1611 if ((camflags
& CAM_RETRY_SELTO
) != 0) {
1612 if (ccb
->ccb_h
.retry_count
> 0) {
1614 ccb
->ccb_h
.retry_count
--;
1616 if (bootverbose
&& printed
== 0) {
1617 xpt_print(ccb
->ccb_h
.path
,
1618 "Selection Timeout\n");
1623 * Wait a bit to give the device
1624 * time to recover before we try again.
1626 relsim_flags
= RELSIM_RELEASE_AFTER_TIMEOUT
;
1627 timeout
= periph_selto_delay
;
1632 /* Should we do more if we can't create the path?? */
1633 if (xpt_create_path(&newpath
, xpt_path_periph(ccb
->ccb_h
.path
),
1634 xpt_path_path_id(ccb
->ccb_h
.path
),
1635 xpt_path_target_id(ccb
->ccb_h
.path
),
1636 CAM_LUN_WILDCARD
) != CAM_REQ_CMP
)
1640 * Let peripheral drivers know that this device has gone
1643 xpt_async(AC_LOST_DEVICE
, newpath
, NULL
);
1644 xpt_free_path(newpath
);
1647 case CAM_REQ_INVALID
:
1648 case CAM_PATH_INVALID
:
1649 case CAM_DEV_NOT_THERE
:
1651 case CAM_PROVIDE_FAIL
:
1652 case CAM_REQ_TOO_BIG
:
1653 case CAM_LUN_INVALID
:
1654 case CAM_TID_INVALID
:
1657 case CAM_SCSI_BUS_RESET
:
1660 * Commands that repeatedly timeout and cause these
1661 * kinds of error recovery actions, should return
1662 * CAM_CMD_TIMEOUT, which allows us to safely assume
1663 * that this command was an innocent bystander to
1664 * these events and should be unconditionally
1667 if (bootverbose
&& printed
== 0) {
1668 xpt_print_path(ccb
->ccb_h
.path
);
1669 if (status
== CAM_BDR_SENT
)
1670 kprintf("Bus Device Reset sent\n");
1672 kprintf("Bus Reset issued\n");
1676 case CAM_REQUEUE_REQ
:
1677 /* Unconditional requeue */
1679 if (bootverbose
&& printed
== 0) {
1680 xpt_print(ccb
->ccb_h
.path
, "Request Requeued\n");
1684 case CAM_RESRC_UNAVAIL
:
1685 /* Wait a bit for the resource shortage to abate. */
1686 timeout
= periph_noresrc_delay
;
1690 /* Wait a bit for the busy condition to abate. */
1691 timeout
= periph_busy_delay
;
1693 relsim_flags
= RELSIM_RELEASE_AFTER_TIMEOUT
;
1696 /* decrement the number of retries */
1697 if (ccb
->ccb_h
.retry_count
> 0) {
1698 ccb
->ccb_h
.retry_count
--;
1700 if (bootverbose
&& printed
== 0) {
1701 xpt_print(ccb
->ccb_h
.path
, "CAM Status 0x%x\n",
1707 action_string
= "Retries Exhausted";
1712 /* Attempt a retry */
1713 if (error
== ERESTART
|| error
== 0) {
1715 ccb
->ccb_h
.status
&= ~CAM_DEV_QFRZN
;
1717 if (error
== ERESTART
) {
1718 action_string
= "Retrying Command";
1723 cam_release_devq(ccb
->ccb_h
.path
,
1727 /*getcount_only*/0);
1731 * If we have an error and are booting verbosely, whine
1732 * *unless* this was a non-retryable selection timeout.
1734 if (error
!= 0 && bootverbose
&&
1735 !(status
== CAM_SEL_TIMEOUT
&& (camflags
& CAM_RETRY_SELTO
) == 0)) {
1738 if (action_string
== NULL
)
1739 action_string
= "Unretryable Error";
1740 if (error
!= ERESTART
) {
1741 xpt_print(ccb
->ccb_h
.path
, "error %d\n", error
);
1743 xpt_print(ccb
->ccb_h
.path
, "%s\n", action_string
);