blob: dba11d94d27d717963c56f8bec3372fd492aabc5 [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
171lpfc_els_abort(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp,
172 int send_abts)
173{
174 struct lpfc_sli *psli;
175 struct lpfc_sli_ring *pring;
176 struct lpfc_iocbq *iocb, *next_iocb;
177 IOCB_t *icmd;
178 int found = 0;
179
180 /* Abort outstanding I/O on NPort <nlp_DID> */
181 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
182 "%d:0201 Abort outstanding I/O on NPort x%x "
183 "Data: x%x x%x x%x\n",
184 phba->brd_no, ndlp->nlp_DID, ndlp->nlp_flag,
185 ndlp->nlp_state, ndlp->nlp_rpi);
186
187 psli = &phba->sli;
188 pring = &psli->ring[LPFC_ELS_RING];
189
190 /* First check the txq */
191 do {
192 found = 0;
193 spin_lock_irq(phba->host->host_lock);
194 list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
195 /* Check to see if iocb matches the nport we are looking
196 for */
197 if ((lpfc_check_sli_ndlp(phba, pring, iocb, ndlp))) {
198 found = 1;
199 /* It matches, so deque and call compl with an
200 error */
201 list_del(&iocb->list);
202 pring->txq_cnt--;
203 if (iocb->iocb_cmpl) {
204 icmd = &iocb->iocb;
205 icmd->ulpStatus = IOSTAT_LOCAL_REJECT;
206 icmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
207 spin_unlock_irq(phba->host->host_lock);
208 (iocb->iocb_cmpl) (phba, iocb, iocb);
209 spin_lock_irq(phba->host->host_lock);
James Bottomley604a3e32005-10-29 10:28:33 -0500210 } else
211 lpfc_sli_release_iocbq(phba, iocb);
dea31012005-04-17 16:05:31 -0500212 break;
213 }
214 }
215 spin_unlock_irq(phba->host->host_lock);
216 } while (found);
217
218 /* Everything on txcmplq will be returned by firmware
219 * with a no rpi / linkdown / abort error. For ring 0,
220 * ELS discovery, we want to get rid of it right here.
221 */
222 /* Next check the txcmplq */
223 do {
224 found = 0;
225 spin_lock_irq(phba->host->host_lock);
226 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq,
227 list) {
228 /* Check to see if iocb matches the nport we are looking
229 for */
230 if ((lpfc_check_sli_ndlp (phba, pring, iocb, ndlp))) {
231 found = 1;
232 /* It matches, so deque and call compl with an
233 error */
234 list_del(&iocb->list);
235 pring->txcmplq_cnt--;
236
237 icmd = &iocb->iocb;
238 /* If the driver is completing an ELS
239 * command early, flush it out of the firmware.
240 */
241 if (send_abts &&
242 (icmd->ulpCommand == CMD_ELS_REQUEST64_CR) &&
243 (icmd->un.elsreq64.bdl.ulpIoTag32)) {
244 lpfc_sli_issue_abort_iotag32(phba,
245 pring, iocb);
246 }
247 if (iocb->iocb_cmpl) {
248 icmd->ulpStatus = IOSTAT_LOCAL_REJECT;
249 icmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
250 spin_unlock_irq(phba->host->host_lock);
251 (iocb->iocb_cmpl) (phba, iocb, iocb);
252 spin_lock_irq(phba->host->host_lock);
James Bottomley604a3e32005-10-29 10:28:33 -0500253 } else
254 lpfc_sli_release_iocbq(phba, iocb);
dea31012005-04-17 16:05:31 -0500255 break;
256 }
257 }
258 spin_unlock_irq(phba->host->host_lock);
259 } while(found);
260
261 /* If we are delaying issuing an ELS command, cancel it */
262 if (ndlp->nlp_flag & NLP_DELAY_TMO) {
263 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -0500264 ndlp->nlp_last_elscmd = 0;
dea31012005-04-17 16:05:31 -0500265 del_timer_sync(&ndlp->nlp_delayfunc);
266 if (!list_empty(&ndlp->els_retry_evt.evt_listp))
267 list_del_init(&ndlp->els_retry_evt.evt_listp);
268 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500269 return 0;
dea31012005-04-17 16:05:31 -0500270}
271
272static int
273lpfc_rcv_plogi(struct lpfc_hba * phba,
274 struct lpfc_nodelist * ndlp,
275 struct lpfc_iocbq *cmdiocb)
276{
277 struct lpfc_dmabuf *pcmd;
278 uint32_t *lp;
279 IOCB_t *icmd;
280 struct serv_parm *sp;
281 LPFC_MBOXQ_t *mbox;
282 struct ls_rjt stat;
283 int rc;
284
285 memset(&stat, 0, sizeof (struct ls_rjt));
286 if (phba->hba_state <= LPFC_FLOGI) {
287 /* Before responding to PLOGI, check for pt2pt mode.
288 * If we are pt2pt, with an outstanding FLOGI, abort
289 * the FLOGI and resend it first.
290 */
291 if (phba->fc_flag & FC_PT2PT) {
292 lpfc_els_abort_flogi(phba);
293 if (!(phba->fc_flag & FC_PT2PT_PLOGI)) {
294 /* If the other side is supposed to initiate
295 * the PLOGI anyway, just ACC it now and
296 * move on with discovery.
297 */
298 phba->fc_edtov = FF_DEF_EDTOV;
299 phba->fc_ratov = FF_DEF_RATOV;
300 /* Start discovery - this should just do
301 CLEAR_LA */
302 lpfc_disc_start(phba);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500303 } else {
dea31012005-04-17 16:05:31 -0500304 lpfc_initial_flogi(phba);
305 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500306 } else {
dea31012005-04-17 16:05:31 -0500307 stat.un.b.lsRjtRsnCode = LSRJT_LOGICAL_BSY;
308 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
309 lpfc_els_rsp_reject(phba, stat.un.lsRjtError, cmdiocb,
310 ndlp);
311 return 0;
312 }
313 }
314 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
315 lp = (uint32_t *) pcmd->virt;
316 sp = (struct serv_parm *) ((uint8_t *) lp + sizeof (uint32_t));
317 if ((lpfc_check_sparm(phba, ndlp, sp, CLASS3) == 0)) {
318 /* Reject this request because invalid parameters */
319 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
320 stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
321 lpfc_els_rsp_reject(phba, stat.un.lsRjtError, cmdiocb, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500322 return 0;
dea31012005-04-17 16:05:31 -0500323 }
324 icmd = &cmdiocb->iocb;
325
326 /* PLOGI chkparm OK */
327 lpfc_printf_log(phba,
328 KERN_INFO,
329 LOG_ELS,
330 "%d:0114 PLOGI chkparm OK Data: x%x x%x x%x x%x\n",
331 phba->brd_no,
332 ndlp->nlp_DID, ndlp->nlp_state, ndlp->nlp_flag,
333 ndlp->nlp_rpi);
334
335 if ((phba->cfg_fcp_class == 2) &&
336 (sp->cls2.classValid)) {
337 ndlp->nlp_fcp_info |= CLASS2;
338 } else {
339 ndlp->nlp_fcp_info |= CLASS3;
340 }
341 ndlp->nlp_class_sup = 0;
342 if (sp->cls1.classValid)
343 ndlp->nlp_class_sup |= FC_COS_CLASS1;
344 if (sp->cls2.classValid)
345 ndlp->nlp_class_sup |= FC_COS_CLASS2;
346 if (sp->cls3.classValid)
347 ndlp->nlp_class_sup |= FC_COS_CLASS3;
348 if (sp->cls4.classValid)
349 ndlp->nlp_class_sup |= FC_COS_CLASS4;
350 ndlp->nlp_maxframe =
351 ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) | sp->cmn.bbRcvSizeLsb;
352
353 /* no need to reg_login if we are already in one of these states */
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500354 switch (ndlp->nlp_state) {
dea31012005-04-17 16:05:31 -0500355 case NLP_STE_NPR_NODE:
356 if (!(ndlp->nlp_flag & NLP_NPR_ADISC))
357 break;
358 case NLP_STE_REG_LOGIN_ISSUE:
359 case NLP_STE_PRLI_ISSUE:
360 case NLP_STE_UNMAPPED_NODE:
361 case NLP_STE_MAPPED_NODE:
362 lpfc_els_rsp_acc(phba, ELS_CMD_PLOGI, cmdiocb, ndlp, NULL, 0);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500363 return 1;
dea31012005-04-17 16:05:31 -0500364 }
365
366 if ((phba->fc_flag & FC_PT2PT)
367 && !(phba->fc_flag & FC_PT2PT_PLOGI)) {
368 /* rcv'ed PLOGI decides what our NPortId will be */
369 phba->fc_myDID = icmd->un.rcvels.parmRo;
370 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
371 if (mbox == NULL)
372 goto out;
373 lpfc_config_link(phba, mbox);
374 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
375 rc = lpfc_sli_issue_mbox
376 (phba, mbox, (MBX_NOWAIT | MBX_STOP_IOCB));
377 if (rc == MBX_NOT_FINISHED) {
378 mempool_free( mbox, phba->mbox_mem_pool);
379 goto out;
380 }
381
382 lpfc_can_disctmo(phba);
383 }
384 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
385 if (mbox == NULL)
386 goto out;
387
388 if (lpfc_reg_login(phba, icmd->un.rcvels.remoteID,
389 (uint8_t *) sp, mbox, 0)) {
390 mempool_free( mbox, phba->mbox_mem_pool);
391 goto out;
392 }
393
394 /* ACC PLOGI rsp command needs to execute first,
395 * queue this mbox command to be processed later.
396 */
397 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
398 mbox->context2 = ndlp;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -0500399 ndlp->nlp_flag |= (NLP_ACC_REGLOGIN | NLP_RCV_PLOGI);
dea31012005-04-17 16:05:31 -0500400
dea31012005-04-17 16:05:31 -0500401 lpfc_els_rsp_acc(phba, ELS_CMD_PLOGI, cmdiocb, ndlp, mbox, 0);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500402 return 1;
dea31012005-04-17 16:05:31 -0500403
404out:
405 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
406 stat.un.b.lsRjtRsnCodeExp = LSEXP_OUT_OF_RESOURCE;
407 lpfc_els_rsp_reject(phba, stat.un.lsRjtError, cmdiocb, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500408 return 0;
dea31012005-04-17 16:05:31 -0500409}
410
411static int
412lpfc_rcv_padisc(struct lpfc_hba * phba,
413 struct lpfc_nodelist * ndlp,
414 struct lpfc_iocbq *cmdiocb)
415{
416 struct lpfc_dmabuf *pcmd;
417 struct serv_parm *sp;
418 struct lpfc_name *pnn, *ppn;
419 struct ls_rjt stat;
420 ADISC *ap;
421 IOCB_t *icmd;
422 uint32_t *lp;
423 uint32_t cmd;
424
425 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
426 lp = (uint32_t *) pcmd->virt;
427
428 cmd = *lp++;
429 if (cmd == ELS_CMD_ADISC) {
430 ap = (ADISC *) lp;
431 pnn = (struct lpfc_name *) & ap->nodeName;
432 ppn = (struct lpfc_name *) & ap->portName;
433 } else {
434 sp = (struct serv_parm *) lp;
435 pnn = (struct lpfc_name *) & sp->nodeName;
436 ppn = (struct lpfc_name *) & sp->portName;
437 }
438
439 icmd = &cmdiocb->iocb;
440 if ((icmd->ulpStatus == 0) &&
441 (lpfc_check_adisc(phba, ndlp, pnn, ppn))) {
442 if (cmd == ELS_CMD_ADISC) {
443 lpfc_els_rsp_adisc_acc(phba, cmdiocb, ndlp);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500444 } else {
dea31012005-04-17 16:05:31 -0500445 lpfc_els_rsp_acc(phba, ELS_CMD_PLOGI, cmdiocb, ndlp,
446 NULL, 0);
447 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500448 return 1;
dea31012005-04-17 16:05:31 -0500449 }
450 /* Reject this request because invalid parameters */
451 stat.un.b.lsRjtRsvd0 = 0;
452 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
453 stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
454 stat.un.b.vendorUnique = 0;
455 lpfc_els_rsp_reject(phba, stat.un.lsRjtError, cmdiocb, ndlp);
456
dea31012005-04-17 16:05:31 -0500457 /* 1 sec timeout */
458 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ);
459
460 spin_lock_irq(phba->host->host_lock);
461 ndlp->nlp_flag |= NLP_DELAY_TMO;
462 spin_unlock_irq(phba->host->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -0500463 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
464 ndlp->nlp_prev_state = ndlp->nlp_state;
dea31012005-04-17 16:05:31 -0500465 ndlp->nlp_state = NLP_STE_NPR_NODE;
466 lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500467 return 0;
dea31012005-04-17 16:05:31 -0500468}
469
470static int
471lpfc_rcv_logo(struct lpfc_hba * phba,
472 struct lpfc_nodelist * ndlp,
473 struct lpfc_iocbq *cmdiocb)
474{
475 /* Put ndlp on NPR list with 1 sec timeout for plogi, ACC logo */
476 /* Only call LOGO ACC for first LOGO, this avoids sending unnecessary
477 * PLOGIs during LOGO storms from a device.
478 */
479 ndlp->nlp_flag |= NLP_LOGO_ACC;
480 lpfc_els_rsp_acc(phba, ELS_CMD_ACC, cmdiocb, ndlp, NULL, 0);
481
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500482 if (!(ndlp->nlp_type & NLP_FABRIC) ||
483 (ndlp->nlp_state == NLP_STE_ADISC_ISSUE)) {
dea31012005-04-17 16:05:31 -0500484 /* Only try to re-login if this is NOT a Fabric Node */
dea31012005-04-17 16:05:31 -0500485 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ * 1);
486 spin_lock_irq(phba->host->host_lock);
487 ndlp->nlp_flag |= NLP_DELAY_TMO;
488 spin_unlock_irq(phba->host->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500489
Jamie Wellnitz5024ab12006-02-28 19:25:28 -0500490 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
491 ndlp->nlp_prev_state = ndlp->nlp_state;
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500492 ndlp->nlp_state = NLP_STE_NPR_NODE;
493 lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
494 } else {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -0500495 ndlp->nlp_prev_state = ndlp->nlp_state;
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500496 ndlp->nlp_state = NLP_STE_UNUSED_NODE;
497 lpfc_nlp_list(phba, ndlp, NLP_UNUSED_LIST);
dea31012005-04-17 16:05:31 -0500498 }
499
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500500 spin_lock_irq(phba->host->host_lock);
dea31012005-04-17 16:05:31 -0500501 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500502 spin_unlock_irq(phba->host->host_lock);
dea31012005-04-17 16:05:31 -0500503 /* The driver has to wait until the ACC completes before it continues
504 * processing the LOGO. The action will resume in
505 * lpfc_cmpl_els_logo_acc routine. Since part of processing includes an
506 * unreg_login, the driver waits so the ACC does not get aborted.
507 */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500508 return 0;
dea31012005-04-17 16:05:31 -0500509}
510
511static void
512lpfc_rcv_prli(struct lpfc_hba * phba,
513 struct lpfc_nodelist * ndlp,
514 struct lpfc_iocbq *cmdiocb)
515{
516 struct lpfc_dmabuf *pcmd;
517 uint32_t *lp;
518 PRLI *npr;
519 struct fc_rport *rport = ndlp->rport;
520 u32 roles;
521
522 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
523 lp = (uint32_t *) pcmd->virt;
524 npr = (PRLI *) ((uint8_t *) lp + sizeof (uint32_t));
525
526 ndlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR);
527 ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
528 if ((npr->acceptRspCode == PRLI_REQ_EXECUTED) &&
529 (npr->prliType == PRLI_FCP_TYPE)) {
530 if (npr->initiatorFunc)
531 ndlp->nlp_type |= NLP_FCP_INITIATOR;
532 if (npr->targetFunc)
533 ndlp->nlp_type |= NLP_FCP_TARGET;
534 if (npr->Retry)
535 ndlp->nlp_fcp_info |= NLP_FCP_2_DEVICE;
536 }
537 if (rport) {
538 /* We need to update the rport role values */
539 roles = FC_RPORT_ROLE_UNKNOWN;
540 if (ndlp->nlp_type & NLP_FCP_INITIATOR)
541 roles |= FC_RPORT_ROLE_FCP_INITIATOR;
542 if (ndlp->nlp_type & NLP_FCP_TARGET)
543 roles |= FC_RPORT_ROLE_FCP_TARGET;
544 fc_remote_port_rolechg(rport, roles);
545 }
546}
547
548static uint32_t
549lpfc_disc_set_adisc(struct lpfc_hba * phba,
550 struct lpfc_nodelist * ndlp)
551{
552 /* Check config parameter use-adisc or FCP-2 */
553 if ((phba->cfg_use_adisc == 0) &&
554 !(phba->fc_flag & FC_RSCN_MODE)) {
555 if (!(ndlp->nlp_fcp_info & NLP_FCP_2_DEVICE))
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500556 return 0;
dea31012005-04-17 16:05:31 -0500557 }
558 spin_lock_irq(phba->host->host_lock);
559 ndlp->nlp_flag |= NLP_NPR_ADISC;
560 spin_unlock_irq(phba->host->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500561 return 1;
dea31012005-04-17 16:05:31 -0500562}
563
564static uint32_t
565lpfc_disc_illegal(struct lpfc_hba * phba,
566 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
567{
568 lpfc_printf_log(phba,
569 KERN_ERR,
570 LOG_DISCOVERY,
571 "%d:0253 Illegal State Transition: node x%x event x%x, "
572 "state x%x Data: x%x x%x\n",
573 phba->brd_no,
574 ndlp->nlp_DID, evt, ndlp->nlp_state, ndlp->nlp_rpi,
575 ndlp->nlp_flag);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500576 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -0500577}
578
579/* Start of Discovery State Machine routines */
580
581static uint32_t
582lpfc_rcv_plogi_unused_node(struct lpfc_hba * phba,
583 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
584{
585 struct lpfc_iocbq *cmdiocb;
586
587 cmdiocb = (struct lpfc_iocbq *) arg;
588
589 if (lpfc_rcv_plogi(phba, ndlp, cmdiocb)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -0500590 ndlp->nlp_prev_state = NLP_STE_UNUSED_NODE;
dea31012005-04-17 16:05:31 -0500591 ndlp->nlp_state = NLP_STE_UNUSED_NODE;
592 lpfc_nlp_list(phba, ndlp, NLP_UNUSED_LIST);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500593 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -0500594 }
595 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500596 return NLP_STE_FREED_NODE;
dea31012005-04-17 16:05:31 -0500597}
598
599static uint32_t
600lpfc_rcv_els_unused_node(struct lpfc_hba * phba,
601 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
602{
603 lpfc_issue_els_logo(phba, ndlp, 0);
604 lpfc_nlp_list(phba, ndlp, NLP_UNUSED_LIST);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500605 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -0500606}
607
608static uint32_t
609lpfc_rcv_logo_unused_node(struct lpfc_hba * phba,
610 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
611{
612 struct lpfc_iocbq *cmdiocb;
613
614 cmdiocb = (struct lpfc_iocbq *) arg;
615
616 spin_lock_irq(phba->host->host_lock);
617 ndlp->nlp_flag |= NLP_LOGO_ACC;
618 spin_unlock_irq(phba->host->host_lock);
619 lpfc_els_rsp_acc(phba, ELS_CMD_ACC, cmdiocb, ndlp, NULL, 0);
620 lpfc_nlp_list(phba, ndlp, NLP_UNUSED_LIST);
621
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500622 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -0500623}
624
625static uint32_t
626lpfc_cmpl_logo_unused_node(struct lpfc_hba * phba,
627 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
628{
629 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500630 return NLP_STE_FREED_NODE;
dea31012005-04-17 16:05:31 -0500631}
632
633static uint32_t
634lpfc_device_rm_unused_node(struct lpfc_hba * phba,
635 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
636{
637 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500638 return NLP_STE_FREED_NODE;
dea31012005-04-17 16:05:31 -0500639}
640
641static uint32_t
642lpfc_rcv_plogi_plogi_issue(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp,
643 void *arg, uint32_t evt)
644{
645 struct lpfc_iocbq *cmdiocb = arg;
646 struct lpfc_dmabuf *pcmd;
647 struct serv_parm *sp;
648 uint32_t *lp;
649 struct ls_rjt stat;
650 int port_cmp;
651
652 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
653 lp = (uint32_t *) pcmd->virt;
654 sp = (struct serv_parm *) ((uint8_t *) lp + sizeof (uint32_t));
655
656 memset(&stat, 0, sizeof (struct ls_rjt));
657
658 /* For a PLOGI, we only accept if our portname is less
659 * than the remote portname.
660 */
661 phba->fc_stat.elsLogiCol++;
662 port_cmp = memcmp(&phba->fc_portname, &sp->portName,
663 sizeof (struct lpfc_name));
664
665 if (port_cmp >= 0) {
666 /* Reject this request because the remote node will accept
667 ours */
668 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
669 stat.un.b.lsRjtRsnCodeExp = LSEXP_CMD_IN_PROGRESS;
670 lpfc_els_rsp_reject(phba, stat.un.lsRjtError, cmdiocb, ndlp);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500671 } else {
dea31012005-04-17 16:05:31 -0500672 lpfc_rcv_plogi(phba, ndlp, cmdiocb);
673 } /* if our portname was less */
674
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500675 return ndlp->nlp_state;
676}
677
678static uint32_t
679lpfc_rcv_logo_plogi_issue(struct lpfc_hba * phba,
680 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
681{
682 struct lpfc_iocbq *cmdiocb;
683
684 cmdiocb = (struct lpfc_iocbq *) arg;
685
686 /* software abort outstanding PLOGI */
687 lpfc_els_abort(phba, ndlp, 1);
688
689 lpfc_rcv_logo(phba, ndlp, cmdiocb);
690 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -0500691}
692
693static uint32_t
694lpfc_rcv_els_plogi_issue(struct lpfc_hba * phba,
695 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
696{
697 struct lpfc_iocbq *cmdiocb;
698
699 cmdiocb = (struct lpfc_iocbq *) arg;
700
701 /* software abort outstanding PLOGI */
702 lpfc_els_abort(phba, ndlp, 1);
dea31012005-04-17 16:05:31 -0500703
704 if (evt == NLP_EVT_RCV_LOGO) {
705 lpfc_els_rsp_acc(phba, ELS_CMD_ACC, cmdiocb, ndlp, NULL, 0);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500706 } else {
dea31012005-04-17 16:05:31 -0500707 lpfc_issue_els_logo(phba, ndlp, 0);
708 }
709
710 /* Put ndlp in npr list set plogi timer for 1 sec */
Jamie Wellnitz5024ab12006-02-28 19:25:28 -0500711 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ * 1);
712 spin_lock_irq(phba->host->host_lock);
713 ndlp->nlp_flag |= NLP_DELAY_TMO;
714 spin_unlock_irq(phba->host->host_lock);
715 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
716 ndlp->nlp_prev_state = NLP_STE_PLOGI_ISSUE;
dea31012005-04-17 16:05:31 -0500717 ndlp->nlp_state = NLP_STE_NPR_NODE;
718 lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
719
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500720 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -0500721}
722
723static uint32_t
724lpfc_cmpl_plogi_plogi_issue(struct lpfc_hba * phba,
725 struct lpfc_nodelist * ndlp, void *arg,
726 uint32_t evt)
727{
728 struct lpfc_iocbq *cmdiocb, *rspiocb;
729 struct lpfc_dmabuf *pcmd, *prsp;
730 uint32_t *lp;
731 IOCB_t *irsp;
732 struct serv_parm *sp;
733 LPFC_MBOXQ_t *mbox;
734
735 cmdiocb = (struct lpfc_iocbq *) arg;
736 rspiocb = cmdiocb->context_un.rsp_iocb;
737
738 if (ndlp->nlp_flag & NLP_ACC_REGLOGIN) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -0500739 /* Recovery from PLOGI collision logic */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500740 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -0500741 }
742
743 irsp = &rspiocb->iocb;
744
745 if (irsp->ulpStatus)
746 goto out;
747
748 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
749
750 prsp = list_get_first(&pcmd->list,
751 struct lpfc_dmabuf,
752 list);
753 lp = (uint32_t *) prsp->virt;
754
755 sp = (struct serv_parm *) ((uint8_t *) lp + sizeof (uint32_t));
756 if (!lpfc_check_sparm(phba, ndlp, sp, CLASS3))
757 goto out;
758
759 /* PLOGI chkparm OK */
760 lpfc_printf_log(phba,
761 KERN_INFO,
762 LOG_ELS,
763 "%d:0121 PLOGI chkparm OK "
764 "Data: x%x x%x x%x x%x\n",
765 phba->brd_no,
766 ndlp->nlp_DID, ndlp->nlp_state,
767 ndlp->nlp_flag, ndlp->nlp_rpi);
768
769 if ((phba->cfg_fcp_class == 2) &&
770 (sp->cls2.classValid)) {
771 ndlp->nlp_fcp_info |= CLASS2;
772 } else {
773 ndlp->nlp_fcp_info |= CLASS3;
774 }
775 ndlp->nlp_class_sup = 0;
776 if (sp->cls1.classValid)
777 ndlp->nlp_class_sup |= FC_COS_CLASS1;
778 if (sp->cls2.classValid)
779 ndlp->nlp_class_sup |= FC_COS_CLASS2;
780 if (sp->cls3.classValid)
781 ndlp->nlp_class_sup |= FC_COS_CLASS3;
782 if (sp->cls4.classValid)
783 ndlp->nlp_class_sup |= FC_COS_CLASS4;
784 ndlp->nlp_maxframe =
785 ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) |
786 sp->cmn.bbRcvSizeLsb;
787
788 if (!(mbox = mempool_alloc(phba->mbox_mem_pool,
789 GFP_KERNEL)))
790 goto out;
791
792 lpfc_unreg_rpi(phba, ndlp);
793 if (lpfc_reg_login
794 (phba, irsp->un.elsreq64.remoteID,
795 (uint8_t *) sp, mbox, 0) == 0) {
796 /* set_slim mailbox command needs to
797 * execute first, queue this command to
798 * be processed later.
799 */
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500800 switch (ndlp->nlp_DID) {
dea31012005-04-17 16:05:31 -0500801 case NameServer_DID:
802 mbox->mbox_cmpl =
803 lpfc_mbx_cmpl_ns_reg_login;
804 break;
805 case FDMI_DID:
806 mbox->mbox_cmpl =
807 lpfc_mbx_cmpl_fdmi_reg_login;
808 break;
809 default:
810 mbox->mbox_cmpl =
811 lpfc_mbx_cmpl_reg_login;
812 }
813 mbox->context2 = ndlp;
814 if (lpfc_sli_issue_mbox(phba, mbox,
815 (MBX_NOWAIT | MBX_STOP_IOCB))
816 != MBX_NOT_FINISHED) {
817 ndlp->nlp_state =
818 NLP_STE_REG_LOGIN_ISSUE;
819 lpfc_nlp_list(phba, ndlp,
820 NLP_REGLOGIN_LIST);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500821 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -0500822 }
823 mempool_free(mbox, phba->mbox_mem_pool);
824 } else {
825 mempool_free(mbox, phba->mbox_mem_pool);
826 }
827
828
829 out:
830 /* Free this node since the driver cannot login or has the wrong
831 sparm */
832 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500833 return NLP_STE_FREED_NODE;
dea31012005-04-17 16:05:31 -0500834}
835
836static uint32_t
837lpfc_device_rm_plogi_issue(struct lpfc_hba * phba,
838 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
839{
840 /* software abort outstanding PLOGI */
841 lpfc_els_abort(phba, ndlp, 1);
842
843 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500844 return NLP_STE_FREED_NODE;
dea31012005-04-17 16:05:31 -0500845}
846
847static uint32_t
848lpfc_device_recov_plogi_issue(struct lpfc_hba * phba,
849 struct lpfc_nodelist * ndlp, void *arg,
850 uint32_t evt)
851{
852 /* software abort outstanding PLOGI */
853 lpfc_els_abort(phba, ndlp, 1);
854
Jamie Wellnitz5024ab12006-02-28 19:25:28 -0500855 ndlp->nlp_prev_state = NLP_STE_PLOGI_ISSUE;
dea31012005-04-17 16:05:31 -0500856 ndlp->nlp_state = NLP_STE_NPR_NODE;
857 lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
858 spin_lock_irq(phba->host->host_lock);
859 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
860 spin_unlock_irq(phba->host->host_lock);
861
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500862 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -0500863}
864
865static uint32_t
866lpfc_rcv_plogi_adisc_issue(struct lpfc_hba * phba,
867 struct lpfc_nodelist * ndlp, void *arg,
868 uint32_t evt)
869{
870 struct lpfc_iocbq *cmdiocb;
871
872 /* software abort outstanding ADISC */
873 lpfc_els_abort(phba, ndlp, 1);
874
875 cmdiocb = (struct lpfc_iocbq *) arg;
876
877 if (lpfc_rcv_plogi(phba, ndlp, cmdiocb)) {
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500878 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -0500879 }
Jamie Wellnitz5024ab12006-02-28 19:25:28 -0500880 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
dea31012005-04-17 16:05:31 -0500881 ndlp->nlp_state = NLP_STE_PLOGI_ISSUE;
882 lpfc_nlp_list(phba, ndlp, NLP_PLOGI_LIST);
883 lpfc_issue_els_plogi(phba, ndlp, 0);
884
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500885 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -0500886}
887
888static uint32_t
889lpfc_rcv_prli_adisc_issue(struct lpfc_hba * phba,
890 struct lpfc_nodelist * ndlp, void *arg,
891 uint32_t evt)
892{
893 struct lpfc_iocbq *cmdiocb;
894
895 cmdiocb = (struct lpfc_iocbq *) arg;
896
897 lpfc_els_rsp_prli_acc(phba, cmdiocb, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500898 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -0500899}
900
901static uint32_t
902lpfc_rcv_logo_adisc_issue(struct lpfc_hba * phba,
903 struct lpfc_nodelist * ndlp, void *arg,
904 uint32_t evt)
905{
906 struct lpfc_iocbq *cmdiocb;
907
908 cmdiocb = (struct lpfc_iocbq *) arg;
909
910 /* software abort outstanding ADISC */
911 lpfc_els_abort(phba, ndlp, 0);
912
913 lpfc_rcv_logo(phba, ndlp, cmdiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500914 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -0500915}
916
917static uint32_t
918lpfc_rcv_padisc_adisc_issue(struct lpfc_hba * phba,
919 struct lpfc_nodelist * ndlp, void *arg,
920 uint32_t evt)
921{
922 struct lpfc_iocbq *cmdiocb;
923
924 cmdiocb = (struct lpfc_iocbq *) arg;
925
926 lpfc_rcv_padisc(phba, ndlp, cmdiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500927 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -0500928}
929
930static uint32_t
931lpfc_rcv_prlo_adisc_issue(struct lpfc_hba * phba,
932 struct lpfc_nodelist * ndlp, void *arg,
933 uint32_t evt)
934{
935 struct lpfc_iocbq *cmdiocb;
936
937 cmdiocb = (struct lpfc_iocbq *) arg;
938
939 /* Treat like rcv logo */
940 lpfc_rcv_logo(phba, ndlp, cmdiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500941 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -0500942}
943
944static uint32_t
945lpfc_cmpl_adisc_adisc_issue(struct lpfc_hba * phba,
946 struct lpfc_nodelist * ndlp, void *arg,
947 uint32_t evt)
948{
949 struct lpfc_iocbq *cmdiocb, *rspiocb;
950 IOCB_t *irsp;
951 ADISC *ap;
952
953 cmdiocb = (struct lpfc_iocbq *) arg;
954 rspiocb = cmdiocb->context_un.rsp_iocb;
955
956 ap = (ADISC *)lpfc_check_elscmpl_iocb(phba, cmdiocb, rspiocb);
957 irsp = &rspiocb->iocb;
958
959 if ((irsp->ulpStatus) ||
960 (!lpfc_check_adisc(phba, ndlp, &ap->nodeName, &ap->portName))) {
dea31012005-04-17 16:05:31 -0500961 /* 1 sec timeout */
962 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ);
963 spin_lock_irq(phba->host->host_lock);
964 ndlp->nlp_flag |= NLP_DELAY_TMO;
965 spin_unlock_irq(phba->host->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -0500966 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
dea31012005-04-17 16:05:31 -0500967
968 memset(&ndlp->nlp_nodename, 0, sizeof (struct lpfc_name));
969 memset(&ndlp->nlp_portname, 0, sizeof (struct lpfc_name));
970
Jamie Wellnitz5024ab12006-02-28 19:25:28 -0500971 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
dea31012005-04-17 16:05:31 -0500972 ndlp->nlp_state = NLP_STE_NPR_NODE;
973 lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
974 lpfc_unreg_rpi(phba, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500975 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -0500976 }
Jamie Wellnitz5024ab12006-02-28 19:25:28 -0500977
James.Smart@Emulex.Com25013222005-06-25 10:34:33 -0400978 if (ndlp->nlp_type & NLP_FCP_TARGET) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -0500979 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
James.Smart@Emulex.Com25013222005-06-25 10:34:33 -0400980 ndlp->nlp_state = NLP_STE_MAPPED_NODE;
981 lpfc_nlp_list(phba, ndlp, NLP_MAPPED_LIST);
982 } else {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -0500983 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
James.Smart@Emulex.Com25013222005-06-25 10:34:33 -0400984 ndlp->nlp_state = NLP_STE_UNMAPPED_NODE;
985 lpfc_nlp_list(phba, ndlp, NLP_UNMAPPED_LIST);
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_device_rm_adisc_issue(struct lpfc_hba * phba,
992 struct lpfc_nodelist * ndlp, void *arg,
993 uint32_t evt)
994{
995 /* software abort outstanding ADISC */
996 lpfc_els_abort(phba, ndlp, 1);
997
998 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500999 return NLP_STE_FREED_NODE;
dea31012005-04-17 16:05:31 -05001000}
1001
1002static uint32_t
1003lpfc_device_recov_adisc_issue(struct lpfc_hba * phba,
1004 struct lpfc_nodelist * ndlp, void *arg,
1005 uint32_t evt)
1006{
1007 /* software abort outstanding ADISC */
1008 lpfc_els_abort(phba, ndlp, 1);
1009
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001010 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
dea31012005-04-17 16:05:31 -05001011 ndlp->nlp_state = NLP_STE_NPR_NODE;
1012 lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
1013 spin_lock_irq(phba->host->host_lock);
1014 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001015 ndlp->nlp_flag |= NLP_NPR_ADISC;
dea31012005-04-17 16:05:31 -05001016 spin_unlock_irq(phba->host->host_lock);
1017
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001018 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001019}
1020
1021static uint32_t
1022lpfc_rcv_plogi_reglogin_issue(struct lpfc_hba * phba,
1023 struct lpfc_nodelist * ndlp, void *arg,
1024 uint32_t evt)
1025{
1026 struct lpfc_iocbq *cmdiocb;
1027
1028 cmdiocb = (struct lpfc_iocbq *) arg;
1029
1030 lpfc_rcv_plogi(phba, ndlp, cmdiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001031 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001032}
1033
1034static uint32_t
1035lpfc_rcv_prli_reglogin_issue(struct lpfc_hba * phba,
1036 struct lpfc_nodelist * ndlp, void *arg,
1037 uint32_t evt)
1038{
1039 struct lpfc_iocbq *cmdiocb;
1040
1041 cmdiocb = (struct lpfc_iocbq *) arg;
1042
1043 lpfc_els_rsp_prli_acc(phba, cmdiocb, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001044 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001045}
1046
1047static uint32_t
1048lpfc_rcv_logo_reglogin_issue(struct lpfc_hba * phba,
1049 struct lpfc_nodelist * ndlp, void *arg,
1050 uint32_t evt)
1051{
1052 struct lpfc_iocbq *cmdiocb;
1053
1054 cmdiocb = (struct lpfc_iocbq *) arg;
1055
1056 lpfc_rcv_logo(phba, ndlp, cmdiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001057 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001058}
1059
1060static uint32_t
1061lpfc_rcv_padisc_reglogin_issue(struct lpfc_hba * phba,
1062 struct lpfc_nodelist * ndlp, void *arg,
1063 uint32_t evt)
1064{
1065 struct lpfc_iocbq *cmdiocb;
1066
1067 cmdiocb = (struct lpfc_iocbq *) arg;
1068
1069 lpfc_rcv_padisc(phba, ndlp, cmdiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001070 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001071}
1072
1073static uint32_t
1074lpfc_rcv_prlo_reglogin_issue(struct lpfc_hba * phba,
1075 struct lpfc_nodelist * ndlp, void *arg,
1076 uint32_t evt)
1077{
1078 struct lpfc_iocbq *cmdiocb;
1079
1080 cmdiocb = (struct lpfc_iocbq *) arg;
1081 lpfc_els_rsp_acc(phba, ELS_CMD_ACC, cmdiocb, ndlp, NULL, 0);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001082 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001083}
1084
1085static uint32_t
1086lpfc_cmpl_reglogin_reglogin_issue(struct lpfc_hba * phba,
1087 struct lpfc_nodelist * ndlp,
1088 void *arg, uint32_t evt)
1089{
1090 LPFC_MBOXQ_t *pmb;
1091 MAILBOX_t *mb;
1092 uint32_t did;
1093
1094 pmb = (LPFC_MBOXQ_t *) arg;
1095 mb = &pmb->mb;
1096 did = mb->un.varWords[1];
1097 if (mb->mbxStatus) {
1098 /* RegLogin failed */
1099 lpfc_printf_log(phba,
1100 KERN_ERR,
1101 LOG_DISCOVERY,
1102 "%d:0246 RegLogin failed Data: x%x x%x x%x\n",
1103 phba->brd_no,
1104 did, mb->mbxStatus, phba->hba_state);
1105
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001106 /* Put ndlp in npr list set plogi timer for 1 sec */
dea31012005-04-17 16:05:31 -05001107 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ * 1);
1108 spin_lock_irq(phba->host->host_lock);
1109 ndlp->nlp_flag |= NLP_DELAY_TMO;
1110 spin_unlock_irq(phba->host->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001111 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
dea31012005-04-17 16:05:31 -05001112
1113 lpfc_issue_els_logo(phba, ndlp, 0);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001114 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
dea31012005-04-17 16:05:31 -05001115 ndlp->nlp_state = NLP_STE_NPR_NODE;
1116 lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001117 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001118 }
1119
dea31012005-04-17 16:05:31 -05001120 ndlp->nlp_rpi = mb->un.varWords[0];
dea31012005-04-17 16:05:31 -05001121
1122 /* Only if we are not a fabric nport do we issue PRLI */
1123 if (!(ndlp->nlp_type & NLP_FABRIC)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001124 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
dea31012005-04-17 16:05:31 -05001125 ndlp->nlp_state = NLP_STE_PRLI_ISSUE;
1126 lpfc_nlp_list(phba, ndlp, NLP_PRLI_LIST);
1127 lpfc_issue_els_prli(phba, ndlp, 0);
1128 } else {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001129 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
dea31012005-04-17 16:05:31 -05001130 ndlp->nlp_state = NLP_STE_UNMAPPED_NODE;
1131 lpfc_nlp_list(phba, ndlp, NLP_UNMAPPED_LIST);
1132 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001133 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001134}
1135
1136static uint32_t
1137lpfc_device_rm_reglogin_issue(struct lpfc_hba * phba,
1138 struct lpfc_nodelist * ndlp, void *arg,
1139 uint32_t evt)
1140{
1141 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001142 return NLP_STE_FREED_NODE;
dea31012005-04-17 16:05:31 -05001143}
1144
1145static uint32_t
1146lpfc_device_recov_reglogin_issue(struct lpfc_hba * phba,
1147 struct lpfc_nodelist * ndlp, void *arg,
1148 uint32_t evt)
1149{
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001150 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
dea31012005-04-17 16:05:31 -05001151 ndlp->nlp_state = NLP_STE_NPR_NODE;
1152 lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
1153 spin_lock_irq(phba->host->host_lock);
1154 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
1155 spin_unlock_irq(phba->host->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001156 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001157}
1158
1159static uint32_t
1160lpfc_rcv_plogi_prli_issue(struct lpfc_hba * phba,
1161 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1162{
1163 struct lpfc_iocbq *cmdiocb;
1164
1165 cmdiocb = (struct lpfc_iocbq *) arg;
1166
1167 lpfc_rcv_plogi(phba, ndlp, cmdiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001168 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001169}
1170
1171static uint32_t
1172lpfc_rcv_prli_prli_issue(struct lpfc_hba * phba,
1173 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1174{
1175 struct lpfc_iocbq *cmdiocb;
1176
1177 cmdiocb = (struct lpfc_iocbq *) arg;
1178
1179 lpfc_els_rsp_prli_acc(phba, cmdiocb, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001180 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001181}
1182
1183static uint32_t
1184lpfc_rcv_logo_prli_issue(struct lpfc_hba * phba,
1185 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1186{
1187 struct lpfc_iocbq *cmdiocb;
1188
1189 cmdiocb = (struct lpfc_iocbq *) arg;
1190
1191 /* Software abort outstanding PRLI before sending acc */
1192 lpfc_els_abort(phba, ndlp, 1);
1193
1194 lpfc_rcv_logo(phba, ndlp, cmdiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001195 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001196}
1197
1198static uint32_t
1199lpfc_rcv_padisc_prli_issue(struct lpfc_hba * phba,
1200 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1201{
1202 struct lpfc_iocbq *cmdiocb;
1203
1204 cmdiocb = (struct lpfc_iocbq *) arg;
1205
1206 lpfc_rcv_padisc(phba, ndlp, cmdiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001207 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001208}
1209
1210/* This routine is envoked when we rcv a PRLO request from a nport
1211 * we are logged into. We should send back a PRLO rsp setting the
1212 * appropriate bits.
1213 * NEXT STATE = PRLI_ISSUE
1214 */
1215static uint32_t
1216lpfc_rcv_prlo_prli_issue(struct lpfc_hba * phba,
1217 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1218{
1219 struct lpfc_iocbq *cmdiocb;
1220
1221 cmdiocb = (struct lpfc_iocbq *) arg;
1222 lpfc_els_rsp_acc(phba, ELS_CMD_ACC, cmdiocb, ndlp, NULL, 0);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001223 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001224}
1225
1226static uint32_t
1227lpfc_cmpl_prli_prli_issue(struct lpfc_hba * phba,
1228 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1229{
1230 struct lpfc_iocbq *cmdiocb, *rspiocb;
1231 IOCB_t *irsp;
1232 PRLI *npr;
1233
1234 cmdiocb = (struct lpfc_iocbq *) arg;
1235 rspiocb = cmdiocb->context_un.rsp_iocb;
1236 npr = (PRLI *)lpfc_check_elscmpl_iocb(phba, cmdiocb, rspiocb);
1237
1238 irsp = &rspiocb->iocb;
1239 if (irsp->ulpStatus) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001240 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
dea31012005-04-17 16:05:31 -05001241 ndlp->nlp_state = NLP_STE_UNMAPPED_NODE;
1242 lpfc_nlp_list(phba, ndlp, NLP_UNMAPPED_LIST);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001243 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001244 }
1245
1246 /* Check out PRLI rsp */
1247 ndlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR);
1248 ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
1249 if ((npr->acceptRspCode == PRLI_REQ_EXECUTED) &&
1250 (npr->prliType == PRLI_FCP_TYPE)) {
1251 if (npr->initiatorFunc)
1252 ndlp->nlp_type |= NLP_FCP_INITIATOR;
1253 if (npr->targetFunc)
1254 ndlp->nlp_type |= NLP_FCP_TARGET;
1255 if (npr->Retry)
1256 ndlp->nlp_fcp_info |= NLP_FCP_2_DEVICE;
1257 }
1258
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001259 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
dea31012005-04-17 16:05:31 -05001260 ndlp->nlp_state = NLP_STE_MAPPED_NODE;
1261 lpfc_nlp_list(phba, ndlp, NLP_MAPPED_LIST);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001262 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001263}
1264
1265/*! lpfc_device_rm_prli_issue
1266 *
1267 * \pre
1268 * \post
1269 * \param phba
1270 * \param ndlp
1271 * \param arg
1272 * \param evt
1273 * \return uint32_t
1274 *
1275 * \b Description:
1276 * This routine is envoked when we a request to remove a nport we are in the
1277 * process of PRLIing. We should software abort outstanding prli, unreg
1278 * login, send a logout. We will change node state to UNUSED_NODE, put it
1279 * on plogi list so it can be freed when LOGO completes.
1280 *
1281 */
1282static uint32_t
1283lpfc_device_rm_prli_issue(struct lpfc_hba * phba,
1284 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1285{
1286 /* software abort outstanding PRLI */
1287 lpfc_els_abort(phba, ndlp, 1);
1288
1289 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001290 return NLP_STE_FREED_NODE;
dea31012005-04-17 16:05:31 -05001291}
1292
1293
1294/*! lpfc_device_recov_prli_issue
1295 *
1296 * \pre
1297 * \post
1298 * \param phba
1299 * \param ndlp
1300 * \param arg
1301 * \param evt
1302 * \return uint32_t
1303 *
1304 * \b Description:
1305 * The routine is envoked when the state of a device is unknown, like
1306 * during a link down. We should remove the nodelist entry from the
1307 * unmapped list, issue a UNREG_LOGIN, do a software abort of the
1308 * outstanding PRLI command, then free the node entry.
1309 */
1310static uint32_t
1311lpfc_device_recov_prli_issue(struct lpfc_hba * phba,
1312 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1313{
1314 /* software abort outstanding PRLI */
1315 lpfc_els_abort(phba, ndlp, 1);
1316
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001317 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
dea31012005-04-17 16:05:31 -05001318 ndlp->nlp_state = NLP_STE_NPR_NODE;
1319 lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
1320 spin_lock_irq(phba->host->host_lock);
1321 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
1322 spin_unlock_irq(phba->host->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001323 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001324}
1325
1326static uint32_t
1327lpfc_rcv_plogi_unmap_node(struct lpfc_hba * phba,
1328 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1329{
1330 struct lpfc_iocbq *cmdiocb;
1331
1332 cmdiocb = (struct lpfc_iocbq *) arg;
1333
1334 lpfc_rcv_plogi(phba, ndlp, cmdiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001335 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001336}
1337
1338static uint32_t
1339lpfc_rcv_prli_unmap_node(struct lpfc_hba * phba,
1340 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1341{
1342 struct lpfc_iocbq *cmdiocb;
1343
1344 cmdiocb = (struct lpfc_iocbq *) arg;
1345
1346 lpfc_rcv_prli(phba, ndlp, cmdiocb);
1347 lpfc_els_rsp_prli_acc(phba, cmdiocb, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001348 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001349}
1350
1351static uint32_t
1352lpfc_rcv_logo_unmap_node(struct lpfc_hba * phba,
1353 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1354{
1355 struct lpfc_iocbq *cmdiocb;
1356
1357 cmdiocb = (struct lpfc_iocbq *) arg;
1358
1359 lpfc_rcv_logo(phba, ndlp, cmdiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001360 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001361}
1362
1363static uint32_t
1364lpfc_rcv_padisc_unmap_node(struct lpfc_hba * phba,
1365 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1366{
1367 struct lpfc_iocbq *cmdiocb;
1368
1369 cmdiocb = (struct lpfc_iocbq *) arg;
1370
1371 lpfc_rcv_padisc(phba, ndlp, cmdiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001372 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001373}
1374
1375static uint32_t
1376lpfc_rcv_prlo_unmap_node(struct lpfc_hba * phba,
1377 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1378{
1379 struct lpfc_iocbq *cmdiocb;
1380
1381 cmdiocb = (struct lpfc_iocbq *) arg;
1382
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001383 lpfc_els_rsp_acc(phba, ELS_CMD_ACC, cmdiocb, ndlp, NULL, 0);
1384 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001385}
1386
1387static uint32_t
1388lpfc_device_recov_unmap_node(struct lpfc_hba * phba,
1389 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1390{
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001391 ndlp->nlp_prev_state = NLP_STE_UNMAPPED_NODE;
dea31012005-04-17 16:05:31 -05001392 ndlp->nlp_state = NLP_STE_NPR_NODE;
1393 lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
1394 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
1395 lpfc_disc_set_adisc(phba, ndlp);
1396
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001397 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001398}
1399
1400static uint32_t
1401lpfc_rcv_plogi_mapped_node(struct lpfc_hba * phba,
1402 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1403{
1404 struct lpfc_iocbq *cmdiocb;
1405
1406 cmdiocb = (struct lpfc_iocbq *) arg;
1407
1408 lpfc_rcv_plogi(phba, ndlp, cmdiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001409 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001410}
1411
1412static uint32_t
1413lpfc_rcv_prli_mapped_node(struct lpfc_hba * phba,
1414 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1415{
1416 struct lpfc_iocbq *cmdiocb;
1417
1418 cmdiocb = (struct lpfc_iocbq *) arg;
1419
1420 lpfc_els_rsp_prli_acc(phba, cmdiocb, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001421 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001422}
1423
1424static uint32_t
1425lpfc_rcv_logo_mapped_node(struct lpfc_hba * phba,
1426 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1427{
1428 struct lpfc_iocbq *cmdiocb;
1429
1430 cmdiocb = (struct lpfc_iocbq *) arg;
1431
1432 lpfc_rcv_logo(phba, ndlp, cmdiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001433 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001434}
1435
1436static uint32_t
1437lpfc_rcv_padisc_mapped_node(struct lpfc_hba * phba,
1438 struct lpfc_nodelist * ndlp, void *arg,
1439 uint32_t evt)
1440{
1441 struct lpfc_iocbq *cmdiocb;
1442
1443 cmdiocb = (struct lpfc_iocbq *) arg;
1444
1445 lpfc_rcv_padisc(phba, ndlp, cmdiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001446 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001447}
1448
1449static uint32_t
1450lpfc_rcv_prlo_mapped_node(struct lpfc_hba * phba,
1451 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1452{
1453 struct lpfc_iocbq *cmdiocb;
1454
1455 cmdiocb = (struct lpfc_iocbq *) arg;
1456
1457 /* flush the target */
1458 spin_lock_irq(phba->host->host_lock);
1459 lpfc_sli_abort_iocb(phba, &phba->sli.ring[phba->sli.fcp_ring],
1460 ndlp->nlp_sid, 0, 0, LPFC_CTX_TGT);
1461 spin_unlock_irq(phba->host->host_lock);
1462
1463 /* Treat like rcv logo */
1464 lpfc_rcv_logo(phba, ndlp, cmdiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001465 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001466}
1467
1468static uint32_t
1469lpfc_device_recov_mapped_node(struct lpfc_hba * phba,
1470 struct lpfc_nodelist * ndlp, void *arg,
1471 uint32_t evt)
1472{
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001473 ndlp->nlp_prev_state = NLP_STE_MAPPED_NODE;
dea31012005-04-17 16:05:31 -05001474 ndlp->nlp_state = NLP_STE_NPR_NODE;
1475 lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
1476 spin_lock_irq(phba->host->host_lock);
1477 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
1478 spin_unlock_irq(phba->host->host_lock);
1479 lpfc_disc_set_adisc(phba, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001480 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001481}
1482
1483static uint32_t
1484lpfc_rcv_plogi_npr_node(struct lpfc_hba * phba,
1485 struct lpfc_nodelist * ndlp, void *arg,
1486 uint32_t evt)
1487{
1488 struct lpfc_iocbq *cmdiocb;
1489
1490 cmdiocb = (struct lpfc_iocbq *) arg;
1491
1492 /* Ignore PLOGI if we have an outstanding LOGO */
1493 if (ndlp->nlp_flag & NLP_LOGO_SND) {
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001494 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001495 }
1496
1497 if (lpfc_rcv_plogi(phba, ndlp, cmdiocb)) {
1498 spin_lock_irq(phba->host->host_lock);
1499 ndlp->nlp_flag &= ~(NLP_NPR_ADISC | NLP_NPR_2B_DISC);
1500 spin_unlock_irq(phba->host->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001501 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001502 }
1503
1504 /* send PLOGI immediately, move to PLOGI issue state */
1505 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001506 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
dea31012005-04-17 16:05:31 -05001507 ndlp->nlp_state = NLP_STE_PLOGI_ISSUE;
1508 lpfc_nlp_list(phba, ndlp, NLP_PLOGI_LIST);
1509 lpfc_issue_els_plogi(phba, ndlp, 0);
1510 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001511 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001512}
1513
1514static uint32_t
1515lpfc_rcv_prli_npr_node(struct lpfc_hba * phba,
1516 struct lpfc_nodelist * ndlp, void *arg,
1517 uint32_t evt)
1518{
1519 struct lpfc_iocbq *cmdiocb;
1520 struct ls_rjt stat;
1521
1522 cmdiocb = (struct lpfc_iocbq *) arg;
1523
1524 memset(&stat, 0, sizeof (struct ls_rjt));
1525 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
1526 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
1527 lpfc_els_rsp_reject(phba, stat.un.lsRjtError, cmdiocb, ndlp);
1528
1529 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
1530 if (ndlp->nlp_flag & NLP_NPR_ADISC) {
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001531 spin_lock_irq(phba->host->host_lock);
1532 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
1533 spin_unlock_irq(phba->host->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001534 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
dea31012005-04-17 16:05:31 -05001535 ndlp->nlp_state = NLP_STE_ADISC_ISSUE;
1536 lpfc_nlp_list(phba, ndlp, NLP_ADISC_LIST);
1537 lpfc_issue_els_adisc(phba, ndlp, 0);
1538 } else {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001539 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
dea31012005-04-17 16:05:31 -05001540 ndlp->nlp_state = NLP_STE_PLOGI_ISSUE;
1541 lpfc_nlp_list(phba, ndlp, NLP_PLOGI_LIST);
1542 lpfc_issue_els_plogi(phba, ndlp, 0);
1543 }
1544 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001545 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001546}
1547
1548static uint32_t
1549lpfc_rcv_logo_npr_node(struct lpfc_hba * phba,
1550 struct lpfc_nodelist * ndlp, void *arg,
1551 uint32_t evt)
1552{
1553 struct lpfc_iocbq *cmdiocb;
1554
1555 cmdiocb = (struct lpfc_iocbq *) arg;
1556
1557 lpfc_rcv_logo(phba, ndlp, cmdiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001558 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001559}
1560
1561static uint32_t
1562lpfc_rcv_padisc_npr_node(struct lpfc_hba * phba,
1563 struct lpfc_nodelist * ndlp, void *arg,
1564 uint32_t evt)
1565{
1566 struct lpfc_iocbq *cmdiocb;
1567
1568 cmdiocb = (struct lpfc_iocbq *) arg;
1569
1570 lpfc_rcv_padisc(phba, ndlp, cmdiocb);
1571
1572 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
1573 if (ndlp->nlp_flag & NLP_NPR_ADISC) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001574 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
dea31012005-04-17 16:05:31 -05001575 ndlp->nlp_state = NLP_STE_ADISC_ISSUE;
1576 lpfc_nlp_list(phba, ndlp, NLP_ADISC_LIST);
1577 lpfc_issue_els_adisc(phba, ndlp, 0);
1578 } else {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001579 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
dea31012005-04-17 16:05:31 -05001580 ndlp->nlp_state = NLP_STE_PLOGI_ISSUE;
1581 lpfc_nlp_list(phba, ndlp, NLP_PLOGI_LIST);
1582 lpfc_issue_els_plogi(phba, ndlp, 0);
1583 }
1584 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001585 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001586}
1587
1588static uint32_t
1589lpfc_rcv_prlo_npr_node(struct lpfc_hba * phba,
1590 struct lpfc_nodelist * ndlp, void *arg,
1591 uint32_t evt)
1592{
1593 struct lpfc_iocbq *cmdiocb;
1594
1595 cmdiocb = (struct lpfc_iocbq *) arg;
1596
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001597 spin_lock_irq(phba->host->host_lock);
1598 ndlp->nlp_flag |= NLP_LOGO_ACC;
1599 spin_unlock_irq(phba->host->host_lock);
1600
dea31012005-04-17 16:05:31 -05001601 lpfc_els_rsp_acc(phba, ELS_CMD_ACC, cmdiocb, ndlp, NULL, 0);
1602
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001603 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
1604 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ * 1);
1605 spin_lock_irq(phba->host->host_lock);
1606 ndlp->nlp_flag |= NLP_DELAY_TMO;
1607 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
1608 spin_unlock_irq(phba->host->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001609 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001610 } else {
1611 spin_lock_irq(phba->host->host_lock);
1612 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
1613 spin_unlock_irq(phba->host->host_lock);
dea31012005-04-17 16:05:31 -05001614 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001615 return ndlp->nlp_state;
1616}
dea31012005-04-17 16:05:31 -05001617
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001618static uint32_t
1619lpfc_cmpl_plogi_npr_node(struct lpfc_hba * phba,
1620 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1621{
1622 struct lpfc_iocbq *cmdiocb, *rspiocb;
1623
1624 cmdiocb = (struct lpfc_iocbq *) arg;
1625 rspiocb = cmdiocb->context_un.rsp_iocb;
1626 return ndlp->nlp_state;
1627}
1628
1629static uint32_t
1630lpfc_cmpl_prli_npr_node(struct lpfc_hba * phba,
1631 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1632{
1633 struct lpfc_iocbq *cmdiocb, *rspiocb;
1634
1635 cmdiocb = (struct lpfc_iocbq *) arg;
1636 rspiocb = cmdiocb->context_un.rsp_iocb;
1637 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001638}
1639
1640static uint32_t
1641lpfc_cmpl_logo_npr_node(struct lpfc_hba * phba,
1642 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1643{
1644 lpfc_unreg_rpi(phba, ndlp);
1645 /* This routine does nothing, just return the current state */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001646 return ndlp->nlp_state;
1647}
1648
1649static uint32_t
1650lpfc_cmpl_adisc_npr_node(struct lpfc_hba * phba,
1651 struct lpfc_nodelist * ndlp, void *arg,
1652 uint32_t evt)
1653{
1654 struct lpfc_iocbq *cmdiocb, *rspiocb;
1655
1656 cmdiocb = (struct lpfc_iocbq *) arg;
1657 rspiocb = cmdiocb->context_un.rsp_iocb;
1658 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001659}
1660
1661static uint32_t
1662lpfc_cmpl_reglogin_npr_node(struct lpfc_hba * phba,
1663 struct lpfc_nodelist * ndlp, void *arg,
1664 uint32_t evt)
1665{
1666 LPFC_MBOXQ_t *pmb;
1667 MAILBOX_t *mb;
1668
1669 pmb = (LPFC_MBOXQ_t *) arg;
1670 mb = &pmb->mb;
1671
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001672 if (!mb->mbxStatus)
1673 ndlp->nlp_rpi = mb->un.varWords[0];
dea31012005-04-17 16:05:31 -05001674
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001675 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001676}
1677
1678static uint32_t
1679lpfc_device_rm_npr_node(struct lpfc_hba * phba,
1680 struct lpfc_nodelist * ndlp, void *arg,
1681 uint32_t evt)
1682{
1683 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001684 return NLP_STE_FREED_NODE;
dea31012005-04-17 16:05:31 -05001685}
1686
1687static uint32_t
1688lpfc_device_recov_npr_node(struct lpfc_hba * phba,
1689 struct lpfc_nodelist * ndlp, void *arg,
1690 uint32_t evt)
1691{
1692 spin_lock_irq(phba->host->host_lock);
1693 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05001694 if (ndlp->nlp_flag & NLP_DELAY_TMO) {
1695 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
1696 if (!list_empty(&ndlp->els_retry_evt.evt_listp))
1697 list_del_init(&ndlp->els_retry_evt.evt_listp);
1698 spin_unlock_irq(phba->host->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001699 ndlp->nlp_last_elscmd = 0;
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05001700 del_timer_sync(&ndlp->nlp_delayfunc);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001701 return ndlp->nlp_state;
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05001702 }
dea31012005-04-17 16:05:31 -05001703 spin_unlock_irq(phba->host->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001704 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001705}
1706
1707
1708/* This next section defines the NPort Discovery State Machine */
1709
1710/* There are 4 different double linked lists nodelist entries can reside on.
1711 * The plogi list and adisc list are used when Link Up discovery or RSCN
1712 * processing is needed. Each list holds the nodes that we will send PLOGI
1713 * or ADISC on. These lists will keep track of what nodes will be effected
1714 * by an RSCN, or a Link Up (Typically, all nodes are effected on Link Up).
1715 * The unmapped_list will contain all nodes that we have successfully logged
1716 * into at the Fibre Channel level. The mapped_list will contain all nodes
1717 * that are mapped FCP targets.
1718 */
1719/*
1720 * The bind list is a list of undiscovered (potentially non-existent) nodes
1721 * that we have saved binding information on. This information is used when
1722 * nodes transition from the unmapped to the mapped list.
1723 */
1724/* For UNUSED_NODE state, the node has just been allocated .
1725 * For PLOGI_ISSUE and REG_LOGIN_ISSUE, the node is on
1726 * the PLOGI list. For REG_LOGIN_COMPL, the node is taken off the PLOGI list
1727 * and put on the unmapped list. For ADISC processing, the node is taken off
1728 * the ADISC list and placed on either the mapped or unmapped list (depending
1729 * on its previous state). Once on the unmapped list, a PRLI is issued and the
1730 * state changed to PRLI_ISSUE. When the PRLI completion occurs, the state is
1731 * changed to UNMAPPED_NODE. If the completion indicates a mapped
1732 * node, the node is taken off the unmapped list. The binding list is checked
1733 * for a valid binding, or a binding is automatically assigned. If binding
1734 * assignment is unsuccessful, the node is left on the unmapped list. If
1735 * binding assignment is successful, the associated binding list entry (if
1736 * any) is removed, and the node is placed on the mapped list.
1737 */
1738/*
1739 * For a Link Down, all nodes on the ADISC, PLOGI, unmapped or mapped
1740 * lists will receive a DEVICE_RECOVERY event. If the linkdown or nodev timers
1741 * expire, all effected nodes will receive a DEVICE_RM event.
1742 */
1743/*
1744 * For a Link Up or RSCN, all nodes will move from the mapped / unmapped lists
1745 * to either the ADISC or PLOGI list. After a Nameserver query or ALPA loopmap
1746 * check, additional nodes may be added or removed (via DEVICE_RM) to / from
1747 * the PLOGI or ADISC lists. Once the PLOGI and ADISC lists are populated,
1748 * we will first process the ADISC list. 32 entries are processed initially and
1749 * ADISC is initited for each one. Completions / Events for each node are
1750 * funnelled thru the state machine. As each node finishes ADISC processing, it
1751 * starts ADISC for any nodes waiting for ADISC processing. If no nodes are
1752 * waiting, and the ADISC list count is identically 0, then we are done. For
1753 * Link Up discovery, since all nodes on the PLOGI list are UNREG_LOGIN'ed, we
1754 * can issue a CLEAR_LA and reenable Link Events. Next we will process the PLOGI
1755 * list. 32 entries are processed initially and PLOGI is initited for each one.
1756 * Completions / Events for each node are funnelled thru the state machine. As
1757 * each node finishes PLOGI processing, it starts PLOGI for any nodes waiting
1758 * for PLOGI processing. If no nodes are waiting, and the PLOGI list count is
1759 * indentically 0, then we are done. We have now completed discovery / RSCN
1760 * handling. Upon completion, ALL nodes should be on either the mapped or
1761 * unmapped lists.
1762 */
1763
1764static uint32_t (*lpfc_disc_action[NLP_STE_MAX_STATE * NLP_EVT_MAX_EVENT])
1765 (struct lpfc_hba *, struct lpfc_nodelist *, void *, uint32_t) = {
1766 /* Action routine Event Current State */
1767 lpfc_rcv_plogi_unused_node, /* RCV_PLOGI UNUSED_NODE */
1768 lpfc_rcv_els_unused_node, /* RCV_PRLI */
1769 lpfc_rcv_logo_unused_node, /* RCV_LOGO */
1770 lpfc_rcv_els_unused_node, /* RCV_ADISC */
1771 lpfc_rcv_els_unused_node, /* RCV_PDISC */
1772 lpfc_rcv_els_unused_node, /* RCV_PRLO */
1773 lpfc_disc_illegal, /* CMPL_PLOGI */
1774 lpfc_disc_illegal, /* CMPL_PRLI */
1775 lpfc_cmpl_logo_unused_node, /* CMPL_LOGO */
1776 lpfc_disc_illegal, /* CMPL_ADISC */
1777 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
1778 lpfc_device_rm_unused_node, /* DEVICE_RM */
1779 lpfc_disc_illegal, /* DEVICE_RECOVERY */
1780
1781 lpfc_rcv_plogi_plogi_issue, /* RCV_PLOGI PLOGI_ISSUE */
1782 lpfc_rcv_els_plogi_issue, /* RCV_PRLI */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001783 lpfc_rcv_logo_plogi_issue, /* RCV_LOGO */
dea31012005-04-17 16:05:31 -05001784 lpfc_rcv_els_plogi_issue, /* RCV_ADISC */
1785 lpfc_rcv_els_plogi_issue, /* RCV_PDISC */
1786 lpfc_rcv_els_plogi_issue, /* RCV_PRLO */
1787 lpfc_cmpl_plogi_plogi_issue, /* CMPL_PLOGI */
1788 lpfc_disc_illegal, /* CMPL_PRLI */
1789 lpfc_disc_illegal, /* CMPL_LOGO */
1790 lpfc_disc_illegal, /* CMPL_ADISC */
1791 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
1792 lpfc_device_rm_plogi_issue, /* DEVICE_RM */
1793 lpfc_device_recov_plogi_issue, /* DEVICE_RECOVERY */
1794
1795 lpfc_rcv_plogi_adisc_issue, /* RCV_PLOGI ADISC_ISSUE */
1796 lpfc_rcv_prli_adisc_issue, /* RCV_PRLI */
1797 lpfc_rcv_logo_adisc_issue, /* RCV_LOGO */
1798 lpfc_rcv_padisc_adisc_issue, /* RCV_ADISC */
1799 lpfc_rcv_padisc_adisc_issue, /* RCV_PDISC */
1800 lpfc_rcv_prlo_adisc_issue, /* RCV_PRLO */
1801 lpfc_disc_illegal, /* CMPL_PLOGI */
1802 lpfc_disc_illegal, /* CMPL_PRLI */
1803 lpfc_disc_illegal, /* CMPL_LOGO */
1804 lpfc_cmpl_adisc_adisc_issue, /* CMPL_ADISC */
1805 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
1806 lpfc_device_rm_adisc_issue, /* DEVICE_RM */
1807 lpfc_device_recov_adisc_issue, /* DEVICE_RECOVERY */
1808
1809 lpfc_rcv_plogi_reglogin_issue, /* RCV_PLOGI REG_LOGIN_ISSUE */
1810 lpfc_rcv_prli_reglogin_issue, /* RCV_PLOGI */
1811 lpfc_rcv_logo_reglogin_issue, /* RCV_LOGO */
1812 lpfc_rcv_padisc_reglogin_issue, /* RCV_ADISC */
1813 lpfc_rcv_padisc_reglogin_issue, /* RCV_PDISC */
1814 lpfc_rcv_prlo_reglogin_issue, /* RCV_PRLO */
1815 lpfc_disc_illegal, /* CMPL_PLOGI */
1816 lpfc_disc_illegal, /* CMPL_PRLI */
1817 lpfc_disc_illegal, /* CMPL_LOGO */
1818 lpfc_disc_illegal, /* CMPL_ADISC */
1819 lpfc_cmpl_reglogin_reglogin_issue,/* CMPL_REG_LOGIN */
1820 lpfc_device_rm_reglogin_issue, /* DEVICE_RM */
1821 lpfc_device_recov_reglogin_issue,/* DEVICE_RECOVERY */
1822
1823 lpfc_rcv_plogi_prli_issue, /* RCV_PLOGI PRLI_ISSUE */
1824 lpfc_rcv_prli_prli_issue, /* RCV_PRLI */
1825 lpfc_rcv_logo_prli_issue, /* RCV_LOGO */
1826 lpfc_rcv_padisc_prli_issue, /* RCV_ADISC */
1827 lpfc_rcv_padisc_prli_issue, /* RCV_PDISC */
1828 lpfc_rcv_prlo_prli_issue, /* RCV_PRLO */
1829 lpfc_disc_illegal, /* CMPL_PLOGI */
1830 lpfc_cmpl_prli_prli_issue, /* CMPL_PRLI */
1831 lpfc_disc_illegal, /* CMPL_LOGO */
1832 lpfc_disc_illegal, /* CMPL_ADISC */
1833 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
1834 lpfc_device_rm_prli_issue, /* DEVICE_RM */
1835 lpfc_device_recov_prli_issue, /* DEVICE_RECOVERY */
1836
1837 lpfc_rcv_plogi_unmap_node, /* RCV_PLOGI UNMAPPED_NODE */
1838 lpfc_rcv_prli_unmap_node, /* RCV_PRLI */
1839 lpfc_rcv_logo_unmap_node, /* RCV_LOGO */
1840 lpfc_rcv_padisc_unmap_node, /* RCV_ADISC */
1841 lpfc_rcv_padisc_unmap_node, /* RCV_PDISC */
1842 lpfc_rcv_prlo_unmap_node, /* RCV_PRLO */
1843 lpfc_disc_illegal, /* CMPL_PLOGI */
1844 lpfc_disc_illegal, /* CMPL_PRLI */
1845 lpfc_disc_illegal, /* CMPL_LOGO */
1846 lpfc_disc_illegal, /* CMPL_ADISC */
1847 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
1848 lpfc_disc_illegal, /* DEVICE_RM */
1849 lpfc_device_recov_unmap_node, /* DEVICE_RECOVERY */
1850
1851 lpfc_rcv_plogi_mapped_node, /* RCV_PLOGI MAPPED_NODE */
1852 lpfc_rcv_prli_mapped_node, /* RCV_PRLI */
1853 lpfc_rcv_logo_mapped_node, /* RCV_LOGO */
1854 lpfc_rcv_padisc_mapped_node, /* RCV_ADISC */
1855 lpfc_rcv_padisc_mapped_node, /* RCV_PDISC */
1856 lpfc_rcv_prlo_mapped_node, /* RCV_PRLO */
1857 lpfc_disc_illegal, /* CMPL_PLOGI */
1858 lpfc_disc_illegal, /* CMPL_PRLI */
1859 lpfc_disc_illegal, /* CMPL_LOGO */
1860 lpfc_disc_illegal, /* CMPL_ADISC */
1861 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
1862 lpfc_disc_illegal, /* DEVICE_RM */
1863 lpfc_device_recov_mapped_node, /* DEVICE_RECOVERY */
1864
1865 lpfc_rcv_plogi_npr_node, /* RCV_PLOGI NPR_NODE */
1866 lpfc_rcv_prli_npr_node, /* RCV_PRLI */
1867 lpfc_rcv_logo_npr_node, /* RCV_LOGO */
1868 lpfc_rcv_padisc_npr_node, /* RCV_ADISC */
1869 lpfc_rcv_padisc_npr_node, /* RCV_PDISC */
1870 lpfc_rcv_prlo_npr_node, /* RCV_PRLO */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001871 lpfc_cmpl_plogi_npr_node, /* CMPL_PLOGI */
1872 lpfc_cmpl_prli_npr_node, /* CMPL_PRLI */
dea31012005-04-17 16:05:31 -05001873 lpfc_cmpl_logo_npr_node, /* CMPL_LOGO */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001874 lpfc_cmpl_adisc_npr_node, /* CMPL_ADISC */
dea31012005-04-17 16:05:31 -05001875 lpfc_cmpl_reglogin_npr_node, /* CMPL_REG_LOGIN */
1876 lpfc_device_rm_npr_node, /* DEVICE_RM */
1877 lpfc_device_recov_npr_node, /* DEVICE_RECOVERY */
1878};
1879
1880int
1881lpfc_disc_state_machine(struct lpfc_hba * phba,
1882 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1883{
1884 uint32_t cur_state, rc;
1885 uint32_t(*func) (struct lpfc_hba *, struct lpfc_nodelist *, void *,
1886 uint32_t);
1887
1888 ndlp->nlp_disc_refcnt++;
1889 cur_state = ndlp->nlp_state;
1890
1891 /* DSM in event <evt> on NPort <nlp_DID> in state <cur_state> */
1892 lpfc_printf_log(phba,
1893 KERN_INFO,
1894 LOG_DISCOVERY,
1895 "%d:0211 DSM in event x%x on NPort x%x in state %d "
1896 "Data: x%x\n",
1897 phba->brd_no,
1898 evt, ndlp->nlp_DID, cur_state, ndlp->nlp_flag);
1899
1900 func = lpfc_disc_action[(cur_state * NLP_EVT_MAX_EVENT) + evt];
1901 rc = (func) (phba, ndlp, arg, evt);
1902
1903 /* DSM out state <rc> on NPort <nlp_DID> */
1904 lpfc_printf_log(phba,
1905 KERN_INFO,
1906 LOG_DISCOVERY,
1907 "%d:0212 DSM out state %d on NPort x%x Data: x%x\n",
1908 phba->brd_no,
1909 rc, ndlp->nlp_DID, ndlp->nlp_flag);
1910
1911 ndlp->nlp_disc_refcnt--;
1912
1913 /* Check to see if ndlp removal is deferred */
1914 if ((ndlp->nlp_disc_refcnt == 0)
1915 && (ndlp->nlp_flag & NLP_DELAY_REMOVE)) {
1916 spin_lock_irq(phba->host->host_lock);
1917 ndlp->nlp_flag &= ~NLP_DELAY_REMOVE;
1918 spin_unlock_irq(phba->host->host_lock);
1919 lpfc_nlp_remove(phba, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001920 return NLP_STE_FREED_NODE;
dea31012005-04-17 16:05:31 -05001921 }
1922 if (rc == NLP_STE_FREED_NODE)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001923 return NLP_STE_FREED_NODE;
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001924 return rc;
dea31012005-04-17 16:05:31 -05001925}