Home | History | Annotate | Line # | Download | only in scsipi
scsi_changer.h revision 1.13
      1 /*	$NetBSD: scsi_changer.h,v 1.13 1999/07/22 17:43:53 thorpej Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1996, 1999 Jason R. Thorpe <thorpej (at) and.com>
      5  * All rights reserved.
      6  *
      7  * Partially based on an autochanger driver written by Stefan Grefen
      8  * and on an autochanger driver written by the Systems Programming Group
      9  * at the University of Utah Computer Science Department.
     10  *
     11  * Redistribution and use in source and binary forms, with or without
     12  * modification, are permitted provided that the following conditions
     13  * are met:
     14  * 1. Redistributions of source code must retain the above copyright
     15  *    notice, this list of conditions and the following disclaimer.
     16  * 2. Redistributions in binary form must reproduce the above copyright
     17  *    notice, this list of conditions and the following disclaimer in the
     18  *    documentation and/or other materials provided with the distribution.
     19  * 3. All advertising materials mentioning features or use of this software
     20  *    must display the following acknowledgements:
     21  *	This product includes software developed by Jason R. Thorpe
     22  *	for And Communications, http://www.and.com/
     23  * 4. The name of the author may not be used to endorse or promote products
     24  *    derived from this software without specific prior written permission.
     25  *
     26  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     27  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     28  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     29  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     30  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
     31  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
     32  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
     33  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
     34  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     35  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     36  * SUCH DAMAGE.
     37  */
     38 
     39 /*
     40  * SCSI changer interface description
     41  */
     42 
     43 /*
     44  * Partially derived from software written by Stefan Grefen
     45  * (grefen (at) goofy.zdv.uni-mainz.de soon grefen (at) convex.com)
     46  * based on the SCSI System by written Julian Elischer (julian (at) tfs.com)
     47  * for TRW Financial Systems.
     48  *
     49  * TRW Financial Systems, in accordance with their agreement with Carnegie
     50  * Mellon University, makes this software available to CMU to distribute
     51  * or use in any manner that they see fit as long as this message is kept with
     52  * the software. For this reason TFS also grants any other persons or
     53  * organisations permission to use or modify this software.
     54  *
     55  * TFS supplies this software to be publicly redistributed
     56  * on the understanding that TFS is not responsible for the correct
     57  * functioning of this software in any circumstances.
     58  *
     59  * Ported to run under 386BSD by Julian Elischer (julian (at) tfs.com) Sept 1992
     60  */
     61 
     62 /*
     63  * SCSI command format
     64  */
     65 
     66 /*
     67  * Exchange the medium in the source element with the medium
     68  * located at the destination element.
     69  */
     70 struct scsi_exchange_medium {
     71 	u_int8_t	opcode;
     72 #define EXCHANGE_MEDIUM		0xa6
     73 	u_int8_t	byte2;
     74 	u_int8_t	tea[2];	/* transport element address */
     75 	u_int8_t	src[2];	/* source address */
     76 	u_int8_t	fdst[2]; /* first destination address */
     77 	u_int8_t	sdst[2]; /* second destination address */
     78 	u_int8_t	flags;
     79 #define EXCHANGE_MEDIUM_INV1	0x01
     80 #define EXCHANGE_MEDIUM_INV2	0x02
     81 	u_int8_t	control;
     82 };
     83 
     84 /*
     85  * Cause the medium changer to check all elements for medium and any
     86  * other status relevant to the element.
     87  */
     88 struct scsi_initialize_element_status {
     89 	u_int8_t	opcode;
     90 #define INITIALIZE_ELEMENT_STATUS	0x07
     91 	u_int8_t	byte2;
     92 	u_int8_t	reserved[3];
     93 	u_int8_t	control;
     94 };
     95 
     96 /*
     97  * Request the changer to move a unit of media from the source element
     98  * to the destination element.
     99  */
    100 struct scsi_move_medium {
    101 	u_int8_t	opcode;
    102 #define MOVE_MEDIUM	0xa5
    103 	u_int8_t	byte2;
    104 	u_int8_t	tea[2];	/* transport element address */
    105 	u_int8_t	src[2];	/* source element address */
    106 	u_int8_t	dst[2];	/* destination element address */
    107 	u_int8_t	reserved[2];
    108 	u_int8_t	flags;
    109 #define MOVE_MEDIUM_INVERT	0x01
    110 	u_int8_t	control;
    111 };
    112 
    113 /*
    114  * Position the specified transport element (picker) in front of
    115  * the destination element specified.
    116  */
    117 struct scsi_position_to_element {
    118 	u_int8_t	opcode;
    119 #define POSITION_TO_ELEMENT	0x2b
    120 	u_int8_t	byte2;
    121 	u_int8_t	tea[2];	/* transport element address */
    122 	u_int8_t	dst[2];	/* destination element address */
    123 	u_int8_t	reserved[2];
    124 	u_int8_t	flags;
    125 #define POSITION_TO_ELEMENT_INVERT	0x01
    126 	u_int8_t	control;
    127 };
    128 
    129 /*
    130  * Request that the changer report the status of its internal elements.
    131  */
    132 struct scsi_read_element_status {
    133 	u_int8_t	opcode;
    134 #define READ_ELEMENT_STATUS	0xb8
    135 	u_int8_t	byte2;
    136 #define READ_ELEMENT_STATUS_VOLTAG	0x10	/* report volume tag info */
    137 	/* ...next 4 bits are an element type code... */
    138 	u_int8_t	sea[2];	/* starting element address */
    139 	u_int8_t	count[2]; /* number of elements */
    140 	u_int8_t	reserved0;
    141 	u_int8_t	len[3];	/* length of data buffer */
    142 	u_int8_t	reserved1;
    143 	u_int8_t	control;
    144 };
    145 
    146 struct scsi_request_volume_element_address {
    147 	u_int8_t	opcode;
    148 #define REQUEST_VOLUME_ELEMENT_ADDRESS	0xb5
    149 	u_int8_t	byte2;
    150 #define REQUEST_VOLUME_ELEMENT_ADDRESS_VOLTAG	0x10
    151 	/* ...next 4 bits are an element type code... */
    152 	u_int8_t	eaddr[2];	/* element address */
    153 	u_int8_t	count[2];	/* number of elements */
    154 	u_int8_t	reserved0;
    155 	u_int8_t	len[3];		/* length of data buffer */
    156 	u_int8_t	reserved1;
    157 	u_int8_t	control;
    158 };
    159 
    160 /* XXX scsi_release */
    161 
    162 /*
    163  * Data returned by READ ELEMENT STATUS consists of an 8-byte header
    164  * followed by one or more read_element_status_pages.
    165  */
    166 struct read_element_status_header {
    167 	u_int8_t	fear[2];  /* first element address reported */
    168 	u_int8_t	count[2]; /* number of elements available */
    169 	u_int8_t	reserved;
    170 	u_int8_t	nbytes[3]; /* byte count of all pages */
    171 };
    172 
    173 struct read_element_status_page_header {
    174 	u_int8_t	type;	/* element type code; see type codes below */
    175 	u_int8_t	flags;
    176 #define READ_ELEMENT_STATUS_AVOLTAG	0x40
    177 #define READ_ELEMENT_STATUS_PVOLTAG	0x80
    178 	u_int8_t	edl[2];	/* element descriptor length */
    179 	u_int8_t	reserved;
    180 	u_int8_t	nbytes[3]; /* byte count of all descriptors */
    181 };
    182 
    183 struct read_element_status_descriptor {
    184 	u_int8_t	eaddr[2];	/* element address */
    185 	u_int8_t	flags1;
    186 
    187 #define READ_ELEMENT_STATUS_FULL	0x01
    188 #define READ_ELEMENT_STATUS_IMPEXP	0x02
    189 #define READ_ELEMENT_STATUS_EXCEPT	0x04
    190 #define READ_ELEMENT_STATUS_ACCESS	0x08
    191 #define READ_ELEMENT_STATUS_EXENAB	0x10
    192 #define READ_ELEMENT_STATUS_INENAB	0x20
    193 
    194 #define READ_ELEMENT_STATUS_MT_MASK1	0x05
    195 #define READ_ELEMENT_STATUS_ST_MASK1	0x0c
    196 #define READ_ELEMENT_STATUS_IE_MASK1	0x3f
    197 #define READ_ELEMENT_STATUS_DT_MASK1	0x0c
    198 
    199 	u_int8_t	reserved0;
    200 	u_int8_t	sense_code;
    201 	u_int8_t	sense_qual;
    202 
    203 	/*
    204 	 * dt_scsi_flags and dt_scsi_addr are valid only on data transport
    205 	 * elements.  These bytes are undefined for all other element types.
    206 	 */
    207 	u_int8_t	dt_scsi_flags;
    208 
    209 #define READ_ELEMENT_STATUS_DT_LUNMASK	0x07
    210 #define READ_ELEMENT_STATUS_DT_LUVALID	0x10
    211 #define READ_ELEMENT_STATUS_DT_IDVALID	0x20
    212 #define READ_ELEMENT_STATUS_DT_NOTBUS	0x80
    213 
    214 	u_int8_t	dt_scsi_addr;
    215 
    216 	u_int8_t	reserved1;
    217 
    218 	u_int8_t	flags2;
    219 #define READ_ELEMENT_STATUS_INVERT	0x40
    220 #define READ_ELEMENT_STATUS_SVALID	0x80
    221 	u_int8_t	ssea[2];	/* source storage element address */
    222 
    223 	/*
    224 	 * bytes 12-47:	Primary volume tag information.
    225 	 *		(field omitted if PVOLTAG = 0)
    226 	 *
    227 	 * bytes 48-83:	Alternate volume tag information.
    228 	 *		(field omitted if AVOLTAG = 0)
    229 	 *
    230 	 * bytes 84-87:	Reserved (moved up if either of the above fields
    231 	 *		are omitted)
    232 	 *
    233 	 * bytes 88-end: Vendor-specific: (moved up if either of the
    234 	 *		 above fields are missing)
    235 	 */
    236 };
    237 
    238 /*
    239  * Volume Tag format:
    240  *
    241  * Volume Tags are a sequence of ASCII characters, unused portion is
    242  * blank-filled.  There should be no blanks in the significant portion
    243  * of the tag.  For maximum compatibility, volume tag characters should
    244  * be limited to '0'..'9', 'A'..'Z', '_'.
    245  */
    246 struct changer_volume_tag {
    247 	u_int8_t volid[32];	/* 32 bytes of ASCII, blank-terminated */
    248 	u_int8_t reserved[2];
    249 	u_int8_t volseq[2];	/* volume sequence number */
    250 };
    251 
    252 /* Element type codes */
    253 #define ELEMENT_TYPE_MASK	0x0f	/* Note: these aren't bits */
    254 #define ELEMENT_TYPE_ALL	0x00
    255 #define ELEMENT_TYPE_MT		0x01
    256 #define ELEMENT_TYPE_ST		0x02
    257 #define ELEMENT_TYPE_IE		0x03
    258 #define ELEMENT_TYPE_DT		0x04
    259 
    260 /*
    261  * XXX The following definitions should be common to all SCSI device types.
    262  */
    263 #define PGCODE_MASK	0x3f	/* valid page number bits in pg_code */
    264 #define PGCODE_PS	0x80	/* indicates page is savable */
    265 
    266 /*
    267  * Device capabilities page.
    268  *
    269  * This page defines characteristics of the elemenet types in the
    270  * medium changer device.
    271  *
    272  * Note in the definitions below, the following abbreviations are
    273  * used:
    274  *		MT	Medium transport element (picker)
    275  *		ST	Storage transport element (slot)
    276  *		IE	Import/export element (portal)
    277  *		DT	Data tranfer element (tape/disk drive)
    278  */
    279 struct page_device_capabilities {
    280 	u_int8_t	pg_code;	/* page code (0x1f) */
    281 	u_int8_t	pg_length;	/* page length (0x12) */
    282 
    283 	/*
    284 	 * The STOR_xx bits indicate that an element of a given
    285 	 * type may provide independent storage for a unit of
    286 	 * media.  The top four bits of this value are reserved.
    287 	 */
    288 	u_int8_t	stor;
    289 #define STOR_MT		0x01
    290 #define STOR_ST		0x02
    291 #define STOR_IE		0x04
    292 #define STOR_DT		0x08
    293 
    294 	u_int8_t	reserved0;
    295 
    296 	/*
    297 	 * The MOVE_TO_yy bits indicate the changer supports
    298 	 * moving a unit of medium from an element of a given type to an
    299 	 * element of type yy.  This is used to determine if a given
    300 	 * MOVE MEDIUM command is legal.  The top four bits of each
    301 	 * of these values are reserved.
    302 	 */
    303 	u_int8_t	move_from_mt;
    304 	u_int8_t	move_from_st;
    305 	u_int8_t	move_from_ie;
    306 	u_int8_t	move_from_dt;
    307 #define MOVE_TO_MT	0x01
    308 #define MOVE_TO_ST	0x02
    309 #define MOVE_TO_IE	0x04
    310 #define MOVE_TO_DT	0x08
    311 
    312 	u_int8_t	reserved1[4];
    313 
    314 	/*
    315 	 * Similar to above, but for EXCHANGE MEDIUM.
    316 	 */
    317 	u_int8_t	exchange_with_mt;
    318 	u_int8_t	exchange_with_st;
    319 	u_int8_t	exchange_with_ie;
    320 	u_int8_t	exchange_with_dt;
    321 #define EXCHANGE_WITH_MT	0x01
    322 #define EXCHANGE_WITH_ST	0x02
    323 #define EXCHANGE_WITH_IE	0x04
    324 #define EXCHANGE_WITH_DT	0x08
    325 };
    326 
    327 /*
    328  * Medium changer elemement address assignment page.
    329  *
    330  * Some of these fields can be a little confusing, so an explanation
    331  * is in order.
    332  *
    333  * Each component within a a medium changer apparatus is called an
    334  * "element".
    335  *
    336  * The "medium transport element address" is the address of the first
    337  * picker (robotic arm).  "Number of medium transport elements" tells
    338  * us how many pickers exist in the changer.
    339  *
    340  * The "first storage element address" is the address of the first
    341  * slot in the tape or disk magazine.  "Number of storage elements" tells
    342  * us how many slots exist in the changer.
    343  *
    344  * The "first import/export element address" is the address of the first
    345  * medium portal accessible both by the medium changer and an outside
    346  * human operator.  This is where the changer might deposit tapes destined
    347  * for some vault.  The "number of import/export elements" tells us
    348  * not many of these portals exist in the changer.  NOTE: this number may
    349  * be 0.
    350  *
    351  * The "first data transfer element address" is the address of the first
    352  * tape or disk drive in the changer.  "Number of data transfer elements"
    353  * tells us how many drives exist in the changer.
    354  */
    355 struct page_element_address_assignment {
    356 	u_int8_t	pg_code;	/* page code (0x1d) */
    357 	u_int8_t	pg_length;	/* page length (0x12) */
    358 
    359 	/* Medium transport element address */
    360 	u_int8_t	mtea[2];
    361 
    362 	/* Number of medium transport elements */
    363 	u_int8_t	nmte[2];
    364 
    365 	/* First storage element address */
    366 	u_int8_t	fsea[2];
    367 
    368 	/* Number of storage elements */
    369 	u_int8_t	nse[2];
    370 
    371 	/* First import/export element address */
    372 	u_int8_t	fieea[2];
    373 
    374 	/* Number of import/export elements */
    375 	u_int8_t	niee[2];
    376 
    377 	/* First data transfer element address */
    378 	u_int8_t	fdtea[2];
    379 
    380 	/* Number of data trafer elements */
    381 	u_int8_t	ndte[2];
    382 
    383 	u_int8_t	reserved[2];
    384 };
    385 
    386 /*
    387  * Transport geometry parameters page.
    388  *
    389  * Defines whether each medium transport element is a member of a set of
    390  * elements that share a common robotics subsystem and whether the element
    391  * is capable of media rotation.  One transport geometry descriptor is
    392  * transferred for each medium transport element, beginning with the first
    393  * medium transport element (other than the default transport element address
    394  * of 0).
    395  */
    396 struct page_transport_geometry_parameters {
    397 	u_int8_t	pg_code;	/* page code (0x1e) */
    398 	u_int8_t	pg_length;	/* page length; variable */
    399 
    400 	/* Transport geometry descriptor(s) are here. */
    401 
    402 	u_int8_t	misc;
    403 #define CAN_ROTATE	0x01
    404 
    405 	/* Member number in transport element set. */
    406 	u_int8_t	member;
    407 };
    408