xref: /titanic_52/usr/src/uts/common/sys/scsi/impl/uscsi.h (revision 9e39c5ba00a55fa05777cc94b148296af305e135)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 /*
27  * Defines for user SCSI commands					*
28  */
29 
30 #ifndef _SYS_SCSI_IMPL_USCSI_H
31 #define	_SYS_SCSI_IMPL_USCSI_H
32 
33 
34 #ifdef	__cplusplus
35 extern "C" {
36 #endif
37 
38 /*
39  * definition for user-scsi command structure
40  */
41 struct uscsi_cmd {
42 	int		uscsi_flags;	/* read, write, etc. see below */
43 	short		uscsi_status;	/* resulting status  */
44 	short		uscsi_timeout;	/* Command Timeout */
45 	caddr_t		uscsi_cdb;	/* cdb to send to target */
46 	caddr_t		uscsi_bufaddr;	/* i/o source/destination */
47 	size_t		uscsi_buflen;	/* size of i/o to take place */
48 	size_t		uscsi_resid;	/* resid from i/o operation */
49 	uchar_t		uscsi_cdblen;	/* # of valid cdb bytes */
50 	uchar_t		uscsi_rqlen;	/* size of uscsi_rqbuf */
51 	uchar_t		uscsi_rqstatus;	/* status of request sense cmd */
52 	uchar_t		uscsi_rqresid;	/* resid of request sense cmd */
53 	caddr_t		uscsi_rqbuf;	/* request sense buffer */
54 	ulong_t		uscsi_path_instance; /* private: hardware path */
55 };
56 
57 #if defined(_SYSCALL32)
58 struct uscsi_cmd32 {
59 	int		uscsi_flags;	/* read, write, etc. see below */
60 	short		uscsi_status;	/* resulting status  */
61 	short		uscsi_timeout;	/* Command Timeout */
62 	caddr32_t	uscsi_cdb;	/* cdb to send to target */
63 	caddr32_t	uscsi_bufaddr;	/* i/o source/destination */
64 	size32_t	uscsi_buflen;	/* size of i/o to take place */
65 	size32_t	uscsi_resid;	/* resid from i/o operation */
66 	uchar_t		uscsi_cdblen;	/* # of valid cdb bytes */
67 	uchar_t		uscsi_rqlen;	/* size of uscsi_rqbuf */
68 	uchar_t		uscsi_rqstatus;	/* status of request sense cmd */
69 	uchar_t		uscsi_rqresid;	/* resid of request sense cmd */
70 	caddr32_t	uscsi_rqbuf;	/* request sense buffer */
71 	uint32_t	uscsi_path_instance; /* private: hardware path */
72 };
73 
74 #define	uscsi_cmd32touscsi_cmd(u32, ucmd)				\
75 	ucmd->uscsi_flags	= u32->uscsi_flags;			\
76 	ucmd->uscsi_status	= u32->uscsi_status;			\
77 	ucmd->uscsi_timeout	= u32->uscsi_timeout;			\
78 	ucmd->uscsi_cdb		= (caddr_t)(uintptr_t)u32->uscsi_cdb;	\
79 	ucmd->uscsi_bufaddr	= (caddr_t)(uintptr_t)u32->uscsi_bufaddr; \
80 	ucmd->uscsi_buflen	= (size_t)u32->uscsi_buflen;		\
81 	ucmd->uscsi_resid	= (size_t)u32->uscsi_resid;		\
82 	ucmd->uscsi_cdblen	= u32->uscsi_cdblen;			\
83 	ucmd->uscsi_rqlen	= u32->uscsi_rqlen;			\
84 	ucmd->uscsi_rqstatus	= u32->uscsi_rqstatus;			\
85 	ucmd->uscsi_rqresid	= u32->uscsi_rqresid;			\
86 	ucmd->uscsi_rqbuf	= (caddr_t)(uintptr_t)u32->uscsi_rqbuf;	\
87 	ucmd->uscsi_path_instance = (ulong_t)u32->uscsi_path_instance;
88 
89 
90 #define	uscsi_cmdtouscsi_cmd32(ucmd, u32)				\
91 	u32->uscsi_flags	= ucmd->uscsi_flags;			\
92 	u32->uscsi_status	= ucmd->uscsi_status;			\
93 	u32->uscsi_timeout	= ucmd->uscsi_timeout;			\
94 	u32->uscsi_cdb		= (caddr32_t)(uintptr_t)ucmd->uscsi_cdb;  \
95 	u32->uscsi_bufaddr	= (caddr32_t)(uintptr_t)ucmd->uscsi_bufaddr; \
96 	u32->uscsi_buflen	= (size32_t)ucmd->uscsi_buflen;		\
97 	u32->uscsi_resid	= (size32_t)ucmd->uscsi_resid;		\
98 	u32->uscsi_cdblen	= ucmd->uscsi_cdblen;			\
99 	u32->uscsi_rqlen	= ucmd->uscsi_rqlen;			\
100 	u32->uscsi_rqstatus	= ucmd->uscsi_rqstatus;			\
101 	u32->uscsi_rqresid	= ucmd->uscsi_rqresid;			\
102 	u32->uscsi_rqbuf	= (caddr32_t)(uintptr_t)ucmd->uscsi_rqbuf; \
103 	u32->uscsi_path_instance = (uint32_t)ucmd->uscsi_path_instance;
104 
105 #endif /* _SYSCALL32 */
106 
107 
108 /*
109  * flags for uscsi_flags field
110  */
111 /*
112  * generic flags
113  */
114 #define	USCSI_SILENT	0x00000001	/* no error messages */
115 #define	USCSI_DIAGNOSE	0x00000002	/* fail if any error occurs */
116 #define	USCSI_ISOLATE	0x00000004	/* isolate from normal commands */
117 #define	USCSI_READ	0x00000008	/* get data from device */
118 #define	USCSI_WRITE	0x00000000	/* send data to device */
119 
120 #define	USCSI_RESET	0x00004000	/* Reset target */
121 #define	USCSI_RESET_TARGET	\
122 			USCSI_RESET	/* Reset target */
123 #define	USCSI_RESET_ALL	0x00008000	/* Reset all targets */
124 #define	USCSI_RQENABLE	0x00010000	/* Enable Request Sense extensions */
125 #define	USCSI_RENEGOT	0x00020000	/* renegotiate wide/sync on next I/O */
126 #define	USCSI_RESET_LUN	0x00040000	/* Reset logical unit */
127 #define	USCSI_PATH_INSTANCE	\
128 			0x00080000	/* use path instance for transport */
129 
130 /*
131  * suitable for parallel SCSI bus only
132  */
133 #define	USCSI_ASYNC	0x00001000	/* Set bus to asynchronous mode */
134 #define	USCSI_SYNC	0x00002000	/* Set bus to sync mode if possible */
135 
136 /*
137  * the following flags should not be used at user level but may
138  * be used by a scsi target driver for internal commands
139  */
140 /*
141  * generic flags
142  */
143 #define	USCSI_NOINTR	0x00000040	/* No interrupts, NEVER use this flag */
144 #define	USCSI_NOTAG	0x00000100	/* Disable tagged queueing */
145 #define	USCSI_OTAG	0x00000200	/* ORDERED QUEUE tagged cmd */
146 #define	USCSI_HTAG	0x00000400	/* HEAD OF QUEUE tagged cmd */
147 #define	USCSI_HEAD	0x00000800	/* Head of HA queue */
148 
149 /*
150  * suitable for parallel SCSI bus only
151  */
152 #define	USCSI_NOPARITY	0x00000010	/* run command without parity */
153 #define	USCSI_NODISCON	0x00000020	/* run command without disconnects */
154 
155 
156 #define	USCSI_RESERVED	0xfff00000	/* Reserved Bits, must be zero */
157 
158 struct uscsi_rqs {
159 	int		rqs_flags;	/* see below */
160 	ushort_t	rqs_buflen;	/* maximum number or bytes to return */
161 	ushort_t	rqs_resid;	/* untransferred length of RQS data */
162 	caddr_t		rqs_bufaddr;	/* request sense buffer */
163 };
164 
165 #if defined(_SYSCALL32)
166 struct uscsi_rqs32	{
167 	int		rqs_flags;	/* see below */
168 	ushort_t	rqs_buflen;	/* maximum number or bytes to return */
169 	ushort_t	rqs_resid;	/* untransferred length of RQS data */
170 	caddr32_t	rqs_bufaddr;	/* request sense buffer */
171 };
172 #endif /* _SYSCALL32 */
173 
174 
175 /*
176  * uscsi_rqs flags
177  */
178 
179 #define	RQS_OVR		0x01	/* RQS data has been overwritten */
180 #define	RQS_VALID	0x02	/* RQS data is valid */
181 
182 /*
183  * User SCSI io control command
184  */
185 #define	USCSIIOC	(0x04 << 8)
186 #define	USCSICMD	(USCSIIOC|201) 	/* user scsi command */
187 
188 #ifdef	_KERNEL
189 
190 #include <sys/scsi/scsi_types.h>
191 
192 struct uscsi_cmd *scsi_uscsi_alloc();
193 int	scsi_uscsi_copyin(intptr_t, int,
194 	    struct scsi_address *, struct uscsi_cmd **);
195 int	scsi_uscsi_alloc_and_copyin(intptr_t, int,
196 	    struct scsi_address *, struct uscsi_cmd **);
197 
198 int	scsi_uscsi_pktinit(struct uscsi_cmd *, struct scsi_pkt *);
199 int	scsi_uscsi_handle_cmd(dev_t, enum uio_seg,
200 	    struct uscsi_cmd *, int (*)(struct buf *),
201 	    struct buf *, void *);
202 int	scsi_uscsi_pktfini(struct scsi_pkt *, struct uscsi_cmd *);
203 
204 int	scsi_uscsi_copyout(intptr_t, struct uscsi_cmd *);
205 void	scsi_uscsi_free(struct uscsi_cmd *);
206 int	scsi_uscsi_copyout_and_free(intptr_t, struct uscsi_cmd *);
207 
208 #endif	/* _KERNEL */
209 
210 #ifdef	__cplusplus
211 }
212 #endif
213 
214 #endif	/* _SYS_SCSI_IMPL_USCSI_H */
215