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.14 2006/07/28 02:17:32 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_bio 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 dev_ops ch_ops = {
219 { "ch", CH_CDEV_MAJOR, 0 },
225 static struct extend_array *chperiphs;
231 struct cam_path *path;
234 * Create our extend array for storing the devices we attach to.
236 chperiphs = cam_extend_new();
237 if (chperiphs == NULL) {
238 printf("ch: Failed to alloc extend array!\n");
243 * Install a global async callback. This callback will
244 * receive async callbacks like "new device found".
246 status = xpt_create_path(&path, /*periph*/NULL, CAM_XPT_PATH_ID,
247 CAM_TARGET_WILDCARD, CAM_LUN_WILDCARD);
249 if (status == CAM_REQ_CMP) {
250 struct ccb_setasync csa;
252 xpt_setup_ccb(&csa.ccb_h, path, /*priority*/5);
253 csa.ccb_h.func_code = XPT_SASYNC_CB;
254 csa.event_enable = AC_FOUND_DEVICE;
255 csa.callback = chasync;
256 csa.callback_arg = NULL;
257 xpt_action((union ccb *)&csa);
258 status = csa.ccb_h.status;
262 if (status != CAM_REQ_CMP) {
263 printf("ch: Failed to attach master async callback "
264 "due to status 0x%x!\n", status);
269 choninvalidate(struct cam_periph *periph)
271 struct ch_softc *softc;
272 struct ccb_setasync csa;
274 softc = (struct ch_softc *)periph->softc;
277 * De-register any async callbacks.
279 xpt_setup_ccb(&csa.ccb_h, periph->path,
281 csa.ccb_h.func_code = XPT_SASYNC_CB;
282 csa.event_enable = 0;
283 csa.callback = chasync;
284 csa.callback_arg = periph;
285 xpt_action((union ccb *)&csa);
287 softc->flags |= CH_FLAG_INVALID;
289 xpt_print_path(periph->path);
290 printf("lost device\n");
295 chcleanup(struct cam_periph *periph)
297 struct ch_softc *softc;
299 softc = (struct ch_softc *)periph->softc;
301 devstat_remove_entry(&softc->device_stats);
302 cam_extend_release(chperiphs, periph->unit_number);
303 xpt_print_path(periph->path);
304 printf("removing device entry\n");
305 dev_ops_remove(&ch_ops, -1, periph->unit_number);
306 free(softc, M_DEVBUF);
310 chasync(void *callback_arg, u_int32_t code, struct cam_path *path, void *arg)
312 struct cam_periph *periph;
314 periph = (struct cam_periph *)callback_arg;
317 case AC_FOUND_DEVICE:
319 struct ccb_getdev *cgd;
322 cgd = (struct ccb_getdev *)arg;
324 if (SID_TYPE(&cgd->inq_data)!= T_CHANGER)
328 * Allocate a peripheral instance for
329 * this device and start the probe
332 status = cam_periph_alloc(chregister, choninvalidate,
333 chcleanup, chstart, "ch",
334 CAM_PERIPH_BIO, cgd->ccb_h.path,
335 chasync, AC_FOUND_DEVICE, cgd);
337 if (status != CAM_REQ_CMP
338 && status != CAM_REQ_INPROG)
339 printf("chasync: Unable to probe new device "
340 "due to status 0x%x\n", status);
346 cam_periph_async(periph, code, path, arg);
352 chregister(struct cam_periph *periph, void *arg)
354 struct ch_softc *softc;
355 struct ccb_setasync csa;
356 struct ccb_getdev *cgd;
358 cgd = (struct ccb_getdev *)arg;
359 if (periph == NULL) {
360 printf("chregister: periph was NULL!!\n");
361 return(CAM_REQ_CMP_ERR);
365 printf("chregister: no getdev CCB, can't register device\n");
366 return(CAM_REQ_CMP_ERR);
369 softc = malloc(sizeof(*softc), M_DEVBUF, M_INTWAIT | M_ZERO);
370 softc->state = CH_STATE_PROBE;
371 periph->softc = softc;
372 cam_extend_set(chperiphs, periph->unit_number, periph);
373 softc->quirks = CH_Q_NONE;
376 * Changers don't have a blocksize, and obviously don't support
379 devstat_add_entry(&softc->device_stats, "ch",
380 periph->unit_number, 0,
381 DEVSTAT_NO_BLOCKSIZE | DEVSTAT_NO_ORDERED_TAGS,
382 SID_TYPE(&cgd->inq_data)| DEVSTAT_TYPE_IF_SCSI,
383 DEVSTAT_PRIORITY_OTHER);
385 /* Register the device */
386 dev_ops_add(&ch_ops, -1, periph->unit_number);
387 make_dev(&ch_ops, periph->unit_number, UID_ROOT,
388 GID_OPERATOR, 0600, "%s%d", periph->periph_name,
389 periph->unit_number);
392 * Add an async callback so that we get
393 * notified if this device goes away.
395 xpt_setup_ccb(&csa.ccb_h, periph->path, /* priority */ 5);
396 csa.ccb_h.func_code = XPT_SASYNC_CB;
397 csa.event_enable = AC_LOST_DEVICE;
398 csa.callback = chasync;
399 csa.callback_arg = periph;
400 xpt_action((union ccb *)&csa);
403 * Lock this peripheral until we are setup.
404 * This first call can't block
406 cam_periph_lock(periph, 0);
407 xpt_schedule(periph, /*priority*/5);
413 chopen(struct dev_open_args *ap)
415 dev_t dev = ap->a_head.a_dev;
416 struct cam_periph *periph;
417 struct ch_softc *softc;
421 periph = cam_extend_get(chperiphs, unit);
426 softc = (struct ch_softc *)periph->softc;
429 if (softc->flags & CH_FLAG_INVALID) {
434 if ((error = cam_periph_lock(periph, PCATCH)) != 0) {
441 if ((softc->flags & CH_FLAG_OPEN) == 0) {
442 if (cam_periph_acquire(periph) != CAM_REQ_CMP)
444 softc->flags |= CH_FLAG_OPEN;
448 * Load information about this changer device into the softc.
450 if ((error = chgetparams(periph)) != 0) {
451 softc->flags &= ~CH_FLAG_OPEN;
452 cam_periph_unlock(periph);
453 cam_periph_release(periph);
457 cam_periph_unlock(periph);
463 chclose(struct dev_close_args *ap)
465 dev_t dev = ap->a_head.a_dev;
466 struct cam_periph *periph;
467 struct ch_softc *softc;
473 periph = cam_extend_get(chperiphs, unit);
477 softc = (struct ch_softc *)periph->softc;
479 if ((error = cam_periph_lock(periph, 0)) != 0)
482 softc->flags &= ~CH_FLAG_OPEN;
484 cam_periph_unlock(periph);
485 cam_periph_release(periph);
491 chstart(struct cam_periph *periph, union ccb *start_ccb)
493 struct ch_softc *softc;
495 softc = (struct ch_softc *)periph->softc;
497 switch (softc->state) {
498 case CH_STATE_NORMAL:
501 if (periph->immediate_priority <= periph->pinfo.priority){
502 start_ccb->ccb_h.ccb_state = CH_CCB_WAITING;
504 SLIST_INSERT_HEAD(&periph->ccb_list, &start_ccb->ccb_h,
506 periph->immediate_priority = CAM_PRIORITY_NONE;
507 wakeup(&periph->ccb_list);
518 * Include the block descriptor when calculating the mode
521 mode_buffer_len = sizeof(struct scsi_mode_header_6) +
522 sizeof(struct scsi_mode_blk_desc) +
523 sizeof(struct page_element_address_assignment);
525 mode_buffer = malloc(mode_buffer_len, M_TEMP, M_INTWAIT | M_ZERO);
527 * Get the element address assignment page.
529 scsi_mode_sense(&start_ccb->csio,
532 /* tag_action */ MSG_SIMPLE_Q_TAG,
533 /* dbd */ (softc->quirks & CH_Q_NO_DBD) ?
535 /* page_code */ SMS_PAGE_CTRL_CURRENT,
536 /* page */ CH_ELEMENT_ADDR_ASSIGN_PAGE,
537 /* param_buf */ (u_int8_t *)mode_buffer,
538 /* param_len */ mode_buffer_len,
539 /* sense_len */ SSD_FULL_SIZE,
540 /* timeout */ CH_TIMEOUT_MODE_SENSE);
542 start_ccb->ccb_h.ccb_bio = NULL;
543 start_ccb->ccb_h.ccb_state = CH_CCB_PROBE;
544 xpt_action(start_ccb);
551 chdone(struct cam_periph *periph, union ccb *done_ccb)
553 struct ch_softc *softc;
554 struct ccb_scsiio *csio;
556 softc = (struct ch_softc *)periph->softc;
557 csio = &done_ccb->csio;
559 switch(done_ccb->ccb_h.ccb_state) {
562 struct scsi_mode_header_6 *mode_header;
563 struct page_element_address_assignment *ea;
564 char announce_buf[80];
567 mode_header = (struct scsi_mode_header_6 *)csio->data_ptr;
569 ea = (struct page_element_address_assignment *)
570 find_mode_page_6(mode_header);
572 if ((done_ccb->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP){
574 softc->sc_firsts[CHET_MT] = scsi_2btoul(ea->mtea);
575 softc->sc_counts[CHET_MT] = scsi_2btoul(ea->nmte);
576 softc->sc_firsts[CHET_ST] = scsi_2btoul(ea->fsea);
577 softc->sc_counts[CHET_ST] = scsi_2btoul(ea->nse);
578 softc->sc_firsts[CHET_IE] = scsi_2btoul(ea->fieea);
579 softc->sc_counts[CHET_IE] = scsi_2btoul(ea->niee);
580 softc->sc_firsts[CHET_DT] = scsi_2btoul(ea->fdtea);
581 softc->sc_counts[CHET_DT] = scsi_2btoul(ea->ndte);
582 softc->sc_picker = softc->sc_firsts[CHET_MT];
584 #define PLURAL(c) (c) == 1 ? "" : "s"
585 snprintf(announce_buf, sizeof(announce_buf),
586 "%d slot%s, %d drive%s, "
587 "%d picker%s, %d portal%s",
588 softc->sc_counts[CHET_ST],
589 PLURAL(softc->sc_counts[CHET_ST]),
590 softc->sc_counts[CHET_DT],
591 PLURAL(softc->sc_counts[CHET_DT]),
592 softc->sc_counts[CHET_MT],
593 PLURAL(softc->sc_counts[CHET_MT]),
594 softc->sc_counts[CHET_IE],
595 PLURAL(softc->sc_counts[CHET_IE]));
600 error = cherror(done_ccb, 0, SF_RETRY_UA |
601 SF_NO_PRINT | SF_RETRY_SELTO);
603 * Retry any UNIT ATTENTION type errors. They
604 * are expected at boot.
606 if (error == ERESTART) {
608 * A retry was scheuled, so
612 } else if (error != 0) {
614 struct scsi_mode_sense_6 *sms;
616 sms = (struct scsi_mode_sense_6 *)
617 done_ccb->csio.cdb_io.cdb_bytes;
620 * Check to see if block descriptors were
621 * disabled. Some devices don't like that.
622 * We're taking advantage of the fact that
623 * the first few bytes of the 6 and 10 byte
624 * mode sense commands are the same. If
625 * block descriptors were disabled, enable
626 * them and re-send the command.
628 if (sms->byte2 & SMS_DBD) {
629 sms->byte2 &= ~SMS_DBD;
630 xpt_action(done_ccb);
631 softc->quirks |= CH_Q_NO_DBD;
636 /* Don't wedge this device's queue */
637 cam_release_devq(done_ccb->ccb_h.path,
646 if ((done_ccb->ccb_h.status & CAM_STATUS_MASK)
647 == CAM_SCSI_STATUS_ERROR)
648 scsi_sense_print(&done_ccb->csio);
650 xpt_print_path(periph->path);
651 printf("got CAM status %#x\n",
652 done_ccb->ccb_h.status);
654 xpt_print_path(periph->path);
655 printf("fatal error, failed to attach to"
658 cam_periph_invalidate(periph);
660 announce_buf[0] = '\0';
663 if (announce_buf[0] != '\0')
664 xpt_announce_periph(periph, announce_buf);
665 softc->state = CH_STATE_NORMAL;
666 free(mode_header, M_TEMP);
668 * Since our peripheral may be invalidated by an error
669 * above or an external event, we must release our CCB
670 * before releasing the probe lock on the peripheral.
671 * The peripheral will only go away once the last lock
672 * is removed, and we need it around for the CCB release
675 xpt_release_ccb(done_ccb);
676 cam_periph_unlock(periph);
681 /* Caller will release the CCB */
682 wakeup(&done_ccb->ccb_h.cbfcnp);
688 xpt_release_ccb(done_ccb);
692 cherror(union ccb *ccb, u_int32_t cam_flags, u_int32_t sense_flags)
694 struct ch_softc *softc;
695 struct cam_periph *periph;
697 periph = xpt_path_periph(ccb->ccb_h.path);
698 softc = (struct ch_softc *)periph->softc;
700 return (cam_periph_error(ccb, cam_flags, sense_flags,
705 chioctl(struct dev_ioctl_args *ap)
707 dev_t dev = ap->a_head.a_dev;
708 caddr_t addr = ap->a_data;
709 int flag = ap->a_fflag;
710 struct cam_periph *periph;
711 struct ch_softc *softc;
717 periph = cam_extend_get(chperiphs, unit);
721 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("entering chioctl\n"));
723 softc = (struct ch_softc *)periph->softc;
727 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE,
728 ("trying to do ioctl %#lx\n", ap->a_cmd));
731 * If this command can change the device's state, we must
732 * have the device open for writing.
741 if ((flag & FWRITE) == 0)
747 error = chmove(periph, (struct changer_move *)addr);
751 error = chexchange(periph, (struct changer_exchange *)addr);
755 error = chposition(periph, (struct changer_position *)addr);
759 *(int *)addr = softc->sc_picker - softc->sc_firsts[CHET_MT];
764 int new_picker = *(int *)addr;
766 if (new_picker > (softc->sc_counts[CHET_MT] - 1))
768 softc->sc_picker = softc->sc_firsts[CHET_MT] + new_picker;
773 struct changer_params *cp = (struct changer_params *)addr;
775 cp->cp_npickers = softc->sc_counts[CHET_MT];
776 cp->cp_nslots = softc->sc_counts[CHET_ST];
777 cp->cp_nportals = softc->sc_counts[CHET_IE];
778 cp->cp_ndrives = softc->sc_counts[CHET_DT];
782 error = chielem(periph, *(unsigned int *)addr);
787 error = chgetelemstatus(periph,
788 (struct changer_element_status_request *) addr);
794 error = chsetvoltag(periph,
795 (struct changer_set_voltag_request *) addr);
799 /* Implement prevent/allow? */
802 error = cam_periph_ioctl(periph, ap->a_cmd, addr, cherror);
810 chmove(struct cam_periph *periph, struct changer_move *cm)
812 struct ch_softc *softc;
813 u_int16_t fromelem, toelem;
818 softc = (struct ch_softc *)periph->softc;
823 if ((cm->cm_fromtype > CHET_DT) || (cm->cm_totype > CHET_DT))
825 if ((cm->cm_fromunit > (softc->sc_counts[cm->cm_fromtype] - 1)) ||
826 (cm->cm_tounit > (softc->sc_counts[cm->cm_totype] - 1)))
830 * Check the request against the changer's capabilities.
832 if ((softc->sc_movemask[cm->cm_fromtype] & (1 << cm->cm_totype)) == 0)
836 * Calculate the source and destination elements.
838 fromelem = softc->sc_firsts[cm->cm_fromtype] + cm->cm_fromunit;
839 toelem = softc->sc_firsts[cm->cm_totype] + cm->cm_tounit;
841 ccb = cam_periph_getccb(periph, /*priority*/ 1);
843 scsi_move_medium(&ccb->csio,
846 /* tag_action */ MSG_SIMPLE_Q_TAG,
847 /* tea */ softc->sc_picker,
850 /* invert */ (cm->cm_flags & CM_INVERT) ? TRUE : FALSE,
851 /* sense_len */ SSD_FULL_SIZE,
852 /* timeout */ CH_TIMEOUT_MOVE_MEDIUM);
854 error = cam_periph_runccb(ccb, cherror, /*cam_flags*/0,
855 /*sense_flags*/ SF_RETRY_UA | SF_RETRY_SELTO,
856 &softc->device_stats);
858 xpt_release_ccb(ccb);
864 chexchange(struct cam_periph *periph, struct changer_exchange *ce)
866 struct ch_softc *softc;
867 u_int16_t src, dst1, dst2;
872 softc = (struct ch_softc *)periph->softc;
876 if ((ce->ce_srctype > CHET_DT) || (ce->ce_fdsttype > CHET_DT) ||
877 (ce->ce_sdsttype > CHET_DT))
879 if ((ce->ce_srcunit > (softc->sc_counts[ce->ce_srctype] - 1)) ||
880 (ce->ce_fdstunit > (softc->sc_counts[ce->ce_fdsttype] - 1)) ||
881 (ce->ce_sdstunit > (softc->sc_counts[ce->ce_sdsttype] - 1)))
885 * Check the request against the changer's capabilities.
887 if (((softc->sc_exchangemask[ce->ce_srctype] &
888 (1 << ce->ce_fdsttype)) == 0) ||
889 ((softc->sc_exchangemask[ce->ce_fdsttype] &
890 (1 << ce->ce_sdsttype)) == 0))
894 * Calculate the source and destination elements.
896 src = softc->sc_firsts[ce->ce_srctype] + ce->ce_srcunit;
897 dst1 = softc->sc_firsts[ce->ce_fdsttype] + ce->ce_fdstunit;
898 dst2 = softc->sc_firsts[ce->ce_sdsttype] + ce->ce_sdstunit;
900 ccb = cam_periph_getccb(periph, /*priority*/ 1);
902 scsi_exchange_medium(&ccb->csio,
905 /* tag_action */ MSG_SIMPLE_Q_TAG,
906 /* tea */ softc->sc_picker,
910 /* invert1 */ (ce->ce_flags & CE_INVERT1) ?
912 /* invert2 */ (ce->ce_flags & CE_INVERT2) ?
914 /* sense_len */ SSD_FULL_SIZE,
915 /* timeout */ CH_TIMEOUT_EXCHANGE_MEDIUM);
917 error = cam_periph_runccb(ccb, cherror, /*cam_flags*/0,
918 /*sense_flags*/ SF_RETRY_UA | SF_RETRY_SELTO,
919 &softc->device_stats);
921 xpt_release_ccb(ccb);
927 chposition(struct cam_periph *periph, struct changer_position *cp)
929 struct ch_softc *softc;
935 softc = (struct ch_softc *)periph->softc;
940 if (cp->cp_type > CHET_DT)
942 if (cp->cp_unit > (softc->sc_counts[cp->cp_type] - 1))
946 * Calculate the destination element.
948 dst = softc->sc_firsts[cp->cp_type] + cp->cp_unit;
950 ccb = cam_periph_getccb(periph, /*priority*/ 1);
952 scsi_position_to_element(&ccb->csio,
955 /* tag_action */ MSG_SIMPLE_Q_TAG,
956 /* tea */ softc->sc_picker,
958 /* invert */ (cp->cp_flags & CP_INVERT) ?
960 /* sense_len */ SSD_FULL_SIZE,
961 /* timeout */ CH_TIMEOUT_POSITION_TO_ELEMENT);
963 error = cam_periph_runccb(ccb, cherror, /*cam_flags*/ 0,
964 /*sense_flags*/ SF_RETRY_UA | SF_RETRY_SELTO,
965 &softc->device_stats);
967 xpt_release_ccb(ccb);
973 * Copy a volume tag to a volume_tag struct, converting SCSI byte order
974 * to host native byte order in the volume serial number. The volume
975 * label as returned by the changer is transferred to user mode as
976 * nul-terminated string. Volume labels are truncated at the first
977 * space, as suggested by SCSI-2.
980 copy_voltag(struct changer_voltag *uvoltag, struct volume_tag *voltag)
983 for (i=0; i<CH_VOLTAG_MAXLEN; i++) {
984 char c = voltag->vif[i];
986 uvoltag->cv_volid[i] = c;
990 uvoltag->cv_serial = scsi_2btoul(voltag->vsn);
994 * Copy an an element status descriptor to a user-mode
995 * changer_element_status structure.
999 copy_element_status(struct ch_softc *softc,
1001 struct read_element_status_descriptor *desc,
1002 struct changer_element_status *ces)
1004 u_int16_t eaddr = scsi_2btoul(desc->eaddr);
1007 ces->ces_int_addr = eaddr;
1008 /* set up logical address in element status */
1009 for (et = CHET_MT; et <= CHET_DT; et++) {
1010 if ((softc->sc_firsts[et] <= eaddr)
1011 && ((softc->sc_firsts[et] + softc->sc_counts[et])
1013 ces->ces_addr = eaddr - softc->sc_firsts[et];
1019 ces->ces_flags = desc->flags1;
1021 ces->ces_sensecode = desc->sense_code;
1022 ces->ces_sensequal = desc->sense_qual;
1024 if (desc->flags2 & READ_ELEMENT_STATUS_INVERT)
1025 ces->ces_flags |= CES_INVERT;
1027 if (desc->flags2 & READ_ELEMENT_STATUS_SVALID) {
1029 eaddr = scsi_2btoul(desc->ssea);
1031 /* convert source address to logical format */
1032 for (et = CHET_MT; et <= CHET_DT; et++) {
1033 if ((softc->sc_firsts[et] <= eaddr)
1034 && ((softc->sc_firsts[et] + softc->sc_counts[et])
1036 ces->ces_source_addr =
1037 eaddr - softc->sc_firsts[et];
1038 ces->ces_source_type = et;
1039 ces->ces_flags |= CES_SOURCE_VALID;
1044 if (!(ces->ces_flags & CES_SOURCE_VALID))
1045 printf("ch: warning: could not map element source "
1046 "address %ud to a valid element type\n",
1051 if (flags & READ_ELEMENT_STATUS_PVOLTAG)
1052 copy_voltag(&(ces->ces_pvoltag), &(desc->pvoltag));
1053 if (flags & READ_ELEMENT_STATUS_AVOLTAG)
1054 copy_voltag(&(ces->ces_avoltag), &(desc->avoltag));
1056 if (desc->dt_scsi_flags & READ_ELEMENT_STATUS_DT_IDVALID) {
1057 ces->ces_flags |= CES_SCSIID_VALID;
1058 ces->ces_scsi_id = desc->dt_scsi_addr;
1061 if (desc->dt_scsi_addr & READ_ELEMENT_STATUS_DT_LUVALID) {
1062 ces->ces_flags |= CES_LUN_VALID;
1064 desc->dt_scsi_flags & READ_ELEMENT_STATUS_DT_LUNMASK;
1069 chgetelemstatus(struct cam_periph *periph,
1070 struct changer_element_status_request *cesr)
1072 struct read_element_status_header *st_hdr;
1073 struct read_element_status_page_header *pg_hdr;
1074 struct read_element_status_descriptor *desc;
1075 caddr_t data = NULL;
1076 size_t size, desclen;
1077 int avail, i, error = 0;
1078 struct changer_element_status *user_data = NULL;
1079 struct ch_softc *softc;
1081 int chet = cesr->cesr_element_type;
1082 int want_voltags = (cesr->cesr_flags & CESR_VOLTAGS) ? 1 : 0;
1084 softc = (struct ch_softc *)periph->softc;
1086 /* perform argument checking */
1089 * Perform a range check on the cesr_element_{base,count}
1090 * request argument fields.
1092 if ((softc->sc_counts[chet] - cesr->cesr_element_base) <= 0
1093 || (cesr->cesr_element_base + cesr->cesr_element_count)
1094 > softc->sc_counts[chet])
1098 * Request one descriptor for the given element type. This
1099 * is used to determine the size of the descriptor so that
1100 * we can allocate enough storage for all of them. We assume
1101 * that the first one can fit into 1k.
1103 data = (caddr_t)malloc(1024, M_DEVBUF, M_INTWAIT);
1105 ccb = cam_periph_getccb(periph, /*priority*/ 1);
1107 scsi_read_element_status(&ccb->csio,
1109 /* cbfcnp */ chdone,
1110 /* tag_action */ MSG_SIMPLE_Q_TAG,
1111 /* voltag */ want_voltags,
1112 /* sea */ softc->sc_firsts[chet],
1114 /* data_ptr */ data,
1115 /* dxfer_len */ 1024,
1116 /* sense_len */ SSD_FULL_SIZE,
1117 /* timeout */ CH_TIMEOUT_READ_ELEMENT_STATUS);
1119 error = cam_periph_runccb(ccb, cherror, /*cam_flags*/ 0,
1120 /*sense_flags*/ SF_RETRY_UA | SF_RETRY_SELTO,
1121 &softc->device_stats);
1126 st_hdr = (struct read_element_status_header *)data;
1127 pg_hdr = (struct read_element_status_page_header *)((uintptr_t)st_hdr +
1128 sizeof(struct read_element_status_header));
1129 desclen = scsi_2btoul(pg_hdr->edl);
1131 size = sizeof(struct read_element_status_header) +
1132 sizeof(struct read_element_status_page_header) +
1133 (desclen * cesr->cesr_element_count);
1136 * Reallocate storage for descriptors and get them from the
1139 free(data, M_DEVBUF);
1140 data = (caddr_t)malloc(size, M_DEVBUF, M_INTWAIT);
1142 scsi_read_element_status(&ccb->csio,
1144 /* cbfcnp */ chdone,
1145 /* tag_action */ MSG_SIMPLE_Q_TAG,
1146 /* voltag */ want_voltags,
1147 /* sea */ softc->sc_firsts[chet]
1148 + cesr->cesr_element_base,
1149 /* count */ cesr->cesr_element_count,
1150 /* data_ptr */ data,
1151 /* dxfer_len */ size,
1152 /* sense_len */ SSD_FULL_SIZE,
1153 /* timeout */ CH_TIMEOUT_READ_ELEMENT_STATUS);
1155 error = cam_periph_runccb(ccb, cherror, /*cam_flags*/ 0,
1156 /*sense_flags*/ SF_RETRY_UA | SF_RETRY_SELTO,
1157 &softc->device_stats);
1163 * Fill in the user status array.
1165 st_hdr = (struct read_element_status_header *)data;
1166 avail = scsi_2btoul(st_hdr->count);
1168 if (avail != cesr->cesr_element_count) {
1169 xpt_print_path(periph->path);
1170 printf("warning, READ ELEMENT STATUS avail != count\n");
1173 user_data = (struct changer_element_status *)
1174 malloc(avail * sizeof(struct changer_element_status),
1175 M_DEVBUF, M_INTWAIT | M_ZERO);
1177 desc = (struct read_element_status_descriptor *)((uintptr_t)data +
1178 sizeof(struct read_element_status_header) +
1179 sizeof(struct read_element_status_page_header));
1181 * Set up the individual element status structures
1183 for (i = 0; i < avail; ++i) {
1184 struct changer_element_status *ces = &(user_data[i]);
1186 copy_element_status(softc, pg_hdr->flags, desc, ces);
1188 desc = (struct read_element_status_descriptor *)
1189 ((uintptr_t)desc + desclen);
1192 /* Copy element status structures out to userspace. */
1193 error = copyout(user_data,
1194 cesr->cesr_element_status,
1195 avail * sizeof(struct changer_element_status));
1198 xpt_release_ccb(ccb);
1201 free(data, M_DEVBUF);
1202 if (user_data != NULL)
1203 free(user_data, M_DEVBUF);
1209 chielem(struct cam_periph *periph,
1210 unsigned int timeout)
1213 struct ch_softc *softc;
1217 timeout = CH_TIMEOUT_INITIALIZE_ELEMENT_STATUS;
1223 softc = (struct ch_softc *)periph->softc;
1225 ccb = cam_periph_getccb(periph, /*priority*/ 1);
1227 scsi_initialize_element_status(&ccb->csio,
1229 /* cbfcnp */ chdone,
1230 /* tag_action */ MSG_SIMPLE_Q_TAG,
1231 /* sense_len */ SSD_FULL_SIZE,
1232 /* timeout */ timeout);
1234 error = cam_periph_runccb(ccb, cherror, /*cam_flags*/ 0,
1235 /*sense_flags*/ SF_RETRY_UA | SF_RETRY_SELTO,
1236 &softc->device_stats);
1238 xpt_release_ccb(ccb);
1244 chsetvoltag(struct cam_periph *periph,
1245 struct changer_set_voltag_request *csvr)
1248 struct ch_softc *softc;
1251 struct scsi_send_volume_tag_parameters ssvtp;
1256 softc = (struct ch_softc *)periph->softc;
1258 bzero(&ssvtp, sizeof(ssvtp));
1259 for (i=0; i<sizeof(ssvtp.vitf); i++) {
1260 ssvtp.vitf[i] = ' ';
1266 if (csvr->csvr_type > CHET_DT)
1268 if (csvr->csvr_addr > (softc->sc_counts[csvr->csvr_type] - 1))
1271 ea = softc->sc_firsts[csvr->csvr_type] + csvr->csvr_addr;
1273 if (csvr->csvr_flags & CSVR_ALTERNATE) {
1274 switch (csvr->csvr_flags & CSVR_MODE_MASK) {
1276 sac = SEND_VOLUME_TAG_ASSERT_ALTERNATE;
1278 case CSVR_MODE_REPLACE:
1279 sac = SEND_VOLUME_TAG_REPLACE_ALTERNATE;
1281 case CSVR_MODE_CLEAR:
1282 sac = SEND_VOLUME_TAG_UNDEFINED_ALTERNATE;
1289 switch (csvr->csvr_flags & CSVR_MODE_MASK) {
1291 sac = SEND_VOLUME_TAG_ASSERT_PRIMARY;
1293 case CSVR_MODE_REPLACE:
1294 sac = SEND_VOLUME_TAG_REPLACE_PRIMARY;
1296 case CSVR_MODE_CLEAR:
1297 sac = SEND_VOLUME_TAG_UNDEFINED_PRIMARY;
1305 memcpy(ssvtp.vitf, csvr->csvr_voltag.cv_volid,
1306 min(strlen(csvr->csvr_voltag.cv_volid), sizeof(ssvtp.vitf)));
1307 scsi_ulto2b(csvr->csvr_voltag.cv_serial, ssvtp.minvsn);
1309 ccb = cam_periph_getccb(periph, /*priority*/ 1);
1311 scsi_send_volume_tag(&ccb->csio,
1313 /* cbfcnp */ chdone,
1314 /* tag_action */ MSG_SIMPLE_Q_TAG,
1315 /* element_address */ ea,
1316 /* send_action_code */ sac,
1317 /* parameters */ &ssvtp,
1318 /* sense_len */ SSD_FULL_SIZE,
1319 /* timeout */ CH_TIMEOUT_SEND_VOLTAG);
1321 error = cam_periph_runccb(ccb, cherror, /*cam_flags*/ 0,
1322 /*sense_flags*/ SF_RETRY_UA | SF_RETRY_SELTO,
1323 &softc->device_stats);
1325 xpt_release_ccb(ccb);
1332 chgetparams(struct cam_periph *periph)
1335 struct ch_softc *softc;
1337 int mode_buffer_len;
1338 struct page_element_address_assignment *ea;
1339 struct page_device_capabilities *cap;
1340 int error, from, dbd;
1341 u_int8_t *moves, *exchanges;
1345 softc = (struct ch_softc *)periph->softc;
1347 ccb = cam_periph_getccb(periph, /*priority*/ 1);
1350 * The scsi_mode_sense_data structure is just a convenience
1351 * structure that allows us to easily calculate the worst-case
1352 * storage size of the mode sense buffer.
1354 mode_buffer_len = sizeof(struct scsi_mode_sense_data);
1356 mode_buffer = malloc(mode_buffer_len, M_TEMP, M_INTWAIT | M_ZERO);
1358 if (softc->quirks & CH_Q_NO_DBD)
1364 * Get the element address assignment page.
1366 scsi_mode_sense(&ccb->csio,
1368 /* cbfcnp */ chdone,
1369 /* tag_action */ MSG_SIMPLE_Q_TAG,
1371 /* page_code */ SMS_PAGE_CTRL_CURRENT,
1372 /* page */ CH_ELEMENT_ADDR_ASSIGN_PAGE,
1373 /* param_buf */ (u_int8_t *)mode_buffer,
1374 /* param_len */ mode_buffer_len,
1375 /* sense_len */ SSD_FULL_SIZE,
1376 /* timeout */ CH_TIMEOUT_MODE_SENSE);
1378 error = cam_periph_runccb(ccb, cherror, /*cam_flags*/ 0,
1379 /* sense_flags */ SF_RETRY_UA |
1380 SF_NO_PRINT | SF_RETRY_SELTO,
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, /*cam_flags*/ 0,
1392 /*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_path(periph->path);
1405 printf("chgetparams: error getting element "
1407 xpt_release_ccb(ccb);
1408 free(mode_buffer, M_TEMP);
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*/ 0,
1443 /* sense_flags */ SF_RETRY_UA | SF_NO_PRINT |
1444 SF_RETRY_SELTO, &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, /*cam_flags*/ 0,
1455 /*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_path(periph->path);
1468 printf("chgetparams: error getting device "
1469 "capabilities page\n");
1470 xpt_release_ccb(ccb);
1471 free(mode_buffer, M_TEMP);
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_mt;
1484 exchanges = &cap->exchange_with_mt;
1485 for (from = CHET_MT; from <= CHET_DT; ++from) {
1486 softc->sc_movemask[from] = moves[from];
1487 softc->sc_exchangemask[from] = exchanges[from];
1490 free(mode_buffer, M_TEMP);
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),