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