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 $
30 * Derived from the NetBSD SCSI changer driver.
32 * $NetBSD: ch.c,v 1.32 1998/01/12 09:49:12 thorpej Exp $
36 * Copyright (c) 1996, 1997 Jason R. Thorpe <thorpej@and.com>
37 * All rights reserved.
39 * Partially based on an autochanger driver written by Stefan Grefen
40 * and on an autochanger driver written by the Systems Programming Group
41 * at the University of Utah Computer Science Department.
43 * Redistribution and use in source and binary forms, with or without
44 * modification, are permitted provided that the following conditions
46 * 1. Redistributions of source code must retain the above copyright
47 * notice, this list of conditions and the following disclaimer.
48 * 2. Redistributions in binary form must reproduce the above copyright
49 * notice, this list of conditions and the following disclaimer in the
50 * documentation and/or other materials provided with the distribution.
51 * 3. All advertising materials mentioning features or use of this software
52 * must display the following acknowledgements:
53 * This product includes software developed by Jason R. Thorpe
54 * for And Communications, http://www.and.com/
55 * 4. The name of the author may not be used to endorse or promote products
56 * derived from this software without specific prior written permission.
58 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
59 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
60 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
61 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
62 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
63 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
64 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
65 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
66 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
67 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
71 #include <sys/param.h>
72 #include <sys/queue.h>
73 #include <sys/systm.h>
74 #include <sys/kernel.h>
75 #include <sys/types.h>
76 #include <sys/malloc.h>
77 #include <sys/fcntl.h>
81 #include <sys/errno.h>
82 #include <sys/devicestat.h>
85 #include "../cam_ccb.h"
86 #include "../cam_extend.h"
87 #include "../cam_periph.h"
88 #include "../cam_xpt_periph.h"
89 #include "../cam_queue.h"
90 #include "../cam_debug.h"
93 #include "scsi_message.h"
97 * Timeout definitions for various changer related commands. They may
98 * be too short for some devices (especially the timeout for INITIALIZE
102 static const u_int32_t CH_TIMEOUT_MODE_SENSE = 6000;
103 static const u_int32_t CH_TIMEOUT_MOVE_MEDIUM = 100000;
104 static const u_int32_t CH_TIMEOUT_EXCHANGE_MEDIUM = 100000;
105 static const u_int32_t CH_TIMEOUT_POSITION_TO_ELEMENT = 100000;
106 static const u_int32_t CH_TIMEOUT_READ_ELEMENT_STATUS = 10000;
107 static const u_int32_t CH_TIMEOUT_SEND_VOLTAG = 10000;
108 static const u_int32_t CH_TIMEOUT_INITIALIZE_ELEMENT_STATUS = 500000;
111 CH_FLAG_INVALID = 0x001,
131 #define ccb_state ppriv_field0
132 #define ccb_bio ppriv_ptr1
134 struct scsi_mode_sense_data {
135 struct scsi_mode_header_6 header;
136 struct scsi_mode_blk_desc blk_desc;
138 struct page_element_address_assignment ea;
139 struct page_transport_geometry_parameters tg;
140 struct page_device_capabilities cap;
149 struct devstat device_stats;
151 int sc_picker; /* current picker */
154 * The following information is obtained from the
155 * element address assignment page.
157 int sc_firsts[CHET_MAX + 1]; /* firsts */
158 int sc_counts[CHET_MAX + 1]; /* counts */
161 * The following mask defines the legal combinations
162 * of elements for the MOVE MEDIUM command.
164 u_int8_t sc_movemask[CHET_MAX + 1];
167 * As above, but for EXCHANGE MEDIUM.
169 u_int8_t sc_exchangemask[CHET_MAX + 1];
172 * Quirks; see below. XXX KDM not implemented yet
174 int sc_settledelay; /* delay for settle */
177 #define CHUNIT(x) (minor((x)))
179 static d_open_t chopen;
180 static d_close_t chclose;
181 static d_ioctl_t chioctl;
182 static periph_init_t chinit;
183 static periph_ctor_t chregister;
184 static periph_oninv_t choninvalidate;
185 static periph_dtor_t chcleanup;
186 static periph_start_t chstart;
187 static void chasync(void *callback_arg, u_int32_t code,
188 struct cam_path *path, void *arg);
189 static void chdone(struct cam_periph *periph,
190 union ccb *done_ccb);
191 static int cherror(union ccb *ccb, u_int32_t cam_flags,
192 u_int32_t sense_flags);
193 static int chmove(struct cam_periph *periph,
194 struct changer_move *cm);
195 static int chexchange(struct cam_periph *periph,
196 struct changer_exchange *ce);
197 static int chposition(struct cam_periph *periph,
198 struct changer_position *cp);
199 static int chgetelemstatus(struct cam_periph *periph,
200 struct changer_element_status_request *csr);
201 static int chsetvoltag(struct cam_periph *periph,
202 struct changer_set_voltag_request *csvr);
203 static int chielem(struct cam_periph *periph,
204 unsigned int timeout);
205 static int chgetparams(struct cam_periph *periph);
207 static struct periph_driver chdriver =
210 TAILQ_HEAD_INITIALIZER(chdriver.units), /* generation */ 0
213 PERIPHDRIVER_DECLARE(ch, chdriver);
215 static struct dev_ops ch_ops = {
222 static struct extend_array *chperiphs;
224 MALLOC_DEFINE(M_SCSICH, "scsi_ch", "scsi_ch buffers");
232 * Create our extend array for storing the devices we attach to.
234 chperiphs = cam_extend_new();
235 if (chperiphs == NULL) {
236 kprintf("ch: Failed to alloc extend array!\n");
241 * Install a global async callback. This callback will
242 * receive async callbacks like "new device found".
244 status = xpt_register_async(AC_FOUND_DEVICE, chasync, NULL, NULL);
246 if (status != CAM_REQ_CMP) {
247 kprintf("ch: Failed to attach master async callback "
248 "due to status 0x%x!\n", status);
253 choninvalidate(struct cam_periph *periph)
255 struct ch_softc *softc;
257 softc = (struct ch_softc *)periph->softc;
260 * De-register any async callbacks.
262 xpt_register_async(0, chasync, periph, periph->path);
264 softc->flags |= CH_FLAG_INVALID;
266 xpt_print(periph->path, "lost device\n");
271 chcleanup(struct cam_periph *periph)
273 struct ch_softc *softc;
275 softc = (struct ch_softc *)periph->softc;
277 devstat_remove_entry(&softc->device_stats);
278 cam_extend_release(chperiphs, periph->unit_number);
279 xpt_print(periph->path, "removing device entry\n");
280 dev_ops_remove_minor(&ch_ops, periph->unit_number);
281 kfree(softc, M_DEVBUF);
285 chasync(void *callback_arg, u_int32_t code, struct cam_path *path, void *arg)
287 struct cam_periph *periph;
289 periph = (struct cam_periph *)callback_arg;
292 case AC_FOUND_DEVICE:
294 struct ccb_getdev *cgd;
297 cgd = (struct ccb_getdev *)arg;
301 if (SID_TYPE(&cgd->inq_data)!= T_CHANGER)
305 * Allocate a peripheral instance for
306 * this device and start the probe
309 status = cam_periph_alloc(chregister, choninvalidate,
310 chcleanup, chstart, "ch",
311 CAM_PERIPH_BIO, cgd->ccb_h.path,
312 chasync, AC_FOUND_DEVICE, cgd);
314 if (status != CAM_REQ_CMP
315 && status != CAM_REQ_INPROG)
316 kprintf("chasync: Unable to probe new device "
317 "due to status 0x%x\n", status);
323 cam_periph_async(periph, code, path, arg);
329 chregister(struct cam_periph *periph, void *arg)
331 struct ch_softc *softc;
332 struct ccb_getdev *cgd;
334 cgd = (struct ccb_getdev *)arg;
335 if (periph == NULL) {
336 kprintf("chregister: periph was NULL!!\n");
337 return(CAM_REQ_CMP_ERR);
341 kprintf("chregister: no getdev CCB, can't register device\n");
342 return(CAM_REQ_CMP_ERR);
345 softc = kmalloc(sizeof(*softc), M_DEVBUF, M_INTWAIT | M_ZERO);
346 softc->state = CH_STATE_PROBE;
347 periph->softc = softc;
348 cam_extend_set(chperiphs, periph->unit_number, periph);
349 softc->quirks = CH_Q_NONE;
352 * Changers don't have a blocksize, and obviously don't support
355 cam_periph_unlock(periph);
356 devstat_add_entry(&softc->device_stats, "ch",
357 periph->unit_number, 0,
358 DEVSTAT_NO_BLOCKSIZE | DEVSTAT_NO_ORDERED_TAGS,
359 SID_TYPE(&cgd->inq_data)| DEVSTAT_TYPE_IF_SCSI,
360 DEVSTAT_PRIORITY_OTHER);
362 /* Register the device */
363 make_dev(&ch_ops, periph->unit_number, UID_ROOT,
364 GID_OPERATOR, 0600, "%s%d", periph->periph_name,
365 periph->unit_number);
366 cam_periph_lock(periph);
369 * Add an async callback so that we get
370 * notified if this device goes away.
372 xpt_register_async(AC_LOST_DEVICE, chasync, periph, periph->path);
375 * Lock this periph until we are setup.
376 * This first call can't block
378 cam_periph_hold(periph, 0);
379 xpt_schedule(periph, /*priority*/5);
385 chopen(struct dev_open_args *ap)
387 cdev_t dev = ap->a_head.a_dev;
388 struct cam_periph *periph;
389 struct ch_softc *softc;
393 periph = cam_extend_get(chperiphs, unit);
395 if (cam_periph_acquire(periph) != CAM_REQ_CMP)
398 softc = (struct ch_softc *)periph->softc;
400 cam_periph_lock(periph);
402 if (softc->flags & CH_FLAG_INVALID) {
403 cam_periph_unlock(periph);
404 cam_periph_release(periph);
408 if ((softc->flags & CH_FLAG_OPEN) == 0)
409 softc->flags |= CH_FLAG_OPEN;
411 cam_periph_release(periph);
413 if ((error = cam_periph_hold(periph, PCATCH)) != 0) {
414 cam_periph_unlock(periph);
415 cam_periph_release(periph);
420 * Load information about this changer device into the softc.
422 if ((error = chgetparams(periph)) != 0) {
423 softc->flags &= ~CH_FLAG_OPEN;
424 cam_periph_unhold(periph, 1);
425 cam_periph_release(periph);
427 cam_periph_unhold(periph, 1);
434 chclose(struct dev_close_args *ap)
436 cdev_t dev = ap->a_head.a_dev;
437 struct cam_periph *periph;
438 struct ch_softc *softc;
442 periph = cam_extend_get(chperiphs, unit);
446 softc = (struct ch_softc *)periph->softc;
448 cam_periph_lock(periph);
450 softc->flags &= ~CH_FLAG_OPEN;
452 cam_periph_unlock(periph);
453 cam_periph_release(periph);
459 chstart(struct cam_periph *periph, union ccb *start_ccb)
461 struct ch_softc *softc;
463 softc = (struct ch_softc *)periph->softc;
465 switch (softc->state) {
466 case CH_STATE_NORMAL:
468 if (periph->immediate_priority <= periph->pinfo.priority){
469 start_ccb->ccb_h.ccb_state = CH_CCB_WAITING;
471 SLIST_INSERT_HEAD(&periph->ccb_list, &start_ccb->ccb_h,
473 periph->immediate_priority = CAM_PRIORITY_NONE;
474 wakeup(&periph->ccb_list);
484 * Include the block descriptor when calculating the mode
487 mode_buffer_len = sizeof(struct scsi_mode_header_6) +
488 sizeof(struct scsi_mode_blk_desc) +
489 sizeof(struct page_element_address_assignment);
491 mode_buffer = kmalloc(mode_buffer_len, M_SCSICH, M_INTWAIT | M_ZERO);
493 * Get the element address assignment page.
495 scsi_mode_sense(&start_ccb->csio,
498 /* tag_action */ MSG_SIMPLE_Q_TAG,
499 /* dbd */ (softc->quirks & CH_Q_NO_DBD) ?
501 /* page_code */ SMS_PAGE_CTRL_CURRENT,
502 /* page */ CH_ELEMENT_ADDR_ASSIGN_PAGE,
503 /* param_buf */ (u_int8_t *)mode_buffer,
504 /* param_len */ mode_buffer_len,
505 /* sense_len */ SSD_FULL_SIZE,
506 /* timeout */ CH_TIMEOUT_MODE_SENSE);
508 start_ccb->ccb_h.ccb_bio = NULL;
509 start_ccb->ccb_h.ccb_state = CH_CCB_PROBE;
510 xpt_action(start_ccb);
517 chdone(struct cam_periph *periph, union ccb *done_ccb)
519 struct ch_softc *softc;
520 struct ccb_scsiio *csio;
522 softc = (struct ch_softc *)periph->softc;
523 csio = &done_ccb->csio;
525 switch(done_ccb->ccb_h.ccb_state) {
527 /* Caller releases ccb */
528 wakeup(&done_ccb->ccb_h.cbfcnp);
532 struct scsi_mode_header_6 *mode_header;
533 struct page_element_address_assignment *ea;
534 char announce_buf[80];
537 mode_header = (struct scsi_mode_header_6 *)csio->data_ptr;
539 ea = (struct page_element_address_assignment *)
540 find_mode_page_6(mode_header);
542 if ((done_ccb->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP){
544 softc->sc_firsts[CHET_MT] = scsi_2btoul(ea->mtea);
545 softc->sc_counts[CHET_MT] = scsi_2btoul(ea->nmte);
546 softc->sc_firsts[CHET_ST] = scsi_2btoul(ea->fsea);
547 softc->sc_counts[CHET_ST] = scsi_2btoul(ea->nse);
548 softc->sc_firsts[CHET_IE] = scsi_2btoul(ea->fieea);
549 softc->sc_counts[CHET_IE] = scsi_2btoul(ea->niee);
550 softc->sc_firsts[CHET_DT] = scsi_2btoul(ea->fdtea);
551 softc->sc_counts[CHET_DT] = scsi_2btoul(ea->ndte);
552 softc->sc_picker = softc->sc_firsts[CHET_MT];
554 #define PLURAL(c) (c) == 1 ? "" : "s"
555 ksnprintf(announce_buf, sizeof(announce_buf),
556 "%d slot%s, %d drive%s, "
557 "%d picker%s, %d portal%s",
558 softc->sc_counts[CHET_ST],
559 PLURAL(softc->sc_counts[CHET_ST]),
560 softc->sc_counts[CHET_DT],
561 PLURAL(softc->sc_counts[CHET_DT]),
562 softc->sc_counts[CHET_MT],
563 PLURAL(softc->sc_counts[CHET_MT]),
564 softc->sc_counts[CHET_IE],
565 PLURAL(softc->sc_counts[CHET_IE]));
570 error = cherror(done_ccb, CAM_RETRY_SELTO,
571 SF_RETRY_UA | SF_NO_PRINT);
573 * Retry any UNIT ATTENTION type errors. They
574 * are expected at boot.
576 if (error == ERESTART) {
578 * A retry was scheuled, so
582 } else if (error != 0) {
584 struct scsi_mode_sense_6 *sms;
586 sms = (struct scsi_mode_sense_6 *)
587 done_ccb->csio.cdb_io.cdb_bytes;
590 * Check to see if block descriptors were
591 * disabled. Some devices don't like that.
592 * We're taking advantage of the fact that
593 * the first few bytes of the 6 and 10 byte
594 * mode sense commands are the same. If
595 * block descriptors were disabled, enable
596 * them and re-send the command.
598 if (sms->byte2 & SMS_DBD) {
599 sms->byte2 &= ~SMS_DBD;
600 xpt_action(done_ccb);
601 softc->quirks |= CH_Q_NO_DBD;
606 /* Don't wedge this device's queue */
607 cam_release_devq(done_ccb->ccb_h.path,
616 if ((done_ccb->ccb_h.status & CAM_STATUS_MASK)
617 == CAM_SCSI_STATUS_ERROR)
618 scsi_sense_print(&done_ccb->csio);
620 xpt_print(periph->path,
621 "got CAM status %#x\n",
622 done_ccb->ccb_h.status);
624 xpt_print(periph->path, "fatal error, failed "
625 "to attach to device\n");
627 cam_periph_invalidate(periph);
629 announce_buf[0] = '\0';
632 if (announce_buf[0] != '\0')
633 xpt_announce_periph(periph, announce_buf);
634 softc->state = CH_STATE_NORMAL;
635 kfree(mode_header, M_SCSICH);
637 * Since our peripheral may be invalidated by an error
638 * above or an external event, we must release our CCB
639 * before releasing the probe lock on the peripheral.
640 * The peripheral will only go away once the last lock
641 * is removed, and we need it around for the CCB release
644 xpt_release_ccb(done_ccb);
645 cam_periph_unhold(periph, 0);
650 /* Caller will release the CCB */
651 wakeup(&done_ccb->ccb_h.cbfcnp);
657 xpt_release_ccb(done_ccb);
661 cherror(union ccb *ccb, u_int32_t cam_flags, u_int32_t sense_flags)
663 struct ch_softc *softc;
664 struct cam_periph *periph;
666 periph = xpt_path_periph(ccb->ccb_h.path);
667 softc = (struct ch_softc *)periph->softc;
669 return (cam_periph_error(ccb, cam_flags, sense_flags,
674 chioctl(struct dev_ioctl_args *ap)
676 cdev_t dev = ap->a_head.a_dev;
677 caddr_t addr = ap->a_data;
678 int flag = ap->a_fflag;
679 struct cam_periph *periph;
680 struct ch_softc *softc;
686 periph = cam_extend_get(chperiphs, unit);
690 cam_periph_lock(periph);
691 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("entering chioctl\n"));
693 softc = (struct ch_softc *)periph->softc;
697 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE,
698 ("trying to do ioctl %#lx\n", ap->a_cmd));
701 * If this command can change the device's state, we must
702 * have the device open for writing.
711 if ((flag & FWRITE) == 0) {
712 cam_periph_unlock(periph);
719 error = chmove(periph, (struct changer_move *)addr);
723 error = chexchange(periph, (struct changer_exchange *)addr);
727 error = chposition(periph, (struct changer_position *)addr);
731 *(int *)addr = softc->sc_picker - softc->sc_firsts[CHET_MT];
736 int new_picker = *(int *)addr;
738 if (new_picker > (softc->sc_counts[CHET_MT] - 1)) {
742 softc->sc_picker = softc->sc_firsts[CHET_MT] + new_picker;
747 struct changer_params *cp = (struct changer_params *)addr;
749 cp->cp_npickers = softc->sc_counts[CHET_MT];
750 cp->cp_nslots = softc->sc_counts[CHET_ST];
751 cp->cp_nportals = softc->sc_counts[CHET_IE];
752 cp->cp_ndrives = softc->sc_counts[CHET_DT];
756 error = chielem(periph, *(unsigned int *)addr);
761 error = chgetelemstatus(periph,
762 (struct changer_element_status_request *) addr);
768 error = chsetvoltag(periph,
769 (struct changer_set_voltag_request *) addr);
773 /* Implement prevent/allow? */
776 error = cam_periph_ioctl(periph, ap->a_cmd, addr, cherror);
780 cam_periph_unlock(periph);
785 chmove(struct cam_periph *periph, struct changer_move *cm)
787 struct ch_softc *softc;
788 u_int16_t fromelem, toelem;
793 softc = (struct ch_softc *)periph->softc;
798 if ((cm->cm_fromtype > CHET_DT) || (cm->cm_totype > CHET_DT))
800 if ((cm->cm_fromunit > (softc->sc_counts[cm->cm_fromtype] - 1)) ||
801 (cm->cm_tounit > (softc->sc_counts[cm->cm_totype] - 1)))
805 * Check the request against the changer's capabilities.
807 if ((softc->sc_movemask[cm->cm_fromtype] & (1 << cm->cm_totype)) == 0)
811 * Calculate the source and destination elements.
813 fromelem = softc->sc_firsts[cm->cm_fromtype] + cm->cm_fromunit;
814 toelem = softc->sc_firsts[cm->cm_totype] + cm->cm_tounit;
816 ccb = cam_periph_getccb(periph, /*priority*/ 1);
817 ccb->ccb_h.ccb_state = CH_CCB_POLLED;
819 scsi_move_medium(&ccb->csio,
822 /* tag_action */ MSG_SIMPLE_Q_TAG,
823 /* tea */ softc->sc_picker,
826 /* invert */ (cm->cm_flags & CM_INVERT) ? TRUE : FALSE,
827 /* sense_len */ SSD_FULL_SIZE,
828 /* timeout */ CH_TIMEOUT_MOVE_MEDIUM);
830 error = cam_periph_runccb(ccb, cherror, /*cam_flags*/CAM_RETRY_SELTO,
831 /*sense_flags*/ SF_RETRY_UA,
832 &softc->device_stats);
834 xpt_release_ccb(ccb);
840 chexchange(struct cam_periph *periph, struct changer_exchange *ce)
842 struct ch_softc *softc;
843 u_int16_t src, dst1, dst2;
848 softc = (struct ch_softc *)periph->softc;
852 if ((ce->ce_srctype > CHET_DT) || (ce->ce_fdsttype > CHET_DT) ||
853 (ce->ce_sdsttype > CHET_DT))
855 if ((ce->ce_srcunit > (softc->sc_counts[ce->ce_srctype] - 1)) ||
856 (ce->ce_fdstunit > (softc->sc_counts[ce->ce_fdsttype] - 1)) ||
857 (ce->ce_sdstunit > (softc->sc_counts[ce->ce_sdsttype] - 1)))
861 * Check the request against the changer's capabilities.
863 if (((softc->sc_exchangemask[ce->ce_srctype] &
864 (1 << ce->ce_fdsttype)) == 0) ||
865 ((softc->sc_exchangemask[ce->ce_fdsttype] &
866 (1 << ce->ce_sdsttype)) == 0))
870 * Calculate the source and destination elements.
872 src = softc->sc_firsts[ce->ce_srctype] + ce->ce_srcunit;
873 dst1 = softc->sc_firsts[ce->ce_fdsttype] + ce->ce_fdstunit;
874 dst2 = softc->sc_firsts[ce->ce_sdsttype] + ce->ce_sdstunit;
876 ccb = cam_periph_getccb(periph, /*priority*/ 1);
877 ccb->ccb_h.ccb_state = CH_CCB_POLLED;
879 scsi_exchange_medium(&ccb->csio,
882 /* tag_action */ MSG_SIMPLE_Q_TAG,
883 /* tea */ softc->sc_picker,
887 /* invert1 */ (ce->ce_flags & CE_INVERT1) ?
889 /* invert2 */ (ce->ce_flags & CE_INVERT2) ?
891 /* sense_len */ SSD_FULL_SIZE,
892 /* timeout */ CH_TIMEOUT_EXCHANGE_MEDIUM);
894 error = cam_periph_runccb(ccb, cherror, /*cam_flags*/CAM_RETRY_SELTO,
895 /*sense_flags*/ SF_RETRY_UA,
896 &softc->device_stats);
898 xpt_release_ccb(ccb);
904 chposition(struct cam_periph *periph, struct changer_position *cp)
906 struct ch_softc *softc;
912 softc = (struct ch_softc *)periph->softc;
917 if (cp->cp_type > CHET_DT)
919 if (cp->cp_unit > (softc->sc_counts[cp->cp_type] - 1))
923 * Calculate the destination element.
925 dst = softc->sc_firsts[cp->cp_type] + cp->cp_unit;
927 ccb = cam_periph_getccb(periph, /*priority*/ 1);
928 ccb->ccb_h.ccb_state = CH_CCB_POLLED;
930 scsi_position_to_element(&ccb->csio,
933 /* tag_action */ MSG_SIMPLE_Q_TAG,
934 /* tea */ softc->sc_picker,
936 /* invert */ (cp->cp_flags & CP_INVERT) ?
938 /* sense_len */ SSD_FULL_SIZE,
939 /* timeout */ CH_TIMEOUT_POSITION_TO_ELEMENT);
941 error = cam_periph_runccb(ccb, cherror, /*cam_flags*/ CAM_RETRY_SELTO,
942 /*sense_flags*/ SF_RETRY_UA,
943 &softc->device_stats);
945 xpt_release_ccb(ccb);
951 * Copy a volume tag to a volume_tag struct, converting SCSI byte order
952 * to host native byte order in the volume serial number. The volume
953 * label as returned by the changer is transferred to user mode as
954 * nul-terminated string. Volume labels are truncated at the first
955 * space, as suggested by SCSI-2.
958 copy_voltag(struct changer_voltag *uvoltag, struct volume_tag *voltag)
961 for (i=0; i<CH_VOLTAG_MAXLEN; i++) {
962 char c = voltag->vif[i];
964 uvoltag->cv_volid[i] = c;
968 uvoltag->cv_serial = scsi_2btoul(voltag->vsn);
972 * Copy an an element status descriptor to a user-mode
973 * changer_element_status structure.
977 copy_element_status(struct ch_softc *softc,
979 struct read_element_status_descriptor *desc,
980 struct changer_element_status *ces)
982 u_int16_t eaddr = scsi_2btoul(desc->eaddr);
985 ces->ces_int_addr = eaddr;
986 /* set up logical address in element status */
987 for (et = CHET_MT; et <= CHET_DT; et++) {
988 if ((softc->sc_firsts[et] <= eaddr)
989 && ((softc->sc_firsts[et] + softc->sc_counts[et])
991 ces->ces_addr = eaddr - softc->sc_firsts[et];
997 ces->ces_flags = desc->flags1;
999 ces->ces_sensecode = desc->sense_code;
1000 ces->ces_sensequal = desc->sense_qual;
1002 if (desc->flags2 & READ_ELEMENT_STATUS_INVERT)
1003 ces->ces_flags |= CES_INVERT;
1005 if (desc->flags2 & READ_ELEMENT_STATUS_SVALID) {
1007 eaddr = scsi_2btoul(desc->ssea);
1009 /* convert source address to logical format */
1010 for (et = CHET_MT; et <= CHET_DT; et++) {
1011 if ((softc->sc_firsts[et] <= eaddr)
1012 && ((softc->sc_firsts[et] + softc->sc_counts[et])
1014 ces->ces_source_addr =
1015 eaddr - softc->sc_firsts[et];
1016 ces->ces_source_type = et;
1017 ces->ces_flags |= CES_SOURCE_VALID;
1022 if (!(ces->ces_flags & CES_SOURCE_VALID))
1023 kprintf("ch: warning: could not map element source "
1024 "address %ud to a valid element type\n",
1029 if (flags & READ_ELEMENT_STATUS_PVOLTAG)
1030 copy_voltag(&(ces->ces_pvoltag), &(desc->pvoltag));
1031 if (flags & READ_ELEMENT_STATUS_AVOLTAG)
1032 copy_voltag(&(ces->ces_avoltag), &(desc->avoltag));
1034 if (desc->dt_scsi_flags & READ_ELEMENT_STATUS_DT_IDVALID) {
1035 ces->ces_flags |= CES_SCSIID_VALID;
1036 ces->ces_scsi_id = desc->dt_scsi_addr;
1039 if (desc->dt_scsi_addr & READ_ELEMENT_STATUS_DT_LUVALID) {
1040 ces->ces_flags |= CES_LUN_VALID;
1042 desc->dt_scsi_flags & READ_ELEMENT_STATUS_DT_LUNMASK;
1047 chgetelemstatus(struct cam_periph *periph,
1048 struct changer_element_status_request *cesr)
1050 struct read_element_status_header *st_hdr;
1051 struct read_element_status_page_header *pg_hdr;
1052 struct read_element_status_descriptor *desc;
1053 caddr_t data = NULL;
1054 size_t size, desclen;
1055 int avail, i, error = 0;
1056 struct changer_element_status *user_data = NULL;
1057 struct ch_softc *softc;
1059 int chet = cesr->cesr_element_type;
1060 int want_voltags = (cesr->cesr_flags & CESR_VOLTAGS) ? 1 : 0;
1062 softc = (struct ch_softc *)periph->softc;
1064 /* perform argument checking */
1067 * Perform a range check on the cesr_element_{base,count}
1068 * request argument fields.
1070 if ((softc->sc_counts[chet] - cesr->cesr_element_base) <= 0
1071 || (cesr->cesr_element_base + cesr->cesr_element_count)
1072 > softc->sc_counts[chet])
1076 * Request one descriptor for the given element type. This
1077 * is used to determine the size of the descriptor so that
1078 * we can allocate enough storage for all of them. We assume
1079 * that the first one can fit into 1k.
1081 cam_periph_unlock(periph);
1082 data = (caddr_t)kmalloc(1024, M_DEVBUF, M_INTWAIT);
1084 cam_periph_lock(periph);
1085 ccb = cam_periph_getccb(periph, /*priority*/ 1);
1086 ccb->ccb_h.ccb_state = CH_CCB_POLLED;
1088 scsi_read_element_status(&ccb->csio,
1090 /* cbfcnp */ chdone,
1091 /* tag_action */ MSG_SIMPLE_Q_TAG,
1092 /* voltag */ want_voltags,
1093 /* sea */ softc->sc_firsts[chet],
1095 /* data_ptr */ data,
1096 /* dxfer_len */ 1024,
1097 /* sense_len */ SSD_FULL_SIZE,
1098 /* timeout */ CH_TIMEOUT_READ_ELEMENT_STATUS);
1100 error = cam_periph_runccb(ccb, cherror, /*cam_flags*/ CAM_RETRY_SELTO,
1101 /*sense_flags*/ SF_RETRY_UA,
1102 &softc->device_stats);
1106 cam_periph_unlock(periph);
1108 st_hdr = (struct read_element_status_header *)data;
1109 pg_hdr = (struct read_element_status_page_header *)((uintptr_t)st_hdr +
1110 sizeof(struct read_element_status_header));
1111 desclen = scsi_2btoul(pg_hdr->edl);
1113 size = sizeof(struct read_element_status_header) +
1114 sizeof(struct read_element_status_page_header) +
1115 (desclen * cesr->cesr_element_count);
1118 * Reallocate storage for descriptors and get them from the
1121 kfree(data, M_DEVBUF);
1122 data = (caddr_t)kmalloc(size, M_DEVBUF, M_INTWAIT);
1124 cam_periph_lock(periph);
1125 scsi_read_element_status(&ccb->csio,
1127 /* cbfcnp */ chdone,
1128 /* tag_action */ MSG_SIMPLE_Q_TAG,
1129 /* voltag */ want_voltags,
1130 /* sea */ softc->sc_firsts[chet]
1131 + cesr->cesr_element_base,
1132 /* count */ cesr->cesr_element_count,
1133 /* data_ptr */ data,
1134 /* dxfer_len */ size,
1135 /* sense_len */ SSD_FULL_SIZE,
1136 /* timeout */ CH_TIMEOUT_READ_ELEMENT_STATUS);
1138 error = cam_periph_runccb(ccb, cherror, /*cam_flags*/ CAM_RETRY_SELTO,
1139 /*sense_flags*/ SF_RETRY_UA,
1140 &softc->device_stats);
1144 cam_periph_unlock(periph);
1147 * Fill in the user status array.
1149 st_hdr = (struct read_element_status_header *)data;
1150 pg_hdr = (struct read_element_status_page_header *)((uintptr_t)st_hdr +
1151 sizeof(struct read_element_status_header));
1152 avail = scsi_2btoul(st_hdr->count);
1154 if (avail != cesr->cesr_element_count) {
1155 xpt_print(periph->path,
1156 "warning, READ ELEMENT STATUS avail != count\n");
1159 user_data = (struct changer_element_status *)
1160 kmalloc(avail * sizeof(struct changer_element_status),
1161 M_DEVBUF, M_INTWAIT | M_ZERO);
1163 desc = (struct read_element_status_descriptor *)((uintptr_t)data +
1164 sizeof(struct read_element_status_header) +
1165 sizeof(struct read_element_status_page_header));
1167 * Set up the individual element status structures
1169 for (i = 0; i < avail; ++i) {
1170 struct changer_element_status *ces = &(user_data[i]);
1172 copy_element_status(softc, pg_hdr->flags, desc, ces);
1174 desc = (struct read_element_status_descriptor *)
1175 ((uintptr_t)desc + desclen);
1178 /* Copy element status structures out to userspace. */
1179 error = copyout(user_data,
1180 cesr->cesr_element_status,
1181 avail * sizeof(struct changer_element_status));
1182 cam_periph_lock(periph);
1185 xpt_release_ccb(ccb);
1188 kfree(data, M_DEVBUF);
1189 if (user_data != NULL)
1190 kfree(user_data, M_DEVBUF);
1196 chielem(struct cam_periph *periph,
1197 unsigned int timeout)
1200 struct ch_softc *softc;
1204 timeout = CH_TIMEOUT_INITIALIZE_ELEMENT_STATUS;
1210 softc = (struct ch_softc *)periph->softc;
1212 ccb = cam_periph_getccb(periph, /*priority*/ 1);
1213 ccb->ccb_h.ccb_state = CH_CCB_POLLED;
1215 scsi_initialize_element_status(&ccb->csio,
1217 /* cbfcnp */ chdone,
1218 /* tag_action */ MSG_SIMPLE_Q_TAG,
1219 /* sense_len */ SSD_FULL_SIZE,
1220 /* timeout */ timeout);
1222 error = cam_periph_runccb(ccb, cherror, /*cam_flags*/ CAM_RETRY_SELTO,
1223 /*sense_flags*/ SF_RETRY_UA,
1224 &softc->device_stats);
1226 xpt_release_ccb(ccb);
1232 chsetvoltag(struct cam_periph *periph,
1233 struct changer_set_voltag_request *csvr)
1236 struct ch_softc *softc;
1239 struct scsi_send_volume_tag_parameters ssvtp;
1244 softc = (struct ch_softc *)periph->softc;
1246 bzero(&ssvtp, sizeof(ssvtp));
1247 for (i=0; i<sizeof(ssvtp.vitf); i++) {
1248 ssvtp.vitf[i] = ' ';
1254 if (csvr->csvr_type > CHET_DT)
1256 if (csvr->csvr_addr > (softc->sc_counts[csvr->csvr_type] - 1))
1259 ea = softc->sc_firsts[csvr->csvr_type] + csvr->csvr_addr;
1261 if (csvr->csvr_flags & CSVR_ALTERNATE) {
1262 switch (csvr->csvr_flags & CSVR_MODE_MASK) {
1264 sac = SEND_VOLUME_TAG_ASSERT_ALTERNATE;
1266 case CSVR_MODE_REPLACE:
1267 sac = SEND_VOLUME_TAG_REPLACE_ALTERNATE;
1269 case CSVR_MODE_CLEAR:
1270 sac = SEND_VOLUME_TAG_UNDEFINED_ALTERNATE;
1277 switch (csvr->csvr_flags & CSVR_MODE_MASK) {
1279 sac = SEND_VOLUME_TAG_ASSERT_PRIMARY;
1281 case CSVR_MODE_REPLACE:
1282 sac = SEND_VOLUME_TAG_REPLACE_PRIMARY;
1284 case CSVR_MODE_CLEAR:
1285 sac = SEND_VOLUME_TAG_UNDEFINED_PRIMARY;
1293 memcpy(ssvtp.vitf, csvr->csvr_voltag.cv_volid,
1294 min(strlen(csvr->csvr_voltag.cv_volid), sizeof(ssvtp.vitf)));
1295 scsi_ulto2b(csvr->csvr_voltag.cv_serial, ssvtp.minvsn);
1297 ccb = cam_periph_getccb(periph, /*priority*/ 1);
1298 ccb->ccb_h.ccb_state = CH_CCB_POLLED;
1300 scsi_send_volume_tag(&ccb->csio,
1302 /* cbfcnp */ chdone,
1303 /* tag_action */ MSG_SIMPLE_Q_TAG,
1304 /* element_address */ ea,
1305 /* send_action_code */ sac,
1306 /* parameters */ &ssvtp,
1307 /* sense_len */ SSD_FULL_SIZE,
1308 /* timeout */ CH_TIMEOUT_SEND_VOLTAG);
1310 error = cam_periph_runccb(ccb, cherror, /*cam_flags*/ CAM_RETRY_SELTO,
1311 /*sense_flags*/ SF_RETRY_UA,
1312 &softc->device_stats);
1314 xpt_release_ccb(ccb);
1321 chgetparams(struct cam_periph *periph)
1324 struct ch_softc *softc;
1326 int mode_buffer_len;
1327 struct page_element_address_assignment *ea;
1328 struct page_device_capabilities *cap;
1329 int error, from, dbd;
1330 u_int8_t *moves, *exchanges;
1334 softc = (struct ch_softc *)periph->softc;
1336 ccb = cam_periph_getccb(periph, /*priority*/ 1);
1337 ccb->ccb_h.ccb_state = CH_CCB_POLLED;
1340 * The scsi_mode_sense_data structure is just a convenience
1341 * structure that allows us to easily calculate the worst-case
1342 * storage size of the mode sense buffer.
1344 mode_buffer_len = sizeof(struct scsi_mode_sense_data);
1346 mode_buffer = kmalloc(mode_buffer_len, M_SCSICH, M_INTWAIT | M_ZERO);
1348 if (softc->quirks & CH_Q_NO_DBD)
1354 * Get the element address assignment page.
1356 scsi_mode_sense(&ccb->csio,
1358 /* cbfcnp */ chdone,
1359 /* tag_action */ MSG_SIMPLE_Q_TAG,
1361 /* page_code */ SMS_PAGE_CTRL_CURRENT,
1362 /* page */ CH_ELEMENT_ADDR_ASSIGN_PAGE,
1363 /* param_buf */ (u_int8_t *)mode_buffer,
1364 /* param_len */ mode_buffer_len,
1365 /* sense_len */ SSD_FULL_SIZE,
1366 /* timeout */ CH_TIMEOUT_MODE_SENSE);
1368 error = cam_periph_runccb(ccb, cherror, /*cam_flags*/ CAM_RETRY_SELTO,
1369 /* sense_flags */ SF_RETRY_UA|SF_NO_PRINT,
1370 &softc->device_stats);
1374 struct scsi_mode_sense_6 *sms;
1376 sms = (struct scsi_mode_sense_6 *)
1377 ccb->csio.cdb_io.cdb_bytes;
1379 sms->byte2 &= ~SMS_DBD;
1380 error = cam_periph_runccb(ccb, cherror,
1381 /*cam_flags*/ CAM_RETRY_SELTO,
1382 /*sense_flags*/ SF_RETRY_UA,
1383 &softc->device_stats);
1386 * Since we disabled sense printing above, print
1387 * out the sense here since we got an error.
1389 scsi_sense_print(&ccb->csio);
1393 xpt_print(periph->path,
1394 "chgetparams: error getting element "
1396 xpt_release_ccb(ccb);
1397 kfree(mode_buffer, M_SCSICH);
1402 ea = (struct page_element_address_assignment *)
1403 find_mode_page_6((struct scsi_mode_header_6 *)mode_buffer);
1405 softc->sc_firsts[CHET_MT] = scsi_2btoul(ea->mtea);
1406 softc->sc_counts[CHET_MT] = scsi_2btoul(ea->nmte);
1407 softc->sc_firsts[CHET_ST] = scsi_2btoul(ea->fsea);
1408 softc->sc_counts[CHET_ST] = scsi_2btoul(ea->nse);
1409 softc->sc_firsts[CHET_IE] = scsi_2btoul(ea->fieea);
1410 softc->sc_counts[CHET_IE] = scsi_2btoul(ea->niee);
1411 softc->sc_firsts[CHET_DT] = scsi_2btoul(ea->fdtea);
1412 softc->sc_counts[CHET_DT] = scsi_2btoul(ea->ndte);
1414 bzero(mode_buffer, mode_buffer_len);
1417 * Now get the device capabilities page.
1419 scsi_mode_sense(&ccb->csio,
1421 /* cbfcnp */ chdone,
1422 /* tag_action */ MSG_SIMPLE_Q_TAG,
1424 /* page_code */ SMS_PAGE_CTRL_CURRENT,
1425 /* page */ CH_DEVICE_CAP_PAGE,
1426 /* param_buf */ (u_int8_t *)mode_buffer,
1427 /* param_len */ mode_buffer_len,
1428 /* sense_len */ SSD_FULL_SIZE,
1429 /* timeout */ CH_TIMEOUT_MODE_SENSE);
1431 error = cam_periph_runccb(ccb, cherror, /*cam_flags*/ CAM_RETRY_SELTO,
1432 /* sense_flags */ SF_RETRY_UA | SF_NO_PRINT,
1433 &softc->device_stats);
1437 struct scsi_mode_sense_6 *sms;
1439 sms = (struct scsi_mode_sense_6 *)
1440 ccb->csio.cdb_io.cdb_bytes;
1442 sms->byte2 &= ~SMS_DBD;
1443 error = cam_periph_runccb(ccb, cherror,
1444 /*cam_flags*/ CAM_RETRY_SELTO,
1445 /*sense_flags*/ SF_RETRY_UA,
1446 &softc->device_stats);
1449 * Since we disabled sense printing above, print
1450 * out the sense here since we got an error.
1452 scsi_sense_print(&ccb->csio);
1456 xpt_print(periph->path,
1457 "chgetparams: error getting device "
1458 "capabilities page\n");
1459 xpt_release_ccb(ccb);
1460 kfree(mode_buffer, M_SCSICH);
1465 xpt_release_ccb(ccb);
1467 cap = (struct page_device_capabilities *)
1468 find_mode_page_6((struct scsi_mode_header_6 *)mode_buffer);
1470 bzero(softc->sc_movemask, sizeof(softc->sc_movemask));
1471 bzero(softc->sc_exchangemask, sizeof(softc->sc_exchangemask));
1472 moves = cap->move_from;
1473 exchanges = cap->exchange_with;
1474 for (from = CHET_MT; from <= CHET_MAX; ++from) {
1475 softc->sc_movemask[from] = moves[from];
1476 softc->sc_exchangemask[from] = exchanges[from];
1479 kfree(mode_buffer, M_SCSICH);
1485 scsi_move_medium(struct ccb_scsiio *csio, u_int32_t retries,
1486 void (*cbfcnp)(struct cam_periph *, union ccb *),
1487 u_int8_t tag_action, u_int32_t tea, u_int32_t src,
1488 u_int32_t dst, int invert, u_int8_t sense_len,
1491 struct scsi_move_medium *scsi_cmd;
1493 scsi_cmd = (struct scsi_move_medium *)&csio->cdb_io.cdb_bytes;
1494 bzero(scsi_cmd, sizeof(*scsi_cmd));
1496 scsi_cmd->opcode = MOVE_MEDIUM;
1498 scsi_ulto2b(tea, scsi_cmd->tea);
1499 scsi_ulto2b(src, scsi_cmd->src);
1500 scsi_ulto2b(dst, scsi_cmd->dst);
1503 scsi_cmd->invert |= MOVE_MEDIUM_INVERT;
1508 /*flags*/ CAM_DIR_NONE,
1518 scsi_exchange_medium(struct ccb_scsiio *csio, u_int32_t retries,
1519 void (*cbfcnp)(struct cam_periph *, union ccb *),
1520 u_int8_t tag_action, u_int32_t tea, u_int32_t src,
1521 u_int32_t dst1, u_int32_t dst2, int invert1,
1522 int invert2, u_int8_t sense_len, u_int32_t timeout)
1524 struct scsi_exchange_medium *scsi_cmd;
1526 scsi_cmd = (struct scsi_exchange_medium *)&csio->cdb_io.cdb_bytes;
1527 bzero(scsi_cmd, sizeof(*scsi_cmd));
1529 scsi_cmd->opcode = EXCHANGE_MEDIUM;
1531 scsi_ulto2b(tea, scsi_cmd->tea);
1532 scsi_ulto2b(src, scsi_cmd->src);
1533 scsi_ulto2b(dst1, scsi_cmd->fdst);
1534 scsi_ulto2b(dst2, scsi_cmd->sdst);
1537 scsi_cmd->invert |= EXCHANGE_MEDIUM_INV1;
1540 scsi_cmd->invert |= EXCHANGE_MEDIUM_INV2;
1545 /*flags*/ CAM_DIR_NONE,
1555 scsi_position_to_element(struct ccb_scsiio *csio, u_int32_t retries,
1556 void (*cbfcnp)(struct cam_periph *, union ccb *),
1557 u_int8_t tag_action, u_int32_t tea, u_int32_t dst,
1558 int invert, u_int8_t sense_len, u_int32_t timeout)
1560 struct scsi_position_to_element *scsi_cmd;
1562 scsi_cmd = (struct scsi_position_to_element *)&csio->cdb_io.cdb_bytes;
1563 bzero(scsi_cmd, sizeof(*scsi_cmd));
1565 scsi_cmd->opcode = POSITION_TO_ELEMENT;
1567 scsi_ulto2b(tea, scsi_cmd->tea);
1568 scsi_ulto2b(dst, scsi_cmd->dst);
1571 scsi_cmd->invert |= POSITION_TO_ELEMENT_INVERT;
1576 /*flags*/ CAM_DIR_NONE,
1586 scsi_read_element_status(struct ccb_scsiio *csio, u_int32_t retries,
1587 void (*cbfcnp)(struct cam_periph *, union ccb *),
1588 u_int8_t tag_action, int voltag, u_int32_t sea,
1589 u_int32_t count, u_int8_t *data_ptr,
1590 u_int32_t dxfer_len, u_int8_t sense_len,
1593 struct scsi_read_element_status *scsi_cmd;
1595 scsi_cmd = (struct scsi_read_element_status *)&csio->cdb_io.cdb_bytes;
1596 bzero(scsi_cmd, sizeof(*scsi_cmd));
1598 scsi_cmd->opcode = READ_ELEMENT_STATUS;
1600 scsi_ulto2b(sea, scsi_cmd->sea);
1601 scsi_ulto2b(count, scsi_cmd->count);
1602 scsi_ulto3b(dxfer_len, scsi_cmd->len);
1605 scsi_cmd->byte2 |= READ_ELEMENT_STATUS_VOLTAG;
1610 /*flags*/ CAM_DIR_IN,
1620 scsi_initialize_element_status(struct ccb_scsiio *csio, u_int32_t retries,
1621 void (*cbfcnp)(struct cam_periph *, union ccb *),
1622 u_int8_t tag_action, u_int8_t sense_len,
1625 struct scsi_initialize_element_status *scsi_cmd;
1627 scsi_cmd = (struct scsi_initialize_element_status *)
1628 &csio->cdb_io.cdb_bytes;
1629 bzero(scsi_cmd, sizeof(*scsi_cmd));
1631 scsi_cmd->opcode = INITIALIZE_ELEMENT_STATUS;
1636 /*flags*/ CAM_DIR_NONE,
1638 /* data_ptr */ NULL,
1646 scsi_send_volume_tag(struct ccb_scsiio *csio, u_int32_t retries,
1647 void (*cbfcnp)(struct cam_periph *, union ccb *),
1648 u_int8_t tag_action,
1649 u_int16_t element_address,
1650 u_int8_t send_action_code,
1651 struct scsi_send_volume_tag_parameters *parameters,
1652 u_int8_t sense_len, u_int32_t timeout)
1654 struct scsi_send_volume_tag *scsi_cmd;
1656 scsi_cmd = (struct scsi_send_volume_tag *) &csio->cdb_io.cdb_bytes;
1657 bzero(scsi_cmd, sizeof(*scsi_cmd));
1659 scsi_cmd->opcode = SEND_VOLUME_TAG;
1660 scsi_ulto2b(element_address, scsi_cmd->ea);
1661 scsi_cmd->sac = send_action_code;
1662 scsi_ulto2b(sizeof(*parameters), scsi_cmd->pll);
1667 /*flags*/ CAM_DIR_OUT,
1669 /* data_ptr */ (u_int8_t *) parameters,
1670 sizeof(*parameters),