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