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.22 2007/11/18 17:53:01 pavalos 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>
82 #include <sys/errno.h>
83 #include <sys/devicestat.h>
84 #include <sys/thread2.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_bio 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 PERIPHDRIVER_DECLARE(ch, chdriver);
217 static struct dev_ops ch_ops = {
218 { "ch", CH_CDEV_MAJOR, 0 },
224 static struct extend_array *chperiphs;
230 struct cam_path *path;
233 * Create our extend array for storing the devices we attach to.
235 chperiphs = cam_extend_new();
236 if (chperiphs == NULL) {
237 kprintf("ch: Failed to alloc extend array!\n");
242 * Install a global async callback. This callback will
243 * receive async callbacks like "new device found".
245 status = xpt_create_path(&path, /*periph*/NULL, CAM_XPT_PATH_ID,
246 CAM_TARGET_WILDCARD, CAM_LUN_WILDCARD);
248 if (status == CAM_REQ_CMP) {
249 struct ccb_setasync csa;
251 xpt_setup_ccb(&csa.ccb_h, path, /*priority*/5);
252 csa.ccb_h.func_code = XPT_SASYNC_CB;
253 csa.event_enable = AC_FOUND_DEVICE;
254 csa.callback = chasync;
255 csa.callback_arg = NULL;
256 xpt_action((union ccb *)&csa);
257 status = csa.ccb_h.status;
261 if (status != CAM_REQ_CMP) {
262 kprintf("ch: Failed to attach master async callback "
263 "due to status 0x%x!\n", status);
268 choninvalidate(struct cam_periph *periph)
270 struct ch_softc *softc;
271 struct ccb_setasync csa;
273 softc = (struct ch_softc *)periph->softc;
276 * De-register any async callbacks.
278 xpt_setup_ccb(&csa.ccb_h, periph->path,
280 csa.ccb_h.func_code = XPT_SASYNC_CB;
281 csa.event_enable = 0;
282 csa.callback = chasync;
283 csa.callback_arg = periph;
284 xpt_action((union ccb *)&csa);
286 softc->flags |= CH_FLAG_INVALID;
288 xpt_print_path(periph->path);
289 kprintf("lost device\n");
294 chcleanup(struct cam_periph *periph)
296 struct ch_softc *softc;
298 softc = (struct ch_softc *)periph->softc;
300 devstat_remove_entry(&softc->device_stats);
301 cam_extend_release(chperiphs, periph->unit_number);
302 xpt_print_path(periph->path);
303 kprintf("removing device entry\n");
304 dev_ops_remove(&ch_ops, -1, periph->unit_number);
305 kfree(softc, M_DEVBUF);
309 chasync(void *callback_arg, u_int32_t code, struct cam_path *path, void *arg)
311 struct cam_periph *periph;
313 periph = (struct cam_periph *)callback_arg;
316 case AC_FOUND_DEVICE:
318 struct ccb_getdev *cgd;
321 cgd = (struct ccb_getdev *)arg;
323 if (SID_TYPE(&cgd->inq_data)!= T_CHANGER)
327 * Allocate a peripheral instance for
328 * this device and start the probe
331 status = cam_periph_alloc(chregister, choninvalidate,
332 chcleanup, chstart, "ch",
333 CAM_PERIPH_BIO, cgd->ccb_h.path,
334 chasync, AC_FOUND_DEVICE, cgd);
336 if (status != CAM_REQ_CMP
337 && status != CAM_REQ_INPROG)
338 kprintf("chasync: Unable to probe new device "
339 "due to status 0x%x\n", status);
345 cam_periph_async(periph, code, path, arg);
351 chregister(struct cam_periph *periph, void *arg)
353 struct ch_softc *softc;
354 struct ccb_setasync csa;
355 struct ccb_getdev *cgd;
357 cgd = (struct ccb_getdev *)arg;
358 if (periph == NULL) {
359 kprintf("chregister: periph was NULL!!\n");
360 return(CAM_REQ_CMP_ERR);
364 kprintf("chregister: no getdev CCB, can't register device\n");
365 return(CAM_REQ_CMP_ERR);
368 softc = kmalloc(sizeof(*softc), M_DEVBUF, M_INTWAIT | M_ZERO);
369 softc->state = CH_STATE_PROBE;
370 periph->softc = softc;
371 cam_extend_set(chperiphs, periph->unit_number, periph);
372 softc->quirks = CH_Q_NONE;
375 * Changers don't have a blocksize, and obviously don't support
378 devstat_add_entry(&softc->device_stats, "ch",
379 periph->unit_number, 0,
380 DEVSTAT_NO_BLOCKSIZE | DEVSTAT_NO_ORDERED_TAGS,
381 SID_TYPE(&cgd->inq_data)| DEVSTAT_TYPE_IF_SCSI,
382 DEVSTAT_PRIORITY_OTHER);
384 /* Register the device */
385 dev_ops_add(&ch_ops, -1, periph->unit_number);
386 make_dev(&ch_ops, periph->unit_number, UID_ROOT,
387 GID_OPERATOR, 0600, "%s%d", periph->periph_name,
388 periph->unit_number);
391 * Add an async callback so that we get
392 * notified if this device goes away.
394 xpt_setup_ccb(&csa.ccb_h, periph->path, /* priority */ 5);
395 csa.ccb_h.func_code = XPT_SASYNC_CB;
396 csa.event_enable = AC_LOST_DEVICE;
397 csa.callback = chasync;
398 csa.callback_arg = periph;
399 xpt_action((union ccb *)&csa);
402 * Lock this peripheral until we are setup.
403 * This first call can't block
405 cam_periph_lock(periph, 0);
406 xpt_schedule(periph, /*priority*/5);
412 chopen(struct dev_open_args *ap)
414 cdev_t dev = ap->a_head.a_dev;
415 struct cam_periph *periph;
416 struct ch_softc *softc;
420 periph = cam_extend_get(chperiphs, unit);
425 softc = (struct ch_softc *)periph->softc;
428 if (softc->flags & CH_FLAG_INVALID) {
433 if ((error = cam_periph_lock(periph, PCATCH)) != 0) {
440 if ((softc->flags & CH_FLAG_OPEN) == 0) {
441 if (cam_periph_acquire(periph) != CAM_REQ_CMP)
443 softc->flags |= CH_FLAG_OPEN;
447 * Load information about this changer device into the softc.
449 if ((error = chgetparams(periph)) != 0) {
450 softc->flags &= ~CH_FLAG_OPEN;
451 cam_periph_unlock(periph);
452 cam_periph_release(periph);
456 cam_periph_unlock(periph);
462 chclose(struct dev_close_args *ap)
464 cdev_t dev = ap->a_head.a_dev;
465 struct cam_periph *periph;
466 struct ch_softc *softc;
472 periph = cam_extend_get(chperiphs, unit);
476 softc = (struct ch_softc *)periph->softc;
478 if ((error = cam_periph_lock(periph, 0)) != 0)
481 softc->flags &= ~CH_FLAG_OPEN;
483 cam_periph_unlock(periph);
484 cam_periph_release(periph);
490 chstart(struct cam_periph *periph, union ccb *start_ccb)
492 struct ch_softc *softc;
494 softc = (struct ch_softc *)periph->softc;
496 switch (softc->state) {
497 case CH_STATE_NORMAL:
500 if (periph->immediate_priority <= periph->pinfo.priority){
501 start_ccb->ccb_h.ccb_state = CH_CCB_WAITING;
503 SLIST_INSERT_HEAD(&periph->ccb_list, &start_ccb->ccb_h,
505 periph->immediate_priority = CAM_PRIORITY_NONE;
506 wakeup(&periph->ccb_list);
517 * Include the block descriptor when calculating the mode
520 mode_buffer_len = sizeof(struct scsi_mode_header_6) +
521 sizeof(struct scsi_mode_blk_desc) +
522 sizeof(struct page_element_address_assignment);
524 mode_buffer = kmalloc(mode_buffer_len, M_TEMP, M_INTWAIT | M_ZERO);
526 * Get the element address assignment page.
528 scsi_mode_sense(&start_ccb->csio,
531 /* tag_action */ MSG_SIMPLE_Q_TAG,
532 /* dbd */ (softc->quirks & CH_Q_NO_DBD) ?
534 /* page_code */ SMS_PAGE_CTRL_CURRENT,
535 /* page */ CH_ELEMENT_ADDR_ASSIGN_PAGE,
536 /* param_buf */ (u_int8_t *)mode_buffer,
537 /* param_len */ mode_buffer_len,
538 /* sense_len */ SSD_FULL_SIZE,
539 /* timeout */ CH_TIMEOUT_MODE_SENSE);
541 start_ccb->ccb_h.ccb_bio = NULL;
542 start_ccb->ccb_h.ccb_state = CH_CCB_PROBE;
543 xpt_action(start_ccb);
550 chdone(struct cam_periph *periph, union ccb *done_ccb)
552 struct ch_softc *softc;
553 struct ccb_scsiio *csio;
555 softc = (struct ch_softc *)periph->softc;
556 csio = &done_ccb->csio;
558 switch(done_ccb->ccb_h.ccb_state) {
561 struct scsi_mode_header_6 *mode_header;
562 struct page_element_address_assignment *ea;
563 char announce_buf[80];
566 mode_header = (struct scsi_mode_header_6 *)csio->data_ptr;
568 ea = (struct page_element_address_assignment *)
569 find_mode_page_6(mode_header);
571 if ((done_ccb->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP){
573 softc->sc_firsts[CHET_MT] = scsi_2btoul(ea->mtea);
574 softc->sc_counts[CHET_MT] = scsi_2btoul(ea->nmte);
575 softc->sc_firsts[CHET_ST] = scsi_2btoul(ea->fsea);
576 softc->sc_counts[CHET_ST] = scsi_2btoul(ea->nse);
577 softc->sc_firsts[CHET_IE] = scsi_2btoul(ea->fieea);
578 softc->sc_counts[CHET_IE] = scsi_2btoul(ea->niee);
579 softc->sc_firsts[CHET_DT] = scsi_2btoul(ea->fdtea);
580 softc->sc_counts[CHET_DT] = scsi_2btoul(ea->ndte);
581 softc->sc_picker = softc->sc_firsts[CHET_MT];
583 #define PLURAL(c) (c) == 1 ? "" : "s"
584 ksnprintf(announce_buf, sizeof(announce_buf),
585 "%d slot%s, %d drive%s, "
586 "%d picker%s, %d portal%s",
587 softc->sc_counts[CHET_ST],
588 PLURAL(softc->sc_counts[CHET_ST]),
589 softc->sc_counts[CHET_DT],
590 PLURAL(softc->sc_counts[CHET_DT]),
591 softc->sc_counts[CHET_MT],
592 PLURAL(softc->sc_counts[CHET_MT]),
593 softc->sc_counts[CHET_IE],
594 PLURAL(softc->sc_counts[CHET_IE]));
599 error = cherror(done_ccb, CAM_RETRY_SELTO,
600 SF_RETRY_UA | SF_NO_PRINT);
602 * Retry any UNIT ATTENTION type errors. They
603 * are expected at boot.
605 if (error == ERESTART) {
607 * A retry was scheuled, so
611 } else if (error != 0) {
613 struct scsi_mode_sense_6 *sms;
615 sms = (struct scsi_mode_sense_6 *)
616 done_ccb->csio.cdb_io.cdb_bytes;
619 * Check to see if block descriptors were
620 * disabled. Some devices don't like that.
621 * We're taking advantage of the fact that
622 * the first few bytes of the 6 and 10 byte
623 * mode sense commands are the same. If
624 * block descriptors were disabled, enable
625 * them and re-send the command.
627 if (sms->byte2 & SMS_DBD) {
628 sms->byte2 &= ~SMS_DBD;
629 xpt_action(done_ccb);
630 softc->quirks |= CH_Q_NO_DBD;
635 /* Don't wedge this device's queue */
636 cam_release_devq(done_ccb->ccb_h.path,
645 if ((done_ccb->ccb_h.status & CAM_STATUS_MASK)
646 == CAM_SCSI_STATUS_ERROR)
647 scsi_sense_print(&done_ccb->csio);
649 xpt_print_path(periph->path);
650 kprintf("got CAM status %#x\n",
651 done_ccb->ccb_h.status);
653 xpt_print_path(periph->path);
654 kprintf("fatal error, failed to attach to"
657 cam_periph_invalidate(periph);
659 announce_buf[0] = '\0';
662 if (announce_buf[0] != '\0')
663 xpt_announce_periph(periph, announce_buf);
664 softc->state = CH_STATE_NORMAL;
665 kfree(mode_header, M_TEMP);
667 * Since our peripheral may be invalidated by an error
668 * above or an external event, we must release our CCB
669 * before releasing the probe lock on the peripheral.
670 * The peripheral will only go away once the last lock
671 * is removed, and we need it around for the CCB release
674 xpt_release_ccb(done_ccb);
675 cam_periph_unlock(periph);
680 /* Caller will release the CCB */
681 wakeup(&done_ccb->ccb_h.cbfcnp);
687 xpt_release_ccb(done_ccb);
691 cherror(union ccb *ccb, u_int32_t cam_flags, u_int32_t sense_flags)
693 struct ch_softc *softc;
694 struct cam_periph *periph;
696 periph = xpt_path_periph(ccb->ccb_h.path);
697 softc = (struct ch_softc *)periph->softc;
699 return (cam_periph_error(ccb, cam_flags, sense_flags,
704 chioctl(struct dev_ioctl_args *ap)
706 cdev_t dev = ap->a_head.a_dev;
707 caddr_t addr = ap->a_data;
708 int flag = ap->a_fflag;
709 struct cam_periph *periph;
710 struct ch_softc *softc;
716 periph = cam_extend_get(chperiphs, unit);
720 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("entering chioctl\n"));
722 softc = (struct ch_softc *)periph->softc;
726 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE,
727 ("trying to do ioctl %#lx\n", ap->a_cmd));
730 * If this command can change the device's state, we must
731 * have the device open for writing.
740 if ((flag & FWRITE) == 0)
746 error = chmove(periph, (struct changer_move *)addr);
750 error = chexchange(periph, (struct changer_exchange *)addr);
754 error = chposition(periph, (struct changer_position *)addr);
758 *(int *)addr = softc->sc_picker - softc->sc_firsts[CHET_MT];
763 int new_picker = *(int *)addr;
765 if (new_picker > (softc->sc_counts[CHET_MT] - 1))
767 softc->sc_picker = softc->sc_firsts[CHET_MT] + new_picker;
772 struct changer_params *cp = (struct changer_params *)addr;
774 cp->cp_npickers = softc->sc_counts[CHET_MT];
775 cp->cp_nslots = softc->sc_counts[CHET_ST];
776 cp->cp_nportals = softc->sc_counts[CHET_IE];
777 cp->cp_ndrives = softc->sc_counts[CHET_DT];
781 error = chielem(periph, *(unsigned int *)addr);
786 error = chgetelemstatus(periph,
787 (struct changer_element_status_request *) addr);
793 error = chsetvoltag(periph,
794 (struct changer_set_voltag_request *) addr);
798 /* Implement prevent/allow? */
801 error = cam_periph_ioctl(periph, ap->a_cmd, addr, cherror);
809 chmove(struct cam_periph *periph, struct changer_move *cm)
811 struct ch_softc *softc;
812 u_int16_t fromelem, toelem;
817 softc = (struct ch_softc *)periph->softc;
822 if ((cm->cm_fromtype > CHET_DT) || (cm->cm_totype > CHET_DT))
824 if ((cm->cm_fromunit > (softc->sc_counts[cm->cm_fromtype] - 1)) ||
825 (cm->cm_tounit > (softc->sc_counts[cm->cm_totype] - 1)))
829 * Check the request against the changer's capabilities.
831 if ((softc->sc_movemask[cm->cm_fromtype] & (1 << cm->cm_totype)) == 0)
835 * Calculate the source and destination elements.
837 fromelem = softc->sc_firsts[cm->cm_fromtype] + cm->cm_fromunit;
838 toelem = softc->sc_firsts[cm->cm_totype] + cm->cm_tounit;
840 ccb = cam_periph_getccb(periph, /*priority*/ 1);
842 scsi_move_medium(&ccb->csio,
845 /* tag_action */ MSG_SIMPLE_Q_TAG,
846 /* tea */ softc->sc_picker,
849 /* invert */ (cm->cm_flags & CM_INVERT) ? TRUE : FALSE,
850 /* sense_len */ SSD_FULL_SIZE,
851 /* timeout */ CH_TIMEOUT_MOVE_MEDIUM);
853 error = cam_periph_runccb(ccb, cherror, /*cam_flags*/CAM_RETRY_SELTO,
854 /*sense_flags*/ SF_RETRY_UA,
855 &softc->device_stats);
857 xpt_release_ccb(ccb);
863 chexchange(struct cam_periph *periph, struct changer_exchange *ce)
865 struct ch_softc *softc;
866 u_int16_t src, dst1, dst2;
871 softc = (struct ch_softc *)periph->softc;
875 if ((ce->ce_srctype > CHET_DT) || (ce->ce_fdsttype > CHET_DT) ||
876 (ce->ce_sdsttype > CHET_DT))
878 if ((ce->ce_srcunit > (softc->sc_counts[ce->ce_srctype] - 1)) ||
879 (ce->ce_fdstunit > (softc->sc_counts[ce->ce_fdsttype] - 1)) ||
880 (ce->ce_sdstunit > (softc->sc_counts[ce->ce_sdsttype] - 1)))
884 * Check the request against the changer's capabilities.
886 if (((softc->sc_exchangemask[ce->ce_srctype] &
887 (1 << ce->ce_fdsttype)) == 0) ||
888 ((softc->sc_exchangemask[ce->ce_fdsttype] &
889 (1 << ce->ce_sdsttype)) == 0))
893 * Calculate the source and destination elements.
895 src = softc->sc_firsts[ce->ce_srctype] + ce->ce_srcunit;
896 dst1 = softc->sc_firsts[ce->ce_fdsttype] + ce->ce_fdstunit;
897 dst2 = softc->sc_firsts[ce->ce_sdsttype] + ce->ce_sdstunit;
899 ccb = cam_periph_getccb(periph, /*priority*/ 1);
901 scsi_exchange_medium(&ccb->csio,
904 /* tag_action */ MSG_SIMPLE_Q_TAG,
905 /* tea */ softc->sc_picker,
909 /* invert1 */ (ce->ce_flags & CE_INVERT1) ?
911 /* invert2 */ (ce->ce_flags & CE_INVERT2) ?
913 /* sense_len */ SSD_FULL_SIZE,
914 /* timeout */ CH_TIMEOUT_EXCHANGE_MEDIUM);
916 error = cam_periph_runccb(ccb, cherror, /*cam_flags*/CAM_RETRY_SELTO,
917 /*sense_flags*/ SF_RETRY_UA,
918 &softc->device_stats);
920 xpt_release_ccb(ccb);
926 chposition(struct cam_periph *periph, struct changer_position *cp)
928 struct ch_softc *softc;
934 softc = (struct ch_softc *)periph->softc;
939 if (cp->cp_type > CHET_DT)
941 if (cp->cp_unit > (softc->sc_counts[cp->cp_type] - 1))
945 * Calculate the destination element.
947 dst = softc->sc_firsts[cp->cp_type] + cp->cp_unit;
949 ccb = cam_periph_getccb(periph, /*priority*/ 1);
951 scsi_position_to_element(&ccb->csio,
954 /* tag_action */ MSG_SIMPLE_Q_TAG,
955 /* tea */ softc->sc_picker,
957 /* invert */ (cp->cp_flags & CP_INVERT) ?
959 /* sense_len */ SSD_FULL_SIZE,
960 /* timeout */ CH_TIMEOUT_POSITION_TO_ELEMENT);
962 error = cam_periph_runccb(ccb, cherror, /*cam_flags*/ CAM_RETRY_SELTO,
963 /*sense_flags*/ SF_RETRY_UA,
964 &softc->device_stats);
966 xpt_release_ccb(ccb);
972 * Copy a volume tag to a volume_tag struct, converting SCSI byte order
973 * to host native byte order in the volume serial number. The volume
974 * label as returned by the changer is transferred to user mode as
975 * nul-terminated string. Volume labels are truncated at the first
976 * space, as suggested by SCSI-2.
979 copy_voltag(struct changer_voltag *uvoltag, struct volume_tag *voltag)
982 for (i=0; i<CH_VOLTAG_MAXLEN; i++) {
983 char c = voltag->vif[i];
985 uvoltag->cv_volid[i] = c;
989 uvoltag->cv_serial = scsi_2btoul(voltag->vsn);
993 * Copy an an element status descriptor to a user-mode
994 * changer_element_status structure.
998 copy_element_status(struct ch_softc *softc,
1000 struct read_element_status_descriptor *desc,
1001 struct changer_element_status *ces)
1003 u_int16_t eaddr = scsi_2btoul(desc->eaddr);
1006 ces->ces_int_addr = eaddr;
1007 /* set up logical address in element status */
1008 for (et = CHET_MT; et <= CHET_DT; et++) {
1009 if ((softc->sc_firsts[et] <= eaddr)
1010 && ((softc->sc_firsts[et] + softc->sc_counts[et])
1012 ces->ces_addr = eaddr - softc->sc_firsts[et];
1018 ces->ces_flags = desc->flags1;
1020 ces->ces_sensecode = desc->sense_code;
1021 ces->ces_sensequal = desc->sense_qual;
1023 if (desc->flags2 & READ_ELEMENT_STATUS_INVERT)
1024 ces->ces_flags |= CES_INVERT;
1026 if (desc->flags2 & READ_ELEMENT_STATUS_SVALID) {
1028 eaddr = scsi_2btoul(desc->ssea);
1030 /* convert source address to logical format */
1031 for (et = CHET_MT; et <= CHET_DT; et++) {
1032 if ((softc->sc_firsts[et] <= eaddr)
1033 && ((softc->sc_firsts[et] + softc->sc_counts[et])
1035 ces->ces_source_addr =
1036 eaddr - softc->sc_firsts[et];
1037 ces->ces_source_type = et;
1038 ces->ces_flags |= CES_SOURCE_VALID;
1043 if (!(ces->ces_flags & CES_SOURCE_VALID))
1044 kprintf("ch: warning: could not map element source "
1045 "address %ud to a valid element type\n",
1050 if (flags & READ_ELEMENT_STATUS_PVOLTAG)
1051 copy_voltag(&(ces->ces_pvoltag), &(desc->pvoltag));
1052 if (flags & READ_ELEMENT_STATUS_AVOLTAG)
1053 copy_voltag(&(ces->ces_avoltag), &(desc->avoltag));
1055 if (desc->dt_scsi_flags & READ_ELEMENT_STATUS_DT_IDVALID) {
1056 ces->ces_flags |= CES_SCSIID_VALID;
1057 ces->ces_scsi_id = desc->dt_scsi_addr;
1060 if (desc->dt_scsi_addr & READ_ELEMENT_STATUS_DT_LUVALID) {
1061 ces->ces_flags |= CES_LUN_VALID;
1063 desc->dt_scsi_flags & READ_ELEMENT_STATUS_DT_LUNMASK;
1068 chgetelemstatus(struct cam_periph *periph,
1069 struct changer_element_status_request *cesr)
1071 struct read_element_status_header *st_hdr;
1072 struct read_element_status_page_header *pg_hdr;
1073 struct read_element_status_descriptor *desc;
1074 caddr_t data = NULL;
1075 size_t size, desclen;
1076 int avail, i, error = 0;
1077 struct changer_element_status *user_data = NULL;
1078 struct ch_softc *softc;
1080 int chet = cesr->cesr_element_type;
1081 int want_voltags = (cesr->cesr_flags & CESR_VOLTAGS) ? 1 : 0;
1083 softc = (struct ch_softc *)periph->softc;
1085 /* perform argument checking */
1088 * Perform a range check on the cesr_element_{base,count}
1089 * request argument fields.
1091 if ((softc->sc_counts[chet] - cesr->cesr_element_base) <= 0
1092 || (cesr->cesr_element_base + cesr->cesr_element_count)
1093 > softc->sc_counts[chet])
1097 * Request one descriptor for the given element type. This
1098 * is used to determine the size of the descriptor so that
1099 * we can allocate enough storage for all of them. We assume
1100 * that the first one can fit into 1k.
1102 data = (caddr_t)kmalloc(1024, M_DEVBUF, M_INTWAIT);
1104 ccb = cam_periph_getccb(periph, /*priority*/ 1);
1106 scsi_read_element_status(&ccb->csio,
1108 /* cbfcnp */ chdone,
1109 /* tag_action */ MSG_SIMPLE_Q_TAG,
1110 /* voltag */ want_voltags,
1111 /* sea */ softc->sc_firsts[chet],
1113 /* data_ptr */ data,
1114 /* dxfer_len */ 1024,
1115 /* sense_len */ SSD_FULL_SIZE,
1116 /* timeout */ CH_TIMEOUT_READ_ELEMENT_STATUS);
1118 error = cam_periph_runccb(ccb, cherror, /*cam_flags*/ CAM_RETRY_SELTO,
1119 /*sense_flags*/ SF_RETRY_UA,
1120 &softc->device_stats);
1125 st_hdr = (struct read_element_status_header *)data;
1126 pg_hdr = (struct read_element_status_page_header *)((uintptr_t)st_hdr +
1127 sizeof(struct read_element_status_header));
1128 desclen = scsi_2btoul(pg_hdr->edl);
1130 size = sizeof(struct read_element_status_header) +
1131 sizeof(struct read_element_status_page_header) +
1132 (desclen * cesr->cesr_element_count);
1135 * Reallocate storage for descriptors and get them from the
1138 kfree(data, M_DEVBUF);
1139 data = (caddr_t)kmalloc(size, M_DEVBUF, M_INTWAIT);
1141 scsi_read_element_status(&ccb->csio,
1143 /* cbfcnp */ chdone,
1144 /* tag_action */ MSG_SIMPLE_Q_TAG,
1145 /* voltag */ want_voltags,
1146 /* sea */ softc->sc_firsts[chet]
1147 + cesr->cesr_element_base,
1148 /* count */ cesr->cesr_element_count,
1149 /* data_ptr */ data,
1150 /* dxfer_len */ size,
1151 /* sense_len */ SSD_FULL_SIZE,
1152 /* timeout */ CH_TIMEOUT_READ_ELEMENT_STATUS);
1154 error = cam_periph_runccb(ccb, cherror, /*cam_flags*/ CAM_RETRY_SELTO,
1155 /*sense_flags*/ SF_RETRY_UA,
1156 &softc->device_stats);
1162 * Fill in the user status array.
1164 st_hdr = (struct read_element_status_header *)data;
1165 avail = scsi_2btoul(st_hdr->count);
1167 if (avail != cesr->cesr_element_count) {
1168 xpt_print_path(periph->path);
1169 kprintf("warning, READ ELEMENT STATUS avail != count\n");
1172 user_data = (struct changer_element_status *)
1173 kmalloc(avail * sizeof(struct changer_element_status),
1174 M_DEVBUF, M_INTWAIT | M_ZERO);
1176 desc = (struct read_element_status_descriptor *)((uintptr_t)data +
1177 sizeof(struct read_element_status_header) +
1178 sizeof(struct read_element_status_page_header));
1180 * Set up the individual element status structures
1182 for (i = 0; i < avail; ++i) {
1183 struct changer_element_status *ces = &(user_data[i]);
1185 copy_element_status(softc, pg_hdr->flags, desc, ces);
1187 desc = (struct read_element_status_descriptor *)
1188 ((uintptr_t)desc + desclen);
1191 /* Copy element status structures out to userspace. */
1192 error = copyout(user_data,
1193 cesr->cesr_element_status,
1194 avail * sizeof(struct changer_element_status));
1197 xpt_release_ccb(ccb);
1200 kfree(data, M_DEVBUF);
1201 if (user_data != NULL)
1202 kfree(user_data, M_DEVBUF);
1208 chielem(struct cam_periph *periph,
1209 unsigned int timeout)
1212 struct ch_softc *softc;
1216 timeout = CH_TIMEOUT_INITIALIZE_ELEMENT_STATUS;
1222 softc = (struct ch_softc *)periph->softc;
1224 ccb = cam_periph_getccb(periph, /*priority*/ 1);
1226 scsi_initialize_element_status(&ccb->csio,
1228 /* cbfcnp */ chdone,
1229 /* tag_action */ MSG_SIMPLE_Q_TAG,
1230 /* sense_len */ SSD_FULL_SIZE,
1231 /* timeout */ timeout);
1233 error = cam_periph_runccb(ccb, cherror, /*cam_flags*/ CAM_RETRY_SELTO,
1234 /*sense_flags*/ SF_RETRY_UA,
1235 &softc->device_stats);
1237 xpt_release_ccb(ccb);
1243 chsetvoltag(struct cam_periph *periph,
1244 struct changer_set_voltag_request *csvr)
1247 struct ch_softc *softc;
1250 struct scsi_send_volume_tag_parameters ssvtp;
1255 softc = (struct ch_softc *)periph->softc;
1257 bzero(&ssvtp, sizeof(ssvtp));
1258 for (i=0; i<sizeof(ssvtp.vitf); i++) {
1259 ssvtp.vitf[i] = ' ';
1265 if (csvr->csvr_type > CHET_DT)
1267 if (csvr->csvr_addr > (softc->sc_counts[csvr->csvr_type] - 1))
1270 ea = softc->sc_firsts[csvr->csvr_type] + csvr->csvr_addr;
1272 if (csvr->csvr_flags & CSVR_ALTERNATE) {
1273 switch (csvr->csvr_flags & CSVR_MODE_MASK) {
1275 sac = SEND_VOLUME_TAG_ASSERT_ALTERNATE;
1277 case CSVR_MODE_REPLACE:
1278 sac = SEND_VOLUME_TAG_REPLACE_ALTERNATE;
1280 case CSVR_MODE_CLEAR:
1281 sac = SEND_VOLUME_TAG_UNDEFINED_ALTERNATE;
1288 switch (csvr->csvr_flags & CSVR_MODE_MASK) {
1290 sac = SEND_VOLUME_TAG_ASSERT_PRIMARY;
1292 case CSVR_MODE_REPLACE:
1293 sac = SEND_VOLUME_TAG_REPLACE_PRIMARY;
1295 case CSVR_MODE_CLEAR:
1296 sac = SEND_VOLUME_TAG_UNDEFINED_PRIMARY;
1304 memcpy(ssvtp.vitf, csvr->csvr_voltag.cv_volid,
1305 min(strlen(csvr->csvr_voltag.cv_volid), sizeof(ssvtp.vitf)));
1306 scsi_ulto2b(csvr->csvr_voltag.cv_serial, ssvtp.minvsn);
1308 ccb = cam_periph_getccb(periph, /*priority*/ 1);
1310 scsi_send_volume_tag(&ccb->csio,
1312 /* cbfcnp */ chdone,
1313 /* tag_action */ MSG_SIMPLE_Q_TAG,
1314 /* element_address */ ea,
1315 /* send_action_code */ sac,
1316 /* parameters */ &ssvtp,
1317 /* sense_len */ SSD_FULL_SIZE,
1318 /* timeout */ CH_TIMEOUT_SEND_VOLTAG);
1320 error = cam_periph_runccb(ccb, cherror, /*cam_flags*/ CAM_RETRY_SELTO,
1321 /*sense_flags*/ SF_RETRY_UA,
1322 &softc->device_stats);
1324 xpt_release_ccb(ccb);
1331 chgetparams(struct cam_periph *periph)
1334 struct ch_softc *softc;
1336 int mode_buffer_len;
1337 struct page_element_address_assignment *ea;
1338 struct page_device_capabilities *cap;
1339 int error, from, dbd;
1340 u_int8_t *moves, *exchanges;
1344 softc = (struct ch_softc *)periph->softc;
1346 ccb = cam_periph_getccb(periph, /*priority*/ 1);
1349 * The scsi_mode_sense_data structure is just a convenience
1350 * structure that allows us to easily calculate the worst-case
1351 * storage size of the mode sense buffer.
1353 mode_buffer_len = sizeof(struct scsi_mode_sense_data);
1355 mode_buffer = kmalloc(mode_buffer_len, M_TEMP, M_INTWAIT | M_ZERO);
1357 if (softc->quirks & CH_Q_NO_DBD)
1363 * Get the element address assignment page.
1365 scsi_mode_sense(&ccb->csio,
1367 /* cbfcnp */ chdone,
1368 /* tag_action */ MSG_SIMPLE_Q_TAG,
1370 /* page_code */ SMS_PAGE_CTRL_CURRENT,
1371 /* page */ CH_ELEMENT_ADDR_ASSIGN_PAGE,
1372 /* param_buf */ (u_int8_t *)mode_buffer,
1373 /* param_len */ mode_buffer_len,
1374 /* sense_len */ SSD_FULL_SIZE,
1375 /* timeout */ CH_TIMEOUT_MODE_SENSE);
1377 error = cam_periph_runccb(ccb, cherror, /*cam_flags*/ CAM_RETRY_SELTO,
1378 /* sense_flags */ SF_RETRY_UA|SF_NO_PRINT,
1379 &softc->device_stats);
1383 struct scsi_mode_sense_6 *sms;
1385 sms = (struct scsi_mode_sense_6 *)
1386 ccb->csio.cdb_io.cdb_bytes;
1388 sms->byte2 &= ~SMS_DBD;
1389 error = cam_periph_runccb(ccb, cherror,
1390 /*cam_flags*/ CAM_RETRY_SELTO,
1391 /*sense_flags*/ SF_RETRY_UA,
1392 &softc->device_stats);
1395 * Since we disabled sense printing above, print
1396 * out the sense here since we got an error.
1398 scsi_sense_print(&ccb->csio);
1402 xpt_print_path(periph->path);
1403 kprintf("chgetparams: error getting element "
1405 xpt_release_ccb(ccb);
1406 kfree(mode_buffer, M_TEMP);
1411 ea = (struct page_element_address_assignment *)
1412 find_mode_page_6((struct scsi_mode_header_6 *)mode_buffer);
1414 softc->sc_firsts[CHET_MT] = scsi_2btoul(ea->mtea);
1415 softc->sc_counts[CHET_MT] = scsi_2btoul(ea->nmte);
1416 softc->sc_firsts[CHET_ST] = scsi_2btoul(ea->fsea);
1417 softc->sc_counts[CHET_ST] = scsi_2btoul(ea->nse);
1418 softc->sc_firsts[CHET_IE] = scsi_2btoul(ea->fieea);
1419 softc->sc_counts[CHET_IE] = scsi_2btoul(ea->niee);
1420 softc->sc_firsts[CHET_DT] = scsi_2btoul(ea->fdtea);
1421 softc->sc_counts[CHET_DT] = scsi_2btoul(ea->ndte);
1423 bzero(mode_buffer, mode_buffer_len);
1426 * Now get the device capabilities page.
1428 scsi_mode_sense(&ccb->csio,
1430 /* cbfcnp */ chdone,
1431 /* tag_action */ MSG_SIMPLE_Q_TAG,
1433 /* page_code */ SMS_PAGE_CTRL_CURRENT,
1434 /* page */ CH_DEVICE_CAP_PAGE,
1435 /* param_buf */ (u_int8_t *)mode_buffer,
1436 /* param_len */ mode_buffer_len,
1437 /* sense_len */ SSD_FULL_SIZE,
1438 /* timeout */ CH_TIMEOUT_MODE_SENSE);
1440 error = cam_periph_runccb(ccb, cherror, /*cam_flags*/ CAM_RETRY_SELTO,
1441 /* sense_flags */ SF_RETRY_UA | SF_NO_PRINT,
1442 &softc->device_stats);
1446 struct scsi_mode_sense_6 *sms;
1448 sms = (struct scsi_mode_sense_6 *)
1449 ccb->csio.cdb_io.cdb_bytes;
1451 sms->byte2 &= ~SMS_DBD;
1452 error = cam_periph_runccb(ccb, cherror,
1453 /*cam_flags*/ CAM_RETRY_SELTO,
1454 /*sense_flags*/ SF_RETRY_UA,
1455 &softc->device_stats);
1458 * Since we disabled sense printing above, print
1459 * out the sense here since we got an error.
1461 scsi_sense_print(&ccb->csio);
1465 xpt_print_path(periph->path);
1466 kprintf("chgetparams: error getting device "
1467 "capabilities page\n");
1468 xpt_release_ccb(ccb);
1469 kfree(mode_buffer, M_TEMP);
1474 xpt_release_ccb(ccb);
1476 cap = (struct page_device_capabilities *)
1477 find_mode_page_6((struct scsi_mode_header_6 *)mode_buffer);
1479 bzero(softc->sc_movemask, sizeof(softc->sc_movemask));
1480 bzero(softc->sc_exchangemask, sizeof(softc->sc_exchangemask));
1481 moves = &cap->move_from_mt;
1482 exchanges = &cap->exchange_with_mt;
1483 for (from = CHET_MT; from <= CHET_DT; ++from) {
1484 softc->sc_movemask[from] = moves[from];
1485 softc->sc_exchangemask[from] = exchanges[from];
1488 kfree(mode_buffer, M_TEMP);
1494 scsi_move_medium(struct ccb_scsiio *csio, u_int32_t retries,
1495 void (*cbfcnp)(struct cam_periph *, union ccb *),
1496 u_int8_t tag_action, u_int32_t tea, u_int32_t src,
1497 u_int32_t dst, int invert, u_int8_t sense_len,
1500 struct scsi_move_medium *scsi_cmd;
1502 scsi_cmd = (struct scsi_move_medium *)&csio->cdb_io.cdb_bytes;
1503 bzero(scsi_cmd, sizeof(*scsi_cmd));
1505 scsi_cmd->opcode = MOVE_MEDIUM;
1507 scsi_ulto2b(tea, scsi_cmd->tea);
1508 scsi_ulto2b(src, scsi_cmd->src);
1509 scsi_ulto2b(dst, scsi_cmd->dst);
1512 scsi_cmd->invert |= MOVE_MEDIUM_INVERT;
1517 /*flags*/ CAM_DIR_NONE,
1527 scsi_exchange_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 dst1, u_int32_t dst2, int invert1,
1531 int invert2, u_int8_t sense_len, u_int32_t timeout)
1533 struct scsi_exchange_medium *scsi_cmd;
1535 scsi_cmd = (struct scsi_exchange_medium *)&csio->cdb_io.cdb_bytes;
1536 bzero(scsi_cmd, sizeof(*scsi_cmd));
1538 scsi_cmd->opcode = EXCHANGE_MEDIUM;
1540 scsi_ulto2b(tea, scsi_cmd->tea);
1541 scsi_ulto2b(src, scsi_cmd->src);
1542 scsi_ulto2b(dst1, scsi_cmd->fdst);
1543 scsi_ulto2b(dst2, scsi_cmd->sdst);
1546 scsi_cmd->invert |= EXCHANGE_MEDIUM_INV1;
1549 scsi_cmd->invert |= EXCHANGE_MEDIUM_INV2;
1554 /*flags*/ CAM_DIR_NONE,
1564 scsi_position_to_element(struct ccb_scsiio *csio, u_int32_t retries,
1565 void (*cbfcnp)(struct cam_periph *, union ccb *),
1566 u_int8_t tag_action, u_int32_t tea, u_int32_t dst,
1567 int invert, u_int8_t sense_len, u_int32_t timeout)
1569 struct scsi_position_to_element *scsi_cmd;
1571 scsi_cmd = (struct scsi_position_to_element *)&csio->cdb_io.cdb_bytes;
1572 bzero(scsi_cmd, sizeof(*scsi_cmd));
1574 scsi_cmd->opcode = POSITION_TO_ELEMENT;
1576 scsi_ulto2b(tea, scsi_cmd->tea);
1577 scsi_ulto2b(dst, scsi_cmd->dst);
1580 scsi_cmd->invert |= POSITION_TO_ELEMENT_INVERT;
1585 /*flags*/ CAM_DIR_NONE,
1595 scsi_read_element_status(struct ccb_scsiio *csio, u_int32_t retries,
1596 void (*cbfcnp)(struct cam_periph *, union ccb *),
1597 u_int8_t tag_action, int voltag, u_int32_t sea,
1598 u_int32_t count, u_int8_t *data_ptr,
1599 u_int32_t dxfer_len, u_int8_t sense_len,
1602 struct scsi_read_element_status *scsi_cmd;
1604 scsi_cmd = (struct scsi_read_element_status *)&csio->cdb_io.cdb_bytes;
1605 bzero(scsi_cmd, sizeof(*scsi_cmd));
1607 scsi_cmd->opcode = READ_ELEMENT_STATUS;
1609 scsi_ulto2b(sea, scsi_cmd->sea);
1610 scsi_ulto2b(count, scsi_cmd->count);
1611 scsi_ulto3b(dxfer_len, scsi_cmd->len);
1614 scsi_cmd->byte2 |= READ_ELEMENT_STATUS_VOLTAG;
1619 /*flags*/ CAM_DIR_IN,
1629 scsi_initialize_element_status(struct ccb_scsiio *csio, u_int32_t retries,
1630 void (*cbfcnp)(struct cam_periph *, union ccb *),
1631 u_int8_t tag_action, u_int8_t sense_len,
1634 struct scsi_initialize_element_status *scsi_cmd;
1636 scsi_cmd = (struct scsi_initialize_element_status *)
1637 &csio->cdb_io.cdb_bytes;
1638 bzero(scsi_cmd, sizeof(*scsi_cmd));
1640 scsi_cmd->opcode = INITIALIZE_ELEMENT_STATUS;
1645 /*flags*/ CAM_DIR_NONE,
1647 /* data_ptr */ NULL,
1655 scsi_send_volume_tag(struct ccb_scsiio *csio, u_int32_t retries,
1656 void (*cbfcnp)(struct cam_periph *, union ccb *),
1657 u_int8_t tag_action,
1658 u_int16_t element_address,
1659 u_int8_t send_action_code,
1660 struct scsi_send_volume_tag_parameters *parameters,
1661 u_int8_t sense_len, u_int32_t timeout)
1663 struct scsi_send_volume_tag *scsi_cmd;
1665 scsi_cmd = (struct scsi_send_volume_tag *) &csio->cdb_io.cdb_bytes;
1666 bzero(scsi_cmd, sizeof(*scsi_cmd));
1668 scsi_cmd->opcode = SEND_VOLUME_TAG;
1669 scsi_ulto2b(element_address, scsi_cmd->ea);
1670 scsi_cmd->sac = send_action_code;
1671 scsi_ulto2b(sizeof(*parameters), scsi_cmd->pll);
1676 /*flags*/ CAM_DIR_OUT,
1678 /* data_ptr */ (u_int8_t *) parameters,
1679 sizeof(*parameters),