xref: /freebsd/sys/dev/isp/isp_stds.h (revision 71625ec9)
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause
3  *
4  *  Copyright (c) 1997-2009 by Matthew Jacob
5  *  All rights reserved.
6  *
7  *  Redistribution and use in source and binary forms, with or without
8  *  modification, are permitted provided that the following conditions
9  *  are met:
10  *
11  *  1. Redistributions of source code must retain the above copyright
12  *     notice, this list of conditions and the following disclaimer.
13  *  2. Redistributions in binary form must reproduce the above copyright
14  *     notice, this list of conditions and the following disclaimer in the
15  *     documentation and/or other materials provided with the distribution.
16  *
17  *  THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18  *  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  *  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  *  ARE DISCLAIMED.  IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
21  *  FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  *  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23  *  OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24  *  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25  *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26  *  OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27  *  SUCH DAMAGE.
28  *
29  */
30 /*
31  * Structures that derive directly from public standards.
32  */
33 #ifndef	_ISP_STDS_H
34 #define	_ISP_STDS_H
35 /*
36  * FC Frame Header
37  *
38  * Source: dpANS-X3.xxx-199x, section 18 (AKA FC-PH-2)
39  *
40  */
41 typedef struct {
42 	uint8_t		r_ctl;
43 	uint8_t		d_id[3];
44 	uint8_t		cs_ctl;
45 	uint8_t		s_id[3];
46 	uint8_t		type;
47 	uint8_t		f_ctl[3];
48 	uint8_t		seq_id;
49 	uint8_t		df_ctl;
50 	uint16_t	seq_cnt;
51 	uint16_t	ox_id;
52 	uint16_t	rx_id;
53 	uint32_t	parameter;
54 } fc_hdr_t;
55 
56 /*
57  * FCP_CMND_IU Payload
58  *
59  * Source: NICTS T10, Project 1144D, Revision 07a, Section 9 (AKA fcp2-r07a)
60  *
61  * Notes:
62  *	When additional cdb length is defined in fcp_cmnd_alen_datadir,
63  * 	bits 2..7, the actual cdb length is 16 + ((fcp_cmnd_alen_datadir>>2)*4),
64  *	with the datalength following in MSB format just after.
65  */
66 typedef struct {
67 	uint8_t		fcp_cmnd_lun[8];
68 	uint8_t		fcp_cmnd_crn;
69 	uint8_t		fcp_cmnd_task_attribute;
70 	uint8_t		fcp_cmnd_task_management;
71 	uint8_t		fcp_cmnd_alen_datadir;
72 	union {
73 		struct {
74 			uint8_t		fcp_cmnd_cdb[16];
75 			uint32_t	fcp_cmnd_dl;
76 		} sf;
77 		struct {
78 			uint8_t		fcp_cmnd_cdb[1];
79 		} lf;
80 	} cdb_dl;
81 } fcp_cmnd_iu_t;
82 
83 
84 #define	FCP_CMND_TASK_ATTR_SIMPLE	0x00
85 #define	FCP_CMND_TASK_ATTR_HEAD		0x01
86 #define	FCP_CMND_TASK_ATTR_ORDERED	0x02
87 #define	FCP_CMND_TASK_ATTR_ACA		0x04
88 #define	FCP_CMND_TASK_ATTR_UNTAGGED	0x05
89 #define	FCP_CMND_TASK_ATTR_MASK		0x07
90 
91 #define	FCP_CMND_PRIO_MASK		0x78
92 #define	FCP_CMND_PRIO_SHIFT		3
93 
94 #define	FCP_CMND_ADDTL_CDBLEN_SHIFT	2
95 
96 #define	FCP_CMND_DATA_WRITE		0x01
97 #define	FCP_CMND_DATA_READ		0x02
98 
99 #define	FCP_CMND_DATA_DIR_MASK		0x03
100 
101 #define	FCP_CMND_TMF_CLEAR_ACA		0x40
102 #define	FCP_CMND_TMF_TGT_RESET		0x20
103 #define	FCP_CMND_TMF_LUN_RESET		0x10
104 #define	FCP_CMND_TMF_QUERY_ASYNC_EVENT	0x08
105 #define	FCP_CMND_TMF_CLEAR_TASK_SET	0x04
106 #define	FCP_CMND_TMF_ABORT_TASK_SET	0x02
107 #define	FCP_CMND_TMF_QUERY_TASK_SET	0x01
108 
109 /*
110  * Basic CT IU Header
111  *
112  * Source: X3.288-199x Generic Services 2 Rev 5.3 (FC-GS-2) Section 4.3.1
113  */
114 
115 typedef struct {
116 	uint8_t		ct_revision;
117 	uint8_t		ct_in_id[3];
118 	uint8_t		ct_fcs_type;
119 	uint8_t		ct_fcs_subtype;
120 	uint8_t		ct_options;
121 	uint8_t		ct_reserved0;
122 	uint16_t	ct_cmd_resp;
123 	uint16_t	ct_bcnt_resid;
124 	uint8_t		ct_reserved1;
125 	uint8_t		ct_reason;
126 	uint8_t		ct_explanation;
127 	uint8_t		ct_vunique;
128 } ct_hdr_t;
129 #define	CT_REVISION		1
130 #define	CT_FC_TYPE_FC		0xFC
131 #define CT_FC_SUBTYPE_NS	0x02
132 
133 /*
134  * RFT_ID Requet CT_IU
135  *
136  * Source: NCITS xxx-200x Generic Services- 5 Rev 8.5 Section 5.2.5.30
137  */
138 typedef struct {
139 	ct_hdr_t	rftid_hdr;
140 	uint8_t		rftid_reserved;
141 	uint8_t		rftid_portid[3];
142 	uint32_t	rftid_fc4types[8];
143 } rft_id_t;
144 
145 /*
146  * RSPN_ID Requet CT_IU
147  *
148  * Source: INCITS 463-2010 Generic Services 6 Section 5.2.5.32
149  */
150 typedef struct {
151 	ct_hdr_t	rspnid_hdr;
152 	uint8_t		rspnid_reserved;
153 	uint8_t		rspnid_portid[3];
154 	uint8_t		rspnid_length;
155 	uint8_t		rspnid_name[0];
156 } rspn_id_t;
157 
158 /*
159  * RFF_ID Requet CT_IU
160  *
161  * Source: INCITS 463-2010 Generic Services 6 Section 5.2.5.34
162  */
163 typedef struct {
164 	ct_hdr_t	rffid_hdr;
165 	uint8_t		rffid_reserved;
166 	uint8_t		rffid_portid[3];
167 	uint16_t	rffid_reserved2;
168 	uint8_t		rffid_fc4features;
169 	uint8_t		rffid_fc4type;
170 } rff_id_t;
171 
172 /*
173  * RSNN_NN Requet CT_IU
174  *
175  * Source: INCITS 463-2010 Generic Services 6 Section 5.2.5.35
176  */
177 typedef struct {
178 	ct_hdr_t	rsnnnn_hdr;
179 	uint8_t		rsnnnn_nodename[8];
180 	uint8_t		rsnnnn_length;
181 	uint8_t		rsnnnn_name[0];
182 } rsnn_nn_t;
183 
184 /*
185  * FCP Response IU and bits of interest
186  * Source: NCITS T10, Project 1828D, Revision 02b (aka FCP4r02b)
187  */
188 typedef struct {
189 	uint8_t		fcp_rsp_reserved[8];
190 	uint16_t	fcp_rsp_status_qualifier;	/* SAM-5 Status Qualifier */
191 	uint8_t		fcp_rsp_bits;
192 	uint8_t		fcp_rsp_scsi_status;		/* SAM-5 SCSI Status Byte */
193 	uint32_t	fcp_rsp_resid;
194 	uint32_t	fcp_rsp_snslen;
195 	uint32_t	fcp_rsp_rsplen;
196 	/*
197 	 * In the bytes that follow, it's going to be
198 	 * FCP RESPONSE INFO (max 8 bytes, possibly 0)
199 	 * FCP SENSE INFO (if any)
200 	 * FCP BIDIRECTIONAL READ RESID (if any)
201 	 */
202 	uint8_t		fcp_rsp_extra[0];
203 } fcp_rsp_iu_t;
204 #define	MIN_FCP_RESPONSE_SIZE		24
205 
206 #define	FCP_BIDIR_RSP			0x80	/* Bi-Directional response */
207 #define	FCP_BIDIR_RESID_UNDERFLOW	0x40
208 #define	FCP_BIDIR_RESID_OVERFLOW	0x20
209 #define	FCP_CONF_REQ			0x10
210 #define	FCP_RESID_UNDERFLOW		0x08
211 #define	FCP_RESID_OVERFLOW		0x04
212 #define	FCP_SNSLEN_VALID		0x02
213 #define	FCP_RSPLEN_VALID		0x01
214 
215 #define FCP_MAX_RSPLEN			0x08
216 /*
217  * FCP Response Code Definitions
218  * Source: NCITS T10, Project 1144D, Revision 08 (aka FCP2r08)
219  */
220 #define	FCP_RSPNS_CODE_OFFSET		3
221 
222 #define	FCP_RSPNS_TMF_DONE		0
223 #define	FCP_RSPNS_DLBRSTX		1
224 #define	FCP_RSPNS_BADCMND		2
225 #define	FCP_RSPNS_EROFS			3
226 #define	FCP_RSPNS_TMF_REJECT		4
227 #define	FCP_RSPNS_TMF_FAILED		5
228 #define	FCP_RSPNS_TMF_SUCCEEDED		8
229 #define	FCP_RSPNS_TMF_INCORRECT_LUN	9
230 
231 /*
232  * R_CTL field definitions
233  *
234  * Bits 31-28 are ROUTING
235  * Bits 27-24 are INFORMATION
236  *
237  * These are nibble values, not bits
238  */
239 #define	R_CTL_ROUTE_DATA	0x00
240 #define	R_CTL_ROUTE_ELS		0x02
241 #define	R_CTL_ROUTE_FC4_LINK	0x03
242 #define	R_CTL_ROUTE_VDATA	0x04
243 #define	R_CTL_ROUTE_EXENDED	0x05
244 #define	R_CTL_ROUTE_BASIC	0x08
245 #define	R_CTL_ROUTE_LINK	0x0c
246 #define	R_CTL_ROUTE_EXT_ROUTING	0x0f
247 
248 #define	R_CTL_INFO_UNCATEGORIZED	0x00
249 #define	R_CTL_INFO_SOLICITED_DATA	0x01
250 #define	R_CTL_INFO_UNSOLICITED_CONTROL	0x02
251 #define	R_CTL_INFO_SOLICITED_CONTROL	0x03
252 #define	R_CTL_INFO_UNSOLICITED_DATA	0x04
253 #define	R_CTL_INFO_DATA_DESCRIPTOR	0x05
254 #define	R_CTL_INFO_UNSOLICITED_COMMAND	0x06
255 #define	R_CTL_INFO_COMMAND_STATUS	0x07
256 
257 #define	MAKE_RCTL(a, b)	(((a) << 4) | (b))
258 
259 /* unconverted miscellany */
260 /*
261  * Basic FC Link Service defines
262  */
263 /* #define	ABTS	MAKE_RCTL(R_CTL_ROUTE_BASIC, R_CTL_INFO_SOLICITED_DATA) */
264 #define	BA_ACC	MAKE_RCTL(R_CTL_ROUTE_BASIC, R_CTL_INFO_UNSOLICITED_DATA)	/* of ABORT */
265 #define	BA_RJT	MAKE_RCTL(R_CTL_ROUTE_BASIC, R_CTL_INFO_DATA_DESCRIPTOR)	/* of ABORT */
266 
267 /*
268  * Link Service Accept/Reject
269  */
270 #define	LS_ACC			0x8002
271 #define	LS_RJT			0x8001
272 
273 /*
274  * FC ELS Codes- bits 31-24 of the first payload word of an ELS frame.
275  */
276 #define	PLOGI			0x03
277 #define	FLOGI			0x04
278 #define	LOGO			0x05
279 #define	ABTX			0x06
280 #define	PRLI			0x20
281 #define	PRLO			0x21
282 #define	SCN			0x22
283 #define	TPRLO			0x24
284 #define	PDISC			0x50
285 #define	ADISC			0x52
286 #define	RNC			0x53
287 
288 /*
289  * PRLI Word 0 definitions
290  * FPC4-r02b January, 2011
291  */
292 #define	PRLI_WD0_TYPE_MASK				0xff000000
293 #define	PRLI_WD0_TC_EXT_MASK				0x00ff0000
294 #define	PRLI_WD0_EST_IMAGE_PAIR				(1 << 13)
295 
296 /*
297  * PRLI Word 3 definitions
298  * FPC4-r02b January, 2011
299  */
300 #define	PRLI_WD3_ENHANCED_DISCOVERY			(1 << 11)
301 #define	PRLI_WD3_REC_SUPPORT				(1 << 10)
302 #define	PRLI_WD3_TASK_RETRY_IDENTIFICATION_REQUESTED	(1 << 9)
303 #define	PRLI_WD3_RETRY					(1 << 8)
304 #define	PRLI_WD3_CONFIRMED_COMPLETION_ALLOWED		(1 << 7)
305 #define	PRLI_WD3_DATA_OVERLAY_ALLOWED			(1 << 6)
306 #define	PRLI_WD3_INITIATOR_FUNCTION			(1 << 5)
307 #define	PRLI_WD3_TARGET_FUNCTION			(1 << 4)
308 #define	PRLI_WD3_READ_FCP_XFER_RDY_DISABLED		(1 << 1)	/* definitely supposed to be set */
309 #define	PRLI_WD3_WRITE_FCP_XFER_RDY_DISABLED		(1 << 0)
310 
311 
312 
313 /*
314  * FC4 defines
315  */
316 #define	FC4_IP		5	/* ISO/EEC 8802-2 LLC/SNAP */
317 #define	FC4_SCSI	8	/* SCSI-3 via Fibre Channel Protocol (FCP) */
318 #define	FC4_FC_SVC	0x20	/* Fibre Channel Services */
319 
320 #ifndef	MSG_ABORT
321 #define	MSG_ABORT		0x06
322 #endif
323 #ifndef	MSG_BUS_DEV_RESET
324 #define	MSG_BUS_DEV_RESET	0x0c
325 #endif
326 #ifndef	MSG_ABORT_TAG
327 #define	MSG_ABORT_TAG		0x0d
328 #endif
329 #ifndef	MSG_CLEAR_QUEUE
330 #define	MSG_CLEAR_QUEUE		0x0e
331 #endif
332 #ifndef	MSG_REL_RECOVERY
333 #define	MSG_REL_RECOVERY	0x10
334 #endif
335 #ifndef	MSG_TERM_IO_PROC
336 #define	MSG_TERM_IO_PROC	0x11
337 #endif
338 #ifndef	MSG_LUN_RESET
339 #define	MSG_LUN_RESET		0x17
340 #endif
341 
342 #endif	/* _ISP_STDS_H */
343