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 $
28 * $DragonFly: src/sys/bus/cam/scsi/scsi_ch.c,v 1.2 2003/06/17 04:28:19 dillon Exp $
31 * Derived from the NetBSD SCSI changer driver.
33 * $NetBSD: ch.c,v 1.32 1998/01/12 09:49:12 thorpej Exp $
37 * Copyright (c) 1996, 1997 Jason R. Thorpe <thorpej@and.com>
38 * All rights reserved.
40 * Partially based on an autochanger driver written by Stefan Grefen
41 * and on an autochanger driver written by the Systems Programming Group
42 * at the University of Utah Computer Science Department.
44 * Redistribution and use in source and binary forms, with or without
45 * modification, are permitted provided that the following conditions
47 * 1. Redistributions of source code must retain the above copyright
48 * notice, this list of conditions and the following disclaimer.
49 * 2. Redistributions in binary form must reproduce the above copyright
50 * notice, this list of conditions and the following disclaimer in the
51 * documentation and/or other materials provided with the distribution.
52 * 3. All advertising materials mentioning features or use of this software
53 * must display the following acknowledgements:
54 * This product includes software developed by Jason R. Thorpe
55 * for And Communications, http://www.and.com/
56 * 4. The name of the author may not be used to endorse or promote products
57 * derived from this software without specific prior written permission.
59 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
60 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
61 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
62 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
63 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
64 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
65 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
66 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
67 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
68 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
72 #include <sys/param.h>
73 #include <sys/queue.h>
74 #include <sys/systm.h>
75 #include <sys/kernel.h>
76 #include <sys/types.h>
77 #include <sys/malloc.h>
78 #include <sys/fcntl.h>
83 #include <sys/errno.h>
84 #include <sys/devicestat.h>
87 #include <cam/cam_ccb.h>
88 #include <cam/cam_extend.h>
89 #include <cam/cam_periph.h>
90 #include <cam/cam_xpt_periph.h>
91 #include <cam/cam_queue.h>
92 #include <cam/cam_debug.h>
94 #include <cam/scsi/scsi_all.h>
95 #include <cam/scsi/scsi_message.h>
96 #include <cam/scsi/scsi_ch.h>
99 * Timeout definitions for various changer related commands. They may
100 * be too short for some devices (especially the timeout for INITIALIZE
104 static const u_int32_t CH_TIMEOUT_MODE_SENSE = 6000;
105 static const u_int32_t CH_TIMEOUT_MOVE_MEDIUM = 100000;
106 static const u_int32_t CH_TIMEOUT_EXCHANGE_MEDIUM = 100000;
107 static const u_int32_t CH_TIMEOUT_POSITION_TO_ELEMENT = 100000;
108 static const u_int32_t CH_TIMEOUT_READ_ELEMENT_STATUS = 10000;
109 static const u_int32_t CH_TIMEOUT_SEND_VOLTAG = 10000;
110 static const u_int32_t CH_TIMEOUT_INITIALIZE_ELEMENT_STATUS = 500000;
113 CH_FLAG_INVALID = 0x001,
132 #define ccb_state ppriv_field0
133 #define ccb_bp ppriv_ptr1
135 struct scsi_mode_sense_data {
136 struct scsi_mode_header_6 header;
137 struct scsi_mode_blk_desc blk_desc;
139 struct page_element_address_assignment ea;
140 struct page_transport_geometry_parameters tg;
141 struct page_device_capabilities cap;
150 struct devstat device_stats;
153 int sc_picker; /* current picker */
156 * The following information is obtained from the
157 * element address assignment page.
159 int sc_firsts[4]; /* firsts, indexed by CHET_* */
160 int sc_counts[4]; /* counts, indexed by CHET_* */
163 * The following mask defines the legal combinations
164 * of elements for the MOVE MEDIUM command.
166 u_int8_t sc_movemask[4];
169 * As above, but for EXCHANGE MEDIUM.
171 u_int8_t sc_exchangemask[4];
174 * Quirks; see below. XXX KDM not implemented yet
176 int sc_settledelay; /* delay for settle */
179 #define CHUNIT(x) (minor((x)))
180 #define CH_CDEV_MAJOR 17
182 static d_open_t chopen;
183 static d_close_t chclose;
184 static d_ioctl_t chioctl;
185 static periph_init_t chinit;
186 static periph_ctor_t chregister;
187 static periph_oninv_t choninvalidate;
188 static periph_dtor_t chcleanup;
189 static periph_start_t chstart;
190 static void chasync(void *callback_arg, u_int32_t code,
191 struct cam_path *path, void *arg);
192 static void chdone(struct cam_periph *periph,
193 union ccb *done_ccb);
194 static int cherror(union ccb *ccb, u_int32_t cam_flags,
195 u_int32_t sense_flags);
196 static int chmove(struct cam_periph *periph,
197 struct changer_move *cm);
198 static int chexchange(struct cam_periph *periph,
199 struct changer_exchange *ce);
200 static int chposition(struct cam_periph *periph,
201 struct changer_position *cp);
202 static int chgetelemstatus(struct cam_periph *periph,
203 struct changer_element_status_request *csr);
204 static int chsetvoltag(struct cam_periph *periph,
205 struct changer_set_voltag_request *csvr);
206 static int chielem(struct cam_periph *periph,
207 unsigned int timeout);
208 static int chgetparams(struct cam_periph *periph);
210 static struct periph_driver chdriver =
213 TAILQ_HEAD_INITIALIZER(chdriver.units), /* generation */ 0
216 DATA_SET(periphdriver_set, chdriver);
218 static struct cdevsw ch_cdevsw = {
226 /* strategy */ nostrategy,
228 /* maj */ CH_CDEV_MAJOR,
235 static struct extend_array *chperiphs;
241 struct cam_path *path;
244 * Create our extend array for storing the devices we attach to.
246 chperiphs = cam_extend_new();
247 if (chperiphs == NULL) {
248 printf("ch: Failed to alloc extend array!\n");
253 * Install a global async callback. This callback will
254 * receive async callbacks like "new device found".
256 status = xpt_create_path(&path, /*periph*/NULL, CAM_XPT_PATH_ID,
257 CAM_TARGET_WILDCARD, CAM_LUN_WILDCARD);
259 if (status == CAM_REQ_CMP) {
260 struct ccb_setasync csa;
262 xpt_setup_ccb(&csa.ccb_h, path, /*priority*/5);
263 csa.ccb_h.func_code = XPT_SASYNC_CB;
264 csa.event_enable = AC_FOUND_DEVICE;
265 csa.callback = chasync;
266 csa.callback_arg = NULL;
267 xpt_action((union ccb *)&csa);
268 status = csa.ccb_h.status;
272 if (status != CAM_REQ_CMP) {
273 printf("ch: Failed to attach master async callback "
274 "due to status 0x%x!\n", status);
279 choninvalidate(struct cam_periph *periph)
281 struct ch_softc *softc;
282 struct ccb_setasync csa;
284 softc = (struct ch_softc *)periph->softc;
287 * De-register any async callbacks.
289 xpt_setup_ccb(&csa.ccb_h, periph->path,
291 csa.ccb_h.func_code = XPT_SASYNC_CB;
292 csa.event_enable = 0;
293 csa.callback = chasync;
294 csa.callback_arg = periph;
295 xpt_action((union ccb *)&csa);
297 softc->flags |= CH_FLAG_INVALID;
299 xpt_print_path(periph->path);
300 printf("lost device\n");
305 chcleanup(struct cam_periph *periph)
307 struct ch_softc *softc;
309 softc = (struct ch_softc *)periph->softc;
311 devstat_remove_entry(&softc->device_stats);
312 destroy_dev(softc->dev);
313 cam_extend_release(chperiphs, periph->unit_number);
314 xpt_print_path(periph->path);
315 printf("removing device entry\n");
316 free(softc, M_DEVBUF);
320 chasync(void *callback_arg, u_int32_t code, struct cam_path *path, void *arg)
322 struct cam_periph *periph;
324 periph = (struct cam_periph *)callback_arg;
327 case AC_FOUND_DEVICE:
329 struct ccb_getdev *cgd;
332 cgd = (struct ccb_getdev *)arg;
334 if (SID_TYPE(&cgd->inq_data)!= T_CHANGER)
338 * Allocate a peripheral instance for
339 * this device and start the probe
342 status = cam_periph_alloc(chregister, choninvalidate,
343 chcleanup, chstart, "ch",
344 CAM_PERIPH_BIO, cgd->ccb_h.path,
345 chasync, AC_FOUND_DEVICE, cgd);
347 if (status != CAM_REQ_CMP
348 && status != CAM_REQ_INPROG)
349 printf("chasync: Unable to probe new device "
350 "due to status 0x%x\n", status);
356 cam_periph_async(periph, code, path, arg);
362 chregister(struct cam_periph *periph, void *arg)
364 struct ch_softc *softc;
365 struct ccb_setasync csa;
366 struct ccb_getdev *cgd;
368 cgd = (struct ccb_getdev *)arg;
369 if (periph == NULL) {
370 printf("chregister: periph was NULL!!\n");
371 return(CAM_REQ_CMP_ERR);
375 printf("chregister: no getdev CCB, can't register device\n");
376 return(CAM_REQ_CMP_ERR);
379 softc = (struct ch_softc *)malloc(sizeof(*softc),M_DEVBUF,M_NOWAIT);
382 printf("chregister: Unable to probe new device. "
383 "Unable to allocate softc\n");
384 return(CAM_REQ_CMP_ERR);
387 bzero(softc, sizeof(*softc));
388 softc->state = CH_STATE_PROBE;
389 periph->softc = softc;
390 cam_extend_set(chperiphs, periph->unit_number, periph);
391 softc->quirks = CH_Q_NONE;
394 * Changers don't have a blocksize, and obviously don't support
397 devstat_add_entry(&softc->device_stats, "ch",
398 periph->unit_number, 0,
399 DEVSTAT_NO_BLOCKSIZE | DEVSTAT_NO_ORDERED_TAGS,
400 SID_TYPE(&cgd->inq_data)| DEVSTAT_TYPE_IF_SCSI,
401 DEVSTAT_PRIORITY_OTHER);
403 /* Register the device */
404 softc->dev = make_dev(&ch_cdevsw, periph->unit_number, UID_ROOT,
405 GID_OPERATOR, 0600, "%s%d", periph->periph_name,
406 periph->unit_number);
409 * Add an async callback so that we get
410 * notified if this device goes away.
412 xpt_setup_ccb(&csa.ccb_h, periph->path, /* priority */ 5);
413 csa.ccb_h.func_code = XPT_SASYNC_CB;
414 csa.event_enable = AC_LOST_DEVICE;
415 csa.callback = chasync;
416 csa.callback_arg = periph;
417 xpt_action((union ccb *)&csa);
420 * Lock this peripheral until we are setup.
421 * This first call can't block
423 (void)cam_periph_lock(periph, PRIBIO);
424 xpt_schedule(periph, /*priority*/5);
430 chopen(dev_t dev, int flags, int fmt, struct proc *p)
432 struct cam_periph *periph;
433 struct ch_softc *softc;
438 periph = cam_extend_get(chperiphs, unit);
443 softc = (struct ch_softc *)periph->softc;
446 if (softc->flags & CH_FLAG_INVALID) {
451 if ((error = cam_periph_lock(periph, PRIBIO | PCATCH)) != 0) {
458 if ((softc->flags & CH_FLAG_OPEN) == 0) {
459 if (cam_periph_acquire(periph) != CAM_REQ_CMP)
461 softc->flags |= CH_FLAG_OPEN;
465 * Load information about this changer device into the softc.
467 if ((error = chgetparams(periph)) != 0) {
468 softc->flags &= ~CH_FLAG_OPEN;
469 cam_periph_unlock(periph);
470 cam_periph_release(periph);
474 cam_periph_unlock(periph);
480 chclose(dev_t dev, int flag, int fmt, struct proc *p)
482 struct cam_periph *periph;
483 struct ch_softc *softc;
489 periph = cam_extend_get(chperiphs, unit);
493 softc = (struct ch_softc *)periph->softc;
495 if ((error = cam_periph_lock(periph, PRIBIO)) != 0)
498 softc->flags &= ~CH_FLAG_OPEN;
500 cam_periph_unlock(periph);
501 cam_periph_release(periph);
507 chstart(struct cam_periph *periph, union ccb *start_ccb)
509 struct ch_softc *softc;
512 softc = (struct ch_softc *)periph->softc;
514 switch (softc->state) {
515 case CH_STATE_NORMAL:
518 if (periph->immediate_priority <= periph->pinfo.priority){
519 start_ccb->ccb_h.ccb_state = CH_CCB_WAITING;
521 SLIST_INSERT_HEAD(&periph->ccb_list, &start_ccb->ccb_h,
523 periph->immediate_priority = CAM_PRIORITY_NONE;
525 wakeup(&periph->ccb_list);
536 * Include the block descriptor when calculating the mode
539 mode_buffer_len = sizeof(struct scsi_mode_header_6) +
540 sizeof(struct scsi_mode_blk_desc) +
541 sizeof(struct page_element_address_assignment);
543 mode_buffer = malloc(mode_buffer_len, M_TEMP, M_NOWAIT);
545 if (mode_buffer == NULL) {
546 printf("chstart: couldn't malloc mode sense data\n");
549 bzero(mode_buffer, mode_buffer_len);
552 * Get the element address assignment page.
554 scsi_mode_sense(&start_ccb->csio,
557 /* tag_action */ MSG_SIMPLE_Q_TAG,
558 /* dbd */ (softc->quirks & CH_Q_NO_DBD) ?
560 /* page_code */ SMS_PAGE_CTRL_CURRENT,
561 /* page */ CH_ELEMENT_ADDR_ASSIGN_PAGE,
562 /* param_buf */ (u_int8_t *)mode_buffer,
563 /* param_len */ mode_buffer_len,
564 /* sense_len */ SSD_FULL_SIZE,
565 /* timeout */ CH_TIMEOUT_MODE_SENSE);
567 start_ccb->ccb_h.ccb_bp = NULL;
568 start_ccb->ccb_h.ccb_state = CH_CCB_PROBE;
569 xpt_action(start_ccb);
576 chdone(struct cam_periph *periph, union ccb *done_ccb)
578 struct ch_softc *softc;
579 struct ccb_scsiio *csio;
581 softc = (struct ch_softc *)periph->softc;
582 csio = &done_ccb->csio;
584 switch(done_ccb->ccb_h.ccb_state) {
587 struct scsi_mode_header_6 *mode_header;
588 struct page_element_address_assignment *ea;
589 char announce_buf[80];
592 mode_header = (struct scsi_mode_header_6 *)csio->data_ptr;
594 ea = (struct page_element_address_assignment *)
595 find_mode_page_6(mode_header);
597 if ((done_ccb->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP){
599 softc->sc_firsts[CHET_MT] = scsi_2btoul(ea->mtea);
600 softc->sc_counts[CHET_MT] = scsi_2btoul(ea->nmte);
601 softc->sc_firsts[CHET_ST] = scsi_2btoul(ea->fsea);
602 softc->sc_counts[CHET_ST] = scsi_2btoul(ea->nse);
603 softc->sc_firsts[CHET_IE] = scsi_2btoul(ea->fieea);
604 softc->sc_counts[CHET_IE] = scsi_2btoul(ea->niee);
605 softc->sc_firsts[CHET_DT] = scsi_2btoul(ea->fdtea);
606 softc->sc_counts[CHET_DT] = scsi_2btoul(ea->ndte);
607 softc->sc_picker = softc->sc_firsts[CHET_MT];
609 #define PLURAL(c) (c) == 1 ? "" : "s"
610 snprintf(announce_buf, sizeof(announce_buf),
611 "%d slot%s, %d drive%s, "
612 "%d picker%s, %d portal%s",
613 softc->sc_counts[CHET_ST],
614 PLURAL(softc->sc_counts[CHET_ST]),
615 softc->sc_counts[CHET_DT],
616 PLURAL(softc->sc_counts[CHET_DT]),
617 softc->sc_counts[CHET_MT],
618 PLURAL(softc->sc_counts[CHET_MT]),
619 softc->sc_counts[CHET_IE],
620 PLURAL(softc->sc_counts[CHET_IE]));
625 error = cherror(done_ccb, 0, SF_RETRY_UA |
626 SF_NO_PRINT | SF_RETRY_SELTO);
628 * Retry any UNIT ATTENTION type errors. They
629 * are expected at boot.
631 if (error == ERESTART) {
633 * A retry was scheuled, so
637 } else if (error != 0) {
639 struct scsi_mode_sense_6 *sms;
641 sms = (struct scsi_mode_sense_6 *)
642 done_ccb->csio.cdb_io.cdb_bytes;
645 * Check to see if block descriptors were
646 * disabled. Some devices don't like that.
647 * We're taking advantage of the fact that
648 * the first few bytes of the 6 and 10 byte
649 * mode sense commands are the same. If
650 * block descriptors were disabled, enable
651 * them and re-send the command.
653 if (sms->byte2 & SMS_DBD) {
654 sms->byte2 &= ~SMS_DBD;
655 xpt_action(done_ccb);
656 softc->quirks |= CH_Q_NO_DBD;
661 /* Don't wedge this device's queue */
662 cam_release_devq(done_ccb->ccb_h.path,
671 if ((done_ccb->ccb_h.status & CAM_STATUS_MASK)
672 == CAM_SCSI_STATUS_ERROR)
673 scsi_sense_print(&done_ccb->csio);
675 xpt_print_path(periph->path);
676 printf("got CAM status %#x\n",
677 done_ccb->ccb_h.status);
679 xpt_print_path(periph->path);
680 printf("fatal error, failed to attach to"
683 cam_periph_invalidate(periph);
685 announce_buf[0] = '\0';
688 if (announce_buf[0] != '\0')
689 xpt_announce_periph(periph, announce_buf);
690 softc->state = CH_STATE_NORMAL;
691 free(mode_header, M_TEMP);
693 * Since our peripheral may be invalidated by an error
694 * above or an external event, we must release our CCB
695 * before releasing the probe lock on the peripheral.
696 * The peripheral will only go away once the last lock
697 * is removed, and we need it around for the CCB release
700 xpt_release_ccb(done_ccb);
701 cam_periph_unlock(periph);
706 /* Caller will release the CCB */
707 wakeup(&done_ccb->ccb_h.cbfcnp);
713 xpt_release_ccb(done_ccb);
717 cherror(union ccb *ccb, u_int32_t cam_flags, u_int32_t sense_flags)
719 struct ch_softc *softc;
720 struct cam_periph *periph;
722 periph = xpt_path_periph(ccb->ccb_h.path);
723 softc = (struct ch_softc *)periph->softc;
725 return (cam_periph_error(ccb, cam_flags, sense_flags,
730 chioctl(dev_t dev, u_long cmd, caddr_t addr, int flag, struct proc *p)
732 struct cam_periph *periph;
733 struct ch_softc *softc;
739 periph = cam_extend_get(chperiphs, unit);
743 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("entering chioctl\n"));
745 softc = (struct ch_softc *)periph->softc;
749 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE,
750 ("trying to do ioctl %#lx\n", cmd));
753 * If this command can change the device's state, we must
754 * have the device open for writing.
763 if ((flag & FWRITE) == 0)
769 error = chmove(periph, (struct changer_move *)addr);
773 error = chexchange(periph, (struct changer_exchange *)addr);
777 error = chposition(periph, (struct changer_position *)addr);
781 *(int *)addr = softc->sc_picker - softc->sc_firsts[CHET_MT];
786 int new_picker = *(int *)addr;
788 if (new_picker > (softc->sc_counts[CHET_MT] - 1))
790 softc->sc_picker = softc->sc_firsts[CHET_MT] + new_picker;
795 struct changer_params *cp = (struct changer_params *)addr;
797 cp->cp_npickers = softc->sc_counts[CHET_MT];
798 cp->cp_nslots = softc->sc_counts[CHET_ST];
799 cp->cp_nportals = softc->sc_counts[CHET_IE];
800 cp->cp_ndrives = softc->sc_counts[CHET_DT];
804 error = chielem(periph, *(unsigned int *)addr);
809 error = chgetelemstatus(periph,
810 (struct changer_element_status_request *) addr);
816 error = chsetvoltag(periph,
817 (struct changer_set_voltag_request *) addr);
821 /* Implement prevent/allow? */
824 error = cam_periph_ioctl(periph, cmd, addr, cherror);
832 chmove(struct cam_periph *periph, struct changer_move *cm)
834 struct ch_softc *softc;
835 u_int16_t fromelem, toelem;
840 softc = (struct ch_softc *)periph->softc;
845 if ((cm->cm_fromtype > CHET_DT) || (cm->cm_totype > CHET_DT))
847 if ((cm->cm_fromunit > (softc->sc_counts[cm->cm_fromtype] - 1)) ||
848 (cm->cm_tounit > (softc->sc_counts[cm->cm_totype] - 1)))
852 * Check the request against the changer's capabilities.
854 if ((softc->sc_movemask[cm->cm_fromtype] & (1 << cm->cm_totype)) == 0)
858 * Calculate the source and destination elements.
860 fromelem = softc->sc_firsts[cm->cm_fromtype] + cm->cm_fromunit;
861 toelem = softc->sc_firsts[cm->cm_totype] + cm->cm_tounit;
863 ccb = cam_periph_getccb(periph, /*priority*/ 1);
865 scsi_move_medium(&ccb->csio,
868 /* tag_action */ MSG_SIMPLE_Q_TAG,
869 /* tea */ softc->sc_picker,
872 /* invert */ (cm->cm_flags & CM_INVERT) ? TRUE : FALSE,
873 /* sense_len */ SSD_FULL_SIZE,
874 /* timeout */ CH_TIMEOUT_MOVE_MEDIUM);
876 error = cam_periph_runccb(ccb, cherror, /*cam_flags*/0,
877 /*sense_flags*/ SF_RETRY_UA | SF_RETRY_SELTO,
878 &softc->device_stats);
880 xpt_release_ccb(ccb);
886 chexchange(struct cam_periph *periph, struct changer_exchange *ce)
888 struct ch_softc *softc;
889 u_int16_t src, dst1, dst2;
894 softc = (struct ch_softc *)periph->softc;
898 if ((ce->ce_srctype > CHET_DT) || (ce->ce_fdsttype > CHET_DT) ||
899 (ce->ce_sdsttype > CHET_DT))
901 if ((ce->ce_srcunit > (softc->sc_counts[ce->ce_srctype] - 1)) ||
902 (ce->ce_fdstunit > (softc->sc_counts[ce->ce_fdsttype] - 1)) ||
903 (ce->ce_sdstunit > (softc->sc_counts[ce->ce_sdsttype] - 1)))
907 * Check the request against the changer's capabilities.
909 if (((softc->sc_exchangemask[ce->ce_srctype] &
910 (1 << ce->ce_fdsttype)) == 0) ||
911 ((softc->sc_exchangemask[ce->ce_fdsttype] &
912 (1 << ce->ce_sdsttype)) == 0))
916 * Calculate the source and destination elements.
918 src = softc->sc_firsts[ce->ce_srctype] + ce->ce_srcunit;
919 dst1 = softc->sc_firsts[ce->ce_fdsttype] + ce->ce_fdstunit;
920 dst2 = softc->sc_firsts[ce->ce_sdsttype] + ce->ce_sdstunit;
922 ccb = cam_periph_getccb(periph, /*priority*/ 1);
924 scsi_exchange_medium(&ccb->csio,
927 /* tag_action */ MSG_SIMPLE_Q_TAG,
928 /* tea */ softc->sc_picker,
932 /* invert1 */ (ce->ce_flags & CE_INVERT1) ?
934 /* invert2 */ (ce->ce_flags & CE_INVERT2) ?
936 /* sense_len */ SSD_FULL_SIZE,
937 /* timeout */ CH_TIMEOUT_EXCHANGE_MEDIUM);
939 error = cam_periph_runccb(ccb, cherror, /*cam_flags*/0,
940 /*sense_flags*/ SF_RETRY_UA | SF_RETRY_SELTO,
941 &softc->device_stats);
943 xpt_release_ccb(ccb);
949 chposition(struct cam_periph *periph, struct changer_position *cp)
951 struct ch_softc *softc;
957 softc = (struct ch_softc *)periph->softc;
962 if (cp->cp_type > CHET_DT)
964 if (cp->cp_unit > (softc->sc_counts[cp->cp_type] - 1))
968 * Calculate the destination element.
970 dst = softc->sc_firsts[cp->cp_type] + cp->cp_unit;
972 ccb = cam_periph_getccb(periph, /*priority*/ 1);
974 scsi_position_to_element(&ccb->csio,
977 /* tag_action */ MSG_SIMPLE_Q_TAG,
978 /* tea */ softc->sc_picker,
980 /* invert */ (cp->cp_flags & CP_INVERT) ?
982 /* sense_len */ SSD_FULL_SIZE,
983 /* timeout */ CH_TIMEOUT_POSITION_TO_ELEMENT);
985 error = cam_periph_runccb(ccb, cherror, /*cam_flags*/ 0,
986 /*sense_flags*/ SF_RETRY_UA | SF_RETRY_SELTO,
987 &softc->device_stats);
989 xpt_release_ccb(ccb);
995 * Copy a volume tag to a volume_tag struct, converting SCSI byte order
996 * to host native byte order in the volume serial number. The volume
997 * label as returned by the changer is transferred to user mode as
998 * nul-terminated string. Volume labels are truncated at the first
999 * space, as suggested by SCSI-2.
1002 copy_voltag(struct changer_voltag *uvoltag, struct volume_tag *voltag)
1005 for (i=0; i<CH_VOLTAG_MAXLEN; i++) {
1006 char c = voltag->vif[i];
1008 uvoltag->cv_volid[i] = c;
1012 uvoltag->cv_serial = scsi_2btoul(voltag->vsn);
1016 * Copy an an element status descriptor to a user-mode
1017 * changer_element_status structure.
1021 copy_element_status(struct ch_softc *softc,
1023 struct read_element_status_descriptor *desc,
1024 struct changer_element_status *ces)
1026 u_int16_t eaddr = scsi_2btoul(desc->eaddr);
1029 ces->ces_int_addr = eaddr;
1030 /* set up logical address in element status */
1031 for (et = CHET_MT; et <= CHET_DT; et++) {
1032 if ((softc->sc_firsts[et] <= eaddr)
1033 && ((softc->sc_firsts[et] + softc->sc_counts[et])
1035 ces->ces_addr = eaddr - softc->sc_firsts[et];
1041 ces->ces_flags = desc->flags1;
1043 ces->ces_sensecode = desc->sense_code;
1044 ces->ces_sensequal = desc->sense_qual;
1046 if (desc->flags2 & READ_ELEMENT_STATUS_INVERT)
1047 ces->ces_flags |= CES_INVERT;
1049 if (desc->flags2 & READ_ELEMENT_STATUS_SVALID) {
1051 eaddr = scsi_2btoul(desc->ssea);
1053 /* convert source address to logical format */
1054 for (et = CHET_MT; et <= CHET_DT; et++) {
1055 if ((softc->sc_firsts[et] <= eaddr)
1056 && ((softc->sc_firsts[et] + softc->sc_counts[et])
1058 ces->ces_source_addr =
1059 eaddr - softc->sc_firsts[et];
1060 ces->ces_source_type = et;
1061 ces->ces_flags |= CES_SOURCE_VALID;
1066 if (!(ces->ces_flags & CES_SOURCE_VALID))
1067 printf("ch: warning: could not map element source "
1068 "address %ud to a valid element type\n",
1073 if (flags & READ_ELEMENT_STATUS_PVOLTAG)
1074 copy_voltag(&(ces->ces_pvoltag), &(desc->pvoltag));
1075 if (flags & READ_ELEMENT_STATUS_AVOLTAG)
1076 copy_voltag(&(ces->ces_avoltag), &(desc->avoltag));
1078 if (desc->dt_scsi_flags & READ_ELEMENT_STATUS_DT_IDVALID) {
1079 ces->ces_flags |= CES_SCSIID_VALID;
1080 ces->ces_scsi_id = desc->dt_scsi_addr;
1083 if (desc->dt_scsi_addr & READ_ELEMENT_STATUS_DT_LUVALID) {
1084 ces->ces_flags |= CES_LUN_VALID;
1086 desc->dt_scsi_flags & READ_ELEMENT_STATUS_DT_LUNMASK;
1091 chgetelemstatus(struct cam_periph *periph,
1092 struct changer_element_status_request *cesr)
1094 struct read_element_status_header *st_hdr;
1095 struct read_element_status_page_header *pg_hdr;
1096 struct read_element_status_descriptor *desc;
1097 caddr_t data = NULL;
1098 size_t size, desclen;
1099 int avail, i, error = 0;
1100 struct changer_element_status *user_data = NULL;
1101 struct ch_softc *softc;
1103 int chet = cesr->cesr_element_type;
1104 int want_voltags = (cesr->cesr_flags & CESR_VOLTAGS) ? 1 : 0;
1106 softc = (struct ch_softc *)periph->softc;
1108 /* perform argument checking */
1111 * Perform a range check on the cesr_element_{base,count}
1112 * request argument fields.
1114 if ((softc->sc_counts[chet] - cesr->cesr_element_base) <= 0
1115 || (cesr->cesr_element_base + cesr->cesr_element_count)
1116 > softc->sc_counts[chet])
1120 * Request one descriptor for the given element type. This
1121 * is used to determine the size of the descriptor so that
1122 * we can allocate enough storage for all of them. We assume
1123 * that the first one can fit into 1k.
1125 data = (caddr_t)malloc(1024, M_DEVBUF, M_WAITOK);
1127 ccb = cam_periph_getccb(periph, /*priority*/ 1);
1129 scsi_read_element_status(&ccb->csio,
1131 /* cbfcnp */ chdone,
1132 /* tag_action */ MSG_SIMPLE_Q_TAG,
1133 /* voltag */ want_voltags,
1134 /* sea */ softc->sc_firsts[chet],
1136 /* data_ptr */ data,
1137 /* dxfer_len */ 1024,
1138 /* sense_len */ SSD_FULL_SIZE,
1139 /* timeout */ CH_TIMEOUT_READ_ELEMENT_STATUS);
1141 error = cam_periph_runccb(ccb, cherror, /*cam_flags*/ 0,
1142 /*sense_flags*/ SF_RETRY_UA | SF_RETRY_SELTO,
1143 &softc->device_stats);
1148 st_hdr = (struct read_element_status_header *)data;
1149 pg_hdr = (struct read_element_status_page_header *)((uintptr_t)st_hdr +
1150 sizeof(struct read_element_status_header));
1151 desclen = scsi_2btoul(pg_hdr->edl);
1153 size = sizeof(struct read_element_status_header) +
1154 sizeof(struct read_element_status_page_header) +
1155 (desclen * cesr->cesr_element_count);
1158 * Reallocate storage for descriptors and get them from the
1161 free(data, M_DEVBUF);
1162 data = (caddr_t)malloc(size, M_DEVBUF, M_WAITOK);
1164 scsi_read_element_status(&ccb->csio,
1166 /* cbfcnp */ chdone,
1167 /* tag_action */ MSG_SIMPLE_Q_TAG,
1168 /* voltag */ want_voltags,
1169 /* sea */ softc->sc_firsts[chet]
1170 + cesr->cesr_element_base,
1171 /* count */ cesr->cesr_element_count,
1172 /* data_ptr */ data,
1173 /* dxfer_len */ size,
1174 /* sense_len */ SSD_FULL_SIZE,
1175 /* timeout */ CH_TIMEOUT_READ_ELEMENT_STATUS);
1177 error = cam_periph_runccb(ccb, cherror, /*cam_flags*/ 0,
1178 /*sense_flags*/ SF_RETRY_UA | SF_RETRY_SELTO,
1179 &softc->device_stats);
1185 * Fill in the user status array.
1187 st_hdr = (struct read_element_status_header *)data;
1188 avail = scsi_2btoul(st_hdr->count);
1190 if (avail != cesr->cesr_element_count) {
1191 xpt_print_path(periph->path);
1192 printf("warning, READ ELEMENT STATUS avail != count\n");
1195 user_data = (struct changer_element_status *)
1196 malloc(avail * sizeof(struct changer_element_status),
1197 M_DEVBUF, M_WAITOK | M_ZERO);
1199 desc = (struct read_element_status_descriptor *)((uintptr_t)data +
1200 sizeof(struct read_element_status_header) +
1201 sizeof(struct read_element_status_page_header));
1203 * Set up the individual element status structures
1205 for (i = 0; i < avail; ++i) {
1206 struct changer_element_status *ces = &(user_data[i]);
1208 copy_element_status(softc, pg_hdr->flags, desc, ces);
1210 desc = (struct read_element_status_descriptor *)
1211 ((uintptr_t)desc + desclen);
1214 /* Copy element status structures out to userspace. */
1215 error = copyout(user_data,
1216 cesr->cesr_element_status,
1217 avail * sizeof(struct changer_element_status));
1220 xpt_release_ccb(ccb);
1223 free(data, M_DEVBUF);
1224 if (user_data != NULL)
1225 free(user_data, M_DEVBUF);
1231 chielem(struct cam_periph *periph,
1232 unsigned int timeout)
1235 struct ch_softc *softc;
1239 timeout = CH_TIMEOUT_INITIALIZE_ELEMENT_STATUS;
1245 softc = (struct ch_softc *)periph->softc;
1247 ccb = cam_periph_getccb(periph, /*priority*/ 1);
1249 scsi_initialize_element_status(&ccb->csio,
1251 /* cbfcnp */ chdone,
1252 /* tag_action */ MSG_SIMPLE_Q_TAG,
1253 /* sense_len */ SSD_FULL_SIZE,
1254 /* timeout */ timeout);
1256 error = cam_periph_runccb(ccb, cherror, /*cam_flags*/ 0,
1257 /*sense_flags*/ SF_RETRY_UA | SF_RETRY_SELTO,
1258 &softc->device_stats);
1260 xpt_release_ccb(ccb);
1266 chsetvoltag(struct cam_periph *periph,
1267 struct changer_set_voltag_request *csvr)
1270 struct ch_softc *softc;
1273 struct scsi_send_volume_tag_parameters ssvtp;
1278 softc = (struct ch_softc *)periph->softc;
1280 bzero(&ssvtp, sizeof(ssvtp));
1281 for (i=0; i<sizeof(ssvtp.vitf); i++) {
1282 ssvtp.vitf[i] = ' ';
1288 if (csvr->csvr_type > CHET_DT)
1290 if (csvr->csvr_addr > (softc->sc_counts[csvr->csvr_type] - 1))
1293 ea = softc->sc_firsts[csvr->csvr_type] + csvr->csvr_addr;
1295 if (csvr->csvr_flags & CSVR_ALTERNATE) {
1296 switch (csvr->csvr_flags & CSVR_MODE_MASK) {
1298 sac = SEND_VOLUME_TAG_ASSERT_ALTERNATE;
1300 case CSVR_MODE_REPLACE:
1301 sac = SEND_VOLUME_TAG_REPLACE_ALTERNATE;
1303 case CSVR_MODE_CLEAR:
1304 sac = SEND_VOLUME_TAG_UNDEFINED_ALTERNATE;
1311 switch (csvr->csvr_flags & CSVR_MODE_MASK) {
1313 sac = SEND_VOLUME_TAG_ASSERT_PRIMARY;
1315 case CSVR_MODE_REPLACE:
1316 sac = SEND_VOLUME_TAG_REPLACE_PRIMARY;
1318 case CSVR_MODE_CLEAR:
1319 sac = SEND_VOLUME_TAG_UNDEFINED_PRIMARY;
1327 memcpy(ssvtp.vitf, csvr->csvr_voltag.cv_volid,
1328 min(strlen(csvr->csvr_voltag.cv_volid), sizeof(ssvtp.vitf)));
1329 scsi_ulto2b(csvr->csvr_voltag.cv_serial, ssvtp.minvsn);
1331 ccb = cam_periph_getccb(periph, /*priority*/ 1);
1333 scsi_send_volume_tag(&ccb->csio,
1335 /* cbfcnp */ chdone,
1336 /* tag_action */ MSG_SIMPLE_Q_TAG,
1337 /* element_address */ ea,
1338 /* send_action_code */ sac,
1339 /* parameters */ &ssvtp,
1340 /* sense_len */ SSD_FULL_SIZE,
1341 /* timeout */ CH_TIMEOUT_SEND_VOLTAG);
1343 error = cam_periph_runccb(ccb, cherror, /*cam_flags*/ 0,
1344 /*sense_flags*/ SF_RETRY_UA | SF_RETRY_SELTO,
1345 &softc->device_stats);
1347 xpt_release_ccb(ccb);
1354 chgetparams(struct cam_periph *periph)
1357 struct ch_softc *softc;
1359 int mode_buffer_len;
1360 struct page_element_address_assignment *ea;
1361 struct page_device_capabilities *cap;
1362 int error, from, dbd;
1363 u_int8_t *moves, *exchanges;
1367 softc = (struct ch_softc *)periph->softc;
1369 ccb = cam_periph_getccb(periph, /*priority*/ 1);
1372 * The scsi_mode_sense_data structure is just a convenience
1373 * structure that allows us to easily calculate the worst-case
1374 * storage size of the mode sense buffer.
1376 mode_buffer_len = sizeof(struct scsi_mode_sense_data);
1378 mode_buffer = malloc(mode_buffer_len, M_TEMP, M_NOWAIT);
1380 if (mode_buffer == NULL) {
1381 printf("chgetparams: couldn't malloc mode sense data\n");
1385 bzero(mode_buffer, mode_buffer_len);
1387 if (softc->quirks & CH_Q_NO_DBD)
1393 * Get the element address assignment page.
1395 scsi_mode_sense(&ccb->csio,
1397 /* cbfcnp */ chdone,
1398 /* tag_action */ MSG_SIMPLE_Q_TAG,
1400 /* page_code */ SMS_PAGE_CTRL_CURRENT,
1401 /* page */ CH_ELEMENT_ADDR_ASSIGN_PAGE,
1402 /* param_buf */ (u_int8_t *)mode_buffer,
1403 /* param_len */ mode_buffer_len,
1404 /* sense_len */ SSD_FULL_SIZE,
1405 /* timeout */ CH_TIMEOUT_MODE_SENSE);
1407 error = cam_periph_runccb(ccb, cherror, /*cam_flags*/ 0,
1408 /* sense_flags */ SF_RETRY_UA |
1409 SF_NO_PRINT | SF_RETRY_SELTO,
1410 &softc->device_stats);
1414 struct scsi_mode_sense_6 *sms;
1416 sms = (struct scsi_mode_sense_6 *)
1417 ccb->csio.cdb_io.cdb_bytes;
1419 sms->byte2 &= ~SMS_DBD;
1420 error = cam_periph_runccb(ccb, cherror, /*cam_flags*/ 0,
1421 /*sense_flags*/ SF_RETRY_UA |
1423 &softc->device_stats);
1426 * Since we disabled sense printing above, print
1427 * out the sense here since we got an error.
1429 scsi_sense_print(&ccb->csio);
1433 xpt_print_path(periph->path);
1434 printf("chgetparams: error getting element "
1436 xpt_release_ccb(ccb);
1437 free(mode_buffer, M_TEMP);
1442 ea = (struct page_element_address_assignment *)
1443 find_mode_page_6((struct scsi_mode_header_6 *)mode_buffer);
1445 softc->sc_firsts[CHET_MT] = scsi_2btoul(ea->mtea);
1446 softc->sc_counts[CHET_MT] = scsi_2btoul(ea->nmte);
1447 softc->sc_firsts[CHET_ST] = scsi_2btoul(ea->fsea);
1448 softc->sc_counts[CHET_ST] = scsi_2btoul(ea->nse);
1449 softc->sc_firsts[CHET_IE] = scsi_2btoul(ea->fieea);
1450 softc->sc_counts[CHET_IE] = scsi_2btoul(ea->niee);
1451 softc->sc_firsts[CHET_DT] = scsi_2btoul(ea->fdtea);
1452 softc->sc_counts[CHET_DT] = scsi_2btoul(ea->ndte);
1454 bzero(mode_buffer, mode_buffer_len);
1457 * Now get the device capabilities page.
1459 scsi_mode_sense(&ccb->csio,
1461 /* cbfcnp */ chdone,
1462 /* tag_action */ MSG_SIMPLE_Q_TAG,
1464 /* page_code */ SMS_PAGE_CTRL_CURRENT,
1465 /* page */ CH_DEVICE_CAP_PAGE,
1466 /* param_buf */ (u_int8_t *)mode_buffer,
1467 /* param_len */ mode_buffer_len,
1468 /* sense_len */ SSD_FULL_SIZE,
1469 /* timeout */ CH_TIMEOUT_MODE_SENSE);
1471 error = cam_periph_runccb(ccb, cherror, /*cam_flags*/ 0,
1472 /* sense_flags */ SF_RETRY_UA | SF_NO_PRINT |
1473 SF_RETRY_SELTO, &softc->device_stats);
1477 struct scsi_mode_sense_6 *sms;
1479 sms = (struct scsi_mode_sense_6 *)
1480 ccb->csio.cdb_io.cdb_bytes;
1482 sms->byte2 &= ~SMS_DBD;
1483 error = cam_periph_runccb(ccb, cherror, /*cam_flags*/ 0,
1484 /*sense_flags*/ SF_RETRY_UA |
1486 &softc->device_stats);
1489 * Since we disabled sense printing above, print
1490 * out the sense here since we got an error.
1492 scsi_sense_print(&ccb->csio);
1496 xpt_print_path(periph->path);
1497 printf("chgetparams: error getting device "
1498 "capabilities page\n");
1499 xpt_release_ccb(ccb);
1500 free(mode_buffer, M_TEMP);
1505 xpt_release_ccb(ccb);
1507 cap = (struct page_device_capabilities *)
1508 find_mode_page_6((struct scsi_mode_header_6 *)mode_buffer);
1510 bzero(softc->sc_movemask, sizeof(softc->sc_movemask));
1511 bzero(softc->sc_exchangemask, sizeof(softc->sc_exchangemask));
1512 moves = &cap->move_from_mt;
1513 exchanges = &cap->exchange_with_mt;
1514 for (from = CHET_MT; from <= CHET_DT; ++from) {
1515 softc->sc_movemask[from] = moves[from];
1516 softc->sc_exchangemask[from] = exchanges[from];
1519 free(mode_buffer, M_TEMP);
1525 scsi_move_medium(struct ccb_scsiio *csio, u_int32_t retries,
1526 void (*cbfcnp)(struct cam_periph *, union ccb *),
1527 u_int8_t tag_action, u_int32_t tea, u_int32_t src,
1528 u_int32_t dst, int invert, u_int8_t sense_len,
1531 struct scsi_move_medium *scsi_cmd;
1533 scsi_cmd = (struct scsi_move_medium *)&csio->cdb_io.cdb_bytes;
1534 bzero(scsi_cmd, sizeof(*scsi_cmd));
1536 scsi_cmd->opcode = MOVE_MEDIUM;
1538 scsi_ulto2b(tea, scsi_cmd->tea);
1539 scsi_ulto2b(src, scsi_cmd->src);
1540 scsi_ulto2b(dst, scsi_cmd->dst);
1543 scsi_cmd->invert |= MOVE_MEDIUM_INVERT;
1548 /*flags*/ CAM_DIR_NONE,
1558 scsi_exchange_medium(struct ccb_scsiio *csio, u_int32_t retries,
1559 void (*cbfcnp)(struct cam_periph *, union ccb *),
1560 u_int8_t tag_action, u_int32_t tea, u_int32_t src,
1561 u_int32_t dst1, u_int32_t dst2, int invert1,
1562 int invert2, u_int8_t sense_len, u_int32_t timeout)
1564 struct scsi_exchange_medium *scsi_cmd;
1566 scsi_cmd = (struct scsi_exchange_medium *)&csio->cdb_io.cdb_bytes;
1567 bzero(scsi_cmd, sizeof(*scsi_cmd));
1569 scsi_cmd->opcode = EXCHANGE_MEDIUM;
1571 scsi_ulto2b(tea, scsi_cmd->tea);
1572 scsi_ulto2b(src, scsi_cmd->src);
1573 scsi_ulto2b(dst1, scsi_cmd->fdst);
1574 scsi_ulto2b(dst2, scsi_cmd->sdst);
1577 scsi_cmd->invert |= EXCHANGE_MEDIUM_INV1;
1580 scsi_cmd->invert |= EXCHANGE_MEDIUM_INV2;
1585 /*flags*/ CAM_DIR_NONE,
1595 scsi_position_to_element(struct ccb_scsiio *csio, u_int32_t retries,
1596 void (*cbfcnp)(struct cam_periph *, union ccb *),
1597 u_int8_t tag_action, u_int32_t tea, u_int32_t dst,
1598 int invert, u_int8_t sense_len, u_int32_t timeout)
1600 struct scsi_position_to_element *scsi_cmd;
1602 scsi_cmd = (struct scsi_position_to_element *)&csio->cdb_io.cdb_bytes;
1603 bzero(scsi_cmd, sizeof(*scsi_cmd));
1605 scsi_cmd->opcode = POSITION_TO_ELEMENT;
1607 scsi_ulto2b(tea, scsi_cmd->tea);
1608 scsi_ulto2b(dst, scsi_cmd->dst);
1611 scsi_cmd->invert |= POSITION_TO_ELEMENT_INVERT;
1616 /*flags*/ CAM_DIR_NONE,
1626 scsi_read_element_status(struct ccb_scsiio *csio, u_int32_t retries,
1627 void (*cbfcnp)(struct cam_periph *, union ccb *),
1628 u_int8_t tag_action, int voltag, u_int32_t sea,
1629 u_int32_t count, u_int8_t *data_ptr,
1630 u_int32_t dxfer_len, u_int8_t sense_len,
1633 struct scsi_read_element_status *scsi_cmd;
1635 scsi_cmd = (struct scsi_read_element_status *)&csio->cdb_io.cdb_bytes;
1636 bzero(scsi_cmd, sizeof(*scsi_cmd));
1638 scsi_cmd->opcode = READ_ELEMENT_STATUS;
1640 scsi_ulto2b(sea, scsi_cmd->sea);
1641 scsi_ulto2b(count, scsi_cmd->count);
1642 scsi_ulto3b(dxfer_len, scsi_cmd->len);
1645 scsi_cmd->byte2 |= READ_ELEMENT_STATUS_VOLTAG;
1650 /*flags*/ CAM_DIR_IN,
1660 scsi_initialize_element_status(struct ccb_scsiio *csio, u_int32_t retries,
1661 void (*cbfcnp)(struct cam_periph *, union ccb *),
1662 u_int8_t tag_action, u_int8_t sense_len,
1665 struct scsi_initialize_element_status *scsi_cmd;
1667 scsi_cmd = (struct scsi_initialize_element_status *)
1668 &csio->cdb_io.cdb_bytes;
1669 bzero(scsi_cmd, sizeof(*scsi_cmd));
1671 scsi_cmd->opcode = INITIALIZE_ELEMENT_STATUS;
1676 /*flags*/ CAM_DIR_NONE,
1678 /* data_ptr */ NULL,
1686 scsi_send_volume_tag(struct ccb_scsiio *csio, u_int32_t retries,
1687 void (*cbfcnp)(struct cam_periph *, union ccb *),
1688 u_int8_t tag_action,
1689 u_int16_t element_address,
1690 u_int8_t send_action_code,
1691 struct scsi_send_volume_tag_parameters *parameters,
1692 u_int8_t sense_len, u_int32_t timeout)
1694 struct scsi_send_volume_tag *scsi_cmd;
1696 scsi_cmd = (struct scsi_send_volume_tag *) &csio->cdb_io.cdb_bytes;
1697 bzero(scsi_cmd, sizeof(*scsi_cmd));
1699 scsi_cmd->opcode = SEND_VOLUME_TAG;
1700 scsi_ulto2b(element_address, scsi_cmd->ea);
1701 scsi_cmd->sac = send_action_code;
1702 scsi_ulto2b(sizeof(*parameters), scsi_cmd->pll);
1707 /*flags*/ CAM_DIR_OUT,
1709 /* data_ptr */ (u_int8_t *) parameters,
1710 sizeof(*parameters),