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
29 * Derived from the NetBSD SCSI changer driver.
31 * $NetBSD: ch.c,v 1.32 1998/01/12 09:49:12 thorpej Exp $
35 * Copyright (c) 1996, 1997 Jason R. Thorpe <thorpej@and.com>
36 * All rights reserved.
38 * Partially based on an autochanger driver written by Stefan Grefen
39 * and on an autochanger driver written by the Systems Programming Group
40 * at the University of Utah Computer Science Department.
42 * Redistribution and use in source and binary forms, with or without
43 * modification, are permitted provided that the following conditions
45 * 1. Redistributions of source code must retain the above copyright
46 * notice, this list of conditions and the following disclaimer.
47 * 2. Redistributions in binary form must reproduce the above copyright
48 * notice, this list of conditions and the following disclaimer in the
49 * documentation and/or other materials provided with the distribution.
50 * 3. All advertising materials mentioning features or use of this software
51 * must display the following acknowledgements:
52 * This product includes software developed by Jason R. Thorpe
53 * for And Communications, http://www.and.com/
54 * 4. The name of the author may not be used to endorse or promote products
55 * derived from this software without specific prior written permission.
57 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
58 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
59 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
60 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
61 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
62 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
63 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
64 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
65 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
66 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
70 #include <sys/cdefs.h>
71 __FBSDID("$FreeBSD$");
73 #include <sys/param.h>
74 #include <sys/queue.h>
75 #include <sys/systm.h>
76 #include <sys/kernel.h>
77 #include <sys/types.h>
78 #include <sys/malloc.h>
79 #include <sys/fcntl.h>
82 #include <sys/errno.h>
83 #include <sys/devicestat.h>
86 #include <cam/cam_ccb.h>
87 #include <cam/cam_periph.h>
88 #include <cam/cam_xpt_periph.h>
89 #include <cam/cam_debug.h>
91 #include <cam/scsi/scsi_all.h>
92 #include <cam/scsi/scsi_message.h>
93 #include <cam/scsi/scsi_ch.h>
96 * Timeout definitions for various changer related commands. They may
97 * be too short for some devices (especially the timeout for INITIALIZE
101 static const u_int32_t CH_TIMEOUT_MODE_SENSE = 6000;
102 static const u_int32_t CH_TIMEOUT_MOVE_MEDIUM = 100000;
103 static const u_int32_t CH_TIMEOUT_EXCHANGE_MEDIUM = 100000;
104 static const u_int32_t CH_TIMEOUT_POSITION_TO_ELEMENT = 100000;
105 static const u_int32_t CH_TIMEOUT_READ_ELEMENT_STATUS = 10000;
106 static const u_int32_t CH_TIMEOUT_SEND_VOLTAG = 10000;
107 static const u_int32_t CH_TIMEOUT_INITIALIZE_ELEMENT_STATUS = 500000;
110 CH_FLAG_INVALID = 0x001,
129 #define CH_Q_BIT_STRING \
133 #define ccb_state ppriv_field0
134 #define ccb_bp ppriv_ptr1
136 struct scsi_mode_sense_data {
137 struct scsi_mode_header_6 header;
138 struct scsi_mode_blk_desc blk_desc;
140 struct page_element_address_assignment ea;
141 struct page_transport_geometry_parameters tg;
142 struct page_device_capabilities cap;
151 struct devstat *device_stats;
154 int sc_picker; /* current picker */
157 * The following information is obtained from the
158 * element address assignment page.
160 int sc_firsts[CHET_MAX + 1]; /* firsts */
161 int sc_counts[CHET_MAX + 1]; /* counts */
164 * The following mask defines the legal combinations
165 * of elements for the MOVE MEDIUM command.
167 u_int8_t sc_movemask[CHET_MAX + 1];
170 * As above, but for EXCHANGE MEDIUM.
172 u_int8_t sc_exchangemask[CHET_MAX + 1];
175 * Quirks; see below. XXX KDM not implemented yet
177 int sc_settledelay; /* delay for settle */
180 static d_open_t chopen;
181 static d_close_t chclose;
182 static d_ioctl_t chioctl;
183 static periph_init_t chinit;
184 static periph_ctor_t chregister;
185 static periph_oninv_t choninvalidate;
186 static periph_dtor_t chcleanup;
187 static periph_start_t chstart;
188 static void chasync(void *callback_arg, u_int32_t code,
189 struct cam_path *path, void *arg);
190 static void chdone(struct cam_periph *periph,
191 union ccb *done_ccb);
192 static int cherror(union ccb *ccb, u_int32_t cam_flags,
193 u_int32_t sense_flags);
194 static int chmove(struct cam_periph *periph,
195 struct changer_move *cm);
196 static int chexchange(struct cam_periph *periph,
197 struct changer_exchange *ce);
198 static int chposition(struct cam_periph *periph,
199 struct changer_position *cp);
200 static int chgetelemstatus(struct cam_periph *periph,
201 struct changer_element_status_request *csr);
202 static int chsetvoltag(struct cam_periph *periph,
203 struct changer_set_voltag_request *csvr);
204 static int chielem(struct cam_periph *periph,
205 unsigned int timeout);
206 static int chgetparams(struct cam_periph *periph);
208 static struct periph_driver chdriver =
211 TAILQ_HEAD_INITIALIZER(chdriver.units), /* generation */ 0
214 PERIPHDRIVER_DECLARE(ch, chdriver);
216 static struct cdevsw ch_cdevsw = {
217 .d_version = D_VERSION,
225 MALLOC_DEFINE(M_SCSICH, "scsi_ch", "scsi_ch buffers");
233 * Install a global async callback. This callback will
234 * receive async callbacks like "new device found".
236 status = xpt_register_async(AC_FOUND_DEVICE, chasync, NULL, NULL);
238 if (status != CAM_REQ_CMP) {
239 printf("ch: Failed to attach master async callback "
240 "due to status 0x%x!\n", status);
245 choninvalidate(struct cam_periph *periph)
247 struct ch_softc *softc;
249 softc = (struct ch_softc *)periph->softc;
252 * De-register any async callbacks.
254 xpt_register_async(0, chasync, periph, periph->path);
256 softc->flags |= CH_FLAG_INVALID;
258 xpt_print(periph->path, "lost device\n");
263 chcleanup(struct cam_periph *periph)
265 struct ch_softc *softc;
267 softc = (struct ch_softc *)periph->softc;
269 xpt_print(periph->path, "removing device entry\n");
270 devstat_remove_entry(softc->device_stats);
271 cam_periph_unlock(periph);
272 destroy_dev(softc->dev);
273 cam_periph_lock(periph);
274 free(softc, M_DEVBUF);
278 chasync(void *callback_arg, u_int32_t code, struct cam_path *path, void *arg)
280 struct cam_periph *periph;
282 periph = (struct cam_periph *)callback_arg;
285 case AC_FOUND_DEVICE:
287 struct ccb_getdev *cgd;
290 cgd = (struct ccb_getdev *)arg;
294 if (cgd->protocol != PROTO_SCSI)
297 if (SID_TYPE(&cgd->inq_data)!= T_CHANGER)
301 * Allocate a peripheral instance for
302 * this device and start the probe
305 status = cam_periph_alloc(chregister, choninvalidate,
306 chcleanup, chstart, "ch",
307 CAM_PERIPH_BIO, cgd->ccb_h.path,
308 chasync, AC_FOUND_DEVICE, cgd);
310 if (status != CAM_REQ_CMP
311 && status != CAM_REQ_INPROG)
312 printf("chasync: Unable to probe new device "
313 "due to status 0x%x\n", status);
319 cam_periph_async(periph, code, path, arg);
325 chregister(struct cam_periph *periph, void *arg)
327 struct ch_softc *softc;
328 struct ccb_getdev *cgd;
329 struct ccb_pathinq cpi;
331 cgd = (struct ccb_getdev *)arg;
332 if (periph == NULL) {
333 printf("chregister: periph was NULL!!\n");
334 return(CAM_REQ_CMP_ERR);
338 printf("chregister: no getdev CCB, can't register device\n");
339 return(CAM_REQ_CMP_ERR);
342 softc = (struct ch_softc *)malloc(sizeof(*softc),M_DEVBUF,M_NOWAIT);
345 printf("chregister: Unable to probe new device. "
346 "Unable to allocate softc\n");
347 return(CAM_REQ_CMP_ERR);
350 bzero(softc, sizeof(*softc));
351 softc->state = CH_STATE_PROBE;
352 periph->softc = softc;
353 softc->quirks = CH_Q_NONE;
355 bzero(&cpi, sizeof(cpi));
356 xpt_setup_ccb(&cpi.ccb_h, periph->path, CAM_PRIORITY_NORMAL);
357 cpi.ccb_h.func_code = XPT_PATH_INQ;
358 xpt_action((union ccb *)&cpi);
361 * Changers don't have a blocksize, and obviously don't support
364 cam_periph_unlock(periph);
365 softc->device_stats = devstat_new_entry("ch",
366 periph->unit_number, 0,
367 DEVSTAT_NO_BLOCKSIZE | DEVSTAT_NO_ORDERED_TAGS,
368 SID_TYPE(&cgd->inq_data) |
369 XPORT_DEVSTAT_TYPE(cpi.transport),
370 DEVSTAT_PRIORITY_OTHER);
372 /* Register the device */
373 softc->dev = make_dev(&ch_cdevsw, periph->unit_number, UID_ROOT,
374 GID_OPERATOR, 0600, "%s%d", periph->periph_name,
375 periph->unit_number);
376 cam_periph_lock(periph);
377 softc->dev->si_drv1 = periph;
380 * Add an async callback so that we get
381 * notified if this device goes away.
383 xpt_register_async(AC_LOST_DEVICE, chasync, periph, periph->path);
386 * Lock this periph until we are setup.
387 * This first call can't block
389 (void)cam_periph_hold(periph, PRIBIO);
390 xpt_schedule(periph, CAM_PRIORITY_DEV);
396 chopen(struct cdev *dev, int flags, int fmt, struct thread *td)
398 struct cam_periph *periph;
399 struct ch_softc *softc;
402 periph = (struct cam_periph *)dev->si_drv1;
403 if (cam_periph_acquire(periph) != CAM_REQ_CMP)
406 softc = (struct ch_softc *)periph->softc;
408 cam_periph_lock(periph);
410 if (softc->flags & CH_FLAG_INVALID) {
411 cam_periph_unlock(periph);
412 cam_periph_release(periph);
416 if ((softc->flags & CH_FLAG_OPEN) == 0)
417 softc->flags |= CH_FLAG_OPEN;
419 cam_periph_release(periph);
421 if ((error = cam_periph_hold(periph, PRIBIO | PCATCH)) != 0) {
422 cam_periph_unlock(periph);
423 cam_periph_release(periph);
428 * Load information about this changer device into the softc.
430 if ((error = chgetparams(periph)) != 0) {
431 softc->flags &= ~CH_FLAG_OPEN;
432 cam_periph_unlock(periph);
433 cam_periph_release(periph);
437 cam_periph_unhold(periph);
438 cam_periph_unlock(periph);
444 chclose(struct cdev *dev, int flag, int fmt, struct thread *td)
446 struct cam_periph *periph;
447 struct ch_softc *softc;
452 periph = (struct cam_periph *)dev->si_drv1;
456 softc = (struct ch_softc *)periph->softc;
458 cam_periph_lock(periph);
460 softc->flags &= ~CH_FLAG_OPEN;
462 cam_periph_unlock(periph);
463 cam_periph_release(periph);
469 chstart(struct cam_periph *periph, union ccb *start_ccb)
471 struct ch_softc *softc;
473 softc = (struct ch_softc *)periph->softc;
475 switch (softc->state) {
476 case CH_STATE_NORMAL:
478 if (periph->immediate_priority <= periph->pinfo.priority){
479 start_ccb->ccb_h.ccb_state = CH_CCB_WAITING;
481 SLIST_INSERT_HEAD(&periph->ccb_list, &start_ccb->ccb_h,
483 periph->immediate_priority = CAM_PRIORITY_NONE;
484 wakeup(&periph->ccb_list);
494 * Include the block descriptor when calculating the mode
497 mode_buffer_len = sizeof(struct scsi_mode_header_6) +
498 sizeof(struct scsi_mode_blk_desc) +
499 sizeof(struct page_element_address_assignment);
501 mode_buffer = malloc(mode_buffer_len, M_SCSICH, M_NOWAIT);
503 if (mode_buffer == NULL) {
504 printf("chstart: couldn't malloc mode sense data\n");
507 bzero(mode_buffer, mode_buffer_len);
510 * Get the element address assignment page.
512 scsi_mode_sense(&start_ccb->csio,
515 /* tag_action */ MSG_SIMPLE_Q_TAG,
516 /* dbd */ (softc->quirks & CH_Q_NO_DBD) ?
518 /* page_code */ SMS_PAGE_CTRL_CURRENT,
519 /* page */ CH_ELEMENT_ADDR_ASSIGN_PAGE,
520 /* param_buf */ (u_int8_t *)mode_buffer,
521 /* param_len */ mode_buffer_len,
522 /* sense_len */ SSD_FULL_SIZE,
523 /* timeout */ CH_TIMEOUT_MODE_SENSE);
525 start_ccb->ccb_h.ccb_bp = NULL;
526 start_ccb->ccb_h.ccb_state = CH_CCB_PROBE;
527 xpt_action(start_ccb);
534 chdone(struct cam_periph *periph, union ccb *done_ccb)
536 struct ch_softc *softc;
537 struct ccb_scsiio *csio;
539 softc = (struct ch_softc *)periph->softc;
540 csio = &done_ccb->csio;
542 switch(done_ccb->ccb_h.ccb_state) {
545 struct scsi_mode_header_6 *mode_header;
546 struct page_element_address_assignment *ea;
547 char announce_buf[80];
550 mode_header = (struct scsi_mode_header_6 *)csio->data_ptr;
552 ea = (struct page_element_address_assignment *)
553 find_mode_page_6(mode_header);
555 if ((done_ccb->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP){
557 softc->sc_firsts[CHET_MT] = scsi_2btoul(ea->mtea);
558 softc->sc_counts[CHET_MT] = scsi_2btoul(ea->nmte);
559 softc->sc_firsts[CHET_ST] = scsi_2btoul(ea->fsea);
560 softc->sc_counts[CHET_ST] = scsi_2btoul(ea->nse);
561 softc->sc_firsts[CHET_IE] = scsi_2btoul(ea->fieea);
562 softc->sc_counts[CHET_IE] = scsi_2btoul(ea->niee);
563 softc->sc_firsts[CHET_DT] = scsi_2btoul(ea->fdtea);
564 softc->sc_counts[CHET_DT] = scsi_2btoul(ea->ndte);
565 softc->sc_picker = softc->sc_firsts[CHET_MT];
567 #define PLURAL(c) (c) == 1 ? "" : "s"
568 snprintf(announce_buf, sizeof(announce_buf),
569 "%d slot%s, %d drive%s, "
570 "%d picker%s, %d portal%s",
571 softc->sc_counts[CHET_ST],
572 PLURAL(softc->sc_counts[CHET_ST]),
573 softc->sc_counts[CHET_DT],
574 PLURAL(softc->sc_counts[CHET_DT]),
575 softc->sc_counts[CHET_MT],
576 PLURAL(softc->sc_counts[CHET_MT]),
577 softc->sc_counts[CHET_IE],
578 PLURAL(softc->sc_counts[CHET_IE]));
583 error = cherror(done_ccb, CAM_RETRY_SELTO,
584 SF_RETRY_UA | SF_NO_PRINT);
586 * Retry any UNIT ATTENTION type errors. They
587 * are expected at boot.
589 if (error == ERESTART) {
591 * A retry was scheuled, so
595 } else if (error != 0) {
597 struct scsi_mode_sense_6 *sms;
599 sms = (struct scsi_mode_sense_6 *)
600 done_ccb->csio.cdb_io.cdb_bytes;
603 * Check to see if block descriptors were
604 * disabled. Some devices don't like that.
605 * We're taking advantage of the fact that
606 * the first few bytes of the 6 and 10 byte
607 * mode sense commands are the same. If
608 * block descriptors were disabled, enable
609 * them and re-send the command.
611 if (sms->byte2 & SMS_DBD) {
612 sms->byte2 &= ~SMS_DBD;
613 xpt_action(done_ccb);
614 softc->quirks |= CH_Q_NO_DBD;
619 /* Don't wedge this device's queue */
620 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0)
621 cam_release_devq(done_ccb->ccb_h.path,
630 if ((done_ccb->ccb_h.status & CAM_STATUS_MASK)
631 == CAM_SCSI_STATUS_ERROR)
632 scsi_sense_print(&done_ccb->csio);
634 xpt_print(periph->path,
635 "got CAM status %#x\n",
636 done_ccb->ccb_h.status);
638 xpt_print(periph->path, "fatal error, failed "
639 "to attach to device\n");
641 cam_periph_invalidate(periph);
643 announce_buf[0] = '\0';
646 if (announce_buf[0] != '\0') {
647 xpt_announce_periph(periph, announce_buf);
648 xpt_announce_quirks(periph, softc->quirks,
651 softc->state = CH_STATE_NORMAL;
652 free(mode_header, M_SCSICH);
654 * Since our peripheral may be invalidated by an error
655 * above or an external event, we must release our CCB
656 * before releasing the probe lock on the peripheral.
657 * The peripheral will only go away once the last lock
658 * is removed, and we need it around for the CCB release
661 xpt_release_ccb(done_ccb);
662 cam_periph_unhold(periph);
667 /* Caller will release the CCB */
668 wakeup(&done_ccb->ccb_h.cbfcnp);
674 xpt_release_ccb(done_ccb);
678 cherror(union ccb *ccb, u_int32_t cam_flags, u_int32_t sense_flags)
680 struct ch_softc *softc;
681 struct cam_periph *periph;
683 periph = xpt_path_periph(ccb->ccb_h.path);
684 softc = (struct ch_softc *)periph->softc;
686 return (cam_periph_error(ccb, cam_flags, sense_flags,
691 chioctl(struct cdev *dev, u_long cmd, caddr_t addr, int flag, struct thread *td)
693 struct cam_periph *periph;
694 struct ch_softc *softc;
697 periph = (struct cam_periph *)dev->si_drv1;
701 cam_periph_lock(periph);
702 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("entering chioctl\n"));
704 softc = (struct ch_softc *)periph->softc;
708 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE,
709 ("trying to do ioctl %#lx\n", cmd));
712 * If this command can change the device's state, we must
713 * have the device open for writing.
722 if ((flag & FWRITE) == 0) {
723 cam_periph_unlock(periph);
730 error = chmove(periph, (struct changer_move *)addr);
734 error = chexchange(periph, (struct changer_exchange *)addr);
738 error = chposition(periph, (struct changer_position *)addr);
742 *(int *)addr = softc->sc_picker - softc->sc_firsts[CHET_MT];
747 int new_picker = *(int *)addr;
749 if (new_picker > (softc->sc_counts[CHET_MT] - 1)) {
753 softc->sc_picker = softc->sc_firsts[CHET_MT] + new_picker;
758 struct changer_params *cp = (struct changer_params *)addr;
760 cp->cp_npickers = softc->sc_counts[CHET_MT];
761 cp->cp_nslots = softc->sc_counts[CHET_ST];
762 cp->cp_nportals = softc->sc_counts[CHET_IE];
763 cp->cp_ndrives = softc->sc_counts[CHET_DT];
767 error = chielem(periph, *(unsigned int *)addr);
772 error = chgetelemstatus(periph,
773 (struct changer_element_status_request *) addr);
779 error = chsetvoltag(periph,
780 (struct changer_set_voltag_request *) addr);
784 /* Implement prevent/allow? */
787 error = cam_periph_ioctl(periph, cmd, addr, cherror);
791 cam_periph_unlock(periph);
796 chmove(struct cam_periph *periph, struct changer_move *cm)
798 struct ch_softc *softc;
799 u_int16_t fromelem, toelem;
804 softc = (struct ch_softc *)periph->softc;
809 if ((cm->cm_fromtype > CHET_DT) || (cm->cm_totype > CHET_DT))
811 if ((cm->cm_fromunit > (softc->sc_counts[cm->cm_fromtype] - 1)) ||
812 (cm->cm_tounit > (softc->sc_counts[cm->cm_totype] - 1)))
816 * Check the request against the changer's capabilities.
818 if ((softc->sc_movemask[cm->cm_fromtype] & (1 << cm->cm_totype)) == 0)
822 * Calculate the source and destination elements.
824 fromelem = softc->sc_firsts[cm->cm_fromtype] + cm->cm_fromunit;
825 toelem = softc->sc_firsts[cm->cm_totype] + cm->cm_tounit;
827 ccb = cam_periph_getccb(periph, CAM_PRIORITY_NORMAL);
829 scsi_move_medium(&ccb->csio,
832 /* tag_action */ MSG_SIMPLE_Q_TAG,
833 /* tea */ softc->sc_picker,
836 /* invert */ (cm->cm_flags & CM_INVERT) ? TRUE : FALSE,
837 /* sense_len */ SSD_FULL_SIZE,
838 /* timeout */ CH_TIMEOUT_MOVE_MEDIUM);
840 error = cam_periph_runccb(ccb, cherror, /*cam_flags*/CAM_RETRY_SELTO,
841 /*sense_flags*/ SF_RETRY_UA,
842 softc->device_stats);
844 xpt_release_ccb(ccb);
850 chexchange(struct cam_periph *periph, struct changer_exchange *ce)
852 struct ch_softc *softc;
853 u_int16_t src, dst1, dst2;
858 softc = (struct ch_softc *)periph->softc;
862 if ((ce->ce_srctype > CHET_DT) || (ce->ce_fdsttype > CHET_DT) ||
863 (ce->ce_sdsttype > CHET_DT))
865 if ((ce->ce_srcunit > (softc->sc_counts[ce->ce_srctype] - 1)) ||
866 (ce->ce_fdstunit > (softc->sc_counts[ce->ce_fdsttype] - 1)) ||
867 (ce->ce_sdstunit > (softc->sc_counts[ce->ce_sdsttype] - 1)))
871 * Check the request against the changer's capabilities.
873 if (((softc->sc_exchangemask[ce->ce_srctype] &
874 (1 << ce->ce_fdsttype)) == 0) ||
875 ((softc->sc_exchangemask[ce->ce_fdsttype] &
876 (1 << ce->ce_sdsttype)) == 0))
880 * Calculate the source and destination elements.
882 src = softc->sc_firsts[ce->ce_srctype] + ce->ce_srcunit;
883 dst1 = softc->sc_firsts[ce->ce_fdsttype] + ce->ce_fdstunit;
884 dst2 = softc->sc_firsts[ce->ce_sdsttype] + ce->ce_sdstunit;
886 ccb = cam_periph_getccb(periph, CAM_PRIORITY_NORMAL);
888 scsi_exchange_medium(&ccb->csio,
891 /* tag_action */ MSG_SIMPLE_Q_TAG,
892 /* tea */ softc->sc_picker,
896 /* invert1 */ (ce->ce_flags & CE_INVERT1) ?
898 /* invert2 */ (ce->ce_flags & CE_INVERT2) ?
900 /* sense_len */ SSD_FULL_SIZE,
901 /* timeout */ CH_TIMEOUT_EXCHANGE_MEDIUM);
903 error = cam_periph_runccb(ccb, cherror, /*cam_flags*/CAM_RETRY_SELTO,
904 /*sense_flags*/ SF_RETRY_UA,
905 softc->device_stats);
907 xpt_release_ccb(ccb);
913 chposition(struct cam_periph *periph, struct changer_position *cp)
915 struct ch_softc *softc;
921 softc = (struct ch_softc *)periph->softc;
926 if (cp->cp_type > CHET_DT)
928 if (cp->cp_unit > (softc->sc_counts[cp->cp_type] - 1))
932 * Calculate the destination element.
934 dst = softc->sc_firsts[cp->cp_type] + cp->cp_unit;
936 ccb = cam_periph_getccb(periph, CAM_PRIORITY_NORMAL);
938 scsi_position_to_element(&ccb->csio,
941 /* tag_action */ MSG_SIMPLE_Q_TAG,
942 /* tea */ softc->sc_picker,
944 /* invert */ (cp->cp_flags & CP_INVERT) ?
946 /* sense_len */ SSD_FULL_SIZE,
947 /* timeout */ CH_TIMEOUT_POSITION_TO_ELEMENT);
949 error = cam_periph_runccb(ccb, cherror, /*cam_flags*/ CAM_RETRY_SELTO,
950 /*sense_flags*/ SF_RETRY_UA,
951 softc->device_stats);
953 xpt_release_ccb(ccb);
959 * Copy a volume tag to a volume_tag struct, converting SCSI byte order
960 * to host native byte order in the volume serial number. The volume
961 * label as returned by the changer is transferred to user mode as
962 * nul-terminated string. Volume labels are truncated at the first
963 * space, as suggested by SCSI-2.
966 copy_voltag(struct changer_voltag *uvoltag, struct volume_tag *voltag)
969 for (i=0; i<CH_VOLTAG_MAXLEN; i++) {
970 char c = voltag->vif[i];
972 uvoltag->cv_volid[i] = c;
976 uvoltag->cv_serial = scsi_2btoul(voltag->vsn);
980 * Copy an an element status descriptor to a user-mode
981 * changer_element_status structure.
985 copy_element_status(struct ch_softc *softc,
987 struct read_element_status_descriptor *desc,
988 struct changer_element_status *ces)
990 u_int16_t eaddr = scsi_2btoul(desc->eaddr);
993 ces->ces_int_addr = eaddr;
994 /* set up logical address in element status */
995 for (et = CHET_MT; et <= CHET_DT; et++) {
996 if ((softc->sc_firsts[et] <= eaddr)
997 && ((softc->sc_firsts[et] + softc->sc_counts[et])
999 ces->ces_addr = eaddr - softc->sc_firsts[et];
1005 ces->ces_flags = desc->flags1;
1007 ces->ces_sensecode = desc->sense_code;
1008 ces->ces_sensequal = desc->sense_qual;
1010 if (desc->flags2 & READ_ELEMENT_STATUS_INVERT)
1011 ces->ces_flags |= CES_INVERT;
1013 if (desc->flags2 & READ_ELEMENT_STATUS_SVALID) {
1015 eaddr = scsi_2btoul(desc->ssea);
1017 /* convert source address to logical format */
1018 for (et = CHET_MT; et <= CHET_DT; et++) {
1019 if ((softc->sc_firsts[et] <= eaddr)
1020 && ((softc->sc_firsts[et] + softc->sc_counts[et])
1022 ces->ces_source_addr =
1023 eaddr - softc->sc_firsts[et];
1024 ces->ces_source_type = et;
1025 ces->ces_flags |= CES_SOURCE_VALID;
1030 if (!(ces->ces_flags & CES_SOURCE_VALID))
1031 printf("ch: warning: could not map element source "
1032 "address %ud to a valid element type\n",
1037 if (flags & READ_ELEMENT_STATUS_PVOLTAG)
1038 copy_voltag(&(ces->ces_pvoltag), &(desc->pvoltag));
1039 if (flags & READ_ELEMENT_STATUS_AVOLTAG)
1040 copy_voltag(&(ces->ces_avoltag), &(desc->avoltag));
1042 if (desc->dt_scsi_flags & READ_ELEMENT_STATUS_DT_IDVALID) {
1043 ces->ces_flags |= CES_SCSIID_VALID;
1044 ces->ces_scsi_id = desc->dt_scsi_addr;
1047 if (desc->dt_scsi_addr & READ_ELEMENT_STATUS_DT_LUVALID) {
1048 ces->ces_flags |= CES_LUN_VALID;
1050 desc->dt_scsi_flags & READ_ELEMENT_STATUS_DT_LUNMASK;
1055 chgetelemstatus(struct cam_periph *periph,
1056 struct changer_element_status_request *cesr)
1058 struct read_element_status_header *st_hdr;
1059 struct read_element_status_page_header *pg_hdr;
1060 struct read_element_status_descriptor *desc;
1061 caddr_t data = NULL;
1062 size_t size, desclen;
1063 int avail, i, error = 0;
1064 struct changer_element_status *user_data = NULL;
1065 struct ch_softc *softc;
1067 int chet = cesr->cesr_element_type;
1068 int want_voltags = (cesr->cesr_flags & CESR_VOLTAGS) ? 1 : 0;
1070 softc = (struct ch_softc *)periph->softc;
1072 /* perform argument checking */
1075 * Perform a range check on the cesr_element_{base,count}
1076 * request argument fields.
1078 if ((softc->sc_counts[chet] - cesr->cesr_element_base) <= 0
1079 || (cesr->cesr_element_base + cesr->cesr_element_count)
1080 > softc->sc_counts[chet])
1084 * Request one descriptor for the given element type. This
1085 * is used to determine the size of the descriptor so that
1086 * we can allocate enough storage for all of them. We assume
1087 * that the first one can fit into 1k.
1089 cam_periph_unlock(periph);
1090 data = (caddr_t)malloc(1024, M_DEVBUF, M_WAITOK);
1092 cam_periph_lock(periph);
1093 ccb = cam_periph_getccb(periph, CAM_PRIORITY_NORMAL);
1095 scsi_read_element_status(&ccb->csio,
1097 /* cbfcnp */ chdone,
1098 /* tag_action */ MSG_SIMPLE_Q_TAG,
1099 /* voltag */ want_voltags,
1100 /* sea */ softc->sc_firsts[chet],
1102 /* data_ptr */ data,
1103 /* dxfer_len */ 1024,
1104 /* sense_len */ SSD_FULL_SIZE,
1105 /* timeout */ CH_TIMEOUT_READ_ELEMENT_STATUS);
1107 error = cam_periph_runccb(ccb, cherror, /*cam_flags*/ CAM_RETRY_SELTO,
1108 /*sense_flags*/ SF_RETRY_UA,
1109 softc->device_stats);
1113 cam_periph_unlock(periph);
1115 st_hdr = (struct read_element_status_header *)data;
1116 pg_hdr = (struct read_element_status_page_header *)((uintptr_t)st_hdr +
1117 sizeof(struct read_element_status_header));
1118 desclen = scsi_2btoul(pg_hdr->edl);
1120 size = sizeof(struct read_element_status_header) +
1121 sizeof(struct read_element_status_page_header) +
1122 (desclen * cesr->cesr_element_count);
1125 * Reallocate storage for descriptors and get them from the
1128 free(data, M_DEVBUF);
1129 data = (caddr_t)malloc(size, M_DEVBUF, M_WAITOK);
1131 cam_periph_lock(periph);
1132 scsi_read_element_status(&ccb->csio,
1134 /* cbfcnp */ chdone,
1135 /* tag_action */ MSG_SIMPLE_Q_TAG,
1136 /* voltag */ want_voltags,
1137 /* sea */ softc->sc_firsts[chet]
1138 + cesr->cesr_element_base,
1139 /* count */ cesr->cesr_element_count,
1140 /* data_ptr */ data,
1141 /* dxfer_len */ size,
1142 /* sense_len */ SSD_FULL_SIZE,
1143 /* timeout */ CH_TIMEOUT_READ_ELEMENT_STATUS);
1145 error = cam_periph_runccb(ccb, cherror, /*cam_flags*/ CAM_RETRY_SELTO,
1146 /*sense_flags*/ SF_RETRY_UA,
1147 softc->device_stats);
1151 cam_periph_unlock(periph);
1154 * Fill in the user status array.
1156 st_hdr = (struct read_element_status_header *)data;
1157 pg_hdr = (struct read_element_status_page_header *)((uintptr_t)st_hdr +
1158 sizeof(struct read_element_status_header));
1159 avail = scsi_2btoul(st_hdr->count);
1161 if (avail != cesr->cesr_element_count) {
1162 xpt_print(periph->path,
1163 "warning, READ ELEMENT STATUS avail != count\n");
1166 user_data = (struct changer_element_status *)
1167 malloc(avail * sizeof(struct changer_element_status),
1168 M_DEVBUF, M_WAITOK | M_ZERO);
1170 desc = (struct read_element_status_descriptor *)((uintptr_t)data +
1171 sizeof(struct read_element_status_header) +
1172 sizeof(struct read_element_status_page_header));
1174 * Set up the individual element status structures
1176 for (i = 0; i < avail; ++i) {
1177 struct changer_element_status *ces = &(user_data[i]);
1179 copy_element_status(softc, pg_hdr->flags, desc, ces);
1181 desc = (struct read_element_status_descriptor *)
1182 ((uintptr_t)desc + desclen);
1185 /* Copy element status structures out to userspace. */
1186 error = copyout(user_data,
1187 cesr->cesr_element_status,
1188 avail * sizeof(struct changer_element_status));
1189 cam_periph_lock(periph);
1192 xpt_release_ccb(ccb);
1195 free(data, M_DEVBUF);
1196 if (user_data != NULL)
1197 free(user_data, M_DEVBUF);
1203 chielem(struct cam_periph *periph,
1204 unsigned int timeout)
1207 struct ch_softc *softc;
1211 timeout = CH_TIMEOUT_INITIALIZE_ELEMENT_STATUS;
1217 softc = (struct ch_softc *)periph->softc;
1219 ccb = cam_periph_getccb(periph, CAM_PRIORITY_NORMAL);
1221 scsi_initialize_element_status(&ccb->csio,
1223 /* cbfcnp */ chdone,
1224 /* tag_action */ MSG_SIMPLE_Q_TAG,
1225 /* sense_len */ SSD_FULL_SIZE,
1226 /* timeout */ timeout);
1228 error = cam_periph_runccb(ccb, cherror, /*cam_flags*/ CAM_RETRY_SELTO,
1229 /*sense_flags*/ SF_RETRY_UA,
1230 softc->device_stats);
1232 xpt_release_ccb(ccb);
1238 chsetvoltag(struct cam_periph *periph,
1239 struct changer_set_voltag_request *csvr)
1242 struct ch_softc *softc;
1245 struct scsi_send_volume_tag_parameters ssvtp;
1250 softc = (struct ch_softc *)periph->softc;
1252 bzero(&ssvtp, sizeof(ssvtp));
1253 for (i=0; i<sizeof(ssvtp.vitf); i++) {
1254 ssvtp.vitf[i] = ' ';
1260 if (csvr->csvr_type > CHET_DT)
1262 if (csvr->csvr_addr > (softc->sc_counts[csvr->csvr_type] - 1))
1265 ea = softc->sc_firsts[csvr->csvr_type] + csvr->csvr_addr;
1267 if (csvr->csvr_flags & CSVR_ALTERNATE) {
1268 switch (csvr->csvr_flags & CSVR_MODE_MASK) {
1270 sac = SEND_VOLUME_TAG_ASSERT_ALTERNATE;
1272 case CSVR_MODE_REPLACE:
1273 sac = SEND_VOLUME_TAG_REPLACE_ALTERNATE;
1275 case CSVR_MODE_CLEAR:
1276 sac = SEND_VOLUME_TAG_UNDEFINED_ALTERNATE;
1283 switch (csvr->csvr_flags & CSVR_MODE_MASK) {
1285 sac = SEND_VOLUME_TAG_ASSERT_PRIMARY;
1287 case CSVR_MODE_REPLACE:
1288 sac = SEND_VOLUME_TAG_REPLACE_PRIMARY;
1290 case CSVR_MODE_CLEAR:
1291 sac = SEND_VOLUME_TAG_UNDEFINED_PRIMARY;
1299 memcpy(ssvtp.vitf, csvr->csvr_voltag.cv_volid,
1300 min(strlen(csvr->csvr_voltag.cv_volid), sizeof(ssvtp.vitf)));
1301 scsi_ulto2b(csvr->csvr_voltag.cv_serial, ssvtp.minvsn);
1303 ccb = cam_periph_getccb(periph, CAM_PRIORITY_NORMAL);
1305 scsi_send_volume_tag(&ccb->csio,
1307 /* cbfcnp */ chdone,
1308 /* tag_action */ MSG_SIMPLE_Q_TAG,
1309 /* element_address */ ea,
1310 /* send_action_code */ sac,
1311 /* parameters */ &ssvtp,
1312 /* sense_len */ SSD_FULL_SIZE,
1313 /* timeout */ CH_TIMEOUT_SEND_VOLTAG);
1315 error = cam_periph_runccb(ccb, cherror, /*cam_flags*/ CAM_RETRY_SELTO,
1316 /*sense_flags*/ SF_RETRY_UA,
1317 softc->device_stats);
1319 xpt_release_ccb(ccb);
1326 chgetparams(struct cam_periph *periph)
1329 struct ch_softc *softc;
1331 int mode_buffer_len;
1332 struct page_element_address_assignment *ea;
1333 struct page_device_capabilities *cap;
1334 int error, from, dbd;
1335 u_int8_t *moves, *exchanges;
1339 softc = (struct ch_softc *)periph->softc;
1341 ccb = cam_periph_getccb(periph, CAM_PRIORITY_NORMAL);
1344 * The scsi_mode_sense_data structure is just a convenience
1345 * structure that allows us to easily calculate the worst-case
1346 * storage size of the mode sense buffer.
1348 mode_buffer_len = sizeof(struct scsi_mode_sense_data);
1350 mode_buffer = malloc(mode_buffer_len, M_SCSICH, M_NOWAIT);
1352 if (mode_buffer == NULL) {
1353 printf("chgetparams: couldn't malloc mode sense data\n");
1357 bzero(mode_buffer, mode_buffer_len);
1359 if (softc->quirks & CH_Q_NO_DBD)
1365 * Get the element address assignment page.
1367 scsi_mode_sense(&ccb->csio,
1369 /* cbfcnp */ chdone,
1370 /* tag_action */ MSG_SIMPLE_Q_TAG,
1372 /* page_code */ SMS_PAGE_CTRL_CURRENT,
1373 /* page */ CH_ELEMENT_ADDR_ASSIGN_PAGE,
1374 /* param_buf */ (u_int8_t *)mode_buffer,
1375 /* param_len */ mode_buffer_len,
1376 /* sense_len */ SSD_FULL_SIZE,
1377 /* timeout */ CH_TIMEOUT_MODE_SENSE);
1379 error = cam_periph_runccb(ccb, cherror, /*cam_flags*/ CAM_RETRY_SELTO,
1380 /* sense_flags */ SF_RETRY_UA|SF_NO_PRINT,
1381 softc->device_stats);
1385 struct scsi_mode_sense_6 *sms;
1387 sms = (struct scsi_mode_sense_6 *)
1388 ccb->csio.cdb_io.cdb_bytes;
1390 sms->byte2 &= ~SMS_DBD;
1391 error = cam_periph_runccb(ccb, cherror,
1392 /*cam_flags*/ CAM_RETRY_SELTO,
1393 /*sense_flags*/ SF_RETRY_UA,
1394 softc->device_stats);
1397 * Since we disabled sense printing above, print
1398 * out the sense here since we got an error.
1400 scsi_sense_print(&ccb->csio);
1404 xpt_print(periph->path,
1405 "chgetparams: error getting element "
1407 xpt_release_ccb(ccb);
1408 free(mode_buffer, M_SCSICH);
1413 ea = (struct page_element_address_assignment *)
1414 find_mode_page_6((struct scsi_mode_header_6 *)mode_buffer);
1416 softc->sc_firsts[CHET_MT] = scsi_2btoul(ea->mtea);
1417 softc->sc_counts[CHET_MT] = scsi_2btoul(ea->nmte);
1418 softc->sc_firsts[CHET_ST] = scsi_2btoul(ea->fsea);
1419 softc->sc_counts[CHET_ST] = scsi_2btoul(ea->nse);
1420 softc->sc_firsts[CHET_IE] = scsi_2btoul(ea->fieea);
1421 softc->sc_counts[CHET_IE] = scsi_2btoul(ea->niee);
1422 softc->sc_firsts[CHET_DT] = scsi_2btoul(ea->fdtea);
1423 softc->sc_counts[CHET_DT] = scsi_2btoul(ea->ndte);
1425 bzero(mode_buffer, mode_buffer_len);
1428 * Now get the device capabilities page.
1430 scsi_mode_sense(&ccb->csio,
1432 /* cbfcnp */ chdone,
1433 /* tag_action */ MSG_SIMPLE_Q_TAG,
1435 /* page_code */ SMS_PAGE_CTRL_CURRENT,
1436 /* page */ CH_DEVICE_CAP_PAGE,
1437 /* param_buf */ (u_int8_t *)mode_buffer,
1438 /* param_len */ mode_buffer_len,
1439 /* sense_len */ SSD_FULL_SIZE,
1440 /* timeout */ CH_TIMEOUT_MODE_SENSE);
1442 error = cam_periph_runccb(ccb, cherror, /*cam_flags*/ CAM_RETRY_SELTO,
1443 /* sense_flags */ SF_RETRY_UA | SF_NO_PRINT,
1444 softc->device_stats);
1448 struct scsi_mode_sense_6 *sms;
1450 sms = (struct scsi_mode_sense_6 *)
1451 ccb->csio.cdb_io.cdb_bytes;
1453 sms->byte2 &= ~SMS_DBD;
1454 error = cam_periph_runccb(ccb, cherror,
1455 /*cam_flags*/ CAM_RETRY_SELTO,
1456 /*sense_flags*/ SF_RETRY_UA,
1457 softc->device_stats);
1460 * Since we disabled sense printing above, print
1461 * out the sense here since we got an error.
1463 scsi_sense_print(&ccb->csio);
1467 xpt_print(periph->path,
1468 "chgetparams: error getting device "
1469 "capabilities page\n");
1470 xpt_release_ccb(ccb);
1471 free(mode_buffer, M_SCSICH);
1476 xpt_release_ccb(ccb);
1478 cap = (struct page_device_capabilities *)
1479 find_mode_page_6((struct scsi_mode_header_6 *)mode_buffer);
1481 bzero(softc->sc_movemask, sizeof(softc->sc_movemask));
1482 bzero(softc->sc_exchangemask, sizeof(softc->sc_exchangemask));
1483 moves = cap->move_from;
1484 exchanges = cap->exchange_with;
1485 for (from = CHET_MT; from <= CHET_MAX; ++from) {
1486 softc->sc_movemask[from] = moves[from];
1487 softc->sc_exchangemask[from] = exchanges[from];
1490 free(mode_buffer, M_SCSICH);
1496 scsi_move_medium(struct ccb_scsiio *csio, u_int32_t retries,
1497 void (*cbfcnp)(struct cam_periph *, union ccb *),
1498 u_int8_t tag_action, u_int32_t tea, u_int32_t src,
1499 u_int32_t dst, int invert, u_int8_t sense_len,
1502 struct scsi_move_medium *scsi_cmd;
1504 scsi_cmd = (struct scsi_move_medium *)&csio->cdb_io.cdb_bytes;
1505 bzero(scsi_cmd, sizeof(*scsi_cmd));
1507 scsi_cmd->opcode = MOVE_MEDIUM;
1509 scsi_ulto2b(tea, scsi_cmd->tea);
1510 scsi_ulto2b(src, scsi_cmd->src);
1511 scsi_ulto2b(dst, scsi_cmd->dst);
1514 scsi_cmd->invert |= MOVE_MEDIUM_INVERT;
1519 /*flags*/ CAM_DIR_NONE,
1529 scsi_exchange_medium(struct ccb_scsiio *csio, u_int32_t retries,
1530 void (*cbfcnp)(struct cam_periph *, union ccb *),
1531 u_int8_t tag_action, u_int32_t tea, u_int32_t src,
1532 u_int32_t dst1, u_int32_t dst2, int invert1,
1533 int invert2, u_int8_t sense_len, u_int32_t timeout)
1535 struct scsi_exchange_medium *scsi_cmd;
1537 scsi_cmd = (struct scsi_exchange_medium *)&csio->cdb_io.cdb_bytes;
1538 bzero(scsi_cmd, sizeof(*scsi_cmd));
1540 scsi_cmd->opcode = EXCHANGE_MEDIUM;
1542 scsi_ulto2b(tea, scsi_cmd->tea);
1543 scsi_ulto2b(src, scsi_cmd->src);
1544 scsi_ulto2b(dst1, scsi_cmd->fdst);
1545 scsi_ulto2b(dst2, scsi_cmd->sdst);
1548 scsi_cmd->invert |= EXCHANGE_MEDIUM_INV1;
1551 scsi_cmd->invert |= EXCHANGE_MEDIUM_INV2;
1556 /*flags*/ CAM_DIR_NONE,
1566 scsi_position_to_element(struct ccb_scsiio *csio, u_int32_t retries,
1567 void (*cbfcnp)(struct cam_periph *, union ccb *),
1568 u_int8_t tag_action, u_int32_t tea, u_int32_t dst,
1569 int invert, u_int8_t sense_len, u_int32_t timeout)
1571 struct scsi_position_to_element *scsi_cmd;
1573 scsi_cmd = (struct scsi_position_to_element *)&csio->cdb_io.cdb_bytes;
1574 bzero(scsi_cmd, sizeof(*scsi_cmd));
1576 scsi_cmd->opcode = POSITION_TO_ELEMENT;
1578 scsi_ulto2b(tea, scsi_cmd->tea);
1579 scsi_ulto2b(dst, scsi_cmd->dst);
1582 scsi_cmd->invert |= POSITION_TO_ELEMENT_INVERT;
1587 /*flags*/ CAM_DIR_NONE,
1597 scsi_read_element_status(struct ccb_scsiio *csio, u_int32_t retries,
1598 void (*cbfcnp)(struct cam_periph *, union ccb *),
1599 u_int8_t tag_action, int voltag, u_int32_t sea,
1600 u_int32_t count, u_int8_t *data_ptr,
1601 u_int32_t dxfer_len, u_int8_t sense_len,
1604 struct scsi_read_element_status *scsi_cmd;
1606 scsi_cmd = (struct scsi_read_element_status *)&csio->cdb_io.cdb_bytes;
1607 bzero(scsi_cmd, sizeof(*scsi_cmd));
1609 scsi_cmd->opcode = READ_ELEMENT_STATUS;
1611 scsi_ulto2b(sea, scsi_cmd->sea);
1612 scsi_ulto2b(count, scsi_cmd->count);
1613 scsi_ulto3b(dxfer_len, scsi_cmd->len);
1616 scsi_cmd->byte2 |= READ_ELEMENT_STATUS_VOLTAG;
1621 /*flags*/ CAM_DIR_IN,
1631 scsi_initialize_element_status(struct ccb_scsiio *csio, u_int32_t retries,
1632 void (*cbfcnp)(struct cam_periph *, union ccb *),
1633 u_int8_t tag_action, u_int8_t sense_len,
1636 struct scsi_initialize_element_status *scsi_cmd;
1638 scsi_cmd = (struct scsi_initialize_element_status *)
1639 &csio->cdb_io.cdb_bytes;
1640 bzero(scsi_cmd, sizeof(*scsi_cmd));
1642 scsi_cmd->opcode = INITIALIZE_ELEMENT_STATUS;
1647 /*flags*/ CAM_DIR_NONE,
1649 /* data_ptr */ NULL,
1657 scsi_send_volume_tag(struct ccb_scsiio *csio, u_int32_t retries,
1658 void (*cbfcnp)(struct cam_periph *, union ccb *),
1659 u_int8_t tag_action,
1660 u_int16_t element_address,
1661 u_int8_t send_action_code,
1662 struct scsi_send_volume_tag_parameters *parameters,
1663 u_int8_t sense_len, u_int32_t timeout)
1665 struct scsi_send_volume_tag *scsi_cmd;
1667 scsi_cmd = (struct scsi_send_volume_tag *) &csio->cdb_io.cdb_bytes;
1668 bzero(scsi_cmd, sizeof(*scsi_cmd));
1670 scsi_cmd->opcode = SEND_VOLUME_TAG;
1671 scsi_ulto2b(element_address, scsi_cmd->ea);
1672 scsi_cmd->sac = send_action_code;
1673 scsi_ulto2b(sizeof(*parameters), scsi_cmd->pll);
1678 /*flags*/ CAM_DIR_OUT,
1680 /* data_ptr */ (u_int8_t *) parameters,
1681 sizeof(*parameters),