2 * Copyright (c) 2007 Scott Long
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions, and the following disclaimer,
10 * without modification, immediately at the beginning of the file.
11 * 2. The name of the author may not be used to endorse or promote products
12 * derived from this software without specific prior written permission.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
18 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 * scsi_sg peripheral driver. This driver is meant to implement the Linux
29 * SG passthrough interface for SCSI.
32 #include <sys/cdefs.h>
33 __FBSDID("$FreeBSD$");
35 #include <sys/param.h>
36 #include <sys/systm.h>
37 #include <sys/kernel.h>
38 #include <sys/types.h>
40 #include <sys/malloc.h>
41 #include <sys/fcntl.h>
42 #include <sys/ioccom.h>
44 #include <sys/errno.h>
45 #include <sys/devicestat.h>
50 #include <cam/cam_ccb.h>
51 #include <cam/cam_periph.h>
52 #include <cam/cam_queue.h>
53 #include <cam/cam_xpt_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_sg.h>
61 #include <compat/linux/linux_ioctl.h>
65 SG_FLAG_LOCKED = 0x02,
66 SG_FLAG_INVALID = 0x04
84 #define ccb_type ppriv_field0
85 #define ccb_rdwr ppriv_ptr1
88 TAILQ_ENTRY(sg_rdwr) rdwr_link;
96 struct sg_io_hdr io_hdr;
103 struct devstat *device_stats;
104 TAILQ_HEAD(, sg_rdwr) rdwr_done;
112 static d_open_t sgopen;
113 static d_close_t sgclose;
114 static d_ioctl_t sgioctl;
115 static d_write_t sgwrite;
116 static d_read_t sgread;
118 static periph_init_t sginit;
119 static periph_ctor_t sgregister;
120 static periph_oninv_t sgoninvalidate;
121 static periph_dtor_t sgcleanup;
122 static periph_start_t sgstart;
123 static void sgasync(void *callback_arg, uint32_t code,
124 struct cam_path *path, void *arg);
125 static void sgdone(struct cam_periph *periph, union ccb *done_ccb);
126 static int sgsendccb(struct cam_periph *periph, union ccb *ccb);
127 static int sgsendrdwr(struct cam_periph *periph, union ccb *ccb);
128 static int sgerror(union ccb *ccb, uint32_t cam_flags,
129 uint32_t sense_flags);
130 static void sg_scsiio_status(struct ccb_scsiio *csio,
131 u_short *hoststat, u_short *drvstat);
133 static int scsi_group_len(u_char cmd);
135 static struct periph_driver sgdriver =
138 TAILQ_HEAD_INITIALIZER(sgdriver.units), /* gen */ 0
140 PERIPHDRIVER_DECLARE(sg, sgdriver);
142 static struct cdevsw sg_cdevsw = {
143 .d_version = D_VERSION,
144 .d_flags = D_NEEDGIANT,
153 static int sg_version = 30125;
159 struct cam_path *path;
162 * Install a global async callback. This callback will receive aync
163 * callbacks like "new device found".
165 status = xpt_create_path(&path, /*periph*/NULL, CAM_XPT_PATH_ID,
166 CAM_TARGET_WILDCARD, CAM_LUN_WILDCARD);
168 if (status == CAM_REQ_CMP) {
169 struct ccb_setasync csa;
171 xpt_setup_ccb(&csa.ccb_h, path, /*priority*/5);
172 csa.ccb_h.func_code = XPT_SASYNC_CB;
173 csa.event_enable = AC_FOUND_DEVICE;
174 csa.callback = sgasync;
175 csa.callback_arg = NULL;
176 xpt_action((union ccb *)&csa);
177 status = csa.ccb_h.status;
181 if (status != CAM_REQ_CMP) {
182 printf("sg: Failed to attach master async callbac "
183 "due to status 0x%x!\n", status);
188 sgoninvalidate(struct cam_periph *periph)
190 struct sg_softc *softc;
191 struct ccb_setasync csa;
193 softc = (struct sg_softc *)periph->softc;
196 * Deregister any async callbacks.
198 xpt_setup_ccb(&csa.ccb_h, periph->path, /*priority*/5);
199 csa.ccb_h.func_code = XPT_SASYNC_CB;
200 csa.event_enable = 0;
201 csa.callback = sgasync;
202 csa.callback_arg = periph;
203 xpt_action((union ccb *)&csa);
205 softc->flags |= SG_FLAG_INVALID;
208 * XXX Return all queued I/O with ENXIO.
209 * XXX Handle any transactions queued to the card
210 * with XPT_ABORT_CCB.
214 xpt_print(periph->path, "lost device\n");
219 sgcleanup(struct cam_periph *periph)
221 struct sg_softc *softc;
223 softc = (struct sg_softc *)periph->softc;
224 devstat_remove_entry(softc->device_stats);
225 destroy_dev(softc->dev);
227 xpt_print(periph->path, "removing device entry\n");
229 free(softc, M_DEVBUF);
233 sgasync(void *callback_arg, uint32_t code, struct cam_path *path, void *arg)
235 struct cam_periph *periph;
237 periph = (struct cam_periph *)callback_arg;
240 case AC_FOUND_DEVICE:
242 struct ccb_getdev *cgd;
245 cgd = (struct ccb_getdev *)arg;
250 * Allocate a peripheral instance for this device and
251 * start the probe process.
253 status = cam_periph_alloc(sgregister, sgoninvalidate,
254 sgcleanup, sgstart, "sg",
255 CAM_PERIPH_BIO, cgd->ccb_h.path,
256 sgasync, AC_FOUND_DEVICE, cgd);
257 if ((status != CAM_REQ_CMP) && (status != CAM_REQ_INPROG)) {
258 const struct cam_status_entry *entry;
260 entry = cam_fetch_status_entry(status);
261 printf("sgasync: Unable to attach new device "
262 "due to status %#x: %s\n", status, entry ?
263 entry->status_text : "Unknown");
268 cam_periph_async(periph, code, path, arg);
274 sgregister(struct cam_periph *periph, void *arg)
276 struct sg_softc *softc;
277 struct ccb_setasync csa;
278 struct ccb_getdev *cgd;
281 cgd = (struct ccb_getdev *)arg;
282 if (periph == NULL) {
283 printf("sgregister: periph was NULL!!\n");
284 return (CAM_REQ_CMP_ERR);
288 printf("sgregister: no getdev CCB, can't register device\n");
289 return (CAM_REQ_CMP_ERR);
292 softc = malloc(sizeof(*softc), M_DEVBUF, M_ZERO | M_NOWAIT);
294 printf("sgregister: Unable to allocate softc\n");
295 return (CAM_REQ_CMP_ERR);
298 softc->state = SG_STATE_NORMAL;
299 softc->pd_type = SID_TYPE(&cgd->inq_data);
300 softc->sg_timeout = SG_DEFAULT_TIMEOUT / SG_DEFAULT_HZ * hz;
301 softc->sg_user_timeout = SG_DEFAULT_TIMEOUT;
302 TAILQ_INIT(&softc->rdwr_done);
303 periph->softc = softc;
306 * We pass in 0 for all blocksize, since we don't know what the
307 * blocksize of the device is, if it even has a blocksize.
309 no_tags = (cgd->inq_data.flags & SID_CmdQue) == 0;
310 softc->device_stats = devstat_new_entry("sg",
311 unit2minor(periph->unit_number), 0,
313 | (no_tags ? DEVSTAT_NO_ORDERED_TAGS : 0),
315 DEVSTAT_TYPE_IF_SCSI |
317 DEVSTAT_PRIORITY_PASS);
319 /* Register the device */
320 softc->dev = make_dev(&sg_cdevsw, unit2minor(periph->unit_number),
321 UID_ROOT, GID_OPERATOR, 0600, "%s%d",
322 periph->periph_name, periph->unit_number);
323 (void)make_dev_alias(softc->dev, "sg%c", 'a' + periph->unit_number);
324 softc->dev->si_drv1 = periph;
327 * Add as async callback so that we get
328 * notified if this device goes away.
330 xpt_setup_ccb(&csa.ccb_h, periph->path, /*priority*/5);
331 csa.ccb_h.func_code = XPT_SASYNC_CB;
332 csa.event_enable = AC_LOST_DEVICE;
333 csa.callback = sgasync;
334 csa.callback_arg = periph;
335 xpt_action((union ccb *)&csa);
338 xpt_announce_periph(periph, NULL);
340 return (CAM_REQ_CMP);
344 sgstart(struct cam_periph *periph, union ccb *start_ccb)
346 struct sg_softc *softc;
348 softc = (struct sg_softc *)periph->softc;
350 switch (softc->state) {
351 case SG_STATE_NORMAL:
352 start_ccb->ccb_h.ccb_type = SG_CCB_WAITING;
353 SLIST_INSERT_HEAD(&periph->ccb_list, &start_ccb->ccb_h,
355 periph->immediate_priority = CAM_PRIORITY_NONE;
356 wakeup(&periph->ccb_list);
362 sgdone(struct cam_periph *periph, union ccb *done_ccb)
364 struct sg_softc *softc;
365 struct ccb_scsiio *csio;
367 softc = (struct sg_softc *)periph->softc;
368 csio = &done_ccb->csio;
369 switch (csio->ccb_h.ccb_type) {
371 /* Caller will release the CCB */
372 wakeup(&done_ccb->ccb_h.cbfcnp);
376 struct sg_rdwr *rdwr;
379 devstat_end_transaction(softc->device_stats,
381 csio->tag_action & 0xf,
382 ((csio->ccb_h.flags & CAM_DIR_MASK) ==
383 CAM_DIR_NONE) ? DEVSTAT_NO_DATA :
384 (csio->ccb_h.flags & CAM_DIR_OUT) ?
385 DEVSTAT_WRITE : DEVSTAT_READ,
388 rdwr = done_ccb->ccb_h.ccb_rdwr;
390 rdwr->state = SG_RDWR_DONE;
395 panic("unknown sg CCB type");
400 sgopen(struct cdev *dev, int flags, int fmt, struct thread *td)
402 struct cam_periph *periph;
403 struct sg_softc *softc;
406 periph = (struct cam_periph *)dev->si_drv1;
410 softc = (struct sg_softc *)periph->softc;
411 if (softc->flags & SG_FLAG_INVALID)
415 * Don't allow access when we're running at a high securelevel.
417 error = securelevel_gt(td->td_ucred, 1);
421 if ((error = cam_periph_lock(periph, PRIBIO | PCATCH)) != 0)
424 if ((softc->flags & SG_FLAG_OPEN) == 0) {
425 if (cam_periph_acquire(periph) != CAM_REQ_CMP)
427 softc->flags |= SG_FLAG_OPEN;
430 cam_periph_unlock(periph);
436 sgclose(struct cdev *dev, int flag, int fmt, struct thread *td)
438 struct cam_periph *periph;
439 struct sg_softc *softc;
442 periph = (struct cam_periph *)dev->si_drv1;
446 softc = (struct sg_softc *)periph->softc;
448 if ((error = cam_periph_lock(periph, PRIBIO)) != 0)
451 softc->flags &= ~SG_FLAG_OPEN;
453 cam_periph_unlock(periph);
454 cam_periph_release(periph);
460 sgioctl(struct cdev *dev, u_long cmd, caddr_t arg, int flag, struct thread *td)
463 struct ccb_scsiio *csio;
464 struct cam_periph *periph;
465 struct sg_softc *softc;
466 struct sg_io_hdr req;
469 periph = (struct cam_periph *)dev->si_drv1;
473 softc = (struct sg_softc *)periph->softc;
477 case LINUX_SCSI_GET_BUS_NUMBER: {
480 busno = xpt_path_path_id(periph->path);
481 error = copyout(&busno, arg, sizeof(busno));
484 case LINUX_SCSI_GET_IDLUN: {
485 struct scsi_idlun idlun;
488 idlun.dev_id = xpt_path_target_id(periph->path);
489 sim = xpt_path_sim(periph->path);
490 idlun.host_unique_id = sim->unit_number;
491 error = copyout(&idlun, arg, sizeof(idlun));
494 case SG_GET_VERSION_NUM:
495 case LINUX_SG_GET_VERSION_NUM:
496 error = copyout(&sg_version, arg, sizeof(sg_version));
499 case LINUX_SG_SET_TIMEOUT: {
502 error = copyin(arg, &user_timeout, sizeof(u_int));
504 softc->sg_user_timeout = user_timeout;
505 softc->sg_timeout = user_timeout / SG_DEFAULT_HZ * hz;
510 case LINUX_SG_GET_TIMEOUT:
512 * The value is returned directly to the syscall.
514 td->td_retval[0] = softc->sg_user_timeout;
519 error = copyin(arg, &req, sizeof(req));
523 if (req.cmd_len > IOCDBLEN) {
528 if (req.iovec_count != 0) {
533 ccb = cam_periph_getccb(periph, /*priority*/5);
536 error = copyin(req.cmdp, &csio->cdb_io.cdb_bytes,
539 xpt_release_ccb(ccb);
543 switch(req.dxfer_direction) {
544 case SG_DXFER_TO_DEV:
547 case SG_DXFER_FROM_DEV:
550 case SG_DXFER_TO_FROM_DEV:
551 dir = CAM_DIR_IN | CAM_DIR_OUT;
570 error = sgsendccb(periph, ccb);
572 req.host_status = DID_ERROR;
573 req.driver_status = DRIVER_INVALID;
574 xpt_release_ccb(ccb);
578 req.status = csio->scsi_status;
579 req.masked_status = (csio->scsi_status >> 1) & 0x7f;
580 sg_scsiio_status(csio, &req.host_status, &req.driver_status);
581 req.resid = csio->resid;
582 req.duration = csio->ccb_h.timeout;
585 error = copyout(&req, arg, sizeof(req));
586 if ((error == 0) && (csio->ccb_h.status & CAM_AUTOSNS_VALID)
587 && (req.sbp != NULL)) {
588 req.sb_len_wr = req.mx_sb_len - csio->sense_resid;
589 error = copyout(&csio->sense_data, req.sbp,
593 xpt_release_ccb(ccb);
596 case SG_GET_RESERVED_SIZE:
597 case LINUX_SG_GET_RESERVED_SIZE: {
600 error = copyout(&size, arg, sizeof(size));
605 case LINUX_SG_GET_SCSI_ID:
607 struct sg_scsi_id id;
609 id.host_no = 0; /* XXX */
610 id.channel = xpt_path_path_id(periph->path);
611 id.scsi_id = xpt_path_target_id(periph->path);
612 id.lun = xpt_path_lun_id(periph->path);
613 id.scsi_type = softc->pd_type;
614 id.h_cmd_per_lun = 1;
615 id.d_queue_depth = 1;
619 error = copyout(&id, arg, sizeof(id));
623 case SG_EMULATED_HOST:
624 case SG_SET_TRANSFORM:
625 case SG_GET_TRANSFORM:
626 case SG_GET_NUM_WAITING:
628 case SG_GET_REQUEST_TABLE:
629 case SG_SET_KEEP_ORPHAN:
630 case SG_GET_KEEP_ORPHAN:
631 case SG_GET_ACCESS_COUNT:
632 case SG_SET_FORCE_LOW_DMA:
634 case SG_GET_SG_TABLESIZE:
635 case SG_SET_FORCE_PACK_ID:
637 case SG_SET_RESERVED_SIZE:
638 case SG_GET_COMMAND_Q:
639 case SG_SET_COMMAND_Q:
641 case SG_NEXT_CMD_LEN:
642 case LINUX_SG_EMULATED_HOST:
643 case LINUX_SG_SET_TRANSFORM:
644 case LINUX_SG_GET_TRANSFORM:
645 case LINUX_SG_GET_NUM_WAITING:
646 case LINUX_SG_SCSI_RESET:
647 case LINUX_SG_GET_REQUEST_TABLE:
648 case LINUX_SG_SET_KEEP_ORPHAN:
649 case LINUX_SG_GET_KEEP_ORPHAN:
650 case LINUX_SG_GET_ACCESS_COUNT:
651 case LINUX_SG_SET_FORCE_LOW_DMA:
652 case LINUX_SG_GET_LOW_DMA:
653 case LINUX_SG_GET_SG_TABLESIZE:
654 case LINUX_SG_SET_FORCE_PACK_ID:
655 case LINUX_SG_GET_PACK_ID:
656 case LINUX_SG_SET_RESERVED_SIZE:
657 case LINUX_SG_GET_COMMAND_Q:
658 case LINUX_SG_SET_COMMAND_Q:
659 case LINUX_SG_SET_DEBUG:
660 case LINUX_SG_NEXT_CMD_LEN:
663 printf("sgioctl: rejecting cmd 0x%lx\n", cmd);
673 sgwrite(struct cdev *dev, struct uio *uio, int ioflag)
676 struct cam_periph *periph;
677 struct ccb_scsiio *csio;
679 struct sg_header *hdr;
680 struct sg_rdwr *rdwr;
683 int error = 0, cdb_len, buf_len, dir;
685 periph = dev->si_drv1;
687 rdwr = malloc(sizeof(*rdwr), M_DEVBUF, M_WAITOK | M_ZERO);
688 hdr = &rdwr->hdr.hdr;
690 /* Copy in the header block and sanity check it */
691 if (uio->uio_resid < sizeof(*hdr)) {
695 error = uiomove(hdr, sizeof(*hdr), uio);
699 ccb = xpt_alloc_ccb();
704 xpt_setup_ccb(&ccb->ccb_h, periph->path, /*priority*/5);
708 * Copy in the CDB block. The designers of the interface didn't
709 * bother to provide a size for this in the header, so we have to
710 * figure it out ourselves.
712 if (uio->uio_resid < 1)
714 error = uiomove(&cdb_cmd, 1, uio);
717 if (hdr->twelve_byte)
720 cdb_len = scsi_group_len(cdb_cmd);
722 * We've already read the first byte of the CDB and advanced the uio
723 * pointer. Just read the rest.
725 csio->cdb_io.cdb_bytes[0] = cdb_cmd;
726 error = uiomove(&csio->cdb_io.cdb_bytes[1], cdb_len - 1, uio);
731 * Now set up the data block. Again, the designers didn't bother
732 * to make this reliable.
734 buf_len = uio->uio_resid;
736 buf = malloc(buf_len, M_DEVBUF, M_WAITOK | M_ZERO);
737 error = uiomove(buf, buf_len, uio);
741 } else if (hdr->reply_len != 0) {
742 buf = malloc(hdr->reply_len, M_DEVBUF, M_WAITOK | M_ZERO);
743 buf_len = hdr->reply_len;
763 * Send off the command and hope that it works. This path does not
764 * go through sgstart because the I/O is supposed to be asynchronous.
767 rdwr->buf_len = buf_len;
768 rdwr->tag = hdr->pack_id;
770 rdwr->state = SG_RDWR_INPROG;
771 ccb->ccb_h.ccb_rdwr = rdwr;
772 ccb->ccb_h.ccb_type = SG_CCB_RDWR_IO;
773 TAILQ_INSERT_TAIL(&sc->rdwr_done, rdwr, rdwr_link);
774 return (sgsendrdwr(periph, ccb));
781 free(rdwr, M_DEVBUF);
786 sgread(struct cdev *dev, struct uio *uio, int ioflag)
788 struct ccb_scsiio *csio;
789 struct cam_periph *periph;
791 struct sg_header *hdr;
792 struct sg_rdwr *rdwr;
793 u_short hstat, dstat;
794 int error, pack_len, reply_len, pack_id;
796 periph = dev->si_drv1;
799 /* XXX The pack len field needs to be updated and written out instead
800 * of discarded. Not sure how to do that.
802 uio->uio_rw = UIO_WRITE;
803 if ((error = uiomove(&pack_len, 4, uio)) != 0)
805 if ((error = uiomove(&reply_len, 4, uio)) != 0)
807 if ((error = uiomove(&pack_id, 4, uio)) != 0)
809 uio->uio_rw = UIO_READ;
812 TAILQ_FOREACH(rdwr, &sc->rdwr_done, rdwr_link) {
813 if (rdwr->tag == pack_id)
816 if ((rdwr == NULL) || (rdwr->state != SG_RDWR_DONE)) {
817 if (tsleep(rdwr, PCATCH, "sgread", 0) == ERESTART)
821 TAILQ_REMOVE(&sc->rdwr_done, rdwr, rdwr_link);
823 hdr = &rdwr->hdr.hdr;
824 csio = &rdwr->ccb->csio;
825 sg_scsiio_status(csio, &hstat, &dstat);
826 hdr->host_status = hstat;
827 hdr->driver_status = dstat;
828 hdr->target_status = csio->scsi_status >> 1;
832 case DID_PASSTHROUGH:
852 if (dstat == DRIVER_SENSE) {
853 bcopy(&csio->sense_data, hdr->sense_buffer,
854 min(csio->sense_len, SG_MAX_SENSE));
856 scsi_sense_print(csio);
860 error = uiomove(&hdr->result, sizeof(*hdr) -
861 offsetof(struct sg_header, result), uio);
862 if ((error == 0) && (hdr->result == 0))
863 error = uiomove(rdwr->buf, rdwr->buf_len, uio);
865 xpt_free_ccb(rdwr->ccb);
866 free(rdwr->buf, M_DEVBUF);
867 free(rdwr, M_DEVBUF);
872 sgsendccb(struct cam_periph *periph, union ccb *ccb)
874 struct sg_softc *softc;
875 struct cam_periph_map_info mapinfo;
876 int error, need_unmap = 0;
878 softc = periph->softc;
879 if (((ccb->ccb_h.flags & CAM_DIR_MASK) != CAM_DIR_NONE)
880 && (ccb->csio.data_ptr != NULL)) {
881 bzero(&mapinfo, sizeof(mapinfo));
882 error = cam_periph_mapmem(ccb, &mapinfo);
888 error = cam_periph_runccb(ccb,
892 softc->device_stats);
895 cam_periph_unmapmem(ccb, &mapinfo);
901 sgsendrdwr(struct cam_periph *periph, union ccb *ccb)
903 struct sg_softc *softc;
905 softc = periph->softc;
906 devstat_start_transaction(softc->device_stats, NULL);
912 sgerror(union ccb *ccb, uint32_t cam_flags, uint32_t sense_flags)
914 struct cam_periph *periph;
915 struct sg_softc *softc;
917 periph = xpt_path_periph(ccb->ccb_h.path);
918 softc = (struct sg_softc *)periph->softc;
920 return (cam_periph_error(ccb, cam_flags, sense_flags,
925 sg_scsiio_status(struct ccb_scsiio *csio, u_short *hoststat, u_short *drvstat)
929 status = csio->ccb_h.status;
931 switch (status & CAM_STATUS_MASK) {
936 case CAM_REQ_CMP_ERR:
937 *hoststat = DID_ERROR;
940 case CAM_REQ_ABORTED:
941 *hoststat = DID_ABORT;
944 case CAM_REQ_INVALID:
945 *hoststat = DID_ERROR;
946 *drvstat = DRIVER_INVALID;
948 case CAM_DEV_NOT_THERE:
949 *hoststat = DID_BAD_TARGET;
951 case CAM_SEL_TIMEOUT:
952 *hoststat = DID_NO_CONNECT;
955 case CAM_CMD_TIMEOUT:
956 *hoststat = DID_TIME_OUT;
959 case CAM_SCSI_STATUS_ERROR:
960 *hoststat = DID_ERROR;
962 case CAM_SCSI_BUS_RESET:
963 *hoststat = DID_RESET;
966 case CAM_UNCOR_PARITY:
967 *hoststat = DID_PARITY;
971 *hoststat = DID_BUS_BUSY;
974 *hoststat = DID_ERROR;
975 *drvstat = DRIVER_ERROR;
978 if (status & CAM_AUTOSNS_VALID)
979 *drvstat = DRIVER_SENSE;
983 scsi_group_len(u_char cmd)
985 int len[] = {6, 10, 10, 12, 12, 12, 10, 10};
988 group = (cmd >> 5) & 0x7;