xref: /titanic_50/usr/src/uts/common/sys/scsi/scsi_pkt.h (revision 0e42dee69ed771bf604dd1789fca9d77b5bbe302)
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 2006 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #ifndef	_SYS_SCSI_SCSI_PKT_H
27 #define	_SYS_SCSI_SCSI_PKT_H
28 
29 #pragma ident	"%Z%%M%	%I%	%E% SMI"
30 
31 #include <sys/scsi/scsi_types.h>
32 
33 #ifdef	__cplusplus
34 extern "C" {
35 #endif
36 
37 #ifdef	_KERNEL
38 /*
39  * SCSI packet definition.
40  *
41  *	This structure defines the packet which is allocated by a library
42  *	function and handed to a target driver. The target driver fills
43  *	in some information, and passes it to the library for transport
44  *	to an addressed SCSI device. The host adapter found by
45  *	the library fills in some other information as the command is
46  *	processed. When the command completes (or can be taken no further)
47  *	the function specified in the packet is called with a pointer to
48  *	the packet as it argument. From fields within the packet, the target
49  *	driver can determine the success or failure of the command.
50  */
51 struct scsi_pkt {
52 	opaque_t pkt_ha_private;	/* private data for host adapter */
53 	struct scsi_address pkt_address;	/* destination packet is for */
54 	opaque_t pkt_private;		/* private data for target driver */
55 	void	(*pkt_comp)(struct scsi_pkt *);	/* completion routine */
56 	uint_t	pkt_flags;		/* flags */
57 	int	pkt_time;		/* time allotted to complete command */
58 	uchar_t	*pkt_scbp;		/* pointer to status block */
59 	uchar_t	*pkt_cdbp;		/* pointer to command block */
60 	ssize_t	pkt_resid;		/* data bytes not transferred */
61 	uint_t	pkt_state;		/* state of command */
62 	uint_t	pkt_statistics;		/* statistics */
63 	uchar_t	pkt_reason;		/* reason completion called */
64 	uint_t	pkt_cdblen;
65 	uint_t	pkt_tgtlen;
66 	uint_t	pkt_scblen;
67 	ddi_dma_handle_t pkt_handle;
68 	uint_t	pkt_numcookies;
69 	off_t	pkt_dma_offset;
70 	size_t	pkt_dma_len;
71 	uint_t	pkt_dma_flags;
72 	ddi_dma_cookie_t *pkt_cookies;
73 };
74 #endif	/* _KERNEL */
75 
76 /*
77  * Definitions for the pkt_flags field.
78  */
79 
80 /*
81  * Following defines are generic.
82  */
83 #define	FLAG_STAG	0x4000	/* Run command with Simple attribute */
84 #define	FLAG_OTAG	0x2000	/* Run command with Ordered attribute */
85 #define	FLAG_HTAG	0x1000	/* Run command with Head of Queue attribute */
86 #define	FLAG_TAGMASK	(FLAG_HTAG|FLAG_OTAG|FLAG_STAG)
87 
88 #define	FLAG_ACA	0x0100	/* internal; do not use */
89 #define	FLAG_HEAD	0x8000	/* This cmd should be put at the head	*/
90 				/* of the HBA driver's queue		*/
91 #define	FLAG_SENSING	0x0400	/* Running request sense for failed pkt */
92 #define	FLAG_NOINTR	0x0001	/* Run command with no cmd completion	*/
93 				/* callback; command has been completed	*/
94 				/* upon	return from scsi_transport(9F)	*/
95 
96 /*
97  * Following defines are appropriate for SCSI parallel bus.
98  */
99 #define	FLAG_NODISCON	0x0002	/* Run command without disconnects	*/
100 #define	FLAG_NOPARITY	0x0008	/* Run command without parity checking	*/
101 #define	FLAG_RENEGOTIATE_WIDE_SYNC \
102 			0x1000000 /* Do wide and sync renegotiation before */
103 				/* transporting this command to target */
104 
105 /*
106  * Following defines are internal i.e. not part of DDI.
107  */
108 #define	FLAG_IMMEDIATE_CB \
109 			0x0800	/* Immediate callback on command */
110 				/* completion, ie. do not defer */
111 
112 /*
113  * Following defines are for USCSI options.
114  */
115 #define	FLAG_SILENT	0x00010000
116 #define	FLAG_DIAGNOSE	0x00020000
117 #define	FLAG_ISOLATE	0x00040000
118 
119 /*
120  * Following define is for scsi_vhci.
121  * If pHCI cannot transport the command to the device, do not queue the pkt
122  * in pHCI. Return immediately with TRAN_BUSY.
123  */
124 #define	FLAG_NOQUEUE	0x80000000
125 
126 /*
127  * Definitions for the pkt_reason field.
128  */
129 
130 /*
131  * Following defines are generic.
132  */
133 #define	CMD_CMPLT	0	/* no transport errors- normal completion */
134 #define	CMD_INCOMPLETE	1	/* transport stopped with not normal state */
135 #define	CMD_DMA_DERR	2	/* dma direction error occurred */
136 #define	CMD_TRAN_ERR	3	/* unspecified transport error */
137 #define	CMD_RESET	4	/* Target completed hard reset sequence */
138 #define	CMD_ABORTED	5	/* Command transport aborted on request */
139 #define	CMD_TIMEOUT	6	/* Command timed out */
140 #define	CMD_DATA_OVR	7	/* Data Overrun */
141 #define	CMD_CMD_OVR	8	/* Command Overrun */
142 #define	CMD_STS_OVR	9	/* Status Overrun */
143 #define	CMD_TERMINATED	22	/* Command transport terminated on request */
144 
145 /*
146  * Following defines are appropriate for SCSI parallel bus.
147  */
148 #define	CMD_BADMSG	10	/* Message not Command Complete */
149 #define	CMD_NOMSGOUT	11	/* Target refused to go to Message Out phase */
150 #define	CMD_XID_FAIL	12	/* Extended Identify message rejected */
151 #define	CMD_IDE_FAIL	13	/* Initiator Detected Error message rejected */
152 #define	CMD_ABORT_FAIL	14	/* Abort message rejected */
153 #define	CMD_REJECT_FAIL 15	/* Reject message rejected */
154 #define	CMD_NOP_FAIL	16	/* No Operation message rejected */
155 #define	CMD_PER_FAIL	17	/* Message Parity Error message rejected */
156 #define	CMD_BDR_FAIL	18	/* Bus Device Reset message rejected */
157 #define	CMD_ID_FAIL	19	/* Identify message rejected */
158 #define	CMD_UNX_BUS_FREE	20	/* Unexpected Bus Free Phase occurred */
159 #define	CMD_TAG_REJECT	21	/* Target rejected our tag message */
160 #define	CMD_DEV_GONE	24	/* The device has been removed */
161 
162 /* Used by scsi_rname(9F) */
163 #define	CMD_REASON_ASCII	{ \
164 	    "cmplt", "incomplete", "dma_derr", "tran_err", "reset", \
165 	    "aborted", "timeout", "data_ovr", "cmd_ovr", "sts_ovr", \
166 	    "badmsg", "nomsgout", "xid_fail", "ide_fail", "abort_fail", \
167 	    "reject_fail", "nop_fail", "per_fail", "bdr_fail", "id_fail", \
168 	    "unexpected_bus_free", "tag reject", "terminated", "", "gone", \
169 	    NULL }
170 
171 /*
172  * Definitions for the pkt_state field
173  */
174 #define	STATE_GOT_BUS		0x01	/* Success in getting SCSI bus */
175 #define	STATE_GOT_TARGET	0x02	/* Successfully connected with target */
176 #define	STATE_SENT_CMD		0x04	/* Command successfully sent */
177 #define	STATE_XFERRED_DATA	0x08	/* Data transfer took place */
178 #define	STATE_GOT_STATUS	0x10	/* SCSI status received */
179 #define	STATE_ARQ_DONE		0x20	/* auto rqsense took place */
180 
181 /*
182  * Definitions for the pkt_statistics field
183  */
184 
185 /*
186  * Following defines are generic.
187  */
188 #define	STAT_BUS_RESET	0x8	/* Reset operation on interconnect */
189 #define	STAT_DEV_RESET	0x10	/* Target completed hard reset sequence */
190 #define	STAT_ABORTED	0x20	/* Command was aborted */
191 #define	STAT_TERMINATED	0x80	/* Command was terminated */
192 #define	STAT_TIMEOUT	0x40	/* Command experienced a timeout */
193 
194 /*
195  * Following defines are appropriate for SCSI parallel bus.
196  */
197 #define	STAT_DISCON	0x1	/* Command experienced a disconnect */
198 #define	STAT_SYNC	0x2	/* Command did a synchronous data transfer */
199 #define	STAT_PERR	0x4	/* Command experienced a SCSI parity error */
200 
201 /*
202  * Definitions for what scsi_transport returns
203  */
204 #define	TRAN_ACCEPT		1
205 #define	TRAN_BUSY		0
206 #define	TRAN_BADPKT		-1
207 #define	TRAN_FATAL_ERROR	-2	/* HBA cannot accept any pkts */
208 
209 #ifdef	_KERNEL
210 /*
211  * Kernel function declarations
212  */
213 int	scsi_transport(struct scsi_pkt *pkt);
214 
215 #define	pkt_transport	scsi_transport
216 
217 #define	SCSI_POLL_TIMEOUT	60
218 
219 #endif	/* _KERNEL */
220 
221 #ifdef	__cplusplus
222 }
223 #endif
224 
225 #endif	/* _SYS_SCSI_SCSI_PKT_H */
226