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.11 2005/06/02 20:40:31 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>
85 #include <sys/thread2.h>
88 #include "../cam_ccb.h"
89 #include "../cam_extend.h"
90 #include "../cam_periph.h"
91 #include "../cam_xpt_periph.h"
92 #include "../cam_queue.h"
93 #include "../cam_debug.h"
96 #include "scsi_message.h"
100 * Timeout definitions for various changer related commands. They may
101 * be too short for some devices (especially the timeout for INITIALIZE
105 static const u_int32_t CH_TIMEOUT_MODE_SENSE = 6000;
106 static const u_int32_t CH_TIMEOUT_MOVE_MEDIUM = 100000;
107 static const u_int32_t CH_TIMEOUT_EXCHANGE_MEDIUM = 100000;
108 static const u_int32_t CH_TIMEOUT_POSITION_TO_ELEMENT = 100000;
109 static const u_int32_t CH_TIMEOUT_READ_ELEMENT_STATUS = 10000;
110 static const u_int32_t CH_TIMEOUT_SEND_VOLTAG = 10000;
111 static const u_int32_t CH_TIMEOUT_INITIALIZE_ELEMENT_STATUS = 500000;
114 CH_FLAG_INVALID = 0x001,
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;
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 = {
220 /* maj */ CH_CDEV_MAJOR,
232 /* strategy */ nostrategy,
237 static struct extend_array *chperiphs;
243 struct cam_path *path;
246 * Create our extend array for storing the devices we attach to.
248 chperiphs = cam_extend_new();
249 if (chperiphs == NULL) {
250 printf("ch: Failed to alloc extend array!\n");
255 * Install a global async callback. This callback will
256 * receive async callbacks like "new device found".
258 status = xpt_create_path(&path, /*periph*/NULL, CAM_XPT_PATH_ID,
259 CAM_TARGET_WILDCARD, CAM_LUN_WILDCARD);
261 if (status == CAM_REQ_CMP) {
262 struct ccb_setasync csa;
264 xpt_setup_ccb(&csa.ccb_h, path, /*priority*/5);
265 csa.ccb_h.func_code = XPT_SASYNC_CB;
266 csa.event_enable = AC_FOUND_DEVICE;
267 csa.callback = chasync;
268 csa.callback_arg = NULL;
269 xpt_action((union ccb *)&csa);
270 status = csa.ccb_h.status;
274 if (status != CAM_REQ_CMP) {
275 printf("ch: Failed to attach master async callback "
276 "due to status 0x%x!\n", status);
281 choninvalidate(struct cam_periph *periph)
283 struct ch_softc *softc;
284 struct ccb_setasync csa;
286 softc = (struct ch_softc *)periph->softc;
289 * De-register any async callbacks.
291 xpt_setup_ccb(&csa.ccb_h, periph->path,
293 csa.ccb_h.func_code = XPT_SASYNC_CB;
294 csa.event_enable = 0;
295 csa.callback = chasync;
296 csa.callback_arg = periph;
297 xpt_action((union ccb *)&csa);
299 softc->flags |= CH_FLAG_INVALID;
301 xpt_print_path(periph->path);
302 printf("lost device\n");
307 chcleanup(struct cam_periph *periph)
309 struct ch_softc *softc;
311 softc = (struct ch_softc *)periph->softc;
313 devstat_remove_entry(&softc->device_stats);
314 cam_extend_release(chperiphs, periph->unit_number);
315 xpt_print_path(periph->path);
316 printf("removing device entry\n");
317 cdevsw_remove(&ch_cdevsw, -1, periph->unit_number);
318 free(softc, M_DEVBUF);
322 chasync(void *callback_arg, u_int32_t code, struct cam_path *path, void *arg)
324 struct cam_periph *periph;
326 periph = (struct cam_periph *)callback_arg;
329 case AC_FOUND_DEVICE:
331 struct ccb_getdev *cgd;
334 cgd = (struct ccb_getdev *)arg;
336 if (SID_TYPE(&cgd->inq_data)!= T_CHANGER)
340 * Allocate a peripheral instance for
341 * this device and start the probe
344 status = cam_periph_alloc(chregister, choninvalidate,
345 chcleanup, chstart, "ch",
346 CAM_PERIPH_BIO, cgd->ccb_h.path,
347 chasync, AC_FOUND_DEVICE, cgd);
349 if (status != CAM_REQ_CMP
350 && status != CAM_REQ_INPROG)
351 printf("chasync: Unable to probe new device "
352 "due to status 0x%x\n", status);
358 cam_periph_async(periph, code, path, arg);
364 chregister(struct cam_periph *periph, void *arg)
366 struct ch_softc *softc;
367 struct ccb_setasync csa;
368 struct ccb_getdev *cgd;
370 cgd = (struct ccb_getdev *)arg;
371 if (periph == NULL) {
372 printf("chregister: periph was NULL!!\n");
373 return(CAM_REQ_CMP_ERR);
377 printf("chregister: no getdev CCB, can't register device\n");
378 return(CAM_REQ_CMP_ERR);
381 softc = malloc(sizeof(*softc), M_DEVBUF, M_INTWAIT | M_ZERO);
382 softc->state = CH_STATE_PROBE;
383 periph->softc = softc;
384 cam_extend_set(chperiphs, periph->unit_number, periph);
385 softc->quirks = CH_Q_NONE;
388 * Changers don't have a blocksize, and obviously don't support
391 devstat_add_entry(&softc->device_stats, "ch",
392 periph->unit_number, 0,
393 DEVSTAT_NO_BLOCKSIZE | DEVSTAT_NO_ORDERED_TAGS,
394 SID_TYPE(&cgd->inq_data)| DEVSTAT_TYPE_IF_SCSI,
395 DEVSTAT_PRIORITY_OTHER);
397 /* Register the device */
398 cdevsw_add(&ch_cdevsw, -1, periph->unit_number);
399 make_dev(&ch_cdevsw, periph->unit_number, UID_ROOT,
400 GID_OPERATOR, 0600, "%s%d", periph->periph_name,
401 periph->unit_number);
404 * Add an async callback so that we get
405 * notified if this device goes away.
407 xpt_setup_ccb(&csa.ccb_h, periph->path, /* priority */ 5);
408 csa.ccb_h.func_code = XPT_SASYNC_CB;
409 csa.event_enable = AC_LOST_DEVICE;
410 csa.callback = chasync;
411 csa.callback_arg = periph;
412 xpt_action((union ccb *)&csa);
415 * Lock this peripheral until we are setup.
416 * This first call can't block
418 (void)cam_periph_lock(periph, 0);
419 xpt_schedule(periph, /*priority*/5);
425 chopen(dev_t dev, int flags, int fmt, struct thread *td)
427 struct cam_periph *periph;
428 struct ch_softc *softc;
432 periph = cam_extend_get(chperiphs, unit);
437 softc = (struct ch_softc *)periph->softc;
440 if (softc->flags & CH_FLAG_INVALID) {
445 if ((error = cam_periph_lock(periph, PCATCH)) != 0) {
452 if ((softc->flags & CH_FLAG_OPEN) == 0) {
453 if (cam_periph_acquire(periph) != CAM_REQ_CMP)
455 softc->flags |= CH_FLAG_OPEN;
459 * Load information about this changer device into the softc.
461 if ((error = chgetparams(periph)) != 0) {
462 softc->flags &= ~CH_FLAG_OPEN;
463 cam_periph_unlock(periph);
464 cam_periph_release(periph);
468 cam_periph_unlock(periph);
474 chclose(dev_t dev, int flag, int fmt, struct thread *td)
476 struct cam_periph *periph;
477 struct ch_softc *softc;
483 periph = cam_extend_get(chperiphs, unit);
487 softc = (struct ch_softc *)periph->softc;
489 if ((error = cam_periph_lock(periph, 0)) != 0)
492 softc->flags &= ~CH_FLAG_OPEN;
494 cam_periph_unlock(periph);
495 cam_periph_release(periph);
501 chstart(struct cam_periph *periph, union ccb *start_ccb)
503 struct ch_softc *softc;
505 softc = (struct ch_softc *)periph->softc;
507 switch (softc->state) {
508 case CH_STATE_NORMAL:
511 if (periph->immediate_priority <= periph->pinfo.priority){
512 start_ccb->ccb_h.ccb_state = CH_CCB_WAITING;
514 SLIST_INSERT_HEAD(&periph->ccb_list, &start_ccb->ccb_h,
516 periph->immediate_priority = CAM_PRIORITY_NONE;
517 wakeup(&periph->ccb_list);
528 * Include the block descriptor when calculating the mode
531 mode_buffer_len = sizeof(struct scsi_mode_header_6) +
532 sizeof(struct scsi_mode_blk_desc) +
533 sizeof(struct page_element_address_assignment);
535 mode_buffer = malloc(mode_buffer_len, M_TEMP, M_INTWAIT | M_ZERO);
537 * Get the element address assignment page.
539 scsi_mode_sense(&start_ccb->csio,
542 /* tag_action */ MSG_SIMPLE_Q_TAG,
543 /* dbd */ (softc->quirks & CH_Q_NO_DBD) ?
545 /* page_code */ SMS_PAGE_CTRL_CURRENT,
546 /* page */ CH_ELEMENT_ADDR_ASSIGN_PAGE,
547 /* param_buf */ (u_int8_t *)mode_buffer,
548 /* param_len */ mode_buffer_len,
549 /* sense_len */ SSD_FULL_SIZE,
550 /* timeout */ CH_TIMEOUT_MODE_SENSE);
552 start_ccb->ccb_h.ccb_bp = NULL;
553 start_ccb->ccb_h.ccb_state = CH_CCB_PROBE;
554 xpt_action(start_ccb);
561 chdone(struct cam_periph *periph, union ccb *done_ccb)
563 struct ch_softc *softc;
564 struct ccb_scsiio *csio;
566 softc = (struct ch_softc *)periph->softc;
567 csio = &done_ccb->csio;
569 switch(done_ccb->ccb_h.ccb_state) {
572 struct scsi_mode_header_6 *mode_header;
573 struct page_element_address_assignment *ea;
574 char announce_buf[80];
577 mode_header = (struct scsi_mode_header_6 *)csio->data_ptr;
579 ea = (struct page_element_address_assignment *)
580 find_mode_page_6(mode_header);
582 if ((done_ccb->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP){
584 softc->sc_firsts[CHET_MT] = scsi_2btoul(ea->mtea);
585 softc->sc_counts[CHET_MT] = scsi_2btoul(ea->nmte);
586 softc->sc_firsts[CHET_ST] = scsi_2btoul(ea->fsea);
587 softc->sc_counts[CHET_ST] = scsi_2btoul(ea->nse);
588 softc->sc_firsts[CHET_IE] = scsi_2btoul(ea->fieea);
589 softc->sc_counts[CHET_IE] = scsi_2btoul(ea->niee);
590 softc->sc_firsts[CHET_DT] = scsi_2btoul(ea->fdtea);
591 softc->sc_counts[CHET_DT] = scsi_2btoul(ea->ndte);
592 softc->sc_picker = softc->sc_firsts[CHET_MT];
594 #define PLURAL(c) (c) == 1 ? "" : "s"
595 snprintf(announce_buf, sizeof(announce_buf),
596 "%d slot%s, %d drive%s, "
597 "%d picker%s, %d portal%s",
598 softc->sc_counts[CHET_ST],
599 PLURAL(softc->sc_counts[CHET_ST]),
600 softc->sc_counts[CHET_DT],
601 PLURAL(softc->sc_counts[CHET_DT]),
602 softc->sc_counts[CHET_MT],
603 PLURAL(softc->sc_counts[CHET_MT]),
604 softc->sc_counts[CHET_IE],
605 PLURAL(softc->sc_counts[CHET_IE]));
610 error = cherror(done_ccb, 0, SF_RETRY_UA |
611 SF_NO_PRINT | SF_RETRY_SELTO);
613 * Retry any UNIT ATTENTION type errors. They
614 * are expected at boot.
616 if (error == ERESTART) {
618 * A retry was scheuled, so
622 } else if (error != 0) {
624 struct scsi_mode_sense_6 *sms;
626 sms = (struct scsi_mode_sense_6 *)
627 done_ccb->csio.cdb_io.cdb_bytes;
630 * Check to see if block descriptors were
631 * disabled. Some devices don't like that.
632 * We're taking advantage of the fact that
633 * the first few bytes of the 6 and 10 byte
634 * mode sense commands are the same. If
635 * block descriptors were disabled, enable
636 * them and re-send the command.
638 if (sms->byte2 & SMS_DBD) {
639 sms->byte2 &= ~SMS_DBD;
640 xpt_action(done_ccb);
641 softc->quirks |= CH_Q_NO_DBD;
646 /* Don't wedge this device's queue */
647 cam_release_devq(done_ccb->ccb_h.path,
656 if ((done_ccb->ccb_h.status & CAM_STATUS_MASK)
657 == CAM_SCSI_STATUS_ERROR)
658 scsi_sense_print(&done_ccb->csio);
660 xpt_print_path(periph->path);
661 printf("got CAM status %#x\n",
662 done_ccb->ccb_h.status);
664 xpt_print_path(periph->path);
665 printf("fatal error, failed to attach to"
668 cam_periph_invalidate(periph);
670 announce_buf[0] = '\0';
673 if (announce_buf[0] != '\0')
674 xpt_announce_periph(periph, announce_buf);
675 softc->state = CH_STATE_NORMAL;
676 free(mode_header, M_TEMP);
678 * Since our peripheral may be invalidated by an error
679 * above or an external event, we must release our CCB
680 * before releasing the probe lock on the peripheral.
681 * The peripheral will only go away once the last lock
682 * is removed, and we need it around for the CCB release
685 xpt_release_ccb(done_ccb);
686 cam_periph_unlock(periph);
691 /* Caller will release the CCB */
692 wakeup(&done_ccb->ccb_h.cbfcnp);
698 xpt_release_ccb(done_ccb);
702 cherror(union ccb *ccb, u_int32_t cam_flags, u_int32_t sense_flags)
704 struct ch_softc *softc;
705 struct cam_periph *periph;
707 periph = xpt_path_periph(ccb->ccb_h.path);
708 softc = (struct ch_softc *)periph->softc;
710 return (cam_periph_error(ccb, cam_flags, sense_flags,
715 chioctl(dev_t dev, u_long cmd, caddr_t addr, int flag, struct thread *td)
717 struct cam_periph *periph;
718 struct ch_softc *softc;
724 periph = cam_extend_get(chperiphs, unit);
728 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("entering chioctl\n"));
730 softc = (struct ch_softc *)periph->softc;
734 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE,
735 ("trying to do ioctl %#lx\n", cmd));
738 * If this command can change the device's state, we must
739 * have the device open for writing.
748 if ((flag & FWRITE) == 0)
754 error = chmove(periph, (struct changer_move *)addr);
758 error = chexchange(periph, (struct changer_exchange *)addr);
762 error = chposition(periph, (struct changer_position *)addr);
766 *(int *)addr = softc->sc_picker - softc->sc_firsts[CHET_MT];
771 int new_picker = *(int *)addr;
773 if (new_picker > (softc->sc_counts[CHET_MT] - 1))
775 softc->sc_picker = softc->sc_firsts[CHET_MT] + new_picker;
780 struct changer_params *cp = (struct changer_params *)addr;
782 cp->cp_npickers = softc->sc_counts[CHET_MT];
783 cp->cp_nslots = softc->sc_counts[CHET_ST];
784 cp->cp_nportals = softc->sc_counts[CHET_IE];
785 cp->cp_ndrives = softc->sc_counts[CHET_DT];
789 error = chielem(periph, *(unsigned int *)addr);
794 error = chgetelemstatus(periph,
795 (struct changer_element_status_request *) addr);
801 error = chsetvoltag(periph,
802 (struct changer_set_voltag_request *) addr);
806 /* Implement prevent/allow? */
809 error = cam_periph_ioctl(periph, cmd, addr, cherror);
817 chmove(struct cam_periph *periph, struct changer_move *cm)
819 struct ch_softc *softc;
820 u_int16_t fromelem, toelem;
825 softc = (struct ch_softc *)periph->softc;
830 if ((cm->cm_fromtype > CHET_DT) || (cm->cm_totype > CHET_DT))
832 if ((cm->cm_fromunit > (softc->sc_counts[cm->cm_fromtype] - 1)) ||
833 (cm->cm_tounit > (softc->sc_counts[cm->cm_totype] - 1)))
837 * Check the request against the changer's capabilities.
839 if ((softc->sc_movemask[cm->cm_fromtype] & (1 << cm->cm_totype)) == 0)
843 * Calculate the source and destination elements.
845 fromelem = softc->sc_firsts[cm->cm_fromtype] + cm->cm_fromunit;
846 toelem = softc->sc_firsts[cm->cm_totype] + cm->cm_tounit;
848 ccb = cam_periph_getccb(periph, /*priority*/ 1);
850 scsi_move_medium(&ccb->csio,
853 /* tag_action */ MSG_SIMPLE_Q_TAG,
854 /* tea */ softc->sc_picker,
857 /* invert */ (cm->cm_flags & CM_INVERT) ? TRUE : FALSE,
858 /* sense_len */ SSD_FULL_SIZE,
859 /* timeout */ CH_TIMEOUT_MOVE_MEDIUM);
861 error = cam_periph_runccb(ccb, cherror, /*cam_flags*/0,
862 /*sense_flags*/ SF_RETRY_UA | SF_RETRY_SELTO,
863 &softc->device_stats);
865 xpt_release_ccb(ccb);
871 chexchange(struct cam_periph *periph, struct changer_exchange *ce)
873 struct ch_softc *softc;
874 u_int16_t src, dst1, dst2;
879 softc = (struct ch_softc *)periph->softc;
883 if ((ce->ce_srctype > CHET_DT) || (ce->ce_fdsttype > CHET_DT) ||
884 (ce->ce_sdsttype > CHET_DT))
886 if ((ce->ce_srcunit > (softc->sc_counts[ce->ce_srctype] - 1)) ||
887 (ce->ce_fdstunit > (softc->sc_counts[ce->ce_fdsttype] - 1)) ||
888 (ce->ce_sdstunit > (softc->sc_counts[ce->ce_sdsttype] - 1)))
892 * Check the request against the changer's capabilities.
894 if (((softc->sc_exchangemask[ce->ce_srctype] &
895 (1 << ce->ce_fdsttype)) == 0) ||
896 ((softc->sc_exchangemask[ce->ce_fdsttype] &
897 (1 << ce->ce_sdsttype)) == 0))
901 * Calculate the source and destination elements.
903 src = softc->sc_firsts[ce->ce_srctype] + ce->ce_srcunit;
904 dst1 = softc->sc_firsts[ce->ce_fdsttype] + ce->ce_fdstunit;
905 dst2 = softc->sc_firsts[ce->ce_sdsttype] + ce->ce_sdstunit;
907 ccb = cam_periph_getccb(periph, /*priority*/ 1);
909 scsi_exchange_medium(&ccb->csio,
912 /* tag_action */ MSG_SIMPLE_Q_TAG,
913 /* tea */ softc->sc_picker,
917 /* invert1 */ (ce->ce_flags & CE_INVERT1) ?
919 /* invert2 */ (ce->ce_flags & CE_INVERT2) ?
921 /* sense_len */ SSD_FULL_SIZE,
922 /* timeout */ CH_TIMEOUT_EXCHANGE_MEDIUM);
924 error = cam_periph_runccb(ccb, cherror, /*cam_flags*/0,
925 /*sense_flags*/ SF_RETRY_UA | SF_RETRY_SELTO,
926 &softc->device_stats);
928 xpt_release_ccb(ccb);
934 chposition(struct cam_periph *periph, struct changer_position *cp)
936 struct ch_softc *softc;
942 softc = (struct ch_softc *)periph->softc;
947 if (cp->cp_type > CHET_DT)
949 if (cp->cp_unit > (softc->sc_counts[cp->cp_type] - 1))
953 * Calculate the destination element.
955 dst = softc->sc_firsts[cp->cp_type] + cp->cp_unit;
957 ccb = cam_periph_getccb(periph, /*priority*/ 1);
959 scsi_position_to_element(&ccb->csio,
962 /* tag_action */ MSG_SIMPLE_Q_TAG,
963 /* tea */ softc->sc_picker,
965 /* invert */ (cp->cp_flags & CP_INVERT) ?
967 /* sense_len */ SSD_FULL_SIZE,
968 /* timeout */ CH_TIMEOUT_POSITION_TO_ELEMENT);
970 error = cam_periph_runccb(ccb, cherror, /*cam_flags*/ 0,
971 /*sense_flags*/ SF_RETRY_UA | SF_RETRY_SELTO,
972 &softc->device_stats);
974 xpt_release_ccb(ccb);
980 * Copy a volume tag to a volume_tag struct, converting SCSI byte order
981 * to host native byte order in the volume serial number. The volume
982 * label as returned by the changer is transferred to user mode as
983 * nul-terminated string. Volume labels are truncated at the first
984 * space, as suggested by SCSI-2.
987 copy_voltag(struct changer_voltag *uvoltag, struct volume_tag *voltag)
990 for (i=0; i<CH_VOLTAG_MAXLEN; i++) {
991 char c = voltag->vif[i];
993 uvoltag->cv_volid[i] = c;
997 uvoltag->cv_serial = scsi_2btoul(voltag->vsn);
1001 * Copy an an element status descriptor to a user-mode
1002 * changer_element_status structure.
1006 copy_element_status(struct ch_softc *softc,
1008 struct read_element_status_descriptor *desc,
1009 struct changer_element_status *ces)
1011 u_int16_t eaddr = scsi_2btoul(desc->eaddr);
1014 ces->ces_int_addr = eaddr;
1015 /* set up logical address in element status */
1016 for (et = CHET_MT; et <= CHET_DT; et++) {
1017 if ((softc->sc_firsts[et] <= eaddr)
1018 && ((softc->sc_firsts[et] + softc->sc_counts[et])
1020 ces->ces_addr = eaddr - softc->sc_firsts[et];
1026 ces->ces_flags = desc->flags1;
1028 ces->ces_sensecode = desc->sense_code;
1029 ces->ces_sensequal = desc->sense_qual;
1031 if (desc->flags2 & READ_ELEMENT_STATUS_INVERT)
1032 ces->ces_flags |= CES_INVERT;
1034 if (desc->flags2 & READ_ELEMENT_STATUS_SVALID) {
1036 eaddr = scsi_2btoul(desc->ssea);
1038 /* convert source address to logical format */
1039 for (et = CHET_MT; et <= CHET_DT; et++) {
1040 if ((softc->sc_firsts[et] <= eaddr)
1041 && ((softc->sc_firsts[et] + softc->sc_counts[et])
1043 ces->ces_source_addr =
1044 eaddr - softc->sc_firsts[et];
1045 ces->ces_source_type = et;
1046 ces->ces_flags |= CES_SOURCE_VALID;
1051 if (!(ces->ces_flags & CES_SOURCE_VALID))
1052 printf("ch: warning: could not map element source "
1053 "address %ud to a valid element type\n",
1058 if (flags & READ_ELEMENT_STATUS_PVOLTAG)
1059 copy_voltag(&(ces->ces_pvoltag), &(desc->pvoltag));
1060 if (flags & READ_ELEMENT_STATUS_AVOLTAG)
1061 copy_voltag(&(ces->ces_avoltag), &(desc->avoltag));
1063 if (desc->dt_scsi_flags & READ_ELEMENT_STATUS_DT_IDVALID) {
1064 ces->ces_flags |= CES_SCSIID_VALID;
1065 ces->ces_scsi_id = desc->dt_scsi_addr;
1068 if (desc->dt_scsi_addr & READ_ELEMENT_STATUS_DT_LUVALID) {
1069 ces->ces_flags |= CES_LUN_VALID;
1071 desc->dt_scsi_flags & READ_ELEMENT_STATUS_DT_LUNMASK;
1076 chgetelemstatus(struct cam_periph *periph,
1077 struct changer_element_status_request *cesr)
1079 struct read_element_status_header *st_hdr;
1080 struct read_element_status_page_header *pg_hdr;
1081 struct read_element_status_descriptor *desc;
1082 caddr_t data = NULL;
1083 size_t size, desclen;
1084 int avail, i, error = 0;
1085 struct changer_element_status *user_data = NULL;
1086 struct ch_softc *softc;
1088 int chet = cesr->cesr_element_type;
1089 int want_voltags = (cesr->cesr_flags & CESR_VOLTAGS) ? 1 : 0;
1091 softc = (struct ch_softc *)periph->softc;
1093 /* perform argument checking */
1096 * Perform a range check on the cesr_element_{base,count}
1097 * request argument fields.
1099 if ((softc->sc_counts[chet] - cesr->cesr_element_base) <= 0
1100 || (cesr->cesr_element_base + cesr->cesr_element_count)
1101 > softc->sc_counts[chet])
1105 * Request one descriptor for the given element type. This
1106 * is used to determine the size of the descriptor so that
1107 * we can allocate enough storage for all of them. We assume
1108 * that the first one can fit into 1k.
1110 data = (caddr_t)malloc(1024, M_DEVBUF, M_INTWAIT);
1112 ccb = cam_periph_getccb(periph, /*priority*/ 1);
1114 scsi_read_element_status(&ccb->csio,
1116 /* cbfcnp */ chdone,
1117 /* tag_action */ MSG_SIMPLE_Q_TAG,
1118 /* voltag */ want_voltags,
1119 /* sea */ softc->sc_firsts[chet],
1121 /* data_ptr */ data,
1122 /* dxfer_len */ 1024,
1123 /* sense_len */ SSD_FULL_SIZE,
1124 /* timeout */ CH_TIMEOUT_READ_ELEMENT_STATUS);
1126 error = cam_periph_runccb(ccb, cherror, /*cam_flags*/ 0,
1127 /*sense_flags*/ SF_RETRY_UA | SF_RETRY_SELTO,
1128 &softc->device_stats);
1133 st_hdr = (struct read_element_status_header *)data;
1134 pg_hdr = (struct read_element_status_page_header *)((uintptr_t)st_hdr +
1135 sizeof(struct read_element_status_header));
1136 desclen = scsi_2btoul(pg_hdr->edl);
1138 size = sizeof(struct read_element_status_header) +
1139 sizeof(struct read_element_status_page_header) +
1140 (desclen * cesr->cesr_element_count);
1143 * Reallocate storage for descriptors and get them from the
1146 free(data, M_DEVBUF);
1147 data = (caddr_t)malloc(size, M_DEVBUF, M_INTWAIT);
1149 scsi_read_element_status(&ccb->csio,
1151 /* cbfcnp */ chdone,
1152 /* tag_action */ MSG_SIMPLE_Q_TAG,
1153 /* voltag */ want_voltags,
1154 /* sea */ softc->sc_firsts[chet]
1155 + cesr->cesr_element_base,
1156 /* count */ cesr->cesr_element_count,
1157 /* data_ptr */ data,
1158 /* dxfer_len */ size,
1159 /* sense_len */ SSD_FULL_SIZE,
1160 /* timeout */ CH_TIMEOUT_READ_ELEMENT_STATUS);
1162 error = cam_periph_runccb(ccb, cherror, /*cam_flags*/ 0,
1163 /*sense_flags*/ SF_RETRY_UA | SF_RETRY_SELTO,
1164 &softc->device_stats);
1170 * Fill in the user status array.
1172 st_hdr = (struct read_element_status_header *)data;
1173 avail = scsi_2btoul(st_hdr->count);
1175 if (avail != cesr->cesr_element_count) {
1176 xpt_print_path(periph->path);
1177 printf("warning, READ ELEMENT STATUS avail != count\n");
1180 user_data = (struct changer_element_status *)
1181 malloc(avail * sizeof(struct changer_element_status),
1182 M_DEVBUF, M_INTWAIT | M_ZERO);
1184 desc = (struct read_element_status_descriptor *)((uintptr_t)data +
1185 sizeof(struct read_element_status_header) +
1186 sizeof(struct read_element_status_page_header));
1188 * Set up the individual element status structures
1190 for (i = 0; i < avail; ++i) {
1191 struct changer_element_status *ces = &(user_data[i]);
1193 copy_element_status(softc, pg_hdr->flags, desc, ces);
1195 desc = (struct read_element_status_descriptor *)
1196 ((uintptr_t)desc + desclen);
1199 /* Copy element status structures out to userspace. */
1200 error = copyout(user_data,
1201 cesr->cesr_element_status,
1202 avail * sizeof(struct changer_element_status));
1205 xpt_release_ccb(ccb);
1208 free(data, M_DEVBUF);
1209 if (user_data != NULL)
1210 free(user_data, M_DEVBUF);
1216 chielem(struct cam_periph *periph,
1217 unsigned int timeout)
1220 struct ch_softc *softc;
1224 timeout = CH_TIMEOUT_INITIALIZE_ELEMENT_STATUS;
1230 softc = (struct ch_softc *)periph->softc;
1232 ccb = cam_periph_getccb(periph, /*priority*/ 1);
1234 scsi_initialize_element_status(&ccb->csio,
1236 /* cbfcnp */ chdone,
1237 /* tag_action */ MSG_SIMPLE_Q_TAG,
1238 /* sense_len */ SSD_FULL_SIZE,
1239 /* timeout */ timeout);
1241 error = cam_periph_runccb(ccb, cherror, /*cam_flags*/ 0,
1242 /*sense_flags*/ SF_RETRY_UA | SF_RETRY_SELTO,
1243 &softc->device_stats);
1245 xpt_release_ccb(ccb);
1251 chsetvoltag(struct cam_periph *periph,
1252 struct changer_set_voltag_request *csvr)
1255 struct ch_softc *softc;
1258 struct scsi_send_volume_tag_parameters ssvtp;
1263 softc = (struct ch_softc *)periph->softc;
1265 bzero(&ssvtp, sizeof(ssvtp));
1266 for (i=0; i<sizeof(ssvtp.vitf); i++) {
1267 ssvtp.vitf[i] = ' ';
1273 if (csvr->csvr_type > CHET_DT)
1275 if (csvr->csvr_addr > (softc->sc_counts[csvr->csvr_type] - 1))
1278 ea = softc->sc_firsts[csvr->csvr_type] + csvr->csvr_addr;
1280 if (csvr->csvr_flags & CSVR_ALTERNATE) {
1281 switch (csvr->csvr_flags & CSVR_MODE_MASK) {
1283 sac = SEND_VOLUME_TAG_ASSERT_ALTERNATE;
1285 case CSVR_MODE_REPLACE:
1286 sac = SEND_VOLUME_TAG_REPLACE_ALTERNATE;
1288 case CSVR_MODE_CLEAR:
1289 sac = SEND_VOLUME_TAG_UNDEFINED_ALTERNATE;
1296 switch (csvr->csvr_flags & CSVR_MODE_MASK) {
1298 sac = SEND_VOLUME_TAG_ASSERT_PRIMARY;
1300 case CSVR_MODE_REPLACE:
1301 sac = SEND_VOLUME_TAG_REPLACE_PRIMARY;
1303 case CSVR_MODE_CLEAR:
1304 sac = SEND_VOLUME_TAG_UNDEFINED_PRIMARY;
1312 memcpy(ssvtp.vitf, csvr->csvr_voltag.cv_volid,
1313 min(strlen(csvr->csvr_voltag.cv_volid), sizeof(ssvtp.vitf)));
1314 scsi_ulto2b(csvr->csvr_voltag.cv_serial, ssvtp.minvsn);
1316 ccb = cam_periph_getccb(periph, /*priority*/ 1);
1318 scsi_send_volume_tag(&ccb->csio,
1320 /* cbfcnp */ chdone,
1321 /* tag_action */ MSG_SIMPLE_Q_TAG,
1322 /* element_address */ ea,
1323 /* send_action_code */ sac,
1324 /* parameters */ &ssvtp,
1325 /* sense_len */ SSD_FULL_SIZE,
1326 /* timeout */ CH_TIMEOUT_SEND_VOLTAG);
1328 error = cam_periph_runccb(ccb, cherror, /*cam_flags*/ 0,
1329 /*sense_flags*/ SF_RETRY_UA | SF_RETRY_SELTO,
1330 &softc->device_stats);
1332 xpt_release_ccb(ccb);
1339 chgetparams(struct cam_periph *periph)
1342 struct ch_softc *softc;
1344 int mode_buffer_len;
1345 struct page_element_address_assignment *ea;
1346 struct page_device_capabilities *cap;
1347 int error, from, dbd;
1348 u_int8_t *moves, *exchanges;
1352 softc = (struct ch_softc *)periph->softc;
1354 ccb = cam_periph_getccb(periph, /*priority*/ 1);
1357 * The scsi_mode_sense_data structure is just a convenience
1358 * structure that allows us to easily calculate the worst-case
1359 * storage size of the mode sense buffer.
1361 mode_buffer_len = sizeof(struct scsi_mode_sense_data);
1363 mode_buffer = malloc(mode_buffer_len, M_TEMP, M_INTWAIT | M_ZERO);
1365 if (softc->quirks & CH_Q_NO_DBD)
1371 * Get the element address assignment page.
1373 scsi_mode_sense(&ccb->csio,
1375 /* cbfcnp */ chdone,
1376 /* tag_action */ MSG_SIMPLE_Q_TAG,
1378 /* page_code */ SMS_PAGE_CTRL_CURRENT,
1379 /* page */ CH_ELEMENT_ADDR_ASSIGN_PAGE,
1380 /* param_buf */ (u_int8_t *)mode_buffer,
1381 /* param_len */ mode_buffer_len,
1382 /* sense_len */ SSD_FULL_SIZE,
1383 /* timeout */ CH_TIMEOUT_MODE_SENSE);
1385 error = cam_periph_runccb(ccb, cherror, /*cam_flags*/ 0,
1386 /* sense_flags */ SF_RETRY_UA |
1387 SF_NO_PRINT | SF_RETRY_SELTO,
1388 &softc->device_stats);
1392 struct scsi_mode_sense_6 *sms;
1394 sms = (struct scsi_mode_sense_6 *)
1395 ccb->csio.cdb_io.cdb_bytes;
1397 sms->byte2 &= ~SMS_DBD;
1398 error = cam_periph_runccb(ccb, cherror, /*cam_flags*/ 0,
1399 /*sense_flags*/ SF_RETRY_UA |
1401 &softc->device_stats);
1404 * Since we disabled sense printing above, print
1405 * out the sense here since we got an error.
1407 scsi_sense_print(&ccb->csio);
1411 xpt_print_path(periph->path);
1412 printf("chgetparams: error getting element "
1414 xpt_release_ccb(ccb);
1415 free(mode_buffer, M_TEMP);
1420 ea = (struct page_element_address_assignment *)
1421 find_mode_page_6((struct scsi_mode_header_6 *)mode_buffer);
1423 softc->sc_firsts[CHET_MT] = scsi_2btoul(ea->mtea);
1424 softc->sc_counts[CHET_MT] = scsi_2btoul(ea->nmte);
1425 softc->sc_firsts[CHET_ST] = scsi_2btoul(ea->fsea);
1426 softc->sc_counts[CHET_ST] = scsi_2btoul(ea->nse);
1427 softc->sc_firsts[CHET_IE] = scsi_2btoul(ea->fieea);
1428 softc->sc_counts[CHET_IE] = scsi_2btoul(ea->niee);
1429 softc->sc_firsts[CHET_DT] = scsi_2btoul(ea->fdtea);
1430 softc->sc_counts[CHET_DT] = scsi_2btoul(ea->ndte);
1432 bzero(mode_buffer, mode_buffer_len);
1435 * Now get the device capabilities page.
1437 scsi_mode_sense(&ccb->csio,
1439 /* cbfcnp */ chdone,
1440 /* tag_action */ MSG_SIMPLE_Q_TAG,
1442 /* page_code */ SMS_PAGE_CTRL_CURRENT,
1443 /* page */ CH_DEVICE_CAP_PAGE,
1444 /* param_buf */ (u_int8_t *)mode_buffer,
1445 /* param_len */ mode_buffer_len,
1446 /* sense_len */ SSD_FULL_SIZE,
1447 /* timeout */ CH_TIMEOUT_MODE_SENSE);
1449 error = cam_periph_runccb(ccb, cherror, /*cam_flags*/ 0,
1450 /* sense_flags */ SF_RETRY_UA | SF_NO_PRINT |
1451 SF_RETRY_SELTO, &softc->device_stats);
1455 struct scsi_mode_sense_6 *sms;
1457 sms = (struct scsi_mode_sense_6 *)
1458 ccb->csio.cdb_io.cdb_bytes;
1460 sms->byte2 &= ~SMS_DBD;
1461 error = cam_periph_runccb(ccb, cherror, /*cam_flags*/ 0,
1462 /*sense_flags*/ SF_RETRY_UA |
1464 &softc->device_stats);
1467 * Since we disabled sense printing above, print
1468 * out the sense here since we got an error.
1470 scsi_sense_print(&ccb->csio);
1474 xpt_print_path(periph->path);
1475 printf("chgetparams: error getting device "
1476 "capabilities page\n");
1477 xpt_release_ccb(ccb);
1478 free(mode_buffer, M_TEMP);
1483 xpt_release_ccb(ccb);
1485 cap = (struct page_device_capabilities *)
1486 find_mode_page_6((struct scsi_mode_header_6 *)mode_buffer);
1488 bzero(softc->sc_movemask, sizeof(softc->sc_movemask));
1489 bzero(softc->sc_exchangemask, sizeof(softc->sc_exchangemask));
1490 moves = &cap->move_from_mt;
1491 exchanges = &cap->exchange_with_mt;
1492 for (from = CHET_MT; from <= CHET_DT; ++from) {
1493 softc->sc_movemask[from] = moves[from];
1494 softc->sc_exchangemask[from] = exchanges[from];
1497 free(mode_buffer, M_TEMP);
1503 scsi_move_medium(struct ccb_scsiio *csio, u_int32_t retries,
1504 void (*cbfcnp)(struct cam_periph *, union ccb *),
1505 u_int8_t tag_action, u_int32_t tea, u_int32_t src,
1506 u_int32_t dst, int invert, u_int8_t sense_len,
1509 struct scsi_move_medium *scsi_cmd;
1511 scsi_cmd = (struct scsi_move_medium *)&csio->cdb_io.cdb_bytes;
1512 bzero(scsi_cmd, sizeof(*scsi_cmd));
1514 scsi_cmd->opcode = MOVE_MEDIUM;
1516 scsi_ulto2b(tea, scsi_cmd->tea);
1517 scsi_ulto2b(src, scsi_cmd->src);
1518 scsi_ulto2b(dst, scsi_cmd->dst);
1521 scsi_cmd->invert |= MOVE_MEDIUM_INVERT;
1526 /*flags*/ CAM_DIR_NONE,
1536 scsi_exchange_medium(struct ccb_scsiio *csio, u_int32_t retries,
1537 void (*cbfcnp)(struct cam_periph *, union ccb *),
1538 u_int8_t tag_action, u_int32_t tea, u_int32_t src,
1539 u_int32_t dst1, u_int32_t dst2, int invert1,
1540 int invert2, u_int8_t sense_len, u_int32_t timeout)
1542 struct scsi_exchange_medium *scsi_cmd;
1544 scsi_cmd = (struct scsi_exchange_medium *)&csio->cdb_io.cdb_bytes;
1545 bzero(scsi_cmd, sizeof(*scsi_cmd));
1547 scsi_cmd->opcode = EXCHANGE_MEDIUM;
1549 scsi_ulto2b(tea, scsi_cmd->tea);
1550 scsi_ulto2b(src, scsi_cmd->src);
1551 scsi_ulto2b(dst1, scsi_cmd->fdst);
1552 scsi_ulto2b(dst2, scsi_cmd->sdst);
1555 scsi_cmd->invert |= EXCHANGE_MEDIUM_INV1;
1558 scsi_cmd->invert |= EXCHANGE_MEDIUM_INV2;
1563 /*flags*/ CAM_DIR_NONE,
1573 scsi_position_to_element(struct ccb_scsiio *csio, u_int32_t retries,
1574 void (*cbfcnp)(struct cam_periph *, union ccb *),
1575 u_int8_t tag_action, u_int32_t tea, u_int32_t dst,
1576 int invert, u_int8_t sense_len, u_int32_t timeout)
1578 struct scsi_position_to_element *scsi_cmd;
1580 scsi_cmd = (struct scsi_position_to_element *)&csio->cdb_io.cdb_bytes;
1581 bzero(scsi_cmd, sizeof(*scsi_cmd));
1583 scsi_cmd->opcode = POSITION_TO_ELEMENT;
1585 scsi_ulto2b(tea, scsi_cmd->tea);
1586 scsi_ulto2b(dst, scsi_cmd->dst);
1589 scsi_cmd->invert |= POSITION_TO_ELEMENT_INVERT;
1594 /*flags*/ CAM_DIR_NONE,
1604 scsi_read_element_status(struct ccb_scsiio *csio, u_int32_t retries,
1605 void (*cbfcnp)(struct cam_periph *, union ccb *),
1606 u_int8_t tag_action, int voltag, u_int32_t sea,
1607 u_int32_t count, u_int8_t *data_ptr,
1608 u_int32_t dxfer_len, u_int8_t sense_len,
1611 struct scsi_read_element_status *scsi_cmd;
1613 scsi_cmd = (struct scsi_read_element_status *)&csio->cdb_io.cdb_bytes;
1614 bzero(scsi_cmd, sizeof(*scsi_cmd));
1616 scsi_cmd->opcode = READ_ELEMENT_STATUS;
1618 scsi_ulto2b(sea, scsi_cmd->sea);
1619 scsi_ulto2b(count, scsi_cmd->count);
1620 scsi_ulto3b(dxfer_len, scsi_cmd->len);
1623 scsi_cmd->byte2 |= READ_ELEMENT_STATUS_VOLTAG;
1628 /*flags*/ CAM_DIR_IN,
1638 scsi_initialize_element_status(struct ccb_scsiio *csio, u_int32_t retries,
1639 void (*cbfcnp)(struct cam_periph *, union ccb *),
1640 u_int8_t tag_action, u_int8_t sense_len,
1643 struct scsi_initialize_element_status *scsi_cmd;
1645 scsi_cmd = (struct scsi_initialize_element_status *)
1646 &csio->cdb_io.cdb_bytes;
1647 bzero(scsi_cmd, sizeof(*scsi_cmd));
1649 scsi_cmd->opcode = INITIALIZE_ELEMENT_STATUS;
1654 /*flags*/ CAM_DIR_NONE,
1656 /* data_ptr */ NULL,
1664 scsi_send_volume_tag(struct ccb_scsiio *csio, u_int32_t retries,
1665 void (*cbfcnp)(struct cam_periph *, union ccb *),
1666 u_int8_t tag_action,
1667 u_int16_t element_address,
1668 u_int8_t send_action_code,
1669 struct scsi_send_volume_tag_parameters *parameters,
1670 u_int8_t sense_len, u_int32_t timeout)
1672 struct scsi_send_volume_tag *scsi_cmd;
1674 scsi_cmd = (struct scsi_send_volume_tag *) &csio->cdb_io.cdb_bytes;
1675 bzero(scsi_cmd, sizeof(*scsi_cmd));
1677 scsi_cmd->opcode = SEND_VOLUME_TAG;
1678 scsi_ulto2b(element_address, scsi_cmd->ea);
1679 scsi_cmd->sac = send_action_code;
1680 scsi_ulto2b(sizeof(*parameters), scsi_cmd->pll);
1685 /*flags*/ CAM_DIR_OUT,
1687 /* data_ptr */ (u_int8_t *) parameters,
1688 sizeof(*parameters),