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