xref: /titanic_44/usr/src/uts/common/sys/fibre-channel/ulp/fcp.h (revision da14cebe459d3275048785f25bd869cb09b5307f)
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 #ifndef	_FCP_H
27 #define	_FCP_H
28 
29 
30 /*
31  * Frame format and protocol definitions for transferring
32  * commands and data between a SCSI initiator and target
33  * using an FC4 serial link interface.
34  *
35  * this file originally taken from fc4/fcp.h
36  */
37 
38 #ifdef	__cplusplus
39 extern "C" {
40 #endif
41 
42 #include <sys/types.h>
43 
44 
45 /*
46  * FCP Device Data Frame Information Categories
47  */
48 #define	FCP_SCSI_DATA		0x01	/* frame contains SCSI data */
49 #define	FCP_SCSI_CMD		0x02	/* frame contains SCSI command */
50 #define	FCP_SCSI_RSP		0x03	/* frame contains SCSI response */
51 #define	FCP_SCSI_XFER_RDY	0x05	/* frame contains xfer rdy block */
52 
53 
54 /*
55  * fcp SCSI control structure
56  */
57 typedef struct fcp_cntl {
58 
59 	uchar_t	cntl_reserved_0;		/* reserved */
60 
61 #if	defined(_BIT_FIELDS_HTOL)
62 
63 	uchar_t	cntl_reserved_1	: 5,		/* reserved */
64 		cntl_qtype	: 3;		/* tagged queueing type */
65 
66 	uchar_t	cntl_kill_tsk	: 1,		/* terminate task */
67 		cntl_clr_aca	: 1,		/* clear aca */
68 		cntl_reset_tgt	: 1,		/* reset target */
69 		cntl_reset_lun	: 1,		/* reset lun */
70 		cntl_reserved_2	: 1,		/* reserved */
71 		cntl_clr_tsk	: 1,		/* clear task set */
72 		cntl_abort_tsk	: 1,		/* abort task set */
73 		cntl_reserved_3	: 1;		/* reserved */
74 
75 	uchar_t	cntl_reserved_4	: 6,		/* reserved */
76 		cntl_read_data	: 1,		/* initiator read */
77 		cntl_write_data	: 1;		/* initiator write */
78 
79 #elif	defined(_BIT_FIELDS_LTOH)
80 
81 	uchar_t	cntl_qtype	: 3,		/* tagged queueing type */
82 		cntl_reserved_1	: 5;		/* reserved */
83 
84 	uchar_t	cntl_reserved_3	: 1,		/* reserved */
85 		cntl_abort_tsk	: 1,		/* abort task set */
86 		cntl_clr_tsk	: 1,		/* clear task set */
87 		cntl_reserved_2	: 1,		/* reserved */
88 		cntl_reset_lun	: 1,		/* reset lun */
89 		cntl_reset_tgt	: 1,		/* reset target */
90 		cntl_clr_aca	: 1,		/* clear aca */
91 		cntl_kill_tsk	: 1;		/* terminate task */
92 
93 	uchar_t	cntl_write_data	: 1,		/* initiator write */
94 		cntl_read_data	: 1,		/* initiator read */
95 		cntl_reserved_4	: 6;		/* reserved */
96 
97 #else
98 #error	one of _BIT_FIELDS_HTOL or _BIT_FIELDS_LTOH must be defined
99 #endif
100 
101 } fcp_cntl_t;
102 
103 /*
104  * fcp SCSI control tagged queueing types - cntl_qtype
105  */
106 #define	FCP_QTYPE_SIMPLE	0		/* simple queueing */
107 #define	FCP_QTYPE_HEAD_OF_Q	1		/* head of queue */
108 #define	FCP_QTYPE_ORDERED	2		/* ordered queueing */
109 #define	FCP_QTYPE_ACA_Q_TAG	4		/* ACA queueing */
110 #define	FCP_QTYPE_UNTAGGED	5		/* Untagged */
111 
112 
113 /*
114  * fcp SCSI entity address
115  *
116  * ent_addr_0 is always the first and highest layer of
117  * the hierarchy.  The depth of the hierarchy of addressing,
118  * up to a maximum of four layers, is arbitrary and
119  * device-dependent.
120  */
121 typedef struct fcp_ent_addr {
122 	ushort_t ent_addr_0;		/* entity address 0 */
123 	ushort_t ent_addr_1;		/* entity address 1 */
124 	ushort_t ent_addr_2;		/* entity address 2 */
125 	ushort_t ent_addr_3;		/* entity address 3 */
126 } fcp_ent_addr_t;
127 
128 
129 /*
130  * maximum size of SCSI cdb in fcp SCSI command
131  */
132 #define	FCP_CDB_SIZE		16
133 #define	FCP_LUN_SIZE		8
134 #define	FCP_LUN_HEADER		8
135 
136 /*
137  * FCP SCSI command payload
138  */
139 typedef struct fcp_cmd {
140 	fcp_ent_addr_t	fcp_ent_addr;			/* entity address */
141 	fcp_cntl_t	fcp_cntl;			/* SCSI options */
142 	uchar_t		fcp_cdb[FCP_CDB_SIZE];		/* SCSI cdb */
143 	int		fcp_data_len;			/* data length */
144 } fcp_cmd_t;
145 
146 
147 /*
148  * fcp SCSI status
149  */
150 typedef struct fcp_status {
151 	ushort_t reserved_0;			/* reserved */
152 
153 #if	defined(_BIT_FIELDS_HTOL)
154 
155 	uchar_t	reserved_1	: 4,		/* reserved */
156 		resid_under	: 1,		/* resid non-zero */
157 		resid_over	: 1,		/* resid non-zero */
158 		sense_len_set	: 1,		/* sense_len non-zero */
159 		rsp_len_set	: 1;		/* response_len non-zero */
160 
161 #elif	defined(_BIT_FIELDS_LTOH)
162 
163 	uchar_t	rsp_len_set	: 1,		/* response_len non-zero */
164 		sense_len_set	: 1,		/* sense_len non-zero */
165 		resid_over	: 1,		/* resid non-zero */
166 		resid_under	: 1,		/* resid non-zero */
167 		reserved_1	: 4;		/* reserved */
168 
169 #endif
170 	uchar_t	scsi_status;			/* status of cmd */
171 } fcp_status_t;
172 
173 
174 /*
175  * fcp SCSI response payload
176  */
177 typedef struct fcp_rsp {
178 	uint32_t	reserved_0;			/* reserved */
179 	uint32_t	reserved_1;			/* reserved */
180 	union {
181 		fcp_status_t	fcp_status;		/* command status */
182 		uint32_t	i_fcp_status;
183 	} fcp_u;
184 	uint32_t	fcp_resid;		/* resid of operation */
185 	uint32_t	fcp_sense_len;		/* sense data length */
186 	uint32_t	fcp_response_len;	/* response data length */
187 	/*
188 	 * 'm' bytes of scsi response info follow
189 	 * 'n' bytes of scsi sense info follow
190 	 */
191 } fcp_rsp_t;
192 
193 
194 /* MAde 256 for sonoma as it wants to give tons of sense info */
195 #define	FCP_MAX_RSP_IU_SIZE	256
196 
197 
198 /*
199  * fcp rsp_info field format
200  */
201 struct fcp_rsp_info {
202 	uchar_t		resvd1;
203 	uchar_t		resvd2;
204 	uchar_t		resvd3;
205 	uchar_t		rsp_code;
206 	uchar_t		resvd4;
207 	uchar_t		resvd5;
208 	uchar_t		resvd6;
209 	uchar_t		resvd7;
210 };
211 
212 /*
213  * rsp_code definitions
214  */
215 #define		FCP_NO_FAILURE			0x0
216 #define		FCP_DL_LEN_MISMATCH		0x1
217 #define		FCP_CMND_INVALID		0x2
218 #define		FCP_DATA_RO_MISMATCH		0x3
219 #define		FCP_TASK_MGMT_NOT_SUPPTD	0x4
220 #define		FCP_TASK_MGMT_FAILED		0x5
221 
222 
223 #ifdef	THIS_NEEDED_YET
224 
225 /*
226  * fcp scsi_xfer_rdy payload
227  */
228 typedef struct fcp_xfer_rdy {
229 	ulong64_t	fcp_seq_offset;		/* relative offset */
230 	ulong64_t	fcp_burst_len;		/* buffer space */
231 	ulong64_t	reserved;		/* reserved */
232 } fcp_xfer_rdy_t;
233 
234 #endif	/* THIS_NEEDED_YET */
235 
236 /*
237  * fcp PRLI payload
238  */
239 struct fcp_prli {
240 	uchar_t		type;
241 	uchar_t		resvd1;			/* rsvd by std */
242 
243 #if	defined(_BIT_FIELDS_HTOL)
244 
245 	uint16_t	orig_process_assoc_valid : 1,
246 			resp_process_assoc_valid : 1,
247 			establish_image_pair : 1,
248 			resvd2 : 13;		/* rsvd by std */
249 
250 #elif	defined(_BIT_FIELDS_LTOH)
251 
252 	uint16_t	resvd2 : 13,		/* rsvd by std */
253 			establish_image_pair : 1,
254 			resp_process_assoc_valid : 1,
255 			orig_process_assoc_valid : 1;
256 
257 #endif
258 
259 	uint32_t	orig_process_associator;
260 	uint32_t	resp_process_associator;
261 
262 #if	defined(_BIT_FIELDS_HTOL)
263 
264 	uint32_t	resvd3 : 23,		/* rsvd by std */
265 			retry : 1,
266 			confirmed_compl_allowed : 1,
267 			data_overlay_allowed : 1,
268 			initiator_fn : 1,
269 			target_fn : 1,
270 			obsolete_2 : 1,
271 			obsolete_1 : 1,
272 			read_xfer_rdy_disabled : 1,
273 			write_xfer_rdy_disabled : 1;
274 
275 #elif	defined(_BIT_FIELDS_LTOH)
276 
277 	uint32_t	write_xfer_rdy_disabled : 1,
278 			read_xfer_rdy_disabled : 1,
279 			obsolete_1 : 1,
280 			obsolete_2 : 1,
281 			target_fn : 1,
282 			initiator_fn : 1,
283 			data_overlay_allowed : 1,
284 			confirmed_compl_allowed : 1,
285 			retry : 1,
286 			resvd3 : 23;		/* rsvd by std */
287 
288 #endif
289 
290 };
291 
292 
293 /*
294  * fcp PRLI ACC payload
295  */
296 struct fcp_prli_acc {
297 	uchar_t		type;
298 	uchar_t		resvd1;
299 
300 	uint32_t	orig_process_assoc_valid : 1;
301 	uint32_t	resp_process_assoc_valid : 1;
302 	uint32_t	image_pair_established : 1;
303 	uint32_t	resvd2 : 1;
304 	uint32_t	accept_response_code : 4;
305 	uint32_t	resvd3 : 8;
306 	uint32_t	orig_process_associator;
307 	uint32_t	resp_process_associator;
308 	uint32_t	resvd4 : 26;
309 	uint32_t	initiator_fn : 1;
310 	uint32_t	target_fn : 1;
311 	uint32_t	cmd_data_mixed : 1;
312 	uint32_t	data_resp_mixed : 1;
313 	uint32_t	read_xfer_rdy_disabled : 1;
314 	uint32_t	write_xfer_rdy_disabled : 1;
315 
316 };
317 
318 
319 #define	FC_UB_FCP_CDB_FLAG	0x0001		/* UB has valid cdb */
320 #define	FC_UB_FCP_PORT_LOGOUT	0x0002		/* Port logout UB */
321 #define	FC_UB_FCP_ABORT_TASK	0x0004		/* Abort task UB */
322 #define	FC_UB_FCP_BUS_RESET	0x0008		/* Bus reset UB */
323 #define	FC_UB_FCP_CMD_DONE	0x8000		/* Work on this UB is done */
324 
325 #define	FC_UB_FCP_OOB_CMD	(FC_UB_FCP_PORT_LOGOUT | FC_UB_FCP_ABORT_TASK \
326 	| FC_UB_FCP_BUS_RESET)			/* Out-of-band traget cmds */
327 
328 
329 #if !defined(__lint)
330 _NOTE(SCHEME_PROTECTS_DATA("Unshared Data",
331     fcp_cmd
332     fcp_rsp
333     fcp_prli))
334 #endif /* __lint */
335 
336 /*
337  * FC4 type setttings for Name Server registration.
338  */
339 #define	FC4_TYPE_WORD_POS(x)	((uchar_t)(x) >> 5)
340 #define	FC4_TYPE_BIT_POS(x)	((uchar_t)(x) & 0x1F)
341 
342 #ifdef	__cplusplus
343 }
344 #endif
345 
346 #endif	/* _FCP_H */
347