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 32 /** 33 * @file 34 * Contains declarations shared between the alex layer and HW/SLI4 35 */ 36 37 #if !defined(__OCS_COMMON_H__) 38 #define __OCS_COMMON_H__ 39 40 #include "ocs_sm.h" 41 #include "ocs_utils.h" 42 43 #define OCS_CTRLMASK_XPORT_DISABLE_AUTORSP_TSEND (1U << 0) 44 #define OCS_CTRLMASK_XPORT_DISABLE_AUTORSP_TRECEIVE (1U << 1) 45 #define OCS_CTRLMASK_XPORT_ENABLE_TARGET_RSCN (1U << 3) 46 #define OCS_CTRLMASK_TGT_ALWAYS_VERIFY_DIF (1U << 4) 47 #define OCS_CTRLMASK_TGT_SET_DIF_REF_TAG_CRC (1U << 5) 48 #define OCS_CTRLMASK_TEST_CHAINED_SGLS (1U << 6) 49 #define OCS_CTRLMASK_ISCSI_ISNS_ENABLE (1U << 7) 50 #define OCS_CTRLMASK_ENABLE_FABRIC_EMULATION (1U << 8) 51 #define OCS_CTRLMASK_INHIBIT_INITIATOR (1U << 9) 52 #define OCS_CTRLMASK_CRASH_RESET (1U << 10) 53 54 #define enable_target_rscn(ocs) \ 55 ((ocs->ctrlmask & OCS_CTRLMASK_XPORT_ENABLE_TARGET_RSCN) != 0) 56 57 /* Used for error injection testing. */ 58 typedef enum { 59 NO_ERR_INJECT = 0, 60 INJECT_DROP_CMD, 61 INJECT_FREE_DROPPED, 62 INJECT_DROP_DATA, 63 INJECT_DROP_RESP, 64 INJECT_DELAY_CMD, 65 } ocs_err_injection_e; 66 67 #define MAX_OCS_DEVICES 64 68 69 typedef enum {OCS_XPORT_FC, OCS_XPORT_ISCSI} ocs_xport_e; 70 71 #define OCS_SERVICE_PARMS_LENGTH 0x74 72 #define OCS_DISPLAY_NAME_LENGTH 32 73 #define OCS_DISPLAY_BUS_INFO_LENGTH 16 74 75 #define OCS_WWN_LENGTH 32 76 77 typedef struct ocs_hw_s ocs_hw_t; 78 typedef struct ocs_domain_s ocs_domain_t; 79 typedef struct ocs_sli_port_s ocs_sli_port_t; 80 typedef struct ocs_sli_port_s ocs_sport_t; 81 typedef struct ocs_remote_node_s ocs_remote_node_t; 82 typedef struct ocs_remote_node_group_s ocs_remote_node_group_t; 83 typedef struct ocs_node_s ocs_node_t; 84 typedef struct ocs_io_s ocs_io_t; 85 typedef struct ocs_xport_s ocs_xport_t; 86 typedef struct ocs_node_cb_s ocs_node_cb_t; 87 typedef struct ocs_ns_s ocs_ns_t; 88 89 /* Node group data structure */ 90 typedef struct ocs_node_group_dir_s ocs_node_group_dir_t; 91 92 #include "ocs_cam.h" 93 94 /*-------------------------------------------------- 95 * Shared HW/SLI objects 96 * 97 * Several objects used by the HW/SLI layers are communal; part of the 98 * object is for the sole use of the lower layers, but implementations 99 * are free to add their own fields if desired. 100 */ 101 102 /** 103 * @brief Description of discovered Fabric Domain 104 * 105 * @note Not all fields are valid for all mediums (FC/ethernet). 106 */ 107 typedef struct ocs_domain_record_s { 108 uint32_t index; /**< FCF table index (used in REG_FCFI) */ 109 uint32_t priority; /**< FCF reported priority */ 110 uint8_t address[6]; /**< Switch MAC/FC address */ 111 uint8_t wwn[8]; /**< Switch WWN */ 112 union { 113 uint8_t vlan[512]; /**< bitmap of valid VLAN IDs */ 114 uint8_t loop[128]; /**< FC-AL position map */ 115 } map; 116 uint32_t speed; /**< link speed */ 117 uint32_t fc_id; /**< our ports fc_id */ 118 uint32_t is_fc:1, /**< Connection medium is native FC */ 119 is_ethernet:1, /**< Connection medium is ethernet (FCoE) */ 120 is_loop:1, /**< Topology is FC-AL */ 121 is_nport:1, /**< Topology is N-PORT */ 122 :28; 123 } ocs_domain_record_t; 124 125 /** 126 * @brief Node group directory entry 127 */ 128 struct ocs_node_group_dir_s { 129 uint32_t instance_index; /*<< instance index */ 130 ocs_sport_t *sport; /*<< pointer to sport */ 131 uint8_t service_params[OCS_SERVICE_PARMS_LENGTH]; /**< Login parameters */ 132 ocs_list_link_t link; /**< linked list link */ 133 ocs_list_t node_group_list; /**< linked list of node groups */ 134 uint32_t node_group_list_count; /**< current number of elements on the node group list */ 135 uint32_t next_idx; /*<< index of the next node group in list */ 136 }; 137 138 typedef enum { 139 OCS_SPORT_TOPOLOGY_UNKNOWN=0, 140 OCS_SPORT_TOPOLOGY_FABRIC, 141 OCS_SPORT_TOPOLOGY_P2P, 142 OCS_SPORT_TOPOLOGY_LOOP, 143 } ocs_sport_topology_e; 144 145 /** 146 * @brief SLI Port object 147 * 148 * The SLI Port object represents the connection between the driver and the 149 * FC/FCoE domain. In some topologies / hardware, it is possible to have 150 * multiple connections to the domain via different WWN. Each would require 151 * a separate SLI port object. 152 */ 153 struct ocs_sli_port_s { 154 ocs_t *ocs; /**< pointer to ocs */ 155 uint32_t tgt_id; /**< target id */ 156 uint32_t index; /**< ??? */ 157 uint32_t instance_index; 158 char display_name[OCS_DISPLAY_NAME_LENGTH]; /**< sport display name */ 159 ocs_domain_t *domain; /**< current fabric domain */ 160 uint32_t is_vport:1; /**< this SPORT is a virtual port */ 161 uint64_t wwpn; /**< WWPN from HW (host endian) */ 162 uint64_t wwnn; /**< WWNN from HW (host endian) */ 163 ocs_list_t node_list; /**< list of nodes */ 164 ocs_scsi_ini_sport_t ini_sport; /**< initiator backend private sport data */ 165 ocs_scsi_tgt_sport_t tgt_sport; /**< target backend private sport data */ 166 void *tgt_data; /**< target backend private pointer */ 167 void *ini_data; /**< initiator backend private pointer */ 168 ocs_mgmt_functions_t *mgmt_functions; 169 170 /* 171 * Members private to HW/SLI 172 */ 173 ocs_sm_ctx_t ctx; /**< state machine context */ 174 ocs_hw_t *hw; /**< pointer to HW */ 175 uint32_t indicator; /**< VPI */ 176 uint32_t fc_id; /**< FC address */ 177 ocs_dma_t dma; /**< memory for Service Parameters */ 178 179 uint8_t wwnn_str[OCS_WWN_LENGTH]; /**< WWN (ASCII) */ 180 uint64_t sli_wwpn; /**< WWPN (wire endian) */ 181 uint64_t sli_wwnn; /**< WWNN (wire endian) */ 182 uint32_t sm_free_req_pending:1; /**< Free request received while waiting for attach response */ 183 184 /* 185 * Implementation specific fields allowed here 186 */ 187 ocs_sm_ctx_t sm; /**< sport context state machine */ 188 sparse_vector_t lookup; /**< fc_id to node lookup object */ 189 ocs_list_link_t link; 190 uint32_t enable_ini:1, /**< SCSI initiator enabled for this node */ 191 enable_tgt:1, /**< SCSI target enabled for this node */ 192 enable_rscn:1, /**< This SPORT will be expecting RSCN */ 193 shutting_down:1, /**< sport in process of shutting down */ 194 p2p_winner:1; /**< TRUE if we're the point-to-point winner */ 195 ocs_sport_topology_e topology; /**< topology: fabric/p2p/unknown */ 196 uint8_t service_params[OCS_SERVICE_PARMS_LENGTH]; /**< Login parameters */ 197 uint32_t p2p_remote_port_id; /**< Remote node's port id for p2p */ 198 uint32_t p2p_port_id; /**< our port's id */ 199 200 /* List of remote node group directory entries (used by high login mode) */ 201 ocs_lock_t node_group_lock; 202 uint32_t node_group_dir_next_instance; /**< HLM next node group directory instance value */ 203 uint32_t node_group_next_instance; /**< HLM next node group instance value */ 204 ocs_list_t node_group_dir_list; 205 }; 206 207 /** 208 * @brief Fibre Channel domain object 209 * 210 * This object is a container for the various SLI components needed 211 * to connect to the domain of a FC or FCoE switch 212 */ 213 struct ocs_domain_s { 214 ocs_t *ocs; /**< pointer back to ocs */ 215 uint32_t instance_index; /**< unique instance index value */ 216 char display_name[OCS_DISPLAY_NAME_LENGTH]; /**< Node display name */ 217 ocs_list_t sport_list; /**< linked list of SLI ports */ 218 ocs_scsi_ini_domain_t ini_domain; /**< initiator backend private domain data */ 219 ocs_scsi_tgt_domain_t tgt_domain; /**< target backend private domain data */ 220 ocs_mgmt_functions_t *mgmt_functions; 221 222 /* Declarations private to HW/SLI */ 223 ocs_hw_t *hw; /**< pointer to HW */ 224 ocs_sm_ctx_t sm; /**< state machine context */ 225 uint32_t fcf; /**< FC Forwarder table index */ 226 uint32_t fcf_indicator; /**< FCFI */ 227 uint32_t vlan_id; /**< VLAN tag for this domain */ 228 uint32_t indicator; /**< VFI */ 229 ocs_dma_t dma; /**< memory for Service Parameters */ 230 uint32_t req_rediscover_fcf:1; /**< TRUE if fcf rediscover is needed (in response 231 * to Vlink Clear async event */ 232 233 /* Declarations private to FC transport */ 234 uint64_t fcf_wwn; /**< WWN for FCF/switch */ 235 ocs_list_link_t link; 236 ocs_sm_ctx_t drvsm; /**< driver domain sm context */ 237 uint32_t attached:1, /**< set true after attach completes */ 238 is_fc:1, /**< is FC */ 239 is_loop:1, /**< is loop topology */ 240 is_nlport:1, /**< is public loop */ 241 domain_found_pending:1, /**< A domain found is pending, drec is updated */ 242 req_domain_free:1, /**< True if domain object should be free'd */ 243 req_accept_frames:1, /**< set in domain state machine to enable frames */ 244 domain_notify_pend:1; /** Set in domain SM to avoid duplicate node event post */ 245 ocs_domain_record_t pending_drec; /**< Pending drec if a domain found is pending */ 246 uint8_t service_params[OCS_SERVICE_PARMS_LENGTH]; /**< any sports service parameters */ 247 uint8_t flogi_service_params[OCS_SERVICE_PARMS_LENGTH]; /**< Fabric/P2p service parameters from FLOGI */ 248 uint8_t femul_enable; /**< TRUE if Fabric Emulation mode is enabled */ 249 250 /* Declarations shared with back-ends */ 251 sparse_vector_t lookup; /**< d_id to node lookup object */ 252 ocs_lock_t lookup_lock; 253 254 ocs_sli_port_t *sport; /**< Pointer to first (physical) SLI port (also at the head of sport_list) */ 255 uint32_t sport_instance_count; /**< count of sport instances */ 256 257 /* Fabric Emulation */ 258 ocs_bitmap_t *portid_pool; 259 ocs_ns_t *ocs_ns; /*>> Directory(Name) services data */ 260 }; 261 262 /** 263 * @brief Remote Node object 264 * 265 * This object represents a connection between the SLI port and another 266 * Nx_Port on the fabric. Note this can be either a well known port such 267 * as a F_Port (i.e. ff:ff:fe) or another N_Port. 268 */ 269 struct ocs_remote_node_s { 270 /* 271 * Members private to HW/SLI 272 */ 273 uint32_t indicator; /**< RPI */ 274 uint32_t index; 275 uint32_t fc_id; /**< FC address */ 276 277 uint32_t attached:1, /**< true if attached */ 278 node_group:1, /**< true if in node group */ 279 free_group:1; /**< true if the node group should be free'd */ 280 281 ocs_sli_port_t *sport; /**< associated SLI port */ 282 283 /* 284 * Implementation specific fields allowed here 285 */ 286 void *node; /**< associated node */ 287 }; 288 289 struct ocs_remote_node_group_s { 290 /* 291 * Members private to HW/SLI 292 */ 293 uint32_t indicator; /**< RPI */ 294 uint32_t index; 295 296 /* 297 * Implementation specific fields allowed here 298 */ 299 300 uint32_t instance_index; /*<< instance index */ 301 ocs_node_group_dir_t *node_group_dir; /*<< pointer to the node group directory */ 302 ocs_list_link_t link; /*<< linked list link */ 303 }; 304 305 typedef enum { 306 OCS_NODE_SHUTDOWN_DEFAULT = 0, 307 OCS_NODE_SHUTDOWN_EXPLICIT_LOGO, 308 OCS_NODE_SHUTDOWN_IMPLICIT_LOGO, 309 } ocs_node_shutd_rsn_e; 310 311 typedef enum { 312 OCS_NODE_SEND_LS_ACC_NONE = 0, 313 OCS_NODE_SEND_LS_ACC_PLOGI, 314 OCS_NODE_SEND_LS_ACC_PRLI, 315 } ocs_node_send_ls_acc_e; 316 317 /** 318 * @brief FC Node object 319 * 320 */ 321 struct ocs_node_s { 322 ocs_t *ocs; /**< pointer back to ocs structure */ 323 uint32_t instance_index; /**< unique instance index value */ 324 char display_name[OCS_DISPLAY_NAME_LENGTH]; /**< Node display name */ 325 ocs_sport_t *sport; 326 uint32_t hold_frames:1; /**< hold incoming frames if true */ 327 ocs_rlock_t lock; /**< node wide lock */ 328 ocs_lock_t active_ios_lock; /**< active SCSI and XPORT I/O's for this node */ 329 ocs_list_t active_ios; /**< active I/O's for this node */ 330 uint32_t max_wr_xfer_size; /**< Max write IO size per phase for the transport */ 331 ocs_scsi_ini_node_t ini_node; /**< backend initiator private node data */ 332 ocs_scsi_tgt_node_t tgt_node; /**< backend target private node data */ 333 ocs_mgmt_functions_t *mgmt_functions; 334 335 /* Declarations private to HW/SLI */ 336 ocs_remote_node_t rnode; /**< Remote node */ 337 338 /* Declarations private to FC transport */ 339 ocs_sm_ctx_t sm; /**< state machine context */ 340 uint32_t evtdepth; /**< current event posting nesting depth */ 341 uint32_t req_free:1, /**< this node is to be free'd */ 342 attached:1, /**< node is attached (REGLOGIN complete) */ 343 fcp_enabled:1, /**< node is enabled to handle FCP */ 344 rscn_pending:1, /**< for name server node RSCN is pending */ 345 send_plogi:1, /**< if initiator, send PLOGI at node initialization */ 346 send_plogi_acc:1,/**< send PLOGI accept, upon completion of node attach */ 347 io_alloc_enabled:1, /**< TRUE if ocs_scsi_io_alloc() and ocs_els_io_alloc() are enabled */ 348 sent_prli:1; /**< if initiator, sent prli. */ 349 ocs_node_send_ls_acc_e send_ls_acc; /**< type of LS acc to send */ 350 ocs_io_t *ls_acc_io; /**< SCSI IO for LS acc */ 351 uint32_t ls_acc_oxid; /**< OX_ID for pending accept */ 352 uint32_t ls_acc_did; /**< D_ID for pending accept */ 353 ocs_node_shutd_rsn_e shutdown_reason;/**< reason for node shutdown */ 354 ocs_dma_t sparm_dma_buf; /**< service parameters buffer */ 355 uint8_t service_params[OCS_SERVICE_PARMS_LENGTH]; /**< plogi/acc frame from remote device */ 356 ocs_lock_t pend_frames_lock; /**< lock for inbound pending frames list */ 357 ocs_list_t pend_frames; /**< inbound pending frames list */ 358 uint32_t pend_frames_processed; /**< count of frames processed in hold frames interval */ 359 uint32_t ox_id_in_use; /**< used to verify one at a time us of ox_id */ 360 uint32_t els_retries_remaining; /**< for ELS, number of retries remaining */ 361 uint32_t els_req_cnt; /**< number of outstanding ELS requests */ 362 uint32_t els_cmpl_cnt; /**< number of outstanding ELS completions */ 363 uint32_t abort_cnt; /**< Abort counter for debugging purpose */ 364 365 char current_state_name[OCS_DISPLAY_NAME_LENGTH]; /**< current node state */ 366 char prev_state_name[OCS_DISPLAY_NAME_LENGTH]; /**< previous node state */ 367 ocs_sm_event_t current_evt; /**< current event */ 368 ocs_sm_event_t prev_evt; /**< current event */ 369 uint32_t targ:1, /**< node is target capable */ 370 init:1, /**< node is initiator capable */ 371 refound:1, /**< Handle node refound case when node is being deleted */ 372 fcp2device:1, /* FCP2 device */ 373 reserved:4, 374 fc_type:8; 375 ocs_list_t els_io_pend_list; /**< list of pending (not yet processed) ELS IOs */ 376 ocs_list_t els_io_active_list; /**< list of active (processed) ELS IOs */ 377 378 ocs_sm_function_t nodedb_state; /**< Node debugging, saved state */ 379 380 ocs_timer_t gidpt_delay_timer; /**< GIDPT delay timer */ 381 time_t time_last_gidpt_msec; /**< Start time of last target RSCN GIDPT */ 382 383 /* WWN */ 384 char wwnn[OCS_WWN_LENGTH]; /**< remote port WWN (uses iSCSI naming) */ 385 char wwpn[OCS_WWN_LENGTH]; /**< remote port WWN (uses iSCSI naming) */ 386 387 /* Statistics */ 388 uint32_t chained_io_count; /**< count of IOs with chained SGL's */ 389 390 ocs_list_link_t link; /**< node list link */ 391 392 ocs_remote_node_group_t *node_group; /**< pointer to node group (if HLM enabled) */ 393 }; 394 395 /** 396 * @brief Virtual port specification 397 * 398 * Collection of the information required to restore a virtual port across 399 * link events 400 */ 401 402 typedef struct ocs_vport_spec_s ocs_vport_spec_t; 403 struct ocs_vport_spec_s { 404 uint32_t domain_instance; /*>> instance index of this domain for the sport */ 405 uint64_t wwnn; /*>> node name */ 406 uint64_t wwpn; /*>> port name */ 407 uint32_t fc_id; /*>> port id */ 408 uint32_t enable_tgt:1, /*>> port is a target */ 409 enable_ini:1; /*>> port is an initiator */ 410 ocs_list_link_t link; /*>> link */ 411 void *tgt_data; /**< target backend pointer */ 412 void *ini_data; /**< initiator backend pointer */ 413 ocs_sport_t *sport; /**< Used to match record after attaching for update */ 414 }; 415 416 #endif /* __OCS_COMMON_H__*/ 417