1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2004-2013 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;
281 struct serv_parm *sp;
286 memset(&stat, 0, sizeof (struct ls_rjt));
287 if (vport->port_state <= LPFC_FDISC) {
288 /* Before responding to PLOGI, check for pt2pt mode.
289 * If we are pt2pt, with an outstanding FLOGI, abort
290 * the FLOGI and resend it first.
292 if (vport->fc_flag & FC_PT2PT) {
293 lpfc_els_abort_flogi(phba);
294 if (!(vport->fc_flag & FC_PT2PT_PLOGI)) {
295 /* If the other side is supposed to initiate
296 * the PLOGI anyway, just ACC it now and
297 * move on with discovery.
299 phba->fc_edtov = FF_DEF_EDTOV;
300 phba->fc_ratov = FF_DEF_RATOV;
301 /* Start discovery - this should just do
303 lpfc_disc_start(vport);
305 lpfc_initial_flogi(vport);
307 stat.un.b.lsRjtRsnCode = LSRJT_LOGICAL_BSY;
308 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
309 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb,
314 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
315 lp = (uint32_t *) pcmd->virt;
316 sp = (struct serv_parm *) ((uint8_t *) lp + sizeof (uint32_t));
317 if (wwn_to_u64(sp->portName.u.wwn) == 0) {
318 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
319 "0140 PLOGI Reject: invalid nname\n");
320 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
321 stat.un.b.lsRjtRsnCodeExp = LSEXP_INVALID_PNAME;
322 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
326 if (wwn_to_u64(sp->nodeName.u.wwn) == 0) {
327 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
328 "0141 PLOGI Reject: invalid pname\n");
329 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
330 stat.un.b.lsRjtRsnCodeExp = LSEXP_INVALID_NNAME;
331 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
335 if ((lpfc_check_sparm(vport, ndlp, sp, CLASS3, 0) == 0)) {
336 /* Reject this request because invalid parameters */
337 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
338 stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
339 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
343 icmd = &cmdiocb->iocb;
345 /* PLOGI chkparm OK */
346 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
347 "0114 PLOGI chkparm OK Data: x%x x%x x%x "
349 ndlp->nlp_DID, ndlp->nlp_state, ndlp->nlp_flag,
350 ndlp->nlp_rpi, vport->port_state,
353 if (vport->cfg_fcp_class == 2 && sp->cls2.classValid)
354 ndlp->nlp_fcp_info |= CLASS2;
356 ndlp->nlp_fcp_info |= CLASS3;
358 ndlp->nlp_class_sup = 0;
359 if (sp->cls1.classValid)
360 ndlp->nlp_class_sup |= FC_COS_CLASS1;
361 if (sp->cls2.classValid)
362 ndlp->nlp_class_sup |= FC_COS_CLASS2;
363 if (sp->cls3.classValid)
364 ndlp->nlp_class_sup |= FC_COS_CLASS3;
365 if (sp->cls4.classValid)
366 ndlp->nlp_class_sup |= FC_COS_CLASS4;
368 ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) | sp->cmn.bbRcvSizeLsb;
370 /* no need to reg_login if we are already in one of these states */
371 switch (ndlp->nlp_state) {
372 case NLP_STE_NPR_NODE:
373 if (!(ndlp->nlp_flag & NLP_NPR_ADISC))
375 case NLP_STE_REG_LOGIN_ISSUE:
376 case NLP_STE_PRLI_ISSUE:
377 case NLP_STE_UNMAPPED_NODE:
378 case NLP_STE_MAPPED_NODE:
379 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp, NULL);
383 /* Check for Nport to NPort pt2pt protocol */
384 if ((vport->fc_flag & FC_PT2PT) &&
385 !(vport->fc_flag & FC_PT2PT_PLOGI)) {
387 /* rcv'ed PLOGI decides what our NPortId will be */
388 vport->fc_myDID = icmd->un.rcvels.parmRo;
389 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
392 lpfc_config_link(phba, mbox);
393 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
395 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
396 if (rc == MBX_NOT_FINISHED) {
397 mempool_free(mbox, phba->mbox_mem_pool);
401 * For SLI4, the VFI/VPI are registered AFTER the
402 * Nport with the higher WWPN sends us a PLOGI with
403 * our assigned NPortId.
405 if (phba->sli_rev == LPFC_SLI_REV4)
406 lpfc_issue_reg_vfi(vport);
408 lpfc_can_disctmo(vport);
410 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
414 /* Registering an existing RPI behaves differently for SLI3 vs SLI4 */
415 if (phba->sli_rev == LPFC_SLI_REV4)
416 lpfc_unreg_rpi(vport, ndlp);
418 rc = lpfc_reg_rpi(phba, vport->vpi, icmd->un.rcvels.remoteID,
419 (uint8_t *) sp, mbox, ndlp->nlp_rpi);
421 mempool_free(mbox, phba->mbox_mem_pool);
425 /* ACC PLOGI rsp command needs to execute first,
426 * queue this mbox command to be processed later.
428 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
430 * mbox->context2 = lpfc_nlp_get(ndlp) deferred until mailbox
431 * command issued in lpfc_cmpl_els_acc().
434 spin_lock_irq(shost->host_lock);
435 ndlp->nlp_flag |= (NLP_ACC_REGLOGIN | NLP_RCV_PLOGI);
436 spin_unlock_irq(shost->host_lock);
439 * If there is an outstanding PLOGI issued, abort it before
440 * sending ACC rsp for received PLOGI. If pending plogi
441 * is not canceled here, the plogi will be rejected by
442 * remote port and will be retried. On a configuration with
443 * single discovery thread, this will cause a huge delay in
444 * discovery. Also this will cause multiple state machines
445 * running in parallel for this node.
447 if (ndlp->nlp_state == NLP_STE_PLOGI_ISSUE) {
448 /* software abort outstanding PLOGI */
449 lpfc_els_abort(phba, ndlp);
452 if ((vport->port_type == LPFC_NPIV_PORT &&
453 vport->cfg_restrict_login)) {
455 /* In order to preserve RPIs, we want to cleanup
456 * the default RPI the firmware created to rcv
457 * this ELS request. The only way to do this is
458 * to register, then unregister the RPI.
460 spin_lock_irq(shost->host_lock);
461 ndlp->nlp_flag |= NLP_RM_DFLT_RPI;
462 spin_unlock_irq(shost->host_lock);
463 stat.un.b.lsRjtRsnCode = LSRJT_INVALID_CMD;
464 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
465 rc = lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb,
468 mempool_free(mbox, phba->mbox_mem_pool);
471 rc = lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp, mbox);
473 mempool_free(mbox, phba->mbox_mem_pool);
476 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
477 stat.un.b.lsRjtRsnCodeExp = LSEXP_OUT_OF_RESOURCE;
478 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
483 * lpfc_mbx_cmpl_resume_rpi - Resume RPI completion routine
484 * @phba: pointer to lpfc hba data structure.
485 * @mboxq: pointer to mailbox object
487 * This routine is invoked to issue a completion to a rcv'ed
488 * ADISC or PDISC after the paused RPI has been resumed.
491 lpfc_mbx_cmpl_resume_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
493 struct lpfc_vport *vport;
494 struct lpfc_iocbq *elsiocb;
495 struct lpfc_nodelist *ndlp;
498 elsiocb = (struct lpfc_iocbq *)mboxq->context1;
499 ndlp = (struct lpfc_nodelist *) mboxq->context2;
500 vport = mboxq->vport;
501 cmd = elsiocb->drvrTimeout;
503 if (cmd == ELS_CMD_ADISC) {
504 lpfc_els_rsp_adisc_acc(vport, elsiocb, ndlp);
506 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, elsiocb,
510 mempool_free(mboxq, phba->mbox_mem_pool);
514 lpfc_rcv_padisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
515 struct lpfc_iocbq *cmdiocb)
517 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
518 struct lpfc_iocbq *elsiocb;
519 struct lpfc_dmabuf *pcmd;
520 struct serv_parm *sp;
521 struct lpfc_name *pnn, *ppn;
528 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
529 lp = (uint32_t *) pcmd->virt;
532 if (cmd == ELS_CMD_ADISC) {
534 pnn = (struct lpfc_name *) & ap->nodeName;
535 ppn = (struct lpfc_name *) & ap->portName;
537 sp = (struct serv_parm *) lp;
538 pnn = (struct lpfc_name *) & sp->nodeName;
539 ppn = (struct lpfc_name *) & sp->portName;
542 icmd = &cmdiocb->iocb;
543 if (icmd->ulpStatus == 0 && lpfc_check_adisc(vport, ndlp, pnn, ppn)) {
546 * As soon as we send ACC, the remote NPort can
547 * start sending us data. Thus, for SLI4 we must
548 * resume the RPI before the ACC goes out.
550 if (vport->phba->sli_rev == LPFC_SLI_REV4) {
551 elsiocb = kmalloc(sizeof(struct lpfc_iocbq),
555 /* Save info from cmd IOCB used in rsp */
556 memcpy((uint8_t *)elsiocb, (uint8_t *)cmdiocb,
557 sizeof(struct lpfc_iocbq));
559 /* Save the ELS cmd */
560 elsiocb->drvrTimeout = cmd;
562 lpfc_sli4_resume_rpi(ndlp,
563 lpfc_mbx_cmpl_resume_rpi, elsiocb);
568 if (cmd == ELS_CMD_ADISC) {
569 lpfc_els_rsp_adisc_acc(vport, cmdiocb, ndlp);
571 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb,
575 /* If we are authenticated, move to the proper state */
576 if (ndlp->nlp_type & NLP_FCP_TARGET)
577 lpfc_nlp_set_state(vport, ndlp, NLP_STE_MAPPED_NODE);
579 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
583 /* Reject this request because invalid parameters */
584 stat.un.b.lsRjtRsvd0 = 0;
585 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
586 stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
587 stat.un.b.vendorUnique = 0;
588 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
591 mod_timer(&ndlp->nlp_delayfunc, jiffies + msecs_to_jiffies(1000));
593 spin_lock_irq(shost->host_lock);
594 ndlp->nlp_flag |= NLP_DELAY_TMO;
595 spin_unlock_irq(shost->host_lock);
596 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
597 ndlp->nlp_prev_state = ndlp->nlp_state;
598 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
603 lpfc_rcv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
604 struct lpfc_iocbq *cmdiocb, uint32_t els_cmd)
606 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
607 struct lpfc_hba *phba = vport->phba;
608 struct lpfc_vport **vports;
609 int i, active_vlink_present = 0 ;
611 /* Put ndlp in NPR state with 1 sec timeout for plogi, ACC logo */
612 /* Only call LOGO ACC for first LOGO, this avoids sending unnecessary
613 * PLOGIs during LOGO storms from a device.
615 spin_lock_irq(shost->host_lock);
616 ndlp->nlp_flag |= NLP_LOGO_ACC;
617 spin_unlock_irq(shost->host_lock);
618 if (els_cmd == ELS_CMD_PRLO)
619 lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL);
621 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
622 if (ndlp->nlp_DID == Fabric_DID) {
623 if (vport->port_state <= LPFC_FDISC)
625 lpfc_linkdown_port(vport);
626 spin_lock_irq(shost->host_lock);
627 vport->fc_flag |= FC_VPORT_LOGO_RCVD;
628 spin_unlock_irq(shost->host_lock);
629 vports = lpfc_create_vport_work_array(phba);
631 for (i = 0; i <= phba->max_vports && vports[i] != NULL;
633 if ((!(vports[i]->fc_flag &
634 FC_VPORT_LOGO_RCVD)) &&
635 (vports[i]->port_state > LPFC_FDISC)) {
636 active_vlink_present = 1;
640 lpfc_destroy_vport_work_array(phba, vports);
643 if (active_vlink_present) {
645 * If there are other active VLinks present,
646 * re-instantiate the Vlink using FDISC.
648 mod_timer(&ndlp->nlp_delayfunc,
649 jiffies + msecs_to_jiffies(1000));
650 spin_lock_irq(shost->host_lock);
651 ndlp->nlp_flag |= NLP_DELAY_TMO;
652 spin_unlock_irq(shost->host_lock);
653 ndlp->nlp_last_elscmd = ELS_CMD_FDISC;
654 vport->port_state = LPFC_FDISC;
656 spin_lock_irq(shost->host_lock);
657 phba->pport->fc_flag &= ~FC_LOGO_RCVD_DID_CHNG;
658 spin_unlock_irq(shost->host_lock);
659 lpfc_retry_pport_discovery(phba);
661 } else if ((!(ndlp->nlp_type & NLP_FABRIC) &&
662 ((ndlp->nlp_type & NLP_FCP_TARGET) ||
663 !(ndlp->nlp_type & NLP_FCP_INITIATOR))) ||
664 (ndlp->nlp_state == NLP_STE_ADISC_ISSUE)) {
665 /* Only try to re-login if this is NOT a Fabric Node */
666 mod_timer(&ndlp->nlp_delayfunc,
667 jiffies + msecs_to_jiffies(1000 * 1));
668 spin_lock_irq(shost->host_lock);
669 ndlp->nlp_flag |= NLP_DELAY_TMO;
670 spin_unlock_irq(shost->host_lock);
672 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
675 ndlp->nlp_prev_state = ndlp->nlp_state;
676 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
678 spin_lock_irq(shost->host_lock);
679 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
680 spin_unlock_irq(shost->host_lock);
681 /* The driver has to wait until the ACC completes before it continues
682 * processing the LOGO. The action will resume in
683 * lpfc_cmpl_els_logo_acc routine. Since part of processing includes an
684 * unreg_login, the driver waits so the ACC does not get aborted.
690 lpfc_rcv_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
691 struct lpfc_iocbq *cmdiocb)
693 struct lpfc_dmabuf *pcmd;
696 struct fc_rport *rport = ndlp->rport;
699 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
700 lp = (uint32_t *) pcmd->virt;
701 npr = (PRLI *) ((uint8_t *) lp + sizeof (uint32_t));
703 ndlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR);
704 ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
705 ndlp->nlp_flag &= ~NLP_FIRSTBURST;
706 if (npr->prliType == PRLI_FCP_TYPE) {
707 if (npr->initiatorFunc)
708 ndlp->nlp_type |= NLP_FCP_INITIATOR;
709 if (npr->targetFunc) {
710 ndlp->nlp_type |= NLP_FCP_TARGET;
711 if (npr->writeXferRdyDis)
712 ndlp->nlp_flag |= NLP_FIRSTBURST;
715 ndlp->nlp_fcp_info |= NLP_FCP_2_DEVICE;
718 /* We need to update the rport role values */
719 roles = FC_RPORT_ROLE_UNKNOWN;
720 if (ndlp->nlp_type & NLP_FCP_INITIATOR)
721 roles |= FC_RPORT_ROLE_FCP_INITIATOR;
722 if (ndlp->nlp_type & NLP_FCP_TARGET)
723 roles |= FC_RPORT_ROLE_FCP_TARGET;
725 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
726 "rport rolechg: role:x%x did:x%x flg:x%x",
727 roles, ndlp->nlp_DID, ndlp->nlp_flag);
729 fc_remote_port_rolechg(rport, roles);
734 lpfc_disc_set_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
736 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
738 if (!(ndlp->nlp_flag & NLP_RPI_REGISTERED)) {
739 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
743 if (!(vport->fc_flag & FC_PT2PT)) {
744 /* Check config parameter use-adisc or FCP-2 */
745 if ((vport->cfg_use_adisc && (vport->fc_flag & FC_RSCN_MODE)) ||
746 ((ndlp->nlp_fcp_info & NLP_FCP_2_DEVICE) &&
747 (ndlp->nlp_type & NLP_FCP_TARGET))) {
748 spin_lock_irq(shost->host_lock);
749 ndlp->nlp_flag |= NLP_NPR_ADISC;
750 spin_unlock_irq(shost->host_lock);
754 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
755 lpfc_unreg_rpi(vport, ndlp);
760 * lpfc_release_rpi - Release a RPI by issuing unreg_login mailbox cmd.
761 * @phba : Pointer to lpfc_hba structure.
762 * @vport: Pointer to lpfc_vport structure.
763 * @rpi : rpi to be release.
765 * This function will send a unreg_login mailbox command to the firmware
769 lpfc_release_rpi(struct lpfc_hba *phba,
770 struct lpfc_vport *vport,
776 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
779 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
780 "2796 mailbox memory allocation failed \n");
782 lpfc_unreg_login(phba, vport->vpi, rpi, pmb);
783 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
784 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
785 if (rc == MBX_NOT_FINISHED)
786 mempool_free(pmb, phba->mbox_mem_pool);
791 lpfc_disc_illegal(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
792 void *arg, uint32_t evt)
794 struct lpfc_hba *phba;
795 LPFC_MBOXQ_t *pmb = (LPFC_MBOXQ_t *) arg;
800 /* Release the RPI if reglogin completing */
801 if (!(phba->pport->load_flag & FC_UNLOADING) &&
802 (evt == NLP_EVT_CMPL_REG_LOGIN) &&
803 (!pmb->u.mb.mbxStatus)) {
805 rpi = pmb->u.mb.un.varWords[0];
806 lpfc_release_rpi(phba, vport, rpi);
808 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
809 "0271 Illegal State Transition: node x%x "
810 "event x%x, state x%x Data: x%x x%x\n",
811 ndlp->nlp_DID, evt, ndlp->nlp_state, ndlp->nlp_rpi,
813 return ndlp->nlp_state;
817 lpfc_cmpl_plogi_illegal(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
818 void *arg, uint32_t evt)
820 /* This transition is only legal if we previously
821 * rcv'ed a PLOGI. Since we don't want 2 discovery threads
822 * working on the same NPortID, do nothing for this thread
825 if (!(ndlp->nlp_flag & NLP_RCV_PLOGI)) {
826 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
827 "0272 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,
832 return ndlp->nlp_state;
835 /* Start of Discovery State Machine routines */
838 lpfc_rcv_plogi_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
839 void *arg, uint32_t evt)
841 struct lpfc_iocbq *cmdiocb;
843 cmdiocb = (struct lpfc_iocbq *) arg;
845 if (lpfc_rcv_plogi(vport, ndlp, cmdiocb)) {
846 return ndlp->nlp_state;
848 return NLP_STE_FREED_NODE;
852 lpfc_rcv_els_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
853 void *arg, uint32_t evt)
855 lpfc_issue_els_logo(vport, ndlp, 0);
856 return ndlp->nlp_state;
860 lpfc_rcv_logo_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
861 void *arg, uint32_t evt)
863 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
864 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
866 spin_lock_irq(shost->host_lock);
867 ndlp->nlp_flag |= NLP_LOGO_ACC;
868 spin_unlock_irq(shost->host_lock);
869 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
871 return ndlp->nlp_state;
875 lpfc_cmpl_logo_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
876 void *arg, uint32_t evt)
878 return NLP_STE_FREED_NODE;
882 lpfc_device_rm_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
883 void *arg, uint32_t evt)
885 return NLP_STE_FREED_NODE;
889 lpfc_device_recov_unused_node(struct lpfc_vport *vport,
890 struct lpfc_nodelist *ndlp,
891 void *arg, uint32_t evt)
893 return ndlp->nlp_state;
897 lpfc_rcv_plogi_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
898 void *arg, uint32_t evt)
900 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
901 struct lpfc_hba *phba = vport->phba;
902 struct lpfc_iocbq *cmdiocb = arg;
903 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
904 uint32_t *lp = (uint32_t *) pcmd->virt;
905 struct serv_parm *sp = (struct serv_parm *) (lp + 1);
909 memset(&stat, 0, sizeof (struct ls_rjt));
911 /* For a PLOGI, we only accept if our portname is less
912 * than the remote portname.
914 phba->fc_stat.elsLogiCol++;
915 port_cmp = memcmp(&vport->fc_portname, &sp->portName,
916 sizeof(struct lpfc_name));
919 /* Reject this request because the remote node will accept
921 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
922 stat.un.b.lsRjtRsnCodeExp = LSEXP_CMD_IN_PROGRESS;
923 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
926 if (lpfc_rcv_plogi(vport, ndlp, cmdiocb) &&
927 (ndlp->nlp_flag & NLP_NPR_2B_DISC) &&
928 (vport->num_disc_nodes)) {
929 spin_lock_irq(shost->host_lock);
930 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
931 spin_unlock_irq(shost->host_lock);
932 /* Check if there are more PLOGIs to be sent */
933 lpfc_more_plogi(vport);
934 if (vport->num_disc_nodes == 0) {
935 spin_lock_irq(shost->host_lock);
936 vport->fc_flag &= ~FC_NDISC_ACTIVE;
937 spin_unlock_irq(shost->host_lock);
938 lpfc_can_disctmo(vport);
939 lpfc_end_rscn(vport);
942 } /* If our portname was less */
944 return ndlp->nlp_state;
948 lpfc_rcv_prli_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
949 void *arg, uint32_t evt)
951 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
954 memset(&stat, 0, sizeof (struct ls_rjt));
955 stat.un.b.lsRjtRsnCode = LSRJT_LOGICAL_BSY;
956 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
957 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
958 return ndlp->nlp_state;
962 lpfc_rcv_logo_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
963 void *arg, uint32_t evt)
965 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
967 /* software abort outstanding PLOGI */
968 lpfc_els_abort(vport->phba, ndlp);
970 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
971 return ndlp->nlp_state;
975 lpfc_rcv_els_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
976 void *arg, uint32_t evt)
978 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
979 struct lpfc_hba *phba = vport->phba;
980 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
982 /* software abort outstanding PLOGI */
983 lpfc_els_abort(phba, ndlp);
985 if (evt == NLP_EVT_RCV_LOGO) {
986 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
988 lpfc_issue_els_logo(vport, ndlp, 0);
991 /* Put ndlp in npr state set plogi timer for 1 sec */
992 mod_timer(&ndlp->nlp_delayfunc, jiffies + msecs_to_jiffies(1000 * 1));
993 spin_lock_irq(shost->host_lock);
994 ndlp->nlp_flag |= NLP_DELAY_TMO;
995 spin_unlock_irq(shost->host_lock);
996 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
997 ndlp->nlp_prev_state = NLP_STE_PLOGI_ISSUE;
998 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1000 return ndlp->nlp_state;
1004 lpfc_cmpl_plogi_plogi_issue(struct lpfc_vport *vport,
1005 struct lpfc_nodelist *ndlp,
1009 struct lpfc_hba *phba = vport->phba;
1010 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1011 struct lpfc_iocbq *cmdiocb, *rspiocb;
1012 struct lpfc_dmabuf *pcmd, *prsp, *mp;
1015 struct serv_parm *sp;
1018 cmdiocb = (struct lpfc_iocbq *) arg;
1019 rspiocb = cmdiocb->context_un.rsp_iocb;
1021 if (ndlp->nlp_flag & NLP_ACC_REGLOGIN) {
1022 /* Recovery from PLOGI collision logic */
1023 return ndlp->nlp_state;
1026 irsp = &rspiocb->iocb;
1028 if (irsp->ulpStatus)
1031 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
1033 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
1035 lp = (uint32_t *) prsp->virt;
1036 sp = (struct serv_parm *) ((uint8_t *) lp + sizeof (uint32_t));
1038 /* Some switches have FDMI servers returning 0 for WWN */
1039 if ((ndlp->nlp_DID != FDMI_DID) &&
1040 (wwn_to_u64(sp->portName.u.wwn) == 0 ||
1041 wwn_to_u64(sp->nodeName.u.wwn) == 0)) {
1042 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1043 "0142 PLOGI RSP: Invalid WWN.\n");
1046 if (!lpfc_check_sparm(vport, ndlp, sp, CLASS3, 0))
1048 /* PLOGI chkparm OK */
1049 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1050 "0121 PLOGI chkparm OK Data: x%x x%x x%x x%x\n",
1051 ndlp->nlp_DID, ndlp->nlp_state,
1052 ndlp->nlp_flag, ndlp->nlp_rpi);
1053 if (vport->cfg_fcp_class == 2 && (sp->cls2.classValid))
1054 ndlp->nlp_fcp_info |= CLASS2;
1056 ndlp->nlp_fcp_info |= CLASS3;
1058 ndlp->nlp_class_sup = 0;
1059 if (sp->cls1.classValid)
1060 ndlp->nlp_class_sup |= FC_COS_CLASS1;
1061 if (sp->cls2.classValid)
1062 ndlp->nlp_class_sup |= FC_COS_CLASS2;
1063 if (sp->cls3.classValid)
1064 ndlp->nlp_class_sup |= FC_COS_CLASS3;
1065 if (sp->cls4.classValid)
1066 ndlp->nlp_class_sup |= FC_COS_CLASS4;
1067 ndlp->nlp_maxframe =
1068 ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) | sp->cmn.bbRcvSizeLsb;
1070 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1072 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1073 "0133 PLOGI: no memory for reg_login "
1074 "Data: x%x x%x x%x x%x\n",
1075 ndlp->nlp_DID, ndlp->nlp_state,
1076 ndlp->nlp_flag, ndlp->nlp_rpi);
1080 lpfc_unreg_rpi(vport, ndlp);
1082 if (lpfc_reg_rpi(phba, vport->vpi, irsp->un.elsreq64.remoteID,
1083 (uint8_t *) sp, mbox, ndlp->nlp_rpi) == 0) {
1084 switch (ndlp->nlp_DID) {
1085 case NameServer_DID:
1086 mbox->mbox_cmpl = lpfc_mbx_cmpl_ns_reg_login;
1089 mbox->mbox_cmpl = lpfc_mbx_cmpl_fdmi_reg_login;
1092 ndlp->nlp_flag |= NLP_REG_LOGIN_SEND;
1093 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
1095 mbox->context2 = lpfc_nlp_get(ndlp);
1096 mbox->vport = vport;
1097 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
1098 != MBX_NOT_FINISHED) {
1099 lpfc_nlp_set_state(vport, ndlp,
1100 NLP_STE_REG_LOGIN_ISSUE);
1101 return ndlp->nlp_state;
1103 if (ndlp->nlp_flag & NLP_REG_LOGIN_SEND)
1104 ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND;
1105 /* decrement node reference count to the failed mbox
1109 mp = (struct lpfc_dmabuf *) mbox->context1;
1110 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1112 mempool_free(mbox, phba->mbox_mem_pool);
1114 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1115 "0134 PLOGI: cannot issue reg_login "
1116 "Data: x%x x%x x%x x%x\n",
1117 ndlp->nlp_DID, ndlp->nlp_state,
1118 ndlp->nlp_flag, ndlp->nlp_rpi);
1120 mempool_free(mbox, phba->mbox_mem_pool);
1122 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1123 "0135 PLOGI: cannot format reg_login "
1124 "Data: x%x x%x x%x x%x\n",
1125 ndlp->nlp_DID, ndlp->nlp_state,
1126 ndlp->nlp_flag, ndlp->nlp_rpi);
1131 if (ndlp->nlp_DID == NameServer_DID) {
1132 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
1133 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1134 "0261 Cannot Register NameServer login\n");
1138 ** In case the node reference counter does not go to zero, ensure that
1139 ** the stale state for the node is not processed.
1142 ndlp->nlp_prev_state = ndlp->nlp_state;
1143 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1144 spin_lock_irq(shost->host_lock);
1145 ndlp->nlp_flag |= NLP_DEFER_RM;
1146 spin_unlock_irq(shost->host_lock);
1147 return NLP_STE_FREED_NODE;
1151 lpfc_cmpl_logo_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1152 void *arg, uint32_t evt)
1154 return ndlp->nlp_state;
1158 lpfc_cmpl_reglogin_plogi_issue(struct lpfc_vport *vport,
1159 struct lpfc_nodelist *ndlp, void *arg, uint32_t evt)
1161 struct lpfc_hba *phba;
1162 LPFC_MBOXQ_t *pmb = (LPFC_MBOXQ_t *) arg;
1163 MAILBOX_t *mb = &pmb->u.mb;
1167 /* Release the RPI */
1168 if (!(phba->pport->load_flag & FC_UNLOADING) &&
1170 rpi = pmb->u.mb.un.varWords[0];
1171 lpfc_release_rpi(phba, vport, rpi);
1173 return ndlp->nlp_state;
1177 lpfc_device_rm_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1178 void *arg, uint32_t evt)
1180 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1182 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1183 spin_lock_irq(shost->host_lock);
1184 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
1185 spin_unlock_irq(shost->host_lock);
1186 return ndlp->nlp_state;
1188 /* software abort outstanding PLOGI */
1189 lpfc_els_abort(vport->phba, ndlp);
1191 lpfc_drop_node(vport, ndlp);
1192 return NLP_STE_FREED_NODE;
1197 lpfc_device_recov_plogi_issue(struct lpfc_vport *vport,
1198 struct lpfc_nodelist *ndlp,
1202 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1203 struct lpfc_hba *phba = vport->phba;
1205 /* Don't do anything that will mess up processing of the
1208 if (vport->fc_flag & FC_RSCN_DEFERRED)
1209 return ndlp->nlp_state;
1211 /* software abort outstanding PLOGI */
1212 lpfc_els_abort(phba, ndlp);
1214 ndlp->nlp_prev_state = NLP_STE_PLOGI_ISSUE;
1215 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1216 spin_lock_irq(shost->host_lock);
1217 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
1218 spin_unlock_irq(shost->host_lock);
1220 return ndlp->nlp_state;
1224 lpfc_rcv_plogi_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1225 void *arg, uint32_t evt)
1227 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1228 struct lpfc_hba *phba = vport->phba;
1229 struct lpfc_iocbq *cmdiocb;
1231 /* software abort outstanding ADISC */
1232 lpfc_els_abort(phba, ndlp);
1234 cmdiocb = (struct lpfc_iocbq *) arg;
1236 if (lpfc_rcv_plogi(vport, ndlp, cmdiocb)) {
1237 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1238 spin_lock_irq(shost->host_lock);
1239 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
1240 spin_unlock_irq(shost->host_lock);
1241 if (vport->num_disc_nodes)
1242 lpfc_more_adisc(vport);
1244 return ndlp->nlp_state;
1246 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
1247 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
1248 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
1250 return ndlp->nlp_state;
1254 lpfc_rcv_prli_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1255 void *arg, uint32_t evt)
1257 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1259 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
1260 return ndlp->nlp_state;
1264 lpfc_rcv_logo_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1265 void *arg, uint32_t evt)
1267 struct lpfc_hba *phba = vport->phba;
1268 struct lpfc_iocbq *cmdiocb;
1270 cmdiocb = (struct lpfc_iocbq *) arg;
1272 /* software abort outstanding ADISC */
1273 lpfc_els_abort(phba, ndlp);
1275 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
1276 return ndlp->nlp_state;
1280 lpfc_rcv_padisc_adisc_issue(struct lpfc_vport *vport,
1281 struct lpfc_nodelist *ndlp,
1282 void *arg, uint32_t evt)
1284 struct lpfc_iocbq *cmdiocb;
1286 cmdiocb = (struct lpfc_iocbq *) arg;
1288 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
1289 return ndlp->nlp_state;
1293 lpfc_rcv_prlo_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1294 void *arg, uint32_t evt)
1296 struct lpfc_iocbq *cmdiocb;
1298 cmdiocb = (struct lpfc_iocbq *) arg;
1300 /* Treat like rcv logo */
1301 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_PRLO);
1302 return ndlp->nlp_state;
1306 lpfc_cmpl_adisc_adisc_issue(struct lpfc_vport *vport,
1307 struct lpfc_nodelist *ndlp,
1308 void *arg, uint32_t evt)
1310 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1311 struct lpfc_hba *phba = vport->phba;
1312 struct lpfc_iocbq *cmdiocb, *rspiocb;
1317 cmdiocb = (struct lpfc_iocbq *) arg;
1318 rspiocb = cmdiocb->context_un.rsp_iocb;
1320 ap = (ADISC *)lpfc_check_elscmpl_iocb(phba, cmdiocb, rspiocb);
1321 irsp = &rspiocb->iocb;
1323 if ((irsp->ulpStatus) ||
1324 (!lpfc_check_adisc(vport, ndlp, &ap->nodeName, &ap->portName))) {
1326 mod_timer(&ndlp->nlp_delayfunc,
1327 jiffies + msecs_to_jiffies(1000));
1328 spin_lock_irq(shost->host_lock);
1329 ndlp->nlp_flag |= NLP_DELAY_TMO;
1330 spin_unlock_irq(shost->host_lock);
1331 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
1333 memset(&ndlp->nlp_nodename, 0, sizeof(struct lpfc_name));
1334 memset(&ndlp->nlp_portname, 0, sizeof(struct lpfc_name));
1336 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
1337 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1338 lpfc_unreg_rpi(vport, ndlp);
1339 return ndlp->nlp_state;
1342 if (phba->sli_rev == LPFC_SLI_REV4) {
1343 rc = lpfc_sli4_resume_rpi(ndlp, NULL, NULL);
1345 /* Stay in state and retry. */
1346 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
1347 return ndlp->nlp_state;
1351 if (ndlp->nlp_type & NLP_FCP_TARGET) {
1352 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
1353 lpfc_nlp_set_state(vport, ndlp, NLP_STE_MAPPED_NODE);
1355 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
1356 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
1359 return ndlp->nlp_state;
1363 lpfc_device_rm_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1364 void *arg, uint32_t evt)
1366 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1368 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1369 spin_lock_irq(shost->host_lock);
1370 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
1371 spin_unlock_irq(shost->host_lock);
1372 return ndlp->nlp_state;
1374 /* software abort outstanding ADISC */
1375 lpfc_els_abort(vport->phba, ndlp);
1377 lpfc_drop_node(vport, ndlp);
1378 return NLP_STE_FREED_NODE;
1383 lpfc_device_recov_adisc_issue(struct lpfc_vport *vport,
1384 struct lpfc_nodelist *ndlp,
1388 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1389 struct lpfc_hba *phba = vport->phba;
1391 /* Don't do anything that will mess up processing of the
1394 if (vport->fc_flag & FC_RSCN_DEFERRED)
1395 return ndlp->nlp_state;
1397 /* software abort outstanding ADISC */
1398 lpfc_els_abort(phba, ndlp);
1400 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
1401 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1402 spin_lock_irq(shost->host_lock);
1403 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
1404 spin_unlock_irq(shost->host_lock);
1405 lpfc_disc_set_adisc(vport, ndlp);
1406 return ndlp->nlp_state;
1410 lpfc_rcv_plogi_reglogin_issue(struct lpfc_vport *vport,
1411 struct lpfc_nodelist *ndlp,
1415 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1417 lpfc_rcv_plogi(vport, ndlp, cmdiocb);
1418 return ndlp->nlp_state;
1422 lpfc_rcv_prli_reglogin_issue(struct lpfc_vport *vport,
1423 struct lpfc_nodelist *ndlp,
1427 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1429 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
1430 return ndlp->nlp_state;
1434 lpfc_rcv_logo_reglogin_issue(struct lpfc_vport *vport,
1435 struct lpfc_nodelist *ndlp,
1439 struct lpfc_hba *phba = vport->phba;
1440 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1442 LPFC_MBOXQ_t *nextmb;
1443 struct lpfc_dmabuf *mp;
1445 cmdiocb = (struct lpfc_iocbq *) arg;
1447 /* cleanup any ndlp on mbox q waiting for reglogin cmpl */
1448 if ((mb = phba->sli.mbox_active)) {
1449 if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) &&
1450 (ndlp == (struct lpfc_nodelist *) mb->context2)) {
1452 mb->context2 = NULL;
1453 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1457 spin_lock_irq(&phba->hbalock);
1458 list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) {
1459 if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) &&
1460 (ndlp == (struct lpfc_nodelist *) mb->context2)) {
1461 mp = (struct lpfc_dmabuf *) (mb->context1);
1463 __lpfc_mbuf_free(phba, mp->virt, mp->phys);
1467 list_del(&mb->list);
1468 phba->sli.mboxq_cnt--;
1469 mempool_free(mb, phba->mbox_mem_pool);
1472 spin_unlock_irq(&phba->hbalock);
1474 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
1475 return ndlp->nlp_state;
1479 lpfc_rcv_padisc_reglogin_issue(struct lpfc_vport *vport,
1480 struct lpfc_nodelist *ndlp,
1484 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1486 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
1487 return ndlp->nlp_state;
1491 lpfc_rcv_prlo_reglogin_issue(struct lpfc_vport *vport,
1492 struct lpfc_nodelist *ndlp,
1496 struct lpfc_iocbq *cmdiocb;
1498 cmdiocb = (struct lpfc_iocbq *) arg;
1499 lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL);
1500 return ndlp->nlp_state;
1504 lpfc_cmpl_reglogin_reglogin_issue(struct lpfc_vport *vport,
1505 struct lpfc_nodelist *ndlp,
1509 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1510 LPFC_MBOXQ_t *pmb = (LPFC_MBOXQ_t *) arg;
1511 MAILBOX_t *mb = &pmb->u.mb;
1512 uint32_t did = mb->un.varWords[1];
1514 if (mb->mbxStatus) {
1515 /* RegLogin failed */
1516 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
1517 "0246 RegLogin failed Data: x%x x%x x%x x%x "
1519 did, mb->mbxStatus, vport->port_state,
1520 mb->un.varRegLogin.vpi,
1521 mb->un.varRegLogin.rpi);
1523 * If RegLogin failed due to lack of HBA resources do not
1526 if (mb->mbxStatus == MBXERR_RPI_FULL) {
1527 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
1528 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1529 return ndlp->nlp_state;
1532 /* Put ndlp in npr state set plogi timer for 1 sec */
1533 mod_timer(&ndlp->nlp_delayfunc,
1534 jiffies + msecs_to_jiffies(1000 * 1));
1535 spin_lock_irq(shost->host_lock);
1536 ndlp->nlp_flag |= NLP_DELAY_TMO;
1537 spin_unlock_irq(shost->host_lock);
1538 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
1540 lpfc_issue_els_logo(vport, ndlp, 0);
1541 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
1542 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1543 return ndlp->nlp_state;
1546 /* SLI4 ports have preallocated logical rpis. */
1547 if (vport->phba->sli_rev < LPFC_SLI_REV4)
1548 ndlp->nlp_rpi = mb->un.varWords[0];
1550 ndlp->nlp_flag |= NLP_RPI_REGISTERED;
1552 /* Only if we are not a fabric nport do we issue PRLI */
1553 if (!(ndlp->nlp_type & NLP_FABRIC)) {
1554 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
1555 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
1556 lpfc_issue_els_prli(vport, ndlp, 0);
1558 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
1559 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
1561 return ndlp->nlp_state;
1565 lpfc_device_rm_reglogin_issue(struct lpfc_vport *vport,
1566 struct lpfc_nodelist *ndlp,
1570 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1572 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1573 spin_lock_irq(shost->host_lock);
1574 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
1575 spin_unlock_irq(shost->host_lock);
1576 return ndlp->nlp_state;
1578 lpfc_drop_node(vport, ndlp);
1579 return NLP_STE_FREED_NODE;
1584 lpfc_device_recov_reglogin_issue(struct lpfc_vport *vport,
1585 struct lpfc_nodelist *ndlp,
1589 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1591 /* Don't do anything that will mess up processing of the
1594 if (vport->fc_flag & FC_RSCN_DEFERRED)
1595 return ndlp->nlp_state;
1597 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
1598 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1599 spin_lock_irq(shost->host_lock);
1600 ndlp->nlp_flag |= NLP_IGNR_REG_CMPL;
1601 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
1602 spin_unlock_irq(shost->host_lock);
1603 lpfc_disc_set_adisc(vport, ndlp);
1604 return ndlp->nlp_state;
1608 lpfc_rcv_plogi_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1609 void *arg, uint32_t evt)
1611 struct lpfc_iocbq *cmdiocb;
1613 cmdiocb = (struct lpfc_iocbq *) arg;
1615 lpfc_rcv_plogi(vport, ndlp, cmdiocb);
1616 return ndlp->nlp_state;
1620 lpfc_rcv_prli_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1621 void *arg, uint32_t evt)
1623 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1625 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
1626 return ndlp->nlp_state;
1630 lpfc_rcv_logo_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1631 void *arg, uint32_t evt)
1633 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1635 /* Software abort outstanding PRLI before sending acc */
1636 lpfc_els_abort(vport->phba, ndlp);
1638 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
1639 return ndlp->nlp_state;
1643 lpfc_rcv_padisc_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1644 void *arg, uint32_t evt)
1646 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1648 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
1649 return ndlp->nlp_state;
1652 /* This routine is envoked when we rcv a PRLO request from a nport
1653 * we are logged into. We should send back a PRLO rsp setting the
1655 * NEXT STATE = PRLI_ISSUE
1658 lpfc_rcv_prlo_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1659 void *arg, uint32_t evt)
1661 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1663 lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL);
1664 return ndlp->nlp_state;
1668 lpfc_cmpl_prli_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1669 void *arg, uint32_t evt)
1671 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1672 struct lpfc_iocbq *cmdiocb, *rspiocb;
1673 struct lpfc_hba *phba = vport->phba;
1677 cmdiocb = (struct lpfc_iocbq *) arg;
1678 rspiocb = cmdiocb->context_un.rsp_iocb;
1679 npr = (PRLI *)lpfc_check_elscmpl_iocb(phba, cmdiocb, rspiocb);
1681 irsp = &rspiocb->iocb;
1682 if (irsp->ulpStatus) {
1683 if ((vport->port_type == LPFC_NPIV_PORT) &&
1684 vport->cfg_restrict_login) {
1687 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
1688 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
1689 return ndlp->nlp_state;
1692 /* Check out PRLI rsp */
1693 ndlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR);
1694 ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
1695 ndlp->nlp_flag &= ~NLP_FIRSTBURST;
1696 if ((npr->acceptRspCode == PRLI_REQ_EXECUTED) &&
1697 (npr->prliType == PRLI_FCP_TYPE)) {
1698 if (npr->initiatorFunc)
1699 ndlp->nlp_type |= NLP_FCP_INITIATOR;
1700 if (npr->targetFunc) {
1701 ndlp->nlp_type |= NLP_FCP_TARGET;
1702 if (npr->writeXferRdyDis)
1703 ndlp->nlp_flag |= NLP_FIRSTBURST;
1706 ndlp->nlp_fcp_info |= NLP_FCP_2_DEVICE;
1708 if (!(ndlp->nlp_type & NLP_FCP_TARGET) &&
1709 (vport->port_type == LPFC_NPIV_PORT) &&
1710 vport->cfg_restrict_login) {
1712 spin_lock_irq(shost->host_lock);
1713 ndlp->nlp_flag |= NLP_TARGET_REMOVE;
1714 spin_unlock_irq(shost->host_lock);
1715 lpfc_issue_els_logo(vport, ndlp, 0);
1717 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
1718 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1719 return ndlp->nlp_state;
1722 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
1723 if (ndlp->nlp_type & NLP_FCP_TARGET)
1724 lpfc_nlp_set_state(vport, ndlp, NLP_STE_MAPPED_NODE);
1726 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
1727 return ndlp->nlp_state;
1730 /*! lpfc_device_rm_prli_issue
1741 * This routine is envoked when we a request to remove a nport we are in the
1742 * process of PRLIing. We should software abort outstanding prli, unreg
1743 * login, send a logout. We will change node state to UNUSED_NODE, put it
1744 * on plogi list so it can be freed when LOGO completes.
1749 lpfc_device_rm_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1750 void *arg, uint32_t evt)
1752 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1754 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1755 spin_lock_irq(shost->host_lock);
1756 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
1757 spin_unlock_irq(shost->host_lock);
1758 return ndlp->nlp_state;
1760 /* software abort outstanding PLOGI */
1761 lpfc_els_abort(vport->phba, ndlp);
1763 lpfc_drop_node(vport, ndlp);
1764 return NLP_STE_FREED_NODE;
1769 /*! lpfc_device_recov_prli_issue
1780 * The routine is envoked when the state of a device is unknown, like
1781 * during a link down. We should remove the nodelist entry from the
1782 * unmapped list, issue a UNREG_LOGIN, do a software abort of the
1783 * outstanding PRLI command, then free the node entry.
1786 lpfc_device_recov_prli_issue(struct lpfc_vport *vport,
1787 struct lpfc_nodelist *ndlp,
1791 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1792 struct lpfc_hba *phba = vport->phba;
1794 /* Don't do anything that will mess up processing of the
1797 if (vport->fc_flag & FC_RSCN_DEFERRED)
1798 return ndlp->nlp_state;
1800 /* software abort outstanding PRLI */
1801 lpfc_els_abort(phba, ndlp);
1803 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
1804 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1805 spin_lock_irq(shost->host_lock);
1806 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
1807 spin_unlock_irq(shost->host_lock);
1808 lpfc_disc_set_adisc(vport, ndlp);
1809 return ndlp->nlp_state;
1813 lpfc_rcv_plogi_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1814 void *arg, uint32_t evt)
1816 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *)arg;
1819 memset(&stat, 0, sizeof(struct ls_rjt));
1820 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
1821 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
1822 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
1823 return ndlp->nlp_state;
1827 lpfc_rcv_prli_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1828 void *arg, uint32_t evt)
1830 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *)arg;
1833 memset(&stat, 0, sizeof(struct ls_rjt));
1834 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
1835 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
1836 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
1837 return ndlp->nlp_state;
1841 lpfc_rcv_logo_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1842 void *arg, uint32_t evt)
1844 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1845 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *)arg;
1847 spin_lock_irq(shost->host_lock);
1848 ndlp->nlp_flag &= NLP_LOGO_ACC;
1849 spin_unlock_irq(shost->host_lock);
1850 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
1851 return ndlp->nlp_state;
1855 lpfc_rcv_padisc_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1856 void *arg, uint32_t evt)
1858 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *)arg;
1861 memset(&stat, 0, sizeof(struct ls_rjt));
1862 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
1863 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
1864 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
1865 return ndlp->nlp_state;
1869 lpfc_rcv_prlo_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1870 void *arg, uint32_t evt)
1872 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *)arg;
1875 memset(&stat, 0, sizeof(struct ls_rjt));
1876 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
1877 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
1878 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
1879 return ndlp->nlp_state;
1883 lpfc_cmpl_logo_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1884 void *arg, uint32_t evt)
1886 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1888 ndlp->nlp_prev_state = NLP_STE_LOGO_ISSUE;
1889 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1890 spin_lock_irq(shost->host_lock);
1891 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
1892 spin_unlock_irq(shost->host_lock);
1893 lpfc_disc_set_adisc(vport, ndlp);
1894 return ndlp->nlp_state;
1898 lpfc_device_rm_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1899 void *arg, uint32_t evt)
1902 * Take no action. If a LOGO is outstanding, then possibly DevLoss has
1903 * timed out and is calling for Device Remove. In this case, the LOGO
1904 * must be allowed to complete in state LOGO_ISSUE so that the rpi
1905 * and other NLP flags are correctly cleaned up.
1907 return ndlp->nlp_state;
1911 lpfc_device_recov_logo_issue(struct lpfc_vport *vport,
1912 struct lpfc_nodelist *ndlp,
1913 void *arg, uint32_t evt)
1916 * Device Recovery events have no meaning for a node with a LOGO
1917 * outstanding. The LOGO has to complete first and handle the
1918 * node from that point.
1920 return ndlp->nlp_state;
1924 lpfc_rcv_plogi_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1925 void *arg, uint32_t evt)
1927 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1929 lpfc_rcv_plogi(vport, ndlp, cmdiocb);
1930 return ndlp->nlp_state;
1934 lpfc_rcv_prli_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1935 void *arg, uint32_t evt)
1937 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1939 lpfc_rcv_prli(vport, ndlp, cmdiocb);
1940 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
1941 return ndlp->nlp_state;
1945 lpfc_rcv_logo_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1946 void *arg, uint32_t evt)
1948 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1950 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
1951 return ndlp->nlp_state;
1955 lpfc_rcv_padisc_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1956 void *arg, uint32_t evt)
1958 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1960 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
1961 return ndlp->nlp_state;
1965 lpfc_rcv_prlo_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1966 void *arg, uint32_t evt)
1968 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1970 lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL);
1971 return ndlp->nlp_state;
1975 lpfc_device_recov_unmap_node(struct lpfc_vport *vport,
1976 struct lpfc_nodelist *ndlp,
1980 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1982 ndlp->nlp_prev_state = NLP_STE_UNMAPPED_NODE;
1983 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1984 spin_lock_irq(shost->host_lock);
1985 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
1986 spin_unlock_irq(shost->host_lock);
1987 lpfc_disc_set_adisc(vport, ndlp);
1989 return ndlp->nlp_state;
1993 lpfc_rcv_plogi_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1994 void *arg, uint32_t evt)
1996 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1998 lpfc_rcv_plogi(vport, ndlp, cmdiocb);
1999 return ndlp->nlp_state;
2003 lpfc_rcv_prli_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2004 void *arg, uint32_t evt)
2006 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2008 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
2009 return ndlp->nlp_state;
2013 lpfc_rcv_logo_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2014 void *arg, uint32_t evt)
2016 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2018 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
2019 return ndlp->nlp_state;
2023 lpfc_rcv_padisc_mapped_node(struct lpfc_vport *vport,
2024 struct lpfc_nodelist *ndlp,
2025 void *arg, uint32_t evt)
2027 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2029 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
2030 return ndlp->nlp_state;
2034 lpfc_rcv_prlo_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2035 void *arg, uint32_t evt)
2037 struct lpfc_hba *phba = vport->phba;
2038 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2040 /* flush the target */
2041 lpfc_sli_abort_iocb(vport, &phba->sli.ring[phba->sli.fcp_ring],
2042 ndlp->nlp_sid, 0, LPFC_CTX_TGT);
2044 /* Treat like rcv logo */
2045 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_PRLO);
2046 return ndlp->nlp_state;
2050 lpfc_device_recov_mapped_node(struct lpfc_vport *vport,
2051 struct lpfc_nodelist *ndlp,
2055 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2057 ndlp->nlp_prev_state = NLP_STE_MAPPED_NODE;
2058 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
2059 spin_lock_irq(shost->host_lock);
2060 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
2061 spin_unlock_irq(shost->host_lock);
2062 lpfc_disc_set_adisc(vport, ndlp);
2063 return ndlp->nlp_state;
2067 lpfc_rcv_plogi_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2068 void *arg, uint32_t evt)
2070 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2071 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2073 /* Ignore PLOGI if we have an outstanding LOGO */
2074 if (ndlp->nlp_flag & (NLP_LOGO_SND | NLP_LOGO_ACC))
2075 return ndlp->nlp_state;
2076 if (lpfc_rcv_plogi(vport, ndlp, cmdiocb)) {
2077 lpfc_cancel_retry_delay_tmo(vport, ndlp);
2078 spin_lock_irq(shost->host_lock);
2079 ndlp->nlp_flag &= ~(NLP_NPR_ADISC | NLP_NPR_2B_DISC);
2080 spin_unlock_irq(shost->host_lock);
2081 } else if (!(ndlp->nlp_flag & NLP_NPR_2B_DISC)) {
2082 /* send PLOGI immediately, move to PLOGI issue state */
2083 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
2084 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
2085 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
2086 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
2089 return ndlp->nlp_state;
2093 lpfc_rcv_prli_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2094 void *arg, uint32_t evt)
2096 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2097 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2100 memset(&stat, 0, sizeof (struct ls_rjt));
2101 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
2102 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
2103 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
2105 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
2106 if (ndlp->nlp_flag & NLP_NPR_ADISC) {
2107 spin_lock_irq(shost->host_lock);
2108 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
2109 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
2110 spin_unlock_irq(shost->host_lock);
2111 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
2112 lpfc_issue_els_adisc(vport, ndlp, 0);
2114 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
2115 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
2116 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
2119 return ndlp->nlp_state;
2123 lpfc_rcv_logo_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2124 void *arg, uint32_t evt)
2126 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2128 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
2129 return ndlp->nlp_state;
2133 lpfc_rcv_padisc_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2134 void *arg, uint32_t evt)
2136 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2138 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
2140 * Do not start discovery if discovery is about to start
2141 * or discovery in progress for this node. Starting discovery
2142 * here will affect the counting of discovery threads.
2144 if (!(ndlp->nlp_flag & NLP_DELAY_TMO) &&
2145 !(ndlp->nlp_flag & NLP_NPR_2B_DISC)) {
2146 if (ndlp->nlp_flag & NLP_NPR_ADISC) {
2147 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
2148 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
2149 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
2150 lpfc_issue_els_adisc(vport, ndlp, 0);
2152 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
2153 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
2154 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
2157 return ndlp->nlp_state;
2161 lpfc_rcv_prlo_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2162 void *arg, uint32_t evt)
2164 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2165 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2167 spin_lock_irq(shost->host_lock);
2168 ndlp->nlp_flag |= NLP_LOGO_ACC;
2169 spin_unlock_irq(shost->host_lock);
2171 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
2173 if ((ndlp->nlp_flag & NLP_DELAY_TMO) == 0) {
2174 mod_timer(&ndlp->nlp_delayfunc,
2175 jiffies + msecs_to_jiffies(1000 * 1));
2176 spin_lock_irq(shost->host_lock);
2177 ndlp->nlp_flag |= NLP_DELAY_TMO;
2178 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
2179 spin_unlock_irq(shost->host_lock);
2180 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
2182 spin_lock_irq(shost->host_lock);
2183 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
2184 spin_unlock_irq(shost->host_lock);
2186 return ndlp->nlp_state;
2190 lpfc_cmpl_plogi_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2191 void *arg, uint32_t evt)
2193 struct lpfc_iocbq *cmdiocb, *rspiocb;
2195 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2197 cmdiocb = (struct lpfc_iocbq *) arg;
2198 rspiocb = cmdiocb->context_un.rsp_iocb;
2200 irsp = &rspiocb->iocb;
2201 if (irsp->ulpStatus) {
2202 spin_lock_irq(shost->host_lock);
2203 ndlp->nlp_flag |= NLP_DEFER_RM;
2204 spin_unlock_irq(shost->host_lock);
2205 return NLP_STE_FREED_NODE;
2207 return ndlp->nlp_state;
2211 lpfc_cmpl_prli_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2212 void *arg, uint32_t evt)
2214 struct lpfc_iocbq *cmdiocb, *rspiocb;
2217 cmdiocb = (struct lpfc_iocbq *) arg;
2218 rspiocb = cmdiocb->context_un.rsp_iocb;
2220 irsp = &rspiocb->iocb;
2221 if (irsp->ulpStatus && (ndlp->nlp_flag & NLP_NODEV_REMOVE)) {
2222 lpfc_drop_node(vport, ndlp);
2223 return NLP_STE_FREED_NODE;
2225 return ndlp->nlp_state;
2229 lpfc_cmpl_logo_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2230 void *arg, uint32_t evt)
2232 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2234 /* For the fabric port just clear the fc flags. */
2235 if (ndlp->nlp_DID == Fabric_DID) {
2236 spin_lock_irq(shost->host_lock);
2237 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
2238 spin_unlock_irq(shost->host_lock);
2240 lpfc_unreg_rpi(vport, ndlp);
2241 return ndlp->nlp_state;
2245 lpfc_cmpl_adisc_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2246 void *arg, uint32_t evt)
2248 struct lpfc_iocbq *cmdiocb, *rspiocb;
2251 cmdiocb = (struct lpfc_iocbq *) arg;
2252 rspiocb = cmdiocb->context_un.rsp_iocb;
2254 irsp = &rspiocb->iocb;
2255 if (irsp->ulpStatus && (ndlp->nlp_flag & NLP_NODEV_REMOVE)) {
2256 lpfc_drop_node(vport, ndlp);
2257 return NLP_STE_FREED_NODE;
2259 return ndlp->nlp_state;
2263 lpfc_cmpl_reglogin_npr_node(struct lpfc_vport *vport,
2264 struct lpfc_nodelist *ndlp,
2265 void *arg, uint32_t evt)
2267 LPFC_MBOXQ_t *pmb = (LPFC_MBOXQ_t *) arg;
2268 MAILBOX_t *mb = &pmb->u.mb;
2270 if (!mb->mbxStatus) {
2271 /* SLI4 ports have preallocated logical rpis. */
2272 if (vport->phba->sli_rev < LPFC_SLI_REV4)
2273 ndlp->nlp_rpi = mb->un.varWords[0];
2274 ndlp->nlp_flag |= NLP_RPI_REGISTERED;
2276 if (ndlp->nlp_flag & NLP_NODEV_REMOVE) {
2277 lpfc_drop_node(vport, ndlp);
2278 return NLP_STE_FREED_NODE;
2281 return ndlp->nlp_state;
2285 lpfc_device_rm_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2286 void *arg, uint32_t evt)
2288 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2290 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
2291 spin_lock_irq(shost->host_lock);
2292 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
2293 spin_unlock_irq(shost->host_lock);
2294 return ndlp->nlp_state;
2296 lpfc_drop_node(vport, ndlp);
2297 return NLP_STE_FREED_NODE;
2301 lpfc_device_recov_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2302 void *arg, uint32_t evt)
2304 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2306 /* Don't do anything that will mess up processing of the
2309 if (vport->fc_flag & FC_RSCN_DEFERRED)
2310 return ndlp->nlp_state;
2312 lpfc_cancel_retry_delay_tmo(vport, ndlp);
2313 spin_lock_irq(shost->host_lock);
2314 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
2315 spin_unlock_irq(shost->host_lock);
2316 return ndlp->nlp_state;
2320 /* This next section defines the NPort Discovery State Machine */
2322 /* There are 4 different double linked lists nodelist entries can reside on.
2323 * The plogi list and adisc list are used when Link Up discovery or RSCN
2324 * processing is needed. Each list holds the nodes that we will send PLOGI
2325 * or ADISC on. These lists will keep track of what nodes will be effected
2326 * by an RSCN, or a Link Up (Typically, all nodes are effected on Link Up).
2327 * The unmapped_list will contain all nodes that we have successfully logged
2328 * into at the Fibre Channel level. The mapped_list will contain all nodes
2329 * that are mapped FCP targets.
2332 * The bind list is a list of undiscovered (potentially non-existent) nodes
2333 * that we have saved binding information on. This information is used when
2334 * nodes transition from the unmapped to the mapped list.
2336 /* For UNUSED_NODE state, the node has just been allocated .
2337 * For PLOGI_ISSUE and REG_LOGIN_ISSUE, the node is on
2338 * the PLOGI list. For REG_LOGIN_COMPL, the node is taken off the PLOGI list
2339 * and put on the unmapped list. For ADISC processing, the node is taken off
2340 * the ADISC list and placed on either the mapped or unmapped list (depending
2341 * on its previous state). Once on the unmapped list, a PRLI is issued and the
2342 * state changed to PRLI_ISSUE. When the PRLI completion occurs, the state is
2343 * changed to UNMAPPED_NODE. If the completion indicates a mapped
2344 * node, the node is taken off the unmapped list. The binding list is checked
2345 * for a valid binding, or a binding is automatically assigned. If binding
2346 * assignment is unsuccessful, the node is left on the unmapped list. If
2347 * binding assignment is successful, the associated binding list entry (if
2348 * any) is removed, and the node is placed on the mapped list.
2351 * For a Link Down, all nodes on the ADISC, PLOGI, unmapped or mapped
2352 * lists will receive a DEVICE_RECOVERY event. If the linkdown or devloss timers
2353 * expire, all effected nodes will receive a DEVICE_RM event.
2356 * For a Link Up or RSCN, all nodes will move from the mapped / unmapped lists
2357 * to either the ADISC or PLOGI list. After a Nameserver query or ALPA loopmap
2358 * check, additional nodes may be added or removed (via DEVICE_RM) to / from
2359 * the PLOGI or ADISC lists. Once the PLOGI and ADISC lists are populated,
2360 * we will first process the ADISC list. 32 entries are processed initially and
2361 * ADISC is initited for each one. Completions / Events for each node are
2362 * funnelled thru the state machine. As each node finishes ADISC processing, it
2363 * starts ADISC for any nodes waiting for ADISC processing. If no nodes are
2364 * waiting, and the ADISC list count is identically 0, then we are done. For
2365 * Link Up discovery, since all nodes on the PLOGI list are UNREG_LOGIN'ed, we
2366 * can issue a CLEAR_LA and reenable Link Events. Next we will process the PLOGI
2367 * list. 32 entries are processed initially and PLOGI is initited for each one.
2368 * Completions / Events for each node are funnelled thru the state machine. As
2369 * each node finishes PLOGI processing, it starts PLOGI for any nodes waiting
2370 * for PLOGI processing. If no nodes are waiting, and the PLOGI list count is
2371 * indentically 0, then we are done. We have now completed discovery / RSCN
2372 * handling. Upon completion, ALL nodes should be on either the mapped or
2376 static uint32_t (*lpfc_disc_action[NLP_STE_MAX_STATE * NLP_EVT_MAX_EVENT])
2377 (struct lpfc_vport *, struct lpfc_nodelist *, void *, uint32_t) = {
2378 /* Action routine Event Current State */
2379 lpfc_rcv_plogi_unused_node, /* RCV_PLOGI UNUSED_NODE */
2380 lpfc_rcv_els_unused_node, /* RCV_PRLI */
2381 lpfc_rcv_logo_unused_node, /* RCV_LOGO */
2382 lpfc_rcv_els_unused_node, /* RCV_ADISC */
2383 lpfc_rcv_els_unused_node, /* RCV_PDISC */
2384 lpfc_rcv_els_unused_node, /* RCV_PRLO */
2385 lpfc_disc_illegal, /* CMPL_PLOGI */
2386 lpfc_disc_illegal, /* CMPL_PRLI */
2387 lpfc_cmpl_logo_unused_node, /* CMPL_LOGO */
2388 lpfc_disc_illegal, /* CMPL_ADISC */
2389 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2390 lpfc_device_rm_unused_node, /* DEVICE_RM */
2391 lpfc_device_recov_unused_node, /* DEVICE_RECOVERY */
2393 lpfc_rcv_plogi_plogi_issue, /* RCV_PLOGI PLOGI_ISSUE */
2394 lpfc_rcv_prli_plogi_issue, /* RCV_PRLI */
2395 lpfc_rcv_logo_plogi_issue, /* RCV_LOGO */
2396 lpfc_rcv_els_plogi_issue, /* RCV_ADISC */
2397 lpfc_rcv_els_plogi_issue, /* RCV_PDISC */
2398 lpfc_rcv_els_plogi_issue, /* RCV_PRLO */
2399 lpfc_cmpl_plogi_plogi_issue, /* CMPL_PLOGI */
2400 lpfc_disc_illegal, /* CMPL_PRLI */
2401 lpfc_cmpl_logo_plogi_issue, /* CMPL_LOGO */
2402 lpfc_disc_illegal, /* CMPL_ADISC */
2403 lpfc_cmpl_reglogin_plogi_issue,/* CMPL_REG_LOGIN */
2404 lpfc_device_rm_plogi_issue, /* DEVICE_RM */
2405 lpfc_device_recov_plogi_issue, /* DEVICE_RECOVERY */
2407 lpfc_rcv_plogi_adisc_issue, /* RCV_PLOGI ADISC_ISSUE */
2408 lpfc_rcv_prli_adisc_issue, /* RCV_PRLI */
2409 lpfc_rcv_logo_adisc_issue, /* RCV_LOGO */
2410 lpfc_rcv_padisc_adisc_issue, /* RCV_ADISC */
2411 lpfc_rcv_padisc_adisc_issue, /* RCV_PDISC */
2412 lpfc_rcv_prlo_adisc_issue, /* RCV_PRLO */
2413 lpfc_disc_illegal, /* CMPL_PLOGI */
2414 lpfc_disc_illegal, /* CMPL_PRLI */
2415 lpfc_disc_illegal, /* CMPL_LOGO */
2416 lpfc_cmpl_adisc_adisc_issue, /* CMPL_ADISC */
2417 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2418 lpfc_device_rm_adisc_issue, /* DEVICE_RM */
2419 lpfc_device_recov_adisc_issue, /* DEVICE_RECOVERY */
2421 lpfc_rcv_plogi_reglogin_issue, /* RCV_PLOGI REG_LOGIN_ISSUE */
2422 lpfc_rcv_prli_reglogin_issue, /* RCV_PLOGI */
2423 lpfc_rcv_logo_reglogin_issue, /* RCV_LOGO */
2424 lpfc_rcv_padisc_reglogin_issue, /* RCV_ADISC */
2425 lpfc_rcv_padisc_reglogin_issue, /* RCV_PDISC */
2426 lpfc_rcv_prlo_reglogin_issue, /* RCV_PRLO */
2427 lpfc_cmpl_plogi_illegal, /* CMPL_PLOGI */
2428 lpfc_disc_illegal, /* CMPL_PRLI */
2429 lpfc_disc_illegal, /* CMPL_LOGO */
2430 lpfc_disc_illegal, /* CMPL_ADISC */
2431 lpfc_cmpl_reglogin_reglogin_issue,/* CMPL_REG_LOGIN */
2432 lpfc_device_rm_reglogin_issue, /* DEVICE_RM */
2433 lpfc_device_recov_reglogin_issue,/* DEVICE_RECOVERY */
2435 lpfc_rcv_plogi_prli_issue, /* RCV_PLOGI PRLI_ISSUE */
2436 lpfc_rcv_prli_prli_issue, /* RCV_PRLI */
2437 lpfc_rcv_logo_prli_issue, /* RCV_LOGO */
2438 lpfc_rcv_padisc_prli_issue, /* RCV_ADISC */
2439 lpfc_rcv_padisc_prli_issue, /* RCV_PDISC */
2440 lpfc_rcv_prlo_prli_issue, /* RCV_PRLO */
2441 lpfc_cmpl_plogi_illegal, /* CMPL_PLOGI */
2442 lpfc_cmpl_prli_prli_issue, /* CMPL_PRLI */
2443 lpfc_disc_illegal, /* CMPL_LOGO */
2444 lpfc_disc_illegal, /* CMPL_ADISC */
2445 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2446 lpfc_device_rm_prli_issue, /* DEVICE_RM */
2447 lpfc_device_recov_prli_issue, /* DEVICE_RECOVERY */
2449 lpfc_rcv_plogi_logo_issue, /* RCV_PLOGI LOGO_ISSUE */
2450 lpfc_rcv_prli_logo_issue, /* RCV_PRLI */
2451 lpfc_rcv_logo_logo_issue, /* RCV_LOGO */
2452 lpfc_rcv_padisc_logo_issue, /* RCV_ADISC */
2453 lpfc_rcv_padisc_logo_issue, /* RCV_PDISC */
2454 lpfc_rcv_prlo_logo_issue, /* RCV_PRLO */
2455 lpfc_cmpl_plogi_illegal, /* CMPL_PLOGI */
2456 lpfc_disc_illegal, /* CMPL_PRLI */
2457 lpfc_cmpl_logo_logo_issue, /* CMPL_LOGO */
2458 lpfc_disc_illegal, /* CMPL_ADISC */
2459 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2460 lpfc_device_rm_logo_issue, /* DEVICE_RM */
2461 lpfc_device_recov_logo_issue, /* DEVICE_RECOVERY */
2463 lpfc_rcv_plogi_unmap_node, /* RCV_PLOGI UNMAPPED_NODE */
2464 lpfc_rcv_prli_unmap_node, /* RCV_PRLI */
2465 lpfc_rcv_logo_unmap_node, /* RCV_LOGO */
2466 lpfc_rcv_padisc_unmap_node, /* RCV_ADISC */
2467 lpfc_rcv_padisc_unmap_node, /* RCV_PDISC */
2468 lpfc_rcv_prlo_unmap_node, /* RCV_PRLO */
2469 lpfc_disc_illegal, /* CMPL_PLOGI */
2470 lpfc_disc_illegal, /* CMPL_PRLI */
2471 lpfc_disc_illegal, /* CMPL_LOGO */
2472 lpfc_disc_illegal, /* CMPL_ADISC */
2473 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2474 lpfc_disc_illegal, /* DEVICE_RM */
2475 lpfc_device_recov_unmap_node, /* DEVICE_RECOVERY */
2477 lpfc_rcv_plogi_mapped_node, /* RCV_PLOGI MAPPED_NODE */
2478 lpfc_rcv_prli_mapped_node, /* RCV_PRLI */
2479 lpfc_rcv_logo_mapped_node, /* RCV_LOGO */
2480 lpfc_rcv_padisc_mapped_node, /* RCV_ADISC */
2481 lpfc_rcv_padisc_mapped_node, /* RCV_PDISC */
2482 lpfc_rcv_prlo_mapped_node, /* RCV_PRLO */
2483 lpfc_disc_illegal, /* CMPL_PLOGI */
2484 lpfc_disc_illegal, /* CMPL_PRLI */
2485 lpfc_disc_illegal, /* CMPL_LOGO */
2486 lpfc_disc_illegal, /* CMPL_ADISC */
2487 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2488 lpfc_disc_illegal, /* DEVICE_RM */
2489 lpfc_device_recov_mapped_node, /* DEVICE_RECOVERY */
2491 lpfc_rcv_plogi_npr_node, /* RCV_PLOGI NPR_NODE */
2492 lpfc_rcv_prli_npr_node, /* RCV_PRLI */
2493 lpfc_rcv_logo_npr_node, /* RCV_LOGO */
2494 lpfc_rcv_padisc_npr_node, /* RCV_ADISC */
2495 lpfc_rcv_padisc_npr_node, /* RCV_PDISC */
2496 lpfc_rcv_prlo_npr_node, /* RCV_PRLO */
2497 lpfc_cmpl_plogi_npr_node, /* CMPL_PLOGI */
2498 lpfc_cmpl_prli_npr_node, /* CMPL_PRLI */
2499 lpfc_cmpl_logo_npr_node, /* CMPL_LOGO */
2500 lpfc_cmpl_adisc_npr_node, /* CMPL_ADISC */
2501 lpfc_cmpl_reglogin_npr_node, /* CMPL_REG_LOGIN */
2502 lpfc_device_rm_npr_node, /* DEVICE_RM */
2503 lpfc_device_recov_npr_node, /* DEVICE_RECOVERY */
2507 lpfc_disc_state_machine(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2508 void *arg, uint32_t evt)
2510 uint32_t cur_state, rc;
2511 uint32_t(*func) (struct lpfc_vport *, struct lpfc_nodelist *, void *,
2513 uint32_t got_ndlp = 0;
2515 if (lpfc_nlp_get(ndlp))
2518 cur_state = ndlp->nlp_state;
2520 /* DSM in event <evt> on NPort <nlp_DID> in state <cur_state> */
2521 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2522 "0211 DSM in event x%x on NPort x%x in "
2523 "state %d Data: x%x\n",
2524 evt, ndlp->nlp_DID, cur_state, ndlp->nlp_flag);
2526 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_DSM,
2527 "DSM in: evt:%d ste:%d did:x%x",
2528 evt, cur_state, ndlp->nlp_DID);
2530 func = lpfc_disc_action[(cur_state * NLP_EVT_MAX_EVENT) + evt];
2531 rc = (func) (vport, ndlp, arg, evt);
2533 /* DSM out state <rc> on NPort <nlp_DID> */
2535 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2536 "0212 DSM out state %d on NPort x%x Data: x%x\n",
2537 rc, ndlp->nlp_DID, ndlp->nlp_flag);
2539 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_DSM,
2540 "DSM out: ste:%d did:x%x flg:x%x",
2541 rc, ndlp->nlp_DID, ndlp->nlp_flag);
2542 /* Decrement the ndlp reference count held for this function */
2545 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2546 "0213 DSM out state %d on NPort free\n", rc);
2548 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_DSM,
2549 "DSM out: ste:%d did:x%x flg:x%x",