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
128 #define ccb_state ppriv_field0
129 #define ccb_bp ppriv_ptr1
131 struct scsi_mode_sense_data {
132 struct scsi_mode_header_6 header;
133 struct scsi_mode_blk_desc blk_desc;
135 struct page_element_address_assignment ea;
136 struct page_transport_geometry_parameters tg;
137 struct page_device_capabilities cap;
146 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,
214 .d_flags = D_TRACKCLOSE,
221 static MALLOC_DEFINE(M_SCSICH, "scsi_ch", "scsi_ch buffers");
229 * Install a global async callback. This callback will
230 * receive async callbacks like "new device found".
232 status = xpt_register_async(AC_FOUND_DEVICE, chasync, NULL, NULL);
234 if (status != CAM_REQ_CMP) {
235 printf("ch: Failed to attach master async callback "
236 "due to status 0x%x!\n", status);
241 chdevgonecb(void *arg)
244 struct ch_softc *softc;
245 struct cam_periph *periph;
248 periph = (struct cam_periph *)arg;
250 softc = (struct ch_softc *)periph->softc;
252 KASSERT(softc->open_count >= 0, ("Negative open count %d",
258 * When we get this callback, we will get no more close calls from
259 * devfs. So if we have any dangling opens, we need to release the
260 * reference held for that particular context.
262 for (i = 0; i < softc->open_count; i++)
263 cam_periph_release_locked(periph);
265 softc->open_count = 0;
268 * Release the reference held for the device node, it is gone now.
270 cam_periph_release_locked(periph);
273 * We reference the SIM lock directly here, instead of using
274 * cam_periph_unlock(). The reason is that the final call to
275 * cam_periph_release_locked() above could result in the periph
276 * getting freed. If that is the case, dereferencing the periph
277 * with a cam_periph_unlock() call would cause a page fault.
279 mtx_unlock(sim->mtx);
283 choninvalidate(struct cam_periph *periph)
285 struct ch_softc *softc;
287 softc = (struct ch_softc *)periph->softc;
290 * De-register any async callbacks.
292 xpt_register_async(0, chasync, periph, periph->path);
294 softc->flags |= CH_FLAG_INVALID;
297 * Tell devfs this device has gone away, and ask for a callback
298 * when it has cleaned up its state.
300 destroy_dev_sched_cb(softc->dev, chdevgonecb, periph);
302 xpt_print(periph->path, "lost device\n");
307 chcleanup(struct cam_periph *periph)
309 struct ch_softc *softc;
311 softc = (struct ch_softc *)periph->softc;
313 xpt_print(periph->path, "removing device entry\n");
315 devstat_remove_entry(softc->device_stats);
317 free(softc, M_DEVBUF);
321 chasync(void *callback_arg, u_int32_t code, struct cam_path *path, void *arg)
323 struct cam_periph *periph;
325 periph = (struct cam_periph *)callback_arg;
328 case AC_FOUND_DEVICE:
330 struct ccb_getdev *cgd;
333 cgd = (struct ccb_getdev *)arg;
337 if (cgd->protocol != PROTO_SCSI)
340 if (SID_TYPE(&cgd->inq_data)!= T_CHANGER)
344 * Allocate a peripheral instance for
345 * this device and start the probe
348 status = cam_periph_alloc(chregister, choninvalidate,
349 chcleanup, chstart, "ch",
350 CAM_PERIPH_BIO, cgd->ccb_h.path,
351 chasync, AC_FOUND_DEVICE, cgd);
353 if (status != CAM_REQ_CMP
354 && status != CAM_REQ_INPROG)
355 printf("chasync: Unable to probe new device "
356 "due to status 0x%x\n", status);
362 cam_periph_async(periph, code, path, arg);
368 chregister(struct cam_periph *periph, void *arg)
370 struct ch_softc *softc;
371 struct ccb_getdev *cgd;
372 struct ccb_pathinq cpi;
374 cgd = (struct ccb_getdev *)arg;
376 printf("chregister: no getdev CCB, can't register device\n");
377 return(CAM_REQ_CMP_ERR);
380 softc = (struct ch_softc *)malloc(sizeof(*softc),M_DEVBUF,M_NOWAIT);
383 printf("chregister: Unable to probe new device. "
384 "Unable to allocate softc\n");
385 return(CAM_REQ_CMP_ERR);
388 bzero(softc, sizeof(*softc));
389 softc->state = CH_STATE_PROBE;
390 periph->softc = softc;
391 softc->quirks = CH_Q_NONE;
393 bzero(&cpi, sizeof(cpi));
394 xpt_setup_ccb(&cpi.ccb_h, periph->path, CAM_PRIORITY_NORMAL);
395 cpi.ccb_h.func_code = XPT_PATH_INQ;
396 xpt_action((union ccb *)&cpi);
399 * Changers don't have a blocksize, and obviously don't support
402 cam_periph_unlock(periph);
403 softc->device_stats = devstat_new_entry("ch",
404 periph->unit_number, 0,
405 DEVSTAT_NO_BLOCKSIZE | DEVSTAT_NO_ORDERED_TAGS,
406 SID_TYPE(&cgd->inq_data) |
407 XPORT_DEVSTAT_TYPE(cpi.transport),
408 DEVSTAT_PRIORITY_OTHER);
411 * Acquire a reference to the periph before we create the devfs
412 * instance for it. We'll release this reference once the devfs
413 * instance has been freed.
415 if (cam_periph_acquire(periph) != CAM_REQ_CMP) {
416 xpt_print(periph->path, "%s: lost periph during "
417 "registration!\n", __func__);
418 cam_periph_lock(periph);
419 return (CAM_REQ_CMP_ERR);
423 /* Register the device */
424 softc->dev = make_dev(&ch_cdevsw, periph->unit_number, UID_ROOT,
425 GID_OPERATOR, 0600, "%s%d", periph->periph_name,
426 periph->unit_number);
427 cam_periph_lock(periph);
428 softc->dev->si_drv1 = periph;
431 * Add an async callback so that we get
432 * notified if this device goes away.
434 xpt_register_async(AC_LOST_DEVICE, chasync, periph, periph->path);
437 * Lock this periph until we are setup.
438 * This first call can't block
440 (void)cam_periph_hold(periph, PRIBIO);
441 xpt_schedule(periph, CAM_PRIORITY_DEV);
447 chopen(struct cdev *dev, int flags, int fmt, struct thread *td)
449 struct cam_periph *periph;
450 struct ch_softc *softc;
453 periph = (struct cam_periph *)dev->si_drv1;
454 if (cam_periph_acquire(periph) != CAM_REQ_CMP)
457 softc = (struct ch_softc *)periph->softc;
459 cam_periph_lock(periph);
461 if (softc->flags & CH_FLAG_INVALID) {
462 cam_periph_release_locked(periph);
463 cam_periph_unlock(periph);
467 if ((error = cam_periph_hold(periph, PRIBIO | PCATCH)) != 0) {
468 cam_periph_unlock(periph);
469 cam_periph_release(periph);
474 * Load information about this changer device into the softc.
476 if ((error = chgetparams(periph)) != 0) {
477 cam_periph_release_locked(periph);
478 cam_periph_unlock(periph);
482 cam_periph_unhold(periph);
486 cam_periph_unlock(periph);
492 chclose(struct cdev *dev, int flag, int fmt, struct thread *td)
495 struct cam_periph *periph;
496 struct ch_softc *softc;
498 periph = (struct cam_periph *)dev->si_drv1;
503 softc = (struct ch_softc *)periph->softc;
509 cam_periph_release_locked(periph);
512 * We reference the SIM lock directly here, instead of using
513 * cam_periph_unlock(). The reason is that the call to
514 * cam_periph_release_locked() above could result in the periph
515 * getting freed. If that is the case, dereferencing the periph
516 * with a cam_periph_unlock() call would cause a page fault.
518 * cam_periph_release() avoids this problem using the same method,
519 * but we're manually acquiring and dropping the lock here to
520 * protect the open count and avoid another lock acquisition and
523 mtx_unlock(sim->mtx);
529 chstart(struct cam_periph *periph, union ccb *start_ccb)
531 struct ch_softc *softc;
533 softc = (struct ch_softc *)periph->softc;
535 switch (softc->state) {
536 case CH_STATE_NORMAL:
538 if (periph->immediate_priority <= periph->pinfo.priority){
539 start_ccb->ccb_h.ccb_state = CH_CCB_WAITING;
541 SLIST_INSERT_HEAD(&periph->ccb_list, &start_ccb->ccb_h,
543 periph->immediate_priority = CAM_PRIORITY_NONE;
544 wakeup(&periph->ccb_list);
554 * Include the block descriptor when calculating the mode
557 mode_buffer_len = sizeof(struct scsi_mode_header_6) +
558 sizeof(struct scsi_mode_blk_desc) +
559 sizeof(struct page_element_address_assignment);
561 mode_buffer = malloc(mode_buffer_len, M_SCSICH, M_NOWAIT);
563 if (mode_buffer == NULL) {
564 printf("chstart: couldn't malloc mode sense data\n");
567 bzero(mode_buffer, mode_buffer_len);
570 * Get the element address assignment page.
572 scsi_mode_sense(&start_ccb->csio,
575 /* tag_action */ MSG_SIMPLE_Q_TAG,
576 /* dbd */ (softc->quirks & CH_Q_NO_DBD) ?
578 /* page_code */ SMS_PAGE_CTRL_CURRENT,
579 /* page */ CH_ELEMENT_ADDR_ASSIGN_PAGE,
580 /* param_buf */ (u_int8_t *)mode_buffer,
581 /* param_len */ mode_buffer_len,
582 /* sense_len */ SSD_FULL_SIZE,
583 /* timeout */ CH_TIMEOUT_MODE_SENSE);
585 start_ccb->ccb_h.ccb_bp = NULL;
586 start_ccb->ccb_h.ccb_state = CH_CCB_PROBE;
587 xpt_action(start_ccb);
594 chdone(struct cam_periph *periph, union ccb *done_ccb)
596 struct ch_softc *softc;
597 struct ccb_scsiio *csio;
599 softc = (struct ch_softc *)periph->softc;
600 csio = &done_ccb->csio;
602 switch(done_ccb->ccb_h.ccb_state) {
605 struct scsi_mode_header_6 *mode_header;
606 struct page_element_address_assignment *ea;
607 char announce_buf[80];
610 mode_header = (struct scsi_mode_header_6 *)csio->data_ptr;
612 ea = (struct page_element_address_assignment *)
613 find_mode_page_6(mode_header);
615 if ((done_ccb->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP){
617 softc->sc_firsts[CHET_MT] = scsi_2btoul(ea->mtea);
618 softc->sc_counts[CHET_MT] = scsi_2btoul(ea->nmte);
619 softc->sc_firsts[CHET_ST] = scsi_2btoul(ea->fsea);
620 softc->sc_counts[CHET_ST] = scsi_2btoul(ea->nse);
621 softc->sc_firsts[CHET_IE] = scsi_2btoul(ea->fieea);
622 softc->sc_counts[CHET_IE] = scsi_2btoul(ea->niee);
623 softc->sc_firsts[CHET_DT] = scsi_2btoul(ea->fdtea);
624 softc->sc_counts[CHET_DT] = scsi_2btoul(ea->ndte);
625 softc->sc_picker = softc->sc_firsts[CHET_MT];
627 #define PLURAL(c) (c) == 1 ? "" : "s"
628 snprintf(announce_buf, sizeof(announce_buf),
629 "%d slot%s, %d drive%s, "
630 "%d picker%s, %d portal%s",
631 softc->sc_counts[CHET_ST],
632 PLURAL(softc->sc_counts[CHET_ST]),
633 softc->sc_counts[CHET_DT],
634 PLURAL(softc->sc_counts[CHET_DT]),
635 softc->sc_counts[CHET_MT],
636 PLURAL(softc->sc_counts[CHET_MT]),
637 softc->sc_counts[CHET_IE],
638 PLURAL(softc->sc_counts[CHET_IE]));
643 error = cherror(done_ccb, CAM_RETRY_SELTO,
644 SF_RETRY_UA | SF_NO_PRINT);
646 * Retry any UNIT ATTENTION type errors. They
647 * are expected at boot.
649 if (error == ERESTART) {
651 * A retry was scheuled, so
655 } else if (error != 0) {
657 struct scsi_mode_sense_6 *sms;
659 sms = (struct scsi_mode_sense_6 *)
660 done_ccb->csio.cdb_io.cdb_bytes;
663 * Check to see if block descriptors were
664 * disabled. Some devices don't like that.
665 * We're taking advantage of the fact that
666 * the first few bytes of the 6 and 10 byte
667 * mode sense commands are the same. If
668 * block descriptors were disabled, enable
669 * them and re-send the command.
671 if (sms->byte2 & SMS_DBD) {
672 sms->byte2 &= ~SMS_DBD;
673 xpt_action(done_ccb);
674 softc->quirks |= CH_Q_NO_DBD;
679 /* Don't wedge this device's queue */
680 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0)
681 cam_release_devq(done_ccb->ccb_h.path,
690 if ((done_ccb->ccb_h.status & CAM_STATUS_MASK)
691 == CAM_SCSI_STATUS_ERROR)
692 scsi_sense_print(&done_ccb->csio);
694 xpt_print(periph->path,
695 "got CAM status %#x\n",
696 done_ccb->ccb_h.status);
698 xpt_print(periph->path, "fatal error, failed "
699 "to attach to device\n");
701 cam_periph_invalidate(periph);
703 announce_buf[0] = '\0';
706 if (announce_buf[0] != '\0')
707 xpt_announce_periph(periph, announce_buf);
708 softc->state = CH_STATE_NORMAL;
709 free(mode_header, M_SCSICH);
711 * Since our peripheral may be invalidated by an error
712 * above or an external event, we must release our CCB
713 * before releasing the probe lock on the peripheral.
714 * The peripheral will only go away once the last lock
715 * is removed, and we need it around for the CCB release
718 xpt_release_ccb(done_ccb);
719 cam_periph_unhold(periph);
724 /* Caller will release the CCB */
725 wakeup(&done_ccb->ccb_h.cbfcnp);
731 xpt_release_ccb(done_ccb);
735 cherror(union ccb *ccb, u_int32_t cam_flags, u_int32_t sense_flags)
737 struct ch_softc *softc;
738 struct cam_periph *periph;
740 periph = xpt_path_periph(ccb->ccb_h.path);
741 softc = (struct ch_softc *)periph->softc;
743 return (cam_periph_error(ccb, cam_flags, sense_flags,
748 chioctl(struct cdev *dev, u_long cmd, caddr_t addr, int flag, struct thread *td)
750 struct cam_periph *periph;
751 struct ch_softc *softc;
754 periph = (struct cam_periph *)dev->si_drv1;
758 cam_periph_lock(periph);
759 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("entering chioctl\n"));
761 softc = (struct ch_softc *)periph->softc;
765 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE,
766 ("trying to do ioctl %#lx\n", cmd));
769 * If this command can change the device's state, we must
770 * have the device open for writing.
779 if ((flag & FWRITE) == 0) {
780 cam_periph_unlock(periph);
787 error = chmove(periph, (struct changer_move *)addr);
791 error = chexchange(periph, (struct changer_exchange *)addr);
795 error = chposition(periph, (struct changer_position *)addr);
799 *(int *)addr = softc->sc_picker - softc->sc_firsts[CHET_MT];
804 int new_picker = *(int *)addr;
806 if (new_picker > (softc->sc_counts[CHET_MT] - 1)) {
810 softc->sc_picker = softc->sc_firsts[CHET_MT] + new_picker;
815 struct changer_params *cp = (struct changer_params *)addr;
817 cp->cp_npickers = softc->sc_counts[CHET_MT];
818 cp->cp_nslots = softc->sc_counts[CHET_ST];
819 cp->cp_nportals = softc->sc_counts[CHET_IE];
820 cp->cp_ndrives = softc->sc_counts[CHET_DT];
824 error = chielem(periph, *(unsigned int *)addr);
829 error = chgetelemstatus(periph,
830 (struct changer_element_status_request *) addr);
836 error = chsetvoltag(periph,
837 (struct changer_set_voltag_request *) addr);
841 /* Implement prevent/allow? */
844 error = cam_periph_ioctl(periph, cmd, addr, cherror);
848 cam_periph_unlock(periph);
853 chmove(struct cam_periph *periph, struct changer_move *cm)
855 struct ch_softc *softc;
856 u_int16_t fromelem, toelem;
861 softc = (struct ch_softc *)periph->softc;
866 if ((cm->cm_fromtype > CHET_DT) || (cm->cm_totype > CHET_DT))
868 if ((cm->cm_fromunit > (softc->sc_counts[cm->cm_fromtype] - 1)) ||
869 (cm->cm_tounit > (softc->sc_counts[cm->cm_totype] - 1)))
873 * Check the request against the changer's capabilities.
875 if ((softc->sc_movemask[cm->cm_fromtype] & (1 << cm->cm_totype)) == 0)
879 * Calculate the source and destination elements.
881 fromelem = softc->sc_firsts[cm->cm_fromtype] + cm->cm_fromunit;
882 toelem = softc->sc_firsts[cm->cm_totype] + cm->cm_tounit;
884 ccb = cam_periph_getccb(periph, CAM_PRIORITY_NORMAL);
886 scsi_move_medium(&ccb->csio,
889 /* tag_action */ MSG_SIMPLE_Q_TAG,
890 /* tea */ softc->sc_picker,
893 /* invert */ (cm->cm_flags & CM_INVERT) ? TRUE : FALSE,
894 /* sense_len */ SSD_FULL_SIZE,
895 /* timeout */ CH_TIMEOUT_MOVE_MEDIUM);
897 error = cam_periph_runccb(ccb, cherror, /*cam_flags*/CAM_RETRY_SELTO,
898 /*sense_flags*/ SF_RETRY_UA,
899 softc->device_stats);
901 xpt_release_ccb(ccb);
907 chexchange(struct cam_periph *periph, struct changer_exchange *ce)
909 struct ch_softc *softc;
910 u_int16_t src, dst1, dst2;
915 softc = (struct ch_softc *)periph->softc;
919 if ((ce->ce_srctype > CHET_DT) || (ce->ce_fdsttype > CHET_DT) ||
920 (ce->ce_sdsttype > CHET_DT))
922 if ((ce->ce_srcunit > (softc->sc_counts[ce->ce_srctype] - 1)) ||
923 (ce->ce_fdstunit > (softc->sc_counts[ce->ce_fdsttype] - 1)) ||
924 (ce->ce_sdstunit > (softc->sc_counts[ce->ce_sdsttype] - 1)))
928 * Check the request against the changer's capabilities.
930 if (((softc->sc_exchangemask[ce->ce_srctype] &
931 (1 << ce->ce_fdsttype)) == 0) ||
932 ((softc->sc_exchangemask[ce->ce_fdsttype] &
933 (1 << ce->ce_sdsttype)) == 0))
937 * Calculate the source and destination elements.
939 src = softc->sc_firsts[ce->ce_srctype] + ce->ce_srcunit;
940 dst1 = softc->sc_firsts[ce->ce_fdsttype] + ce->ce_fdstunit;
941 dst2 = softc->sc_firsts[ce->ce_sdsttype] + ce->ce_sdstunit;
943 ccb = cam_periph_getccb(periph, CAM_PRIORITY_NORMAL);
945 scsi_exchange_medium(&ccb->csio,
948 /* tag_action */ MSG_SIMPLE_Q_TAG,
949 /* tea */ softc->sc_picker,
953 /* invert1 */ (ce->ce_flags & CE_INVERT1) ?
955 /* invert2 */ (ce->ce_flags & CE_INVERT2) ?
957 /* sense_len */ SSD_FULL_SIZE,
958 /* timeout */ CH_TIMEOUT_EXCHANGE_MEDIUM);
960 error = cam_periph_runccb(ccb, cherror, /*cam_flags*/CAM_RETRY_SELTO,
961 /*sense_flags*/ SF_RETRY_UA,
962 softc->device_stats);
964 xpt_release_ccb(ccb);
970 chposition(struct cam_periph *periph, struct changer_position *cp)
972 struct ch_softc *softc;
978 softc = (struct ch_softc *)periph->softc;
983 if (cp->cp_type > CHET_DT)
985 if (cp->cp_unit > (softc->sc_counts[cp->cp_type] - 1))
989 * Calculate the destination element.
991 dst = softc->sc_firsts[cp->cp_type] + cp->cp_unit;
993 ccb = cam_periph_getccb(periph, CAM_PRIORITY_NORMAL);
995 scsi_position_to_element(&ccb->csio,
998 /* tag_action */ MSG_SIMPLE_Q_TAG,
999 /* tea */ softc->sc_picker,
1001 /* invert */ (cp->cp_flags & CP_INVERT) ?
1003 /* sense_len */ SSD_FULL_SIZE,
1004 /* timeout */ CH_TIMEOUT_POSITION_TO_ELEMENT);
1006 error = cam_periph_runccb(ccb, cherror, /*cam_flags*/ CAM_RETRY_SELTO,
1007 /*sense_flags*/ SF_RETRY_UA,
1008 softc->device_stats);
1010 xpt_release_ccb(ccb);
1016 * Copy a volume tag to a volume_tag struct, converting SCSI byte order
1017 * to host native byte order in the volume serial number. The volume
1018 * label as returned by the changer is transferred to user mode as
1019 * nul-terminated string. Volume labels are truncated at the first
1020 * space, as suggested by SCSI-2.
1023 copy_voltag(struct changer_voltag *uvoltag, struct volume_tag *voltag)
1026 for (i=0; i<CH_VOLTAG_MAXLEN; i++) {
1027 char c = voltag->vif[i];
1029 uvoltag->cv_volid[i] = c;
1033 uvoltag->cv_serial = scsi_2btoul(voltag->vsn);
1037 * Copy an an element status descriptor to a user-mode
1038 * changer_element_status structure.
1042 copy_element_status(struct ch_softc *softc,
1044 struct read_element_status_descriptor *desc,
1045 struct changer_element_status *ces)
1047 u_int16_t eaddr = scsi_2btoul(desc->eaddr);
1050 ces->ces_int_addr = eaddr;
1051 /* set up logical address in element status */
1052 for (et = CHET_MT; et <= CHET_DT; et++) {
1053 if ((softc->sc_firsts[et] <= eaddr)
1054 && ((softc->sc_firsts[et] + softc->sc_counts[et])
1056 ces->ces_addr = eaddr - softc->sc_firsts[et];
1062 ces->ces_flags = desc->flags1;
1064 ces->ces_sensecode = desc->sense_code;
1065 ces->ces_sensequal = desc->sense_qual;
1067 if (desc->flags2 & READ_ELEMENT_STATUS_INVERT)
1068 ces->ces_flags |= CES_INVERT;
1070 if (desc->flags2 & READ_ELEMENT_STATUS_SVALID) {
1072 eaddr = scsi_2btoul(desc->ssea);
1074 /* convert source address to logical format */
1075 for (et = CHET_MT; et <= CHET_DT; et++) {
1076 if ((softc->sc_firsts[et] <= eaddr)
1077 && ((softc->sc_firsts[et] + softc->sc_counts[et])
1079 ces->ces_source_addr =
1080 eaddr - softc->sc_firsts[et];
1081 ces->ces_source_type = et;
1082 ces->ces_flags |= CES_SOURCE_VALID;
1087 if (!(ces->ces_flags & CES_SOURCE_VALID))
1088 printf("ch: warning: could not map element source "
1089 "address %ud to a valid element type\n",
1094 if (flags & READ_ELEMENT_STATUS_PVOLTAG)
1095 copy_voltag(&(ces->ces_pvoltag), &(desc->pvoltag));
1096 if (flags & READ_ELEMENT_STATUS_AVOLTAG)
1097 copy_voltag(&(ces->ces_avoltag), &(desc->avoltag));
1099 if (desc->dt_scsi_flags & READ_ELEMENT_STATUS_DT_IDVALID) {
1100 ces->ces_flags |= CES_SCSIID_VALID;
1101 ces->ces_scsi_id = desc->dt_scsi_addr;
1104 if (desc->dt_scsi_addr & READ_ELEMENT_STATUS_DT_LUVALID) {
1105 ces->ces_flags |= CES_LUN_VALID;
1107 desc->dt_scsi_flags & READ_ELEMENT_STATUS_DT_LUNMASK;
1112 chgetelemstatus(struct cam_periph *periph,
1113 struct changer_element_status_request *cesr)
1115 struct read_element_status_header *st_hdr;
1116 struct read_element_status_page_header *pg_hdr;
1117 struct read_element_status_descriptor *desc;
1118 caddr_t data = NULL;
1119 size_t size, desclen;
1120 int avail, i, error = 0;
1121 struct changer_element_status *user_data = NULL;
1122 struct ch_softc *softc;
1124 int chet = cesr->cesr_element_type;
1125 int want_voltags = (cesr->cesr_flags & CESR_VOLTAGS) ? 1 : 0;
1127 softc = (struct ch_softc *)periph->softc;
1129 /* perform argument checking */
1132 * Perform a range check on the cesr_element_{base,count}
1133 * request argument fields.
1135 if ((softc->sc_counts[chet] - cesr->cesr_element_base) <= 0
1136 || (cesr->cesr_element_base + cesr->cesr_element_count)
1137 > softc->sc_counts[chet])
1141 * Request one descriptor for the given element type. This
1142 * is used to determine the size of the descriptor so that
1143 * we can allocate enough storage for all of them. We assume
1144 * that the first one can fit into 1k.
1146 cam_periph_unlock(periph);
1147 data = (caddr_t)malloc(1024, M_DEVBUF, M_WAITOK);
1149 cam_periph_lock(periph);
1150 ccb = cam_periph_getccb(periph, CAM_PRIORITY_NORMAL);
1152 scsi_read_element_status(&ccb->csio,
1154 /* cbfcnp */ chdone,
1155 /* tag_action */ MSG_SIMPLE_Q_TAG,
1156 /* voltag */ want_voltags,
1157 /* sea */ softc->sc_firsts[chet],
1159 /* data_ptr */ data,
1160 /* dxfer_len */ 1024,
1161 /* sense_len */ SSD_FULL_SIZE,
1162 /* timeout */ CH_TIMEOUT_READ_ELEMENT_STATUS);
1164 error = cam_periph_runccb(ccb, cherror, /*cam_flags*/ CAM_RETRY_SELTO,
1165 /*sense_flags*/ SF_RETRY_UA,
1166 softc->device_stats);
1170 cam_periph_unlock(periph);
1172 st_hdr = (struct read_element_status_header *)data;
1173 pg_hdr = (struct read_element_status_page_header *)((uintptr_t)st_hdr +
1174 sizeof(struct read_element_status_header));
1175 desclen = scsi_2btoul(pg_hdr->edl);
1177 size = sizeof(struct read_element_status_header) +
1178 sizeof(struct read_element_status_page_header) +
1179 (desclen * cesr->cesr_element_count);
1182 * Reallocate storage for descriptors and get them from the
1185 free(data, M_DEVBUF);
1186 data = (caddr_t)malloc(size, M_DEVBUF, M_WAITOK);
1188 cam_periph_lock(periph);
1189 scsi_read_element_status(&ccb->csio,
1191 /* cbfcnp */ chdone,
1192 /* tag_action */ MSG_SIMPLE_Q_TAG,
1193 /* voltag */ want_voltags,
1194 /* sea */ softc->sc_firsts[chet]
1195 + cesr->cesr_element_base,
1196 /* count */ cesr->cesr_element_count,
1197 /* data_ptr */ data,
1198 /* dxfer_len */ size,
1199 /* sense_len */ SSD_FULL_SIZE,
1200 /* timeout */ CH_TIMEOUT_READ_ELEMENT_STATUS);
1202 error = cam_periph_runccb(ccb, cherror, /*cam_flags*/ CAM_RETRY_SELTO,
1203 /*sense_flags*/ SF_RETRY_UA,
1204 softc->device_stats);
1208 cam_periph_unlock(periph);
1211 * Fill in the user status array.
1213 st_hdr = (struct read_element_status_header *)data;
1214 pg_hdr = (struct read_element_status_page_header *)((uintptr_t)st_hdr +
1215 sizeof(struct read_element_status_header));
1216 avail = scsi_2btoul(st_hdr->count);
1218 if (avail != cesr->cesr_element_count) {
1219 xpt_print(periph->path,
1220 "warning, READ ELEMENT STATUS avail != count\n");
1223 user_data = (struct changer_element_status *)
1224 malloc(avail * sizeof(struct changer_element_status),
1225 M_DEVBUF, M_WAITOK | M_ZERO);
1227 desc = (struct read_element_status_descriptor *)((uintptr_t)data +
1228 sizeof(struct read_element_status_header) +
1229 sizeof(struct read_element_status_page_header));
1231 * Set up the individual element status structures
1233 for (i = 0; i < avail; ++i) {
1234 struct changer_element_status *ces = &(user_data[i]);
1236 copy_element_status(softc, pg_hdr->flags, desc, ces);
1238 desc = (struct read_element_status_descriptor *)
1239 ((uintptr_t)desc + desclen);
1242 /* Copy element status structures out to userspace. */
1243 error = copyout(user_data,
1244 cesr->cesr_element_status,
1245 avail * sizeof(struct changer_element_status));
1246 cam_periph_lock(periph);
1249 xpt_release_ccb(ccb);
1252 free(data, M_DEVBUF);
1253 if (user_data != NULL)
1254 free(user_data, M_DEVBUF);
1260 chielem(struct cam_periph *periph,
1261 unsigned int timeout)
1264 struct ch_softc *softc;
1268 timeout = CH_TIMEOUT_INITIALIZE_ELEMENT_STATUS;
1274 softc = (struct ch_softc *)periph->softc;
1276 ccb = cam_periph_getccb(periph, CAM_PRIORITY_NORMAL);
1278 scsi_initialize_element_status(&ccb->csio,
1280 /* cbfcnp */ chdone,
1281 /* tag_action */ MSG_SIMPLE_Q_TAG,
1282 /* sense_len */ SSD_FULL_SIZE,
1283 /* timeout */ timeout);
1285 error = cam_periph_runccb(ccb, cherror, /*cam_flags*/ CAM_RETRY_SELTO,
1286 /*sense_flags*/ SF_RETRY_UA,
1287 softc->device_stats);
1289 xpt_release_ccb(ccb);
1295 chsetvoltag(struct cam_periph *periph,
1296 struct changer_set_voltag_request *csvr)
1299 struct ch_softc *softc;
1302 struct scsi_send_volume_tag_parameters ssvtp;
1307 softc = (struct ch_softc *)periph->softc;
1309 bzero(&ssvtp, sizeof(ssvtp));
1310 for (i=0; i<sizeof(ssvtp.vitf); i++) {
1311 ssvtp.vitf[i] = ' ';
1317 if (csvr->csvr_type > CHET_DT)
1319 if (csvr->csvr_addr > (softc->sc_counts[csvr->csvr_type] - 1))
1322 ea = softc->sc_firsts[csvr->csvr_type] + csvr->csvr_addr;
1324 if (csvr->csvr_flags & CSVR_ALTERNATE) {
1325 switch (csvr->csvr_flags & CSVR_MODE_MASK) {
1327 sac = SEND_VOLUME_TAG_ASSERT_ALTERNATE;
1329 case CSVR_MODE_REPLACE:
1330 sac = SEND_VOLUME_TAG_REPLACE_ALTERNATE;
1332 case CSVR_MODE_CLEAR:
1333 sac = SEND_VOLUME_TAG_UNDEFINED_ALTERNATE;
1340 switch (csvr->csvr_flags & CSVR_MODE_MASK) {
1342 sac = SEND_VOLUME_TAG_ASSERT_PRIMARY;
1344 case CSVR_MODE_REPLACE:
1345 sac = SEND_VOLUME_TAG_REPLACE_PRIMARY;
1347 case CSVR_MODE_CLEAR:
1348 sac = SEND_VOLUME_TAG_UNDEFINED_PRIMARY;
1356 memcpy(ssvtp.vitf, csvr->csvr_voltag.cv_volid,
1357 min(strlen(csvr->csvr_voltag.cv_volid), sizeof(ssvtp.vitf)));
1358 scsi_ulto2b(csvr->csvr_voltag.cv_serial, ssvtp.minvsn);
1360 ccb = cam_periph_getccb(periph, CAM_PRIORITY_NORMAL);
1362 scsi_send_volume_tag(&ccb->csio,
1364 /* cbfcnp */ chdone,
1365 /* tag_action */ MSG_SIMPLE_Q_TAG,
1366 /* element_address */ ea,
1367 /* send_action_code */ sac,
1368 /* parameters */ &ssvtp,
1369 /* sense_len */ SSD_FULL_SIZE,
1370 /* timeout */ CH_TIMEOUT_SEND_VOLTAG);
1372 error = cam_periph_runccb(ccb, cherror, /*cam_flags*/ CAM_RETRY_SELTO,
1373 /*sense_flags*/ SF_RETRY_UA,
1374 softc->device_stats);
1376 xpt_release_ccb(ccb);
1383 chgetparams(struct cam_periph *periph)
1386 struct ch_softc *softc;
1388 int mode_buffer_len;
1389 struct page_element_address_assignment *ea;
1390 struct page_device_capabilities *cap;
1391 int error, from, dbd;
1392 u_int8_t *moves, *exchanges;
1396 softc = (struct ch_softc *)periph->softc;
1398 ccb = cam_periph_getccb(periph, CAM_PRIORITY_NORMAL);
1401 * The scsi_mode_sense_data structure is just a convenience
1402 * structure that allows us to easily calculate the worst-case
1403 * storage size of the mode sense buffer.
1405 mode_buffer_len = sizeof(struct scsi_mode_sense_data);
1407 mode_buffer = malloc(mode_buffer_len, M_SCSICH, M_NOWAIT);
1409 if (mode_buffer == NULL) {
1410 printf("chgetparams: couldn't malloc mode sense data\n");
1414 bzero(mode_buffer, mode_buffer_len);
1416 if (softc->quirks & CH_Q_NO_DBD)
1422 * Get the element address assignment page.
1424 scsi_mode_sense(&ccb->csio,
1426 /* cbfcnp */ chdone,
1427 /* tag_action */ MSG_SIMPLE_Q_TAG,
1429 /* page_code */ SMS_PAGE_CTRL_CURRENT,
1430 /* page */ CH_ELEMENT_ADDR_ASSIGN_PAGE,
1431 /* param_buf */ (u_int8_t *)mode_buffer,
1432 /* param_len */ mode_buffer_len,
1433 /* sense_len */ SSD_FULL_SIZE,
1434 /* timeout */ CH_TIMEOUT_MODE_SENSE);
1436 error = cam_periph_runccb(ccb, cherror, /*cam_flags*/ CAM_RETRY_SELTO,
1437 /* sense_flags */ SF_RETRY_UA|SF_NO_PRINT,
1438 softc->device_stats);
1442 struct scsi_mode_sense_6 *sms;
1444 sms = (struct scsi_mode_sense_6 *)
1445 ccb->csio.cdb_io.cdb_bytes;
1447 sms->byte2 &= ~SMS_DBD;
1448 error = cam_periph_runccb(ccb, cherror,
1449 /*cam_flags*/ CAM_RETRY_SELTO,
1450 /*sense_flags*/ SF_RETRY_UA,
1451 softc->device_stats);
1454 * Since we disabled sense printing above, print
1455 * out the sense here since we got an error.
1457 scsi_sense_print(&ccb->csio);
1461 xpt_print(periph->path,
1462 "chgetparams: error getting element "
1464 xpt_release_ccb(ccb);
1465 free(mode_buffer, M_SCSICH);
1470 ea = (struct page_element_address_assignment *)
1471 find_mode_page_6((struct scsi_mode_header_6 *)mode_buffer);
1473 softc->sc_firsts[CHET_MT] = scsi_2btoul(ea->mtea);
1474 softc->sc_counts[CHET_MT] = scsi_2btoul(ea->nmte);
1475 softc->sc_firsts[CHET_ST] = scsi_2btoul(ea->fsea);
1476 softc->sc_counts[CHET_ST] = scsi_2btoul(ea->nse);
1477 softc->sc_firsts[CHET_IE] = scsi_2btoul(ea->fieea);
1478 softc->sc_counts[CHET_IE] = scsi_2btoul(ea->niee);
1479 softc->sc_firsts[CHET_DT] = scsi_2btoul(ea->fdtea);
1480 softc->sc_counts[CHET_DT] = scsi_2btoul(ea->ndte);
1482 bzero(mode_buffer, mode_buffer_len);
1485 * Now get the device capabilities page.
1487 scsi_mode_sense(&ccb->csio,
1489 /* cbfcnp */ chdone,
1490 /* tag_action */ MSG_SIMPLE_Q_TAG,
1492 /* page_code */ SMS_PAGE_CTRL_CURRENT,
1493 /* page */ CH_DEVICE_CAP_PAGE,
1494 /* param_buf */ (u_int8_t *)mode_buffer,
1495 /* param_len */ mode_buffer_len,
1496 /* sense_len */ SSD_FULL_SIZE,
1497 /* timeout */ CH_TIMEOUT_MODE_SENSE);
1499 error = cam_periph_runccb(ccb, cherror, /*cam_flags*/ CAM_RETRY_SELTO,
1500 /* sense_flags */ SF_RETRY_UA | SF_NO_PRINT,
1501 softc->device_stats);
1505 struct scsi_mode_sense_6 *sms;
1507 sms = (struct scsi_mode_sense_6 *)
1508 ccb->csio.cdb_io.cdb_bytes;
1510 sms->byte2 &= ~SMS_DBD;
1511 error = cam_periph_runccb(ccb, cherror,
1512 /*cam_flags*/ CAM_RETRY_SELTO,
1513 /*sense_flags*/ SF_RETRY_UA,
1514 softc->device_stats);
1517 * Since we disabled sense printing above, print
1518 * out the sense here since we got an error.
1520 scsi_sense_print(&ccb->csio);
1524 xpt_print(periph->path,
1525 "chgetparams: error getting device "
1526 "capabilities page\n");
1527 xpt_release_ccb(ccb);
1528 free(mode_buffer, M_SCSICH);
1533 xpt_release_ccb(ccb);
1535 cap = (struct page_device_capabilities *)
1536 find_mode_page_6((struct scsi_mode_header_6 *)mode_buffer);
1538 bzero(softc->sc_movemask, sizeof(softc->sc_movemask));
1539 bzero(softc->sc_exchangemask, sizeof(softc->sc_exchangemask));
1540 moves = cap->move_from;
1541 exchanges = cap->exchange_with;
1542 for (from = CHET_MT; from <= CHET_MAX; ++from) {
1543 softc->sc_movemask[from] = moves[from];
1544 softc->sc_exchangemask[from] = exchanges[from];
1547 free(mode_buffer, M_SCSICH);
1553 scsi_move_medium(struct ccb_scsiio *csio, u_int32_t retries,
1554 void (*cbfcnp)(struct cam_periph *, union ccb *),
1555 u_int8_t tag_action, u_int32_t tea, u_int32_t src,
1556 u_int32_t dst, int invert, u_int8_t sense_len,
1559 struct scsi_move_medium *scsi_cmd;
1561 scsi_cmd = (struct scsi_move_medium *)&csio->cdb_io.cdb_bytes;
1562 bzero(scsi_cmd, sizeof(*scsi_cmd));
1564 scsi_cmd->opcode = MOVE_MEDIUM;
1566 scsi_ulto2b(tea, scsi_cmd->tea);
1567 scsi_ulto2b(src, scsi_cmd->src);
1568 scsi_ulto2b(dst, scsi_cmd->dst);
1571 scsi_cmd->invert |= MOVE_MEDIUM_INVERT;
1576 /*flags*/ CAM_DIR_NONE,
1586 scsi_exchange_medium(struct ccb_scsiio *csio, u_int32_t retries,
1587 void (*cbfcnp)(struct cam_periph *, union ccb *),
1588 u_int8_t tag_action, u_int32_t tea, u_int32_t src,
1589 u_int32_t dst1, u_int32_t dst2, int invert1,
1590 int invert2, u_int8_t sense_len, u_int32_t timeout)
1592 struct scsi_exchange_medium *scsi_cmd;
1594 scsi_cmd = (struct scsi_exchange_medium *)&csio->cdb_io.cdb_bytes;
1595 bzero(scsi_cmd, sizeof(*scsi_cmd));
1597 scsi_cmd->opcode = EXCHANGE_MEDIUM;
1599 scsi_ulto2b(tea, scsi_cmd->tea);
1600 scsi_ulto2b(src, scsi_cmd->src);
1601 scsi_ulto2b(dst1, scsi_cmd->fdst);
1602 scsi_ulto2b(dst2, scsi_cmd->sdst);
1605 scsi_cmd->invert |= EXCHANGE_MEDIUM_INV1;
1608 scsi_cmd->invert |= EXCHANGE_MEDIUM_INV2;
1613 /*flags*/ CAM_DIR_NONE,
1623 scsi_position_to_element(struct ccb_scsiio *csio, u_int32_t retries,
1624 void (*cbfcnp)(struct cam_periph *, union ccb *),
1625 u_int8_t tag_action, u_int32_t tea, u_int32_t dst,
1626 int invert, u_int8_t sense_len, u_int32_t timeout)
1628 struct scsi_position_to_element *scsi_cmd;
1630 scsi_cmd = (struct scsi_position_to_element *)&csio->cdb_io.cdb_bytes;
1631 bzero(scsi_cmd, sizeof(*scsi_cmd));
1633 scsi_cmd->opcode = POSITION_TO_ELEMENT;
1635 scsi_ulto2b(tea, scsi_cmd->tea);
1636 scsi_ulto2b(dst, scsi_cmd->dst);
1639 scsi_cmd->invert |= POSITION_TO_ELEMENT_INVERT;
1644 /*flags*/ CAM_DIR_NONE,
1654 scsi_read_element_status(struct ccb_scsiio *csio, u_int32_t retries,
1655 void (*cbfcnp)(struct cam_periph *, union ccb *),
1656 u_int8_t tag_action, int voltag, u_int32_t sea,
1657 u_int32_t count, u_int8_t *data_ptr,
1658 u_int32_t dxfer_len, u_int8_t sense_len,
1661 struct scsi_read_element_status *scsi_cmd;
1663 scsi_cmd = (struct scsi_read_element_status *)&csio->cdb_io.cdb_bytes;
1664 bzero(scsi_cmd, sizeof(*scsi_cmd));
1666 scsi_cmd->opcode = READ_ELEMENT_STATUS;
1668 scsi_ulto2b(sea, scsi_cmd->sea);
1669 scsi_ulto2b(count, scsi_cmd->count);
1670 scsi_ulto3b(dxfer_len, scsi_cmd->len);
1673 scsi_cmd->byte2 |= READ_ELEMENT_STATUS_VOLTAG;
1678 /*flags*/ CAM_DIR_IN,
1688 scsi_initialize_element_status(struct ccb_scsiio *csio, u_int32_t retries,
1689 void (*cbfcnp)(struct cam_periph *, union ccb *),
1690 u_int8_t tag_action, u_int8_t sense_len,
1693 struct scsi_initialize_element_status *scsi_cmd;
1695 scsi_cmd = (struct scsi_initialize_element_status *)
1696 &csio->cdb_io.cdb_bytes;
1697 bzero(scsi_cmd, sizeof(*scsi_cmd));
1699 scsi_cmd->opcode = INITIALIZE_ELEMENT_STATUS;
1704 /*flags*/ CAM_DIR_NONE,
1706 /* data_ptr */ NULL,
1714 scsi_send_volume_tag(struct ccb_scsiio *csio, u_int32_t retries,
1715 void (*cbfcnp)(struct cam_periph *, union ccb *),
1716 u_int8_t tag_action,
1717 u_int16_t element_address,
1718 u_int8_t send_action_code,
1719 struct scsi_send_volume_tag_parameters *parameters,
1720 u_int8_t sense_len, u_int32_t timeout)
1722 struct scsi_send_volume_tag *scsi_cmd;
1724 scsi_cmd = (struct scsi_send_volume_tag *) &csio->cdb_io.cdb_bytes;
1725 bzero(scsi_cmd, sizeof(*scsi_cmd));
1727 scsi_cmd->opcode = SEND_VOLUME_TAG;
1728 scsi_ulto2b(element_address, scsi_cmd->ea);
1729 scsi_cmd->sac = send_action_code;
1730 scsi_ulto2b(sizeof(*parameters), scsi_cmd->pll);
1735 /*flags*/ CAM_DIR_OUT,
1737 /* data_ptr */ (u_int8_t *) parameters,
1738 sizeof(*parameters),