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 $
32 #include <sys/param.h>
33 #include <sys/systm.h>
34 #include <sys/types.h>
35 #include <sys/malloc.h>
36 #include <sys/kernel.h>
40 #include <sys/devicestat.h>
43 #include <vm/vm_extern.h>
45 #include <sys/thread2.h>
49 #include "cam_xpt_periph.h"
50 #include "cam_periph.h"
51 #include "cam_debug.h"
54 #include <bus/cam/scsi/scsi_all.h>
55 #include <bus/cam/scsi/scsi_message.h>
56 #include <bus/cam/scsi/scsi_pass.h>
58 static u_int
camperiphnextunit(struct periph_driver
*p_drv
,
59 u_int newunit
, int wired
,
60 path_id_t pathid
, target_id_t target
,
62 static u_int
camperiphunit(struct periph_driver
*p_drv
,
63 struct cam_sim
*sim
, path_id_t pathid
,
64 target_id_t target
, lun_id_t lun
);
65 static void camperiphdone(struct cam_periph
*periph
,
67 static void camperiphfree(struct cam_periph
*periph
);
68 static int camperiphscsistatuserror(union ccb
*ccb
,
70 u_int32_t sense_flags
,
73 u_int32_t
*relsim_flags
,
75 static int camperiphscsisenseerror(union ccb
*ccb
,
77 u_int32_t sense_flags
,
80 u_int32_t
*relsim_flags
,
82 static void cam_periph_unmapbufs(struct cam_periph_map_info
*mapinfo
,
83 u_int8_t
***data_ptrs
, int numbufs
);
85 static int nperiph_drivers
;
86 struct periph_driver
**periph_drivers
;
88 MALLOC_DEFINE(M_CAMPERIPH
, "CAM periph", "CAM peripheral buffers");
90 static int periph_selto_delay
= 1000;
91 TUNABLE_INT("kern.cam.periph_selto_delay", &periph_selto_delay
);
92 static int periph_noresrc_delay
= 500;
93 TUNABLE_INT("kern.cam.periph_noresrc_delay", &periph_noresrc_delay
);
94 static int periph_busy_delay
= 500;
95 TUNABLE_INT("kern.cam.periph_busy_delay", &periph_busy_delay
);
98 * This is a horrible hack. The CAM code was just bulk-copying the ccb
99 * to 'restore' it from the saved version. This completely destroys list
100 * linkages and such, so hack the hack to not copy-over fields that cannot
101 * be safely copied over.
103 * This fixes list races when scsi errors occur simultaneously on multiple
106 #define RESTORE_CCB(saved, ccbh, field) \
107 bcopy(&(saved)->field, &(ccbh)->field, sizeof((ccbh)->field))
109 #define saved_ccb_ptr ppriv_ptr0
112 restore_ccb(struct ccb_hdr
*ccb_h
)
114 struct ccb_hdr
*saved
;
116 saved
= ccb_h
->saved_ccb_ptr
;
117 bcopy(saved
+ 1, ccb_h
+ 1, sizeof(union ccb
) - sizeof(*saved
));
118 RESTORE_CCB(saved
, ccb_h
, retry_count
);
119 RESTORE_CCB(saved
, ccb_h
, cbfcnp
);
120 RESTORE_CCB(saved
, ccb_h
, func_code
);
121 RESTORE_CCB(saved
, ccb_h
, status
);
122 RESTORE_CCB(saved
, ccb_h
, path
);
123 RESTORE_CCB(saved
, ccb_h
, path_id
);
124 RESTORE_CCB(saved
, ccb_h
, target_id
);
125 RESTORE_CCB(saved
, ccb_h
, target_lun
);
126 RESTORE_CCB(saved
, ccb_h
, flags
);
127 RESTORE_CCB(saved
, ccb_h
, periph_priv
);
128 RESTORE_CCB(saved
, ccb_h
, sim_priv
);
129 RESTORE_CCB(saved
, ccb_h
, timeout
);
133 periphdriver_register(void *data
)
135 struct periph_driver
**newdrivers
, **old
;
138 ndrivers
= nperiph_drivers
+ 2;
139 newdrivers
= kmalloc(sizeof(*newdrivers
) * ndrivers
, M_CAMPERIPH
,
142 bcopy(periph_drivers
, newdrivers
,
143 sizeof(*newdrivers
) * nperiph_drivers
);
144 newdrivers
[nperiph_drivers
] = (struct periph_driver
*)data
;
145 newdrivers
[nperiph_drivers
+ 1] = NULL
;
146 old
= periph_drivers
;
147 periph_drivers
= newdrivers
;
149 kfree(old
, M_CAMPERIPH
);
154 cam_periph_alloc(periph_ctor_t
*periph_ctor
,
155 periph_oninv_t
*periph_oninvalidate
,
156 periph_dtor_t
*periph_dtor
, periph_start_t
*periph_start
,
157 char *name
, cam_periph_type type
, struct cam_path
*path
,
158 ac_callback_t
*ac_callback
, ac_code code
, void *arg
)
160 struct periph_driver
**p_drv
;
162 struct cam_periph
*periph
;
163 struct cam_periph
*cur_periph
;
165 target_id_t target_id
;
172 * Handle Hot-Plug scenarios. If there is already a peripheral
173 * of our type assigned to this path, we are likely waiting for
174 * final close on an old, invalidated, peripheral. If this is
175 * the case, queue up a deferred call to the peripheral's async
176 * handler. If it looks like a mistaken re-allocation, complain.
178 if ((periph
= cam_periph_find(path
, name
)) != NULL
) {
180 if ((periph
->flags
& CAM_PERIPH_INVALID
) != 0
181 && (periph
->flags
& CAM_PERIPH_NEW_DEV_FOUND
) == 0) {
182 periph
->flags
|= CAM_PERIPH_NEW_DEV_FOUND
;
183 periph
->deferred_callback
= ac_callback
;
184 periph
->deferred_ac
= code
;
185 return (CAM_REQ_INPROG
);
187 kprintf("cam_periph_alloc: attempt to re-allocate "
188 "valid device %s%d rejected\n",
189 periph
->periph_name
, periph
->unit_number
);
191 return (CAM_REQ_INVALID
);
194 periph
= kmalloc(sizeof(*periph
), M_CAMPERIPH
, M_INTWAIT
| M_ZERO
);
196 init_level
++; /* 1 */
199 for (p_drv
= periph_drivers
; *p_drv
!= NULL
; p_drv
++) {
200 if (strcmp((*p_drv
)->driver_name
, name
) == 0)
205 sim
= xpt_path_sim(path
);
207 path_id
= xpt_path_path_id(path
);
208 target_id
= xpt_path_target_id(path
);
209 lun_id
= xpt_path_lun_id(path
);
210 cam_init_pinfo(&periph
->pinfo
);
211 periph
->periph_start
= periph_start
;
212 periph
->periph_dtor
= periph_dtor
;
213 periph
->periph_oninval
= periph_oninvalidate
;
215 periph
->periph_name
= name
;
216 periph
->immediate_priority
= CAM_PRIORITY_NONE
;
217 periph
->refcount
= 0;
219 SLIST_INIT(&periph
->ccb_list
);
220 status
= xpt_create_path(&path
, periph
, path_id
, target_id
, lun_id
);
221 if (status
!= CAM_REQ_CMP
)
224 init_level
++; /* 2 */
229 * Finalize with buses locked. Allocate unit number and add to
230 * list to reserve the unit number. Undo later if the XPT fails.
233 periph
->unit_number
= camperiphunit(*p_drv
, sim
, path_id
,
235 cur_periph
= TAILQ_FIRST(&(*p_drv
)->units
);
236 while (cur_periph
!= NULL
&&
237 cur_periph
->unit_number
< periph
->unit_number
) {
238 cur_periph
= TAILQ_NEXT(cur_periph
, unit_links
);
240 if (cur_periph
!= NULL
) {
241 TAILQ_INSERT_BEFORE(cur_periph
, periph
, unit_links
);
243 TAILQ_INSERT_TAIL(&(*p_drv
)->units
, periph
, unit_links
);
244 (*p_drv
)->generation
++;
248 status
= xpt_add_periph(periph
);
250 if (status
!= CAM_REQ_CMP
)
253 init_level
++; /* 3 */
255 status
= periph_ctor(periph
, arg
);
257 if (status
== CAM_REQ_CMP
)
258 init_level
++; /* 4 */
261 switch (init_level
) {
263 /* Initialized successfully */
269 TAILQ_REMOVE(&(*p_drv
)->units
, periph
, unit_links
);
272 xpt_remove_periph(periph
);
276 CAM_SIM_UNLOCK(sim
); /* sim was retrieved from path */
278 kfree(periph
, M_CAMPERIPH
);
281 /* No cleanup to perform. */
284 panic("cam_periph_alloc: Unknown init level");
290 * Find a peripheral structure with the specified path, target, lun,
291 * and (optionally) type. If the name is NULL, this function will return
292 * the first peripheral driver that matches the specified path.
295 cam_periph_find(struct cam_path
*path
, char *name
)
297 struct periph_driver
**p_drv
;
298 struct cam_periph
*periph
;
301 for (p_drv
= periph_drivers
; *p_drv
!= NULL
; p_drv
++) {
302 if (name
!= NULL
&& (strcmp((*p_drv
)->driver_name
, name
) != 0))
305 TAILQ_FOREACH(periph
, &(*p_drv
)->units
, unit_links
) {
306 if (xpt_path_comp(periph
->path
, path
) == 0) {
321 cam_periph_acquire(struct cam_periph
*periph
)
324 return(CAM_REQ_CMP_ERR
);
334 * Release the peripheral. The XPT is not locked and the SIM may or may
335 * not be locked on entry.
337 * The last release on a peripheral marked invalid frees it. In this
338 * case we must be sure to hold both the XPT lock and the SIM lock,
339 * requiring a bit of fancy footwork if the SIM lock already happens
343 cam_periph_release(struct cam_periph
*periph
)
350 * First try the critical path case
354 if ((periph
->flags
& CAM_PERIPH_INVALID
) == 0 ||
355 periph
->refcount
!= 1) {
362 * Otherwise we also need to free the peripheral and must
363 * acquire the sim lock and xpt lock in the correct order
366 * The condition must be re-checked after the locks have
370 doun
= CAM_SIM_COND_LOCK(sim
);
373 if ((periph
->flags
& CAM_PERIPH_INVALID
) &&
374 periph
->refcount
== 0) {
375 camperiphfree(periph
);
378 CAM_SIM_COND_UNLOCK(sim
, doun
);
384 cam_periph_hold(struct cam_periph
*periph
, int flags
)
388 sim_lock_assert_owned(periph
->sim
->lock
);
391 * Increment the reference count on the peripheral
392 * while we wait for our lock attempt to succeed
393 * to ensure the peripheral doesn't disappear out
394 * from user us while we sleep.
397 if (cam_periph_acquire(periph
) != CAM_REQ_CMP
)
400 while ((periph
->flags
& CAM_PERIPH_LOCKED
) != 0) {
401 periph
->flags
|= CAM_PERIPH_LOCK_WANTED
;
402 if ((error
= sim_lock_sleep(periph
, flags
, "caplck", 0,
403 periph
->sim
->lock
)) != 0) {
404 cam_periph_release(periph
);
409 periph
->flags
|= CAM_PERIPH_LOCKED
;
414 cam_periph_unhold(struct cam_periph
*periph
, int unlock
)
418 sim_lock_assert_owned(periph
->sim
->lock
);
419 periph
->flags
&= ~CAM_PERIPH_LOCKED
;
420 if ((periph
->flags
& CAM_PERIPH_LOCK_WANTED
) != 0) {
421 periph
->flags
&= ~CAM_PERIPH_LOCK_WANTED
;
426 cam_periph_release(periph
);
427 /* periph may be garbage now */
430 cam_periph_release(periph
);
435 * Look for the next unit number that is not currently in use for this
436 * peripheral type starting at "newunit". Also exclude unit numbers that
437 * are reserved by for future "hardwiring" unless we already know that this
438 * is a potential wired device. Only assume that the device is "wired" the
439 * first time through the loop since after that we'll be looking at unit
440 * numbers that did not match a wiring entry.
443 camperiphnextunit(struct periph_driver
*p_drv
, u_int newunit
, int wired
,
444 path_id_t pathid
, target_id_t target
, lun_id_t lun
)
446 struct cam_periph
*periph
;
449 const char *dname
, *strval
;
451 periph_name
= p_drv
->driver_name
;
453 for (periph
= TAILQ_FIRST(&p_drv
->units
);
454 periph
!= NULL
&& periph
->unit_number
!= newunit
;
455 periph
= TAILQ_NEXT(periph
, unit_links
))
458 if (periph
!= NULL
&& periph
->unit_number
== newunit
) {
460 xpt_print(periph
->path
, "Duplicate Wired "
462 xpt_print(periph
->path
, "Second device (%s "
463 "device at scbus%d target %d lun %d) will "
464 "not be wired\n", periph_name
, pathid
,
475 * Don't match entries like "da 4" as a wired down
476 * device, but do match entries like "da 4 target 5"
477 * or even "da 4 scbus 1".
480 while ((i
= resource_locate(i
, periph_name
)) != -1) {
481 dname
= resource_query_name(i
);
482 dunit
= resource_query_unit(i
);
483 /* if no "target" and no specific scbus, skip */
484 if (resource_int_value(dname
, dunit
, "target", &val
) &&
485 (resource_string_value(dname
, dunit
, "at",&strval
)||
486 strcmp(strval
, "scbus") == 0)) {
489 if (newunit
== dunit
)
500 camperiphunit(struct periph_driver
*p_drv
,
501 struct cam_sim
*sim
, path_id_t pathid
,
502 target_id_t target
, lun_id_t lun
)
505 int hit
, i
, val
, dunit
;
506 const char *dname
, *strval
;
507 char pathbuf
[32], *periph_name
;
511 periph_name
= p_drv
->driver_name
;
512 ksnprintf(pathbuf
, sizeof(pathbuf
), "scbus%d", pathid
);
514 for (hit
= 0; (i
= resource_locate(i
, periph_name
)) != -1; hit
= 0) {
515 dname
= resource_query_name(i
);
516 dunit
= resource_query_unit(i
);
517 if (resource_string_value(dname
, dunit
, "at", &strval
) == 0) {
518 if (strcmp(strval
, pathbuf
) != 0)
522 if (resource_int_value(dname
, dunit
, "target", &val
) == 0) {
527 if (resource_int_value(dname
, dunit
, "lun", &val
) == 0) {
539 * If no wired units are in the kernel config do an auto unit
540 * start selection. We want usb mass storage out of the way
541 * so it doesn't steal low numbered da%d slots from ahci, sili,
542 * or other scsi attachments.
544 if (hit
== 0 && sim
) {
545 if (strncmp(sim
->sim_name
, "umass", 4) == 0 && unit
< 8)
550 * Either start from 0 looking for the next unit or from
551 * the unit number given in the resource config. This way,
552 * if we have wildcard matches, we don't return the same
555 unit
= camperiphnextunit(p_drv
, unit
, /*wired*/hit
, pathid
,
562 cam_periph_invalidate(struct cam_periph
*periph
)
565 * We only call this routine the first time a peripheral is
568 if (((periph
->flags
& CAM_PERIPH_INVALID
) == 0)
569 && (periph
->periph_oninval
!= NULL
))
570 periph
->periph_oninval(periph
);
572 periph
->flags
|= CAM_PERIPH_INVALID
;
573 periph
->flags
&= ~CAM_PERIPH_NEW_DEV_FOUND
;
576 if (periph
->refcount
== 0)
577 camperiphfree(periph
);
578 else if (periph
->refcount
< 0)
579 kprintf("cam_invalidate_periph: refcount < 0!!\n");
584 camperiphfree(struct cam_periph
*periph
)
586 struct periph_driver
**p_drv
;
588 for (p_drv
= periph_drivers
; *p_drv
!= NULL
; p_drv
++) {
589 if (strcmp((*p_drv
)->driver_name
, periph
->periph_name
) == 0)
593 if (*p_drv
== NULL
) {
594 kprintf("camperiphfree: attempt to free non-existent periph\n");
598 TAILQ_REMOVE(&(*p_drv
)->units
, periph
, unit_links
);
599 (*p_drv
)->generation
++;
602 if (periph
->periph_dtor
!= NULL
)
603 periph
->periph_dtor(periph
);
604 xpt_remove_periph(periph
);
606 if (periph
->flags
& CAM_PERIPH_NEW_DEV_FOUND
) {
610 switch (periph
->deferred_ac
) {
611 case AC_FOUND_DEVICE
:
612 ccb
.ccb_h
.func_code
= XPT_GDEV_TYPE
;
613 xpt_setup_ccb(&ccb
.ccb_h
, periph
->path
, /*priority*/ 1);
617 case AC_PATH_REGISTERED
:
618 ccb
.ccb_h
.func_code
= XPT_PATH_INQ
;
619 xpt_setup_ccb(&ccb
.ccb_h
, periph
->path
, /*priority*/ 1);
627 periph
->deferred_callback(NULL
, periph
->deferred_ac
,
630 xpt_free_path(periph
->path
);
631 kfree(periph
, M_CAMPERIPH
);
636 * We don't map user pointers into KVM, instead we use pbufs.
638 * This won't work on physical pointers(?OLD), for now it's
639 * up to the caller to check for that. (XXX KDM -- should we do that here
640 * instead?) This also only works for up to MAXPHYS memory. Since we use
641 * buffers to map stuff in and out, we're limited to the buffer size.
644 cam_periph_mapmem(union ccb
*ccb
, struct cam_periph_map_info
*mapinfo
)
646 buf_cmd_t cmd
[CAM_PERIPH_MAXMAPS
];
647 u_int8_t
**data_ptrs
[CAM_PERIPH_MAXMAPS
];
648 u_int32_t lengths
[CAM_PERIPH_MAXMAPS
];
654 switch(ccb
->ccb_h
.func_code
) {
656 if (ccb
->cdm
.match_buf_len
== 0) {
657 kprintf("cam_periph_mapmem: invalid match buffer "
661 if (ccb
->cdm
.pattern_buf_len
> 0) {
662 data_ptrs
[0] = (void *)&ccb
->cdm
.patterns
;
663 lengths
[0] = ccb
->cdm
.pattern_buf_len
;
664 mapinfo
->dirs
[0] = CAM_DIR_OUT
;
665 data_ptrs
[1] = (void *)&ccb
->cdm
.matches
;
666 lengths
[1] = ccb
->cdm
.match_buf_len
;
667 mapinfo
->dirs
[1] = CAM_DIR_IN
;
670 data_ptrs
[0] = (void *)&ccb
->cdm
.matches
;
671 lengths
[0] = ccb
->cdm
.match_buf_len
;
672 mapinfo
->dirs
[0] = CAM_DIR_IN
;
677 case XPT_CONT_TARGET_IO
:
678 if ((ccb
->ccb_h
.flags
& CAM_DIR_MASK
) == CAM_DIR_NONE
)
681 data_ptrs
[0] = &ccb
->csio
.data_ptr
;
682 lengths
[0] = ccb
->csio
.dxfer_len
;
683 mapinfo
->dirs
[0] = ccb
->ccb_h
.flags
& CAM_DIR_MASK
;
688 break; /* NOTREACHED */
692 * Check the transfer length and permissions first, so we don't
693 * have to unmap any previously mapped buffers.
695 for (i
= 0; i
< numbufs
; i
++) {
697 * Its kinda bogus, we need a R+W command. For now the
698 * buffer needs some sort of command. Use BUF_CMD_WRITE
699 * to indicate a write and BUF_CMD_READ to indicate R+W.
701 cmd
[i
] = BUF_CMD_WRITE
;
703 if (lengths
[i
] > MAXPHYS
) {
704 kprintf("cam_periph_mapmem: attempt to map %lu bytes, "
705 "which is greater than MAXPHYS(%d)\n",
707 (((vm_offset_t
)(*data_ptrs
[i
])) & PAGE_MASK
)),
712 if (mapinfo
->dirs
[i
] & CAM_DIR_OUT
) {
713 if (!useracc(*data_ptrs
[i
], lengths
[i
],
715 kprintf("cam_periph_mapmem: error, "
716 "address %p, length %lu isn't "
717 "user accessible for READ\n",
718 (void *)*data_ptrs
[i
],
724 if (mapinfo
->dirs
[i
] & CAM_DIR_IN
) {
725 cmd
[i
] = BUF_CMD_READ
;
726 if (!useracc(*data_ptrs
[i
], lengths
[i
],
728 kprintf("cam_periph_mapmem: error, "
729 "address %p, length %lu isn't "
730 "user accessible for WRITE\n",
731 (void *)*data_ptrs
[i
],
740 for (i
= 0; i
< numbufs
; i
++) {
744 bp
= getpbuf_mem(NULL
);
746 /* save the original user pointer */
747 mapinfo
->saved_ptrs
[i
] = *data_ptrs
[i
];
753 * Always bounce the I/O through kernel memory.
755 bp
->b_bcount
= lengths
[i
];
756 if (mapinfo
->dirs
[i
] & CAM_DIR_OUT
) {
757 error
= copyin(*data_ptrs
[i
], bp
->b_data
, bp
->b_bcount
);
763 cam_periph_unmapbufs(mapinfo
, data_ptrs
, i
);
764 mapinfo
->num_bufs_used
-= i
;
768 /* set our pointer to the new mapped area */
769 *data_ptrs
[i
] = bp
->b_data
;
772 mapinfo
->num_bufs_used
++;
779 * Unmap memory segments mapped into kernel virtual address space by
780 * cam_periph_mapmem().
783 cam_periph_unmapmem(union ccb
*ccb
, struct cam_periph_map_info
*mapinfo
)
786 u_int8_t
**data_ptrs
[CAM_PERIPH_MAXMAPS
];
788 if (mapinfo
->num_bufs_used
<= 0) {
789 /* allow ourselves to be swapped once again */
793 switch (ccb
->ccb_h
.func_code
) {
795 numbufs
= min(mapinfo
->num_bufs_used
, 2);
798 data_ptrs
[0] = (void *)&ccb
->cdm
.matches
;
800 data_ptrs
[0] = (void *)&ccb
->cdm
.patterns
;
801 data_ptrs
[1] = (void *)&ccb
->cdm
.matches
;
805 case XPT_CONT_TARGET_IO
:
806 data_ptrs
[0] = &ccb
->csio
.data_ptr
;
807 numbufs
= min(mapinfo
->num_bufs_used
, 1);
810 /* allow ourselves to be swapped once again */
812 break; /* NOTREACHED */
814 cam_periph_unmapbufs(mapinfo
, data_ptrs
, numbufs
);
818 cam_periph_unmapbufs(struct cam_periph_map_info
*mapinfo
,
819 u_int8_t
***data_ptrs
, int numbufs
)
824 for (i
= 0; i
< numbufs
; i
++) {
827 /* Set the user's pointer back to the original value */
828 *data_ptrs
[i
] = mapinfo
->saved_ptrs
[i
];
830 if (mapinfo
->dirs
[i
] & CAM_DIR_IN
) {
831 /* XXX return error */
832 copyout(bp
->b_data
, *data_ptrs
[i
], bp
->b_bcount
);
835 mapinfo
->bp
[i
] = NULL
;
840 cam_periph_getccb(struct cam_periph
*periph
, u_int32_t priority
)
842 struct ccb_hdr
*ccb_h
;
844 sim_lock_assert_owned(periph
->sim
->lock
);
845 CAM_DEBUG(periph
->path
, CAM_DEBUG_TRACE
, ("entering cdgetccb\n"));
847 while (SLIST_FIRST(&periph
->ccb_list
) == NULL
) {
848 if (periph
->immediate_priority
> priority
)
849 periph
->immediate_priority
= priority
;
850 xpt_schedule(periph
, priority
);
851 if ((SLIST_FIRST(&periph
->ccb_list
) != NULL
)
852 && (SLIST_FIRST(&periph
->ccb_list
)->pinfo
.priority
== priority
))
854 sim_lock_sleep(&periph
->ccb_list
, 0, "cgticb", 0,
858 ccb_h
= SLIST_FIRST(&periph
->ccb_list
);
859 SLIST_REMOVE_HEAD(&periph
->ccb_list
, periph_links
.sle
);
860 return ((union ccb
*)ccb_h
);
864 cam_periph_ccbwait(union ccb
*ccb
)
868 sim
= xpt_path_sim(ccb
->ccb_h
.path
);
869 while ((ccb
->ccb_h
.pinfo
.index
!= CAM_UNQUEUED_INDEX
)
870 || ((ccb
->ccb_h
.status
& CAM_STATUS_MASK
) == CAM_REQ_INPROG
)) {
871 sim_lock_sleep(&ccb
->ccb_h
.cbfcnp
, 0, "cbwait", 0, sim
->lock
);
876 cam_periph_ioctl(struct cam_periph
*periph
, u_long cmd
, caddr_t addr
,
877 int (*error_routine
)(union ccb
*ccb
,
879 u_int32_t sense_flags
))
889 ccb
= cam_periph_getccb(periph
, /* priority */ 1);
890 xpt_setup_ccb(&ccb
->ccb_h
,
893 ccb
->ccb_h
.func_code
= XPT_GDEVLIST
;
896 * Basically, the point of this is that we go through
897 * getting the list of devices, until we find a passthrough
898 * device. In the current version of the CAM code, the
899 * only way to determine what type of device we're dealing
900 * with is by its name.
904 ccb
->cgdl
.status
= CAM_GDEVLIST_MORE_DEVS
;
905 while (ccb
->cgdl
.status
== CAM_GDEVLIST_MORE_DEVS
) {
907 /* we want the next device in the list */
909 if (strncmp(ccb
->cgdl
.periph_name
,
915 if ((ccb
->cgdl
.status
== CAM_GDEVLIST_LAST_DEVICE
) &&
917 ccb
->cgdl
.periph_name
[0] = '\0';
918 ccb
->cgdl
.unit_number
= 0;
923 /* copy the result back out */
924 bcopy(ccb
, addr
, sizeof(union ccb
));
926 /* and release the ccb */
927 xpt_release_ccb(ccb
);
938 cam_periph_runccb(union ccb
*ccb
,
939 int (*error_routine
)(union ccb
*ccb
,
941 u_int32_t sense_flags
),
942 cam_flags camflags
, u_int32_t sense_flags
,
949 sim
= xpt_path_sim(ccb
->ccb_h
.path
);
950 sim_lock_assert_owned(sim
->lock
);
953 * If the user has supplied a stats structure, and if we understand
954 * this particular type of ccb, record the transaction start.
956 if ((ds
!= NULL
) && (ccb
->ccb_h
.func_code
== XPT_SCSI_IO
))
957 devstat_start_transaction(ds
);
962 cam_periph_ccbwait(ccb
);
963 if ((ccb
->ccb_h
.status
& CAM_STATUS_MASK
) == CAM_REQ_CMP
)
965 else if (error_routine
!= NULL
)
966 error
= (*error_routine
)(ccb
, camflags
, sense_flags
);
970 } while (error
== ERESTART
);
972 if ((ccb
->ccb_h
.status
& CAM_DEV_QFRZN
) != 0)
973 cam_release_devq(ccb
->ccb_h
.path
,
977 /* getcount_only */ FALSE
);
979 if ((ds
!= NULL
) && (ccb
->ccb_h
.func_code
== XPT_SCSI_IO
))
980 devstat_end_transaction(ds
,
982 ccb
->csio
.tag_action
& 0xf,
983 ((ccb
->ccb_h
.flags
& CAM_DIR_MASK
) ==
984 CAM_DIR_NONE
) ? DEVSTAT_NO_DATA
:
985 (ccb
->ccb_h
.flags
& CAM_DIR_OUT
) ?
993 cam_freeze_devq(struct cam_path
*path
)
995 struct ccb_hdr ccb_h
;
997 xpt_setup_ccb(&ccb_h
, path
, /*priority*/1);
998 ccb_h
.func_code
= XPT_NOOP
;
999 ccb_h
.flags
= CAM_DEV_QFREEZE
;
1000 xpt_action((union ccb
*)&ccb_h
);
1004 cam_release_devq(struct cam_path
*path
, u_int32_t relsim_flags
,
1005 u_int32_t openings
, u_int32_t timeout
,
1008 struct ccb_relsim crs
;
1010 xpt_setup_ccb(&crs
.ccb_h
, path
,
1012 crs
.ccb_h
.func_code
= XPT_REL_SIMQ
;
1013 crs
.ccb_h
.flags
= getcount_only
? CAM_DEV_QFREEZE
: 0;
1014 crs
.release_flags
= relsim_flags
;
1015 crs
.openings
= openings
;
1016 crs
.release_timeout
= timeout
;
1017 xpt_action((union ccb
*)&crs
);
1018 return (crs
.qfrozen_cnt
);
1022 camperiphdone(struct cam_periph
*periph
, union ccb
*done_ccb
)
1024 union ccb
*saved_ccb
;
1028 struct scsi_start_stop_unit
*scsi_cmd
;
1029 u_int32_t relsim_flags
, timeout
;
1030 u_int32_t qfrozen_cnt
;
1033 xpt_done_ccb
= FALSE
;
1034 status
= done_ccb
->ccb_h
.status
;
1035 frozen
= (status
& CAM_DEV_QFRZN
) != 0;
1036 sense
= (status
& CAM_AUTOSNS_VALID
) != 0;
1037 status
&= CAM_STATUS_MASK
;
1041 saved_ccb
= (union ccb
*)done_ccb
->ccb_h
.saved_ccb_ptr
;
1044 * Unfreeze the queue once if it is already frozen..
1047 qfrozen_cnt
= cam_release_devq(done_ccb
->ccb_h
.path
,
1051 /*getcount_only*/0);
1058 * If we have successfully taken a device from the not
1059 * ready to ready state, re-scan the device and re-get
1060 * the inquiry information. Many devices (mostly disks)
1061 * don't properly report their inquiry information unless
1064 * If we manually retrieved sense into a CCB and got
1065 * something other than "NO SENSE" send the updated CCB
1066 * back to the client via xpt_done() to be processed via
1067 * the error recovery code again.
1069 if (done_ccb
->ccb_h
.func_code
== XPT_SCSI_IO
) {
1070 scsi_cmd
= (struct scsi_start_stop_unit
*)
1071 &done_ccb
->csio
.cdb_io
.cdb_bytes
;
1073 if (scsi_cmd
->opcode
== START_STOP_UNIT
)
1074 xpt_async(AC_INQ_CHANGED
,
1075 done_ccb
->ccb_h
.path
, NULL
);
1076 if (scsi_cmd
->opcode
== REQUEST_SENSE
) {
1079 sense_key
= saved_ccb
->csio
.sense_data
.flags
;
1080 sense_key
&= SSD_KEY
;
1081 if (sense_key
!= SSD_KEY_NO_SENSE
) {
1082 saved_ccb
->ccb_h
.status
|=
1085 xpt_print(saved_ccb
->ccb_h
.path
,
1086 "Recovered Sense\n");
1087 scsi_sense_print(&saved_ccb
->csio
);
1088 cam_error_print(saved_ccb
, CAM_ESF_ALL
,
1091 xpt_done_ccb
= TRUE
;
1095 restore_ccb(&done_ccb
->ccb_h
);
1097 periph
->flags
&= ~CAM_PERIPH_RECOVERY_INPROG
;
1099 if (xpt_done_ccb
== FALSE
)
1100 xpt_action(done_ccb
);
1104 case CAM_SCSI_STATUS_ERROR
:
1105 scsi_cmd
= (struct scsi_start_stop_unit
*)
1106 &done_ccb
->csio
.cdb_io
.cdb_bytes
;
1108 struct ccb_getdev cgd
;
1109 struct scsi_sense_data
*sense
;
1110 int error_code
, sense_key
, asc
, ascq
;
1111 scsi_sense_action err_action
;
1113 sense
= &done_ccb
->csio
.sense_data
;
1114 scsi_extract_sense(sense
, &error_code
,
1115 &sense_key
, &asc
, &ascq
);
1118 * Grab the inquiry data for this device.
1120 xpt_setup_ccb(&cgd
.ccb_h
, done_ccb
->ccb_h
.path
,
1122 cgd
.ccb_h
.func_code
= XPT_GDEV_TYPE
;
1123 xpt_action((union ccb
*)&cgd
);
1124 err_action
= scsi_error_action(&done_ccb
->csio
,
1128 * If the error is "invalid field in CDB",
1129 * and the load/eject flag is set, turn the
1130 * flag off and try again. This is just in
1131 * case the drive in question barfs on the
1132 * load eject flag. The CAM code should set
1133 * the load/eject flag by default for
1138 * Should we check to see what the specific
1139 * scsi status is?? Or does it not matter
1140 * since we already know that there was an
1141 * error, and we know what the specific
1142 * error code was, and we know what the
1145 if ((scsi_cmd
->opcode
== START_STOP_UNIT
) &&
1146 ((scsi_cmd
->how
& SSS_LOEJ
) != 0) &&
1147 (asc
== 0x24) && (ascq
== 0x00) &&
1148 (done_ccb
->ccb_h
.retry_count
> 0)) {
1150 scsi_cmd
->how
&= ~SSS_LOEJ
;
1152 xpt_action(done_ccb
);
1154 } else if ((done_ccb
->ccb_h
.retry_count
> 1)
1155 && ((err_action
& SS_MASK
) != SS_FAIL
)) {
1158 * In this case, the error recovery
1159 * command failed, but we've got
1160 * some retries left on it. Give
1161 * it another try unless this is an
1162 * unretryable error.
1165 /* set the timeout to .5 sec */
1167 RELSIM_RELEASE_AFTER_TIMEOUT
;
1170 xpt_action(done_ccb
);
1176 * Perform the final retry with the original
1177 * CCB so that final error processing is
1178 * performed by the owner of the CCB.
1180 restore_ccb(&done_ccb
->ccb_h
);
1182 periph
->flags
&= ~CAM_PERIPH_RECOVERY_INPROG
;
1184 xpt_action(done_ccb
);
1188 * Eh?? The command failed, but we don't
1189 * have any sense. What's up with that?
1190 * Fire the CCB again to return it to the
1193 restore_ccb(&done_ccb
->ccb_h
);
1195 periph
->flags
&= ~CAM_PERIPH_RECOVERY_INPROG
;
1197 xpt_action(done_ccb
);
1202 restore_ccb(&done_ccb
->ccb_h
);
1204 periph
->flags
&= ~CAM_PERIPH_RECOVERY_INPROG
;
1206 xpt_action(done_ccb
);
1211 /* decrement the retry count */
1213 * XXX This isn't appropriate in all cases. Restructure,
1214 * so that the retry count is only decremented on an
1215 * actual retry. Remeber that the orignal ccb had its
1216 * retry count dropped before entering recovery, so
1217 * doing it again is a bug.
1219 if (done_ccb
->ccb_h
.retry_count
> 0)
1220 done_ccb
->ccb_h
.retry_count
--;
1222 qfrozen_cnt
= cam_release_devq(done_ccb
->ccb_h
.path
,
1223 /*relsim_flags*/relsim_flags
,
1226 /*getcount_only*/0);
1227 if (xpt_done_ccb
== TRUE
)
1228 (*done_ccb
->ccb_h
.cbfcnp
)(periph
, done_ccb
);
1232 * Generic Async Event handler. Peripheral drivers usually
1233 * filter out the events that require personal attention,
1234 * and leave the rest to this function.
1237 cam_periph_async(struct cam_periph
*periph
, u_int32_t code
,
1238 struct cam_path
*path
, void *arg
)
1241 case AC_LOST_DEVICE
:
1242 cam_periph_invalidate(periph
);
1247 cam_periph_bus_settle(periph
, scsi_delay
);
1256 cam_periph_bus_settle(struct cam_periph
*periph
, u_int bus_settle
)
1258 struct ccb_getdevstats cgds
;
1260 xpt_setup_ccb(&cgds
.ccb_h
, periph
->path
, /*priority*/1);
1261 cgds
.ccb_h
.func_code
= XPT_GDEV_STATS
;
1262 xpt_action((union ccb
*)&cgds
);
1263 cam_periph_freeze_after_event(periph
, &cgds
.last_reset
, bus_settle
);
1267 cam_periph_freeze_after_event(struct cam_periph
*periph
,
1268 struct timeval
* event_time
, u_int duration_ms
)
1270 struct timeval delta
;
1271 struct timeval duration_tv
;
1273 microuptime(&delta
);
1274 timevalsub(&delta
, event_time
);
1275 duration_tv
.tv_sec
= duration_ms
/ 1000;
1276 duration_tv
.tv_usec
= (duration_ms
% 1000) * 1000;
1277 if (timevalcmp(&delta
, &duration_tv
, <)) {
1278 timevalsub(&duration_tv
, &delta
);
1280 duration_ms
= duration_tv
.tv_sec
* 1000;
1281 duration_ms
+= duration_tv
.tv_usec
/ 1000;
1282 cam_freeze_devq(periph
->path
);
1283 cam_release_devq(periph
->path
,
1284 RELSIM_RELEASE_AFTER_TIMEOUT
,
1286 /*timeout*/duration_ms
,
1287 /*getcount_only*/0);
1293 camperiphscsistatuserror(union ccb
*ccb
, cam_flags camflags
,
1294 u_int32_t sense_flags
, union ccb
*save_ccb
,
1295 int *openings
, u_int32_t
*relsim_flags
,
1300 switch (ccb
->csio
.scsi_status
) {
1301 case SCSI_STATUS_OK
:
1302 case SCSI_STATUS_COND_MET
:
1303 case SCSI_STATUS_INTERMED
:
1304 case SCSI_STATUS_INTERMED_COND_MET
:
1307 case SCSI_STATUS_CMD_TERMINATED
:
1308 case SCSI_STATUS_CHECK_COND
:
1309 error
= camperiphscsisenseerror(ccb
,
1317 case SCSI_STATUS_QUEUE_FULL
:
1320 struct ccb_getdevstats cgds
;
1323 * First off, find out what the current
1324 * transaction counts are.
1326 xpt_setup_ccb(&cgds
.ccb_h
,
1329 cgds
.ccb_h
.func_code
= XPT_GDEV_STATS
;
1330 xpt_action((union ccb
*)&cgds
);
1333 * If we were the only transaction active, treat
1334 * the QUEUE FULL as if it were a BUSY condition.
1336 if (cgds
.dev_active
!= 0) {
1340 * Reduce the number of openings to
1341 * be 1 less than the amount it took
1342 * to get a queue full bounded by the
1343 * minimum allowed tag count for this
1346 total_openings
= cgds
.dev_active
+ cgds
.dev_openings
;
1347 *openings
= cgds
.dev_active
;
1348 if (*openings
< cgds
.mintags
)
1349 *openings
= cgds
.mintags
;
1350 if (*openings
< total_openings
)
1351 *relsim_flags
= RELSIM_ADJUST_OPENINGS
;
1354 * Some devices report queue full for
1355 * temporary resource shortages. For
1356 * this reason, we allow a minimum
1357 * tag count to be entered via a
1358 * quirk entry to prevent the queue
1359 * count on these devices from falling
1360 * to a pessimisticly low value. We
1361 * still wait for the next successful
1362 * completion, however, before queueing
1363 * more transactions to the device.
1365 *relsim_flags
= RELSIM_RELEASE_AFTER_CMDCMPLT
;
1370 xpt_print(ccb
->ccb_h
.path
, "Queue Full\n");
1376 case SCSI_STATUS_BUSY
:
1378 * Restart the queue after either another
1379 * command completes or a 1 second timeout.
1382 xpt_print(ccb
->ccb_h
.path
, "Device Busy\n");
1384 if (ccb
->ccb_h
.retry_count
> 0) {
1385 ccb
->ccb_h
.retry_count
--;
1387 *relsim_flags
= RELSIM_RELEASE_AFTER_TIMEOUT
1388 | RELSIM_RELEASE_AFTER_CMDCMPLT
;
1394 case SCSI_STATUS_RESERV_CONFLICT
:
1395 xpt_print(ccb
->ccb_h
.path
, "Reservation Conflict\n");
1399 xpt_print(ccb
->ccb_h
.path
, "SCSI Status 0x%x\n",
1400 ccb
->csio
.scsi_status
);
1408 camperiphscsisenseerror(union ccb
*ccb
, cam_flags camflags
,
1409 u_int32_t sense_flags
, union ccb
*save_ccb
,
1410 int *openings
, u_int32_t
*relsim_flags
,
1413 struct cam_periph
*periph
;
1416 periph
= xpt_path_periph(ccb
->ccb_h
.path
);
1417 if (periph
->flags
& CAM_PERIPH_RECOVERY_INPROG
) {
1420 * If error recovery is already in progress, don't attempt
1421 * to process this error, but requeue it unconditionally
1422 * and attempt to process it once error recovery has
1423 * completed. This failed command is probably related to
1424 * the error that caused the currently active error recovery
1425 * action so our current recovery efforts should also
1426 * address this command. Be aware that the error recovery
1427 * code assumes that only one recovery action is in progress
1428 * on a particular peripheral instance at any given time
1429 * (e.g. only one saved CCB for error recovery) so it is
1430 * imperitive that we don't violate this assumption.
1434 scsi_sense_action err_action
;
1435 struct ccb_getdev cgd
;
1436 const char *action_string
;
1437 union ccb
* print_ccb
;
1439 /* A description of the error recovery action performed */
1440 action_string
= NULL
;
1443 * The location of the orignal ccb
1444 * for sense printing purposes.
1449 * Grab the inquiry data for this device.
1451 xpt_setup_ccb(&cgd
.ccb_h
, ccb
->ccb_h
.path
, /*priority*/ 1);
1452 cgd
.ccb_h
.func_code
= XPT_GDEV_TYPE
;
1453 xpt_action((union ccb
*)&cgd
);
1455 if ((ccb
->ccb_h
.status
& CAM_AUTOSNS_VALID
) != 0)
1456 err_action
= scsi_error_action(&ccb
->csio
,
1459 else if ((ccb
->ccb_h
.flags
& CAM_DIS_AUTOSENSE
) == 0)
1460 err_action
= SS_REQSENSE
;
1462 err_action
= SS_RETRY
|SSQ_DECREMENT_COUNT
|EIO
;
1464 error
= err_action
& SS_ERRMASK
;
1467 * If the recovery action will consume a retry,
1468 * make sure we actually have retries available.
1470 if ((err_action
& SSQ_DECREMENT_COUNT
) != 0) {
1471 if (ccb
->ccb_h
.retry_count
> 0)
1472 ccb
->ccb_h
.retry_count
--;
1474 action_string
= "Retries Exhausted";
1475 goto sense_error_done
;
1479 if ((err_action
& SS_MASK
) >= SS_START
) {
1481 * Do common portions of commands that
1482 * use recovery CCBs.
1484 if (save_ccb
== NULL
) {
1485 action_string
= "No recovery CCB supplied";
1486 goto sense_error_done
;
1488 bcopy(ccb
, save_ccb
, sizeof(*save_ccb
));
1489 print_ccb
= save_ccb
;
1490 periph
->flags
|= CAM_PERIPH_RECOVERY_INPROG
;
1493 switch (err_action
& SS_MASK
) {
1495 action_string
= "No Recovery Action Needed";
1499 action_string
= "Retrying Command (per Sense Data)";
1503 action_string
= "Unretryable error";
1510 * Send a start unit command to the device, and
1511 * then retry the command.
1513 action_string
= "Attempting to Start Unit";
1516 * Check for removable media and set
1517 * load/eject flag appropriately.
1519 if (SID_IS_REMOVABLE(&cgd
.inq_data
))
1524 scsi_start_stop(&ccb
->csio
,
1538 * Send a Test Unit Ready to the device.
1539 * If the 'many' flag is set, we send 120
1540 * test unit ready commands, one every half
1541 * second. Otherwise, we just send one TUR.
1542 * We only want to do this if the retry
1543 * count has not been exhausted.
1547 if ((err_action
& SSQ_MANY
) != 0) {
1548 action_string
= "Polling device for readiness";
1551 action_string
= "Testing device for readiness";
1554 scsi_test_unit_ready(&ccb
->csio
,
1562 * Accomplish our 500ms delay by deferring
1563 * the release of our device queue appropriately.
1565 *relsim_flags
= RELSIM_RELEASE_AFTER_TIMEOUT
;
1572 * Send a Request Sense to the device. We
1573 * assume that we are in a contingent allegiance
1574 * condition so we do not tag this request.
1576 scsi_request_sense(&ccb
->csio
, /*retries*/1,
1578 &save_ccb
->csio
.sense_data
,
1579 sizeof(save_ccb
->csio
.sense_data
),
1580 CAM_TAG_ACTION_NONE
,
1581 /*sense_len*/SSD_FULL_SIZE
,
1586 panic("Unhandled error action %x", err_action
);
1589 if ((err_action
& SS_MASK
) >= SS_START
) {
1591 * Drop the priority to 0 so that the recovery
1592 * CCB is the first to execute. Freeze the queue
1593 * after this command is sent so that we can
1594 * restore the old csio and have it queued in
1595 * the proper order before we release normal
1596 * transactions to the device.
1598 ccb
->ccb_h
.pinfo
.priority
= 0;
1599 ccb
->ccb_h
.flags
|= CAM_DEV_QFREEZE
;
1600 ccb
->ccb_h
.saved_ccb_ptr
= save_ccb
;
1605 if ((err_action
& SSQ_PRINT_SENSE
) != 0
1606 && (ccb
->ccb_h
.status
& CAM_AUTOSNS_VALID
) != 0) {
1607 cam_error_print(print_ccb
, CAM_ESF_ALL
, CAM_EPF_ALL
);
1608 xpt_print_path(ccb
->ccb_h
.path
);
1610 scsi_sense_print(&print_ccb
->csio
);
1611 kprintf("%s\n", action_string
);
1618 * Generic error handler. Peripheral drivers usually filter
1619 * out the errors that they handle in a unique mannor, then
1620 * call this function.
1623 cam_periph_error(union ccb
*ccb
, cam_flags camflags
,
1624 u_int32_t sense_flags
, union ccb
*save_ccb
)
1626 const char *action_string
;
1629 int error
, printed
= 0;
1631 u_int32_t relsim_flags
;
1632 u_int32_t timeout
= 0;
1634 action_string
= NULL
;
1635 status
= ccb
->ccb_h
.status
;
1636 frozen
= (status
& CAM_DEV_QFRZN
) != 0;
1637 status
&= CAM_STATUS_MASK
;
1638 openings
= relsim_flags
= 0;
1644 case CAM_SCSI_STATUS_ERROR
:
1645 error
= camperiphscsistatuserror(ccb
,
1653 case CAM_AUTOSENSE_FAIL
:
1654 xpt_print(ccb
->ccb_h
.path
, "AutoSense Failed\n");
1655 error
= EIO
; /* we have to kill the command */
1657 case CAM_REQ_CMP_ERR
:
1658 if (bootverbose
&& printed
== 0) {
1659 xpt_print(ccb
->ccb_h
.path
,
1660 "Request completed with CAM_REQ_CMP_ERR\n");
1664 case CAM_CMD_TIMEOUT
:
1665 if (bootverbose
&& printed
== 0) {
1666 xpt_print(ccb
->ccb_h
.path
, "Command timed out\n");
1670 case CAM_UNEXP_BUSFREE
:
1671 if (bootverbose
&& printed
== 0) {
1672 xpt_print(ccb
->ccb_h
.path
, "Unexpected Bus Free\n");
1676 case CAM_UNCOR_PARITY
:
1677 if (bootverbose
&& printed
== 0) {
1678 xpt_print(ccb
->ccb_h
.path
,
1679 "Uncorrected Parity Error\n");
1683 case CAM_DATA_RUN_ERR
:
1684 if (bootverbose
&& printed
== 0) {
1685 xpt_print(ccb
->ccb_h
.path
, "Data Overrun\n");
1688 error
= EIO
; /* we have to kill the command */
1689 /* decrement the number of retries */
1690 if (ccb
->ccb_h
.retry_count
> 0) {
1691 ccb
->ccb_h
.retry_count
--;
1694 action_string
= "Retries Exhausted";
1700 case CAM_MSG_REJECT_REC
:
1701 /* XXX Don't know that these are correct */
1704 case CAM_SEL_TIMEOUT
:
1706 struct cam_path
*newpath
;
1708 if ((camflags
& CAM_RETRY_SELTO
) != 0) {
1709 if (ccb
->ccb_h
.retry_count
> 0) {
1711 ccb
->ccb_h
.retry_count
--;
1713 if (bootverbose
&& printed
== 0) {
1714 xpt_print(ccb
->ccb_h
.path
,
1715 "Selection Timeout\n");
1720 * Wait a bit to give the device
1721 * time to recover before we try again.
1723 relsim_flags
= RELSIM_RELEASE_AFTER_TIMEOUT
;
1724 timeout
= periph_selto_delay
;
1729 /* Should we do more if we can't create the path?? */
1730 if (xpt_create_path(&newpath
, xpt_path_periph(ccb
->ccb_h
.path
),
1731 xpt_path_path_id(ccb
->ccb_h
.path
),
1732 xpt_path_target_id(ccb
->ccb_h
.path
),
1733 CAM_LUN_WILDCARD
) != CAM_REQ_CMP
)
1737 * Let peripheral drivers know that this device has gone
1740 xpt_async(AC_LOST_DEVICE
, newpath
, NULL
);
1741 xpt_free_path(newpath
);
1744 case CAM_REQ_INVALID
:
1745 case CAM_PATH_INVALID
:
1746 case CAM_DEV_NOT_THERE
:
1748 case CAM_PROVIDE_FAIL
:
1749 case CAM_REQ_TOO_BIG
:
1750 case CAM_LUN_INVALID
:
1751 case CAM_TID_INVALID
:
1754 case CAM_SCSI_BUS_RESET
:
1757 * Commands that repeatedly timeout and cause these
1758 * kinds of error recovery actions, should return
1759 * CAM_CMD_TIMEOUT, which allows us to safely assume
1760 * that this command was an innocent bystander to
1761 * these events and should be unconditionally
1764 if (bootverbose
&& printed
== 0) {
1765 xpt_print_path(ccb
->ccb_h
.path
);
1766 if (status
== CAM_BDR_SENT
)
1767 kprintf("Bus Device Reset sent\n");
1769 kprintf("Bus Reset issued\n");
1773 case CAM_REQUEUE_REQ
:
1774 /* Unconditional requeue */
1776 if (bootverbose
&& printed
== 0) {
1777 xpt_print(ccb
->ccb_h
.path
, "Request Requeued\n");
1781 case CAM_RESRC_UNAVAIL
:
1782 /* Wait a bit for the resource shortage to abate. */
1783 timeout
= periph_noresrc_delay
;
1787 /* Wait a bit for the busy condition to abate. */
1788 timeout
= periph_busy_delay
;
1790 relsim_flags
= RELSIM_RELEASE_AFTER_TIMEOUT
;
1793 /* decrement the number of retries */
1794 if (ccb
->ccb_h
.retry_count
> 0) {
1795 ccb
->ccb_h
.retry_count
--;
1797 if (bootverbose
&& printed
== 0) {
1798 xpt_print(ccb
->ccb_h
.path
, "CAM Status 0x%x\n",
1804 action_string
= "Retries Exhausted";
1809 /* Attempt a retry */
1810 if (error
== ERESTART
|| error
== 0) {
1812 ccb
->ccb_h
.status
&= ~CAM_DEV_QFRZN
;
1814 if (error
== ERESTART
) {
1815 action_string
= "Retrying Command";
1820 cam_release_devq(ccb
->ccb_h
.path
,
1824 /*getcount_only*/0);
1828 * If we have an error and are booting verbosely, whine
1829 * *unless* this was a non-retryable selection timeout.
1831 if (error
!= 0 && bootverbose
&& (sense_flags
& SF_NO_PRINT
) == 0 &&
1832 !(status
== CAM_SEL_TIMEOUT
&& (camflags
& CAM_RETRY_SELTO
) == 0)) {
1835 if (action_string
== NULL
)
1836 action_string
= "Unretryable Error";
1837 if (error
!= ERESTART
) {
1838 xpt_print(ccb
->ccb_h
.path
, "error %d\n", error
);
1840 xpt_print(ccb
->ccb_h
.path
, "%s\n", action_string
);