2 * Copyright (c) 2017 Broadcom. All rights reserved.
3 * The term "Broadcom" refers to Broadcom Limited and/or its subsidiaries.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
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.
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.
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.
36 * Define Fibre Channel types and structures.
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
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
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 */
67 #define FC_GS_TYPE_ALIAS_SERVICE 0xf8
68 #define FC_GS_TYPE_MANAGEMENT_SERVICE 0xfa
69 #define FC_GS_TYPE_DIRECTORY_SERVICE 0xfc
71 #define FC_GS_SUBTYPE_NAME_SERVER 0x02
74 * Generic Services FC Type Bit mask macros:
76 #define FC_GS_TYPE_WORD(type) ((type) >> 5)
77 #define FC_GS_TYPE_BIT(type) ((type) & 0x1f)
80 * Generic Services Name Server Request Command codes:
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
98 #define FC_GS_REVISION 0x03
100 #define FC_GS_IO_PARAMS { .fc_ct.r_ctl = 0x02, \
101 .fc_ct.type = FC_TYPE_GS, \
102 .fc_ct.df_ctl = 0x00 }
104 typedef struct fc_vft_header_s {
117 #if BYTE_ORDER == LITTLE_ENDIAN
118 static inline uint32_t fc_be24toh(uint32_t x) { return (ocs_be32toh(x) >> 8); }
120 static inline uint32_t fc_be24toh(uint32_t x) { }
122 static inline uint32_t fc_htobe24(uint32_t x) { return fc_be24toh(x); }
124 #define FC_SOFI3 0x2e
125 #define FC_SOFn3 0x36
130 * @brief FC header in big-endian order
132 typedef struct fc_header_s {
149 * @brief FC header in little-endian order
151 typedef struct fc_header_le_s {
152 #if BYTE_ORDER == LITTLE_ENDIAN
167 #error big endian version not defined
172 * @brief FC VM header in big-endian order
174 typedef struct fc_vm_header_s {
181 #define FC_DFCTL_DEVICE_HDR_16_MASK 0x1
182 #define FC_DFCTL_NETWORK_HDR_MASK 0x20
183 #define FC_DFCTL_ESP_HDR_MASK 0x40
184 #define FC_DFCTL_NETWORK_HDR_SIZE 16
185 #define FC_DFCTL_ESP_HDR_SIZE 0 //FIXME
187 #define FC_RCTL_FC4_DATA 0
188 #define FC_RCTL_ELS 2
189 #define FC_RCTL_BLS 8
191 #define FC_RCTL_INFO_UNCAT 0
192 #define FC_RCTL_INFO_SOL_DATA 1
193 #define FC_RCTL_INFO_UNSOL_CTRL 2
194 #define FC_RCTL_INFO_SOL_CTRL 3
195 #define FC_RCTL_INFO_UNSOL_DATA 4
196 #define FC_RCTL_INFO_DATA_DESC 5
197 #define FC_RCTL_INFO_UNSOL_CMD 6
198 #define FC_RCTL_INFO_CMD_STATUS 7
200 #define FC_FCTL_EXCHANGE_RESPONDER 0x800000
201 #define FC_FCTL_SEQUENCE_CONTEXT 0x400000
202 #define FC_FCTL_FIRST_SEQUENCE 0x200000
203 #define FC_FCTL_LAST_SEQUENCE 0x100000
204 #define FC_FCTL_END_SEQUENCE 0x080000
205 #define FC_FCTL_END_CONNECTION 0x040000
206 #define FC_FCTL_PRIORITY_ENABLE 0x020000
207 #define FC_FCTL_SEQUENCE_INITIATIVE 0x010000
208 #define FC_FCTL_FILL_DATA_BYTES_MASK 0x000003
211 * Common BLS definitions:
213 #define FC_INFO_NOP 0x0
214 #define FC_INFO_ABTS 0x1
215 #define FC_INFO_RMC 0x2
217 #define FC_INFO_BA_ACC 0x4
218 #define FC_INFO_BA_RJT 0x5
219 #define FC_INFO_PRMT 0x6
221 /* (FC-LS) LS_RJT Reason Codes */
222 #define FC_REASON_INVALID_COMMAND_CODE 0x01
223 #define FC_REASON_LOGICAL_ERROR 0x03
224 #define FC_REASON_LOGICAL_BUSY 0x05
225 #define FC_REASON_PROTOCOL_ERROR 0x07
226 #define FC_REASON_UNABLE_TO_PERFORM 0x09
227 #define FC_REASON_COMMAND_NOT_SUPPORTED 0x0b
228 #define FC_REASON_COMMAND_IN_PROGRESS 0x0e
229 #define FC_REASON_VENDOR_SPECIFIC 0xff
231 /* (FC-LS) LS_RJT Reason Codes Explanations */
232 #define FC_EXPL_NO_ADDITIONAL 0x00
233 #define FC_EXPL_SPARAM_OPTIONS 0x01
234 #define FC_EXPL_SPARAM_INITIATOR 0x03
235 #define FC_EXPL_SPARAM_RECPIENT 0x05
236 #define FC_EXPL_SPARM_DATA_SIZE 0x07
237 #define FC_EXPL_SPARM_CONCURRENT 0x09
238 #define FC_EXPL_SPARM_CREDIT 0x0b
239 #define FC_EXPL_INV_PORT_NAME 0x0d
240 #define FC_EXPL_INV_NODE_NAME 0x0e
241 #define FC_EXPL_INV_COMMON_SPARAMS 0x0f
242 #define FC_EXPL_INV_ASSOC_HEADER 0x11
243 #define FC_EXPL_ASSOC_HDR_REQUIRED 0x13
244 #define FC_EXPL_INV_ORIGINATOR_S_ID 0x15
245 #define FC_EXPL_INV_X_ID_COMBINATION 0x17
246 #define FC_EXPL_COMMAND_IN_PROGRESS 0x19
247 #define FC_EXPL_NPORT_LOGIN_REQUIRED 0x1e
248 #define FC_EXPL_N_PORT_ID 0x1f
249 #define FC_EXPL_INSUFFICIENT_RESOURCES 0x29
250 #define FC_EXPL_UNABLE_TO_SUPPLY_DATA 0x2a
251 #define FC_EXPL_REQUEST_NOT_SUPPORTED 0x2c
252 #define FC_EXPL_INV_PAYLOAD_LEN 0x1d
253 #define FC_EXPL_INV_PORT_NODE_NAME 0x44
254 #define FC_EXPL_LOGIN_EXT_NOT_SUPPORTED 0x46
255 #define FC_EXPL_AUTH_REQUIRED 0x48
256 #define FC_EXPL_SCAN_VALUE_NOT_ALLOWED 0x50
257 #define FC_EXPL_SCAN_VALUE_NOT_SUPPORTED 0x51
258 #define FC_EXPL_NO_RESOURCES_ASSIGNED 0x52
259 #define FC_EXPL_MAC_ADDR_MODE_NOT_SUPPORTED 0x60
260 #define FC_EXPL_MAC_ADDR_INCORRECTLY_FORMED 0x61
261 #define FC_EXPL_VN2VN_PORT_NOT_IN_NEIGHBOR_SET 0x62
263 #define FC_EXPL_INV_X_ID 0x03 /* invalid OX_ID - RX_ID combination */
264 #define FC_EXPL_SEQUENCE_ABORTED 0x05
266 typedef struct fc_ba_acc_payload_s {
267 #define FC_SEQ_ID_VALID 0x80
268 #define FC_SEQ_ID_INVALID 0x00
269 uint32_t seq_id_validity:8,
274 uint32_t low_seq_cnt:16,
276 } fc_ba_acc_payload_t;
278 typedef struct fc_ba_rjt_payload_s {
279 uint32_t vendor_unique:8,
280 reason_explanation:8,
283 } fc_ba_rjt_payload_t;
285 typedef struct fc_els_gen_s {
286 uint32_t command_code: 8,
290 typedef struct fc_plogi_playload_s {
291 uint32_t command_code: 8,
293 uint32_t common_service_parameters[4];
294 uint32_t port_name_hi;
295 uint32_t port_name_lo;
296 uint32_t node_name_hi;
297 uint32_t node_name_lo;
298 uint32_t class1_service_parameters[4];
299 uint32_t class2_service_parameters[4];
300 uint32_t class3_service_parameters[4];
301 uint32_t class4_service_parameters[4];
302 uint32_t vendor_version_level[4];
303 } fc_plogi_payload_t;
305 typedef fc_plogi_payload_t fc_sparms_t;
307 typedef struct fc_logo_payload_s {
308 uint32_t command_code: 8,
312 uint32_t port_name_hi;
313 uint32_t port_name_lo;
316 typedef struct fc_acc_payload_s {
317 uint32_t command_code: 8,
321 typedef struct fc_ls_rjt_payload_s {
322 uint32_t command_code:8,
328 } fc_ls_rjt_payload_t;
330 typedef struct fc_prli_payload_s {
331 uint32_t command_code:8,
337 uint32_t originator_pa;
338 uint32_t responder_pa;
343 typedef struct fc_prlo_payload_s {
344 uint32_t command_code:8,
355 typedef struct fc_prlo_acc_payload_s {
356 uint32_t command_code:8,
367 } fc_prlo_acc_payload_t;
369 typedef struct fc_adisc_payload_s {
370 uint32_t command_code:8,
374 uint32_t port_name_hi;
375 uint32_t port_name_lo;
376 uint32_t node_name_hi;
377 uint32_t node_name_lo;
380 } fc_adisc_payload_t;
383 #define FC_PRLI_ORIGINATOR_PA_VALID 0x8000
384 #define FC_PRLI_RESPONDER_PA_VALID 0x4000
385 #define FC_PRLI_ESTABLISH_IMAGE_PAIR 0x2000
386 #define FC_PRLI_SERVICE_PARAM_INVALID 0x0800
387 #define FC_PRLI_REQUEST_EXECUTED 0x0100
389 /* PRLI Service Parameters */
390 #define FC_PRLI_REC_SUPPORT 0x0400
391 #define FC_PRLI_TASK_RETRY_ID_REQ 0x0200
392 #define FC_PRLI_RETRY 0x0100
393 #define FC_PRLI_CONFIRMED_COMPLETION 0x0080
394 #define FC_PRLI_DATA_OVERLAY 0x0040
395 #define FC_PRLI_INITIATOR_FUNCTION 0x0020
396 #define FC_PRLI_TARGET_FUNCTION 0x0010
397 #define FC_PRLI_READ_XRDY_DISABLED 0x0002
398 #define FC_PRLI_WRITE_XRDY_DISABLED 0x0001
400 /* PRLO Logout flags */
401 #define FC_PRLO_REQUEST_EXECUTED 0x0001
403 typedef struct fc_scr_payload_s {
404 uint32_t command_code:8,
410 #define FC_SCR_REG_FABRIC 1
411 #define FC_SCR_REG_NPORT 2
412 #define FC_SCR_REG_FULL 3
416 rscn_event_qualifier:4,
419 } fc_rscn_affected_port_id_page_t;
421 typedef struct fc_rscn_payload_s {
422 uint32_t command_code:8,
425 fc_rscn_affected_port_id_page_t port_list[1];
428 typedef struct fcct_iu_header_s {
429 #if BYTE_ORDER == LITTLE_ENDIAN
436 uint32_t cmd_rsp_code:16,
437 max_residual_size:16;
438 uint32_t fragment_id:8,
440 reason_code_explanation:8,
443 #error big endian version not defined
447 #define FCCT_REJECT_INVALID_COMMAND_CODE 1
448 #define FCCT_REJECT_INVALID_VERSION_LEVEL 2
449 #define FCCT_LOGICAL_ERROR 3
450 #define FCCT_INVALID_CT_IU_SIZE 4
451 #define FCCT_LOGICAL_BUSY 5
452 #define FCCT_PROTOCOL_ERROR 7
453 #define FCCT_UNABLE_TO_PERFORM 9
454 #define FCCT_COMMAND_NOT_SUPPORTED 0x0b
455 #define FCCT_FABRIC_PORT_NAME_NOT_REGISTERED 0x0c
456 #define FCCT_SERVER_NOT_AVAILABLE 0x0d
457 #define FCCT_SESSION_COULD_NOT_BE_ESTABLISHED 0x0e
458 #define FCCT_VENDOR_SPECIFIC_ERROR 0xff
460 #define FCCT_NO_ADDITIONAL_EXPLANATION 0
461 #define FCCT_AUTHORIZATION_EXCEPTION 0xf0
462 #define FCCT_AUTHENTICATION_EXCEPTION 0xf1
463 #define FCCT_DATA_BASE_FULL 0xf2
464 #define FCCT_DATA_BASE_EMPTY 0xf3
465 #define FCCT_PROCESSING_REQUEST 0xf4
466 #define FCCT_UNABLE_TO_VERIFY_CONNECTION 0xf5
467 #define FCCT_DEVICES_NOT_IN_COMMON_ZONE 0xf6
470 fcct_iu_header_t hdr;
471 #if BYTE_ORDER == LITTLE_ENDIAN
475 #error big endian version not defined
480 fcct_iu_header_t hdr;
481 #if BYTE_ORDER == LITTLE_ENDIAN
487 #error big endian version not defined
493 fcct_iu_header_t hdr;
494 #if BYTE_ORDER == LITTLE_ENDIAN
498 #error big endian version not defined
505 fcct_iu_header_t hdr;
506 #if BYTE_ORDER == LITTLE_ENDIAN
510 #error big endian version not defined
515 #define FCCT_CLASS_OF_SERVICE_F 0x1
516 #define FCCT_CLASS_OF_SERVICE_2 0x4
517 #define FCCT_CLASS_OF_SERVICE_3 0x8
520 fcct_iu_header_t hdr;
521 #if BYTE_ORDER == LITTLE_ENDIAN
523 uint32_t class_of_srvc;
525 #error big endian version not defined
532 fcct_iu_header_t hdr;
533 #if BYTE_ORDER == LITTLE_ENDIAN
536 char sym_node_name[1];
537 /*TODO: need name length and symbolic name */
539 #error big endian version not defined
544 #define FCCT_HDR_CMDRSP_ACCEPT 0x8002
545 #define FCCT_HDR_CMDRSP_REJECT 0x8001
547 static inline void fcct_build_req_header(fcct_iu_header_t *hdr, uint16_t cmd, uint16_t max_size)
549 /* use old rev (1) to accommodate older switches */
552 hdr->gs_type = FC_GS_TYPE_DIRECTORY_SERVICE;
553 hdr->gs_subtype = FC_GS_SUBTYPE_NAME_SERVER;
556 hdr->cmd_rsp_code = ocs_htobe16(cmd);
557 hdr->max_residual_size = ocs_htobe16(max_size/(sizeof(uint32_t))); /* words */
558 hdr->fragment_id = 0;
559 hdr->reason_code = 0;
560 hdr->reason_code_explanation = 0;
561 hdr->vendor_specific = 0;
564 typedef struct fcct_rftid_req_s {
565 fcct_iu_header_t hdr;
567 uint32_t fc4_types[8];
570 #define FC4_FEATURE_TARGET (1U << 0)
571 #define FC4_FEATURE_INITIATOR (1U << 1)
573 typedef struct fcct_rffid_req_s {
574 fcct_iu_header_t hdr;
581 typedef struct fcct_gnnid_req_s {
582 fcct_iu_header_t hdr;
587 typedef struct fcct_gpnid_req_s {
588 fcct_iu_header_t hdr;
593 typedef struct fcct_gffid_req_s {
594 fcct_iu_header_t hdr;
599 typedef struct fcct_gidft_req_s {
600 fcct_iu_header_t hdr;
607 typedef struct fcct_gidpt_req_s {
608 fcct_iu_header_t hdr;
609 uint32_t port_type:8,
615 typedef struct fcct_gnnid_acc_s {
616 fcct_iu_header_t hdr;
620 typedef struct fcct_gpnid_acc_s {
621 fcct_iu_header_t hdr;
625 typedef struct fcct_gffid_acc_s {
626 fcct_iu_header_t hdr;
627 uint8_t fc4_feature_bits;
630 typedef struct fcct_gidft_acc_s {
631 fcct_iu_header_t hdr;
638 typedef struct fcct_gidpt_acc_s {
639 fcct_iu_header_t hdr;
646 #define FCCT_GID_PT_LAST_ID 0x80
647 #define FCCT_GIDPT_ID_MASK 0x00ffffff
649 typedef struct fcp_cmnd_iu_s {
651 uint8_t command_reference_number;
652 uint8_t task_attribute:3,
655 uint8_t task_management_flags;
658 additional_fcp_cdb_length:6;
660 uint8_t fcp_cdb_and_dl[20]; /* < May contain up to 16 bytes of CDB, followed by fcp_dl */
663 #define FCP_LUN_ADDRESS_METHOD_SHIFT 6
664 #define FCP_LUN_ADDRESS_METHOD_MASK 0xc0
665 #define FCP_LUN_ADDR_METHOD_PERIPHERAL 0x0
666 #define FCP_LUN_ADDR_METHOD_FLAT 0x1
667 #define FCP_LUN_ADDR_METHOD_LOGICAL 0x2
668 #define FCP_LUN_ADDR_METHOD_EXTENDED 0x3
670 #define FCP_LUN_ADDR_SIMPLE_MAX 0xff
671 #define FCP_LUN_ADDR_FLAT_MAX 0x3fff
673 #define FCP_TASK_ATTR_SIMPLE 0x0
674 #define FCP_TASK_ATTR_HEAD_OF_QUEUE 0x1
675 #define FCP_TASK_ATTR_ORDERED 0x2
676 #define FCP_TASK_ATTR_ACA 0x4
677 #define FCP_TASK_ATTR_UNTAGGED 0x5
679 #define FCP_QUERY_TASK_SET BIT(0)
680 #define FCP_ABORT_TASK_SET BIT(1)
681 #define FCP_CLEAR_TASK_SET BIT(2)
682 #define FCP_QUERY_ASYNCHRONOUS_EVENT BIT(3)
683 #define FCP_LOGICAL_UNIT_RESET BIT(4)
684 #define FCP_TARGET_RESET BIT(5)
685 #define FCP_CLEAR_ACA BIT(6)
687 /* SPC-4 says that the maximum length of sense data is 252 bytes */
688 #define FCP_MAX_SENSE_LEN 252
689 #define FCP_MAX_RSP_LEN 8
691 * FCP_RSP buffer will either have sense or response data, but not both
692 * so pick the larger.
694 #define FCP_MAX_RSP_INFO_LEN FCP_MAX_SENSE_LEN
696 typedef struct fcp_rsp_iu_s {
698 uint8_t status_qualifier[2];
701 uint8_t fcp_resid[4];
702 uint8_t fcp_sns_len[4];
703 uint8_t fcp_rsp_len[4];
704 uint8_t data[FCP_MAX_RSP_INFO_LEN];
707 /** Flag field defines: */
708 #define FCP_RSP_LEN_VALID BIT(0)
709 #define FCP_SNS_LEN_VALID BIT(1)
710 #define FCP_RESID_OVER BIT(2)
711 #define FCP_RESID_UNDER BIT(3)
712 #define FCP_CONF_REQ BIT(4)
713 #define FCP_BIDI_READ_RESID_OVER BIT(5)
714 #define FCP_BIDI_READ_RESID_UNDER BIT(6)
715 #define FCP_BIDI_RSP BIT(7)
717 /** Status values: */
718 #define FCP_TMF_COMPLETE 0x00
719 #define FCP_DATA_LENGTH_MISMATCH 0x01
720 #define FCP_INVALID_FIELD 0x02
721 #define FCP_DATA_RO_MISMATCH 0x03
722 #define FCP_TMF_REJECTED 0x04
723 #define FCP_TMF_FAILED 0x05
724 #define FCP_TMF_SUCCEEDED 0x08
725 #define FCP_TMF_INCORRECT_LUN 0x09
727 /** FCP-4 Table 28, TMF response information: */
728 typedef struct fc_rsp_info_s {
729 uint8_t addl_rsp_info[3];
734 typedef struct fcp_xfer_rdy_iu_s {
735 uint8_t fcp_data_ro[4];
736 uint8_t fcp_burst_len[4];
740 #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))
742 #endif /* !_OCS_FCP_H */