1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2017 Broadcom. All Rights Reserved. The term *
5 * “Broadcom” refers to Broadcom Limited 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 /* Abort outstanding I/O on NPort <nlp_DID> */
219 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_DISCOVERY,
220 "2819 Abort outstanding I/O on NPort x%x "
221 "Data: x%x x%x x%x\n",
222 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
224 /* Clean up all fabric IOs first.*/
225 lpfc_fabric_abort_nport(ndlp);
228 * Lock the ELS ring txcmplq for SLI3/SLI4 and build a local list
229 * of all ELS IOs that need an ABTS. The IOs need to stay on the
230 * txcmplq so that the abort operation completes them successfully.
232 spin_lock_irq(&phba->hbalock);
233 if (phba->sli_rev == LPFC_SLI_REV4)
234 spin_lock(&pring->ring_lock);
235 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
236 /* Add to abort_list on on NDLP match. */
237 if (lpfc_check_sli_ndlp(phba, pring, iocb, ndlp))
238 list_add_tail(&iocb->dlist, &abort_list);
240 if (phba->sli_rev == LPFC_SLI_REV4)
241 spin_unlock(&pring->ring_lock);
242 spin_unlock_irq(&phba->hbalock);
244 /* Abort the targeted IOs and remove them from the abort list. */
245 list_for_each_entry_safe(iocb, next_iocb, &abort_list, dlist) {
246 spin_lock_irq(&phba->hbalock);
247 list_del_init(&iocb->dlist);
248 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
249 spin_unlock_irq(&phba->hbalock);
252 INIT_LIST_HEAD(&abort_list);
254 /* Now process the txq */
255 spin_lock_irq(&phba->hbalock);
256 if (phba->sli_rev == LPFC_SLI_REV4)
257 spin_lock(&pring->ring_lock);
259 list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
260 /* Check to see if iocb matches the nport we are looking for */
261 if (lpfc_check_sli_ndlp(phba, pring, iocb, ndlp)) {
262 list_del_init(&iocb->list);
263 list_add_tail(&iocb->list, &abort_list);
267 if (phba->sli_rev == LPFC_SLI_REV4)
268 spin_unlock(&pring->ring_lock);
269 spin_unlock_irq(&phba->hbalock);
271 /* Cancel all the IOCBs from the completions list */
272 lpfc_sli_cancel_iocbs(phba, &abort_list,
273 IOSTAT_LOCAL_REJECT, IOERR_SLI_ABORTED);
275 lpfc_cancel_retry_delay_tmo(phba->pport, ndlp);
280 lpfc_rcv_plogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
281 struct lpfc_iocbq *cmdiocb)
283 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
284 struct lpfc_hba *phba = vport->phba;
285 struct lpfc_dmabuf *pcmd;
286 uint64_t nlp_portwwn = 0;
289 struct serv_parm *sp;
296 memset(&stat, 0, sizeof (struct ls_rjt));
297 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
298 lp = (uint32_t *) pcmd->virt;
299 sp = (struct serv_parm *) ((uint8_t *) lp + sizeof (uint32_t));
300 if (wwn_to_u64(sp->portName.u.wwn) == 0) {
301 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
302 "0140 PLOGI Reject: invalid nname\n");
303 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
304 stat.un.b.lsRjtRsnCodeExp = LSEXP_INVALID_PNAME;
305 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
309 if (wwn_to_u64(sp->nodeName.u.wwn) == 0) {
310 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
311 "0141 PLOGI Reject: invalid pname\n");
312 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
313 stat.un.b.lsRjtRsnCodeExp = LSEXP_INVALID_NNAME;
314 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
319 nlp_portwwn = wwn_to_u64(ndlp->nlp_portname.u.wwn);
320 if ((lpfc_check_sparm(vport, ndlp, sp, CLASS3, 0) == 0)) {
321 /* Reject this request because invalid parameters */
322 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
323 stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
324 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
328 icmd = &cmdiocb->iocb;
330 /* PLOGI chkparm OK */
331 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
332 "0114 PLOGI chkparm OK Data: x%x x%x x%x "
334 ndlp->nlp_DID, ndlp->nlp_state, ndlp->nlp_flag,
335 ndlp->nlp_rpi, vport->port_state,
338 if (vport->cfg_fcp_class == 2 && sp->cls2.classValid)
339 ndlp->nlp_fcp_info |= CLASS2;
341 ndlp->nlp_fcp_info |= CLASS3;
343 ndlp->nlp_class_sup = 0;
344 if (sp->cls1.classValid)
345 ndlp->nlp_class_sup |= FC_COS_CLASS1;
346 if (sp->cls2.classValid)
347 ndlp->nlp_class_sup |= FC_COS_CLASS2;
348 if (sp->cls3.classValid)
349 ndlp->nlp_class_sup |= FC_COS_CLASS3;
350 if (sp->cls4.classValid)
351 ndlp->nlp_class_sup |= FC_COS_CLASS4;
353 ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) | sp->cmn.bbRcvSizeLsb;
355 /* if already logged in, do implicit logout */
356 switch (ndlp->nlp_state) {
357 case NLP_STE_NPR_NODE:
358 if (!(ndlp->nlp_flag & NLP_NPR_ADISC))
360 case NLP_STE_REG_LOGIN_ISSUE:
361 case NLP_STE_PRLI_ISSUE:
362 case NLP_STE_UNMAPPED_NODE:
363 case NLP_STE_MAPPED_NODE:
364 /* lpfc_plogi_confirm_nport skips fabric did, handle it here */
365 if (!(ndlp->nlp_type & NLP_FABRIC)) {
366 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb,
370 if (nlp_portwwn != 0 &&
371 nlp_portwwn != wwn_to_u64(sp->portName.u.wwn))
372 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
373 "0143 PLOGI recv'd from DID: x%x "
374 "WWPN changed: old %llx new %llx\n",
376 (unsigned long long)nlp_portwwn,
378 wwn_to_u64(sp->portName.u.wwn));
380 ndlp->nlp_prev_state = ndlp->nlp_state;
381 /* rport needs to be unregistered first */
382 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
386 /* Check for Nport to NPort pt2pt protocol */
387 if ((vport->fc_flag & FC_PT2PT) &&
388 !(vport->fc_flag & FC_PT2PT_PLOGI)) {
389 /* rcv'ed PLOGI decides what our NPortId will be */
390 vport->fc_myDID = icmd->un.rcvels.parmRo;
392 ed_tov = be32_to_cpu(sp->cmn.e_d_tov);
393 if (sp->cmn.edtovResolution) {
394 /* E_D_TOV ticks are in nanoseconds */
395 ed_tov = (phba->fc_edtov + 999999) / 1000000;
399 * For pt-to-pt, use the larger EDTOV
402 if (ed_tov > phba->fc_edtov)
403 phba->fc_edtov = ed_tov;
404 phba->fc_ratov = (2 * phba->fc_edtov) / 1000;
406 memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
408 /* Issue config_link / reg_vfi to account for updated TOV's */
410 if (phba->sli_rev == LPFC_SLI_REV4)
411 lpfc_issue_reg_vfi(vport);
413 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
416 lpfc_config_link(phba, mbox);
417 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
419 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
420 if (rc == MBX_NOT_FINISHED) {
421 mempool_free(mbox, phba->mbox_mem_pool);
426 lpfc_can_disctmo(vport);
429 ndlp->nlp_flag &= ~NLP_SUPPRESS_RSP;
430 if ((phba->sli.sli_flag & LPFC_SLI_SUPPRESS_RSP) &&
431 sp->cmn.valid_vendor_ver_level) {
432 vid = be32_to_cpu(sp->un.vv.vid);
433 flag = be32_to_cpu(sp->un.vv.flags);
434 if ((vid == LPFC_VV_EMLX_ID) && (flag & LPFC_VV_SUPPRESS_RSP))
435 ndlp->nlp_flag |= NLP_SUPPRESS_RSP;
438 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
442 /* Registering an existing RPI behaves differently for SLI3 vs SLI4 */
443 if (phba->sli_rev == LPFC_SLI_REV4)
444 lpfc_unreg_rpi(vport, ndlp);
446 rc = lpfc_reg_rpi(phba, vport->vpi, icmd->un.rcvels.remoteID,
447 (uint8_t *) sp, mbox, ndlp->nlp_rpi);
449 mempool_free(mbox, phba->mbox_mem_pool);
453 /* ACC PLOGI rsp command needs to execute first,
454 * queue this mbox command to be processed later.
456 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
458 * mbox->context2 = lpfc_nlp_get(ndlp) deferred until mailbox
459 * command issued in lpfc_cmpl_els_acc().
462 spin_lock_irq(shost->host_lock);
463 ndlp->nlp_flag |= (NLP_ACC_REGLOGIN | NLP_RCV_PLOGI);
464 spin_unlock_irq(shost->host_lock);
467 * If there is an outstanding PLOGI issued, abort it before
468 * sending ACC rsp for received PLOGI. If pending plogi
469 * is not canceled here, the plogi will be rejected by
470 * remote port and will be retried. On a configuration with
471 * single discovery thread, this will cause a huge delay in
472 * discovery. Also this will cause multiple state machines
473 * running in parallel for this node.
475 if (ndlp->nlp_state == NLP_STE_PLOGI_ISSUE) {
476 /* software abort outstanding PLOGI */
477 lpfc_els_abort(phba, ndlp);
480 if ((vport->port_type == LPFC_NPIV_PORT &&
481 vport->cfg_restrict_login)) {
483 /* In order to preserve RPIs, we want to cleanup
484 * the default RPI the firmware created to rcv
485 * this ELS request. The only way to do this is
486 * to register, then unregister the RPI.
488 spin_lock_irq(shost->host_lock);
489 ndlp->nlp_flag |= NLP_RM_DFLT_RPI;
490 spin_unlock_irq(shost->host_lock);
491 stat.un.b.lsRjtRsnCode = LSRJT_INVALID_CMD;
492 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
493 rc = lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb,
496 mempool_free(mbox, phba->mbox_mem_pool);
499 rc = lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp, mbox);
501 mempool_free(mbox, phba->mbox_mem_pool);
504 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
505 stat.un.b.lsRjtRsnCodeExp = LSEXP_OUT_OF_RESOURCE;
506 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
511 * lpfc_mbx_cmpl_resume_rpi - Resume RPI completion routine
512 * @phba: pointer to lpfc hba data structure.
513 * @mboxq: pointer to mailbox object
515 * This routine is invoked to issue a completion to a rcv'ed
516 * ADISC or PDISC after the paused RPI has been resumed.
519 lpfc_mbx_cmpl_resume_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
521 struct lpfc_vport *vport;
522 struct lpfc_iocbq *elsiocb;
523 struct lpfc_nodelist *ndlp;
526 elsiocb = (struct lpfc_iocbq *)mboxq->context1;
527 ndlp = (struct lpfc_nodelist *) mboxq->context2;
528 vport = mboxq->vport;
529 cmd = elsiocb->drvrTimeout;
531 if (cmd == ELS_CMD_ADISC) {
532 lpfc_els_rsp_adisc_acc(vport, elsiocb, ndlp);
534 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, elsiocb,
538 mempool_free(mboxq, phba->mbox_mem_pool);
542 lpfc_rcv_padisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
543 struct lpfc_iocbq *cmdiocb)
545 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
546 struct lpfc_iocbq *elsiocb;
547 struct lpfc_dmabuf *pcmd;
548 struct serv_parm *sp;
549 struct lpfc_name *pnn, *ppn;
556 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
557 lp = (uint32_t *) pcmd->virt;
560 if (cmd == ELS_CMD_ADISC) {
562 pnn = (struct lpfc_name *) & ap->nodeName;
563 ppn = (struct lpfc_name *) & ap->portName;
565 sp = (struct serv_parm *) lp;
566 pnn = (struct lpfc_name *) & sp->nodeName;
567 ppn = (struct lpfc_name *) & sp->portName;
570 icmd = &cmdiocb->iocb;
571 if (icmd->ulpStatus == 0 && lpfc_check_adisc(vport, ndlp, pnn, ppn)) {
574 * As soon as we send ACC, the remote NPort can
575 * start sending us data. Thus, for SLI4 we must
576 * resume the RPI before the ACC goes out.
578 if (vport->phba->sli_rev == LPFC_SLI_REV4) {
579 elsiocb = kmalloc(sizeof(struct lpfc_iocbq),
583 /* Save info from cmd IOCB used in rsp */
584 memcpy((uint8_t *)elsiocb, (uint8_t *)cmdiocb,
585 sizeof(struct lpfc_iocbq));
587 /* Save the ELS cmd */
588 elsiocb->drvrTimeout = cmd;
590 lpfc_sli4_resume_rpi(ndlp,
591 lpfc_mbx_cmpl_resume_rpi, elsiocb);
596 if (cmd == ELS_CMD_ADISC) {
597 lpfc_els_rsp_adisc_acc(vport, cmdiocb, ndlp);
599 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb,
603 /* If we are authenticated, move to the proper state */
604 if (ndlp->nlp_type & NLP_FCP_TARGET)
605 lpfc_nlp_set_state(vport, ndlp, NLP_STE_MAPPED_NODE);
607 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
611 /* Reject this request because invalid parameters */
612 stat.un.b.lsRjtRsvd0 = 0;
613 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
614 stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
615 stat.un.b.vendorUnique = 0;
616 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
619 mod_timer(&ndlp->nlp_delayfunc, jiffies + msecs_to_jiffies(1000));
621 spin_lock_irq(shost->host_lock);
622 ndlp->nlp_flag |= NLP_DELAY_TMO;
623 spin_unlock_irq(shost->host_lock);
624 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
625 ndlp->nlp_prev_state = ndlp->nlp_state;
626 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
631 lpfc_rcv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
632 struct lpfc_iocbq *cmdiocb, uint32_t els_cmd)
634 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
635 struct lpfc_hba *phba = vport->phba;
636 struct lpfc_vport **vports;
637 int i, active_vlink_present = 0 ;
639 /* Put ndlp in NPR state with 1 sec timeout for plogi, ACC logo */
640 /* Only call LOGO ACC for first LOGO, this avoids sending unnecessary
641 * PLOGIs during LOGO storms from a device.
643 spin_lock_irq(shost->host_lock);
644 ndlp->nlp_flag |= NLP_LOGO_ACC;
645 spin_unlock_irq(shost->host_lock);
646 if (els_cmd == ELS_CMD_PRLO)
647 lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL);
649 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
650 if (ndlp->nlp_DID == Fabric_DID) {
651 if (vport->port_state <= LPFC_FDISC)
653 lpfc_linkdown_port(vport);
654 spin_lock_irq(shost->host_lock);
655 vport->fc_flag |= FC_VPORT_LOGO_RCVD;
656 spin_unlock_irq(shost->host_lock);
657 vports = lpfc_create_vport_work_array(phba);
659 for (i = 0; i <= phba->max_vports && vports[i] != NULL;
661 if ((!(vports[i]->fc_flag &
662 FC_VPORT_LOGO_RCVD)) &&
663 (vports[i]->port_state > LPFC_FDISC)) {
664 active_vlink_present = 1;
668 lpfc_destroy_vport_work_array(phba, vports);
672 * Don't re-instantiate if vport is marked for deletion.
673 * If we are here first then vport_delete is going to wait
674 * for discovery to complete.
676 if (!(vport->load_flag & FC_UNLOADING) &&
677 active_vlink_present) {
679 * If there are other active VLinks present,
680 * re-instantiate the Vlink using FDISC.
682 mod_timer(&ndlp->nlp_delayfunc,
683 jiffies + msecs_to_jiffies(1000));
684 spin_lock_irq(shost->host_lock);
685 ndlp->nlp_flag |= NLP_DELAY_TMO;
686 spin_unlock_irq(shost->host_lock);
687 ndlp->nlp_last_elscmd = ELS_CMD_FDISC;
688 vport->port_state = LPFC_FDISC;
690 spin_lock_irq(shost->host_lock);
691 phba->pport->fc_flag &= ~FC_LOGO_RCVD_DID_CHNG;
692 spin_unlock_irq(shost->host_lock);
693 lpfc_retry_pport_discovery(phba);
695 } else if ((!(ndlp->nlp_type & NLP_FABRIC) &&
696 ((ndlp->nlp_type & NLP_FCP_TARGET) ||
697 !(ndlp->nlp_type & NLP_FCP_INITIATOR))) ||
698 (ndlp->nlp_state == NLP_STE_ADISC_ISSUE)) {
699 /* Only try to re-login if this is NOT a Fabric Node */
700 mod_timer(&ndlp->nlp_delayfunc,
701 jiffies + msecs_to_jiffies(1000 * 1));
702 spin_lock_irq(shost->host_lock);
703 ndlp->nlp_flag |= NLP_DELAY_TMO;
704 spin_unlock_irq(shost->host_lock);
706 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
709 ndlp->nlp_prev_state = ndlp->nlp_state;
710 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
712 spin_lock_irq(shost->host_lock);
713 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
714 spin_unlock_irq(shost->host_lock);
715 /* The driver has to wait until the ACC completes before it continues
716 * processing the LOGO. The action will resume in
717 * lpfc_cmpl_els_logo_acc routine. Since part of processing includes an
718 * unreg_login, the driver waits so the ACC does not get aborted.
724 lpfc_rcv_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
725 struct lpfc_iocbq *cmdiocb)
727 struct lpfc_hba *phba = vport->phba;
728 struct lpfc_dmabuf *pcmd;
731 struct fc_rport *rport = ndlp->rport;
734 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
735 lp = (uint32_t *) pcmd->virt;
736 npr = (PRLI *) ((uint8_t *) lp + sizeof (uint32_t));
738 ndlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR);
739 ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
740 ndlp->nlp_flag &= ~NLP_FIRSTBURST;
741 if ((npr->prliType == PRLI_FCP_TYPE) ||
742 (npr->prliType == PRLI_NVME_TYPE)) {
743 if (npr->initiatorFunc) {
744 if (npr->prliType == PRLI_FCP_TYPE)
745 ndlp->nlp_type |= NLP_FCP_INITIATOR;
746 if (npr->prliType == PRLI_NVME_TYPE)
747 ndlp->nlp_type |= NLP_NVME_INITIATOR;
749 if (npr->targetFunc) {
750 if (npr->prliType == PRLI_FCP_TYPE)
751 ndlp->nlp_type |= NLP_FCP_TARGET;
752 if (npr->prliType == PRLI_NVME_TYPE)
753 ndlp->nlp_type |= NLP_NVME_TARGET;
754 if (npr->writeXferRdyDis)
755 ndlp->nlp_flag |= NLP_FIRSTBURST;
758 ndlp->nlp_fcp_info |= NLP_FCP_2_DEVICE;
760 /* If this driver is in nvme target mode, set the ndlp's fc4
761 * type to NVME provided the PRLI response claims NVME FC4
762 * type. Target mode does not issue gft_id so doesn't get
763 * the fc4 type set until now.
765 if ((phba->nvmet_support) && (npr->prliType == PRLI_NVME_TYPE))
766 ndlp->nlp_fc4_type |= NLP_FC4_NVME;
769 /* We need to update the rport role values */
770 roles = FC_RPORT_ROLE_UNKNOWN;
771 if (ndlp->nlp_type & NLP_FCP_INITIATOR)
772 roles |= FC_RPORT_ROLE_FCP_INITIATOR;
773 if (ndlp->nlp_type & NLP_FCP_TARGET)
774 roles |= FC_RPORT_ROLE_FCP_TARGET;
776 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
777 "rport rolechg: role:x%x did:x%x flg:x%x",
778 roles, ndlp->nlp_DID, ndlp->nlp_flag);
780 if (phba->cfg_enable_fc4_type != LPFC_ENABLE_NVME)
781 fc_remote_port_rolechg(rport, roles);
786 lpfc_disc_set_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
788 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
790 if (!(ndlp->nlp_flag & NLP_RPI_REGISTERED)) {
791 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
795 if (!(vport->fc_flag & FC_PT2PT)) {
796 /* Check config parameter use-adisc or FCP-2 */
797 if ((vport->cfg_use_adisc && (vport->fc_flag & FC_RSCN_MODE)) ||
798 ((ndlp->nlp_fcp_info & NLP_FCP_2_DEVICE) &&
799 (ndlp->nlp_type & NLP_FCP_TARGET))) {
800 spin_lock_irq(shost->host_lock);
801 ndlp->nlp_flag |= NLP_NPR_ADISC;
802 spin_unlock_irq(shost->host_lock);
806 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
807 lpfc_unreg_rpi(vport, ndlp);
812 * lpfc_release_rpi - Release a RPI by issuing unreg_login mailbox cmd.
813 * @phba : Pointer to lpfc_hba structure.
814 * @vport: Pointer to lpfc_vport structure.
815 * @rpi : rpi to be release.
817 * This function will send a unreg_login mailbox command to the firmware
821 lpfc_release_rpi(struct lpfc_hba *phba,
822 struct lpfc_vport *vport,
828 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
831 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
832 "2796 mailbox memory allocation failed \n");
834 lpfc_unreg_login(phba, vport->vpi, rpi, pmb);
835 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
836 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
837 if (rc == MBX_NOT_FINISHED)
838 mempool_free(pmb, phba->mbox_mem_pool);
843 lpfc_disc_illegal(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
844 void *arg, uint32_t evt)
846 struct lpfc_hba *phba;
847 LPFC_MBOXQ_t *pmb = (LPFC_MBOXQ_t *) arg;
851 /* Release the RPI if reglogin completing */
852 if (!(phba->pport->load_flag & FC_UNLOADING) &&
853 (evt == NLP_EVT_CMPL_REG_LOGIN) &&
854 (!pmb->u.mb.mbxStatus)) {
855 rpi = pmb->u.mb.un.varWords[0];
856 lpfc_release_rpi(phba, vport, rpi);
858 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
859 "0271 Illegal State Transition: node x%x "
860 "event x%x, state x%x Data: x%x x%x\n",
861 ndlp->nlp_DID, evt, ndlp->nlp_state, ndlp->nlp_rpi,
863 return ndlp->nlp_state;
867 lpfc_cmpl_plogi_illegal(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
868 void *arg, uint32_t evt)
870 /* This transition is only legal if we previously
871 * rcv'ed a PLOGI. Since we don't want 2 discovery threads
872 * working on the same NPortID, do nothing for this thread
875 if (!(ndlp->nlp_flag & NLP_RCV_PLOGI)) {
876 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
877 "0272 Illegal State Transition: node x%x "
878 "event x%x, state x%x Data: x%x x%x\n",
879 ndlp->nlp_DID, evt, ndlp->nlp_state, ndlp->nlp_rpi,
882 return ndlp->nlp_state;
885 /* Start of Discovery State Machine routines */
888 lpfc_rcv_plogi_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
889 void *arg, uint32_t evt)
891 struct lpfc_iocbq *cmdiocb;
893 cmdiocb = (struct lpfc_iocbq *) arg;
895 if (lpfc_rcv_plogi(vport, ndlp, cmdiocb)) {
896 return ndlp->nlp_state;
898 return NLP_STE_FREED_NODE;
902 lpfc_rcv_els_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
903 void *arg, uint32_t evt)
905 lpfc_issue_els_logo(vport, ndlp, 0);
906 return ndlp->nlp_state;
910 lpfc_rcv_logo_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
911 void *arg, uint32_t evt)
913 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
914 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
916 spin_lock_irq(shost->host_lock);
917 ndlp->nlp_flag |= NLP_LOGO_ACC;
918 spin_unlock_irq(shost->host_lock);
919 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
921 return ndlp->nlp_state;
925 lpfc_cmpl_logo_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
926 void *arg, uint32_t evt)
928 return NLP_STE_FREED_NODE;
932 lpfc_device_rm_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
933 void *arg, uint32_t evt)
935 return NLP_STE_FREED_NODE;
939 lpfc_device_recov_unused_node(struct lpfc_vport *vport,
940 struct lpfc_nodelist *ndlp,
941 void *arg, uint32_t evt)
943 return ndlp->nlp_state;
947 lpfc_rcv_plogi_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
948 void *arg, uint32_t evt)
950 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
951 struct lpfc_hba *phba = vport->phba;
952 struct lpfc_iocbq *cmdiocb = arg;
953 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
954 uint32_t *lp = (uint32_t *) pcmd->virt;
955 struct serv_parm *sp = (struct serv_parm *) (lp + 1);
959 memset(&stat, 0, sizeof (struct ls_rjt));
961 /* For a PLOGI, we only accept if our portname is less
962 * than the remote portname.
964 phba->fc_stat.elsLogiCol++;
965 port_cmp = memcmp(&vport->fc_portname, &sp->portName,
966 sizeof(struct lpfc_name));
969 /* Reject this request because the remote node will accept
971 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
972 stat.un.b.lsRjtRsnCodeExp = LSEXP_CMD_IN_PROGRESS;
973 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
976 if (lpfc_rcv_plogi(vport, ndlp, cmdiocb) &&
977 (ndlp->nlp_flag & NLP_NPR_2B_DISC) &&
978 (vport->num_disc_nodes)) {
979 spin_lock_irq(shost->host_lock);
980 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
981 spin_unlock_irq(shost->host_lock);
982 /* Check if there are more PLOGIs to be sent */
983 lpfc_more_plogi(vport);
984 if (vport->num_disc_nodes == 0) {
985 spin_lock_irq(shost->host_lock);
986 vport->fc_flag &= ~FC_NDISC_ACTIVE;
987 spin_unlock_irq(shost->host_lock);
988 lpfc_can_disctmo(vport);
989 lpfc_end_rscn(vport);
992 } /* If our portname was less */
994 return ndlp->nlp_state;
998 lpfc_rcv_prli_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
999 void *arg, uint32_t evt)
1001 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1004 memset(&stat, 0, sizeof (struct ls_rjt));
1005 stat.un.b.lsRjtRsnCode = LSRJT_LOGICAL_BSY;
1006 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
1007 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
1008 return ndlp->nlp_state;
1012 lpfc_rcv_logo_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1013 void *arg, uint32_t evt)
1015 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1017 /* software abort outstanding PLOGI */
1018 lpfc_els_abort(vport->phba, ndlp);
1020 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
1021 return ndlp->nlp_state;
1025 lpfc_rcv_els_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1026 void *arg, uint32_t evt)
1028 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1029 struct lpfc_hba *phba = vport->phba;
1030 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1032 /* software abort outstanding PLOGI */
1033 lpfc_els_abort(phba, ndlp);
1035 if (evt == NLP_EVT_RCV_LOGO) {
1036 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
1038 lpfc_issue_els_logo(vport, ndlp, 0);
1041 /* Put ndlp in npr state set plogi timer for 1 sec */
1042 mod_timer(&ndlp->nlp_delayfunc, jiffies + msecs_to_jiffies(1000 * 1));
1043 spin_lock_irq(shost->host_lock);
1044 ndlp->nlp_flag |= NLP_DELAY_TMO;
1045 spin_unlock_irq(shost->host_lock);
1046 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
1047 ndlp->nlp_prev_state = NLP_STE_PLOGI_ISSUE;
1048 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1050 return ndlp->nlp_state;
1054 lpfc_cmpl_plogi_plogi_issue(struct lpfc_vport *vport,
1055 struct lpfc_nodelist *ndlp,
1059 struct lpfc_hba *phba = vport->phba;
1060 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1061 struct lpfc_iocbq *cmdiocb, *rspiocb;
1062 struct lpfc_dmabuf *pcmd, *prsp, *mp;
1066 struct serv_parm *sp;
1071 cmdiocb = (struct lpfc_iocbq *) arg;
1072 rspiocb = cmdiocb->context_un.rsp_iocb;
1074 if (ndlp->nlp_flag & NLP_ACC_REGLOGIN) {
1075 /* Recovery from PLOGI collision logic */
1076 return ndlp->nlp_state;
1079 irsp = &rspiocb->iocb;
1081 if (irsp->ulpStatus)
1084 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
1086 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
1090 lp = (uint32_t *) prsp->virt;
1091 sp = (struct serv_parm *) ((uint8_t *) lp + sizeof (uint32_t));
1093 /* Some switches have FDMI servers returning 0 for WWN */
1094 if ((ndlp->nlp_DID != FDMI_DID) &&
1095 (wwn_to_u64(sp->portName.u.wwn) == 0 ||
1096 wwn_to_u64(sp->nodeName.u.wwn) == 0)) {
1097 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1098 "0142 PLOGI RSP: Invalid WWN.\n");
1101 if (!lpfc_check_sparm(vport, ndlp, sp, CLASS3, 0))
1103 /* PLOGI chkparm OK */
1104 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1105 "0121 PLOGI chkparm OK Data: x%x x%x x%x x%x\n",
1106 ndlp->nlp_DID, ndlp->nlp_state,
1107 ndlp->nlp_flag, ndlp->nlp_rpi);
1108 if (vport->cfg_fcp_class == 2 && (sp->cls2.classValid))
1109 ndlp->nlp_fcp_info |= CLASS2;
1111 ndlp->nlp_fcp_info |= CLASS3;
1113 ndlp->nlp_class_sup = 0;
1114 if (sp->cls1.classValid)
1115 ndlp->nlp_class_sup |= FC_COS_CLASS1;
1116 if (sp->cls2.classValid)
1117 ndlp->nlp_class_sup |= FC_COS_CLASS2;
1118 if (sp->cls3.classValid)
1119 ndlp->nlp_class_sup |= FC_COS_CLASS3;
1120 if (sp->cls4.classValid)
1121 ndlp->nlp_class_sup |= FC_COS_CLASS4;
1122 ndlp->nlp_maxframe =
1123 ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) | sp->cmn.bbRcvSizeLsb;
1125 if ((vport->fc_flag & FC_PT2PT) &&
1126 (vport->fc_flag & FC_PT2PT_PLOGI)) {
1127 ed_tov = be32_to_cpu(sp->cmn.e_d_tov);
1128 if (sp->cmn.edtovResolution) {
1129 /* E_D_TOV ticks are in nanoseconds */
1130 ed_tov = (phba->fc_edtov + 999999) / 1000000;
1133 ndlp->nlp_flag &= ~NLP_SUPPRESS_RSP;
1134 if ((phba->sli.sli_flag & LPFC_SLI_SUPPRESS_RSP) &&
1135 sp->cmn.valid_vendor_ver_level) {
1136 vid = be32_to_cpu(sp->un.vv.vid);
1137 flag = be32_to_cpu(sp->un.vv.flags);
1138 if ((vid == LPFC_VV_EMLX_ID) &&
1139 (flag & LPFC_VV_SUPPRESS_RSP))
1140 ndlp->nlp_flag |= NLP_SUPPRESS_RSP;
1144 * Use the larger EDTOV
1145 * RATOV = 2 * EDTOV for pt-to-pt
1147 if (ed_tov > phba->fc_edtov)
1148 phba->fc_edtov = ed_tov;
1149 phba->fc_ratov = (2 * phba->fc_edtov) / 1000;
1151 memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
1153 /* Issue config_link / reg_vfi to account for updated TOV's */
1154 if (phba->sli_rev == LPFC_SLI_REV4) {
1155 lpfc_issue_reg_vfi(vport);
1157 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1159 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1160 "0133 PLOGI: no memory "
1162 "Data: x%x x%x x%x x%x\n",
1163 ndlp->nlp_DID, ndlp->nlp_state,
1164 ndlp->nlp_flag, ndlp->nlp_rpi);
1168 lpfc_config_link(phba, mbox);
1170 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1171 mbox->vport = vport;
1172 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
1173 if (rc == MBX_NOT_FINISHED) {
1174 mempool_free(mbox, phba->mbox_mem_pool);
1180 lpfc_unreg_rpi(vport, ndlp);
1182 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1184 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1185 "0018 PLOGI: no memory for reg_login "
1186 "Data: x%x x%x x%x x%x\n",
1187 ndlp->nlp_DID, ndlp->nlp_state,
1188 ndlp->nlp_flag, ndlp->nlp_rpi);
1192 if (lpfc_reg_rpi(phba, vport->vpi, irsp->un.elsreq64.remoteID,
1193 (uint8_t *) sp, mbox, ndlp->nlp_rpi) == 0) {
1194 switch (ndlp->nlp_DID) {
1195 case NameServer_DID:
1196 mbox->mbox_cmpl = lpfc_mbx_cmpl_ns_reg_login;
1199 mbox->mbox_cmpl = lpfc_mbx_cmpl_fdmi_reg_login;
1202 ndlp->nlp_flag |= NLP_REG_LOGIN_SEND;
1203 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
1205 mbox->context2 = lpfc_nlp_get(ndlp);
1206 mbox->vport = vport;
1207 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
1208 != MBX_NOT_FINISHED) {
1209 lpfc_nlp_set_state(vport, ndlp,
1210 NLP_STE_REG_LOGIN_ISSUE);
1211 return ndlp->nlp_state;
1213 if (ndlp->nlp_flag & NLP_REG_LOGIN_SEND)
1214 ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND;
1215 /* decrement node reference count to the failed mbox
1219 mp = (struct lpfc_dmabuf *) mbox->context1;
1220 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1222 mempool_free(mbox, phba->mbox_mem_pool);
1224 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1225 "0134 PLOGI: cannot issue reg_login "
1226 "Data: x%x x%x x%x x%x\n",
1227 ndlp->nlp_DID, ndlp->nlp_state,
1228 ndlp->nlp_flag, ndlp->nlp_rpi);
1230 mempool_free(mbox, phba->mbox_mem_pool);
1232 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1233 "0135 PLOGI: cannot format reg_login "
1234 "Data: x%x x%x x%x x%x\n",
1235 ndlp->nlp_DID, ndlp->nlp_state,
1236 ndlp->nlp_flag, ndlp->nlp_rpi);
1241 if (ndlp->nlp_DID == NameServer_DID) {
1242 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
1243 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1244 "0261 Cannot Register NameServer login\n");
1248 ** In case the node reference counter does not go to zero, ensure that
1249 ** the stale state for the node is not processed.
1252 ndlp->nlp_prev_state = ndlp->nlp_state;
1253 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1254 spin_lock_irq(shost->host_lock);
1255 ndlp->nlp_flag |= NLP_DEFER_RM;
1256 spin_unlock_irq(shost->host_lock);
1257 return NLP_STE_FREED_NODE;
1261 lpfc_cmpl_logo_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1262 void *arg, uint32_t evt)
1264 return ndlp->nlp_state;
1268 lpfc_cmpl_reglogin_plogi_issue(struct lpfc_vport *vport,
1269 struct lpfc_nodelist *ndlp, void *arg, uint32_t evt)
1271 struct lpfc_hba *phba;
1272 LPFC_MBOXQ_t *pmb = (LPFC_MBOXQ_t *) arg;
1273 MAILBOX_t *mb = &pmb->u.mb;
1277 /* Release the RPI */
1278 if (!(phba->pport->load_flag & FC_UNLOADING) &&
1280 rpi = pmb->u.mb.un.varWords[0];
1281 lpfc_release_rpi(phba, vport, rpi);
1283 return ndlp->nlp_state;
1287 lpfc_device_rm_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1288 void *arg, uint32_t evt)
1290 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1292 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1293 spin_lock_irq(shost->host_lock);
1294 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
1295 spin_unlock_irq(shost->host_lock);
1296 return ndlp->nlp_state;
1298 /* software abort outstanding PLOGI */
1299 lpfc_els_abort(vport->phba, ndlp);
1301 lpfc_drop_node(vport, ndlp);
1302 return NLP_STE_FREED_NODE;
1307 lpfc_device_recov_plogi_issue(struct lpfc_vport *vport,
1308 struct lpfc_nodelist *ndlp,
1312 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1313 struct lpfc_hba *phba = vport->phba;
1315 /* Don't do anything that will mess up processing of the
1318 if (vport->fc_flag & FC_RSCN_DEFERRED)
1319 return ndlp->nlp_state;
1321 /* software abort outstanding PLOGI */
1322 lpfc_els_abort(phba, ndlp);
1324 ndlp->nlp_prev_state = NLP_STE_PLOGI_ISSUE;
1325 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1326 spin_lock_irq(shost->host_lock);
1327 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
1328 spin_unlock_irq(shost->host_lock);
1330 return ndlp->nlp_state;
1334 lpfc_rcv_plogi_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1335 void *arg, uint32_t evt)
1337 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1338 struct lpfc_hba *phba = vport->phba;
1339 struct lpfc_iocbq *cmdiocb;
1341 /* software abort outstanding ADISC */
1342 lpfc_els_abort(phba, ndlp);
1344 cmdiocb = (struct lpfc_iocbq *) arg;
1346 if (lpfc_rcv_plogi(vport, ndlp, cmdiocb)) {
1347 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1348 spin_lock_irq(shost->host_lock);
1349 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
1350 spin_unlock_irq(shost->host_lock);
1351 if (vport->num_disc_nodes)
1352 lpfc_more_adisc(vport);
1354 return ndlp->nlp_state;
1356 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
1357 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
1358 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
1360 return ndlp->nlp_state;
1364 lpfc_rcv_prli_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1365 void *arg, uint32_t evt)
1367 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1369 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
1370 return ndlp->nlp_state;
1374 lpfc_rcv_logo_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1375 void *arg, uint32_t evt)
1377 struct lpfc_hba *phba = vport->phba;
1378 struct lpfc_iocbq *cmdiocb;
1380 cmdiocb = (struct lpfc_iocbq *) arg;
1382 /* software abort outstanding ADISC */
1383 lpfc_els_abort(phba, ndlp);
1385 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
1386 return ndlp->nlp_state;
1390 lpfc_rcv_padisc_adisc_issue(struct lpfc_vport *vport,
1391 struct lpfc_nodelist *ndlp,
1392 void *arg, uint32_t evt)
1394 struct lpfc_iocbq *cmdiocb;
1396 cmdiocb = (struct lpfc_iocbq *) arg;
1398 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
1399 return ndlp->nlp_state;
1403 lpfc_rcv_prlo_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1404 void *arg, uint32_t evt)
1406 struct lpfc_iocbq *cmdiocb;
1408 cmdiocb = (struct lpfc_iocbq *) arg;
1410 /* Treat like rcv logo */
1411 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_PRLO);
1412 return ndlp->nlp_state;
1416 lpfc_cmpl_adisc_adisc_issue(struct lpfc_vport *vport,
1417 struct lpfc_nodelist *ndlp,
1418 void *arg, uint32_t evt)
1420 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1421 struct lpfc_hba *phba = vport->phba;
1422 struct lpfc_iocbq *cmdiocb, *rspiocb;
1427 cmdiocb = (struct lpfc_iocbq *) arg;
1428 rspiocb = cmdiocb->context_un.rsp_iocb;
1430 ap = (ADISC *)lpfc_check_elscmpl_iocb(phba, cmdiocb, rspiocb);
1431 irsp = &rspiocb->iocb;
1433 if ((irsp->ulpStatus) ||
1434 (!lpfc_check_adisc(vport, ndlp, &ap->nodeName, &ap->portName))) {
1436 mod_timer(&ndlp->nlp_delayfunc,
1437 jiffies + msecs_to_jiffies(1000));
1438 spin_lock_irq(shost->host_lock);
1439 ndlp->nlp_flag |= NLP_DELAY_TMO;
1440 spin_unlock_irq(shost->host_lock);
1441 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
1443 memset(&ndlp->nlp_nodename, 0, sizeof(struct lpfc_name));
1444 memset(&ndlp->nlp_portname, 0, sizeof(struct lpfc_name));
1446 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
1447 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1448 lpfc_unreg_rpi(vport, ndlp);
1449 return ndlp->nlp_state;
1452 if (phba->sli_rev == LPFC_SLI_REV4) {
1453 rc = lpfc_sli4_resume_rpi(ndlp, NULL, NULL);
1455 /* Stay in state and retry. */
1456 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
1457 return ndlp->nlp_state;
1461 if (ndlp->nlp_type & NLP_FCP_TARGET) {
1462 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
1463 lpfc_nlp_set_state(vport, ndlp, NLP_STE_MAPPED_NODE);
1465 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
1466 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
1469 return ndlp->nlp_state;
1473 lpfc_device_rm_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1474 void *arg, uint32_t evt)
1476 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1478 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1479 spin_lock_irq(shost->host_lock);
1480 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
1481 spin_unlock_irq(shost->host_lock);
1482 return ndlp->nlp_state;
1484 /* software abort outstanding ADISC */
1485 lpfc_els_abort(vport->phba, ndlp);
1487 lpfc_drop_node(vport, ndlp);
1488 return NLP_STE_FREED_NODE;
1493 lpfc_device_recov_adisc_issue(struct lpfc_vport *vport,
1494 struct lpfc_nodelist *ndlp,
1498 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1499 struct lpfc_hba *phba = vport->phba;
1501 /* Don't do anything that will mess up processing of the
1504 if (vport->fc_flag & FC_RSCN_DEFERRED)
1505 return ndlp->nlp_state;
1507 /* software abort outstanding ADISC */
1508 lpfc_els_abort(phba, ndlp);
1510 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
1511 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1512 spin_lock_irq(shost->host_lock);
1513 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
1514 spin_unlock_irq(shost->host_lock);
1515 lpfc_disc_set_adisc(vport, ndlp);
1516 return ndlp->nlp_state;
1520 lpfc_rcv_plogi_reglogin_issue(struct lpfc_vport *vport,
1521 struct lpfc_nodelist *ndlp,
1525 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1527 lpfc_rcv_plogi(vport, ndlp, cmdiocb);
1528 return ndlp->nlp_state;
1532 lpfc_rcv_prli_reglogin_issue(struct lpfc_vport *vport,
1533 struct lpfc_nodelist *ndlp,
1537 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1540 if (vport->phba->nvmet_support) {
1541 /* NVME Target mode. Handle and respond to the PRLI and
1542 * transition to UNMAPPED provided the RPI has completed
1545 if (ndlp->nlp_flag & NLP_RPI_REGISTERED) {
1546 lpfc_rcv_prli(vport, ndlp, cmdiocb);
1547 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
1548 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
1550 /* RPI registration has not completed. Reject the PRLI
1551 * to prevent an illegal state transition when the
1552 * rpi registration does complete.
1554 lpfc_printf_vlog(vport, KERN_WARNING, LOG_NVME_DISC,
1555 "6115 NVMET ndlp rpi %d state "
1556 "unknown, state x%x flags x%08x\n",
1557 ndlp->nlp_rpi, ndlp->nlp_state,
1559 memset(&stat, 0, sizeof(struct ls_rjt));
1560 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
1561 stat.un.b.lsRjtRsnCodeExp = LSEXP_CMD_IN_PROGRESS;
1562 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb,
1566 /* Initiator mode. */
1567 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
1570 return ndlp->nlp_state;
1574 lpfc_rcv_logo_reglogin_issue(struct lpfc_vport *vport,
1575 struct lpfc_nodelist *ndlp,
1579 struct lpfc_hba *phba = vport->phba;
1580 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1582 LPFC_MBOXQ_t *nextmb;
1583 struct lpfc_dmabuf *mp;
1585 cmdiocb = (struct lpfc_iocbq *) arg;
1587 /* cleanup any ndlp on mbox q waiting for reglogin cmpl */
1588 if ((mb = phba->sli.mbox_active)) {
1589 if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) &&
1590 (ndlp == (struct lpfc_nodelist *) mb->context2)) {
1591 ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND;
1593 mb->context2 = NULL;
1594 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1598 spin_lock_irq(&phba->hbalock);
1599 list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) {
1600 if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) &&
1601 (ndlp == (struct lpfc_nodelist *) mb->context2)) {
1602 mp = (struct lpfc_dmabuf *) (mb->context1);
1604 __lpfc_mbuf_free(phba, mp->virt, mp->phys);
1607 ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND;
1609 list_del(&mb->list);
1610 phba->sli.mboxq_cnt--;
1611 mempool_free(mb, phba->mbox_mem_pool);
1614 spin_unlock_irq(&phba->hbalock);
1616 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
1617 return ndlp->nlp_state;
1621 lpfc_rcv_padisc_reglogin_issue(struct lpfc_vport *vport,
1622 struct lpfc_nodelist *ndlp,
1626 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1628 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
1629 return ndlp->nlp_state;
1633 lpfc_rcv_prlo_reglogin_issue(struct lpfc_vport *vport,
1634 struct lpfc_nodelist *ndlp,
1638 struct lpfc_iocbq *cmdiocb;
1640 cmdiocb = (struct lpfc_iocbq *) arg;
1641 lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL);
1642 return ndlp->nlp_state;
1646 lpfc_cmpl_reglogin_reglogin_issue(struct lpfc_vport *vport,
1647 struct lpfc_nodelist *ndlp,
1651 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1652 struct lpfc_hba *phba = vport->phba;
1653 LPFC_MBOXQ_t *pmb = (LPFC_MBOXQ_t *) arg;
1654 MAILBOX_t *mb = &pmb->u.mb;
1655 uint32_t did = mb->un.varWords[1];
1658 if (mb->mbxStatus) {
1659 /* RegLogin failed */
1660 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
1661 "0246 RegLogin failed Data: x%x x%x x%x x%x "
1663 did, mb->mbxStatus, vport->port_state,
1664 mb->un.varRegLogin.vpi,
1665 mb->un.varRegLogin.rpi);
1667 * If RegLogin failed due to lack of HBA resources do not
1670 if (mb->mbxStatus == MBXERR_RPI_FULL) {
1671 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
1672 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1673 return ndlp->nlp_state;
1676 /* Put ndlp in npr state set plogi timer for 1 sec */
1677 mod_timer(&ndlp->nlp_delayfunc,
1678 jiffies + msecs_to_jiffies(1000 * 1));
1679 spin_lock_irq(shost->host_lock);
1680 ndlp->nlp_flag |= NLP_DELAY_TMO;
1681 spin_unlock_irq(shost->host_lock);
1682 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
1684 lpfc_issue_els_logo(vport, ndlp, 0);
1685 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
1686 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1687 return ndlp->nlp_state;
1690 /* SLI4 ports have preallocated logical rpis. */
1691 if (phba->sli_rev < LPFC_SLI_REV4)
1692 ndlp->nlp_rpi = mb->un.varWords[0];
1694 ndlp->nlp_flag |= NLP_RPI_REGISTERED;
1696 /* Only if we are not a fabric nport do we issue PRLI */
1697 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1698 "3066 RegLogin Complete on x%x x%x x%x\n",
1699 did, ndlp->nlp_type, ndlp->nlp_fc4_type);
1700 if (!(ndlp->nlp_type & NLP_FABRIC) &&
1701 (phba->nvmet_support == 0)) {
1702 /* The driver supports FCP and NVME concurrently. If the
1703 * ndlp's nlp_fc4_type is still zero, the driver doesn't
1704 * know what PRLI to send yet. Figure that out now and
1705 * call PRLI depending on the outcome.
1707 if (vport->fc_flag & FC_PT2PT) {
1708 /* If we are pt2pt, there is no Fabric to determine
1709 * the FC4 type of the remote nport. So if NVME
1710 * is configured try it.
1712 ndlp->nlp_fc4_type |= NLP_FC4_FCP;
1713 if ((phba->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
1714 (phba->cfg_enable_fc4_type == LPFC_ENABLE_NVME)) {
1715 ndlp->nlp_fc4_type |= NLP_FC4_NVME;
1716 /* We need to update the localport also */
1717 lpfc_nvme_update_localport(vport);
1720 } else if (ndlp->nlp_fc4_type == 0) {
1721 rc = lpfc_ns_cmd(vport, SLI_CTNS_GFT_ID,
1723 return ndlp->nlp_state;
1726 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
1727 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
1728 lpfc_issue_els_prli(vport, ndlp, 0);
1730 if ((vport->fc_flag & FC_PT2PT) && phba->nvmet_support)
1731 phba->targetport->port_id = vport->fc_myDID;
1733 /* Only Fabric ports should transition. NVME target
1734 * must complete PRLI.
1736 if (ndlp->nlp_type & NLP_FABRIC) {
1737 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
1738 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
1741 return ndlp->nlp_state;
1745 lpfc_device_rm_reglogin_issue(struct lpfc_vport *vport,
1746 struct lpfc_nodelist *ndlp,
1750 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1752 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1753 spin_lock_irq(shost->host_lock);
1754 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
1755 spin_unlock_irq(shost->host_lock);
1756 return ndlp->nlp_state;
1758 lpfc_drop_node(vport, ndlp);
1759 return NLP_STE_FREED_NODE;
1764 lpfc_device_recov_reglogin_issue(struct lpfc_vport *vport,
1765 struct lpfc_nodelist *ndlp,
1769 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1771 /* Don't do anything that will mess up processing of the
1774 if (vport->fc_flag & FC_RSCN_DEFERRED)
1775 return ndlp->nlp_state;
1777 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
1778 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1779 spin_lock_irq(shost->host_lock);
1781 /* If we are a target we won't immediately transition into PRLI,
1782 * so if REG_LOGIN already completed we don't need to ignore it.
1784 if (!(ndlp->nlp_flag & NLP_RPI_REGISTERED) ||
1785 !vport->phba->nvmet_support)
1786 ndlp->nlp_flag |= NLP_IGNR_REG_CMPL;
1788 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
1789 spin_unlock_irq(shost->host_lock);
1790 lpfc_disc_set_adisc(vport, ndlp);
1791 return ndlp->nlp_state;
1795 lpfc_rcv_plogi_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1796 void *arg, uint32_t evt)
1798 struct lpfc_iocbq *cmdiocb;
1800 cmdiocb = (struct lpfc_iocbq *) arg;
1802 lpfc_rcv_plogi(vport, ndlp, cmdiocb);
1803 return ndlp->nlp_state;
1807 lpfc_rcv_prli_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1808 void *arg, uint32_t evt)
1810 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1812 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
1813 return ndlp->nlp_state;
1817 lpfc_rcv_logo_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1818 void *arg, uint32_t evt)
1820 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1822 /* Software abort outstanding PRLI before sending acc */
1823 lpfc_els_abort(vport->phba, ndlp);
1825 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
1826 return ndlp->nlp_state;
1830 lpfc_rcv_padisc_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1831 void *arg, uint32_t evt)
1833 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1835 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
1836 return ndlp->nlp_state;
1839 /* This routine is envoked when we rcv a PRLO request from a nport
1840 * we are logged into. We should send back a PRLO rsp setting the
1842 * NEXT STATE = PRLI_ISSUE
1845 lpfc_rcv_prlo_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1846 void *arg, uint32_t evt)
1848 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1850 lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL);
1851 return ndlp->nlp_state;
1855 lpfc_cmpl_prli_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1856 void *arg, uint32_t evt)
1858 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1859 struct lpfc_iocbq *cmdiocb, *rspiocb;
1860 struct lpfc_hba *phba = vport->phba;
1863 struct lpfc_nvme_prli *nvpr;
1866 cmdiocb = (struct lpfc_iocbq *) arg;
1867 rspiocb = cmdiocb->context_un.rsp_iocb;
1869 /* A solicited PRLI is either FCP or NVME. The PRLI cmd/rsp
1870 * format is different so NULL the two PRLI types so that the
1871 * driver correctly gets the correct context.
1875 temp_ptr = lpfc_check_elscmpl_iocb(phba, cmdiocb, rspiocb);
1876 if (cmdiocb->iocb_flag & LPFC_PRLI_FCP_REQ)
1877 npr = (PRLI *) temp_ptr;
1878 else if (cmdiocb->iocb_flag & LPFC_PRLI_NVME_REQ)
1879 nvpr = (struct lpfc_nvme_prli *) temp_ptr;
1881 irsp = &rspiocb->iocb;
1882 if (irsp->ulpStatus) {
1883 if ((vport->port_type == LPFC_NPIV_PORT) &&
1884 vport->cfg_restrict_login) {
1888 /* The LS Req had some error. Don't let this be a
1891 if ((ndlp->fc4_prli_sent == 1) &&
1892 (ndlp->nlp_state == NLP_STE_PRLI_ISSUE) &&
1893 (ndlp->nlp_type & (NLP_FCP_TARGET | NLP_FCP_INITIATOR)))
1894 /* The FCP PRLI completed successfully but
1895 * the NVME PRLI failed. Since they are sent in
1896 * succession, allow the FCP to complete.
1900 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
1901 ndlp->nlp_type |= NLP_FCP_INITIATOR;
1902 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
1903 return ndlp->nlp_state;
1906 /* Check out PRLI rsp */
1907 ndlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR);
1908 ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
1910 /* NVME or FCP first burst must be negotiated for each PRLI. */
1911 ndlp->nlp_flag &= ~NLP_FIRSTBURST;
1912 ndlp->nvme_fb_size = 0;
1913 if (npr && (npr->acceptRspCode == PRLI_REQ_EXECUTED) &&
1914 (npr->prliType == PRLI_FCP_TYPE)) {
1915 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_DISC,
1916 "6028 FCP NPR PRLI Cmpl Init %d Target %d\n",
1919 if (npr->initiatorFunc)
1920 ndlp->nlp_type |= NLP_FCP_INITIATOR;
1921 if (npr->targetFunc) {
1922 ndlp->nlp_type |= NLP_FCP_TARGET;
1923 if (npr->writeXferRdyDis)
1924 ndlp->nlp_flag |= NLP_FIRSTBURST;
1927 ndlp->nlp_fcp_info |= NLP_FCP_2_DEVICE;
1929 /* PRLI completed. Decrement count. */
1930 ndlp->fc4_prli_sent--;
1932 (bf_get_be32(prli_acc_rsp_code, nvpr) ==
1933 PRLI_REQ_EXECUTED) &&
1934 (bf_get_be32(prli_type_code, nvpr) ==
1937 /* Complete setting up the remote ndlp personality. */
1938 if (bf_get_be32(prli_init, nvpr))
1939 ndlp->nlp_type |= NLP_NVME_INITIATOR;
1941 /* Target driver cannot solicit NVME FB. */
1942 if (bf_get_be32(prli_tgt, nvpr)) {
1943 ndlp->nlp_type |= NLP_NVME_TARGET;
1944 if ((bf_get_be32(prli_fba, nvpr) == 1) &&
1945 (bf_get_be32(prli_fb_sz, nvpr) > 0) &&
1946 (phba->cfg_nvme_enable_fb) &&
1947 (!phba->nvmet_support)) {
1948 /* Both sides support FB. The target's first
1949 * burst size is a 512 byte encoded value.
1951 ndlp->nlp_flag |= NLP_FIRSTBURST;
1952 ndlp->nvme_fb_size = bf_get_be32(prli_fb_sz,
1957 if (bf_get_be32(prli_recov, nvpr))
1958 ndlp->nlp_fcp_info |= NLP_FCP_2_DEVICE;
1960 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_DISC,
1961 "6029 NVME PRLI Cmpl w1 x%08x "
1962 "w4 x%08x w5 x%08x flag x%x, "
1963 "fcp_info x%x nlp_type x%x\n",
1964 be32_to_cpu(nvpr->word1),
1965 be32_to_cpu(nvpr->word4),
1966 be32_to_cpu(nvpr->word5),
1967 ndlp->nlp_flag, ndlp->nlp_fcp_info,
1969 /* PRLI completed. Decrement count. */
1970 ndlp->fc4_prli_sent--;
1972 if (!(ndlp->nlp_type & NLP_FCP_TARGET) &&
1973 (vport->port_type == LPFC_NPIV_PORT) &&
1974 vport->cfg_restrict_login) {
1976 spin_lock_irq(shost->host_lock);
1977 ndlp->nlp_flag |= NLP_TARGET_REMOVE;
1978 spin_unlock_irq(shost->host_lock);
1979 lpfc_issue_els_logo(vport, ndlp, 0);
1981 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
1982 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1983 return ndlp->nlp_state;
1987 /* The ndlp state cannot move to MAPPED or UNMAPPED before all PRLIs
1990 if (ndlp->fc4_prli_sent == 0) {
1991 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
1992 if (ndlp->nlp_type & (NLP_FCP_TARGET | NLP_NVME_TARGET))
1993 lpfc_nlp_set_state(vport, ndlp, NLP_STE_MAPPED_NODE);
1995 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
1997 lpfc_printf_vlog(vport,
1999 "3067 PRLI's still outstanding "
2000 "on x%06x - count %d, Pend Node Mode "
2002 ndlp->nlp_DID, ndlp->fc4_prli_sent);
2004 return ndlp->nlp_state;
2007 /*! lpfc_device_rm_prli_issue
2018 * This routine is envoked when we a request to remove a nport we are in the
2019 * process of PRLIing. We should software abort outstanding prli, unreg
2020 * login, send a logout. We will change node state to UNUSED_NODE, put it
2021 * on plogi list so it can be freed when LOGO completes.
2026 lpfc_device_rm_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2027 void *arg, uint32_t evt)
2029 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2031 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
2032 spin_lock_irq(shost->host_lock);
2033 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
2034 spin_unlock_irq(shost->host_lock);
2035 return ndlp->nlp_state;
2037 /* software abort outstanding PLOGI */
2038 lpfc_els_abort(vport->phba, ndlp);
2040 lpfc_drop_node(vport, ndlp);
2041 return NLP_STE_FREED_NODE;
2046 /*! lpfc_device_recov_prli_issue
2057 * The routine is envoked when the state of a device is unknown, like
2058 * during a link down. We should remove the nodelist entry from the
2059 * unmapped list, issue a UNREG_LOGIN, do a software abort of the
2060 * outstanding PRLI command, then free the node entry.
2063 lpfc_device_recov_prli_issue(struct lpfc_vport *vport,
2064 struct lpfc_nodelist *ndlp,
2068 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2069 struct lpfc_hba *phba = vport->phba;
2071 /* Don't do anything that will mess up processing of the
2074 if (vport->fc_flag & FC_RSCN_DEFERRED)
2075 return ndlp->nlp_state;
2077 /* software abort outstanding PRLI */
2078 lpfc_els_abort(phba, ndlp);
2080 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
2081 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
2082 spin_lock_irq(shost->host_lock);
2083 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
2084 spin_unlock_irq(shost->host_lock);
2085 lpfc_disc_set_adisc(vport, ndlp);
2086 return ndlp->nlp_state;
2090 lpfc_rcv_plogi_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2091 void *arg, uint32_t evt)
2093 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *)arg;
2096 memset(&stat, 0, sizeof(struct ls_rjt));
2097 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
2098 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
2099 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
2100 return ndlp->nlp_state;
2104 lpfc_rcv_prli_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2105 void *arg, uint32_t evt)
2107 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *)arg;
2110 memset(&stat, 0, sizeof(struct ls_rjt));
2111 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
2112 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
2113 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
2114 return ndlp->nlp_state;
2118 lpfc_rcv_logo_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2119 void *arg, uint32_t evt)
2121 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2122 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *)arg;
2124 spin_lock_irq(shost->host_lock);
2125 ndlp->nlp_flag |= NLP_LOGO_ACC;
2126 spin_unlock_irq(shost->host_lock);
2127 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
2128 return ndlp->nlp_state;
2132 lpfc_rcv_padisc_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2133 void *arg, uint32_t evt)
2135 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *)arg;
2138 memset(&stat, 0, sizeof(struct ls_rjt));
2139 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
2140 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
2141 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
2142 return ndlp->nlp_state;
2146 lpfc_rcv_prlo_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2147 void *arg, uint32_t evt)
2149 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *)arg;
2152 memset(&stat, 0, sizeof(struct ls_rjt));
2153 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
2154 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
2155 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
2156 return ndlp->nlp_state;
2160 lpfc_cmpl_logo_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2161 void *arg, uint32_t evt)
2163 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2165 ndlp->nlp_prev_state = NLP_STE_LOGO_ISSUE;
2166 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
2167 spin_lock_irq(shost->host_lock);
2168 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
2169 spin_unlock_irq(shost->host_lock);
2170 lpfc_disc_set_adisc(vport, ndlp);
2171 return ndlp->nlp_state;
2175 lpfc_device_rm_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2176 void *arg, uint32_t evt)
2179 * Take no action. If a LOGO is outstanding, then possibly DevLoss has
2180 * timed out and is calling for Device Remove. In this case, the LOGO
2181 * must be allowed to complete in state LOGO_ISSUE so that the rpi
2182 * and other NLP flags are correctly cleaned up.
2184 return ndlp->nlp_state;
2188 lpfc_device_recov_logo_issue(struct lpfc_vport *vport,
2189 struct lpfc_nodelist *ndlp,
2190 void *arg, uint32_t evt)
2193 * Device Recovery events have no meaning for a node with a LOGO
2194 * outstanding. The LOGO has to complete first and handle the
2195 * node from that point.
2197 return ndlp->nlp_state;
2201 lpfc_rcv_plogi_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2202 void *arg, uint32_t evt)
2204 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2206 lpfc_rcv_plogi(vport, ndlp, cmdiocb);
2207 return ndlp->nlp_state;
2211 lpfc_rcv_prli_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2212 void *arg, uint32_t evt)
2214 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2216 lpfc_rcv_prli(vport, ndlp, cmdiocb);
2217 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
2218 return ndlp->nlp_state;
2222 lpfc_rcv_logo_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2223 void *arg, uint32_t evt)
2225 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2227 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
2228 return ndlp->nlp_state;
2232 lpfc_rcv_padisc_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2233 void *arg, uint32_t evt)
2235 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2237 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
2238 return ndlp->nlp_state;
2242 lpfc_rcv_prlo_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2243 void *arg, uint32_t evt)
2245 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2247 lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL);
2248 return ndlp->nlp_state;
2252 lpfc_device_recov_unmap_node(struct lpfc_vport *vport,
2253 struct lpfc_nodelist *ndlp,
2257 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2259 ndlp->nlp_prev_state = NLP_STE_UNMAPPED_NODE;
2260 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
2261 spin_lock_irq(shost->host_lock);
2262 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
2263 spin_unlock_irq(shost->host_lock);
2264 lpfc_disc_set_adisc(vport, ndlp);
2266 return ndlp->nlp_state;
2270 lpfc_rcv_plogi_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2271 void *arg, uint32_t evt)
2273 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2275 lpfc_rcv_plogi(vport, ndlp, cmdiocb);
2276 return ndlp->nlp_state;
2280 lpfc_rcv_prli_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2281 void *arg, uint32_t evt)
2283 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2285 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
2286 return ndlp->nlp_state;
2290 lpfc_rcv_logo_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2291 void *arg, uint32_t evt)
2293 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2295 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
2296 return ndlp->nlp_state;
2300 lpfc_rcv_padisc_mapped_node(struct lpfc_vport *vport,
2301 struct lpfc_nodelist *ndlp,
2302 void *arg, uint32_t evt)
2304 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2306 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
2307 return ndlp->nlp_state;
2311 lpfc_rcv_prlo_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2312 void *arg, uint32_t evt)
2314 struct lpfc_hba *phba = vport->phba;
2315 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2317 /* flush the target */
2318 lpfc_sli_abort_iocb(vport, &phba->sli.sli3_ring[LPFC_FCP_RING],
2319 ndlp->nlp_sid, 0, LPFC_CTX_TGT);
2321 /* Treat like rcv logo */
2322 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_PRLO);
2323 return ndlp->nlp_state;
2327 lpfc_device_recov_mapped_node(struct lpfc_vport *vport,
2328 struct lpfc_nodelist *ndlp,
2332 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2334 ndlp->nlp_prev_state = NLP_STE_MAPPED_NODE;
2335 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
2336 spin_lock_irq(shost->host_lock);
2337 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
2338 spin_unlock_irq(shost->host_lock);
2339 lpfc_disc_set_adisc(vport, ndlp);
2340 return ndlp->nlp_state;
2344 lpfc_rcv_plogi_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2345 void *arg, uint32_t evt)
2347 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2348 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2350 /* Ignore PLOGI if we have an outstanding LOGO */
2351 if (ndlp->nlp_flag & (NLP_LOGO_SND | NLP_LOGO_ACC))
2352 return ndlp->nlp_state;
2353 if (lpfc_rcv_plogi(vport, ndlp, cmdiocb)) {
2354 lpfc_cancel_retry_delay_tmo(vport, ndlp);
2355 spin_lock_irq(shost->host_lock);
2356 ndlp->nlp_flag &= ~(NLP_NPR_ADISC | NLP_NPR_2B_DISC);
2357 spin_unlock_irq(shost->host_lock);
2358 } else if (!(ndlp->nlp_flag & NLP_NPR_2B_DISC)) {
2359 /* send PLOGI immediately, move to PLOGI issue state */
2360 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
2361 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
2362 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
2363 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
2366 return ndlp->nlp_state;
2370 lpfc_rcv_prli_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2371 void *arg, uint32_t evt)
2373 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2374 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2377 memset(&stat, 0, sizeof (struct ls_rjt));
2378 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
2379 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
2380 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
2382 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
2383 if (ndlp->nlp_flag & NLP_NPR_ADISC) {
2384 spin_lock_irq(shost->host_lock);
2385 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
2386 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
2387 spin_unlock_irq(shost->host_lock);
2388 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
2389 lpfc_issue_els_adisc(vport, ndlp, 0);
2391 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
2392 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
2393 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
2396 return ndlp->nlp_state;
2400 lpfc_rcv_logo_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2401 void *arg, uint32_t evt)
2403 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2405 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
2406 return ndlp->nlp_state;
2410 lpfc_rcv_padisc_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2411 void *arg, uint32_t evt)
2413 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2415 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
2417 * Do not start discovery if discovery is about to start
2418 * or discovery in progress for this node. Starting discovery
2419 * here will affect the counting of discovery threads.
2421 if (!(ndlp->nlp_flag & NLP_DELAY_TMO) &&
2422 !(ndlp->nlp_flag & NLP_NPR_2B_DISC)) {
2423 if (ndlp->nlp_flag & NLP_NPR_ADISC) {
2424 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
2425 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
2426 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
2427 lpfc_issue_els_adisc(vport, ndlp, 0);
2429 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
2430 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
2431 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
2434 return ndlp->nlp_state;
2438 lpfc_rcv_prlo_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2439 void *arg, uint32_t evt)
2441 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2442 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2444 spin_lock_irq(shost->host_lock);
2445 ndlp->nlp_flag |= NLP_LOGO_ACC;
2446 spin_unlock_irq(shost->host_lock);
2448 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
2450 if ((ndlp->nlp_flag & NLP_DELAY_TMO) == 0) {
2451 mod_timer(&ndlp->nlp_delayfunc,
2452 jiffies + msecs_to_jiffies(1000 * 1));
2453 spin_lock_irq(shost->host_lock);
2454 ndlp->nlp_flag |= NLP_DELAY_TMO;
2455 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
2456 spin_unlock_irq(shost->host_lock);
2457 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
2459 spin_lock_irq(shost->host_lock);
2460 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
2461 spin_unlock_irq(shost->host_lock);
2463 return ndlp->nlp_state;
2467 lpfc_cmpl_plogi_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2468 void *arg, uint32_t evt)
2470 struct lpfc_iocbq *cmdiocb, *rspiocb;
2472 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2474 cmdiocb = (struct lpfc_iocbq *) arg;
2475 rspiocb = cmdiocb->context_un.rsp_iocb;
2477 irsp = &rspiocb->iocb;
2478 if (irsp->ulpStatus) {
2479 spin_lock_irq(shost->host_lock);
2480 ndlp->nlp_flag |= NLP_DEFER_RM;
2481 spin_unlock_irq(shost->host_lock);
2482 return NLP_STE_FREED_NODE;
2484 return ndlp->nlp_state;
2488 lpfc_cmpl_prli_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2489 void *arg, uint32_t evt)
2491 struct lpfc_iocbq *cmdiocb, *rspiocb;
2494 cmdiocb = (struct lpfc_iocbq *) arg;
2495 rspiocb = cmdiocb->context_un.rsp_iocb;
2497 irsp = &rspiocb->iocb;
2498 if (irsp->ulpStatus && (ndlp->nlp_flag & NLP_NODEV_REMOVE)) {
2499 lpfc_drop_node(vport, ndlp);
2500 return NLP_STE_FREED_NODE;
2502 return ndlp->nlp_state;
2506 lpfc_cmpl_logo_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2507 void *arg, uint32_t evt)
2509 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2511 /* For the fabric port just clear the fc flags. */
2512 if (ndlp->nlp_DID == Fabric_DID) {
2513 spin_lock_irq(shost->host_lock);
2514 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
2515 spin_unlock_irq(shost->host_lock);
2517 lpfc_unreg_rpi(vport, ndlp);
2518 return ndlp->nlp_state;
2522 lpfc_cmpl_adisc_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2523 void *arg, uint32_t evt)
2525 struct lpfc_iocbq *cmdiocb, *rspiocb;
2528 cmdiocb = (struct lpfc_iocbq *) arg;
2529 rspiocb = cmdiocb->context_un.rsp_iocb;
2531 irsp = &rspiocb->iocb;
2532 if (irsp->ulpStatus && (ndlp->nlp_flag & NLP_NODEV_REMOVE)) {
2533 lpfc_drop_node(vport, ndlp);
2534 return NLP_STE_FREED_NODE;
2536 return ndlp->nlp_state;
2540 lpfc_cmpl_reglogin_npr_node(struct lpfc_vport *vport,
2541 struct lpfc_nodelist *ndlp,
2542 void *arg, uint32_t evt)
2544 LPFC_MBOXQ_t *pmb = (LPFC_MBOXQ_t *) arg;
2545 MAILBOX_t *mb = &pmb->u.mb;
2547 if (!mb->mbxStatus) {
2548 /* SLI4 ports have preallocated logical rpis. */
2549 if (vport->phba->sli_rev < LPFC_SLI_REV4)
2550 ndlp->nlp_rpi = mb->un.varWords[0];
2551 ndlp->nlp_flag |= NLP_RPI_REGISTERED;
2552 if (ndlp->nlp_flag & NLP_LOGO_ACC) {
2553 lpfc_unreg_rpi(vport, ndlp);
2556 if (ndlp->nlp_flag & NLP_NODEV_REMOVE) {
2557 lpfc_drop_node(vport, ndlp);
2558 return NLP_STE_FREED_NODE;
2561 return ndlp->nlp_state;
2565 lpfc_device_rm_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2566 void *arg, uint32_t evt)
2568 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2570 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
2571 spin_lock_irq(shost->host_lock);
2572 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
2573 spin_unlock_irq(shost->host_lock);
2574 return ndlp->nlp_state;
2576 lpfc_drop_node(vport, ndlp);
2577 return NLP_STE_FREED_NODE;
2581 lpfc_device_recov_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2582 void *arg, uint32_t evt)
2584 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2586 /* Don't do anything that will mess up processing of the
2589 if (vport->fc_flag & FC_RSCN_DEFERRED)
2590 return ndlp->nlp_state;
2592 lpfc_cancel_retry_delay_tmo(vport, ndlp);
2593 spin_lock_irq(shost->host_lock);
2594 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
2595 spin_unlock_irq(shost->host_lock);
2596 return ndlp->nlp_state;
2600 /* This next section defines the NPort Discovery State Machine */
2602 /* There are 4 different double linked lists nodelist entries can reside on.
2603 * The plogi list and adisc list are used when Link Up discovery or RSCN
2604 * processing is needed. Each list holds the nodes that we will send PLOGI
2605 * or ADISC on. These lists will keep track of what nodes will be effected
2606 * by an RSCN, or a Link Up (Typically, all nodes are effected on Link Up).
2607 * The unmapped_list will contain all nodes that we have successfully logged
2608 * into at the Fibre Channel level. The mapped_list will contain all nodes
2609 * that are mapped FCP targets.
2612 * The bind list is a list of undiscovered (potentially non-existent) nodes
2613 * that we have saved binding information on. This information is used when
2614 * nodes transition from the unmapped to the mapped list.
2616 /* For UNUSED_NODE state, the node has just been allocated .
2617 * For PLOGI_ISSUE and REG_LOGIN_ISSUE, the node is on
2618 * the PLOGI list. For REG_LOGIN_COMPL, the node is taken off the PLOGI list
2619 * and put on the unmapped list. For ADISC processing, the node is taken off
2620 * the ADISC list and placed on either the mapped or unmapped list (depending
2621 * on its previous state). Once on the unmapped list, a PRLI is issued and the
2622 * state changed to PRLI_ISSUE. When the PRLI completion occurs, the state is
2623 * changed to UNMAPPED_NODE. If the completion indicates a mapped
2624 * node, the node is taken off the unmapped list. The binding list is checked
2625 * for a valid binding, or a binding is automatically assigned. If binding
2626 * assignment is unsuccessful, the node is left on the unmapped list. If
2627 * binding assignment is successful, the associated binding list entry (if
2628 * any) is removed, and the node is placed on the mapped list.
2631 * For a Link Down, all nodes on the ADISC, PLOGI, unmapped or mapped
2632 * lists will receive a DEVICE_RECOVERY event. If the linkdown or devloss timers
2633 * expire, all effected nodes will receive a DEVICE_RM event.
2636 * For a Link Up or RSCN, all nodes will move from the mapped / unmapped lists
2637 * to either the ADISC or PLOGI list. After a Nameserver query or ALPA loopmap
2638 * check, additional nodes may be added or removed (via DEVICE_RM) to / from
2639 * the PLOGI or ADISC lists. Once the PLOGI and ADISC lists are populated,
2640 * we will first process the ADISC list. 32 entries are processed initially and
2641 * ADISC is initited for each one. Completions / Events for each node are
2642 * funnelled thru the state machine. As each node finishes ADISC processing, it
2643 * starts ADISC for any nodes waiting for ADISC processing. If no nodes are
2644 * waiting, and the ADISC list count is identically 0, then we are done. For
2645 * Link Up discovery, since all nodes on the PLOGI list are UNREG_LOGIN'ed, we
2646 * can issue a CLEAR_LA and reenable Link Events. Next we will process the PLOGI
2647 * list. 32 entries are processed initially and PLOGI is initited for each one.
2648 * Completions / Events for each node are funnelled thru the state machine. As
2649 * each node finishes PLOGI processing, it starts PLOGI for any nodes waiting
2650 * for PLOGI processing. If no nodes are waiting, and the PLOGI list count is
2651 * indentically 0, then we are done. We have now completed discovery / RSCN
2652 * handling. Upon completion, ALL nodes should be on either the mapped or
2656 static uint32_t (*lpfc_disc_action[NLP_STE_MAX_STATE * NLP_EVT_MAX_EVENT])
2657 (struct lpfc_vport *, struct lpfc_nodelist *, void *, uint32_t) = {
2658 /* Action routine Event Current State */
2659 lpfc_rcv_plogi_unused_node, /* RCV_PLOGI UNUSED_NODE */
2660 lpfc_rcv_els_unused_node, /* RCV_PRLI */
2661 lpfc_rcv_logo_unused_node, /* RCV_LOGO */
2662 lpfc_rcv_els_unused_node, /* RCV_ADISC */
2663 lpfc_rcv_els_unused_node, /* RCV_PDISC */
2664 lpfc_rcv_els_unused_node, /* RCV_PRLO */
2665 lpfc_disc_illegal, /* CMPL_PLOGI */
2666 lpfc_disc_illegal, /* CMPL_PRLI */
2667 lpfc_cmpl_logo_unused_node, /* CMPL_LOGO */
2668 lpfc_disc_illegal, /* CMPL_ADISC */
2669 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2670 lpfc_device_rm_unused_node, /* DEVICE_RM */
2671 lpfc_device_recov_unused_node, /* DEVICE_RECOVERY */
2673 lpfc_rcv_plogi_plogi_issue, /* RCV_PLOGI PLOGI_ISSUE */
2674 lpfc_rcv_prli_plogi_issue, /* RCV_PRLI */
2675 lpfc_rcv_logo_plogi_issue, /* RCV_LOGO */
2676 lpfc_rcv_els_plogi_issue, /* RCV_ADISC */
2677 lpfc_rcv_els_plogi_issue, /* RCV_PDISC */
2678 lpfc_rcv_els_plogi_issue, /* RCV_PRLO */
2679 lpfc_cmpl_plogi_plogi_issue, /* CMPL_PLOGI */
2680 lpfc_disc_illegal, /* CMPL_PRLI */
2681 lpfc_cmpl_logo_plogi_issue, /* CMPL_LOGO */
2682 lpfc_disc_illegal, /* CMPL_ADISC */
2683 lpfc_cmpl_reglogin_plogi_issue,/* CMPL_REG_LOGIN */
2684 lpfc_device_rm_plogi_issue, /* DEVICE_RM */
2685 lpfc_device_recov_plogi_issue, /* DEVICE_RECOVERY */
2687 lpfc_rcv_plogi_adisc_issue, /* RCV_PLOGI ADISC_ISSUE */
2688 lpfc_rcv_prli_adisc_issue, /* RCV_PRLI */
2689 lpfc_rcv_logo_adisc_issue, /* RCV_LOGO */
2690 lpfc_rcv_padisc_adisc_issue, /* RCV_ADISC */
2691 lpfc_rcv_padisc_adisc_issue, /* RCV_PDISC */
2692 lpfc_rcv_prlo_adisc_issue, /* RCV_PRLO */
2693 lpfc_disc_illegal, /* CMPL_PLOGI */
2694 lpfc_disc_illegal, /* CMPL_PRLI */
2695 lpfc_disc_illegal, /* CMPL_LOGO */
2696 lpfc_cmpl_adisc_adisc_issue, /* CMPL_ADISC */
2697 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2698 lpfc_device_rm_adisc_issue, /* DEVICE_RM */
2699 lpfc_device_recov_adisc_issue, /* DEVICE_RECOVERY */
2701 lpfc_rcv_plogi_reglogin_issue, /* RCV_PLOGI REG_LOGIN_ISSUE */
2702 lpfc_rcv_prli_reglogin_issue, /* RCV_PLOGI */
2703 lpfc_rcv_logo_reglogin_issue, /* RCV_LOGO */
2704 lpfc_rcv_padisc_reglogin_issue, /* RCV_ADISC */
2705 lpfc_rcv_padisc_reglogin_issue, /* RCV_PDISC */
2706 lpfc_rcv_prlo_reglogin_issue, /* RCV_PRLO */
2707 lpfc_cmpl_plogi_illegal, /* CMPL_PLOGI */
2708 lpfc_disc_illegal, /* CMPL_PRLI */
2709 lpfc_disc_illegal, /* CMPL_LOGO */
2710 lpfc_disc_illegal, /* CMPL_ADISC */
2711 lpfc_cmpl_reglogin_reglogin_issue,/* CMPL_REG_LOGIN */
2712 lpfc_device_rm_reglogin_issue, /* DEVICE_RM */
2713 lpfc_device_recov_reglogin_issue,/* DEVICE_RECOVERY */
2715 lpfc_rcv_plogi_prli_issue, /* RCV_PLOGI PRLI_ISSUE */
2716 lpfc_rcv_prli_prli_issue, /* RCV_PRLI */
2717 lpfc_rcv_logo_prli_issue, /* RCV_LOGO */
2718 lpfc_rcv_padisc_prli_issue, /* RCV_ADISC */
2719 lpfc_rcv_padisc_prli_issue, /* RCV_PDISC */
2720 lpfc_rcv_prlo_prli_issue, /* RCV_PRLO */
2721 lpfc_cmpl_plogi_illegal, /* CMPL_PLOGI */
2722 lpfc_cmpl_prli_prli_issue, /* CMPL_PRLI */
2723 lpfc_disc_illegal, /* CMPL_LOGO */
2724 lpfc_disc_illegal, /* CMPL_ADISC */
2725 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2726 lpfc_device_rm_prli_issue, /* DEVICE_RM */
2727 lpfc_device_recov_prli_issue, /* DEVICE_RECOVERY */
2729 lpfc_rcv_plogi_logo_issue, /* RCV_PLOGI LOGO_ISSUE */
2730 lpfc_rcv_prli_logo_issue, /* RCV_PRLI */
2731 lpfc_rcv_logo_logo_issue, /* RCV_LOGO */
2732 lpfc_rcv_padisc_logo_issue, /* RCV_ADISC */
2733 lpfc_rcv_padisc_logo_issue, /* RCV_PDISC */
2734 lpfc_rcv_prlo_logo_issue, /* RCV_PRLO */
2735 lpfc_cmpl_plogi_illegal, /* CMPL_PLOGI */
2736 lpfc_disc_illegal, /* CMPL_PRLI */
2737 lpfc_cmpl_logo_logo_issue, /* CMPL_LOGO */
2738 lpfc_disc_illegal, /* CMPL_ADISC */
2739 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2740 lpfc_device_rm_logo_issue, /* DEVICE_RM */
2741 lpfc_device_recov_logo_issue, /* DEVICE_RECOVERY */
2743 lpfc_rcv_plogi_unmap_node, /* RCV_PLOGI UNMAPPED_NODE */
2744 lpfc_rcv_prli_unmap_node, /* RCV_PRLI */
2745 lpfc_rcv_logo_unmap_node, /* RCV_LOGO */
2746 lpfc_rcv_padisc_unmap_node, /* RCV_ADISC */
2747 lpfc_rcv_padisc_unmap_node, /* RCV_PDISC */
2748 lpfc_rcv_prlo_unmap_node, /* RCV_PRLO */
2749 lpfc_disc_illegal, /* CMPL_PLOGI */
2750 lpfc_disc_illegal, /* CMPL_PRLI */
2751 lpfc_disc_illegal, /* CMPL_LOGO */
2752 lpfc_disc_illegal, /* CMPL_ADISC */
2753 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2754 lpfc_disc_illegal, /* DEVICE_RM */
2755 lpfc_device_recov_unmap_node, /* DEVICE_RECOVERY */
2757 lpfc_rcv_plogi_mapped_node, /* RCV_PLOGI MAPPED_NODE */
2758 lpfc_rcv_prli_mapped_node, /* RCV_PRLI */
2759 lpfc_rcv_logo_mapped_node, /* RCV_LOGO */
2760 lpfc_rcv_padisc_mapped_node, /* RCV_ADISC */
2761 lpfc_rcv_padisc_mapped_node, /* RCV_PDISC */
2762 lpfc_rcv_prlo_mapped_node, /* RCV_PRLO */
2763 lpfc_disc_illegal, /* CMPL_PLOGI */
2764 lpfc_disc_illegal, /* CMPL_PRLI */
2765 lpfc_disc_illegal, /* CMPL_LOGO */
2766 lpfc_disc_illegal, /* CMPL_ADISC */
2767 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2768 lpfc_disc_illegal, /* DEVICE_RM */
2769 lpfc_device_recov_mapped_node, /* DEVICE_RECOVERY */
2771 lpfc_rcv_plogi_npr_node, /* RCV_PLOGI NPR_NODE */
2772 lpfc_rcv_prli_npr_node, /* RCV_PRLI */
2773 lpfc_rcv_logo_npr_node, /* RCV_LOGO */
2774 lpfc_rcv_padisc_npr_node, /* RCV_ADISC */
2775 lpfc_rcv_padisc_npr_node, /* RCV_PDISC */
2776 lpfc_rcv_prlo_npr_node, /* RCV_PRLO */
2777 lpfc_cmpl_plogi_npr_node, /* CMPL_PLOGI */
2778 lpfc_cmpl_prli_npr_node, /* CMPL_PRLI */
2779 lpfc_cmpl_logo_npr_node, /* CMPL_LOGO */
2780 lpfc_cmpl_adisc_npr_node, /* CMPL_ADISC */
2781 lpfc_cmpl_reglogin_npr_node, /* CMPL_REG_LOGIN */
2782 lpfc_device_rm_npr_node, /* DEVICE_RM */
2783 lpfc_device_recov_npr_node, /* DEVICE_RECOVERY */
2787 lpfc_disc_state_machine(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2788 void *arg, uint32_t evt)
2790 uint32_t cur_state, rc;
2791 uint32_t(*func) (struct lpfc_vport *, struct lpfc_nodelist *, void *,
2793 uint32_t got_ndlp = 0;
2795 if (lpfc_nlp_get(ndlp))
2798 cur_state = ndlp->nlp_state;
2800 /* DSM in event <evt> on NPort <nlp_DID> in state <cur_state> */
2801 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2802 "0211 DSM in event x%x on NPort x%x in "
2803 "state %d Data: x%x\n",
2804 evt, ndlp->nlp_DID, cur_state, ndlp->nlp_flag);
2806 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_DSM,
2807 "DSM in: evt:%d ste:%d did:x%x",
2808 evt, cur_state, ndlp->nlp_DID);
2810 func = lpfc_disc_action[(cur_state * NLP_EVT_MAX_EVENT) + evt];
2811 rc = (func) (vport, ndlp, arg, evt);
2813 /* DSM out state <rc> on NPort <nlp_DID> */
2815 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2816 "0212 DSM out state %d on NPort x%x Data: x%x\n",
2817 rc, ndlp->nlp_DID, ndlp->nlp_flag);
2819 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_DSM,
2820 "DSM out: ste:%d did:x%x flg:x%x",
2821 rc, ndlp->nlp_DID, ndlp->nlp_flag);
2822 /* Decrement the ndlp reference count held for this function */
2825 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2826 "0213 DSM out state %d on NPort free\n", rc);
2828 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_DSM,
2829 "DSM out: ste:%d did:x%x flg:x%x",