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.6 2003/08/07 21:16:44 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;
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 destroy_dev(softc->dev);
315 cam_extend_release(chperiphs, periph->unit_number);
316 xpt_print_path(periph->path);
317 printf("removing device entry\n");
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 = (struct ch_softc *)malloc(sizeof(*softc),M_DEVBUF,M_NOWAIT);
384 printf("chregister: Unable to probe new device. "
385 "Unable to allocate softc\n");
386 return(CAM_REQ_CMP_ERR);
389 bzero(softc, sizeof(*softc));
390 softc->state = CH_STATE_PROBE;
391 periph->softc = softc;
392 cam_extend_set(chperiphs, periph->unit_number, periph);
393 softc->quirks = CH_Q_NONE;
396 * Changers don't have a blocksize, and obviously don't support
399 devstat_add_entry(&softc->device_stats, "ch",
400 periph->unit_number, 0,
401 DEVSTAT_NO_BLOCKSIZE | DEVSTAT_NO_ORDERED_TAGS,
402 SID_TYPE(&cgd->inq_data)| DEVSTAT_TYPE_IF_SCSI,
403 DEVSTAT_PRIORITY_OTHER);
405 /* Register the device */
406 softc->dev = make_dev(&ch_cdevsw, periph->unit_number, UID_ROOT,
407 GID_OPERATOR, 0600, "%s%d", periph->periph_name,
408 periph->unit_number);
411 * Add an async callback so that we get
412 * notified if this device goes away.
414 xpt_setup_ccb(&csa.ccb_h, periph->path, /* priority */ 5);
415 csa.ccb_h.func_code = XPT_SASYNC_CB;
416 csa.event_enable = AC_LOST_DEVICE;
417 csa.callback = chasync;
418 csa.callback_arg = periph;
419 xpt_action((union ccb *)&csa);
422 * Lock this peripheral until we are setup.
423 * This first call can't block
425 (void)cam_periph_lock(periph, 0);
426 xpt_schedule(periph, /*priority*/5);
432 chopen(dev_t dev, int flags, int fmt, struct thread *td)
434 struct cam_periph *periph;
435 struct ch_softc *softc;
440 periph = cam_extend_get(chperiphs, unit);
445 softc = (struct ch_softc *)periph->softc;
448 if (softc->flags & CH_FLAG_INVALID) {
453 if ((error = cam_periph_lock(periph, PCATCH)) != 0) {
460 if ((softc->flags & CH_FLAG_OPEN) == 0) {
461 if (cam_periph_acquire(periph) != CAM_REQ_CMP)
463 softc->flags |= CH_FLAG_OPEN;
467 * Load information about this changer device into the softc.
469 if ((error = chgetparams(periph)) != 0) {
470 softc->flags &= ~CH_FLAG_OPEN;
471 cam_periph_unlock(periph);
472 cam_periph_release(periph);
476 cam_periph_unlock(periph);
482 chclose(dev_t dev, int flag, int fmt, struct thread *td)
484 struct cam_periph *periph;
485 struct ch_softc *softc;
491 periph = cam_extend_get(chperiphs, unit);
495 softc = (struct ch_softc *)periph->softc;
497 if ((error = cam_periph_lock(periph, 0)) != 0)
500 softc->flags &= ~CH_FLAG_OPEN;
502 cam_periph_unlock(periph);
503 cam_periph_release(periph);
509 chstart(struct cam_periph *periph, union ccb *start_ccb)
511 struct ch_softc *softc;
514 softc = (struct ch_softc *)periph->softc;
516 switch (softc->state) {
517 case CH_STATE_NORMAL:
520 if (periph->immediate_priority <= periph->pinfo.priority){
521 start_ccb->ccb_h.ccb_state = CH_CCB_WAITING;
523 SLIST_INSERT_HEAD(&periph->ccb_list, &start_ccb->ccb_h,
525 periph->immediate_priority = CAM_PRIORITY_NONE;
527 wakeup(&periph->ccb_list);
538 * Include the block descriptor when calculating the mode
541 mode_buffer_len = sizeof(struct scsi_mode_header_6) +
542 sizeof(struct scsi_mode_blk_desc) +
543 sizeof(struct page_element_address_assignment);
545 mode_buffer = malloc(mode_buffer_len, M_TEMP, M_NOWAIT);
547 if (mode_buffer == NULL) {
548 printf("chstart: couldn't malloc mode sense data\n");
551 bzero(mode_buffer, mode_buffer_len);
554 * Get the element address assignment page.
556 scsi_mode_sense(&start_ccb->csio,
559 /* tag_action */ MSG_SIMPLE_Q_TAG,
560 /* dbd */ (softc->quirks & CH_Q_NO_DBD) ?
562 /* page_code */ SMS_PAGE_CTRL_CURRENT,
563 /* page */ CH_ELEMENT_ADDR_ASSIGN_PAGE,
564 /* param_buf */ (u_int8_t *)mode_buffer,
565 /* param_len */ mode_buffer_len,
566 /* sense_len */ SSD_FULL_SIZE,
567 /* timeout */ CH_TIMEOUT_MODE_SENSE);
569 start_ccb->ccb_h.ccb_bp = NULL;
570 start_ccb->ccb_h.ccb_state = CH_CCB_PROBE;
571 xpt_action(start_ccb);
578 chdone(struct cam_periph *periph, union ccb *done_ccb)
580 struct ch_softc *softc;
581 struct ccb_scsiio *csio;
583 softc = (struct ch_softc *)periph->softc;
584 csio = &done_ccb->csio;
586 switch(done_ccb->ccb_h.ccb_state) {
589 struct scsi_mode_header_6 *mode_header;
590 struct page_element_address_assignment *ea;
591 char announce_buf[80];
594 mode_header = (struct scsi_mode_header_6 *)csio->data_ptr;
596 ea = (struct page_element_address_assignment *)
597 find_mode_page_6(mode_header);
599 if ((done_ccb->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP){
601 softc->sc_firsts[CHET_MT] = scsi_2btoul(ea->mtea);
602 softc->sc_counts[CHET_MT] = scsi_2btoul(ea->nmte);
603 softc->sc_firsts[CHET_ST] = scsi_2btoul(ea->fsea);
604 softc->sc_counts[CHET_ST] = scsi_2btoul(ea->nse);
605 softc->sc_firsts[CHET_IE] = scsi_2btoul(ea->fieea);
606 softc->sc_counts[CHET_IE] = scsi_2btoul(ea->niee);
607 softc->sc_firsts[CHET_DT] = scsi_2btoul(ea->fdtea);
608 softc->sc_counts[CHET_DT] = scsi_2btoul(ea->ndte);
609 softc->sc_picker = softc->sc_firsts[CHET_MT];
611 #define PLURAL(c) (c) == 1 ? "" : "s"
612 snprintf(announce_buf, sizeof(announce_buf),
613 "%d slot%s, %d drive%s, "
614 "%d picker%s, %d portal%s",
615 softc->sc_counts[CHET_ST],
616 PLURAL(softc->sc_counts[CHET_ST]),
617 softc->sc_counts[CHET_DT],
618 PLURAL(softc->sc_counts[CHET_DT]),
619 softc->sc_counts[CHET_MT],
620 PLURAL(softc->sc_counts[CHET_MT]),
621 softc->sc_counts[CHET_IE],
622 PLURAL(softc->sc_counts[CHET_IE]));
627 error = cherror(done_ccb, 0, SF_RETRY_UA |
628 SF_NO_PRINT | SF_RETRY_SELTO);
630 * Retry any UNIT ATTENTION type errors. They
631 * are expected at boot.
633 if (error == ERESTART) {
635 * A retry was scheuled, so
639 } else if (error != 0) {
641 struct scsi_mode_sense_6 *sms;
643 sms = (struct scsi_mode_sense_6 *)
644 done_ccb->csio.cdb_io.cdb_bytes;
647 * Check to see if block descriptors were
648 * disabled. Some devices don't like that.
649 * We're taking advantage of the fact that
650 * the first few bytes of the 6 and 10 byte
651 * mode sense commands are the same. If
652 * block descriptors were disabled, enable
653 * them and re-send the command.
655 if (sms->byte2 & SMS_DBD) {
656 sms->byte2 &= ~SMS_DBD;
657 xpt_action(done_ccb);
658 softc->quirks |= CH_Q_NO_DBD;
663 /* Don't wedge this device's queue */
664 cam_release_devq(done_ccb->ccb_h.path,
673 if ((done_ccb->ccb_h.status & CAM_STATUS_MASK)
674 == CAM_SCSI_STATUS_ERROR)
675 scsi_sense_print(&done_ccb->csio);
677 xpt_print_path(periph->path);
678 printf("got CAM status %#x\n",
679 done_ccb->ccb_h.status);
681 xpt_print_path(periph->path);
682 printf("fatal error, failed to attach to"
685 cam_periph_invalidate(periph);
687 announce_buf[0] = '\0';
690 if (announce_buf[0] != '\0')
691 xpt_announce_periph(periph, announce_buf);
692 softc->state = CH_STATE_NORMAL;
693 free(mode_header, M_TEMP);
695 * Since our peripheral may be invalidated by an error
696 * above or an external event, we must release our CCB
697 * before releasing the probe lock on the peripheral.
698 * The peripheral will only go away once the last lock
699 * is removed, and we need it around for the CCB release
702 xpt_release_ccb(done_ccb);
703 cam_periph_unlock(periph);
708 /* Caller will release the CCB */
709 wakeup(&done_ccb->ccb_h.cbfcnp);
715 xpt_release_ccb(done_ccb);
719 cherror(union ccb *ccb, u_int32_t cam_flags, u_int32_t sense_flags)
721 struct ch_softc *softc;
722 struct cam_periph *periph;
724 periph = xpt_path_periph(ccb->ccb_h.path);
725 softc = (struct ch_softc *)periph->softc;
727 return (cam_periph_error(ccb, cam_flags, sense_flags,
732 chioctl(dev_t dev, u_long cmd, caddr_t addr, int flag, struct thread *td)
734 struct cam_periph *periph;
735 struct ch_softc *softc;
741 periph = cam_extend_get(chperiphs, unit);
745 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("entering chioctl\n"));
747 softc = (struct ch_softc *)periph->softc;
751 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE,
752 ("trying to do ioctl %#lx\n", cmd));
755 * If this command can change the device's state, we must
756 * have the device open for writing.
765 if ((flag & FWRITE) == 0)
771 error = chmove(periph, (struct changer_move *)addr);
775 error = chexchange(periph, (struct changer_exchange *)addr);
779 error = chposition(periph, (struct changer_position *)addr);
783 *(int *)addr = softc->sc_picker - softc->sc_firsts[CHET_MT];
788 int new_picker = *(int *)addr;
790 if (new_picker > (softc->sc_counts[CHET_MT] - 1))
792 softc->sc_picker = softc->sc_firsts[CHET_MT] + new_picker;
797 struct changer_params *cp = (struct changer_params *)addr;
799 cp->cp_npickers = softc->sc_counts[CHET_MT];
800 cp->cp_nslots = softc->sc_counts[CHET_ST];
801 cp->cp_nportals = softc->sc_counts[CHET_IE];
802 cp->cp_ndrives = softc->sc_counts[CHET_DT];
806 error = chielem(periph, *(unsigned int *)addr);
811 error = chgetelemstatus(periph,
812 (struct changer_element_status_request *) addr);
818 error = chsetvoltag(periph,
819 (struct changer_set_voltag_request *) addr);
823 /* Implement prevent/allow? */
826 error = cam_periph_ioctl(periph, cmd, addr, cherror);
834 chmove(struct cam_periph *periph, struct changer_move *cm)
836 struct ch_softc *softc;
837 u_int16_t fromelem, toelem;
842 softc = (struct ch_softc *)periph->softc;
847 if ((cm->cm_fromtype > CHET_DT) || (cm->cm_totype > CHET_DT))
849 if ((cm->cm_fromunit > (softc->sc_counts[cm->cm_fromtype] - 1)) ||
850 (cm->cm_tounit > (softc->sc_counts[cm->cm_totype] - 1)))
854 * Check the request against the changer's capabilities.
856 if ((softc->sc_movemask[cm->cm_fromtype] & (1 << cm->cm_totype)) == 0)
860 * Calculate the source and destination elements.
862 fromelem = softc->sc_firsts[cm->cm_fromtype] + cm->cm_fromunit;
863 toelem = softc->sc_firsts[cm->cm_totype] + cm->cm_tounit;
865 ccb = cam_periph_getccb(periph, /*priority*/ 1);
867 scsi_move_medium(&ccb->csio,
870 /* tag_action */ MSG_SIMPLE_Q_TAG,
871 /* tea */ softc->sc_picker,
874 /* invert */ (cm->cm_flags & CM_INVERT) ? TRUE : FALSE,
875 /* sense_len */ SSD_FULL_SIZE,
876 /* timeout */ CH_TIMEOUT_MOVE_MEDIUM);
878 error = cam_periph_runccb(ccb, cherror, /*cam_flags*/0,
879 /*sense_flags*/ SF_RETRY_UA | SF_RETRY_SELTO,
880 &softc->device_stats);
882 xpt_release_ccb(ccb);
888 chexchange(struct cam_periph *periph, struct changer_exchange *ce)
890 struct ch_softc *softc;
891 u_int16_t src, dst1, dst2;
896 softc = (struct ch_softc *)periph->softc;
900 if ((ce->ce_srctype > CHET_DT) || (ce->ce_fdsttype > CHET_DT) ||
901 (ce->ce_sdsttype > CHET_DT))
903 if ((ce->ce_srcunit > (softc->sc_counts[ce->ce_srctype] - 1)) ||
904 (ce->ce_fdstunit > (softc->sc_counts[ce->ce_fdsttype] - 1)) ||
905 (ce->ce_sdstunit > (softc->sc_counts[ce->ce_sdsttype] - 1)))
909 * Check the request against the changer's capabilities.
911 if (((softc->sc_exchangemask[ce->ce_srctype] &
912 (1 << ce->ce_fdsttype)) == 0) ||
913 ((softc->sc_exchangemask[ce->ce_fdsttype] &
914 (1 << ce->ce_sdsttype)) == 0))
918 * Calculate the source and destination elements.
920 src = softc->sc_firsts[ce->ce_srctype] + ce->ce_srcunit;
921 dst1 = softc->sc_firsts[ce->ce_fdsttype] + ce->ce_fdstunit;
922 dst2 = softc->sc_firsts[ce->ce_sdsttype] + ce->ce_sdstunit;
924 ccb = cam_periph_getccb(periph, /*priority*/ 1);
926 scsi_exchange_medium(&ccb->csio,
929 /* tag_action */ MSG_SIMPLE_Q_TAG,
930 /* tea */ softc->sc_picker,
934 /* invert1 */ (ce->ce_flags & CE_INVERT1) ?
936 /* invert2 */ (ce->ce_flags & CE_INVERT2) ?
938 /* sense_len */ SSD_FULL_SIZE,
939 /* timeout */ CH_TIMEOUT_EXCHANGE_MEDIUM);
941 error = cam_periph_runccb(ccb, cherror, /*cam_flags*/0,
942 /*sense_flags*/ SF_RETRY_UA | SF_RETRY_SELTO,
943 &softc->device_stats);
945 xpt_release_ccb(ccb);
951 chposition(struct cam_periph *periph, struct changer_position *cp)
953 struct ch_softc *softc;
959 softc = (struct ch_softc *)periph->softc;
964 if (cp->cp_type > CHET_DT)
966 if (cp->cp_unit > (softc->sc_counts[cp->cp_type] - 1))
970 * Calculate the destination element.
972 dst = softc->sc_firsts[cp->cp_type] + cp->cp_unit;
974 ccb = cam_periph_getccb(periph, /*priority*/ 1);
976 scsi_position_to_element(&ccb->csio,
979 /* tag_action */ MSG_SIMPLE_Q_TAG,
980 /* tea */ softc->sc_picker,
982 /* invert */ (cp->cp_flags & CP_INVERT) ?
984 /* sense_len */ SSD_FULL_SIZE,
985 /* timeout */ CH_TIMEOUT_POSITION_TO_ELEMENT);
987 error = cam_periph_runccb(ccb, cherror, /*cam_flags*/ 0,
988 /*sense_flags*/ SF_RETRY_UA | SF_RETRY_SELTO,
989 &softc->device_stats);
991 xpt_release_ccb(ccb);
997 * Copy a volume tag to a volume_tag struct, converting SCSI byte order
998 * to host native byte order in the volume serial number. The volume
999 * label as returned by the changer is transferred to user mode as
1000 * nul-terminated string. Volume labels are truncated at the first
1001 * space, as suggested by SCSI-2.
1004 copy_voltag(struct changer_voltag *uvoltag, struct volume_tag *voltag)
1007 for (i=0; i<CH_VOLTAG_MAXLEN; i++) {
1008 char c = voltag->vif[i];
1010 uvoltag->cv_volid[i] = c;
1014 uvoltag->cv_serial = scsi_2btoul(voltag->vsn);
1018 * Copy an an element status descriptor to a user-mode
1019 * changer_element_status structure.
1023 copy_element_status(struct ch_softc *softc,
1025 struct read_element_status_descriptor *desc,
1026 struct changer_element_status *ces)
1028 u_int16_t eaddr = scsi_2btoul(desc->eaddr);
1031 ces->ces_int_addr = eaddr;
1032 /* set up logical address in element status */
1033 for (et = CHET_MT; et <= CHET_DT; et++) {
1034 if ((softc->sc_firsts[et] <= eaddr)
1035 && ((softc->sc_firsts[et] + softc->sc_counts[et])
1037 ces->ces_addr = eaddr - softc->sc_firsts[et];
1043 ces->ces_flags = desc->flags1;
1045 ces->ces_sensecode = desc->sense_code;
1046 ces->ces_sensequal = desc->sense_qual;
1048 if (desc->flags2 & READ_ELEMENT_STATUS_INVERT)
1049 ces->ces_flags |= CES_INVERT;
1051 if (desc->flags2 & READ_ELEMENT_STATUS_SVALID) {
1053 eaddr = scsi_2btoul(desc->ssea);
1055 /* convert source address to logical format */
1056 for (et = CHET_MT; et <= CHET_DT; et++) {
1057 if ((softc->sc_firsts[et] <= eaddr)
1058 && ((softc->sc_firsts[et] + softc->sc_counts[et])
1060 ces->ces_source_addr =
1061 eaddr - softc->sc_firsts[et];
1062 ces->ces_source_type = et;
1063 ces->ces_flags |= CES_SOURCE_VALID;
1068 if (!(ces->ces_flags & CES_SOURCE_VALID))
1069 printf("ch: warning: could not map element source "
1070 "address %ud to a valid element type\n",
1075 if (flags & READ_ELEMENT_STATUS_PVOLTAG)
1076 copy_voltag(&(ces->ces_pvoltag), &(desc->pvoltag));
1077 if (flags & READ_ELEMENT_STATUS_AVOLTAG)
1078 copy_voltag(&(ces->ces_avoltag), &(desc->avoltag));
1080 if (desc->dt_scsi_flags & READ_ELEMENT_STATUS_DT_IDVALID) {
1081 ces->ces_flags |= CES_SCSIID_VALID;
1082 ces->ces_scsi_id = desc->dt_scsi_addr;
1085 if (desc->dt_scsi_addr & READ_ELEMENT_STATUS_DT_LUVALID) {
1086 ces->ces_flags |= CES_LUN_VALID;
1088 desc->dt_scsi_flags & READ_ELEMENT_STATUS_DT_LUNMASK;
1093 chgetelemstatus(struct cam_periph *periph,
1094 struct changer_element_status_request *cesr)
1096 struct read_element_status_header *st_hdr;
1097 struct read_element_status_page_header *pg_hdr;
1098 struct read_element_status_descriptor *desc;
1099 caddr_t data = NULL;
1100 size_t size, desclen;
1101 int avail, i, error = 0;
1102 struct changer_element_status *user_data = NULL;
1103 struct ch_softc *softc;
1105 int chet = cesr->cesr_element_type;
1106 int want_voltags = (cesr->cesr_flags & CESR_VOLTAGS) ? 1 : 0;
1108 softc = (struct ch_softc *)periph->softc;
1110 /* perform argument checking */
1113 * Perform a range check on the cesr_element_{base,count}
1114 * request argument fields.
1116 if ((softc->sc_counts[chet] - cesr->cesr_element_base) <= 0
1117 || (cesr->cesr_element_base + cesr->cesr_element_count)
1118 > softc->sc_counts[chet])
1122 * Request one descriptor for the given element type. This
1123 * is used to determine the size of the descriptor so that
1124 * we can allocate enough storage for all of them. We assume
1125 * that the first one can fit into 1k.
1127 data = (caddr_t)malloc(1024, M_DEVBUF, M_WAITOK);
1129 ccb = cam_periph_getccb(periph, /*priority*/ 1);
1131 scsi_read_element_status(&ccb->csio,
1133 /* cbfcnp */ chdone,
1134 /* tag_action */ MSG_SIMPLE_Q_TAG,
1135 /* voltag */ want_voltags,
1136 /* sea */ softc->sc_firsts[chet],
1138 /* data_ptr */ data,
1139 /* dxfer_len */ 1024,
1140 /* sense_len */ SSD_FULL_SIZE,
1141 /* timeout */ CH_TIMEOUT_READ_ELEMENT_STATUS);
1143 error = cam_periph_runccb(ccb, cherror, /*cam_flags*/ 0,
1144 /*sense_flags*/ SF_RETRY_UA | SF_RETRY_SELTO,
1145 &softc->device_stats);
1150 st_hdr = (struct read_element_status_header *)data;
1151 pg_hdr = (struct read_element_status_page_header *)((uintptr_t)st_hdr +
1152 sizeof(struct read_element_status_header));
1153 desclen = scsi_2btoul(pg_hdr->edl);
1155 size = sizeof(struct read_element_status_header) +
1156 sizeof(struct read_element_status_page_header) +
1157 (desclen * cesr->cesr_element_count);
1160 * Reallocate storage for descriptors and get them from the
1163 free(data, M_DEVBUF);
1164 data = (caddr_t)malloc(size, M_DEVBUF, M_WAITOK);
1166 scsi_read_element_status(&ccb->csio,
1168 /* cbfcnp */ chdone,
1169 /* tag_action */ MSG_SIMPLE_Q_TAG,
1170 /* voltag */ want_voltags,
1171 /* sea */ softc->sc_firsts[chet]
1172 + cesr->cesr_element_base,
1173 /* count */ cesr->cesr_element_count,
1174 /* data_ptr */ data,
1175 /* dxfer_len */ size,
1176 /* sense_len */ SSD_FULL_SIZE,
1177 /* timeout */ CH_TIMEOUT_READ_ELEMENT_STATUS);
1179 error = cam_periph_runccb(ccb, cherror, /*cam_flags*/ 0,
1180 /*sense_flags*/ SF_RETRY_UA | SF_RETRY_SELTO,
1181 &softc->device_stats);
1187 * Fill in the user status array.
1189 st_hdr = (struct read_element_status_header *)data;
1190 avail = scsi_2btoul(st_hdr->count);
1192 if (avail != cesr->cesr_element_count) {
1193 xpt_print_path(periph->path);
1194 printf("warning, READ ELEMENT STATUS avail != count\n");
1197 user_data = (struct changer_element_status *)
1198 malloc(avail * sizeof(struct changer_element_status),
1199 M_DEVBUF, M_WAITOK | M_ZERO);
1201 desc = (struct read_element_status_descriptor *)((uintptr_t)data +
1202 sizeof(struct read_element_status_header) +
1203 sizeof(struct read_element_status_page_header));
1205 * Set up the individual element status structures
1207 for (i = 0; i < avail; ++i) {
1208 struct changer_element_status *ces = &(user_data[i]);
1210 copy_element_status(softc, pg_hdr->flags, desc, ces);
1212 desc = (struct read_element_status_descriptor *)
1213 ((uintptr_t)desc + desclen);
1216 /* Copy element status structures out to userspace. */
1217 error = copyout(user_data,
1218 cesr->cesr_element_status,
1219 avail * sizeof(struct changer_element_status));
1222 xpt_release_ccb(ccb);
1225 free(data, M_DEVBUF);
1226 if (user_data != NULL)
1227 free(user_data, M_DEVBUF);
1233 chielem(struct cam_periph *periph,
1234 unsigned int timeout)
1237 struct ch_softc *softc;
1241 timeout = CH_TIMEOUT_INITIALIZE_ELEMENT_STATUS;
1247 softc = (struct ch_softc *)periph->softc;
1249 ccb = cam_periph_getccb(periph, /*priority*/ 1);
1251 scsi_initialize_element_status(&ccb->csio,
1253 /* cbfcnp */ chdone,
1254 /* tag_action */ MSG_SIMPLE_Q_TAG,
1255 /* sense_len */ SSD_FULL_SIZE,
1256 /* timeout */ timeout);
1258 error = cam_periph_runccb(ccb, cherror, /*cam_flags*/ 0,
1259 /*sense_flags*/ SF_RETRY_UA | SF_RETRY_SELTO,
1260 &softc->device_stats);
1262 xpt_release_ccb(ccb);
1268 chsetvoltag(struct cam_periph *periph,
1269 struct changer_set_voltag_request *csvr)
1272 struct ch_softc *softc;
1275 struct scsi_send_volume_tag_parameters ssvtp;
1280 softc = (struct ch_softc *)periph->softc;
1282 bzero(&ssvtp, sizeof(ssvtp));
1283 for (i=0; i<sizeof(ssvtp.vitf); i++) {
1284 ssvtp.vitf[i] = ' ';
1290 if (csvr->csvr_type > CHET_DT)
1292 if (csvr->csvr_addr > (softc->sc_counts[csvr->csvr_type] - 1))
1295 ea = softc->sc_firsts[csvr->csvr_type] + csvr->csvr_addr;
1297 if (csvr->csvr_flags & CSVR_ALTERNATE) {
1298 switch (csvr->csvr_flags & CSVR_MODE_MASK) {
1300 sac = SEND_VOLUME_TAG_ASSERT_ALTERNATE;
1302 case CSVR_MODE_REPLACE:
1303 sac = SEND_VOLUME_TAG_REPLACE_ALTERNATE;
1305 case CSVR_MODE_CLEAR:
1306 sac = SEND_VOLUME_TAG_UNDEFINED_ALTERNATE;
1313 switch (csvr->csvr_flags & CSVR_MODE_MASK) {
1315 sac = SEND_VOLUME_TAG_ASSERT_PRIMARY;
1317 case CSVR_MODE_REPLACE:
1318 sac = SEND_VOLUME_TAG_REPLACE_PRIMARY;
1320 case CSVR_MODE_CLEAR:
1321 sac = SEND_VOLUME_TAG_UNDEFINED_PRIMARY;
1329 memcpy(ssvtp.vitf, csvr->csvr_voltag.cv_volid,
1330 min(strlen(csvr->csvr_voltag.cv_volid), sizeof(ssvtp.vitf)));
1331 scsi_ulto2b(csvr->csvr_voltag.cv_serial, ssvtp.minvsn);
1333 ccb = cam_periph_getccb(periph, /*priority*/ 1);
1335 scsi_send_volume_tag(&ccb->csio,
1337 /* cbfcnp */ chdone,
1338 /* tag_action */ MSG_SIMPLE_Q_TAG,
1339 /* element_address */ ea,
1340 /* send_action_code */ sac,
1341 /* parameters */ &ssvtp,
1342 /* sense_len */ SSD_FULL_SIZE,
1343 /* timeout */ CH_TIMEOUT_SEND_VOLTAG);
1345 error = cam_periph_runccb(ccb, cherror, /*cam_flags*/ 0,
1346 /*sense_flags*/ SF_RETRY_UA | SF_RETRY_SELTO,
1347 &softc->device_stats);
1349 xpt_release_ccb(ccb);
1356 chgetparams(struct cam_periph *periph)
1359 struct ch_softc *softc;
1361 int mode_buffer_len;
1362 struct page_element_address_assignment *ea;
1363 struct page_device_capabilities *cap;
1364 int error, from, dbd;
1365 u_int8_t *moves, *exchanges;
1369 softc = (struct ch_softc *)periph->softc;
1371 ccb = cam_periph_getccb(periph, /*priority*/ 1);
1374 * The scsi_mode_sense_data structure is just a convenience
1375 * structure that allows us to easily calculate the worst-case
1376 * storage size of the mode sense buffer.
1378 mode_buffer_len = sizeof(struct scsi_mode_sense_data);
1380 mode_buffer = malloc(mode_buffer_len, M_TEMP, M_NOWAIT);
1382 if (mode_buffer == NULL) {
1383 printf("chgetparams: couldn't malloc mode sense data\n");
1387 bzero(mode_buffer, mode_buffer_len);
1389 if (softc->quirks & CH_Q_NO_DBD)
1395 * Get the element address assignment page.
1397 scsi_mode_sense(&ccb->csio,
1399 /* cbfcnp */ chdone,
1400 /* tag_action */ MSG_SIMPLE_Q_TAG,
1402 /* page_code */ SMS_PAGE_CTRL_CURRENT,
1403 /* page */ CH_ELEMENT_ADDR_ASSIGN_PAGE,
1404 /* param_buf */ (u_int8_t *)mode_buffer,
1405 /* param_len */ mode_buffer_len,
1406 /* sense_len */ SSD_FULL_SIZE,
1407 /* timeout */ CH_TIMEOUT_MODE_SENSE);
1409 error = cam_periph_runccb(ccb, cherror, /*cam_flags*/ 0,
1410 /* sense_flags */ SF_RETRY_UA |
1411 SF_NO_PRINT | SF_RETRY_SELTO,
1412 &softc->device_stats);
1416 struct scsi_mode_sense_6 *sms;
1418 sms = (struct scsi_mode_sense_6 *)
1419 ccb->csio.cdb_io.cdb_bytes;
1421 sms->byte2 &= ~SMS_DBD;
1422 error = cam_periph_runccb(ccb, cherror, /*cam_flags*/ 0,
1423 /*sense_flags*/ SF_RETRY_UA |
1425 &softc->device_stats);
1428 * Since we disabled sense printing above, print
1429 * out the sense here since we got an error.
1431 scsi_sense_print(&ccb->csio);
1435 xpt_print_path(periph->path);
1436 printf("chgetparams: error getting element "
1438 xpt_release_ccb(ccb);
1439 free(mode_buffer, M_TEMP);
1444 ea = (struct page_element_address_assignment *)
1445 find_mode_page_6((struct scsi_mode_header_6 *)mode_buffer);
1447 softc->sc_firsts[CHET_MT] = scsi_2btoul(ea->mtea);
1448 softc->sc_counts[CHET_MT] = scsi_2btoul(ea->nmte);
1449 softc->sc_firsts[CHET_ST] = scsi_2btoul(ea->fsea);
1450 softc->sc_counts[CHET_ST] = scsi_2btoul(ea->nse);
1451 softc->sc_firsts[CHET_IE] = scsi_2btoul(ea->fieea);
1452 softc->sc_counts[CHET_IE] = scsi_2btoul(ea->niee);
1453 softc->sc_firsts[CHET_DT] = scsi_2btoul(ea->fdtea);
1454 softc->sc_counts[CHET_DT] = scsi_2btoul(ea->ndte);
1456 bzero(mode_buffer, mode_buffer_len);
1459 * Now get the device capabilities page.
1461 scsi_mode_sense(&ccb->csio,
1463 /* cbfcnp */ chdone,
1464 /* tag_action */ MSG_SIMPLE_Q_TAG,
1466 /* page_code */ SMS_PAGE_CTRL_CURRENT,
1467 /* page */ CH_DEVICE_CAP_PAGE,
1468 /* param_buf */ (u_int8_t *)mode_buffer,
1469 /* param_len */ mode_buffer_len,
1470 /* sense_len */ SSD_FULL_SIZE,
1471 /* timeout */ CH_TIMEOUT_MODE_SENSE);
1473 error = cam_periph_runccb(ccb, cherror, /*cam_flags*/ 0,
1474 /* sense_flags */ SF_RETRY_UA | SF_NO_PRINT |
1475 SF_RETRY_SELTO, &softc->device_stats);
1479 struct scsi_mode_sense_6 *sms;
1481 sms = (struct scsi_mode_sense_6 *)
1482 ccb->csio.cdb_io.cdb_bytes;
1484 sms->byte2 &= ~SMS_DBD;
1485 error = cam_periph_runccb(ccb, cherror, /*cam_flags*/ 0,
1486 /*sense_flags*/ SF_RETRY_UA |
1488 &softc->device_stats);
1491 * Since we disabled sense printing above, print
1492 * out the sense here since we got an error.
1494 scsi_sense_print(&ccb->csio);
1498 xpt_print_path(periph->path);
1499 printf("chgetparams: error getting device "
1500 "capabilities page\n");
1501 xpt_release_ccb(ccb);
1502 free(mode_buffer, M_TEMP);
1507 xpt_release_ccb(ccb);
1509 cap = (struct page_device_capabilities *)
1510 find_mode_page_6((struct scsi_mode_header_6 *)mode_buffer);
1512 bzero(softc->sc_movemask, sizeof(softc->sc_movemask));
1513 bzero(softc->sc_exchangemask, sizeof(softc->sc_exchangemask));
1514 moves = &cap->move_from_mt;
1515 exchanges = &cap->exchange_with_mt;
1516 for (from = CHET_MT; from <= CHET_DT; ++from) {
1517 softc->sc_movemask[from] = moves[from];
1518 softc->sc_exchangemask[from] = exchanges[from];
1521 free(mode_buffer, M_TEMP);
1527 scsi_move_medium(struct ccb_scsiio *csio, u_int32_t retries,
1528 void (*cbfcnp)(struct cam_periph *, union ccb *),
1529 u_int8_t tag_action, u_int32_t tea, u_int32_t src,
1530 u_int32_t dst, int invert, u_int8_t sense_len,
1533 struct scsi_move_medium *scsi_cmd;
1535 scsi_cmd = (struct scsi_move_medium *)&csio->cdb_io.cdb_bytes;
1536 bzero(scsi_cmd, sizeof(*scsi_cmd));
1538 scsi_cmd->opcode = MOVE_MEDIUM;
1540 scsi_ulto2b(tea, scsi_cmd->tea);
1541 scsi_ulto2b(src, scsi_cmd->src);
1542 scsi_ulto2b(dst, scsi_cmd->dst);
1545 scsi_cmd->invert |= MOVE_MEDIUM_INVERT;
1550 /*flags*/ CAM_DIR_NONE,
1560 scsi_exchange_medium(struct ccb_scsiio *csio, u_int32_t retries,
1561 void (*cbfcnp)(struct cam_periph *, union ccb *),
1562 u_int8_t tag_action, u_int32_t tea, u_int32_t src,
1563 u_int32_t dst1, u_int32_t dst2, int invert1,
1564 int invert2, u_int8_t sense_len, u_int32_t timeout)
1566 struct scsi_exchange_medium *scsi_cmd;
1568 scsi_cmd = (struct scsi_exchange_medium *)&csio->cdb_io.cdb_bytes;
1569 bzero(scsi_cmd, sizeof(*scsi_cmd));
1571 scsi_cmd->opcode = EXCHANGE_MEDIUM;
1573 scsi_ulto2b(tea, scsi_cmd->tea);
1574 scsi_ulto2b(src, scsi_cmd->src);
1575 scsi_ulto2b(dst1, scsi_cmd->fdst);
1576 scsi_ulto2b(dst2, scsi_cmd->sdst);
1579 scsi_cmd->invert |= EXCHANGE_MEDIUM_INV1;
1582 scsi_cmd->invert |= EXCHANGE_MEDIUM_INV2;
1587 /*flags*/ CAM_DIR_NONE,
1597 scsi_position_to_element(struct ccb_scsiio *csio, u_int32_t retries,
1598 void (*cbfcnp)(struct cam_periph *, union ccb *),
1599 u_int8_t tag_action, u_int32_t tea, u_int32_t dst,
1600 int invert, u_int8_t sense_len, u_int32_t timeout)
1602 struct scsi_position_to_element *scsi_cmd;
1604 scsi_cmd = (struct scsi_position_to_element *)&csio->cdb_io.cdb_bytes;
1605 bzero(scsi_cmd, sizeof(*scsi_cmd));
1607 scsi_cmd->opcode = POSITION_TO_ELEMENT;
1609 scsi_ulto2b(tea, scsi_cmd->tea);
1610 scsi_ulto2b(dst, scsi_cmd->dst);
1613 scsi_cmd->invert |= POSITION_TO_ELEMENT_INVERT;
1618 /*flags*/ CAM_DIR_NONE,
1628 scsi_read_element_status(struct ccb_scsiio *csio, u_int32_t retries,
1629 void (*cbfcnp)(struct cam_periph *, union ccb *),
1630 u_int8_t tag_action, int voltag, u_int32_t sea,
1631 u_int32_t count, u_int8_t *data_ptr,
1632 u_int32_t dxfer_len, u_int8_t sense_len,
1635 struct scsi_read_element_status *scsi_cmd;
1637 scsi_cmd = (struct scsi_read_element_status *)&csio->cdb_io.cdb_bytes;
1638 bzero(scsi_cmd, sizeof(*scsi_cmd));
1640 scsi_cmd->opcode = READ_ELEMENT_STATUS;
1642 scsi_ulto2b(sea, scsi_cmd->sea);
1643 scsi_ulto2b(count, scsi_cmd->count);
1644 scsi_ulto3b(dxfer_len, scsi_cmd->len);
1647 scsi_cmd->byte2 |= READ_ELEMENT_STATUS_VOLTAG;
1652 /*flags*/ CAM_DIR_IN,
1662 scsi_initialize_element_status(struct ccb_scsiio *csio, u_int32_t retries,
1663 void (*cbfcnp)(struct cam_periph *, union ccb *),
1664 u_int8_t tag_action, u_int8_t sense_len,
1667 struct scsi_initialize_element_status *scsi_cmd;
1669 scsi_cmd = (struct scsi_initialize_element_status *)
1670 &csio->cdb_io.cdb_bytes;
1671 bzero(scsi_cmd, sizeof(*scsi_cmd));
1673 scsi_cmd->opcode = INITIALIZE_ELEMENT_STATUS;
1678 /*flags*/ CAM_DIR_NONE,
1680 /* data_ptr */ NULL,
1688 scsi_send_volume_tag(struct ccb_scsiio *csio, u_int32_t retries,
1689 void (*cbfcnp)(struct cam_periph *, union ccb *),
1690 u_int8_t tag_action,
1691 u_int16_t element_address,
1692 u_int8_t send_action_code,
1693 struct scsi_send_volume_tag_parameters *parameters,
1694 u_int8_t sense_len, u_int32_t timeout)
1696 struct scsi_send_volume_tag *scsi_cmd;
1698 scsi_cmd = (struct scsi_send_volume_tag *) &csio->cdb_io.cdb_bytes;
1699 bzero(scsi_cmd, sizeof(*scsi_cmd));
1701 scsi_cmd->opcode = SEND_VOLUME_TAG;
1702 scsi_ulto2b(element_address, scsi_cmd->ea);
1703 scsi_cmd->sac = send_action_code;
1704 scsi_ulto2b(sizeof(*parameters), scsi_cmd->pll);
1709 /*flags*/ CAM_DIR_OUT,
1711 /* data_ptr */ (u_int8_t *) parameters,
1712 sizeof(*parameters),