1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2004-2005 Emulex. All rights reserved. *
5 * EMULEX and SLI are trademarks of Emulex. *
7 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
9 * This program is free software; you can redistribute it and/or *
10 * 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. *
20 *******************************************************************/
22 #include <linux/blkdev.h>
23 #include <linux/pci.h>
24 #include <linux/interrupt.h>
26 #include <scsi/scsi.h>
27 #include <scsi/scsi_device.h>
28 #include <scsi/scsi_host.h>
29 #include <scsi/scsi_transport_fc.h>
33 #include "lpfc_disc.h"
34 #include "lpfc_scsi.h"
36 #include "lpfc_logmsg.h"
37 #include "lpfc_crtn.h"
40 /* Called to verify a rcv'ed ADISC was intended for us. */
42 lpfc_check_adisc(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp,
43 struct lpfc_name * nn, struct lpfc_name * pn)
45 /* Compare the ADISC rsp WWNN / WWPN matches our internal node
46 * table entry for that node.
48 if (memcmp(nn, &ndlp->nlp_nodename, sizeof (struct lpfc_name)) != 0)
51 if (memcmp(pn, &ndlp->nlp_portname, sizeof (struct lpfc_name)) != 0)
54 /* we match, return success */
59 lpfc_check_sparm(struct lpfc_hba * phba,
60 struct lpfc_nodelist * ndlp, struct serv_parm * sp,
63 volatile struct serv_parm *hsp = &phba->fc_sparam;
64 uint16_t hsp_value, ssp_value = 0;
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.
73 if (sp->cls1.classValid) {
74 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) {
79 sp->cls1.rcvDataSizeLsb = hsp->cls1.rcvDataSizeLsb;
80 sp->cls1.rcvDataSizeMsb = hsp->cls1.rcvDataSizeMsb;
82 } else if (class == CLASS1) {
86 if (sp->cls2.classValid) {
87 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) {
92 sp->cls2.rcvDataSizeLsb = hsp->cls2.rcvDataSizeLsb;
93 sp->cls2.rcvDataSizeMsb = hsp->cls2.rcvDataSizeMsb;
95 } else if (class == CLASS2) {
99 if (sp->cls3.classValid) {
100 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) {
105 sp->cls3.rcvDataSizeLsb = hsp->cls3.rcvDataSizeLsb;
106 sp->cls3.rcvDataSizeMsb = hsp->cls3.rcvDataSizeMsb;
108 } else if (class == CLASS3) {
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.
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) {
120 sp->cmn.bbRcvSizeLsb = hsp->cmn.bbRcvSizeLsb;
121 sp->cmn.bbRcvSizeMsb = (sp->cmn.bbRcvSizeMsb & 0xF0) |
122 (hsp->cmn.bbRcvSizeMsb & 0x0F);
125 memcpy(&ndlp->nlp_nodename, &sp->nodeName, sizeof (struct lpfc_name));
126 memcpy(&ndlp->nlp_portname, &sp->portName, sizeof (struct lpfc_name));
131 lpfc_check_elscmpl_iocb(struct lpfc_hba * phba,
132 struct lpfc_iocbq *cmdiocb,
133 struct lpfc_iocbq *rspiocb)
135 struct lpfc_dmabuf *pcmd, *prsp;
140 irsp = &rspiocb->iocb;
141 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
143 /* For lpfc_els_abort, context2 could be zero'ed to delay
144 * freeing associated memory till after ABTS completes.
147 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf,
150 lp = (uint32_t *) prsp->virt;
151 ptr = (void *)((uint8_t *)lp + sizeof(uint32_t));
155 /* Force ulpStatus error since we are returning NULL ptr */
156 if (!(irsp->ulpStatus)) {
157 irsp->ulpStatus = IOSTAT_LOCAL_REJECT;
158 irsp->un.ulpWord[4] = IOERR_SLI_ABORTED;
167 * Free resources / clean up outstanding I/Os
168 * associated with a LPFC_NODELIST entry. This
169 * routine effectively results in a "software abort".
172 lpfc_els_abort(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp,
175 struct lpfc_sli *psli;
176 struct lpfc_sli_ring *pring;
177 struct lpfc_iocbq *iocb, *next_iocb;
181 /* Abort outstanding I/O on NPort <nlp_DID> */
182 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
183 "%d:0201 Abort outstanding I/O on NPort x%x "
184 "Data: x%x x%x x%x\n",
185 phba->brd_no, ndlp->nlp_DID, ndlp->nlp_flag,
186 ndlp->nlp_state, ndlp->nlp_rpi);
189 pring = &psli->ring[LPFC_ELS_RING];
191 /* First check the txq */
194 spin_lock_irq(phba->host->host_lock);
195 list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
196 /* Check to see if iocb matches the nport we are looking
198 if ((lpfc_check_sli_ndlp(phba, pring, iocb, ndlp))) {
200 /* It matches, so deque and call compl with an
202 list_del(&iocb->list);
204 if (iocb->iocb_cmpl) {
206 icmd->ulpStatus = IOSTAT_LOCAL_REJECT;
207 icmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
208 spin_unlock_irq(phba->host->host_lock);
209 (iocb->iocb_cmpl) (phba, iocb, iocb);
210 spin_lock_irq(phba->host->host_lock);
212 lpfc_sli_release_iocbq(phba, iocb);
216 spin_unlock_irq(phba->host->host_lock);
219 /* Everything on txcmplq will be returned by firmware
220 * with a no rpi / linkdown / abort error. For ring 0,
221 * ELS discovery, we want to get rid of it right here.
223 /* Next check the txcmplq */
226 spin_lock_irq(phba->host->host_lock);
227 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq,
229 /* Check to see if iocb matches the nport we are looking
231 if ((lpfc_check_sli_ndlp (phba, pring, iocb, ndlp))) {
233 /* It matches, so deque and call compl with an
235 list_del(&iocb->list);
236 pring->txcmplq_cnt--;
239 /* If the driver is completing an ELS
240 * command early, flush it out of the firmware.
243 (icmd->ulpCommand == CMD_ELS_REQUEST64_CR) &&
244 (icmd->un.elsreq64.bdl.ulpIoTag32)) {
245 lpfc_sli_issue_abort_iotag32(phba,
248 if (iocb->iocb_cmpl) {
249 icmd->ulpStatus = IOSTAT_LOCAL_REJECT;
250 icmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
251 spin_unlock_irq(phba->host->host_lock);
252 (iocb->iocb_cmpl) (phba, iocb, iocb);
253 spin_lock_irq(phba->host->host_lock);
255 lpfc_sli_release_iocbq(phba, iocb);
259 spin_unlock_irq(phba->host->host_lock);
262 /* If we are delaying issuing an ELS command, cancel it */
263 if (ndlp->nlp_flag & NLP_DELAY_TMO) {
264 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
265 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);
273 lpfc_rcv_plogi(struct lpfc_hba * phba,
274 struct lpfc_nodelist * ndlp,
275 struct lpfc_iocbq *cmdiocb)
277 struct lpfc_dmabuf *pcmd;
280 struct serv_parm *sp;
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.
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.
298 phba->fc_edtov = FF_DEF_EDTOV;
299 phba->fc_ratov = FF_DEF_RATOV;
300 /* Start discovery - this should just do
302 lpfc_disc_start(phba);
305 lpfc_initial_flogi(phba);
309 stat.un.b.lsRjtRsnCode = LSRJT_LOGICAL_BSY;
310 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
311 lpfc_els_rsp_reject(phba, stat.un.lsRjtError, cmdiocb,
316 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
317 lp = (uint32_t *) pcmd->virt;
318 sp = (struct serv_parm *) ((uint8_t *) lp + sizeof (uint32_t));
319 if ((lpfc_check_sparm(phba, ndlp, sp, CLASS3) == 0)) {
320 /* Reject this request because invalid parameters */
321 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
322 stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
323 lpfc_els_rsp_reject(phba, stat.un.lsRjtError, cmdiocb, ndlp);
326 icmd = &cmdiocb->iocb;
328 /* PLOGI chkparm OK */
329 lpfc_printf_log(phba,
332 "%d:0114 PLOGI chkparm OK Data: x%x x%x x%x x%x\n",
334 ndlp->nlp_DID, ndlp->nlp_state, ndlp->nlp_flag,
337 if ((phba->cfg_fcp_class == 2) &&
338 (sp->cls2.classValid)) {
339 ndlp->nlp_fcp_info |= CLASS2;
341 ndlp->nlp_fcp_info |= CLASS3;
343 ndlp->nlp_class_sup = 0;
344 if (sp->cls1.classValid)
345 ndlp->nlp_class_sup |= FC_COS_CLASS1;
346 if (sp->cls2.classValid)
347 ndlp->nlp_class_sup |= FC_COS_CLASS2;
348 if (sp->cls3.classValid)
349 ndlp->nlp_class_sup |= FC_COS_CLASS3;
350 if (sp->cls4.classValid)
351 ndlp->nlp_class_sup |= FC_COS_CLASS4;
353 ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) | sp->cmn.bbRcvSizeLsb;
355 /* no need to reg_login if we are already in one of these states */
356 switch(ndlp->nlp_state) {
357 case NLP_STE_NPR_NODE:
358 if (!(ndlp->nlp_flag & NLP_NPR_ADISC))
360 case NLP_STE_REG_LOGIN_ISSUE:
361 case NLP_STE_PRLI_ISSUE:
362 case NLP_STE_UNMAPPED_NODE:
363 case NLP_STE_MAPPED_NODE:
364 lpfc_els_rsp_acc(phba, ELS_CMD_PLOGI, cmdiocb, ndlp, NULL, 0);
368 if ((phba->fc_flag & FC_PT2PT)
369 && !(phba->fc_flag & FC_PT2PT_PLOGI)) {
370 /* rcv'ed PLOGI decides what our NPortId will be */
371 phba->fc_myDID = icmd->un.rcvels.parmRo;
372 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
375 lpfc_config_link(phba, mbox);
376 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
377 rc = lpfc_sli_issue_mbox
378 (phba, mbox, (MBX_NOWAIT | MBX_STOP_IOCB));
379 if (rc == MBX_NOT_FINISHED) {
380 mempool_free( mbox, phba->mbox_mem_pool);
384 lpfc_can_disctmo(phba);
386 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
390 if (lpfc_reg_login(phba, icmd->un.rcvels.remoteID,
391 (uint8_t *) sp, mbox, 0)) {
392 mempool_free( mbox, phba->mbox_mem_pool);
396 /* ACC PLOGI rsp command needs to execute first,
397 * queue this mbox command to be processed later.
399 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
400 mbox->context2 = ndlp;
401 ndlp->nlp_flag |= NLP_ACC_REGLOGIN;
403 /* If there is an outstanding PLOGI issued, abort it before
404 * sending ACC rsp to PLOGI recieved.
406 if (ndlp->nlp_state == NLP_STE_PLOGI_ISSUE) {
407 /* software abort outstanding PLOGI */
408 lpfc_els_abort(phba, ndlp, 1);
410 ndlp->nlp_flag |= NLP_RCV_PLOGI;
411 lpfc_els_rsp_acc(phba, ELS_CMD_PLOGI, cmdiocb, ndlp, mbox, 0);
415 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
416 stat.un.b.lsRjtRsnCodeExp = LSEXP_OUT_OF_RESOURCE;
417 lpfc_els_rsp_reject(phba, stat.un.lsRjtError, cmdiocb, ndlp);
422 lpfc_rcv_padisc(struct lpfc_hba * phba,
423 struct lpfc_nodelist * ndlp,
424 struct lpfc_iocbq *cmdiocb)
426 struct lpfc_dmabuf *pcmd;
427 struct serv_parm *sp;
428 struct lpfc_name *pnn, *ppn;
435 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
436 lp = (uint32_t *) pcmd->virt;
439 if (cmd == ELS_CMD_ADISC) {
441 pnn = (struct lpfc_name *) & ap->nodeName;
442 ppn = (struct lpfc_name *) & ap->portName;
444 sp = (struct serv_parm *) lp;
445 pnn = (struct lpfc_name *) & sp->nodeName;
446 ppn = (struct lpfc_name *) & sp->portName;
449 icmd = &cmdiocb->iocb;
450 if ((icmd->ulpStatus == 0) &&
451 (lpfc_check_adisc(phba, ndlp, pnn, ppn))) {
452 if (cmd == ELS_CMD_ADISC) {
453 lpfc_els_rsp_adisc_acc(phba, cmdiocb, ndlp);
456 lpfc_els_rsp_acc(phba, ELS_CMD_PLOGI, cmdiocb, ndlp,
461 /* Reject this request because invalid parameters */
462 stat.un.b.lsRjtRsvd0 = 0;
463 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
464 stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
465 stat.un.b.vendorUnique = 0;
466 lpfc_els_rsp_reject(phba, stat.un.lsRjtError, cmdiocb, ndlp);
468 ndlp->nlp_last_elscmd = (unsigned long)ELS_CMD_PLOGI;
470 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ);
472 spin_lock_irq(phba->host->host_lock);
473 ndlp->nlp_flag |= NLP_DELAY_TMO;
474 spin_unlock_irq(phba->host->host_lock);
475 ndlp->nlp_state = NLP_STE_NPR_NODE;
476 lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
481 lpfc_rcv_logo(struct lpfc_hba * phba,
482 struct lpfc_nodelist * ndlp,
483 struct lpfc_iocbq *cmdiocb)
485 /* Put ndlp on NPR list with 1 sec timeout for plogi, ACC logo */
486 /* Only call LOGO ACC for first LOGO, this avoids sending unnecessary
487 * PLOGIs during LOGO storms from a device.
489 ndlp->nlp_flag |= NLP_LOGO_ACC;
490 lpfc_els_rsp_acc(phba, ELS_CMD_ACC, cmdiocb, ndlp, NULL, 0);
492 if (!(ndlp->nlp_type & NLP_FABRIC) ||
493 (ndlp->nlp_state == NLP_STE_ADISC_ISSUE)) {
494 /* Only try to re-login if this is NOT a Fabric Node */
495 ndlp->nlp_last_elscmd = (unsigned long)ELS_CMD_PLOGI;
496 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ * 1);
497 spin_lock_irq(phba->host->host_lock);
498 ndlp->nlp_flag |= NLP_DELAY_TMO;
499 spin_unlock_irq(phba->host->host_lock);
501 ndlp->nlp_state = NLP_STE_NPR_NODE;
502 lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
504 ndlp->nlp_state = NLP_STE_UNUSED_NODE;
505 lpfc_nlp_list(phba, ndlp, NLP_UNUSED_LIST);
508 spin_lock_irq(phba->host->host_lock);
509 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
510 spin_unlock_irq(phba->host->host_lock);
511 /* The driver has to wait until the ACC completes before it continues
512 * processing the LOGO. The action will resume in
513 * lpfc_cmpl_els_logo_acc routine. Since part of processing includes an
514 * unreg_login, the driver waits so the ACC does not get aborted.
520 lpfc_rcv_prli(struct lpfc_hba * phba,
521 struct lpfc_nodelist * ndlp,
522 struct lpfc_iocbq *cmdiocb)
524 struct lpfc_dmabuf *pcmd;
527 struct fc_rport *rport = ndlp->rport;
530 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
531 lp = (uint32_t *) pcmd->virt;
532 npr = (PRLI *) ((uint8_t *) lp + sizeof (uint32_t));
534 ndlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR);
535 ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
536 if ((npr->acceptRspCode == PRLI_REQ_EXECUTED) &&
537 (npr->prliType == PRLI_FCP_TYPE)) {
538 if (npr->initiatorFunc)
539 ndlp->nlp_type |= NLP_FCP_INITIATOR;
541 ndlp->nlp_type |= NLP_FCP_TARGET;
543 ndlp->nlp_fcp_info |= NLP_FCP_2_DEVICE;
546 /* We need to update the rport role values */
547 roles = FC_RPORT_ROLE_UNKNOWN;
548 if (ndlp->nlp_type & NLP_FCP_INITIATOR)
549 roles |= FC_RPORT_ROLE_FCP_INITIATOR;
550 if (ndlp->nlp_type & NLP_FCP_TARGET)
551 roles |= FC_RPORT_ROLE_FCP_TARGET;
552 fc_remote_port_rolechg(rport, roles);
557 lpfc_disc_set_adisc(struct lpfc_hba * phba,
558 struct lpfc_nodelist * ndlp)
560 /* Check config parameter use-adisc or FCP-2 */
561 if ((phba->cfg_use_adisc == 0) &&
562 !(phba->fc_flag & FC_RSCN_MODE)) {
563 if (!(ndlp->nlp_fcp_info & NLP_FCP_2_DEVICE))
566 spin_lock_irq(phba->host->host_lock);
567 ndlp->nlp_flag |= NLP_NPR_ADISC;
568 spin_unlock_irq(phba->host->host_lock);
573 lpfc_disc_illegal(struct lpfc_hba * phba,
574 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
576 lpfc_printf_log(phba,
579 "%d:0253 Illegal State Transition: node x%x event x%x, "
580 "state x%x Data: x%x x%x\n",
582 ndlp->nlp_DID, evt, ndlp->nlp_state, ndlp->nlp_rpi,
584 return ndlp->nlp_state;
587 /* Start of Discovery State Machine routines */
590 lpfc_rcv_plogi_unused_node(struct lpfc_hba * phba,
591 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
593 struct lpfc_iocbq *cmdiocb;
595 cmdiocb = (struct lpfc_iocbq *) arg;
597 if (lpfc_rcv_plogi(phba, ndlp, cmdiocb)) {
598 ndlp->nlp_state = NLP_STE_UNUSED_NODE;
599 lpfc_nlp_list(phba, ndlp, NLP_UNUSED_LIST);
600 return ndlp->nlp_state;
602 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
603 return NLP_STE_FREED_NODE;
607 lpfc_rcv_els_unused_node(struct lpfc_hba * phba,
608 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
610 lpfc_issue_els_logo(phba, ndlp, 0);
611 lpfc_nlp_list(phba, ndlp, NLP_UNUSED_LIST);
612 return ndlp->nlp_state;
616 lpfc_rcv_logo_unused_node(struct lpfc_hba * phba,
617 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
619 struct lpfc_iocbq *cmdiocb;
621 cmdiocb = (struct lpfc_iocbq *) arg;
623 spin_lock_irq(phba->host->host_lock);
624 ndlp->nlp_flag |= NLP_LOGO_ACC;
625 spin_unlock_irq(phba->host->host_lock);
626 lpfc_els_rsp_acc(phba, ELS_CMD_ACC, cmdiocb, ndlp, NULL, 0);
627 lpfc_nlp_list(phba, ndlp, NLP_UNUSED_LIST);
629 return ndlp->nlp_state;
633 lpfc_cmpl_logo_unused_node(struct lpfc_hba * phba,
634 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
636 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
637 return NLP_STE_FREED_NODE;
641 lpfc_device_rm_unused_node(struct lpfc_hba * phba,
642 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
644 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
645 return NLP_STE_FREED_NODE;
649 lpfc_rcv_plogi_plogi_issue(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp,
650 void *arg, uint32_t evt)
652 struct lpfc_iocbq *cmdiocb = arg;
653 struct lpfc_dmabuf *pcmd;
654 struct serv_parm *sp;
659 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
660 lp = (uint32_t *) pcmd->virt;
661 sp = (struct serv_parm *) ((uint8_t *) lp + sizeof (uint32_t));
663 memset(&stat, 0, sizeof (struct ls_rjt));
665 /* For a PLOGI, we only accept if our portname is less
666 * than the remote portname.
668 phba->fc_stat.elsLogiCol++;
669 port_cmp = memcmp(&phba->fc_portname, &sp->portName,
670 sizeof (struct lpfc_name));
673 /* Reject this request because the remote node will accept
675 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
676 stat.un.b.lsRjtRsnCodeExp = LSEXP_CMD_IN_PROGRESS;
677 lpfc_els_rsp_reject(phba, stat.un.lsRjtError, cmdiocb, ndlp);
680 lpfc_rcv_plogi(phba, ndlp, cmdiocb);
681 } /* if our portname was less */
683 return ndlp->nlp_state;
687 lpfc_rcv_logo_plogi_issue(struct lpfc_hba * phba,
688 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
690 struct lpfc_iocbq *cmdiocb;
692 cmdiocb = (struct lpfc_iocbq *) arg;
694 /* software abort outstanding PLOGI */
695 lpfc_els_abort(phba, ndlp, 1);
697 lpfc_rcv_logo(phba, ndlp, cmdiocb);
698 return ndlp->nlp_state;
702 lpfc_rcv_els_plogi_issue(struct lpfc_hba * phba,
703 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
705 struct lpfc_iocbq *cmdiocb;
707 cmdiocb = (struct lpfc_iocbq *) arg;
709 /* software abort outstanding PLOGI */
710 lpfc_els_abort(phba, ndlp, 1);
711 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);
716 if (evt == NLP_EVT_RCV_LOGO) {
717 lpfc_els_rsp_acc(phba, ELS_CMD_ACC, cmdiocb, ndlp, NULL, 0);
720 lpfc_issue_els_logo(phba, ndlp, 0);
723 /* Put ndlp in npr list set plogi timer for 1 sec */
724 ndlp->nlp_last_elscmd = (unsigned long)ELS_CMD_PLOGI;
725 ndlp->nlp_state = NLP_STE_NPR_NODE;
726 lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
728 return ndlp->nlp_state;
732 lpfc_cmpl_plogi_plogi_issue(struct lpfc_hba * phba,
733 struct lpfc_nodelist * ndlp, void *arg,
736 struct lpfc_iocbq *cmdiocb, *rspiocb;
737 struct lpfc_dmabuf *pcmd, *prsp;
740 struct serv_parm *sp;
743 cmdiocb = (struct lpfc_iocbq *) arg;
744 rspiocb = cmdiocb->context_un.rsp_iocb;
746 if (ndlp->nlp_flag & NLP_ACC_REGLOGIN) {
747 return ndlp->nlp_state;
750 irsp = &rspiocb->iocb;
755 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
757 prsp = list_get_first(&pcmd->list,
760 lp = (uint32_t *) prsp->virt;
762 sp = (struct serv_parm *) ((uint8_t *) lp + sizeof (uint32_t));
763 if (!lpfc_check_sparm(phba, ndlp, sp, CLASS3))
766 /* PLOGI chkparm OK */
767 lpfc_printf_log(phba,
770 "%d:0121 PLOGI chkparm OK "
771 "Data: x%x x%x x%x x%x\n",
773 ndlp->nlp_DID, ndlp->nlp_state,
774 ndlp->nlp_flag, ndlp->nlp_rpi);
776 if ((phba->cfg_fcp_class == 2) &&
777 (sp->cls2.classValid)) {
778 ndlp->nlp_fcp_info |= CLASS2;
780 ndlp->nlp_fcp_info |= CLASS3;
782 ndlp->nlp_class_sup = 0;
783 if (sp->cls1.classValid)
784 ndlp->nlp_class_sup |= FC_COS_CLASS1;
785 if (sp->cls2.classValid)
786 ndlp->nlp_class_sup |= FC_COS_CLASS2;
787 if (sp->cls3.classValid)
788 ndlp->nlp_class_sup |= FC_COS_CLASS3;
789 if (sp->cls4.classValid)
790 ndlp->nlp_class_sup |= FC_COS_CLASS4;
792 ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) |
793 sp->cmn.bbRcvSizeLsb;
795 if (!(mbox = mempool_alloc(phba->mbox_mem_pool,
799 lpfc_unreg_rpi(phba, ndlp);
801 (phba, irsp->un.elsreq64.remoteID,
802 (uint8_t *) sp, mbox, 0) == 0) {
803 /* set_slim mailbox command needs to
804 * execute first, queue this command to
805 * be processed later.
807 switch(ndlp->nlp_DID) {
810 lpfc_mbx_cmpl_ns_reg_login;
814 lpfc_mbx_cmpl_fdmi_reg_login;
818 lpfc_mbx_cmpl_reg_login;
820 mbox->context2 = ndlp;
821 if (lpfc_sli_issue_mbox(phba, mbox,
822 (MBX_NOWAIT | MBX_STOP_IOCB))
823 != MBX_NOT_FINISHED) {
825 NLP_STE_REG_LOGIN_ISSUE;
826 lpfc_nlp_list(phba, ndlp,
828 return ndlp->nlp_state;
830 mempool_free(mbox, phba->mbox_mem_pool);
832 mempool_free(mbox, phba->mbox_mem_pool);
837 /* Free this node since the driver cannot login or has the wrong
839 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
840 return NLP_STE_FREED_NODE;
844 lpfc_device_rm_plogi_issue(struct lpfc_hba * phba,
845 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
847 /* software abort outstanding PLOGI */
848 lpfc_els_abort(phba, ndlp, 1);
850 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
851 return NLP_STE_FREED_NODE;
855 lpfc_device_recov_plogi_issue(struct lpfc_hba * phba,
856 struct lpfc_nodelist * ndlp, void *arg,
859 /* software abort outstanding PLOGI */
860 lpfc_els_abort(phba, ndlp, 1);
862 ndlp->nlp_state = NLP_STE_NPR_NODE;
863 lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
864 spin_lock_irq(phba->host->host_lock);
865 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
866 spin_unlock_irq(phba->host->host_lock);
868 return ndlp->nlp_state;
872 lpfc_rcv_plogi_adisc_issue(struct lpfc_hba * phba,
873 struct lpfc_nodelist * ndlp, void *arg,
876 struct lpfc_iocbq *cmdiocb;
878 /* software abort outstanding ADISC */
879 lpfc_els_abort(phba, ndlp, 1);
881 cmdiocb = (struct lpfc_iocbq *) arg;
883 if (lpfc_rcv_plogi(phba, ndlp, cmdiocb)) {
884 return ndlp->nlp_state;
886 ndlp->nlp_state = NLP_STE_PLOGI_ISSUE;
887 lpfc_nlp_list(phba, ndlp, NLP_PLOGI_LIST);
888 lpfc_issue_els_plogi(phba, ndlp, 0);
890 return ndlp->nlp_state;
894 lpfc_rcv_prli_adisc_issue(struct lpfc_hba * phba,
895 struct lpfc_nodelist * ndlp, void *arg,
898 struct lpfc_iocbq *cmdiocb;
900 cmdiocb = (struct lpfc_iocbq *) arg;
902 lpfc_els_rsp_prli_acc(phba, cmdiocb, ndlp);
903 return ndlp->nlp_state;
907 lpfc_rcv_logo_adisc_issue(struct lpfc_hba * phba,
908 struct lpfc_nodelist * ndlp, void *arg,
911 struct lpfc_iocbq *cmdiocb;
913 cmdiocb = (struct lpfc_iocbq *) arg;
915 /* software abort outstanding ADISC */
916 lpfc_els_abort(phba, ndlp, 0);
918 lpfc_rcv_logo(phba, ndlp, cmdiocb);
919 return ndlp->nlp_state;
923 lpfc_rcv_padisc_adisc_issue(struct lpfc_hba * phba,
924 struct lpfc_nodelist * ndlp, void *arg,
927 struct lpfc_iocbq *cmdiocb;
929 cmdiocb = (struct lpfc_iocbq *) arg;
931 lpfc_rcv_padisc(phba, ndlp, cmdiocb);
932 return ndlp->nlp_state;
936 lpfc_rcv_prlo_adisc_issue(struct lpfc_hba * phba,
937 struct lpfc_nodelist * ndlp, void *arg,
940 struct lpfc_iocbq *cmdiocb;
942 cmdiocb = (struct lpfc_iocbq *) arg;
944 /* Treat like rcv logo */
945 lpfc_rcv_logo(phba, ndlp, cmdiocb);
946 return ndlp->nlp_state;
950 lpfc_cmpl_adisc_adisc_issue(struct lpfc_hba * phba,
951 struct lpfc_nodelist * ndlp, void *arg,
954 struct lpfc_iocbq *cmdiocb, *rspiocb;
958 cmdiocb = (struct lpfc_iocbq *) arg;
959 rspiocb = cmdiocb->context_un.rsp_iocb;
961 ap = (ADISC *)lpfc_check_elscmpl_iocb(phba, cmdiocb, rspiocb);
962 irsp = &rspiocb->iocb;
964 if ((irsp->ulpStatus) ||
965 (!lpfc_check_adisc(phba, ndlp, &ap->nodeName, &ap->portName))) {
966 ndlp->nlp_last_elscmd = (unsigned long)ELS_CMD_PLOGI;
968 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ);
969 spin_lock_irq(phba->host->host_lock);
970 ndlp->nlp_flag |= NLP_DELAY_TMO;
971 spin_unlock_irq(phba->host->host_lock);
973 memset(&ndlp->nlp_nodename, 0, sizeof (struct lpfc_name));
974 memset(&ndlp->nlp_portname, 0, sizeof (struct lpfc_name));
976 ndlp->nlp_state = NLP_STE_NPR_NODE;
977 lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
978 lpfc_unreg_rpi(phba, ndlp);
979 return ndlp->nlp_state;
981 if (ndlp->nlp_type & NLP_FCP_TARGET) {
982 ndlp->nlp_state = NLP_STE_MAPPED_NODE;
983 lpfc_nlp_list(phba, ndlp, NLP_MAPPED_LIST);
985 ndlp->nlp_state = NLP_STE_UNMAPPED_NODE;
986 lpfc_nlp_list(phba, ndlp, NLP_UNMAPPED_LIST);
988 return ndlp->nlp_state;
992 lpfc_device_rm_adisc_issue(struct lpfc_hba * phba,
993 struct lpfc_nodelist * ndlp, void *arg,
996 /* software abort outstanding ADISC */
997 lpfc_els_abort(phba, ndlp, 1);
999 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
1000 return NLP_STE_FREED_NODE;
1004 lpfc_device_recov_adisc_issue(struct lpfc_hba * phba,
1005 struct lpfc_nodelist * ndlp, void *arg,
1008 /* software abort outstanding ADISC */
1009 lpfc_els_abort(phba, ndlp, 1);
1011 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;
1015 ndlp->nlp_flag |= NLP_NPR_ADISC;
1016 spin_unlock_irq(phba->host->host_lock);
1018 return ndlp->nlp_state;
1022 lpfc_rcv_plogi_reglogin_issue(struct lpfc_hba * phba,
1023 struct lpfc_nodelist * ndlp, void *arg,
1026 struct lpfc_iocbq *cmdiocb;
1028 cmdiocb = (struct lpfc_iocbq *) arg;
1030 lpfc_rcv_plogi(phba, ndlp, cmdiocb);
1031 return ndlp->nlp_state;
1035 lpfc_rcv_prli_reglogin_issue(struct lpfc_hba * phba,
1036 struct lpfc_nodelist * ndlp, void *arg,
1039 struct lpfc_iocbq *cmdiocb;
1041 cmdiocb = (struct lpfc_iocbq *) arg;
1043 lpfc_els_rsp_prli_acc(phba, cmdiocb, ndlp);
1044 return ndlp->nlp_state;
1048 lpfc_rcv_logo_reglogin_issue(struct lpfc_hba * phba,
1049 struct lpfc_nodelist * ndlp, void *arg,
1052 struct lpfc_iocbq *cmdiocb;
1054 cmdiocb = (struct lpfc_iocbq *) arg;
1056 lpfc_rcv_logo(phba, ndlp, cmdiocb);
1057 return ndlp->nlp_state;
1061 lpfc_rcv_padisc_reglogin_issue(struct lpfc_hba * phba,
1062 struct lpfc_nodelist * ndlp, void *arg,
1065 struct lpfc_iocbq *cmdiocb;
1067 cmdiocb = (struct lpfc_iocbq *) arg;
1069 lpfc_rcv_padisc(phba, ndlp, cmdiocb);
1070 return ndlp->nlp_state;
1074 lpfc_rcv_prlo_reglogin_issue(struct lpfc_hba * phba,
1075 struct lpfc_nodelist * ndlp, void *arg,
1078 struct lpfc_iocbq *cmdiocb;
1080 cmdiocb = (struct lpfc_iocbq *) arg;
1081 lpfc_els_rsp_acc(phba, ELS_CMD_ACC, cmdiocb, ndlp, NULL, 0);
1082 return ndlp->nlp_state;
1086 lpfc_cmpl_reglogin_reglogin_issue(struct lpfc_hba * phba,
1087 struct lpfc_nodelist * ndlp,
1088 void *arg, uint32_t evt)
1094 pmb = (LPFC_MBOXQ_t *) arg;
1096 did = mb->un.varWords[1];
1097 if (mb->mbxStatus) {
1098 /* RegLogin failed */
1099 lpfc_printf_log(phba,
1102 "%d:0246 RegLogin failed Data: x%x x%x x%x\n",
1104 did, mb->mbxStatus, phba->hba_state);
1106 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ * 1);
1107 spin_lock_irq(phba->host->host_lock);
1108 ndlp->nlp_flag |= NLP_DELAY_TMO;
1109 spin_unlock_irq(phba->host->host_lock);
1111 lpfc_issue_els_logo(phba, ndlp, 0);
1112 /* Put ndlp in npr list set plogi timer for 1 sec */
1113 ndlp->nlp_last_elscmd = (unsigned long)ELS_CMD_PLOGI;
1114 ndlp->nlp_state = NLP_STE_NPR_NODE;
1115 lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
1116 return ndlp->nlp_state;
1119 ndlp->nlp_rpi = mb->un.varWords[0];
1121 /* Only if we are not a fabric nport do we issue PRLI */
1122 if (!(ndlp->nlp_type & NLP_FABRIC)) {
1123 ndlp->nlp_state = NLP_STE_PRLI_ISSUE;
1124 lpfc_nlp_list(phba, ndlp, NLP_PRLI_LIST);
1125 lpfc_issue_els_prli(phba, ndlp, 0);
1127 ndlp->nlp_state = NLP_STE_UNMAPPED_NODE;
1128 lpfc_nlp_list(phba, ndlp, NLP_UNMAPPED_LIST);
1130 return ndlp->nlp_state;
1134 lpfc_device_rm_reglogin_issue(struct lpfc_hba * phba,
1135 struct lpfc_nodelist * ndlp, void *arg,
1138 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
1139 return NLP_STE_FREED_NODE;
1143 lpfc_device_recov_reglogin_issue(struct lpfc_hba * phba,
1144 struct lpfc_nodelist * ndlp, void *arg,
1147 ndlp->nlp_state = NLP_STE_NPR_NODE;
1148 lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
1149 spin_lock_irq(phba->host->host_lock);
1150 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
1151 spin_unlock_irq(phba->host->host_lock);
1152 return ndlp->nlp_state;
1156 lpfc_rcv_plogi_prli_issue(struct lpfc_hba * phba,
1157 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1159 struct lpfc_iocbq *cmdiocb;
1161 cmdiocb = (struct lpfc_iocbq *) arg;
1163 lpfc_rcv_plogi(phba, ndlp, cmdiocb);
1164 return ndlp->nlp_state;
1168 lpfc_rcv_prli_prli_issue(struct lpfc_hba * phba,
1169 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1171 struct lpfc_iocbq *cmdiocb;
1173 cmdiocb = (struct lpfc_iocbq *) arg;
1175 lpfc_els_rsp_prli_acc(phba, cmdiocb, ndlp);
1176 return ndlp->nlp_state;
1180 lpfc_rcv_logo_prli_issue(struct lpfc_hba * phba,
1181 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1183 struct lpfc_iocbq *cmdiocb;
1185 cmdiocb = (struct lpfc_iocbq *) arg;
1187 /* Software abort outstanding PRLI before sending acc */
1188 lpfc_els_abort(phba, ndlp, 1);
1190 lpfc_rcv_logo(phba, ndlp, cmdiocb);
1191 return ndlp->nlp_state;
1195 lpfc_rcv_padisc_prli_issue(struct lpfc_hba * phba,
1196 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1198 struct lpfc_iocbq *cmdiocb;
1200 cmdiocb = (struct lpfc_iocbq *) arg;
1202 lpfc_rcv_padisc(phba, ndlp, cmdiocb);
1203 return ndlp->nlp_state;
1206 /* This routine is envoked when we rcv a PRLO request from a nport
1207 * we are logged into. We should send back a PRLO rsp setting the
1209 * NEXT STATE = PRLI_ISSUE
1212 lpfc_rcv_prlo_prli_issue(struct lpfc_hba * phba,
1213 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1215 struct lpfc_iocbq *cmdiocb;
1217 cmdiocb = (struct lpfc_iocbq *) arg;
1218 lpfc_els_rsp_acc(phba, ELS_CMD_ACC, cmdiocb, ndlp, NULL, 0);
1219 return ndlp->nlp_state;
1223 lpfc_cmpl_prli_prli_issue(struct lpfc_hba * phba,
1224 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1226 struct lpfc_iocbq *cmdiocb, *rspiocb;
1230 cmdiocb = (struct lpfc_iocbq *) arg;
1231 rspiocb = cmdiocb->context_un.rsp_iocb;
1232 npr = (PRLI *)lpfc_check_elscmpl_iocb(phba, cmdiocb, rspiocb);
1234 irsp = &rspiocb->iocb;
1235 if (irsp->ulpStatus) {
1236 ndlp->nlp_state = NLP_STE_UNMAPPED_NODE;
1237 lpfc_nlp_list(phba, ndlp, NLP_UNMAPPED_LIST);
1238 return ndlp->nlp_state;
1241 /* Check out PRLI rsp */
1242 ndlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR);
1243 ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
1244 if ((npr->acceptRspCode == PRLI_REQ_EXECUTED) &&
1245 (npr->prliType == PRLI_FCP_TYPE)) {
1246 if (npr->initiatorFunc)
1247 ndlp->nlp_type |= NLP_FCP_INITIATOR;
1248 if (npr->targetFunc)
1249 ndlp->nlp_type |= NLP_FCP_TARGET;
1251 ndlp->nlp_fcp_info |= NLP_FCP_2_DEVICE;
1254 ndlp->nlp_state = NLP_STE_MAPPED_NODE;
1255 lpfc_nlp_list(phba, ndlp, NLP_MAPPED_LIST);
1256 return ndlp->nlp_state;
1259 /*! lpfc_device_rm_prli_issue
1270 * This routine is envoked when we a request to remove a nport we are in the
1271 * process of PRLIing. We should software abort outstanding prli, unreg
1272 * login, send a logout. We will change node state to UNUSED_NODE, put it
1273 * on plogi list so it can be freed when LOGO completes.
1277 lpfc_device_rm_prli_issue(struct lpfc_hba * phba,
1278 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1280 /* software abort outstanding PRLI */
1281 lpfc_els_abort(phba, ndlp, 1);
1283 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
1284 return NLP_STE_FREED_NODE;
1288 /*! lpfc_device_recov_prli_issue
1299 * The routine is envoked when the state of a device is unknown, like
1300 * during a link down. We should remove the nodelist entry from the
1301 * unmapped list, issue a UNREG_LOGIN, do a software abort of the
1302 * outstanding PRLI command, then free the node entry.
1305 lpfc_device_recov_prli_issue(struct lpfc_hba * phba,
1306 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1308 /* software abort outstanding PRLI */
1309 lpfc_els_abort(phba, ndlp, 1);
1311 ndlp->nlp_state = NLP_STE_NPR_NODE;
1312 lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
1313 spin_lock_irq(phba->host->host_lock);
1314 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
1315 spin_unlock_irq(phba->host->host_lock);
1316 return ndlp->nlp_state;
1320 lpfc_rcv_plogi_unmap_node(struct lpfc_hba * phba,
1321 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1323 struct lpfc_iocbq *cmdiocb;
1325 cmdiocb = (struct lpfc_iocbq *) arg;
1327 lpfc_rcv_plogi(phba, ndlp, cmdiocb);
1328 return ndlp->nlp_state;
1332 lpfc_rcv_prli_unmap_node(struct lpfc_hba * phba,
1333 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1335 struct lpfc_iocbq *cmdiocb;
1337 cmdiocb = (struct lpfc_iocbq *) arg;
1339 lpfc_rcv_prli(phba, ndlp, cmdiocb);
1340 lpfc_els_rsp_prli_acc(phba, cmdiocb, ndlp);
1341 return ndlp->nlp_state;
1345 lpfc_rcv_logo_unmap_node(struct lpfc_hba * phba,
1346 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1348 struct lpfc_iocbq *cmdiocb;
1350 cmdiocb = (struct lpfc_iocbq *) arg;
1352 lpfc_rcv_logo(phba, ndlp, cmdiocb);
1353 return ndlp->nlp_state;
1357 lpfc_rcv_padisc_unmap_node(struct lpfc_hba * phba,
1358 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1360 struct lpfc_iocbq *cmdiocb;
1362 cmdiocb = (struct lpfc_iocbq *) arg;
1364 lpfc_rcv_padisc(phba, ndlp, cmdiocb);
1365 return ndlp->nlp_state;
1369 lpfc_rcv_prlo_unmap_node(struct lpfc_hba * phba,
1370 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1372 struct lpfc_iocbq *cmdiocb;
1374 cmdiocb = (struct lpfc_iocbq *) arg;
1376 lpfc_els_rsp_acc(phba, ELS_CMD_ACC, cmdiocb, ndlp, NULL, 0);
1377 return ndlp->nlp_state;
1381 lpfc_device_recov_unmap_node(struct lpfc_hba * phba,
1382 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1384 ndlp->nlp_state = NLP_STE_NPR_NODE;
1385 lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
1386 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
1387 lpfc_disc_set_adisc(phba, ndlp);
1389 return ndlp->nlp_state;
1393 lpfc_rcv_plogi_mapped_node(struct lpfc_hba * phba,
1394 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1396 struct lpfc_iocbq *cmdiocb;
1398 cmdiocb = (struct lpfc_iocbq *) arg;
1400 lpfc_rcv_plogi(phba, ndlp, cmdiocb);
1401 return ndlp->nlp_state;
1405 lpfc_rcv_prli_mapped_node(struct lpfc_hba * phba,
1406 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1408 struct lpfc_iocbq *cmdiocb;
1410 cmdiocb = (struct lpfc_iocbq *) arg;
1412 lpfc_els_rsp_prli_acc(phba, cmdiocb, ndlp);
1413 return ndlp->nlp_state;
1417 lpfc_rcv_logo_mapped_node(struct lpfc_hba * phba,
1418 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1420 struct lpfc_iocbq *cmdiocb;
1422 cmdiocb = (struct lpfc_iocbq *) arg;
1424 lpfc_rcv_logo(phba, ndlp, cmdiocb);
1425 return ndlp->nlp_state;
1429 lpfc_rcv_padisc_mapped_node(struct lpfc_hba * phba,
1430 struct lpfc_nodelist * ndlp, void *arg,
1433 struct lpfc_iocbq *cmdiocb;
1435 cmdiocb = (struct lpfc_iocbq *) arg;
1437 lpfc_rcv_padisc(phba, ndlp, cmdiocb);
1438 return ndlp->nlp_state;
1442 lpfc_rcv_prlo_mapped_node(struct lpfc_hba * phba,
1443 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1445 struct lpfc_iocbq *cmdiocb;
1447 cmdiocb = (struct lpfc_iocbq *) arg;
1449 /* flush the target */
1450 spin_lock_irq(phba->host->host_lock);
1451 lpfc_sli_abort_iocb(phba, &phba->sli.ring[phba->sli.fcp_ring],
1452 ndlp->nlp_sid, 0, 0, LPFC_CTX_TGT);
1453 spin_unlock_irq(phba->host->host_lock);
1455 /* Treat like rcv logo */
1456 lpfc_rcv_logo(phba, ndlp, cmdiocb);
1457 return ndlp->nlp_state;
1461 lpfc_device_recov_mapped_node(struct lpfc_hba * phba,
1462 struct lpfc_nodelist * ndlp, void *arg,
1465 ndlp->nlp_state = NLP_STE_NPR_NODE;
1466 lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
1467 spin_lock_irq(phba->host->host_lock);
1468 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
1469 spin_unlock_irq(phba->host->host_lock);
1470 lpfc_disc_set_adisc(phba, ndlp);
1471 return ndlp->nlp_state;
1475 lpfc_rcv_plogi_npr_node(struct lpfc_hba * phba,
1476 struct lpfc_nodelist * ndlp, void *arg,
1479 struct lpfc_iocbq *cmdiocb;
1481 cmdiocb = (struct lpfc_iocbq *) arg;
1483 /* Ignore PLOGI if we have an outstanding LOGO */
1484 if (ndlp->nlp_flag & NLP_LOGO_SND) {
1485 return ndlp->nlp_state;
1488 if (lpfc_rcv_plogi(phba, ndlp, cmdiocb)) {
1489 spin_lock_irq(phba->host->host_lock);
1490 ndlp->nlp_flag &= ~(NLP_NPR_ADISC | NLP_NPR_2B_DISC);
1491 spin_unlock_irq(phba->host->host_lock);
1492 return ndlp->nlp_state;
1495 /* send PLOGI immediately, move to PLOGI issue state */
1496 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
1497 ndlp->nlp_state = NLP_STE_PLOGI_ISSUE;
1498 lpfc_nlp_list(phba, ndlp, NLP_PLOGI_LIST);
1499 lpfc_issue_els_plogi(phba, ndlp, 0);
1501 return ndlp->nlp_state;
1505 lpfc_rcv_prli_npr_node(struct lpfc_hba * phba,
1506 struct lpfc_nodelist * ndlp, void *arg,
1509 struct lpfc_iocbq *cmdiocb;
1512 cmdiocb = (struct lpfc_iocbq *) arg;
1514 memset(&stat, 0, sizeof (struct ls_rjt));
1515 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
1516 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
1517 lpfc_els_rsp_reject(phba, stat.un.lsRjtError, cmdiocb, ndlp);
1519 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
1520 if (ndlp->nlp_flag & NLP_NPR_ADISC) {
1521 spin_lock_irq(phba->host->host_lock);
1522 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
1523 spin_unlock_irq(phba->host->host_lock);
1524 ndlp->nlp_state = NLP_STE_ADISC_ISSUE;
1525 lpfc_nlp_list(phba, ndlp, NLP_ADISC_LIST);
1526 lpfc_issue_els_adisc(phba, ndlp, 0);
1528 ndlp->nlp_state = NLP_STE_PLOGI_ISSUE;
1529 lpfc_nlp_list(phba, ndlp, NLP_PLOGI_LIST);
1530 lpfc_issue_els_plogi(phba, ndlp, 0);
1533 return ndlp->nlp_state;
1537 lpfc_rcv_logo_npr_node(struct lpfc_hba * phba,
1538 struct lpfc_nodelist * ndlp, void *arg,
1541 struct lpfc_iocbq *cmdiocb;
1543 cmdiocb = (struct lpfc_iocbq *) arg;
1545 lpfc_rcv_logo(phba, ndlp, cmdiocb);
1546 return ndlp->nlp_state;
1550 lpfc_rcv_padisc_npr_node(struct lpfc_hba * phba,
1551 struct lpfc_nodelist * ndlp, void *arg,
1554 struct lpfc_iocbq *cmdiocb;
1556 cmdiocb = (struct lpfc_iocbq *) arg;
1558 lpfc_rcv_padisc(phba, ndlp, cmdiocb);
1560 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
1561 if (ndlp->nlp_flag & NLP_NPR_ADISC) {
1562 ndlp->nlp_state = NLP_STE_ADISC_ISSUE;
1563 lpfc_nlp_list(phba, ndlp, NLP_ADISC_LIST);
1564 lpfc_issue_els_adisc(phba, ndlp, 0);
1566 ndlp->nlp_state = NLP_STE_PLOGI_ISSUE;
1567 lpfc_nlp_list(phba, ndlp, NLP_PLOGI_LIST);
1568 lpfc_issue_els_plogi(phba, ndlp, 0);
1571 return ndlp->nlp_state;
1575 lpfc_rcv_prlo_npr_node(struct lpfc_hba * phba,
1576 struct lpfc_nodelist * ndlp, void *arg,
1579 struct lpfc_iocbq *cmdiocb;
1581 cmdiocb = (struct lpfc_iocbq *) arg;
1583 spin_lock_irq(phba->host->host_lock);
1584 ndlp->nlp_flag |= NLP_LOGO_ACC;
1585 spin_unlock_irq(phba->host->host_lock);
1587 lpfc_els_rsp_acc(phba, ELS_CMD_ACC, cmdiocb, ndlp, NULL, 0);
1589 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
1590 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ * 1);
1591 spin_lock_irq(phba->host->host_lock);
1592 ndlp->nlp_flag |= NLP_DELAY_TMO;
1593 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
1594 spin_unlock_irq(phba->host->host_lock);
1596 spin_lock_irq(phba->host->host_lock);
1597 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
1598 spin_unlock_irq(phba->host->host_lock);
1600 return ndlp->nlp_state;
1604 lpfc_cmpl_plogi_npr_node(struct lpfc_hba * phba,
1605 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1607 struct lpfc_iocbq *cmdiocb, *rspiocb;
1609 cmdiocb = (struct lpfc_iocbq *) arg;
1610 rspiocb = cmdiocb->context_un.rsp_iocb;
1611 return ndlp->nlp_state;
1615 lpfc_cmpl_prli_npr_node(struct lpfc_hba * phba,
1616 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1618 struct lpfc_iocbq *cmdiocb, *rspiocb;
1620 cmdiocb = (struct lpfc_iocbq *) arg;
1621 rspiocb = cmdiocb->context_un.rsp_iocb;
1622 return ndlp->nlp_state;
1626 lpfc_cmpl_logo_npr_node(struct lpfc_hba * phba,
1627 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1629 lpfc_unreg_rpi(phba, ndlp);
1630 /* This routine does nothing, just return the current state */
1631 return ndlp->nlp_state;
1635 lpfc_cmpl_adisc_npr_node(struct lpfc_hba * phba,
1636 struct lpfc_nodelist * ndlp, void *arg,
1639 struct lpfc_iocbq *cmdiocb, *rspiocb;
1641 cmdiocb = (struct lpfc_iocbq *) arg;
1642 rspiocb = cmdiocb->context_un.rsp_iocb;
1643 return ndlp->nlp_state;
1647 lpfc_cmpl_reglogin_npr_node(struct lpfc_hba * phba,
1648 struct lpfc_nodelist * ndlp, void *arg,
1654 pmb = (LPFC_MBOXQ_t *) arg;
1658 ndlp->nlp_rpi = mb->un.varWords[0];
1660 return ndlp->nlp_state;
1664 lpfc_device_rm_npr_node(struct lpfc_hba * phba,
1665 struct lpfc_nodelist * ndlp, void *arg,
1668 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
1669 return NLP_STE_FREED_NODE;
1673 lpfc_device_recov_npr_node(struct lpfc_hba * phba,
1674 struct lpfc_nodelist * ndlp, void *arg,
1677 spin_lock_irq(phba->host->host_lock);
1678 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
1679 if (ndlp->nlp_flag & NLP_DELAY_TMO) {
1680 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
1681 if (!list_empty(&ndlp->els_retry_evt.evt_listp))
1682 list_del_init(&ndlp->els_retry_evt.evt_listp);
1683 spin_unlock_irq(phba->host->host_lock);
1684 del_timer_sync(&ndlp->nlp_delayfunc);
1685 return ndlp->nlp_state;
1687 spin_unlock_irq(phba->host->host_lock);
1688 return ndlp->nlp_state;
1692 /* This next section defines the NPort Discovery State Machine */
1694 /* There are 4 different double linked lists nodelist entries can reside on.
1695 * The plogi list and adisc list are used when Link Up discovery or RSCN
1696 * processing is needed. Each list holds the nodes that we will send PLOGI
1697 * or ADISC on. These lists will keep track of what nodes will be effected
1698 * by an RSCN, or a Link Up (Typically, all nodes are effected on Link Up).
1699 * The unmapped_list will contain all nodes that we have successfully logged
1700 * into at the Fibre Channel level. The mapped_list will contain all nodes
1701 * that are mapped FCP targets.
1704 * The bind list is a list of undiscovered (potentially non-existent) nodes
1705 * that we have saved binding information on. This information is used when
1706 * nodes transition from the unmapped to the mapped list.
1708 /* For UNUSED_NODE state, the node has just been allocated .
1709 * For PLOGI_ISSUE and REG_LOGIN_ISSUE, the node is on
1710 * the PLOGI list. For REG_LOGIN_COMPL, the node is taken off the PLOGI list
1711 * and put on the unmapped list. For ADISC processing, the node is taken off
1712 * the ADISC list and placed on either the mapped or unmapped list (depending
1713 * on its previous state). Once on the unmapped list, a PRLI is issued and the
1714 * state changed to PRLI_ISSUE. When the PRLI completion occurs, the state is
1715 * changed to UNMAPPED_NODE. If the completion indicates a mapped
1716 * node, the node is taken off the unmapped list. The binding list is checked
1717 * for a valid binding, or a binding is automatically assigned. If binding
1718 * assignment is unsuccessful, the node is left on the unmapped list. If
1719 * binding assignment is successful, the associated binding list entry (if
1720 * any) is removed, and the node is placed on the mapped list.
1723 * For a Link Down, all nodes on the ADISC, PLOGI, unmapped or mapped
1724 * lists will receive a DEVICE_RECOVERY event. If the linkdown or nodev timers
1725 * expire, all effected nodes will receive a DEVICE_RM event.
1728 * For a Link Up or RSCN, all nodes will move from the mapped / unmapped lists
1729 * to either the ADISC or PLOGI list. After a Nameserver query or ALPA loopmap
1730 * check, additional nodes may be added or removed (via DEVICE_RM) to / from
1731 * the PLOGI or ADISC lists. Once the PLOGI and ADISC lists are populated,
1732 * we will first process the ADISC list. 32 entries are processed initially and
1733 * ADISC is initited for each one. Completions / Events for each node are
1734 * funnelled thru the state machine. As each node finishes ADISC processing, it
1735 * starts ADISC for any nodes waiting for ADISC processing. If no nodes are
1736 * waiting, and the ADISC list count is identically 0, then we are done. For
1737 * Link Up discovery, since all nodes on the PLOGI list are UNREG_LOGIN'ed, we
1738 * can issue a CLEAR_LA and reenable Link Events. Next we will process the PLOGI
1739 * list. 32 entries are processed initially and PLOGI is initited for each one.
1740 * Completions / Events for each node are funnelled thru the state machine. As
1741 * each node finishes PLOGI processing, it starts PLOGI for any nodes waiting
1742 * for PLOGI processing. If no nodes are waiting, and the PLOGI list count is
1743 * indentically 0, then we are done. We have now completed discovery / RSCN
1744 * handling. Upon completion, ALL nodes should be on either the mapped or
1748 static uint32_t (*lpfc_disc_action[NLP_STE_MAX_STATE * NLP_EVT_MAX_EVENT])
1749 (struct lpfc_hba *, struct lpfc_nodelist *, void *, uint32_t) = {
1750 /* Action routine Event Current State */
1751 lpfc_rcv_plogi_unused_node, /* RCV_PLOGI UNUSED_NODE */
1752 lpfc_rcv_els_unused_node, /* RCV_PRLI */
1753 lpfc_rcv_logo_unused_node, /* RCV_LOGO */
1754 lpfc_rcv_els_unused_node, /* RCV_ADISC */
1755 lpfc_rcv_els_unused_node, /* RCV_PDISC */
1756 lpfc_rcv_els_unused_node, /* RCV_PRLO */
1757 lpfc_disc_illegal, /* CMPL_PLOGI */
1758 lpfc_disc_illegal, /* CMPL_PRLI */
1759 lpfc_cmpl_logo_unused_node, /* CMPL_LOGO */
1760 lpfc_disc_illegal, /* CMPL_ADISC */
1761 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
1762 lpfc_device_rm_unused_node, /* DEVICE_RM */
1763 lpfc_disc_illegal, /* DEVICE_RECOVERY */
1765 lpfc_rcv_plogi_plogi_issue, /* RCV_PLOGI PLOGI_ISSUE */
1766 lpfc_rcv_els_plogi_issue, /* RCV_PRLI */
1767 lpfc_rcv_logo_plogi_issue, /* RCV_LOGO */
1768 lpfc_rcv_els_plogi_issue, /* RCV_ADISC */
1769 lpfc_rcv_els_plogi_issue, /* RCV_PDISC */
1770 lpfc_rcv_els_plogi_issue, /* RCV_PRLO */
1771 lpfc_cmpl_plogi_plogi_issue, /* CMPL_PLOGI */
1772 lpfc_disc_illegal, /* CMPL_PRLI */
1773 lpfc_disc_illegal, /* CMPL_LOGO */
1774 lpfc_disc_illegal, /* CMPL_ADISC */
1775 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
1776 lpfc_device_rm_plogi_issue, /* DEVICE_RM */
1777 lpfc_device_recov_plogi_issue, /* DEVICE_RECOVERY */
1779 lpfc_rcv_plogi_adisc_issue, /* RCV_PLOGI ADISC_ISSUE */
1780 lpfc_rcv_prli_adisc_issue, /* RCV_PRLI */
1781 lpfc_rcv_logo_adisc_issue, /* RCV_LOGO */
1782 lpfc_rcv_padisc_adisc_issue, /* RCV_ADISC */
1783 lpfc_rcv_padisc_adisc_issue, /* RCV_PDISC */
1784 lpfc_rcv_prlo_adisc_issue, /* RCV_PRLO */
1785 lpfc_disc_illegal, /* CMPL_PLOGI */
1786 lpfc_disc_illegal, /* CMPL_PRLI */
1787 lpfc_disc_illegal, /* CMPL_LOGO */
1788 lpfc_cmpl_adisc_adisc_issue, /* CMPL_ADISC */
1789 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
1790 lpfc_device_rm_adisc_issue, /* DEVICE_RM */
1791 lpfc_device_recov_adisc_issue, /* DEVICE_RECOVERY */
1793 lpfc_rcv_plogi_reglogin_issue, /* RCV_PLOGI REG_LOGIN_ISSUE */
1794 lpfc_rcv_prli_reglogin_issue, /* RCV_PLOGI */
1795 lpfc_rcv_logo_reglogin_issue, /* RCV_LOGO */
1796 lpfc_rcv_padisc_reglogin_issue, /* RCV_ADISC */
1797 lpfc_rcv_padisc_reglogin_issue, /* RCV_PDISC */
1798 lpfc_rcv_prlo_reglogin_issue, /* RCV_PRLO */
1799 lpfc_disc_illegal, /* CMPL_PLOGI */
1800 lpfc_disc_illegal, /* CMPL_PRLI */
1801 lpfc_disc_illegal, /* CMPL_LOGO */
1802 lpfc_disc_illegal, /* CMPL_ADISC */
1803 lpfc_cmpl_reglogin_reglogin_issue,/* CMPL_REG_LOGIN */
1804 lpfc_device_rm_reglogin_issue, /* DEVICE_RM */
1805 lpfc_device_recov_reglogin_issue,/* DEVICE_RECOVERY */
1807 lpfc_rcv_plogi_prli_issue, /* RCV_PLOGI PRLI_ISSUE */
1808 lpfc_rcv_prli_prli_issue, /* RCV_PRLI */
1809 lpfc_rcv_logo_prli_issue, /* RCV_LOGO */
1810 lpfc_rcv_padisc_prli_issue, /* RCV_ADISC */
1811 lpfc_rcv_padisc_prli_issue, /* RCV_PDISC */
1812 lpfc_rcv_prlo_prli_issue, /* RCV_PRLO */
1813 lpfc_disc_illegal, /* CMPL_PLOGI */
1814 lpfc_cmpl_prli_prli_issue, /* CMPL_PRLI */
1815 lpfc_disc_illegal, /* CMPL_LOGO */
1816 lpfc_disc_illegal, /* CMPL_ADISC */
1817 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
1818 lpfc_device_rm_prli_issue, /* DEVICE_RM */
1819 lpfc_device_recov_prli_issue, /* DEVICE_RECOVERY */
1821 lpfc_rcv_plogi_unmap_node, /* RCV_PLOGI UNMAPPED_NODE */
1822 lpfc_rcv_prli_unmap_node, /* RCV_PRLI */
1823 lpfc_rcv_logo_unmap_node, /* RCV_LOGO */
1824 lpfc_rcv_padisc_unmap_node, /* RCV_ADISC */
1825 lpfc_rcv_padisc_unmap_node, /* RCV_PDISC */
1826 lpfc_rcv_prlo_unmap_node, /* RCV_PRLO */
1827 lpfc_disc_illegal, /* CMPL_PLOGI */
1828 lpfc_disc_illegal, /* CMPL_PRLI */
1829 lpfc_disc_illegal, /* CMPL_LOGO */
1830 lpfc_disc_illegal, /* CMPL_ADISC */
1831 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
1832 lpfc_disc_illegal, /* DEVICE_RM */
1833 lpfc_device_recov_unmap_node, /* DEVICE_RECOVERY */
1835 lpfc_rcv_plogi_mapped_node, /* RCV_PLOGI MAPPED_NODE */
1836 lpfc_rcv_prli_mapped_node, /* RCV_PRLI */
1837 lpfc_rcv_logo_mapped_node, /* RCV_LOGO */
1838 lpfc_rcv_padisc_mapped_node, /* RCV_ADISC */
1839 lpfc_rcv_padisc_mapped_node, /* RCV_PDISC */
1840 lpfc_rcv_prlo_mapped_node, /* RCV_PRLO */
1841 lpfc_disc_illegal, /* CMPL_PLOGI */
1842 lpfc_disc_illegal, /* CMPL_PRLI */
1843 lpfc_disc_illegal, /* CMPL_LOGO */
1844 lpfc_disc_illegal, /* CMPL_ADISC */
1845 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
1846 lpfc_disc_illegal, /* DEVICE_RM */
1847 lpfc_device_recov_mapped_node, /* DEVICE_RECOVERY */
1849 lpfc_rcv_plogi_npr_node, /* RCV_PLOGI NPR_NODE */
1850 lpfc_rcv_prli_npr_node, /* RCV_PRLI */
1851 lpfc_rcv_logo_npr_node, /* RCV_LOGO */
1852 lpfc_rcv_padisc_npr_node, /* RCV_ADISC */
1853 lpfc_rcv_padisc_npr_node, /* RCV_PDISC */
1854 lpfc_rcv_prlo_npr_node, /* RCV_PRLO */
1855 lpfc_cmpl_plogi_npr_node, /* CMPL_PLOGI */
1856 lpfc_cmpl_prli_npr_node, /* CMPL_PRLI */
1857 lpfc_cmpl_logo_npr_node, /* CMPL_LOGO */
1858 lpfc_cmpl_adisc_npr_node, /* CMPL_ADISC */
1859 lpfc_cmpl_reglogin_npr_node, /* CMPL_REG_LOGIN */
1860 lpfc_device_rm_npr_node, /* DEVICE_RM */
1861 lpfc_device_recov_npr_node, /* DEVICE_RECOVERY */
1865 lpfc_disc_state_machine(struct lpfc_hba * phba,
1866 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1868 uint32_t cur_state, rc;
1869 uint32_t(*func) (struct lpfc_hba *, struct lpfc_nodelist *, void *,
1872 ndlp->nlp_disc_refcnt++;
1873 cur_state = ndlp->nlp_state;
1875 /* DSM in event <evt> on NPort <nlp_DID> in state <cur_state> */
1876 lpfc_printf_log(phba,
1879 "%d:0211 DSM in event x%x on NPort x%x in state %d "
1882 evt, ndlp->nlp_DID, cur_state, ndlp->nlp_flag);
1884 func = lpfc_disc_action[(cur_state * NLP_EVT_MAX_EVENT) + evt];
1885 rc = (func) (phba, ndlp, arg, evt);
1887 /* DSM out state <rc> on NPort <nlp_DID> */
1888 lpfc_printf_log(phba,
1891 "%d:0212 DSM out state %d on NPort x%x Data: x%x\n",
1893 rc, ndlp->nlp_DID, ndlp->nlp_flag);
1895 ndlp->nlp_disc_refcnt--;
1897 /* Check to see if ndlp removal is deferred */
1898 if ((ndlp->nlp_disc_refcnt == 0)
1899 && (ndlp->nlp_flag & NLP_DELAY_REMOVE)) {
1900 spin_lock_irq(phba->host->host_lock);
1901 ndlp->nlp_flag &= ~NLP_DELAY_REMOVE;
1902 spin_unlock_irq(phba->host->host_lock);
1903 lpfc_nlp_remove(phba, ndlp);
1904 return NLP_STE_FREED_NODE;
1906 if (rc == NLP_STE_FREED_NODE)
1907 return NLP_STE_FREED_NODE;
1908 ndlp->nlp_state = rc;