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
99 #define FC_GS_REVISION 0x03
101 #define FC_GS_IO_PARAMS { .fc_ct.r_ctl = 0x02, \
102 .fc_ct.type = FC_TYPE_GS, \
103 .fc_ct.df_ctl = 0x00 }
105 typedef struct fc_vft_header_s {
119 #if BYTE_ORDER == LITTLE_ENDIAN
120 static inline uint32_t fc_be24toh(uint32_t x) { return (ocs_be32toh(x) >> 8); }
122 static inline uint32_t fc_be24toh(uint32_t x) { }
124 static inline uint32_t fc_htobe24(uint32_t x) { return fc_be24toh(x); }
126 #define FC_SOFI3 0x2e
127 #define FC_SOFn3 0x36
132 * @brief FC header in big-endian order
134 typedef struct fc_header_s {
152 * @brief FC header in little-endian order
154 typedef struct fc_header_le_s {
155 #if BYTE_ORDER == LITTLE_ENDIAN
170 #error big endian version not defined
175 * @brief FC VM header in big-endian order
177 typedef struct fc_vm_header_s {
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
190 #define FC_RCTL_FC4_DATA 0
191 #define FC_RCTL_ELS 2
192 #define FC_RCTL_BLS 8
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
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
214 * Common BLS definitions:
216 #define FC_INFO_NOP 0x0
217 #define FC_INFO_ABTS 0x1
218 #define FC_INFO_RMC 0x2
220 #define FC_INFO_BA_ACC 0x4
221 #define FC_INFO_BA_RJT 0x5
222 #define FC_INFO_PRMT 0x6
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
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
266 #define FC_EXPL_INV_X_ID 0x03 /* invalid OX_ID - RX_ID combination */
267 #define FC_EXPL_SEQUENCE_ABORTED 0x05
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,
277 uint32_t low_seq_cnt:16,
279 } fc_ba_acc_payload_t;
281 typedef struct fc_ba_rjt_payload_s {
282 uint32_t vendor_unique:8,
283 reason_explanation:8,
286 } fc_ba_rjt_payload_t;
288 typedef struct fc_els_gen_s {
289 uint32_t command_code: 8,
293 typedef struct fc_plogi_playload_s {
294 uint32_t command_code: 8,
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;
308 typedef fc_plogi_payload_t fc_sparms_t;
310 typedef struct fc_logo_payload_s {
311 uint32_t command_code: 8,
315 uint32_t port_name_hi;
316 uint32_t port_name_lo;
319 typedef struct fc_acc_payload_s {
320 uint32_t command_code: 8,
325 typedef struct fc_ls_rjt_payload_s {
326 uint32_t command_code:8,
332 } fc_ls_rjt_payload_t;
334 typedef struct fc_prli_payload_s {
335 uint32_t command_code:8,
341 uint32_t originator_pa;
342 uint32_t responder_pa;
347 typedef struct fc_prlo_payload_s {
348 uint32_t command_code:8,
359 typedef struct fc_prlo_acc_payload_s {
360 uint32_t command_code:8,
371 } fc_prlo_acc_payload_t;
373 typedef struct fc_adisc_payload_s {
374 uint32_t command_code:8,
378 uint32_t port_name_hi;
379 uint32_t port_name_lo;
380 uint32_t node_name_hi;
381 uint32_t node_name_lo;
384 } fc_adisc_payload_t;
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
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
404 /* PRLO Logout flags */
405 #define FC_PRLO_REQUEST_EXECUTED 0x0001
407 typedef struct fc_scr_payload_s {
408 uint32_t command_code:8,
414 #define FC_SCR_REG_FABRIC 1
415 #define FC_SCR_REG_NPORT 2
416 #define FC_SCR_REG_FULL 3
420 rscn_event_qualifier:4,
423 } fc_rscn_affected_port_id_page_t;
425 typedef struct fc_rscn_payload_s {
426 uint32_t command_code:8,
429 fc_rscn_affected_port_id_page_t port_list[1];
432 typedef struct fcct_iu_header_s {
433 #if BYTE_ORDER == LITTLE_ENDIAN
440 uint32_t cmd_rsp_code:16,
441 max_residual_size:16;
442 uint32_t fragment_id:8,
444 reason_code_explanation:8,
447 #error big endian version not defined
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
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
474 fcct_iu_header_t hdr;
475 #if BYTE_ORDER == LITTLE_ENDIAN
479 #error big endian version not defined
484 fcct_iu_header_t hdr;
485 #if BYTE_ORDER == LITTLE_ENDIAN
491 #error big endian version not defined
497 fcct_iu_header_t hdr;
498 #if BYTE_ORDER == LITTLE_ENDIAN
502 #error big endian version not defined
509 fcct_iu_header_t hdr;
510 #if BYTE_ORDER == LITTLE_ENDIAN
514 #error big endian version not defined
519 #define FCCT_CLASS_OF_SERVICE_F 0x1
520 #define FCCT_CLASS_OF_SERVICE_2 0x4
521 #define FCCT_CLASS_OF_SERVICE_3 0x8
524 fcct_iu_header_t hdr;
525 #if BYTE_ORDER == LITTLE_ENDIAN
527 uint32_t class_of_srvc;
529 #error big endian version not defined
536 fcct_iu_header_t hdr;
537 #if BYTE_ORDER == LITTLE_ENDIAN
540 char sym_node_name[1];
541 /*TODO: need name length and symbolic name */
543 #error big endian version not defined
548 #define FCCT_HDR_CMDRSP_ACCEPT 0x8002
549 #define FCCT_HDR_CMDRSP_REJECT 0x8001
551 static inline void fcct_build_req_header(fcct_iu_header_t *hdr, uint16_t cmd, uint16_t max_size)
553 /* use old rev (1) to accommodate older switches */
556 hdr->gs_type = FC_GS_TYPE_DIRECTORY_SERVICE;
557 hdr->gs_subtype = FC_GS_SUBTYPE_NAME_SERVER;
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;
568 typedef struct fcct_rftid_req_s {
569 fcct_iu_header_t hdr;
571 uint32_t fc4_types[8];
574 #define FC4_FEATURE_TARGET (1U << 0)
575 #define FC4_FEATURE_INITIATOR (1U << 1)
577 typedef struct fcct_rffid_req_s {
578 fcct_iu_header_t hdr;
585 typedef struct fcct_gnnid_req_s {
586 fcct_iu_header_t hdr;
591 typedef struct fcct_gpnid_req_s {
592 fcct_iu_header_t hdr;
597 typedef struct fcct_gffid_req_s {
598 fcct_iu_header_t hdr;
603 typedef struct fcct_gidft_req_s {
604 fcct_iu_header_t hdr;
611 typedef struct fcct_gidpt_req_s {
612 fcct_iu_header_t hdr;
613 uint32_t port_type:8,
619 typedef struct fcct_gnnid_acc_s {
620 fcct_iu_header_t hdr;
624 typedef struct fcct_gpnid_acc_s {
625 fcct_iu_header_t hdr;
629 typedef struct fcct_gffid_acc_s {
630 fcct_iu_header_t hdr;
631 uint8_t fc4_feature_bits;
634 typedef struct fcct_gidft_acc_s {
635 fcct_iu_header_t hdr;
642 typedef struct fcct_gidpt_acc_s {
643 fcct_iu_header_t hdr;
650 #define FCCT_GID_PT_LAST_ID 0x80
651 #define FCCT_GIDPT_ID_MASK 0x00ffffff
653 typedef struct fcp_cmnd_iu_s {
655 uint8_t command_reference_number;
656 uint8_t task_attribute:3,
659 uint8_t task_management_flags;
662 additional_fcp_cdb_length:6;
664 uint8_t fcp_cdb_and_dl[20]; /* < May contain up to 16 bytes of CDB, followed by fcp_dl */
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
674 #define FCP_LUN_ADDR_SIMPLE_MAX 0xff
675 #define FCP_LUN_ADDR_FLAT_MAX 0x3fff
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
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)
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
695 * FCP_RSP buffer will either have sense or response data, but not both
696 * so pick the larger.
698 #define FCP_MAX_RSP_INFO_LEN FCP_MAX_SENSE_LEN
700 typedef struct fcp_rsp_iu_s {
702 uint8_t status_qualifier[2];
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];
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)
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
731 /** FCP-4 Table 28, TMF response information: */
732 typedef struct fc_rsp_info_s {
733 uint8_t addl_rsp_info[3];
738 typedef struct fcp_xfer_rdy_iu_s {
739 uint8_t fcp_data_ro[4];
740 uint8_t fcp_burst_len[4];
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))
747 #endif /* !_OCS_FCP_H */