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
29 * Derived from the NetBSD SCSI changer driver.
31 * $NetBSD: ch.c,v 1.32 1998/01/12 09:49:12 thorpej Exp $
35 * Copyright (c) 1996, 1997 Jason R. Thorpe <thorpej@and.com>
36 * All rights reserved.
38 * Partially based on an autochanger driver written by Stefan Grefen
39 * and on an autochanger driver written by the Systems Programming Group
40 * at the University of Utah Computer Science Department.
42 * Redistribution and use in source and binary forms, with or without
43 * modification, are permitted provided that the following conditions
45 * 1. Redistributions of source code must retain the above copyright
46 * notice, this list of conditions and the following disclaimer.
47 * 2. Redistributions in binary form must reproduce the above copyright
48 * notice, this list of conditions and the following disclaimer in the
49 * documentation and/or other materials provided with the distribution.
50 * 3. All advertising materials mentioning features or use of this software
51 * must display the following acknowledgements:
52 * This product includes software developed by Jason R. Thorpe
53 * for And Communications, http://www.and.com/
54 * 4. The name of the author may not be used to endorse or promote products
55 * derived from this software without specific prior written permission.
57 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
58 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
59 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
60 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
61 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
62 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
63 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
64 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
65 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
66 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
70 #include <sys/cdefs.h>
71 __FBSDID("$FreeBSD$");
73 #include <sys/param.h>
74 #include <sys/queue.h>
75 #include <sys/systm.h>
76 #include <sys/kernel.h>
77 #include <sys/types.h>
78 #include <sys/malloc.h>
79 #include <sys/fcntl.h>
82 #include <sys/errno.h>
83 #include <sys/devicestat.h>
86 #include <cam/cam_ccb.h>
87 #include <cam/cam_periph.h>
88 #include <cam/cam_xpt_periph.h>
89 #include <cam/cam_debug.h>
91 #include <cam/scsi/scsi_all.h>
92 #include <cam/scsi/scsi_message.h>
93 #include <cam/scsi/scsi_ch.h>
96 * Timeout definitions for various changer related commands. They may
97 * be too short for some devices (especially the timeout for INITIALIZE
101 static const u_int32_t CH_TIMEOUT_MODE_SENSE = 6000;
102 static const u_int32_t CH_TIMEOUT_MOVE_MEDIUM = 100000;
103 static const u_int32_t CH_TIMEOUT_EXCHANGE_MEDIUM = 100000;
104 static const u_int32_t CH_TIMEOUT_POSITION_TO_ELEMENT = 100000;
105 static const u_int32_t CH_TIMEOUT_READ_ELEMENT_STATUS = 10000;
106 static const u_int32_t CH_TIMEOUT_SEND_VOLTAG = 10000;
107 static const u_int32_t CH_TIMEOUT_INITIALIZE_ELEMENT_STATUS = 500000;
110 CH_FLAG_INVALID = 0x001,
129 #define ccb_state ppriv_field0
130 #define ccb_bp ppriv_ptr1
132 struct scsi_mode_sense_data {
133 struct scsi_mode_header_6 header;
134 struct scsi_mode_blk_desc blk_desc;
136 struct page_element_address_assignment ea;
137 struct page_transport_geometry_parameters tg;
138 struct page_device_capabilities cap;
147 struct devstat *device_stats;
150 int sc_picker; /* current picker */
153 * The following information is obtained from the
154 * element address assignment page.
156 int sc_firsts[CHET_MAX + 1]; /* firsts */
157 int sc_counts[CHET_MAX + 1]; /* counts */
160 * The following mask defines the legal combinations
161 * of elements for the MOVE MEDIUM command.
163 u_int8_t sc_movemask[CHET_MAX + 1];
166 * As above, but for EXCHANGE MEDIUM.
168 u_int8_t sc_exchangemask[CHET_MAX + 1];
171 * Quirks; see below. XXX KDM not implemented yet
173 int sc_settledelay; /* delay for settle */
176 static d_open_t chopen;
177 static d_close_t chclose;
178 static d_ioctl_t chioctl;
179 static periph_init_t chinit;
180 static periph_ctor_t chregister;
181 static periph_oninv_t choninvalidate;
182 static periph_dtor_t chcleanup;
183 static periph_start_t chstart;
184 static void chasync(void *callback_arg, u_int32_t code,
185 struct cam_path *path, void *arg);
186 static void chdone(struct cam_periph *periph,
187 union ccb *done_ccb);
188 static int cherror(union ccb *ccb, u_int32_t cam_flags,
189 u_int32_t sense_flags);
190 static int chmove(struct cam_periph *periph,
191 struct changer_move *cm);
192 static int chexchange(struct cam_periph *periph,
193 struct changer_exchange *ce);
194 static int chposition(struct cam_periph *periph,
195 struct changer_position *cp);
196 static int chgetelemstatus(struct cam_periph *periph,
197 struct changer_element_status_request *csr);
198 static int chsetvoltag(struct cam_periph *periph,
199 struct changer_set_voltag_request *csvr);
200 static int chielem(struct cam_periph *periph,
201 unsigned int timeout);
202 static int chgetparams(struct cam_periph *periph);
204 static struct periph_driver chdriver =
207 TAILQ_HEAD_INITIALIZER(chdriver.units), /* generation */ 0
210 PERIPHDRIVER_DECLARE(ch, chdriver);
212 static struct cdevsw ch_cdevsw = {
213 .d_version = D_VERSION,
225 struct cam_path *path;
228 * Install a global async callback. This callback will
229 * receive async callbacks like "new device found".
231 status = xpt_create_path(&path, /*periph*/NULL, CAM_XPT_PATH_ID,
232 CAM_TARGET_WILDCARD, CAM_LUN_WILDCARD);
234 if (status == CAM_REQ_CMP) {
235 struct ccb_setasync csa;
237 xpt_setup_ccb(&csa.ccb_h, path, /*priority*/5);
238 csa.ccb_h.func_code = XPT_SASYNC_CB;
239 csa.event_enable = AC_FOUND_DEVICE;
240 csa.callback = chasync;
241 csa.callback_arg = NULL;
242 xpt_action((union ccb *)&csa);
243 status = csa.ccb_h.status;
247 if (status != CAM_REQ_CMP) {
248 printf("ch: Failed to attach master async callback "
249 "due to status 0x%x!\n", status);
254 choninvalidate(struct cam_periph *periph)
256 struct ch_softc *softc;
257 struct ccb_setasync csa;
259 softc = (struct ch_softc *)periph->softc;
262 * De-register any async callbacks.
264 xpt_setup_ccb(&csa.ccb_h, periph->path,
266 csa.ccb_h.func_code = XPT_SASYNC_CB;
267 csa.event_enable = 0;
268 csa.callback = chasync;
269 csa.callback_arg = periph;
270 xpt_action((union ccb *)&csa);
272 softc->flags |= CH_FLAG_INVALID;
274 xpt_print(periph->path, "lost device\n");
279 chcleanup(struct cam_periph *periph)
281 struct ch_softc *softc;
283 softc = (struct ch_softc *)periph->softc;
285 devstat_remove_entry(softc->device_stats);
286 destroy_dev(softc->dev);
287 xpt_print(periph->path, "removing device entry\n");
288 free(softc, M_DEVBUF);
292 chasync(void *callback_arg, u_int32_t code, struct cam_path *path, void *arg)
294 struct cam_periph *periph;
296 periph = (struct cam_periph *)callback_arg;
299 case AC_FOUND_DEVICE:
301 struct ccb_getdev *cgd;
304 cgd = (struct ccb_getdev *)arg;
308 if (SID_TYPE(&cgd->inq_data)!= T_CHANGER)
312 * Allocate a peripheral instance for
313 * this device and start the probe
316 status = cam_periph_alloc(chregister, choninvalidate,
317 chcleanup, chstart, "ch",
318 CAM_PERIPH_BIO, cgd->ccb_h.path,
319 chasync, AC_FOUND_DEVICE, cgd);
321 if (status != CAM_REQ_CMP
322 && status != CAM_REQ_INPROG)
323 printf("chasync: Unable to probe new device "
324 "due to status 0x%x\n", status);
330 cam_periph_async(periph, code, path, arg);
336 chregister(struct cam_periph *periph, void *arg)
338 struct ch_softc *softc;
339 struct ccb_setasync csa;
340 struct ccb_getdev *cgd;
342 cgd = (struct ccb_getdev *)arg;
343 if (periph == NULL) {
344 printf("chregister: periph was NULL!!\n");
345 return(CAM_REQ_CMP_ERR);
349 printf("chregister: no getdev CCB, can't register device\n");
350 return(CAM_REQ_CMP_ERR);
353 softc = (struct ch_softc *)malloc(sizeof(*softc),M_DEVBUF,M_NOWAIT);
356 printf("chregister: Unable to probe new device. "
357 "Unable to allocate softc\n");
358 return(CAM_REQ_CMP_ERR);
361 bzero(softc, sizeof(*softc));
362 softc->state = CH_STATE_PROBE;
363 periph->softc = softc;
364 softc->quirks = CH_Q_NONE;
367 * Changers don't have a blocksize, and obviously don't support
370 softc->device_stats = devstat_new_entry("ch",
371 periph->unit_number, 0,
372 DEVSTAT_NO_BLOCKSIZE | DEVSTAT_NO_ORDERED_TAGS,
373 SID_TYPE(&cgd->inq_data)| DEVSTAT_TYPE_IF_SCSI,
374 DEVSTAT_PRIORITY_OTHER);
376 /* Register the device */
377 cam_periph_unlock(periph);
378 softc->dev = make_dev(&ch_cdevsw, periph->unit_number, UID_ROOT,
379 GID_OPERATOR, 0600, "%s%d", periph->periph_name,
380 periph->unit_number);
381 cam_periph_lock(periph);
382 softc->dev->si_drv1 = periph;
385 * Add an async callback so that we get
386 * notified if this device goes away.
388 xpt_setup_ccb(&csa.ccb_h, periph->path, /* priority */ 5);
389 csa.ccb_h.func_code = XPT_SASYNC_CB;
390 csa.event_enable = AC_LOST_DEVICE;
391 csa.callback = chasync;
392 csa.callback_arg = periph;
393 xpt_action((union ccb *)&csa);
396 * Lock this periph until we are setup.
397 * This first call can't block
399 (void)cam_periph_hold(periph, PRIBIO);
400 xpt_schedule(periph, /*priority*/5);
406 chopen(struct cdev *dev, int flags, int fmt, struct thread *td)
408 struct cam_periph *periph;
409 struct ch_softc *softc;
412 periph = (struct cam_periph *)dev->si_drv1;
413 if (cam_periph_acquire(periph) != CAM_REQ_CMP)
416 softc = (struct ch_softc *)periph->softc;
418 cam_periph_lock(periph);
420 if (softc->flags & CH_FLAG_INVALID) {
421 cam_periph_unlock(periph);
422 cam_periph_release(periph);
426 if ((softc->flags & CH_FLAG_OPEN) == 0)
427 softc->flags |= CH_FLAG_OPEN;
429 cam_periph_release(periph);
431 if ((error = cam_periph_hold(periph, PRIBIO | PCATCH)) != 0) {
432 cam_periph_unlock(periph);
433 cam_periph_release(periph);
438 * Load information about this changer device into the softc.
440 if ((error = chgetparams(periph)) != 0) {
441 softc->flags &= ~CH_FLAG_OPEN;
442 cam_periph_unlock(periph);
443 cam_periph_release(periph);
447 cam_periph_unhold(periph);
448 cam_periph_unlock(periph);
454 chclose(struct cdev *dev, int flag, int fmt, struct thread *td)
456 struct cam_periph *periph;
457 struct ch_softc *softc;
462 periph = (struct cam_periph *)dev->si_drv1;
466 softc = (struct ch_softc *)periph->softc;
468 cam_periph_lock(periph);
470 softc->flags &= ~CH_FLAG_OPEN;
472 cam_periph_unlock(periph);
473 cam_periph_release(periph);
479 chstart(struct cam_periph *periph, union ccb *start_ccb)
481 struct ch_softc *softc;
483 softc = (struct ch_softc *)periph->softc;
485 switch (softc->state) {
486 case CH_STATE_NORMAL:
488 if (periph->immediate_priority <= periph->pinfo.priority){
489 start_ccb->ccb_h.ccb_state = CH_CCB_WAITING;
491 SLIST_INSERT_HEAD(&periph->ccb_list, &start_ccb->ccb_h,
493 periph->immediate_priority = CAM_PRIORITY_NONE;
494 wakeup(&periph->ccb_list);
504 * Include the block descriptor when calculating the mode
507 mode_buffer_len = sizeof(struct scsi_mode_header_6) +
508 sizeof(struct scsi_mode_blk_desc) +
509 sizeof(struct page_element_address_assignment);
511 mode_buffer = malloc(mode_buffer_len, M_TEMP, M_NOWAIT);
513 if (mode_buffer == NULL) {
514 printf("chstart: couldn't malloc mode sense data\n");
517 bzero(mode_buffer, mode_buffer_len);
520 * Get the element address assignment page.
522 scsi_mode_sense(&start_ccb->csio,
525 /* tag_action */ MSG_SIMPLE_Q_TAG,
526 /* dbd */ (softc->quirks & CH_Q_NO_DBD) ?
528 /* page_code */ SMS_PAGE_CTRL_CURRENT,
529 /* page */ CH_ELEMENT_ADDR_ASSIGN_PAGE,
530 /* param_buf */ (u_int8_t *)mode_buffer,
531 /* param_len */ mode_buffer_len,
532 /* sense_len */ SSD_FULL_SIZE,
533 /* timeout */ CH_TIMEOUT_MODE_SENSE);
535 start_ccb->ccb_h.ccb_bp = NULL;
536 start_ccb->ccb_h.ccb_state = CH_CCB_PROBE;
537 xpt_action(start_ccb);
544 chdone(struct cam_periph *periph, union ccb *done_ccb)
546 struct ch_softc *softc;
547 struct ccb_scsiio *csio;
549 softc = (struct ch_softc *)periph->softc;
550 csio = &done_ccb->csio;
552 switch(done_ccb->ccb_h.ccb_state) {
555 struct scsi_mode_header_6 *mode_header;
556 struct page_element_address_assignment *ea;
557 char announce_buf[80];
560 mode_header = (struct scsi_mode_header_6 *)csio->data_ptr;
562 ea = (struct page_element_address_assignment *)
563 find_mode_page_6(mode_header);
565 if ((done_ccb->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP){
567 softc->sc_firsts[CHET_MT] = scsi_2btoul(ea->mtea);
568 softc->sc_counts[CHET_MT] = scsi_2btoul(ea->nmte);
569 softc->sc_firsts[CHET_ST] = scsi_2btoul(ea->fsea);
570 softc->sc_counts[CHET_ST] = scsi_2btoul(ea->nse);
571 softc->sc_firsts[CHET_IE] = scsi_2btoul(ea->fieea);
572 softc->sc_counts[CHET_IE] = scsi_2btoul(ea->niee);
573 softc->sc_firsts[CHET_DT] = scsi_2btoul(ea->fdtea);
574 softc->sc_counts[CHET_DT] = scsi_2btoul(ea->ndte);
575 softc->sc_picker = softc->sc_firsts[CHET_MT];
577 #define PLURAL(c) (c) == 1 ? "" : "s"
578 snprintf(announce_buf, sizeof(announce_buf),
579 "%d slot%s, %d drive%s, "
580 "%d picker%s, %d portal%s",
581 softc->sc_counts[CHET_ST],
582 PLURAL(softc->sc_counts[CHET_ST]),
583 softc->sc_counts[CHET_DT],
584 PLURAL(softc->sc_counts[CHET_DT]),
585 softc->sc_counts[CHET_MT],
586 PLURAL(softc->sc_counts[CHET_MT]),
587 softc->sc_counts[CHET_IE],
588 PLURAL(softc->sc_counts[CHET_IE]));
593 error = cherror(done_ccb, CAM_RETRY_SELTO,
594 SF_RETRY_UA | SF_NO_PRINT);
596 * Retry any UNIT ATTENTION type errors. They
597 * are expected at boot.
599 if (error == ERESTART) {
601 * A retry was scheuled, so
605 } else if (error != 0) {
607 struct scsi_mode_sense_6 *sms;
609 sms = (struct scsi_mode_sense_6 *)
610 done_ccb->csio.cdb_io.cdb_bytes;
613 * Check to see if block descriptors were
614 * disabled. Some devices don't like that.
615 * We're taking advantage of the fact that
616 * the first few bytes of the 6 and 10 byte
617 * mode sense commands are the same. If
618 * block descriptors were disabled, enable
619 * them and re-send the command.
621 if (sms->byte2 & SMS_DBD) {
622 sms->byte2 &= ~SMS_DBD;
623 xpt_action(done_ccb);
624 softc->quirks |= CH_Q_NO_DBD;
629 /* Don't wedge this device's queue */
630 cam_release_devq(done_ccb->ccb_h.path,
639 if ((done_ccb->ccb_h.status & CAM_STATUS_MASK)
640 == CAM_SCSI_STATUS_ERROR)
641 scsi_sense_print(&done_ccb->csio);
643 xpt_print(periph->path,
644 "got CAM status %#x\n",
645 done_ccb->ccb_h.status);
647 xpt_print(periph->path, "fatal error, failed "
648 "to attach to device\n");
650 cam_periph_invalidate(periph);
652 announce_buf[0] = '\0';
655 if (announce_buf[0] != '\0')
656 xpt_announce_periph(periph, announce_buf);
657 softc->state = CH_STATE_NORMAL;
658 free(mode_header, M_TEMP);
660 * Since our peripheral may be invalidated by an error
661 * above or an external event, we must release our CCB
662 * before releasing the probe lock on the peripheral.
663 * The peripheral will only go away once the last lock
664 * is removed, and we need it around for the CCB release
667 xpt_release_ccb(done_ccb);
668 cam_periph_unhold(periph);
673 /* Caller will release the CCB */
674 wakeup(&done_ccb->ccb_h.cbfcnp);
680 xpt_release_ccb(done_ccb);
684 cherror(union ccb *ccb, u_int32_t cam_flags, u_int32_t sense_flags)
686 struct ch_softc *softc;
687 struct cam_periph *periph;
689 periph = xpt_path_periph(ccb->ccb_h.path);
690 softc = (struct ch_softc *)periph->softc;
692 return (cam_periph_error(ccb, cam_flags, sense_flags,
697 chioctl(struct cdev *dev, u_long cmd, caddr_t addr, int flag, struct thread *td)
699 struct cam_periph *periph;
700 struct ch_softc *softc;
703 periph = (struct cam_periph *)dev->si_drv1;
707 cam_periph_lock(periph);
708 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("entering chioctl\n"));
710 softc = (struct ch_softc *)periph->softc;
714 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE,
715 ("trying to do ioctl %#lx\n", cmd));
718 * If this command can change the device's state, we must
719 * have the device open for writing.
728 if ((flag & FWRITE) == 0) {
729 cam_periph_unlock(periph);
736 error = chmove(periph, (struct changer_move *)addr);
740 error = chexchange(periph, (struct changer_exchange *)addr);
744 error = chposition(periph, (struct changer_position *)addr);
748 *(int *)addr = softc->sc_picker - softc->sc_firsts[CHET_MT];
753 int new_picker = *(int *)addr;
755 if (new_picker > (softc->sc_counts[CHET_MT] - 1)) {
759 softc->sc_picker = softc->sc_firsts[CHET_MT] + new_picker;
764 struct changer_params *cp = (struct changer_params *)addr;
766 cp->cp_npickers = softc->sc_counts[CHET_MT];
767 cp->cp_nslots = softc->sc_counts[CHET_ST];
768 cp->cp_nportals = softc->sc_counts[CHET_IE];
769 cp->cp_ndrives = softc->sc_counts[CHET_DT];
773 error = chielem(periph, *(unsigned int *)addr);
778 error = chgetelemstatus(periph,
779 (struct changer_element_status_request *) addr);
785 error = chsetvoltag(periph,
786 (struct changer_set_voltag_request *) addr);
790 /* Implement prevent/allow? */
793 error = cam_periph_ioctl(periph, cmd, addr, cherror);
797 cam_periph_unlock(periph);
802 chmove(struct cam_periph *periph, struct changer_move *cm)
804 struct ch_softc *softc;
805 u_int16_t fromelem, toelem;
810 softc = (struct ch_softc *)periph->softc;
815 if ((cm->cm_fromtype > CHET_DT) || (cm->cm_totype > CHET_DT))
817 if ((cm->cm_fromunit > (softc->sc_counts[cm->cm_fromtype] - 1)) ||
818 (cm->cm_tounit > (softc->sc_counts[cm->cm_totype] - 1)))
822 * Check the request against the changer's capabilities.
824 if ((softc->sc_movemask[cm->cm_fromtype] & (1 << cm->cm_totype)) == 0)
828 * Calculate the source and destination elements.
830 fromelem = softc->sc_firsts[cm->cm_fromtype] + cm->cm_fromunit;
831 toelem = softc->sc_firsts[cm->cm_totype] + cm->cm_tounit;
833 ccb = cam_periph_getccb(periph, /*priority*/ 1);
835 scsi_move_medium(&ccb->csio,
838 /* tag_action */ MSG_SIMPLE_Q_TAG,
839 /* tea */ softc->sc_picker,
842 /* invert */ (cm->cm_flags & CM_INVERT) ? TRUE : FALSE,
843 /* sense_len */ SSD_FULL_SIZE,
844 /* timeout */ CH_TIMEOUT_MOVE_MEDIUM);
846 error = cam_periph_runccb(ccb, cherror, /*cam_flags*/CAM_RETRY_SELTO,
847 /*sense_flags*/ SF_RETRY_UA,
848 softc->device_stats);
850 xpt_release_ccb(ccb);
856 chexchange(struct cam_periph *periph, struct changer_exchange *ce)
858 struct ch_softc *softc;
859 u_int16_t src, dst1, dst2;
864 softc = (struct ch_softc *)periph->softc;
868 if ((ce->ce_srctype > CHET_DT) || (ce->ce_fdsttype > CHET_DT) ||
869 (ce->ce_sdsttype > CHET_DT))
871 if ((ce->ce_srcunit > (softc->sc_counts[ce->ce_srctype] - 1)) ||
872 (ce->ce_fdstunit > (softc->sc_counts[ce->ce_fdsttype] - 1)) ||
873 (ce->ce_sdstunit > (softc->sc_counts[ce->ce_sdsttype] - 1)))
877 * Check the request against the changer's capabilities.
879 if (((softc->sc_exchangemask[ce->ce_srctype] &
880 (1 << ce->ce_fdsttype)) == 0) ||
881 ((softc->sc_exchangemask[ce->ce_fdsttype] &
882 (1 << ce->ce_sdsttype)) == 0))
886 * Calculate the source and destination elements.
888 src = softc->sc_firsts[ce->ce_srctype] + ce->ce_srcunit;
889 dst1 = softc->sc_firsts[ce->ce_fdsttype] + ce->ce_fdstunit;
890 dst2 = softc->sc_firsts[ce->ce_sdsttype] + ce->ce_sdstunit;
892 ccb = cam_periph_getccb(periph, /*priority*/ 1);
894 scsi_exchange_medium(&ccb->csio,
897 /* tag_action */ MSG_SIMPLE_Q_TAG,
898 /* tea */ softc->sc_picker,
902 /* invert1 */ (ce->ce_flags & CE_INVERT1) ?
904 /* invert2 */ (ce->ce_flags & CE_INVERT2) ?
906 /* sense_len */ SSD_FULL_SIZE,
907 /* timeout */ CH_TIMEOUT_EXCHANGE_MEDIUM);
909 error = cam_periph_runccb(ccb, cherror, /*cam_flags*/CAM_RETRY_SELTO,
910 /*sense_flags*/ SF_RETRY_UA,
911 softc->device_stats);
913 xpt_release_ccb(ccb);
919 chposition(struct cam_periph *periph, struct changer_position *cp)
921 struct ch_softc *softc;
927 softc = (struct ch_softc *)periph->softc;
932 if (cp->cp_type > CHET_DT)
934 if (cp->cp_unit > (softc->sc_counts[cp->cp_type] - 1))
938 * Calculate the destination element.
940 dst = softc->sc_firsts[cp->cp_type] + cp->cp_unit;
942 ccb = cam_periph_getccb(periph, /*priority*/ 1);
944 scsi_position_to_element(&ccb->csio,
947 /* tag_action */ MSG_SIMPLE_Q_TAG,
948 /* tea */ softc->sc_picker,
950 /* invert */ (cp->cp_flags & CP_INVERT) ?
952 /* sense_len */ SSD_FULL_SIZE,
953 /* timeout */ CH_TIMEOUT_POSITION_TO_ELEMENT);
955 error = cam_periph_runccb(ccb, cherror, /*cam_flags*/ CAM_RETRY_SELTO,
956 /*sense_flags*/ SF_RETRY_UA,
957 softc->device_stats);
959 xpt_release_ccb(ccb);
965 * Copy a volume tag to a volume_tag struct, converting SCSI byte order
966 * to host native byte order in the volume serial number. The volume
967 * label as returned by the changer is transferred to user mode as
968 * nul-terminated string. Volume labels are truncated at the first
969 * space, as suggested by SCSI-2.
972 copy_voltag(struct changer_voltag *uvoltag, struct volume_tag *voltag)
975 for (i=0; i<CH_VOLTAG_MAXLEN; i++) {
976 char c = voltag->vif[i];
978 uvoltag->cv_volid[i] = c;
982 uvoltag->cv_serial = scsi_2btoul(voltag->vsn);
986 * Copy an an element status descriptor to a user-mode
987 * changer_element_status structure.
991 copy_element_status(struct ch_softc *softc,
993 struct read_element_status_descriptor *desc,
994 struct changer_element_status *ces)
996 u_int16_t eaddr = scsi_2btoul(desc->eaddr);
999 ces->ces_int_addr = eaddr;
1000 /* set up logical address in element status */
1001 for (et = CHET_MT; et <= CHET_DT; et++) {
1002 if ((softc->sc_firsts[et] <= eaddr)
1003 && ((softc->sc_firsts[et] + softc->sc_counts[et])
1005 ces->ces_addr = eaddr - softc->sc_firsts[et];
1011 ces->ces_flags = desc->flags1;
1013 ces->ces_sensecode = desc->sense_code;
1014 ces->ces_sensequal = desc->sense_qual;
1016 if (desc->flags2 & READ_ELEMENT_STATUS_INVERT)
1017 ces->ces_flags |= CES_INVERT;
1019 if (desc->flags2 & READ_ELEMENT_STATUS_SVALID) {
1021 eaddr = scsi_2btoul(desc->ssea);
1023 /* convert source address to logical format */
1024 for (et = CHET_MT; et <= CHET_DT; et++) {
1025 if ((softc->sc_firsts[et] <= eaddr)
1026 && ((softc->sc_firsts[et] + softc->sc_counts[et])
1028 ces->ces_source_addr =
1029 eaddr - softc->sc_firsts[et];
1030 ces->ces_source_type = et;
1031 ces->ces_flags |= CES_SOURCE_VALID;
1036 if (!(ces->ces_flags & CES_SOURCE_VALID))
1037 printf("ch: warning: could not map element source "
1038 "address %ud to a valid element type\n",
1043 if (flags & READ_ELEMENT_STATUS_PVOLTAG)
1044 copy_voltag(&(ces->ces_pvoltag), &(desc->pvoltag));
1045 if (flags & READ_ELEMENT_STATUS_AVOLTAG)
1046 copy_voltag(&(ces->ces_avoltag), &(desc->avoltag));
1048 if (desc->dt_scsi_flags & READ_ELEMENT_STATUS_DT_IDVALID) {
1049 ces->ces_flags |= CES_SCSIID_VALID;
1050 ces->ces_scsi_id = desc->dt_scsi_addr;
1053 if (desc->dt_scsi_addr & READ_ELEMENT_STATUS_DT_LUVALID) {
1054 ces->ces_flags |= CES_LUN_VALID;
1056 desc->dt_scsi_flags & READ_ELEMENT_STATUS_DT_LUNMASK;
1061 chgetelemstatus(struct cam_periph *periph,
1062 struct changer_element_status_request *cesr)
1064 struct read_element_status_header *st_hdr;
1065 struct read_element_status_page_header *pg_hdr;
1066 struct read_element_status_descriptor *desc;
1067 caddr_t data = NULL;
1068 size_t size, desclen;
1069 int avail, i, error = 0;
1070 struct changer_element_status *user_data = NULL;
1071 struct ch_softc *softc;
1073 int chet = cesr->cesr_element_type;
1074 int want_voltags = (cesr->cesr_flags & CESR_VOLTAGS) ? 1 : 0;
1076 softc = (struct ch_softc *)periph->softc;
1078 /* perform argument checking */
1081 * Perform a range check on the cesr_element_{base,count}
1082 * request argument fields.
1084 if ((softc->sc_counts[chet] - cesr->cesr_element_base) <= 0
1085 || (cesr->cesr_element_base + cesr->cesr_element_count)
1086 > softc->sc_counts[chet])
1090 * Request one descriptor for the given element type. This
1091 * is used to determine the size of the descriptor so that
1092 * we can allocate enough storage for all of them. We assume
1093 * that the first one can fit into 1k.
1095 cam_periph_unlock(periph);
1096 data = (caddr_t)malloc(1024, M_DEVBUF, M_WAITOK);
1098 cam_periph_lock(periph);
1099 ccb = cam_periph_getccb(periph, /*priority*/ 1);
1101 scsi_read_element_status(&ccb->csio,
1103 /* cbfcnp */ chdone,
1104 /* tag_action */ MSG_SIMPLE_Q_TAG,
1105 /* voltag */ want_voltags,
1106 /* sea */ softc->sc_firsts[chet],
1108 /* data_ptr */ data,
1109 /* dxfer_len */ 1024,
1110 /* sense_len */ SSD_FULL_SIZE,
1111 /* timeout */ CH_TIMEOUT_READ_ELEMENT_STATUS);
1113 error = cam_periph_runccb(ccb, cherror, /*cam_flags*/ CAM_RETRY_SELTO,
1114 /*sense_flags*/ SF_RETRY_UA,
1115 softc->device_stats);
1119 cam_periph_unlock(periph);
1121 st_hdr = (struct read_element_status_header *)data;
1122 pg_hdr = (struct read_element_status_page_header *)((uintptr_t)st_hdr +
1123 sizeof(struct read_element_status_header));
1124 desclen = scsi_2btoul(pg_hdr->edl);
1126 size = sizeof(struct read_element_status_header) +
1127 sizeof(struct read_element_status_page_header) +
1128 (desclen * cesr->cesr_element_count);
1131 * Reallocate storage for descriptors and get them from the
1134 free(data, M_DEVBUF);
1135 data = (caddr_t)malloc(size, M_DEVBUF, M_WAITOK);
1137 cam_periph_lock(periph);
1138 scsi_read_element_status(&ccb->csio,
1140 /* cbfcnp */ chdone,
1141 /* tag_action */ MSG_SIMPLE_Q_TAG,
1142 /* voltag */ want_voltags,
1143 /* sea */ softc->sc_firsts[chet]
1144 + cesr->cesr_element_base,
1145 /* count */ cesr->cesr_element_count,
1146 /* data_ptr */ data,
1147 /* dxfer_len */ size,
1148 /* sense_len */ SSD_FULL_SIZE,
1149 /* timeout */ CH_TIMEOUT_READ_ELEMENT_STATUS);
1151 error = cam_periph_runccb(ccb, cherror, /*cam_flags*/ CAM_RETRY_SELTO,
1152 /*sense_flags*/ SF_RETRY_UA,
1153 softc->device_stats);
1157 cam_periph_unlock(periph);
1160 * Fill in the user status array.
1162 st_hdr = (struct read_element_status_header *)data;
1163 pg_hdr = (struct read_element_status_page_header *)((uintptr_t)st_hdr +
1164 sizeof(struct read_element_status_header));
1165 avail = scsi_2btoul(st_hdr->count);
1167 if (avail != cesr->cesr_element_count) {
1168 xpt_print(periph->path,
1169 "warning, READ ELEMENT STATUS avail != count\n");
1172 user_data = (struct changer_element_status *)
1173 malloc(avail * sizeof(struct changer_element_status),
1174 M_DEVBUF, M_WAITOK | 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));
1195 cam_periph_lock(periph);
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*/ CAM_RETRY_SELTO,
1235 /*sense_flags*/ SF_RETRY_UA,
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*/ CAM_RETRY_SELTO,
1322 /*sense_flags*/ SF_RETRY_UA,
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_NOWAIT);
1358 if (mode_buffer == NULL) {
1359 printf("chgetparams: couldn't malloc mode sense data\n");
1363 bzero(mode_buffer, mode_buffer_len);
1365 if (softc->quirks & CH_Q_NO_DBD)
1371 * Get the element address assignment page.
1373 scsi_mode_sense(&ccb->csio,
1375 /* cbfcnp */ chdone,
1376 /* tag_action */ MSG_SIMPLE_Q_TAG,
1378 /* page_code */ SMS_PAGE_CTRL_CURRENT,
1379 /* page */ CH_ELEMENT_ADDR_ASSIGN_PAGE,
1380 /* param_buf */ (u_int8_t *)mode_buffer,
1381 /* param_len */ mode_buffer_len,
1382 /* sense_len */ SSD_FULL_SIZE,
1383 /* timeout */ CH_TIMEOUT_MODE_SENSE);
1385 error = cam_periph_runccb(ccb, cherror, /*cam_flags*/ CAM_RETRY_SELTO,
1386 /* sense_flags */ SF_RETRY_UA|SF_NO_PRINT,
1387 softc->device_stats);
1391 struct scsi_mode_sense_6 *sms;
1393 sms = (struct scsi_mode_sense_6 *)
1394 ccb->csio.cdb_io.cdb_bytes;
1396 sms->byte2 &= ~SMS_DBD;
1397 error = cam_periph_runccb(ccb, cherror,
1398 /*cam_flags*/ CAM_RETRY_SELTO,
1399 /*sense_flags*/ SF_RETRY_UA,
1400 softc->device_stats);
1403 * Since we disabled sense printing above, print
1404 * out the sense here since we got an error.
1406 scsi_sense_print(&ccb->csio);
1410 xpt_print(periph->path,
1411 "chgetparams: error getting element "
1413 xpt_release_ccb(ccb);
1414 free(mode_buffer, M_TEMP);
1419 ea = (struct page_element_address_assignment *)
1420 find_mode_page_6((struct scsi_mode_header_6 *)mode_buffer);
1422 softc->sc_firsts[CHET_MT] = scsi_2btoul(ea->mtea);
1423 softc->sc_counts[CHET_MT] = scsi_2btoul(ea->nmte);
1424 softc->sc_firsts[CHET_ST] = scsi_2btoul(ea->fsea);
1425 softc->sc_counts[CHET_ST] = scsi_2btoul(ea->nse);
1426 softc->sc_firsts[CHET_IE] = scsi_2btoul(ea->fieea);
1427 softc->sc_counts[CHET_IE] = scsi_2btoul(ea->niee);
1428 softc->sc_firsts[CHET_DT] = scsi_2btoul(ea->fdtea);
1429 softc->sc_counts[CHET_DT] = scsi_2btoul(ea->ndte);
1431 bzero(mode_buffer, mode_buffer_len);
1434 * Now get the device capabilities page.
1436 scsi_mode_sense(&ccb->csio,
1438 /* cbfcnp */ chdone,
1439 /* tag_action */ MSG_SIMPLE_Q_TAG,
1441 /* page_code */ SMS_PAGE_CTRL_CURRENT,
1442 /* page */ CH_DEVICE_CAP_PAGE,
1443 /* param_buf */ (u_int8_t *)mode_buffer,
1444 /* param_len */ mode_buffer_len,
1445 /* sense_len */ SSD_FULL_SIZE,
1446 /* timeout */ CH_TIMEOUT_MODE_SENSE);
1448 error = cam_periph_runccb(ccb, cherror, /*cam_flags*/ CAM_RETRY_SELTO,
1449 /* sense_flags */ SF_RETRY_UA | SF_NO_PRINT,
1450 softc->device_stats);
1454 struct scsi_mode_sense_6 *sms;
1456 sms = (struct scsi_mode_sense_6 *)
1457 ccb->csio.cdb_io.cdb_bytes;
1459 sms->byte2 &= ~SMS_DBD;
1460 error = cam_periph_runccb(ccb, cherror,
1461 /*cam_flags*/ CAM_RETRY_SELTO,
1462 /*sense_flags*/ SF_RETRY_UA,
1463 softc->device_stats);
1466 * Since we disabled sense printing above, print
1467 * out the sense here since we got an error.
1469 scsi_sense_print(&ccb->csio);
1473 xpt_print(periph->path,
1474 "chgetparams: error getting device "
1475 "capabilities page\n");
1476 xpt_release_ccb(ccb);
1477 free(mode_buffer, M_TEMP);
1482 xpt_release_ccb(ccb);
1484 cap = (struct page_device_capabilities *)
1485 find_mode_page_6((struct scsi_mode_header_6 *)mode_buffer);
1487 bzero(softc->sc_movemask, sizeof(softc->sc_movemask));
1488 bzero(softc->sc_exchangemask, sizeof(softc->sc_exchangemask));
1489 moves = cap->move_from;
1490 exchanges = cap->exchange_with;
1491 for (from = CHET_MT; from <= CHET_MAX; ++from) {
1492 softc->sc_movemask[from] = moves[from];
1493 softc->sc_exchangemask[from] = exchanges[from];
1496 free(mode_buffer, M_TEMP);
1502 scsi_move_medium(struct ccb_scsiio *csio, u_int32_t retries,
1503 void (*cbfcnp)(struct cam_periph *, union ccb *),
1504 u_int8_t tag_action, u_int32_t tea, u_int32_t src,
1505 u_int32_t dst, int invert, u_int8_t sense_len,
1508 struct scsi_move_medium *scsi_cmd;
1510 scsi_cmd = (struct scsi_move_medium *)&csio->cdb_io.cdb_bytes;
1511 bzero(scsi_cmd, sizeof(*scsi_cmd));
1513 scsi_cmd->opcode = MOVE_MEDIUM;
1515 scsi_ulto2b(tea, scsi_cmd->tea);
1516 scsi_ulto2b(src, scsi_cmd->src);
1517 scsi_ulto2b(dst, scsi_cmd->dst);
1520 scsi_cmd->invert |= MOVE_MEDIUM_INVERT;
1525 /*flags*/ CAM_DIR_NONE,
1535 scsi_exchange_medium(struct ccb_scsiio *csio, u_int32_t retries,
1536 void (*cbfcnp)(struct cam_periph *, union ccb *),
1537 u_int8_t tag_action, u_int32_t tea, u_int32_t src,
1538 u_int32_t dst1, u_int32_t dst2, int invert1,
1539 int invert2, u_int8_t sense_len, u_int32_t timeout)
1541 struct scsi_exchange_medium *scsi_cmd;
1543 scsi_cmd = (struct scsi_exchange_medium *)&csio->cdb_io.cdb_bytes;
1544 bzero(scsi_cmd, sizeof(*scsi_cmd));
1546 scsi_cmd->opcode = EXCHANGE_MEDIUM;
1548 scsi_ulto2b(tea, scsi_cmd->tea);
1549 scsi_ulto2b(src, scsi_cmd->src);
1550 scsi_ulto2b(dst1, scsi_cmd->fdst);
1551 scsi_ulto2b(dst2, scsi_cmd->sdst);
1554 scsi_cmd->invert |= EXCHANGE_MEDIUM_INV1;
1557 scsi_cmd->invert |= EXCHANGE_MEDIUM_INV2;
1562 /*flags*/ CAM_DIR_NONE,
1572 scsi_position_to_element(struct ccb_scsiio *csio, u_int32_t retries,
1573 void (*cbfcnp)(struct cam_periph *, union ccb *),
1574 u_int8_t tag_action, u_int32_t tea, u_int32_t dst,
1575 int invert, u_int8_t sense_len, u_int32_t timeout)
1577 struct scsi_position_to_element *scsi_cmd;
1579 scsi_cmd = (struct scsi_position_to_element *)&csio->cdb_io.cdb_bytes;
1580 bzero(scsi_cmd, sizeof(*scsi_cmd));
1582 scsi_cmd->opcode = POSITION_TO_ELEMENT;
1584 scsi_ulto2b(tea, scsi_cmd->tea);
1585 scsi_ulto2b(dst, scsi_cmd->dst);
1588 scsi_cmd->invert |= POSITION_TO_ELEMENT_INVERT;
1593 /*flags*/ CAM_DIR_NONE,
1603 scsi_read_element_status(struct ccb_scsiio *csio, u_int32_t retries,
1604 void (*cbfcnp)(struct cam_periph *, union ccb *),
1605 u_int8_t tag_action, int voltag, u_int32_t sea,
1606 u_int32_t count, u_int8_t *data_ptr,
1607 u_int32_t dxfer_len, u_int8_t sense_len,
1610 struct scsi_read_element_status *scsi_cmd;
1612 scsi_cmd = (struct scsi_read_element_status *)&csio->cdb_io.cdb_bytes;
1613 bzero(scsi_cmd, sizeof(*scsi_cmd));
1615 scsi_cmd->opcode = READ_ELEMENT_STATUS;
1617 scsi_ulto2b(sea, scsi_cmd->sea);
1618 scsi_ulto2b(count, scsi_cmd->count);
1619 scsi_ulto3b(dxfer_len, scsi_cmd->len);
1622 scsi_cmd->byte2 |= READ_ELEMENT_STATUS_VOLTAG;
1627 /*flags*/ CAM_DIR_IN,
1637 scsi_initialize_element_status(struct ccb_scsiio *csio, u_int32_t retries,
1638 void (*cbfcnp)(struct cam_periph *, union ccb *),
1639 u_int8_t tag_action, u_int8_t sense_len,
1642 struct scsi_initialize_element_status *scsi_cmd;
1644 scsi_cmd = (struct scsi_initialize_element_status *)
1645 &csio->cdb_io.cdb_bytes;
1646 bzero(scsi_cmd, sizeof(*scsi_cmd));
1648 scsi_cmd->opcode = INITIALIZE_ELEMENT_STATUS;
1653 /*flags*/ CAM_DIR_NONE,
1655 /* data_ptr */ NULL,
1663 scsi_send_volume_tag(struct ccb_scsiio *csio, u_int32_t retries,
1664 void (*cbfcnp)(struct cam_periph *, union ccb *),
1665 u_int8_t tag_action,
1666 u_int16_t element_address,
1667 u_int8_t send_action_code,
1668 struct scsi_send_volume_tag_parameters *parameters,
1669 u_int8_t sense_len, u_int32_t timeout)
1671 struct scsi_send_volume_tag *scsi_cmd;
1673 scsi_cmd = (struct scsi_send_volume_tag *) &csio->cdb_io.cdb_bytes;
1674 bzero(scsi_cmd, sizeof(*scsi_cmd));
1676 scsi_cmd->opcode = SEND_VOLUME_TAG;
1677 scsi_ulto2b(element_address, scsi_cmd->ea);
1678 scsi_cmd->sac = send_action_code;
1679 scsi_ulto2b(sizeof(*parameters), scsi_cmd->pll);
1684 /*flags*/ CAM_DIR_OUT,
1686 /* data_ptr */ (u_int8_t *) parameters,
1687 sizeof(*parameters),