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