chio.h revision 252214
117680Spst/*-
217680Spst * Copyright (c) 1996 Jason R. Thorpe <thorpej@and.com>
317680Spst * All rights reserved.
417680Spst *
517680Spst * Redistribution and use in source and binary forms, with or without
617680Spst * modification, are permitted provided that the following conditions
717680Spst * are met:
817680Spst * 1. Redistributions of source code must retain the above copyright
917680Spst *    notice, this list of conditions and the following disclaimer.
1017680Spst * 2. Redistributions in binary form must reproduce the above copyright
1117680Spst *    notice, this list of conditions and the following disclaimer in the
1217680Spst *    documentation and/or other materials provided with the distribution.
1317680Spst * 3. All advertising materials mentioning features or use of this software
1417680Spst *    must display the following acknowledgements:
1517680Spst *	This product includes software developed by Jason R. Thorpe
1617680Spst *	for And Communications, http://www.and.com/
1717680Spst * 4. The name of the author may not be used to endorse or promote products
1817680Spst *    derived from this software without specific prior written permission.
1917680Spst *
2017680Spst * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
2117680Spst * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
2217680Spst * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
2317680Spst * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
2417680Spst * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
2517680Spst * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
2617680Spst * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
2717680Spst * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
2817680Spst * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2917680Spst * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3017680Spst * SUCH DAMAGE.
3117680Spst *
3217680Spst * $FreeBSD: stable/9/sys/sys/chio.h 252214 2013-06-25 21:43:49Z ken $
3317680Spst */
3417680Spst
3517680Spst#ifndef	_SYS_CHIO_H_
3617680Spst#define	_SYS_CHIO_H_
3717680Spst
3817680Spst#ifndef _KERNEL
3917680Spst#include <sys/types.h>
4017680Spst#endif
4117680Spst#include <sys/ioccom.h>
4221262Swollman
4317680Spst/*
4417680Spst * Element types.  Used as "to" and "from" type indicators in move
4517680Spst * and exchange operations.
4617680Spst *
4717680Spst * Note that code in sys/scsi/ch.c relies on these values (uses them
4817680Spst * as offsets in an array, and other evil), so don't muck with them
4917680Spst * unless you know what you're doing.
5017680Spst */
5117680Spst#define CHET_MT		0	/* medium transport (picker) */
5217680Spst#define CHET_ST		1	/* storage transport (slot) */
5317680Spst#define CHET_IE		2	/* import/export (portal) */
5417680Spst#define CHET_DT		3	/* data transfer (drive) */
5517680Spst#define CHET_MAX	CHET_DT
5617680Spst
5717680Spst/*
5817680Spst * Maximum length of a volume identification string
5917680Spst */
6017680Spst#define CH_VOLTAG_MAXLEN	32
6117680Spst
6217680Spst/*
6317680Spst * Structure used to execute a MOVE MEDIUM command.
6417680Spst */
6517680Spststruct changer_move {
6617680Spst	u_int16_t	cm_fromtype;	/* element type to move from */
6717680Spst	u_int16_t	cm_fromunit;	/* logical unit of from element */
6817680Spst	u_int16_t	cm_totype;	/* element type to move to */
6917680Spst	u_int16_t	cm_tounit;	/* logical unit of to element */
7017680Spst	u_int16_t	cm_flags;	/* misc. flags */
7117680Spst};
7217680Spst
7317680Spst/* cm_flags */
7417680Spst#define CM_INVERT	0x01	/* invert media */
7517680Spst
7617680Spst/*
7717680Spst * Structure used to execute an EXCHANGE MEDIUM command.  In an
7817680Spst * exchange operation, the following steps occur:
7917680Spst *
8017680Spst *	- media from source is moved to first destination.
8117680Spst *
8217680Spst *	- media previously occupying first destination is moved
8317680Spst *	  to the second destination.
8417680Spst *
8517680Spst * The second destination may or may not be the same as the source.
8617680Spst * In the case of a simple exchange, the source and second destination
8717680Spst * are the same.
8817680Spst */
8917680Spststruct changer_exchange {
9017680Spst	u_int16_t	ce_srctype;	/* element type of source */
9117680Spst	u_int16_t	ce_srcunit;	/* logical unit of source */
9217680Spst	u_int16_t	ce_fdsttype;	/* element type of first destination */
9317680Spst	u_int16_t	ce_fdstunit;	/* logical unit of first destination */
9417680Spst	u_int16_t	ce_sdsttype;	/* element type of second destination */
9517680Spst	u_int16_t	ce_sdstunit;	/* logical unit of second destination */
9617680Spst	u_int16_t	ce_flags;	/* misc. flags */
9717680Spst};
9817680Spst
9917680Spst/* ce_flags */
10017680Spst#define CE_INVERT1	0x01	/* invert media 1 */
10117680Spst#define CE_INVERT2	0x02	/* invert media 2 */
10217680Spst
10317680Spst/*
10417680Spst * Structure used to execute a POSITION TO ELEMENT command.  This
10517680Spst * moves the current picker in front of the specified element.
10617680Spst */
10717680Spststruct changer_position {
10817680Spst	u_int16_t	cp_type;	/* element type */
10917680Spst	u_int16_t	cp_unit;	/* logical unit of element */
11017680Spst	u_int16_t	cp_flags;	/* misc. flags */
11117680Spst};
11217680Spst
11317680Spst/* cp_flags */
11417680Spst#define CP_INVERT	0x01	/* invert picker */
11517680Spst
116/*
117 * Data returned by CHIOGPARAMS.
118 */
119struct changer_params {
120	u_int16_t	cp_npickers;	/* number of pickers */
121	u_int16_t	cp_nslots;	/* number of slots */
122	u_int16_t	cp_nportals;	/* number of import/export portals */
123	u_int16_t	cp_ndrives;	/* number of drives */
124};
125
126/*
127 * Command used to get element status.
128 */
129
130struct changer_voltag {
131	u_char		cv_volid[CH_VOLTAG_MAXLEN+1];
132	u_int16_t	cv_serial;
133};
134
135typedef struct changer_voltag changer_voltag_t;
136
137/*
138 * Flags definitions for ces_status
139 * Not all flags have meaning for all element types.
140 */
141typedef enum {
142	CES_STATUS_FULL	  = 0x001,	/* element is full */
143	CES_STATUS_IMPEXP = 0x002,	/* media deposited by operator */
144	CES_STATUS_EXCEPT = 0x004,	/* element in abnormal state */
145	CES_PICKER_MASK	  = 0x005,	/* flags valid for pickers */
146	CES_STATUS_ACCESS = 0x008,	/* media accessible by picker */
147	CES_SLOT_MASK	  = 0x00c,	/* flags valid for slots */
148	CES_DRIVE_MASK	  = 0x00c,	/* flags valid for drives */
149	CES_STATUS_EXENAB = 0x010,	/* element supports exporting */
150	CES_STATUS_INENAB = 0x020,	/* element supports importing */
151	CES_PORTAL_MASK	  = 0x03f,	/* flags valid for portals */
152	CES_INVERT	  = 0x040,	/* invert bit */
153	CES_SOURCE_VALID  = 0x080,	/* source address (ces_source) valid */
154	CES_SCSIID_VALID  = 0x100,	/* ces_scsi_id is valid */
155	CES_LUN_VALID	  = 0x200,	/* ces_scsi_lun is valid */
156	CES_PIV		  = 0x400	/* ces_protocol_id is valid */
157} ces_status_flags;
158
159struct changer_element_status {
160	u_int8_t		ces_type;	  /* element type */
161	u_int16_t		ces_addr;	  /* logical element address */
162	u_int16_t		ces_int_addr;	  /* changer element address */
163	ces_status_flags	ces_flags;	  /*
164						   * see CESTATUS definitions
165						   * below
166						   */
167	u_int8_t		ces_sensecode;	  /*
168						   * additional sense
169						   * code for element */
170	u_int8_t		ces_sensequal;	  /*
171						   * additional sense
172						   * code qualifier
173						   */
174	u_int8_t		ces_source_type;  /*
175						   * element type of
176						   * source address
177						   */
178	u_int16_t		ces_source_addr;  /*
179						   * source address of medium
180						   */
181	changer_voltag_t     	ces_pvoltag;	  /* primary volume tag */
182	changer_voltag_t	ces_avoltag;	  /* alternate volume tag */
183	u_int8_t		ces_scsi_id;	  /* SCSI id of element */
184	u_int8_t		ces_scsi_lun;	  /* SCSI lun of element */
185
186	/*
187	 * Data members for SMC3 and later versions
188	 */
189	u_int8_t		ces_medium_type;
190#define	CES_MEDIUM_TYPE_UNKNOWN		0	/* Medium type unspecified */
191#define	CES_MEDIUM_TYPE_DATA		1	/* Data medium */
192#define	CES_MEDIUM_TYPE_CLEANING	2	/* Cleaning medium */
193#define	CES_MEDIUM_TYPE_DIAGNOSTIC	3	/* Diagnostic medium */
194#define	CES_MEDIUM_TYPE_WORM		4	/* WORM medium */
195#define	CES_MEDIUM_TYPE_MICROCODE	5	/* Microcode image medium */
196
197	u_int8_t		ces_protocol_id;
198#define	CES_PROTOCOL_ID_FCP_4	0	/* Fiber channel */
199#define	CES_PROTOCOL_ID_SPI_5	1	/* Parallel SCSI */
200#define	CES_PROTOCOL_ID_SSA_S3P	2	/* SSA */
201#define	CES_PROTOCOL_ID_SBP_3	3	/* IEEE 1394 */
202#define	CES_PROTOCOL_ID_SRP	4	/* SCSI Remote DMA */
203#define	CES_PROTOCOL_ID_ISCSI	5	/* iSCSI */
204#define	CES_PROTOCOL_ID_SPL	6	/* SAS */
205#define	CES_PROTOCOL_ID_ADT_2	7	/* Automation/Drive Interface */
206#define	CES_PROTOCOL_ID_ACS_2	8	/* ATA */
207
208	u_int8_t		ces_assoc;
209#define	CES_ASSOC_LOGICAL_UNIT	0
210#define	CES_ASSOC_TARGET_PORT	1
211#define	CES_ASSOC_TARGET_DEVICE	2
212
213	u_int8_t		ces_designator_type;
214#define	CES_DESIGNATOR_TYPE_VENDOR_SPECIFIC	0
215#define	CES_DESIGNATOR_TYPE_T10_VENDOR_ID	1
216#define	CES_DESIGNATOR_TYPE_EUI_64		2
217#define	CES_DESIGNATOR_TYPE_NAA			3
218#define	CES_DESIGNATOR_TYPE_TARGET_PORT_ID	4
219#define	CES_DESIGNATOR_TYPE_TARGET_PORT_GRP	5
220#define	CES_DESIGNATOR_TYPE_LOGICAL_UNIT_GRP	6
221#define	CES_DESIGNATOR_TYPE_MD5_LOGICAL_UNIT_ID	7
222#define	CES_DESIGNATOR_TYPE_SCSI_NAME_STRING	8
223
224	u_int8_t		ces_code_set;
225#define	CES_CODE_SET_RESERVED	0
226#define	CES_CODE_SET_BINARY	1
227#define	CES_CODE_SET_ASCII	2
228#define	CES_CODE_SET_UTF_8	3
229
230	u_int8_t		ces_designator_length;
231
232#define	CES_MAX_DESIGNATOR_LENGTH (1 << 8)
233	u_int8_t		ces_designator[CES_MAX_DESIGNATOR_LENGTH + 1];
234};
235
236struct changer_element_status_request {
237	u_int16_t			cesr_element_type;
238	u_int16_t			cesr_element_base;
239	u_int16_t			cesr_element_count;
240
241	u_int16_t			cesr_flags;
242#define	CESR_VOLTAGS	0x01
243
244	struct changer_element_status	*cesr_element_status;
245};
246
247
248struct changer_set_voltag_request {
249	u_int16_t		csvr_type;
250	u_int16_t		csvr_addr;
251
252	u_int16_t		csvr_flags;
253#define	CSVR_MODE_MASK		0x0f	/* mode mask, acceptable modes below: */
254#define	CSVR_MODE_SET		0x00	/* set volume tag if not set */
255#define	CSVR_MODE_REPLACE	0x01	/* unconditionally replace volume tag */
256#define	CSVR_MODE_CLEAR		0x02	/* clear volume tag */
257
258#define	CSVR_ALTERNATE		0x10	/* set to work with alternate voltag */
259
260	changer_voltag_t     	csvr_voltag;
261};
262
263
264#define	CESTATUS_BITS	\
265	"\20\6INEAB\5EXENAB\4ACCESS\3EXCEPT\2IMPEXP\1FULL"
266
267#define	CHIOMOVE	_IOW('c', 0x01, struct changer_move)
268#define	CHIOEXCHANGE	_IOW('c', 0x02, struct changer_exchange)
269#define	CHIOPOSITION	_IOW('c', 0x03, struct changer_position)
270#define	CHIOGPICKER	_IOR('c', 0x04, int)
271#define	CHIOSPICKER	_IOW('c', 0x05, int)
272#define	CHIOGPARAMS	_IOR('c', 0x06, struct changer_params)
273#define	CHIOIELEM	_IOW('c', 0x07, u_int32_t)
274#define	OCHIOGSTATUS	_IOW('c', 0x08, struct changer_element_status_request)
275#define	CHIOSETVOLTAG	_IOW('c', 0x09, struct changer_set_voltag_request)
276#define	CHIOGSTATUS	_IOW('c', 0x0A, struct changer_element_status_request)
277
278#endif /* !_SYS_CHIO_H_ */
279