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.10 2004/05/19 22:52:38 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_ccb.h"
88 #include "../cam_extend.h"
89 #include "../cam_periph.h"
90 #include "../cam_xpt_periph.h"
91 #include "../cam_queue.h"
92 #include "../cam_debug.h"
95 #include "scsi_message.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;
152 int sc_picker; /* current picker */
155 * The following information is obtained from the
156 * element address assignment page.
158 int sc_firsts[4]; /* firsts, indexed by CHET_* */
159 int sc_counts[4]; /* counts, indexed by CHET_* */
162 * The following mask defines the legal combinations
163 * of elements for the MOVE MEDIUM command.
165 u_int8_t sc_movemask[4];
168 * As above, but for EXCHANGE MEDIUM.
170 u_int8_t sc_exchangemask[4];
173 * Quirks; see below. XXX KDM not implemented yet
175 int sc_settledelay; /* delay for settle */
178 #define CHUNIT(x) (minor((x)))
179 #define CH_CDEV_MAJOR 17
181 static d_open_t chopen;
182 static d_close_t chclose;
183 static d_ioctl_t chioctl;
184 static periph_init_t chinit;
185 static periph_ctor_t chregister;
186 static periph_oninv_t choninvalidate;
187 static periph_dtor_t chcleanup;
188 static periph_start_t chstart;
189 static void chasync(void *callback_arg, u_int32_t code,
190 struct cam_path *path, void *arg);
191 static void chdone(struct cam_periph *periph,
192 union ccb *done_ccb);
193 static int cherror(union ccb *ccb, u_int32_t cam_flags,
194 u_int32_t sense_flags);
195 static int chmove(struct cam_periph *periph,
196 struct changer_move *cm);
197 static int chexchange(struct cam_periph *periph,
198 struct changer_exchange *ce);
199 static int chposition(struct cam_periph *periph,
200 struct changer_position *cp);
201 static int chgetelemstatus(struct cam_periph *periph,
202 struct changer_element_status_request *csr);
203 static int chsetvoltag(struct cam_periph *periph,
204 struct changer_set_voltag_request *csvr);
205 static int chielem(struct cam_periph *periph,
206 unsigned int timeout);
207 static int chgetparams(struct cam_periph *periph);
209 static struct periph_driver chdriver =
212 TAILQ_HEAD_INITIALIZER(chdriver.units), /* generation */ 0
215 DATA_SET(periphdriver_set, chdriver);
217 static struct cdevsw ch_cdevsw = {
219 /* maj */ CH_CDEV_MAJOR,
231 /* strategy */ nostrategy,
236 static struct extend_array *chperiphs;
242 struct cam_path *path;
245 * Create our extend array for storing the devices we attach to.
247 chperiphs = cam_extend_new();
248 if (chperiphs == NULL) {
249 printf("ch: Failed to alloc extend array!\n");
254 * Install a global async callback. This callback will
255 * receive async callbacks like "new device found".
257 status = xpt_create_path(&path, /*periph*/NULL, CAM_XPT_PATH_ID,
258 CAM_TARGET_WILDCARD, CAM_LUN_WILDCARD);
260 if (status == CAM_REQ_CMP) {
261 struct ccb_setasync csa;
263 xpt_setup_ccb(&csa.ccb_h, path, /*priority*/5);
264 csa.ccb_h.func_code = XPT_SASYNC_CB;
265 csa.event_enable = AC_FOUND_DEVICE;
266 csa.callback = chasync;
267 csa.callback_arg = NULL;
268 xpt_action((union ccb *)&csa);
269 status = csa.ccb_h.status;
273 if (status != CAM_REQ_CMP) {
274 printf("ch: Failed to attach master async callback "
275 "due to status 0x%x!\n", status);
280 choninvalidate(struct cam_periph *periph)
282 struct ch_softc *softc;
283 struct ccb_setasync csa;
285 softc = (struct ch_softc *)periph->softc;
288 * De-register any async callbacks.
290 xpt_setup_ccb(&csa.ccb_h, periph->path,
292 csa.ccb_h.func_code = XPT_SASYNC_CB;
293 csa.event_enable = 0;
294 csa.callback = chasync;
295 csa.callback_arg = periph;
296 xpt_action((union ccb *)&csa);
298 softc->flags |= CH_FLAG_INVALID;
300 xpt_print_path(periph->path);
301 printf("lost device\n");
306 chcleanup(struct cam_periph *periph)
308 struct ch_softc *softc;
310 softc = (struct ch_softc *)periph->softc;
312 devstat_remove_entry(&softc->device_stats);
313 cam_extend_release(chperiphs, periph->unit_number);
314 xpt_print_path(periph->path);
315 printf("removing device entry\n");
316 cdevsw_remove(&ch_cdevsw, -1, periph->unit_number);
317 free(softc, M_DEVBUF);
321 chasync(void *callback_arg, u_int32_t code, struct cam_path *path, void *arg)
323 struct cam_periph *periph;
325 periph = (struct cam_periph *)callback_arg;
328 case AC_FOUND_DEVICE:
330 struct ccb_getdev *cgd;
333 cgd = (struct ccb_getdev *)arg;
335 if (SID_TYPE(&cgd->inq_data)!= T_CHANGER)
339 * Allocate a peripheral instance for
340 * this device and start the probe
343 status = cam_periph_alloc(chregister, choninvalidate,
344 chcleanup, chstart, "ch",
345 CAM_PERIPH_BIO, cgd->ccb_h.path,
346 chasync, AC_FOUND_DEVICE, cgd);
348 if (status != CAM_REQ_CMP
349 && status != CAM_REQ_INPROG)
350 printf("chasync: Unable to probe new device "
351 "due to status 0x%x\n", status);
357 cam_periph_async(periph, code, path, arg);
363 chregister(struct cam_periph *periph, void *arg)
365 struct ch_softc *softc;
366 struct ccb_setasync csa;
367 struct ccb_getdev *cgd;
369 cgd = (struct ccb_getdev *)arg;
370 if (periph == NULL) {
371 printf("chregister: periph was NULL!!\n");
372 return(CAM_REQ_CMP_ERR);
376 printf("chregister: no getdev CCB, can't register device\n");
377 return(CAM_REQ_CMP_ERR);
380 softc = malloc(sizeof(*softc), M_DEVBUF, M_INTWAIT | M_ZERO);
381 softc->state = CH_STATE_PROBE;
382 periph->softc = softc;
383 cam_extend_set(chperiphs, periph->unit_number, periph);
384 softc->quirks = CH_Q_NONE;
387 * Changers don't have a blocksize, and obviously don't support
390 devstat_add_entry(&softc->device_stats, "ch",
391 periph->unit_number, 0,
392 DEVSTAT_NO_BLOCKSIZE | DEVSTAT_NO_ORDERED_TAGS,
393 SID_TYPE(&cgd->inq_data)| DEVSTAT_TYPE_IF_SCSI,
394 DEVSTAT_PRIORITY_OTHER);
396 /* Register the device */
397 cdevsw_add(&ch_cdevsw, -1, periph->unit_number);
398 make_dev(&ch_cdevsw, periph->unit_number, UID_ROOT,
399 GID_OPERATOR, 0600, "%s%d", periph->periph_name,
400 periph->unit_number);
403 * Add an async callback so that we get
404 * notified if this device goes away.
406 xpt_setup_ccb(&csa.ccb_h, periph->path, /* priority */ 5);
407 csa.ccb_h.func_code = XPT_SASYNC_CB;
408 csa.event_enable = AC_LOST_DEVICE;
409 csa.callback = chasync;
410 csa.callback_arg = periph;
411 xpt_action((union ccb *)&csa);
414 * Lock this peripheral until we are setup.
415 * This first call can't block
417 (void)cam_periph_lock(periph, 0);
418 xpt_schedule(periph, /*priority*/5);
424 chopen(dev_t dev, int flags, int fmt, struct thread *td)
426 struct cam_periph *periph;
427 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;
506 softc = (struct ch_softc *)periph->softc;
508 switch (softc->state) {
509 case CH_STATE_NORMAL:
512 if (periph->immediate_priority <= periph->pinfo.priority){
513 start_ccb->ccb_h.ccb_state = CH_CCB_WAITING;
515 SLIST_INSERT_HEAD(&periph->ccb_list, &start_ccb->ccb_h,
517 periph->immediate_priority = CAM_PRIORITY_NONE;
519 wakeup(&periph->ccb_list);
530 * Include the block descriptor when calculating the mode
533 mode_buffer_len = sizeof(struct scsi_mode_header_6) +
534 sizeof(struct scsi_mode_blk_desc) +
535 sizeof(struct page_element_address_assignment);
537 mode_buffer = malloc(mode_buffer_len, M_TEMP, M_INTWAIT | M_ZERO);
539 * Get the element address assignment page.
541 scsi_mode_sense(&start_ccb->csio,
544 /* tag_action */ MSG_SIMPLE_Q_TAG,
545 /* dbd */ (softc->quirks & CH_Q_NO_DBD) ?
547 /* page_code */ SMS_PAGE_CTRL_CURRENT,
548 /* page */ CH_ELEMENT_ADDR_ASSIGN_PAGE,
549 /* param_buf */ (u_int8_t *)mode_buffer,
550 /* param_len */ mode_buffer_len,
551 /* sense_len */ SSD_FULL_SIZE,
552 /* timeout */ CH_TIMEOUT_MODE_SENSE);
554 start_ccb->ccb_h.ccb_bp = NULL;
555 start_ccb->ccb_h.ccb_state = CH_CCB_PROBE;
556 xpt_action(start_ccb);
563 chdone(struct cam_periph *periph, union ccb *done_ccb)
565 struct ch_softc *softc;
566 struct ccb_scsiio *csio;
568 softc = (struct ch_softc *)periph->softc;
569 csio = &done_ccb->csio;
571 switch(done_ccb->ccb_h.ccb_state) {
574 struct scsi_mode_header_6 *mode_header;
575 struct page_element_address_assignment *ea;
576 char announce_buf[80];
579 mode_header = (struct scsi_mode_header_6 *)csio->data_ptr;
581 ea = (struct page_element_address_assignment *)
582 find_mode_page_6(mode_header);
584 if ((done_ccb->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP){
586 softc->sc_firsts[CHET_MT] = scsi_2btoul(ea->mtea);
587 softc->sc_counts[CHET_MT] = scsi_2btoul(ea->nmte);
588 softc->sc_firsts[CHET_ST] = scsi_2btoul(ea->fsea);
589 softc->sc_counts[CHET_ST] = scsi_2btoul(ea->nse);
590 softc->sc_firsts[CHET_IE] = scsi_2btoul(ea->fieea);
591 softc->sc_counts[CHET_IE] = scsi_2btoul(ea->niee);
592 softc->sc_firsts[CHET_DT] = scsi_2btoul(ea->fdtea);
593 softc->sc_counts[CHET_DT] = scsi_2btoul(ea->ndte);
594 softc->sc_picker = softc->sc_firsts[CHET_MT];
596 #define PLURAL(c) (c) == 1 ? "" : "s"
597 snprintf(announce_buf, sizeof(announce_buf),
598 "%d slot%s, %d drive%s, "
599 "%d picker%s, %d portal%s",
600 softc->sc_counts[CHET_ST],
601 PLURAL(softc->sc_counts[CHET_ST]),
602 softc->sc_counts[CHET_DT],
603 PLURAL(softc->sc_counts[CHET_DT]),
604 softc->sc_counts[CHET_MT],
605 PLURAL(softc->sc_counts[CHET_MT]),
606 softc->sc_counts[CHET_IE],
607 PLURAL(softc->sc_counts[CHET_IE]));
612 error = cherror(done_ccb, 0, SF_RETRY_UA |
613 SF_NO_PRINT | SF_RETRY_SELTO);
615 * Retry any UNIT ATTENTION type errors. They
616 * are expected at boot.
618 if (error == ERESTART) {
620 * A retry was scheuled, so
624 } else if (error != 0) {
626 struct scsi_mode_sense_6 *sms;
628 sms = (struct scsi_mode_sense_6 *)
629 done_ccb->csio.cdb_io.cdb_bytes;
632 * Check to see if block descriptors were
633 * disabled. Some devices don't like that.
634 * We're taking advantage of the fact that
635 * the first few bytes of the 6 and 10 byte
636 * mode sense commands are the same. If
637 * block descriptors were disabled, enable
638 * them and re-send the command.
640 if (sms->byte2 & SMS_DBD) {
641 sms->byte2 &= ~SMS_DBD;
642 xpt_action(done_ccb);
643 softc->quirks |= CH_Q_NO_DBD;
648 /* Don't wedge this device's queue */
649 cam_release_devq(done_ccb->ccb_h.path,
658 if ((done_ccb->ccb_h.status & CAM_STATUS_MASK)
659 == CAM_SCSI_STATUS_ERROR)
660 scsi_sense_print(&done_ccb->csio);
662 xpt_print_path(periph->path);
663 printf("got CAM status %#x\n",
664 done_ccb->ccb_h.status);
666 xpt_print_path(periph->path);
667 printf("fatal error, failed to attach to"
670 cam_periph_invalidate(periph);
672 announce_buf[0] = '\0';
675 if (announce_buf[0] != '\0')
676 xpt_announce_periph(periph, announce_buf);
677 softc->state = CH_STATE_NORMAL;
678 free(mode_header, M_TEMP);
680 * Since our peripheral may be invalidated by an error
681 * above or an external event, we must release our CCB
682 * before releasing the probe lock on the peripheral.
683 * The peripheral will only go away once the last lock
684 * is removed, and we need it around for the CCB release
687 xpt_release_ccb(done_ccb);
688 cam_periph_unlock(periph);
693 /* Caller will release the CCB */
694 wakeup(&done_ccb->ccb_h.cbfcnp);
700 xpt_release_ccb(done_ccb);
704 cherror(union ccb *ccb, u_int32_t cam_flags, u_int32_t sense_flags)
706 struct ch_softc *softc;
707 struct cam_periph *periph;
709 periph = xpt_path_periph(ccb->ccb_h.path);
710 softc = (struct ch_softc *)periph->softc;
712 return (cam_periph_error(ccb, cam_flags, sense_flags,
717 chioctl(dev_t dev, u_long cmd, caddr_t addr, int flag, struct thread *td)
719 struct cam_periph *periph;
720 struct ch_softc *softc;
726 periph = cam_extend_get(chperiphs, unit);
730 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("entering chioctl\n"));
732 softc = (struct ch_softc *)periph->softc;
736 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE,
737 ("trying to do ioctl %#lx\n", cmd));
740 * If this command can change the device's state, we must
741 * have the device open for writing.
750 if ((flag & FWRITE) == 0)
756 error = chmove(periph, (struct changer_move *)addr);
760 error = chexchange(periph, (struct changer_exchange *)addr);
764 error = chposition(periph, (struct changer_position *)addr);
768 *(int *)addr = softc->sc_picker - softc->sc_firsts[CHET_MT];
773 int new_picker = *(int *)addr;
775 if (new_picker > (softc->sc_counts[CHET_MT] - 1))
777 softc->sc_picker = softc->sc_firsts[CHET_MT] + new_picker;
782 struct changer_params *cp = (struct changer_params *)addr;
784 cp->cp_npickers = softc->sc_counts[CHET_MT];
785 cp->cp_nslots = softc->sc_counts[CHET_ST];
786 cp->cp_nportals = softc->sc_counts[CHET_IE];
787 cp->cp_ndrives = softc->sc_counts[CHET_DT];
791 error = chielem(periph, *(unsigned int *)addr);
796 error = chgetelemstatus(periph,
797 (struct changer_element_status_request *) addr);
803 error = chsetvoltag(periph,
804 (struct changer_set_voltag_request *) addr);
808 /* Implement prevent/allow? */
811 error = cam_periph_ioctl(periph, cmd, addr, cherror);
819 chmove(struct cam_periph *periph, struct changer_move *cm)
821 struct ch_softc *softc;
822 u_int16_t fromelem, toelem;
827 softc = (struct ch_softc *)periph->softc;
832 if ((cm->cm_fromtype > CHET_DT) || (cm->cm_totype > CHET_DT))
834 if ((cm->cm_fromunit > (softc->sc_counts[cm->cm_fromtype] - 1)) ||
835 (cm->cm_tounit > (softc->sc_counts[cm->cm_totype] - 1)))
839 * Check the request against the changer's capabilities.
841 if ((softc->sc_movemask[cm->cm_fromtype] & (1 << cm->cm_totype)) == 0)
845 * Calculate the source and destination elements.
847 fromelem = softc->sc_firsts[cm->cm_fromtype] + cm->cm_fromunit;
848 toelem = softc->sc_firsts[cm->cm_totype] + cm->cm_tounit;
850 ccb = cam_periph_getccb(periph, /*priority*/ 1);
852 scsi_move_medium(&ccb->csio,
855 /* tag_action */ MSG_SIMPLE_Q_TAG,
856 /* tea */ softc->sc_picker,
859 /* invert */ (cm->cm_flags & CM_INVERT) ? TRUE : FALSE,
860 /* sense_len */ SSD_FULL_SIZE,
861 /* timeout */ CH_TIMEOUT_MOVE_MEDIUM);
863 error = cam_periph_runccb(ccb, cherror, /*cam_flags*/0,
864 /*sense_flags*/ SF_RETRY_UA | SF_RETRY_SELTO,
865 &softc->device_stats);
867 xpt_release_ccb(ccb);
873 chexchange(struct cam_periph *periph, struct changer_exchange *ce)
875 struct ch_softc *softc;
876 u_int16_t src, dst1, dst2;
881 softc = (struct ch_softc *)periph->softc;
885 if ((ce->ce_srctype > CHET_DT) || (ce->ce_fdsttype > CHET_DT) ||
886 (ce->ce_sdsttype > CHET_DT))
888 if ((ce->ce_srcunit > (softc->sc_counts[ce->ce_srctype] - 1)) ||
889 (ce->ce_fdstunit > (softc->sc_counts[ce->ce_fdsttype] - 1)) ||
890 (ce->ce_sdstunit > (softc->sc_counts[ce->ce_sdsttype] - 1)))
894 * Check the request against the changer's capabilities.
896 if (((softc->sc_exchangemask[ce->ce_srctype] &
897 (1 << ce->ce_fdsttype)) == 0) ||
898 ((softc->sc_exchangemask[ce->ce_fdsttype] &
899 (1 << ce->ce_sdsttype)) == 0))
903 * Calculate the source and destination elements.
905 src = softc->sc_firsts[ce->ce_srctype] + ce->ce_srcunit;
906 dst1 = softc->sc_firsts[ce->ce_fdsttype] + ce->ce_fdstunit;
907 dst2 = softc->sc_firsts[ce->ce_sdsttype] + ce->ce_sdstunit;
909 ccb = cam_periph_getccb(periph, /*priority*/ 1);
911 scsi_exchange_medium(&ccb->csio,
914 /* tag_action */ MSG_SIMPLE_Q_TAG,
915 /* tea */ softc->sc_picker,
919 /* invert1 */ (ce->ce_flags & CE_INVERT1) ?
921 /* invert2 */ (ce->ce_flags & CE_INVERT2) ?
923 /* sense_len */ SSD_FULL_SIZE,
924 /* timeout */ CH_TIMEOUT_EXCHANGE_MEDIUM);
926 error = cam_periph_runccb(ccb, cherror, /*cam_flags*/0,
927 /*sense_flags*/ SF_RETRY_UA | SF_RETRY_SELTO,
928 &softc->device_stats);
930 xpt_release_ccb(ccb);
936 chposition(struct cam_periph *periph, struct changer_position *cp)
938 struct ch_softc *softc;
944 softc = (struct ch_softc *)periph->softc;
949 if (cp->cp_type > CHET_DT)
951 if (cp->cp_unit > (softc->sc_counts[cp->cp_type] - 1))
955 * Calculate the destination element.
957 dst = softc->sc_firsts[cp->cp_type] + cp->cp_unit;
959 ccb = cam_periph_getccb(periph, /*priority*/ 1);
961 scsi_position_to_element(&ccb->csio,
964 /* tag_action */ MSG_SIMPLE_Q_TAG,
965 /* tea */ softc->sc_picker,
967 /* invert */ (cp->cp_flags & CP_INVERT) ?
969 /* sense_len */ SSD_FULL_SIZE,
970 /* timeout */ CH_TIMEOUT_POSITION_TO_ELEMENT);
972 error = cam_periph_runccb(ccb, cherror, /*cam_flags*/ 0,
973 /*sense_flags*/ SF_RETRY_UA | SF_RETRY_SELTO,
974 &softc->device_stats);
976 xpt_release_ccb(ccb);
982 * Copy a volume tag to a volume_tag struct, converting SCSI byte order
983 * to host native byte order in the volume serial number. The volume
984 * label as returned by the changer is transferred to user mode as
985 * nul-terminated string. Volume labels are truncated at the first
986 * space, as suggested by SCSI-2.
989 copy_voltag(struct changer_voltag *uvoltag, struct volume_tag *voltag)
992 for (i=0; i<CH_VOLTAG_MAXLEN; i++) {
993 char c = voltag->vif[i];
995 uvoltag->cv_volid[i] = c;
999 uvoltag->cv_serial = scsi_2btoul(voltag->vsn);
1003 * Copy an an element status descriptor to a user-mode
1004 * changer_element_status structure.
1008 copy_element_status(struct ch_softc *softc,
1010 struct read_element_status_descriptor *desc,
1011 struct changer_element_status *ces)
1013 u_int16_t eaddr = scsi_2btoul(desc->eaddr);
1016 ces->ces_int_addr = eaddr;
1017 /* set up logical address in element status */
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_addr = eaddr - softc->sc_firsts[et];
1028 ces->ces_flags = desc->flags1;
1030 ces->ces_sensecode = desc->sense_code;
1031 ces->ces_sensequal = desc->sense_qual;
1033 if (desc->flags2 & READ_ELEMENT_STATUS_INVERT)
1034 ces->ces_flags |= CES_INVERT;
1036 if (desc->flags2 & READ_ELEMENT_STATUS_SVALID) {
1038 eaddr = scsi_2btoul(desc->ssea);
1040 /* convert source address to logical format */
1041 for (et = CHET_MT; et <= CHET_DT; et++) {
1042 if ((softc->sc_firsts[et] <= eaddr)
1043 && ((softc->sc_firsts[et] + softc->sc_counts[et])
1045 ces->ces_source_addr =
1046 eaddr - softc->sc_firsts[et];
1047 ces->ces_source_type = et;
1048 ces->ces_flags |= CES_SOURCE_VALID;
1053 if (!(ces->ces_flags & CES_SOURCE_VALID))
1054 printf("ch: warning: could not map element source "
1055 "address %ud to a valid element type\n",
1060 if (flags & READ_ELEMENT_STATUS_PVOLTAG)
1061 copy_voltag(&(ces->ces_pvoltag), &(desc->pvoltag));
1062 if (flags & READ_ELEMENT_STATUS_AVOLTAG)
1063 copy_voltag(&(ces->ces_avoltag), &(desc->avoltag));
1065 if (desc->dt_scsi_flags & READ_ELEMENT_STATUS_DT_IDVALID) {
1066 ces->ces_flags |= CES_SCSIID_VALID;
1067 ces->ces_scsi_id = desc->dt_scsi_addr;
1070 if (desc->dt_scsi_addr & READ_ELEMENT_STATUS_DT_LUVALID) {
1071 ces->ces_flags |= CES_LUN_VALID;
1073 desc->dt_scsi_flags & READ_ELEMENT_STATUS_DT_LUNMASK;
1078 chgetelemstatus(struct cam_periph *periph,
1079 struct changer_element_status_request *cesr)
1081 struct read_element_status_header *st_hdr;
1082 struct read_element_status_page_header *pg_hdr;
1083 struct read_element_status_descriptor *desc;
1084 caddr_t data = NULL;
1085 size_t size, desclen;
1086 int avail, i, error = 0;
1087 struct changer_element_status *user_data = NULL;
1088 struct ch_softc *softc;
1090 int chet = cesr->cesr_element_type;
1091 int want_voltags = (cesr->cesr_flags & CESR_VOLTAGS) ? 1 : 0;
1093 softc = (struct ch_softc *)periph->softc;
1095 /* perform argument checking */
1098 * Perform a range check on the cesr_element_{base,count}
1099 * request argument fields.
1101 if ((softc->sc_counts[chet] - cesr->cesr_element_base) <= 0
1102 || (cesr->cesr_element_base + cesr->cesr_element_count)
1103 > softc->sc_counts[chet])
1107 * Request one descriptor for the given element type. This
1108 * is used to determine the size of the descriptor so that
1109 * we can allocate enough storage for all of them. We assume
1110 * that the first one can fit into 1k.
1112 data = (caddr_t)malloc(1024, M_DEVBUF, M_INTWAIT);
1114 ccb = cam_periph_getccb(periph, /*priority*/ 1);
1116 scsi_read_element_status(&ccb->csio,
1118 /* cbfcnp */ chdone,
1119 /* tag_action */ MSG_SIMPLE_Q_TAG,
1120 /* voltag */ want_voltags,
1121 /* sea */ softc->sc_firsts[chet],
1123 /* data_ptr */ data,
1124 /* dxfer_len */ 1024,
1125 /* sense_len */ SSD_FULL_SIZE,
1126 /* timeout */ CH_TIMEOUT_READ_ELEMENT_STATUS);
1128 error = cam_periph_runccb(ccb, cherror, /*cam_flags*/ 0,
1129 /*sense_flags*/ SF_RETRY_UA | SF_RETRY_SELTO,
1130 &softc->device_stats);
1135 st_hdr = (struct read_element_status_header *)data;
1136 pg_hdr = (struct read_element_status_page_header *)((uintptr_t)st_hdr +
1137 sizeof(struct read_element_status_header));
1138 desclen = scsi_2btoul(pg_hdr->edl);
1140 size = sizeof(struct read_element_status_header) +
1141 sizeof(struct read_element_status_page_header) +
1142 (desclen * cesr->cesr_element_count);
1145 * Reallocate storage for descriptors and get them from the
1148 free(data, M_DEVBUF);
1149 data = (caddr_t)malloc(size, M_DEVBUF, M_INTWAIT);
1151 scsi_read_element_status(&ccb->csio,
1153 /* cbfcnp */ chdone,
1154 /* tag_action */ MSG_SIMPLE_Q_TAG,
1155 /* voltag */ want_voltags,
1156 /* sea */ softc->sc_firsts[chet]
1157 + cesr->cesr_element_base,
1158 /* count */ cesr->cesr_element_count,
1159 /* data_ptr */ data,
1160 /* dxfer_len */ size,
1161 /* sense_len */ SSD_FULL_SIZE,
1162 /* timeout */ CH_TIMEOUT_READ_ELEMENT_STATUS);
1164 error = cam_periph_runccb(ccb, cherror, /*cam_flags*/ 0,
1165 /*sense_flags*/ SF_RETRY_UA | SF_RETRY_SELTO,
1166 &softc->device_stats);
1172 * Fill in the user status array.
1174 st_hdr = (struct read_element_status_header *)data;
1175 avail = scsi_2btoul(st_hdr->count);
1177 if (avail != cesr->cesr_element_count) {
1178 xpt_print_path(periph->path);
1179 printf("warning, READ ELEMENT STATUS avail != count\n");
1182 user_data = (struct changer_element_status *)
1183 malloc(avail * sizeof(struct changer_element_status),
1184 M_DEVBUF, M_INTWAIT | M_ZERO);
1186 desc = (struct read_element_status_descriptor *)((uintptr_t)data +
1187 sizeof(struct read_element_status_header) +
1188 sizeof(struct read_element_status_page_header));
1190 * Set up the individual element status structures
1192 for (i = 0; i < avail; ++i) {
1193 struct changer_element_status *ces = &(user_data[i]);
1195 copy_element_status(softc, pg_hdr->flags, desc, ces);
1197 desc = (struct read_element_status_descriptor *)
1198 ((uintptr_t)desc + desclen);
1201 /* Copy element status structures out to userspace. */
1202 error = copyout(user_data,
1203 cesr->cesr_element_status,
1204 avail * sizeof(struct changer_element_status));
1207 xpt_release_ccb(ccb);
1210 free(data, M_DEVBUF);
1211 if (user_data != NULL)
1212 free(user_data, M_DEVBUF);
1218 chielem(struct cam_periph *periph,
1219 unsigned int timeout)
1222 struct ch_softc *softc;
1226 timeout = CH_TIMEOUT_INITIALIZE_ELEMENT_STATUS;
1232 softc = (struct ch_softc *)periph->softc;
1234 ccb = cam_periph_getccb(periph, /*priority*/ 1);
1236 scsi_initialize_element_status(&ccb->csio,
1238 /* cbfcnp */ chdone,
1239 /* tag_action */ MSG_SIMPLE_Q_TAG,
1240 /* sense_len */ SSD_FULL_SIZE,
1241 /* timeout */ timeout);
1243 error = cam_periph_runccb(ccb, cherror, /*cam_flags*/ 0,
1244 /*sense_flags*/ SF_RETRY_UA | SF_RETRY_SELTO,
1245 &softc->device_stats);
1247 xpt_release_ccb(ccb);
1253 chsetvoltag(struct cam_periph *periph,
1254 struct changer_set_voltag_request *csvr)
1257 struct ch_softc *softc;
1260 struct scsi_send_volume_tag_parameters ssvtp;
1265 softc = (struct ch_softc *)periph->softc;
1267 bzero(&ssvtp, sizeof(ssvtp));
1268 for (i=0; i<sizeof(ssvtp.vitf); i++) {
1269 ssvtp.vitf[i] = ' ';
1275 if (csvr->csvr_type > CHET_DT)
1277 if (csvr->csvr_addr > (softc->sc_counts[csvr->csvr_type] - 1))
1280 ea = softc->sc_firsts[csvr->csvr_type] + csvr->csvr_addr;
1282 if (csvr->csvr_flags & CSVR_ALTERNATE) {
1283 switch (csvr->csvr_flags & CSVR_MODE_MASK) {
1285 sac = SEND_VOLUME_TAG_ASSERT_ALTERNATE;
1287 case CSVR_MODE_REPLACE:
1288 sac = SEND_VOLUME_TAG_REPLACE_ALTERNATE;
1290 case CSVR_MODE_CLEAR:
1291 sac = SEND_VOLUME_TAG_UNDEFINED_ALTERNATE;
1298 switch (csvr->csvr_flags & CSVR_MODE_MASK) {
1300 sac = SEND_VOLUME_TAG_ASSERT_PRIMARY;
1302 case CSVR_MODE_REPLACE:
1303 sac = SEND_VOLUME_TAG_REPLACE_PRIMARY;
1305 case CSVR_MODE_CLEAR:
1306 sac = SEND_VOLUME_TAG_UNDEFINED_PRIMARY;
1314 memcpy(ssvtp.vitf, csvr->csvr_voltag.cv_volid,
1315 min(strlen(csvr->csvr_voltag.cv_volid), sizeof(ssvtp.vitf)));
1316 scsi_ulto2b(csvr->csvr_voltag.cv_serial, ssvtp.minvsn);
1318 ccb = cam_periph_getccb(periph, /*priority*/ 1);
1320 scsi_send_volume_tag(&ccb->csio,
1322 /* cbfcnp */ chdone,
1323 /* tag_action */ MSG_SIMPLE_Q_TAG,
1324 /* element_address */ ea,
1325 /* send_action_code */ sac,
1326 /* parameters */ &ssvtp,
1327 /* sense_len */ SSD_FULL_SIZE,
1328 /* timeout */ CH_TIMEOUT_SEND_VOLTAG);
1330 error = cam_periph_runccb(ccb, cherror, /*cam_flags*/ 0,
1331 /*sense_flags*/ SF_RETRY_UA | SF_RETRY_SELTO,
1332 &softc->device_stats);
1334 xpt_release_ccb(ccb);
1341 chgetparams(struct cam_periph *periph)
1344 struct ch_softc *softc;
1346 int mode_buffer_len;
1347 struct page_element_address_assignment *ea;
1348 struct page_device_capabilities *cap;
1349 int error, from, dbd;
1350 u_int8_t *moves, *exchanges;
1354 softc = (struct ch_softc *)periph->softc;
1356 ccb = cam_periph_getccb(periph, /*priority*/ 1);
1359 * The scsi_mode_sense_data structure is just a convenience
1360 * structure that allows us to easily calculate the worst-case
1361 * storage size of the mode sense buffer.
1363 mode_buffer_len = sizeof(struct scsi_mode_sense_data);
1365 mode_buffer = malloc(mode_buffer_len, M_TEMP, M_INTWAIT | M_ZERO);
1367 if (softc->quirks & CH_Q_NO_DBD)
1373 * Get the element address assignment page.
1375 scsi_mode_sense(&ccb->csio,
1377 /* cbfcnp */ chdone,
1378 /* tag_action */ MSG_SIMPLE_Q_TAG,
1380 /* page_code */ SMS_PAGE_CTRL_CURRENT,
1381 /* page */ CH_ELEMENT_ADDR_ASSIGN_PAGE,
1382 /* param_buf */ (u_int8_t *)mode_buffer,
1383 /* param_len */ mode_buffer_len,
1384 /* sense_len */ SSD_FULL_SIZE,
1385 /* timeout */ CH_TIMEOUT_MODE_SENSE);
1387 error = cam_periph_runccb(ccb, cherror, /*cam_flags*/ 0,
1388 /* sense_flags */ SF_RETRY_UA |
1389 SF_NO_PRINT | SF_RETRY_SELTO,
1390 &softc->device_stats);
1394 struct scsi_mode_sense_6 *sms;
1396 sms = (struct scsi_mode_sense_6 *)
1397 ccb->csio.cdb_io.cdb_bytes;
1399 sms->byte2 &= ~SMS_DBD;
1400 error = cam_periph_runccb(ccb, cherror, /*cam_flags*/ 0,
1401 /*sense_flags*/ SF_RETRY_UA |
1403 &softc->device_stats);
1406 * Since we disabled sense printing above, print
1407 * out the sense here since we got an error.
1409 scsi_sense_print(&ccb->csio);
1413 xpt_print_path(periph->path);
1414 printf("chgetparams: error getting element "
1416 xpt_release_ccb(ccb);
1417 free(mode_buffer, M_TEMP);
1422 ea = (struct page_element_address_assignment *)
1423 find_mode_page_6((struct scsi_mode_header_6 *)mode_buffer);
1425 softc->sc_firsts[CHET_MT] = scsi_2btoul(ea->mtea);
1426 softc->sc_counts[CHET_MT] = scsi_2btoul(ea->nmte);
1427 softc->sc_firsts[CHET_ST] = scsi_2btoul(ea->fsea);
1428 softc->sc_counts[CHET_ST] = scsi_2btoul(ea->nse);
1429 softc->sc_firsts[CHET_IE] = scsi_2btoul(ea->fieea);
1430 softc->sc_counts[CHET_IE] = scsi_2btoul(ea->niee);
1431 softc->sc_firsts[CHET_DT] = scsi_2btoul(ea->fdtea);
1432 softc->sc_counts[CHET_DT] = scsi_2btoul(ea->ndte);
1434 bzero(mode_buffer, mode_buffer_len);
1437 * Now get the device capabilities page.
1439 scsi_mode_sense(&ccb->csio,
1441 /* cbfcnp */ chdone,
1442 /* tag_action */ MSG_SIMPLE_Q_TAG,
1444 /* page_code */ SMS_PAGE_CTRL_CURRENT,
1445 /* page */ CH_DEVICE_CAP_PAGE,
1446 /* param_buf */ (u_int8_t *)mode_buffer,
1447 /* param_len */ mode_buffer_len,
1448 /* sense_len */ SSD_FULL_SIZE,
1449 /* timeout */ CH_TIMEOUT_MODE_SENSE);
1451 error = cam_periph_runccb(ccb, cherror, /*cam_flags*/ 0,
1452 /* sense_flags */ SF_RETRY_UA | SF_NO_PRINT |
1453 SF_RETRY_SELTO, &softc->device_stats);
1457 struct scsi_mode_sense_6 *sms;
1459 sms = (struct scsi_mode_sense_6 *)
1460 ccb->csio.cdb_io.cdb_bytes;
1462 sms->byte2 &= ~SMS_DBD;
1463 error = cam_periph_runccb(ccb, cherror, /*cam_flags*/ 0,
1464 /*sense_flags*/ SF_RETRY_UA |
1466 &softc->device_stats);
1469 * Since we disabled sense printing above, print
1470 * out the sense here since we got an error.
1472 scsi_sense_print(&ccb->csio);
1476 xpt_print_path(periph->path);
1477 printf("chgetparams: error getting device "
1478 "capabilities page\n");
1479 xpt_release_ccb(ccb);
1480 free(mode_buffer, M_TEMP);
1485 xpt_release_ccb(ccb);
1487 cap = (struct page_device_capabilities *)
1488 find_mode_page_6((struct scsi_mode_header_6 *)mode_buffer);
1490 bzero(softc->sc_movemask, sizeof(softc->sc_movemask));
1491 bzero(softc->sc_exchangemask, sizeof(softc->sc_exchangemask));
1492 moves = &cap->move_from_mt;
1493 exchanges = &cap->exchange_with_mt;
1494 for (from = CHET_MT; from <= CHET_DT; ++from) {
1495 softc->sc_movemask[from] = moves[from];
1496 softc->sc_exchangemask[from] = exchanges[from];
1499 free(mode_buffer, M_TEMP);
1505 scsi_move_medium(struct ccb_scsiio *csio, u_int32_t retries,
1506 void (*cbfcnp)(struct cam_periph *, union ccb *),
1507 u_int8_t tag_action, u_int32_t tea, u_int32_t src,
1508 u_int32_t dst, int invert, u_int8_t sense_len,
1511 struct scsi_move_medium *scsi_cmd;
1513 scsi_cmd = (struct scsi_move_medium *)&csio->cdb_io.cdb_bytes;
1514 bzero(scsi_cmd, sizeof(*scsi_cmd));
1516 scsi_cmd->opcode = MOVE_MEDIUM;
1518 scsi_ulto2b(tea, scsi_cmd->tea);
1519 scsi_ulto2b(src, scsi_cmd->src);
1520 scsi_ulto2b(dst, scsi_cmd->dst);
1523 scsi_cmd->invert |= MOVE_MEDIUM_INVERT;
1528 /*flags*/ CAM_DIR_NONE,
1538 scsi_exchange_medium(struct ccb_scsiio *csio, u_int32_t retries,
1539 void (*cbfcnp)(struct cam_periph *, union ccb *),
1540 u_int8_t tag_action, u_int32_t tea, u_int32_t src,
1541 u_int32_t dst1, u_int32_t dst2, int invert1,
1542 int invert2, u_int8_t sense_len, u_int32_t timeout)
1544 struct scsi_exchange_medium *scsi_cmd;
1546 scsi_cmd = (struct scsi_exchange_medium *)&csio->cdb_io.cdb_bytes;
1547 bzero(scsi_cmd, sizeof(*scsi_cmd));
1549 scsi_cmd->opcode = EXCHANGE_MEDIUM;
1551 scsi_ulto2b(tea, scsi_cmd->tea);
1552 scsi_ulto2b(src, scsi_cmd->src);
1553 scsi_ulto2b(dst1, scsi_cmd->fdst);
1554 scsi_ulto2b(dst2, scsi_cmd->sdst);
1557 scsi_cmd->invert |= EXCHANGE_MEDIUM_INV1;
1560 scsi_cmd->invert |= EXCHANGE_MEDIUM_INV2;
1565 /*flags*/ CAM_DIR_NONE,
1575 scsi_position_to_element(struct ccb_scsiio *csio, u_int32_t retries,
1576 void (*cbfcnp)(struct cam_periph *, union ccb *),
1577 u_int8_t tag_action, u_int32_t tea, u_int32_t dst,
1578 int invert, u_int8_t sense_len, u_int32_t timeout)
1580 struct scsi_position_to_element *scsi_cmd;
1582 scsi_cmd = (struct scsi_position_to_element *)&csio->cdb_io.cdb_bytes;
1583 bzero(scsi_cmd, sizeof(*scsi_cmd));
1585 scsi_cmd->opcode = POSITION_TO_ELEMENT;
1587 scsi_ulto2b(tea, scsi_cmd->tea);
1588 scsi_ulto2b(dst, scsi_cmd->dst);
1591 scsi_cmd->invert |= POSITION_TO_ELEMENT_INVERT;
1596 /*flags*/ CAM_DIR_NONE,
1606 scsi_read_element_status(struct ccb_scsiio *csio, u_int32_t retries,
1607 void (*cbfcnp)(struct cam_periph *, union ccb *),
1608 u_int8_t tag_action, int voltag, u_int32_t sea,
1609 u_int32_t count, u_int8_t *data_ptr,
1610 u_int32_t dxfer_len, u_int8_t sense_len,
1613 struct scsi_read_element_status *scsi_cmd;
1615 scsi_cmd = (struct scsi_read_element_status *)&csio->cdb_io.cdb_bytes;
1616 bzero(scsi_cmd, sizeof(*scsi_cmd));
1618 scsi_cmd->opcode = READ_ELEMENT_STATUS;
1620 scsi_ulto2b(sea, scsi_cmd->sea);
1621 scsi_ulto2b(count, scsi_cmd->count);
1622 scsi_ulto3b(dxfer_len, scsi_cmd->len);
1625 scsi_cmd->byte2 |= READ_ELEMENT_STATUS_VOLTAG;
1630 /*flags*/ CAM_DIR_IN,
1640 scsi_initialize_element_status(struct ccb_scsiio *csio, u_int32_t retries,
1641 void (*cbfcnp)(struct cam_periph *, union ccb *),
1642 u_int8_t tag_action, u_int8_t sense_len,
1645 struct scsi_initialize_element_status *scsi_cmd;
1647 scsi_cmd = (struct scsi_initialize_element_status *)
1648 &csio->cdb_io.cdb_bytes;
1649 bzero(scsi_cmd, sizeof(*scsi_cmd));
1651 scsi_cmd->opcode = INITIALIZE_ELEMENT_STATUS;
1656 /*flags*/ CAM_DIR_NONE,
1658 /* data_ptr */ NULL,
1666 scsi_send_volume_tag(struct ccb_scsiio *csio, u_int32_t retries,
1667 void (*cbfcnp)(struct cam_periph *, union ccb *),
1668 u_int8_t tag_action,
1669 u_int16_t element_address,
1670 u_int8_t send_action_code,
1671 struct scsi_send_volume_tag_parameters *parameters,
1672 u_int8_t sense_len, u_int32_t timeout)
1674 struct scsi_send_volume_tag *scsi_cmd;
1676 scsi_cmd = (struct scsi_send_volume_tag *) &csio->cdb_io.cdb_bytes;
1677 bzero(scsi_cmd, sizeof(*scsi_cmd));
1679 scsi_cmd->opcode = SEND_VOLUME_TAG;
1680 scsi_ulto2b(element_address, scsi_cmd->ea);
1681 scsi_cmd->sac = send_action_code;
1682 scsi_ulto2b(sizeof(*parameters), scsi_cmd->pll);
1687 /*flags*/ CAM_DIR_OUT,
1689 /* data_ptr */ (u_int8_t *) parameters,
1690 sizeof(*parameters),