1dea3101eS /******************************************************************* 2dea3101eS * This file is part of the Emulex Linux Device Driver for * 3c44ce173SJames.Smart@Emulex.Com * Fibre Channel Host Bus Adapters. * 41775c208SJames Smart * Copyright (C) 2017-2022 Broadcom. All Rights Reserved. The term * 54ae2ebdeSJames Smart * “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. * 6a89a96bdSJames Smart * Copyright (C) 2004-2013 Emulex. All rights reserved. * 7c44ce173SJames.Smart@Emulex.Com * EMULEX and SLI are trademarks of Emulex. * 8d080abe0SJames Smart * www.broadcom.com * 9dea3101eS * * 10dea3101eS * This program is free software; you can redistribute it and/or * 11c44ce173SJames.Smart@Emulex.Com * modify it under the terms of version 2 of the GNU General * 12c44ce173SJames.Smart@Emulex.Com * Public License as published by the Free Software Foundation. * 13c44ce173SJames.Smart@Emulex.Com * This program is distributed in the hope that it will be useful. * 14c44ce173SJames.Smart@Emulex.Com * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND * 15c44ce173SJames.Smart@Emulex.Com * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, * 16c44ce173SJames.Smart@Emulex.Com * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE * 17c44ce173SJames.Smart@Emulex.Com * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD * 18c44ce173SJames.Smart@Emulex.Com * TO BE LEGALLY INVALID. See the GNU General Public License for * 19c44ce173SJames.Smart@Emulex.Com * more details, a copy of which can be found in the file COPYING * 20c44ce173SJames.Smart@Emulex.Com * included with this package. * 21dea3101eS *******************************************************************/ 22dea3101eS 23dea3101eS #define FC_MAX_HOLD_RSCN 32 /* max number of deferred RSCNs */ 246a9c52cfSJames Smart #define FC_MAX_NS_RSP 64512 /* max size NameServer rsp */ 25dea3101eS #define FC_MAXLOOP 126 /* max devices supported on a fc loop */ 26dea3101eS #define LPFC_DISC_FLOGI_TMO 10 /* Discovery FLOGI ratov */ 27dea3101eS 28dea3101eS 29dea3101eS /* This is the protocol dependent definition for a Node List Entry. 30dea3101eS * This is used by Fibre Channel protocol to support FCP. 31dea3101eS */ 32dea3101eS 3341415862SJamie Wellnitz /* worker thread events */ 3441415862SJamie Wellnitz enum lpfc_work_type { 3541415862SJamie Wellnitz LPFC_EVT_ONLINE, 3646fa311eSJames Smart LPFC_EVT_OFFLINE_PREP, 3741415862SJamie Wellnitz LPFC_EVT_OFFLINE, 3841415862SJamie Wellnitz LPFC_EVT_WARM_START, 3941415862SJamie Wellnitz LPFC_EVT_KILL, 4041415862SJamie Wellnitz LPFC_EVT_ELS_RETRY, 4192d7f7b0SJames Smart LPFC_EVT_DEV_LOSS, 42ea2151b4SJames Smart LPFC_EVT_FASTPATH_MGMT_EVT, 4378730cfeSJames Smart LPFC_EVT_RESET_HBA, 44e7dab164SJames Smart LPFC_EVT_RECOVER_PORT 4541415862SJamie Wellnitz }; 4641415862SJamie Wellnitz 47dea3101eS /* structure used to queue event to the discovery tasklet */ 48dea3101eS struct lpfc_work_evt { 49dea3101eS struct list_head evt_listp; 50dea3101eS void *evt_arg1; 51dea3101eS void *evt_arg2; 5241415862SJamie Wellnitz enum lpfc_work_type evt; 53dea3101eS }; 54dea3101eS 55ea2151b4SJames Smart struct lpfc_scsi_check_condition_event; 56ea2151b4SJames Smart struct lpfc_scsi_varqueuedepth_event; 57ea2151b4SJames Smart struct lpfc_scsi_event_header; 58ea2151b4SJames Smart struct lpfc_fabric_event_header; 59ea2151b4SJames Smart struct lpfc_fcprdchkerr_event; 60ea2151b4SJames Smart 61ea2151b4SJames Smart /* structure used for sending events from fast path */ 62ea2151b4SJames Smart struct lpfc_fast_path_event { 63ea2151b4SJames Smart struct lpfc_work_evt work_evt; 64ea2151b4SJames Smart struct lpfc_vport *vport; 65ea2151b4SJames Smart union { 66ea2151b4SJames Smart struct lpfc_scsi_check_condition_event check_cond_evt; 67ea2151b4SJames Smart struct lpfc_scsi_varqueuedepth_event queue_depth_evt; 68ea2151b4SJames Smart struct lpfc_scsi_event_header scsi_evt; 69ea2151b4SJames Smart struct lpfc_fabric_event_header fabric_evt; 70ea2151b4SJames Smart struct lpfc_fcprdchkerr_event read_check_error; 71ea2151b4SJames Smart } un; 72ea2151b4SJames Smart }; 73dea3101eS 7419ca7609SJames Smart #define LPFC_SLI4_MAX_XRI 1024 /* Used to make the ndlp's xri_bitmap */ 7519ca7609SJames Smart #define XRI_BITMAP_ULONGS (LPFC_SLI4_MAX_XRI / BITS_PER_LONG) 7619ca7609SJames Smart struct lpfc_node_rrqs { 7719ca7609SJames Smart unsigned long xri_bitmap[XRI_BITMAP_ULONGS]; 7819ca7609SJames Smart }; 7919ca7609SJames Smart 80243156c0SJames Smart enum lpfc_fc4_xpt_flags { 8106145683SJames Smart NLP_XPT_REGD = 0x1, 82243156c0SJames Smart SCSI_XPT_REGD = 0x2, 83243156c0SJames Smart NVME_XPT_REGD = 0x4, 8406145683SJames Smart NVME_XPT_UNREG_WAIT = 0x8, 8506145683SJames Smart NLP_XPT_HAS_HH = 0x10 86243156c0SJames Smart }; 87243156c0SJames Smart 88af984c87SJames Smart enum lpfc_nlp_save_flags { 89af984c87SJames Smart /* devloss occurred during recovery */ 90af984c87SJames Smart NLP_IN_RECOV_POST_DEV_LOSS = 0x1, 91af984c87SJames Smart /* wait for outstanding LOGO to cmpl */ 92af984c87SJames Smart NLP_WAIT_FOR_LOGO = 0x2, 93*0a3c84f7SJustin Tee /* wait for outstanding DA_ID to finish */ 94*0a3c84f7SJustin Tee NLP_WAIT_FOR_DA_ID = 0x4 95af984c87SJames Smart }; 96af984c87SJames Smart 97dea3101eS struct lpfc_nodelist { 98dea3101eS struct list_head nlp_listp; 99fe83e3b9SJames Smart struct serv_parm fc_sparam; /* buffer for service params */ 1002e0fef85SJames Smart struct lpfc_name nlp_portname; 1012e0fef85SJames Smart struct lpfc_name nlp_nodename; 102c6adba15SJames Smart 103c6adba15SJames Smart spinlock_t lock; /* Node management lock */ 104c6adba15SJames Smart 105dea3101eS uint32_t nlp_flag; /* entry flags */ 106dea3101eS uint32_t nlp_DID; /* FC D_ID of entry */ 107dea3101eS uint32_t nlp_last_elscmd; /* Last ELS cmd sent */ 108dea3101eS uint16_t nlp_type; 109dea3101eS #define NLP_FC_NODE 0x1 /* entry is an FC node */ 110dea3101eS #define NLP_FABRIC 0x4 /* entry rep a Fabric entity */ 111dea3101eS #define NLP_FCP_TARGET 0x8 /* entry is an FCP target */ 112dea3101eS #define NLP_FCP_INITIATOR 0x10 /* entry is an FCP Initiator */ 113a0f2d3efSJames Smart #define NLP_NVME_TARGET 0x20 /* entry is a NVME Target */ 114a0f2d3efSJames Smart #define NLP_NVME_INITIATOR 0x40 /* entry is a NVME Initiator */ 115dc53a618SJames Smart #define NLP_NVME_DISCOVERY 0x80 /* entry has NVME disc srvc */ 116a0f2d3efSJames Smart 117a0f2d3efSJames Smart uint16_t nlp_fc4_type; /* FC types node supports. */ 118a0f2d3efSJames Smart /* Assigned from GID_FF, only 119a0f2d3efSJames Smart * FCP (0x8) and NVME (0x28) 120a0f2d3efSJames Smart * supported. 121a0f2d3efSJames Smart */ 122a0f2d3efSJames Smart #define NLP_FC4_NONE 0x0 123a0f2d3efSJames Smart #define NLP_FC4_FCP 0x1 /* FC4 Type FCP (value x8)) */ 124a0f2d3efSJames Smart #define NLP_FC4_NVME 0x2 /* FC4 TYPE NVME (value x28) */ 125dea3101eS 126dea3101eS uint16_t nlp_rpi; 127dea3101eS uint16_t nlp_state; /* state transition indicator */ 1285024ab17SJamie Wellnitz uint16_t nlp_prev_state; /* state transition indicator */ 129dea3101eS uint16_t nlp_xri; /* output exchange id for RPI */ 130dea3101eS uint16_t nlp_sid; /* scsi id */ 131dea3101eS #define NLP_NO_SID 0xffff 132dea3101eS uint16_t nlp_maxframe; /* Max RCV frame size */ 133dea3101eS uint8_t nlp_class_sup; /* Supported Classes */ 134dea3101eS uint8_t nlp_retry; /* used for ELS retries */ 135dea3101eS uint8_t nlp_fcp_info; /* class info, bits 0-3 */ 136dea3101eS #define NLP_FCP_2_DEVICE 0x10 /* FCP-2 device */ 1370d8af096SJames Smart u8 nlp_nvme_info; /* NVME NSLER Support */ 13802169e84SGaurav Srivastava uint8_t vmid_support; /* destination VMID support */ 1390d8af096SJames Smart #define NLP_NVME_NSLER 0x1 /* NVME NSLER device */ 140dea3101eS 141dea3101eS struct timer_list nlp_delayfunc; /* Used for delayed ELS cmds */ 142a257bf90SJames Smart struct lpfc_hba *phba; 143a0f2d3efSJames Smart struct fc_rport *rport; /* scsi_transport_fc port structure */ 144a0f2d3efSJames Smart struct lpfc_nvme_rport *nrport; /* nvme transport rport struct. */ 1452e0fef85SJames Smart struct lpfc_vport *vport; 146dea3101eS struct lpfc_work_evt els_retry_evt; 14792d7f7b0SJames Smart struct lpfc_work_evt dev_loss_evt; 148e7dab164SJames Smart struct lpfc_work_evt recovery_evt; 149329f9bc7SJames Smart struct kref kref; 150977b5a0aSJames Smart atomic_t cmd_pending; 151977b5a0aSJames Smart uint32_t cmd_qdepth; 152977b5a0aSJames Smart unsigned long last_change_time; 153cff261f6SJames Smart unsigned long *active_rrqs_xri_bitmap; 154a0f2d3efSJames Smart uint32_t fc4_prli_sent; 155af984c87SJames Smart 156af984c87SJames Smart /* flags to keep ndlp alive until special conditions are met */ 157af984c87SJames Smart enum lpfc_nlp_save_flags save_flags; 158e9b11083SJames Smart 159243156c0SJames Smart enum lpfc_fc4_xpt_flags fc4_xpt_flags; 160add9d6beSJames Smart 161a0f2d3efSJames Smart uint32_t nvme_fb_size; /* NVME target's supported byte cnt */ 162a0f2d3efSJames Smart #define NVME_FB_BIT_SHIFT 9 /* PRLI Rsp first burst in 512B units. */ 163dea16bdaSJames Smart uint32_t nlp_defer_did; 164*0a3c84f7SJustin Tee 165*0a3c84f7SJustin Tee /* These wait objects are NPIV specific. These IOs must complete 166*0a3c84f7SJustin Tee * synchronously. 167*0a3c84f7SJustin Tee */ 16831051249SJames Smart wait_queue_head_t *logo_waitq; 169*0a3c84f7SJustin Tee wait_queue_head_t *da_id_waitq; 170dea3101eS }; 171e9b11083SJames Smart 17219ca7609SJames Smart struct lpfc_node_rrq { 17319ca7609SJames Smart struct list_head list; 17419ca7609SJames Smart uint16_t xritag; 17519ca7609SJames Smart uint16_t send_rrq; 17619ca7609SJames Smart uint16_t rxid; 17719ca7609SJames Smart uint32_t nlp_DID; /* FC D_ID of entry */ 17819ca7609SJames Smart struct lpfc_vport *vport; 17919ca7609SJames Smart unsigned long rrq_stop_time; 18019ca7609SJames Smart }; 181dea3101eS 1822a5b7d62SJames Smart #define lpfc_ndlp_check_qdepth(phba, ndlp) \ 1832a5b7d62SJames Smart (ndlp->cmd_qdepth < phba->sli4_hba.max_cfg_param.max_xri) 1842a5b7d62SJames Smart 185dea3101eS /* Defines for nlp_flag (uint32) */ 186ffc95493SJames Smart #define NLP_IGNR_REG_CMPL 0x00000001 /* Rcvd rscn before we cmpl reg login */ 187ffc95493SJames Smart #define NLP_REG_LOGIN_SEND 0x00000002 /* sent reglogin to adapter */ 1884f1a2fefSJames Smart #define NLP_RELEASE_RPI 0x00000004 /* Release RPI to free pool */ 189f358dd0cSJames Smart #define NLP_SUPPRESS_RSP 0x00000010 /* Remote NPort supports suppress rsp */ 1907f5f3d0dSJames Smart #define NLP_PLOGI_SND 0x00000020 /* sent PLOGI request for this entry */ 1917f5f3d0dSJames Smart #define NLP_PRLI_SND 0x00000040 /* sent PRLI request for this entry */ 1927f5f3d0dSJames Smart #define NLP_ADISC_SND 0x00000080 /* sent ADISC request for this entry */ 1937f5f3d0dSJames Smart #define NLP_LOGO_SND 0x00000100 /* sent LOGO request for this entry */ 1947f5f3d0dSJames Smart #define NLP_RNID_SND 0x00000400 /* sent RNID request for this entry */ 1957f5f3d0dSJames Smart #define NLP_ELS_SND_MASK 0x000007e0 /* sent ELS request for this entry */ 1961c5b12f7SJames Smart #define NLP_NVMET_RECOV 0x00001000 /* NVMET auditing node for recovery. */ 197dea16bdaSJames Smart #define NLP_UNREG_INP 0x00008000 /* UNREG_RPI cmd is in progress */ 1984430f7fdSJames Smart #define NLP_DROPPED 0x00010000 /* Init ref count has been dropped */ 1997f5f3d0dSJames Smart #define NLP_DELAY_TMO 0x00020000 /* delay timeout is running for node */ 2007f5f3d0dSJames Smart #define NLP_NPR_2B_DISC 0x00040000 /* node is included in num_disc_nodes */ 2017f5f3d0dSJames Smart #define NLP_RCV_PLOGI 0x00080000 /* Rcv'ed PLOGI from remote system */ 2027f5f3d0dSJames Smart #define NLP_LOGO_ACC 0x00100000 /* Process LOGO after ACC completes */ 2037f5f3d0dSJames Smart #define NLP_TGT_NO_SCSIID 0x00200000 /* good PRLI but no binding for scsid */ 204086a345fSJames Smart #define NLP_ISSUE_LOGO 0x00400000 /* waiting to issue a LOGO */ 205466e840bSJames Smart #define NLP_IN_DEV_LOSS 0x00800000 /* devloss in progress */ 2067f5f3d0dSJames Smart #define NLP_ACC_REGLOGIN 0x01000000 /* Issue Reg Login after successful 207dea3101eS ACC */ 2087f5f3d0dSJames Smart #define NLP_NPR_ADISC 0x02000000 /* Issue ADISC when dq'ed from 209dea3101eS NPR list */ 2107f5f3d0dSJames Smart #define NLP_RM_DFLT_RPI 0x04000000 /* need to remove leftover dflt RPI */ 2117f5f3d0dSJames Smart #define NLP_NODEV_REMOVE 0x08000000 /* Defer removal till discovery ends */ 21292d7f7b0SJames Smart #define NLP_TARGET_REMOVE 0x10000000 /* Target remove in process */ 2137f5f3d0dSJames Smart #define NLP_SC_REQ 0x20000000 /* Target requires authentication */ 2143cb01c57SJames Smart #define NLP_FIRSTBURST 0x40000000 /* Target supports FirstBurst */ 2154042629eSJames Smart #define NLP_RPI_REGISTERED 0x80000000 /* nlp_rpi is valid */ 216dea3101eS 217dea3101eS /* There are 4 different double linked lists nodelist entries can reside on. 218dea3101eS * The Port Login (PLOGI) list and Address Discovery (ADISC) list are used 219dea3101eS * when Link Up discovery or Registered State Change Notification (RSCN) 220dea3101eS * processing is needed. Each list holds the nodes that require a PLOGI or 221dea3101eS * ADISC Extended Link Service (ELS) request. These lists keep track of the 222dea3101eS * nodes affected by an RSCN, or a Link Up (Typically, all nodes are effected 223dea3101eS * by Link Up) event. The unmapped_list contains all nodes that have 224dea3101eS * successfully logged into at the Fibre Channel level. The 225dea3101eS * mapped_list will contain all nodes that are mapped FCP targets. 226dea3101eS * 227dea3101eS * The bind list is a list of undiscovered (potentially non-existent) nodes 228dea3101eS * that we have saved binding information on. This information is used when 229dea3101eS * nodes transition from the unmapped to the mapped list. 230dea3101eS */ 231dea3101eS 232dea3101eS /* Defines for nlp_state */ 233dea3101eS #define NLP_STE_UNUSED_NODE 0x0 /* node is just allocated */ 234dea3101eS #define NLP_STE_PLOGI_ISSUE 0x1 /* PLOGI was sent to NL_PORT */ 235dea3101eS #define NLP_STE_ADISC_ISSUE 0x2 /* ADISC was sent to NL_PORT */ 236dea3101eS #define NLP_STE_REG_LOGIN_ISSUE 0x3 /* REG_LOGIN was issued for NL_PORT */ 237dea3101eS #define NLP_STE_PRLI_ISSUE 0x4 /* PRLI was sent to NL_PORT */ 238086a345fSJames Smart #define NLP_STE_LOGO_ISSUE 0x5 /* LOGO was sent to NL_PORT */ 239086a345fSJames Smart #define NLP_STE_UNMAPPED_NODE 0x6 /* PRLI completed from NL_PORT */ 240086a345fSJames Smart #define NLP_STE_MAPPED_NODE 0x7 /* Identified as a FCP Target */ 241086a345fSJames Smart #define NLP_STE_NPR_NODE 0x8 /* NPort disappeared */ 242086a345fSJames Smart #define NLP_STE_MAX_STATE 0x9 243dea3101eS #define NLP_STE_FREED_NODE 0xff /* node entry was freed to MEM_NLP */ 244dea3101eS 245dea3101eS /* For UNUSED_NODE state, the node has just been allocated. 246dea3101eS * For PLOGI_ISSUE and REG_LOGIN_ISSUE, the node is on 247dea3101eS * the PLOGI list. For REG_LOGIN_COMPL, the node is taken off the PLOGI list 248dea3101eS * and put on the unmapped list. For ADISC processing, the node is taken off 249dea3101eS * the ADISC list and placed on either the mapped or unmapped list (depending 250dea3101eS * on its previous state). Once on the unmapped list, a PRLI is issued and the 251dea3101eS * state changed to PRLI_ISSUE. When the PRLI completion occurs, the state is 252dea3101eS * changed to PRLI_COMPL. If the completion indicates a mapped 253dea3101eS * node, the node is taken off the unmapped list. The binding list is checked 254dea3101eS * for a valid binding, or a binding is automatically assigned. If binding 255dea3101eS * assignment is unsuccessful, the node is left on the unmapped list. If 256dea3101eS * binding assignment is successful, the associated binding list entry (if 257dea3101eS * any) is removed, and the node is placed on the mapped list. 258dea3101eS */ 259dea3101eS /* 260dea3101eS * For a Link Down, all nodes on the ADISC, PLOGI, unmapped or mapped 261c01f3208SJames Smart * lists will receive a DEVICE_RECOVERY event. If the linkdown or devloss timers 262dea3101eS * expire, all effected nodes will receive a DEVICE_RM event. 263dea3101eS */ 264dea3101eS /* 265dea3101eS * For a Link Up or RSCN, all nodes will move from the mapped / unmapped lists 266dea3101eS * to either the ADISC or PLOGI list. After a Nameserver query or ALPA loopmap 267dea3101eS * check, additional nodes may be added (DEVICE_ADD) or removed (DEVICE_RM) to / 268dea3101eS * from the PLOGI or ADISC lists. Once the PLOGI and ADISC lists are populated, 269dea3101eS * we will first process the ADISC list. 32 entries are processed initially and 270dea3101eS * ADISC is initited for each one. Completions / Events for each node are 271dea3101eS * funnelled thru the state machine. As each node finishes ADISC processing, it 272dea3101eS * starts ADISC for any nodes waiting for ADISC processing. If no nodes are 273dea3101eS * waiting, and the ADISC list count is identically 0, then we are done. For 274dea3101eS * Link Up discovery, since all nodes on the PLOGI list are UNREG_LOGIN'ed, we 275dea3101eS * can issue a CLEAR_LA and reenable Link Events. Next we will process the PLOGI 276dea3101eS * list. 32 entries are processed initially and PLOGI is initited for each one. 277dea3101eS * Completions / Events for each node are funnelled thru the state machine. As 278dea3101eS * each node finishes PLOGI processing, it starts PLOGI for any nodes waiting 279dea3101eS * for PLOGI processing. If no nodes are waiting, and the PLOGI list count is 280dea3101eS * identically 0, then we are done. We have now completed discovery / RSCN 281dea3101eS * handling. Upon completion, ALL nodes should be on either the mapped or 282dea3101eS * unmapped lists. 283dea3101eS */ 284dea3101eS 285dea3101eS /* Defines for Node List Entry Events that could happen */ 286dea3101eS #define NLP_EVT_RCV_PLOGI 0x0 /* Rcv'd an ELS PLOGI command */ 287dea3101eS #define NLP_EVT_RCV_PRLI 0x1 /* Rcv'd an ELS PRLI command */ 288dea3101eS #define NLP_EVT_RCV_LOGO 0x2 /* Rcv'd an ELS LOGO command */ 289dea3101eS #define NLP_EVT_RCV_ADISC 0x3 /* Rcv'd an ELS ADISC command */ 290dea3101eS #define NLP_EVT_RCV_PDISC 0x4 /* Rcv'd an ELS PDISC command */ 291dea3101eS #define NLP_EVT_RCV_PRLO 0x5 /* Rcv'd an ELS PRLO command */ 292dea3101eS #define NLP_EVT_CMPL_PLOGI 0x6 /* Sent an ELS PLOGI command */ 293dea3101eS #define NLP_EVT_CMPL_PRLI 0x7 /* Sent an ELS PRLI command */ 294dea3101eS #define NLP_EVT_CMPL_LOGO 0x8 /* Sent an ELS LOGO command */ 295dea3101eS #define NLP_EVT_CMPL_ADISC 0x9 /* Sent an ELS ADISC command */ 296dea3101eS #define NLP_EVT_CMPL_REG_LOGIN 0xa /* REG_LOGIN mbox cmd completed */ 297dea3101eS #define NLP_EVT_DEVICE_RM 0xb /* Device not found in NS / ALPAmap */ 298dea3101eS #define NLP_EVT_DEVICE_RECOVERY 0xc /* Device existence unknown */ 299dea3101eS #define NLP_EVT_MAX_EVENT 0xd 300dea16bdaSJames Smart #define NLP_EVT_NOTHING_PENDING 0xff 301