1dea3101eS /******************************************************************* 2dea3101eS * This file is part of the Emulex Linux Device Driver for * 3c44ce173SJames.Smart@Emulex.Com * Fibre Channel Host Bus Adapters. * 4e47c9093SJames Smart * Copyright (C) 2004-2008 Emulex. All rights reserved. * 5c44ce173SJames.Smart@Emulex.Com * EMULEX and SLI are trademarks of Emulex. * 6dea3101eS * www.emulex.com * 7dea3101eS * * 8dea3101eS * This program is free software; you can redistribute it and/or * 9c44ce173SJames.Smart@Emulex.Com * modify it under the terms of version 2 of the GNU General * 10c44ce173SJames.Smart@Emulex.Com * Public License as published by the Free Software Foundation. * 11c44ce173SJames.Smart@Emulex.Com * This program is distributed in the hope that it will be useful. * 12c44ce173SJames.Smart@Emulex.Com * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND * 13c44ce173SJames.Smart@Emulex.Com * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, * 14c44ce173SJames.Smart@Emulex.Com * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE * 15c44ce173SJames.Smart@Emulex.Com * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD * 16c44ce173SJames.Smart@Emulex.Com * TO BE LEGALLY INVALID. See the GNU General Public License for * 17c44ce173SJames.Smart@Emulex.Com * more details, a copy of which can be found in the file COPYING * 18c44ce173SJames.Smart@Emulex.Com * included with this package. * 19dea3101eS *******************************************************************/ 20dea3101eS 21dea3101eS #define FC_MAX_HOLD_RSCN 32 /* max number of deferred RSCNs */ 226a9c52cfSJames Smart #define FC_MAX_NS_RSP 64512 /* max size NameServer rsp */ 23dea3101eS #define FC_MAXLOOP 126 /* max devices supported on a fc loop */ 24dea3101eS #define LPFC_DISC_FLOGI_TMO 10 /* Discovery FLOGI ratov */ 25dea3101eS 26dea3101eS 27dea3101eS /* This is the protocol dependent definition for a Node List Entry. 28dea3101eS * This is used by Fibre Channel protocol to support FCP. 29dea3101eS */ 30dea3101eS 3141415862SJamie Wellnitz /* worker thread events */ 3241415862SJamie Wellnitz enum lpfc_work_type { 3341415862SJamie Wellnitz LPFC_EVT_ONLINE, 3446fa311eSJames Smart LPFC_EVT_OFFLINE_PREP, 3541415862SJamie Wellnitz LPFC_EVT_OFFLINE, 3641415862SJamie Wellnitz LPFC_EVT_WARM_START, 3741415862SJamie Wellnitz LPFC_EVT_KILL, 3841415862SJamie Wellnitz LPFC_EVT_ELS_RETRY, 3992d7f7b0SJames Smart LPFC_EVT_DEV_LOSS, 40ea2151b4SJames Smart LPFC_EVT_FASTPATH_MGMT_EVT, 4178730cfeSJames Smart LPFC_EVT_RESET_HBA, 4241415862SJamie Wellnitz }; 4341415862SJamie Wellnitz 44dea3101eS /* structure used to queue event to the discovery tasklet */ 45dea3101eS struct lpfc_work_evt { 46dea3101eS struct list_head evt_listp; 47dea3101eS void *evt_arg1; 48dea3101eS void *evt_arg2; 4941415862SJamie Wellnitz enum lpfc_work_type evt; 50dea3101eS }; 51dea3101eS 52ea2151b4SJames Smart struct lpfc_scsi_check_condition_event; 53ea2151b4SJames Smart struct lpfc_scsi_varqueuedepth_event; 54ea2151b4SJames Smart struct lpfc_scsi_event_header; 55ea2151b4SJames Smart struct lpfc_fabric_event_header; 56ea2151b4SJames Smart struct lpfc_fcprdchkerr_event; 57ea2151b4SJames Smart 58ea2151b4SJames Smart /* structure used for sending events from fast path */ 59ea2151b4SJames Smart struct lpfc_fast_path_event { 60ea2151b4SJames Smart struct lpfc_work_evt work_evt; 61ea2151b4SJames Smart struct lpfc_vport *vport; 62ea2151b4SJames Smart union { 63ea2151b4SJames Smart struct lpfc_scsi_check_condition_event check_cond_evt; 64ea2151b4SJames Smart struct lpfc_scsi_varqueuedepth_event queue_depth_evt; 65ea2151b4SJames Smart struct lpfc_scsi_event_header scsi_evt; 66ea2151b4SJames Smart struct lpfc_fabric_event_header fabric_evt; 67ea2151b4SJames Smart struct lpfc_fcprdchkerr_event read_check_error; 68ea2151b4SJames Smart } un; 69ea2151b4SJames Smart }; 70dea3101eS 7119ca7609SJames Smart #define LPFC_SLI4_MAX_XRI 1024 /* Used to make the ndlp's xri_bitmap */ 7219ca7609SJames Smart #define XRI_BITMAP_ULONGS (LPFC_SLI4_MAX_XRI / BITS_PER_LONG) 7319ca7609SJames Smart struct lpfc_node_rrqs { 7419ca7609SJames Smart unsigned long xri_bitmap[XRI_BITMAP_ULONGS]; 7519ca7609SJames Smart }; 7619ca7609SJames Smart 77dea3101eS struct lpfc_nodelist { 78dea3101eS struct list_head nlp_listp; 792e0fef85SJames Smart struct lpfc_name nlp_portname; 802e0fef85SJames Smart struct lpfc_name nlp_nodename; 81dea3101eS uint32_t nlp_flag; /* entry flags */ 82dea3101eS uint32_t nlp_DID; /* FC D_ID of entry */ 83dea3101eS uint32_t nlp_last_elscmd; /* Last ELS cmd sent */ 84dea3101eS uint16_t nlp_type; 85dea3101eS #define NLP_FC_NODE 0x1 /* entry is an FC node */ 86dea3101eS #define NLP_FABRIC 0x4 /* entry rep a Fabric entity */ 87dea3101eS #define NLP_FCP_TARGET 0x8 /* entry is an FCP target */ 88dea3101eS #define NLP_FCP_INITIATOR 0x10 /* entry is an FCP Initiator */ 89dea3101eS 90dea3101eS uint16_t nlp_rpi; 91dea3101eS uint16_t nlp_state; /* state transition indicator */ 925024ab17SJamie Wellnitz uint16_t nlp_prev_state; /* state transition indicator */ 93dea3101eS uint16_t nlp_xri; /* output exchange id for RPI */ 94dea3101eS uint16_t nlp_sid; /* scsi id */ 95dea3101eS #define NLP_NO_SID 0xffff 96dea3101eS uint16_t nlp_maxframe; /* Max RCV frame size */ 97dea3101eS uint8_t nlp_class_sup; /* Supported Classes */ 98dea3101eS uint8_t nlp_retry; /* used for ELS retries */ 99dea3101eS uint8_t nlp_fcp_info; /* class info, bits 0-3 */ 100dea3101eS #define NLP_FCP_2_DEVICE 0x10 /* FCP-2 device */ 101dea3101eS 102e47c9093SJames Smart uint16_t nlp_usg_map; /* ndlp management usage bitmap */ 103e47c9093SJames Smart #define NLP_USG_NODE_ACT_BIT 0x1 /* Indicate ndlp is actively used */ 104e47c9093SJames Smart #define NLP_USG_IACT_REQ_BIT 0x2 /* Request to inactivate ndlp */ 105e47c9093SJames Smart #define NLP_USG_FREE_REQ_BIT 0x4 /* Request to invoke ndlp memory free */ 106e47c9093SJames Smart #define NLP_USG_FREE_ACK_BIT 0x8 /* Indicate ndlp memory free invoked */ 107e47c9093SJames Smart 108dea3101eS struct timer_list nlp_delayfunc; /* Used for delayed ELS cmds */ 109a257bf90SJames Smart struct lpfc_hba *phba; 110dea3101eS struct fc_rport *rport; /* Corresponding FC transport 111dea3101eS port structure */ 1122e0fef85SJames Smart struct lpfc_vport *vport; 113dea3101eS struct lpfc_work_evt els_retry_evt; 11492d7f7b0SJames Smart struct lpfc_work_evt dev_loss_evt; 115329f9bc7SJames Smart struct kref kref; 116977b5a0aSJames Smart atomic_t cmd_pending; 117977b5a0aSJames Smart uint32_t cmd_qdepth; 118977b5a0aSJames Smart unsigned long last_change_time; 11919ca7609SJames Smart struct lpfc_node_rrqs active_rrqs; 120ea2151b4SJames Smart struct lpfc_scsicmd_bkt *lat_data; /* Latency data */ 121dea3101eS }; 12219ca7609SJames Smart struct lpfc_node_rrq { 12319ca7609SJames Smart struct list_head list; 12419ca7609SJames Smart uint16_t xritag; 12519ca7609SJames Smart uint16_t send_rrq; 12619ca7609SJames Smart uint16_t rxid; 12719ca7609SJames Smart uint32_t nlp_DID; /* FC D_ID of entry */ 12819ca7609SJames Smart struct lpfc_vport *vport; 12919ca7609SJames Smart struct lpfc_nodelist *ndlp; 13019ca7609SJames Smart unsigned long rrq_stop_time; 13119ca7609SJames Smart }; 132dea3101eS 133dea3101eS /* Defines for nlp_flag (uint32) */ 134ffc95493SJames Smart #define NLP_IGNR_REG_CMPL 0x00000001 /* Rcvd rscn before we cmpl reg login */ 135ffc95493SJames Smart #define NLP_REG_LOGIN_SEND 0x00000002 /* sent reglogin to adapter */ 1367f5f3d0dSJames Smart #define NLP_PLOGI_SND 0x00000020 /* sent PLOGI request for this entry */ 1377f5f3d0dSJames Smart #define NLP_PRLI_SND 0x00000040 /* sent PRLI request for this entry */ 1387f5f3d0dSJames Smart #define NLP_ADISC_SND 0x00000080 /* sent ADISC request for this entry */ 1397f5f3d0dSJames Smart #define NLP_LOGO_SND 0x00000100 /* sent LOGO request for this entry */ 1407f5f3d0dSJames Smart #define NLP_RNID_SND 0x00000400 /* sent RNID request for this entry */ 1417f5f3d0dSJames Smart #define NLP_ELS_SND_MASK 0x000007e0 /* sent ELS request for this entry */ 1427f5f3d0dSJames Smart #define NLP_DEFER_RM 0x00010000 /* Remove this ndlp if no longer used */ 1437f5f3d0dSJames Smart #define NLP_DELAY_TMO 0x00020000 /* delay timeout is running for node */ 1447f5f3d0dSJames Smart #define NLP_NPR_2B_DISC 0x00040000 /* node is included in num_disc_nodes */ 1457f5f3d0dSJames Smart #define NLP_RCV_PLOGI 0x00080000 /* Rcv'ed PLOGI from remote system */ 1467f5f3d0dSJames Smart #define NLP_LOGO_ACC 0x00100000 /* Process LOGO after ACC completes */ 1477f5f3d0dSJames Smart #define NLP_TGT_NO_SCSIID 0x00200000 /* good PRLI but no binding for scsid */ 148086a345fSJames Smart #define NLP_ISSUE_LOGO 0x00400000 /* waiting to issue a LOGO */ 1497f5f3d0dSJames Smart #define NLP_ACC_REGLOGIN 0x01000000 /* Issue Reg Login after successful 150dea3101eS ACC */ 1517f5f3d0dSJames Smart #define NLP_NPR_ADISC 0x02000000 /* Issue ADISC when dq'ed from 152dea3101eS NPR list */ 1537f5f3d0dSJames Smart #define NLP_RM_DFLT_RPI 0x04000000 /* need to remove leftover dflt RPI */ 1547f5f3d0dSJames Smart #define NLP_NODEV_REMOVE 0x08000000 /* Defer removal till discovery ends */ 15592d7f7b0SJames Smart #define NLP_TARGET_REMOVE 0x10000000 /* Target remove in process */ 1567f5f3d0dSJames Smart #define NLP_SC_REQ 0x20000000 /* Target requires authentication */ 157*3cb01c57SJames Smart #define NLP_FIRSTBURST 0x40000000 /* Target supports FirstBurst */ 1584042629eSJames Smart #define NLP_RPI_REGISTERED 0x80000000 /* nlp_rpi is valid */ 159dea3101eS 160e47c9093SJames Smart /* ndlp usage management macros */ 161e47c9093SJames Smart #define NLP_CHK_NODE_ACT(ndlp) (((ndlp)->nlp_usg_map \ 162e47c9093SJames Smart & NLP_USG_NODE_ACT_BIT) \ 163e47c9093SJames Smart && \ 164e47c9093SJames Smart !((ndlp)->nlp_usg_map \ 165e47c9093SJames Smart & NLP_USG_FREE_ACK_BIT)) 166e47c9093SJames Smart #define NLP_SET_NODE_ACT(ndlp) ((ndlp)->nlp_usg_map \ 167e47c9093SJames Smart |= NLP_USG_NODE_ACT_BIT) 168e47c9093SJames Smart #define NLP_INT_NODE_ACT(ndlp) ((ndlp)->nlp_usg_map \ 169e47c9093SJames Smart = NLP_USG_NODE_ACT_BIT) 170e47c9093SJames Smart #define NLP_CLR_NODE_ACT(ndlp) ((ndlp)->nlp_usg_map \ 171e47c9093SJames Smart &= ~NLP_USG_NODE_ACT_BIT) 172e47c9093SJames Smart #define NLP_CHK_IACT_REQ(ndlp) ((ndlp)->nlp_usg_map \ 173e47c9093SJames Smart & NLP_USG_IACT_REQ_BIT) 174e47c9093SJames Smart #define NLP_SET_IACT_REQ(ndlp) ((ndlp)->nlp_usg_map \ 175e47c9093SJames Smart |= NLP_USG_IACT_REQ_BIT) 176e47c9093SJames Smart #define NLP_CHK_FREE_REQ(ndlp) ((ndlp)->nlp_usg_map \ 177e47c9093SJames Smart & NLP_USG_FREE_REQ_BIT) 178e47c9093SJames Smart #define NLP_SET_FREE_REQ(ndlp) ((ndlp)->nlp_usg_map \ 179e47c9093SJames Smart |= NLP_USG_FREE_REQ_BIT) 180e47c9093SJames Smart #define NLP_CHK_FREE_ACK(ndlp) ((ndlp)->nlp_usg_map \ 181e47c9093SJames Smart & NLP_USG_FREE_ACK_BIT) 182e47c9093SJames Smart #define NLP_SET_FREE_ACK(ndlp) ((ndlp)->nlp_usg_map \ 183e47c9093SJames Smart |= NLP_USG_FREE_ACK_BIT) 184e47c9093SJames Smart 185dea3101eS /* There are 4 different double linked lists nodelist entries can reside on. 186dea3101eS * The Port Login (PLOGI) list and Address Discovery (ADISC) list are used 187dea3101eS * when Link Up discovery or Registered State Change Notification (RSCN) 188dea3101eS * processing is needed. Each list holds the nodes that require a PLOGI or 189dea3101eS * ADISC Extended Link Service (ELS) request. These lists keep track of the 190dea3101eS * nodes affected by an RSCN, or a Link Up (Typically, all nodes are effected 191dea3101eS * by Link Up) event. The unmapped_list contains all nodes that have 192dea3101eS * successfully logged into at the Fibre Channel level. The 193dea3101eS * mapped_list will contain all nodes that are mapped FCP targets. 194dea3101eS * 195dea3101eS * The bind list is a list of undiscovered (potentially non-existent) nodes 196dea3101eS * that we have saved binding information on. This information is used when 197dea3101eS * nodes transition from the unmapped to the mapped list. 198dea3101eS */ 199dea3101eS 200dea3101eS /* Defines for nlp_state */ 201dea3101eS #define NLP_STE_UNUSED_NODE 0x0 /* node is just allocated */ 202dea3101eS #define NLP_STE_PLOGI_ISSUE 0x1 /* PLOGI was sent to NL_PORT */ 203dea3101eS #define NLP_STE_ADISC_ISSUE 0x2 /* ADISC was sent to NL_PORT */ 204dea3101eS #define NLP_STE_REG_LOGIN_ISSUE 0x3 /* REG_LOGIN was issued for NL_PORT */ 205dea3101eS #define NLP_STE_PRLI_ISSUE 0x4 /* PRLI was sent to NL_PORT */ 206086a345fSJames Smart #define NLP_STE_LOGO_ISSUE 0x5 /* LOGO was sent to NL_PORT */ 207086a345fSJames Smart #define NLP_STE_UNMAPPED_NODE 0x6 /* PRLI completed from NL_PORT */ 208086a345fSJames Smart #define NLP_STE_MAPPED_NODE 0x7 /* Identified as a FCP Target */ 209086a345fSJames Smart #define NLP_STE_NPR_NODE 0x8 /* NPort disappeared */ 210086a345fSJames Smart #define NLP_STE_MAX_STATE 0x9 211dea3101eS #define NLP_STE_FREED_NODE 0xff /* node entry was freed to MEM_NLP */ 212dea3101eS 213dea3101eS /* For UNUSED_NODE state, the node has just been allocated. 214dea3101eS * For PLOGI_ISSUE and REG_LOGIN_ISSUE, the node is on 215dea3101eS * the PLOGI list. For REG_LOGIN_COMPL, the node is taken off the PLOGI list 216dea3101eS * and put on the unmapped list. For ADISC processing, the node is taken off 217dea3101eS * the ADISC list and placed on either the mapped or unmapped list (depending 218dea3101eS * on its previous state). Once on the unmapped list, a PRLI is issued and the 219dea3101eS * state changed to PRLI_ISSUE. When the PRLI completion occurs, the state is 220dea3101eS * changed to PRLI_COMPL. If the completion indicates a mapped 221dea3101eS * node, the node is taken off the unmapped list. The binding list is checked 222dea3101eS * for a valid binding, or a binding is automatically assigned. If binding 223dea3101eS * assignment is unsuccessful, the node is left on the unmapped list. If 224dea3101eS * binding assignment is successful, the associated binding list entry (if 225dea3101eS * any) is removed, and the node is placed on the mapped list. 226dea3101eS */ 227dea3101eS /* 228dea3101eS * For a Link Down, all nodes on the ADISC, PLOGI, unmapped or mapped 229c01f3208SJames Smart * lists will receive a DEVICE_RECOVERY event. If the linkdown or devloss timers 230dea3101eS * expire, all effected nodes will receive a DEVICE_RM event. 231dea3101eS */ 232dea3101eS /* 233dea3101eS * For a Link Up or RSCN, all nodes will move from the mapped / unmapped lists 234dea3101eS * to either the ADISC or PLOGI list. After a Nameserver query or ALPA loopmap 235dea3101eS * check, additional nodes may be added (DEVICE_ADD) or removed (DEVICE_RM) to / 236dea3101eS * from the PLOGI or ADISC lists. Once the PLOGI and ADISC lists are populated, 237dea3101eS * we will first process the ADISC list. 32 entries are processed initially and 238dea3101eS * ADISC is initited for each one. Completions / Events for each node are 239dea3101eS * funnelled thru the state machine. As each node finishes ADISC processing, it 240dea3101eS * starts ADISC for any nodes waiting for ADISC processing. If no nodes are 241dea3101eS * waiting, and the ADISC list count is identically 0, then we are done. For 242dea3101eS * Link Up discovery, since all nodes on the PLOGI list are UNREG_LOGIN'ed, we 243dea3101eS * can issue a CLEAR_LA and reenable Link Events. Next we will process the PLOGI 244dea3101eS * list. 32 entries are processed initially and PLOGI is initited for each one. 245dea3101eS * Completions / Events for each node are funnelled thru the state machine. As 246dea3101eS * each node finishes PLOGI processing, it starts PLOGI for any nodes waiting 247dea3101eS * for PLOGI processing. If no nodes are waiting, and the PLOGI list count is 248dea3101eS * identically 0, then we are done. We have now completed discovery / RSCN 249dea3101eS * handling. Upon completion, ALL nodes should be on either the mapped or 250dea3101eS * unmapped lists. 251dea3101eS */ 252dea3101eS 253dea3101eS /* Defines for Node List Entry Events that could happen */ 254dea3101eS #define NLP_EVT_RCV_PLOGI 0x0 /* Rcv'd an ELS PLOGI command */ 255dea3101eS #define NLP_EVT_RCV_PRLI 0x1 /* Rcv'd an ELS PRLI command */ 256dea3101eS #define NLP_EVT_RCV_LOGO 0x2 /* Rcv'd an ELS LOGO command */ 257dea3101eS #define NLP_EVT_RCV_ADISC 0x3 /* Rcv'd an ELS ADISC command */ 258dea3101eS #define NLP_EVT_RCV_PDISC 0x4 /* Rcv'd an ELS PDISC command */ 259dea3101eS #define NLP_EVT_RCV_PRLO 0x5 /* Rcv'd an ELS PRLO command */ 260dea3101eS #define NLP_EVT_CMPL_PLOGI 0x6 /* Sent an ELS PLOGI command */ 261dea3101eS #define NLP_EVT_CMPL_PRLI 0x7 /* Sent an ELS PRLI command */ 262dea3101eS #define NLP_EVT_CMPL_LOGO 0x8 /* Sent an ELS LOGO command */ 263dea3101eS #define NLP_EVT_CMPL_ADISC 0x9 /* Sent an ELS ADISC command */ 264dea3101eS #define NLP_EVT_CMPL_REG_LOGIN 0xa /* REG_LOGIN mbox cmd completed */ 265dea3101eS #define NLP_EVT_DEVICE_RM 0xb /* Device not found in NS / ALPAmap */ 266dea3101eS #define NLP_EVT_DEVICE_RECOVERY 0xc /* Device existence unknown */ 267dea3101eS #define NLP_EVT_MAX_EVENT 0xd 268dea3101eS 269