chio.h revision 139825
1139825Simp/*-
223452Sjoerg * Copyright (c) 1996 Jason R. Thorpe <thorpej@and.com>
323452Sjoerg * All rights reserved.
4624Srgrimes *
523452Sjoerg * Redistribution and use in source and binary forms, with or without
623452Sjoerg * modification, are permitted provided that the following conditions
723452Sjoerg * are met:
823452Sjoerg * 1. Redistributions of source code must retain the above copyright
923452Sjoerg *    notice, this list of conditions and the following disclaimer.
1023452Sjoerg * 2. Redistributions in binary form must reproduce the above copyright
1123452Sjoerg *    notice, this list of conditions and the following disclaimer in the
1223452Sjoerg *    documentation and/or other materials provided with the distribution.
1323452Sjoerg * 3. All advertising materials mentioning features or use of this software
1423452Sjoerg *    must display the following acknowledgements:
1523452Sjoerg *	This product includes software developed by Jason R. Thorpe
1623452Sjoerg *	for And Communications, http://www.and.com/
1723452Sjoerg * 4. The name of the author may not be used to endorse or promote products
1823452Sjoerg *    derived from this software without specific prior written permission.
1923452Sjoerg *
2023452Sjoerg * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
2123452Sjoerg * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
2223452Sjoerg * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
2323452Sjoerg * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
2423452Sjoerg * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
2523452Sjoerg * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
2623452Sjoerg * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
2723452Sjoerg * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
2823452Sjoerg * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2923452Sjoerg * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3023452Sjoerg * SUCH DAMAGE.
3123452Sjoerg *
3250477Speter * $FreeBSD: head/sys/sys/chio.h 139825 2005-01-07 02:29:27Z imp $
334Srgrimes */
344Srgrimes
3523736Sjoerg#ifndef	_SYS_CHIO_H_
3623736Sjoerg#define	_SYS_CHIO_H_
3723452Sjoerg
3855205Speter#ifndef _KERNEL
3923736Sjoerg#include <sys/types.h>
4023736Sjoerg#endif
4123736Sjoerg#include <sys/ioccom.h>
4223736Sjoerg
4323452Sjoerg/*
4423452Sjoerg * Element types.  Used as "to" and "from" type indicators in move
4523452Sjoerg * and exchange operations.
4623452Sjoerg *
4723452Sjoerg * Note that code in sys/scsi/ch.c relies on these values (uses them
4823452Sjoerg * as offsets in an array, and other evil), so don't muck with them
4923452Sjoerg * unless you know what you're doing.
504Srgrimes */
5123452Sjoerg#define CHET_MT		0	/* medium transport (picker) */
5223452Sjoerg#define CHET_ST		1	/* storage transport (slot) */
5323452Sjoerg#define CHET_IE		2	/* import/export (portal) */
5423452Sjoerg#define CHET_DT		3	/* data transfer (drive) */
55115464Sphk#define CHET_MAX	CHET_DT
564Srgrimes
574Srgrimes/*
5839248Sgibbs * Maximum length of a volume identification string
5939248Sgibbs */
6039248Sgibbs#define CH_VOLTAG_MAXLEN	32
6139248Sgibbs
6239248Sgibbs/*
6323452Sjoerg * Structure used to execute a MOVE MEDIUM command.
644Srgrimes */
6523452Sjoergstruct changer_move {
6639248Sgibbs	u_int16_t	cm_fromtype;	/* element type to move from */
6739248Sgibbs	u_int16_t	cm_fromunit;	/* logical unit of from element */
6839248Sgibbs	u_int16_t	cm_totype;	/* element type to move to */
6939248Sgibbs	u_int16_t	cm_tounit;	/* logical unit of to element */
7039248Sgibbs	u_int16_t	cm_flags;	/* misc. flags */
7123452Sjoerg};
724Srgrimes
7323452Sjoerg/* cm_flags */
7423452Sjoerg#define CM_INVERT	0x01	/* invert media */
7518444Sbde
7623452Sjoerg/*
7723452Sjoerg * Structure used to execute an EXCHANGE MEDIUM command.  In an
7823452Sjoerg * exchange operation, the following steps occur:
7923452Sjoerg *
8023452Sjoerg *	- media from source is moved to first destination.
8123452Sjoerg *
8223452Sjoerg *	- media previously occupying first destination is moved
8323452Sjoerg *	  to the second destination.
8423452Sjoerg *
8523452Sjoerg * The second destination may or may not be the same as the source.
8623452Sjoerg * In the case of a simple exchange, the source and second destination
8723452Sjoerg * are the same.
8823452Sjoerg */
8923452Sjoergstruct changer_exchange {
9039248Sgibbs	u_int16_t	ce_srctype;	/* element type of source */
9139248Sgibbs	u_int16_t	ce_srcunit;	/* logical unit of source */
9239248Sgibbs	u_int16_t	ce_fdsttype;	/* element type of first destination */
9339248Sgibbs	u_int16_t	ce_fdstunit;	/* logical unit of first destination */
9439248Sgibbs	u_int16_t	ce_sdsttype;	/* element type of second destination */
9539248Sgibbs	u_int16_t	ce_sdstunit;	/* logical unit of second destination */
9639248Sgibbs	u_int16_t	ce_flags;	/* misc. flags */
9723452Sjoerg};
9818444Sbde
9923452Sjoerg/* ce_flags */
10023452Sjoerg#define CE_INVERT1	0x01	/* invert media 1 */
10123452Sjoerg#define CE_INVERT2	0x02	/* invert media 2 */
1024Srgrimes
10323452Sjoerg/*
10423452Sjoerg * Structure used to execute a POSITION TO ELEMENT command.  This
10523452Sjoerg * moves the current picker in front of the specified element.
10623452Sjoerg */
10723452Sjoergstruct changer_position {
10839248Sgibbs	u_int16_t	cp_type;	/* element type */
10939248Sgibbs	u_int16_t	cp_unit;	/* logical unit of element */
11039248Sgibbs	u_int16_t	cp_flags;	/* misc. flags */
1114Srgrimes};
1124Srgrimes
11323452Sjoerg/* cp_flags */
11423452Sjoerg#define CP_INVERT	0x01	/* invert picker */
1154Srgrimes
11623452Sjoerg/*
11723452Sjoerg * Data returned by CHIOGPARAMS.
11823452Sjoerg */
11923452Sjoergstruct changer_params {
12039248Sgibbs	u_int16_t	cp_npickers;	/* number of pickers */
12139248Sgibbs	u_int16_t	cp_nslots;	/* number of slots */
12239248Sgibbs	u_int16_t	cp_nportals;	/* number of import/export portals */
12339248Sgibbs	u_int16_t	cp_ndrives;	/* number of drives */
12423452Sjoerg};
1254Srgrimes
12623452Sjoerg/*
12723452Sjoerg * Command used to get element status.
12823452Sjoerg */
12939248Sgibbs
13039248Sgibbsstruct changer_voltag {
13139248Sgibbs	u_char		cv_volid[CH_VOLTAG_MAXLEN+1];
13239248Sgibbs	u_int16_t	cv_serial;
13323452Sjoerg};
134785Srgrimes
13539248Sgibbstypedef struct changer_voltag changer_voltag_t;
13639248Sgibbs
13723452Sjoerg/*
13839248Sgibbs * Flags definitions for ces_status
13923452Sjoerg * Not all flags have meaning for all element types.
14023452Sjoerg */
14139248Sgibbstypedef enum {
14239248Sgibbs	CES_STATUS_FULL	  = 0x001,	/* element is full */
14339248Sgibbs	CES_STATUS_IMPEXP = 0x002,	/* media deposited by operator */
14439248Sgibbs	CES_STATUS_EXCEPT = 0x004,	/* element in abnormal state */
14539248Sgibbs	CES_PICKER_MASK	  = 0x005,	/* flags valid for pickers */
14639248Sgibbs	CES_STATUS_ACCESS = 0x008,	/* media accessible by picker */
14739248Sgibbs	CES_SLOT_MASK	  = 0x00c,	/* flags valid for slots */
14839248Sgibbs	CES_DRIVE_MASK	  = 0x00c,	/* flags valid for drives */
14939248Sgibbs	CES_STATUS_EXENAB = 0x010,	/* element supports exporting */
15039248Sgibbs	CES_STATUS_INENAB = 0x020,	/* element supports importing */
15139248Sgibbs	CES_PORTAL_MASK	  = 0x03f,	/* flags valid for portals */
15239248Sgibbs	CES_INVERT	  = 0x040,	/* invert bit */
15339248Sgibbs	CES_SOURCE_VALID  = 0x080,	/* source address (ces_source) valid */
15439248Sgibbs	CES_SCSIID_VALID  = 0x100,	/* ces_scsi_id is valid */
15544516Sbde	CES_LUN_VALID	  = 0x200	/* ces_scsi_lun is valid */
15639248Sgibbs} ces_status_flags;
15723452Sjoerg
15839248Sgibbsstruct changer_element_status {
15939248Sgibbs	u_int8_t		ces_type;	  /* element type */
16039248Sgibbs	u_int16_t		ces_addr;	  /* logical element address */
16139248Sgibbs	u_int16_t		ces_int_addr;	  /* changer element address */
16239248Sgibbs	ces_status_flags	ces_flags;	  /*
16339248Sgibbs						   * see CESTATUS definitions
16439248Sgibbs						   * below
16539248Sgibbs						   */
16639248Sgibbs	u_int8_t		ces_sensecode;	  /*
16739248Sgibbs						   * additional sense
16839248Sgibbs						   * code for element */
16939248Sgibbs	u_int8_t		ces_sensequal;	  /*
17039248Sgibbs						   * additional sense
17139248Sgibbs						   * code qualifier
17239248Sgibbs						   */
17339248Sgibbs	u_int8_t		ces_source_type;  /*
17439248Sgibbs						   * element type of
17539248Sgibbs						   * source address
17639248Sgibbs						   */
17739248Sgibbs	u_int16_t		ces_source_addr;  /*
17839248Sgibbs						   * source address of medium
17939248Sgibbs						   */
18039248Sgibbs	changer_voltag_t     	ces_pvoltag;	  /* primary volume tag */
18139248Sgibbs	changer_voltag_t	ces_avoltag;	  /* alternate volume tag */
18239248Sgibbs	u_int8_t		ces_scsi_id;	  /* SCSI id of element */
18339248Sgibbs	u_int8_t		ces_scsi_lun;	  /* SCSI lun of element */
18439248Sgibbs};
18523452Sjoerg
18639248Sgibbsstruct changer_element_status_request {
18739248Sgibbs	u_int16_t			cesr_element_type;
18839248Sgibbs	u_int16_t			cesr_element_base;
18939248Sgibbs	u_int16_t			cesr_element_count;
19039248Sgibbs
19139248Sgibbs	u_int16_t			cesr_flags;
19239248Sgibbs#define CESR_VOLTAGS	0x01
19339248Sgibbs
19439248Sgibbs	struct changer_element_status	*cesr_element_status;
19539248Sgibbs};
19639248Sgibbs
19739248Sgibbs
19839248Sgibbsstruct changer_set_voltag_request {
19939248Sgibbs	u_int16_t		csvr_type;
20039248Sgibbs	u_int16_t		csvr_addr;
20139248Sgibbs
20239248Sgibbs	u_int16_t		csvr_flags;
20339248Sgibbs#define CSVR_MODE_MASK		0x0f	/* mode mask, acceptable modes below: */
20439248Sgibbs#define	CSVR_MODE_SET		0x00	/* set volume tag if not set */
20539248Sgibbs#define CSVR_MODE_REPLACE	0x01	/* unconditionally replace volume tag */
20639248Sgibbs#define CSVR_MODE_CLEAR		0x02	/* clear volume tag */
20739248Sgibbs
20839248Sgibbs#define CSVR_ALTERNATE		0x10	/* set to work with alternate voltag */
20939248Sgibbs
21039248Sgibbs	changer_voltag_t     	csvr_voltag;
21139248Sgibbs};
21239248Sgibbs
21339248Sgibbs
21423452Sjoerg#define CESTATUS_BITS	\
21523452Sjoerg	"\20\6INEAB\5EXENAB\4ACCESS\3EXCEPT\2IMPEXP\1FULL"
21623452Sjoerg
21723452Sjoerg#define CHIOMOVE	_IOW('c', 0x01, struct changer_move)
21823452Sjoerg#define CHIOEXCHANGE	_IOW('c', 0x02, struct changer_exchange)
21923452Sjoerg#define CHIOPOSITION	_IOW('c', 0x03, struct changer_position)
22023452Sjoerg#define CHIOGPICKER	_IOR('c', 0x04, int)
22123452Sjoerg#define CHIOSPICKER	_IOW('c', 0x05, int)
22223452Sjoerg#define CHIOGPARAMS	_IOR('c', 0x06, struct changer_params)
22339248Sgibbs#define CHIOIELEM	_IOW('c', 0x07, u_int32_t)
22439248Sgibbs#define CHIOGSTATUS	_IOW('c', 0x08, struct changer_element_status_request)
22539248Sgibbs#define CHIOSETVOLTAG	_IOW('c', 0x09, struct changer_set_voltag_request)
22623452Sjoerg
22723736Sjoerg#endif /* !_SYS_CHIO_H_ */
228