blob: 789a12dc986b36637339e9b7180ef6b6dc7a713b [file] [log] [blame]
dea31012005-04-17 16:05:31 -05001/*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04003 * Fibre Channel Host Bus Adapters. *
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004 * Copyright (C) 2004-2006 Emulex. All rights reserved. *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04005 * EMULEX and SLI are trademarks of Emulex. *
dea31012005-04-17 16:05:31 -05006 * www.emulex.com *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04007 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
dea31012005-04-17 16:05:31 -05008 * *
9 * This program is free software; you can redistribute it and/or *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -040010 * modify it under the terms of version 2 of the GNU General *
11 * Public License as published by the Free Software Foundation. *
12 * This program is distributed in the hope that it will be useful. *
13 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
14 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
15 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
16 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
17 * TO BE LEGALLY INVALID. See the GNU General Public License for *
18 * more details, a copy of which can be found in the file COPYING *
19 * included with this package. *
dea31012005-04-17 16:05:31 -050020 *******************************************************************/
21
dea31012005-04-17 16:05:31 -050022#include <linux/blkdev.h>
23#include <linux/pci.h>
24#include <linux/interrupt.h>
25
James.Smart@Emulex.Com91886522005-08-10 15:03:09 -040026#include <scsi/scsi.h>
dea31012005-04-17 16:05:31 -050027#include <scsi/scsi_device.h>
28#include <scsi/scsi_host.h>
29#include <scsi/scsi_transport_fc.h>
30
31#include "lpfc_hw.h"
32#include "lpfc_sli.h"
33#include "lpfc_disc.h"
34#include "lpfc_scsi.h"
35#include "lpfc.h"
36#include "lpfc_logmsg.h"
37#include "lpfc_crtn.h"
38
39
40/* Called to verify a rcv'ed ADISC was intended for us. */
41static int
42lpfc_check_adisc(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp,
43 struct lpfc_name * nn, struct lpfc_name * pn)
44{
45 /* Compare the ADISC rsp WWNN / WWPN matches our internal node
46 * table entry for that node.
47 */
48 if (memcmp(nn, &ndlp->nlp_nodename, sizeof (struct lpfc_name)) != 0)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -050049 return 0;
dea31012005-04-17 16:05:31 -050050
51 if (memcmp(pn, &ndlp->nlp_portname, sizeof (struct lpfc_name)) != 0)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -050052 return 0;
dea31012005-04-17 16:05:31 -050053
54 /* we match, return success */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -050055 return 1;
dea31012005-04-17 16:05:31 -050056}
57
dea31012005-04-17 16:05:31 -050058int
59lpfc_check_sparm(struct lpfc_hba * phba,
60 struct lpfc_nodelist * ndlp, struct serv_parm * sp,
61 uint32_t class)
62{
63 volatile struct serv_parm *hsp = &phba->fc_sparam;
James.Smart@Emulex.Com2fb70f72005-11-28 11:41:24 -050064 uint16_t hsp_value, ssp_value = 0;
dea31012005-04-17 16:05:31 -050065
James.Smart@Emulex.Com2fb70f72005-11-28 11:41:24 -050066 /*
67 * The receive data field size and buffer-to-buffer receive data field
68 * size entries are 16 bits but are represented as two 8-bit fields in
69 * the driver data structure to account for rsvd bits and other control
70 * bits. Reconstruct and compare the fields as a 16-bit values before
71 * correcting the byte values.
72 */
dea31012005-04-17 16:05:31 -050073 if (sp->cls1.classValid) {
James.Smart@Emulex.Com2fb70f72005-11-28 11:41:24 -050074 hsp_value = (hsp->cls1.rcvDataSizeMsb << 8) |
75 hsp->cls1.rcvDataSizeLsb;
76 ssp_value = (sp->cls1.rcvDataSizeMsb << 8) |
77 sp->cls1.rcvDataSizeLsb;
78 if (ssp_value > hsp_value) {
dea31012005-04-17 16:05:31 -050079 sp->cls1.rcvDataSizeLsb = hsp->cls1.rcvDataSizeLsb;
James.Smart@Emulex.Com2fb70f72005-11-28 11:41:24 -050080 sp->cls1.rcvDataSizeMsb = hsp->cls1.rcvDataSizeMsb;
81 }
dea31012005-04-17 16:05:31 -050082 } else if (class == CLASS1) {
James.Smart@Emulex.Com2fb70f72005-11-28 11:41:24 -050083 return 0;
dea31012005-04-17 16:05:31 -050084 }
85
86 if (sp->cls2.classValid) {
James.Smart@Emulex.Com2fb70f72005-11-28 11:41:24 -050087 hsp_value = (hsp->cls2.rcvDataSizeMsb << 8) |
88 hsp->cls2.rcvDataSizeLsb;
89 ssp_value = (sp->cls2.rcvDataSizeMsb << 8) |
90 sp->cls2.rcvDataSizeLsb;
91 if (ssp_value > hsp_value) {
dea31012005-04-17 16:05:31 -050092 sp->cls2.rcvDataSizeLsb = hsp->cls2.rcvDataSizeLsb;
James.Smart@Emulex.Com2fb70f72005-11-28 11:41:24 -050093 sp->cls2.rcvDataSizeMsb = hsp->cls2.rcvDataSizeMsb;
94 }
dea31012005-04-17 16:05:31 -050095 } else if (class == CLASS2) {
James.Smart@Emulex.Com2fb70f72005-11-28 11:41:24 -050096 return 0;
dea31012005-04-17 16:05:31 -050097 }
98
99 if (sp->cls3.classValid) {
James.Smart@Emulex.Com2fb70f72005-11-28 11:41:24 -0500100 hsp_value = (hsp->cls3.rcvDataSizeMsb << 8) |
101 hsp->cls3.rcvDataSizeLsb;
102 ssp_value = (sp->cls3.rcvDataSizeMsb << 8) |
103 sp->cls3.rcvDataSizeLsb;
104 if (ssp_value > hsp_value) {
dea31012005-04-17 16:05:31 -0500105 sp->cls3.rcvDataSizeLsb = hsp->cls3.rcvDataSizeLsb;
James.Smart@Emulex.Com2fb70f72005-11-28 11:41:24 -0500106 sp->cls3.rcvDataSizeMsb = hsp->cls3.rcvDataSizeMsb;
107 }
dea31012005-04-17 16:05:31 -0500108 } else if (class == CLASS3) {
James.Smart@Emulex.Com2fb70f72005-11-28 11:41:24 -0500109 return 0;
dea31012005-04-17 16:05:31 -0500110 }
111
James.Smart@Emulex.Com2fb70f72005-11-28 11:41:24 -0500112 /*
113 * Preserve the upper four bits of the MSB from the PLOGI response.
114 * These bits contain the Buffer-to-Buffer State Change Number
115 * from the target and need to be passed to the FW.
116 */
117 hsp_value = (hsp->cmn.bbRcvSizeMsb << 8) | hsp->cmn.bbRcvSizeLsb;
118 ssp_value = (sp->cmn.bbRcvSizeMsb << 8) | sp->cmn.bbRcvSizeLsb;
119 if (ssp_value > hsp_value) {
dea31012005-04-17 16:05:31 -0500120 sp->cmn.bbRcvSizeLsb = hsp->cmn.bbRcvSizeLsb;
James.Smart@Emulex.Com2fb70f72005-11-28 11:41:24 -0500121 sp->cmn.bbRcvSizeMsb = (sp->cmn.bbRcvSizeMsb & 0xF0) |
122 (hsp->cmn.bbRcvSizeMsb & 0x0F);
123 }
dea31012005-04-17 16:05:31 -0500124
dea31012005-04-17 16:05:31 -0500125 memcpy(&ndlp->nlp_nodename, &sp->nodeName, sizeof (struct lpfc_name));
126 memcpy(&ndlp->nlp_portname, &sp->portName, sizeof (struct lpfc_name));
James.Smart@Emulex.Com2fb70f72005-11-28 11:41:24 -0500127 return 1;
dea31012005-04-17 16:05:31 -0500128}
129
130static void *
131lpfc_check_elscmpl_iocb(struct lpfc_hba * phba,
132 struct lpfc_iocbq *cmdiocb,
133 struct lpfc_iocbq *rspiocb)
134{
135 struct lpfc_dmabuf *pcmd, *prsp;
136 uint32_t *lp;
137 void *ptr = NULL;
138 IOCB_t *irsp;
139
140 irsp = &rspiocb->iocb;
141 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
142
143 /* For lpfc_els_abort, context2 could be zero'ed to delay
144 * freeing associated memory till after ABTS completes.
145 */
146 if (pcmd) {
147 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf,
148 list);
149 if (prsp) {
150 lp = (uint32_t *) prsp->virt;
151 ptr = (void *)((uint8_t *)lp + sizeof(uint32_t));
152 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500153 } else {
dea31012005-04-17 16:05:31 -0500154 /* Force ulpStatus error since we are returning NULL ptr */
155 if (!(irsp->ulpStatus)) {
156 irsp->ulpStatus = IOSTAT_LOCAL_REJECT;
157 irsp->un.ulpWord[4] = IOERR_SLI_ABORTED;
158 }
159 ptr = NULL;
160 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500161 return ptr;
dea31012005-04-17 16:05:31 -0500162}
163
164
165/*
166 * Free resources / clean up outstanding I/Os
167 * associated with a LPFC_NODELIST entry. This
168 * routine effectively results in a "software abort".
169 */
170int
James Smart07951072007-04-25 09:51:38 -0400171lpfc_els_abort(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp)
dea31012005-04-17 16:05:31 -0500172{
James Smart2534ba72007-04-25 09:52:20 -0400173 LIST_HEAD(completions);
dea31012005-04-17 16:05:31 -0500174 struct lpfc_sli *psli;
175 struct lpfc_sli_ring *pring;
176 struct lpfc_iocbq *iocb, *next_iocb;
James Smart2534ba72007-04-25 09:52:20 -0400177 IOCB_t *cmd;
dea31012005-04-17 16:05:31 -0500178
179 /* Abort outstanding I/O on NPort <nlp_DID> */
180 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
James Smartdca94792006-08-01 07:34:08 -0400181 "%d:0205 Abort outstanding I/O on NPort x%x "
dea31012005-04-17 16:05:31 -0500182 "Data: x%x x%x x%x\n",
183 phba->brd_no, ndlp->nlp_DID, ndlp->nlp_flag,
184 ndlp->nlp_state, ndlp->nlp_rpi);
185
186 psli = &phba->sli;
187 pring = &psli->ring[LPFC_ELS_RING];
188
189 /* First check the txq */
James Smart2534ba72007-04-25 09:52:20 -0400190 spin_lock_irq(phba->host->host_lock);
191 list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
192 /* Check to see if iocb matches the nport we are looking
193 for */
194 if (lpfc_check_sli_ndlp(phba, pring, iocb, ndlp)) {
195 /* It matches, so deque and call compl with an
196 error */
197 list_move_tail(&iocb->list, &completions);
198 pring->txq_cnt--;
dea31012005-04-17 16:05:31 -0500199 }
James Smart2534ba72007-04-25 09:52:20 -0400200 }
dea31012005-04-17 16:05:31 -0500201
dea31012005-04-17 16:05:31 -0500202 /* Next check the txcmplq */
James Smart07951072007-04-25 09:51:38 -0400203 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
204 /* Check to see if iocb matches the nport we are looking
205 for */
James Smart2534ba72007-04-25 09:52:20 -0400206 if (lpfc_check_sli_ndlp(phba, pring, iocb, ndlp))
James Smart07951072007-04-25 09:51:38 -0400207 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
James Smart07951072007-04-25 09:51:38 -0400208 }
209 spin_unlock_irq(phba->host->host_lock);
dea31012005-04-17 16:05:31 -0500210
James Smart2534ba72007-04-25 09:52:20 -0400211 while (!list_empty(&completions)) {
212 iocb = list_get_first(&completions, struct lpfc_iocbq, list);
213 cmd = &iocb->iocb;
214 list_del(&iocb->list);
215
216 if (iocb->iocb_cmpl) {
217 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
218 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
219 (iocb->iocb_cmpl) (phba, iocb, iocb);
220 } else
221 lpfc_sli_release_iocbq(phba, iocb);
222 }
223
dea31012005-04-17 16:05:31 -0500224 /* If we are delaying issuing an ELS command, cancel it */
James Smartfdcebe22006-03-07 15:04:01 -0500225 if (ndlp->nlp_flag & NLP_DELAY_TMO)
226 lpfc_cancel_retry_delay_tmo(phba, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500227 return 0;
dea31012005-04-17 16:05:31 -0500228}
229
230static int
231lpfc_rcv_plogi(struct lpfc_hba * phba,
232 struct lpfc_nodelist * ndlp,
233 struct lpfc_iocbq *cmdiocb)
234{
235 struct lpfc_dmabuf *pcmd;
236 uint32_t *lp;
237 IOCB_t *icmd;
238 struct serv_parm *sp;
239 LPFC_MBOXQ_t *mbox;
240 struct ls_rjt stat;
241 int rc;
242
243 memset(&stat, 0, sizeof (struct ls_rjt));
244 if (phba->hba_state <= LPFC_FLOGI) {
245 /* Before responding to PLOGI, check for pt2pt mode.
246 * If we are pt2pt, with an outstanding FLOGI, abort
247 * the FLOGI and resend it first.
248 */
249 if (phba->fc_flag & FC_PT2PT) {
250 lpfc_els_abort_flogi(phba);
251 if (!(phba->fc_flag & FC_PT2PT_PLOGI)) {
252 /* If the other side is supposed to initiate
253 * the PLOGI anyway, just ACC it now and
254 * move on with discovery.
255 */
256 phba->fc_edtov = FF_DEF_EDTOV;
257 phba->fc_ratov = FF_DEF_RATOV;
258 /* Start discovery - this should just do
259 CLEAR_LA */
260 lpfc_disc_start(phba);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500261 } else {
dea31012005-04-17 16:05:31 -0500262 lpfc_initial_flogi(phba);
263 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500264 } else {
dea31012005-04-17 16:05:31 -0500265 stat.un.b.lsRjtRsnCode = LSRJT_LOGICAL_BSY;
266 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
267 lpfc_els_rsp_reject(phba, stat.un.lsRjtError, cmdiocb,
268 ndlp);
269 return 0;
270 }
271 }
272 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
273 lp = (uint32_t *) pcmd->virt;
274 sp = (struct serv_parm *) ((uint8_t *) lp + sizeof (uint32_t));
275 if ((lpfc_check_sparm(phba, ndlp, sp, CLASS3) == 0)) {
276 /* Reject this request because invalid parameters */
277 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
278 stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
279 lpfc_els_rsp_reject(phba, stat.un.lsRjtError, cmdiocb, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500280 return 0;
dea31012005-04-17 16:05:31 -0500281 }
282 icmd = &cmdiocb->iocb;
283
284 /* PLOGI chkparm OK */
285 lpfc_printf_log(phba,
286 KERN_INFO,
287 LOG_ELS,
288 "%d:0114 PLOGI chkparm OK Data: x%x x%x x%x x%x\n",
289 phba->brd_no,
290 ndlp->nlp_DID, ndlp->nlp_state, ndlp->nlp_flag,
291 ndlp->nlp_rpi);
292
293 if ((phba->cfg_fcp_class == 2) &&
294 (sp->cls2.classValid)) {
295 ndlp->nlp_fcp_info |= CLASS2;
296 } else {
297 ndlp->nlp_fcp_info |= CLASS3;
298 }
299 ndlp->nlp_class_sup = 0;
300 if (sp->cls1.classValid)
301 ndlp->nlp_class_sup |= FC_COS_CLASS1;
302 if (sp->cls2.classValid)
303 ndlp->nlp_class_sup |= FC_COS_CLASS2;
304 if (sp->cls3.classValid)
305 ndlp->nlp_class_sup |= FC_COS_CLASS3;
306 if (sp->cls4.classValid)
307 ndlp->nlp_class_sup |= FC_COS_CLASS4;
308 ndlp->nlp_maxframe =
309 ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) | sp->cmn.bbRcvSizeLsb;
310
311 /* no need to reg_login if we are already in one of these states */
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500312 switch (ndlp->nlp_state) {
dea31012005-04-17 16:05:31 -0500313 case NLP_STE_NPR_NODE:
314 if (!(ndlp->nlp_flag & NLP_NPR_ADISC))
315 break;
316 case NLP_STE_REG_LOGIN_ISSUE:
317 case NLP_STE_PRLI_ISSUE:
318 case NLP_STE_UNMAPPED_NODE:
319 case NLP_STE_MAPPED_NODE:
320 lpfc_els_rsp_acc(phba, ELS_CMD_PLOGI, cmdiocb, ndlp, NULL, 0);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500321 return 1;
dea31012005-04-17 16:05:31 -0500322 }
323
324 if ((phba->fc_flag & FC_PT2PT)
325 && !(phba->fc_flag & FC_PT2PT_PLOGI)) {
326 /* rcv'ed PLOGI decides what our NPortId will be */
327 phba->fc_myDID = icmd->un.rcvels.parmRo;
328 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
329 if (mbox == NULL)
330 goto out;
331 lpfc_config_link(phba, mbox);
332 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
333 rc = lpfc_sli_issue_mbox
334 (phba, mbox, (MBX_NOWAIT | MBX_STOP_IOCB));
335 if (rc == MBX_NOT_FINISHED) {
336 mempool_free( mbox, phba->mbox_mem_pool);
337 goto out;
338 }
339
340 lpfc_can_disctmo(phba);
341 }
342 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
343 if (mbox == NULL)
344 goto out;
345
346 if (lpfc_reg_login(phba, icmd->un.rcvels.remoteID,
347 (uint8_t *) sp, mbox, 0)) {
348 mempool_free( mbox, phba->mbox_mem_pool);
349 goto out;
350 }
351
352 /* ACC PLOGI rsp command needs to execute first,
353 * queue this mbox command to be processed later.
354 */
355 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
356 mbox->context2 = ndlp;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -0500357 ndlp->nlp_flag |= (NLP_ACC_REGLOGIN | NLP_RCV_PLOGI);
dea31012005-04-17 16:05:31 -0500358
James Smart33ccf8d2006-08-17 11:57:58 -0400359 /*
360 * If there is an outstanding PLOGI issued, abort it before
361 * sending ACC rsp for received PLOGI. If pending plogi
362 * is not canceled here, the plogi will be rejected by
363 * remote port and will be retried. On a configuration with
364 * single discovery thread, this will cause a huge delay in
365 * discovery. Also this will cause multiple state machines
366 * running in parallel for this node.
367 */
368 if (ndlp->nlp_state == NLP_STE_PLOGI_ISSUE) {
369 /* software abort outstanding PLOGI */
James Smart07951072007-04-25 09:51:38 -0400370 lpfc_els_abort(phba, ndlp);
James Smart33ccf8d2006-08-17 11:57:58 -0400371 }
372
dea31012005-04-17 16:05:31 -0500373 lpfc_els_rsp_acc(phba, ELS_CMD_PLOGI, cmdiocb, ndlp, mbox, 0);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500374 return 1;
dea31012005-04-17 16:05:31 -0500375
376out:
377 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
378 stat.un.b.lsRjtRsnCodeExp = LSEXP_OUT_OF_RESOURCE;
379 lpfc_els_rsp_reject(phba, stat.un.lsRjtError, cmdiocb, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500380 return 0;
dea31012005-04-17 16:05:31 -0500381}
382
383static int
384lpfc_rcv_padisc(struct lpfc_hba * phba,
385 struct lpfc_nodelist * ndlp,
386 struct lpfc_iocbq *cmdiocb)
387{
388 struct lpfc_dmabuf *pcmd;
389 struct serv_parm *sp;
390 struct lpfc_name *pnn, *ppn;
391 struct ls_rjt stat;
392 ADISC *ap;
393 IOCB_t *icmd;
394 uint32_t *lp;
395 uint32_t cmd;
396
397 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
398 lp = (uint32_t *) pcmd->virt;
399
400 cmd = *lp++;
401 if (cmd == ELS_CMD_ADISC) {
402 ap = (ADISC *) lp;
403 pnn = (struct lpfc_name *) & ap->nodeName;
404 ppn = (struct lpfc_name *) & ap->portName;
405 } else {
406 sp = (struct serv_parm *) lp;
407 pnn = (struct lpfc_name *) & sp->nodeName;
408 ppn = (struct lpfc_name *) & sp->portName;
409 }
410
411 icmd = &cmdiocb->iocb;
412 if ((icmd->ulpStatus == 0) &&
413 (lpfc_check_adisc(phba, ndlp, pnn, ppn))) {
414 if (cmd == ELS_CMD_ADISC) {
415 lpfc_els_rsp_adisc_acc(phba, cmdiocb, ndlp);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500416 } else {
dea31012005-04-17 16:05:31 -0500417 lpfc_els_rsp_acc(phba, ELS_CMD_PLOGI, cmdiocb, ndlp,
418 NULL, 0);
419 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500420 return 1;
dea31012005-04-17 16:05:31 -0500421 }
422 /* Reject this request because invalid parameters */
423 stat.un.b.lsRjtRsvd0 = 0;
424 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
425 stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
426 stat.un.b.vendorUnique = 0;
427 lpfc_els_rsp_reject(phba, stat.un.lsRjtError, cmdiocb, ndlp);
428
dea31012005-04-17 16:05:31 -0500429 /* 1 sec timeout */
430 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ);
431
432 spin_lock_irq(phba->host->host_lock);
433 ndlp->nlp_flag |= NLP_DELAY_TMO;
434 spin_unlock_irq(phba->host->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -0500435 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
436 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smartde0c5b32007-04-25 09:52:27 -0400437 lpfc_nlp_set_state(phba, ndlp, NLP_STE_NPR_NODE);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500438 return 0;
dea31012005-04-17 16:05:31 -0500439}
440
441static int
442lpfc_rcv_logo(struct lpfc_hba * phba,
443 struct lpfc_nodelist * ndlp,
James Smart82d9a2a2006-04-15 11:53:05 -0400444 struct lpfc_iocbq *cmdiocb,
445 uint32_t els_cmd)
dea31012005-04-17 16:05:31 -0500446{
447 /* Put ndlp on NPR list with 1 sec timeout for plogi, ACC logo */
448 /* Only call LOGO ACC for first LOGO, this avoids sending unnecessary
449 * PLOGIs during LOGO storms from a device.
450 */
451 ndlp->nlp_flag |= NLP_LOGO_ACC;
James Smart82d9a2a2006-04-15 11:53:05 -0400452 if (els_cmd == ELS_CMD_PRLO)
453 lpfc_els_rsp_acc(phba, ELS_CMD_PRLO, cmdiocb, ndlp, NULL, 0);
454 else
455 lpfc_els_rsp_acc(phba, ELS_CMD_ACC, cmdiocb, ndlp, NULL, 0);
dea31012005-04-17 16:05:31 -0500456
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500457 if (!(ndlp->nlp_type & NLP_FABRIC) ||
458 (ndlp->nlp_state == NLP_STE_ADISC_ISSUE)) {
dea31012005-04-17 16:05:31 -0500459 /* Only try to re-login if this is NOT a Fabric Node */
dea31012005-04-17 16:05:31 -0500460 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ * 1);
461 spin_lock_irq(phba->host->host_lock);
462 ndlp->nlp_flag |= NLP_DELAY_TMO;
463 spin_unlock_irq(phba->host->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500464
Jamie Wellnitz5024ab12006-02-28 19:25:28 -0500465 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
466 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smartde0c5b32007-04-25 09:52:27 -0400467 lpfc_nlp_set_state(phba, ndlp, NLP_STE_NPR_NODE);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500468 } else {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -0500469 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smartde0c5b32007-04-25 09:52:27 -0400470 lpfc_nlp_set_state(phba, ndlp, NLP_STE_UNUSED_NODE);
dea31012005-04-17 16:05:31 -0500471 }
472
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500473 spin_lock_irq(phba->host->host_lock);
dea31012005-04-17 16:05:31 -0500474 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500475 spin_unlock_irq(phba->host->host_lock);
dea31012005-04-17 16:05:31 -0500476 /* The driver has to wait until the ACC completes before it continues
477 * processing the LOGO. The action will resume in
478 * lpfc_cmpl_els_logo_acc routine. Since part of processing includes an
479 * unreg_login, the driver waits so the ACC does not get aborted.
480 */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500481 return 0;
dea31012005-04-17 16:05:31 -0500482}
483
484static void
485lpfc_rcv_prli(struct lpfc_hba * phba,
486 struct lpfc_nodelist * ndlp,
487 struct lpfc_iocbq *cmdiocb)
488{
489 struct lpfc_dmabuf *pcmd;
490 uint32_t *lp;
491 PRLI *npr;
492 struct fc_rport *rport = ndlp->rport;
493 u32 roles;
494
495 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
496 lp = (uint32_t *) pcmd->virt;
497 npr = (PRLI *) ((uint8_t *) lp + sizeof (uint32_t));
498
499 ndlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR);
500 ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
501 if ((npr->acceptRspCode == PRLI_REQ_EXECUTED) &&
502 (npr->prliType == PRLI_FCP_TYPE)) {
503 if (npr->initiatorFunc)
504 ndlp->nlp_type |= NLP_FCP_INITIATOR;
505 if (npr->targetFunc)
506 ndlp->nlp_type |= NLP_FCP_TARGET;
507 if (npr->Retry)
508 ndlp->nlp_fcp_info |= NLP_FCP_2_DEVICE;
509 }
510 if (rport) {
511 /* We need to update the rport role values */
512 roles = FC_RPORT_ROLE_UNKNOWN;
513 if (ndlp->nlp_type & NLP_FCP_INITIATOR)
514 roles |= FC_RPORT_ROLE_FCP_INITIATOR;
515 if (ndlp->nlp_type & NLP_FCP_TARGET)
516 roles |= FC_RPORT_ROLE_FCP_TARGET;
517 fc_remote_port_rolechg(rport, roles);
518 }
519}
520
521static uint32_t
522lpfc_disc_set_adisc(struct lpfc_hba * phba,
523 struct lpfc_nodelist * ndlp)
524{
525 /* Check config parameter use-adisc or FCP-2 */
526 if ((phba->cfg_use_adisc == 0) &&
527 !(phba->fc_flag & FC_RSCN_MODE)) {
528 if (!(ndlp->nlp_fcp_info & NLP_FCP_2_DEVICE))
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500529 return 0;
dea31012005-04-17 16:05:31 -0500530 }
531 spin_lock_irq(phba->host->host_lock);
532 ndlp->nlp_flag |= NLP_NPR_ADISC;
533 spin_unlock_irq(phba->host->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500534 return 1;
dea31012005-04-17 16:05:31 -0500535}
536
537static uint32_t
538lpfc_disc_illegal(struct lpfc_hba * phba,
539 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
540{
541 lpfc_printf_log(phba,
542 KERN_ERR,
543 LOG_DISCOVERY,
544 "%d:0253 Illegal State Transition: node x%x event x%x, "
545 "state x%x Data: x%x x%x\n",
546 phba->brd_no,
547 ndlp->nlp_DID, evt, ndlp->nlp_state, ndlp->nlp_rpi,
548 ndlp->nlp_flag);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500549 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -0500550}
551
552/* Start of Discovery State Machine routines */
553
554static uint32_t
555lpfc_rcv_plogi_unused_node(struct lpfc_hba * phba,
556 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
557{
558 struct lpfc_iocbq *cmdiocb;
559
560 cmdiocb = (struct lpfc_iocbq *) arg;
561
562 if (lpfc_rcv_plogi(phba, ndlp, cmdiocb)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -0500563 ndlp->nlp_prev_state = NLP_STE_UNUSED_NODE;
James Smartde0c5b32007-04-25 09:52:27 -0400564 lpfc_nlp_set_state(phba, ndlp, NLP_STE_UNUSED_NODE);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500565 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -0500566 }
James Smartde0c5b32007-04-25 09:52:27 -0400567 lpfc_drop_node(phba, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500568 return NLP_STE_FREED_NODE;
dea31012005-04-17 16:05:31 -0500569}
570
571static uint32_t
572lpfc_rcv_els_unused_node(struct lpfc_hba * phba,
573 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
574{
575 lpfc_issue_els_logo(phba, ndlp, 0);
James Smartde0c5b32007-04-25 09:52:27 -0400576 lpfc_nlp_set_state(phba, ndlp, NLP_STE_UNUSED_NODE);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500577 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -0500578}
579
580static uint32_t
581lpfc_rcv_logo_unused_node(struct lpfc_hba * phba,
582 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
583{
584 struct lpfc_iocbq *cmdiocb;
585
586 cmdiocb = (struct lpfc_iocbq *) arg;
587
588 spin_lock_irq(phba->host->host_lock);
589 ndlp->nlp_flag |= NLP_LOGO_ACC;
590 spin_unlock_irq(phba->host->host_lock);
591 lpfc_els_rsp_acc(phba, ELS_CMD_ACC, cmdiocb, ndlp, NULL, 0);
James Smartde0c5b32007-04-25 09:52:27 -0400592 lpfc_nlp_set_state(phba, ndlp, NLP_STE_UNUSED_NODE);
dea31012005-04-17 16:05:31 -0500593
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500594 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -0500595}
596
597static uint32_t
598lpfc_cmpl_logo_unused_node(struct lpfc_hba * phba,
599 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
600{
James Smartde0c5b32007-04-25 09:52:27 -0400601 lpfc_drop_node(phba, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500602 return NLP_STE_FREED_NODE;
dea31012005-04-17 16:05:31 -0500603}
604
605static uint32_t
606lpfc_device_rm_unused_node(struct lpfc_hba * phba,
607 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
608{
James Smartde0c5b32007-04-25 09:52:27 -0400609 lpfc_drop_node(phba, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500610 return NLP_STE_FREED_NODE;
dea31012005-04-17 16:05:31 -0500611}
612
613static uint32_t
614lpfc_rcv_plogi_plogi_issue(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp,
615 void *arg, uint32_t evt)
616{
617 struct lpfc_iocbq *cmdiocb = arg;
618 struct lpfc_dmabuf *pcmd;
619 struct serv_parm *sp;
620 uint32_t *lp;
621 struct ls_rjt stat;
622 int port_cmp;
623
624 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
625 lp = (uint32_t *) pcmd->virt;
626 sp = (struct serv_parm *) ((uint8_t *) lp + sizeof (uint32_t));
627
628 memset(&stat, 0, sizeof (struct ls_rjt));
629
630 /* For a PLOGI, we only accept if our portname is less
631 * than the remote portname.
632 */
633 phba->fc_stat.elsLogiCol++;
634 port_cmp = memcmp(&phba->fc_portname, &sp->portName,
635 sizeof (struct lpfc_name));
636
637 if (port_cmp >= 0) {
638 /* Reject this request because the remote node will accept
639 ours */
640 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
641 stat.un.b.lsRjtRsnCodeExp = LSEXP_CMD_IN_PROGRESS;
642 lpfc_els_rsp_reject(phba, stat.un.lsRjtError, cmdiocb, ndlp);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500643 } else {
dea31012005-04-17 16:05:31 -0500644 lpfc_rcv_plogi(phba, ndlp, cmdiocb);
645 } /* if our portname was less */
646
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500647 return ndlp->nlp_state;
648}
649
650static uint32_t
651lpfc_rcv_logo_plogi_issue(struct lpfc_hba * phba,
652 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
653{
654 struct lpfc_iocbq *cmdiocb;
655
656 cmdiocb = (struct lpfc_iocbq *) arg;
657
658 /* software abort outstanding PLOGI */
James Smart07951072007-04-25 09:51:38 -0400659 lpfc_els_abort(phba, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500660
James Smart82d9a2a2006-04-15 11:53:05 -0400661 lpfc_rcv_logo(phba, ndlp, cmdiocb, ELS_CMD_LOGO);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500662 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -0500663}
664
665static uint32_t
666lpfc_rcv_els_plogi_issue(struct lpfc_hba * phba,
667 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
668{
669 struct lpfc_iocbq *cmdiocb;
670
671 cmdiocb = (struct lpfc_iocbq *) arg;
672
673 /* software abort outstanding PLOGI */
James Smart07951072007-04-25 09:51:38 -0400674 lpfc_els_abort(phba, ndlp);
dea31012005-04-17 16:05:31 -0500675
676 if (evt == NLP_EVT_RCV_LOGO) {
677 lpfc_els_rsp_acc(phba, ELS_CMD_ACC, cmdiocb, ndlp, NULL, 0);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500678 } else {
dea31012005-04-17 16:05:31 -0500679 lpfc_issue_els_logo(phba, ndlp, 0);
680 }
681
682 /* Put ndlp in npr list set plogi timer for 1 sec */
Jamie Wellnitz5024ab12006-02-28 19:25:28 -0500683 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ * 1);
684 spin_lock_irq(phba->host->host_lock);
685 ndlp->nlp_flag |= NLP_DELAY_TMO;
686 spin_unlock_irq(phba->host->host_lock);
687 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
688 ndlp->nlp_prev_state = NLP_STE_PLOGI_ISSUE;
James Smartde0c5b32007-04-25 09:52:27 -0400689 lpfc_nlp_set_state(phba, ndlp, NLP_STE_NPR_NODE);
dea31012005-04-17 16:05:31 -0500690
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500691 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -0500692}
693
694static uint32_t
695lpfc_cmpl_plogi_plogi_issue(struct lpfc_hba * phba,
696 struct lpfc_nodelist * ndlp, void *arg,
697 uint32_t evt)
698{
699 struct lpfc_iocbq *cmdiocb, *rspiocb;
James Smart14691152006-12-02 13:34:28 -0500700 struct lpfc_dmabuf *pcmd, *prsp, *mp;
dea31012005-04-17 16:05:31 -0500701 uint32_t *lp;
702 IOCB_t *irsp;
703 struct serv_parm *sp;
704 LPFC_MBOXQ_t *mbox;
705
706 cmdiocb = (struct lpfc_iocbq *) arg;
707 rspiocb = cmdiocb->context_un.rsp_iocb;
708
709 if (ndlp->nlp_flag & NLP_ACC_REGLOGIN) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -0500710 /* Recovery from PLOGI collision logic */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500711 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -0500712 }
713
714 irsp = &rspiocb->iocb;
715
716 if (irsp->ulpStatus)
717 goto out;
718
719 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
720
721 prsp = list_get_first(&pcmd->list,
722 struct lpfc_dmabuf,
723 list);
724 lp = (uint32_t *) prsp->virt;
725
726 sp = (struct serv_parm *) ((uint8_t *) lp + sizeof (uint32_t));
727 if (!lpfc_check_sparm(phba, ndlp, sp, CLASS3))
728 goto out;
729
730 /* PLOGI chkparm OK */
731 lpfc_printf_log(phba,
732 KERN_INFO,
733 LOG_ELS,
734 "%d:0121 PLOGI chkparm OK "
735 "Data: x%x x%x x%x x%x\n",
736 phba->brd_no,
737 ndlp->nlp_DID, ndlp->nlp_state,
738 ndlp->nlp_flag, ndlp->nlp_rpi);
739
740 if ((phba->cfg_fcp_class == 2) &&
741 (sp->cls2.classValid)) {
742 ndlp->nlp_fcp_info |= CLASS2;
743 } else {
744 ndlp->nlp_fcp_info |= CLASS3;
745 }
746 ndlp->nlp_class_sup = 0;
747 if (sp->cls1.classValid)
748 ndlp->nlp_class_sup |= FC_COS_CLASS1;
749 if (sp->cls2.classValid)
750 ndlp->nlp_class_sup |= FC_COS_CLASS2;
751 if (sp->cls3.classValid)
752 ndlp->nlp_class_sup |= FC_COS_CLASS3;
753 if (sp->cls4.classValid)
754 ndlp->nlp_class_sup |= FC_COS_CLASS4;
755 ndlp->nlp_maxframe =
756 ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) |
757 sp->cmn.bbRcvSizeLsb;
758
759 if (!(mbox = mempool_alloc(phba->mbox_mem_pool,
760 GFP_KERNEL)))
761 goto out;
762
763 lpfc_unreg_rpi(phba, ndlp);
James Smartde0c5b32007-04-25 09:52:27 -0400764 if (lpfc_reg_login(phba, irsp->un.elsreq64.remoteID, (uint8_t *) sp,
765 mbox, 0) == 0) {
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500766 switch (ndlp->nlp_DID) {
dea31012005-04-17 16:05:31 -0500767 case NameServer_DID:
James Smartde0c5b32007-04-25 09:52:27 -0400768 mbox->mbox_cmpl = lpfc_mbx_cmpl_ns_reg_login;
dea31012005-04-17 16:05:31 -0500769 break;
770 case FDMI_DID:
James Smartde0c5b32007-04-25 09:52:27 -0400771 mbox->mbox_cmpl = lpfc_mbx_cmpl_fdmi_reg_login;
dea31012005-04-17 16:05:31 -0500772 break;
773 default:
James Smartde0c5b32007-04-25 09:52:27 -0400774 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
dea31012005-04-17 16:05:31 -0500775 }
776 mbox->context2 = ndlp;
777 if (lpfc_sli_issue_mbox(phba, mbox,
778 (MBX_NOWAIT | MBX_STOP_IOCB))
779 != MBX_NOT_FINISHED) {
James Smartde0c5b32007-04-25 09:52:27 -0400780 lpfc_nlp_set_state(phba, ndlp, NLP_STE_REG_LOGIN_ISSUE);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500781 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -0500782 }
James Smart14691152006-12-02 13:34:28 -0500783 mp = (struct lpfc_dmabuf *)mbox->context1;
784 lpfc_mbuf_free(phba, mp->virt, mp->phys);
785 kfree(mp);
dea31012005-04-17 16:05:31 -0500786 mempool_free(mbox, phba->mbox_mem_pool);
787 } else {
788 mempool_free(mbox, phba->mbox_mem_pool);
789 }
790
791
792 out:
793 /* Free this node since the driver cannot login or has the wrong
794 sparm */
James Smartde0c5b32007-04-25 09:52:27 -0400795 lpfc_drop_node(phba, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500796 return NLP_STE_FREED_NODE;
dea31012005-04-17 16:05:31 -0500797}
798
799static uint32_t
800lpfc_device_rm_plogi_issue(struct lpfc_hba * phba,
801 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
802{
James Smarta0f9b482006-04-15 11:52:56 -0400803 if(ndlp->nlp_flag & NLP_NPR_2B_DISC) {
804 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
805 return ndlp->nlp_state;
806 }
807 else {
808 /* software abort outstanding PLOGI */
James Smart07951072007-04-25 09:51:38 -0400809 lpfc_els_abort(phba, ndlp);
dea31012005-04-17 16:05:31 -0500810
James Smartde0c5b32007-04-25 09:52:27 -0400811 lpfc_drop_node(phba, ndlp);
James Smarta0f9b482006-04-15 11:52:56 -0400812 return NLP_STE_FREED_NODE;
813 }
dea31012005-04-17 16:05:31 -0500814}
815
816static uint32_t
817lpfc_device_recov_plogi_issue(struct lpfc_hba * phba,
818 struct lpfc_nodelist * ndlp, void *arg,
819 uint32_t evt)
820{
821 /* software abort outstanding PLOGI */
James Smart07951072007-04-25 09:51:38 -0400822 lpfc_els_abort(phba, ndlp);
dea31012005-04-17 16:05:31 -0500823
Jamie Wellnitz5024ab12006-02-28 19:25:28 -0500824 ndlp->nlp_prev_state = NLP_STE_PLOGI_ISSUE;
James Smartde0c5b32007-04-25 09:52:27 -0400825 lpfc_nlp_set_state(phba, ndlp, NLP_STE_NPR_NODE);
dea31012005-04-17 16:05:31 -0500826 spin_lock_irq(phba->host->host_lock);
James Smarta0f9b482006-04-15 11:52:56 -0400827 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
dea31012005-04-17 16:05:31 -0500828 spin_unlock_irq(phba->host->host_lock);
829
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500830 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -0500831}
832
833static uint32_t
834lpfc_rcv_plogi_adisc_issue(struct lpfc_hba * phba,
835 struct lpfc_nodelist * ndlp, void *arg,
836 uint32_t evt)
837{
838 struct lpfc_iocbq *cmdiocb;
839
840 /* software abort outstanding ADISC */
James Smart07951072007-04-25 09:51:38 -0400841 lpfc_els_abort(phba, ndlp);
dea31012005-04-17 16:05:31 -0500842
843 cmdiocb = (struct lpfc_iocbq *) arg;
844
845 if (lpfc_rcv_plogi(phba, ndlp, cmdiocb)) {
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500846 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -0500847 }
Jamie Wellnitz5024ab12006-02-28 19:25:28 -0500848 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
James Smartde0c5b32007-04-25 09:52:27 -0400849 lpfc_nlp_set_state(phba, ndlp, NLP_STE_PLOGI_ISSUE);
James Smart488d1462006-03-07 15:02:37 -0500850 lpfc_issue_els_plogi(phba, ndlp->nlp_DID, 0);
dea31012005-04-17 16:05:31 -0500851
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500852 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -0500853}
854
855static uint32_t
856lpfc_rcv_prli_adisc_issue(struct lpfc_hba * phba,
857 struct lpfc_nodelist * ndlp, void *arg,
858 uint32_t evt)
859{
860 struct lpfc_iocbq *cmdiocb;
861
862 cmdiocb = (struct lpfc_iocbq *) arg;
863
864 lpfc_els_rsp_prli_acc(phba, cmdiocb, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500865 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -0500866}
867
868static uint32_t
869lpfc_rcv_logo_adisc_issue(struct lpfc_hba * phba,
870 struct lpfc_nodelist * ndlp, void *arg,
871 uint32_t evt)
872{
873 struct lpfc_iocbq *cmdiocb;
874
875 cmdiocb = (struct lpfc_iocbq *) arg;
876
877 /* software abort outstanding ADISC */
James Smart07951072007-04-25 09:51:38 -0400878 lpfc_els_abort(phba, ndlp);
dea31012005-04-17 16:05:31 -0500879
James Smart82d9a2a2006-04-15 11:53:05 -0400880 lpfc_rcv_logo(phba, ndlp, cmdiocb, ELS_CMD_LOGO);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500881 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -0500882}
883
884static uint32_t
885lpfc_rcv_padisc_adisc_issue(struct lpfc_hba * phba,
886 struct lpfc_nodelist * ndlp, void *arg,
887 uint32_t evt)
888{
889 struct lpfc_iocbq *cmdiocb;
890
891 cmdiocb = (struct lpfc_iocbq *) arg;
892
893 lpfc_rcv_padisc(phba, ndlp, cmdiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500894 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -0500895}
896
897static uint32_t
898lpfc_rcv_prlo_adisc_issue(struct lpfc_hba * phba,
899 struct lpfc_nodelist * ndlp, void *arg,
900 uint32_t evt)
901{
902 struct lpfc_iocbq *cmdiocb;
903
904 cmdiocb = (struct lpfc_iocbq *) arg;
905
906 /* Treat like rcv logo */
James Smart82d9a2a2006-04-15 11:53:05 -0400907 lpfc_rcv_logo(phba, ndlp, cmdiocb, ELS_CMD_PRLO);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500908 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -0500909}
910
911static uint32_t
912lpfc_cmpl_adisc_adisc_issue(struct lpfc_hba * phba,
913 struct lpfc_nodelist * ndlp, void *arg,
914 uint32_t evt)
915{
916 struct lpfc_iocbq *cmdiocb, *rspiocb;
917 IOCB_t *irsp;
918 ADISC *ap;
919
920 cmdiocb = (struct lpfc_iocbq *) arg;
921 rspiocb = cmdiocb->context_un.rsp_iocb;
922
923 ap = (ADISC *)lpfc_check_elscmpl_iocb(phba, cmdiocb, rspiocb);
924 irsp = &rspiocb->iocb;
925
926 if ((irsp->ulpStatus) ||
927 (!lpfc_check_adisc(phba, ndlp, &ap->nodeName, &ap->portName))) {
dea31012005-04-17 16:05:31 -0500928 /* 1 sec timeout */
929 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ);
930 spin_lock_irq(phba->host->host_lock);
931 ndlp->nlp_flag |= NLP_DELAY_TMO;
932 spin_unlock_irq(phba->host->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -0500933 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
dea31012005-04-17 16:05:31 -0500934
935 memset(&ndlp->nlp_nodename, 0, sizeof (struct lpfc_name));
936 memset(&ndlp->nlp_portname, 0, sizeof (struct lpfc_name));
937
Jamie Wellnitz5024ab12006-02-28 19:25:28 -0500938 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
James Smartde0c5b32007-04-25 09:52:27 -0400939 lpfc_nlp_set_state(phba, ndlp, NLP_STE_NPR_NODE);
dea31012005-04-17 16:05:31 -0500940 lpfc_unreg_rpi(phba, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500941 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -0500942 }
Jamie Wellnitz5024ab12006-02-28 19:25:28 -0500943
James.Smart@Emulex.Com25013222005-06-25 10:34:33 -0400944 if (ndlp->nlp_type & NLP_FCP_TARGET) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -0500945 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
James Smartde0c5b32007-04-25 09:52:27 -0400946 lpfc_nlp_set_state(phba, ndlp, NLP_STE_MAPPED_NODE);
James.Smart@Emulex.Com25013222005-06-25 10:34:33 -0400947 } else {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -0500948 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
James Smartde0c5b32007-04-25 09:52:27 -0400949 lpfc_nlp_set_state(phba, ndlp, NLP_STE_UNMAPPED_NODE);
James.Smart@Emulex.Com25013222005-06-25 10:34:33 -0400950 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500951 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -0500952}
953
954static uint32_t
955lpfc_device_rm_adisc_issue(struct lpfc_hba * phba,
956 struct lpfc_nodelist * ndlp, void *arg,
957 uint32_t evt)
958{
James Smarta0f9b482006-04-15 11:52:56 -0400959 if(ndlp->nlp_flag & NLP_NPR_2B_DISC) {
960 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
961 return ndlp->nlp_state;
962 }
963 else {
964 /* software abort outstanding ADISC */
James Smart07951072007-04-25 09:51:38 -0400965 lpfc_els_abort(phba, ndlp);
dea31012005-04-17 16:05:31 -0500966
James Smartde0c5b32007-04-25 09:52:27 -0400967 lpfc_drop_node(phba, ndlp);
James Smarta0f9b482006-04-15 11:52:56 -0400968 return NLP_STE_FREED_NODE;
969 }
dea31012005-04-17 16:05:31 -0500970}
971
972static uint32_t
973lpfc_device_recov_adisc_issue(struct lpfc_hba * phba,
974 struct lpfc_nodelist * ndlp, void *arg,
975 uint32_t evt)
976{
977 /* software abort outstanding ADISC */
James Smart07951072007-04-25 09:51:38 -0400978 lpfc_els_abort(phba, ndlp);
dea31012005-04-17 16:05:31 -0500979
Jamie Wellnitz5024ab12006-02-28 19:25:28 -0500980 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
James Smartde0c5b32007-04-25 09:52:27 -0400981 lpfc_nlp_set_state(phba, ndlp, NLP_STE_NPR_NODE);
dea31012005-04-17 16:05:31 -0500982 spin_lock_irq(phba->host->host_lock);
James Smarta0f9b482006-04-15 11:52:56 -0400983 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500984 ndlp->nlp_flag |= NLP_NPR_ADISC;
dea31012005-04-17 16:05:31 -0500985 spin_unlock_irq(phba->host->host_lock);
986
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500987 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -0500988}
989
990static uint32_t
991lpfc_rcv_plogi_reglogin_issue(struct lpfc_hba * phba,
992 struct lpfc_nodelist * ndlp, void *arg,
993 uint32_t evt)
994{
995 struct lpfc_iocbq *cmdiocb;
996
997 cmdiocb = (struct lpfc_iocbq *) arg;
998
999 lpfc_rcv_plogi(phba, ndlp, cmdiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001000 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001001}
1002
1003static uint32_t
1004lpfc_rcv_prli_reglogin_issue(struct lpfc_hba * phba,
1005 struct lpfc_nodelist * ndlp, void *arg,
1006 uint32_t evt)
1007{
1008 struct lpfc_iocbq *cmdiocb;
1009
1010 cmdiocb = (struct lpfc_iocbq *) arg;
1011
1012 lpfc_els_rsp_prli_acc(phba, cmdiocb, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001013 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001014}
1015
1016static uint32_t
1017lpfc_rcv_logo_reglogin_issue(struct lpfc_hba * phba,
1018 struct lpfc_nodelist * ndlp, void *arg,
1019 uint32_t evt)
1020{
1021 struct lpfc_iocbq *cmdiocb;
James Smart7054a602007-04-25 09:52:34 -04001022 LPFC_MBOXQ_t *mb;
1023 LPFC_MBOXQ_t *nextmb;
1024 struct lpfc_dmabuf *mp;
dea31012005-04-17 16:05:31 -05001025
1026 cmdiocb = (struct lpfc_iocbq *) arg;
1027
James Smart7054a602007-04-25 09:52:34 -04001028 /* cleanup any ndlp on mbox q waiting for reglogin cmpl */
1029 if ((mb = phba->sli.mbox_active)) {
1030 if ((mb->mb.mbxCommand == MBX_REG_LOGIN64) &&
1031 (ndlp == (struct lpfc_nodelist *) mb->context2)) {
1032 mb->context2 = NULL;
1033 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1034 }
1035 }
1036
1037 spin_lock_irq(phba->host->host_lock);
1038 list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) {
1039 if ((mb->mb.mbxCommand == MBX_REG_LOGIN64) &&
1040 (ndlp == (struct lpfc_nodelist *) mb->context2)) {
1041 mp = (struct lpfc_dmabuf *) (mb->context1);
1042 if (mp) {
1043 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1044 kfree(mp);
1045 }
1046 list_del(&mb->list);
1047 mempool_free(mb, phba->mbox_mem_pool);
1048 }
1049 }
1050 spin_unlock_irq(phba->host->host_lock);
1051
James Smart82d9a2a2006-04-15 11:53:05 -04001052 lpfc_rcv_logo(phba, ndlp, cmdiocb, ELS_CMD_LOGO);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001053 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001054}
1055
1056static uint32_t
1057lpfc_rcv_padisc_reglogin_issue(struct lpfc_hba * phba,
1058 struct lpfc_nodelist * ndlp, void *arg,
1059 uint32_t evt)
1060{
1061 struct lpfc_iocbq *cmdiocb;
1062
1063 cmdiocb = (struct lpfc_iocbq *) arg;
1064
1065 lpfc_rcv_padisc(phba, ndlp, cmdiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001066 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001067}
1068
1069static uint32_t
1070lpfc_rcv_prlo_reglogin_issue(struct lpfc_hba * phba,
1071 struct lpfc_nodelist * ndlp, void *arg,
1072 uint32_t evt)
1073{
1074 struct lpfc_iocbq *cmdiocb;
1075
1076 cmdiocb = (struct lpfc_iocbq *) arg;
James Smart82d9a2a2006-04-15 11:53:05 -04001077 lpfc_els_rsp_acc(phba, ELS_CMD_PRLO, cmdiocb, ndlp, NULL, 0);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001078 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001079}
1080
1081static uint32_t
1082lpfc_cmpl_reglogin_reglogin_issue(struct lpfc_hba * phba,
1083 struct lpfc_nodelist * ndlp,
1084 void *arg, uint32_t evt)
1085{
1086 LPFC_MBOXQ_t *pmb;
1087 MAILBOX_t *mb;
1088 uint32_t did;
1089
1090 pmb = (LPFC_MBOXQ_t *) arg;
1091 mb = &pmb->mb;
1092 did = mb->un.varWords[1];
1093 if (mb->mbxStatus) {
1094 /* RegLogin failed */
1095 lpfc_printf_log(phba,
1096 KERN_ERR,
1097 LOG_DISCOVERY,
1098 "%d:0246 RegLogin failed Data: x%x x%x x%x\n",
1099 phba->brd_no,
1100 did, mb->mbxStatus, phba->hba_state);
1101
James Smartd0e56da2006-07-06 15:49:42 -04001102 /*
1103 * If RegLogin failed due to lack of HBA resources do not
1104 * retry discovery.
1105 */
1106 if (mb->mbxStatus == MBXERR_RPI_FULL) {
1107 ndlp->nlp_prev_state = NLP_STE_UNUSED_NODE;
James Smartde0c5b32007-04-25 09:52:27 -04001108 lpfc_nlp_set_state(phba, ndlp, NLP_STE_UNUSED_NODE);
James Smartd0e56da2006-07-06 15:49:42 -04001109 return ndlp->nlp_state;
1110 }
1111
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001112 /* Put ndlp in npr list set plogi timer for 1 sec */
dea31012005-04-17 16:05:31 -05001113 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ * 1);
1114 spin_lock_irq(phba->host->host_lock);
1115 ndlp->nlp_flag |= NLP_DELAY_TMO;
1116 spin_unlock_irq(phba->host->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001117 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
dea31012005-04-17 16:05:31 -05001118
1119 lpfc_issue_els_logo(phba, ndlp, 0);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001120 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
James Smartde0c5b32007-04-25 09:52:27 -04001121 lpfc_nlp_set_state(phba, ndlp, NLP_STE_NPR_NODE);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001122 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001123 }
1124
dea31012005-04-17 16:05:31 -05001125 ndlp->nlp_rpi = mb->un.varWords[0];
dea31012005-04-17 16:05:31 -05001126
1127 /* Only if we are not a fabric nport do we issue PRLI */
1128 if (!(ndlp->nlp_type & NLP_FABRIC)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001129 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
James Smartde0c5b32007-04-25 09:52:27 -04001130 lpfc_nlp_set_state(phba, ndlp, NLP_STE_PRLI_ISSUE);
dea31012005-04-17 16:05:31 -05001131 lpfc_issue_els_prli(phba, ndlp, 0);
1132 } else {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001133 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
James Smartde0c5b32007-04-25 09:52:27 -04001134 lpfc_nlp_set_state(phba, ndlp, NLP_STE_UNMAPPED_NODE);
dea31012005-04-17 16:05:31 -05001135 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001136 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001137}
1138
1139static uint32_t
1140lpfc_device_rm_reglogin_issue(struct lpfc_hba * phba,
1141 struct lpfc_nodelist * ndlp, void *arg,
1142 uint32_t evt)
1143{
James Smarta0f9b482006-04-15 11:52:56 -04001144 if(ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1145 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
1146 return ndlp->nlp_state;
1147 }
1148 else {
James Smartde0c5b32007-04-25 09:52:27 -04001149 lpfc_drop_node(phba, ndlp);
James Smarta0f9b482006-04-15 11:52:56 -04001150 return NLP_STE_FREED_NODE;
1151 }
dea31012005-04-17 16:05:31 -05001152}
1153
1154static uint32_t
1155lpfc_device_recov_reglogin_issue(struct lpfc_hba * phba,
1156 struct lpfc_nodelist * ndlp, void *arg,
1157 uint32_t evt)
1158{
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001159 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
James Smartde0c5b32007-04-25 09:52:27 -04001160 lpfc_nlp_set_state(phba, ndlp, NLP_STE_NPR_NODE);
dea31012005-04-17 16:05:31 -05001161 spin_lock_irq(phba->host->host_lock);
James Smarta0f9b482006-04-15 11:52:56 -04001162 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
dea31012005-04-17 16:05:31 -05001163 spin_unlock_irq(phba->host->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001164 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001165}
1166
1167static uint32_t
1168lpfc_rcv_plogi_prli_issue(struct lpfc_hba * phba,
1169 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1170{
1171 struct lpfc_iocbq *cmdiocb;
1172
1173 cmdiocb = (struct lpfc_iocbq *) arg;
1174
1175 lpfc_rcv_plogi(phba, ndlp, cmdiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001176 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001177}
1178
1179static uint32_t
1180lpfc_rcv_prli_prli_issue(struct lpfc_hba * phba,
1181 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1182{
1183 struct lpfc_iocbq *cmdiocb;
1184
1185 cmdiocb = (struct lpfc_iocbq *) arg;
1186
1187 lpfc_els_rsp_prli_acc(phba, cmdiocb, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001188 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001189}
1190
1191static uint32_t
1192lpfc_rcv_logo_prli_issue(struct lpfc_hba * phba,
1193 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1194{
1195 struct lpfc_iocbq *cmdiocb;
1196
1197 cmdiocb = (struct lpfc_iocbq *) arg;
1198
1199 /* Software abort outstanding PRLI before sending acc */
James Smart07951072007-04-25 09:51:38 -04001200 lpfc_els_abort(phba, ndlp);
dea31012005-04-17 16:05:31 -05001201
James Smart82d9a2a2006-04-15 11:53:05 -04001202 lpfc_rcv_logo(phba, ndlp, cmdiocb, ELS_CMD_LOGO);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001203 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001204}
1205
1206static uint32_t
1207lpfc_rcv_padisc_prli_issue(struct lpfc_hba * phba,
1208 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1209{
1210 struct lpfc_iocbq *cmdiocb;
1211
1212 cmdiocb = (struct lpfc_iocbq *) arg;
1213
1214 lpfc_rcv_padisc(phba, ndlp, cmdiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001215 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001216}
1217
1218/* This routine is envoked when we rcv a PRLO request from a nport
1219 * we are logged into. We should send back a PRLO rsp setting the
1220 * appropriate bits.
1221 * NEXT STATE = PRLI_ISSUE
1222 */
1223static uint32_t
1224lpfc_rcv_prlo_prli_issue(struct lpfc_hba * phba,
1225 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1226{
1227 struct lpfc_iocbq *cmdiocb;
1228
1229 cmdiocb = (struct lpfc_iocbq *) arg;
James Smart82d9a2a2006-04-15 11:53:05 -04001230 lpfc_els_rsp_acc(phba, ELS_CMD_PRLO, cmdiocb, ndlp, NULL, 0);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001231 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001232}
1233
1234static uint32_t
1235lpfc_cmpl_prli_prli_issue(struct lpfc_hba * phba,
1236 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1237{
1238 struct lpfc_iocbq *cmdiocb, *rspiocb;
1239 IOCB_t *irsp;
1240 PRLI *npr;
1241
1242 cmdiocb = (struct lpfc_iocbq *) arg;
1243 rspiocb = cmdiocb->context_un.rsp_iocb;
1244 npr = (PRLI *)lpfc_check_elscmpl_iocb(phba, cmdiocb, rspiocb);
1245
1246 irsp = &rspiocb->iocb;
1247 if (irsp->ulpStatus) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001248 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
James Smartde0c5b32007-04-25 09:52:27 -04001249 lpfc_nlp_set_state(phba, ndlp, NLP_STE_UNMAPPED_NODE);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001250 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001251 }
1252
1253 /* Check out PRLI rsp */
1254 ndlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR);
1255 ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
1256 if ((npr->acceptRspCode == PRLI_REQ_EXECUTED) &&
1257 (npr->prliType == PRLI_FCP_TYPE)) {
1258 if (npr->initiatorFunc)
1259 ndlp->nlp_type |= NLP_FCP_INITIATOR;
1260 if (npr->targetFunc)
1261 ndlp->nlp_type |= NLP_FCP_TARGET;
1262 if (npr->Retry)
1263 ndlp->nlp_fcp_info |= NLP_FCP_2_DEVICE;
1264 }
1265
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001266 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
James Smartde0c5b32007-04-25 09:52:27 -04001267 lpfc_nlp_set_state(phba, ndlp, NLP_STE_MAPPED_NODE);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001268 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001269}
1270
1271/*! lpfc_device_rm_prli_issue
1272 *
1273 * \pre
1274 * \post
1275 * \param phba
1276 * \param ndlp
1277 * \param arg
1278 * \param evt
1279 * \return uint32_t
1280 *
1281 * \b Description:
1282 * This routine is envoked when we a request to remove a nport we are in the
1283 * process of PRLIing. We should software abort outstanding prli, unreg
1284 * login, send a logout. We will change node state to UNUSED_NODE, put it
1285 * on plogi list so it can be freed when LOGO completes.
1286 *
1287 */
1288static uint32_t
1289lpfc_device_rm_prli_issue(struct lpfc_hba * phba,
1290 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1291{
James Smarta0f9b482006-04-15 11:52:56 -04001292 if(ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1293 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
1294 return ndlp->nlp_state;
1295 }
1296 else {
1297 /* software abort outstanding PLOGI */
James Smart07951072007-04-25 09:51:38 -04001298 lpfc_els_abort(phba, ndlp);
dea31012005-04-17 16:05:31 -05001299
James Smartde0c5b32007-04-25 09:52:27 -04001300 lpfc_drop_node(phba, ndlp);
James Smarta0f9b482006-04-15 11:52:56 -04001301 return NLP_STE_FREED_NODE;
1302 }
dea31012005-04-17 16:05:31 -05001303}
1304
1305
1306/*! lpfc_device_recov_prli_issue
1307 *
1308 * \pre
1309 * \post
1310 * \param phba
1311 * \param ndlp
1312 * \param arg
1313 * \param evt
1314 * \return uint32_t
1315 *
1316 * \b Description:
1317 * The routine is envoked when the state of a device is unknown, like
1318 * during a link down. We should remove the nodelist entry from the
1319 * unmapped list, issue a UNREG_LOGIN, do a software abort of the
1320 * outstanding PRLI command, then free the node entry.
1321 */
1322static uint32_t
1323lpfc_device_recov_prli_issue(struct lpfc_hba * phba,
1324 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1325{
1326 /* software abort outstanding PRLI */
James Smart07951072007-04-25 09:51:38 -04001327 lpfc_els_abort(phba, ndlp);
dea31012005-04-17 16:05:31 -05001328
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001329 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
James Smartde0c5b32007-04-25 09:52:27 -04001330 lpfc_nlp_set_state(phba, ndlp, NLP_STE_NPR_NODE);
dea31012005-04-17 16:05:31 -05001331 spin_lock_irq(phba->host->host_lock);
James Smarta0f9b482006-04-15 11:52:56 -04001332 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
dea31012005-04-17 16:05:31 -05001333 spin_unlock_irq(phba->host->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001334 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001335}
1336
1337static uint32_t
1338lpfc_rcv_plogi_unmap_node(struct lpfc_hba * phba,
1339 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1340{
1341 struct lpfc_iocbq *cmdiocb;
1342
1343 cmdiocb = (struct lpfc_iocbq *) arg;
1344
1345 lpfc_rcv_plogi(phba, ndlp, cmdiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001346 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001347}
1348
1349static uint32_t
1350lpfc_rcv_prli_unmap_node(struct lpfc_hba * phba,
1351 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1352{
1353 struct lpfc_iocbq *cmdiocb;
1354
1355 cmdiocb = (struct lpfc_iocbq *) arg;
1356
1357 lpfc_rcv_prli(phba, ndlp, cmdiocb);
1358 lpfc_els_rsp_prli_acc(phba, cmdiocb, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001359 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001360}
1361
1362static uint32_t
1363lpfc_rcv_logo_unmap_node(struct lpfc_hba * phba,
1364 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1365{
1366 struct lpfc_iocbq *cmdiocb;
1367
1368 cmdiocb = (struct lpfc_iocbq *) arg;
1369
James Smart82d9a2a2006-04-15 11:53:05 -04001370 lpfc_rcv_logo(phba, ndlp, cmdiocb, ELS_CMD_LOGO);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001371 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001372}
1373
1374static uint32_t
1375lpfc_rcv_padisc_unmap_node(struct lpfc_hba * phba,
1376 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1377{
1378 struct lpfc_iocbq *cmdiocb;
1379
1380 cmdiocb = (struct lpfc_iocbq *) arg;
1381
1382 lpfc_rcv_padisc(phba, ndlp, cmdiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001383 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001384}
1385
1386static uint32_t
1387lpfc_rcv_prlo_unmap_node(struct lpfc_hba * phba,
1388 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1389{
1390 struct lpfc_iocbq *cmdiocb;
1391
1392 cmdiocb = (struct lpfc_iocbq *) arg;
1393
James Smart82d9a2a2006-04-15 11:53:05 -04001394 lpfc_els_rsp_acc(phba, ELS_CMD_PRLO, cmdiocb, ndlp, NULL, 0);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001395 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001396}
1397
1398static uint32_t
1399lpfc_device_recov_unmap_node(struct lpfc_hba * phba,
1400 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1401{
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001402 ndlp->nlp_prev_state = NLP_STE_UNMAPPED_NODE;
James Smartde0c5b32007-04-25 09:52:27 -04001403 lpfc_nlp_set_state(phba, ndlp, NLP_STE_NPR_NODE);
James Smarta0f9b482006-04-15 11:52:56 -04001404 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
dea31012005-04-17 16:05:31 -05001405 lpfc_disc_set_adisc(phba, ndlp);
1406
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001407 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001408}
1409
1410static uint32_t
1411lpfc_rcv_plogi_mapped_node(struct lpfc_hba * phba,
1412 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1413{
1414 struct lpfc_iocbq *cmdiocb;
1415
1416 cmdiocb = (struct lpfc_iocbq *) arg;
1417
1418 lpfc_rcv_plogi(phba, ndlp, cmdiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001419 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001420}
1421
1422static uint32_t
1423lpfc_rcv_prli_mapped_node(struct lpfc_hba * phba,
1424 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1425{
1426 struct lpfc_iocbq *cmdiocb;
1427
1428 cmdiocb = (struct lpfc_iocbq *) arg;
1429
1430 lpfc_els_rsp_prli_acc(phba, cmdiocb, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001431 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001432}
1433
1434static uint32_t
1435lpfc_rcv_logo_mapped_node(struct lpfc_hba * phba,
1436 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1437{
1438 struct lpfc_iocbq *cmdiocb;
1439
1440 cmdiocb = (struct lpfc_iocbq *) arg;
1441
James Smart82d9a2a2006-04-15 11:53:05 -04001442 lpfc_rcv_logo(phba, ndlp, cmdiocb, ELS_CMD_LOGO);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001443 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001444}
1445
1446static uint32_t
1447lpfc_rcv_padisc_mapped_node(struct lpfc_hba * phba,
1448 struct lpfc_nodelist * ndlp, void *arg,
1449 uint32_t evt)
1450{
1451 struct lpfc_iocbq *cmdiocb;
1452
1453 cmdiocb = (struct lpfc_iocbq *) arg;
1454
1455 lpfc_rcv_padisc(phba, ndlp, cmdiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001456 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001457}
1458
1459static uint32_t
1460lpfc_rcv_prlo_mapped_node(struct lpfc_hba * phba,
1461 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1462{
1463 struct lpfc_iocbq *cmdiocb;
1464
1465 cmdiocb = (struct lpfc_iocbq *) arg;
1466
1467 /* flush the target */
1468 spin_lock_irq(phba->host->host_lock);
1469 lpfc_sli_abort_iocb(phba, &phba->sli.ring[phba->sli.fcp_ring],
1470 ndlp->nlp_sid, 0, 0, LPFC_CTX_TGT);
1471 spin_unlock_irq(phba->host->host_lock);
1472
1473 /* Treat like rcv logo */
James Smart82d9a2a2006-04-15 11:53:05 -04001474 lpfc_rcv_logo(phba, ndlp, cmdiocb, ELS_CMD_PRLO);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001475 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001476}
1477
1478static uint32_t
1479lpfc_device_recov_mapped_node(struct lpfc_hba * phba,
1480 struct lpfc_nodelist * ndlp, void *arg,
1481 uint32_t evt)
1482{
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001483 ndlp->nlp_prev_state = NLP_STE_MAPPED_NODE;
James Smartde0c5b32007-04-25 09:52:27 -04001484 lpfc_nlp_set_state(phba, ndlp, NLP_STE_NPR_NODE);
dea31012005-04-17 16:05:31 -05001485 spin_lock_irq(phba->host->host_lock);
James Smarta0f9b482006-04-15 11:52:56 -04001486 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
dea31012005-04-17 16:05:31 -05001487 spin_unlock_irq(phba->host->host_lock);
1488 lpfc_disc_set_adisc(phba, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001489 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001490}
1491
1492static uint32_t
1493lpfc_rcv_plogi_npr_node(struct lpfc_hba * phba,
1494 struct lpfc_nodelist * ndlp, void *arg,
1495 uint32_t evt)
1496{
1497 struct lpfc_iocbq *cmdiocb;
1498
1499 cmdiocb = (struct lpfc_iocbq *) arg;
1500
1501 /* Ignore PLOGI if we have an outstanding LOGO */
1502 if (ndlp->nlp_flag & NLP_LOGO_SND) {
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001503 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001504 }
1505
1506 if (lpfc_rcv_plogi(phba, ndlp, cmdiocb)) {
1507 spin_lock_irq(phba->host->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05001508 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
dea31012005-04-17 16:05:31 -05001509 spin_unlock_irq(phba->host->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001510 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001511 }
1512
1513 /* send PLOGI immediately, move to PLOGI issue state */
1514 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
James Smart488d1462006-03-07 15:02:37 -05001515 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
James Smartde0c5b32007-04-25 09:52:27 -04001516 lpfc_nlp_set_state(phba, ndlp, NLP_STE_PLOGI_ISSUE);
James Smart488d1462006-03-07 15:02:37 -05001517 lpfc_issue_els_plogi(phba, ndlp->nlp_DID, 0);
dea31012005-04-17 16:05:31 -05001518 }
James Smart488d1462006-03-07 15:02:37 -05001519
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001520 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001521}
1522
1523static uint32_t
1524lpfc_rcv_prli_npr_node(struct lpfc_hba * phba,
1525 struct lpfc_nodelist * ndlp, void *arg,
1526 uint32_t evt)
1527{
1528 struct lpfc_iocbq *cmdiocb;
1529 struct ls_rjt stat;
1530
1531 cmdiocb = (struct lpfc_iocbq *) arg;
1532
1533 memset(&stat, 0, sizeof (struct ls_rjt));
1534 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
1535 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
1536 lpfc_els_rsp_reject(phba, stat.un.lsRjtError, cmdiocb, ndlp);
1537
1538 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
1539 if (ndlp->nlp_flag & NLP_NPR_ADISC) {
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001540 spin_lock_irq(phba->host->host_lock);
1541 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
1542 spin_unlock_irq(phba->host->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001543 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
James Smartde0c5b32007-04-25 09:52:27 -04001544 lpfc_nlp_set_state(phba, ndlp, NLP_STE_ADISC_ISSUE);
dea31012005-04-17 16:05:31 -05001545 lpfc_issue_els_adisc(phba, ndlp, 0);
1546 } else {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001547 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
James Smartde0c5b32007-04-25 09:52:27 -04001548 lpfc_nlp_set_state(phba, ndlp, NLP_STE_PLOGI_ISSUE);
James Smart488d1462006-03-07 15:02:37 -05001549 lpfc_issue_els_plogi(phba, ndlp->nlp_DID, 0);
dea31012005-04-17 16:05:31 -05001550 }
1551 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001552 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001553}
1554
1555static uint32_t
1556lpfc_rcv_logo_npr_node(struct lpfc_hba * phba,
1557 struct lpfc_nodelist * ndlp, void *arg,
1558 uint32_t evt)
1559{
1560 struct lpfc_iocbq *cmdiocb;
1561
1562 cmdiocb = (struct lpfc_iocbq *) arg;
1563
James Smart82d9a2a2006-04-15 11:53:05 -04001564 lpfc_rcv_logo(phba, ndlp, cmdiocb, ELS_CMD_LOGO);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001565 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001566}
1567
1568static uint32_t
1569lpfc_rcv_padisc_npr_node(struct lpfc_hba * phba,
1570 struct lpfc_nodelist * ndlp, void *arg,
1571 uint32_t evt)
1572{
1573 struct lpfc_iocbq *cmdiocb;
1574
1575 cmdiocb = (struct lpfc_iocbq *) arg;
1576
1577 lpfc_rcv_padisc(phba, ndlp, cmdiocb);
1578
James Smart33ccf8d2006-08-17 11:57:58 -04001579 /*
1580 * Do not start discovery if discovery is about to start
1581 * or discovery in progress for this node. Starting discovery
1582 * here will affect the counting of discovery threads.
1583 */
James Smart2fb9bd82006-12-02 13:33:57 -05001584 if (!(ndlp->nlp_flag & NLP_DELAY_TMO) &&
1585 !(ndlp->nlp_flag & NLP_NPR_2B_DISC)){
dea31012005-04-17 16:05:31 -05001586 if (ndlp->nlp_flag & NLP_NPR_ADISC) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001587 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
James Smartde0c5b32007-04-25 09:52:27 -04001588 lpfc_nlp_set_state(phba, ndlp, NLP_STE_ADISC_ISSUE);
dea31012005-04-17 16:05:31 -05001589 lpfc_issue_els_adisc(phba, ndlp, 0);
1590 } else {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001591 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
James Smartde0c5b32007-04-25 09:52:27 -04001592 lpfc_nlp_set_state(phba, ndlp, NLP_STE_PLOGI_ISSUE);
James Smart488d1462006-03-07 15:02:37 -05001593 lpfc_issue_els_plogi(phba, ndlp->nlp_DID, 0);
dea31012005-04-17 16:05:31 -05001594 }
1595 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001596 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001597}
1598
1599static uint32_t
1600lpfc_rcv_prlo_npr_node(struct lpfc_hba * phba,
1601 struct lpfc_nodelist * ndlp, void *arg,
1602 uint32_t evt)
1603{
1604 struct lpfc_iocbq *cmdiocb;
1605
1606 cmdiocb = (struct lpfc_iocbq *) arg;
1607
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001608 spin_lock_irq(phba->host->host_lock);
1609 ndlp->nlp_flag |= NLP_LOGO_ACC;
1610 spin_unlock_irq(phba->host->host_lock);
1611
dea31012005-04-17 16:05:31 -05001612 lpfc_els_rsp_acc(phba, ELS_CMD_ACC, cmdiocb, ndlp, NULL, 0);
1613
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001614 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
1615 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ * 1);
1616 spin_lock_irq(phba->host->host_lock);
1617 ndlp->nlp_flag |= NLP_DELAY_TMO;
1618 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
1619 spin_unlock_irq(phba->host->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001620 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001621 } else {
1622 spin_lock_irq(phba->host->host_lock);
1623 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
1624 spin_unlock_irq(phba->host->host_lock);
dea31012005-04-17 16:05:31 -05001625 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001626 return ndlp->nlp_state;
1627}
dea31012005-04-17 16:05:31 -05001628
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001629static uint32_t
1630lpfc_cmpl_plogi_npr_node(struct lpfc_hba * phba,
1631 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1632{
1633 struct lpfc_iocbq *cmdiocb, *rspiocb;
James Smarta0f9b482006-04-15 11:52:56 -04001634 IOCB_t *irsp;
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001635
1636 cmdiocb = (struct lpfc_iocbq *) arg;
1637 rspiocb = cmdiocb->context_un.rsp_iocb;
James Smarta0f9b482006-04-15 11:52:56 -04001638
1639 irsp = &rspiocb->iocb;
1640 if (irsp->ulpStatus) {
James Smartde0c5b32007-04-25 09:52:27 -04001641 lpfc_drop_node(phba, ndlp);
James Smarta0f9b482006-04-15 11:52:56 -04001642 return NLP_STE_FREED_NODE;
1643 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001644 return ndlp->nlp_state;
1645}
1646
1647static uint32_t
1648lpfc_cmpl_prli_npr_node(struct lpfc_hba * phba,
1649 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1650{
1651 struct lpfc_iocbq *cmdiocb, *rspiocb;
James Smarta0f9b482006-04-15 11:52:56 -04001652 IOCB_t *irsp;
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001653
1654 cmdiocb = (struct lpfc_iocbq *) arg;
1655 rspiocb = cmdiocb->context_un.rsp_iocb;
James Smarta0f9b482006-04-15 11:52:56 -04001656
1657 irsp = &rspiocb->iocb;
1658 if (irsp->ulpStatus && (ndlp->nlp_flag & NLP_NODEV_REMOVE)) {
James Smartde0c5b32007-04-25 09:52:27 -04001659 lpfc_drop_node(phba, ndlp);
James Smarta0f9b482006-04-15 11:52:56 -04001660 return NLP_STE_FREED_NODE;
1661 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001662 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001663}
1664
1665static uint32_t
1666lpfc_cmpl_logo_npr_node(struct lpfc_hba * phba,
1667 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1668{
1669 lpfc_unreg_rpi(phba, ndlp);
1670 /* This routine does nothing, just return the current state */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001671 return ndlp->nlp_state;
1672}
1673
1674static uint32_t
1675lpfc_cmpl_adisc_npr_node(struct lpfc_hba * phba,
1676 struct lpfc_nodelist * ndlp, void *arg,
1677 uint32_t evt)
1678{
1679 struct lpfc_iocbq *cmdiocb, *rspiocb;
James Smarta0f9b482006-04-15 11:52:56 -04001680 IOCB_t *irsp;
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001681
1682 cmdiocb = (struct lpfc_iocbq *) arg;
1683 rspiocb = cmdiocb->context_un.rsp_iocb;
James Smarta0f9b482006-04-15 11:52:56 -04001684
1685 irsp = &rspiocb->iocb;
1686 if (irsp->ulpStatus && (ndlp->nlp_flag & NLP_NODEV_REMOVE)) {
James Smartde0c5b32007-04-25 09:52:27 -04001687 lpfc_drop_node(phba, ndlp);
James Smarta0f9b482006-04-15 11:52:56 -04001688 return NLP_STE_FREED_NODE;
1689 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001690 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001691}
1692
1693static uint32_t
1694lpfc_cmpl_reglogin_npr_node(struct lpfc_hba * phba,
1695 struct lpfc_nodelist * ndlp, void *arg,
1696 uint32_t evt)
1697{
1698 LPFC_MBOXQ_t *pmb;
1699 MAILBOX_t *mb;
1700
1701 pmb = (LPFC_MBOXQ_t *) arg;
1702 mb = &pmb->mb;
1703
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001704 if (!mb->mbxStatus)
1705 ndlp->nlp_rpi = mb->un.varWords[0];
James Smarta0f9b482006-04-15 11:52:56 -04001706 else {
1707 if (ndlp->nlp_flag & NLP_NODEV_REMOVE) {
James Smartde0c5b32007-04-25 09:52:27 -04001708 lpfc_drop_node(phba, ndlp);
James Smarta0f9b482006-04-15 11:52:56 -04001709 return NLP_STE_FREED_NODE;
1710 }
1711 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001712 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001713}
1714
1715static uint32_t
1716lpfc_device_rm_npr_node(struct lpfc_hba * phba,
1717 struct lpfc_nodelist * ndlp, void *arg,
1718 uint32_t evt)
1719{
James Smarta0f9b482006-04-15 11:52:56 -04001720 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1721 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
1722 return ndlp->nlp_state;
1723 }
James Smartde0c5b32007-04-25 09:52:27 -04001724 lpfc_drop_node(phba, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001725 return NLP_STE_FREED_NODE;
dea31012005-04-17 16:05:31 -05001726}
1727
1728static uint32_t
1729lpfc_device_recov_npr_node(struct lpfc_hba * phba,
1730 struct lpfc_nodelist * ndlp, void *arg,
1731 uint32_t evt)
1732{
1733 spin_lock_irq(phba->host->host_lock);
James Smarta0f9b482006-04-15 11:52:56 -04001734 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
dea31012005-04-17 16:05:31 -05001735 spin_unlock_irq(phba->host->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05001736 if (ndlp->nlp_flag & NLP_DELAY_TMO) {
1737 lpfc_cancel_retry_delay_tmo(phba, ndlp);
1738 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001739 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001740}
1741
1742
1743/* This next section defines the NPort Discovery State Machine */
1744
1745/* There are 4 different double linked lists nodelist entries can reside on.
1746 * The plogi list and adisc list are used when Link Up discovery or RSCN
1747 * processing is needed. Each list holds the nodes that we will send PLOGI
1748 * or ADISC on. These lists will keep track of what nodes will be effected
1749 * by an RSCN, or a Link Up (Typically, all nodes are effected on Link Up).
1750 * The unmapped_list will contain all nodes that we have successfully logged
1751 * into at the Fibre Channel level. The mapped_list will contain all nodes
1752 * that are mapped FCP targets.
1753 */
1754/*
1755 * The bind list is a list of undiscovered (potentially non-existent) nodes
1756 * that we have saved binding information on. This information is used when
1757 * nodes transition from the unmapped to the mapped list.
1758 */
1759/* For UNUSED_NODE state, the node has just been allocated .
1760 * For PLOGI_ISSUE and REG_LOGIN_ISSUE, the node is on
1761 * the PLOGI list. For REG_LOGIN_COMPL, the node is taken off the PLOGI list
1762 * and put on the unmapped list. For ADISC processing, the node is taken off
1763 * the ADISC list and placed on either the mapped or unmapped list (depending
1764 * on its previous state). Once on the unmapped list, a PRLI is issued and the
1765 * state changed to PRLI_ISSUE. When the PRLI completion occurs, the state is
1766 * changed to UNMAPPED_NODE. If the completion indicates a mapped
1767 * node, the node is taken off the unmapped list. The binding list is checked
1768 * for a valid binding, or a binding is automatically assigned. If binding
1769 * assignment is unsuccessful, the node is left on the unmapped list. If
1770 * binding assignment is successful, the associated binding list entry (if
1771 * any) is removed, and the node is placed on the mapped list.
1772 */
1773/*
1774 * For a Link Down, all nodes on the ADISC, PLOGI, unmapped or mapped
James Smartc01f3202006-08-18 17:47:08 -04001775 * lists will receive a DEVICE_RECOVERY event. If the linkdown or devloss timers
dea31012005-04-17 16:05:31 -05001776 * expire, all effected nodes will receive a DEVICE_RM event.
1777 */
1778/*
1779 * For a Link Up or RSCN, all nodes will move from the mapped / unmapped lists
1780 * to either the ADISC or PLOGI list. After a Nameserver query or ALPA loopmap
1781 * check, additional nodes may be added or removed (via DEVICE_RM) to / from
1782 * the PLOGI or ADISC lists. Once the PLOGI and ADISC lists are populated,
1783 * we will first process the ADISC list. 32 entries are processed initially and
1784 * ADISC is initited for each one. Completions / Events for each node are
1785 * funnelled thru the state machine. As each node finishes ADISC processing, it
1786 * starts ADISC for any nodes waiting for ADISC processing. If no nodes are
1787 * waiting, and the ADISC list count is identically 0, then we are done. For
1788 * Link Up discovery, since all nodes on the PLOGI list are UNREG_LOGIN'ed, we
1789 * can issue a CLEAR_LA and reenable Link Events. Next we will process the PLOGI
1790 * list. 32 entries are processed initially and PLOGI is initited for each one.
1791 * Completions / Events for each node are funnelled thru the state machine. As
1792 * each node finishes PLOGI processing, it starts PLOGI for any nodes waiting
1793 * for PLOGI processing. If no nodes are waiting, and the PLOGI list count is
1794 * indentically 0, then we are done. We have now completed discovery / RSCN
1795 * handling. Upon completion, ALL nodes should be on either the mapped or
1796 * unmapped lists.
1797 */
1798
1799static uint32_t (*lpfc_disc_action[NLP_STE_MAX_STATE * NLP_EVT_MAX_EVENT])
1800 (struct lpfc_hba *, struct lpfc_nodelist *, void *, uint32_t) = {
1801 /* Action routine Event Current State */
1802 lpfc_rcv_plogi_unused_node, /* RCV_PLOGI UNUSED_NODE */
1803 lpfc_rcv_els_unused_node, /* RCV_PRLI */
1804 lpfc_rcv_logo_unused_node, /* RCV_LOGO */
1805 lpfc_rcv_els_unused_node, /* RCV_ADISC */
1806 lpfc_rcv_els_unused_node, /* RCV_PDISC */
1807 lpfc_rcv_els_unused_node, /* RCV_PRLO */
1808 lpfc_disc_illegal, /* CMPL_PLOGI */
1809 lpfc_disc_illegal, /* CMPL_PRLI */
1810 lpfc_cmpl_logo_unused_node, /* CMPL_LOGO */
1811 lpfc_disc_illegal, /* CMPL_ADISC */
1812 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
1813 lpfc_device_rm_unused_node, /* DEVICE_RM */
1814 lpfc_disc_illegal, /* DEVICE_RECOVERY */
1815
1816 lpfc_rcv_plogi_plogi_issue, /* RCV_PLOGI PLOGI_ISSUE */
1817 lpfc_rcv_els_plogi_issue, /* RCV_PRLI */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001818 lpfc_rcv_logo_plogi_issue, /* RCV_LOGO */
dea31012005-04-17 16:05:31 -05001819 lpfc_rcv_els_plogi_issue, /* RCV_ADISC */
1820 lpfc_rcv_els_plogi_issue, /* RCV_PDISC */
1821 lpfc_rcv_els_plogi_issue, /* RCV_PRLO */
1822 lpfc_cmpl_plogi_plogi_issue, /* CMPL_PLOGI */
1823 lpfc_disc_illegal, /* CMPL_PRLI */
1824 lpfc_disc_illegal, /* CMPL_LOGO */
1825 lpfc_disc_illegal, /* CMPL_ADISC */
1826 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
1827 lpfc_device_rm_plogi_issue, /* DEVICE_RM */
1828 lpfc_device_recov_plogi_issue, /* DEVICE_RECOVERY */
1829
1830 lpfc_rcv_plogi_adisc_issue, /* RCV_PLOGI ADISC_ISSUE */
1831 lpfc_rcv_prli_adisc_issue, /* RCV_PRLI */
1832 lpfc_rcv_logo_adisc_issue, /* RCV_LOGO */
1833 lpfc_rcv_padisc_adisc_issue, /* RCV_ADISC */
1834 lpfc_rcv_padisc_adisc_issue, /* RCV_PDISC */
1835 lpfc_rcv_prlo_adisc_issue, /* RCV_PRLO */
1836 lpfc_disc_illegal, /* CMPL_PLOGI */
1837 lpfc_disc_illegal, /* CMPL_PRLI */
1838 lpfc_disc_illegal, /* CMPL_LOGO */
1839 lpfc_cmpl_adisc_adisc_issue, /* CMPL_ADISC */
1840 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
1841 lpfc_device_rm_adisc_issue, /* DEVICE_RM */
1842 lpfc_device_recov_adisc_issue, /* DEVICE_RECOVERY */
1843
1844 lpfc_rcv_plogi_reglogin_issue, /* RCV_PLOGI REG_LOGIN_ISSUE */
1845 lpfc_rcv_prli_reglogin_issue, /* RCV_PLOGI */
1846 lpfc_rcv_logo_reglogin_issue, /* RCV_LOGO */
1847 lpfc_rcv_padisc_reglogin_issue, /* RCV_ADISC */
1848 lpfc_rcv_padisc_reglogin_issue, /* RCV_PDISC */
1849 lpfc_rcv_prlo_reglogin_issue, /* RCV_PRLO */
1850 lpfc_disc_illegal, /* CMPL_PLOGI */
1851 lpfc_disc_illegal, /* CMPL_PRLI */
1852 lpfc_disc_illegal, /* CMPL_LOGO */
1853 lpfc_disc_illegal, /* CMPL_ADISC */
1854 lpfc_cmpl_reglogin_reglogin_issue,/* CMPL_REG_LOGIN */
1855 lpfc_device_rm_reglogin_issue, /* DEVICE_RM */
1856 lpfc_device_recov_reglogin_issue,/* DEVICE_RECOVERY */
1857
1858 lpfc_rcv_plogi_prli_issue, /* RCV_PLOGI PRLI_ISSUE */
1859 lpfc_rcv_prli_prli_issue, /* RCV_PRLI */
1860 lpfc_rcv_logo_prli_issue, /* RCV_LOGO */
1861 lpfc_rcv_padisc_prli_issue, /* RCV_ADISC */
1862 lpfc_rcv_padisc_prli_issue, /* RCV_PDISC */
1863 lpfc_rcv_prlo_prli_issue, /* RCV_PRLO */
1864 lpfc_disc_illegal, /* CMPL_PLOGI */
1865 lpfc_cmpl_prli_prli_issue, /* CMPL_PRLI */
1866 lpfc_disc_illegal, /* CMPL_LOGO */
1867 lpfc_disc_illegal, /* CMPL_ADISC */
1868 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
1869 lpfc_device_rm_prli_issue, /* DEVICE_RM */
1870 lpfc_device_recov_prli_issue, /* DEVICE_RECOVERY */
1871
1872 lpfc_rcv_plogi_unmap_node, /* RCV_PLOGI UNMAPPED_NODE */
1873 lpfc_rcv_prli_unmap_node, /* RCV_PRLI */
1874 lpfc_rcv_logo_unmap_node, /* RCV_LOGO */
1875 lpfc_rcv_padisc_unmap_node, /* RCV_ADISC */
1876 lpfc_rcv_padisc_unmap_node, /* RCV_PDISC */
1877 lpfc_rcv_prlo_unmap_node, /* RCV_PRLO */
1878 lpfc_disc_illegal, /* CMPL_PLOGI */
1879 lpfc_disc_illegal, /* CMPL_PRLI */
1880 lpfc_disc_illegal, /* CMPL_LOGO */
1881 lpfc_disc_illegal, /* CMPL_ADISC */
1882 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
1883 lpfc_disc_illegal, /* DEVICE_RM */
1884 lpfc_device_recov_unmap_node, /* DEVICE_RECOVERY */
1885
1886 lpfc_rcv_plogi_mapped_node, /* RCV_PLOGI MAPPED_NODE */
1887 lpfc_rcv_prli_mapped_node, /* RCV_PRLI */
1888 lpfc_rcv_logo_mapped_node, /* RCV_LOGO */
1889 lpfc_rcv_padisc_mapped_node, /* RCV_ADISC */
1890 lpfc_rcv_padisc_mapped_node, /* RCV_PDISC */
1891 lpfc_rcv_prlo_mapped_node, /* RCV_PRLO */
1892 lpfc_disc_illegal, /* CMPL_PLOGI */
1893 lpfc_disc_illegal, /* CMPL_PRLI */
1894 lpfc_disc_illegal, /* CMPL_LOGO */
1895 lpfc_disc_illegal, /* CMPL_ADISC */
1896 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
1897 lpfc_disc_illegal, /* DEVICE_RM */
1898 lpfc_device_recov_mapped_node, /* DEVICE_RECOVERY */
1899
1900 lpfc_rcv_plogi_npr_node, /* RCV_PLOGI NPR_NODE */
1901 lpfc_rcv_prli_npr_node, /* RCV_PRLI */
1902 lpfc_rcv_logo_npr_node, /* RCV_LOGO */
1903 lpfc_rcv_padisc_npr_node, /* RCV_ADISC */
1904 lpfc_rcv_padisc_npr_node, /* RCV_PDISC */
1905 lpfc_rcv_prlo_npr_node, /* RCV_PRLO */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001906 lpfc_cmpl_plogi_npr_node, /* CMPL_PLOGI */
1907 lpfc_cmpl_prli_npr_node, /* CMPL_PRLI */
dea31012005-04-17 16:05:31 -05001908 lpfc_cmpl_logo_npr_node, /* CMPL_LOGO */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001909 lpfc_cmpl_adisc_npr_node, /* CMPL_ADISC */
dea31012005-04-17 16:05:31 -05001910 lpfc_cmpl_reglogin_npr_node, /* CMPL_REG_LOGIN */
1911 lpfc_device_rm_npr_node, /* DEVICE_RM */
1912 lpfc_device_recov_npr_node, /* DEVICE_RECOVERY */
1913};
1914
1915int
1916lpfc_disc_state_machine(struct lpfc_hba * phba,
1917 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1918{
1919 uint32_t cur_state, rc;
1920 uint32_t(*func) (struct lpfc_hba *, struct lpfc_nodelist *, void *,
1921 uint32_t);
1922
1923 ndlp->nlp_disc_refcnt++;
1924 cur_state = ndlp->nlp_state;
1925
1926 /* DSM in event <evt> on NPort <nlp_DID> in state <cur_state> */
1927 lpfc_printf_log(phba,
1928 KERN_INFO,
1929 LOG_DISCOVERY,
1930 "%d:0211 DSM in event x%x on NPort x%x in state %d "
1931 "Data: x%x\n",
1932 phba->brd_no,
1933 evt, ndlp->nlp_DID, cur_state, ndlp->nlp_flag);
1934
1935 func = lpfc_disc_action[(cur_state * NLP_EVT_MAX_EVENT) + evt];
1936 rc = (func) (phba, ndlp, arg, evt);
1937
1938 /* DSM out state <rc> on NPort <nlp_DID> */
1939 lpfc_printf_log(phba,
1940 KERN_INFO,
1941 LOG_DISCOVERY,
1942 "%d:0212 DSM out state %d on NPort x%x Data: x%x\n",
1943 phba->brd_no,
1944 rc, ndlp->nlp_DID, ndlp->nlp_flag);
1945
1946 ndlp->nlp_disc_refcnt--;
1947
1948 /* Check to see if ndlp removal is deferred */
1949 if ((ndlp->nlp_disc_refcnt == 0)
1950 && (ndlp->nlp_flag & NLP_DELAY_REMOVE)) {
1951 spin_lock_irq(phba->host->host_lock);
1952 ndlp->nlp_flag &= ~NLP_DELAY_REMOVE;
1953 spin_unlock_irq(phba->host->host_lock);
1954 lpfc_nlp_remove(phba, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001955 return NLP_STE_FREED_NODE;
dea31012005-04-17 16:05:31 -05001956 }
1957 if (rc == NLP_STE_FREED_NODE)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001958 return NLP_STE_FREED_NODE;
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001959 return rc;
dea31012005-04-17 16:05:31 -05001960}