xref: /titanic_50/usr/src/uts/common/sys/scsi/impl/uscsi.h (revision dcdfe824b3dff2df12578b936adf1daf000aa129)
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  * Copyright 2016 Joyent, Inc.
26  */
27 
28 /*
29  * Defines for user SCSI commands
30  */
31 
32 #ifndef _SYS_SCSI_IMPL_USCSI_H
33 #define	_SYS_SCSI_IMPL_USCSI_H
34 
35 
36 #ifdef	__cplusplus
37 extern "C" {
38 #endif
39 
40 /*
41  * definition for user-scsi command structure
42  */
43 struct uscsi_cmd {
44 	int		uscsi_flags;	/* read, write, etc. see below */
45 	short		uscsi_status;	/* resulting status  */
46 	short		uscsi_timeout;	/* Command Timeout */
47 	caddr_t		uscsi_cdb;	/* cdb to send to target */
48 	caddr_t		uscsi_bufaddr;	/* i/o source/destination */
49 	size_t		uscsi_buflen;	/* size of i/o to take place */
50 	size_t		uscsi_resid;	/* resid from i/o operation */
51 	uchar_t		uscsi_cdblen;	/* # of valid cdb bytes */
52 	uchar_t		uscsi_rqlen;	/* size of uscsi_rqbuf */
53 	uchar_t		uscsi_rqstatus;	/* status of request sense cmd */
54 	uchar_t		uscsi_rqresid;	/* resid of request sense cmd */
55 	caddr_t		uscsi_rqbuf;	/* request sense buffer */
56 	ulong_t		uscsi_path_instance; /* private: hardware path */
57 };
58 
59 #if defined(_SYSCALL32)
60 struct uscsi_cmd32 {
61 	int		uscsi_flags;	/* read, write, etc. see below */
62 	short		uscsi_status;	/* resulting status  */
63 	short		uscsi_timeout;	/* Command Timeout */
64 	caddr32_t	uscsi_cdb;	/* cdb to send to target */
65 	caddr32_t	uscsi_bufaddr;	/* i/o source/destination */
66 	size32_t	uscsi_buflen;	/* size of i/o to take place */
67 	size32_t	uscsi_resid;	/* resid from i/o operation */
68 	uchar_t		uscsi_cdblen;	/* # of valid cdb bytes */
69 	uchar_t		uscsi_rqlen;	/* size of uscsi_rqbuf */
70 	uchar_t		uscsi_rqstatus;	/* status of request sense cmd */
71 	uchar_t		uscsi_rqresid;	/* resid of request sense cmd */
72 	caddr32_t	uscsi_rqbuf;	/* request sense buffer */
73 	uint32_t	uscsi_path_instance; /* private: hardware path */
74 };
75 
76 #define	uscsi_cmd32touscsi_cmd(u32, ucmd)				\
77 	ucmd->uscsi_flags	= u32->uscsi_flags;			\
78 	ucmd->uscsi_status	= u32->uscsi_status;			\
79 	ucmd->uscsi_timeout	= u32->uscsi_timeout;			\
80 	ucmd->uscsi_cdb		= (caddr_t)(uintptr_t)u32->uscsi_cdb;	\
81 	ucmd->uscsi_bufaddr	= (caddr_t)(uintptr_t)u32->uscsi_bufaddr; \
82 	ucmd->uscsi_buflen	= (size_t)u32->uscsi_buflen;		\
83 	ucmd->uscsi_resid	= (size_t)u32->uscsi_resid;		\
84 	ucmd->uscsi_cdblen	= u32->uscsi_cdblen;			\
85 	ucmd->uscsi_rqlen	= u32->uscsi_rqlen;			\
86 	ucmd->uscsi_rqstatus	= u32->uscsi_rqstatus;			\
87 	ucmd->uscsi_rqresid	= u32->uscsi_rqresid;			\
88 	ucmd->uscsi_rqbuf	= (caddr_t)(uintptr_t)u32->uscsi_rqbuf;	\
89 	ucmd->uscsi_path_instance = (ulong_t)u32->uscsi_path_instance;
90 
91 
92 #define	uscsi_cmdtouscsi_cmd32(ucmd, u32)				\
93 	u32->uscsi_flags	= ucmd->uscsi_flags;			\
94 	u32->uscsi_status	= ucmd->uscsi_status;			\
95 	u32->uscsi_timeout	= ucmd->uscsi_timeout;			\
96 	u32->uscsi_cdb		= (caddr32_t)(uintptr_t)ucmd->uscsi_cdb;  \
97 	u32->uscsi_bufaddr	= (caddr32_t)(uintptr_t)ucmd->uscsi_bufaddr; \
98 	u32->uscsi_buflen	= (size32_t)ucmd->uscsi_buflen;		\
99 	u32->uscsi_resid	= (size32_t)ucmd->uscsi_resid;		\
100 	u32->uscsi_cdblen	= ucmd->uscsi_cdblen;			\
101 	u32->uscsi_rqlen	= ucmd->uscsi_rqlen;			\
102 	u32->uscsi_rqstatus	= ucmd->uscsi_rqstatus;			\
103 	u32->uscsi_rqresid	= ucmd->uscsi_rqresid;			\
104 	u32->uscsi_rqbuf	= (caddr32_t)(uintptr_t)ucmd->uscsi_rqbuf; \
105 	u32->uscsi_path_instance = (uint32_t)ucmd->uscsi_path_instance;
106 
107 #endif /* _SYSCALL32 */
108 
109 
110 /*
111  * flags for uscsi_flags field
112  */
113 /*
114  * generic flags
115  */
116 #define	USCSI_SILENT	0x00000001	/* no error messages */
117 #define	USCSI_DIAGNOSE	0x00000002	/* fail if any error occurs */
118 #define	USCSI_ISOLATE	0x00000004	/* isolate from normal commands */
119 #define	USCSI_READ	0x00000008	/* get data from device */
120 #define	USCSI_WRITE	0x00000000	/* send data to device */
121 
122 #define	USCSI_RESET	0x00004000	/* Reset target */
123 #define	USCSI_RESET_TARGET	\
124 			USCSI_RESET	/* Reset target */
125 #define	USCSI_RESET_ALL	0x00008000	/* Reset all targets */
126 #define	USCSI_RQENABLE	0x00010000	/* Enable Request Sense extensions */
127 #define	USCSI_RENEGOT	0x00020000	/* renegotiate wide/sync on next I/O */
128 #define	USCSI_RESET_LUN	0x00040000	/* Reset logical unit */
129 #define	USCSI_PATH_INSTANCE	\
130 			0x00080000	/* use path instance for transport */
131 
132 /*
133  * suitable for parallel SCSI bus only
134  */
135 #define	USCSI_ASYNC	0x00001000	/* Set bus to asynchronous mode */
136 #define	USCSI_SYNC	0x00002000	/* Set bus to sync mode if possible */
137 
138 /*
139  * the following flags should not be used at user level but may
140  * be used by a scsi target driver for internal commands
141  */
142 /*
143  * generic flags
144  */
145 #define	USCSI_NOINTR	0x00000040	/* No interrupts, NEVER use this flag */
146 #define	USCSI_NOTAG	0x00000100	/* Disable tagged queueing */
147 #define	USCSI_OTAG	0x00000200	/* ORDERED QUEUE tagged cmd */
148 #define	USCSI_HTAG	0x00000400	/* HEAD OF QUEUE tagged cmd */
149 #define	USCSI_HEAD	0x00000800	/* Head of HA queue */
150 
151 /*
152  * suitable for parallel SCSI bus only
153  */
154 #define	USCSI_NOPARITY	0x00000010	/* run command without parity */
155 #define	USCSI_NODISCON	0x00000020	/* run command without disconnects */
156 
157 /*
158  * suitable for FMA module for PM purpose
159  */
160 #define	USCSI_PMFAILFAST	0x00100000	/* fail command if device is */
161 						/* in low power */
162 
163 
164 #define	USCSI_RESERVED	0xffe00000	/* Reserved Bits, must be zero */
165 
166 struct uscsi_rqs {
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 	caddr_t		rqs_bufaddr;	/* request sense buffer */
171 };
172 
173 #if defined(_SYSCALL32)
174 struct uscsi_rqs32	{
175 	int		rqs_flags;	/* see below */
176 	ushort_t	rqs_buflen;	/* maximum number or bytes to return */
177 	ushort_t	rqs_resid;	/* untransferred length of RQS data */
178 	caddr32_t	rqs_bufaddr;	/* request sense buffer */
179 };
180 #endif /* _SYSCALL32 */
181 
182 
183 /*
184  * uscsi_rqs flags
185  */
186 
187 #define	RQS_OVR		0x01	/* RQS data has been overwritten */
188 #define	RQS_VALID	0x02	/* RQS data is valid */
189 
190 /*
191  * Structure for USCSIMAXXFER ioctls
192  */
193 typedef uint64_t	uscsi_xfer_t;
194 
195 /*
196  * User SCSI io control command
197  */
198 #define	USCSIIOC	(0x04 << 8)
199 #define	USCSICMD	(USCSIIOC|201) 	/* user scsi command */
200 #define	USCSIMAXXFER	(USCSIIOC|202)	/* get max transfer size */
201 
202 #ifdef	_KERNEL
203 
204 #include <sys/scsi/scsi_types.h>
205 
206 struct uscsi_cmd *scsi_uscsi_alloc();
207 int	scsi_uscsi_copyin(intptr_t, int,
208 	    struct scsi_address *, struct uscsi_cmd **);
209 int	scsi_uscsi_alloc_and_copyin(intptr_t, int,
210 	    struct scsi_address *, struct uscsi_cmd **);
211 
212 int	scsi_uscsi_pktinit(struct uscsi_cmd *, struct scsi_pkt *);
213 int	scsi_uscsi_handle_cmd(dev_t, enum uio_seg,
214 	    struct uscsi_cmd *, int (*)(struct buf *),
215 	    struct buf *, void *);
216 int	scsi_uscsi_pktfini(struct scsi_pkt *, struct uscsi_cmd *);
217 
218 int	scsi_uscsi_copyout(intptr_t, struct uscsi_cmd *);
219 void	scsi_uscsi_free(struct uscsi_cmd *);
220 int	scsi_uscsi_copyout_and_free(intptr_t, struct uscsi_cmd *);
221 
222 #endif	/* _KERNEL */
223 
224 #ifdef	__cplusplus
225 }
226 #endif
227 
228 #endif	/* _SYS_SCSI_IMPL_USCSI_H */
229