xref: /titanic_50/usr/src/uts/common/sys/scsi/impl/uscsi.h (revision 4b22b9337f359bfd063322244f5336cc7c6ffcfa)
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 2007 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 	void		*uscsi_reserved_5;	/* Reserved for Future Use */
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 	caddr32_t	uscsi_reserved_5;	/* Reserved for Future Use */
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_reserved_5	= (void *)(uintptr_t)u32->uscsi_reserved_5;
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_reserved_5	= (caddr32_t)(uintptr_t)ucmd->uscsi_reserved_5;
105 
106 #endif /* _SYSCALL32 */
107 
108 
109 /*
110  * flags for uscsi_flags field
111  */
112 /*
113  * generic flags
114  */
115 #define	USCSI_WRITE	0x00000	/* send data to device */
116 #define	USCSI_SILENT	0x00001	/* no error messages */
117 #define	USCSI_DIAGNOSE	0x00002	/* fail if any error occurs */
118 #define	USCSI_ISOLATE	0x00004	/* isolate from normal commands */
119 #define	USCSI_READ	0x00008	/* get data from device */
120 #define	USCSI_RESET_LUN	0x40000	/* Reset logical unit */
121 #define	USCSI_RESET	0x04000	/* Reset target */
122 #define	USCSI_RESET_TARGET	USCSI_RESET	/* Reset target */
123 #define	USCSI_RESET_ALL	0x08000	/* Reset all targets */
124 #define	USCSI_RQENABLE	0x10000	/* Enable Request Sense extensions */
125 #define	USCSI_RENEGOT	0x20000	/* renegotiate wide/sync on next I/O */
126 
127 /*
128  * suitable for parallel SCSI bus only
129  */
130 #define	USCSI_ASYNC	0x01000	/* Set bus to asynchronous mode */
131 #define	USCSI_SYNC	0x02000	/* Return bus to sync mode if possible */
132 
133 /*
134  * the following flags should not be used at user level but may
135  * be used by a scsi target driver for internal commands
136  */
137 /*
138  * generic flags
139  */
140 #define	USCSI_NOINTR	0x00040	/* No interrupts, NEVER to use this flag */
141 #define	USCSI_NOTAG	0x00100	/* Disable tagged queueing */
142 #define	USCSI_OTAG	0x00200	/* ORDERED QUEUE tagged cmd */
143 #define	USCSI_HTAG	0x00400	/* HEAD OF QUEUE tagged cmd */
144 #define	USCSI_HEAD	0x00800	/* Head of HA queue */
145 
146 /*
147  * suitable for parallel SCSI bus only
148  */
149 #define	USCSI_NOPARITY	0x00010	/* run command without parity */
150 #define	USCSI_NODISCON	0x00020	/* run command without disconnects */
151 
152 
153 #define	USCSI_RESERVED	0xfffc0000	/* Reserved Bits, must be zero */
154 
155 struct uscsi_rqs {
156 	int		rqs_flags;	/* see below */
157 	ushort_t	rqs_buflen;	/* maximum number or bytes to return */
158 	ushort_t	rqs_resid;	/* untransferred length of RQS data */
159 	caddr_t		rqs_bufaddr;	/* request sense buffer */
160 };
161 
162 #if defined(_SYSCALL32)
163 struct uscsi_rqs32	{
164 	int		rqs_flags;	/* see below */
165 	ushort_t	rqs_buflen;	/* maximum number or bytes to return */
166 	ushort_t	rqs_resid;	/* untransferred length of RQS data */
167 	caddr32_t	rqs_bufaddr;	/* request sense buffer */
168 };
169 #endif /* _SYSCALL32 */
170 
171 
172 /*
173  * uscsi_rqs flags
174  */
175 
176 #define	RQS_OVR		0x01	/* RQS data has been overwritten */
177 #define	RQS_VALID	0x02	/* RQS data is valid */
178 
179 /*
180  * User SCSI io control command
181  */
182 #define	USCSIIOC	(0x04 << 8)
183 #define	USCSICMD	(USCSIIOC|201) 	/* user scsi command */
184 
185 #ifdef	_KERNEL
186 
187 #include <sys/scsi/scsi_types.h>
188 
189 int	scsi_uscsi_alloc_and_copyin(intptr_t, int,
190 	    struct scsi_address *, struct uscsi_cmd **);
191 int	scsi_uscsi_handle_cmd(dev_t, enum uio_seg,
192 	    struct uscsi_cmd *, int (*)(struct buf *),
193 	    struct buf *, void *);
194 int	scsi_uscsi_copyout_and_free(intptr_t, struct uscsi_cmd *);
195 
196 #endif	/* _KERNEL */
197 
198 #ifdef	__cplusplus
199 }
200 #endif
201 
202 #endif	/* _SYS_SCSI_IMPL_USCSI_H */
203