1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2004-2016 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(abort_list);
207 struct lpfc_sli *psli = &phba->sli;
208 struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING];
209 struct lpfc_iocbq *iocb, *next_iocb;
211 /* Abort outstanding I/O on NPort <nlp_DID> */
212 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_DISCOVERY,
213 "2819 Abort outstanding I/O on NPort x%x "
214 "Data: x%x x%x x%x\n",
215 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
217 /* Clean up all fabric IOs first.*/
218 lpfc_fabric_abort_nport(ndlp);
221 * Lock the ELS ring txcmplq for SLI3/SLI4 and build a local list
222 * of all ELS IOs that need an ABTS. The IOs need to stay on the
223 * txcmplq so that the abort operation completes them successfully.
225 spin_lock_irq(&phba->hbalock);
226 if (phba->sli_rev == LPFC_SLI_REV4)
227 spin_lock(&pring->ring_lock);
228 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
229 /* Add to abort_list on on NDLP match. */
230 if (lpfc_check_sli_ndlp(phba, pring, iocb, ndlp))
231 list_add_tail(&iocb->dlist, &abort_list);
233 if (phba->sli_rev == LPFC_SLI_REV4)
234 spin_unlock(&pring->ring_lock);
235 spin_unlock_irq(&phba->hbalock);
237 /* Abort the targeted IOs and remove them from the abort list. */
238 list_for_each_entry_safe(iocb, next_iocb, &abort_list, dlist) {
239 spin_lock_irq(&phba->hbalock);
240 list_del_init(&iocb->dlist);
241 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
242 spin_unlock_irq(&phba->hbalock);
245 INIT_LIST_HEAD(&abort_list);
247 /* Now process the txq */
248 spin_lock_irq(&phba->hbalock);
249 if (phba->sli_rev == LPFC_SLI_REV4)
250 spin_lock(&pring->ring_lock);
252 list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
253 /* Check to see if iocb matches the nport we are looking for */
254 if (lpfc_check_sli_ndlp(phba, pring, iocb, ndlp)) {
255 list_del_init(&iocb->list);
256 list_add_tail(&iocb->list, &abort_list);
260 if (phba->sli_rev == LPFC_SLI_REV4)
261 spin_unlock(&pring->ring_lock);
262 spin_unlock_irq(&phba->hbalock);
264 /* Cancel all the IOCBs from the completions list */
265 lpfc_sli_cancel_iocbs(phba, &abort_list,
266 IOSTAT_LOCAL_REJECT, IOERR_SLI_ABORTED);
268 lpfc_cancel_retry_delay_tmo(phba->pport, ndlp);
273 lpfc_rcv_plogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
274 struct lpfc_iocbq *cmdiocb)
276 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
277 struct lpfc_hba *phba = vport->phba;
278 struct lpfc_dmabuf *pcmd;
279 uint64_t nlp_portwwn = 0;
282 struct serv_parm *sp;
288 memset(&stat, 0, sizeof (struct ls_rjt));
289 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
290 lp = (uint32_t *) pcmd->virt;
291 sp = (struct serv_parm *) ((uint8_t *) lp + sizeof (uint32_t));
292 if (wwn_to_u64(sp->portName.u.wwn) == 0) {
293 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
294 "0140 PLOGI Reject: invalid nname\n");
295 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
296 stat.un.b.lsRjtRsnCodeExp = LSEXP_INVALID_PNAME;
297 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
301 if (wwn_to_u64(sp->nodeName.u.wwn) == 0) {
302 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
303 "0141 PLOGI Reject: invalid pname\n");
304 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
305 stat.un.b.lsRjtRsnCodeExp = LSEXP_INVALID_NNAME;
306 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
311 nlp_portwwn = wwn_to_u64(ndlp->nlp_portname.u.wwn);
312 if ((lpfc_check_sparm(vport, ndlp, sp, CLASS3, 0) == 0)) {
313 /* Reject this request because invalid parameters */
314 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
315 stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
316 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
320 icmd = &cmdiocb->iocb;
322 /* PLOGI chkparm OK */
323 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
324 "0114 PLOGI chkparm OK Data: x%x x%x x%x "
326 ndlp->nlp_DID, ndlp->nlp_state, ndlp->nlp_flag,
327 ndlp->nlp_rpi, vport->port_state,
330 if (vport->cfg_fcp_class == 2 && sp->cls2.classValid)
331 ndlp->nlp_fcp_info |= CLASS2;
333 ndlp->nlp_fcp_info |= CLASS3;
335 ndlp->nlp_class_sup = 0;
336 if (sp->cls1.classValid)
337 ndlp->nlp_class_sup |= FC_COS_CLASS1;
338 if (sp->cls2.classValid)
339 ndlp->nlp_class_sup |= FC_COS_CLASS2;
340 if (sp->cls3.classValid)
341 ndlp->nlp_class_sup |= FC_COS_CLASS3;
342 if (sp->cls4.classValid)
343 ndlp->nlp_class_sup |= FC_COS_CLASS4;
345 ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) | sp->cmn.bbRcvSizeLsb;
347 /* if already logged in, do implicit logout */
348 switch (ndlp->nlp_state) {
349 case NLP_STE_NPR_NODE:
350 if (!(ndlp->nlp_flag & NLP_NPR_ADISC))
352 case NLP_STE_REG_LOGIN_ISSUE:
353 case NLP_STE_PRLI_ISSUE:
354 case NLP_STE_UNMAPPED_NODE:
355 case NLP_STE_MAPPED_NODE:
356 /* lpfc_plogi_confirm_nport skips fabric did, handle it here */
357 if (!(ndlp->nlp_type & NLP_FABRIC)) {
358 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb,
362 if (nlp_portwwn != 0 &&
363 nlp_portwwn != wwn_to_u64(sp->portName.u.wwn))
364 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
365 "0143 PLOGI recv'd from DID: x%x "
366 "WWPN changed: old %llx new %llx\n",
368 (unsigned long long)nlp_portwwn,
370 wwn_to_u64(sp->portName.u.wwn));
372 ndlp->nlp_prev_state = ndlp->nlp_state;
373 /* rport needs to be unregistered first */
374 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
378 /* Check for Nport to NPort pt2pt protocol */
379 if ((vport->fc_flag & FC_PT2PT) &&
380 !(vport->fc_flag & FC_PT2PT_PLOGI)) {
381 /* rcv'ed PLOGI decides what our NPortId will be */
382 vport->fc_myDID = icmd->un.rcvels.parmRo;
384 ed_tov = be32_to_cpu(sp->cmn.e_d_tov);
385 if (sp->cmn.edtovResolution) {
386 /* E_D_TOV ticks are in nanoseconds */
387 ed_tov = (phba->fc_edtov + 999999) / 1000000;
391 * For pt-to-pt, use the larger EDTOV
394 if (ed_tov > phba->fc_edtov)
395 phba->fc_edtov = ed_tov;
396 phba->fc_ratov = (2 * phba->fc_edtov) / 1000;
398 memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
400 /* Issue config_link / reg_vfi to account for updated TOV's */
402 if (phba->sli_rev == LPFC_SLI_REV4)
403 lpfc_issue_reg_vfi(vport);
405 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
408 lpfc_config_link(phba, mbox);
409 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
411 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
412 if (rc == MBX_NOT_FINISHED) {
413 mempool_free(mbox, phba->mbox_mem_pool);
418 lpfc_can_disctmo(vport);
421 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
425 /* Registering an existing RPI behaves differently for SLI3 vs SLI4 */
426 if (phba->sli_rev == LPFC_SLI_REV4)
427 lpfc_unreg_rpi(vport, ndlp);
429 rc = lpfc_reg_rpi(phba, vport->vpi, icmd->un.rcvels.remoteID,
430 (uint8_t *) sp, mbox, ndlp->nlp_rpi);
432 mempool_free(mbox, phba->mbox_mem_pool);
436 /* ACC PLOGI rsp command needs to execute first,
437 * queue this mbox command to be processed later.
439 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
441 * mbox->context2 = lpfc_nlp_get(ndlp) deferred until mailbox
442 * command issued in lpfc_cmpl_els_acc().
445 spin_lock_irq(shost->host_lock);
446 ndlp->nlp_flag |= (NLP_ACC_REGLOGIN | NLP_RCV_PLOGI);
447 spin_unlock_irq(shost->host_lock);
450 * If there is an outstanding PLOGI issued, abort it before
451 * sending ACC rsp for received PLOGI. If pending plogi
452 * is not canceled here, the plogi will be rejected by
453 * remote port and will be retried. On a configuration with
454 * single discovery thread, this will cause a huge delay in
455 * discovery. Also this will cause multiple state machines
456 * running in parallel for this node.
457 * This only applies to a fabric environment.
459 if ((ndlp->nlp_state == NLP_STE_PLOGI_ISSUE) &&
460 (vport->fc_flag & FC_FABRIC)) {
461 /* software abort outstanding PLOGI */
462 lpfc_els_abort(phba, ndlp);
465 if ((vport->port_type == LPFC_NPIV_PORT &&
466 vport->cfg_restrict_login)) {
468 /* In order to preserve RPIs, we want to cleanup
469 * the default RPI the firmware created to rcv
470 * this ELS request. The only way to do this is
471 * to register, then unregister the RPI.
473 spin_lock_irq(shost->host_lock);
474 ndlp->nlp_flag |= NLP_RM_DFLT_RPI;
475 spin_unlock_irq(shost->host_lock);
476 stat.un.b.lsRjtRsnCode = LSRJT_INVALID_CMD;
477 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
478 rc = lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb,
481 mempool_free(mbox, phba->mbox_mem_pool);
484 rc = lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp, mbox);
486 mempool_free(mbox, phba->mbox_mem_pool);
489 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
490 stat.un.b.lsRjtRsnCodeExp = LSEXP_OUT_OF_RESOURCE;
491 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
496 * lpfc_mbx_cmpl_resume_rpi - Resume RPI completion routine
497 * @phba: pointer to lpfc hba data structure.
498 * @mboxq: pointer to mailbox object
500 * This routine is invoked to issue a completion to a rcv'ed
501 * ADISC or PDISC after the paused RPI has been resumed.
504 lpfc_mbx_cmpl_resume_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
506 struct lpfc_vport *vport;
507 struct lpfc_iocbq *elsiocb;
508 struct lpfc_nodelist *ndlp;
511 elsiocb = (struct lpfc_iocbq *)mboxq->context1;
512 ndlp = (struct lpfc_nodelist *) mboxq->context2;
513 vport = mboxq->vport;
514 cmd = elsiocb->drvrTimeout;
516 if (cmd == ELS_CMD_ADISC) {
517 lpfc_els_rsp_adisc_acc(vport, elsiocb, ndlp);
519 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, elsiocb,
523 mempool_free(mboxq, phba->mbox_mem_pool);
527 lpfc_rcv_padisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
528 struct lpfc_iocbq *cmdiocb)
530 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
531 struct lpfc_iocbq *elsiocb;
532 struct lpfc_dmabuf *pcmd;
533 struct serv_parm *sp;
534 struct lpfc_name *pnn, *ppn;
541 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
542 lp = (uint32_t *) pcmd->virt;
545 if (cmd == ELS_CMD_ADISC) {
547 pnn = (struct lpfc_name *) & ap->nodeName;
548 ppn = (struct lpfc_name *) & ap->portName;
550 sp = (struct serv_parm *) lp;
551 pnn = (struct lpfc_name *) & sp->nodeName;
552 ppn = (struct lpfc_name *) & sp->portName;
555 icmd = &cmdiocb->iocb;
556 if (icmd->ulpStatus == 0 && lpfc_check_adisc(vport, ndlp, pnn, ppn)) {
559 * As soon as we send ACC, the remote NPort can
560 * start sending us data. Thus, for SLI4 we must
561 * resume the RPI before the ACC goes out.
563 if (vport->phba->sli_rev == LPFC_SLI_REV4) {
564 elsiocb = kmalloc(sizeof(struct lpfc_iocbq),
568 /* Save info from cmd IOCB used in rsp */
569 memcpy((uint8_t *)elsiocb, (uint8_t *)cmdiocb,
570 sizeof(struct lpfc_iocbq));
572 /* Save the ELS cmd */
573 elsiocb->drvrTimeout = cmd;
575 lpfc_sli4_resume_rpi(ndlp,
576 lpfc_mbx_cmpl_resume_rpi, elsiocb);
581 if (cmd == ELS_CMD_ADISC) {
582 lpfc_els_rsp_adisc_acc(vport, cmdiocb, ndlp);
584 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb,
588 /* If we are authenticated, move to the proper state */
589 if (ndlp->nlp_type & NLP_FCP_TARGET)
590 lpfc_nlp_set_state(vport, ndlp, NLP_STE_MAPPED_NODE);
592 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
596 /* Reject this request because invalid parameters */
597 stat.un.b.lsRjtRsvd0 = 0;
598 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
599 stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
600 stat.un.b.vendorUnique = 0;
601 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
604 mod_timer(&ndlp->nlp_delayfunc, jiffies + msecs_to_jiffies(1000));
606 spin_lock_irq(shost->host_lock);
607 ndlp->nlp_flag |= NLP_DELAY_TMO;
608 spin_unlock_irq(shost->host_lock);
609 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
610 ndlp->nlp_prev_state = ndlp->nlp_state;
611 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
616 lpfc_rcv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
617 struct lpfc_iocbq *cmdiocb, uint32_t els_cmd)
619 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
620 struct lpfc_hba *phba = vport->phba;
621 struct lpfc_vport **vports;
622 int i, active_vlink_present = 0 ;
624 /* Put ndlp in NPR state with 1 sec timeout for plogi, ACC logo */
625 /* Only call LOGO ACC for first LOGO, this avoids sending unnecessary
626 * PLOGIs during LOGO storms from a device.
628 spin_lock_irq(shost->host_lock);
629 ndlp->nlp_flag |= NLP_LOGO_ACC;
630 spin_unlock_irq(shost->host_lock);
631 if (els_cmd == ELS_CMD_PRLO)
632 lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL);
634 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
635 if (ndlp->nlp_DID == Fabric_DID) {
636 if (vport->port_state <= LPFC_FDISC)
638 lpfc_linkdown_port(vport);
639 spin_lock_irq(shost->host_lock);
640 vport->fc_flag |= FC_VPORT_LOGO_RCVD;
641 spin_unlock_irq(shost->host_lock);
642 vports = lpfc_create_vport_work_array(phba);
644 for (i = 0; i <= phba->max_vports && vports[i] != NULL;
646 if ((!(vports[i]->fc_flag &
647 FC_VPORT_LOGO_RCVD)) &&
648 (vports[i]->port_state > LPFC_FDISC)) {
649 active_vlink_present = 1;
653 lpfc_destroy_vport_work_array(phba, vports);
657 * Don't re-instantiate if vport is marked for deletion.
658 * If we are here first then vport_delete is going to wait
659 * for discovery to complete.
661 if (!(vport->load_flag & FC_UNLOADING) &&
662 active_vlink_present) {
664 * If there are other active VLinks present,
665 * re-instantiate the Vlink using FDISC.
667 mod_timer(&ndlp->nlp_delayfunc,
668 jiffies + msecs_to_jiffies(1000));
669 spin_lock_irq(shost->host_lock);
670 ndlp->nlp_flag |= NLP_DELAY_TMO;
671 spin_unlock_irq(shost->host_lock);
672 ndlp->nlp_last_elscmd = ELS_CMD_FDISC;
673 vport->port_state = LPFC_FDISC;
675 spin_lock_irq(shost->host_lock);
676 phba->pport->fc_flag &= ~FC_LOGO_RCVD_DID_CHNG;
677 spin_unlock_irq(shost->host_lock);
678 lpfc_retry_pport_discovery(phba);
680 } else if ((!(ndlp->nlp_type & NLP_FABRIC) &&
681 ((ndlp->nlp_type & NLP_FCP_TARGET) ||
682 !(ndlp->nlp_type & NLP_FCP_INITIATOR))) ||
683 (ndlp->nlp_state == NLP_STE_ADISC_ISSUE)) {
684 /* Only try to re-login if this is NOT a Fabric Node */
685 mod_timer(&ndlp->nlp_delayfunc,
686 jiffies + msecs_to_jiffies(1000 * 1));
687 spin_lock_irq(shost->host_lock);
688 ndlp->nlp_flag |= NLP_DELAY_TMO;
689 spin_unlock_irq(shost->host_lock);
691 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
694 ndlp->nlp_prev_state = ndlp->nlp_state;
695 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
697 spin_lock_irq(shost->host_lock);
698 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
699 spin_unlock_irq(shost->host_lock);
700 /* The driver has to wait until the ACC completes before it continues
701 * processing the LOGO. The action will resume in
702 * lpfc_cmpl_els_logo_acc routine. Since part of processing includes an
703 * unreg_login, the driver waits so the ACC does not get aborted.
709 lpfc_rcv_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
710 struct lpfc_iocbq *cmdiocb)
712 struct lpfc_dmabuf *pcmd;
715 struct fc_rport *rport = ndlp->rport;
718 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
719 lp = (uint32_t *) pcmd->virt;
720 npr = (PRLI *) ((uint8_t *) lp + sizeof (uint32_t));
722 ndlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR);
723 ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
724 ndlp->nlp_flag &= ~NLP_FIRSTBURST;
725 if (npr->prliType == PRLI_FCP_TYPE) {
726 if (npr->initiatorFunc)
727 ndlp->nlp_type |= NLP_FCP_INITIATOR;
728 if (npr->targetFunc) {
729 ndlp->nlp_type |= NLP_FCP_TARGET;
730 if (npr->writeXferRdyDis)
731 ndlp->nlp_flag |= NLP_FIRSTBURST;
734 ndlp->nlp_fcp_info |= NLP_FCP_2_DEVICE;
737 /* We need to update the rport role values */
738 roles = FC_RPORT_ROLE_UNKNOWN;
739 if (ndlp->nlp_type & NLP_FCP_INITIATOR)
740 roles |= FC_RPORT_ROLE_FCP_INITIATOR;
741 if (ndlp->nlp_type & NLP_FCP_TARGET)
742 roles |= FC_RPORT_ROLE_FCP_TARGET;
744 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
745 "rport rolechg: role:x%x did:x%x flg:x%x",
746 roles, ndlp->nlp_DID, ndlp->nlp_flag);
748 fc_remote_port_rolechg(rport, roles);
753 lpfc_disc_set_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
755 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
757 if (!(ndlp->nlp_flag & NLP_RPI_REGISTERED)) {
758 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
762 if (!(vport->fc_flag & FC_PT2PT)) {
763 /* Check config parameter use-adisc or FCP-2 */
764 if (vport->cfg_use_adisc && ((vport->fc_flag & FC_RSCN_MODE) ||
765 ((ndlp->nlp_fcp_info & NLP_FCP_2_DEVICE) &&
766 (ndlp->nlp_type & NLP_FCP_TARGET)))) {
767 spin_lock_irq(shost->host_lock);
768 ndlp->nlp_flag |= NLP_NPR_ADISC;
769 spin_unlock_irq(shost->host_lock);
773 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
774 lpfc_unreg_rpi(vport, ndlp);
779 * lpfc_release_rpi - Release a RPI by issuing unreg_login mailbox cmd.
780 * @phba : Pointer to lpfc_hba structure.
781 * @vport: Pointer to lpfc_vport structure.
782 * @rpi : rpi to be release.
784 * This function will send a unreg_login mailbox command to the firmware
788 lpfc_release_rpi(struct lpfc_hba *phba,
789 struct lpfc_vport *vport,
795 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
798 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
799 "2796 mailbox memory allocation failed \n");
801 lpfc_unreg_login(phba, vport->vpi, rpi, pmb);
802 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
803 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
804 if (rc == MBX_NOT_FINISHED)
805 mempool_free(pmb, phba->mbox_mem_pool);
810 lpfc_disc_illegal(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
811 void *arg, uint32_t evt)
813 struct lpfc_hba *phba;
814 LPFC_MBOXQ_t *pmb = (LPFC_MBOXQ_t *) arg;
818 /* Release the RPI if reglogin completing */
819 if (!(phba->pport->load_flag & FC_UNLOADING) &&
820 (evt == NLP_EVT_CMPL_REG_LOGIN) &&
821 (!pmb->u.mb.mbxStatus)) {
822 rpi = pmb->u.mb.un.varWords[0];
823 lpfc_release_rpi(phba, vport, rpi);
825 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
826 "0271 Illegal State Transition: node x%x "
827 "event x%x, state x%x Data: x%x x%x\n",
828 ndlp->nlp_DID, evt, ndlp->nlp_state, ndlp->nlp_rpi,
830 return ndlp->nlp_state;
834 lpfc_cmpl_plogi_illegal(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
835 void *arg, uint32_t evt)
837 /* This transition is only legal if we previously
838 * rcv'ed a PLOGI. Since we don't want 2 discovery threads
839 * working on the same NPortID, do nothing for this thread
842 if (!(ndlp->nlp_flag & NLP_RCV_PLOGI)) {
843 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
844 "0272 Illegal State Transition: node x%x "
845 "event x%x, state x%x Data: x%x x%x\n",
846 ndlp->nlp_DID, evt, ndlp->nlp_state, ndlp->nlp_rpi,
849 return ndlp->nlp_state;
852 /* Start of Discovery State Machine routines */
855 lpfc_rcv_plogi_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
856 void *arg, uint32_t evt)
858 struct lpfc_iocbq *cmdiocb;
860 cmdiocb = (struct lpfc_iocbq *) arg;
862 if (lpfc_rcv_plogi(vport, ndlp, cmdiocb)) {
863 return ndlp->nlp_state;
865 return NLP_STE_FREED_NODE;
869 lpfc_rcv_els_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
870 void *arg, uint32_t evt)
872 lpfc_issue_els_logo(vport, ndlp, 0);
873 return ndlp->nlp_state;
877 lpfc_rcv_logo_unused_node(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_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
883 spin_lock_irq(shost->host_lock);
884 ndlp->nlp_flag |= NLP_LOGO_ACC;
885 spin_unlock_irq(shost->host_lock);
886 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
888 return ndlp->nlp_state;
892 lpfc_cmpl_logo_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
893 void *arg, uint32_t evt)
895 return NLP_STE_FREED_NODE;
899 lpfc_device_rm_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
900 void *arg, uint32_t evt)
902 return NLP_STE_FREED_NODE;
906 lpfc_device_recov_unused_node(struct lpfc_vport *vport,
907 struct lpfc_nodelist *ndlp,
908 void *arg, uint32_t evt)
910 return ndlp->nlp_state;
914 lpfc_rcv_plogi_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
915 void *arg, uint32_t evt)
917 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
918 struct lpfc_hba *phba = vport->phba;
919 struct lpfc_iocbq *cmdiocb = arg;
920 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
921 uint32_t *lp = (uint32_t *) pcmd->virt;
922 struct serv_parm *sp = (struct serv_parm *) (lp + 1);
926 memset(&stat, 0, sizeof (struct ls_rjt));
928 /* For a PLOGI, we only accept if our portname is less
929 * than the remote portname.
931 phba->fc_stat.elsLogiCol++;
932 port_cmp = memcmp(&vport->fc_portname, &sp->portName,
933 sizeof(struct lpfc_name));
936 /* Reject this request because the remote node will accept
938 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
939 stat.un.b.lsRjtRsnCodeExp = LSEXP_CMD_IN_PROGRESS;
940 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
943 if (lpfc_rcv_plogi(vport, ndlp, cmdiocb) &&
944 (ndlp->nlp_flag & NLP_NPR_2B_DISC) &&
945 (vport->num_disc_nodes)) {
946 spin_lock_irq(shost->host_lock);
947 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
948 spin_unlock_irq(shost->host_lock);
949 /* Check if there are more PLOGIs to be sent */
950 lpfc_more_plogi(vport);
951 if (vport->num_disc_nodes == 0) {
952 spin_lock_irq(shost->host_lock);
953 vport->fc_flag &= ~FC_NDISC_ACTIVE;
954 spin_unlock_irq(shost->host_lock);
955 lpfc_can_disctmo(vport);
956 lpfc_end_rscn(vport);
959 } /* If our portname was less */
961 return ndlp->nlp_state;
965 lpfc_rcv_prli_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
966 void *arg, uint32_t evt)
968 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
971 memset(&stat, 0, sizeof (struct ls_rjt));
972 stat.un.b.lsRjtRsnCode = LSRJT_LOGICAL_BSY;
973 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
974 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
975 return ndlp->nlp_state;
979 lpfc_rcv_logo_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
980 void *arg, uint32_t evt)
982 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
984 /* software abort outstanding PLOGI */
985 lpfc_els_abort(vport->phba, ndlp);
987 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
988 return ndlp->nlp_state;
992 lpfc_rcv_els_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
993 void *arg, uint32_t evt)
995 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
996 struct lpfc_hba *phba = vport->phba;
997 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
999 /* software abort outstanding PLOGI */
1000 lpfc_els_abort(phba, ndlp);
1002 if (evt == NLP_EVT_RCV_LOGO) {
1003 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
1005 lpfc_issue_els_logo(vport, ndlp, 0);
1008 /* Put ndlp in npr state set plogi timer for 1 sec */
1009 mod_timer(&ndlp->nlp_delayfunc, jiffies + msecs_to_jiffies(1000 * 1));
1010 spin_lock_irq(shost->host_lock);
1011 ndlp->nlp_flag |= NLP_DELAY_TMO;
1012 spin_unlock_irq(shost->host_lock);
1013 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
1014 ndlp->nlp_prev_state = NLP_STE_PLOGI_ISSUE;
1015 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1017 return ndlp->nlp_state;
1021 lpfc_cmpl_plogi_plogi_issue(struct lpfc_vport *vport,
1022 struct lpfc_nodelist *ndlp,
1026 struct lpfc_hba *phba = vport->phba;
1027 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1028 struct lpfc_iocbq *cmdiocb, *rspiocb;
1029 struct lpfc_dmabuf *pcmd, *prsp, *mp;
1032 struct serv_parm *sp;
1037 cmdiocb = (struct lpfc_iocbq *) arg;
1038 rspiocb = cmdiocb->context_un.rsp_iocb;
1040 if (ndlp->nlp_flag & NLP_ACC_REGLOGIN) {
1041 /* Recovery from PLOGI collision logic */
1042 return ndlp->nlp_state;
1045 irsp = &rspiocb->iocb;
1047 if (irsp->ulpStatus)
1050 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
1052 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
1056 lp = (uint32_t *) prsp->virt;
1057 sp = (struct serv_parm *) ((uint8_t *) lp + sizeof (uint32_t));
1059 /* Some switches have FDMI servers returning 0 for WWN */
1060 if ((ndlp->nlp_DID != FDMI_DID) &&
1061 (wwn_to_u64(sp->portName.u.wwn) == 0 ||
1062 wwn_to_u64(sp->nodeName.u.wwn) == 0)) {
1063 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1064 "0142 PLOGI RSP: Invalid WWN.\n");
1067 if (!lpfc_check_sparm(vport, ndlp, sp, CLASS3, 0))
1069 /* PLOGI chkparm OK */
1070 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1071 "0121 PLOGI chkparm OK Data: x%x x%x x%x x%x\n",
1072 ndlp->nlp_DID, ndlp->nlp_state,
1073 ndlp->nlp_flag, ndlp->nlp_rpi);
1074 if (vport->cfg_fcp_class == 2 && (sp->cls2.classValid))
1075 ndlp->nlp_fcp_info |= CLASS2;
1077 ndlp->nlp_fcp_info |= CLASS3;
1079 ndlp->nlp_class_sup = 0;
1080 if (sp->cls1.classValid)
1081 ndlp->nlp_class_sup |= FC_COS_CLASS1;
1082 if (sp->cls2.classValid)
1083 ndlp->nlp_class_sup |= FC_COS_CLASS2;
1084 if (sp->cls3.classValid)
1085 ndlp->nlp_class_sup |= FC_COS_CLASS3;
1086 if (sp->cls4.classValid)
1087 ndlp->nlp_class_sup |= FC_COS_CLASS4;
1088 ndlp->nlp_maxframe =
1089 ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) | sp->cmn.bbRcvSizeLsb;
1091 if ((vport->fc_flag & FC_PT2PT) &&
1092 (vport->fc_flag & FC_PT2PT_PLOGI)) {
1093 ed_tov = be32_to_cpu(sp->cmn.e_d_tov);
1094 if (sp->cmn.edtovResolution) {
1095 /* E_D_TOV ticks are in nanoseconds */
1096 ed_tov = (phba->fc_edtov + 999999) / 1000000;
1100 * Use the larger EDTOV
1101 * RATOV = 2 * EDTOV for pt-to-pt
1103 if (ed_tov > phba->fc_edtov)
1104 phba->fc_edtov = ed_tov;
1105 phba->fc_ratov = (2 * phba->fc_edtov) / 1000;
1107 memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
1109 /* Issue config_link / reg_vfi to account for updated TOV's */
1110 if (phba->sli_rev == LPFC_SLI_REV4) {
1111 lpfc_issue_reg_vfi(vport);
1113 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1115 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1116 "0133 PLOGI: no memory "
1118 "Data: x%x x%x x%x x%x\n",
1119 ndlp->nlp_DID, ndlp->nlp_state,
1120 ndlp->nlp_flag, ndlp->nlp_rpi);
1124 lpfc_config_link(phba, mbox);
1126 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1127 mbox->vport = vport;
1128 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
1129 if (rc == MBX_NOT_FINISHED) {
1130 mempool_free(mbox, phba->mbox_mem_pool);
1136 lpfc_unreg_rpi(vport, ndlp);
1138 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1140 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1141 "0018 PLOGI: no memory for reg_login "
1142 "Data: x%x x%x x%x x%x\n",
1143 ndlp->nlp_DID, ndlp->nlp_state,
1144 ndlp->nlp_flag, ndlp->nlp_rpi);
1148 if (lpfc_reg_rpi(phba, vport->vpi, irsp->un.elsreq64.remoteID,
1149 (uint8_t *) sp, mbox, ndlp->nlp_rpi) == 0) {
1150 switch (ndlp->nlp_DID) {
1151 case NameServer_DID:
1152 mbox->mbox_cmpl = lpfc_mbx_cmpl_ns_reg_login;
1155 mbox->mbox_cmpl = lpfc_mbx_cmpl_fdmi_reg_login;
1158 ndlp->nlp_flag |= NLP_REG_LOGIN_SEND;
1159 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
1161 mbox->context2 = lpfc_nlp_get(ndlp);
1162 mbox->vport = vport;
1163 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
1164 != MBX_NOT_FINISHED) {
1165 lpfc_nlp_set_state(vport, ndlp,
1166 NLP_STE_REG_LOGIN_ISSUE);
1167 return ndlp->nlp_state;
1169 if (ndlp->nlp_flag & NLP_REG_LOGIN_SEND)
1170 ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND;
1171 /* decrement node reference count to the failed mbox
1175 mp = (struct lpfc_dmabuf *) mbox->context1;
1176 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1178 mempool_free(mbox, phba->mbox_mem_pool);
1180 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1181 "0134 PLOGI: cannot issue reg_login "
1182 "Data: x%x x%x x%x x%x\n",
1183 ndlp->nlp_DID, ndlp->nlp_state,
1184 ndlp->nlp_flag, ndlp->nlp_rpi);
1186 mempool_free(mbox, phba->mbox_mem_pool);
1188 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1189 "0135 PLOGI: cannot format reg_login "
1190 "Data: x%x x%x x%x x%x\n",
1191 ndlp->nlp_DID, ndlp->nlp_state,
1192 ndlp->nlp_flag, ndlp->nlp_rpi);
1197 if (ndlp->nlp_DID == NameServer_DID) {
1198 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
1199 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1200 "0261 Cannot Register NameServer login\n");
1204 ** In case the node reference counter does not go to zero, ensure that
1205 ** the stale state for the node is not processed.
1208 ndlp->nlp_prev_state = ndlp->nlp_state;
1209 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1210 spin_lock_irq(shost->host_lock);
1211 ndlp->nlp_flag |= NLP_DEFER_RM;
1212 spin_unlock_irq(shost->host_lock);
1213 return NLP_STE_FREED_NODE;
1217 lpfc_cmpl_logo_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1218 void *arg, uint32_t evt)
1220 return ndlp->nlp_state;
1224 lpfc_cmpl_reglogin_plogi_issue(struct lpfc_vport *vport,
1225 struct lpfc_nodelist *ndlp, void *arg, uint32_t evt)
1227 struct lpfc_hba *phba;
1228 LPFC_MBOXQ_t *pmb = (LPFC_MBOXQ_t *) arg;
1229 MAILBOX_t *mb = &pmb->u.mb;
1233 /* Release the RPI */
1234 if (!(phba->pport->load_flag & FC_UNLOADING) &&
1236 rpi = pmb->u.mb.un.varWords[0];
1237 lpfc_release_rpi(phba, vport, rpi);
1239 return ndlp->nlp_state;
1243 lpfc_device_rm_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1244 void *arg, uint32_t evt)
1246 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1248 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1249 spin_lock_irq(shost->host_lock);
1250 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
1251 spin_unlock_irq(shost->host_lock);
1252 return ndlp->nlp_state;
1254 /* software abort outstanding PLOGI */
1255 lpfc_els_abort(vport->phba, ndlp);
1257 lpfc_drop_node(vport, ndlp);
1258 return NLP_STE_FREED_NODE;
1263 lpfc_device_recov_plogi_issue(struct lpfc_vport *vport,
1264 struct lpfc_nodelist *ndlp,
1268 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1269 struct lpfc_hba *phba = vport->phba;
1271 /* Don't do anything that will mess up processing of the
1274 if (vport->fc_flag & FC_RSCN_DEFERRED)
1275 return ndlp->nlp_state;
1277 /* software abort outstanding PLOGI */
1278 lpfc_els_abort(phba, ndlp);
1280 ndlp->nlp_prev_state = NLP_STE_PLOGI_ISSUE;
1281 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1282 spin_lock_irq(shost->host_lock);
1283 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
1284 spin_unlock_irq(shost->host_lock);
1286 return ndlp->nlp_state;
1290 lpfc_rcv_plogi_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1291 void *arg, uint32_t evt)
1293 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1294 struct lpfc_hba *phba = vport->phba;
1295 struct lpfc_iocbq *cmdiocb;
1297 /* software abort outstanding ADISC */
1298 lpfc_els_abort(phba, ndlp);
1300 cmdiocb = (struct lpfc_iocbq *) arg;
1302 if (lpfc_rcv_plogi(vport, ndlp, cmdiocb)) {
1303 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1304 spin_lock_irq(shost->host_lock);
1305 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
1306 spin_unlock_irq(shost->host_lock);
1307 if (vport->num_disc_nodes)
1308 lpfc_more_adisc(vport);
1310 return ndlp->nlp_state;
1312 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
1313 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
1314 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
1316 return ndlp->nlp_state;
1320 lpfc_rcv_prli_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1321 void *arg, uint32_t evt)
1323 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1325 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
1326 return ndlp->nlp_state;
1330 lpfc_rcv_logo_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1331 void *arg, uint32_t evt)
1333 struct lpfc_hba *phba = vport->phba;
1334 struct lpfc_iocbq *cmdiocb;
1336 cmdiocb = (struct lpfc_iocbq *) arg;
1338 /* software abort outstanding ADISC */
1339 lpfc_els_abort(phba, ndlp);
1341 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
1342 return ndlp->nlp_state;
1346 lpfc_rcv_padisc_adisc_issue(struct lpfc_vport *vport,
1347 struct lpfc_nodelist *ndlp,
1348 void *arg, uint32_t evt)
1350 struct lpfc_iocbq *cmdiocb;
1352 cmdiocb = (struct lpfc_iocbq *) arg;
1354 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
1355 return ndlp->nlp_state;
1359 lpfc_rcv_prlo_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1360 void *arg, uint32_t evt)
1362 struct lpfc_iocbq *cmdiocb;
1364 cmdiocb = (struct lpfc_iocbq *) arg;
1366 /* Treat like rcv logo */
1367 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_PRLO);
1368 return ndlp->nlp_state;
1372 lpfc_cmpl_adisc_adisc_issue(struct lpfc_vport *vport,
1373 struct lpfc_nodelist *ndlp,
1374 void *arg, uint32_t evt)
1376 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1377 struct lpfc_hba *phba = vport->phba;
1378 struct lpfc_iocbq *cmdiocb, *rspiocb;
1383 cmdiocb = (struct lpfc_iocbq *) arg;
1384 rspiocb = cmdiocb->context_un.rsp_iocb;
1386 ap = (ADISC *)lpfc_check_elscmpl_iocb(phba, cmdiocb, rspiocb);
1387 irsp = &rspiocb->iocb;
1389 if ((irsp->ulpStatus) ||
1390 (!lpfc_check_adisc(vport, ndlp, &ap->nodeName, &ap->portName))) {
1392 mod_timer(&ndlp->nlp_delayfunc,
1393 jiffies + msecs_to_jiffies(1000));
1394 spin_lock_irq(shost->host_lock);
1395 ndlp->nlp_flag |= NLP_DELAY_TMO;
1396 spin_unlock_irq(shost->host_lock);
1397 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
1399 memset(&ndlp->nlp_nodename, 0, sizeof(struct lpfc_name));
1400 memset(&ndlp->nlp_portname, 0, sizeof(struct lpfc_name));
1402 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
1403 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1404 lpfc_unreg_rpi(vport, ndlp);
1405 return ndlp->nlp_state;
1408 if (phba->sli_rev == LPFC_SLI_REV4) {
1409 rc = lpfc_sli4_resume_rpi(ndlp, NULL, NULL);
1411 /* Stay in state and retry. */
1412 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
1413 return ndlp->nlp_state;
1417 if (ndlp->nlp_type & NLP_FCP_TARGET) {
1418 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
1419 lpfc_nlp_set_state(vport, ndlp, NLP_STE_MAPPED_NODE);
1421 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
1422 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
1425 return ndlp->nlp_state;
1429 lpfc_device_rm_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1430 void *arg, uint32_t evt)
1432 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1434 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1435 spin_lock_irq(shost->host_lock);
1436 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
1437 spin_unlock_irq(shost->host_lock);
1438 return ndlp->nlp_state;
1440 /* software abort outstanding ADISC */
1441 lpfc_els_abort(vport->phba, ndlp);
1443 lpfc_drop_node(vport, ndlp);
1444 return NLP_STE_FREED_NODE;
1449 lpfc_device_recov_adisc_issue(struct lpfc_vport *vport,
1450 struct lpfc_nodelist *ndlp,
1454 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1455 struct lpfc_hba *phba = vport->phba;
1457 /* Don't do anything that will mess up processing of the
1460 if (vport->fc_flag & FC_RSCN_DEFERRED)
1461 return ndlp->nlp_state;
1463 /* software abort outstanding ADISC */
1464 lpfc_els_abort(phba, ndlp);
1466 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
1467 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1468 spin_lock_irq(shost->host_lock);
1469 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
1470 spin_unlock_irq(shost->host_lock);
1471 lpfc_disc_set_adisc(vport, ndlp);
1472 return ndlp->nlp_state;
1476 lpfc_rcv_plogi_reglogin_issue(struct lpfc_vport *vport,
1477 struct lpfc_nodelist *ndlp,
1481 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1483 lpfc_rcv_plogi(vport, ndlp, cmdiocb);
1484 return ndlp->nlp_state;
1488 lpfc_rcv_prli_reglogin_issue(struct lpfc_vport *vport,
1489 struct lpfc_nodelist *ndlp,
1493 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1495 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
1496 return ndlp->nlp_state;
1500 lpfc_rcv_logo_reglogin_issue(struct lpfc_vport *vport,
1501 struct lpfc_nodelist *ndlp,
1505 struct lpfc_hba *phba = vport->phba;
1506 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1508 LPFC_MBOXQ_t *nextmb;
1509 struct lpfc_dmabuf *mp;
1511 cmdiocb = (struct lpfc_iocbq *) arg;
1513 /* cleanup any ndlp on mbox q waiting for reglogin cmpl */
1514 if ((mb = phba->sli.mbox_active)) {
1515 if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) &&
1516 (ndlp == (struct lpfc_nodelist *) mb->context2)) {
1517 ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND;
1519 mb->context2 = NULL;
1520 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1524 spin_lock_irq(&phba->hbalock);
1525 list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) {
1526 if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) &&
1527 (ndlp == (struct lpfc_nodelist *) mb->context2)) {
1528 mp = (struct lpfc_dmabuf *) (mb->context1);
1530 __lpfc_mbuf_free(phba, mp->virt, mp->phys);
1533 ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND;
1535 list_del(&mb->list);
1536 phba->sli.mboxq_cnt--;
1537 mempool_free(mb, phba->mbox_mem_pool);
1540 spin_unlock_irq(&phba->hbalock);
1542 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
1543 return ndlp->nlp_state;
1547 lpfc_rcv_padisc_reglogin_issue(struct lpfc_vport *vport,
1548 struct lpfc_nodelist *ndlp,
1552 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1554 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
1555 return ndlp->nlp_state;
1559 lpfc_rcv_prlo_reglogin_issue(struct lpfc_vport *vport,
1560 struct lpfc_nodelist *ndlp,
1564 struct lpfc_iocbq *cmdiocb;
1566 cmdiocb = (struct lpfc_iocbq *) arg;
1567 lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL);
1568 return ndlp->nlp_state;
1572 lpfc_cmpl_reglogin_reglogin_issue(struct lpfc_vport *vport,
1573 struct lpfc_nodelist *ndlp,
1577 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1578 LPFC_MBOXQ_t *pmb = (LPFC_MBOXQ_t *) arg;
1579 MAILBOX_t *mb = &pmb->u.mb;
1580 uint32_t did = mb->un.varWords[1];
1582 if (mb->mbxStatus) {
1583 /* RegLogin failed */
1584 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
1585 "0246 RegLogin failed Data: x%x x%x x%x x%x "
1587 did, mb->mbxStatus, vport->port_state,
1588 mb->un.varRegLogin.vpi,
1589 mb->un.varRegLogin.rpi);
1591 * If RegLogin failed due to lack of HBA resources do not
1594 if (mb->mbxStatus == MBXERR_RPI_FULL) {
1595 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
1596 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1597 return ndlp->nlp_state;
1600 /* Put ndlp in npr state set plogi timer for 1 sec */
1601 mod_timer(&ndlp->nlp_delayfunc,
1602 jiffies + msecs_to_jiffies(1000 * 1));
1603 spin_lock_irq(shost->host_lock);
1604 ndlp->nlp_flag |= NLP_DELAY_TMO;
1605 spin_unlock_irq(shost->host_lock);
1606 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
1608 lpfc_issue_els_logo(vport, ndlp, 0);
1609 return ndlp->nlp_state;
1612 /* SLI4 ports have preallocated logical rpis. */
1613 if (vport->phba->sli_rev < LPFC_SLI_REV4)
1614 ndlp->nlp_rpi = mb->un.varWords[0];
1616 ndlp->nlp_flag |= NLP_RPI_REGISTERED;
1618 /* Only if we are not a fabric nport do we issue PRLI */
1619 if (!(ndlp->nlp_type & NLP_FABRIC)) {
1620 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
1621 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
1622 lpfc_issue_els_prli(vport, ndlp, 0);
1624 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
1625 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
1627 return ndlp->nlp_state;
1631 lpfc_device_rm_reglogin_issue(struct lpfc_vport *vport,
1632 struct lpfc_nodelist *ndlp,
1636 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1638 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1639 spin_lock_irq(shost->host_lock);
1640 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
1641 spin_unlock_irq(shost->host_lock);
1642 return ndlp->nlp_state;
1644 lpfc_drop_node(vport, ndlp);
1645 return NLP_STE_FREED_NODE;
1650 lpfc_device_recov_reglogin_issue(struct lpfc_vport *vport,
1651 struct lpfc_nodelist *ndlp,
1655 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1657 /* Don't do anything that will mess up processing of the
1660 if (vport->fc_flag & FC_RSCN_DEFERRED)
1661 return ndlp->nlp_state;
1663 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
1664 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1665 spin_lock_irq(shost->host_lock);
1666 ndlp->nlp_flag |= NLP_IGNR_REG_CMPL;
1667 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
1668 spin_unlock_irq(shost->host_lock);
1669 lpfc_disc_set_adisc(vport, ndlp);
1670 return ndlp->nlp_state;
1674 lpfc_rcv_plogi_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1675 void *arg, uint32_t evt)
1677 struct lpfc_iocbq *cmdiocb;
1679 cmdiocb = (struct lpfc_iocbq *) arg;
1681 lpfc_rcv_plogi(vport, ndlp, cmdiocb);
1682 return ndlp->nlp_state;
1686 lpfc_rcv_prli_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1687 void *arg, uint32_t evt)
1689 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1691 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
1692 return ndlp->nlp_state;
1696 lpfc_rcv_logo_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1697 void *arg, uint32_t evt)
1699 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1701 /* Software abort outstanding PRLI before sending acc */
1702 lpfc_els_abort(vport->phba, ndlp);
1704 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
1705 return ndlp->nlp_state;
1709 lpfc_rcv_padisc_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1710 void *arg, uint32_t evt)
1712 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1714 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
1715 return ndlp->nlp_state;
1718 /* This routine is envoked when we rcv a PRLO request from a nport
1719 * we are logged into. We should send back a PRLO rsp setting the
1721 * NEXT STATE = PRLI_ISSUE
1724 lpfc_rcv_prlo_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1725 void *arg, uint32_t evt)
1727 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1729 lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL);
1730 return ndlp->nlp_state;
1734 lpfc_cmpl_prli_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1735 void *arg, uint32_t evt)
1737 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1738 struct lpfc_iocbq *cmdiocb, *rspiocb;
1739 struct lpfc_hba *phba = vport->phba;
1743 cmdiocb = (struct lpfc_iocbq *) arg;
1744 rspiocb = cmdiocb->context_un.rsp_iocb;
1745 npr = (PRLI *)lpfc_check_elscmpl_iocb(phba, cmdiocb, rspiocb);
1747 irsp = &rspiocb->iocb;
1748 if (irsp->ulpStatus) {
1749 if ((vport->port_type == LPFC_NPIV_PORT) &&
1750 vport->cfg_restrict_login) {
1753 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
1754 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
1755 return ndlp->nlp_state;
1758 /* Check out PRLI rsp */
1759 ndlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR);
1760 ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
1761 ndlp->nlp_flag &= ~NLP_FIRSTBURST;
1762 if ((npr->acceptRspCode == PRLI_REQ_EXECUTED) &&
1763 (npr->prliType == PRLI_FCP_TYPE)) {
1764 if (npr->initiatorFunc)
1765 ndlp->nlp_type |= NLP_FCP_INITIATOR;
1766 if (npr->targetFunc) {
1767 ndlp->nlp_type |= NLP_FCP_TARGET;
1768 if (npr->writeXferRdyDis)
1769 ndlp->nlp_flag |= NLP_FIRSTBURST;
1772 ndlp->nlp_fcp_info |= NLP_FCP_2_DEVICE;
1774 if (!(ndlp->nlp_type & NLP_FCP_TARGET) &&
1775 (vport->port_type == LPFC_NPIV_PORT) &&
1776 vport->cfg_restrict_login) {
1778 spin_lock_irq(shost->host_lock);
1779 ndlp->nlp_flag |= NLP_TARGET_REMOVE;
1780 spin_unlock_irq(shost->host_lock);
1781 lpfc_issue_els_logo(vport, ndlp, 0);
1783 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
1784 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1785 return ndlp->nlp_state;
1788 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
1789 if (ndlp->nlp_type & NLP_FCP_TARGET)
1790 lpfc_nlp_set_state(vport, ndlp, NLP_STE_MAPPED_NODE);
1792 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
1793 return ndlp->nlp_state;
1796 /*! lpfc_device_rm_prli_issue
1807 * This routine is envoked when we a request to remove a nport we are in the
1808 * process of PRLIing. We should software abort outstanding prli, unreg
1809 * login, send a logout. We will change node state to UNUSED_NODE, put it
1810 * on plogi list so it can be freed when LOGO completes.
1815 lpfc_device_rm_prli_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);
1820 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1821 spin_lock_irq(shost->host_lock);
1822 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
1823 spin_unlock_irq(shost->host_lock);
1824 return ndlp->nlp_state;
1826 /* software abort outstanding PLOGI */
1827 lpfc_els_abort(vport->phba, ndlp);
1829 lpfc_drop_node(vport, ndlp);
1830 return NLP_STE_FREED_NODE;
1835 /*! lpfc_device_recov_prli_issue
1846 * The routine is envoked when the state of a device is unknown, like
1847 * during a link down. We should remove the nodelist entry from the
1848 * unmapped list, issue a UNREG_LOGIN, do a software abort of the
1849 * outstanding PRLI command, then free the node entry.
1852 lpfc_device_recov_prli_issue(struct lpfc_vport *vport,
1853 struct lpfc_nodelist *ndlp,
1857 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1858 struct lpfc_hba *phba = vport->phba;
1860 /* Don't do anything that will mess up processing of the
1863 if (vport->fc_flag & FC_RSCN_DEFERRED)
1864 return ndlp->nlp_state;
1866 /* software abort outstanding PRLI */
1867 lpfc_els_abort(phba, ndlp);
1869 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
1870 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1871 spin_lock_irq(shost->host_lock);
1872 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
1873 spin_unlock_irq(shost->host_lock);
1874 lpfc_disc_set_adisc(vport, ndlp);
1875 return ndlp->nlp_state;
1879 lpfc_rcv_plogi_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1880 void *arg, uint32_t evt)
1882 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *)arg;
1885 memset(&stat, 0, sizeof(struct ls_rjt));
1886 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
1887 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
1888 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
1889 return ndlp->nlp_state;
1893 lpfc_rcv_prli_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1894 void *arg, uint32_t evt)
1896 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *)arg;
1899 memset(&stat, 0, sizeof(struct ls_rjt));
1900 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
1901 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
1902 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
1903 return ndlp->nlp_state;
1907 lpfc_rcv_logo_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1908 void *arg, uint32_t evt)
1910 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1911 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *)arg;
1913 spin_lock_irq(shost->host_lock);
1914 ndlp->nlp_flag |= NLP_LOGO_ACC;
1915 spin_unlock_irq(shost->host_lock);
1916 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
1917 return ndlp->nlp_state;
1921 lpfc_rcv_padisc_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1922 void *arg, uint32_t evt)
1924 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *)arg;
1927 memset(&stat, 0, sizeof(struct ls_rjt));
1928 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
1929 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
1930 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
1931 return ndlp->nlp_state;
1935 lpfc_rcv_prlo_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1936 void *arg, uint32_t evt)
1938 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *)arg;
1941 memset(&stat, 0, sizeof(struct ls_rjt));
1942 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
1943 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
1944 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
1945 return ndlp->nlp_state;
1949 lpfc_cmpl_logo_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1950 void *arg, uint32_t evt)
1952 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1954 ndlp->nlp_prev_state = NLP_STE_LOGO_ISSUE;
1955 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1956 spin_lock_irq(shost->host_lock);
1957 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
1958 spin_unlock_irq(shost->host_lock);
1959 lpfc_disc_set_adisc(vport, ndlp);
1960 return ndlp->nlp_state;
1964 lpfc_device_rm_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1965 void *arg, uint32_t evt)
1968 * Take no action. If a LOGO is outstanding, then possibly DevLoss has
1969 * timed out and is calling for Device Remove. In this case, the LOGO
1970 * must be allowed to complete in state LOGO_ISSUE so that the rpi
1971 * and other NLP flags are correctly cleaned up.
1973 return ndlp->nlp_state;
1977 lpfc_device_recov_logo_issue(struct lpfc_vport *vport,
1978 struct lpfc_nodelist *ndlp,
1979 void *arg, uint32_t evt)
1982 * Device Recovery events have no meaning for a node with a LOGO
1983 * outstanding. The LOGO has to complete first and handle the
1984 * node from that point.
1986 return ndlp->nlp_state;
1990 lpfc_rcv_plogi_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1991 void *arg, uint32_t evt)
1993 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1995 lpfc_rcv_plogi(vport, ndlp, cmdiocb);
1996 return ndlp->nlp_state;
2000 lpfc_rcv_prli_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2001 void *arg, uint32_t evt)
2003 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2005 lpfc_rcv_prli(vport, ndlp, cmdiocb);
2006 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
2007 return ndlp->nlp_state;
2011 lpfc_rcv_logo_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2012 void *arg, uint32_t evt)
2014 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2016 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
2017 return ndlp->nlp_state;
2021 lpfc_rcv_padisc_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2022 void *arg, uint32_t evt)
2024 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2026 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
2027 return ndlp->nlp_state;
2031 lpfc_rcv_prlo_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2032 void *arg, uint32_t evt)
2034 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2036 lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL);
2037 return ndlp->nlp_state;
2041 lpfc_device_recov_unmap_node(struct lpfc_vport *vport,
2042 struct lpfc_nodelist *ndlp,
2046 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2048 ndlp->nlp_prev_state = NLP_STE_UNMAPPED_NODE;
2049 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
2050 spin_lock_irq(shost->host_lock);
2051 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
2052 spin_unlock_irq(shost->host_lock);
2053 lpfc_disc_set_adisc(vport, ndlp);
2055 return ndlp->nlp_state;
2059 lpfc_rcv_plogi_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2060 void *arg, uint32_t evt)
2062 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2064 lpfc_rcv_plogi(vport, ndlp, cmdiocb);
2065 return ndlp->nlp_state;
2069 lpfc_rcv_prli_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2070 void *arg, uint32_t evt)
2072 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2074 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
2075 return ndlp->nlp_state;
2079 lpfc_rcv_logo_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2080 void *arg, uint32_t evt)
2082 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2084 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
2085 return ndlp->nlp_state;
2089 lpfc_rcv_padisc_mapped_node(struct lpfc_vport *vport,
2090 struct lpfc_nodelist *ndlp,
2091 void *arg, uint32_t evt)
2093 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2095 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
2096 return ndlp->nlp_state;
2100 lpfc_rcv_prlo_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2101 void *arg, uint32_t evt)
2103 struct lpfc_hba *phba = vport->phba;
2104 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2106 /* flush the target */
2107 lpfc_sli_abort_iocb(vport, &phba->sli.ring[phba->sli.fcp_ring],
2108 ndlp->nlp_sid, 0, LPFC_CTX_TGT);
2110 /* Treat like rcv logo */
2111 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_PRLO);
2112 return ndlp->nlp_state;
2116 lpfc_device_recov_mapped_node(struct lpfc_vport *vport,
2117 struct lpfc_nodelist *ndlp,
2121 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2123 ndlp->nlp_prev_state = NLP_STE_MAPPED_NODE;
2124 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
2125 spin_lock_irq(shost->host_lock);
2126 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
2127 spin_unlock_irq(shost->host_lock);
2128 lpfc_disc_set_adisc(vport, ndlp);
2129 return ndlp->nlp_state;
2133 lpfc_rcv_plogi_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2134 void *arg, uint32_t evt)
2136 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2137 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2139 /* Ignore PLOGI if we have an outstanding LOGO */
2140 if (ndlp->nlp_flag & (NLP_LOGO_SND | NLP_LOGO_ACC))
2141 return ndlp->nlp_state;
2142 if (lpfc_rcv_plogi(vport, ndlp, cmdiocb)) {
2143 lpfc_cancel_retry_delay_tmo(vport, ndlp);
2144 spin_lock_irq(shost->host_lock);
2145 ndlp->nlp_flag &= ~(NLP_NPR_ADISC | NLP_NPR_2B_DISC);
2146 spin_unlock_irq(shost->host_lock);
2147 } else if (!(ndlp->nlp_flag & NLP_NPR_2B_DISC)) {
2148 /* send PLOGI immediately, move to PLOGI issue state */
2149 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
2150 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
2151 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
2152 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
2155 return ndlp->nlp_state;
2159 lpfc_rcv_prli_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2160 void *arg, uint32_t evt)
2162 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2163 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2166 memset(&stat, 0, sizeof (struct ls_rjt));
2167 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
2168 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
2169 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
2171 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
2172 if (ndlp->nlp_flag & NLP_NPR_ADISC) {
2173 spin_lock_irq(shost->host_lock);
2174 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
2175 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
2176 spin_unlock_irq(shost->host_lock);
2177 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
2178 lpfc_issue_els_adisc(vport, ndlp, 0);
2180 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
2181 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
2182 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
2185 return ndlp->nlp_state;
2189 lpfc_rcv_logo_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2190 void *arg, uint32_t evt)
2192 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2194 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
2195 return ndlp->nlp_state;
2199 lpfc_rcv_padisc_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2200 void *arg, uint32_t evt)
2202 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2204 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
2206 * Do not start discovery if discovery is about to start
2207 * or discovery in progress for this node. Starting discovery
2208 * here will affect the counting of discovery threads.
2210 if (!(ndlp->nlp_flag & NLP_DELAY_TMO) &&
2211 !(ndlp->nlp_flag & NLP_NPR_2B_DISC)) {
2212 if (ndlp->nlp_flag & NLP_NPR_ADISC) {
2213 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
2214 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
2215 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
2216 lpfc_issue_els_adisc(vport, ndlp, 0);
2218 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
2219 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
2220 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
2223 return ndlp->nlp_state;
2227 lpfc_rcv_prlo_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2228 void *arg, uint32_t evt)
2230 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2231 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2233 spin_lock_irq(shost->host_lock);
2234 ndlp->nlp_flag |= NLP_LOGO_ACC;
2235 spin_unlock_irq(shost->host_lock);
2237 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
2239 if ((ndlp->nlp_flag & NLP_DELAY_TMO) == 0) {
2240 mod_timer(&ndlp->nlp_delayfunc,
2241 jiffies + msecs_to_jiffies(1000 * 1));
2242 spin_lock_irq(shost->host_lock);
2243 ndlp->nlp_flag |= NLP_DELAY_TMO;
2244 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
2245 spin_unlock_irq(shost->host_lock);
2246 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
2248 spin_lock_irq(shost->host_lock);
2249 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
2250 spin_unlock_irq(shost->host_lock);
2252 return ndlp->nlp_state;
2256 lpfc_cmpl_plogi_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2257 void *arg, uint32_t evt)
2259 struct lpfc_iocbq *cmdiocb, *rspiocb;
2261 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2263 cmdiocb = (struct lpfc_iocbq *) arg;
2264 rspiocb = cmdiocb->context_un.rsp_iocb;
2266 irsp = &rspiocb->iocb;
2267 if (irsp->ulpStatus) {
2268 spin_lock_irq(shost->host_lock);
2269 ndlp->nlp_flag |= NLP_DEFER_RM;
2270 spin_unlock_irq(shost->host_lock);
2271 return NLP_STE_FREED_NODE;
2273 return ndlp->nlp_state;
2277 lpfc_cmpl_prli_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2278 void *arg, uint32_t evt)
2280 struct lpfc_iocbq *cmdiocb, *rspiocb;
2283 cmdiocb = (struct lpfc_iocbq *) arg;
2284 rspiocb = cmdiocb->context_un.rsp_iocb;
2286 irsp = &rspiocb->iocb;
2287 if (irsp->ulpStatus && (ndlp->nlp_flag & NLP_NODEV_REMOVE)) {
2288 lpfc_drop_node(vport, ndlp);
2289 return NLP_STE_FREED_NODE;
2291 return ndlp->nlp_state;
2295 lpfc_cmpl_logo_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2296 void *arg, uint32_t evt)
2298 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2300 /* For the fabric port just clear the fc flags. */
2301 if (ndlp->nlp_DID == Fabric_DID) {
2302 spin_lock_irq(shost->host_lock);
2303 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
2304 spin_unlock_irq(shost->host_lock);
2306 lpfc_unreg_rpi(vport, ndlp);
2307 return ndlp->nlp_state;
2311 lpfc_cmpl_adisc_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2312 void *arg, uint32_t evt)
2314 struct lpfc_iocbq *cmdiocb, *rspiocb;
2317 cmdiocb = (struct lpfc_iocbq *) arg;
2318 rspiocb = cmdiocb->context_un.rsp_iocb;
2320 irsp = &rspiocb->iocb;
2321 if (irsp->ulpStatus && (ndlp->nlp_flag & NLP_NODEV_REMOVE)) {
2322 lpfc_drop_node(vport, ndlp);
2323 return NLP_STE_FREED_NODE;
2325 return ndlp->nlp_state;
2329 lpfc_cmpl_reglogin_npr_node(struct lpfc_vport *vport,
2330 struct lpfc_nodelist *ndlp,
2331 void *arg, uint32_t evt)
2333 LPFC_MBOXQ_t *pmb = (LPFC_MBOXQ_t *) arg;
2334 MAILBOX_t *mb = &pmb->u.mb;
2336 if (!mb->mbxStatus) {
2337 /* SLI4 ports have preallocated logical rpis. */
2338 if (vport->phba->sli_rev < LPFC_SLI_REV4)
2339 ndlp->nlp_rpi = mb->un.varWords[0];
2340 ndlp->nlp_flag |= NLP_RPI_REGISTERED;
2341 if (ndlp->nlp_flag & NLP_LOGO_ACC) {
2342 lpfc_unreg_rpi(vport, ndlp);
2345 if (ndlp->nlp_flag & NLP_NODEV_REMOVE) {
2346 lpfc_drop_node(vport, ndlp);
2347 return NLP_STE_FREED_NODE;
2350 return ndlp->nlp_state;
2354 lpfc_device_rm_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2355 void *arg, uint32_t evt)
2357 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2359 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
2360 spin_lock_irq(shost->host_lock);
2361 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
2362 spin_unlock_irq(shost->host_lock);
2363 return ndlp->nlp_state;
2365 lpfc_drop_node(vport, ndlp);
2366 return NLP_STE_FREED_NODE;
2370 lpfc_device_recov_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2371 void *arg, uint32_t evt)
2373 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2375 /* Don't do anything that will mess up processing of the
2378 if (vport->fc_flag & FC_RSCN_DEFERRED)
2379 return ndlp->nlp_state;
2381 lpfc_cancel_retry_delay_tmo(vport, ndlp);
2382 spin_lock_irq(shost->host_lock);
2383 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
2384 spin_unlock_irq(shost->host_lock);
2385 return ndlp->nlp_state;
2389 /* This next section defines the NPort Discovery State Machine */
2391 /* There are 4 different double linked lists nodelist entries can reside on.
2392 * The plogi list and adisc list are used when Link Up discovery or RSCN
2393 * processing is needed. Each list holds the nodes that we will send PLOGI
2394 * or ADISC on. These lists will keep track of what nodes will be effected
2395 * by an RSCN, or a Link Up (Typically, all nodes are effected on Link Up).
2396 * The unmapped_list will contain all nodes that we have successfully logged
2397 * into at the Fibre Channel level. The mapped_list will contain all nodes
2398 * that are mapped FCP targets.
2401 * The bind list is a list of undiscovered (potentially non-existent) nodes
2402 * that we have saved binding information on. This information is used when
2403 * nodes transition from the unmapped to the mapped list.
2405 /* For UNUSED_NODE state, the node has just been allocated .
2406 * For PLOGI_ISSUE and REG_LOGIN_ISSUE, the node is on
2407 * the PLOGI list. For REG_LOGIN_COMPL, the node is taken off the PLOGI list
2408 * and put on the unmapped list. For ADISC processing, the node is taken off
2409 * the ADISC list and placed on either the mapped or unmapped list (depending
2410 * on its previous state). Once on the unmapped list, a PRLI is issued and the
2411 * state changed to PRLI_ISSUE. When the PRLI completion occurs, the state is
2412 * changed to UNMAPPED_NODE. If the completion indicates a mapped
2413 * node, the node is taken off the unmapped list. The binding list is checked
2414 * for a valid binding, or a binding is automatically assigned. If binding
2415 * assignment is unsuccessful, the node is left on the unmapped list. If
2416 * binding assignment is successful, the associated binding list entry (if
2417 * any) is removed, and the node is placed on the mapped list.
2420 * For a Link Down, all nodes on the ADISC, PLOGI, unmapped or mapped
2421 * lists will receive a DEVICE_RECOVERY event. If the linkdown or devloss timers
2422 * expire, all effected nodes will receive a DEVICE_RM event.
2425 * For a Link Up or RSCN, all nodes will move from the mapped / unmapped lists
2426 * to either the ADISC or PLOGI list. After a Nameserver query or ALPA loopmap
2427 * check, additional nodes may be added or removed (via DEVICE_RM) to / from
2428 * the PLOGI or ADISC lists. Once the PLOGI and ADISC lists are populated,
2429 * we will first process the ADISC list. 32 entries are processed initially and
2430 * ADISC is initited for each one. Completions / Events for each node are
2431 * funnelled thru the state machine. As each node finishes ADISC processing, it
2432 * starts ADISC for any nodes waiting for ADISC processing. If no nodes are
2433 * waiting, and the ADISC list count is identically 0, then we are done. For
2434 * Link Up discovery, since all nodes on the PLOGI list are UNREG_LOGIN'ed, we
2435 * can issue a CLEAR_LA and reenable Link Events. Next we will process the PLOGI
2436 * list. 32 entries are processed initially and PLOGI is initited for each one.
2437 * Completions / Events for each node are funnelled thru the state machine. As
2438 * each node finishes PLOGI processing, it starts PLOGI for any nodes waiting
2439 * for PLOGI processing. If no nodes are waiting, and the PLOGI list count is
2440 * indentically 0, then we are done. We have now completed discovery / RSCN
2441 * handling. Upon completion, ALL nodes should be on either the mapped or
2445 static uint32_t (*lpfc_disc_action[NLP_STE_MAX_STATE * NLP_EVT_MAX_EVENT])
2446 (struct lpfc_vport *, struct lpfc_nodelist *, void *, uint32_t) = {
2447 /* Action routine Event Current State */
2448 lpfc_rcv_plogi_unused_node, /* RCV_PLOGI UNUSED_NODE */
2449 lpfc_rcv_els_unused_node, /* RCV_PRLI */
2450 lpfc_rcv_logo_unused_node, /* RCV_LOGO */
2451 lpfc_rcv_els_unused_node, /* RCV_ADISC */
2452 lpfc_rcv_els_unused_node, /* RCV_PDISC */
2453 lpfc_rcv_els_unused_node, /* RCV_PRLO */
2454 lpfc_disc_illegal, /* CMPL_PLOGI */
2455 lpfc_disc_illegal, /* CMPL_PRLI */
2456 lpfc_cmpl_logo_unused_node, /* CMPL_LOGO */
2457 lpfc_disc_illegal, /* CMPL_ADISC */
2458 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2459 lpfc_device_rm_unused_node, /* DEVICE_RM */
2460 lpfc_device_recov_unused_node, /* DEVICE_RECOVERY */
2462 lpfc_rcv_plogi_plogi_issue, /* RCV_PLOGI PLOGI_ISSUE */
2463 lpfc_rcv_prli_plogi_issue, /* RCV_PRLI */
2464 lpfc_rcv_logo_plogi_issue, /* RCV_LOGO */
2465 lpfc_rcv_els_plogi_issue, /* RCV_ADISC */
2466 lpfc_rcv_els_plogi_issue, /* RCV_PDISC */
2467 lpfc_rcv_els_plogi_issue, /* RCV_PRLO */
2468 lpfc_cmpl_plogi_plogi_issue, /* CMPL_PLOGI */
2469 lpfc_disc_illegal, /* CMPL_PRLI */
2470 lpfc_cmpl_logo_plogi_issue, /* CMPL_LOGO */
2471 lpfc_disc_illegal, /* CMPL_ADISC */
2472 lpfc_cmpl_reglogin_plogi_issue,/* CMPL_REG_LOGIN */
2473 lpfc_device_rm_plogi_issue, /* DEVICE_RM */
2474 lpfc_device_recov_plogi_issue, /* DEVICE_RECOVERY */
2476 lpfc_rcv_plogi_adisc_issue, /* RCV_PLOGI ADISC_ISSUE */
2477 lpfc_rcv_prli_adisc_issue, /* RCV_PRLI */
2478 lpfc_rcv_logo_adisc_issue, /* RCV_LOGO */
2479 lpfc_rcv_padisc_adisc_issue, /* RCV_ADISC */
2480 lpfc_rcv_padisc_adisc_issue, /* RCV_PDISC */
2481 lpfc_rcv_prlo_adisc_issue, /* RCV_PRLO */
2482 lpfc_disc_illegal, /* CMPL_PLOGI */
2483 lpfc_disc_illegal, /* CMPL_PRLI */
2484 lpfc_disc_illegal, /* CMPL_LOGO */
2485 lpfc_cmpl_adisc_adisc_issue, /* CMPL_ADISC */
2486 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2487 lpfc_device_rm_adisc_issue, /* DEVICE_RM */
2488 lpfc_device_recov_adisc_issue, /* DEVICE_RECOVERY */
2490 lpfc_rcv_plogi_reglogin_issue, /* RCV_PLOGI REG_LOGIN_ISSUE */
2491 lpfc_rcv_prli_reglogin_issue, /* RCV_PLOGI */
2492 lpfc_rcv_logo_reglogin_issue, /* RCV_LOGO */
2493 lpfc_rcv_padisc_reglogin_issue, /* RCV_ADISC */
2494 lpfc_rcv_padisc_reglogin_issue, /* RCV_PDISC */
2495 lpfc_rcv_prlo_reglogin_issue, /* RCV_PRLO */
2496 lpfc_cmpl_plogi_illegal, /* CMPL_PLOGI */
2497 lpfc_disc_illegal, /* CMPL_PRLI */
2498 lpfc_disc_illegal, /* CMPL_LOGO */
2499 lpfc_disc_illegal, /* CMPL_ADISC */
2500 lpfc_cmpl_reglogin_reglogin_issue,/* CMPL_REG_LOGIN */
2501 lpfc_device_rm_reglogin_issue, /* DEVICE_RM */
2502 lpfc_device_recov_reglogin_issue,/* DEVICE_RECOVERY */
2504 lpfc_rcv_plogi_prli_issue, /* RCV_PLOGI PRLI_ISSUE */
2505 lpfc_rcv_prli_prli_issue, /* RCV_PRLI */
2506 lpfc_rcv_logo_prli_issue, /* RCV_LOGO */
2507 lpfc_rcv_padisc_prli_issue, /* RCV_ADISC */
2508 lpfc_rcv_padisc_prli_issue, /* RCV_PDISC */
2509 lpfc_rcv_prlo_prli_issue, /* RCV_PRLO */
2510 lpfc_cmpl_plogi_illegal, /* CMPL_PLOGI */
2511 lpfc_cmpl_prli_prli_issue, /* CMPL_PRLI */
2512 lpfc_disc_illegal, /* CMPL_LOGO */
2513 lpfc_disc_illegal, /* CMPL_ADISC */
2514 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2515 lpfc_device_rm_prli_issue, /* DEVICE_RM */
2516 lpfc_device_recov_prli_issue, /* DEVICE_RECOVERY */
2518 lpfc_rcv_plogi_logo_issue, /* RCV_PLOGI LOGO_ISSUE */
2519 lpfc_rcv_prli_logo_issue, /* RCV_PRLI */
2520 lpfc_rcv_logo_logo_issue, /* RCV_LOGO */
2521 lpfc_rcv_padisc_logo_issue, /* RCV_ADISC */
2522 lpfc_rcv_padisc_logo_issue, /* RCV_PDISC */
2523 lpfc_rcv_prlo_logo_issue, /* RCV_PRLO */
2524 lpfc_cmpl_plogi_illegal, /* CMPL_PLOGI */
2525 lpfc_disc_illegal, /* CMPL_PRLI */
2526 lpfc_cmpl_logo_logo_issue, /* CMPL_LOGO */
2527 lpfc_disc_illegal, /* CMPL_ADISC */
2528 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2529 lpfc_device_rm_logo_issue, /* DEVICE_RM */
2530 lpfc_device_recov_logo_issue, /* DEVICE_RECOVERY */
2532 lpfc_rcv_plogi_unmap_node, /* RCV_PLOGI UNMAPPED_NODE */
2533 lpfc_rcv_prli_unmap_node, /* RCV_PRLI */
2534 lpfc_rcv_logo_unmap_node, /* RCV_LOGO */
2535 lpfc_rcv_padisc_unmap_node, /* RCV_ADISC */
2536 lpfc_rcv_padisc_unmap_node, /* RCV_PDISC */
2537 lpfc_rcv_prlo_unmap_node, /* RCV_PRLO */
2538 lpfc_disc_illegal, /* CMPL_PLOGI */
2539 lpfc_disc_illegal, /* CMPL_PRLI */
2540 lpfc_disc_illegal, /* CMPL_LOGO */
2541 lpfc_disc_illegal, /* CMPL_ADISC */
2542 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2543 lpfc_disc_illegal, /* DEVICE_RM */
2544 lpfc_device_recov_unmap_node, /* DEVICE_RECOVERY */
2546 lpfc_rcv_plogi_mapped_node, /* RCV_PLOGI MAPPED_NODE */
2547 lpfc_rcv_prli_mapped_node, /* RCV_PRLI */
2548 lpfc_rcv_logo_mapped_node, /* RCV_LOGO */
2549 lpfc_rcv_padisc_mapped_node, /* RCV_ADISC */
2550 lpfc_rcv_padisc_mapped_node, /* RCV_PDISC */
2551 lpfc_rcv_prlo_mapped_node, /* RCV_PRLO */
2552 lpfc_disc_illegal, /* CMPL_PLOGI */
2553 lpfc_disc_illegal, /* CMPL_PRLI */
2554 lpfc_disc_illegal, /* CMPL_LOGO */
2555 lpfc_disc_illegal, /* CMPL_ADISC */
2556 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2557 lpfc_disc_illegal, /* DEVICE_RM */
2558 lpfc_device_recov_mapped_node, /* DEVICE_RECOVERY */
2560 lpfc_rcv_plogi_npr_node, /* RCV_PLOGI NPR_NODE */
2561 lpfc_rcv_prli_npr_node, /* RCV_PRLI */
2562 lpfc_rcv_logo_npr_node, /* RCV_LOGO */
2563 lpfc_rcv_padisc_npr_node, /* RCV_ADISC */
2564 lpfc_rcv_padisc_npr_node, /* RCV_PDISC */
2565 lpfc_rcv_prlo_npr_node, /* RCV_PRLO */
2566 lpfc_cmpl_plogi_npr_node, /* CMPL_PLOGI */
2567 lpfc_cmpl_prli_npr_node, /* CMPL_PRLI */
2568 lpfc_cmpl_logo_npr_node, /* CMPL_LOGO */
2569 lpfc_cmpl_adisc_npr_node, /* CMPL_ADISC */
2570 lpfc_cmpl_reglogin_npr_node, /* CMPL_REG_LOGIN */
2571 lpfc_device_rm_npr_node, /* DEVICE_RM */
2572 lpfc_device_recov_npr_node, /* DEVICE_RECOVERY */
2576 lpfc_disc_state_machine(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2577 void *arg, uint32_t evt)
2579 uint32_t cur_state, rc;
2580 uint32_t(*func) (struct lpfc_vport *, struct lpfc_nodelist *, void *,
2582 uint32_t got_ndlp = 0;
2584 if (lpfc_nlp_get(ndlp))
2587 cur_state = ndlp->nlp_state;
2589 /* DSM in event <evt> on NPort <nlp_DID> in state <cur_state> */
2590 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2591 "0211 DSM in event x%x on NPort x%x in "
2592 "state %d Data: x%x\n",
2593 evt, ndlp->nlp_DID, cur_state, ndlp->nlp_flag);
2595 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_DSM,
2596 "DSM in: evt:%d ste:%d did:x%x",
2597 evt, cur_state, ndlp->nlp_DID);
2599 func = lpfc_disc_action[(cur_state * NLP_EVT_MAX_EVENT) + evt];
2600 rc = (func) (vport, ndlp, arg, evt);
2602 /* DSM out state <rc> on NPort <nlp_DID> */
2604 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2605 "0212 DSM out state %d on NPort x%x Data: x%x\n",
2606 rc, ndlp->nlp_DID, ndlp->nlp_flag);
2608 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_DSM,
2609 "DSM out: ste:%d did:x%x flg:x%x",
2610 rc, ndlp->nlp_DID, ndlp->nlp_flag);
2611 /* Decrement the ndlp reference count held for this function */
2614 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2615 "0213 DSM out state %d on NPort free\n", rc);
2617 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_DSM,
2618 "DSM out: ste:%d did:x%x flg:x%x",