xref: /openbmc/linux/include/uapi/scsi/fc/fc_fs.h (revision e657c18a)
1 /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
2 /*
3  * Copyright(c) 2007 Intel Corporation. All rights reserved.
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms and conditions of the GNU General Public License,
7  * version 2, as published by the Free Software Foundation.
8  *
9  * This program is distributed in the hope it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
12  * more details.
13  *
14  * You should have received a copy of the GNU General Public License along with
15  * this program; if not, write to the Free Software Foundation, Inc.,
16  * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
17  *
18  * Maintained at www.Open-FCoE.org
19  */
20 
21 #ifndef _FC_FS_H_
22 #define _FC_FS_H_
23 
24 #include <linux/types.h>
25 
26 /*
27  * Fibre Channel Framing and Signalling definitions.
28  * From T11 FC-FS-2 Rev 0.90 - 9 August 2005.
29  */
30 
31 /*
32  * Frame header
33  */
34 struct fc_frame_header {
35 	__u8          fh_r_ctl;	/* routing control */
36 	__u8          fh_d_id[3];	/* Destination ID */
37 
38 	__u8          fh_cs_ctl;	/* class of service control / pri */
39 	__u8          fh_s_id[3];	/* Source ID */
40 
41 	__u8          fh_type;		/* see enum fc_fh_type below */
42 	__u8          fh_f_ctl[3];	/* frame control */
43 
44 	__u8          fh_seq_id;	/* sequence ID */
45 	__u8          fh_df_ctl;	/* data field control */
46 	__be16        fh_seq_cnt;	/* sequence count */
47 
48 	__be16        fh_ox_id;		/* originator exchange ID */
49 	__be16        fh_rx_id;		/* responder exchange ID */
50 	__be32        fh_parm_offset;	/* parameter or relative offset */
51 };
52 
53 #define FC_FRAME_HEADER_LEN 24	/* expected length of structure */
54 
55 #define FC_MAX_PAYLOAD  2112U		/* max payload length in bytes */
56 #define FC_MIN_MAX_PAYLOAD  256U 	/* lower limit on max payload */
57 
58 #define FC_MAX_FRAME	(FC_MAX_PAYLOAD + FC_FRAME_HEADER_LEN)
59 #define FC_MIN_MAX_FRAME (FC_MIN_MAX_PAYLOAD + FC_FRAME_HEADER_LEN)
60 
61 /*
62  * fh_r_ctl - Routing control definitions.
63  */
64     /*
65      * FC-4 device_data.
66      */
67 enum fc_rctl {
68 	FC_RCTL_DD_UNCAT = 0x00,	/* uncategorized information */
69 	FC_RCTL_DD_SOL_DATA = 0x01,	/* solicited data */
70 	FC_RCTL_DD_UNSOL_CTL = 0x02,	/* unsolicited control */
71 	FC_RCTL_DD_SOL_CTL = 0x03,	/* solicited control or reply */
72 	FC_RCTL_DD_UNSOL_DATA = 0x04,	/* unsolicited data */
73 	FC_RCTL_DD_DATA_DESC = 0x05,	/* data descriptor */
74 	FC_RCTL_DD_UNSOL_CMD = 0x06,	/* unsolicited command */
75 	FC_RCTL_DD_CMD_STATUS = 0x07,	/* command status */
76 
77 #define FC_RCTL_ILS_REQ FC_RCTL_DD_UNSOL_CTL	/* ILS request */
78 #define FC_RCTL_ILS_REP FC_RCTL_DD_SOL_CTL	/* ILS reply */
79 
80 	/*
81 	 * Extended Link_Data
82 	 */
83 	FC_RCTL_ELS_REQ = 0x22,	/* extended link services request */
84 	FC_RCTL_ELS_REP = 0x23,	/* extended link services reply */
85 	FC_RCTL_ELS4_REQ = 0x32, /* FC-4 ELS request */
86 	FC_RCTL_ELS4_REP = 0x33, /* FC-4 ELS reply */
87 	/*
88 	 * Optional Extended Headers
89 	 */
90 	FC_RCTL_VFTH = 0x50,	/* virtual fabric tagging header */
91 	FC_RCTL_IFRH = 0x51,	/* inter-fabric routing header */
92 	FC_RCTL_ENCH = 0x52,	/* encapsulation header */
93 	/*
94 	 * Basic Link Services fh_r_ctl values.
95 	 */
96 	FC_RCTL_BA_NOP = 0x80,	/* basic link service NOP */
97 	FC_RCTL_BA_ABTS = 0x81,	/* basic link service abort */
98 	FC_RCTL_BA_RMC = 0x82,	/* remove connection */
99 	FC_RCTL_BA_ACC = 0x84,	/* basic accept */
100 	FC_RCTL_BA_RJT = 0x85,	/* basic reject */
101 	FC_RCTL_BA_PRMT = 0x86,	/* dedicated connection preempted */
102 	/*
103 	 * Link Control Information.
104 	 */
105 	FC_RCTL_ACK_1 = 0xc0,	/* acknowledge_1 */
106 	FC_RCTL_ACK_0 = 0xc1,	/* acknowledge_0 */
107 	FC_RCTL_P_RJT = 0xc2,	/* port reject */
108 	FC_RCTL_F_RJT = 0xc3,	/* fabric reject */
109 	FC_RCTL_P_BSY = 0xc4,	/* port busy */
110 	FC_RCTL_F_BSY = 0xc5,	/* fabric busy to data frame */
111 	FC_RCTL_F_BSYL = 0xc6,	/* fabric busy to link control frame */
112 	FC_RCTL_LCR = 0xc7,	/* link credit reset */
113 	FC_RCTL_END = 0xc9,	/* end */
114 };
115 				    /* incomplete list of definitions */
116 
117 /*
118  * R_CTL names initializer.
119  * Please keep this matching the above definitions.
120  */
121 #define FC_RCTL_NAMES_INIT { \
122 	[FC_RCTL_DD_UNCAT] =		"uncat",			\
123 	[FC_RCTL_DD_SOL_DATA] =		"sol data",			\
124 	[FC_RCTL_DD_UNSOL_CTL] =	"unsol ctl",			\
125 	[FC_RCTL_DD_SOL_CTL] =		"sol ctl/reply",		\
126 	[FC_RCTL_DD_UNSOL_DATA] =	"unsol data",			\
127 	[FC_RCTL_DD_DATA_DESC] =	"data desc",			\
128 	[FC_RCTL_DD_UNSOL_CMD] =	"unsol cmd",			\
129 	[FC_RCTL_DD_CMD_STATUS] =	"cmd status",			\
130 	[FC_RCTL_ELS_REQ] =		"ELS req",			\
131 	[FC_RCTL_ELS_REP] =		"ELS rep",			\
132 	[FC_RCTL_ELS4_REQ] =		"FC-4 ELS req",			\
133 	[FC_RCTL_ELS4_REP] =		"FC-4 ELS rep",			\
134 	[FC_RCTL_BA_NOP] =		"BLS NOP",			\
135 	[FC_RCTL_BA_ABTS] =		"BLS abort",			\
136 	[FC_RCTL_BA_RMC] =		"BLS remove connection",	\
137 	[FC_RCTL_BA_ACC] =		"BLS accept",			\
138 	[FC_RCTL_BA_RJT] =		"BLS reject",			\
139 	[FC_RCTL_BA_PRMT] =		"BLS dedicated connection preempted", \
140 	[FC_RCTL_ACK_1] =		"LC ACK_1",			\
141 	[FC_RCTL_ACK_0] =		"LC ACK_0",			\
142 	[FC_RCTL_P_RJT] =		"LC port reject",		\
143 	[FC_RCTL_F_RJT] =		"LC fabric reject",		\
144 	[FC_RCTL_P_BSY] =		"LC port busy",			\
145 	[FC_RCTL_F_BSY] =		"LC fabric busy to data frame",	\
146 	[FC_RCTL_F_BSYL] =		"LC fabric busy to link control frame",\
147 	[FC_RCTL_LCR] =			"LC link credit reset",		\
148 	[FC_RCTL_END] =			"LC end",			\
149 }
150 
151 /*
152  * Well-known fabric addresses.
153  */
154 enum fc_well_known_fid {
155 	FC_FID_NONE =           0x000000,       /* No destination */
156 	FC_FID_BCAST =		0xffffff,	/* broadcast */
157 	FC_FID_FLOGI =		0xfffffe,	/* fabric login */
158 	FC_FID_FCTRL =		0xfffffd,	/* fabric controller */
159 	FC_FID_DIR_SERV =	0xfffffc,	/* directory server */
160 	FC_FID_TIME_SERV =	0xfffffb,	/* time server */
161 	FC_FID_MGMT_SERV =	0xfffffa,	/* management server */
162 	FC_FID_QOS =		0xfffff9,	/* QoS Facilitator */
163 	FC_FID_ALIASES =	0xfffff8,	/* alias server (FC-PH2) */
164 	FC_FID_SEC_KEY =	0xfffff7,	/* Security key dist. server */
165 	FC_FID_CLOCK =		0xfffff6,	/* clock synch server */
166 	FC_FID_MCAST_SERV =	0xfffff5,	/* multicast server */
167 };
168 
169 #define	FC_FID_WELL_KNOWN_MAX	0xffffff /* highest well-known fabric ID */
170 #define	FC_FID_WELL_KNOWN_BASE	0xfffff5 /* start of well-known fabric ID */
171 
172 /*
173  * Other well-known addresses, outside the above contiguous range.
174  */
175 #define	FC_FID_DOM_MGR		0xfffc00	/* domain manager base */
176 
177 /*
178  * Fabric ID bytes.
179  */
180 #define	FC_FID_DOMAIN		0
181 #define	FC_FID_PORT		1
182 #define	FC_FID_LINK		2
183 
184 /*
185  * fh_type codes
186  */
187 enum fc_fh_type {
188 	FC_TYPE_BLS =	0x00,	/* basic link service */
189 	FC_TYPE_ELS =	0x01,	/* extended link service */
190 	FC_TYPE_IP =	0x05,	/* IP over FC, RFC 4338 */
191 	FC_TYPE_FCP =	0x08,	/* SCSI FCP */
192 	FC_TYPE_CT =	0x20,	/* Fibre Channel Services (FC-CT) */
193 	FC_TYPE_ILS =	0x22,	/* internal link service */
194 	FC_TYPE_NVME =	0x28,	/* FC-NVME */
195 };
196 
197 /*
198  * FC_TYPE names initializer.
199  * Please keep this matching the above definitions.
200  */
201 #define FC_TYPE_NAMES_INIT {				\
202 	[FC_TYPE_BLS] =		"BLS",			\
203 	[FC_TYPE_ELS] =		"ELS",			\
204 	[FC_TYPE_IP] =		"IP",			\
205 	[FC_TYPE_FCP] =		"FCP",			\
206 	[FC_TYPE_CT] =		"CT",			\
207 	[FC_TYPE_ILS] =		"ILS",			\
208 	[FC_TYPE_NVME] =	"NVME",			\
209 }
210 
211 /*
212  * Exchange IDs.
213  */
214 #define FC_XID_UNKNOWN  0xffff	/* unknown exchange ID */
215 #define FC_XID_MIN	0x0	/* supported min exchange ID */
216 #define FC_XID_MAX	0xfffe	/* supported max exchange ID */
217 
218 /*
219  * fh_f_ctl - Frame control flags.
220  */
221 #define	FC_FC_EX_CTX	(1 << 23)	/* sent by responder to exchange */
222 #define	FC_FC_SEQ_CTX	(1 << 22)	/* sent by responder to sequence */
223 #define	FC_FC_FIRST_SEQ (1 << 21)	/* first sequence of this exchange */
224 #define	FC_FC_LAST_SEQ	(1 << 20)	/* last sequence of this exchange */
225 #define	FC_FC_END_SEQ	(1 << 19)	/* last frame of sequence */
226 #define	FC_FC_END_CONN	(1 << 18)	/* end of class 1 connection pending */
227 #define	FC_FC_RES_B17	(1 << 17)	/* reserved */
228 #define	FC_FC_SEQ_INIT	(1 << 16)	/* transfer of sequence initiative */
229 #define	FC_FC_X_ID_REASS (1 << 15)	/* exchange ID has been changed */
230 #define	FC_FC_X_ID_INVAL (1 << 14)	/* exchange ID invalidated */
231 
232 #define	FC_FC_ACK_1	(1 << 12)	/* 13:12 = 1: ACK_1 expected */
233 #define	FC_FC_ACK_N	(2 << 12)	/* 13:12 = 2: ACK_N expected */
234 #define	FC_FC_ACK_0	(3 << 12)	/* 13:12 = 3: ACK_0 expected */
235 
236 #define	FC_FC_RES_B11	(1 << 11)	/* reserved */
237 #define	FC_FC_RES_B10	(1 << 10)	/* reserved */
238 #define	FC_FC_RETX_SEQ	(1 << 9)	/* retransmitted sequence */
239 #define	FC_FC_UNI_TX	(1 << 8)	/* unidirectional transmit (class 1) */
240 #define	FC_FC_CONT_SEQ(i) ((i) << 6)
241 #define	FC_FC_ABT_SEQ(i) ((i) << 4)
242 #define	FC_FC_REL_OFF	(1 << 3)	/* parameter is relative offset */
243 #define	FC_FC_RES2	(1 << 2)	/* reserved */
244 #define	FC_FC_FILL(i)	((i) & 3)	/* 1:0: bytes of trailing fill */
245 
246 /*
247  * BA_ACC payload.
248  */
249 struct fc_ba_acc {
250 	__u8		ba_seq_id_val;	/* SEQ_ID validity */
251 #define FC_BA_SEQ_ID_VAL 0x80
252 	__u8		ba_seq_id;	/* SEQ_ID of seq last deliverable */
253 	__u8		ba_resvd[2];	/* reserved */
254 	__be16		ba_ox_id;	/* OX_ID for aborted seq or exch */
255 	__be16		ba_rx_id;	/* RX_ID for aborted seq or exch */
256 	__be16		ba_low_seq_cnt;	/* low SEQ_CNT of aborted seq */
257 	__be16		ba_high_seq_cnt; /* high SEQ_CNT of aborted seq */
258 };
259 
260 /*
261  * BA_RJT: Basic Reject payload.
262  */
263 struct fc_ba_rjt {
264 	__u8		br_resvd;	/* reserved */
265 	__u8		br_reason;	/* reason code */
266 	__u8		br_explan;	/* reason explanation */
267 	__u8		br_vendor;	/* vendor unique code */
268 };
269 
270 /*
271  * BA_RJT reason codes.
272  * From FS-2.
273  */
274 enum fc_ba_rjt_reason {
275 	FC_BA_RJT_NONE =	0,	/* in software this means no reject */
276 	FC_BA_RJT_INVL_CMD =	0x01,	/* invalid command code */
277 	FC_BA_RJT_LOG_ERR =	0x03,	/* logical error */
278 	FC_BA_RJT_LOG_BUSY =	0x05,	/* logical busy */
279 	FC_BA_RJT_PROTO_ERR =	0x07,	/* protocol error */
280 	FC_BA_RJT_UNABLE =	0x09,	/* unable to perform request */
281 	FC_BA_RJT_VENDOR =	0xff,	/* vendor-specific (see br_vendor) */
282 };
283 
284 /*
285  * BA_RJT reason code explanations.
286  */
287 enum fc_ba_rjt_explan {
288 	FC_BA_RJT_EXP_NONE =	0x00,	/* no additional expanation */
289 	FC_BA_RJT_INV_XID =	0x03,	/* invalid OX_ID-RX_ID combination */
290 	FC_BA_RJT_ABT =		0x05,	/* sequence aborted, no seq info */
291 };
292 
293 /*
294  * P_RJT or F_RJT: Port Reject or Fabric Reject parameter field.
295  */
296 struct fc_pf_rjt {
297 	__u8		rj_action;	/* reserved */
298 	__u8		rj_reason;	/* reason code */
299 	__u8		rj_resvd;	/* reserved */
300 	__u8		rj_vendor;	/* vendor unique code */
301 };
302 
303 /*
304  * P_RJT and F_RJT reject reason codes.
305  */
306 enum fc_pf_rjt_reason {
307 	FC_RJT_NONE =		0,	/* non-reject (reserved by standard) */
308 	FC_RJT_INVL_DID =	0x01,	/* invalid destination ID */
309 	FC_RJT_INVL_SID =	0x02,	/* invalid source ID */
310 	FC_RJT_P_UNAV_T =	0x03,	/* port unavailable, temporary */
311 	FC_RJT_P_UNAV =		0x04,	/* port unavailable, permanent */
312 	FC_RJT_CLS_UNSUP =	0x05,	/* class not supported */
313 	FC_RJT_DEL_USAGE =	0x06,	/* delimiter usage error */
314 	FC_RJT_TYPE_UNSUP =	0x07,	/* type not supported */
315 	FC_RJT_LINK_CTL =	0x08,	/* invalid link control */
316 	FC_RJT_R_CTL =		0x09,	/* invalid R_CTL field */
317 	FC_RJT_F_CTL =		0x0a,	/* invalid F_CTL field */
318 	FC_RJT_OX_ID =		0x0b,	/* invalid originator exchange ID */
319 	FC_RJT_RX_ID =		0x0c,	/* invalid responder exchange ID */
320 	FC_RJT_SEQ_ID =		0x0d,	/* invalid sequence ID */
321 	FC_RJT_DF_CTL =		0x0e,	/* invalid DF_CTL field */
322 	FC_RJT_SEQ_CNT =	0x0f,	/* invalid SEQ_CNT field */
323 	FC_RJT_PARAM =		0x10,	/* invalid parameter field */
324 	FC_RJT_EXCH_ERR =	0x11,	/* exchange error */
325 	FC_RJT_PROTO =		0x12,	/* protocol error */
326 	FC_RJT_LEN =		0x13,	/* incorrect length */
327 	FC_RJT_UNEXP_ACK =	0x14,	/* unexpected ACK */
328 	FC_RJT_FAB_CLASS =	0x15,	/* class unsupported by fabric entity */
329 	FC_RJT_LOGI_REQ =	0x16,	/* login required */
330 	FC_RJT_SEQ_XS =		0x17,	/* excessive sequences attempted */
331 	FC_RJT_EXCH_EST =	0x18,	/* unable to establish exchange */
332 	FC_RJT_FAB_UNAV =	0x1a,	/* fabric unavailable */
333 	FC_RJT_VC_ID =		0x1b,	/* invalid VC_ID (class 4) */
334 	FC_RJT_CS_CTL =		0x1c,	/* invalid CS_CTL field */
335 	FC_RJT_INSUF_RES =	0x1d,	/* insuff. resources for VC (Class 4) */
336 	FC_RJT_INVL_CLS =	0x1f,	/* invalid class of service */
337 	FC_RJT_PREEMT_RJT =	0x20,	/* preemption request rejected */
338 	FC_RJT_PREEMT_DIS =	0x21,	/* preemption not enabled */
339 	FC_RJT_MCAST_ERR =	0x22,	/* multicast error */
340 	FC_RJT_MCAST_ET =	0x23,	/* multicast error terminate */
341 	FC_RJT_PRLI_REQ =	0x24,	/* process login required */
342 	FC_RJT_INVL_ATT =	0x25,	/* invalid attachment */
343 	FC_RJT_VENDOR =		0xff,	/* vendor specific reject */
344 };
345 
346 /* default timeout values */
347 
348 #define FC_DEF_E_D_TOV	2000UL
349 #define FC_DEF_R_A_TOV	10000UL
350 
351 #endif /* _FC_FS_H_ */
352