xref: /freebsd/sys/dev/ocs_fc/ocs_fcp.h (revision 123af6ec70016f5556da5972d4d63c7d175c06d3)
1 /*-
2  * Copyright (c) 2017 Broadcom. All rights reserved.
3  * The term "Broadcom" refers to Broadcom Limited and/or its subsidiaries.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * 1. Redistributions of source code must retain the above copyright notice,
9  *    this list of conditions and the following disclaimer.
10  *
11  * 2. Redistributions in binary form must reproduce the above copyright notice,
12  *    this list of conditions and the following disclaimer in the documentation
13  *    and/or other materials provided with the distribution.
14  *
15  * 3. Neither the name of the copyright holder nor the names of its contributors
16  *    may be used to endorse or promote products derived from this software
17  *    without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  * POSSIBILITY OF SUCH DAMAGE.
30  *
31  * $FreeBSD$
32  */
33 
34 /**
35  * @file
36  * Define Fibre Channel types and structures.
37  */
38 
39 #ifndef _OCS_FCP_H
40 #define _OCS_FCP_H
41 
42 #define FC_ELS_CMD_RJT		0x01
43 #define FC_ELS_CMD_ACC		0x02
44 #define FC_ELS_CMD_PLOGI	0x03
45 #define FC_ELS_CMD_FLOGI	0x04
46 #define FC_ELS_CMD_LOGO		0x05
47 #define FC_ELS_CMD_RRQ		0x12
48 #define FC_ELS_CMD_PRLI		0x20
49 #define FC_ELS_CMD_PRLO		0x21
50 #define FC_ELS_CMD_PDISC	0x50
51 #define FC_ELS_CMD_FDISC	0x51
52 #define FC_ELS_CMD_ADISC	0x52
53 #define FC_ELS_CMD_RSCN		0x61
54 #define FC_ELS_CMD_SCR		0x62
55 
56 #define FC_TYPE_BASIC_LINK	0
57 #define FC_TYPE_FCP		0x08
58 #define FC_TYPE_GS		0x20
59 #define FC_TYPE_SW		0x22
60 
61 #define FC_ADDR_FABRIC			0xfffffe	/** well known fabric address */
62 #define FC_ADDR_CONTROLLER              0xfffffd        /** well known fabric controller address */
63 #define FC_ADDR_IS_DOMAIN_CTRL(x)	(((x) & 0xffff00) == 0xfffc00)	/** is well known domain controller */
64 #define FC_ADDR_GET_DOMAIN_CTRL(x)	((x) & 0x0000ff)	/** get domain controller number */
65 #define FC_ADDR_NAMESERVER              0xfffffc        /** well known directory server address */
66 
67 #define FC_GS_TYPE_ALIAS_SERVICE		0xf8
68 #define FC_GS_TYPE_MANAGEMENT_SERVICE		0xfa
69 #define FC_GS_TYPE_DIRECTORY_SERVICE		0xfc
70 
71 #define FC_GS_SUBTYPE_NAME_SERVER		0x02
72 
73 /**
74  * Generic Services FC Type Bit mask macros:
75  */
76 #define FC_GS_TYPE_WORD(type)	((type) >> 5)
77 #define FC_GS_TYPE_BIT(type)	((type) & 0x1f)
78 
79 /**
80  * Generic Services Name Server Request Command codes:
81  */
82 #define FC_GS_NAMESERVER_GPN_ID		0x0112
83 #define FC_GS_NAMESERVER_GNN_ID		0x0113
84 #define FC_GS_NAMESERVER_GFPN_ID	0x011c
85 #define FC_GS_NAMESERVER_GFF_ID		0x011f
86 #define FC_GS_NAMESERVER_GID_FT		0x0171
87 #define FC_GS_NAMESERVER_GID_PT		0x01a1
88 #define FC_GS_NAMESERVER_RHBA		0x0200
89 #define FC_GS_NAMESERVER_RPA		0x0211
90 #define FC_GS_NAMESERVER_RPN_ID		0x0212
91 #define FC_GS_NAMESERVER_RNN_ID		0x0213
92 #define FC_GS_NAMESERVER_RCS_ID		0x0214
93 #define FC_GS_NAMESERVER_RFT_ID		0x0217
94 #define FC_GS_NAMESERVER_RFF_ID		0x021f
95 #define FC_GS_NAMESERVER_RSNN_NN	0x0239
96 #define FC_GS_NAMESERVER_RSPN_ID	0x0218
97 
98 
99 #define FC_GS_REVISION		0x03
100 
101 #define FC_GS_IO_PARAMS		{ .fc_ct.r_ctl = 0x02, \
102 				.fc_ct.type = FC_TYPE_GS, \
103 				.fc_ct.df_ctl = 0x00 }
104 
105 typedef struct fc_vft_header_s {
106 	uint32_t	:1,
107 			vf_id:12,
108 			priority:3,
109 			e:1,
110 			:1,
111 			type:4,
112 			ver:2,
113 			r_ctl:8;
114 	uint32_t	:24,
115 			hopct:8;
116 } fc_vft_header_t;
117 
118 
119 #if BYTE_ORDER == LITTLE_ENDIAN
120 static inline uint32_t fc_be24toh(uint32_t x) { return (ocs_be32toh(x) >> 8); }
121 #else
122 static inline uint32_t fc_be24toh(uint32_t x) { }
123 #endif
124 static inline uint32_t fc_htobe24(uint32_t x) { return fc_be24toh(x); }
125 
126 #define FC_SOFI3	0x2e
127 #define FC_SOFn3	0x36
128 #define FC_EOFN		0x41
129 #define FC_EOFT		0x42
130 
131 /**
132  * @brief FC header in big-endian order
133  */
134 typedef struct fc_header_s {
135 	uint32_t	info:4,
136 			r_ctl:4,
137 			d_id:24;
138 	uint32_t	cs_ctl:8,
139 			s_id:24;
140 	uint32_t	type:8,
141 			f_ctl:24;
142 	uint32_t	seq_id:8,
143 			df_ctl:8,
144 			seq_cnt:16;
145 	uint32_t	ox_id:16,
146 			rx_id:16;
147 	uint32_t	parameter;
148 } fc_header_t;
149 
150 
151 /**
152  * @brief FC header in little-endian order
153  */
154 typedef struct fc_header_le_s {
155 #if BYTE_ORDER == LITTLE_ENDIAN
156 	uint32_t	d_id:24,
157 			info:4,
158 			r_ctl:4;
159 	uint32_t	s_id:24,
160 			cs_ctl:8;
161 	uint32_t	f_ctl:24,
162 			type:8;
163 	uint32_t	seq_cnt:16,
164 			df_ctl:8,
165 			seq_id:8;
166 	uint32_t	rx_id:16,
167 			ox_id:16;
168 	uint32_t	parameter;
169 #else
170 #error big endian version not defined
171 #endif
172 } fc_header_le_t;
173 
174 /**
175  * @brief FC VM header in big-endian order
176  */
177 typedef struct fc_vm_header_s {
178 	uint32_t	dst_vmid;
179 	uint32_t	src_vmid;
180 	uint32_t	rsvd0;
181 	uint32_t	rsvd1;
182 } fc_vm_header_t;
183 
184 #define FC_DFCTL_DEVICE_HDR_16_MASK	0x1
185 #define FC_DFCTL_NETWORK_HDR_MASK	0x20
186 #define FC_DFCTL_ESP_HDR_MASK		0x40
187 #define FC_DFCTL_NETWORK_HDR_SIZE	16
188 #define FC_DFCTL_ESP_HDR_SIZE		0 //FIXME
189 
190 #define FC_RCTL_FC4_DATA	0
191 #define FC_RCTL_ELS		2
192 #define FC_RCTL_BLS		8
193 
194 #define FC_RCTL_INFO_UNCAT	0
195 #define FC_RCTL_INFO_SOL_DATA	1
196 #define FC_RCTL_INFO_UNSOL_CTRL	2
197 #define FC_RCTL_INFO_SOL_CTRL	3
198 #define FC_RCTL_INFO_UNSOL_DATA	4
199 #define FC_RCTL_INFO_DATA_DESC	5
200 #define FC_RCTL_INFO_UNSOL_CMD	6
201 #define FC_RCTL_INFO_CMD_STATUS	7
202 
203 #define FC_FCTL_EXCHANGE_RESPONDER	0x800000
204 #define FC_FCTL_SEQUENCE_CONTEXT	0x400000
205 #define FC_FCTL_FIRST_SEQUENCE		0x200000
206 #define FC_FCTL_LAST_SEQUENCE		0x100000
207 #define FC_FCTL_END_SEQUENCE		0x080000
208 #define FC_FCTL_END_CONNECTION		0x040000
209 #define FC_FCTL_PRIORITY_ENABLE		0x020000
210 #define FC_FCTL_SEQUENCE_INITIATIVE	0x010000
211 #define FC_FCTL_FILL_DATA_BYTES_MASK	0x000003
212 
213 /**
214  * Common BLS definitions:
215  */
216 #define FC_INFO_NOP			0x0
217 #define FC_INFO_ABTS			0x1
218 #define FC_INFO_RMC			0x2
219 /* reserved				0x3 */
220 #define FC_INFO_BA_ACC			0x4
221 #define FC_INFO_BA_RJT			0x5
222 #define FC_INFO_PRMT			0x6
223 
224 /* (FC-LS) LS_RJT Reason Codes */
225 #define FC_REASON_INVALID_COMMAND_CODE		0x01
226 #define FC_REASON_LOGICAL_ERROR			0x03
227 #define FC_REASON_LOGICAL_BUSY			0x05
228 #define FC_REASON_PROTOCOL_ERROR		0x07
229 #define FC_REASON_UNABLE_TO_PERFORM		0x09
230 #define FC_REASON_COMMAND_NOT_SUPPORTED		0x0b
231 #define FC_REASON_COMMAND_IN_PROGRESS   	0x0e
232 #define FC_REASON_VENDOR_SPECIFIC		0xff
233 
234 /* (FC-LS) LS_RJT Reason Codes Explanations */
235 #define FC_EXPL_NO_ADDITIONAL			0x00
236 #define FC_EXPL_SPARAM_OPTIONS			0x01
237 #define FC_EXPL_SPARAM_INITIATOR		0x03
238 #define FC_EXPL_SPARAM_RECPIENT			0x05
239 #define FC_EXPL_SPARM_DATA_SIZE			0x07
240 #define FC_EXPL_SPARM_CONCURRENT		0x09
241 #define FC_EXPL_SPARM_CREDIT			0x0b
242 #define FC_EXPL_INV_PORT_NAME 			0x0d
243 #define FC_EXPL_INV_NODE_NAME 			0x0e
244 #define FC_EXPL_INV_COMMON_SPARAMS 		0x0f
245 #define FC_EXPL_INV_ASSOC_HEADER		0x11
246 #define FC_EXPL_ASSOC_HDR_REQUIRED		0x13
247 #define FC_EXPL_INV_ORIGINATOR_S_ID		0x15
248 #define FC_EXPL_INV_X_ID_COMBINATION		0x17
249 #define FC_EXPL_COMMAND_IN_PROGRESS		0x19
250 #define FC_EXPL_NPORT_LOGIN_REQUIRED		0x1e
251 #define FC_EXPL_N_PORT_ID			0x1f
252 #define FC_EXPL_INSUFFICIENT_RESOURCES		0x29
253 #define FC_EXPL_UNABLE_TO_SUPPLY_DATA		0x2a
254 #define FC_EXPL_REQUEST_NOT_SUPPORTED		0x2c
255 #define FC_EXPL_INV_PAYLOAD_LEN			0x1d
256 #define FC_EXPL_INV_PORT_NODE_NAME		0x44
257 #define FC_EXPL_LOGIN_EXT_NOT_SUPPORTED		0x46
258 #define FC_EXPL_AUTH_REQUIRED			0x48
259 #define FC_EXPL_SCAN_VALUE_NOT_ALLOWED		0x50
260 #define FC_EXPL_SCAN_VALUE_NOT_SUPPORTED 	0x51
261 #define FC_EXPL_NO_RESOURCES_ASSIGNED		0x52
262 #define FC_EXPL_MAC_ADDR_MODE_NOT_SUPPORTED	0x60
263 #define FC_EXPL_MAC_ADDR_INCORRECTLY_FORMED	0x61
264 #define FC_EXPL_VN2VN_PORT_NOT_IN_NEIGHBOR_SET	0x62
265 
266 #define FC_EXPL_INV_X_ID			0x03	/* invalid OX_ID - RX_ID combination */
267 #define FC_EXPL_SEQUENCE_ABORTED		0x05
268 
269 typedef struct fc_ba_acc_payload_s {
270 #define FC_SEQ_ID_VALID			0x80
271 #define FC_SEQ_ID_INVALID		0x00
272 	uint32_t	seq_id_validity:8,
273 			seq_id:8,
274 			:16;
275 	uint32_t	ox_id:16,
276 			rx_id:16;
277 	uint32_t	low_seq_cnt:16,
278 			high_seq_cnt:16;
279 } fc_ba_acc_payload_t;
280 
281 typedef struct fc_ba_rjt_payload_s {
282 	uint32_t	vendor_unique:8,
283 			reason_explanation:8,
284 			reason_code:8,
285 			:8;
286 } fc_ba_rjt_payload_t;
287 
288 typedef struct fc_els_gen_s {
289 	uint32_t	command_code: 8,
290 			resv1: 24;
291 } fc_els_gen_t;
292 
293 typedef struct fc_plogi_playload_s {
294 	uint32_t	command_code: 8,
295 			resv1: 24;
296 	uint32_t	common_service_parameters[4];
297 	uint32_t	port_name_hi;
298 	uint32_t	port_name_lo;
299 	uint32_t	node_name_hi;
300 	uint32_t	node_name_lo;
301 	uint32_t	class1_service_parameters[4];
302 	uint32_t	class2_service_parameters[4];
303 	uint32_t	class3_service_parameters[4];
304 	uint32_t	class4_service_parameters[4];
305 	uint32_t	vendor_version_level[4];
306 } fc_plogi_payload_t;
307 
308 typedef fc_plogi_payload_t fc_sparms_t;
309 
310 typedef struct fc_logo_payload_s {
311 	uint32_t	command_code: 8,
312 			resv1:24;
313 	uint32_t	:8,
314 			port_id:24;
315 	uint32_t	port_name_hi;
316 	uint32_t	port_name_lo;
317 } fc_logo_payload_t;
318 
319 typedef struct fc_acc_payload_s {
320 	uint32_t	command_code: 8,
321 			resv1:24;
322 } fc_acc_payload_t;
323 
324 
325 typedef struct fc_ls_rjt_payload_s {
326 	uint32_t	command_code:8,
327 			resv1:24;
328 	uint32_t	resv2:8,
329 			reason_code:8,
330 			reason_code_exp:8,
331 			vendor_unique:8;
332 } fc_ls_rjt_payload_t;
333 
334 typedef struct fc_prli_payload_s {
335 	uint32_t	command_code:8,
336 			page_length:8,
337 			payload_length:16;
338 	uint32_t	type:8,
339 			type_ext:8,
340 			flags:16;
341 	uint32_t	originator_pa;
342 	uint32_t	responder_pa;
343 	uint32_t	:16,
344 			service_params:16;
345 } fc_prli_payload_t;
346 
347 typedef struct fc_prlo_payload_s {
348 	uint32_t	command_code:8,
349 			page_length:8,
350 			payload_length:16;
351 	uint32_t	type:8,
352 			type_ext:8,
353 			:16;
354 	uint32_t	:32;
355 	uint32_t	:32;
356 	uint32_t	:32;
357 } fc_prlo_payload_t;
358 
359 typedef struct fc_prlo_acc_payload_s {
360 	uint32_t	command_code:8,
361 			page_length:8,
362 			payload_length:16;
363 	uint32_t	type:8,
364 			type_ext:8,
365 			:4,
366 			response_code:4,
367 			:8;
368 	uint32_t	:32;
369 	uint32_t	:32;
370 	uint32_t	:32;
371 } fc_prlo_acc_payload_t;
372 
373 typedef struct fc_adisc_payload_s {
374 	uint32_t	command_code:8,
375 			payload_length:24;
376 	uint32_t	:8,
377 			hard_address:24;
378 	uint32_t	port_name_hi;
379 	uint32_t	port_name_lo;
380 	uint32_t	node_name_hi;
381 	uint32_t	node_name_lo;
382 	uint32_t	:8,
383 			port_id:24;
384 } fc_adisc_payload_t;
385 
386 /* PRLI flags */
387 #define FC_PRLI_ORIGINATOR_PA_VALID	0x8000
388 #define FC_PRLI_RESPONDER_PA_VALID	0x4000
389 #define FC_PRLI_ESTABLISH_IMAGE_PAIR	0x2000
390 #define FC_PRLI_SERVICE_PARAM_INVALID	0x0800
391 #define FC_PRLI_REQUEST_EXECUTED	0x0100
392 
393 /* PRLI Service Parameters */
394 #define FC_PRLI_REC_SUPPORT		0x0400
395 #define FC_PRLI_TASK_RETRY_ID_REQ	0x0200
396 #define FC_PRLI_RETRY			0x0100
397 #define FC_PRLI_CONFIRMED_COMPLETION	0x0080
398 #define FC_PRLI_DATA_OVERLAY		0x0040
399 #define FC_PRLI_INITIATOR_FUNCTION      0x0020
400 #define FC_PRLI_TARGET_FUNCTION         0x0010
401 #define FC_PRLI_READ_XRDY_DISABLED	0x0002
402 #define FC_PRLI_WRITE_XRDY_DISABLED	0x0001
403 
404 /* PRLO Logout flags */
405 #define FC_PRLO_REQUEST_EXECUTED	0x0001
406 
407 typedef struct fc_scr_payload_s {
408 	uint32_t	command_code:8,
409 			:24;
410 	uint32_t	:24,
411 			function:8;
412 } fc_scr_payload_t;
413 
414 #define FC_SCR_REG_FABRIC		1
415 #define FC_SCR_REG_NPORT		2
416 #define FC_SCR_REG_FULL			3
417 
418 typedef struct {
419 	uint32_t :2,
420 		rscn_event_qualifier:4,
421 		address_format:2,
422 		port_id:24;
423 } fc_rscn_affected_port_id_page_t;
424 
425 typedef struct fc_rscn_payload_s {
426 	uint32_t	command_code:8,
427 			page_length:8,
428 			payload_length:16;
429 	fc_rscn_affected_port_id_page_t port_list[1];
430 } fc_rscn_payload_t;
431 
432 typedef struct fcct_iu_header_s {
433 #if BYTE_ORDER == LITTLE_ENDIAN
434 	uint32_t	revision:8,
435 			in_id:24;
436 	uint32_t	gs_type:8,
437 			gs_subtype:8,
438 			options:8,
439 			resv1:8;
440 	uint32_t	cmd_rsp_code:16,
441 			max_residual_size:16;
442 	uint32_t	fragment_id:8,
443 			reason_code:8,
444 			reason_code_explanation:8,
445 			vendor_specific:8;
446 #else
447 #error big endian version not defined
448 #endif
449 } fcct_iu_header_t;
450 
451 #define FCCT_REJECT_INVALID_COMMAND_CODE	1
452 #define FCCT_REJECT_INVALID_VERSION_LEVEL	2
453 #define FCCT_LOGICAL_ERROR			3
454 #define FCCT_INVALID_CT_IU_SIZE			4
455 #define FCCT_LOGICAL_BUSY			5
456 #define FCCT_PROTOCOL_ERROR			7
457 #define FCCT_UNABLE_TO_PERFORM			9
458 #define FCCT_COMMAND_NOT_SUPPORTED		0x0b
459 #define FCCT_FABRIC_PORT_NAME_NOT_REGISTERED	0x0c
460 #define FCCT_SERVER_NOT_AVAILABLE		0x0d
461 #define FCCT_SESSION_COULD_NOT_BE_ESTABLISHED	0x0e
462 #define FCCT_VENDOR_SPECIFIC_ERROR		0xff
463 
464 #define FCCT_NO_ADDITIONAL_EXPLANATION		0
465 #define FCCT_AUTHORIZATION_EXCEPTION		0xf0
466 #define FCCT_AUTHENTICATION_EXCEPTION		0xf1
467 #define FCCT_DATA_BASE_FULL			0xf2
468 #define FCCT_DATA_BASE_EMPTY			0xf3
469 #define FCCT_PROCESSING_REQUEST			0xf4
470 #define FCCT_UNABLE_TO_VERIFY_CONNECTION	0xf5
471 #define FCCT_DEVICES_NOT_IN_COMMON_ZONE		0xf6
472 
473 typedef struct {
474 	fcct_iu_header_t hdr;
475 #if BYTE_ORDER == LITTLE_ENDIAN
476 	uint32_t	port_id;
477 	uint32_t	fc4_types;
478 #else
479 #error big endian version not defined
480 #endif
481 } fcgs_rft_id_t;
482 
483 typedef struct {
484 	fcct_iu_header_t hdr;
485 #if BYTE_ORDER == LITTLE_ENDIAN
486 	uint32_t	port_id;
487 	uint32_t	:16,
488 			fc4_features:8,
489 			type_code:8;
490 #else
491 #error big endian version not defined
492 #endif
493 } fcgs_rff_id_t;
494 
495 #pragma pack(1)
496 typedef struct {
497 	fcct_iu_header_t hdr;
498 #if BYTE_ORDER == LITTLE_ENDIAN
499 	uint32_t	port_id;
500 	uint64_t	port_name;
501 #else
502 #error big endian version not defined
503 #endif
504 } fcgs_rpn_id_t;
505 #pragma pack()
506 
507 #pragma pack(1)
508 typedef struct {
509 	fcct_iu_header_t hdr;
510 #if BYTE_ORDER == LITTLE_ENDIAN
511 	uint32_t	port_id;
512 	uint64_t	node_name;
513 #else
514 #error big endian version not defined
515 #endif
516 } fcgs_rnn_id_t;
517 #pragma pack()
518 
519 #define FCCT_CLASS_OF_SERVICE_F	0x1
520 #define FCCT_CLASS_OF_SERVICE_2	0x4
521 #define FCCT_CLASS_OF_SERVICE_3	0x8
522 #pragma pack(1)
523 typedef struct {
524 	fcct_iu_header_t hdr;
525 #if BYTE_ORDER == LITTLE_ENDIAN
526 	uint32_t	port_id;
527 	uint32_t	class_of_srvc;
528 #else
529 #error big endian version not defined
530 #endif
531 } fcgs_rcs_id_t;
532 #pragma pack()
533 
534 #pragma pack(1)
535 typedef struct {
536 	fcct_iu_header_t hdr;
537 #if BYTE_ORDER == LITTLE_ENDIAN
538 	uint64_t	node_name;
539 	uint8_t		name_len;
540 	char		sym_node_name[1];
541 /*TODO: need name length and symbolic name */
542 #else
543 #error big endian version not defined
544 #endif
545 } fcgs_rsnn_nn_t;
546 #pragma pack()
547 
548 #define FCCT_HDR_CMDRSP_ACCEPT	0x8002
549 #define FCCT_HDR_CMDRSP_REJECT	0x8001
550 
551 static inline void fcct_build_req_header(fcct_iu_header_t *hdr, uint16_t cmd, uint16_t max_size)
552 {
553 	/* use old rev (1) to accommodate older switches */
554 	hdr->revision = 1;
555 	hdr->in_id = 0;
556 	hdr->gs_type = FC_GS_TYPE_DIRECTORY_SERVICE;
557 	hdr->gs_subtype = FC_GS_SUBTYPE_NAME_SERVER;
558 	hdr->options = 0;
559 	hdr->resv1 = 0;
560 	hdr->cmd_rsp_code = ocs_htobe16(cmd);
561 	hdr->max_residual_size = ocs_htobe16(max_size/(sizeof(uint32_t))); /* words */
562 	hdr->fragment_id = 0;
563 	hdr->reason_code = 0;
564 	hdr->reason_code_explanation = 0;
565 	hdr->vendor_specific = 0;
566 }
567 
568 typedef struct fcct_rftid_req_s {
569 	fcct_iu_header_t	hdr;
570 	uint32_t		port_id;
571 	uint32_t		fc4_types[8];
572 } fcct_rftid_req_t;
573 
574 #define FC4_FEATURE_TARGET	(1U << 0)
575 #define FC4_FEATURE_INITIATOR	(1U << 1)
576 
577 typedef struct fcct_rffid_req_s {
578 	fcct_iu_header_t	hdr;
579 	uint32_t		port_id;
580 	uint32_t		:16,
581 				fc4_feature_bits:8,
582 				type:8;
583 } fcct_rffid_req_t;
584 
585 typedef struct fcct_gnnid_req_s {
586 	fcct_iu_header_t	hdr;
587 	uint32_t		:8,
588 				port_id:24;
589 } fcct_gnnid_req_t;
590 
591 typedef struct fcct_gpnid_req_s {
592 	fcct_iu_header_t	hdr;
593 	uint32_t		:8,
594 				port_id:24;
595 } fcct_gpnid_req_t;
596 
597 typedef struct fcct_gffid_req_s {
598 	fcct_iu_header_t	hdr;
599 	uint32_t		:8,
600 				port_id:24;
601 } fcct_gffid_req_t;
602 
603 typedef struct fcct_gidft_req_s {
604 	fcct_iu_header_t	hdr;
605 	uint32_t		:8,
606 				domain_id_scope:8,
607 				area_id_scope:8,
608 				type:8;
609 } fcct_gidft_req_t;
610 
611 typedef struct fcct_gidpt_req_s {
612 	fcct_iu_header_t	hdr;
613 	uint32_t		port_type:8,
614 				domain_id_scope:8,
615 				area_id_scope:8,
616 				flags:8;
617 } fcct_gidpt_req_t;
618 
619 typedef struct fcct_gnnid_acc_s {
620 	fcct_iu_header_t	hdr;
621 	uint64_t		node_name;
622 } fcct_gnnid_acc_t;
623 
624 typedef struct fcct_gpnid_acc_s {
625 	fcct_iu_header_t	hdr;
626 	uint64_t		port_name;
627 } fcct_gpnid_acc_t;
628 
629 typedef struct fcct_gffid_acc_s {
630 	fcct_iu_header_t	hdr;
631 	uint8_t			fc4_feature_bits;
632 } fcct_gffid_acc_t;
633 
634 typedef struct fcct_gidft_acc_s {
635 	fcct_iu_header_t	hdr;
636 	struct {
637 		uint32_t	ctl:8,
638 				port_id:24;
639 	} port_list[1];
640 } fcct_gidft_acc_t;
641 
642 typedef struct fcct_gidpt_acc_s {
643 	fcct_iu_header_t	hdr;
644 	struct {
645 		uint32_t	ctl:8,
646 				port_id:24;
647 	} port_list[1];
648 } fcct_gidpt_acc_t;
649 
650 #define FCCT_GID_PT_LAST_ID	0x80
651 #define FCCT_GIDPT_ID_MASK	0x00ffffff
652 
653 typedef struct fcp_cmnd_iu_s {
654 	uint8_t		fcp_lun[8];
655 	uint8_t		command_reference_number;
656 	uint8_t		task_attribute:3,
657 			command_priority:4,
658 			:1;
659 	uint8_t		task_management_flags;
660 	uint8_t		wrdata:1,
661 			rddata:1,
662 			additional_fcp_cdb_length:6;
663 	uint8_t		fcp_cdb[16];
664 	uint8_t		fcp_cdb_and_dl[20];	/* < May contain up to 16 bytes of CDB, followed by fcp_dl */
665 } fcp_cmnd_iu_t;
666 
667 #define FCP_LUN_ADDRESS_METHOD_SHIFT	6
668 #define FCP_LUN_ADDRESS_METHOD_MASK	0xc0
669 #define FCP_LUN_ADDR_METHOD_PERIPHERAL	0x0
670 #define FCP_LUN_ADDR_METHOD_FLAT	0x1
671 #define FCP_LUN_ADDR_METHOD_LOGICAL	0x2
672 #define FCP_LUN_ADDR_METHOD_EXTENDED	0x3
673 
674 #define FCP_LUN_ADDR_SIMPLE_MAX		0xff
675 #define FCP_LUN_ADDR_FLAT_MAX		0x3fff
676 
677 #define FCP_TASK_ATTR_SIMPLE		0x0
678 #define FCP_TASK_ATTR_HEAD_OF_QUEUE	0x1
679 #define FCP_TASK_ATTR_ORDERED		0x2
680 #define FCP_TASK_ATTR_ACA		0x4
681 #define FCP_TASK_ATTR_UNTAGGED          0x5
682 
683 #define FCP_QUERY_TASK_SET		BIT(0)
684 #define FCP_ABORT_TASK_SET		BIT(1)
685 #define FCP_CLEAR_TASK_SET		BIT(2)
686 #define FCP_QUERY_ASYNCHRONOUS_EVENT	BIT(3)
687 #define FCP_LOGICAL_UNIT_RESET		BIT(4)
688 #define FCP_TARGET_RESET		BIT(5)
689 #define FCP_CLEAR_ACA			BIT(6)
690 
691 /* SPC-4 says that the maximum length of sense data is 252 bytes */
692 #define FCP_MAX_SENSE_LEN		252
693 #define FCP_MAX_RSP_LEN			  8
694 /*
695  * FCP_RSP buffer will either have sense or response data, but not both
696  * so pick the larger.
697  */
698 #define FCP_MAX_RSP_INFO_LEN		FCP_MAX_SENSE_LEN
699 
700 typedef struct fcp_rsp_iu_s {
701 	uint8_t		rsvd[8];
702 	uint8_t		status_qualifier[2];
703 	uint8_t		flags;
704 	uint8_t		scsi_status;
705 	uint8_t		fcp_resid[4];
706 	uint8_t		fcp_sns_len[4];
707 	uint8_t		fcp_rsp_len[4];
708 	uint8_t		data[FCP_MAX_RSP_INFO_LEN];
709 } fcp_rsp_iu_t;
710 
711 /** Flag field defines: */
712 #define FCP_RSP_LEN_VALID		BIT(0)
713 #define FCP_SNS_LEN_VALID		BIT(1)
714 #define FCP_RESID_OVER			BIT(2)
715 #define FCP_RESID_UNDER			BIT(3)
716 #define FCP_CONF_REQ			BIT(4)
717 #define FCP_BIDI_READ_RESID_OVER	BIT(5)
718 #define FCP_BIDI_READ_RESID_UNDER	BIT(6)
719 #define FCP_BIDI_RSP			BIT(7)
720 
721 /** Status values: */
722 #define FCP_TMF_COMPLETE		0x00
723 #define FCP_DATA_LENGTH_MISMATCH	0x01
724 #define FCP_INVALID_FIELD		0x02
725 #define FCP_DATA_RO_MISMATCH		0x03
726 #define FCP_TMF_REJECTED		0x04
727 #define FCP_TMF_FAILED			0x05
728 #define FCP_TMF_SUCCEEDED		0x08
729 #define FCP_TMF_INCORRECT_LUN		0x09
730 
731 /** FCP-4 Table 28, TMF response information: */
732 typedef struct fc_rsp_info_s {
733 	uint8_t addl_rsp_info[3];
734 	uint8_t rsp_code;
735 	uint32_t :32;
736 } fcp_rsp_info_t;
737 
738 typedef struct fcp_xfer_rdy_iu_s {
739 	uint8_t		fcp_data_ro[4];
740 	uint8_t		fcp_burst_len[4];
741 	uint8_t		rsvd[4];
742 } fcp_xfer_rdy_iu_t;
743 
744 #define MAX_ACC_REJECT_PAYLOAD (sizeof(fc_ls_rjt_payload_t) > sizeof(fc_acc_payload_t) ? sizeof(fc_ls_rjt_payload_t) : sizeof(fc_acc_payload_t))
745 
746 
747 #endif /* !_OCS_FCP_H */
748