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