xref: /titanic_41/usr/src/uts/common/sys/scsi/scsi_pkt.h (revision 0adc16190e36914964740716575460dda750de39)
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, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef	_SYS_SCSI_SCSI_PKT_H
28 #define	_SYS_SCSI_SCSI_PKT_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #include <sys/scsi/scsi_types.h>
33 
34 #ifdef	__cplusplus
35 extern "C" {
36 #endif
37 
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 };
68 
69 /*
70  * Definitions for the pkt_flags field.
71  */
72 
73 /*
74  * Following defines are generic.
75  */
76 #define	FLAG_STAG	0x4000	/* Run command with Simple attribute */
77 #define	FLAG_OTAG	0x2000	/* Run command with Ordered attribute */
78 #define	FLAG_HTAG	0x1000	/* Run command with Head of Queue attribute */
79 #define	FLAG_TAGMASK	(FLAG_HTAG|FLAG_OTAG|FLAG_STAG)
80 
81 #define	FLAG_ACA	0x0100	/* Run command with ACA attribute */
82 #define	FLAG_HEAD	0x8000	/* This cmd should be put at the head	*/
83 				/* of the HBA driver's queue		*/
84 #define	FLAG_SENSING	0x0400	/* Running request sense for failed pkt */
85 #define	FLAG_NOINTR	0x0001	/* Run command with no cmd completion	*/
86 				/* callback; command has been completed	*/
87 				/* upon	return from scsi_transport(9F)	*/
88 
89 /*
90  * Following defines are appropriate for SCSI parallel bus.
91  */
92 #define	FLAG_NODISCON	0x0002	/* Run command without disconnects	*/
93 #define	FLAG_NOPARITY	0x0008	/* Run command without parity checking	*/
94 #define	FLAG_RENEGOTIATE_WIDE_SYNC \
95 			0x1000000 /* Do wide and sync renegotiation before */
96 				/* transporting this command to target */
97 
98 /*
99  * Following defines are internal i.e. not part of DDI.
100  */
101 #define	FLAG_SUBLUN	0x0004	/* Use the sublun field in pkt_address	*/
102 #define	FLAG_QUEHOLD	0x0200	/* Don't advance HA que until cmd completes */
103 #define	FLAG_IMMEDIATE_CB \
104 			0x0800	/* Immediate callback on command */
105 				/* completion, ie. do not defer */
106 
107 
108 /*
109  * Following defines are for USCSI options.
110  */
111 #define	FLAG_SILENT	0x00010000
112 #define	FLAG_DIAGNOSE	0x00020000
113 #define	FLAG_ISOLATE	0x00040000
114 
115 /*
116  * Following define is for scsi_vhci.
117  * If pHCI cannot transport the command to the device, do not queue the pkt
118  * in pHCI. Return immediately with TRAN_BUSY.
119  */
120 #define	FLAG_NOQUEUE	0x80000000
121 
122 /*
123  * Definitions for the pkt_reason field.
124  */
125 
126 /*
127  * Following defines are generic.
128  */
129 #define	CMD_CMPLT	0	/* no transport errors- normal completion */
130 #define	CMD_INCOMPLETE	1	/* transport stopped with not normal state */
131 #define	CMD_DMA_DERR	2	/* dma direction error occurred */
132 #define	CMD_TRAN_ERR	3	/* unspecified transport error */
133 #define	CMD_RESET	4	/* Target completed hard reset sequence */
134 #define	CMD_ABORTED	5	/* Command transport aborted on request */
135 #define	CMD_TIMEOUT	6	/* Command timed out */
136 #define	CMD_DATA_OVR	7	/* Data Overrun */
137 #define	CMD_CMD_OVR	8	/* Command Overrun */
138 #define	CMD_STS_OVR	9	/* Status Overrun */
139 #define	CMD_TERMINATED	22	/* Command transport terminated on request */
140 
141 /*
142  * Following defines are appropriate for SCSI parallel bus.
143  */
144 #define	CMD_BADMSG	10	/* Message not Command Complete */
145 #define	CMD_NOMSGOUT	11	/* Target refused to go to Message Out phase */
146 #define	CMD_XID_FAIL	12	/* Extended Identify message rejected */
147 #define	CMD_IDE_FAIL	13	/* Initiator Detected Error message rejected */
148 #define	CMD_ABORT_FAIL	14	/* Abort message rejected */
149 #define	CMD_REJECT_FAIL 15	/* Reject message rejected */
150 #define	CMD_NOP_FAIL	16	/* No Operation message rejected */
151 #define	CMD_PER_FAIL	17	/* Message Parity Error message rejected */
152 #define	CMD_BDR_FAIL	18	/* Bus Device Reset message rejected */
153 #define	CMD_ID_FAIL	19	/* Identify message rejected */
154 #define	CMD_UNX_BUS_FREE	20	/* Unexpected Bus Free Phase occurred */
155 #define	CMD_TAG_REJECT	21	/* Target rejected our tag message */
156 #define	CMD_DEV_GONE	24	/* The device has been removed */
157 
158 /* Used by scsi_rname(9F) */
159 #define	CMD_REASON_ASCII	{ \
160 	    "cmplt", "incomplete", "dma_derr", "tran_err", "reset", \
161 	    "aborted", "timeout", "data_ovr", "cmd_ovr", "sts_ovr", \
162 	    "badmsg", "nomsgout", "xid_fail", "ide_fail", "abort_fail", \
163 	    "reject_fail", "nop_fail", "per_fail", "bdr_fail", "id_fail", \
164 	    "unexpected_bus_free", "tag reject", "terminated", "", "gone", \
165 	    NULL }
166 
167 /*
168  * Definitions for the pkt_state field
169  */
170 #define	STATE_GOT_BUS		0x01	/* Success in getting SCSI bus */
171 #define	STATE_GOT_TARGET	0x02	/* Successfully connected with target */
172 #define	STATE_SENT_CMD		0x04	/* Command successfully sent */
173 #define	STATE_XFERRED_DATA	0x08	/* Data transfer took place */
174 #define	STATE_GOT_STATUS	0x10	/* SCSI status received */
175 #define	STATE_ARQ_DONE		0x20	/* auto rqsense took place */
176 
177 /*
178  * Definitions for the pkt_statistics field
179  */
180 
181 /*
182  * Following defines are generic.
183  */
184 #define	STAT_BUS_RESET	0x8	/* Reset operation on interconnect */
185 #define	STAT_DEV_RESET	0x10	/* Target completed hard reset sequence */
186 #define	STAT_ABORTED	0x20	/* Command was aborted */
187 #define	STAT_TERMINATED	0x80	/* Command was terminated */
188 #define	STAT_TIMEOUT	0x40	/* Command experienced a timeout */
189 
190 /*
191  * Following defines are appropriate for SCSI parallel bus.
192  */
193 #define	STAT_DISCON	0x1	/* Command experienced a disconnect */
194 #define	STAT_SYNC	0x2	/* Command did a synchronous data transfer */
195 #define	STAT_PERR	0x4	/* Command experienced a SCSI parity error */
196 
197 /*
198  * Definitions for what scsi_transport returns
199  */
200 #define	TRAN_ACCEPT		1
201 #define	TRAN_BUSY		0
202 #define	TRAN_BADPKT		-1
203 #define	TRAN_FATAL_ERROR	-2	/* HBA cannot accept any pkts */
204 
205 #ifdef	_KERNEL
206 /*
207  * Kernel function declarations
208  */
209 int	scsi_transport(struct scsi_pkt *pkt);
210 
211 #define	pkt_transport	scsi_transport
212 
213 #define	SCSI_POLL_TIMEOUT	60
214 
215 #endif	/* _KERNEL */
216 
217 #ifdef	__cplusplus
218 }
219 #endif
220 
221 #endif	/* _SYS_SCSI_SCSI_PKT_H */
222