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