xref: /linux/drivers/scsi/lpfc/lpfc_disc.h (revision 977b5a0af6d22a1a0170057c19cde37eeac68acd)
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 */
22dea3101eS #define FC_MAX_NS_RSP        65536    /* 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,
4041415862SJamie Wellnitz };
4141415862SJamie Wellnitz 
42dea3101eS /* structure used to queue event to the discovery tasklet */
43dea3101eS struct lpfc_work_evt {
44dea3101eS 	struct list_head      evt_listp;
45dea3101eS 	void                 *evt_arg1;
46dea3101eS 	void                 *evt_arg2;
4741415862SJamie Wellnitz 	enum lpfc_work_type   evt;
48dea3101eS };
49dea3101eS 
50dea3101eS 
51dea3101eS struct lpfc_nodelist {
52dea3101eS 	struct list_head nlp_listp;
532e0fef85SJames Smart 	struct lpfc_name nlp_portname;
542e0fef85SJames Smart 	struct lpfc_name nlp_nodename;
55dea3101eS 	uint32_t         nlp_flag;		/* entry  flags */
56dea3101eS 	uint32_t         nlp_DID;		/* FC D_ID of entry */
57dea3101eS 	uint32_t         nlp_last_elscmd;	/* Last ELS cmd sent */
58dea3101eS 	uint16_t         nlp_type;
59dea3101eS #define NLP_FC_NODE        0x1			/* entry is an FC node */
60dea3101eS #define NLP_FABRIC         0x4			/* entry rep a Fabric entity */
61dea3101eS #define NLP_FCP_TARGET     0x8			/* entry is an FCP target */
62dea3101eS #define NLP_FCP_INITIATOR  0x10			/* entry is an FCP Initiator */
63dea3101eS 
64dea3101eS 	uint16_t        nlp_rpi;
65dea3101eS 	uint16_t        nlp_state;		/* state transition indicator */
665024ab17SJamie Wellnitz 	uint16_t        nlp_prev_state;		/* state transition indicator */
67dea3101eS 	uint16_t        nlp_xri;		/* output exchange id for RPI */
68dea3101eS 	uint16_t        nlp_sid;		/* scsi id */
69dea3101eS #define NLP_NO_SID		0xffff
70dea3101eS 	uint16_t	nlp_maxframe;		/* Max RCV frame size */
71dea3101eS 	uint8_t		nlp_class_sup;		/* Supported Classes */
72dea3101eS 	uint8_t         nlp_retry;		/* used for ELS retries */
73dea3101eS 	uint8_t         nlp_fcp_info;	        /* class info, bits 0-3 */
74dea3101eS #define NLP_FCP_2_DEVICE   0x10			/* FCP-2 device */
75dea3101eS 
76e47c9093SJames Smart 	uint16_t        nlp_usg_map;	/* ndlp management usage bitmap */
77e47c9093SJames Smart #define NLP_USG_NODE_ACT_BIT	0x1	/* Indicate ndlp is actively used */
78e47c9093SJames Smart #define NLP_USG_IACT_REQ_BIT	0x2	/* Request to inactivate ndlp */
79e47c9093SJames Smart #define NLP_USG_FREE_REQ_BIT	0x4	/* Request to invoke ndlp memory free */
80e47c9093SJames Smart #define NLP_USG_FREE_ACK_BIT	0x8	/* Indicate ndlp memory free invoked */
81e47c9093SJames Smart 
82dea3101eS 	struct timer_list   nlp_delayfunc;	/* Used for delayed ELS cmds */
83dea3101eS 	struct fc_rport *rport;			/* Corresponding FC transport
84dea3101eS 						   port structure */
852e0fef85SJames Smart 	struct lpfc_vport *vport;
86dea3101eS 	struct lpfc_work_evt els_retry_evt;
8792d7f7b0SJames Smart 	struct lpfc_work_evt dev_loss_evt;
88445cf4f4SJames.Smart@Emulex.Com 	unsigned long last_ramp_up_time;        /* jiffy of last ramp up */
89445cf4f4SJames.Smart@Emulex.Com 	unsigned long last_q_full_time;		/* jiffy of last queue full */
90329f9bc7SJames Smart 	struct kref     kref;
91*977b5a0aSJames Smart 	atomic_t cmd_pending;
92*977b5a0aSJames Smart 	uint32_t cmd_qdepth;
93*977b5a0aSJames Smart 	unsigned long last_change_time;
94dea3101eS };
95dea3101eS 
96dea3101eS /* Defines for nlp_flag (uint32) */
977f5f3d0dSJames Smart #define NLP_PLOGI_SND      0x00000020	/* sent PLOGI request for this entry */
987f5f3d0dSJames Smart #define NLP_PRLI_SND       0x00000040	/* sent PRLI request for this entry */
997f5f3d0dSJames Smart #define NLP_ADISC_SND      0x00000080	/* sent ADISC request for this entry */
1007f5f3d0dSJames Smart #define NLP_LOGO_SND       0x00000100	/* sent LOGO request for this entry */
1017f5f3d0dSJames Smart #define NLP_RNID_SND       0x00000400	/* sent RNID request for this entry */
1027f5f3d0dSJames Smart #define NLP_ELS_SND_MASK   0x000007e0	/* sent ELS request for this entry */
1037f5f3d0dSJames Smart #define NLP_DEFER_RM       0x00010000	/* Remove this ndlp if no longer used */
1047f5f3d0dSJames Smart #define NLP_DELAY_TMO      0x00020000	/* delay timeout is running for node */
1057f5f3d0dSJames Smart #define NLP_NPR_2B_DISC    0x00040000	/* node is included in num_disc_nodes */
1067f5f3d0dSJames Smart #define NLP_RCV_PLOGI      0x00080000	/* Rcv'ed PLOGI from remote system */
1077f5f3d0dSJames Smart #define NLP_LOGO_ACC       0x00100000	/* Process LOGO after ACC completes */
1087f5f3d0dSJames Smart #define NLP_TGT_NO_SCSIID  0x00200000	/* good PRLI but no binding for scsid */
1097f5f3d0dSJames Smart #define NLP_ACC_REGLOGIN   0x01000000	/* Issue Reg Login after successful
110dea3101eS 					   ACC */
1117f5f3d0dSJames Smart #define NLP_NPR_ADISC      0x02000000	/* Issue ADISC when dq'ed from
112dea3101eS 					   NPR list */
1137f5f3d0dSJames Smart #define NLP_RM_DFLT_RPI    0x04000000	/* need to remove leftover dflt RPI */
1147f5f3d0dSJames Smart #define NLP_NODEV_REMOVE   0x08000000	/* Defer removal till discovery ends */
11592d7f7b0SJames Smart #define NLP_TARGET_REMOVE  0x10000000   /* Target remove in process */
1167f5f3d0dSJames Smart #define NLP_SC_REQ         0x20000000	/* Target requires authentication */
117dea3101eS 
118e47c9093SJames Smart /* ndlp usage management macros */
119e47c9093SJames Smart #define NLP_CHK_NODE_ACT(ndlp)		(((ndlp)->nlp_usg_map \
120e47c9093SJames Smart 						& NLP_USG_NODE_ACT_BIT) \
121e47c9093SJames Smart 					&& \
122e47c9093SJames Smart 					!((ndlp)->nlp_usg_map \
123e47c9093SJames Smart 						& NLP_USG_FREE_ACK_BIT))
124e47c9093SJames Smart #define NLP_SET_NODE_ACT(ndlp)		((ndlp)->nlp_usg_map \
125e47c9093SJames Smart 						|= NLP_USG_NODE_ACT_BIT)
126e47c9093SJames Smart #define NLP_INT_NODE_ACT(ndlp)		((ndlp)->nlp_usg_map \
127e47c9093SJames Smart 						= NLP_USG_NODE_ACT_BIT)
128e47c9093SJames Smart #define NLP_CLR_NODE_ACT(ndlp)		((ndlp)->nlp_usg_map \
129e47c9093SJames Smart 						&= ~NLP_USG_NODE_ACT_BIT)
130e47c9093SJames Smart #define NLP_CHK_IACT_REQ(ndlp)          ((ndlp)->nlp_usg_map \
131e47c9093SJames Smart 						& NLP_USG_IACT_REQ_BIT)
132e47c9093SJames Smart #define NLP_SET_IACT_REQ(ndlp)          ((ndlp)->nlp_usg_map \
133e47c9093SJames Smart 						|= NLP_USG_IACT_REQ_BIT)
134e47c9093SJames Smart #define NLP_CHK_FREE_REQ(ndlp)		((ndlp)->nlp_usg_map \
135e47c9093SJames Smart 						& NLP_USG_FREE_REQ_BIT)
136e47c9093SJames Smart #define NLP_SET_FREE_REQ(ndlp)		((ndlp)->nlp_usg_map \
137e47c9093SJames Smart 						|= NLP_USG_FREE_REQ_BIT)
138e47c9093SJames Smart #define NLP_CHK_FREE_ACK(ndlp)		((ndlp)->nlp_usg_map \
139e47c9093SJames Smart 						& NLP_USG_FREE_ACK_BIT)
140e47c9093SJames Smart #define NLP_SET_FREE_ACK(ndlp)		((ndlp)->nlp_usg_map \
141e47c9093SJames Smart 						|= NLP_USG_FREE_ACK_BIT)
142e47c9093SJames Smart 
143dea3101eS /* There are 4 different double linked lists nodelist entries can reside on.
144dea3101eS  * The Port Login (PLOGI) list and Address Discovery (ADISC) list are used
145dea3101eS  * when Link Up discovery or Registered State Change Notification (RSCN)
146dea3101eS  * processing is needed.  Each list holds the nodes that require a PLOGI or
147dea3101eS  * ADISC Extended Link Service (ELS) request.  These lists keep track of the
148dea3101eS  * nodes affected by an RSCN, or a Link Up (Typically, all nodes are effected
149dea3101eS  * by Link Up) event.  The unmapped_list contains all nodes that have
150dea3101eS  * successfully logged into at the Fibre Channel level.  The
151dea3101eS  * mapped_list will contain all nodes that are mapped FCP targets.
152dea3101eS  *
153dea3101eS  * The bind list is a list of undiscovered (potentially non-existent) nodes
154dea3101eS  * that we have saved binding information on. This information is used when
155dea3101eS  * nodes transition from the unmapped to the mapped list.
156dea3101eS  */
157dea3101eS 
158dea3101eS /* Defines for nlp_state */
159dea3101eS #define NLP_STE_UNUSED_NODE       0x0	/* node is just allocated */
160dea3101eS #define NLP_STE_PLOGI_ISSUE       0x1	/* PLOGI was sent to NL_PORT */
161dea3101eS #define NLP_STE_ADISC_ISSUE       0x2	/* ADISC was sent to NL_PORT */
162dea3101eS #define NLP_STE_REG_LOGIN_ISSUE   0x3	/* REG_LOGIN was issued for NL_PORT */
163dea3101eS #define NLP_STE_PRLI_ISSUE        0x4	/* PRLI was sent to NL_PORT */
164dea3101eS #define NLP_STE_UNMAPPED_NODE     0x5	/* PRLI completed from NL_PORT */
165dea3101eS #define NLP_STE_MAPPED_NODE       0x6	/* Identified as a FCP Target */
166dea3101eS #define NLP_STE_NPR_NODE          0x7	/* NPort disappeared */
167dea3101eS #define NLP_STE_MAX_STATE         0x8
168dea3101eS #define NLP_STE_FREED_NODE        0xff	/* node entry was freed to MEM_NLP */
169dea3101eS 
170dea3101eS /* For UNUSED_NODE state, the node has just been allocated.
171dea3101eS  * For PLOGI_ISSUE and REG_LOGIN_ISSUE, the node is on
172dea3101eS  * the PLOGI list. For REG_LOGIN_COMPL, the node is taken off the PLOGI list
173dea3101eS  * and put on the unmapped list. For ADISC processing, the node is taken off
174dea3101eS  * the ADISC list and placed on either the mapped or unmapped list (depending
175dea3101eS  * on its previous state). Once on the unmapped list, a PRLI is issued and the
176dea3101eS  * state changed to PRLI_ISSUE. When the PRLI completion occurs, the state is
177dea3101eS  * changed to PRLI_COMPL. If the completion indicates a mapped
178dea3101eS  * node, the node is taken off the unmapped list. The binding list is checked
179dea3101eS  * for a valid binding, or a binding is automatically assigned. If binding
180dea3101eS  * assignment is unsuccessful, the node is left on the unmapped list. If
181dea3101eS  * binding assignment is successful, the associated binding list entry (if
182dea3101eS  * any) is removed, and the node is placed on the mapped list.
183dea3101eS  */
184dea3101eS /*
185dea3101eS  * For a Link Down, all nodes on the ADISC, PLOGI, unmapped or mapped
186c01f3208SJames Smart  * lists will receive a DEVICE_RECOVERY event. If the linkdown or devloss timers
187dea3101eS  * expire, all effected nodes will receive a DEVICE_RM event.
188dea3101eS  */
189dea3101eS /*
190dea3101eS  * For a Link Up or RSCN, all nodes will move from the mapped / unmapped lists
191dea3101eS  * to either the ADISC or PLOGI list.  After a Nameserver query or ALPA loopmap
192dea3101eS  * check, additional nodes may be added (DEVICE_ADD) or removed (DEVICE_RM) to /
193dea3101eS  * from the PLOGI or ADISC lists. Once the PLOGI and ADISC lists are populated,
194dea3101eS  * we will first process the ADISC list.  32 entries are processed initially and
195dea3101eS  * ADISC is initited for each one.  Completions / Events for each node are
196dea3101eS  * funnelled thru the state machine.  As each node finishes ADISC processing, it
197dea3101eS  * starts ADISC for any nodes waiting for ADISC processing. If no nodes are
198dea3101eS  * waiting, and the ADISC list count is identically 0, then we are done. For
199dea3101eS  * Link Up discovery, since all nodes on the PLOGI list are UNREG_LOGIN'ed, we
200dea3101eS  * can issue a CLEAR_LA and reenable Link Events. Next we will process the PLOGI
201dea3101eS  * list.  32 entries are processed initially and PLOGI is initited for each one.
202dea3101eS  * Completions / Events for each node are funnelled thru the state machine.  As
203dea3101eS  * each node finishes PLOGI processing, it starts PLOGI for any nodes waiting
204dea3101eS  * for PLOGI processing. If no nodes are waiting, and the PLOGI list count is
205dea3101eS  * identically 0, then we are done. We have now completed discovery / RSCN
206dea3101eS  * handling. Upon completion, ALL nodes should be on either the mapped or
207dea3101eS  * unmapped lists.
208dea3101eS  */
209dea3101eS 
210dea3101eS /* Defines for Node List Entry Events that could happen */
211dea3101eS #define NLP_EVT_RCV_PLOGI         0x0	/* Rcv'd an ELS PLOGI command */
212dea3101eS #define NLP_EVT_RCV_PRLI          0x1	/* Rcv'd an ELS PRLI  command */
213dea3101eS #define NLP_EVT_RCV_LOGO          0x2	/* Rcv'd an ELS LOGO  command */
214dea3101eS #define NLP_EVT_RCV_ADISC         0x3	/* Rcv'd an ELS ADISC command */
215dea3101eS #define NLP_EVT_RCV_PDISC         0x4	/* Rcv'd an ELS PDISC command */
216dea3101eS #define NLP_EVT_RCV_PRLO          0x5	/* Rcv'd an ELS PRLO  command */
217dea3101eS #define NLP_EVT_CMPL_PLOGI        0x6	/* Sent an ELS PLOGI command */
218dea3101eS #define NLP_EVT_CMPL_PRLI         0x7	/* Sent an ELS PRLI  command */
219dea3101eS #define NLP_EVT_CMPL_LOGO         0x8	/* Sent an ELS LOGO  command */
220dea3101eS #define NLP_EVT_CMPL_ADISC        0x9	/* Sent an ELS ADISC command */
221dea3101eS #define NLP_EVT_CMPL_REG_LOGIN    0xa	/* REG_LOGIN mbox cmd completed */
222dea3101eS #define NLP_EVT_DEVICE_RM         0xb	/* Device not found in NS / ALPAmap */
223dea3101eS #define NLP_EVT_DEVICE_RECOVERY   0xc	/* Device existence unknown */
224dea3101eS #define NLP_EVT_MAX_EVENT         0xd
225dea3101eS 
226