xref: /titanic_41/usr/src/uts/common/sys/scsi/impl/uscsi.h (revision 0dc2366f7b9f9f36e10909b1e95edbf2a261c2ac)
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 2009 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  * suitable for FMA module for PM purpose
157  */
158 #define	USCSI_PMFAILFAST	0x00100000	/* fail command if device is */
159 						/* in low power */
160 
161 
162 #define	USCSI_RESERVED	0xffe00000	/* Reserved Bits, must be zero */
163 
164 struct uscsi_rqs {
165 	int		rqs_flags;	/* see below */
166 	ushort_t	rqs_buflen;	/* maximum number or bytes to return */
167 	ushort_t	rqs_resid;	/* untransferred length of RQS data */
168 	caddr_t		rqs_bufaddr;	/* request sense buffer */
169 };
170 
171 #if defined(_SYSCALL32)
172 struct uscsi_rqs32	{
173 	int		rqs_flags;	/* see below */
174 	ushort_t	rqs_buflen;	/* maximum number or bytes to return */
175 	ushort_t	rqs_resid;	/* untransferred length of RQS data */
176 	caddr32_t	rqs_bufaddr;	/* request sense buffer */
177 };
178 #endif /* _SYSCALL32 */
179 
180 
181 /*
182  * uscsi_rqs flags
183  */
184 
185 #define	RQS_OVR		0x01	/* RQS data has been overwritten */
186 #define	RQS_VALID	0x02	/* RQS data is valid */
187 
188 /*
189  * User SCSI io control command
190  */
191 #define	USCSIIOC	(0x04 << 8)
192 #define	USCSICMD	(USCSIIOC|201) 	/* user scsi command */
193 
194 #ifdef	_KERNEL
195 
196 #include <sys/scsi/scsi_types.h>
197 
198 struct uscsi_cmd *scsi_uscsi_alloc();
199 int	scsi_uscsi_copyin(intptr_t, int,
200 	    struct scsi_address *, struct uscsi_cmd **);
201 int	scsi_uscsi_alloc_and_copyin(intptr_t, int,
202 	    struct scsi_address *, struct uscsi_cmd **);
203 
204 int	scsi_uscsi_pktinit(struct uscsi_cmd *, struct scsi_pkt *);
205 int	scsi_uscsi_handle_cmd(dev_t, enum uio_seg,
206 	    struct uscsi_cmd *, int (*)(struct buf *),
207 	    struct buf *, void *);
208 int	scsi_uscsi_pktfini(struct scsi_pkt *, struct uscsi_cmd *);
209 
210 int	scsi_uscsi_copyout(intptr_t, struct uscsi_cmd *);
211 void	scsi_uscsi_free(struct uscsi_cmd *);
212 int	scsi_uscsi_copyout_and_free(intptr_t, struct uscsi_cmd *);
213 
214 #endif	/* _KERNEL */
215 
216 #ifdef	__cplusplus
217 }
218 #endif
219 
220 #endif	/* _SYS_SCSI_IMPL_USCSI_H */
221