1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2004-2012 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);
232 /* Next check the txcmplq */
233 list_splice_init(&pring->txcmplq, &txcmplq_completions);
234 spin_unlock_irq(&phba->hbalock);
236 list_for_each_entry_safe(iocb, next_iocb, &txcmplq_completions, list) {
237 /* Check to see if iocb matches the nport we are looking for */
238 if (lpfc_check_sli_ndlp(phba, pring, iocb, ndlp))
239 list_add_tail(&iocb->dlist, &abort_list);
241 spin_lock_irq(&phba->hbalock);
242 list_splice(&txcmplq_completions, &pring->txcmplq);
243 spin_unlock_irq(&phba->hbalock);
245 list_for_each_entry_safe(iocb, next_iocb, &abort_list, dlist) {
246 spin_lock_irq(&phba->hbalock);
247 list_del_init(&iocb->dlist);
248 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
249 spin_unlock_irq(&phba->hbalock);
252 /* Cancel all the IOCBs from the completions list */
253 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
256 lpfc_cancel_retry_delay_tmo(phba->pport, ndlp);
261 lpfc_rcv_plogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
262 struct lpfc_iocbq *cmdiocb)
264 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
265 struct lpfc_hba *phba = vport->phba;
266 struct lpfc_dmabuf *pcmd;
269 struct serv_parm *sp;
274 memset(&stat, 0, sizeof (struct ls_rjt));
275 if (vport->port_state <= LPFC_FDISC) {
276 /* Before responding to PLOGI, check for pt2pt mode.
277 * If we are pt2pt, with an outstanding FLOGI, abort
278 * the FLOGI and resend it first.
280 if (vport->fc_flag & FC_PT2PT) {
281 lpfc_els_abort_flogi(phba);
282 if (!(vport->fc_flag & FC_PT2PT_PLOGI)) {
283 /* If the other side is supposed to initiate
284 * the PLOGI anyway, just ACC it now and
285 * move on with discovery.
287 phba->fc_edtov = FF_DEF_EDTOV;
288 phba->fc_ratov = FF_DEF_RATOV;
289 /* Start discovery - this should just do
291 lpfc_disc_start(vport);
293 lpfc_initial_flogi(vport);
295 stat.un.b.lsRjtRsnCode = LSRJT_LOGICAL_BSY;
296 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
297 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb,
302 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
303 lp = (uint32_t *) pcmd->virt;
304 sp = (struct serv_parm *) ((uint8_t *) lp + sizeof (uint32_t));
305 if (wwn_to_u64(sp->portName.u.wwn) == 0) {
306 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
307 "0140 PLOGI Reject: invalid nname\n");
308 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
309 stat.un.b.lsRjtRsnCodeExp = LSEXP_INVALID_PNAME;
310 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
314 if (wwn_to_u64(sp->nodeName.u.wwn) == 0) {
315 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
316 "0141 PLOGI Reject: invalid pname\n");
317 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
318 stat.un.b.lsRjtRsnCodeExp = LSEXP_INVALID_NNAME;
319 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
323 if ((lpfc_check_sparm(vport, ndlp, sp, CLASS3, 0) == 0)) {
324 /* Reject this request because invalid parameters */
325 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
326 stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
327 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
331 icmd = &cmdiocb->iocb;
333 /* PLOGI chkparm OK */
334 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
335 "0114 PLOGI chkparm OK Data: x%x x%x x%x x%x\n",
336 ndlp->nlp_DID, ndlp->nlp_state, ndlp->nlp_flag,
339 if (vport->cfg_fcp_class == 2 && sp->cls2.classValid)
340 ndlp->nlp_fcp_info |= CLASS2;
342 ndlp->nlp_fcp_info |= CLASS3;
344 ndlp->nlp_class_sup = 0;
345 if (sp->cls1.classValid)
346 ndlp->nlp_class_sup |= FC_COS_CLASS1;
347 if (sp->cls2.classValid)
348 ndlp->nlp_class_sup |= FC_COS_CLASS2;
349 if (sp->cls3.classValid)
350 ndlp->nlp_class_sup |= FC_COS_CLASS3;
351 if (sp->cls4.classValid)
352 ndlp->nlp_class_sup |= FC_COS_CLASS4;
354 ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) | sp->cmn.bbRcvSizeLsb;
356 /* no need to reg_login if we are already in one of these states */
357 switch (ndlp->nlp_state) {
358 case NLP_STE_NPR_NODE:
359 if (!(ndlp->nlp_flag & NLP_NPR_ADISC))
361 case NLP_STE_REG_LOGIN_ISSUE:
362 case NLP_STE_PRLI_ISSUE:
363 case NLP_STE_UNMAPPED_NODE:
364 case NLP_STE_MAPPED_NODE:
365 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp, NULL);
369 /* Check for Nport to NPort pt2pt protocol */
370 if ((vport->fc_flag & FC_PT2PT) &&
371 !(vport->fc_flag & FC_PT2PT_PLOGI)) {
373 /* rcv'ed PLOGI decides what our NPortId will be */
374 vport->fc_myDID = icmd->un.rcvels.parmRo;
375 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
378 lpfc_config_link(phba, mbox);
379 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
381 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
382 if (rc == MBX_NOT_FINISHED) {
383 mempool_free(mbox, phba->mbox_mem_pool);
387 * For SLI4, the VFI/VPI are registered AFTER the
388 * Nport with the higher WWPN sends us a PLOGI with
389 * our assigned NPortId.
391 if (phba->sli_rev == LPFC_SLI_REV4)
392 lpfc_issue_reg_vfi(vport);
394 lpfc_can_disctmo(vport);
396 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
400 /* Registering an existing RPI behaves differently for SLI3 vs SLI4 */
401 if (phba->sli_rev == LPFC_SLI_REV4)
402 lpfc_unreg_rpi(vport, ndlp);
404 rc = lpfc_reg_rpi(phba, vport->vpi, icmd->un.rcvels.remoteID,
405 (uint8_t *) sp, mbox, ndlp->nlp_rpi);
407 mempool_free(mbox, phba->mbox_mem_pool);
411 /* ACC PLOGI rsp command needs to execute first,
412 * queue this mbox command to be processed later.
414 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
416 * mbox->context2 = lpfc_nlp_get(ndlp) deferred until mailbox
417 * command issued in lpfc_cmpl_els_acc().
420 spin_lock_irq(shost->host_lock);
421 ndlp->nlp_flag |= (NLP_ACC_REGLOGIN | NLP_RCV_PLOGI);
422 spin_unlock_irq(shost->host_lock);
425 * If there is an outstanding PLOGI issued, abort it before
426 * sending ACC rsp for received PLOGI. If pending plogi
427 * is not canceled here, the plogi will be rejected by
428 * remote port and will be retried. On a configuration with
429 * single discovery thread, this will cause a huge delay in
430 * discovery. Also this will cause multiple state machines
431 * running in parallel for this node.
433 if (ndlp->nlp_state == NLP_STE_PLOGI_ISSUE) {
434 /* software abort outstanding PLOGI */
435 lpfc_els_abort(phba, ndlp);
438 if ((vport->port_type == LPFC_NPIV_PORT &&
439 vport->cfg_restrict_login)) {
441 /* In order to preserve RPIs, we want to cleanup
442 * the default RPI the firmware created to rcv
443 * this ELS request. The only way to do this is
444 * to register, then unregister the RPI.
446 spin_lock_irq(shost->host_lock);
447 ndlp->nlp_flag |= NLP_RM_DFLT_RPI;
448 spin_unlock_irq(shost->host_lock);
449 stat.un.b.lsRjtRsnCode = LSRJT_INVALID_CMD;
450 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
451 rc = lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb,
454 mempool_free(mbox, phba->mbox_mem_pool);
457 rc = lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp, mbox);
459 mempool_free(mbox, phba->mbox_mem_pool);
462 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
463 stat.un.b.lsRjtRsnCodeExp = LSEXP_OUT_OF_RESOURCE;
464 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
469 * lpfc_mbx_cmpl_resume_rpi - Resume RPI completion routine
470 * @phba: pointer to lpfc hba data structure.
471 * @mboxq: pointer to mailbox object
473 * This routine is invoked to issue a completion to a rcv'ed
474 * ADISC or PDISC after the paused RPI has been resumed.
477 lpfc_mbx_cmpl_resume_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
479 struct lpfc_vport *vport;
480 struct lpfc_iocbq *elsiocb;
481 struct lpfc_nodelist *ndlp;
484 elsiocb = (struct lpfc_iocbq *)mboxq->context1;
485 ndlp = (struct lpfc_nodelist *) mboxq->context2;
486 vport = mboxq->vport;
487 cmd = elsiocb->drvrTimeout;
489 if (cmd == ELS_CMD_ADISC) {
490 lpfc_els_rsp_adisc_acc(vport, elsiocb, ndlp);
492 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, elsiocb,
496 mempool_free(mboxq, phba->mbox_mem_pool);
500 lpfc_rcv_padisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
501 struct lpfc_iocbq *cmdiocb)
503 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
504 struct lpfc_iocbq *elsiocb;
505 struct lpfc_dmabuf *pcmd;
506 struct serv_parm *sp;
507 struct lpfc_name *pnn, *ppn;
514 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
515 lp = (uint32_t *) pcmd->virt;
518 if (cmd == ELS_CMD_ADISC) {
520 pnn = (struct lpfc_name *) & ap->nodeName;
521 ppn = (struct lpfc_name *) & ap->portName;
523 sp = (struct serv_parm *) lp;
524 pnn = (struct lpfc_name *) & sp->nodeName;
525 ppn = (struct lpfc_name *) & sp->portName;
528 icmd = &cmdiocb->iocb;
529 if (icmd->ulpStatus == 0 && lpfc_check_adisc(vport, ndlp, pnn, ppn)) {
532 * As soon as we send ACC, the remote NPort can
533 * start sending us data. Thus, for SLI4 we must
534 * resume the RPI before the ACC goes out.
536 if (vport->phba->sli_rev == LPFC_SLI_REV4) {
537 elsiocb = kmalloc(sizeof(struct lpfc_iocbq),
541 /* Save info from cmd IOCB used in rsp */
542 memcpy((uint8_t *)elsiocb, (uint8_t *)cmdiocb,
543 sizeof(struct lpfc_iocbq));
545 /* Save the ELS cmd */
546 elsiocb->drvrTimeout = cmd;
548 lpfc_sli4_resume_rpi(ndlp,
549 lpfc_mbx_cmpl_resume_rpi, elsiocb);
554 if (cmd == ELS_CMD_ADISC) {
555 lpfc_els_rsp_adisc_acc(vport, cmdiocb, ndlp);
557 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb,
561 /* If we are authenticated, move to the proper state */
562 if (ndlp->nlp_type & NLP_FCP_TARGET)
563 lpfc_nlp_set_state(vport, ndlp, NLP_STE_MAPPED_NODE);
565 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
569 /* Reject this request because invalid parameters */
570 stat.un.b.lsRjtRsvd0 = 0;
571 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
572 stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
573 stat.un.b.vendorUnique = 0;
574 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
577 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ);
579 spin_lock_irq(shost->host_lock);
580 ndlp->nlp_flag |= NLP_DELAY_TMO;
581 spin_unlock_irq(shost->host_lock);
582 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
583 ndlp->nlp_prev_state = ndlp->nlp_state;
584 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
589 lpfc_rcv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
590 struct lpfc_iocbq *cmdiocb, uint32_t els_cmd)
592 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
593 struct lpfc_hba *phba = vport->phba;
594 struct lpfc_vport **vports;
595 int i, active_vlink_present = 0 ;
597 /* Put ndlp in NPR state with 1 sec timeout for plogi, ACC logo */
598 /* Only call LOGO ACC for first LOGO, this avoids sending unnecessary
599 * PLOGIs during LOGO storms from a device.
601 spin_lock_irq(shost->host_lock);
602 ndlp->nlp_flag |= NLP_LOGO_ACC;
603 spin_unlock_irq(shost->host_lock);
604 if (els_cmd == ELS_CMD_PRLO)
605 lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL);
607 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
608 if (ndlp->nlp_DID == Fabric_DID) {
609 if (vport->port_state <= LPFC_FDISC)
611 lpfc_linkdown_port(vport);
612 spin_lock_irq(shost->host_lock);
613 vport->fc_flag |= FC_VPORT_LOGO_RCVD;
614 spin_unlock_irq(shost->host_lock);
615 vports = lpfc_create_vport_work_array(phba);
617 for (i = 0; i <= phba->max_vports && vports[i] != NULL;
619 if ((!(vports[i]->fc_flag &
620 FC_VPORT_LOGO_RCVD)) &&
621 (vports[i]->port_state > LPFC_FDISC)) {
622 active_vlink_present = 1;
626 lpfc_destroy_vport_work_array(phba, vports);
629 if (active_vlink_present) {
631 * If there are other active VLinks present,
632 * re-instantiate the Vlink using FDISC.
634 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ);
635 spin_lock_irq(shost->host_lock);
636 ndlp->nlp_flag |= NLP_DELAY_TMO;
637 spin_unlock_irq(shost->host_lock);
638 ndlp->nlp_last_elscmd = ELS_CMD_FDISC;
639 vport->port_state = LPFC_FDISC;
641 spin_lock_irq(shost->host_lock);
642 phba->pport->fc_flag &= ~FC_LOGO_RCVD_DID_CHNG;
643 spin_unlock_irq(shost->host_lock);
644 lpfc_retry_pport_discovery(phba);
646 } else if ((!(ndlp->nlp_type & NLP_FABRIC) &&
647 ((ndlp->nlp_type & NLP_FCP_TARGET) ||
648 !(ndlp->nlp_type & NLP_FCP_INITIATOR))) ||
649 (ndlp->nlp_state == NLP_STE_ADISC_ISSUE)) {
650 /* Only try to re-login if this is NOT a Fabric Node */
651 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ * 1);
652 spin_lock_irq(shost->host_lock);
653 ndlp->nlp_flag |= NLP_DELAY_TMO;
654 spin_unlock_irq(shost->host_lock);
656 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
659 ndlp->nlp_prev_state = ndlp->nlp_state;
660 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
662 spin_lock_irq(shost->host_lock);
663 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
664 spin_unlock_irq(shost->host_lock);
665 /* The driver has to wait until the ACC completes before it continues
666 * processing the LOGO. The action will resume in
667 * lpfc_cmpl_els_logo_acc routine. Since part of processing includes an
668 * unreg_login, the driver waits so the ACC does not get aborted.
674 lpfc_rcv_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
675 struct lpfc_iocbq *cmdiocb)
677 struct lpfc_dmabuf *pcmd;
680 struct fc_rport *rport = ndlp->rport;
683 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
684 lp = (uint32_t *) pcmd->virt;
685 npr = (PRLI *) ((uint8_t *) lp + sizeof (uint32_t));
687 ndlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR);
688 ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
689 if (npr->prliType == PRLI_FCP_TYPE) {
690 if (npr->initiatorFunc)
691 ndlp->nlp_type |= NLP_FCP_INITIATOR;
693 ndlp->nlp_type |= NLP_FCP_TARGET;
695 ndlp->nlp_fcp_info |= NLP_FCP_2_DEVICE;
698 /* We need to update the rport role values */
699 roles = FC_RPORT_ROLE_UNKNOWN;
700 if (ndlp->nlp_type & NLP_FCP_INITIATOR)
701 roles |= FC_RPORT_ROLE_FCP_INITIATOR;
702 if (ndlp->nlp_type & NLP_FCP_TARGET)
703 roles |= FC_RPORT_ROLE_FCP_TARGET;
705 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
706 "rport rolechg: role:x%x did:x%x flg:x%x",
707 roles, ndlp->nlp_DID, ndlp->nlp_flag);
709 fc_remote_port_rolechg(rport, roles);
714 lpfc_disc_set_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
716 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
718 if (!(ndlp->nlp_flag & NLP_RPI_REGISTERED)) {
719 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
723 if (!(vport->fc_flag & FC_PT2PT)) {
724 /* Check config parameter use-adisc or FCP-2 */
725 if ((vport->cfg_use_adisc && (vport->fc_flag & FC_RSCN_MODE)) ||
726 ((ndlp->nlp_fcp_info & NLP_FCP_2_DEVICE) &&
727 (ndlp->nlp_type & NLP_FCP_TARGET))) {
728 spin_lock_irq(shost->host_lock);
729 ndlp->nlp_flag |= NLP_NPR_ADISC;
730 spin_unlock_irq(shost->host_lock);
734 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
735 lpfc_unreg_rpi(vport, ndlp);
740 * lpfc_release_rpi - Release a RPI by issuing unreg_login mailbox cmd.
741 * @phba : Pointer to lpfc_hba structure.
742 * @vport: Pointer to lpfc_vport structure.
743 * @rpi : rpi to be release.
745 * This function will send a unreg_login mailbox command to the firmware
749 lpfc_release_rpi(struct lpfc_hba *phba,
750 struct lpfc_vport *vport,
756 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
759 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
760 "2796 mailbox memory allocation failed \n");
762 lpfc_unreg_login(phba, vport->vpi, rpi, pmb);
763 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
764 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
765 if (rc == MBX_NOT_FINISHED)
766 mempool_free(pmb, phba->mbox_mem_pool);
771 lpfc_disc_illegal(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
772 void *arg, uint32_t evt)
774 struct lpfc_hba *phba;
775 LPFC_MBOXQ_t *pmb = (LPFC_MBOXQ_t *) arg;
780 /* Release the RPI if reglogin completing */
781 if (!(phba->pport->load_flag & FC_UNLOADING) &&
782 (evt == NLP_EVT_CMPL_REG_LOGIN) &&
783 (!pmb->u.mb.mbxStatus)) {
785 rpi = pmb->u.mb.un.varWords[0];
786 lpfc_release_rpi(phba, vport, rpi);
788 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
789 "0271 Illegal State Transition: node x%x "
790 "event x%x, state x%x Data: x%x x%x\n",
791 ndlp->nlp_DID, evt, ndlp->nlp_state, ndlp->nlp_rpi,
793 return ndlp->nlp_state;
797 lpfc_cmpl_plogi_illegal(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
798 void *arg, uint32_t evt)
800 /* This transition is only legal if we previously
801 * rcv'ed a PLOGI. Since we don't want 2 discovery threads
802 * working on the same NPortID, do nothing for this thread
805 if (!(ndlp->nlp_flag & NLP_RCV_PLOGI)) {
806 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
807 "0272 Illegal State Transition: node x%x "
808 "event x%x, state x%x Data: x%x x%x\n",
809 ndlp->nlp_DID, evt, ndlp->nlp_state, ndlp->nlp_rpi,
812 return ndlp->nlp_state;
815 /* Start of Discovery State Machine routines */
818 lpfc_rcv_plogi_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
819 void *arg, uint32_t evt)
821 struct lpfc_iocbq *cmdiocb;
823 cmdiocb = (struct lpfc_iocbq *) arg;
825 if (lpfc_rcv_plogi(vport, ndlp, cmdiocb)) {
826 return ndlp->nlp_state;
828 return NLP_STE_FREED_NODE;
832 lpfc_rcv_els_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
833 void *arg, uint32_t evt)
835 lpfc_issue_els_logo(vport, ndlp, 0);
836 return ndlp->nlp_state;
840 lpfc_rcv_logo_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
841 void *arg, uint32_t evt)
843 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
844 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
846 spin_lock_irq(shost->host_lock);
847 ndlp->nlp_flag |= NLP_LOGO_ACC;
848 spin_unlock_irq(shost->host_lock);
849 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
851 return ndlp->nlp_state;
855 lpfc_cmpl_logo_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
856 void *arg, uint32_t evt)
858 return NLP_STE_FREED_NODE;
862 lpfc_device_rm_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
863 void *arg, uint32_t evt)
865 return NLP_STE_FREED_NODE;
869 lpfc_device_recov_unused_node(struct lpfc_vport *vport,
870 struct lpfc_nodelist *ndlp,
871 void *arg, uint32_t evt)
873 return ndlp->nlp_state;
877 lpfc_rcv_plogi_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
878 void *arg, uint32_t evt)
880 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
881 struct lpfc_hba *phba = vport->phba;
882 struct lpfc_iocbq *cmdiocb = arg;
883 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
884 uint32_t *lp = (uint32_t *) pcmd->virt;
885 struct serv_parm *sp = (struct serv_parm *) (lp + 1);
889 memset(&stat, 0, sizeof (struct ls_rjt));
891 /* For a PLOGI, we only accept if our portname is less
892 * than the remote portname.
894 phba->fc_stat.elsLogiCol++;
895 port_cmp = memcmp(&vport->fc_portname, &sp->portName,
896 sizeof(struct lpfc_name));
899 /* Reject this request because the remote node will accept
901 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
902 stat.un.b.lsRjtRsnCodeExp = LSEXP_CMD_IN_PROGRESS;
903 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
906 if (lpfc_rcv_plogi(vport, ndlp, cmdiocb) &&
907 (ndlp->nlp_flag & NLP_NPR_2B_DISC) &&
908 (vport->num_disc_nodes)) {
909 spin_lock_irq(shost->host_lock);
910 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
911 spin_unlock_irq(shost->host_lock);
912 /* Check if there are more PLOGIs to be sent */
913 lpfc_more_plogi(vport);
914 if (vport->num_disc_nodes == 0) {
915 spin_lock_irq(shost->host_lock);
916 vport->fc_flag &= ~FC_NDISC_ACTIVE;
917 spin_unlock_irq(shost->host_lock);
918 lpfc_can_disctmo(vport);
919 lpfc_end_rscn(vport);
922 } /* If our portname was less */
924 return ndlp->nlp_state;
928 lpfc_rcv_prli_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
929 void *arg, uint32_t evt)
931 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
934 memset(&stat, 0, sizeof (struct ls_rjt));
935 stat.un.b.lsRjtRsnCode = LSRJT_LOGICAL_BSY;
936 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
937 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
938 return ndlp->nlp_state;
942 lpfc_rcv_logo_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
943 void *arg, uint32_t evt)
945 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
947 /* software abort outstanding PLOGI */
948 lpfc_els_abort(vport->phba, ndlp);
950 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
951 return ndlp->nlp_state;
955 lpfc_rcv_els_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
956 void *arg, uint32_t evt)
958 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
959 struct lpfc_hba *phba = vport->phba;
960 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
962 /* software abort outstanding PLOGI */
963 lpfc_els_abort(phba, ndlp);
965 if (evt == NLP_EVT_RCV_LOGO) {
966 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
968 lpfc_issue_els_logo(vport, ndlp, 0);
971 /* Put ndlp in npr state set plogi timer for 1 sec */
972 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ * 1);
973 spin_lock_irq(shost->host_lock);
974 ndlp->nlp_flag |= NLP_DELAY_TMO;
975 spin_unlock_irq(shost->host_lock);
976 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
977 ndlp->nlp_prev_state = NLP_STE_PLOGI_ISSUE;
978 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
980 return ndlp->nlp_state;
984 lpfc_cmpl_plogi_plogi_issue(struct lpfc_vport *vport,
985 struct lpfc_nodelist *ndlp,
989 struct lpfc_hba *phba = vport->phba;
990 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
991 struct lpfc_iocbq *cmdiocb, *rspiocb;
992 struct lpfc_dmabuf *pcmd, *prsp, *mp;
995 struct serv_parm *sp;
998 cmdiocb = (struct lpfc_iocbq *) arg;
999 rspiocb = cmdiocb->context_un.rsp_iocb;
1001 if (ndlp->nlp_flag & NLP_ACC_REGLOGIN) {
1002 /* Recovery from PLOGI collision logic */
1003 return ndlp->nlp_state;
1006 irsp = &rspiocb->iocb;
1008 if (irsp->ulpStatus)
1011 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
1013 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
1015 lp = (uint32_t *) prsp->virt;
1016 sp = (struct serv_parm *) ((uint8_t *) lp + sizeof (uint32_t));
1018 /* Some switches have FDMI servers returning 0 for WWN */
1019 if ((ndlp->nlp_DID != FDMI_DID) &&
1020 (wwn_to_u64(sp->portName.u.wwn) == 0 ||
1021 wwn_to_u64(sp->nodeName.u.wwn) == 0)) {
1022 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1023 "0142 PLOGI RSP: Invalid WWN.\n");
1026 if (!lpfc_check_sparm(vport, ndlp, sp, CLASS3, 0))
1028 /* PLOGI chkparm OK */
1029 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1030 "0121 PLOGI chkparm OK Data: x%x x%x x%x x%x\n",
1031 ndlp->nlp_DID, ndlp->nlp_state,
1032 ndlp->nlp_flag, ndlp->nlp_rpi);
1033 if (vport->cfg_fcp_class == 2 && (sp->cls2.classValid))
1034 ndlp->nlp_fcp_info |= CLASS2;
1036 ndlp->nlp_fcp_info |= CLASS3;
1038 ndlp->nlp_class_sup = 0;
1039 if (sp->cls1.classValid)
1040 ndlp->nlp_class_sup |= FC_COS_CLASS1;
1041 if (sp->cls2.classValid)
1042 ndlp->nlp_class_sup |= FC_COS_CLASS2;
1043 if (sp->cls3.classValid)
1044 ndlp->nlp_class_sup |= FC_COS_CLASS3;
1045 if (sp->cls4.classValid)
1046 ndlp->nlp_class_sup |= FC_COS_CLASS4;
1047 ndlp->nlp_maxframe =
1048 ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) | sp->cmn.bbRcvSizeLsb;
1050 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1052 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1053 "0133 PLOGI: no memory for reg_login "
1054 "Data: x%x x%x x%x x%x\n",
1055 ndlp->nlp_DID, ndlp->nlp_state,
1056 ndlp->nlp_flag, ndlp->nlp_rpi);
1060 lpfc_unreg_rpi(vport, ndlp);
1062 if (lpfc_reg_rpi(phba, vport->vpi, irsp->un.elsreq64.remoteID,
1063 (uint8_t *) sp, mbox, ndlp->nlp_rpi) == 0) {
1064 switch (ndlp->nlp_DID) {
1065 case NameServer_DID:
1066 mbox->mbox_cmpl = lpfc_mbx_cmpl_ns_reg_login;
1069 mbox->mbox_cmpl = lpfc_mbx_cmpl_fdmi_reg_login;
1072 ndlp->nlp_flag |= NLP_REG_LOGIN_SEND;
1073 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
1075 mbox->context2 = lpfc_nlp_get(ndlp);
1076 mbox->vport = vport;
1077 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
1078 != MBX_NOT_FINISHED) {
1079 lpfc_nlp_set_state(vport, ndlp,
1080 NLP_STE_REG_LOGIN_ISSUE);
1081 return ndlp->nlp_state;
1083 if (ndlp->nlp_flag & NLP_REG_LOGIN_SEND)
1084 ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND;
1085 /* decrement node reference count to the failed mbox
1089 mp = (struct lpfc_dmabuf *) mbox->context1;
1090 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1092 mempool_free(mbox, phba->mbox_mem_pool);
1094 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1095 "0134 PLOGI: cannot issue reg_login "
1096 "Data: x%x x%x x%x x%x\n",
1097 ndlp->nlp_DID, ndlp->nlp_state,
1098 ndlp->nlp_flag, ndlp->nlp_rpi);
1100 mempool_free(mbox, phba->mbox_mem_pool);
1102 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1103 "0135 PLOGI: cannot format reg_login "
1104 "Data: x%x x%x x%x x%x\n",
1105 ndlp->nlp_DID, ndlp->nlp_state,
1106 ndlp->nlp_flag, ndlp->nlp_rpi);
1111 if (ndlp->nlp_DID == NameServer_DID) {
1112 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
1113 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1114 "0261 Cannot Register NameServer login\n");
1118 ** In case the node reference counter does not go to zero, ensure that
1119 ** the stale state for the node is not processed.
1122 ndlp->nlp_prev_state = ndlp->nlp_state;
1123 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1124 spin_lock_irq(shost->host_lock);
1125 ndlp->nlp_flag |= NLP_DEFER_RM;
1126 spin_unlock_irq(shost->host_lock);
1127 return NLP_STE_FREED_NODE;
1131 lpfc_cmpl_logo_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1132 void *arg, uint32_t evt)
1134 return ndlp->nlp_state;
1138 lpfc_cmpl_reglogin_plogi_issue(struct lpfc_vport *vport,
1139 struct lpfc_nodelist *ndlp, void *arg, uint32_t evt)
1141 struct lpfc_hba *phba;
1142 LPFC_MBOXQ_t *pmb = (LPFC_MBOXQ_t *) arg;
1143 MAILBOX_t *mb = &pmb->u.mb;
1147 /* Release the RPI */
1148 if (!(phba->pport->load_flag & FC_UNLOADING) &&
1150 rpi = pmb->u.mb.un.varWords[0];
1151 lpfc_release_rpi(phba, vport, rpi);
1153 return ndlp->nlp_state;
1157 lpfc_device_rm_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1158 void *arg, uint32_t evt)
1160 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1162 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1163 spin_lock_irq(shost->host_lock);
1164 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
1165 spin_unlock_irq(shost->host_lock);
1166 return ndlp->nlp_state;
1168 /* software abort outstanding PLOGI */
1169 lpfc_els_abort(vport->phba, ndlp);
1171 lpfc_drop_node(vport, ndlp);
1172 return NLP_STE_FREED_NODE;
1177 lpfc_device_recov_plogi_issue(struct lpfc_vport *vport,
1178 struct lpfc_nodelist *ndlp,
1182 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1183 struct lpfc_hba *phba = vport->phba;
1185 /* Don't do anything that will mess up processing of the
1188 if (vport->fc_flag & FC_RSCN_DEFERRED)
1189 return ndlp->nlp_state;
1191 /* software abort outstanding PLOGI */
1192 lpfc_els_abort(phba, ndlp);
1194 ndlp->nlp_prev_state = NLP_STE_PLOGI_ISSUE;
1195 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1196 spin_lock_irq(shost->host_lock);
1197 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
1198 spin_unlock_irq(shost->host_lock);
1200 return ndlp->nlp_state;
1204 lpfc_rcv_plogi_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1205 void *arg, uint32_t evt)
1207 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1208 struct lpfc_hba *phba = vport->phba;
1209 struct lpfc_iocbq *cmdiocb;
1211 /* software abort outstanding ADISC */
1212 lpfc_els_abort(phba, ndlp);
1214 cmdiocb = (struct lpfc_iocbq *) arg;
1216 if (lpfc_rcv_plogi(vport, ndlp, cmdiocb)) {
1217 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1218 spin_lock_irq(shost->host_lock);
1219 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
1220 spin_unlock_irq(shost->host_lock);
1221 if (vport->num_disc_nodes)
1222 lpfc_more_adisc(vport);
1224 return ndlp->nlp_state;
1226 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
1227 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
1228 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
1230 return ndlp->nlp_state;
1234 lpfc_rcv_prli_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1235 void *arg, uint32_t evt)
1237 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1239 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
1240 return ndlp->nlp_state;
1244 lpfc_rcv_logo_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1245 void *arg, uint32_t evt)
1247 struct lpfc_hba *phba = vport->phba;
1248 struct lpfc_iocbq *cmdiocb;
1250 cmdiocb = (struct lpfc_iocbq *) arg;
1252 /* software abort outstanding ADISC */
1253 lpfc_els_abort(phba, ndlp);
1255 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
1256 return ndlp->nlp_state;
1260 lpfc_rcv_padisc_adisc_issue(struct lpfc_vport *vport,
1261 struct lpfc_nodelist *ndlp,
1262 void *arg, uint32_t evt)
1264 struct lpfc_iocbq *cmdiocb;
1266 cmdiocb = (struct lpfc_iocbq *) arg;
1268 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
1269 return ndlp->nlp_state;
1273 lpfc_rcv_prlo_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1274 void *arg, uint32_t evt)
1276 struct lpfc_iocbq *cmdiocb;
1278 cmdiocb = (struct lpfc_iocbq *) arg;
1280 /* Treat like rcv logo */
1281 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_PRLO);
1282 return ndlp->nlp_state;
1286 lpfc_cmpl_adisc_adisc_issue(struct lpfc_vport *vport,
1287 struct lpfc_nodelist *ndlp,
1288 void *arg, uint32_t evt)
1290 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1291 struct lpfc_hba *phba = vport->phba;
1292 struct lpfc_iocbq *cmdiocb, *rspiocb;
1297 cmdiocb = (struct lpfc_iocbq *) arg;
1298 rspiocb = cmdiocb->context_un.rsp_iocb;
1300 ap = (ADISC *)lpfc_check_elscmpl_iocb(phba, cmdiocb, rspiocb);
1301 irsp = &rspiocb->iocb;
1303 if ((irsp->ulpStatus) ||
1304 (!lpfc_check_adisc(vport, ndlp, &ap->nodeName, &ap->portName))) {
1306 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ);
1307 spin_lock_irq(shost->host_lock);
1308 ndlp->nlp_flag |= NLP_DELAY_TMO;
1309 spin_unlock_irq(shost->host_lock);
1310 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
1312 memset(&ndlp->nlp_nodename, 0, sizeof(struct lpfc_name));
1313 memset(&ndlp->nlp_portname, 0, sizeof(struct lpfc_name));
1315 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
1316 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1317 lpfc_unreg_rpi(vport, ndlp);
1318 return ndlp->nlp_state;
1321 if (phba->sli_rev == LPFC_SLI_REV4) {
1322 rc = lpfc_sli4_resume_rpi(ndlp, NULL, NULL);
1324 /* Stay in state and retry. */
1325 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
1326 return ndlp->nlp_state;
1330 if (ndlp->nlp_type & NLP_FCP_TARGET) {
1331 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
1332 lpfc_nlp_set_state(vport, ndlp, NLP_STE_MAPPED_NODE);
1334 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
1335 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
1338 return ndlp->nlp_state;
1342 lpfc_device_rm_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1343 void *arg, uint32_t evt)
1345 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1347 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1348 spin_lock_irq(shost->host_lock);
1349 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
1350 spin_unlock_irq(shost->host_lock);
1351 return ndlp->nlp_state;
1353 /* software abort outstanding ADISC */
1354 lpfc_els_abort(vport->phba, ndlp);
1356 lpfc_drop_node(vport, ndlp);
1357 return NLP_STE_FREED_NODE;
1362 lpfc_device_recov_adisc_issue(struct lpfc_vport *vport,
1363 struct lpfc_nodelist *ndlp,
1367 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1368 struct lpfc_hba *phba = vport->phba;
1370 /* Don't do anything that will mess up processing of the
1373 if (vport->fc_flag & FC_RSCN_DEFERRED)
1374 return ndlp->nlp_state;
1376 /* software abort outstanding ADISC */
1377 lpfc_els_abort(phba, ndlp);
1379 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
1380 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1381 spin_lock_irq(shost->host_lock);
1382 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
1383 spin_unlock_irq(shost->host_lock);
1384 lpfc_disc_set_adisc(vport, ndlp);
1385 return ndlp->nlp_state;
1389 lpfc_rcv_plogi_reglogin_issue(struct lpfc_vport *vport,
1390 struct lpfc_nodelist *ndlp,
1394 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1396 lpfc_rcv_plogi(vport, ndlp, cmdiocb);
1397 return ndlp->nlp_state;
1401 lpfc_rcv_prli_reglogin_issue(struct lpfc_vport *vport,
1402 struct lpfc_nodelist *ndlp,
1406 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1408 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
1409 return ndlp->nlp_state;
1413 lpfc_rcv_logo_reglogin_issue(struct lpfc_vport *vport,
1414 struct lpfc_nodelist *ndlp,
1418 struct lpfc_hba *phba = vport->phba;
1419 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1421 LPFC_MBOXQ_t *nextmb;
1422 struct lpfc_dmabuf *mp;
1424 cmdiocb = (struct lpfc_iocbq *) arg;
1426 /* cleanup any ndlp on mbox q waiting for reglogin cmpl */
1427 if ((mb = phba->sli.mbox_active)) {
1428 if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) &&
1429 (ndlp == (struct lpfc_nodelist *) mb->context2)) {
1431 mb->context2 = NULL;
1432 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1436 spin_lock_irq(&phba->hbalock);
1437 list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) {
1438 if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) &&
1439 (ndlp == (struct lpfc_nodelist *) mb->context2)) {
1440 mp = (struct lpfc_dmabuf *) (mb->context1);
1442 __lpfc_mbuf_free(phba, mp->virt, mp->phys);
1446 list_del(&mb->list);
1447 phba->sli.mboxq_cnt--;
1448 mempool_free(mb, phba->mbox_mem_pool);
1451 spin_unlock_irq(&phba->hbalock);
1453 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
1454 return ndlp->nlp_state;
1458 lpfc_rcv_padisc_reglogin_issue(struct lpfc_vport *vport,
1459 struct lpfc_nodelist *ndlp,
1463 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1465 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
1466 return ndlp->nlp_state;
1470 lpfc_rcv_prlo_reglogin_issue(struct lpfc_vport *vport,
1471 struct lpfc_nodelist *ndlp,
1475 struct lpfc_iocbq *cmdiocb;
1477 cmdiocb = (struct lpfc_iocbq *) arg;
1478 lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL);
1479 return ndlp->nlp_state;
1483 lpfc_cmpl_reglogin_reglogin_issue(struct lpfc_vport *vport,
1484 struct lpfc_nodelist *ndlp,
1488 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1489 LPFC_MBOXQ_t *pmb = (LPFC_MBOXQ_t *) arg;
1490 MAILBOX_t *mb = &pmb->u.mb;
1491 uint32_t did = mb->un.varWords[1];
1493 if (mb->mbxStatus) {
1494 /* RegLogin failed */
1495 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
1496 "0246 RegLogin failed Data: x%x x%x x%x x%x "
1498 did, mb->mbxStatus, vport->port_state,
1499 mb->un.varRegLogin.vpi,
1500 mb->un.varRegLogin.rpi);
1502 * If RegLogin failed due to lack of HBA resources do not
1505 if (mb->mbxStatus == MBXERR_RPI_FULL) {
1506 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
1507 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1508 return ndlp->nlp_state;
1511 /* Put ndlp in npr state set plogi timer for 1 sec */
1512 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ * 1);
1513 spin_lock_irq(shost->host_lock);
1514 ndlp->nlp_flag |= NLP_DELAY_TMO;
1515 spin_unlock_irq(shost->host_lock);
1516 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
1518 lpfc_issue_els_logo(vport, ndlp, 0);
1519 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
1520 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1521 return ndlp->nlp_state;
1524 /* SLI4 ports have preallocated logical rpis. */
1525 if (vport->phba->sli_rev < LPFC_SLI_REV4)
1526 ndlp->nlp_rpi = mb->un.varWords[0];
1528 ndlp->nlp_flag |= NLP_RPI_REGISTERED;
1530 /* Only if we are not a fabric nport do we issue PRLI */
1531 if (!(ndlp->nlp_type & NLP_FABRIC)) {
1532 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
1533 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
1534 lpfc_issue_els_prli(vport, ndlp, 0);
1536 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
1537 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
1539 return ndlp->nlp_state;
1543 lpfc_device_rm_reglogin_issue(struct lpfc_vport *vport,
1544 struct lpfc_nodelist *ndlp,
1548 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1550 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1551 spin_lock_irq(shost->host_lock);
1552 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
1553 spin_unlock_irq(shost->host_lock);
1554 return ndlp->nlp_state;
1556 lpfc_drop_node(vport, ndlp);
1557 return NLP_STE_FREED_NODE;
1562 lpfc_device_recov_reglogin_issue(struct lpfc_vport *vport,
1563 struct lpfc_nodelist *ndlp,
1567 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1569 /* Don't do anything that will mess up processing of the
1572 if (vport->fc_flag & FC_RSCN_DEFERRED)
1573 return ndlp->nlp_state;
1575 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
1576 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1577 spin_lock_irq(shost->host_lock);
1578 ndlp->nlp_flag |= NLP_IGNR_REG_CMPL;
1579 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
1580 spin_unlock_irq(shost->host_lock);
1581 lpfc_disc_set_adisc(vport, ndlp);
1582 return ndlp->nlp_state;
1586 lpfc_rcv_plogi_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1587 void *arg, uint32_t evt)
1589 struct lpfc_iocbq *cmdiocb;
1591 cmdiocb = (struct lpfc_iocbq *) arg;
1593 lpfc_rcv_plogi(vport, ndlp, cmdiocb);
1594 return ndlp->nlp_state;
1598 lpfc_rcv_prli_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1599 void *arg, uint32_t evt)
1601 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1603 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
1604 return ndlp->nlp_state;
1608 lpfc_rcv_logo_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1609 void *arg, uint32_t evt)
1611 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1613 /* Software abort outstanding PRLI before sending acc */
1614 lpfc_els_abort(vport->phba, ndlp);
1616 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
1617 return ndlp->nlp_state;
1621 lpfc_rcv_padisc_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1622 void *arg, uint32_t evt)
1624 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1626 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
1627 return ndlp->nlp_state;
1630 /* This routine is envoked when we rcv a PRLO request from a nport
1631 * we are logged into. We should send back a PRLO rsp setting the
1633 * NEXT STATE = PRLI_ISSUE
1636 lpfc_rcv_prlo_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1637 void *arg, uint32_t evt)
1639 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1641 lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL);
1642 return ndlp->nlp_state;
1646 lpfc_cmpl_prli_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1647 void *arg, uint32_t evt)
1649 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1650 struct lpfc_iocbq *cmdiocb, *rspiocb;
1651 struct lpfc_hba *phba = vport->phba;
1655 cmdiocb = (struct lpfc_iocbq *) arg;
1656 rspiocb = cmdiocb->context_un.rsp_iocb;
1657 npr = (PRLI *)lpfc_check_elscmpl_iocb(phba, cmdiocb, rspiocb);
1659 irsp = &rspiocb->iocb;
1660 if (irsp->ulpStatus) {
1661 if ((vport->port_type == LPFC_NPIV_PORT) &&
1662 vport->cfg_restrict_login) {
1665 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
1666 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
1667 return ndlp->nlp_state;
1670 /* Check out PRLI rsp */
1671 ndlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR);
1672 ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
1673 if ((npr->acceptRspCode == PRLI_REQ_EXECUTED) &&
1674 (npr->prliType == PRLI_FCP_TYPE)) {
1675 if (npr->initiatorFunc)
1676 ndlp->nlp_type |= NLP_FCP_INITIATOR;
1677 if (npr->targetFunc)
1678 ndlp->nlp_type |= NLP_FCP_TARGET;
1680 ndlp->nlp_fcp_info |= NLP_FCP_2_DEVICE;
1682 if (!(ndlp->nlp_type & NLP_FCP_TARGET) &&
1683 (vport->port_type == LPFC_NPIV_PORT) &&
1684 vport->cfg_restrict_login) {
1686 spin_lock_irq(shost->host_lock);
1687 ndlp->nlp_flag |= NLP_TARGET_REMOVE;
1688 spin_unlock_irq(shost->host_lock);
1689 lpfc_issue_els_logo(vport, ndlp, 0);
1691 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
1692 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1693 return ndlp->nlp_state;
1696 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
1697 if (ndlp->nlp_type & NLP_FCP_TARGET)
1698 lpfc_nlp_set_state(vport, ndlp, NLP_STE_MAPPED_NODE);
1700 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
1701 return ndlp->nlp_state;
1704 /*! lpfc_device_rm_prli_issue
1715 * This routine is envoked when we a request to remove a nport we are in the
1716 * process of PRLIing. We should software abort outstanding prli, unreg
1717 * login, send a logout. We will change node state to UNUSED_NODE, put it
1718 * on plogi list so it can be freed when LOGO completes.
1723 lpfc_device_rm_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1724 void *arg, uint32_t evt)
1726 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1728 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1729 spin_lock_irq(shost->host_lock);
1730 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
1731 spin_unlock_irq(shost->host_lock);
1732 return ndlp->nlp_state;
1734 /* software abort outstanding PLOGI */
1735 lpfc_els_abort(vport->phba, ndlp);
1737 lpfc_drop_node(vport, ndlp);
1738 return NLP_STE_FREED_NODE;
1743 /*! lpfc_device_recov_prli_issue
1754 * The routine is envoked when the state of a device is unknown, like
1755 * during a link down. We should remove the nodelist entry from the
1756 * unmapped list, issue a UNREG_LOGIN, do a software abort of the
1757 * outstanding PRLI command, then free the node entry.
1760 lpfc_device_recov_prli_issue(struct lpfc_vport *vport,
1761 struct lpfc_nodelist *ndlp,
1765 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1766 struct lpfc_hba *phba = vport->phba;
1768 /* Don't do anything that will mess up processing of the
1771 if (vport->fc_flag & FC_RSCN_DEFERRED)
1772 return ndlp->nlp_state;
1774 /* software abort outstanding PRLI */
1775 lpfc_els_abort(phba, ndlp);
1777 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
1778 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1779 spin_lock_irq(shost->host_lock);
1780 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
1781 spin_unlock_irq(shost->host_lock);
1782 lpfc_disc_set_adisc(vport, ndlp);
1783 return ndlp->nlp_state;
1787 lpfc_rcv_plogi_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1788 void *arg, uint32_t evt)
1790 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *)arg;
1793 memset(&stat, 0, sizeof(struct ls_rjt));
1794 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
1795 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
1796 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
1797 return ndlp->nlp_state;
1801 lpfc_rcv_prli_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1802 void *arg, uint32_t evt)
1804 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *)arg;
1807 memset(&stat, 0, sizeof(struct ls_rjt));
1808 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
1809 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
1810 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
1811 return ndlp->nlp_state;
1815 lpfc_rcv_logo_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1816 void *arg, uint32_t evt)
1818 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1819 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *)arg;
1821 spin_lock_irq(shost->host_lock);
1822 ndlp->nlp_flag &= NLP_LOGO_ACC;
1823 spin_unlock_irq(shost->host_lock);
1824 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
1825 return ndlp->nlp_state;
1829 lpfc_rcv_padisc_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1830 void *arg, uint32_t evt)
1832 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *)arg;
1835 memset(&stat, 0, sizeof(struct ls_rjt));
1836 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
1837 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
1838 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
1839 return ndlp->nlp_state;
1843 lpfc_rcv_prlo_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1844 void *arg, uint32_t evt)
1846 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *)arg;
1849 memset(&stat, 0, sizeof(struct ls_rjt));
1850 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
1851 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
1852 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
1853 return ndlp->nlp_state;
1857 lpfc_cmpl_logo_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1858 void *arg, uint32_t evt)
1860 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1862 ndlp->nlp_prev_state = NLP_STE_LOGO_ISSUE;
1863 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1864 spin_lock_irq(shost->host_lock);
1865 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
1866 spin_unlock_irq(shost->host_lock);
1867 lpfc_disc_set_adisc(vport, ndlp);
1868 return ndlp->nlp_state;
1872 lpfc_device_rm_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1873 void *arg, uint32_t evt)
1876 * Take no action. If a LOGO is outstanding, then possibly DevLoss has
1877 * timed out and is calling for Device Remove. In this case, the LOGO
1878 * must be allowed to complete in state LOGO_ISSUE so that the rpi
1879 * and other NLP flags are correctly cleaned up.
1881 return ndlp->nlp_state;
1885 lpfc_device_recov_logo_issue(struct lpfc_vport *vport,
1886 struct lpfc_nodelist *ndlp,
1887 void *arg, uint32_t evt)
1890 * Device Recovery events have no meaning for a node with a LOGO
1891 * outstanding. The LOGO has to complete first and handle the
1892 * node from that point.
1894 return ndlp->nlp_state;
1898 lpfc_rcv_plogi_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1899 void *arg, uint32_t evt)
1901 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1903 lpfc_rcv_plogi(vport, ndlp, cmdiocb);
1904 return ndlp->nlp_state;
1908 lpfc_rcv_prli_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1909 void *arg, uint32_t evt)
1911 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1913 lpfc_rcv_prli(vport, ndlp, cmdiocb);
1914 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
1915 return ndlp->nlp_state;
1919 lpfc_rcv_logo_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1920 void *arg, uint32_t evt)
1922 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1924 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
1925 return ndlp->nlp_state;
1929 lpfc_rcv_padisc_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1930 void *arg, uint32_t evt)
1932 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1934 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
1935 return ndlp->nlp_state;
1939 lpfc_rcv_prlo_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1940 void *arg, uint32_t evt)
1942 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1944 lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL);
1945 return ndlp->nlp_state;
1949 lpfc_device_recov_unmap_node(struct lpfc_vport *vport,
1950 struct lpfc_nodelist *ndlp,
1954 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1956 ndlp->nlp_prev_state = NLP_STE_UNMAPPED_NODE;
1957 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1958 spin_lock_irq(shost->host_lock);
1959 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
1960 spin_unlock_irq(shost->host_lock);
1961 lpfc_disc_set_adisc(vport, ndlp);
1963 return ndlp->nlp_state;
1967 lpfc_rcv_plogi_mapped_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_plogi(vport, ndlp, cmdiocb);
1973 return ndlp->nlp_state;
1977 lpfc_rcv_prli_mapped_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_els_rsp_prli_acc(vport, cmdiocb, ndlp);
1983 return ndlp->nlp_state;
1987 lpfc_rcv_logo_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1988 void *arg, uint32_t evt)
1990 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1992 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
1993 return ndlp->nlp_state;
1997 lpfc_rcv_padisc_mapped_node(struct lpfc_vport *vport,
1998 struct lpfc_nodelist *ndlp,
1999 void *arg, uint32_t evt)
2001 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2003 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
2004 return ndlp->nlp_state;
2008 lpfc_rcv_prlo_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2009 void *arg, uint32_t evt)
2011 struct lpfc_hba *phba = vport->phba;
2012 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2014 /* flush the target */
2015 lpfc_sli_abort_iocb(vport, &phba->sli.ring[phba->sli.fcp_ring],
2016 ndlp->nlp_sid, 0, LPFC_CTX_TGT);
2018 /* Treat like rcv logo */
2019 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_PRLO);
2020 return ndlp->nlp_state;
2024 lpfc_device_recov_mapped_node(struct lpfc_vport *vport,
2025 struct lpfc_nodelist *ndlp,
2029 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2031 ndlp->nlp_prev_state = NLP_STE_MAPPED_NODE;
2032 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
2033 spin_lock_irq(shost->host_lock);
2034 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
2035 spin_unlock_irq(shost->host_lock);
2036 lpfc_disc_set_adisc(vport, ndlp);
2037 return ndlp->nlp_state;
2041 lpfc_rcv_plogi_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2042 void *arg, uint32_t evt)
2044 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2045 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2047 /* Ignore PLOGI if we have an outstanding LOGO */
2048 if (ndlp->nlp_flag & (NLP_LOGO_SND | NLP_LOGO_ACC))
2049 return ndlp->nlp_state;
2050 if (lpfc_rcv_plogi(vport, ndlp, cmdiocb)) {
2051 lpfc_cancel_retry_delay_tmo(vport, ndlp);
2052 spin_lock_irq(shost->host_lock);
2053 ndlp->nlp_flag &= ~(NLP_NPR_ADISC | NLP_NPR_2B_DISC);
2054 spin_unlock_irq(shost->host_lock);
2055 } else if (!(ndlp->nlp_flag & NLP_NPR_2B_DISC)) {
2056 /* send PLOGI immediately, move to PLOGI issue state */
2057 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
2058 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
2059 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
2060 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
2063 return ndlp->nlp_state;
2067 lpfc_rcv_prli_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2068 void *arg, uint32_t evt)
2070 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2071 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2074 memset(&stat, 0, sizeof (struct ls_rjt));
2075 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
2076 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
2077 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
2079 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
2080 if (ndlp->nlp_flag & NLP_NPR_ADISC) {
2081 spin_lock_irq(shost->host_lock);
2082 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
2083 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
2084 spin_unlock_irq(shost->host_lock);
2085 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
2086 lpfc_issue_els_adisc(vport, ndlp, 0);
2088 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
2089 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
2090 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
2093 return ndlp->nlp_state;
2097 lpfc_rcv_logo_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2098 void *arg, uint32_t evt)
2100 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2102 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
2103 return ndlp->nlp_state;
2107 lpfc_rcv_padisc_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2108 void *arg, uint32_t evt)
2110 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2112 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
2114 * Do not start discovery if discovery is about to start
2115 * or discovery in progress for this node. Starting discovery
2116 * here will affect the counting of discovery threads.
2118 if (!(ndlp->nlp_flag & NLP_DELAY_TMO) &&
2119 !(ndlp->nlp_flag & NLP_NPR_2B_DISC)) {
2120 if (ndlp->nlp_flag & NLP_NPR_ADISC) {
2121 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
2122 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
2123 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
2124 lpfc_issue_els_adisc(vport, ndlp, 0);
2126 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
2127 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
2128 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
2131 return ndlp->nlp_state;
2135 lpfc_rcv_prlo_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2136 void *arg, uint32_t evt)
2138 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2139 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2141 spin_lock_irq(shost->host_lock);
2142 ndlp->nlp_flag |= NLP_LOGO_ACC;
2143 spin_unlock_irq(shost->host_lock);
2145 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
2147 if ((ndlp->nlp_flag & NLP_DELAY_TMO) == 0) {
2148 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ * 1);
2149 spin_lock_irq(shost->host_lock);
2150 ndlp->nlp_flag |= NLP_DELAY_TMO;
2151 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
2152 spin_unlock_irq(shost->host_lock);
2153 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
2155 spin_lock_irq(shost->host_lock);
2156 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
2157 spin_unlock_irq(shost->host_lock);
2159 return ndlp->nlp_state;
2163 lpfc_cmpl_plogi_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2164 void *arg, uint32_t evt)
2166 struct lpfc_iocbq *cmdiocb, *rspiocb;
2168 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2170 cmdiocb = (struct lpfc_iocbq *) arg;
2171 rspiocb = cmdiocb->context_un.rsp_iocb;
2173 irsp = &rspiocb->iocb;
2174 if (irsp->ulpStatus) {
2175 spin_lock_irq(shost->host_lock);
2176 ndlp->nlp_flag |= NLP_DEFER_RM;
2177 spin_unlock_irq(shost->host_lock);
2178 return NLP_STE_FREED_NODE;
2180 return ndlp->nlp_state;
2184 lpfc_cmpl_prli_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2185 void *arg, uint32_t evt)
2187 struct lpfc_iocbq *cmdiocb, *rspiocb;
2190 cmdiocb = (struct lpfc_iocbq *) arg;
2191 rspiocb = cmdiocb->context_un.rsp_iocb;
2193 irsp = &rspiocb->iocb;
2194 if (irsp->ulpStatus && (ndlp->nlp_flag & NLP_NODEV_REMOVE)) {
2195 lpfc_drop_node(vport, ndlp);
2196 return NLP_STE_FREED_NODE;
2198 return ndlp->nlp_state;
2202 lpfc_cmpl_logo_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2203 void *arg, uint32_t evt)
2205 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2207 /* For the fabric port just clear the fc flags. */
2208 if (ndlp->nlp_DID == Fabric_DID) {
2209 spin_lock_irq(shost->host_lock);
2210 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
2211 spin_unlock_irq(shost->host_lock);
2213 lpfc_unreg_rpi(vport, ndlp);
2214 return ndlp->nlp_state;
2218 lpfc_cmpl_adisc_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2219 void *arg, uint32_t evt)
2221 struct lpfc_iocbq *cmdiocb, *rspiocb;
2224 cmdiocb = (struct lpfc_iocbq *) arg;
2225 rspiocb = cmdiocb->context_un.rsp_iocb;
2227 irsp = &rspiocb->iocb;
2228 if (irsp->ulpStatus && (ndlp->nlp_flag & NLP_NODEV_REMOVE)) {
2229 lpfc_drop_node(vport, ndlp);
2230 return NLP_STE_FREED_NODE;
2232 return ndlp->nlp_state;
2236 lpfc_cmpl_reglogin_npr_node(struct lpfc_vport *vport,
2237 struct lpfc_nodelist *ndlp,
2238 void *arg, uint32_t evt)
2240 LPFC_MBOXQ_t *pmb = (LPFC_MBOXQ_t *) arg;
2241 MAILBOX_t *mb = &pmb->u.mb;
2243 if (!mb->mbxStatus) {
2244 /* SLI4 ports have preallocated logical rpis. */
2245 if (vport->phba->sli_rev < LPFC_SLI_REV4)
2246 ndlp->nlp_rpi = mb->un.varWords[0];
2247 ndlp->nlp_flag |= NLP_RPI_REGISTERED;
2249 if (ndlp->nlp_flag & NLP_NODEV_REMOVE) {
2250 lpfc_drop_node(vport, ndlp);
2251 return NLP_STE_FREED_NODE;
2254 return ndlp->nlp_state;
2258 lpfc_device_rm_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2259 void *arg, uint32_t evt)
2261 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2263 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
2264 spin_lock_irq(shost->host_lock);
2265 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
2266 spin_unlock_irq(shost->host_lock);
2267 return ndlp->nlp_state;
2269 lpfc_drop_node(vport, ndlp);
2270 return NLP_STE_FREED_NODE;
2274 lpfc_device_recov_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2275 void *arg, uint32_t evt)
2277 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2279 /* Don't do anything that will mess up processing of the
2282 if (vport->fc_flag & FC_RSCN_DEFERRED)
2283 return ndlp->nlp_state;
2285 lpfc_cancel_retry_delay_tmo(vport, ndlp);
2286 spin_lock_irq(shost->host_lock);
2287 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
2288 spin_unlock_irq(shost->host_lock);
2289 return ndlp->nlp_state;
2293 /* This next section defines the NPort Discovery State Machine */
2295 /* There are 4 different double linked lists nodelist entries can reside on.
2296 * The plogi list and adisc list are used when Link Up discovery or RSCN
2297 * processing is needed. Each list holds the nodes that we will send PLOGI
2298 * or ADISC on. These lists will keep track of what nodes will be effected
2299 * by an RSCN, or a Link Up (Typically, all nodes are effected on Link Up).
2300 * The unmapped_list will contain all nodes that we have successfully logged
2301 * into at the Fibre Channel level. The mapped_list will contain all nodes
2302 * that are mapped FCP targets.
2305 * The bind list is a list of undiscovered (potentially non-existent) nodes
2306 * that we have saved binding information on. This information is used when
2307 * nodes transition from the unmapped to the mapped list.
2309 /* For UNUSED_NODE state, the node has just been allocated .
2310 * For PLOGI_ISSUE and REG_LOGIN_ISSUE, the node is on
2311 * the PLOGI list. For REG_LOGIN_COMPL, the node is taken off the PLOGI list
2312 * and put on the unmapped list. For ADISC processing, the node is taken off
2313 * the ADISC list and placed on either the mapped or unmapped list (depending
2314 * on its previous state). Once on the unmapped list, a PRLI is issued and the
2315 * state changed to PRLI_ISSUE. When the PRLI completion occurs, the state is
2316 * changed to UNMAPPED_NODE. If the completion indicates a mapped
2317 * node, the node is taken off the unmapped list. The binding list is checked
2318 * for a valid binding, or a binding is automatically assigned. If binding
2319 * assignment is unsuccessful, the node is left on the unmapped list. If
2320 * binding assignment is successful, the associated binding list entry (if
2321 * any) is removed, and the node is placed on the mapped list.
2324 * For a Link Down, all nodes on the ADISC, PLOGI, unmapped or mapped
2325 * lists will receive a DEVICE_RECOVERY event. If the linkdown or devloss timers
2326 * expire, all effected nodes will receive a DEVICE_RM event.
2329 * For a Link Up or RSCN, all nodes will move from the mapped / unmapped lists
2330 * to either the ADISC or PLOGI list. After a Nameserver query or ALPA loopmap
2331 * check, additional nodes may be added or removed (via DEVICE_RM) to / from
2332 * the PLOGI or ADISC lists. Once the PLOGI and ADISC lists are populated,
2333 * we will first process the ADISC list. 32 entries are processed initially and
2334 * ADISC is initited for each one. Completions / Events for each node are
2335 * funnelled thru the state machine. As each node finishes ADISC processing, it
2336 * starts ADISC for any nodes waiting for ADISC processing. If no nodes are
2337 * waiting, and the ADISC list count is identically 0, then we are done. For
2338 * Link Up discovery, since all nodes on the PLOGI list are UNREG_LOGIN'ed, we
2339 * can issue a CLEAR_LA and reenable Link Events. Next we will process the PLOGI
2340 * list. 32 entries are processed initially and PLOGI is initited for each one.
2341 * Completions / Events for each node are funnelled thru the state machine. As
2342 * each node finishes PLOGI processing, it starts PLOGI for any nodes waiting
2343 * for PLOGI processing. If no nodes are waiting, and the PLOGI list count is
2344 * indentically 0, then we are done. We have now completed discovery / RSCN
2345 * handling. Upon completion, ALL nodes should be on either the mapped or
2349 static uint32_t (*lpfc_disc_action[NLP_STE_MAX_STATE * NLP_EVT_MAX_EVENT])
2350 (struct lpfc_vport *, struct lpfc_nodelist *, void *, uint32_t) = {
2351 /* Action routine Event Current State */
2352 lpfc_rcv_plogi_unused_node, /* RCV_PLOGI UNUSED_NODE */
2353 lpfc_rcv_els_unused_node, /* RCV_PRLI */
2354 lpfc_rcv_logo_unused_node, /* RCV_LOGO */
2355 lpfc_rcv_els_unused_node, /* RCV_ADISC */
2356 lpfc_rcv_els_unused_node, /* RCV_PDISC */
2357 lpfc_rcv_els_unused_node, /* RCV_PRLO */
2358 lpfc_disc_illegal, /* CMPL_PLOGI */
2359 lpfc_disc_illegal, /* CMPL_PRLI */
2360 lpfc_cmpl_logo_unused_node, /* CMPL_LOGO */
2361 lpfc_disc_illegal, /* CMPL_ADISC */
2362 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2363 lpfc_device_rm_unused_node, /* DEVICE_RM */
2364 lpfc_device_recov_unused_node, /* DEVICE_RECOVERY */
2366 lpfc_rcv_plogi_plogi_issue, /* RCV_PLOGI PLOGI_ISSUE */
2367 lpfc_rcv_prli_plogi_issue, /* RCV_PRLI */
2368 lpfc_rcv_logo_plogi_issue, /* RCV_LOGO */
2369 lpfc_rcv_els_plogi_issue, /* RCV_ADISC */
2370 lpfc_rcv_els_plogi_issue, /* RCV_PDISC */
2371 lpfc_rcv_els_plogi_issue, /* RCV_PRLO */
2372 lpfc_cmpl_plogi_plogi_issue, /* CMPL_PLOGI */
2373 lpfc_disc_illegal, /* CMPL_PRLI */
2374 lpfc_cmpl_logo_plogi_issue, /* CMPL_LOGO */
2375 lpfc_disc_illegal, /* CMPL_ADISC */
2376 lpfc_cmpl_reglogin_plogi_issue,/* CMPL_REG_LOGIN */
2377 lpfc_device_rm_plogi_issue, /* DEVICE_RM */
2378 lpfc_device_recov_plogi_issue, /* DEVICE_RECOVERY */
2380 lpfc_rcv_plogi_adisc_issue, /* RCV_PLOGI ADISC_ISSUE */
2381 lpfc_rcv_prli_adisc_issue, /* RCV_PRLI */
2382 lpfc_rcv_logo_adisc_issue, /* RCV_LOGO */
2383 lpfc_rcv_padisc_adisc_issue, /* RCV_ADISC */
2384 lpfc_rcv_padisc_adisc_issue, /* RCV_PDISC */
2385 lpfc_rcv_prlo_adisc_issue, /* RCV_PRLO */
2386 lpfc_disc_illegal, /* CMPL_PLOGI */
2387 lpfc_disc_illegal, /* CMPL_PRLI */
2388 lpfc_disc_illegal, /* CMPL_LOGO */
2389 lpfc_cmpl_adisc_adisc_issue, /* CMPL_ADISC */
2390 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2391 lpfc_device_rm_adisc_issue, /* DEVICE_RM */
2392 lpfc_device_recov_adisc_issue, /* DEVICE_RECOVERY */
2394 lpfc_rcv_plogi_reglogin_issue, /* RCV_PLOGI REG_LOGIN_ISSUE */
2395 lpfc_rcv_prli_reglogin_issue, /* RCV_PLOGI */
2396 lpfc_rcv_logo_reglogin_issue, /* RCV_LOGO */
2397 lpfc_rcv_padisc_reglogin_issue, /* RCV_ADISC */
2398 lpfc_rcv_padisc_reglogin_issue, /* RCV_PDISC */
2399 lpfc_rcv_prlo_reglogin_issue, /* RCV_PRLO */
2400 lpfc_cmpl_plogi_illegal, /* CMPL_PLOGI */
2401 lpfc_disc_illegal, /* CMPL_PRLI */
2402 lpfc_disc_illegal, /* CMPL_LOGO */
2403 lpfc_disc_illegal, /* CMPL_ADISC */
2404 lpfc_cmpl_reglogin_reglogin_issue,/* CMPL_REG_LOGIN */
2405 lpfc_device_rm_reglogin_issue, /* DEVICE_RM */
2406 lpfc_device_recov_reglogin_issue,/* DEVICE_RECOVERY */
2408 lpfc_rcv_plogi_prli_issue, /* RCV_PLOGI PRLI_ISSUE */
2409 lpfc_rcv_prli_prli_issue, /* RCV_PRLI */
2410 lpfc_rcv_logo_prli_issue, /* RCV_LOGO */
2411 lpfc_rcv_padisc_prli_issue, /* RCV_ADISC */
2412 lpfc_rcv_padisc_prli_issue, /* RCV_PDISC */
2413 lpfc_rcv_prlo_prli_issue, /* RCV_PRLO */
2414 lpfc_cmpl_plogi_illegal, /* CMPL_PLOGI */
2415 lpfc_cmpl_prli_prli_issue, /* CMPL_PRLI */
2416 lpfc_disc_illegal, /* CMPL_LOGO */
2417 lpfc_disc_illegal, /* CMPL_ADISC */
2418 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2419 lpfc_device_rm_prli_issue, /* DEVICE_RM */
2420 lpfc_device_recov_prli_issue, /* DEVICE_RECOVERY */
2422 lpfc_rcv_plogi_logo_issue, /* RCV_PLOGI LOGO_ISSUE */
2423 lpfc_rcv_prli_logo_issue, /* RCV_PRLI */
2424 lpfc_rcv_logo_logo_issue, /* RCV_LOGO */
2425 lpfc_rcv_padisc_logo_issue, /* RCV_ADISC */
2426 lpfc_rcv_padisc_logo_issue, /* RCV_PDISC */
2427 lpfc_rcv_prlo_logo_issue, /* RCV_PRLO */
2428 lpfc_cmpl_plogi_illegal, /* CMPL_PLOGI */
2429 lpfc_disc_illegal, /* CMPL_PRLI */
2430 lpfc_cmpl_logo_logo_issue, /* CMPL_LOGO */
2431 lpfc_disc_illegal, /* CMPL_ADISC */
2432 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2433 lpfc_device_rm_logo_issue, /* DEVICE_RM */
2434 lpfc_device_recov_logo_issue, /* DEVICE_RECOVERY */
2436 lpfc_rcv_plogi_unmap_node, /* RCV_PLOGI UNMAPPED_NODE */
2437 lpfc_rcv_prli_unmap_node, /* RCV_PRLI */
2438 lpfc_rcv_logo_unmap_node, /* RCV_LOGO */
2439 lpfc_rcv_padisc_unmap_node, /* RCV_ADISC */
2440 lpfc_rcv_padisc_unmap_node, /* RCV_PDISC */
2441 lpfc_rcv_prlo_unmap_node, /* RCV_PRLO */
2442 lpfc_disc_illegal, /* CMPL_PLOGI */
2443 lpfc_disc_illegal, /* CMPL_PRLI */
2444 lpfc_disc_illegal, /* CMPL_LOGO */
2445 lpfc_disc_illegal, /* CMPL_ADISC */
2446 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2447 lpfc_disc_illegal, /* DEVICE_RM */
2448 lpfc_device_recov_unmap_node, /* DEVICE_RECOVERY */
2450 lpfc_rcv_plogi_mapped_node, /* RCV_PLOGI MAPPED_NODE */
2451 lpfc_rcv_prli_mapped_node, /* RCV_PRLI */
2452 lpfc_rcv_logo_mapped_node, /* RCV_LOGO */
2453 lpfc_rcv_padisc_mapped_node, /* RCV_ADISC */
2454 lpfc_rcv_padisc_mapped_node, /* RCV_PDISC */
2455 lpfc_rcv_prlo_mapped_node, /* RCV_PRLO */
2456 lpfc_disc_illegal, /* CMPL_PLOGI */
2457 lpfc_disc_illegal, /* CMPL_PRLI */
2458 lpfc_disc_illegal, /* CMPL_LOGO */
2459 lpfc_disc_illegal, /* CMPL_ADISC */
2460 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2461 lpfc_disc_illegal, /* DEVICE_RM */
2462 lpfc_device_recov_mapped_node, /* DEVICE_RECOVERY */
2464 lpfc_rcv_plogi_npr_node, /* RCV_PLOGI NPR_NODE */
2465 lpfc_rcv_prli_npr_node, /* RCV_PRLI */
2466 lpfc_rcv_logo_npr_node, /* RCV_LOGO */
2467 lpfc_rcv_padisc_npr_node, /* RCV_ADISC */
2468 lpfc_rcv_padisc_npr_node, /* RCV_PDISC */
2469 lpfc_rcv_prlo_npr_node, /* RCV_PRLO */
2470 lpfc_cmpl_plogi_npr_node, /* CMPL_PLOGI */
2471 lpfc_cmpl_prli_npr_node, /* CMPL_PRLI */
2472 lpfc_cmpl_logo_npr_node, /* CMPL_LOGO */
2473 lpfc_cmpl_adisc_npr_node, /* CMPL_ADISC */
2474 lpfc_cmpl_reglogin_npr_node, /* CMPL_REG_LOGIN */
2475 lpfc_device_rm_npr_node, /* DEVICE_RM */
2476 lpfc_device_recov_npr_node, /* DEVICE_RECOVERY */
2480 lpfc_disc_state_machine(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2481 void *arg, uint32_t evt)
2483 uint32_t cur_state, rc;
2484 uint32_t(*func) (struct lpfc_vport *, struct lpfc_nodelist *, void *,
2486 uint32_t got_ndlp = 0;
2488 if (lpfc_nlp_get(ndlp))
2491 cur_state = ndlp->nlp_state;
2493 /* DSM in event <evt> on NPort <nlp_DID> in state <cur_state> */
2494 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2495 "0211 DSM in event x%x on NPort x%x in "
2496 "state %d Data: x%x\n",
2497 evt, ndlp->nlp_DID, cur_state, ndlp->nlp_flag);
2499 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_DSM,
2500 "DSM in: evt:%d ste:%d did:x%x",
2501 evt, cur_state, ndlp->nlp_DID);
2503 func = lpfc_disc_action[(cur_state * NLP_EVT_MAX_EVENT) + evt];
2504 rc = (func) (vport, ndlp, arg, evt);
2506 /* DSM out state <rc> on NPort <nlp_DID> */
2508 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2509 "0212 DSM out state %d on NPort x%x Data: x%x\n",
2510 rc, ndlp->nlp_DID, ndlp->nlp_flag);
2512 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_DSM,
2513 "DSM out: ste:%d did:x%x flg:x%x",
2514 rc, ndlp->nlp_DID, ndlp->nlp_flag);
2515 /* Decrement the ndlp reference count held for this function */
2518 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2519 "0213 DSM out state %d on NPort free\n", rc);
2521 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_DSM,
2522 "DSM out: ste:%d did:x%x flg:x%x",