1 /* @(#)scgcmd.h	2.26 07/11/22 Copyright 1986 J. Schilling */
2 /*
3  *	Definitions for the SCSI 'scg_cmd' structure that has been created
4  *	for the SCSI general driver 'scg' for SunOS and Solaris but
5  *	now is used for wrapping general libscg SCSI transport requests.
6  *
7  *	Copyright (c) 1986 J. Schilling
8  */
9 /*
10  * The contents of this file are subject to the terms of the
11  * Common Development and Distribution License, Version 1.0 only
12  * (the "License").  You may not use this file except in compliance
13  * with the License.
14  *
15  * See the file CDDL.Schily.txt in this distribution for details.
16  *
17  * The following exceptions apply:
18  * CDDL �3.6 needs to be replaced by: "You may create a Larger Work by
19  * combining Covered Software with other code if all other code is governed by
20  * the terms of a license that is OSI approved (see www.opensource.org) and
21  * you may distribute the Larger Work as a single product. In such a case,
22  * You must make sure the requirements of this License are fulfilled for
23  * the Covered Software."
24  *
25  * When distributing Covered Code, include this CDDL HEADER in each
26  * file and include the License file CDDL.Schily.txt from this distribution.
27  */
28 
29 #ifndef	_SCG_SCGCMD_H
30 #define	_SCG_SCGCMD_H
31 
32 #ifdef	_KERNEL
33 #define	scsi_status	scg_status
34 #define	scsi_sense	scg_sense
35 #define	scsi_ext_sense	scg_ext_sense
36 #endif
37 
38 #include <schily/utypes.h>
39 #include <schily/btorder.h>
40 
41 #if	defined(_BIT_FIELDS_LTOH)	/* Intel byteorder */
42 #else
43 # if	defined(_BIT_FIELDS_HTOL)	/* Motorola byteorder */
44 # else
45 /*
46  * #error will not work for all compilers (e.g. sunos4)
47  * The following line will abort compilation on all compilers
48  * if none of the above is defines. And that's  what we want.
49  */
50 error  One of _BIT_FIELDS_LTOH or _BIT_FIELDS_HTOL must be defined
51 # endif
52 #endif
53 
54 #include <scg/scsisense.h>
55 #include <scg/scsicdb.h>
56 #include <schily/intcvt.h>
57 
58 #ifdef	__cplusplus
59 extern "C" {
60 #endif
61 
62 /*
63  * Leave these definitions here if possible to avoid the need to
64  * include scsireg.h which makes problems on some OS because these
65  * OS define the same types as in scsireg.h
66  */
67 
68 /*
69  * SCSI status bits.
70  */
71 #define	ST_VU_00	0x01	/* Vendor unique		*/
72 #define	ST_CHK_COND	0x02	/* Check condition		*/
73 #define	ST_COND_MET	0x04	/* Condition met		*/
74 #define	ST_BUSY		0x08	/* Busy				*/
75 #define	ST_IS_SEND	0x10	/* Intermediate status send	*/
76 #define	ST_VU_05	0x20	/* Vendor unique		*/
77 #define	ST_VU_06	0x40	/* Vendor unique		*/
78 #define	ST_RSVD_07	0x80	/* Reserved			*/
79 
80 /*
81  * Sense key values for extended sense.
82  */
83 #define	SC_NO_SENSE		0x00
84 #define	SC_RECOVERABLE_ERROR	0x01
85 #define	SC_NOT_READY		0x02
86 #define	SC_MEDIUM_ERROR		0x03
87 #define	SC_HARDWARE_ERROR	0x04
88 #define	SC_ILLEGAL_REQUEST	0x05
89 #define	SC_UNIT_ATTENTION	0x06
90 #define	SC_WRITE_PROTECT	0x07
91 #define	SC_BLANK_CHECK		0x08
92 #define	SC_VENDOR_UNIQUE	0x09
93 #define	SC_COPY_ABORTED		0x0A
94 #define	SC_ABORTED_COMMAND	0x0B
95 #define	SC_EQUAL		0x0C
96 #define	SC_VOLUME_OVERFLOW	0x0D
97 #define	SC_MISCOMPARE		0x0E
98 #define	SC_RESERVED		0x0F
99 
100 /*
101  * Messages that SCSI can send.
102  */
103 #define	SC_COMMAND_COMPLETE	0x00
104 #define	SC_SYNCHRONOUS		0x01
105 #define	SC_SAVE_DATA_PTR	0x02
106 #define	SC_RESTORE_PTRS		0x03
107 #define	SC_DISCONNECT		0x04
108 #define	SC_ABORT		0x06
109 #define	SC_MSG_REJECT		0x07
110 #define	SC_NO_OP		0x08
111 #define	SC_PARITY		0x09
112 #define	SC_IDENTIFY		0x80
113 #define	SC_DR_IDENTIFY		0xc0
114 #define	SC_DEVICE_RESET		0x0c
115 
116 #define	SC_G0_CDBLEN	6	/* Len of Group 0 commands */
117 #define	SC_G1_CDBLEN	10	/* Len of Group 1 commands */
118 #define	SC_G5_CDBLEN	12	/* Len of Group 5 commands */
119 
120 #define	SCG_MAX_CMD	24	/* 24 bytes max. size is supported */
121 #define	SCG_MAX_STATUS	3	/* XXX (sollte 4 allign.) Mamimum Status Len */
122 #define	SCG_MAX_SENSE	32	/* Mamimum Sense Len for auto Req. Sense */
123 
124 #define	DEF_SENSE_LEN	16	/* Default Sense Len */
125 #define	CCS_SENSE_LEN	18	/* Sense Len for CCS compatible devices */
126 
127 struct	scg_cmd {
128 	caddr_t	addr;			/* Address of data in user space */
129 	int	size;			/* DMA count for data transfer */
130 	int	flags;			/* see below for definition */
131 	int	cdb_len;		/* Size of SCSI command in bytes */
132 					/* NOTE: rel 4 uses this field only */
133 					/* with commands not in group 1 or 2*/
134 	int	sense_len;		/* for intr() if -1 don't get sense */
135 	int	timeout;		/* timeout in seconds */
136 					/* NOTE: actual resolution depends */
137 					/* on driver implementation */
138 	int	kdebug;			/* driver kernel debug level */
139 	int	resid;			/* Bytes not transfered */
140 	int	error;			/* Error code from scgintr() */
141 	int	ux_errno;		/* UNIX error code */
142 	union {
143 		struct	scsi_status Scb; /* Status returnd by command */
144 		Uchar	cmd_scb[SCG_MAX_STATUS];
145 	} u_scb;
146 #define	scb	u_scb.Scb
147 
148 	union {
149 		struct	scsi_sense Sense; /* Sense bytes from command */
150 		Uchar	cmd_sense[SCG_MAX_SENSE];
151 	} u_sense;
152 #define	sense	u_sense.Sense
153 	int	sense_count;		/* Number of bytes valid in sense */
154 	int	target;			/* SCSI target id */
155 					/* NOTE: The SCSI target id field   */
156 					/* does not need to be filled unless */
157 					/* the low level transport is a real */
158 					/* scg driver. In this case the low */
159 					/* level transport routine of libscg */
160 					/* will fill in the needed value    */
161 	union {				/* SCSI command descriptor block */
162 		struct	scsi_g0cdb g0_cdb;
163 		struct	scsi_g1cdb g1_cdb;
164 		struct	scsi_g5cdb g5_cdb;
165 		Uchar	cmd_cdb[SCG_MAX_CMD];
166 	} cdb;				/* 24 bytes max. size is supported */
167 };
168 
169 #if	defined(_KERNEL) && defined(_MULTI_DATAMODEL)
170 struct	scg_cmd32 {
171 	caddr32_t	addr;			/* Address of data in user space */
172 	int	size;			/* DMA count for data transfer */
173 	int	flags;			/* see below for definition */
174 	int	cdb_len;		/* Size of SCSI command in bytes */
175 					/* NOTE: rel 4 uses this field only */
176 					/* with commands not in group 1 or 2*/
177 	int	sense_len;		/* for intr() if -1 don't get sense */
178 	int	timeout;		/* timeout in seconds */
179 					/* NOTE: actual resolution depends */
180 					/* on driver implementation */
181 	int	kdebug;			/* driver kernel debug level */
182 	int	resid;			/* Bytes not transfered */
183 	int	error;			/* Error code from scgintr() */
184 	int	ux_errno;		/* UNIX error code */
185 	union {
186 		struct	scsi_status Scb; /* Status returnd by command */
187 		Uchar	cmd_scb[SCG_MAX_STATUS];
188 	} u_scb;
189 #define	scb	u_scb.Scb
190 
191 	union {
192 		struct	scsi_sense Sense; /* Sense bytes from command */
193 		Uchar	cmd_sense[SCG_MAX_SENSE];
194 	} u_sense;
195 #define	sense	u_sense.Sense
196 	int	sense_count;		/* Number of bytes valid in sense */
197 	int	target;			/* SCSI target id */
198 	union {				/* SCSI command descriptor block */
199 		struct	scsi_g0cdb g0_cdb;
200 		struct	scsi_g1cdb g1_cdb;
201 		struct	scsi_g5cdb g5_cdb;
202 		Uchar	cmd_cdb[SCG_MAX_CMD];
203 	} cdb;				/* 24 bytes max. size is supported */
204 };
205 #endif	/* defined(_KERNEL) && defined(_MULTI_DATAMODEL) */
206 
207 #define	dma_read	flags		/* 1 if DMA to Sun, 0 otherwise */
208 
209 /*
210  * definition for flags field in scg_cmd struct
211  */
212 #define	SCG_RECV_DATA	0x0001		/* DMA direction to Sun */
213 #define	SCG_DISRE_ENA	0x0002		/* enable disconnect/reconnect */
214 #define	SCG_SILENT	0x0004		/* be silent on errors */
215 #define	SCG_CMD_RETRY	0x0008		/* enable retries */
216 #define	SCG_NOPARITY	0x0010		/* disable parity for this command */
217 
218 /*
219  * definition for error field in scg_cmd struct
220  *
221  * The codes refer to SCSI general errors, not to device
222  * specific errors.  Device specific errors are discovered
223  * by checking the sense data.
224  * The distinction between retryable and fatal is somewhat ad hoc.
225  */
226 #define	SCG_NO_ERROR	0		/* cdb transported without error    */
227 					/* SCG_NO_ERROR incudes all commands */
228 					/* where the SCSI status is valid   */
229 
230 #define	SCG_RETRYABLE	1		/* any other case e.g. SCSI bus busy */
231 					/* SCSI cdb could not be send,	    */
232 					/* includes DMA errors other than   */
233 					/* DMA underrun			    */
234 
235 #define	SCG_FATAL	2		/* could not select target	    */
236 #define	SCG_TIMEOUT	3		/* driver timed out		    */
237 
238 
239 #ifdef	__cplusplus
240 }
241 #endif
242 
243 #ifdef	_KERNEL
244 #undef	scsi_status
245 #undef	scsi_sense
246 #undef	scsi_ext_sense
247 #endif
248 
249 #endif	/* _SCG_SCGCMD_H */
250