xref: /freebsd/sys/dev/isp/isp_stds.h (revision d139ce67c0b39ab6532275f7baff67d220fe8001)
1 /* $FreeBSD$ */
2 /*-
3  * Mailbox and Queue Entry Definitions for for Qlogic ISP SCSI adapters.
4  *
5  * Copyright (c) 1997-2006 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  * 1. Redistributions of source code must retain the above copyright
12  *    notice immediately at the beginning of the file, without modification,
13  *    this list of conditions, and the following disclaimer.
14  * 2. The name of the author may not be used to endorse or promote products
15  *    derived from this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE 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 THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
21  * 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 /*
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;
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_ADDTL_CDBLEN_SHIFT	2
93 
94 #define	FCP_CMND_DATA_WRITE		0x01
95 #define	FCP_CMND_DATA_READ		0x02
96 
97 #define	FCP_CMND_DATA_DIR_MASK		0x03
98 
99 #define	FCP_CMND_TMF_CLEAR_ACA		0x40
100 #define	FCP_CMND_TMF_TGT_RESET		0x20
101 #define	FCP_CMND_TMF_LUN_RESET		0x10
102 #define	FCP_CMND_TMF_CLEAR_TASK_SET	0x04
103 #define	FCP_CMND_TMF_ABORT_TASK_SET	0x02
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 
111 typedef 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  */
134 typedef 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  * FCP Response Code Definitions
143  * Source: NCITS T10, Project 1144D, Revision 07a (aka FCP2r07a)
144  */
145 #define	FCP_RSPNS_CODE_OFFSET		3
146 
147 #define	FCP_RSPNS_TMF_DONE		0
148 #define	FCP_RSPNS_DLBRSTX		1
149 #define	FCP_RSPNS_BADCMND		2
150 #define	FCP_RSPNS_EROFS			3
151 #define	FCP_RSPNS_TMF_REJECT		4
152 #define	FCP_RSPNS_TMF_FAILED		5
153 
154 
155 /* unconverted miscellany */
156 /*
157  * Basic FC Link Service defines
158  */
159 /*
160  * These are in the R_CTL field.
161  */
162 #define	ABTS			0x81
163 #define	BA_ACC			0x84	/* of ABORT SEQUENCE */
164 #define	BA_RJT			0x85	/* of ABORT SEQUENCE */
165 
166 /*
167  * Link Service Accept/Reject
168  */
169 #define	LS_ACC			0x8002
170 #define	LS_RJT			0x8001
171 
172 /*
173  * FC ELS Codes- bits 31-24 of the first payload word of an ELS frame.
174  */
175 #define	PLOGI			0x03
176 #define	FLOGI			0x04
177 #define	LOGO			0x05
178 #define	ABTX			0x06
179 #define	PRLI			0x20
180 #define	PRLO			0x21
181 #define	TPRLO			0x24
182 #define	RNC			0x53
183 
184 /*
185  * FC4 defines
186  */
187 #define	FC4_IP		5	/* ISO/EEC 8802-2 LLC/SNAP */
188 #define	FC4_SCSI	8	/* SCSI-3 via Fibre Channel Protocol (FCP) */
189 #define	FC4_FC_SVC	0x20	/* Fibre Channel Services */
190 
191 #ifndef	MSG_ABORT
192 #define	MSG_ABORT		0x06
193 #endif
194 #ifndef	MSG_BUS_DEV_RESET
195 #define	MSG_BUS_DEV_RESET	0x0c
196 #endif
197 #ifndef	MSG_ABORT_TAG
198 #define	MSG_ABORT_TAG		0x0d
199 #endif
200 #ifndef	MSG_CLEAR_QUEUE
201 #define	MSG_CLEAR_QUEUE		0x0e
202 #endif
203 #ifndef	MSG_REL_RECOVERY
204 #define	MSG_REL_RECOVERY	0x10
205 #endif
206 #ifndef	MSG_TERM_IO_PROC
207 #define	MSG_TERM_IO_PROC	0x11
208 #endif
209 #ifndef	MSG_LUN_RESET
210 #define	MSG_LUN_RESET		0x17
211 #endif
212 
213 #endif	/* _ISP_STDS_H */
214