1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2017-2019 Broadcom. All Rights Reserved. The term *
5 * “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. *
6 * Copyright (C) 2004-2016 Emulex. All rights reserved. *
7 * EMULEX and SLI are trademarks of Emulex. *
9 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
11 * This program is free software; you can redistribute it and/or *
12 * modify it under the terms of version 2 of the GNU General *
13 * Public License as published by the Free Software Foundation. *
14 * This program is distributed in the hope that it will be useful. *
15 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
16 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
17 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
18 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
19 * TO BE LEGALLY INVALID. See the GNU General Public License for *
20 * more details, a copy of which can be found in the file COPYING *
21 * included with this package. *
22 *******************************************************************/
24 #include <linux/blkdev.h>
25 #include <linux/pci.h>
26 #include <linux/slab.h>
27 #include <linux/interrupt.h>
29 #include <scsi/scsi.h>
30 #include <scsi/scsi_device.h>
31 #include <scsi/scsi_host.h>
32 #include <scsi/scsi_transport_fc.h>
33 #include <scsi/fc/fc_fs.h>
35 #include <linux/nvme-fc-driver.h>
40 #include "lpfc_sli4.h"
42 #include "lpfc_disc.h"
44 #include "lpfc_scsi.h"
45 #include "lpfc_nvme.h"
46 #include "lpfc_logmsg.h"
47 #include "lpfc_crtn.h"
48 #include "lpfc_vport.h"
49 #include "lpfc_debugfs.h"
52 /* Called to verify a rcv'ed ADISC was intended for us. */
54 lpfc_check_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
55 struct lpfc_name *nn, struct lpfc_name *pn)
57 /* First, we MUST have a RPI registered */
58 if (!(ndlp->nlp_flag & NLP_RPI_REGISTERED))
61 /* Compare the ADISC rsp WWNN / WWPN matches our internal node
62 * table entry for that node.
64 if (memcmp(nn, &ndlp->nlp_nodename, sizeof (struct lpfc_name)))
67 if (memcmp(pn, &ndlp->nlp_portname, sizeof (struct lpfc_name)))
70 /* we match, return success */
75 lpfc_check_sparm(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
76 struct serv_parm *sp, uint32_t class, int flogi)
78 volatile struct serv_parm *hsp = &vport->fc_sparam;
79 uint16_t hsp_value, ssp_value = 0;
82 * The receive data field size and buffer-to-buffer receive data field
83 * size entries are 16 bits but are represented as two 8-bit fields in
84 * the driver data structure to account for rsvd bits and other control
85 * bits. Reconstruct and compare the fields as a 16-bit values before
86 * correcting the byte values.
88 if (sp->cls1.classValid) {
90 hsp_value = ((hsp->cls1.rcvDataSizeMsb << 8) |
91 hsp->cls1.rcvDataSizeLsb);
92 ssp_value = ((sp->cls1.rcvDataSizeMsb << 8) |
93 sp->cls1.rcvDataSizeLsb);
95 goto bad_service_param;
96 if (ssp_value > hsp_value) {
97 sp->cls1.rcvDataSizeLsb =
98 hsp->cls1.rcvDataSizeLsb;
99 sp->cls1.rcvDataSizeMsb =
100 hsp->cls1.rcvDataSizeMsb;
103 } else if (class == CLASS1)
104 goto bad_service_param;
105 if (sp->cls2.classValid) {
107 hsp_value = ((hsp->cls2.rcvDataSizeMsb << 8) |
108 hsp->cls2.rcvDataSizeLsb);
109 ssp_value = ((sp->cls2.rcvDataSizeMsb << 8) |
110 sp->cls2.rcvDataSizeLsb);
112 goto bad_service_param;
113 if (ssp_value > hsp_value) {
114 sp->cls2.rcvDataSizeLsb =
115 hsp->cls2.rcvDataSizeLsb;
116 sp->cls2.rcvDataSizeMsb =
117 hsp->cls2.rcvDataSizeMsb;
120 } else if (class == CLASS2)
121 goto bad_service_param;
122 if (sp->cls3.classValid) {
124 hsp_value = ((hsp->cls3.rcvDataSizeMsb << 8) |
125 hsp->cls3.rcvDataSizeLsb);
126 ssp_value = ((sp->cls3.rcvDataSizeMsb << 8) |
127 sp->cls3.rcvDataSizeLsb);
129 goto bad_service_param;
130 if (ssp_value > hsp_value) {
131 sp->cls3.rcvDataSizeLsb =
132 hsp->cls3.rcvDataSizeLsb;
133 sp->cls3.rcvDataSizeMsb =
134 hsp->cls3.rcvDataSizeMsb;
137 } else if (class == CLASS3)
138 goto bad_service_param;
141 * Preserve the upper four bits of the MSB from the PLOGI response.
142 * These bits contain the Buffer-to-Buffer State Change Number
143 * from the target and need to be passed to the FW.
145 hsp_value = (hsp->cmn.bbRcvSizeMsb << 8) | hsp->cmn.bbRcvSizeLsb;
146 ssp_value = (sp->cmn.bbRcvSizeMsb << 8) | sp->cmn.bbRcvSizeLsb;
147 if (ssp_value > hsp_value) {
148 sp->cmn.bbRcvSizeLsb = hsp->cmn.bbRcvSizeLsb;
149 sp->cmn.bbRcvSizeMsb = (sp->cmn.bbRcvSizeMsb & 0xF0) |
150 (hsp->cmn.bbRcvSizeMsb & 0x0F);
153 memcpy(&ndlp->nlp_nodename, &sp->nodeName, sizeof (struct lpfc_name));
154 memcpy(&ndlp->nlp_portname, &sp->portName, sizeof (struct lpfc_name));
157 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
159 "(%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x) sent "
160 "invalid service parameters. Ignoring device.\n",
162 sp->nodeName.u.wwn[0], sp->nodeName.u.wwn[1],
163 sp->nodeName.u.wwn[2], sp->nodeName.u.wwn[3],
164 sp->nodeName.u.wwn[4], sp->nodeName.u.wwn[5],
165 sp->nodeName.u.wwn[6], sp->nodeName.u.wwn[7]);
170 lpfc_check_elscmpl_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
171 struct lpfc_iocbq *rspiocb)
173 struct lpfc_dmabuf *pcmd, *prsp;
178 irsp = &rspiocb->iocb;
179 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
181 /* For lpfc_els_abort, context2 could be zero'ed to delay
182 * freeing associated memory till after ABTS completes.
185 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf,
188 lp = (uint32_t *) prsp->virt;
189 ptr = (void *)((uint8_t *)lp + sizeof(uint32_t));
192 /* Force ulpStatus error since we are returning NULL ptr */
193 if (!(irsp->ulpStatus)) {
194 irsp->ulpStatus = IOSTAT_LOCAL_REJECT;
195 irsp->un.ulpWord[4] = IOERR_SLI_ABORTED;
205 * Free resources / clean up outstanding I/Os
206 * associated with a LPFC_NODELIST entry. This
207 * routine effectively results in a "software abort".
210 lpfc_els_abort(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp)
212 LIST_HEAD(abort_list);
213 struct lpfc_sli_ring *pring;
214 struct lpfc_iocbq *iocb, *next_iocb;
216 pring = lpfc_phba_elsring(phba);
218 /* In case of error recovery path, we might have a NULL pring here */
219 if (unlikely(!pring))
222 /* Abort outstanding I/O on NPort <nlp_DID> */
223 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_DISCOVERY,
224 "2819 Abort outstanding I/O on NPort x%x "
225 "Data: x%x x%x x%x\n",
226 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
228 /* Clean up all fabric IOs first.*/
229 lpfc_fabric_abort_nport(ndlp);
232 * Lock the ELS ring txcmplq for SLI3/SLI4 and build a local list
233 * of all ELS IOs that need an ABTS. The IOs need to stay on the
234 * txcmplq so that the abort operation completes them successfully.
236 spin_lock_irq(&phba->hbalock);
237 if (phba->sli_rev == LPFC_SLI_REV4)
238 spin_lock(&pring->ring_lock);
239 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
240 /* Add to abort_list on on NDLP match. */
241 if (lpfc_check_sli_ndlp(phba, pring, iocb, ndlp))
242 list_add_tail(&iocb->dlist, &abort_list);
244 if (phba->sli_rev == LPFC_SLI_REV4)
245 spin_unlock(&pring->ring_lock);
246 spin_unlock_irq(&phba->hbalock);
248 /* Abort the targeted IOs and remove them from the abort list. */
249 list_for_each_entry_safe(iocb, next_iocb, &abort_list, dlist) {
250 spin_lock_irq(&phba->hbalock);
251 list_del_init(&iocb->dlist);
252 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
253 spin_unlock_irq(&phba->hbalock);
256 INIT_LIST_HEAD(&abort_list);
258 /* Now process the txq */
259 spin_lock_irq(&phba->hbalock);
260 if (phba->sli_rev == LPFC_SLI_REV4)
261 spin_lock(&pring->ring_lock);
263 list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
264 /* Check to see if iocb matches the nport we are looking for */
265 if (lpfc_check_sli_ndlp(phba, pring, iocb, ndlp)) {
266 list_del_init(&iocb->list);
267 list_add_tail(&iocb->list, &abort_list);
271 if (phba->sli_rev == LPFC_SLI_REV4)
272 spin_unlock(&pring->ring_lock);
273 spin_unlock_irq(&phba->hbalock);
275 /* Cancel all the IOCBs from the completions list */
276 lpfc_sli_cancel_iocbs(phba, &abort_list,
277 IOSTAT_LOCAL_REJECT, IOERR_SLI_ABORTED);
279 lpfc_cancel_retry_delay_tmo(phba->pport, ndlp);
283 lpfc_rcv_plogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
284 struct lpfc_iocbq *cmdiocb)
286 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
287 struct lpfc_hba *phba = vport->phba;
288 struct lpfc_dmabuf *pcmd;
289 uint64_t nlp_portwwn = 0;
292 struct serv_parm *sp;
299 memset(&stat, 0, sizeof (struct ls_rjt));
300 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
301 lp = (uint32_t *) pcmd->virt;
302 sp = (struct serv_parm *) ((uint8_t *) lp + sizeof (uint32_t));
303 if (wwn_to_u64(sp->portName.u.wwn) == 0) {
304 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
305 "0140 PLOGI Reject: invalid nname\n");
306 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
307 stat.un.b.lsRjtRsnCodeExp = LSEXP_INVALID_PNAME;
308 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
312 if (wwn_to_u64(sp->nodeName.u.wwn) == 0) {
313 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
314 "0141 PLOGI Reject: invalid pname\n");
315 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
316 stat.un.b.lsRjtRsnCodeExp = LSEXP_INVALID_NNAME;
317 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
322 nlp_portwwn = wwn_to_u64(ndlp->nlp_portname.u.wwn);
323 if ((lpfc_check_sparm(vport, ndlp, sp, CLASS3, 0) == 0)) {
324 /* Reject this request because invalid parameters */
325 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
326 stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
327 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
331 icmd = &cmdiocb->iocb;
333 /* PLOGI chkparm OK */
334 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
335 "0114 PLOGI chkparm OK Data: x%x x%x x%x "
337 ndlp->nlp_DID, ndlp->nlp_state, ndlp->nlp_flag,
338 ndlp->nlp_rpi, vport->port_state,
341 if (vport->cfg_fcp_class == 2 && sp->cls2.classValid)
342 ndlp->nlp_fcp_info |= CLASS2;
344 ndlp->nlp_fcp_info |= CLASS3;
346 ndlp->nlp_class_sup = 0;
347 if (sp->cls1.classValid)
348 ndlp->nlp_class_sup |= FC_COS_CLASS1;
349 if (sp->cls2.classValid)
350 ndlp->nlp_class_sup |= FC_COS_CLASS2;
351 if (sp->cls3.classValid)
352 ndlp->nlp_class_sup |= FC_COS_CLASS3;
353 if (sp->cls4.classValid)
354 ndlp->nlp_class_sup |= FC_COS_CLASS4;
356 ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) | sp->cmn.bbRcvSizeLsb;
358 /* if already logged in, do implicit logout */
359 switch (ndlp->nlp_state) {
360 case NLP_STE_NPR_NODE:
361 if (!(ndlp->nlp_flag & NLP_NPR_ADISC))
364 case NLP_STE_REG_LOGIN_ISSUE:
365 case NLP_STE_PRLI_ISSUE:
366 case NLP_STE_UNMAPPED_NODE:
367 case NLP_STE_MAPPED_NODE:
368 /* For initiators, lpfc_plogi_confirm_nport skips fabric did.
369 * For target mode, execute implicit logo.
370 * Fabric nodes go into NPR.
372 if (!(ndlp->nlp_type & NLP_FABRIC) &&
373 !(phba->nvmet_support)) {
374 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb,
378 if (nlp_portwwn != 0 &&
379 nlp_portwwn != wwn_to_u64(sp->portName.u.wwn))
380 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
381 "0143 PLOGI recv'd from DID: x%x "
382 "WWPN changed: old %llx new %llx\n",
384 (unsigned long long)nlp_portwwn,
386 wwn_to_u64(sp->portName.u.wwn));
388 ndlp->nlp_prev_state = ndlp->nlp_state;
389 /* rport needs to be unregistered first */
390 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
394 ndlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR);
395 ndlp->nlp_type &= ~(NLP_NVME_TARGET | NLP_NVME_INITIATOR);
396 ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
397 ndlp->nlp_flag &= ~NLP_FIRSTBURST;
399 /* Check for Nport to NPort pt2pt protocol */
400 if ((vport->fc_flag & FC_PT2PT) &&
401 !(vport->fc_flag & FC_PT2PT_PLOGI)) {
402 /* rcv'ed PLOGI decides what our NPortId will be */
403 vport->fc_myDID = icmd->un.rcvels.parmRo;
405 ed_tov = be32_to_cpu(sp->cmn.e_d_tov);
406 if (sp->cmn.edtovResolution) {
407 /* E_D_TOV ticks are in nanoseconds */
408 ed_tov = (phba->fc_edtov + 999999) / 1000000;
412 * For pt-to-pt, use the larger EDTOV
415 if (ed_tov > phba->fc_edtov)
416 phba->fc_edtov = ed_tov;
417 phba->fc_ratov = (2 * phba->fc_edtov) / 1000;
419 memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
421 /* Issue config_link / reg_vfi to account for updated TOV's */
423 if (phba->sli_rev == LPFC_SLI_REV4)
424 lpfc_issue_reg_vfi(vport);
426 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
429 lpfc_config_link(phba, mbox);
430 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
432 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
433 if (rc == MBX_NOT_FINISHED) {
434 mempool_free(mbox, phba->mbox_mem_pool);
439 lpfc_can_disctmo(vport);
442 ndlp->nlp_flag &= ~NLP_SUPPRESS_RSP;
443 if ((phba->sli.sli_flag & LPFC_SLI_SUPPRESS_RSP) &&
444 sp->cmn.valid_vendor_ver_level) {
445 vid = be32_to_cpu(sp->un.vv.vid);
446 flag = be32_to_cpu(sp->un.vv.flags);
447 if ((vid == LPFC_VV_EMLX_ID) && (flag & LPFC_VV_SUPPRESS_RSP))
448 ndlp->nlp_flag |= NLP_SUPPRESS_RSP;
451 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
455 /* Registering an existing RPI behaves differently for SLI3 vs SLI4 */
456 if (phba->sli_rev == LPFC_SLI_REV4)
457 lpfc_unreg_rpi(vport, ndlp);
459 rc = lpfc_reg_rpi(phba, vport->vpi, icmd->un.rcvels.remoteID,
460 (uint8_t *) sp, mbox, ndlp->nlp_rpi);
462 mempool_free(mbox, phba->mbox_mem_pool);
466 /* ACC PLOGI rsp command needs to execute first,
467 * queue this mbox command to be processed later.
469 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
471 * mbox->ctx_ndlp = lpfc_nlp_get(ndlp) deferred until mailbox
472 * command issued in lpfc_cmpl_els_acc().
475 spin_lock_irq(shost->host_lock);
476 ndlp->nlp_flag |= (NLP_ACC_REGLOGIN | NLP_RCV_PLOGI);
477 spin_unlock_irq(shost->host_lock);
480 * If there is an outstanding PLOGI issued, abort it before
481 * sending ACC rsp for received PLOGI. If pending plogi
482 * is not canceled here, the plogi will be rejected by
483 * remote port and will be retried. On a configuration with
484 * single discovery thread, this will cause a huge delay in
485 * discovery. Also this will cause multiple state machines
486 * running in parallel for this node.
488 if (ndlp->nlp_state == NLP_STE_PLOGI_ISSUE) {
489 /* software abort outstanding PLOGI */
490 lpfc_els_abort(phba, ndlp);
493 if ((vport->port_type == LPFC_NPIV_PORT &&
494 vport->cfg_restrict_login)) {
496 /* In order to preserve RPIs, we want to cleanup
497 * the default RPI the firmware created to rcv
498 * this ELS request. The only way to do this is
499 * to register, then unregister the RPI.
501 spin_lock_irq(shost->host_lock);
502 ndlp->nlp_flag |= NLP_RM_DFLT_RPI;
503 spin_unlock_irq(shost->host_lock);
504 stat.un.b.lsRjtRsnCode = LSRJT_INVALID_CMD;
505 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
506 rc = lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb,
509 mempool_free(mbox, phba->mbox_mem_pool);
512 rc = lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp, mbox);
514 mempool_free(mbox, phba->mbox_mem_pool);
517 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
518 stat.un.b.lsRjtRsnCodeExp = LSEXP_OUT_OF_RESOURCE;
519 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
524 * lpfc_mbx_cmpl_resume_rpi - Resume RPI completion routine
525 * @phba: pointer to lpfc hba data structure.
526 * @mboxq: pointer to mailbox object
528 * This routine is invoked to issue a completion to a rcv'ed
529 * ADISC or PDISC after the paused RPI has been resumed.
532 lpfc_mbx_cmpl_resume_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
534 struct lpfc_vport *vport;
535 struct lpfc_iocbq *elsiocb;
536 struct lpfc_nodelist *ndlp;
539 elsiocb = (struct lpfc_iocbq *)mboxq->ctx_buf;
540 ndlp = (struct lpfc_nodelist *)mboxq->ctx_ndlp;
541 vport = mboxq->vport;
542 cmd = elsiocb->drvrTimeout;
544 if (cmd == ELS_CMD_ADISC) {
545 lpfc_els_rsp_adisc_acc(vport, elsiocb, ndlp);
547 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, elsiocb,
551 mempool_free(mboxq, phba->mbox_mem_pool);
555 lpfc_rcv_padisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
556 struct lpfc_iocbq *cmdiocb)
558 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
559 struct lpfc_iocbq *elsiocb;
560 struct lpfc_dmabuf *pcmd;
561 struct serv_parm *sp;
562 struct lpfc_name *pnn, *ppn;
569 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
570 lp = (uint32_t *) pcmd->virt;
573 if (cmd == ELS_CMD_ADISC) {
575 pnn = (struct lpfc_name *) & ap->nodeName;
576 ppn = (struct lpfc_name *) & ap->portName;
578 sp = (struct serv_parm *) lp;
579 pnn = (struct lpfc_name *) & sp->nodeName;
580 ppn = (struct lpfc_name *) & sp->portName;
583 icmd = &cmdiocb->iocb;
584 if (icmd->ulpStatus == 0 && lpfc_check_adisc(vport, ndlp, pnn, ppn)) {
587 * As soon as we send ACC, the remote NPort can
588 * start sending us data. Thus, for SLI4 we must
589 * resume the RPI before the ACC goes out.
591 if (vport->phba->sli_rev == LPFC_SLI_REV4) {
592 elsiocb = kmalloc(sizeof(struct lpfc_iocbq),
596 /* Save info from cmd IOCB used in rsp */
597 memcpy((uint8_t *)elsiocb, (uint8_t *)cmdiocb,
598 sizeof(struct lpfc_iocbq));
600 /* Save the ELS cmd */
601 elsiocb->drvrTimeout = cmd;
603 lpfc_sli4_resume_rpi(ndlp,
604 lpfc_mbx_cmpl_resume_rpi, elsiocb);
609 if (cmd == ELS_CMD_ADISC) {
610 lpfc_els_rsp_adisc_acc(vport, cmdiocb, ndlp);
612 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb,
616 /* If we are authenticated, move to the proper state */
617 if (ndlp->nlp_type & (NLP_FCP_TARGET | NLP_NVME_TARGET))
618 lpfc_nlp_set_state(vport, ndlp, NLP_STE_MAPPED_NODE);
620 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
624 /* Reject this request because invalid parameters */
625 stat.un.b.lsRjtRsvd0 = 0;
626 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
627 stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
628 stat.un.b.vendorUnique = 0;
629 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
632 mod_timer(&ndlp->nlp_delayfunc, jiffies + msecs_to_jiffies(1000));
634 spin_lock_irq(shost->host_lock);
635 ndlp->nlp_flag |= NLP_DELAY_TMO;
636 spin_unlock_irq(shost->host_lock);
637 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
638 ndlp->nlp_prev_state = ndlp->nlp_state;
639 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
644 lpfc_rcv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
645 struct lpfc_iocbq *cmdiocb, uint32_t els_cmd)
647 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
648 struct lpfc_hba *phba = vport->phba;
649 struct lpfc_vport **vports;
650 int i, active_vlink_present = 0 ;
652 /* Put ndlp in NPR state with 1 sec timeout for plogi, ACC logo */
653 /* Only call LOGO ACC for first LOGO, this avoids sending unnecessary
654 * PLOGIs during LOGO storms from a device.
656 spin_lock_irq(shost->host_lock);
657 ndlp->nlp_flag |= NLP_LOGO_ACC;
658 spin_unlock_irq(shost->host_lock);
659 if (els_cmd == ELS_CMD_PRLO)
660 lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL);
662 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
663 if (ndlp->nlp_DID == Fabric_DID) {
664 if (vport->port_state <= LPFC_FDISC)
666 lpfc_linkdown_port(vport);
667 spin_lock_irq(shost->host_lock);
668 vport->fc_flag |= FC_VPORT_LOGO_RCVD;
669 spin_unlock_irq(shost->host_lock);
670 vports = lpfc_create_vport_work_array(phba);
672 for (i = 0; i <= phba->max_vports && vports[i] != NULL;
674 if ((!(vports[i]->fc_flag &
675 FC_VPORT_LOGO_RCVD)) &&
676 (vports[i]->port_state > LPFC_FDISC)) {
677 active_vlink_present = 1;
681 lpfc_destroy_vport_work_array(phba, vports);
685 * Don't re-instantiate if vport is marked for deletion.
686 * If we are here first then vport_delete is going to wait
687 * for discovery to complete.
689 if (!(vport->load_flag & FC_UNLOADING) &&
690 active_vlink_present) {
692 * If there are other active VLinks present,
693 * re-instantiate the Vlink using FDISC.
695 mod_timer(&ndlp->nlp_delayfunc,
696 jiffies + msecs_to_jiffies(1000));
697 spin_lock_irq(shost->host_lock);
698 ndlp->nlp_flag |= NLP_DELAY_TMO;
699 spin_unlock_irq(shost->host_lock);
700 ndlp->nlp_last_elscmd = ELS_CMD_FDISC;
701 vport->port_state = LPFC_FDISC;
703 spin_lock_irq(shost->host_lock);
704 phba->pport->fc_flag &= ~FC_LOGO_RCVD_DID_CHNG;
705 spin_unlock_irq(shost->host_lock);
706 lpfc_retry_pport_discovery(phba);
708 } else if ((!(ndlp->nlp_type & NLP_FABRIC) &&
709 ((ndlp->nlp_type & NLP_FCP_TARGET) ||
710 !(ndlp->nlp_type & NLP_FCP_INITIATOR))) ||
711 (ndlp->nlp_state == NLP_STE_ADISC_ISSUE)) {
712 /* Only try to re-login if this is NOT a Fabric Node */
713 mod_timer(&ndlp->nlp_delayfunc,
714 jiffies + msecs_to_jiffies(1000 * 1));
715 spin_lock_irq(shost->host_lock);
716 ndlp->nlp_flag |= NLP_DELAY_TMO;
717 spin_unlock_irq(shost->host_lock);
719 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
722 ndlp->nlp_prev_state = ndlp->nlp_state;
723 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
725 spin_lock_irq(shost->host_lock);
726 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
727 spin_unlock_irq(shost->host_lock);
728 /* The driver has to wait until the ACC completes before it continues
729 * processing the LOGO. The action will resume in
730 * lpfc_cmpl_els_logo_acc routine. Since part of processing includes an
731 * unreg_login, the driver waits so the ACC does not get aborted.
737 lpfc_rcv_prli_support_check(struct lpfc_vport *vport,
738 struct lpfc_nodelist *ndlp,
739 struct lpfc_iocbq *cmdiocb)
745 payload = ((struct lpfc_dmabuf *)cmdiocb->context2)->virt;
747 if (vport->phba->nvmet_support) {
748 /* Must be a NVME PRLI */
749 if (cmd == ELS_CMD_PRLI)
752 /* Initiator mode. */
753 if (!vport->nvmei_support && (cmd == ELS_CMD_NVMEPRLI))
758 lpfc_printf_vlog(vport, KERN_WARNING, LOG_NVME_DISC,
759 "6115 Rcv PRLI (%x) check failed: ndlp rpi %d "
760 "state x%x flags x%x\n",
761 cmd, ndlp->nlp_rpi, ndlp->nlp_state,
763 memset(&stat, 0, sizeof(struct ls_rjt));
764 stat.un.b.lsRjtRsnCode = LSRJT_CMD_UNSUPPORTED;
765 stat.un.b.lsRjtRsnCodeExp = LSEXP_REQ_UNSUPPORTED;
766 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb,
772 lpfc_rcv_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
773 struct lpfc_iocbq *cmdiocb)
775 struct lpfc_hba *phba = vport->phba;
776 struct lpfc_dmabuf *pcmd;
779 struct fc_rport *rport = ndlp->rport;
782 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
783 lp = (uint32_t *) pcmd->virt;
784 npr = (PRLI *) ((uint8_t *) lp + sizeof (uint32_t));
786 if ((npr->prliType == PRLI_FCP_TYPE) ||
787 (npr->prliType == PRLI_NVME_TYPE)) {
788 if (npr->initiatorFunc) {
789 if (npr->prliType == PRLI_FCP_TYPE)
790 ndlp->nlp_type |= NLP_FCP_INITIATOR;
791 if (npr->prliType == PRLI_NVME_TYPE)
792 ndlp->nlp_type |= NLP_NVME_INITIATOR;
794 if (npr->targetFunc) {
795 if (npr->prliType == PRLI_FCP_TYPE)
796 ndlp->nlp_type |= NLP_FCP_TARGET;
797 if (npr->prliType == PRLI_NVME_TYPE)
798 ndlp->nlp_type |= NLP_NVME_TARGET;
799 if (npr->writeXferRdyDis)
800 ndlp->nlp_flag |= NLP_FIRSTBURST;
802 if (npr->Retry && ndlp->nlp_type &
803 (NLP_FCP_INITIATOR | NLP_FCP_TARGET))
804 ndlp->nlp_fcp_info |= NLP_FCP_2_DEVICE;
806 if (npr->Retry && phba->nsler &&
807 ndlp->nlp_type & (NLP_NVME_INITIATOR | NLP_NVME_TARGET))
808 ndlp->nlp_nvme_info |= NLP_NVME_NSLER;
811 /* If this driver is in nvme target mode, set the ndlp's fc4
812 * type to NVME provided the PRLI response claims NVME FC4
813 * type. Target mode does not issue gft_id so doesn't get
814 * the fc4 type set until now.
816 if (phba->nvmet_support && (npr->prliType == PRLI_NVME_TYPE)) {
817 ndlp->nlp_fc4_type |= NLP_FC4_NVME;
818 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
820 if (npr->prliType == PRLI_FCP_TYPE)
821 ndlp->nlp_fc4_type |= NLP_FC4_FCP;
824 /* We need to update the rport role values */
825 roles = FC_RPORT_ROLE_UNKNOWN;
826 if (ndlp->nlp_type & NLP_FCP_INITIATOR)
827 roles |= FC_RPORT_ROLE_FCP_INITIATOR;
828 if (ndlp->nlp_type & NLP_FCP_TARGET)
829 roles |= FC_RPORT_ROLE_FCP_TARGET;
831 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
832 "rport rolechg: role:x%x did:x%x flg:x%x",
833 roles, ndlp->nlp_DID, ndlp->nlp_flag);
835 if (vport->cfg_enable_fc4_type != LPFC_ENABLE_NVME)
836 fc_remote_port_rolechg(rport, roles);
841 lpfc_disc_set_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
843 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
845 if (!(ndlp->nlp_flag & NLP_RPI_REGISTERED)) {
846 spin_lock_irq(shost->host_lock);
847 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
848 spin_unlock_irq(shost->host_lock);
852 if (!(vport->fc_flag & FC_PT2PT)) {
853 /* Check config parameter use-adisc or FCP-2 */
854 if (vport->cfg_use_adisc && ((vport->fc_flag & FC_RSCN_MODE) ||
855 ((ndlp->nlp_fcp_info & NLP_FCP_2_DEVICE) &&
856 (ndlp->nlp_type & NLP_FCP_TARGET)))) {
857 spin_lock_irq(shost->host_lock);
858 ndlp->nlp_flag |= NLP_NPR_ADISC;
859 spin_unlock_irq(shost->host_lock);
864 spin_lock_irq(shost->host_lock);
865 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
866 spin_unlock_irq(shost->host_lock);
867 lpfc_unreg_rpi(vport, ndlp);
872 * lpfc_release_rpi - Release a RPI by issuing unreg_login mailbox cmd.
873 * @phba : Pointer to lpfc_hba structure.
874 * @vport: Pointer to lpfc_vport structure.
875 * @rpi : rpi to be release.
877 * This function will send a unreg_login mailbox command to the firmware
881 lpfc_release_rpi(struct lpfc_hba *phba, struct lpfc_vport *vport,
882 struct lpfc_nodelist *ndlp, uint16_t rpi)
887 /* If there is already an UNREG in progress for this ndlp,
888 * no need to queue up another one.
890 if (ndlp->nlp_flag & NLP_UNREG_INP) {
891 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
892 "1435 release_rpi SKIP UNREG x%x on "
893 "NPort x%x deferred x%x flg x%x "
895 ndlp->nlp_rpi, ndlp->nlp_DID,
897 ndlp->nlp_flag, ndlp);
901 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
904 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
905 "2796 mailbox memory allocation failed \n");
907 lpfc_unreg_login(phba, vport->vpi, rpi, pmb);
908 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
910 pmb->ctx_ndlp = ndlp;
912 if (((ndlp->nlp_DID & Fabric_DID_MASK) != Fabric_DID_MASK) &&
913 (!(vport->fc_flag & FC_OFFLINE_MODE)))
914 ndlp->nlp_flag |= NLP_UNREG_INP;
916 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
917 "1437 release_rpi UNREG x%x "
918 "on NPort x%x flg x%x\n",
919 ndlp->nlp_rpi, ndlp->nlp_DID, ndlp->nlp_flag);
921 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
922 if (rc == MBX_NOT_FINISHED)
923 mempool_free(pmb, phba->mbox_mem_pool);
928 lpfc_disc_illegal(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
929 void *arg, uint32_t evt)
931 struct lpfc_hba *phba;
932 LPFC_MBOXQ_t *pmb = (LPFC_MBOXQ_t *) arg;
936 /* Release the RPI if reglogin completing */
937 if (!(phba->pport->load_flag & FC_UNLOADING) &&
938 (evt == NLP_EVT_CMPL_REG_LOGIN) &&
939 (!pmb->u.mb.mbxStatus)) {
940 rpi = pmb->u.mb.un.varWords[0];
941 lpfc_release_rpi(phba, vport, ndlp, rpi);
943 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
944 "0271 Illegal State Transition: node x%x "
945 "event x%x, state x%x Data: x%x x%x\n",
946 ndlp->nlp_DID, evt, ndlp->nlp_state, ndlp->nlp_rpi,
948 return ndlp->nlp_state;
952 lpfc_cmpl_plogi_illegal(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
953 void *arg, uint32_t evt)
955 /* This transition is only legal if we previously
956 * rcv'ed a PLOGI. Since we don't want 2 discovery threads
957 * working on the same NPortID, do nothing for this thread
960 if (!(ndlp->nlp_flag & NLP_RCV_PLOGI)) {
961 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
962 "0272 Illegal State Transition: node x%x "
963 "event x%x, state x%x Data: x%x x%x\n",
964 ndlp->nlp_DID, evt, ndlp->nlp_state, ndlp->nlp_rpi,
967 return ndlp->nlp_state;
970 /* Start of Discovery State Machine routines */
973 lpfc_rcv_plogi_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
974 void *arg, uint32_t evt)
976 struct lpfc_iocbq *cmdiocb;
978 cmdiocb = (struct lpfc_iocbq *) arg;
980 if (lpfc_rcv_plogi(vport, ndlp, cmdiocb)) {
981 return ndlp->nlp_state;
983 return NLP_STE_FREED_NODE;
987 lpfc_rcv_els_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
988 void *arg, uint32_t evt)
990 lpfc_issue_els_logo(vport, ndlp, 0);
991 return ndlp->nlp_state;
995 lpfc_rcv_logo_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
996 void *arg, uint32_t evt)
998 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
999 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1001 spin_lock_irq(shost->host_lock);
1002 ndlp->nlp_flag |= NLP_LOGO_ACC;
1003 spin_unlock_irq(shost->host_lock);
1004 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
1006 return ndlp->nlp_state;
1010 lpfc_cmpl_logo_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1011 void *arg, uint32_t evt)
1013 return NLP_STE_FREED_NODE;
1017 lpfc_device_rm_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1018 void *arg, uint32_t evt)
1020 return NLP_STE_FREED_NODE;
1024 lpfc_device_recov_unused_node(struct lpfc_vport *vport,
1025 struct lpfc_nodelist *ndlp,
1026 void *arg, uint32_t evt)
1028 return ndlp->nlp_state;
1032 lpfc_rcv_plogi_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1033 void *arg, uint32_t evt)
1035 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1036 struct lpfc_hba *phba = vport->phba;
1037 struct lpfc_iocbq *cmdiocb = arg;
1038 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
1039 uint32_t *lp = (uint32_t *) pcmd->virt;
1040 struct serv_parm *sp = (struct serv_parm *) (lp + 1);
1044 memset(&stat, 0, sizeof (struct ls_rjt));
1046 /* For a PLOGI, we only accept if our portname is less
1047 * than the remote portname.
1049 phba->fc_stat.elsLogiCol++;
1050 port_cmp = memcmp(&vport->fc_portname, &sp->portName,
1051 sizeof(struct lpfc_name));
1053 if (port_cmp >= 0) {
1054 /* Reject this request because the remote node will accept
1056 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
1057 stat.un.b.lsRjtRsnCodeExp = LSEXP_CMD_IN_PROGRESS;
1058 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
1061 if (lpfc_rcv_plogi(vport, ndlp, cmdiocb) &&
1062 (ndlp->nlp_flag & NLP_NPR_2B_DISC) &&
1063 (vport->num_disc_nodes)) {
1064 spin_lock_irq(shost->host_lock);
1065 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
1066 spin_unlock_irq(shost->host_lock);
1067 /* Check if there are more PLOGIs to be sent */
1068 lpfc_more_plogi(vport);
1069 if (vport->num_disc_nodes == 0) {
1070 spin_lock_irq(shost->host_lock);
1071 vport->fc_flag &= ~FC_NDISC_ACTIVE;
1072 spin_unlock_irq(shost->host_lock);
1073 lpfc_can_disctmo(vport);
1074 lpfc_end_rscn(vport);
1077 } /* If our portname was less */
1079 return ndlp->nlp_state;
1083 lpfc_rcv_prli_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1084 void *arg, uint32_t evt)
1086 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1089 memset(&stat, 0, sizeof (struct ls_rjt));
1090 stat.un.b.lsRjtRsnCode = LSRJT_LOGICAL_BSY;
1091 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
1092 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
1093 return ndlp->nlp_state;
1097 lpfc_rcv_logo_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1098 void *arg, uint32_t evt)
1100 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1102 /* Retrieve RPI from LOGO IOCB. RPI is used for CMD_ABORT_XRI_CN */
1103 if (vport->phba->sli_rev == LPFC_SLI_REV3)
1104 ndlp->nlp_rpi = cmdiocb->iocb.ulpIoTag;
1105 /* software abort outstanding PLOGI */
1106 lpfc_els_abort(vport->phba, ndlp);
1108 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
1109 return ndlp->nlp_state;
1113 lpfc_rcv_els_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1114 void *arg, uint32_t evt)
1116 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1117 struct lpfc_hba *phba = vport->phba;
1118 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1120 /* software abort outstanding PLOGI */
1121 lpfc_els_abort(phba, ndlp);
1123 if (evt == NLP_EVT_RCV_LOGO) {
1124 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
1126 lpfc_issue_els_logo(vport, ndlp, 0);
1129 /* Put ndlp in npr state set plogi timer for 1 sec */
1130 mod_timer(&ndlp->nlp_delayfunc, jiffies + msecs_to_jiffies(1000 * 1));
1131 spin_lock_irq(shost->host_lock);
1132 ndlp->nlp_flag |= NLP_DELAY_TMO;
1133 spin_unlock_irq(shost->host_lock);
1134 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
1135 ndlp->nlp_prev_state = NLP_STE_PLOGI_ISSUE;
1136 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1138 return ndlp->nlp_state;
1142 lpfc_cmpl_plogi_plogi_issue(struct lpfc_vport *vport,
1143 struct lpfc_nodelist *ndlp,
1147 struct lpfc_hba *phba = vport->phba;
1148 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1149 struct lpfc_iocbq *cmdiocb, *rspiocb;
1150 struct lpfc_dmabuf *pcmd, *prsp, *mp;
1154 struct serv_parm *sp;
1159 cmdiocb = (struct lpfc_iocbq *) arg;
1160 rspiocb = cmdiocb->context_un.rsp_iocb;
1162 if (ndlp->nlp_flag & NLP_ACC_REGLOGIN) {
1163 /* Recovery from PLOGI collision logic */
1164 return ndlp->nlp_state;
1167 irsp = &rspiocb->iocb;
1169 if (irsp->ulpStatus)
1172 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
1174 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
1178 lp = (uint32_t *) prsp->virt;
1179 sp = (struct serv_parm *) ((uint8_t *) lp + sizeof (uint32_t));
1181 /* Some switches have FDMI servers returning 0 for WWN */
1182 if ((ndlp->nlp_DID != FDMI_DID) &&
1183 (wwn_to_u64(sp->portName.u.wwn) == 0 ||
1184 wwn_to_u64(sp->nodeName.u.wwn) == 0)) {
1185 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1186 "0142 PLOGI RSP: Invalid WWN.\n");
1189 if (!lpfc_check_sparm(vport, ndlp, sp, CLASS3, 0))
1191 /* PLOGI chkparm OK */
1192 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1193 "0121 PLOGI chkparm OK Data: x%x x%x x%x x%x\n",
1194 ndlp->nlp_DID, ndlp->nlp_state,
1195 ndlp->nlp_flag, ndlp->nlp_rpi);
1196 if (vport->cfg_fcp_class == 2 && (sp->cls2.classValid))
1197 ndlp->nlp_fcp_info |= CLASS2;
1199 ndlp->nlp_fcp_info |= CLASS3;
1201 ndlp->nlp_class_sup = 0;
1202 if (sp->cls1.classValid)
1203 ndlp->nlp_class_sup |= FC_COS_CLASS1;
1204 if (sp->cls2.classValid)
1205 ndlp->nlp_class_sup |= FC_COS_CLASS2;
1206 if (sp->cls3.classValid)
1207 ndlp->nlp_class_sup |= FC_COS_CLASS3;
1208 if (sp->cls4.classValid)
1209 ndlp->nlp_class_sup |= FC_COS_CLASS4;
1210 ndlp->nlp_maxframe =
1211 ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) | sp->cmn.bbRcvSizeLsb;
1213 if ((vport->fc_flag & FC_PT2PT) &&
1214 (vport->fc_flag & FC_PT2PT_PLOGI)) {
1215 ed_tov = be32_to_cpu(sp->cmn.e_d_tov);
1216 if (sp->cmn.edtovResolution) {
1217 /* E_D_TOV ticks are in nanoseconds */
1218 ed_tov = (phba->fc_edtov + 999999) / 1000000;
1221 ndlp->nlp_flag &= ~NLP_SUPPRESS_RSP;
1222 if ((phba->sli.sli_flag & LPFC_SLI_SUPPRESS_RSP) &&
1223 sp->cmn.valid_vendor_ver_level) {
1224 vid = be32_to_cpu(sp->un.vv.vid);
1225 flag = be32_to_cpu(sp->un.vv.flags);
1226 if ((vid == LPFC_VV_EMLX_ID) &&
1227 (flag & LPFC_VV_SUPPRESS_RSP))
1228 ndlp->nlp_flag |= NLP_SUPPRESS_RSP;
1232 * Use the larger EDTOV
1233 * RATOV = 2 * EDTOV for pt-to-pt
1235 if (ed_tov > phba->fc_edtov)
1236 phba->fc_edtov = ed_tov;
1237 phba->fc_ratov = (2 * phba->fc_edtov) / 1000;
1239 memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
1241 /* Issue config_link / reg_vfi to account for updated TOV's */
1242 if (phba->sli_rev == LPFC_SLI_REV4) {
1243 lpfc_issue_reg_vfi(vport);
1245 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1247 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1248 "0133 PLOGI: no memory "
1250 "Data: x%x x%x x%x x%x\n",
1251 ndlp->nlp_DID, ndlp->nlp_state,
1252 ndlp->nlp_flag, ndlp->nlp_rpi);
1256 lpfc_config_link(phba, mbox);
1258 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1259 mbox->vport = vport;
1260 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
1261 if (rc == MBX_NOT_FINISHED) {
1262 mempool_free(mbox, phba->mbox_mem_pool);
1268 lpfc_unreg_rpi(vport, ndlp);
1270 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1272 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1273 "0018 PLOGI: no memory for reg_login "
1274 "Data: x%x x%x x%x x%x\n",
1275 ndlp->nlp_DID, ndlp->nlp_state,
1276 ndlp->nlp_flag, ndlp->nlp_rpi);
1280 if (lpfc_reg_rpi(phba, vport->vpi, irsp->un.elsreq64.remoteID,
1281 (uint8_t *) sp, mbox, ndlp->nlp_rpi) == 0) {
1282 switch (ndlp->nlp_DID) {
1283 case NameServer_DID:
1284 mbox->mbox_cmpl = lpfc_mbx_cmpl_ns_reg_login;
1287 mbox->mbox_cmpl = lpfc_mbx_cmpl_fdmi_reg_login;
1290 ndlp->nlp_flag |= NLP_REG_LOGIN_SEND;
1291 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
1293 mbox->ctx_ndlp = lpfc_nlp_get(ndlp);
1294 mbox->vport = vport;
1295 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
1296 != MBX_NOT_FINISHED) {
1297 lpfc_nlp_set_state(vport, ndlp,
1298 NLP_STE_REG_LOGIN_ISSUE);
1299 return ndlp->nlp_state;
1301 if (ndlp->nlp_flag & NLP_REG_LOGIN_SEND)
1302 ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND;
1303 /* decrement node reference count to the failed mbox
1307 mp = (struct lpfc_dmabuf *)mbox->ctx_buf;
1308 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1310 mempool_free(mbox, phba->mbox_mem_pool);
1312 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1313 "0134 PLOGI: cannot issue reg_login "
1314 "Data: x%x x%x x%x x%x\n",
1315 ndlp->nlp_DID, ndlp->nlp_state,
1316 ndlp->nlp_flag, ndlp->nlp_rpi);
1318 mempool_free(mbox, phba->mbox_mem_pool);
1320 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1321 "0135 PLOGI: cannot format reg_login "
1322 "Data: x%x x%x x%x x%x\n",
1323 ndlp->nlp_DID, ndlp->nlp_state,
1324 ndlp->nlp_flag, ndlp->nlp_rpi);
1329 if (ndlp->nlp_DID == NameServer_DID) {
1330 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
1331 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1332 "0261 Cannot Register NameServer login\n");
1336 ** In case the node reference counter does not go to zero, ensure that
1337 ** the stale state for the node is not processed.
1340 ndlp->nlp_prev_state = ndlp->nlp_state;
1341 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1342 spin_lock_irq(shost->host_lock);
1343 ndlp->nlp_flag |= NLP_DEFER_RM;
1344 spin_unlock_irq(shost->host_lock);
1345 return NLP_STE_FREED_NODE;
1349 lpfc_cmpl_logo_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1350 void *arg, uint32_t evt)
1352 return ndlp->nlp_state;
1356 lpfc_cmpl_reglogin_plogi_issue(struct lpfc_vport *vport,
1357 struct lpfc_nodelist *ndlp, void *arg, uint32_t evt)
1359 struct lpfc_hba *phba;
1360 LPFC_MBOXQ_t *pmb = (LPFC_MBOXQ_t *) arg;
1361 MAILBOX_t *mb = &pmb->u.mb;
1365 /* Release the RPI */
1366 if (!(phba->pport->load_flag & FC_UNLOADING) &&
1368 rpi = pmb->u.mb.un.varWords[0];
1369 lpfc_release_rpi(phba, vport, ndlp, rpi);
1371 return ndlp->nlp_state;
1375 lpfc_device_rm_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1376 void *arg, uint32_t evt)
1378 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1380 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1381 spin_lock_irq(shost->host_lock);
1382 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
1383 spin_unlock_irq(shost->host_lock);
1384 return ndlp->nlp_state;
1386 /* software abort outstanding PLOGI */
1387 lpfc_els_abort(vport->phba, ndlp);
1389 lpfc_drop_node(vport, ndlp);
1390 return NLP_STE_FREED_NODE;
1395 lpfc_device_recov_plogi_issue(struct lpfc_vport *vport,
1396 struct lpfc_nodelist *ndlp,
1400 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1401 struct lpfc_hba *phba = vport->phba;
1403 /* Don't do anything that will mess up processing of the
1406 if (vport->fc_flag & FC_RSCN_DEFERRED)
1407 return ndlp->nlp_state;
1409 /* software abort outstanding PLOGI */
1410 lpfc_els_abort(phba, ndlp);
1412 ndlp->nlp_prev_state = NLP_STE_PLOGI_ISSUE;
1413 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1414 spin_lock_irq(shost->host_lock);
1415 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
1416 spin_unlock_irq(shost->host_lock);
1418 return ndlp->nlp_state;
1422 lpfc_rcv_plogi_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1423 void *arg, uint32_t evt)
1425 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1426 struct lpfc_hba *phba = vport->phba;
1427 struct lpfc_iocbq *cmdiocb;
1429 /* software abort outstanding ADISC */
1430 lpfc_els_abort(phba, ndlp);
1432 cmdiocb = (struct lpfc_iocbq *) arg;
1434 if (lpfc_rcv_plogi(vport, ndlp, cmdiocb)) {
1435 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1436 spin_lock_irq(shost->host_lock);
1437 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
1438 spin_unlock_irq(shost->host_lock);
1439 if (vport->num_disc_nodes)
1440 lpfc_more_adisc(vport);
1442 return ndlp->nlp_state;
1444 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
1445 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
1446 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
1448 return ndlp->nlp_state;
1452 lpfc_rcv_prli_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1453 void *arg, uint32_t evt)
1455 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1457 if (lpfc_rcv_prli_support_check(vport, ndlp, cmdiocb))
1458 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
1459 return ndlp->nlp_state;
1463 lpfc_rcv_logo_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1464 void *arg, uint32_t evt)
1466 struct lpfc_hba *phba = vport->phba;
1467 struct lpfc_iocbq *cmdiocb;
1469 cmdiocb = (struct lpfc_iocbq *) arg;
1471 /* software abort outstanding ADISC */
1472 lpfc_els_abort(phba, ndlp);
1474 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
1475 return ndlp->nlp_state;
1479 lpfc_rcv_padisc_adisc_issue(struct lpfc_vport *vport,
1480 struct lpfc_nodelist *ndlp,
1481 void *arg, uint32_t evt)
1483 struct lpfc_iocbq *cmdiocb;
1485 cmdiocb = (struct lpfc_iocbq *) arg;
1487 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
1488 return ndlp->nlp_state;
1492 lpfc_rcv_prlo_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1493 void *arg, uint32_t evt)
1495 struct lpfc_iocbq *cmdiocb;
1497 cmdiocb = (struct lpfc_iocbq *) arg;
1499 /* Treat like rcv logo */
1500 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_PRLO);
1501 return ndlp->nlp_state;
1505 lpfc_cmpl_adisc_adisc_issue(struct lpfc_vport *vport,
1506 struct lpfc_nodelist *ndlp,
1507 void *arg, uint32_t evt)
1509 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1510 struct lpfc_hba *phba = vport->phba;
1511 struct lpfc_iocbq *cmdiocb, *rspiocb;
1516 cmdiocb = (struct lpfc_iocbq *) arg;
1517 rspiocb = cmdiocb->context_un.rsp_iocb;
1519 ap = (ADISC *)lpfc_check_elscmpl_iocb(phba, cmdiocb, rspiocb);
1520 irsp = &rspiocb->iocb;
1522 if ((irsp->ulpStatus) ||
1523 (!lpfc_check_adisc(vport, ndlp, &ap->nodeName, &ap->portName))) {
1525 mod_timer(&ndlp->nlp_delayfunc,
1526 jiffies + msecs_to_jiffies(1000));
1527 spin_lock_irq(shost->host_lock);
1528 ndlp->nlp_flag |= NLP_DELAY_TMO;
1529 spin_unlock_irq(shost->host_lock);
1530 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
1532 memset(&ndlp->nlp_nodename, 0, sizeof(struct lpfc_name));
1533 memset(&ndlp->nlp_portname, 0, sizeof(struct lpfc_name));
1535 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
1536 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1537 lpfc_unreg_rpi(vport, ndlp);
1538 return ndlp->nlp_state;
1541 if (phba->sli_rev == LPFC_SLI_REV4) {
1542 rc = lpfc_sli4_resume_rpi(ndlp, NULL, NULL);
1544 /* Stay in state and retry. */
1545 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
1546 return ndlp->nlp_state;
1550 if (ndlp->nlp_type & NLP_FCP_TARGET) {
1551 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
1552 lpfc_nlp_set_state(vport, ndlp, NLP_STE_MAPPED_NODE);
1554 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
1555 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
1558 return ndlp->nlp_state;
1562 lpfc_device_rm_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1563 void *arg, uint32_t evt)
1565 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1567 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1568 spin_lock_irq(shost->host_lock);
1569 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
1570 spin_unlock_irq(shost->host_lock);
1571 return ndlp->nlp_state;
1573 /* software abort outstanding ADISC */
1574 lpfc_els_abort(vport->phba, ndlp);
1576 lpfc_drop_node(vport, ndlp);
1577 return NLP_STE_FREED_NODE;
1582 lpfc_device_recov_adisc_issue(struct lpfc_vport *vport,
1583 struct lpfc_nodelist *ndlp,
1587 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1588 struct lpfc_hba *phba = vport->phba;
1590 /* Don't do anything that will mess up processing of the
1593 if (vport->fc_flag & FC_RSCN_DEFERRED)
1594 return ndlp->nlp_state;
1596 /* software abort outstanding ADISC */
1597 lpfc_els_abort(phba, ndlp);
1599 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
1600 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1601 spin_lock_irq(shost->host_lock);
1602 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
1603 spin_unlock_irq(shost->host_lock);
1604 lpfc_disc_set_adisc(vport, ndlp);
1605 return ndlp->nlp_state;
1609 lpfc_rcv_plogi_reglogin_issue(struct lpfc_vport *vport,
1610 struct lpfc_nodelist *ndlp,
1614 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1616 lpfc_rcv_plogi(vport, ndlp, cmdiocb);
1617 return ndlp->nlp_state;
1621 lpfc_rcv_prli_reglogin_issue(struct lpfc_vport *vport,
1622 struct lpfc_nodelist *ndlp,
1626 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1629 if (!lpfc_rcv_prli_support_check(vport, ndlp, cmdiocb)) {
1630 return ndlp->nlp_state;
1632 if (vport->phba->nvmet_support) {
1633 /* NVME Target mode. Handle and respond to the PRLI and
1634 * transition to UNMAPPED provided the RPI has completed
1637 if (ndlp->nlp_flag & NLP_RPI_REGISTERED) {
1638 lpfc_rcv_prli(vport, ndlp, cmdiocb);
1639 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
1641 /* RPI registration has not completed. Reject the PRLI
1642 * to prevent an illegal state transition when the
1643 * rpi registration does complete.
1645 memset(&stat, 0, sizeof(struct ls_rjt));
1646 stat.un.b.lsRjtRsnCode = LSRJT_LOGICAL_BSY;
1647 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
1648 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb,
1650 return ndlp->nlp_state;
1653 /* Initiator mode. */
1654 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
1656 return ndlp->nlp_state;
1660 lpfc_rcv_logo_reglogin_issue(struct lpfc_vport *vport,
1661 struct lpfc_nodelist *ndlp,
1665 struct lpfc_hba *phba = vport->phba;
1666 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1668 LPFC_MBOXQ_t *nextmb;
1669 struct lpfc_dmabuf *mp;
1670 struct lpfc_nodelist *ns_ndlp;
1672 cmdiocb = (struct lpfc_iocbq *) arg;
1674 /* cleanup any ndlp on mbox q waiting for reglogin cmpl */
1675 if ((mb = phba->sli.mbox_active)) {
1676 if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) &&
1677 (ndlp == (struct lpfc_nodelist *)mb->ctx_ndlp)) {
1678 ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND;
1680 mb->ctx_ndlp = NULL;
1681 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1685 spin_lock_irq(&phba->hbalock);
1686 list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) {
1687 if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) &&
1688 (ndlp == (struct lpfc_nodelist *)mb->ctx_ndlp)) {
1689 mp = (struct lpfc_dmabuf *)(mb->ctx_buf);
1691 __lpfc_mbuf_free(phba, mp->virt, mp->phys);
1694 ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND;
1696 list_del(&mb->list);
1697 phba->sli.mboxq_cnt--;
1698 mempool_free(mb, phba->mbox_mem_pool);
1701 spin_unlock_irq(&phba->hbalock);
1703 /* software abort if any GID_FT is outstanding */
1704 if (vport->cfg_enable_fc4_type != LPFC_ENABLE_FCP) {
1705 ns_ndlp = lpfc_findnode_did(vport, NameServer_DID);
1706 if (ns_ndlp && NLP_CHK_NODE_ACT(ns_ndlp))
1707 lpfc_els_abort(phba, ns_ndlp);
1710 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
1711 return ndlp->nlp_state;
1715 lpfc_rcv_padisc_reglogin_issue(struct lpfc_vport *vport,
1716 struct lpfc_nodelist *ndlp,
1720 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1722 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
1723 return ndlp->nlp_state;
1727 lpfc_rcv_prlo_reglogin_issue(struct lpfc_vport *vport,
1728 struct lpfc_nodelist *ndlp,
1732 struct lpfc_iocbq *cmdiocb;
1734 cmdiocb = (struct lpfc_iocbq *) arg;
1735 lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL);
1736 return ndlp->nlp_state;
1740 lpfc_cmpl_reglogin_reglogin_issue(struct lpfc_vport *vport,
1741 struct lpfc_nodelist *ndlp,
1745 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1746 struct lpfc_hba *phba = vport->phba;
1747 LPFC_MBOXQ_t *pmb = (LPFC_MBOXQ_t *) arg;
1748 MAILBOX_t *mb = &pmb->u.mb;
1749 uint32_t did = mb->un.varWords[1];
1751 if (mb->mbxStatus) {
1752 /* RegLogin failed */
1753 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
1754 "0246 RegLogin failed Data: x%x x%x x%x x%x "
1756 did, mb->mbxStatus, vport->port_state,
1757 mb->un.varRegLogin.vpi,
1758 mb->un.varRegLogin.rpi);
1760 * If RegLogin failed due to lack of HBA resources do not
1763 if (mb->mbxStatus == MBXERR_RPI_FULL) {
1764 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
1765 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1766 return ndlp->nlp_state;
1769 /* Put ndlp in npr state set plogi timer for 1 sec */
1770 mod_timer(&ndlp->nlp_delayfunc,
1771 jiffies + msecs_to_jiffies(1000 * 1));
1772 spin_lock_irq(shost->host_lock);
1773 ndlp->nlp_flag |= NLP_DELAY_TMO;
1774 spin_unlock_irq(shost->host_lock);
1775 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
1777 lpfc_issue_els_logo(vport, ndlp, 0);
1778 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
1779 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1780 return ndlp->nlp_state;
1783 /* SLI4 ports have preallocated logical rpis. */
1784 if (phba->sli_rev < LPFC_SLI_REV4)
1785 ndlp->nlp_rpi = mb->un.varWords[0];
1787 ndlp->nlp_flag |= NLP_RPI_REGISTERED;
1789 /* Only if we are not a fabric nport do we issue PRLI */
1790 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1791 "3066 RegLogin Complete on x%x x%x x%x\n",
1792 did, ndlp->nlp_type, ndlp->nlp_fc4_type);
1793 if (!(ndlp->nlp_type & NLP_FABRIC) &&
1794 (phba->nvmet_support == 0)) {
1795 /* The driver supports FCP and NVME concurrently. If the
1796 * ndlp's nlp_fc4_type is still zero, the driver doesn't
1797 * know what PRLI to send yet. Figure that out now and
1798 * call PRLI depending on the outcome.
1800 if (vport->fc_flag & FC_PT2PT) {
1801 /* If we are pt2pt, there is no Fabric to determine
1802 * the FC4 type of the remote nport. So if NVME
1803 * is configured try it.
1805 ndlp->nlp_fc4_type |= NLP_FC4_FCP;
1806 if ((vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
1807 (vport->cfg_enable_fc4_type == LPFC_ENABLE_NVME)) {
1808 ndlp->nlp_fc4_type |= NLP_FC4_NVME;
1809 /* We need to update the localport also */
1810 lpfc_nvme_update_localport(vport);
1813 } else if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
1814 ndlp->nlp_fc4_type |= NLP_FC4_FCP;
1816 } else if (ndlp->nlp_fc4_type == 0) {
1817 /* If we are only configured for FCP, the driver
1818 * should just issue PRLI for FCP. Otherwise issue
1819 * GFT_ID to determine if remote port supports NVME.
1821 if (vport->cfg_enable_fc4_type != LPFC_ENABLE_FCP) {
1822 lpfc_ns_cmd(vport, SLI_CTNS_GFT_ID, 0,
1824 return ndlp->nlp_state;
1826 ndlp->nlp_fc4_type = NLP_FC4_FCP;
1829 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
1830 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
1831 if (lpfc_issue_els_prli(vport, ndlp, 0)) {
1832 lpfc_issue_els_logo(vport, ndlp, 0);
1833 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
1834 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1837 if ((vport->fc_flag & FC_PT2PT) && phba->nvmet_support)
1838 phba->targetport->port_id = vport->fc_myDID;
1840 /* Only Fabric ports should transition. NVME target
1841 * must complete PRLI.
1843 if (ndlp->nlp_type & NLP_FABRIC) {
1844 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
1845 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
1848 return ndlp->nlp_state;
1852 lpfc_device_rm_reglogin_issue(struct lpfc_vport *vport,
1853 struct lpfc_nodelist *ndlp,
1857 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1859 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1860 spin_lock_irq(shost->host_lock);
1861 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
1862 spin_unlock_irq(shost->host_lock);
1863 return ndlp->nlp_state;
1865 lpfc_drop_node(vport, ndlp);
1866 return NLP_STE_FREED_NODE;
1871 lpfc_device_recov_reglogin_issue(struct lpfc_vport *vport,
1872 struct lpfc_nodelist *ndlp,
1876 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1878 /* Don't do anything that will mess up processing of the
1881 if (vport->fc_flag & FC_RSCN_DEFERRED)
1882 return ndlp->nlp_state;
1884 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
1885 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1886 spin_lock_irq(shost->host_lock);
1888 /* If we are a target we won't immediately transition into PRLI,
1889 * so if REG_LOGIN already completed we don't need to ignore it.
1891 if (!(ndlp->nlp_flag & NLP_RPI_REGISTERED) ||
1892 !vport->phba->nvmet_support)
1893 ndlp->nlp_flag |= NLP_IGNR_REG_CMPL;
1895 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
1896 spin_unlock_irq(shost->host_lock);
1897 lpfc_disc_set_adisc(vport, ndlp);
1898 return ndlp->nlp_state;
1902 lpfc_rcv_plogi_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1903 void *arg, uint32_t evt)
1905 struct lpfc_iocbq *cmdiocb;
1907 cmdiocb = (struct lpfc_iocbq *) arg;
1909 lpfc_rcv_plogi(vport, ndlp, cmdiocb);
1910 return ndlp->nlp_state;
1914 lpfc_rcv_prli_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1915 void *arg, uint32_t evt)
1917 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1919 if (!lpfc_rcv_prli_support_check(vport, ndlp, cmdiocb))
1920 return ndlp->nlp_state;
1921 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
1922 return ndlp->nlp_state;
1926 lpfc_rcv_logo_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1927 void *arg, uint32_t evt)
1929 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1931 /* Software abort outstanding PRLI before sending acc */
1932 lpfc_els_abort(vport->phba, ndlp);
1934 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
1935 return ndlp->nlp_state;
1939 lpfc_rcv_padisc_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1940 void *arg, uint32_t evt)
1942 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1944 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
1945 return ndlp->nlp_state;
1948 /* This routine is envoked when we rcv a PRLO request from a nport
1949 * we are logged into. We should send back a PRLO rsp setting the
1951 * NEXT STATE = PRLI_ISSUE
1954 lpfc_rcv_prlo_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1955 void *arg, uint32_t evt)
1957 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1959 lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL);
1960 return ndlp->nlp_state;
1964 lpfc_cmpl_prli_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1965 void *arg, uint32_t evt)
1967 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1968 struct lpfc_iocbq *cmdiocb, *rspiocb;
1969 struct lpfc_hba *phba = vport->phba;
1972 struct lpfc_nvme_prli *nvpr;
1975 cmdiocb = (struct lpfc_iocbq *) arg;
1976 rspiocb = cmdiocb->context_un.rsp_iocb;
1978 /* A solicited PRLI is either FCP or NVME. The PRLI cmd/rsp
1979 * format is different so NULL the two PRLI types so that the
1980 * driver correctly gets the correct context.
1984 temp_ptr = lpfc_check_elscmpl_iocb(phba, cmdiocb, rspiocb);
1985 if (cmdiocb->iocb_flag & LPFC_PRLI_FCP_REQ)
1986 npr = (PRLI *) temp_ptr;
1987 else if (cmdiocb->iocb_flag & LPFC_PRLI_NVME_REQ)
1988 nvpr = (struct lpfc_nvme_prli *) temp_ptr;
1990 irsp = &rspiocb->iocb;
1991 if (irsp->ulpStatus) {
1992 if ((vport->port_type == LPFC_NPIV_PORT) &&
1993 vport->cfg_restrict_login) {
1997 /* Adjust the nlp_type accordingly if the PRLI failed */
1999 ndlp->nlp_fc4_type &= ~NLP_FC4_FCP;
2001 ndlp->nlp_fc4_type &= ~NLP_FC4_NVME;
2003 /* We can't set the DSM state till BOTH PRLIs complete */
2007 if (npr && (npr->acceptRspCode == PRLI_REQ_EXECUTED) &&
2008 (npr->prliType == PRLI_FCP_TYPE)) {
2009 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_DISC,
2010 "6028 FCP NPR PRLI Cmpl Init %d Target %d\n",
2013 if (npr->initiatorFunc)
2014 ndlp->nlp_type |= NLP_FCP_INITIATOR;
2015 if (npr->targetFunc) {
2016 ndlp->nlp_type |= NLP_FCP_TARGET;
2017 if (npr->writeXferRdyDis)
2018 ndlp->nlp_flag |= NLP_FIRSTBURST;
2021 ndlp->nlp_fcp_info |= NLP_FCP_2_DEVICE;
2024 (bf_get_be32(prli_acc_rsp_code, nvpr) ==
2025 PRLI_REQ_EXECUTED) &&
2026 (bf_get_be32(prli_type_code, nvpr) ==
2029 /* Complete setting up the remote ndlp personality. */
2030 if (bf_get_be32(prli_init, nvpr))
2031 ndlp->nlp_type |= NLP_NVME_INITIATOR;
2033 if (phba->nsler && bf_get_be32(prli_nsler, nvpr))
2034 ndlp->nlp_nvme_info |= NLP_NVME_NSLER;
2036 ndlp->nlp_nvme_info &= ~NLP_NVME_NSLER;
2038 /* Target driver cannot solicit NVME FB. */
2039 if (bf_get_be32(prli_tgt, nvpr)) {
2040 /* Complete the nvme target roles. The transport
2041 * needs to know if the rport is capable of
2042 * discovery in addition to its role.
2044 ndlp->nlp_type |= NLP_NVME_TARGET;
2045 if (bf_get_be32(prli_disc, nvpr))
2046 ndlp->nlp_type |= NLP_NVME_DISCOVERY;
2049 * If prli_fba is set, the Target supports FirstBurst.
2050 * If prli_fb_sz is 0, the FirstBurst size is unlimited,
2051 * otherwise it defines the actual size supported by
2054 if ((bf_get_be32(prli_fba, nvpr) == 1) &&
2055 (phba->cfg_nvme_enable_fb) &&
2056 (!phba->nvmet_support)) {
2057 /* Both sides support FB. The target's first
2058 * burst size is a 512 byte encoded value.
2060 ndlp->nlp_flag |= NLP_FIRSTBURST;
2061 ndlp->nvme_fb_size = bf_get_be32(prli_fb_sz,
2064 /* Expressed in units of 512 bytes */
2065 if (ndlp->nvme_fb_size)
2066 ndlp->nvme_fb_size <<=
2069 ndlp->nvme_fb_size = LPFC_NVME_MAX_FB;
2073 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_DISC,
2074 "6029 NVME PRLI Cmpl w1 x%08x "
2075 "w4 x%08x w5 x%08x flag x%x, "
2076 "fcp_info x%x nlp_type x%x\n",
2077 be32_to_cpu(nvpr->word1),
2078 be32_to_cpu(nvpr->word4),
2079 be32_to_cpu(nvpr->word5),
2080 ndlp->nlp_flag, ndlp->nlp_fcp_info,
2083 if (!(ndlp->nlp_type & NLP_FCP_TARGET) &&
2084 (vport->port_type == LPFC_NPIV_PORT) &&
2085 vport->cfg_restrict_login) {
2087 spin_lock_irq(shost->host_lock);
2088 ndlp->nlp_flag |= NLP_TARGET_REMOVE;
2089 spin_unlock_irq(shost->host_lock);
2090 lpfc_issue_els_logo(vport, ndlp, 0);
2092 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
2093 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
2094 return ndlp->nlp_state;
2098 /* The ndlp state cannot move to MAPPED or UNMAPPED before all PRLIs
2101 if (ndlp->fc4_prli_sent == 0) {
2102 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
2103 if (ndlp->nlp_type & (NLP_FCP_TARGET | NLP_NVME_TARGET))
2104 lpfc_nlp_set_state(vport, ndlp, NLP_STE_MAPPED_NODE);
2105 else if (ndlp->nlp_type &
2106 (NLP_FCP_INITIATOR | NLP_NVME_INITIATOR))
2107 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
2109 lpfc_printf_vlog(vport,
2111 "3067 PRLI's still outstanding "
2112 "on x%06x - count %d, Pend Node Mode "
2114 ndlp->nlp_DID, ndlp->fc4_prli_sent);
2116 return ndlp->nlp_state;
2119 /*! lpfc_device_rm_prli_issue
2130 * This routine is envoked when we a request to remove a nport we are in the
2131 * process of PRLIing. We should software abort outstanding prli, unreg
2132 * login, send a logout. We will change node state to UNUSED_NODE, put it
2133 * on plogi list so it can be freed when LOGO completes.
2138 lpfc_device_rm_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2139 void *arg, uint32_t evt)
2141 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2143 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
2144 spin_lock_irq(shost->host_lock);
2145 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
2146 spin_unlock_irq(shost->host_lock);
2147 return ndlp->nlp_state;
2149 /* software abort outstanding PLOGI */
2150 lpfc_els_abort(vport->phba, ndlp);
2152 lpfc_drop_node(vport, ndlp);
2153 return NLP_STE_FREED_NODE;
2158 /*! lpfc_device_recov_prli_issue
2169 * The routine is envoked when the state of a device is unknown, like
2170 * during a link down. We should remove the nodelist entry from the
2171 * unmapped list, issue a UNREG_LOGIN, do a software abort of the
2172 * outstanding PRLI command, then free the node entry.
2175 lpfc_device_recov_prli_issue(struct lpfc_vport *vport,
2176 struct lpfc_nodelist *ndlp,
2180 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2181 struct lpfc_hba *phba = vport->phba;
2183 /* Don't do anything that will mess up processing of the
2186 if (vport->fc_flag & FC_RSCN_DEFERRED)
2187 return ndlp->nlp_state;
2189 /* software abort outstanding PRLI */
2190 lpfc_els_abort(phba, ndlp);
2192 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
2193 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
2194 spin_lock_irq(shost->host_lock);
2195 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
2196 spin_unlock_irq(shost->host_lock);
2197 lpfc_disc_set_adisc(vport, ndlp);
2198 return ndlp->nlp_state;
2202 lpfc_rcv_plogi_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2203 void *arg, uint32_t evt)
2205 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *)arg;
2208 memset(&stat, 0, sizeof(struct ls_rjt));
2209 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
2210 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
2211 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
2212 return ndlp->nlp_state;
2216 lpfc_rcv_prli_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2217 void *arg, uint32_t evt)
2219 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *)arg;
2222 memset(&stat, 0, sizeof(struct ls_rjt));
2223 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
2224 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
2225 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
2226 return ndlp->nlp_state;
2230 lpfc_rcv_logo_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2231 void *arg, uint32_t evt)
2233 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2234 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *)arg;
2236 spin_lock_irq(shost->host_lock);
2237 ndlp->nlp_flag |= NLP_LOGO_ACC;
2238 spin_unlock_irq(shost->host_lock);
2239 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
2240 return ndlp->nlp_state;
2244 lpfc_rcv_padisc_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2245 void *arg, uint32_t evt)
2247 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *)arg;
2250 memset(&stat, 0, sizeof(struct ls_rjt));
2251 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
2252 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
2253 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
2254 return ndlp->nlp_state;
2258 lpfc_rcv_prlo_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2259 void *arg, uint32_t evt)
2261 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *)arg;
2264 memset(&stat, 0, sizeof(struct ls_rjt));
2265 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
2266 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
2267 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
2268 return ndlp->nlp_state;
2272 lpfc_cmpl_logo_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2273 void *arg, uint32_t evt)
2275 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2277 ndlp->nlp_prev_state = NLP_STE_LOGO_ISSUE;
2278 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
2279 spin_lock_irq(shost->host_lock);
2280 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
2281 spin_unlock_irq(shost->host_lock);
2282 lpfc_disc_set_adisc(vport, ndlp);
2283 return ndlp->nlp_state;
2287 lpfc_device_rm_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2288 void *arg, uint32_t evt)
2291 * DevLoss has timed out and is calling for Device Remove.
2292 * In this case, abort the LOGO and cleanup the ndlp
2295 lpfc_unreg_rpi(vport, ndlp);
2296 /* software abort outstanding PLOGI */
2297 lpfc_els_abort(vport->phba, ndlp);
2298 lpfc_drop_node(vport, ndlp);
2299 return NLP_STE_FREED_NODE;
2303 lpfc_device_recov_logo_issue(struct lpfc_vport *vport,
2304 struct lpfc_nodelist *ndlp,
2305 void *arg, uint32_t evt)
2308 * Device Recovery events have no meaning for a node with a LOGO
2309 * outstanding. The LOGO has to complete first and handle the
2310 * node from that point.
2312 return ndlp->nlp_state;
2316 lpfc_rcv_plogi_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2317 void *arg, uint32_t evt)
2319 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2321 lpfc_rcv_plogi(vport, ndlp, cmdiocb);
2322 return ndlp->nlp_state;
2326 lpfc_rcv_prli_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2327 void *arg, uint32_t evt)
2329 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2331 if (!lpfc_rcv_prli_support_check(vport, ndlp, cmdiocb))
2332 return ndlp->nlp_state;
2334 lpfc_rcv_prli(vport, ndlp, cmdiocb);
2335 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
2336 return ndlp->nlp_state;
2340 lpfc_rcv_logo_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2341 void *arg, uint32_t evt)
2343 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2345 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
2346 return ndlp->nlp_state;
2350 lpfc_rcv_padisc_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2351 void *arg, uint32_t evt)
2353 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2355 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
2356 return ndlp->nlp_state;
2360 lpfc_rcv_prlo_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2361 void *arg, uint32_t evt)
2363 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2365 lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL);
2366 return ndlp->nlp_state;
2370 lpfc_device_recov_unmap_node(struct lpfc_vport *vport,
2371 struct lpfc_nodelist *ndlp,
2375 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2377 ndlp->nlp_prev_state = NLP_STE_UNMAPPED_NODE;
2378 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
2379 spin_lock_irq(shost->host_lock);
2380 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
2381 ndlp->nlp_fc4_type &= ~(NLP_FC4_FCP | NLP_FC4_NVME);
2382 spin_unlock_irq(shost->host_lock);
2383 lpfc_disc_set_adisc(vport, ndlp);
2385 return ndlp->nlp_state;
2389 lpfc_rcv_plogi_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2390 void *arg, uint32_t evt)
2392 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2394 lpfc_rcv_plogi(vport, ndlp, cmdiocb);
2395 return ndlp->nlp_state;
2399 lpfc_rcv_prli_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2400 void *arg, uint32_t evt)
2402 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2404 if (!lpfc_rcv_prli_support_check(vport, ndlp, cmdiocb))
2405 return ndlp->nlp_state;
2406 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
2407 return ndlp->nlp_state;
2411 lpfc_rcv_logo_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2412 void *arg, uint32_t evt)
2414 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2416 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
2417 return ndlp->nlp_state;
2421 lpfc_rcv_padisc_mapped_node(struct lpfc_vport *vport,
2422 struct lpfc_nodelist *ndlp,
2423 void *arg, uint32_t evt)
2425 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2427 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
2428 return ndlp->nlp_state;
2432 lpfc_rcv_prlo_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2433 void *arg, uint32_t evt)
2435 struct lpfc_hba *phba = vport->phba;
2436 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2438 /* flush the target */
2439 lpfc_sli_abort_iocb(vport, &phba->sli.sli3_ring[LPFC_FCP_RING],
2440 ndlp->nlp_sid, 0, LPFC_CTX_TGT);
2442 /* Treat like rcv logo */
2443 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_PRLO);
2444 return ndlp->nlp_state;
2448 lpfc_device_recov_mapped_node(struct lpfc_vport *vport,
2449 struct lpfc_nodelist *ndlp,
2453 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2455 ndlp->nlp_prev_state = NLP_STE_MAPPED_NODE;
2456 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
2457 spin_lock_irq(shost->host_lock);
2458 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
2459 ndlp->nlp_fc4_type &= ~(NLP_FC4_FCP | NLP_FC4_NVME);
2460 spin_unlock_irq(shost->host_lock);
2461 lpfc_disc_set_adisc(vport, ndlp);
2462 return ndlp->nlp_state;
2466 lpfc_rcv_plogi_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2467 void *arg, uint32_t evt)
2469 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2470 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2472 /* Ignore PLOGI if we have an outstanding LOGO */
2473 if (ndlp->nlp_flag & (NLP_LOGO_SND | NLP_LOGO_ACC))
2474 return ndlp->nlp_state;
2475 if (lpfc_rcv_plogi(vport, ndlp, cmdiocb)) {
2476 lpfc_cancel_retry_delay_tmo(vport, ndlp);
2477 spin_lock_irq(shost->host_lock);
2478 ndlp->nlp_flag &= ~(NLP_NPR_ADISC | NLP_NPR_2B_DISC);
2479 spin_unlock_irq(shost->host_lock);
2480 } else if (!(ndlp->nlp_flag & NLP_NPR_2B_DISC)) {
2481 /* send PLOGI immediately, move to PLOGI issue state */
2482 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
2483 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
2484 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
2485 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
2488 return ndlp->nlp_state;
2492 lpfc_rcv_prli_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2493 void *arg, uint32_t evt)
2495 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2496 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2499 memset(&stat, 0, sizeof (struct ls_rjt));
2500 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
2501 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
2502 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
2504 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
2505 if (ndlp->nlp_flag & NLP_NPR_ADISC) {
2506 spin_lock_irq(shost->host_lock);
2507 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
2508 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
2509 spin_unlock_irq(shost->host_lock);
2510 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
2511 lpfc_issue_els_adisc(vport, ndlp, 0);
2513 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
2514 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
2515 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
2518 return ndlp->nlp_state;
2522 lpfc_rcv_logo_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2523 void *arg, uint32_t evt)
2525 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2527 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
2528 return ndlp->nlp_state;
2532 lpfc_rcv_padisc_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2533 void *arg, uint32_t evt)
2535 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2537 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
2539 * Do not start discovery if discovery is about to start
2540 * or discovery in progress for this node. Starting discovery
2541 * here will affect the counting of discovery threads.
2543 if (!(ndlp->nlp_flag & NLP_DELAY_TMO) &&
2544 !(ndlp->nlp_flag & NLP_NPR_2B_DISC)) {
2545 if (ndlp->nlp_flag & NLP_NPR_ADISC) {
2546 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
2547 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
2548 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
2549 lpfc_issue_els_adisc(vport, ndlp, 0);
2551 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
2552 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
2553 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
2556 return ndlp->nlp_state;
2560 lpfc_rcv_prlo_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2561 void *arg, uint32_t evt)
2563 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2564 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2566 spin_lock_irq(shost->host_lock);
2567 ndlp->nlp_flag |= NLP_LOGO_ACC;
2568 spin_unlock_irq(shost->host_lock);
2570 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
2572 if ((ndlp->nlp_flag & NLP_DELAY_TMO) == 0) {
2573 mod_timer(&ndlp->nlp_delayfunc,
2574 jiffies + msecs_to_jiffies(1000 * 1));
2575 spin_lock_irq(shost->host_lock);
2576 ndlp->nlp_flag |= NLP_DELAY_TMO;
2577 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
2578 spin_unlock_irq(shost->host_lock);
2579 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
2581 spin_lock_irq(shost->host_lock);
2582 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
2583 spin_unlock_irq(shost->host_lock);
2585 return ndlp->nlp_state;
2589 lpfc_cmpl_plogi_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2590 void *arg, uint32_t evt)
2592 struct lpfc_iocbq *cmdiocb, *rspiocb;
2594 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2596 cmdiocb = (struct lpfc_iocbq *) arg;
2597 rspiocb = cmdiocb->context_un.rsp_iocb;
2599 irsp = &rspiocb->iocb;
2600 if (irsp->ulpStatus) {
2601 spin_lock_irq(shost->host_lock);
2602 ndlp->nlp_flag |= NLP_DEFER_RM;
2603 spin_unlock_irq(shost->host_lock);
2604 return NLP_STE_FREED_NODE;
2606 return ndlp->nlp_state;
2610 lpfc_cmpl_prli_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2611 void *arg, uint32_t evt)
2613 struct lpfc_iocbq *cmdiocb, *rspiocb;
2616 cmdiocb = (struct lpfc_iocbq *) arg;
2617 rspiocb = cmdiocb->context_un.rsp_iocb;
2619 irsp = &rspiocb->iocb;
2620 if (irsp->ulpStatus && (ndlp->nlp_flag & NLP_NODEV_REMOVE)) {
2621 lpfc_drop_node(vport, ndlp);
2622 return NLP_STE_FREED_NODE;
2624 return ndlp->nlp_state;
2628 lpfc_cmpl_logo_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2629 void *arg, uint32_t evt)
2631 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2633 /* For the fabric port just clear the fc flags. */
2634 if (ndlp->nlp_DID == Fabric_DID) {
2635 spin_lock_irq(shost->host_lock);
2636 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
2637 spin_unlock_irq(shost->host_lock);
2639 lpfc_unreg_rpi(vport, ndlp);
2640 return ndlp->nlp_state;
2644 lpfc_cmpl_adisc_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2645 void *arg, uint32_t evt)
2647 struct lpfc_iocbq *cmdiocb, *rspiocb;
2650 cmdiocb = (struct lpfc_iocbq *) arg;
2651 rspiocb = cmdiocb->context_un.rsp_iocb;
2653 irsp = &rspiocb->iocb;
2654 if (irsp->ulpStatus && (ndlp->nlp_flag & NLP_NODEV_REMOVE)) {
2655 lpfc_drop_node(vport, ndlp);
2656 return NLP_STE_FREED_NODE;
2658 return ndlp->nlp_state;
2662 lpfc_cmpl_reglogin_npr_node(struct lpfc_vport *vport,
2663 struct lpfc_nodelist *ndlp,
2664 void *arg, uint32_t evt)
2666 LPFC_MBOXQ_t *pmb = (LPFC_MBOXQ_t *) arg;
2667 MAILBOX_t *mb = &pmb->u.mb;
2669 if (!mb->mbxStatus) {
2670 /* SLI4 ports have preallocated logical rpis. */
2671 if (vport->phba->sli_rev < LPFC_SLI_REV4)
2672 ndlp->nlp_rpi = mb->un.varWords[0];
2673 ndlp->nlp_flag |= NLP_RPI_REGISTERED;
2674 if (ndlp->nlp_flag & NLP_LOGO_ACC) {
2675 lpfc_unreg_rpi(vport, ndlp);
2678 if (ndlp->nlp_flag & NLP_NODEV_REMOVE) {
2679 lpfc_drop_node(vport, ndlp);
2680 return NLP_STE_FREED_NODE;
2683 return ndlp->nlp_state;
2687 lpfc_device_rm_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2688 void *arg, uint32_t evt)
2690 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2692 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
2693 spin_lock_irq(shost->host_lock);
2694 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
2695 spin_unlock_irq(shost->host_lock);
2696 return ndlp->nlp_state;
2698 lpfc_drop_node(vport, ndlp);
2699 return NLP_STE_FREED_NODE;
2703 lpfc_device_recov_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2704 void *arg, uint32_t evt)
2706 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2708 /* Don't do anything that will mess up processing of the
2711 if (vport->fc_flag & FC_RSCN_DEFERRED)
2712 return ndlp->nlp_state;
2714 lpfc_cancel_retry_delay_tmo(vport, ndlp);
2715 spin_lock_irq(shost->host_lock);
2716 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
2717 ndlp->nlp_fc4_type &= ~(NLP_FC4_FCP | NLP_FC4_NVME);
2718 spin_unlock_irq(shost->host_lock);
2719 return ndlp->nlp_state;
2723 /* This next section defines the NPort Discovery State Machine */
2725 /* There are 4 different double linked lists nodelist entries can reside on.
2726 * The plogi list and adisc list are used when Link Up discovery or RSCN
2727 * processing is needed. Each list holds the nodes that we will send PLOGI
2728 * or ADISC on. These lists will keep track of what nodes will be effected
2729 * by an RSCN, or a Link Up (Typically, all nodes are effected on Link Up).
2730 * The unmapped_list will contain all nodes that we have successfully logged
2731 * into at the Fibre Channel level. The mapped_list will contain all nodes
2732 * that are mapped FCP targets.
2735 * The bind list is a list of undiscovered (potentially non-existent) nodes
2736 * that we have saved binding information on. This information is used when
2737 * nodes transition from the unmapped to the mapped list.
2739 /* For UNUSED_NODE state, the node has just been allocated .
2740 * For PLOGI_ISSUE and REG_LOGIN_ISSUE, the node is on
2741 * the PLOGI list. For REG_LOGIN_COMPL, the node is taken off the PLOGI list
2742 * and put on the unmapped list. For ADISC processing, the node is taken off
2743 * the ADISC list and placed on either the mapped or unmapped list (depending
2744 * on its previous state). Once on the unmapped list, a PRLI is issued and the
2745 * state changed to PRLI_ISSUE. When the PRLI completion occurs, the state is
2746 * changed to UNMAPPED_NODE. If the completion indicates a mapped
2747 * node, the node is taken off the unmapped list. The binding list is checked
2748 * for a valid binding, or a binding is automatically assigned. If binding
2749 * assignment is unsuccessful, the node is left on the unmapped list. If
2750 * binding assignment is successful, the associated binding list entry (if
2751 * any) is removed, and the node is placed on the mapped list.
2754 * For a Link Down, all nodes on the ADISC, PLOGI, unmapped or mapped
2755 * lists will receive a DEVICE_RECOVERY event. If the linkdown or devloss timers
2756 * expire, all effected nodes will receive a DEVICE_RM event.
2759 * For a Link Up or RSCN, all nodes will move from the mapped / unmapped lists
2760 * to either the ADISC or PLOGI list. After a Nameserver query or ALPA loopmap
2761 * check, additional nodes may be added or removed (via DEVICE_RM) to / from
2762 * the PLOGI or ADISC lists. Once the PLOGI and ADISC lists are populated,
2763 * we will first process the ADISC list. 32 entries are processed initially and
2764 * ADISC is initited for each one. Completions / Events for each node are
2765 * funnelled thru the state machine. As each node finishes ADISC processing, it
2766 * starts ADISC for any nodes waiting for ADISC processing. If no nodes are
2767 * waiting, and the ADISC list count is identically 0, then we are done. For
2768 * Link Up discovery, since all nodes on the PLOGI list are UNREG_LOGIN'ed, we
2769 * can issue a CLEAR_LA and reenable Link Events. Next we will process the PLOGI
2770 * list. 32 entries are processed initially and PLOGI is initited for each one.
2771 * Completions / Events for each node are funnelled thru the state machine. As
2772 * each node finishes PLOGI processing, it starts PLOGI for any nodes waiting
2773 * for PLOGI processing. If no nodes are waiting, and the PLOGI list count is
2774 * indentically 0, then we are done. We have now completed discovery / RSCN
2775 * handling. Upon completion, ALL nodes should be on either the mapped or
2779 static uint32_t (*lpfc_disc_action[NLP_STE_MAX_STATE * NLP_EVT_MAX_EVENT])
2780 (struct lpfc_vport *, struct lpfc_nodelist *, void *, uint32_t) = {
2781 /* Action routine Event Current State */
2782 lpfc_rcv_plogi_unused_node, /* RCV_PLOGI UNUSED_NODE */
2783 lpfc_rcv_els_unused_node, /* RCV_PRLI */
2784 lpfc_rcv_logo_unused_node, /* RCV_LOGO */
2785 lpfc_rcv_els_unused_node, /* RCV_ADISC */
2786 lpfc_rcv_els_unused_node, /* RCV_PDISC */
2787 lpfc_rcv_els_unused_node, /* RCV_PRLO */
2788 lpfc_disc_illegal, /* CMPL_PLOGI */
2789 lpfc_disc_illegal, /* CMPL_PRLI */
2790 lpfc_cmpl_logo_unused_node, /* CMPL_LOGO */
2791 lpfc_disc_illegal, /* CMPL_ADISC */
2792 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2793 lpfc_device_rm_unused_node, /* DEVICE_RM */
2794 lpfc_device_recov_unused_node, /* DEVICE_RECOVERY */
2796 lpfc_rcv_plogi_plogi_issue, /* RCV_PLOGI PLOGI_ISSUE */
2797 lpfc_rcv_prli_plogi_issue, /* RCV_PRLI */
2798 lpfc_rcv_logo_plogi_issue, /* RCV_LOGO */
2799 lpfc_rcv_els_plogi_issue, /* RCV_ADISC */
2800 lpfc_rcv_els_plogi_issue, /* RCV_PDISC */
2801 lpfc_rcv_els_plogi_issue, /* RCV_PRLO */
2802 lpfc_cmpl_plogi_plogi_issue, /* CMPL_PLOGI */
2803 lpfc_disc_illegal, /* CMPL_PRLI */
2804 lpfc_cmpl_logo_plogi_issue, /* CMPL_LOGO */
2805 lpfc_disc_illegal, /* CMPL_ADISC */
2806 lpfc_cmpl_reglogin_plogi_issue,/* CMPL_REG_LOGIN */
2807 lpfc_device_rm_plogi_issue, /* DEVICE_RM */
2808 lpfc_device_recov_plogi_issue, /* DEVICE_RECOVERY */
2810 lpfc_rcv_plogi_adisc_issue, /* RCV_PLOGI ADISC_ISSUE */
2811 lpfc_rcv_prli_adisc_issue, /* RCV_PRLI */
2812 lpfc_rcv_logo_adisc_issue, /* RCV_LOGO */
2813 lpfc_rcv_padisc_adisc_issue, /* RCV_ADISC */
2814 lpfc_rcv_padisc_adisc_issue, /* RCV_PDISC */
2815 lpfc_rcv_prlo_adisc_issue, /* RCV_PRLO */
2816 lpfc_disc_illegal, /* CMPL_PLOGI */
2817 lpfc_disc_illegal, /* CMPL_PRLI */
2818 lpfc_disc_illegal, /* CMPL_LOGO */
2819 lpfc_cmpl_adisc_adisc_issue, /* CMPL_ADISC */
2820 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2821 lpfc_device_rm_adisc_issue, /* DEVICE_RM */
2822 lpfc_device_recov_adisc_issue, /* DEVICE_RECOVERY */
2824 lpfc_rcv_plogi_reglogin_issue, /* RCV_PLOGI REG_LOGIN_ISSUE */
2825 lpfc_rcv_prli_reglogin_issue, /* RCV_PLOGI */
2826 lpfc_rcv_logo_reglogin_issue, /* RCV_LOGO */
2827 lpfc_rcv_padisc_reglogin_issue, /* RCV_ADISC */
2828 lpfc_rcv_padisc_reglogin_issue, /* RCV_PDISC */
2829 lpfc_rcv_prlo_reglogin_issue, /* RCV_PRLO */
2830 lpfc_cmpl_plogi_illegal, /* CMPL_PLOGI */
2831 lpfc_disc_illegal, /* CMPL_PRLI */
2832 lpfc_disc_illegal, /* CMPL_LOGO */
2833 lpfc_disc_illegal, /* CMPL_ADISC */
2834 lpfc_cmpl_reglogin_reglogin_issue,/* CMPL_REG_LOGIN */
2835 lpfc_device_rm_reglogin_issue, /* DEVICE_RM */
2836 lpfc_device_recov_reglogin_issue,/* DEVICE_RECOVERY */
2838 lpfc_rcv_plogi_prli_issue, /* RCV_PLOGI PRLI_ISSUE */
2839 lpfc_rcv_prli_prli_issue, /* RCV_PRLI */
2840 lpfc_rcv_logo_prli_issue, /* RCV_LOGO */
2841 lpfc_rcv_padisc_prli_issue, /* RCV_ADISC */
2842 lpfc_rcv_padisc_prli_issue, /* RCV_PDISC */
2843 lpfc_rcv_prlo_prli_issue, /* RCV_PRLO */
2844 lpfc_cmpl_plogi_illegal, /* CMPL_PLOGI */
2845 lpfc_cmpl_prli_prli_issue, /* CMPL_PRLI */
2846 lpfc_disc_illegal, /* CMPL_LOGO */
2847 lpfc_disc_illegal, /* CMPL_ADISC */
2848 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2849 lpfc_device_rm_prli_issue, /* DEVICE_RM */
2850 lpfc_device_recov_prli_issue, /* DEVICE_RECOVERY */
2852 lpfc_rcv_plogi_logo_issue, /* RCV_PLOGI LOGO_ISSUE */
2853 lpfc_rcv_prli_logo_issue, /* RCV_PRLI */
2854 lpfc_rcv_logo_logo_issue, /* RCV_LOGO */
2855 lpfc_rcv_padisc_logo_issue, /* RCV_ADISC */
2856 lpfc_rcv_padisc_logo_issue, /* RCV_PDISC */
2857 lpfc_rcv_prlo_logo_issue, /* RCV_PRLO */
2858 lpfc_cmpl_plogi_illegal, /* CMPL_PLOGI */
2859 lpfc_disc_illegal, /* CMPL_PRLI */
2860 lpfc_cmpl_logo_logo_issue, /* CMPL_LOGO */
2861 lpfc_disc_illegal, /* CMPL_ADISC */
2862 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2863 lpfc_device_rm_logo_issue, /* DEVICE_RM */
2864 lpfc_device_recov_logo_issue, /* DEVICE_RECOVERY */
2866 lpfc_rcv_plogi_unmap_node, /* RCV_PLOGI UNMAPPED_NODE */
2867 lpfc_rcv_prli_unmap_node, /* RCV_PRLI */
2868 lpfc_rcv_logo_unmap_node, /* RCV_LOGO */
2869 lpfc_rcv_padisc_unmap_node, /* RCV_ADISC */
2870 lpfc_rcv_padisc_unmap_node, /* RCV_PDISC */
2871 lpfc_rcv_prlo_unmap_node, /* RCV_PRLO */
2872 lpfc_disc_illegal, /* CMPL_PLOGI */
2873 lpfc_disc_illegal, /* CMPL_PRLI */
2874 lpfc_disc_illegal, /* CMPL_LOGO */
2875 lpfc_disc_illegal, /* CMPL_ADISC */
2876 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2877 lpfc_disc_illegal, /* DEVICE_RM */
2878 lpfc_device_recov_unmap_node, /* DEVICE_RECOVERY */
2880 lpfc_rcv_plogi_mapped_node, /* RCV_PLOGI MAPPED_NODE */
2881 lpfc_rcv_prli_mapped_node, /* RCV_PRLI */
2882 lpfc_rcv_logo_mapped_node, /* RCV_LOGO */
2883 lpfc_rcv_padisc_mapped_node, /* RCV_ADISC */
2884 lpfc_rcv_padisc_mapped_node, /* RCV_PDISC */
2885 lpfc_rcv_prlo_mapped_node, /* RCV_PRLO */
2886 lpfc_disc_illegal, /* CMPL_PLOGI */
2887 lpfc_disc_illegal, /* CMPL_PRLI */
2888 lpfc_disc_illegal, /* CMPL_LOGO */
2889 lpfc_disc_illegal, /* CMPL_ADISC */
2890 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2891 lpfc_disc_illegal, /* DEVICE_RM */
2892 lpfc_device_recov_mapped_node, /* DEVICE_RECOVERY */
2894 lpfc_rcv_plogi_npr_node, /* RCV_PLOGI NPR_NODE */
2895 lpfc_rcv_prli_npr_node, /* RCV_PRLI */
2896 lpfc_rcv_logo_npr_node, /* RCV_LOGO */
2897 lpfc_rcv_padisc_npr_node, /* RCV_ADISC */
2898 lpfc_rcv_padisc_npr_node, /* RCV_PDISC */
2899 lpfc_rcv_prlo_npr_node, /* RCV_PRLO */
2900 lpfc_cmpl_plogi_npr_node, /* CMPL_PLOGI */
2901 lpfc_cmpl_prli_npr_node, /* CMPL_PRLI */
2902 lpfc_cmpl_logo_npr_node, /* CMPL_LOGO */
2903 lpfc_cmpl_adisc_npr_node, /* CMPL_ADISC */
2904 lpfc_cmpl_reglogin_npr_node, /* CMPL_REG_LOGIN */
2905 lpfc_device_rm_npr_node, /* DEVICE_RM */
2906 lpfc_device_recov_npr_node, /* DEVICE_RECOVERY */
2910 lpfc_disc_state_machine(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2911 void *arg, uint32_t evt)
2913 uint32_t cur_state, rc;
2914 uint32_t(*func) (struct lpfc_vport *, struct lpfc_nodelist *, void *,
2916 uint32_t got_ndlp = 0;
2919 if (lpfc_nlp_get(ndlp))
2922 cur_state = ndlp->nlp_state;
2924 data1 = (((uint32_t)ndlp->nlp_fc4_type << 16) |
2925 ((uint32_t)ndlp->nlp_type));
2926 /* DSM in event <evt> on NPort <nlp_DID> in state <cur_state> */
2927 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2928 "0211 DSM in event x%x on NPort x%x in "
2929 "state %d rpi x%x Data: x%x x%x\n",
2930 evt, ndlp->nlp_DID, cur_state, ndlp->nlp_rpi,
2931 ndlp->nlp_flag, data1);
2933 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_DSM,
2934 "DSM in: evt:%d ste:%d did:x%x",
2935 evt, cur_state, ndlp->nlp_DID);
2937 func = lpfc_disc_action[(cur_state * NLP_EVT_MAX_EVENT) + evt];
2938 rc = (func) (vport, ndlp, arg, evt);
2940 /* DSM out state <rc> on NPort <nlp_DID> */
2942 data1 = (((uint32_t)ndlp->nlp_fc4_type << 16) |
2943 ((uint32_t)ndlp->nlp_type));
2944 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2945 "0212 DSM out state %d on NPort x%x "
2946 "rpi x%x Data: x%x x%x\n",
2947 rc, ndlp->nlp_DID, ndlp->nlp_rpi, ndlp->nlp_flag,
2950 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_DSM,
2951 "DSM out: ste:%d did:x%x flg:x%x",
2952 rc, ndlp->nlp_DID, ndlp->nlp_flag);
2953 /* Decrement the ndlp reference count held for this function */
2956 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2957 "0213 DSM out state %d on NPort free\n", rc);
2959 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_DSM,
2960 "DSM out: ste:%d did:x%x flg:x%x",