2 * Copyright (c) 1997 Justin T. Gibbs.
3 * Copyright (c) 1997, 1998, 1999 Kenneth D. Merry.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions, and the following disclaimer,
11 * without modification, immediately at the beginning of the file.
12 * 2. The name of the author may not be used to endorse or promote products
13 * derived from this software without specific prior written permission.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
19 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * $FreeBSD: src/sys/cam/scsi/scsi_ch.c,v 1.20.2.2 2000/10/31 08:09:49 dwmalone Exp $
30 * Derived from the NetBSD SCSI changer driver.
32 * $NetBSD: ch.c,v 1.32 1998/01/12 09:49:12 thorpej Exp $
36 * Copyright (c) 1996, 1997 Jason R. Thorpe <thorpej@and.com>
37 * All rights reserved.
39 * Partially based on an autochanger driver written by Stefan Grefen
40 * and on an autochanger driver written by the Systems Programming Group
41 * at the University of Utah Computer Science Department.
43 * Redistribution and use in source and binary forms, with or without
44 * modification, are permitted provided that the following conditions
46 * 1. Redistributions of source code must retain the above copyright
47 * notice, this list of conditions and the following disclaimer.
48 * 2. Redistributions in binary form must reproduce the above copyright
49 * notice, this list of conditions and the following disclaimer in the
50 * documentation and/or other materials provided with the distribution.
51 * 3. All advertising materials mentioning features or use of this software
52 * must display the following acknowledgements:
53 * This product includes software developed by Jason R. Thorpe
54 * for And Communications, http://www.and.com/
55 * 4. The name of the author may not be used to endorse or promote products
56 * derived from this software without specific prior written permission.
58 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
59 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
60 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
61 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
62 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
63 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
64 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
65 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
66 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
67 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
71 #include <sys/param.h>
72 #include <sys/queue.h>
73 #include <sys/systm.h>
74 #include <sys/kernel.h>
75 #include <sys/types.h>
76 #include <sys/malloc.h>
77 #include <sys/fcntl.h>
82 #include <sys/errno.h>
83 #include <sys/devicestat.h>
86 #include <cam/cam_ccb.h>
87 #include <cam/cam_extend.h>
88 #include <cam/cam_periph.h>
89 #include <cam/cam_xpt_periph.h>
90 #include <cam/cam_queue.h>
91 #include <cam/cam_debug.h>
93 #include <cam/scsi/scsi_all.h>
94 #include <cam/scsi/scsi_message.h>
95 #include <cam/scsi/scsi_ch.h>
98 * Timeout definitions for various changer related commands. They may
99 * be too short for some devices (especially the timeout for INITIALIZE
103 static const u_int32_t CH_TIMEOUT_MODE_SENSE = 6000;
104 static const u_int32_t CH_TIMEOUT_MOVE_MEDIUM = 100000;
105 static const u_int32_t CH_TIMEOUT_EXCHANGE_MEDIUM = 100000;
106 static const u_int32_t CH_TIMEOUT_POSITION_TO_ELEMENT = 100000;
107 static const u_int32_t CH_TIMEOUT_READ_ELEMENT_STATUS = 10000;
108 static const u_int32_t CH_TIMEOUT_SEND_VOLTAG = 10000;
109 static const u_int32_t CH_TIMEOUT_INITIALIZE_ELEMENT_STATUS = 500000;
112 CH_FLAG_INVALID = 0x001,
131 #define ccb_state ppriv_field0
132 #define ccb_bp ppriv_ptr1
134 struct scsi_mode_sense_data {
135 struct scsi_mode_header_6 header;
136 struct scsi_mode_blk_desc blk_desc;
138 struct page_element_address_assignment ea;
139 struct page_transport_geometry_parameters tg;
140 struct page_device_capabilities cap;
149 struct devstat device_stats;
152 int sc_picker; /* current picker */
155 * The following information is obtained from the
156 * element address assignment page.
158 int sc_firsts[4]; /* firsts, indexed by CHET_* */
159 int sc_counts[4]; /* counts, indexed by CHET_* */
162 * The following mask defines the legal combinations
163 * of elements for the MOVE MEDIUM command.
165 u_int8_t sc_movemask[4];
168 * As above, but for EXCHANGE MEDIUM.
170 u_int8_t sc_exchangemask[4];
173 * Quirks; see below. XXX KDM not implemented yet
175 int sc_settledelay; /* delay for settle */
178 #define CHUNIT(x) (minor((x)))
179 #define CH_CDEV_MAJOR 17
181 static d_open_t chopen;
182 static d_close_t chclose;
183 static d_ioctl_t chioctl;
184 static periph_init_t chinit;
185 static periph_ctor_t chregister;
186 static periph_oninv_t choninvalidate;
187 static periph_dtor_t chcleanup;
188 static periph_start_t chstart;
189 static void chasync(void *callback_arg, u_int32_t code,
190 struct cam_path *path, void *arg);
191 static void chdone(struct cam_periph *periph,
192 union ccb *done_ccb);
193 static int cherror(union ccb *ccb, u_int32_t cam_flags,
194 u_int32_t sense_flags);
195 static int chmove(struct cam_periph *periph,
196 struct changer_move *cm);
197 static int chexchange(struct cam_periph *periph,
198 struct changer_exchange *ce);
199 static int chposition(struct cam_periph *periph,
200 struct changer_position *cp);
201 static int chgetelemstatus(struct cam_periph *periph,
202 struct changer_element_status_request *csr);
203 static int chsetvoltag(struct cam_periph *periph,
204 struct changer_set_voltag_request *csvr);
205 static int chielem(struct cam_periph *periph,
206 unsigned int timeout);
207 static int chgetparams(struct cam_periph *periph);
209 static struct periph_driver chdriver =
212 TAILQ_HEAD_INITIALIZER(chdriver.units), /* generation */ 0
215 DATA_SET(periphdriver_set, chdriver);
217 static struct cdevsw ch_cdevsw = {
225 /* strategy */ nostrategy,
227 /* maj */ CH_CDEV_MAJOR,
234 static struct extend_array *chperiphs;
240 struct cam_path *path;
243 * Create our extend array for storing the devices we attach to.
245 chperiphs = cam_extend_new();
246 if (chperiphs == NULL) {
247 printf("ch: Failed to alloc extend array!\n");
252 * Install a global async callback. This callback will
253 * receive async callbacks like "new device found".
255 status = xpt_create_path(&path, /*periph*/NULL, CAM_XPT_PATH_ID,
256 CAM_TARGET_WILDCARD, CAM_LUN_WILDCARD);
258 if (status == CAM_REQ_CMP) {
259 struct ccb_setasync csa;
261 xpt_setup_ccb(&csa.ccb_h, path, /*priority*/5);
262 csa.ccb_h.func_code = XPT_SASYNC_CB;
263 csa.event_enable = AC_FOUND_DEVICE;
264 csa.callback = chasync;
265 csa.callback_arg = NULL;
266 xpt_action((union ccb *)&csa);
267 status = csa.ccb_h.status;
271 if (status != CAM_REQ_CMP) {
272 printf("ch: Failed to attach master async callback "
273 "due to status 0x%x!\n", status);
278 choninvalidate(struct cam_periph *periph)
280 struct ch_softc *softc;
281 struct ccb_setasync csa;
283 softc = (struct ch_softc *)periph->softc;
286 * De-register any async callbacks.
288 xpt_setup_ccb(&csa.ccb_h, periph->path,
290 csa.ccb_h.func_code = XPT_SASYNC_CB;
291 csa.event_enable = 0;
292 csa.callback = chasync;
293 csa.callback_arg = periph;
294 xpt_action((union ccb *)&csa);
296 softc->flags |= CH_FLAG_INVALID;
298 xpt_print_path(periph->path);
299 printf("lost device\n");
304 chcleanup(struct cam_periph *periph)
306 struct ch_softc *softc;
308 softc = (struct ch_softc *)periph->softc;
310 devstat_remove_entry(&softc->device_stats);
311 destroy_dev(softc->dev);
312 cam_extend_release(chperiphs, periph->unit_number);
313 xpt_print_path(periph->path);
314 printf("removing device entry\n");
315 free(softc, M_DEVBUF);
319 chasync(void *callback_arg, u_int32_t code, struct cam_path *path, void *arg)
321 struct cam_periph *periph;
323 periph = (struct cam_periph *)callback_arg;
326 case AC_FOUND_DEVICE:
328 struct ccb_getdev *cgd;
331 cgd = (struct ccb_getdev *)arg;
333 if (SID_TYPE(&cgd->inq_data)!= T_CHANGER)
337 * Allocate a peripheral instance for
338 * this device and start the probe
341 status = cam_periph_alloc(chregister, choninvalidate,
342 chcleanup, chstart, "ch",
343 CAM_PERIPH_BIO, cgd->ccb_h.path,
344 chasync, AC_FOUND_DEVICE, cgd);
346 if (status != CAM_REQ_CMP
347 && status != CAM_REQ_INPROG)
348 printf("chasync: Unable to probe new device "
349 "due to status 0x%x\n", status);
355 cam_periph_async(periph, code, path, arg);
361 chregister(struct cam_periph *periph, void *arg)
363 struct ch_softc *softc;
364 struct ccb_setasync csa;
365 struct ccb_getdev *cgd;
367 cgd = (struct ccb_getdev *)arg;
368 if (periph == NULL) {
369 printf("chregister: periph was NULL!!\n");
370 return(CAM_REQ_CMP_ERR);
374 printf("chregister: no getdev CCB, can't register device\n");
375 return(CAM_REQ_CMP_ERR);
378 softc = (struct ch_softc *)malloc(sizeof(*softc),M_DEVBUF,M_NOWAIT);
381 printf("chregister: Unable to probe new device. "
382 "Unable to allocate softc\n");
383 return(CAM_REQ_CMP_ERR);
386 bzero(softc, sizeof(*softc));
387 softc->state = CH_STATE_PROBE;
388 periph->softc = softc;
389 cam_extend_set(chperiphs, periph->unit_number, periph);
390 softc->quirks = CH_Q_NONE;
393 * Changers don't have a blocksize, and obviously don't support
396 devstat_add_entry(&softc->device_stats, "ch",
397 periph->unit_number, 0,
398 DEVSTAT_NO_BLOCKSIZE | DEVSTAT_NO_ORDERED_TAGS,
399 SID_TYPE(&cgd->inq_data)| DEVSTAT_TYPE_IF_SCSI,
400 DEVSTAT_PRIORITY_OTHER);
402 /* Register the device */
403 softc->dev = make_dev(&ch_cdevsw, periph->unit_number, UID_ROOT,
404 GID_OPERATOR, 0600, "%s%d", periph->periph_name,
405 periph->unit_number);
408 * Add an async callback so that we get
409 * notified if this device goes away.
411 xpt_setup_ccb(&csa.ccb_h, periph->path, /* priority */ 5);
412 csa.ccb_h.func_code = XPT_SASYNC_CB;
413 csa.event_enable = AC_LOST_DEVICE;
414 csa.callback = chasync;
415 csa.callback_arg = periph;
416 xpt_action((union ccb *)&csa);
419 * Lock this peripheral until we are setup.
420 * This first call can't block
422 (void)cam_periph_lock(periph, PRIBIO);
423 xpt_schedule(periph, /*priority*/5);
429 chopen(dev_t dev, int flags, int fmt, struct proc *p)
431 struct cam_periph *periph;
432 struct ch_softc *softc;
437 periph = cam_extend_get(chperiphs, unit);
442 softc = (struct ch_softc *)periph->softc;
445 if (softc->flags & CH_FLAG_INVALID) {
450 if ((error = cam_periph_lock(periph, PRIBIO | PCATCH)) != 0) {
457 if ((softc->flags & CH_FLAG_OPEN) == 0) {
458 if (cam_periph_acquire(periph) != CAM_REQ_CMP)
460 softc->flags |= CH_FLAG_OPEN;
464 * Load information about this changer device into the softc.
466 if ((error = chgetparams(periph)) != 0) {
467 softc->flags &= ~CH_FLAG_OPEN;
468 cam_periph_unlock(periph);
469 cam_periph_release(periph);
473 cam_periph_unlock(periph);
479 chclose(dev_t dev, int flag, int fmt, struct proc *p)
481 struct cam_periph *periph;
482 struct ch_softc *softc;
488 periph = cam_extend_get(chperiphs, unit);
492 softc = (struct ch_softc *)periph->softc;
494 if ((error = cam_periph_lock(periph, PRIBIO)) != 0)
497 softc->flags &= ~CH_FLAG_OPEN;
499 cam_periph_unlock(periph);
500 cam_periph_release(periph);
506 chstart(struct cam_periph *periph, union ccb *start_ccb)
508 struct ch_softc *softc;
511 softc = (struct ch_softc *)periph->softc;
513 switch (softc->state) {
514 case CH_STATE_NORMAL:
517 if (periph->immediate_priority <= periph->pinfo.priority){
518 start_ccb->ccb_h.ccb_state = CH_CCB_WAITING;
520 SLIST_INSERT_HEAD(&periph->ccb_list, &start_ccb->ccb_h,
522 periph->immediate_priority = CAM_PRIORITY_NONE;
524 wakeup(&periph->ccb_list);
535 * Include the block descriptor when calculating the mode
538 mode_buffer_len = sizeof(struct scsi_mode_header_6) +
539 sizeof(struct scsi_mode_blk_desc) +
540 sizeof(struct page_element_address_assignment);
542 mode_buffer = malloc(mode_buffer_len, M_TEMP, M_NOWAIT);
544 if (mode_buffer == NULL) {
545 printf("chstart: couldn't malloc mode sense data\n");
548 bzero(mode_buffer, mode_buffer_len);
551 * Get the element address assignment page.
553 scsi_mode_sense(&start_ccb->csio,
556 /* tag_action */ MSG_SIMPLE_Q_TAG,
557 /* dbd */ (softc->quirks & CH_Q_NO_DBD) ?
559 /* page_code */ SMS_PAGE_CTRL_CURRENT,
560 /* page */ CH_ELEMENT_ADDR_ASSIGN_PAGE,
561 /* param_buf */ (u_int8_t *)mode_buffer,
562 /* param_len */ mode_buffer_len,
563 /* sense_len */ SSD_FULL_SIZE,
564 /* timeout */ CH_TIMEOUT_MODE_SENSE);
566 start_ccb->ccb_h.ccb_bp = NULL;
567 start_ccb->ccb_h.ccb_state = CH_CCB_PROBE;
568 xpt_action(start_ccb);
575 chdone(struct cam_periph *periph, union ccb *done_ccb)
577 struct ch_softc *softc;
578 struct ccb_scsiio *csio;
580 softc = (struct ch_softc *)periph->softc;
581 csio = &done_ccb->csio;
583 switch(done_ccb->ccb_h.ccb_state) {
586 struct scsi_mode_header_6 *mode_header;
587 struct page_element_address_assignment *ea;
588 char announce_buf[80];
591 mode_header = (struct scsi_mode_header_6 *)csio->data_ptr;
593 ea = (struct page_element_address_assignment *)
594 find_mode_page_6(mode_header);
596 if ((done_ccb->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP){
598 softc->sc_firsts[CHET_MT] = scsi_2btoul(ea->mtea);
599 softc->sc_counts[CHET_MT] = scsi_2btoul(ea->nmte);
600 softc->sc_firsts[CHET_ST] = scsi_2btoul(ea->fsea);
601 softc->sc_counts[CHET_ST] = scsi_2btoul(ea->nse);
602 softc->sc_firsts[CHET_IE] = scsi_2btoul(ea->fieea);
603 softc->sc_counts[CHET_IE] = scsi_2btoul(ea->niee);
604 softc->sc_firsts[CHET_DT] = scsi_2btoul(ea->fdtea);
605 softc->sc_counts[CHET_DT] = scsi_2btoul(ea->ndte);
606 softc->sc_picker = softc->sc_firsts[CHET_MT];
608 #define PLURAL(c) (c) == 1 ? "" : "s"
609 snprintf(announce_buf, sizeof(announce_buf),
610 "%d slot%s, %d drive%s, "
611 "%d picker%s, %d portal%s",
612 softc->sc_counts[CHET_ST],
613 PLURAL(softc->sc_counts[CHET_ST]),
614 softc->sc_counts[CHET_DT],
615 PLURAL(softc->sc_counts[CHET_DT]),
616 softc->sc_counts[CHET_MT],
617 PLURAL(softc->sc_counts[CHET_MT]),
618 softc->sc_counts[CHET_IE],
619 PLURAL(softc->sc_counts[CHET_IE]));
624 error = cherror(done_ccb, 0, SF_RETRY_UA |
625 SF_NO_PRINT | SF_RETRY_SELTO);
627 * Retry any UNIT ATTENTION type errors. They
628 * are expected at boot.
630 if (error == ERESTART) {
632 * A retry was scheuled, so
636 } else if (error != 0) {
638 struct scsi_mode_sense_6 *sms;
640 sms = (struct scsi_mode_sense_6 *)
641 done_ccb->csio.cdb_io.cdb_bytes;
644 * Check to see if block descriptors were
645 * disabled. Some devices don't like that.
646 * We're taking advantage of the fact that
647 * the first few bytes of the 6 and 10 byte
648 * mode sense commands are the same. If
649 * block descriptors were disabled, enable
650 * them and re-send the command.
652 if (sms->byte2 & SMS_DBD) {
653 sms->byte2 &= ~SMS_DBD;
654 xpt_action(done_ccb);
655 softc->quirks |= CH_Q_NO_DBD;
660 /* Don't wedge this device's queue */
661 cam_release_devq(done_ccb->ccb_h.path,
670 if ((done_ccb->ccb_h.status & CAM_STATUS_MASK)
671 == CAM_SCSI_STATUS_ERROR)
672 scsi_sense_print(&done_ccb->csio);
674 xpt_print_path(periph->path);
675 printf("got CAM status %#x\n",
676 done_ccb->ccb_h.status);
678 xpt_print_path(periph->path);
679 printf("fatal error, failed to attach to"
682 cam_periph_invalidate(periph);
684 announce_buf[0] = '\0';
687 if (announce_buf[0] != '\0')
688 xpt_announce_periph(periph, announce_buf);
689 softc->state = CH_STATE_NORMAL;
690 free(mode_header, M_TEMP);
692 * Since our peripheral may be invalidated by an error
693 * above or an external event, we must release our CCB
694 * before releasing the probe lock on the peripheral.
695 * The peripheral will only go away once the last lock
696 * is removed, and we need it around for the CCB release
699 xpt_release_ccb(done_ccb);
700 cam_periph_unlock(periph);
705 /* Caller will release the CCB */
706 wakeup(&done_ccb->ccb_h.cbfcnp);
712 xpt_release_ccb(done_ccb);
716 cherror(union ccb *ccb, u_int32_t cam_flags, u_int32_t sense_flags)
718 struct ch_softc *softc;
719 struct cam_periph *periph;
721 periph = xpt_path_periph(ccb->ccb_h.path);
722 softc = (struct ch_softc *)periph->softc;
724 return (cam_periph_error(ccb, cam_flags, sense_flags,
729 chioctl(dev_t dev, u_long cmd, caddr_t addr, int flag, struct proc *p)
731 struct cam_periph *periph;
732 struct ch_softc *softc;
738 periph = cam_extend_get(chperiphs, unit);
742 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("entering chioctl\n"));
744 softc = (struct ch_softc *)periph->softc;
748 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE,
749 ("trying to do ioctl %#lx\n", cmd));
752 * If this command can change the device's state, we must
753 * have the device open for writing.
762 if ((flag & FWRITE) == 0)
768 error = chmove(periph, (struct changer_move *)addr);
772 error = chexchange(periph, (struct changer_exchange *)addr);
776 error = chposition(periph, (struct changer_position *)addr);
780 *(int *)addr = softc->sc_picker - softc->sc_firsts[CHET_MT];
785 int new_picker = *(int *)addr;
787 if (new_picker > (softc->sc_counts[CHET_MT] - 1))
789 softc->sc_picker = softc->sc_firsts[CHET_MT] + new_picker;
794 struct changer_params *cp = (struct changer_params *)addr;
796 cp->cp_npickers = softc->sc_counts[CHET_MT];
797 cp->cp_nslots = softc->sc_counts[CHET_ST];
798 cp->cp_nportals = softc->sc_counts[CHET_IE];
799 cp->cp_ndrives = softc->sc_counts[CHET_DT];
803 error = chielem(periph, *(unsigned int *)addr);
808 error = chgetelemstatus(periph,
809 (struct changer_element_status_request *) addr);
815 error = chsetvoltag(periph,
816 (struct changer_set_voltag_request *) addr);
820 /* Implement prevent/allow? */
823 error = cam_periph_ioctl(periph, cmd, addr, cherror);
831 chmove(struct cam_periph *periph, struct changer_move *cm)
833 struct ch_softc *softc;
834 u_int16_t fromelem, toelem;
839 softc = (struct ch_softc *)periph->softc;
844 if ((cm->cm_fromtype > CHET_DT) || (cm->cm_totype > CHET_DT))
846 if ((cm->cm_fromunit > (softc->sc_counts[cm->cm_fromtype] - 1)) ||
847 (cm->cm_tounit > (softc->sc_counts[cm->cm_totype] - 1)))
851 * Check the request against the changer's capabilities.
853 if ((softc->sc_movemask[cm->cm_fromtype] & (1 << cm->cm_totype)) == 0)
857 * Calculate the source and destination elements.
859 fromelem = softc->sc_firsts[cm->cm_fromtype] + cm->cm_fromunit;
860 toelem = softc->sc_firsts[cm->cm_totype] + cm->cm_tounit;
862 ccb = cam_periph_getccb(periph, /*priority*/ 1);
864 scsi_move_medium(&ccb->csio,
867 /* tag_action */ MSG_SIMPLE_Q_TAG,
868 /* tea */ softc->sc_picker,
871 /* invert */ (cm->cm_flags & CM_INVERT) ? TRUE : FALSE,
872 /* sense_len */ SSD_FULL_SIZE,
873 /* timeout */ CH_TIMEOUT_MOVE_MEDIUM);
875 error = cam_periph_runccb(ccb, cherror, /*cam_flags*/0,
876 /*sense_flags*/ SF_RETRY_UA | SF_RETRY_SELTO,
877 &softc->device_stats);
879 xpt_release_ccb(ccb);
885 chexchange(struct cam_periph *periph, struct changer_exchange *ce)
887 struct ch_softc *softc;
888 u_int16_t src, dst1, dst2;
893 softc = (struct ch_softc *)periph->softc;
897 if ((ce->ce_srctype > CHET_DT) || (ce->ce_fdsttype > CHET_DT) ||
898 (ce->ce_sdsttype > CHET_DT))
900 if ((ce->ce_srcunit > (softc->sc_counts[ce->ce_srctype] - 1)) ||
901 (ce->ce_fdstunit > (softc->sc_counts[ce->ce_fdsttype] - 1)) ||
902 (ce->ce_sdstunit > (softc->sc_counts[ce->ce_sdsttype] - 1)))
906 * Check the request against the changer's capabilities.
908 if (((softc->sc_exchangemask[ce->ce_srctype] &
909 (1 << ce->ce_fdsttype)) == 0) ||
910 ((softc->sc_exchangemask[ce->ce_fdsttype] &
911 (1 << ce->ce_sdsttype)) == 0))
915 * Calculate the source and destination elements.
917 src = softc->sc_firsts[ce->ce_srctype] + ce->ce_srcunit;
918 dst1 = softc->sc_firsts[ce->ce_fdsttype] + ce->ce_fdstunit;
919 dst2 = softc->sc_firsts[ce->ce_sdsttype] + ce->ce_sdstunit;
921 ccb = cam_periph_getccb(periph, /*priority*/ 1);
923 scsi_exchange_medium(&ccb->csio,
926 /* tag_action */ MSG_SIMPLE_Q_TAG,
927 /* tea */ softc->sc_picker,
931 /* invert1 */ (ce->ce_flags & CE_INVERT1) ?
933 /* invert2 */ (ce->ce_flags & CE_INVERT2) ?
935 /* sense_len */ SSD_FULL_SIZE,
936 /* timeout */ CH_TIMEOUT_EXCHANGE_MEDIUM);
938 error = cam_periph_runccb(ccb, cherror, /*cam_flags*/0,
939 /*sense_flags*/ SF_RETRY_UA | SF_RETRY_SELTO,
940 &softc->device_stats);
942 xpt_release_ccb(ccb);
948 chposition(struct cam_periph *periph, struct changer_position *cp)
950 struct ch_softc *softc;
956 softc = (struct ch_softc *)periph->softc;
961 if (cp->cp_type > CHET_DT)
963 if (cp->cp_unit > (softc->sc_counts[cp->cp_type] - 1))
967 * Calculate the destination element.
969 dst = softc->sc_firsts[cp->cp_type] + cp->cp_unit;
971 ccb = cam_periph_getccb(periph, /*priority*/ 1);
973 scsi_position_to_element(&ccb->csio,
976 /* tag_action */ MSG_SIMPLE_Q_TAG,
977 /* tea */ softc->sc_picker,
979 /* invert */ (cp->cp_flags & CP_INVERT) ?
981 /* sense_len */ SSD_FULL_SIZE,
982 /* timeout */ CH_TIMEOUT_POSITION_TO_ELEMENT);
984 error = cam_periph_runccb(ccb, cherror, /*cam_flags*/ 0,
985 /*sense_flags*/ SF_RETRY_UA | SF_RETRY_SELTO,
986 &softc->device_stats);
988 xpt_release_ccb(ccb);
994 * Copy a volume tag to a volume_tag struct, converting SCSI byte order
995 * to host native byte order in the volume serial number. The volume
996 * label as returned by the changer is transferred to user mode as
997 * nul-terminated string. Volume labels are truncated at the first
998 * space, as suggested by SCSI-2.
1001 copy_voltag(struct changer_voltag *uvoltag, struct volume_tag *voltag)
1004 for (i=0; i<CH_VOLTAG_MAXLEN; i++) {
1005 char c = voltag->vif[i];
1007 uvoltag->cv_volid[i] = c;
1011 uvoltag->cv_serial = scsi_2btoul(voltag->vsn);
1015 * Copy an an element status descriptor to a user-mode
1016 * changer_element_status structure.
1020 copy_element_status(struct ch_softc *softc,
1022 struct read_element_status_descriptor *desc,
1023 struct changer_element_status *ces)
1025 u_int16_t eaddr = scsi_2btoul(desc->eaddr);
1028 ces->ces_int_addr = eaddr;
1029 /* set up logical address in element status */
1030 for (et = CHET_MT; et <= CHET_DT; et++) {
1031 if ((softc->sc_firsts[et] <= eaddr)
1032 && ((softc->sc_firsts[et] + softc->sc_counts[et])
1034 ces->ces_addr = eaddr - softc->sc_firsts[et];
1040 ces->ces_flags = desc->flags1;
1042 ces->ces_sensecode = desc->sense_code;
1043 ces->ces_sensequal = desc->sense_qual;
1045 if (desc->flags2 & READ_ELEMENT_STATUS_INVERT)
1046 ces->ces_flags |= CES_INVERT;
1048 if (desc->flags2 & READ_ELEMENT_STATUS_SVALID) {
1050 eaddr = scsi_2btoul(desc->ssea);
1052 /* convert source address to logical format */
1053 for (et = CHET_MT; et <= CHET_DT; et++) {
1054 if ((softc->sc_firsts[et] <= eaddr)
1055 && ((softc->sc_firsts[et] + softc->sc_counts[et])
1057 ces->ces_source_addr =
1058 eaddr - softc->sc_firsts[et];
1059 ces->ces_source_type = et;
1060 ces->ces_flags |= CES_SOURCE_VALID;
1065 if (!(ces->ces_flags & CES_SOURCE_VALID))
1066 printf("ch: warning: could not map element source "
1067 "address %ud to a valid element type\n",
1072 if (flags & READ_ELEMENT_STATUS_PVOLTAG)
1073 copy_voltag(&(ces->ces_pvoltag), &(desc->pvoltag));
1074 if (flags & READ_ELEMENT_STATUS_AVOLTAG)
1075 copy_voltag(&(ces->ces_avoltag), &(desc->avoltag));
1077 if (desc->dt_scsi_flags & READ_ELEMENT_STATUS_DT_IDVALID) {
1078 ces->ces_flags |= CES_SCSIID_VALID;
1079 ces->ces_scsi_id = desc->dt_scsi_addr;
1082 if (desc->dt_scsi_addr & READ_ELEMENT_STATUS_DT_LUVALID) {
1083 ces->ces_flags |= CES_LUN_VALID;
1085 desc->dt_scsi_flags & READ_ELEMENT_STATUS_DT_LUNMASK;
1090 chgetelemstatus(struct cam_periph *periph,
1091 struct changer_element_status_request *cesr)
1093 struct read_element_status_header *st_hdr;
1094 struct read_element_status_page_header *pg_hdr;
1095 struct read_element_status_descriptor *desc;
1096 caddr_t data = NULL;
1097 size_t size, desclen;
1098 int avail, i, error = 0;
1099 struct changer_element_status *user_data = NULL;
1100 struct ch_softc *softc;
1102 int chet = cesr->cesr_element_type;
1103 int want_voltags = (cesr->cesr_flags & CESR_VOLTAGS) ? 1 : 0;
1105 softc = (struct ch_softc *)periph->softc;
1107 /* perform argument checking */
1110 * Perform a range check on the cesr_element_{base,count}
1111 * request argument fields.
1113 if ((softc->sc_counts[chet] - cesr->cesr_element_base) <= 0
1114 || (cesr->cesr_element_base + cesr->cesr_element_count)
1115 > softc->sc_counts[chet])
1119 * Request one descriptor for the given element type. This
1120 * is used to determine the size of the descriptor so that
1121 * we can allocate enough storage for all of them. We assume
1122 * that the first one can fit into 1k.
1124 data = (caddr_t)malloc(1024, M_DEVBUF, M_WAITOK);
1126 ccb = cam_periph_getccb(periph, /*priority*/ 1);
1128 scsi_read_element_status(&ccb->csio,
1130 /* cbfcnp */ chdone,
1131 /* tag_action */ MSG_SIMPLE_Q_TAG,
1132 /* voltag */ want_voltags,
1133 /* sea */ softc->sc_firsts[chet],
1135 /* data_ptr */ data,
1136 /* dxfer_len */ 1024,
1137 /* sense_len */ SSD_FULL_SIZE,
1138 /* timeout */ CH_TIMEOUT_READ_ELEMENT_STATUS);
1140 error = cam_periph_runccb(ccb, cherror, /*cam_flags*/ 0,
1141 /*sense_flags*/ SF_RETRY_UA | SF_RETRY_SELTO,
1142 &softc->device_stats);
1147 st_hdr = (struct read_element_status_header *)data;
1148 pg_hdr = (struct read_element_status_page_header *)((uintptr_t)st_hdr +
1149 sizeof(struct read_element_status_header));
1150 desclen = scsi_2btoul(pg_hdr->edl);
1152 size = sizeof(struct read_element_status_header) +
1153 sizeof(struct read_element_status_page_header) +
1154 (desclen * cesr->cesr_element_count);
1157 * Reallocate storage for descriptors and get them from the
1160 free(data, M_DEVBUF);
1161 data = (caddr_t)malloc(size, M_DEVBUF, M_WAITOK);
1163 scsi_read_element_status(&ccb->csio,
1165 /* cbfcnp */ chdone,
1166 /* tag_action */ MSG_SIMPLE_Q_TAG,
1167 /* voltag */ want_voltags,
1168 /* sea */ softc->sc_firsts[chet]
1169 + cesr->cesr_element_base,
1170 /* count */ cesr->cesr_element_count,
1171 /* data_ptr */ data,
1172 /* dxfer_len */ size,
1173 /* sense_len */ SSD_FULL_SIZE,
1174 /* timeout */ CH_TIMEOUT_READ_ELEMENT_STATUS);
1176 error = cam_periph_runccb(ccb, cherror, /*cam_flags*/ 0,
1177 /*sense_flags*/ SF_RETRY_UA | SF_RETRY_SELTO,
1178 &softc->device_stats);
1184 * Fill in the user status array.
1186 st_hdr = (struct read_element_status_header *)data;
1187 avail = scsi_2btoul(st_hdr->count);
1189 if (avail != cesr->cesr_element_count) {
1190 xpt_print_path(periph->path);
1191 printf("warning, READ ELEMENT STATUS avail != count\n");
1194 user_data = (struct changer_element_status *)
1195 malloc(avail * sizeof(struct changer_element_status),
1196 M_DEVBUF, M_WAITOK | M_ZERO);
1198 desc = (struct read_element_status_descriptor *)((uintptr_t)data +
1199 sizeof(struct read_element_status_header) +
1200 sizeof(struct read_element_status_page_header));
1202 * Set up the individual element status structures
1204 for (i = 0; i < avail; ++i) {
1205 struct changer_element_status *ces = &(user_data[i]);
1207 copy_element_status(softc, pg_hdr->flags, desc, ces);
1209 desc = (struct read_element_status_descriptor *)
1210 ((uintptr_t)desc + desclen);
1213 /* Copy element status structures out to userspace. */
1214 error = copyout(user_data,
1215 cesr->cesr_element_status,
1216 avail * sizeof(struct changer_element_status));
1219 xpt_release_ccb(ccb);
1222 free(data, M_DEVBUF);
1223 if (user_data != NULL)
1224 free(user_data, M_DEVBUF);
1230 chielem(struct cam_periph *periph,
1231 unsigned int timeout)
1234 struct ch_softc *softc;
1238 timeout = CH_TIMEOUT_INITIALIZE_ELEMENT_STATUS;
1244 softc = (struct ch_softc *)periph->softc;
1246 ccb = cam_periph_getccb(periph, /*priority*/ 1);
1248 scsi_initialize_element_status(&ccb->csio,
1250 /* cbfcnp */ chdone,
1251 /* tag_action */ MSG_SIMPLE_Q_TAG,
1252 /* sense_len */ SSD_FULL_SIZE,
1253 /* timeout */ timeout);
1255 error = cam_periph_runccb(ccb, cherror, /*cam_flags*/ 0,
1256 /*sense_flags*/ SF_RETRY_UA | SF_RETRY_SELTO,
1257 &softc->device_stats);
1259 xpt_release_ccb(ccb);
1265 chsetvoltag(struct cam_periph *periph,
1266 struct changer_set_voltag_request *csvr)
1269 struct ch_softc *softc;
1272 struct scsi_send_volume_tag_parameters ssvtp;
1277 softc = (struct ch_softc *)periph->softc;
1279 bzero(&ssvtp, sizeof(ssvtp));
1280 for (i=0; i<sizeof(ssvtp.vitf); i++) {
1281 ssvtp.vitf[i] = ' ';
1287 if (csvr->csvr_type > CHET_DT)
1289 if (csvr->csvr_addr > (softc->sc_counts[csvr->csvr_type] - 1))
1292 ea = softc->sc_firsts[csvr->csvr_type] + csvr->csvr_addr;
1294 if (csvr->csvr_flags & CSVR_ALTERNATE) {
1295 switch (csvr->csvr_flags & CSVR_MODE_MASK) {
1297 sac = SEND_VOLUME_TAG_ASSERT_ALTERNATE;
1299 case CSVR_MODE_REPLACE:
1300 sac = SEND_VOLUME_TAG_REPLACE_ALTERNATE;
1302 case CSVR_MODE_CLEAR:
1303 sac = SEND_VOLUME_TAG_UNDEFINED_ALTERNATE;
1310 switch (csvr->csvr_flags & CSVR_MODE_MASK) {
1312 sac = SEND_VOLUME_TAG_ASSERT_PRIMARY;
1314 case CSVR_MODE_REPLACE:
1315 sac = SEND_VOLUME_TAG_REPLACE_PRIMARY;
1317 case CSVR_MODE_CLEAR:
1318 sac = SEND_VOLUME_TAG_UNDEFINED_PRIMARY;
1326 memcpy(ssvtp.vitf, csvr->csvr_voltag.cv_volid,
1327 min(strlen(csvr->csvr_voltag.cv_volid), sizeof(ssvtp.vitf)));
1328 scsi_ulto2b(csvr->csvr_voltag.cv_serial, ssvtp.minvsn);
1330 ccb = cam_periph_getccb(periph, /*priority*/ 1);
1332 scsi_send_volume_tag(&ccb->csio,
1334 /* cbfcnp */ chdone,
1335 /* tag_action */ MSG_SIMPLE_Q_TAG,
1336 /* element_address */ ea,
1337 /* send_action_code */ sac,
1338 /* parameters */ &ssvtp,
1339 /* sense_len */ SSD_FULL_SIZE,
1340 /* timeout */ CH_TIMEOUT_SEND_VOLTAG);
1342 error = cam_periph_runccb(ccb, cherror, /*cam_flags*/ 0,
1343 /*sense_flags*/ SF_RETRY_UA | SF_RETRY_SELTO,
1344 &softc->device_stats);
1346 xpt_release_ccb(ccb);
1353 chgetparams(struct cam_periph *periph)
1356 struct ch_softc *softc;
1358 int mode_buffer_len;
1359 struct page_element_address_assignment *ea;
1360 struct page_device_capabilities *cap;
1361 int error, from, dbd;
1362 u_int8_t *moves, *exchanges;
1366 softc = (struct ch_softc *)periph->softc;
1368 ccb = cam_periph_getccb(periph, /*priority*/ 1);
1371 * The scsi_mode_sense_data structure is just a convenience
1372 * structure that allows us to easily calculate the worst-case
1373 * storage size of the mode sense buffer.
1375 mode_buffer_len = sizeof(struct scsi_mode_sense_data);
1377 mode_buffer = malloc(mode_buffer_len, M_TEMP, M_NOWAIT);
1379 if (mode_buffer == NULL) {
1380 printf("chgetparams: couldn't malloc mode sense data\n");
1384 bzero(mode_buffer, mode_buffer_len);
1386 if (softc->quirks & CH_Q_NO_DBD)
1392 * Get the element address assignment page.
1394 scsi_mode_sense(&ccb->csio,
1396 /* cbfcnp */ chdone,
1397 /* tag_action */ MSG_SIMPLE_Q_TAG,
1399 /* page_code */ SMS_PAGE_CTRL_CURRENT,
1400 /* page */ CH_ELEMENT_ADDR_ASSIGN_PAGE,
1401 /* param_buf */ (u_int8_t *)mode_buffer,
1402 /* param_len */ mode_buffer_len,
1403 /* sense_len */ SSD_FULL_SIZE,
1404 /* timeout */ CH_TIMEOUT_MODE_SENSE);
1406 error = cam_periph_runccb(ccb, cherror, /*cam_flags*/ 0,
1407 /* sense_flags */ SF_RETRY_UA |
1408 SF_NO_PRINT | SF_RETRY_SELTO,
1409 &softc->device_stats);
1413 struct scsi_mode_sense_6 *sms;
1415 sms = (struct scsi_mode_sense_6 *)
1416 ccb->csio.cdb_io.cdb_bytes;
1418 sms->byte2 &= ~SMS_DBD;
1419 error = cam_periph_runccb(ccb, cherror, /*cam_flags*/ 0,
1420 /*sense_flags*/ SF_RETRY_UA |
1422 &softc->device_stats);
1425 * Since we disabled sense printing above, print
1426 * out the sense here since we got an error.
1428 scsi_sense_print(&ccb->csio);
1432 xpt_print_path(periph->path);
1433 printf("chgetparams: error getting element "
1435 xpt_release_ccb(ccb);
1436 free(mode_buffer, M_TEMP);
1441 ea = (struct page_element_address_assignment *)
1442 find_mode_page_6((struct scsi_mode_header_6 *)mode_buffer);
1444 softc->sc_firsts[CHET_MT] = scsi_2btoul(ea->mtea);
1445 softc->sc_counts[CHET_MT] = scsi_2btoul(ea->nmte);
1446 softc->sc_firsts[CHET_ST] = scsi_2btoul(ea->fsea);
1447 softc->sc_counts[CHET_ST] = scsi_2btoul(ea->nse);
1448 softc->sc_firsts[CHET_IE] = scsi_2btoul(ea->fieea);
1449 softc->sc_counts[CHET_IE] = scsi_2btoul(ea->niee);
1450 softc->sc_firsts[CHET_DT] = scsi_2btoul(ea->fdtea);
1451 softc->sc_counts[CHET_DT] = scsi_2btoul(ea->ndte);
1453 bzero(mode_buffer, mode_buffer_len);
1456 * Now get the device capabilities page.
1458 scsi_mode_sense(&ccb->csio,
1460 /* cbfcnp */ chdone,
1461 /* tag_action */ MSG_SIMPLE_Q_TAG,
1463 /* page_code */ SMS_PAGE_CTRL_CURRENT,
1464 /* page */ CH_DEVICE_CAP_PAGE,
1465 /* param_buf */ (u_int8_t *)mode_buffer,
1466 /* param_len */ mode_buffer_len,
1467 /* sense_len */ SSD_FULL_SIZE,
1468 /* timeout */ CH_TIMEOUT_MODE_SENSE);
1470 error = cam_periph_runccb(ccb, cherror, /*cam_flags*/ 0,
1471 /* sense_flags */ SF_RETRY_UA | SF_NO_PRINT |
1472 SF_RETRY_SELTO, &softc->device_stats);
1476 struct scsi_mode_sense_6 *sms;
1478 sms = (struct scsi_mode_sense_6 *)
1479 ccb->csio.cdb_io.cdb_bytes;
1481 sms->byte2 &= ~SMS_DBD;
1482 error = cam_periph_runccb(ccb, cherror, /*cam_flags*/ 0,
1483 /*sense_flags*/ SF_RETRY_UA |
1485 &softc->device_stats);
1488 * Since we disabled sense printing above, print
1489 * out the sense here since we got an error.
1491 scsi_sense_print(&ccb->csio);
1495 xpt_print_path(periph->path);
1496 printf("chgetparams: error getting device "
1497 "capabilities page\n");
1498 xpt_release_ccb(ccb);
1499 free(mode_buffer, M_TEMP);
1504 xpt_release_ccb(ccb);
1506 cap = (struct page_device_capabilities *)
1507 find_mode_page_6((struct scsi_mode_header_6 *)mode_buffer);
1509 bzero(softc->sc_movemask, sizeof(softc->sc_movemask));
1510 bzero(softc->sc_exchangemask, sizeof(softc->sc_exchangemask));
1511 moves = &cap->move_from_mt;
1512 exchanges = &cap->exchange_with_mt;
1513 for (from = CHET_MT; from <= CHET_DT; ++from) {
1514 softc->sc_movemask[from] = moves[from];
1515 softc->sc_exchangemask[from] = exchanges[from];
1518 free(mode_buffer, M_TEMP);
1524 scsi_move_medium(struct ccb_scsiio *csio, u_int32_t retries,
1525 void (*cbfcnp)(struct cam_periph *, union ccb *),
1526 u_int8_t tag_action, u_int32_t tea, u_int32_t src,
1527 u_int32_t dst, int invert, u_int8_t sense_len,
1530 struct scsi_move_medium *scsi_cmd;
1532 scsi_cmd = (struct scsi_move_medium *)&csio->cdb_io.cdb_bytes;
1533 bzero(scsi_cmd, sizeof(*scsi_cmd));
1535 scsi_cmd->opcode = MOVE_MEDIUM;
1537 scsi_ulto2b(tea, scsi_cmd->tea);
1538 scsi_ulto2b(src, scsi_cmd->src);
1539 scsi_ulto2b(dst, scsi_cmd->dst);
1542 scsi_cmd->invert |= MOVE_MEDIUM_INVERT;
1547 /*flags*/ CAM_DIR_NONE,
1557 scsi_exchange_medium(struct ccb_scsiio *csio, u_int32_t retries,
1558 void (*cbfcnp)(struct cam_periph *, union ccb *),
1559 u_int8_t tag_action, u_int32_t tea, u_int32_t src,
1560 u_int32_t dst1, u_int32_t dst2, int invert1,
1561 int invert2, u_int8_t sense_len, u_int32_t timeout)
1563 struct scsi_exchange_medium *scsi_cmd;
1565 scsi_cmd = (struct scsi_exchange_medium *)&csio->cdb_io.cdb_bytes;
1566 bzero(scsi_cmd, sizeof(*scsi_cmd));
1568 scsi_cmd->opcode = EXCHANGE_MEDIUM;
1570 scsi_ulto2b(tea, scsi_cmd->tea);
1571 scsi_ulto2b(src, scsi_cmd->src);
1572 scsi_ulto2b(dst1, scsi_cmd->fdst);
1573 scsi_ulto2b(dst2, scsi_cmd->sdst);
1576 scsi_cmd->invert |= EXCHANGE_MEDIUM_INV1;
1579 scsi_cmd->invert |= EXCHANGE_MEDIUM_INV2;
1584 /*flags*/ CAM_DIR_NONE,
1594 scsi_position_to_element(struct ccb_scsiio *csio, u_int32_t retries,
1595 void (*cbfcnp)(struct cam_periph *, union ccb *),
1596 u_int8_t tag_action, u_int32_t tea, u_int32_t dst,
1597 int invert, u_int8_t sense_len, u_int32_t timeout)
1599 struct scsi_position_to_element *scsi_cmd;
1601 scsi_cmd = (struct scsi_position_to_element *)&csio->cdb_io.cdb_bytes;
1602 bzero(scsi_cmd, sizeof(*scsi_cmd));
1604 scsi_cmd->opcode = POSITION_TO_ELEMENT;
1606 scsi_ulto2b(tea, scsi_cmd->tea);
1607 scsi_ulto2b(dst, scsi_cmd->dst);
1610 scsi_cmd->invert |= POSITION_TO_ELEMENT_INVERT;
1615 /*flags*/ CAM_DIR_NONE,
1625 scsi_read_element_status(struct ccb_scsiio *csio, u_int32_t retries,
1626 void (*cbfcnp)(struct cam_periph *, union ccb *),
1627 u_int8_t tag_action, int voltag, u_int32_t sea,
1628 u_int32_t count, u_int8_t *data_ptr,
1629 u_int32_t dxfer_len, u_int8_t sense_len,
1632 struct scsi_read_element_status *scsi_cmd;
1634 scsi_cmd = (struct scsi_read_element_status *)&csio->cdb_io.cdb_bytes;
1635 bzero(scsi_cmd, sizeof(*scsi_cmd));
1637 scsi_cmd->opcode = READ_ELEMENT_STATUS;
1639 scsi_ulto2b(sea, scsi_cmd->sea);
1640 scsi_ulto2b(count, scsi_cmd->count);
1641 scsi_ulto3b(dxfer_len, scsi_cmd->len);
1644 scsi_cmd->byte2 |= READ_ELEMENT_STATUS_VOLTAG;
1649 /*flags*/ CAM_DIR_IN,
1659 scsi_initialize_element_status(struct ccb_scsiio *csio, u_int32_t retries,
1660 void (*cbfcnp)(struct cam_periph *, union ccb *),
1661 u_int8_t tag_action, u_int8_t sense_len,
1664 struct scsi_initialize_element_status *scsi_cmd;
1666 scsi_cmd = (struct scsi_initialize_element_status *)
1667 &csio->cdb_io.cdb_bytes;
1668 bzero(scsi_cmd, sizeof(*scsi_cmd));
1670 scsi_cmd->opcode = INITIALIZE_ELEMENT_STATUS;
1675 /*flags*/ CAM_DIR_NONE,
1677 /* data_ptr */ NULL,
1685 scsi_send_volume_tag(struct ccb_scsiio *csio, u_int32_t retries,
1686 void (*cbfcnp)(struct cam_periph *, union ccb *),
1687 u_int8_t tag_action,
1688 u_int16_t element_address,
1689 u_int8_t send_action_code,
1690 struct scsi_send_volume_tag_parameters *parameters,
1691 u_int8_t sense_len, u_int32_t timeout)
1693 struct scsi_send_volume_tag *scsi_cmd;
1695 scsi_cmd = (struct scsi_send_volume_tag *) &csio->cdb_io.cdb_bytes;
1696 bzero(scsi_cmd, sizeof(*scsi_cmd));
1698 scsi_cmd->opcode = SEND_VOLUME_TAG;
1699 scsi_ulto2b(element_address, scsi_cmd->ea);
1700 scsi_cmd->sac = send_action_code;
1701 scsi_ulto2b(sizeof(*parameters), scsi_cmd->pll);
1706 /*flags*/ CAM_DIR_OUT,
1708 /* data_ptr */ (u_int8_t *) parameters,
1709 sizeof(*parameters),