1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2004-2009 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/slab.h>
25 #include <linux/interrupt.h>
27 #include <scsi/scsi.h>
28 #include <scsi/scsi_device.h>
29 #include <scsi/scsi_host.h>
30 #include <scsi/scsi_transport_fc.h>
35 #include "lpfc_sli4.h"
37 #include "lpfc_disc.h"
38 #include "lpfc_scsi.h"
40 #include "lpfc_logmsg.h"
41 #include "lpfc_crtn.h"
42 #include "lpfc_vport.h"
43 #include "lpfc_debugfs.h"
46 /* Called to verify a rcv'ed ADISC was intended for us. */
48 lpfc_check_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
49 struct lpfc_name *nn, struct lpfc_name *pn)
51 /* First, we MUST have a RPI registered */
52 if (!(ndlp->nlp_flag & NLP_RPI_REGISTERED))
55 /* Compare the ADISC rsp WWNN / WWPN matches our internal node
56 * table entry for that node.
58 if (memcmp(nn, &ndlp->nlp_nodename, sizeof (struct lpfc_name)))
61 if (memcmp(pn, &ndlp->nlp_portname, sizeof (struct lpfc_name)))
64 /* we match, return success */
69 lpfc_check_sparm(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
70 struct serv_parm *sp, uint32_t class, int flogi)
72 volatile struct serv_parm *hsp = &vport->fc_sparam;
73 uint16_t hsp_value, ssp_value = 0;
76 * The receive data field size and buffer-to-buffer receive data field
77 * size entries are 16 bits but are represented as two 8-bit fields in
78 * the driver data structure to account for rsvd bits and other control
79 * bits. Reconstruct and compare the fields as a 16-bit values before
80 * correcting the byte values.
82 if (sp->cls1.classValid) {
84 hsp_value = ((hsp->cls1.rcvDataSizeMsb << 8) |
85 hsp->cls1.rcvDataSizeLsb);
86 ssp_value = ((sp->cls1.rcvDataSizeMsb << 8) |
87 sp->cls1.rcvDataSizeLsb);
89 goto bad_service_param;
90 if (ssp_value > hsp_value) {
91 sp->cls1.rcvDataSizeLsb =
92 hsp->cls1.rcvDataSizeLsb;
93 sp->cls1.rcvDataSizeMsb =
94 hsp->cls1.rcvDataSizeMsb;
97 } else if (class == CLASS1)
98 goto bad_service_param;
99 if (sp->cls2.classValid) {
101 hsp_value = ((hsp->cls2.rcvDataSizeMsb << 8) |
102 hsp->cls2.rcvDataSizeLsb);
103 ssp_value = ((sp->cls2.rcvDataSizeMsb << 8) |
104 sp->cls2.rcvDataSizeLsb);
106 goto bad_service_param;
107 if (ssp_value > hsp_value) {
108 sp->cls2.rcvDataSizeLsb =
109 hsp->cls2.rcvDataSizeLsb;
110 sp->cls2.rcvDataSizeMsb =
111 hsp->cls2.rcvDataSizeMsb;
114 } else if (class == CLASS2)
115 goto bad_service_param;
116 if (sp->cls3.classValid) {
118 hsp_value = ((hsp->cls3.rcvDataSizeMsb << 8) |
119 hsp->cls3.rcvDataSizeLsb);
120 ssp_value = ((sp->cls3.rcvDataSizeMsb << 8) |
121 sp->cls3.rcvDataSizeLsb);
123 goto bad_service_param;
124 if (ssp_value > hsp_value) {
125 sp->cls3.rcvDataSizeLsb =
126 hsp->cls3.rcvDataSizeLsb;
127 sp->cls3.rcvDataSizeMsb =
128 hsp->cls3.rcvDataSizeMsb;
131 } else if (class == CLASS3)
132 goto bad_service_param;
135 * Preserve the upper four bits of the MSB from the PLOGI response.
136 * These bits contain the Buffer-to-Buffer State Change Number
137 * from the target and need to be passed to the FW.
139 hsp_value = (hsp->cmn.bbRcvSizeMsb << 8) | hsp->cmn.bbRcvSizeLsb;
140 ssp_value = (sp->cmn.bbRcvSizeMsb << 8) | sp->cmn.bbRcvSizeLsb;
141 if (ssp_value > hsp_value) {
142 sp->cmn.bbRcvSizeLsb = hsp->cmn.bbRcvSizeLsb;
143 sp->cmn.bbRcvSizeMsb = (sp->cmn.bbRcvSizeMsb & 0xF0) |
144 (hsp->cmn.bbRcvSizeMsb & 0x0F);
147 memcpy(&ndlp->nlp_nodename, &sp->nodeName, sizeof (struct lpfc_name));
148 memcpy(&ndlp->nlp_portname, &sp->portName, sizeof (struct lpfc_name));
151 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
153 "(%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x) sent "
154 "invalid service parameters. Ignoring device.\n",
156 sp->nodeName.u.wwn[0], sp->nodeName.u.wwn[1],
157 sp->nodeName.u.wwn[2], sp->nodeName.u.wwn[3],
158 sp->nodeName.u.wwn[4], sp->nodeName.u.wwn[5],
159 sp->nodeName.u.wwn[6], sp->nodeName.u.wwn[7]);
164 lpfc_check_elscmpl_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
165 struct lpfc_iocbq *rspiocb)
167 struct lpfc_dmabuf *pcmd, *prsp;
172 irsp = &rspiocb->iocb;
173 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
175 /* For lpfc_els_abort, context2 could be zero'ed to delay
176 * freeing associated memory till after ABTS completes.
179 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf,
182 lp = (uint32_t *) prsp->virt;
183 ptr = (void *)((uint8_t *)lp + sizeof(uint32_t));
186 /* Force ulpStatus error since we are returning NULL ptr */
187 if (!(irsp->ulpStatus)) {
188 irsp->ulpStatus = IOSTAT_LOCAL_REJECT;
189 irsp->un.ulpWord[4] = IOERR_SLI_ABORTED;
199 * Free resources / clean up outstanding I/Os
200 * associated with a LPFC_NODELIST entry. This
201 * routine effectively results in a "software abort".
204 lpfc_els_abort(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp)
206 LIST_HEAD(completions);
207 LIST_HEAD(txcmplq_completions);
208 LIST_HEAD(abort_list);
209 struct lpfc_sli *psli = &phba->sli;
210 struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING];
211 struct lpfc_iocbq *iocb, *next_iocb;
213 /* Abort outstanding I/O on NPort <nlp_DID> */
214 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_DISCOVERY,
215 "2819 Abort outstanding I/O on NPort x%x "
216 "Data: x%x x%x x%x\n",
217 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
220 lpfc_fabric_abort_nport(ndlp);
222 /* First check the txq */
223 spin_lock_irq(&phba->hbalock);
224 list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
225 /* Check to see if iocb matches the nport we are looking for */
226 if (lpfc_check_sli_ndlp(phba, pring, iocb, ndlp)) {
227 /* It matches, so deque and call compl with anp error */
228 list_move_tail(&iocb->list, &completions);
233 /* Next check the txcmplq */
234 list_splice_init(&pring->txcmplq, &txcmplq_completions);
235 spin_unlock_irq(&phba->hbalock);
237 list_for_each_entry_safe(iocb, next_iocb, &txcmplq_completions, list) {
238 /* Check to see if iocb matches the nport we are looking for */
239 if (lpfc_check_sli_ndlp(phba, pring, iocb, ndlp))
240 list_add_tail(&iocb->dlist, &abort_list);
242 spin_lock_irq(&phba->hbalock);
243 list_splice(&txcmplq_completions, &pring->txcmplq);
244 spin_unlock_irq(&phba->hbalock);
246 list_for_each_entry_safe(iocb, next_iocb, &abort_list, dlist) {
247 spin_lock_irq(&phba->hbalock);
248 list_del_init(&iocb->dlist);
249 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
250 spin_unlock_irq(&phba->hbalock);
253 /* Cancel all the IOCBs from the completions list */
254 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
257 lpfc_cancel_retry_delay_tmo(phba->pport, ndlp);
262 lpfc_rcv_plogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
263 struct lpfc_iocbq *cmdiocb)
265 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
266 struct lpfc_hba *phba = vport->phba;
267 struct lpfc_dmabuf *pcmd;
270 struct serv_parm *sp;
275 memset(&stat, 0, sizeof (struct ls_rjt));
276 if (vport->port_state <= LPFC_FDISC) {
277 /* Before responding to PLOGI, check for pt2pt mode.
278 * If we are pt2pt, with an outstanding FLOGI, abort
279 * the FLOGI and resend it first.
281 if (vport->fc_flag & FC_PT2PT) {
282 lpfc_els_abort_flogi(phba);
283 if (!(vport->fc_flag & FC_PT2PT_PLOGI)) {
284 /* If the other side is supposed to initiate
285 * the PLOGI anyway, just ACC it now and
286 * move on with discovery.
288 phba->fc_edtov = FF_DEF_EDTOV;
289 phba->fc_ratov = FF_DEF_RATOV;
290 /* Start discovery - this should just do
292 lpfc_disc_start(vport);
294 lpfc_initial_flogi(vport);
296 stat.un.b.lsRjtRsnCode = LSRJT_LOGICAL_BSY;
297 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
298 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb,
303 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
304 lp = (uint32_t *) pcmd->virt;
305 sp = (struct serv_parm *) ((uint8_t *) lp + sizeof (uint32_t));
306 if (wwn_to_u64(sp->portName.u.wwn) == 0) {
307 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
308 "0140 PLOGI Reject: invalid nname\n");
309 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
310 stat.un.b.lsRjtRsnCodeExp = LSEXP_INVALID_PNAME;
311 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
315 if (wwn_to_u64(sp->nodeName.u.wwn) == 0) {
316 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
317 "0141 PLOGI Reject: invalid pname\n");
318 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
319 stat.un.b.lsRjtRsnCodeExp = LSEXP_INVALID_NNAME;
320 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
324 if ((lpfc_check_sparm(vport, ndlp, sp, CLASS3, 0) == 0)) {
325 /* Reject this request because invalid parameters */
326 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
327 stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
328 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
332 icmd = &cmdiocb->iocb;
334 /* PLOGI chkparm OK */
335 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
336 "0114 PLOGI chkparm OK Data: x%x x%x x%x x%x\n",
337 ndlp->nlp_DID, ndlp->nlp_state, ndlp->nlp_flag,
340 if (vport->cfg_fcp_class == 2 && sp->cls2.classValid)
341 ndlp->nlp_fcp_info |= CLASS2;
343 ndlp->nlp_fcp_info |= CLASS3;
345 ndlp->nlp_class_sup = 0;
346 if (sp->cls1.classValid)
347 ndlp->nlp_class_sup |= FC_COS_CLASS1;
348 if (sp->cls2.classValid)
349 ndlp->nlp_class_sup |= FC_COS_CLASS2;
350 if (sp->cls3.classValid)
351 ndlp->nlp_class_sup |= FC_COS_CLASS3;
352 if (sp->cls4.classValid)
353 ndlp->nlp_class_sup |= FC_COS_CLASS4;
355 ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) | sp->cmn.bbRcvSizeLsb;
357 /* no need to reg_login if we are already in one of these states */
358 switch (ndlp->nlp_state) {
359 case NLP_STE_NPR_NODE:
360 if (!(ndlp->nlp_flag & NLP_NPR_ADISC))
362 case NLP_STE_REG_LOGIN_ISSUE:
363 case NLP_STE_PRLI_ISSUE:
364 case NLP_STE_UNMAPPED_NODE:
365 case NLP_STE_MAPPED_NODE:
366 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp, NULL);
370 if ((vport->fc_flag & FC_PT2PT) &&
371 !(vport->fc_flag & FC_PT2PT_PLOGI)) {
372 /* rcv'ed PLOGI decides what our NPortId will be */
373 vport->fc_myDID = icmd->un.rcvels.parmRo;
374 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
377 lpfc_config_link(phba, mbox);
378 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
380 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
381 if (rc == MBX_NOT_FINISHED) {
382 mempool_free(mbox, phba->mbox_mem_pool);
386 lpfc_can_disctmo(vport);
388 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
392 /* Registering an existing RPI behaves differently for SLI3 vs SLI4 */
393 if (phba->sli_rev == LPFC_SLI_REV4)
394 lpfc_unreg_rpi(vport, ndlp);
396 rc = lpfc_reg_rpi(phba, vport->vpi, icmd->un.rcvels.remoteID,
397 (uint8_t *) sp, mbox, ndlp->nlp_rpi);
399 mempool_free(mbox, phba->mbox_mem_pool);
403 /* ACC PLOGI rsp command needs to execute first,
404 * queue this mbox command to be processed later.
406 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
408 * mbox->context2 = lpfc_nlp_get(ndlp) deferred until mailbox
409 * command issued in lpfc_cmpl_els_acc().
412 spin_lock_irq(shost->host_lock);
413 ndlp->nlp_flag |= (NLP_ACC_REGLOGIN | NLP_RCV_PLOGI);
414 spin_unlock_irq(shost->host_lock);
417 * If there is an outstanding PLOGI issued, abort it before
418 * sending ACC rsp for received PLOGI. If pending plogi
419 * is not canceled here, the plogi will be rejected by
420 * remote port and will be retried. On a configuration with
421 * single discovery thread, this will cause a huge delay in
422 * discovery. Also this will cause multiple state machines
423 * running in parallel for this node.
425 if (ndlp->nlp_state == NLP_STE_PLOGI_ISSUE) {
426 /* software abort outstanding PLOGI */
427 lpfc_els_abort(phba, ndlp);
430 if ((vport->port_type == LPFC_NPIV_PORT &&
431 vport->cfg_restrict_login)) {
433 /* In order to preserve RPIs, we want to cleanup
434 * the default RPI the firmware created to rcv
435 * this ELS request. The only way to do this is
436 * to register, then unregister the RPI.
438 spin_lock_irq(shost->host_lock);
439 ndlp->nlp_flag |= NLP_RM_DFLT_RPI;
440 spin_unlock_irq(shost->host_lock);
441 stat.un.b.lsRjtRsnCode = LSRJT_INVALID_CMD;
442 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
443 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb,
447 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp, mbox);
450 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
451 stat.un.b.lsRjtRsnCodeExp = LSEXP_OUT_OF_RESOURCE;
452 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
457 * lpfc_mbx_cmpl_resume_rpi - Resume RPI completion routine
458 * @phba: pointer to lpfc hba data structure.
459 * @mboxq: pointer to mailbox object
461 * This routine is invoked to issue a completion to a rcv'ed
462 * ADISC or PDISC after the paused RPI has been resumed.
465 lpfc_mbx_cmpl_resume_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
467 struct lpfc_vport *vport;
468 struct lpfc_iocbq *elsiocb;
469 struct lpfc_nodelist *ndlp;
472 elsiocb = (struct lpfc_iocbq *)mboxq->context1;
473 ndlp = (struct lpfc_nodelist *) mboxq->context2;
474 vport = mboxq->vport;
475 cmd = elsiocb->drvrTimeout;
477 if (cmd == ELS_CMD_ADISC) {
478 lpfc_els_rsp_adisc_acc(vport, elsiocb, ndlp);
480 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, elsiocb,
484 mempool_free(mboxq, phba->mbox_mem_pool);
488 lpfc_rcv_padisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
489 struct lpfc_iocbq *cmdiocb)
491 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
492 struct lpfc_iocbq *elsiocb;
493 struct lpfc_dmabuf *pcmd;
494 struct serv_parm *sp;
495 struct lpfc_name *pnn, *ppn;
502 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
503 lp = (uint32_t *) pcmd->virt;
506 if (cmd == ELS_CMD_ADISC) {
508 pnn = (struct lpfc_name *) & ap->nodeName;
509 ppn = (struct lpfc_name *) & ap->portName;
511 sp = (struct serv_parm *) lp;
512 pnn = (struct lpfc_name *) & sp->nodeName;
513 ppn = (struct lpfc_name *) & sp->portName;
516 icmd = &cmdiocb->iocb;
517 if (icmd->ulpStatus == 0 && lpfc_check_adisc(vport, ndlp, pnn, ppn)) {
520 * As soon as we send ACC, the remote NPort can
521 * start sending us data. Thus, for SLI4 we must
522 * resume the RPI before the ACC goes out.
524 if (vport->phba->sli_rev == LPFC_SLI_REV4) {
525 elsiocb = kmalloc(sizeof(struct lpfc_iocbq),
529 /* Save info from cmd IOCB used in rsp */
530 memcpy((uint8_t *)elsiocb, (uint8_t *)cmdiocb,
531 sizeof(struct lpfc_iocbq));
533 /* Save the ELS cmd */
534 elsiocb->drvrTimeout = cmd;
536 lpfc_sli4_resume_rpi(ndlp,
537 lpfc_mbx_cmpl_resume_rpi, elsiocb);
542 if (cmd == ELS_CMD_ADISC) {
543 lpfc_els_rsp_adisc_acc(vport, cmdiocb, ndlp);
545 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb,
549 /* If we are authenticated, move to the proper state */
550 if (ndlp->nlp_type & NLP_FCP_TARGET)
551 lpfc_nlp_set_state(vport, ndlp, NLP_STE_MAPPED_NODE);
553 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
557 /* Reject this request because invalid parameters */
558 stat.un.b.lsRjtRsvd0 = 0;
559 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
560 stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
561 stat.un.b.vendorUnique = 0;
562 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
565 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ);
567 spin_lock_irq(shost->host_lock);
568 ndlp->nlp_flag |= NLP_DELAY_TMO;
569 spin_unlock_irq(shost->host_lock);
570 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
571 ndlp->nlp_prev_state = ndlp->nlp_state;
572 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
577 lpfc_rcv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
578 struct lpfc_iocbq *cmdiocb, uint32_t els_cmd)
580 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
581 struct lpfc_hba *phba = vport->phba;
582 struct lpfc_vport **vports;
583 int i, active_vlink_present = 0 ;
585 /* Put ndlp in NPR state with 1 sec timeout for plogi, ACC logo */
586 /* Only call LOGO ACC for first LOGO, this avoids sending unnecessary
587 * PLOGIs during LOGO storms from a device.
589 spin_lock_irq(shost->host_lock);
590 ndlp->nlp_flag |= NLP_LOGO_ACC;
591 spin_unlock_irq(shost->host_lock);
592 if (els_cmd == ELS_CMD_PRLO)
593 lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL);
595 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
596 if (ndlp->nlp_DID == Fabric_DID) {
597 if (vport->port_state <= LPFC_FDISC)
599 lpfc_linkdown_port(vport);
600 spin_lock_irq(shost->host_lock);
601 vport->fc_flag |= FC_VPORT_LOGO_RCVD;
602 spin_unlock_irq(shost->host_lock);
603 vports = lpfc_create_vport_work_array(phba);
605 for (i = 0; i <= phba->max_vports && vports[i] != NULL;
607 if ((!(vports[i]->fc_flag &
608 FC_VPORT_LOGO_RCVD)) &&
609 (vports[i]->port_state > LPFC_FDISC)) {
610 active_vlink_present = 1;
614 lpfc_destroy_vport_work_array(phba, vports);
617 if (active_vlink_present) {
619 * If there are other active VLinks present,
620 * re-instantiate the Vlink using FDISC.
622 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ);
623 spin_lock_irq(shost->host_lock);
624 ndlp->nlp_flag |= NLP_DELAY_TMO;
625 spin_unlock_irq(shost->host_lock);
626 ndlp->nlp_last_elscmd = ELS_CMD_FDISC;
627 vport->port_state = LPFC_FDISC;
629 spin_lock_irq(shost->host_lock);
630 phba->pport->fc_flag &= ~FC_LOGO_RCVD_DID_CHNG;
631 spin_unlock_irq(shost->host_lock);
632 lpfc_retry_pport_discovery(phba);
634 } else if ((!(ndlp->nlp_type & NLP_FABRIC) &&
635 ((ndlp->nlp_type & NLP_FCP_TARGET) ||
636 !(ndlp->nlp_type & NLP_FCP_INITIATOR))) ||
637 (ndlp->nlp_state == NLP_STE_ADISC_ISSUE)) {
638 /* Only try to re-login if this is NOT a Fabric Node */
639 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ * 1);
640 spin_lock_irq(shost->host_lock);
641 ndlp->nlp_flag |= NLP_DELAY_TMO;
642 spin_unlock_irq(shost->host_lock);
644 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
647 ndlp->nlp_prev_state = ndlp->nlp_state;
648 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
650 spin_lock_irq(shost->host_lock);
651 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
652 spin_unlock_irq(shost->host_lock);
653 /* The driver has to wait until the ACC completes before it continues
654 * processing the LOGO. The action will resume in
655 * lpfc_cmpl_els_logo_acc routine. Since part of processing includes an
656 * unreg_login, the driver waits so the ACC does not get aborted.
662 lpfc_rcv_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
663 struct lpfc_iocbq *cmdiocb)
665 struct lpfc_dmabuf *pcmd;
668 struct fc_rport *rport = ndlp->rport;
671 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
672 lp = (uint32_t *) pcmd->virt;
673 npr = (PRLI *) ((uint8_t *) lp + sizeof (uint32_t));
675 ndlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR);
676 ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
677 if (npr->prliType == PRLI_FCP_TYPE) {
678 if (npr->initiatorFunc)
679 ndlp->nlp_type |= NLP_FCP_INITIATOR;
681 ndlp->nlp_type |= NLP_FCP_TARGET;
683 ndlp->nlp_fcp_info |= NLP_FCP_2_DEVICE;
686 /* We need to update the rport role values */
687 roles = FC_RPORT_ROLE_UNKNOWN;
688 if (ndlp->nlp_type & NLP_FCP_INITIATOR)
689 roles |= FC_RPORT_ROLE_FCP_INITIATOR;
690 if (ndlp->nlp_type & NLP_FCP_TARGET)
691 roles |= FC_RPORT_ROLE_FCP_TARGET;
693 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
694 "rport rolechg: role:x%x did:x%x flg:x%x",
695 roles, ndlp->nlp_DID, ndlp->nlp_flag);
697 fc_remote_port_rolechg(rport, roles);
702 lpfc_disc_set_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
704 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
706 if (!(ndlp->nlp_flag & NLP_RPI_REGISTERED)) {
707 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
711 if (!(vport->fc_flag & FC_PT2PT)) {
712 /* Check config parameter use-adisc or FCP-2 */
713 if ((vport->cfg_use_adisc && (vport->fc_flag & FC_RSCN_MODE)) ||
714 ((ndlp->nlp_fcp_info & NLP_FCP_2_DEVICE) &&
715 (ndlp->nlp_type & NLP_FCP_TARGET))) {
716 spin_lock_irq(shost->host_lock);
717 ndlp->nlp_flag |= NLP_NPR_ADISC;
718 spin_unlock_irq(shost->host_lock);
722 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
723 lpfc_unreg_rpi(vport, ndlp);
728 * lpfc_release_rpi - Release a RPI by issuing unreg_login mailbox cmd.
729 * @phba : Pointer to lpfc_hba structure.
730 * @vport: Pointer to lpfc_vport structure.
731 * @rpi : rpi to be release.
733 * This function will send a unreg_login mailbox command to the firmware
737 lpfc_release_rpi(struct lpfc_hba *phba,
738 struct lpfc_vport *vport,
744 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
747 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
748 "2796 mailbox memory allocation failed \n");
750 lpfc_unreg_login(phba, vport->vpi, rpi, pmb);
751 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
752 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
753 if (rc == MBX_NOT_FINISHED)
754 mempool_free(pmb, phba->mbox_mem_pool);
759 lpfc_disc_illegal(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
760 void *arg, uint32_t evt)
762 struct lpfc_hba *phba;
763 LPFC_MBOXQ_t *pmb = (LPFC_MBOXQ_t *) arg;
768 /* Release the RPI if reglogin completing */
769 if (!(phba->pport->load_flag & FC_UNLOADING) &&
770 (evt == NLP_EVT_CMPL_REG_LOGIN) &&
771 (!pmb->u.mb.mbxStatus)) {
773 rpi = pmb->u.mb.un.varWords[0];
774 lpfc_release_rpi(phba, vport, rpi);
776 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
777 "0271 Illegal State Transition: node x%x "
778 "event x%x, state x%x Data: x%x x%x\n",
779 ndlp->nlp_DID, evt, ndlp->nlp_state, ndlp->nlp_rpi,
781 return ndlp->nlp_state;
785 lpfc_cmpl_plogi_illegal(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
786 void *arg, uint32_t evt)
788 /* This transition is only legal if we previously
789 * rcv'ed a PLOGI. Since we don't want 2 discovery threads
790 * working on the same NPortID, do nothing for this thread
793 if (!(ndlp->nlp_flag & NLP_RCV_PLOGI)) {
794 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
795 "0272 Illegal State Transition: node x%x "
796 "event x%x, state x%x Data: x%x x%x\n",
797 ndlp->nlp_DID, evt, ndlp->nlp_state, ndlp->nlp_rpi,
800 return ndlp->nlp_state;
803 /* Start of Discovery State Machine routines */
806 lpfc_rcv_plogi_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
807 void *arg, uint32_t evt)
809 struct lpfc_iocbq *cmdiocb;
811 cmdiocb = (struct lpfc_iocbq *) arg;
813 if (lpfc_rcv_plogi(vport, ndlp, cmdiocb)) {
814 return ndlp->nlp_state;
816 return NLP_STE_FREED_NODE;
820 lpfc_rcv_els_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
821 void *arg, uint32_t evt)
823 lpfc_issue_els_logo(vport, ndlp, 0);
824 return ndlp->nlp_state;
828 lpfc_rcv_logo_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
829 void *arg, uint32_t evt)
831 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
832 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
834 spin_lock_irq(shost->host_lock);
835 ndlp->nlp_flag |= NLP_LOGO_ACC;
836 spin_unlock_irq(shost->host_lock);
837 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
839 return ndlp->nlp_state;
843 lpfc_cmpl_logo_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
844 void *arg, uint32_t evt)
846 return NLP_STE_FREED_NODE;
850 lpfc_device_rm_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
851 void *arg, uint32_t evt)
853 return NLP_STE_FREED_NODE;
857 lpfc_device_recov_unused_node(struct lpfc_vport *vport,
858 struct lpfc_nodelist *ndlp,
859 void *arg, uint32_t evt)
861 return ndlp->nlp_state;
865 lpfc_rcv_plogi_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
866 void *arg, uint32_t evt)
868 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
869 struct lpfc_hba *phba = vport->phba;
870 struct lpfc_iocbq *cmdiocb = arg;
871 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
872 uint32_t *lp = (uint32_t *) pcmd->virt;
873 struct serv_parm *sp = (struct serv_parm *) (lp + 1);
877 memset(&stat, 0, sizeof (struct ls_rjt));
879 /* For a PLOGI, we only accept if our portname is less
880 * than the remote portname.
882 phba->fc_stat.elsLogiCol++;
883 port_cmp = memcmp(&vport->fc_portname, &sp->portName,
884 sizeof(struct lpfc_name));
887 /* Reject this request because the remote node will accept
889 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
890 stat.un.b.lsRjtRsnCodeExp = LSEXP_CMD_IN_PROGRESS;
891 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
894 if (lpfc_rcv_plogi(vport, ndlp, cmdiocb) &&
895 (ndlp->nlp_flag & NLP_NPR_2B_DISC) &&
896 (vport->num_disc_nodes)) {
897 spin_lock_irq(shost->host_lock);
898 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
899 spin_unlock_irq(shost->host_lock);
900 /* Check if there are more PLOGIs to be sent */
901 lpfc_more_plogi(vport);
902 if (vport->num_disc_nodes == 0) {
903 spin_lock_irq(shost->host_lock);
904 vport->fc_flag &= ~FC_NDISC_ACTIVE;
905 spin_unlock_irq(shost->host_lock);
906 lpfc_can_disctmo(vport);
907 lpfc_end_rscn(vport);
910 } /* If our portname was less */
912 return ndlp->nlp_state;
916 lpfc_rcv_prli_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
917 void *arg, uint32_t evt)
919 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
922 memset(&stat, 0, sizeof (struct ls_rjt));
923 stat.un.b.lsRjtRsnCode = LSRJT_LOGICAL_BSY;
924 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
925 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
926 return ndlp->nlp_state;
930 lpfc_rcv_logo_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
931 void *arg, uint32_t evt)
933 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
935 /* software abort outstanding PLOGI */
936 lpfc_els_abort(vport->phba, ndlp);
938 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
939 return ndlp->nlp_state;
943 lpfc_rcv_els_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
944 void *arg, uint32_t evt)
946 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
947 struct lpfc_hba *phba = vport->phba;
948 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
950 /* software abort outstanding PLOGI */
951 lpfc_els_abort(phba, ndlp);
953 if (evt == NLP_EVT_RCV_LOGO) {
954 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
956 lpfc_issue_els_logo(vport, ndlp, 0);
959 /* Put ndlp in npr state set plogi timer for 1 sec */
960 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ * 1);
961 spin_lock_irq(shost->host_lock);
962 ndlp->nlp_flag |= NLP_DELAY_TMO;
963 spin_unlock_irq(shost->host_lock);
964 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
965 ndlp->nlp_prev_state = NLP_STE_PLOGI_ISSUE;
966 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
968 return ndlp->nlp_state;
972 lpfc_cmpl_plogi_plogi_issue(struct lpfc_vport *vport,
973 struct lpfc_nodelist *ndlp,
977 struct lpfc_hba *phba = vport->phba;
978 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
979 struct lpfc_iocbq *cmdiocb, *rspiocb;
980 struct lpfc_dmabuf *pcmd, *prsp, *mp;
983 struct serv_parm *sp;
986 cmdiocb = (struct lpfc_iocbq *) arg;
987 rspiocb = cmdiocb->context_un.rsp_iocb;
989 if (ndlp->nlp_flag & NLP_ACC_REGLOGIN) {
990 /* Recovery from PLOGI collision logic */
991 return ndlp->nlp_state;
994 irsp = &rspiocb->iocb;
999 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
1001 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
1003 lp = (uint32_t *) prsp->virt;
1004 sp = (struct serv_parm *) ((uint8_t *) lp + sizeof (uint32_t));
1006 /* Some switches have FDMI servers returning 0 for WWN */
1007 if ((ndlp->nlp_DID != FDMI_DID) &&
1008 (wwn_to_u64(sp->portName.u.wwn) == 0 ||
1009 wwn_to_u64(sp->nodeName.u.wwn) == 0)) {
1010 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1011 "0142 PLOGI RSP: Invalid WWN.\n");
1014 if (!lpfc_check_sparm(vport, ndlp, sp, CLASS3, 0))
1016 /* PLOGI chkparm OK */
1017 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1018 "0121 PLOGI chkparm OK Data: x%x x%x x%x x%x\n",
1019 ndlp->nlp_DID, ndlp->nlp_state,
1020 ndlp->nlp_flag, ndlp->nlp_rpi);
1021 if (vport->cfg_fcp_class == 2 && (sp->cls2.classValid))
1022 ndlp->nlp_fcp_info |= CLASS2;
1024 ndlp->nlp_fcp_info |= CLASS3;
1026 ndlp->nlp_class_sup = 0;
1027 if (sp->cls1.classValid)
1028 ndlp->nlp_class_sup |= FC_COS_CLASS1;
1029 if (sp->cls2.classValid)
1030 ndlp->nlp_class_sup |= FC_COS_CLASS2;
1031 if (sp->cls3.classValid)
1032 ndlp->nlp_class_sup |= FC_COS_CLASS3;
1033 if (sp->cls4.classValid)
1034 ndlp->nlp_class_sup |= FC_COS_CLASS4;
1035 ndlp->nlp_maxframe =
1036 ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) | sp->cmn.bbRcvSizeLsb;
1038 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1040 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1041 "0133 PLOGI: no memory for reg_login "
1042 "Data: x%x x%x x%x x%x\n",
1043 ndlp->nlp_DID, ndlp->nlp_state,
1044 ndlp->nlp_flag, ndlp->nlp_rpi);
1048 lpfc_unreg_rpi(vport, ndlp);
1050 if (lpfc_reg_rpi(phba, vport->vpi, irsp->un.elsreq64.remoteID,
1051 (uint8_t *) sp, mbox, ndlp->nlp_rpi) == 0) {
1052 switch (ndlp->nlp_DID) {
1053 case NameServer_DID:
1054 mbox->mbox_cmpl = lpfc_mbx_cmpl_ns_reg_login;
1057 mbox->mbox_cmpl = lpfc_mbx_cmpl_fdmi_reg_login;
1060 ndlp->nlp_flag |= NLP_REG_LOGIN_SEND;
1061 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
1063 mbox->context2 = lpfc_nlp_get(ndlp);
1064 mbox->vport = vport;
1065 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
1066 != MBX_NOT_FINISHED) {
1067 lpfc_nlp_set_state(vport, ndlp,
1068 NLP_STE_REG_LOGIN_ISSUE);
1069 return ndlp->nlp_state;
1071 if (ndlp->nlp_flag & NLP_REG_LOGIN_SEND)
1072 ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND;
1073 /* decrement node reference count to the failed mbox
1077 mp = (struct lpfc_dmabuf *) mbox->context1;
1078 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1080 mempool_free(mbox, phba->mbox_mem_pool);
1082 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1083 "0134 PLOGI: cannot issue reg_login "
1084 "Data: x%x x%x x%x x%x\n",
1085 ndlp->nlp_DID, ndlp->nlp_state,
1086 ndlp->nlp_flag, ndlp->nlp_rpi);
1088 mempool_free(mbox, phba->mbox_mem_pool);
1090 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1091 "0135 PLOGI: cannot format reg_login "
1092 "Data: x%x x%x x%x x%x\n",
1093 ndlp->nlp_DID, ndlp->nlp_state,
1094 ndlp->nlp_flag, ndlp->nlp_rpi);
1099 if (ndlp->nlp_DID == NameServer_DID) {
1100 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
1101 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1102 "0261 Cannot Register NameServer login\n");
1105 spin_lock_irq(shost->host_lock);
1106 ndlp->nlp_flag |= NLP_DEFER_RM;
1107 spin_unlock_irq(shost->host_lock);
1108 return NLP_STE_FREED_NODE;
1112 lpfc_cmpl_logo_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1113 void *arg, uint32_t evt)
1115 return ndlp->nlp_state;
1119 lpfc_cmpl_reglogin_plogi_issue(struct lpfc_vport *vport,
1120 struct lpfc_nodelist *ndlp, void *arg, uint32_t evt)
1122 struct lpfc_hba *phba;
1123 LPFC_MBOXQ_t *pmb = (LPFC_MBOXQ_t *) arg;
1124 MAILBOX_t *mb = &pmb->u.mb;
1128 /* Release the RPI */
1129 if (!(phba->pport->load_flag & FC_UNLOADING) &&
1131 rpi = pmb->u.mb.un.varWords[0];
1132 lpfc_release_rpi(phba, vport, rpi);
1134 return ndlp->nlp_state;
1138 lpfc_device_rm_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1139 void *arg, uint32_t evt)
1141 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1143 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1144 spin_lock_irq(shost->host_lock);
1145 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
1146 spin_unlock_irq(shost->host_lock);
1147 return ndlp->nlp_state;
1149 /* software abort outstanding PLOGI */
1150 lpfc_els_abort(vport->phba, ndlp);
1152 lpfc_drop_node(vport, ndlp);
1153 return NLP_STE_FREED_NODE;
1158 lpfc_device_recov_plogi_issue(struct lpfc_vport *vport,
1159 struct lpfc_nodelist *ndlp,
1163 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1164 struct lpfc_hba *phba = vport->phba;
1166 /* Don't do anything that will mess up processing of the
1169 if (vport->fc_flag & FC_RSCN_DEFERRED)
1170 return ndlp->nlp_state;
1172 /* software abort outstanding PLOGI */
1173 lpfc_els_abort(phba, ndlp);
1175 ndlp->nlp_prev_state = NLP_STE_PLOGI_ISSUE;
1176 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1177 spin_lock_irq(shost->host_lock);
1178 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
1179 spin_unlock_irq(shost->host_lock);
1181 return ndlp->nlp_state;
1185 lpfc_rcv_plogi_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1186 void *arg, uint32_t evt)
1188 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1189 struct lpfc_hba *phba = vport->phba;
1190 struct lpfc_iocbq *cmdiocb;
1192 /* software abort outstanding ADISC */
1193 lpfc_els_abort(phba, ndlp);
1195 cmdiocb = (struct lpfc_iocbq *) arg;
1197 if (lpfc_rcv_plogi(vport, ndlp, cmdiocb)) {
1198 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1199 spin_lock_irq(shost->host_lock);
1200 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
1201 spin_unlock_irq(shost->host_lock);
1202 if (vport->num_disc_nodes)
1203 lpfc_more_adisc(vport);
1205 return ndlp->nlp_state;
1207 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
1208 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
1209 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
1211 return ndlp->nlp_state;
1215 lpfc_rcv_prli_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1216 void *arg, uint32_t evt)
1218 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1220 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
1221 return ndlp->nlp_state;
1225 lpfc_rcv_logo_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1226 void *arg, uint32_t evt)
1228 struct lpfc_hba *phba = vport->phba;
1229 struct lpfc_iocbq *cmdiocb;
1231 cmdiocb = (struct lpfc_iocbq *) arg;
1233 /* software abort outstanding ADISC */
1234 lpfc_els_abort(phba, ndlp);
1236 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
1237 return ndlp->nlp_state;
1241 lpfc_rcv_padisc_adisc_issue(struct lpfc_vport *vport,
1242 struct lpfc_nodelist *ndlp,
1243 void *arg, uint32_t evt)
1245 struct lpfc_iocbq *cmdiocb;
1247 cmdiocb = (struct lpfc_iocbq *) arg;
1249 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
1250 return ndlp->nlp_state;
1254 lpfc_rcv_prlo_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1255 void *arg, uint32_t evt)
1257 struct lpfc_iocbq *cmdiocb;
1259 cmdiocb = (struct lpfc_iocbq *) arg;
1261 /* Treat like rcv logo */
1262 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_PRLO);
1263 return ndlp->nlp_state;
1267 lpfc_cmpl_adisc_adisc_issue(struct lpfc_vport *vport,
1268 struct lpfc_nodelist *ndlp,
1269 void *arg, uint32_t evt)
1271 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1272 struct lpfc_hba *phba = vport->phba;
1273 struct lpfc_iocbq *cmdiocb, *rspiocb;
1278 cmdiocb = (struct lpfc_iocbq *) arg;
1279 rspiocb = cmdiocb->context_un.rsp_iocb;
1281 ap = (ADISC *)lpfc_check_elscmpl_iocb(phba, cmdiocb, rspiocb);
1282 irsp = &rspiocb->iocb;
1284 if ((irsp->ulpStatus) ||
1285 (!lpfc_check_adisc(vport, ndlp, &ap->nodeName, &ap->portName))) {
1287 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ);
1288 spin_lock_irq(shost->host_lock);
1289 ndlp->nlp_flag |= NLP_DELAY_TMO;
1290 spin_unlock_irq(shost->host_lock);
1291 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
1293 memset(&ndlp->nlp_nodename, 0, sizeof(struct lpfc_name));
1294 memset(&ndlp->nlp_portname, 0, sizeof(struct lpfc_name));
1296 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
1297 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1298 lpfc_unreg_rpi(vport, ndlp);
1299 return ndlp->nlp_state;
1302 if (phba->sli_rev == LPFC_SLI_REV4) {
1303 rc = lpfc_sli4_resume_rpi(ndlp, NULL, NULL);
1305 /* Stay in state and retry. */
1306 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
1307 return ndlp->nlp_state;
1311 if (ndlp->nlp_type & NLP_FCP_TARGET) {
1312 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
1313 lpfc_nlp_set_state(vport, ndlp, NLP_STE_MAPPED_NODE);
1315 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
1316 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
1319 return ndlp->nlp_state;
1323 lpfc_device_rm_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1324 void *arg, uint32_t evt)
1326 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1328 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1329 spin_lock_irq(shost->host_lock);
1330 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
1331 spin_unlock_irq(shost->host_lock);
1332 return ndlp->nlp_state;
1334 /* software abort outstanding ADISC */
1335 lpfc_els_abort(vport->phba, ndlp);
1337 lpfc_drop_node(vport, ndlp);
1338 return NLP_STE_FREED_NODE;
1343 lpfc_device_recov_adisc_issue(struct lpfc_vport *vport,
1344 struct lpfc_nodelist *ndlp,
1348 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1349 struct lpfc_hba *phba = vport->phba;
1351 /* Don't do anything that will mess up processing of the
1354 if (vport->fc_flag & FC_RSCN_DEFERRED)
1355 return ndlp->nlp_state;
1357 /* software abort outstanding ADISC */
1358 lpfc_els_abort(phba, ndlp);
1360 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
1361 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1362 spin_lock_irq(shost->host_lock);
1363 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
1364 spin_unlock_irq(shost->host_lock);
1365 lpfc_disc_set_adisc(vport, ndlp);
1366 return ndlp->nlp_state;
1370 lpfc_rcv_plogi_reglogin_issue(struct lpfc_vport *vport,
1371 struct lpfc_nodelist *ndlp,
1375 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1377 lpfc_rcv_plogi(vport, ndlp, cmdiocb);
1378 return ndlp->nlp_state;
1382 lpfc_rcv_prli_reglogin_issue(struct lpfc_vport *vport,
1383 struct lpfc_nodelist *ndlp,
1387 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1389 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
1390 return ndlp->nlp_state;
1394 lpfc_rcv_logo_reglogin_issue(struct lpfc_vport *vport,
1395 struct lpfc_nodelist *ndlp,
1399 struct lpfc_hba *phba = vport->phba;
1400 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1402 LPFC_MBOXQ_t *nextmb;
1403 struct lpfc_dmabuf *mp;
1405 cmdiocb = (struct lpfc_iocbq *) arg;
1407 /* cleanup any ndlp on mbox q waiting for reglogin cmpl */
1408 if ((mb = phba->sli.mbox_active)) {
1409 if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) &&
1410 (ndlp == (struct lpfc_nodelist *) mb->context2)) {
1412 mb->context2 = NULL;
1413 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1417 spin_lock_irq(&phba->hbalock);
1418 list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) {
1419 if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) &&
1420 (ndlp == (struct lpfc_nodelist *) mb->context2)) {
1421 mp = (struct lpfc_dmabuf *) (mb->context1);
1423 __lpfc_mbuf_free(phba, mp->virt, mp->phys);
1427 list_del(&mb->list);
1428 phba->sli.mboxq_cnt--;
1429 mempool_free(mb, phba->mbox_mem_pool);
1432 spin_unlock_irq(&phba->hbalock);
1434 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
1435 return ndlp->nlp_state;
1439 lpfc_rcv_padisc_reglogin_issue(struct lpfc_vport *vport,
1440 struct lpfc_nodelist *ndlp,
1444 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1446 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
1447 return ndlp->nlp_state;
1451 lpfc_rcv_prlo_reglogin_issue(struct lpfc_vport *vport,
1452 struct lpfc_nodelist *ndlp,
1456 struct lpfc_iocbq *cmdiocb;
1458 cmdiocb = (struct lpfc_iocbq *) arg;
1459 lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL);
1460 return ndlp->nlp_state;
1464 lpfc_cmpl_reglogin_reglogin_issue(struct lpfc_vport *vport,
1465 struct lpfc_nodelist *ndlp,
1469 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1470 LPFC_MBOXQ_t *pmb = (LPFC_MBOXQ_t *) arg;
1471 MAILBOX_t *mb = &pmb->u.mb;
1472 uint32_t did = mb->un.varWords[1];
1474 if (mb->mbxStatus) {
1475 /* RegLogin failed */
1476 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
1477 "0246 RegLogin failed Data: x%x x%x x%x x%x "
1479 did, mb->mbxStatus, vport->port_state,
1480 mb->un.varRegLogin.vpi,
1481 mb->un.varRegLogin.rpi);
1483 * If RegLogin failed due to lack of HBA resources do not
1486 if (mb->mbxStatus == MBXERR_RPI_FULL) {
1487 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
1488 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1489 return ndlp->nlp_state;
1492 /* Put ndlp in npr state set plogi timer for 1 sec */
1493 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ * 1);
1494 spin_lock_irq(shost->host_lock);
1495 ndlp->nlp_flag |= NLP_DELAY_TMO;
1496 spin_unlock_irq(shost->host_lock);
1497 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
1499 lpfc_issue_els_logo(vport, ndlp, 0);
1500 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
1501 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1502 return ndlp->nlp_state;
1505 /* SLI4 ports have preallocated logical rpis. */
1506 if (vport->phba->sli_rev < LPFC_SLI_REV4)
1507 ndlp->nlp_rpi = mb->un.varWords[0];
1509 ndlp->nlp_flag |= NLP_RPI_REGISTERED;
1511 /* Only if we are not a fabric nport do we issue PRLI */
1512 if (!(ndlp->nlp_type & NLP_FABRIC)) {
1513 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
1514 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
1515 lpfc_issue_els_prli(vport, ndlp, 0);
1517 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
1518 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
1520 return ndlp->nlp_state;
1524 lpfc_device_rm_reglogin_issue(struct lpfc_vport *vport,
1525 struct lpfc_nodelist *ndlp,
1529 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1531 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1532 spin_lock_irq(shost->host_lock);
1533 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
1534 spin_unlock_irq(shost->host_lock);
1535 return ndlp->nlp_state;
1537 lpfc_drop_node(vport, ndlp);
1538 return NLP_STE_FREED_NODE;
1543 lpfc_device_recov_reglogin_issue(struct lpfc_vport *vport,
1544 struct lpfc_nodelist *ndlp,
1548 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1550 /* Don't do anything that will mess up processing of the
1553 if (vport->fc_flag & FC_RSCN_DEFERRED)
1554 return ndlp->nlp_state;
1556 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
1557 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1558 spin_lock_irq(shost->host_lock);
1559 ndlp->nlp_flag |= NLP_IGNR_REG_CMPL;
1560 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
1561 spin_unlock_irq(shost->host_lock);
1562 lpfc_disc_set_adisc(vport, ndlp);
1563 return ndlp->nlp_state;
1567 lpfc_rcv_plogi_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1568 void *arg, uint32_t evt)
1570 struct lpfc_iocbq *cmdiocb;
1572 cmdiocb = (struct lpfc_iocbq *) arg;
1574 lpfc_rcv_plogi(vport, ndlp, cmdiocb);
1575 return ndlp->nlp_state;
1579 lpfc_rcv_prli_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1580 void *arg, uint32_t evt)
1582 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1584 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
1585 return ndlp->nlp_state;
1589 lpfc_rcv_logo_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1590 void *arg, uint32_t evt)
1592 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1594 /* Software abort outstanding PRLI before sending acc */
1595 lpfc_els_abort(vport->phba, ndlp);
1597 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
1598 return ndlp->nlp_state;
1602 lpfc_rcv_padisc_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1603 void *arg, uint32_t evt)
1605 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1607 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
1608 return ndlp->nlp_state;
1611 /* This routine is envoked when we rcv a PRLO request from a nport
1612 * we are logged into. We should send back a PRLO rsp setting the
1614 * NEXT STATE = PRLI_ISSUE
1617 lpfc_rcv_prlo_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1618 void *arg, uint32_t evt)
1620 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1622 lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL);
1623 return ndlp->nlp_state;
1627 lpfc_cmpl_prli_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1628 void *arg, uint32_t evt)
1630 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1631 struct lpfc_iocbq *cmdiocb, *rspiocb;
1632 struct lpfc_hba *phba = vport->phba;
1636 cmdiocb = (struct lpfc_iocbq *) arg;
1637 rspiocb = cmdiocb->context_un.rsp_iocb;
1638 npr = (PRLI *)lpfc_check_elscmpl_iocb(phba, cmdiocb, rspiocb);
1640 irsp = &rspiocb->iocb;
1641 if (irsp->ulpStatus) {
1642 if ((vport->port_type == LPFC_NPIV_PORT) &&
1643 vport->cfg_restrict_login) {
1646 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
1647 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
1648 return ndlp->nlp_state;
1651 /* Check out PRLI rsp */
1652 ndlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR);
1653 ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
1654 if ((npr->acceptRspCode == PRLI_REQ_EXECUTED) &&
1655 (npr->prliType == PRLI_FCP_TYPE)) {
1656 if (npr->initiatorFunc)
1657 ndlp->nlp_type |= NLP_FCP_INITIATOR;
1658 if (npr->targetFunc)
1659 ndlp->nlp_type |= NLP_FCP_TARGET;
1661 ndlp->nlp_fcp_info |= NLP_FCP_2_DEVICE;
1663 if (!(ndlp->nlp_type & NLP_FCP_TARGET) &&
1664 (vport->port_type == LPFC_NPIV_PORT) &&
1665 vport->cfg_restrict_login) {
1667 spin_lock_irq(shost->host_lock);
1668 ndlp->nlp_flag |= NLP_TARGET_REMOVE;
1669 spin_unlock_irq(shost->host_lock);
1670 lpfc_issue_els_logo(vport, ndlp, 0);
1672 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
1673 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1674 return ndlp->nlp_state;
1677 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
1678 if (ndlp->nlp_type & NLP_FCP_TARGET)
1679 lpfc_nlp_set_state(vport, ndlp, NLP_STE_MAPPED_NODE);
1681 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
1682 return ndlp->nlp_state;
1685 /*! lpfc_device_rm_prli_issue
1696 * This routine is envoked when we a request to remove a nport we are in the
1697 * process of PRLIing. We should software abort outstanding prli, unreg
1698 * login, send a logout. We will change node state to UNUSED_NODE, put it
1699 * on plogi list so it can be freed when LOGO completes.
1704 lpfc_device_rm_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1705 void *arg, uint32_t evt)
1707 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1709 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1710 spin_lock_irq(shost->host_lock);
1711 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
1712 spin_unlock_irq(shost->host_lock);
1713 return ndlp->nlp_state;
1715 /* software abort outstanding PLOGI */
1716 lpfc_els_abort(vport->phba, ndlp);
1718 lpfc_drop_node(vport, ndlp);
1719 return NLP_STE_FREED_NODE;
1724 /*! lpfc_device_recov_prli_issue
1735 * The routine is envoked when the state of a device is unknown, like
1736 * during a link down. We should remove the nodelist entry from the
1737 * unmapped list, issue a UNREG_LOGIN, do a software abort of the
1738 * outstanding PRLI command, then free the node entry.
1741 lpfc_device_recov_prli_issue(struct lpfc_vport *vport,
1742 struct lpfc_nodelist *ndlp,
1746 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1747 struct lpfc_hba *phba = vport->phba;
1749 /* Don't do anything that will mess up processing of the
1752 if (vport->fc_flag & FC_RSCN_DEFERRED)
1753 return ndlp->nlp_state;
1755 /* software abort outstanding PRLI */
1756 lpfc_els_abort(phba, ndlp);
1758 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
1759 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1760 spin_lock_irq(shost->host_lock);
1761 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
1762 spin_unlock_irq(shost->host_lock);
1763 lpfc_disc_set_adisc(vport, ndlp);
1764 return ndlp->nlp_state;
1768 lpfc_rcv_plogi_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1769 void *arg, uint32_t evt)
1771 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1773 lpfc_rcv_plogi(vport, ndlp, cmdiocb);
1774 return ndlp->nlp_state;
1778 lpfc_rcv_prli_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1779 void *arg, uint32_t evt)
1781 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1783 lpfc_rcv_prli(vport, ndlp, cmdiocb);
1784 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
1785 return ndlp->nlp_state;
1789 lpfc_rcv_logo_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1790 void *arg, uint32_t evt)
1792 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1794 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
1795 return ndlp->nlp_state;
1799 lpfc_rcv_padisc_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1800 void *arg, uint32_t evt)
1802 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1804 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
1805 return ndlp->nlp_state;
1809 lpfc_rcv_prlo_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1810 void *arg, uint32_t evt)
1812 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1814 lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL);
1815 return ndlp->nlp_state;
1819 lpfc_device_recov_unmap_node(struct lpfc_vport *vport,
1820 struct lpfc_nodelist *ndlp,
1824 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1826 ndlp->nlp_prev_state = NLP_STE_UNMAPPED_NODE;
1827 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1828 spin_lock_irq(shost->host_lock);
1829 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
1830 spin_unlock_irq(shost->host_lock);
1831 lpfc_disc_set_adisc(vport, ndlp);
1833 return ndlp->nlp_state;
1837 lpfc_rcv_plogi_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1838 void *arg, uint32_t evt)
1840 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1842 lpfc_rcv_plogi(vport, ndlp, cmdiocb);
1843 return ndlp->nlp_state;
1847 lpfc_rcv_prli_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1848 void *arg, uint32_t evt)
1850 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1852 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
1853 return ndlp->nlp_state;
1857 lpfc_rcv_logo_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1858 void *arg, uint32_t evt)
1860 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1862 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
1863 return ndlp->nlp_state;
1867 lpfc_rcv_padisc_mapped_node(struct lpfc_vport *vport,
1868 struct lpfc_nodelist *ndlp,
1869 void *arg, uint32_t evt)
1871 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1873 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
1874 return ndlp->nlp_state;
1878 lpfc_rcv_prlo_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1879 void *arg, uint32_t evt)
1881 struct lpfc_hba *phba = vport->phba;
1882 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1884 /* flush the target */
1885 lpfc_sli_abort_iocb(vport, &phba->sli.ring[phba->sli.fcp_ring],
1886 ndlp->nlp_sid, 0, LPFC_CTX_TGT);
1888 /* Treat like rcv logo */
1889 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_PRLO);
1890 return ndlp->nlp_state;
1894 lpfc_device_recov_mapped_node(struct lpfc_vport *vport,
1895 struct lpfc_nodelist *ndlp,
1899 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1901 ndlp->nlp_prev_state = NLP_STE_MAPPED_NODE;
1902 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1903 spin_lock_irq(shost->host_lock);
1904 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
1905 spin_unlock_irq(shost->host_lock);
1906 lpfc_disc_set_adisc(vport, ndlp);
1907 return ndlp->nlp_state;
1911 lpfc_rcv_plogi_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1912 void *arg, uint32_t evt)
1914 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1915 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1917 /* Ignore PLOGI if we have an outstanding LOGO */
1918 if (ndlp->nlp_flag & (NLP_LOGO_SND | NLP_LOGO_ACC))
1919 return ndlp->nlp_state;
1920 if (lpfc_rcv_plogi(vport, ndlp, cmdiocb)) {
1921 lpfc_cancel_retry_delay_tmo(vport, ndlp);
1922 spin_lock_irq(shost->host_lock);
1923 ndlp->nlp_flag &= ~(NLP_NPR_ADISC | NLP_NPR_2B_DISC);
1924 spin_unlock_irq(shost->host_lock);
1925 } else if (!(ndlp->nlp_flag & NLP_NPR_2B_DISC)) {
1926 /* send PLOGI immediately, move to PLOGI issue state */
1927 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
1928 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
1929 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
1930 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
1933 return ndlp->nlp_state;
1937 lpfc_rcv_prli_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1938 void *arg, uint32_t evt)
1940 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1941 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1944 memset(&stat, 0, sizeof (struct ls_rjt));
1945 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
1946 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
1947 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
1949 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
1950 if (ndlp->nlp_flag & NLP_NPR_ADISC) {
1951 spin_lock_irq(shost->host_lock);
1952 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
1953 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
1954 spin_unlock_irq(shost->host_lock);
1955 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
1956 lpfc_issue_els_adisc(vport, ndlp, 0);
1958 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
1959 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
1960 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
1963 return ndlp->nlp_state;
1967 lpfc_rcv_logo_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1968 void *arg, uint32_t evt)
1970 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1972 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
1973 return ndlp->nlp_state;
1977 lpfc_rcv_padisc_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1978 void *arg, uint32_t evt)
1980 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1982 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
1984 * Do not start discovery if discovery is about to start
1985 * or discovery in progress for this node. Starting discovery
1986 * here will affect the counting of discovery threads.
1988 if (!(ndlp->nlp_flag & NLP_DELAY_TMO) &&
1989 !(ndlp->nlp_flag & NLP_NPR_2B_DISC)) {
1990 if (ndlp->nlp_flag & NLP_NPR_ADISC) {
1991 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
1992 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
1993 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
1994 lpfc_issue_els_adisc(vport, ndlp, 0);
1996 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
1997 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
1998 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
2001 return ndlp->nlp_state;
2005 lpfc_rcv_prlo_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2006 void *arg, uint32_t evt)
2008 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2009 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2011 spin_lock_irq(shost->host_lock);
2012 ndlp->nlp_flag |= NLP_LOGO_ACC;
2013 spin_unlock_irq(shost->host_lock);
2015 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
2017 if ((ndlp->nlp_flag & NLP_DELAY_TMO) == 0) {
2018 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ * 1);
2019 spin_lock_irq(shost->host_lock);
2020 ndlp->nlp_flag |= NLP_DELAY_TMO;
2021 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
2022 spin_unlock_irq(shost->host_lock);
2023 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
2025 spin_lock_irq(shost->host_lock);
2026 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
2027 spin_unlock_irq(shost->host_lock);
2029 return ndlp->nlp_state;
2033 lpfc_cmpl_plogi_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2034 void *arg, uint32_t evt)
2036 struct lpfc_iocbq *cmdiocb, *rspiocb;
2039 cmdiocb = (struct lpfc_iocbq *) arg;
2040 rspiocb = cmdiocb->context_un.rsp_iocb;
2042 irsp = &rspiocb->iocb;
2043 if (irsp->ulpStatus) {
2044 ndlp->nlp_flag |= NLP_DEFER_RM;
2045 return NLP_STE_FREED_NODE;
2047 return ndlp->nlp_state;
2051 lpfc_cmpl_prli_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2052 void *arg, uint32_t evt)
2054 struct lpfc_iocbq *cmdiocb, *rspiocb;
2057 cmdiocb = (struct lpfc_iocbq *) arg;
2058 rspiocb = cmdiocb->context_un.rsp_iocb;
2060 irsp = &rspiocb->iocb;
2061 if (irsp->ulpStatus && (ndlp->nlp_flag & NLP_NODEV_REMOVE)) {
2062 lpfc_drop_node(vport, ndlp);
2063 return NLP_STE_FREED_NODE;
2065 return ndlp->nlp_state;
2069 lpfc_cmpl_logo_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2070 void *arg, uint32_t evt)
2072 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2073 if (ndlp->nlp_DID == Fabric_DID) {
2074 spin_lock_irq(shost->host_lock);
2075 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
2076 spin_unlock_irq(shost->host_lock);
2078 lpfc_unreg_rpi(vport, ndlp);
2079 return ndlp->nlp_state;
2083 lpfc_cmpl_adisc_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2084 void *arg, uint32_t evt)
2086 struct lpfc_iocbq *cmdiocb, *rspiocb;
2089 cmdiocb = (struct lpfc_iocbq *) arg;
2090 rspiocb = cmdiocb->context_un.rsp_iocb;
2092 irsp = &rspiocb->iocb;
2093 if (irsp->ulpStatus && (ndlp->nlp_flag & NLP_NODEV_REMOVE)) {
2094 lpfc_drop_node(vport, ndlp);
2095 return NLP_STE_FREED_NODE;
2097 return ndlp->nlp_state;
2101 lpfc_cmpl_reglogin_npr_node(struct lpfc_vport *vport,
2102 struct lpfc_nodelist *ndlp,
2103 void *arg, uint32_t evt)
2105 LPFC_MBOXQ_t *pmb = (LPFC_MBOXQ_t *) arg;
2106 MAILBOX_t *mb = &pmb->u.mb;
2108 if (!mb->mbxStatus) {
2109 /* SLI4 ports have preallocated logical rpis. */
2110 if (vport->phba->sli_rev < LPFC_SLI_REV4)
2111 ndlp->nlp_rpi = mb->un.varWords[0];
2112 ndlp->nlp_flag |= NLP_RPI_REGISTERED;
2114 if (ndlp->nlp_flag & NLP_NODEV_REMOVE) {
2115 lpfc_drop_node(vport, ndlp);
2116 return NLP_STE_FREED_NODE;
2119 return ndlp->nlp_state;
2123 lpfc_device_rm_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2124 void *arg, uint32_t evt)
2126 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2128 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
2129 spin_lock_irq(shost->host_lock);
2130 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
2131 spin_unlock_irq(shost->host_lock);
2132 return ndlp->nlp_state;
2134 lpfc_drop_node(vport, ndlp);
2135 return NLP_STE_FREED_NODE;
2139 lpfc_device_recov_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2140 void *arg, uint32_t evt)
2142 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2144 /* Don't do anything that will mess up processing of the
2147 if (vport->fc_flag & FC_RSCN_DEFERRED)
2148 return ndlp->nlp_state;
2150 lpfc_cancel_retry_delay_tmo(vport, ndlp);
2151 spin_lock_irq(shost->host_lock);
2152 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
2153 spin_unlock_irq(shost->host_lock);
2154 return ndlp->nlp_state;
2158 /* This next section defines the NPort Discovery State Machine */
2160 /* There are 4 different double linked lists nodelist entries can reside on.
2161 * The plogi list and adisc list are used when Link Up discovery or RSCN
2162 * processing is needed. Each list holds the nodes that we will send PLOGI
2163 * or ADISC on. These lists will keep track of what nodes will be effected
2164 * by an RSCN, or a Link Up (Typically, all nodes are effected on Link Up).
2165 * The unmapped_list will contain all nodes that we have successfully logged
2166 * into at the Fibre Channel level. The mapped_list will contain all nodes
2167 * that are mapped FCP targets.
2170 * The bind list is a list of undiscovered (potentially non-existent) nodes
2171 * that we have saved binding information on. This information is used when
2172 * nodes transition from the unmapped to the mapped list.
2174 /* For UNUSED_NODE state, the node has just been allocated .
2175 * For PLOGI_ISSUE and REG_LOGIN_ISSUE, the node is on
2176 * the PLOGI list. For REG_LOGIN_COMPL, the node is taken off the PLOGI list
2177 * and put on the unmapped list. For ADISC processing, the node is taken off
2178 * the ADISC list and placed on either the mapped or unmapped list (depending
2179 * on its previous state). Once on the unmapped list, a PRLI is issued and the
2180 * state changed to PRLI_ISSUE. When the PRLI completion occurs, the state is
2181 * changed to UNMAPPED_NODE. If the completion indicates a mapped
2182 * node, the node is taken off the unmapped list. The binding list is checked
2183 * for a valid binding, or a binding is automatically assigned. If binding
2184 * assignment is unsuccessful, the node is left on the unmapped list. If
2185 * binding assignment is successful, the associated binding list entry (if
2186 * any) is removed, and the node is placed on the mapped list.
2189 * For a Link Down, all nodes on the ADISC, PLOGI, unmapped or mapped
2190 * lists will receive a DEVICE_RECOVERY event. If the linkdown or devloss timers
2191 * expire, all effected nodes will receive a DEVICE_RM event.
2194 * For a Link Up or RSCN, all nodes will move from the mapped / unmapped lists
2195 * to either the ADISC or PLOGI list. After a Nameserver query or ALPA loopmap
2196 * check, additional nodes may be added or removed (via DEVICE_RM) to / from
2197 * the PLOGI or ADISC lists. Once the PLOGI and ADISC lists are populated,
2198 * we will first process the ADISC list. 32 entries are processed initially and
2199 * ADISC is initited for each one. Completions / Events for each node are
2200 * funnelled thru the state machine. As each node finishes ADISC processing, it
2201 * starts ADISC for any nodes waiting for ADISC processing. If no nodes are
2202 * waiting, and the ADISC list count is identically 0, then we are done. For
2203 * Link Up discovery, since all nodes on the PLOGI list are UNREG_LOGIN'ed, we
2204 * can issue a CLEAR_LA and reenable Link Events. Next we will process the PLOGI
2205 * list. 32 entries are processed initially and PLOGI is initited for each one.
2206 * Completions / Events for each node are funnelled thru the state machine. As
2207 * each node finishes PLOGI processing, it starts PLOGI for any nodes waiting
2208 * for PLOGI processing. If no nodes are waiting, and the PLOGI list count is
2209 * indentically 0, then we are done. We have now completed discovery / RSCN
2210 * handling. Upon completion, ALL nodes should be on either the mapped or
2214 static uint32_t (*lpfc_disc_action[NLP_STE_MAX_STATE * NLP_EVT_MAX_EVENT])
2215 (struct lpfc_vport *, struct lpfc_nodelist *, void *, uint32_t) = {
2216 /* Action routine Event Current State */
2217 lpfc_rcv_plogi_unused_node, /* RCV_PLOGI UNUSED_NODE */
2218 lpfc_rcv_els_unused_node, /* RCV_PRLI */
2219 lpfc_rcv_logo_unused_node, /* RCV_LOGO */
2220 lpfc_rcv_els_unused_node, /* RCV_ADISC */
2221 lpfc_rcv_els_unused_node, /* RCV_PDISC */
2222 lpfc_rcv_els_unused_node, /* RCV_PRLO */
2223 lpfc_disc_illegal, /* CMPL_PLOGI */
2224 lpfc_disc_illegal, /* CMPL_PRLI */
2225 lpfc_cmpl_logo_unused_node, /* CMPL_LOGO */
2226 lpfc_disc_illegal, /* CMPL_ADISC */
2227 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2228 lpfc_device_rm_unused_node, /* DEVICE_RM */
2229 lpfc_device_recov_unused_node, /* DEVICE_RECOVERY */
2231 lpfc_rcv_plogi_plogi_issue, /* RCV_PLOGI PLOGI_ISSUE */
2232 lpfc_rcv_prli_plogi_issue, /* RCV_PRLI */
2233 lpfc_rcv_logo_plogi_issue, /* RCV_LOGO */
2234 lpfc_rcv_els_plogi_issue, /* RCV_ADISC */
2235 lpfc_rcv_els_plogi_issue, /* RCV_PDISC */
2236 lpfc_rcv_els_plogi_issue, /* RCV_PRLO */
2237 lpfc_cmpl_plogi_plogi_issue, /* CMPL_PLOGI */
2238 lpfc_disc_illegal, /* CMPL_PRLI */
2239 lpfc_cmpl_logo_plogi_issue, /* CMPL_LOGO */
2240 lpfc_disc_illegal, /* CMPL_ADISC */
2241 lpfc_cmpl_reglogin_plogi_issue,/* CMPL_REG_LOGIN */
2242 lpfc_device_rm_plogi_issue, /* DEVICE_RM */
2243 lpfc_device_recov_plogi_issue, /* DEVICE_RECOVERY */
2245 lpfc_rcv_plogi_adisc_issue, /* RCV_PLOGI ADISC_ISSUE */
2246 lpfc_rcv_prli_adisc_issue, /* RCV_PRLI */
2247 lpfc_rcv_logo_adisc_issue, /* RCV_LOGO */
2248 lpfc_rcv_padisc_adisc_issue, /* RCV_ADISC */
2249 lpfc_rcv_padisc_adisc_issue, /* RCV_PDISC */
2250 lpfc_rcv_prlo_adisc_issue, /* RCV_PRLO */
2251 lpfc_disc_illegal, /* CMPL_PLOGI */
2252 lpfc_disc_illegal, /* CMPL_PRLI */
2253 lpfc_disc_illegal, /* CMPL_LOGO */
2254 lpfc_cmpl_adisc_adisc_issue, /* CMPL_ADISC */
2255 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2256 lpfc_device_rm_adisc_issue, /* DEVICE_RM */
2257 lpfc_device_recov_adisc_issue, /* DEVICE_RECOVERY */
2259 lpfc_rcv_plogi_reglogin_issue, /* RCV_PLOGI REG_LOGIN_ISSUE */
2260 lpfc_rcv_prli_reglogin_issue, /* RCV_PLOGI */
2261 lpfc_rcv_logo_reglogin_issue, /* RCV_LOGO */
2262 lpfc_rcv_padisc_reglogin_issue, /* RCV_ADISC */
2263 lpfc_rcv_padisc_reglogin_issue, /* RCV_PDISC */
2264 lpfc_rcv_prlo_reglogin_issue, /* RCV_PRLO */
2265 lpfc_cmpl_plogi_illegal, /* CMPL_PLOGI */
2266 lpfc_disc_illegal, /* CMPL_PRLI */
2267 lpfc_disc_illegal, /* CMPL_LOGO */
2268 lpfc_disc_illegal, /* CMPL_ADISC */
2269 lpfc_cmpl_reglogin_reglogin_issue,/* CMPL_REG_LOGIN */
2270 lpfc_device_rm_reglogin_issue, /* DEVICE_RM */
2271 lpfc_device_recov_reglogin_issue,/* DEVICE_RECOVERY */
2273 lpfc_rcv_plogi_prli_issue, /* RCV_PLOGI PRLI_ISSUE */
2274 lpfc_rcv_prli_prli_issue, /* RCV_PRLI */
2275 lpfc_rcv_logo_prli_issue, /* RCV_LOGO */
2276 lpfc_rcv_padisc_prli_issue, /* RCV_ADISC */
2277 lpfc_rcv_padisc_prli_issue, /* RCV_PDISC */
2278 lpfc_rcv_prlo_prli_issue, /* RCV_PRLO */
2279 lpfc_cmpl_plogi_illegal, /* CMPL_PLOGI */
2280 lpfc_cmpl_prli_prli_issue, /* CMPL_PRLI */
2281 lpfc_disc_illegal, /* CMPL_LOGO */
2282 lpfc_disc_illegal, /* CMPL_ADISC */
2283 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2284 lpfc_device_rm_prli_issue, /* DEVICE_RM */
2285 lpfc_device_recov_prli_issue, /* DEVICE_RECOVERY */
2287 lpfc_rcv_plogi_unmap_node, /* RCV_PLOGI UNMAPPED_NODE */
2288 lpfc_rcv_prli_unmap_node, /* RCV_PRLI */
2289 lpfc_rcv_logo_unmap_node, /* RCV_LOGO */
2290 lpfc_rcv_padisc_unmap_node, /* RCV_ADISC */
2291 lpfc_rcv_padisc_unmap_node, /* RCV_PDISC */
2292 lpfc_rcv_prlo_unmap_node, /* RCV_PRLO */
2293 lpfc_disc_illegal, /* CMPL_PLOGI */
2294 lpfc_disc_illegal, /* CMPL_PRLI */
2295 lpfc_disc_illegal, /* CMPL_LOGO */
2296 lpfc_disc_illegal, /* CMPL_ADISC */
2297 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2298 lpfc_disc_illegal, /* DEVICE_RM */
2299 lpfc_device_recov_unmap_node, /* DEVICE_RECOVERY */
2301 lpfc_rcv_plogi_mapped_node, /* RCV_PLOGI MAPPED_NODE */
2302 lpfc_rcv_prli_mapped_node, /* RCV_PRLI */
2303 lpfc_rcv_logo_mapped_node, /* RCV_LOGO */
2304 lpfc_rcv_padisc_mapped_node, /* RCV_ADISC */
2305 lpfc_rcv_padisc_mapped_node, /* RCV_PDISC */
2306 lpfc_rcv_prlo_mapped_node, /* RCV_PRLO */
2307 lpfc_disc_illegal, /* CMPL_PLOGI */
2308 lpfc_disc_illegal, /* CMPL_PRLI */
2309 lpfc_disc_illegal, /* CMPL_LOGO */
2310 lpfc_disc_illegal, /* CMPL_ADISC */
2311 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2312 lpfc_disc_illegal, /* DEVICE_RM */
2313 lpfc_device_recov_mapped_node, /* DEVICE_RECOVERY */
2315 lpfc_rcv_plogi_npr_node, /* RCV_PLOGI NPR_NODE */
2316 lpfc_rcv_prli_npr_node, /* RCV_PRLI */
2317 lpfc_rcv_logo_npr_node, /* RCV_LOGO */
2318 lpfc_rcv_padisc_npr_node, /* RCV_ADISC */
2319 lpfc_rcv_padisc_npr_node, /* RCV_PDISC */
2320 lpfc_rcv_prlo_npr_node, /* RCV_PRLO */
2321 lpfc_cmpl_plogi_npr_node, /* CMPL_PLOGI */
2322 lpfc_cmpl_prli_npr_node, /* CMPL_PRLI */
2323 lpfc_cmpl_logo_npr_node, /* CMPL_LOGO */
2324 lpfc_cmpl_adisc_npr_node, /* CMPL_ADISC */
2325 lpfc_cmpl_reglogin_npr_node, /* CMPL_REG_LOGIN */
2326 lpfc_device_rm_npr_node, /* DEVICE_RM */
2327 lpfc_device_recov_npr_node, /* DEVICE_RECOVERY */
2331 lpfc_disc_state_machine(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2332 void *arg, uint32_t evt)
2334 uint32_t cur_state, rc;
2335 uint32_t(*func) (struct lpfc_vport *, struct lpfc_nodelist *, void *,
2337 uint32_t got_ndlp = 0;
2339 if (lpfc_nlp_get(ndlp))
2342 cur_state = ndlp->nlp_state;
2344 /* DSM in event <evt> on NPort <nlp_DID> in state <cur_state> */
2345 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2346 "0211 DSM in event x%x on NPort x%x in "
2347 "state %d Data: x%x\n",
2348 evt, ndlp->nlp_DID, cur_state, ndlp->nlp_flag);
2350 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_DSM,
2351 "DSM in: evt:%d ste:%d did:x%x",
2352 evt, cur_state, ndlp->nlp_DID);
2354 func = lpfc_disc_action[(cur_state * NLP_EVT_MAX_EVENT) + evt];
2355 rc = (func) (vport, ndlp, arg, evt);
2357 /* DSM out state <rc> on NPort <nlp_DID> */
2359 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2360 "0212 DSM out state %d on NPort x%x Data: x%x\n",
2361 rc, ndlp->nlp_DID, ndlp->nlp_flag);
2363 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_DSM,
2364 "DSM out: ste:%d did:x%x flg:x%x",
2365 rc, ndlp->nlp_DID, ndlp->nlp_flag);
2366 /* Decrement the ndlp reference count held for this function */
2369 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2370 "0213 DSM out state %d on NPort free\n", rc);
2372 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_DSM,
2373 "DSM out: ste:%d did:x%x flg:x%x",