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 ||
637 vport->fc_flag & FC_PT2PT)
639 lpfc_linkdown_port(vport);
640 spin_lock_irq(shost->host_lock);
641 vport->fc_flag |= FC_VPORT_LOGO_RCVD;
642 spin_unlock_irq(shost->host_lock);
643 vports = lpfc_create_vport_work_array(phba);
645 for (i = 0; i <= phba->max_vports && vports[i] != NULL;
647 if ((!(vports[i]->fc_flag &
648 FC_VPORT_LOGO_RCVD)) &&
649 (vports[i]->port_state > LPFC_FDISC)) {
650 active_vlink_present = 1;
654 lpfc_destroy_vport_work_array(phba, vports);
658 * Don't re-instantiate if vport is marked for deletion.
659 * If we are here first then vport_delete is going to wait
660 * for discovery to complete.
662 if (!(vport->load_flag & FC_UNLOADING) &&
663 active_vlink_present) {
665 * If there are other active VLinks present,
666 * re-instantiate the Vlink using FDISC.
668 mod_timer(&ndlp->nlp_delayfunc,
669 jiffies + msecs_to_jiffies(1000));
670 spin_lock_irq(shost->host_lock);
671 ndlp->nlp_flag |= NLP_DELAY_TMO;
672 spin_unlock_irq(shost->host_lock);
673 ndlp->nlp_last_elscmd = ELS_CMD_FDISC;
674 vport->port_state = LPFC_FDISC;
676 spin_lock_irq(shost->host_lock);
677 phba->pport->fc_flag &= ~FC_LOGO_RCVD_DID_CHNG;
678 spin_unlock_irq(shost->host_lock);
679 lpfc_retry_pport_discovery(phba);
681 } else if ((!(ndlp->nlp_type & NLP_FABRIC) &&
682 ((ndlp->nlp_type & NLP_FCP_TARGET) ||
683 !(ndlp->nlp_type & NLP_FCP_INITIATOR))) ||
684 (ndlp->nlp_state == NLP_STE_ADISC_ISSUE)) {
685 /* Only try to re-login if this is NOT a Fabric Node */
686 mod_timer(&ndlp->nlp_delayfunc,
687 jiffies + msecs_to_jiffies(1000 * 1));
688 spin_lock_irq(shost->host_lock);
689 ndlp->nlp_flag |= NLP_DELAY_TMO;
690 spin_unlock_irq(shost->host_lock);
692 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
695 ndlp->nlp_prev_state = ndlp->nlp_state;
696 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
698 spin_lock_irq(shost->host_lock);
699 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
700 spin_unlock_irq(shost->host_lock);
701 /* The driver has to wait until the ACC completes before it continues
702 * processing the LOGO. The action will resume in
703 * lpfc_cmpl_els_logo_acc routine. Since part of processing includes an
704 * unreg_login, the driver waits so the ACC does not get aborted.
710 lpfc_rcv_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
711 struct lpfc_iocbq *cmdiocb)
713 struct lpfc_dmabuf *pcmd;
716 struct fc_rport *rport = ndlp->rport;
719 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
720 lp = (uint32_t *) pcmd->virt;
721 npr = (PRLI *) ((uint8_t *) lp + sizeof (uint32_t));
723 ndlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR);
724 ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
725 ndlp->nlp_flag &= ~NLP_FIRSTBURST;
726 if (npr->prliType == PRLI_FCP_TYPE) {
727 if (npr->initiatorFunc)
728 ndlp->nlp_type |= NLP_FCP_INITIATOR;
729 if (npr->targetFunc) {
730 ndlp->nlp_type |= NLP_FCP_TARGET;
731 if (npr->writeXferRdyDis)
732 ndlp->nlp_flag |= NLP_FIRSTBURST;
735 ndlp->nlp_fcp_info |= NLP_FCP_2_DEVICE;
738 /* We need to update the rport role values */
739 roles = FC_RPORT_ROLE_UNKNOWN;
740 if (ndlp->nlp_type & NLP_FCP_INITIATOR)
741 roles |= FC_RPORT_ROLE_FCP_INITIATOR;
742 if (ndlp->nlp_type & NLP_FCP_TARGET)
743 roles |= FC_RPORT_ROLE_FCP_TARGET;
745 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
746 "rport rolechg: role:x%x did:x%x flg:x%x",
747 roles, ndlp->nlp_DID, ndlp->nlp_flag);
749 fc_remote_port_rolechg(rport, roles);
754 lpfc_disc_set_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
756 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
758 if (!(ndlp->nlp_flag & NLP_RPI_REGISTERED)) {
759 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
763 if (!(vport->fc_flag & FC_PT2PT)) {
764 /* Check config parameter use-adisc or FCP-2 */
765 if (vport->cfg_use_adisc && ((vport->fc_flag & FC_RSCN_MODE) ||
766 ((ndlp->nlp_fcp_info & NLP_FCP_2_DEVICE) &&
767 (ndlp->nlp_type & NLP_FCP_TARGET)))) {
768 spin_lock_irq(shost->host_lock);
769 ndlp->nlp_flag |= NLP_NPR_ADISC;
770 spin_unlock_irq(shost->host_lock);
774 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
775 lpfc_unreg_rpi(vport, ndlp);
780 * lpfc_release_rpi - Release a RPI by issuing unreg_login mailbox cmd.
781 * @phba : Pointer to lpfc_hba structure.
782 * @vport: Pointer to lpfc_vport structure.
783 * @rpi : rpi to be release.
785 * This function will send a unreg_login mailbox command to the firmware
789 lpfc_release_rpi(struct lpfc_hba *phba,
790 struct lpfc_vport *vport,
796 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
799 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
800 "2796 mailbox memory allocation failed \n");
802 lpfc_unreg_login(phba, vport->vpi, rpi, pmb);
803 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
804 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
805 if (rc == MBX_NOT_FINISHED)
806 mempool_free(pmb, phba->mbox_mem_pool);
811 lpfc_disc_illegal(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
812 void *arg, uint32_t evt)
814 struct lpfc_hba *phba;
815 LPFC_MBOXQ_t *pmb = (LPFC_MBOXQ_t *) arg;
819 /* Release the RPI if reglogin completing */
820 if (!(phba->pport->load_flag & FC_UNLOADING) &&
821 (evt == NLP_EVT_CMPL_REG_LOGIN) &&
822 (!pmb->u.mb.mbxStatus)) {
823 rpi = pmb->u.mb.un.varWords[0];
824 lpfc_release_rpi(phba, vport, rpi);
826 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
827 "0271 Illegal State Transition: node x%x "
828 "event x%x, state x%x Data: x%x x%x\n",
829 ndlp->nlp_DID, evt, ndlp->nlp_state, ndlp->nlp_rpi,
831 return ndlp->nlp_state;
835 lpfc_cmpl_plogi_illegal(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
836 void *arg, uint32_t evt)
838 /* This transition is only legal if we previously
839 * rcv'ed a PLOGI. Since we don't want 2 discovery threads
840 * working on the same NPortID, do nothing for this thread
843 if (!(ndlp->nlp_flag & NLP_RCV_PLOGI)) {
844 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
845 "0272 Illegal State Transition: node x%x "
846 "event x%x, state x%x Data: x%x x%x\n",
847 ndlp->nlp_DID, evt, ndlp->nlp_state, ndlp->nlp_rpi,
850 return ndlp->nlp_state;
853 /* Start of Discovery State Machine routines */
856 lpfc_rcv_plogi_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
857 void *arg, uint32_t evt)
859 struct lpfc_iocbq *cmdiocb;
861 cmdiocb = (struct lpfc_iocbq *) arg;
863 if (lpfc_rcv_plogi(vport, ndlp, cmdiocb)) {
864 return ndlp->nlp_state;
866 return NLP_STE_FREED_NODE;
870 lpfc_rcv_els_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
871 void *arg, uint32_t evt)
873 lpfc_issue_els_logo(vport, ndlp, 0);
874 return ndlp->nlp_state;
878 lpfc_rcv_logo_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
879 void *arg, uint32_t evt)
881 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
882 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
884 spin_lock_irq(shost->host_lock);
885 ndlp->nlp_flag |= NLP_LOGO_ACC;
886 spin_unlock_irq(shost->host_lock);
887 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
889 return ndlp->nlp_state;
893 lpfc_cmpl_logo_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
894 void *arg, uint32_t evt)
896 return NLP_STE_FREED_NODE;
900 lpfc_device_rm_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
901 void *arg, uint32_t evt)
903 return NLP_STE_FREED_NODE;
907 lpfc_device_recov_unused_node(struct lpfc_vport *vport,
908 struct lpfc_nodelist *ndlp,
909 void *arg, uint32_t evt)
911 return ndlp->nlp_state;
915 lpfc_rcv_plogi_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
916 void *arg, uint32_t evt)
918 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
919 struct lpfc_hba *phba = vport->phba;
920 struct lpfc_iocbq *cmdiocb = arg;
921 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
922 uint32_t *lp = (uint32_t *) pcmd->virt;
923 struct serv_parm *sp = (struct serv_parm *) (lp + 1);
927 memset(&stat, 0, sizeof (struct ls_rjt));
929 /* For a PLOGI, we only accept if our portname is less
930 * than the remote portname.
932 phba->fc_stat.elsLogiCol++;
933 port_cmp = memcmp(&vport->fc_portname, &sp->portName,
934 sizeof(struct lpfc_name));
937 /* Reject this request because the remote node will accept
939 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
940 stat.un.b.lsRjtRsnCodeExp = LSEXP_CMD_IN_PROGRESS;
941 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
944 if (lpfc_rcv_plogi(vport, ndlp, cmdiocb) &&
945 (ndlp->nlp_flag & NLP_NPR_2B_DISC) &&
946 (vport->num_disc_nodes)) {
947 spin_lock_irq(shost->host_lock);
948 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
949 spin_unlock_irq(shost->host_lock);
950 /* Check if there are more PLOGIs to be sent */
951 lpfc_more_plogi(vport);
952 if (vport->num_disc_nodes == 0) {
953 spin_lock_irq(shost->host_lock);
954 vport->fc_flag &= ~FC_NDISC_ACTIVE;
955 spin_unlock_irq(shost->host_lock);
956 lpfc_can_disctmo(vport);
957 lpfc_end_rscn(vport);
960 } /* If our portname was less */
962 return ndlp->nlp_state;
966 lpfc_rcv_prli_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
967 void *arg, uint32_t evt)
969 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
972 memset(&stat, 0, sizeof (struct ls_rjt));
973 stat.un.b.lsRjtRsnCode = LSRJT_LOGICAL_BSY;
974 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
975 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
976 return ndlp->nlp_state;
980 lpfc_rcv_logo_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
981 void *arg, uint32_t evt)
983 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
985 /* software abort outstanding PLOGI */
986 lpfc_els_abort(vport->phba, ndlp);
988 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
989 return ndlp->nlp_state;
993 lpfc_rcv_els_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
994 void *arg, uint32_t evt)
996 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
997 struct lpfc_hba *phba = vport->phba;
998 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1000 /* software abort outstanding PLOGI */
1001 lpfc_els_abort(phba, ndlp);
1003 if (evt == NLP_EVT_RCV_LOGO) {
1004 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
1006 lpfc_issue_els_logo(vport, ndlp, 0);
1009 /* Put ndlp in npr state set plogi timer for 1 sec */
1010 mod_timer(&ndlp->nlp_delayfunc, jiffies + msecs_to_jiffies(1000 * 1));
1011 spin_lock_irq(shost->host_lock);
1012 ndlp->nlp_flag |= NLP_DELAY_TMO;
1013 spin_unlock_irq(shost->host_lock);
1014 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
1015 ndlp->nlp_prev_state = NLP_STE_PLOGI_ISSUE;
1016 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1018 return ndlp->nlp_state;
1022 lpfc_cmpl_plogi_plogi_issue(struct lpfc_vport *vport,
1023 struct lpfc_nodelist *ndlp,
1027 struct lpfc_hba *phba = vport->phba;
1028 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1029 struct lpfc_iocbq *cmdiocb, *rspiocb;
1030 struct lpfc_dmabuf *pcmd, *prsp, *mp;
1033 struct serv_parm *sp;
1038 cmdiocb = (struct lpfc_iocbq *) arg;
1039 rspiocb = cmdiocb->context_un.rsp_iocb;
1041 if (ndlp->nlp_flag & NLP_ACC_REGLOGIN) {
1042 /* Recovery from PLOGI collision logic */
1043 return ndlp->nlp_state;
1046 irsp = &rspiocb->iocb;
1048 if (irsp->ulpStatus)
1051 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
1053 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
1057 lp = (uint32_t *) prsp->virt;
1058 sp = (struct serv_parm *) ((uint8_t *) lp + sizeof (uint32_t));
1060 /* Some switches have FDMI servers returning 0 for WWN */
1061 if ((ndlp->nlp_DID != FDMI_DID) &&
1062 (wwn_to_u64(sp->portName.u.wwn) == 0 ||
1063 wwn_to_u64(sp->nodeName.u.wwn) == 0)) {
1064 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1065 "0142 PLOGI RSP: Invalid WWN.\n");
1068 if (!lpfc_check_sparm(vport, ndlp, sp, CLASS3, 0))
1070 /* PLOGI chkparm OK */
1071 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1072 "0121 PLOGI chkparm OK Data: x%x x%x x%x x%x\n",
1073 ndlp->nlp_DID, ndlp->nlp_state,
1074 ndlp->nlp_flag, ndlp->nlp_rpi);
1075 if (vport->cfg_fcp_class == 2 && (sp->cls2.classValid))
1076 ndlp->nlp_fcp_info |= CLASS2;
1078 ndlp->nlp_fcp_info |= CLASS3;
1080 ndlp->nlp_class_sup = 0;
1081 if (sp->cls1.classValid)
1082 ndlp->nlp_class_sup |= FC_COS_CLASS1;
1083 if (sp->cls2.classValid)
1084 ndlp->nlp_class_sup |= FC_COS_CLASS2;
1085 if (sp->cls3.classValid)
1086 ndlp->nlp_class_sup |= FC_COS_CLASS3;
1087 if (sp->cls4.classValid)
1088 ndlp->nlp_class_sup |= FC_COS_CLASS4;
1089 ndlp->nlp_maxframe =
1090 ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) | sp->cmn.bbRcvSizeLsb;
1092 if ((vport->fc_flag & FC_PT2PT) &&
1093 (vport->fc_flag & FC_PT2PT_PLOGI)) {
1094 ed_tov = be32_to_cpu(sp->cmn.e_d_tov);
1095 if (sp->cmn.edtovResolution) {
1096 /* E_D_TOV ticks are in nanoseconds */
1097 ed_tov = (phba->fc_edtov + 999999) / 1000000;
1101 * Use the larger EDTOV
1102 * RATOV = 2 * EDTOV for pt-to-pt
1104 if (ed_tov > phba->fc_edtov)
1105 phba->fc_edtov = ed_tov;
1106 phba->fc_ratov = (2 * phba->fc_edtov) / 1000;
1108 memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
1110 /* Issue config_link / reg_vfi to account for updated TOV's */
1111 if (phba->sli_rev == LPFC_SLI_REV4) {
1112 lpfc_issue_reg_vfi(vport);
1114 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1116 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1117 "0133 PLOGI: no memory "
1119 "Data: x%x x%x x%x x%x\n",
1120 ndlp->nlp_DID, ndlp->nlp_state,
1121 ndlp->nlp_flag, ndlp->nlp_rpi);
1125 lpfc_config_link(phba, mbox);
1127 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1128 mbox->vport = vport;
1129 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
1130 if (rc == MBX_NOT_FINISHED) {
1131 mempool_free(mbox, phba->mbox_mem_pool);
1137 lpfc_unreg_rpi(vport, ndlp);
1139 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1141 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1142 "0018 PLOGI: no memory for reg_login "
1143 "Data: x%x x%x x%x x%x\n",
1144 ndlp->nlp_DID, ndlp->nlp_state,
1145 ndlp->nlp_flag, ndlp->nlp_rpi);
1149 if (lpfc_reg_rpi(phba, vport->vpi, irsp->un.elsreq64.remoteID,
1150 (uint8_t *) sp, mbox, ndlp->nlp_rpi) == 0) {
1151 switch (ndlp->nlp_DID) {
1152 case NameServer_DID:
1153 mbox->mbox_cmpl = lpfc_mbx_cmpl_ns_reg_login;
1156 mbox->mbox_cmpl = lpfc_mbx_cmpl_fdmi_reg_login;
1159 ndlp->nlp_flag |= NLP_REG_LOGIN_SEND;
1160 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
1162 mbox->context2 = lpfc_nlp_get(ndlp);
1163 mbox->vport = vport;
1164 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
1165 != MBX_NOT_FINISHED) {
1166 lpfc_nlp_set_state(vport, ndlp,
1167 NLP_STE_REG_LOGIN_ISSUE);
1168 return ndlp->nlp_state;
1170 if (ndlp->nlp_flag & NLP_REG_LOGIN_SEND)
1171 ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND;
1172 /* decrement node reference count to the failed mbox
1176 mp = (struct lpfc_dmabuf *) mbox->context1;
1177 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1179 mempool_free(mbox, phba->mbox_mem_pool);
1181 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1182 "0134 PLOGI: cannot issue reg_login "
1183 "Data: x%x x%x x%x x%x\n",
1184 ndlp->nlp_DID, ndlp->nlp_state,
1185 ndlp->nlp_flag, ndlp->nlp_rpi);
1187 mempool_free(mbox, phba->mbox_mem_pool);
1189 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1190 "0135 PLOGI: cannot format reg_login "
1191 "Data: x%x x%x x%x x%x\n",
1192 ndlp->nlp_DID, ndlp->nlp_state,
1193 ndlp->nlp_flag, ndlp->nlp_rpi);
1198 if (ndlp->nlp_DID == NameServer_DID) {
1199 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
1200 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1201 "0261 Cannot Register NameServer login\n");
1205 ** In case the node reference counter does not go to zero, ensure that
1206 ** the stale state for the node is not processed.
1209 ndlp->nlp_prev_state = ndlp->nlp_state;
1210 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1211 spin_lock_irq(shost->host_lock);
1212 ndlp->nlp_flag |= NLP_DEFER_RM;
1213 spin_unlock_irq(shost->host_lock);
1214 return NLP_STE_FREED_NODE;
1218 lpfc_cmpl_logo_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1219 void *arg, uint32_t evt)
1221 return ndlp->nlp_state;
1225 lpfc_cmpl_reglogin_plogi_issue(struct lpfc_vport *vport,
1226 struct lpfc_nodelist *ndlp, void *arg, uint32_t evt)
1228 struct lpfc_hba *phba;
1229 LPFC_MBOXQ_t *pmb = (LPFC_MBOXQ_t *) arg;
1230 MAILBOX_t *mb = &pmb->u.mb;
1234 /* Release the RPI */
1235 if (!(phba->pport->load_flag & FC_UNLOADING) &&
1237 rpi = pmb->u.mb.un.varWords[0];
1238 lpfc_release_rpi(phba, vport, rpi);
1240 return ndlp->nlp_state;
1244 lpfc_device_rm_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1245 void *arg, uint32_t evt)
1247 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1249 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1250 spin_lock_irq(shost->host_lock);
1251 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
1252 spin_unlock_irq(shost->host_lock);
1253 return ndlp->nlp_state;
1255 /* software abort outstanding PLOGI */
1256 lpfc_els_abort(vport->phba, ndlp);
1258 lpfc_drop_node(vport, ndlp);
1259 return NLP_STE_FREED_NODE;
1264 lpfc_device_recov_plogi_issue(struct lpfc_vport *vport,
1265 struct lpfc_nodelist *ndlp,
1269 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1270 struct lpfc_hba *phba = vport->phba;
1272 /* Don't do anything that will mess up processing of the
1275 if (vport->fc_flag & FC_RSCN_DEFERRED)
1276 return ndlp->nlp_state;
1278 /* software abort outstanding PLOGI */
1279 lpfc_els_abort(phba, ndlp);
1281 ndlp->nlp_prev_state = NLP_STE_PLOGI_ISSUE;
1282 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1283 spin_lock_irq(shost->host_lock);
1284 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
1285 spin_unlock_irq(shost->host_lock);
1287 return ndlp->nlp_state;
1291 lpfc_rcv_plogi_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1292 void *arg, uint32_t evt)
1294 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1295 struct lpfc_hba *phba = vport->phba;
1296 struct lpfc_iocbq *cmdiocb;
1298 /* software abort outstanding ADISC */
1299 lpfc_els_abort(phba, ndlp);
1301 cmdiocb = (struct lpfc_iocbq *) arg;
1303 if (lpfc_rcv_plogi(vport, ndlp, cmdiocb)) {
1304 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1305 spin_lock_irq(shost->host_lock);
1306 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
1307 spin_unlock_irq(shost->host_lock);
1308 if (vport->num_disc_nodes)
1309 lpfc_more_adisc(vport);
1311 return ndlp->nlp_state;
1313 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
1314 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
1315 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
1317 return ndlp->nlp_state;
1321 lpfc_rcv_prli_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1322 void *arg, uint32_t evt)
1324 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1326 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
1327 return ndlp->nlp_state;
1331 lpfc_rcv_logo_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1332 void *arg, uint32_t evt)
1334 struct lpfc_hba *phba = vport->phba;
1335 struct lpfc_iocbq *cmdiocb;
1337 cmdiocb = (struct lpfc_iocbq *) arg;
1339 /* software abort outstanding ADISC */
1340 lpfc_els_abort(phba, ndlp);
1342 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
1343 return ndlp->nlp_state;
1347 lpfc_rcv_padisc_adisc_issue(struct lpfc_vport *vport,
1348 struct lpfc_nodelist *ndlp,
1349 void *arg, uint32_t evt)
1351 struct lpfc_iocbq *cmdiocb;
1353 cmdiocb = (struct lpfc_iocbq *) arg;
1355 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
1356 return ndlp->nlp_state;
1360 lpfc_rcv_prlo_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1361 void *arg, uint32_t evt)
1363 struct lpfc_iocbq *cmdiocb;
1365 cmdiocb = (struct lpfc_iocbq *) arg;
1367 /* Treat like rcv logo */
1368 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_PRLO);
1369 return ndlp->nlp_state;
1373 lpfc_cmpl_adisc_adisc_issue(struct lpfc_vport *vport,
1374 struct lpfc_nodelist *ndlp,
1375 void *arg, uint32_t evt)
1377 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1378 struct lpfc_hba *phba = vport->phba;
1379 struct lpfc_iocbq *cmdiocb, *rspiocb;
1384 cmdiocb = (struct lpfc_iocbq *) arg;
1385 rspiocb = cmdiocb->context_un.rsp_iocb;
1387 ap = (ADISC *)lpfc_check_elscmpl_iocb(phba, cmdiocb, rspiocb);
1388 irsp = &rspiocb->iocb;
1390 if ((irsp->ulpStatus) ||
1391 (!lpfc_check_adisc(vport, ndlp, &ap->nodeName, &ap->portName))) {
1393 mod_timer(&ndlp->nlp_delayfunc,
1394 jiffies + msecs_to_jiffies(1000));
1395 spin_lock_irq(shost->host_lock);
1396 ndlp->nlp_flag |= NLP_DELAY_TMO;
1397 spin_unlock_irq(shost->host_lock);
1398 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
1400 memset(&ndlp->nlp_nodename, 0, sizeof(struct lpfc_name));
1401 memset(&ndlp->nlp_portname, 0, sizeof(struct lpfc_name));
1403 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
1404 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1405 lpfc_unreg_rpi(vport, ndlp);
1406 return ndlp->nlp_state;
1409 if (phba->sli_rev == LPFC_SLI_REV4) {
1410 rc = lpfc_sli4_resume_rpi(ndlp, NULL, NULL);
1412 /* Stay in state and retry. */
1413 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
1414 return ndlp->nlp_state;
1418 if (ndlp->nlp_type & NLP_FCP_TARGET) {
1419 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
1420 lpfc_nlp_set_state(vport, ndlp, NLP_STE_MAPPED_NODE);
1422 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
1423 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
1426 return ndlp->nlp_state;
1430 lpfc_device_rm_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1431 void *arg, uint32_t evt)
1433 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1435 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1436 spin_lock_irq(shost->host_lock);
1437 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
1438 spin_unlock_irq(shost->host_lock);
1439 return ndlp->nlp_state;
1441 /* software abort outstanding ADISC */
1442 lpfc_els_abort(vport->phba, ndlp);
1444 lpfc_drop_node(vport, ndlp);
1445 return NLP_STE_FREED_NODE;
1450 lpfc_device_recov_adisc_issue(struct lpfc_vport *vport,
1451 struct lpfc_nodelist *ndlp,
1455 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1456 struct lpfc_hba *phba = vport->phba;
1458 /* Don't do anything that will mess up processing of the
1461 if (vport->fc_flag & FC_RSCN_DEFERRED)
1462 return ndlp->nlp_state;
1464 /* software abort outstanding ADISC */
1465 lpfc_els_abort(phba, ndlp);
1467 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
1468 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1469 spin_lock_irq(shost->host_lock);
1470 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
1471 spin_unlock_irq(shost->host_lock);
1472 lpfc_disc_set_adisc(vport, ndlp);
1473 return ndlp->nlp_state;
1477 lpfc_rcv_plogi_reglogin_issue(struct lpfc_vport *vport,
1478 struct lpfc_nodelist *ndlp,
1482 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1484 lpfc_rcv_plogi(vport, ndlp, cmdiocb);
1485 return ndlp->nlp_state;
1489 lpfc_rcv_prli_reglogin_issue(struct lpfc_vport *vport,
1490 struct lpfc_nodelist *ndlp,
1494 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1496 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
1497 return ndlp->nlp_state;
1501 lpfc_rcv_logo_reglogin_issue(struct lpfc_vport *vport,
1502 struct lpfc_nodelist *ndlp,
1506 struct lpfc_hba *phba = vport->phba;
1507 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1509 LPFC_MBOXQ_t *nextmb;
1510 struct lpfc_dmabuf *mp;
1512 cmdiocb = (struct lpfc_iocbq *) arg;
1514 /* cleanup any ndlp on mbox q waiting for reglogin cmpl */
1515 if ((mb = phba->sli.mbox_active)) {
1516 if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) &&
1517 (ndlp == (struct lpfc_nodelist *) mb->context2)) {
1518 ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND;
1520 mb->context2 = NULL;
1521 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1525 spin_lock_irq(&phba->hbalock);
1526 list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) {
1527 if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) &&
1528 (ndlp == (struct lpfc_nodelist *) mb->context2)) {
1529 mp = (struct lpfc_dmabuf *) (mb->context1);
1531 __lpfc_mbuf_free(phba, mp->virt, mp->phys);
1534 ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND;
1536 list_del(&mb->list);
1537 phba->sli.mboxq_cnt--;
1538 mempool_free(mb, phba->mbox_mem_pool);
1541 spin_unlock_irq(&phba->hbalock);
1543 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
1544 return ndlp->nlp_state;
1548 lpfc_rcv_padisc_reglogin_issue(struct lpfc_vport *vport,
1549 struct lpfc_nodelist *ndlp,
1553 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1555 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
1556 return ndlp->nlp_state;
1560 lpfc_rcv_prlo_reglogin_issue(struct lpfc_vport *vport,
1561 struct lpfc_nodelist *ndlp,
1565 struct lpfc_iocbq *cmdiocb;
1567 cmdiocb = (struct lpfc_iocbq *) arg;
1568 lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL);
1569 return ndlp->nlp_state;
1573 lpfc_cmpl_reglogin_reglogin_issue(struct lpfc_vport *vport,
1574 struct lpfc_nodelist *ndlp,
1578 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1579 LPFC_MBOXQ_t *pmb = (LPFC_MBOXQ_t *) arg;
1580 MAILBOX_t *mb = &pmb->u.mb;
1581 uint32_t did = mb->un.varWords[1];
1583 if (mb->mbxStatus) {
1584 /* RegLogin failed */
1585 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
1586 "0246 RegLogin failed Data: x%x x%x x%x x%x "
1588 did, mb->mbxStatus, vport->port_state,
1589 mb->un.varRegLogin.vpi,
1590 mb->un.varRegLogin.rpi);
1592 * If RegLogin failed due to lack of HBA resources do not
1595 if (mb->mbxStatus == MBXERR_RPI_FULL) {
1596 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
1597 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1598 return ndlp->nlp_state;
1601 /* Put ndlp in npr state set plogi timer for 1 sec */
1602 mod_timer(&ndlp->nlp_delayfunc,
1603 jiffies + msecs_to_jiffies(1000 * 1));
1604 spin_lock_irq(shost->host_lock);
1605 ndlp->nlp_flag |= NLP_DELAY_TMO;
1606 spin_unlock_irq(shost->host_lock);
1607 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
1609 lpfc_issue_els_logo(vport, ndlp, 0);
1610 return ndlp->nlp_state;
1613 /* SLI4 ports have preallocated logical rpis. */
1614 if (vport->phba->sli_rev < LPFC_SLI_REV4)
1615 ndlp->nlp_rpi = mb->un.varWords[0];
1617 ndlp->nlp_flag |= NLP_RPI_REGISTERED;
1619 /* Only if we are not a fabric nport do we issue PRLI */
1620 if (!(ndlp->nlp_type & NLP_FABRIC)) {
1621 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
1622 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
1623 lpfc_issue_els_prli(vport, ndlp, 0);
1625 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
1626 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
1628 return ndlp->nlp_state;
1632 lpfc_device_rm_reglogin_issue(struct lpfc_vport *vport,
1633 struct lpfc_nodelist *ndlp,
1637 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1639 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1640 spin_lock_irq(shost->host_lock);
1641 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
1642 spin_unlock_irq(shost->host_lock);
1643 return ndlp->nlp_state;
1645 lpfc_drop_node(vport, ndlp);
1646 return NLP_STE_FREED_NODE;
1651 lpfc_device_recov_reglogin_issue(struct lpfc_vport *vport,
1652 struct lpfc_nodelist *ndlp,
1656 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1658 /* Don't do anything that will mess up processing of the
1661 if (vport->fc_flag & FC_RSCN_DEFERRED)
1662 return ndlp->nlp_state;
1664 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
1665 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1666 spin_lock_irq(shost->host_lock);
1667 ndlp->nlp_flag |= NLP_IGNR_REG_CMPL;
1668 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
1669 spin_unlock_irq(shost->host_lock);
1670 lpfc_disc_set_adisc(vport, ndlp);
1671 return ndlp->nlp_state;
1675 lpfc_rcv_plogi_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1676 void *arg, uint32_t evt)
1678 struct lpfc_iocbq *cmdiocb;
1680 cmdiocb = (struct lpfc_iocbq *) arg;
1682 lpfc_rcv_plogi(vport, ndlp, cmdiocb);
1683 return ndlp->nlp_state;
1687 lpfc_rcv_prli_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1688 void *arg, uint32_t evt)
1690 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1692 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
1693 return ndlp->nlp_state;
1697 lpfc_rcv_logo_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1698 void *arg, uint32_t evt)
1700 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1702 /* Software abort outstanding PRLI before sending acc */
1703 lpfc_els_abort(vport->phba, ndlp);
1705 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
1706 return ndlp->nlp_state;
1710 lpfc_rcv_padisc_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1711 void *arg, uint32_t evt)
1713 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1715 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
1716 return ndlp->nlp_state;
1719 /* This routine is envoked when we rcv a PRLO request from a nport
1720 * we are logged into. We should send back a PRLO rsp setting the
1722 * NEXT STATE = PRLI_ISSUE
1725 lpfc_rcv_prlo_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1726 void *arg, uint32_t evt)
1728 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1730 lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL);
1731 return ndlp->nlp_state;
1735 lpfc_cmpl_prli_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1736 void *arg, uint32_t evt)
1738 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1739 struct lpfc_iocbq *cmdiocb, *rspiocb;
1740 struct lpfc_hba *phba = vport->phba;
1744 cmdiocb = (struct lpfc_iocbq *) arg;
1745 rspiocb = cmdiocb->context_un.rsp_iocb;
1746 npr = (PRLI *)lpfc_check_elscmpl_iocb(phba, cmdiocb, rspiocb);
1748 irsp = &rspiocb->iocb;
1749 if (irsp->ulpStatus) {
1750 if ((vport->port_type == LPFC_NPIV_PORT) &&
1751 vport->cfg_restrict_login) {
1754 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
1755 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
1756 return ndlp->nlp_state;
1759 /* Check out PRLI rsp */
1760 ndlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR);
1761 ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
1762 ndlp->nlp_flag &= ~NLP_FIRSTBURST;
1763 if ((npr->acceptRspCode == PRLI_REQ_EXECUTED) &&
1764 (npr->prliType == PRLI_FCP_TYPE)) {
1765 if (npr->initiatorFunc)
1766 ndlp->nlp_type |= NLP_FCP_INITIATOR;
1767 if (npr->targetFunc) {
1768 ndlp->nlp_type |= NLP_FCP_TARGET;
1769 if (npr->writeXferRdyDis)
1770 ndlp->nlp_flag |= NLP_FIRSTBURST;
1773 ndlp->nlp_fcp_info |= NLP_FCP_2_DEVICE;
1775 if (!(ndlp->nlp_type & NLP_FCP_TARGET) &&
1776 (vport->port_type == LPFC_NPIV_PORT) &&
1777 vport->cfg_restrict_login) {
1779 spin_lock_irq(shost->host_lock);
1780 ndlp->nlp_flag |= NLP_TARGET_REMOVE;
1781 spin_unlock_irq(shost->host_lock);
1782 lpfc_issue_els_logo(vport, ndlp, 0);
1784 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
1785 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1786 return ndlp->nlp_state;
1789 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
1790 if (ndlp->nlp_type & NLP_FCP_TARGET)
1791 lpfc_nlp_set_state(vport, ndlp, NLP_STE_MAPPED_NODE);
1793 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
1794 return ndlp->nlp_state;
1797 /*! lpfc_device_rm_prli_issue
1808 * This routine is envoked when we a request to remove a nport we are in the
1809 * process of PRLIing. We should software abort outstanding prli, unreg
1810 * login, send a logout. We will change node state to UNUSED_NODE, put it
1811 * on plogi list so it can be freed when LOGO completes.
1816 lpfc_device_rm_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1817 void *arg, uint32_t evt)
1819 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1821 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1822 spin_lock_irq(shost->host_lock);
1823 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
1824 spin_unlock_irq(shost->host_lock);
1825 return ndlp->nlp_state;
1827 /* software abort outstanding PLOGI */
1828 lpfc_els_abort(vport->phba, ndlp);
1830 lpfc_drop_node(vport, ndlp);
1831 return NLP_STE_FREED_NODE;
1836 /*! lpfc_device_recov_prli_issue
1847 * The routine is envoked when the state of a device is unknown, like
1848 * during a link down. We should remove the nodelist entry from the
1849 * unmapped list, issue a UNREG_LOGIN, do a software abort of the
1850 * outstanding PRLI command, then free the node entry.
1853 lpfc_device_recov_prli_issue(struct lpfc_vport *vport,
1854 struct lpfc_nodelist *ndlp,
1858 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1859 struct lpfc_hba *phba = vport->phba;
1861 /* Don't do anything that will mess up processing of the
1864 if (vport->fc_flag & FC_RSCN_DEFERRED)
1865 return ndlp->nlp_state;
1867 /* software abort outstanding PRLI */
1868 lpfc_els_abort(phba, ndlp);
1870 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
1871 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1872 spin_lock_irq(shost->host_lock);
1873 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
1874 spin_unlock_irq(shost->host_lock);
1875 lpfc_disc_set_adisc(vport, ndlp);
1876 return ndlp->nlp_state;
1880 lpfc_rcv_plogi_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1881 void *arg, uint32_t evt)
1883 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *)arg;
1886 memset(&stat, 0, sizeof(struct ls_rjt));
1887 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
1888 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
1889 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
1890 return ndlp->nlp_state;
1894 lpfc_rcv_prli_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1895 void *arg, uint32_t evt)
1897 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *)arg;
1900 memset(&stat, 0, sizeof(struct ls_rjt));
1901 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
1902 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
1903 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
1904 return ndlp->nlp_state;
1908 lpfc_rcv_logo_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1909 void *arg, uint32_t evt)
1911 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1912 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *)arg;
1914 spin_lock_irq(shost->host_lock);
1915 ndlp->nlp_flag |= NLP_LOGO_ACC;
1916 spin_unlock_irq(shost->host_lock);
1917 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
1918 return ndlp->nlp_state;
1922 lpfc_rcv_padisc_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1923 void *arg, uint32_t evt)
1925 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *)arg;
1928 memset(&stat, 0, sizeof(struct ls_rjt));
1929 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
1930 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
1931 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
1932 return ndlp->nlp_state;
1936 lpfc_rcv_prlo_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1937 void *arg, uint32_t evt)
1939 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *)arg;
1942 memset(&stat, 0, sizeof(struct ls_rjt));
1943 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
1944 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
1945 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
1946 return ndlp->nlp_state;
1950 lpfc_cmpl_logo_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1951 void *arg, uint32_t evt)
1953 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1955 ndlp->nlp_prev_state = NLP_STE_LOGO_ISSUE;
1956 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1957 spin_lock_irq(shost->host_lock);
1958 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
1959 spin_unlock_irq(shost->host_lock);
1960 lpfc_disc_set_adisc(vport, ndlp);
1961 return ndlp->nlp_state;
1965 lpfc_device_rm_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1966 void *arg, uint32_t evt)
1969 * Take no action. If a LOGO is outstanding, then possibly DevLoss has
1970 * timed out and is calling for Device Remove. In this case, the LOGO
1971 * must be allowed to complete in state LOGO_ISSUE so that the rpi
1972 * and other NLP flags are correctly cleaned up.
1974 return ndlp->nlp_state;
1978 lpfc_device_recov_logo_issue(struct lpfc_vport *vport,
1979 struct lpfc_nodelist *ndlp,
1980 void *arg, uint32_t evt)
1983 * Device Recovery events have no meaning for a node with a LOGO
1984 * outstanding. The LOGO has to complete first and handle the
1985 * node from that point.
1987 return ndlp->nlp_state;
1991 lpfc_rcv_plogi_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1992 void *arg, uint32_t evt)
1994 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1996 lpfc_rcv_plogi(vport, ndlp, cmdiocb);
1997 return ndlp->nlp_state;
2001 lpfc_rcv_prli_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2002 void *arg, uint32_t evt)
2004 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2006 lpfc_rcv_prli(vport, ndlp, cmdiocb);
2007 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
2008 return ndlp->nlp_state;
2012 lpfc_rcv_logo_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2013 void *arg, uint32_t evt)
2015 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2017 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
2018 return ndlp->nlp_state;
2022 lpfc_rcv_padisc_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2023 void *arg, uint32_t evt)
2025 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2027 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
2028 return ndlp->nlp_state;
2032 lpfc_rcv_prlo_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2033 void *arg, uint32_t evt)
2035 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2037 lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL);
2038 return ndlp->nlp_state;
2042 lpfc_device_recov_unmap_node(struct lpfc_vport *vport,
2043 struct lpfc_nodelist *ndlp,
2047 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2049 ndlp->nlp_prev_state = NLP_STE_UNMAPPED_NODE;
2050 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
2051 spin_lock_irq(shost->host_lock);
2052 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
2053 spin_unlock_irq(shost->host_lock);
2054 lpfc_disc_set_adisc(vport, ndlp);
2056 return ndlp->nlp_state;
2060 lpfc_rcv_plogi_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2061 void *arg, uint32_t evt)
2063 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2065 lpfc_rcv_plogi(vport, ndlp, cmdiocb);
2066 return ndlp->nlp_state;
2070 lpfc_rcv_prli_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2071 void *arg, uint32_t evt)
2073 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2075 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
2076 return ndlp->nlp_state;
2080 lpfc_rcv_logo_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2081 void *arg, uint32_t evt)
2083 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2085 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
2086 return ndlp->nlp_state;
2090 lpfc_rcv_padisc_mapped_node(struct lpfc_vport *vport,
2091 struct lpfc_nodelist *ndlp,
2092 void *arg, uint32_t evt)
2094 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2096 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
2097 return ndlp->nlp_state;
2101 lpfc_rcv_prlo_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2102 void *arg, uint32_t evt)
2104 struct lpfc_hba *phba = vport->phba;
2105 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2107 /* flush the target */
2108 lpfc_sli_abort_iocb(vport, &phba->sli.ring[phba->sli.fcp_ring],
2109 ndlp->nlp_sid, 0, LPFC_CTX_TGT);
2111 /* Treat like rcv logo */
2112 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_PRLO);
2113 return ndlp->nlp_state;
2117 lpfc_device_recov_mapped_node(struct lpfc_vport *vport,
2118 struct lpfc_nodelist *ndlp,
2122 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2124 ndlp->nlp_prev_state = NLP_STE_MAPPED_NODE;
2125 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
2126 spin_lock_irq(shost->host_lock);
2127 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
2128 spin_unlock_irq(shost->host_lock);
2129 lpfc_disc_set_adisc(vport, ndlp);
2130 return ndlp->nlp_state;
2134 lpfc_rcv_plogi_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2135 void *arg, uint32_t evt)
2137 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2138 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2140 /* Ignore PLOGI if we have an outstanding LOGO */
2141 if (ndlp->nlp_flag & (NLP_LOGO_SND | NLP_LOGO_ACC))
2142 return ndlp->nlp_state;
2143 if (lpfc_rcv_plogi(vport, ndlp, cmdiocb)) {
2144 lpfc_cancel_retry_delay_tmo(vport, ndlp);
2145 spin_lock_irq(shost->host_lock);
2146 ndlp->nlp_flag &= ~(NLP_NPR_ADISC | NLP_NPR_2B_DISC);
2147 spin_unlock_irq(shost->host_lock);
2148 } else if (!(ndlp->nlp_flag & NLP_NPR_2B_DISC)) {
2149 /* send PLOGI immediately, move to PLOGI issue state */
2150 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
2151 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
2152 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
2153 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
2156 return ndlp->nlp_state;
2160 lpfc_rcv_prli_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2161 void *arg, uint32_t evt)
2163 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2164 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2167 memset(&stat, 0, sizeof (struct ls_rjt));
2168 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
2169 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
2170 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
2172 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
2173 if (ndlp->nlp_flag & NLP_NPR_ADISC) {
2174 spin_lock_irq(shost->host_lock);
2175 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
2176 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
2177 spin_unlock_irq(shost->host_lock);
2178 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
2179 lpfc_issue_els_adisc(vport, ndlp, 0);
2181 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
2182 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
2183 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
2186 return ndlp->nlp_state;
2190 lpfc_rcv_logo_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2191 void *arg, uint32_t evt)
2193 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2195 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
2196 return ndlp->nlp_state;
2200 lpfc_rcv_padisc_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2201 void *arg, uint32_t evt)
2203 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2205 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
2207 * Do not start discovery if discovery is about to start
2208 * or discovery in progress for this node. Starting discovery
2209 * here will affect the counting of discovery threads.
2211 if (!(ndlp->nlp_flag & NLP_DELAY_TMO) &&
2212 !(ndlp->nlp_flag & NLP_NPR_2B_DISC)) {
2213 if (ndlp->nlp_flag & NLP_NPR_ADISC) {
2214 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
2215 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
2216 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
2217 lpfc_issue_els_adisc(vport, ndlp, 0);
2219 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
2220 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
2221 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
2224 return ndlp->nlp_state;
2228 lpfc_rcv_prlo_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2229 void *arg, uint32_t evt)
2231 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2232 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2234 spin_lock_irq(shost->host_lock);
2235 ndlp->nlp_flag |= NLP_LOGO_ACC;
2236 spin_unlock_irq(shost->host_lock);
2238 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
2240 if ((ndlp->nlp_flag & NLP_DELAY_TMO) == 0) {
2241 mod_timer(&ndlp->nlp_delayfunc,
2242 jiffies + msecs_to_jiffies(1000 * 1));
2243 spin_lock_irq(shost->host_lock);
2244 ndlp->nlp_flag |= NLP_DELAY_TMO;
2245 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
2246 spin_unlock_irq(shost->host_lock);
2247 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
2249 spin_lock_irq(shost->host_lock);
2250 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
2251 spin_unlock_irq(shost->host_lock);
2253 return ndlp->nlp_state;
2257 lpfc_cmpl_plogi_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2258 void *arg, uint32_t evt)
2260 struct lpfc_iocbq *cmdiocb, *rspiocb;
2262 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2264 cmdiocb = (struct lpfc_iocbq *) arg;
2265 rspiocb = cmdiocb->context_un.rsp_iocb;
2267 irsp = &rspiocb->iocb;
2268 if (irsp->ulpStatus) {
2269 spin_lock_irq(shost->host_lock);
2270 ndlp->nlp_flag |= NLP_DEFER_RM;
2271 spin_unlock_irq(shost->host_lock);
2272 return NLP_STE_FREED_NODE;
2274 return ndlp->nlp_state;
2278 lpfc_cmpl_prli_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2279 void *arg, uint32_t evt)
2281 struct lpfc_iocbq *cmdiocb, *rspiocb;
2284 cmdiocb = (struct lpfc_iocbq *) arg;
2285 rspiocb = cmdiocb->context_un.rsp_iocb;
2287 irsp = &rspiocb->iocb;
2288 if (irsp->ulpStatus && (ndlp->nlp_flag & NLP_NODEV_REMOVE)) {
2289 lpfc_drop_node(vport, ndlp);
2290 return NLP_STE_FREED_NODE;
2292 return ndlp->nlp_state;
2296 lpfc_cmpl_logo_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2297 void *arg, uint32_t evt)
2299 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2301 /* For the fabric port just clear the fc flags. */
2302 if (ndlp->nlp_DID == Fabric_DID) {
2303 spin_lock_irq(shost->host_lock);
2304 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
2305 spin_unlock_irq(shost->host_lock);
2307 lpfc_unreg_rpi(vport, ndlp);
2308 return ndlp->nlp_state;
2312 lpfc_cmpl_adisc_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2313 void *arg, uint32_t evt)
2315 struct lpfc_iocbq *cmdiocb, *rspiocb;
2318 cmdiocb = (struct lpfc_iocbq *) arg;
2319 rspiocb = cmdiocb->context_un.rsp_iocb;
2321 irsp = &rspiocb->iocb;
2322 if (irsp->ulpStatus && (ndlp->nlp_flag & NLP_NODEV_REMOVE)) {
2323 lpfc_drop_node(vport, ndlp);
2324 return NLP_STE_FREED_NODE;
2326 return ndlp->nlp_state;
2330 lpfc_cmpl_reglogin_npr_node(struct lpfc_vport *vport,
2331 struct lpfc_nodelist *ndlp,
2332 void *arg, uint32_t evt)
2334 LPFC_MBOXQ_t *pmb = (LPFC_MBOXQ_t *) arg;
2335 MAILBOX_t *mb = &pmb->u.mb;
2337 if (!mb->mbxStatus) {
2338 /* SLI4 ports have preallocated logical rpis. */
2339 if (vport->phba->sli_rev < LPFC_SLI_REV4)
2340 ndlp->nlp_rpi = mb->un.varWords[0];
2341 ndlp->nlp_flag |= NLP_RPI_REGISTERED;
2342 if (ndlp->nlp_flag & NLP_LOGO_ACC) {
2343 lpfc_unreg_rpi(vport, ndlp);
2346 if (ndlp->nlp_flag & NLP_NODEV_REMOVE) {
2347 lpfc_drop_node(vport, ndlp);
2348 return NLP_STE_FREED_NODE;
2351 return ndlp->nlp_state;
2355 lpfc_device_rm_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2356 void *arg, uint32_t evt)
2358 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2360 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
2361 spin_lock_irq(shost->host_lock);
2362 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
2363 spin_unlock_irq(shost->host_lock);
2364 return ndlp->nlp_state;
2366 lpfc_drop_node(vport, ndlp);
2367 return NLP_STE_FREED_NODE;
2371 lpfc_device_recov_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2372 void *arg, uint32_t evt)
2374 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2376 /* Don't do anything that will mess up processing of the
2379 if (vport->fc_flag & FC_RSCN_DEFERRED)
2380 return ndlp->nlp_state;
2382 lpfc_cancel_retry_delay_tmo(vport, ndlp);
2383 spin_lock_irq(shost->host_lock);
2384 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
2385 spin_unlock_irq(shost->host_lock);
2386 return ndlp->nlp_state;
2390 /* This next section defines the NPort Discovery State Machine */
2392 /* There are 4 different double linked lists nodelist entries can reside on.
2393 * The plogi list and adisc list are used when Link Up discovery or RSCN
2394 * processing is needed. Each list holds the nodes that we will send PLOGI
2395 * or ADISC on. These lists will keep track of what nodes will be effected
2396 * by an RSCN, or a Link Up (Typically, all nodes are effected on Link Up).
2397 * The unmapped_list will contain all nodes that we have successfully logged
2398 * into at the Fibre Channel level. The mapped_list will contain all nodes
2399 * that are mapped FCP targets.
2402 * The bind list is a list of undiscovered (potentially non-existent) nodes
2403 * that we have saved binding information on. This information is used when
2404 * nodes transition from the unmapped to the mapped list.
2406 /* For UNUSED_NODE state, the node has just been allocated .
2407 * For PLOGI_ISSUE and REG_LOGIN_ISSUE, the node is on
2408 * the PLOGI list. For REG_LOGIN_COMPL, the node is taken off the PLOGI list
2409 * and put on the unmapped list. For ADISC processing, the node is taken off
2410 * the ADISC list and placed on either the mapped or unmapped list (depending
2411 * on its previous state). Once on the unmapped list, a PRLI is issued and the
2412 * state changed to PRLI_ISSUE. When the PRLI completion occurs, the state is
2413 * changed to UNMAPPED_NODE. If the completion indicates a mapped
2414 * node, the node is taken off the unmapped list. The binding list is checked
2415 * for a valid binding, or a binding is automatically assigned. If binding
2416 * assignment is unsuccessful, the node is left on the unmapped list. If
2417 * binding assignment is successful, the associated binding list entry (if
2418 * any) is removed, and the node is placed on the mapped list.
2421 * For a Link Down, all nodes on the ADISC, PLOGI, unmapped or mapped
2422 * lists will receive a DEVICE_RECOVERY event. If the linkdown or devloss timers
2423 * expire, all effected nodes will receive a DEVICE_RM event.
2426 * For a Link Up or RSCN, all nodes will move from the mapped / unmapped lists
2427 * to either the ADISC or PLOGI list. After a Nameserver query or ALPA loopmap
2428 * check, additional nodes may be added or removed (via DEVICE_RM) to / from
2429 * the PLOGI or ADISC lists. Once the PLOGI and ADISC lists are populated,
2430 * we will first process the ADISC list. 32 entries are processed initially and
2431 * ADISC is initited for each one. Completions / Events for each node are
2432 * funnelled thru the state machine. As each node finishes ADISC processing, it
2433 * starts ADISC for any nodes waiting for ADISC processing. If no nodes are
2434 * waiting, and the ADISC list count is identically 0, then we are done. For
2435 * Link Up discovery, since all nodes on the PLOGI list are UNREG_LOGIN'ed, we
2436 * can issue a CLEAR_LA and reenable Link Events. Next we will process the PLOGI
2437 * list. 32 entries are processed initially and PLOGI is initited for each one.
2438 * Completions / Events for each node are funnelled thru the state machine. As
2439 * each node finishes PLOGI processing, it starts PLOGI for any nodes waiting
2440 * for PLOGI processing. If no nodes are waiting, and the PLOGI list count is
2441 * indentically 0, then we are done. We have now completed discovery / RSCN
2442 * handling. Upon completion, ALL nodes should be on either the mapped or
2446 static uint32_t (*lpfc_disc_action[NLP_STE_MAX_STATE * NLP_EVT_MAX_EVENT])
2447 (struct lpfc_vport *, struct lpfc_nodelist *, void *, uint32_t) = {
2448 /* Action routine Event Current State */
2449 lpfc_rcv_plogi_unused_node, /* RCV_PLOGI UNUSED_NODE */
2450 lpfc_rcv_els_unused_node, /* RCV_PRLI */
2451 lpfc_rcv_logo_unused_node, /* RCV_LOGO */
2452 lpfc_rcv_els_unused_node, /* RCV_ADISC */
2453 lpfc_rcv_els_unused_node, /* RCV_PDISC */
2454 lpfc_rcv_els_unused_node, /* RCV_PRLO */
2455 lpfc_disc_illegal, /* CMPL_PLOGI */
2456 lpfc_disc_illegal, /* CMPL_PRLI */
2457 lpfc_cmpl_logo_unused_node, /* CMPL_LOGO */
2458 lpfc_disc_illegal, /* CMPL_ADISC */
2459 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2460 lpfc_device_rm_unused_node, /* DEVICE_RM */
2461 lpfc_device_recov_unused_node, /* DEVICE_RECOVERY */
2463 lpfc_rcv_plogi_plogi_issue, /* RCV_PLOGI PLOGI_ISSUE */
2464 lpfc_rcv_prli_plogi_issue, /* RCV_PRLI */
2465 lpfc_rcv_logo_plogi_issue, /* RCV_LOGO */
2466 lpfc_rcv_els_plogi_issue, /* RCV_ADISC */
2467 lpfc_rcv_els_plogi_issue, /* RCV_PDISC */
2468 lpfc_rcv_els_plogi_issue, /* RCV_PRLO */
2469 lpfc_cmpl_plogi_plogi_issue, /* CMPL_PLOGI */
2470 lpfc_disc_illegal, /* CMPL_PRLI */
2471 lpfc_cmpl_logo_plogi_issue, /* CMPL_LOGO */
2472 lpfc_disc_illegal, /* CMPL_ADISC */
2473 lpfc_cmpl_reglogin_plogi_issue,/* CMPL_REG_LOGIN */
2474 lpfc_device_rm_plogi_issue, /* DEVICE_RM */
2475 lpfc_device_recov_plogi_issue, /* DEVICE_RECOVERY */
2477 lpfc_rcv_plogi_adisc_issue, /* RCV_PLOGI ADISC_ISSUE */
2478 lpfc_rcv_prli_adisc_issue, /* RCV_PRLI */
2479 lpfc_rcv_logo_adisc_issue, /* RCV_LOGO */
2480 lpfc_rcv_padisc_adisc_issue, /* RCV_ADISC */
2481 lpfc_rcv_padisc_adisc_issue, /* RCV_PDISC */
2482 lpfc_rcv_prlo_adisc_issue, /* RCV_PRLO */
2483 lpfc_disc_illegal, /* CMPL_PLOGI */
2484 lpfc_disc_illegal, /* CMPL_PRLI */
2485 lpfc_disc_illegal, /* CMPL_LOGO */
2486 lpfc_cmpl_adisc_adisc_issue, /* CMPL_ADISC */
2487 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2488 lpfc_device_rm_adisc_issue, /* DEVICE_RM */
2489 lpfc_device_recov_adisc_issue, /* DEVICE_RECOVERY */
2491 lpfc_rcv_plogi_reglogin_issue, /* RCV_PLOGI REG_LOGIN_ISSUE */
2492 lpfc_rcv_prli_reglogin_issue, /* RCV_PLOGI */
2493 lpfc_rcv_logo_reglogin_issue, /* RCV_LOGO */
2494 lpfc_rcv_padisc_reglogin_issue, /* RCV_ADISC */
2495 lpfc_rcv_padisc_reglogin_issue, /* RCV_PDISC */
2496 lpfc_rcv_prlo_reglogin_issue, /* RCV_PRLO */
2497 lpfc_cmpl_plogi_illegal, /* CMPL_PLOGI */
2498 lpfc_disc_illegal, /* CMPL_PRLI */
2499 lpfc_disc_illegal, /* CMPL_LOGO */
2500 lpfc_disc_illegal, /* CMPL_ADISC */
2501 lpfc_cmpl_reglogin_reglogin_issue,/* CMPL_REG_LOGIN */
2502 lpfc_device_rm_reglogin_issue, /* DEVICE_RM */
2503 lpfc_device_recov_reglogin_issue,/* DEVICE_RECOVERY */
2505 lpfc_rcv_plogi_prli_issue, /* RCV_PLOGI PRLI_ISSUE */
2506 lpfc_rcv_prli_prli_issue, /* RCV_PRLI */
2507 lpfc_rcv_logo_prli_issue, /* RCV_LOGO */
2508 lpfc_rcv_padisc_prli_issue, /* RCV_ADISC */
2509 lpfc_rcv_padisc_prli_issue, /* RCV_PDISC */
2510 lpfc_rcv_prlo_prli_issue, /* RCV_PRLO */
2511 lpfc_cmpl_plogi_illegal, /* CMPL_PLOGI */
2512 lpfc_cmpl_prli_prli_issue, /* CMPL_PRLI */
2513 lpfc_disc_illegal, /* CMPL_LOGO */
2514 lpfc_disc_illegal, /* CMPL_ADISC */
2515 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2516 lpfc_device_rm_prli_issue, /* DEVICE_RM */
2517 lpfc_device_recov_prli_issue, /* DEVICE_RECOVERY */
2519 lpfc_rcv_plogi_logo_issue, /* RCV_PLOGI LOGO_ISSUE */
2520 lpfc_rcv_prli_logo_issue, /* RCV_PRLI */
2521 lpfc_rcv_logo_logo_issue, /* RCV_LOGO */
2522 lpfc_rcv_padisc_logo_issue, /* RCV_ADISC */
2523 lpfc_rcv_padisc_logo_issue, /* RCV_PDISC */
2524 lpfc_rcv_prlo_logo_issue, /* RCV_PRLO */
2525 lpfc_cmpl_plogi_illegal, /* CMPL_PLOGI */
2526 lpfc_disc_illegal, /* CMPL_PRLI */
2527 lpfc_cmpl_logo_logo_issue, /* CMPL_LOGO */
2528 lpfc_disc_illegal, /* CMPL_ADISC */
2529 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2530 lpfc_device_rm_logo_issue, /* DEVICE_RM */
2531 lpfc_device_recov_logo_issue, /* DEVICE_RECOVERY */
2533 lpfc_rcv_plogi_unmap_node, /* RCV_PLOGI UNMAPPED_NODE */
2534 lpfc_rcv_prli_unmap_node, /* RCV_PRLI */
2535 lpfc_rcv_logo_unmap_node, /* RCV_LOGO */
2536 lpfc_rcv_padisc_unmap_node, /* RCV_ADISC */
2537 lpfc_rcv_padisc_unmap_node, /* RCV_PDISC */
2538 lpfc_rcv_prlo_unmap_node, /* RCV_PRLO */
2539 lpfc_disc_illegal, /* CMPL_PLOGI */
2540 lpfc_disc_illegal, /* CMPL_PRLI */
2541 lpfc_disc_illegal, /* CMPL_LOGO */
2542 lpfc_disc_illegal, /* CMPL_ADISC */
2543 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2544 lpfc_disc_illegal, /* DEVICE_RM */
2545 lpfc_device_recov_unmap_node, /* DEVICE_RECOVERY */
2547 lpfc_rcv_plogi_mapped_node, /* RCV_PLOGI MAPPED_NODE */
2548 lpfc_rcv_prli_mapped_node, /* RCV_PRLI */
2549 lpfc_rcv_logo_mapped_node, /* RCV_LOGO */
2550 lpfc_rcv_padisc_mapped_node, /* RCV_ADISC */
2551 lpfc_rcv_padisc_mapped_node, /* RCV_PDISC */
2552 lpfc_rcv_prlo_mapped_node, /* RCV_PRLO */
2553 lpfc_disc_illegal, /* CMPL_PLOGI */
2554 lpfc_disc_illegal, /* CMPL_PRLI */
2555 lpfc_disc_illegal, /* CMPL_LOGO */
2556 lpfc_disc_illegal, /* CMPL_ADISC */
2557 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2558 lpfc_disc_illegal, /* DEVICE_RM */
2559 lpfc_device_recov_mapped_node, /* DEVICE_RECOVERY */
2561 lpfc_rcv_plogi_npr_node, /* RCV_PLOGI NPR_NODE */
2562 lpfc_rcv_prli_npr_node, /* RCV_PRLI */
2563 lpfc_rcv_logo_npr_node, /* RCV_LOGO */
2564 lpfc_rcv_padisc_npr_node, /* RCV_ADISC */
2565 lpfc_rcv_padisc_npr_node, /* RCV_PDISC */
2566 lpfc_rcv_prlo_npr_node, /* RCV_PRLO */
2567 lpfc_cmpl_plogi_npr_node, /* CMPL_PLOGI */
2568 lpfc_cmpl_prli_npr_node, /* CMPL_PRLI */
2569 lpfc_cmpl_logo_npr_node, /* CMPL_LOGO */
2570 lpfc_cmpl_adisc_npr_node, /* CMPL_ADISC */
2571 lpfc_cmpl_reglogin_npr_node, /* CMPL_REG_LOGIN */
2572 lpfc_device_rm_npr_node, /* DEVICE_RM */
2573 lpfc_device_recov_npr_node, /* DEVICE_RECOVERY */
2577 lpfc_disc_state_machine(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2578 void *arg, uint32_t evt)
2580 uint32_t cur_state, rc;
2581 uint32_t(*func) (struct lpfc_vport *, struct lpfc_nodelist *, void *,
2583 uint32_t got_ndlp = 0;
2585 if (lpfc_nlp_get(ndlp))
2588 cur_state = ndlp->nlp_state;
2590 /* DSM in event <evt> on NPort <nlp_DID> in state <cur_state> */
2591 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2592 "0211 DSM in event x%x on NPort x%x in "
2593 "state %d Data: x%x\n",
2594 evt, ndlp->nlp_DID, cur_state, ndlp->nlp_flag);
2596 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_DSM,
2597 "DSM in: evt:%d ste:%d did:x%x",
2598 evt, cur_state, ndlp->nlp_DID);
2600 func = lpfc_disc_action[(cur_state * NLP_EVT_MAX_EVENT) + evt];
2601 rc = (func) (vport, ndlp, arg, evt);
2603 /* DSM out state <rc> on NPort <nlp_DID> */
2605 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2606 "0212 DSM out state %d on NPort x%x Data: x%x\n",
2607 rc, ndlp->nlp_DID, ndlp->nlp_flag);
2609 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_DSM,
2610 "DSM out: ste:%d did:x%x flg:x%x",
2611 rc, ndlp->nlp_DID, ndlp->nlp_flag);
2612 /* Decrement the ndlp reference count held for this function */
2615 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2616 "0213 DSM out state %d on NPort free\n", rc);
2618 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_DSM,
2619 "DSM out: ste:%d did:x%x flg:x%x",