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 /* In case of error recovery path, we might have a NULL pring here */
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))
363 case NLP_STE_REG_LOGIN_ISSUE:
364 case NLP_STE_PRLI_ISSUE:
365 case NLP_STE_UNMAPPED_NODE:
366 case NLP_STE_MAPPED_NODE:
367 /* For initiators, lpfc_plogi_confirm_nport skips fabric did.
368 * For target mode, execute implicit logo.
369 * Fabric nodes go into NPR.
371 if (!(ndlp->nlp_type & NLP_FABRIC) &&
372 !(phba->nvmet_support)) {
373 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb,
377 if (nlp_portwwn != 0 &&
378 nlp_portwwn != wwn_to_u64(sp->portName.u.wwn))
379 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
380 "0143 PLOGI recv'd from DID: x%x "
381 "WWPN changed: old %llx new %llx\n",
383 (unsigned long long)nlp_portwwn,
385 wwn_to_u64(sp->portName.u.wwn));
387 ndlp->nlp_prev_state = ndlp->nlp_state;
388 /* rport needs to be unregistered first */
389 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
393 /* Check for Nport to NPort pt2pt protocol */
394 if ((vport->fc_flag & FC_PT2PT) &&
395 !(vport->fc_flag & FC_PT2PT_PLOGI)) {
396 /* rcv'ed PLOGI decides what our NPortId will be */
397 vport->fc_myDID = icmd->un.rcvels.parmRo;
399 ed_tov = be32_to_cpu(sp->cmn.e_d_tov);
400 if (sp->cmn.edtovResolution) {
401 /* E_D_TOV ticks are in nanoseconds */
402 ed_tov = (phba->fc_edtov + 999999) / 1000000;
406 * For pt-to-pt, use the larger EDTOV
409 if (ed_tov > phba->fc_edtov)
410 phba->fc_edtov = ed_tov;
411 phba->fc_ratov = (2 * phba->fc_edtov) / 1000;
413 memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
415 /* Issue config_link / reg_vfi to account for updated TOV's */
417 if (phba->sli_rev == LPFC_SLI_REV4)
418 lpfc_issue_reg_vfi(vport);
420 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
423 lpfc_config_link(phba, mbox);
424 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
426 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
427 if (rc == MBX_NOT_FINISHED) {
428 mempool_free(mbox, phba->mbox_mem_pool);
433 lpfc_can_disctmo(vport);
436 ndlp->nlp_flag &= ~NLP_SUPPRESS_RSP;
437 if ((phba->sli.sli_flag & LPFC_SLI_SUPPRESS_RSP) &&
438 sp->cmn.valid_vendor_ver_level) {
439 vid = be32_to_cpu(sp->un.vv.vid);
440 flag = be32_to_cpu(sp->un.vv.flags);
441 if ((vid == LPFC_VV_EMLX_ID) && (flag & LPFC_VV_SUPPRESS_RSP))
442 ndlp->nlp_flag |= NLP_SUPPRESS_RSP;
445 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
449 /* Registering an existing RPI behaves differently for SLI3 vs SLI4 */
450 if (phba->sli_rev == LPFC_SLI_REV4)
451 lpfc_unreg_rpi(vport, ndlp);
453 rc = lpfc_reg_rpi(phba, vport->vpi, icmd->un.rcvels.remoteID,
454 (uint8_t *) sp, mbox, ndlp->nlp_rpi);
456 mempool_free(mbox, phba->mbox_mem_pool);
460 /* ACC PLOGI rsp command needs to execute first,
461 * queue this mbox command to be processed later.
463 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
465 * mbox->context2 = lpfc_nlp_get(ndlp) deferred until mailbox
466 * command issued in lpfc_cmpl_els_acc().
469 spin_lock_irq(shost->host_lock);
470 ndlp->nlp_flag |= (NLP_ACC_REGLOGIN | NLP_RCV_PLOGI);
471 spin_unlock_irq(shost->host_lock);
474 * If there is an outstanding PLOGI issued, abort it before
475 * sending ACC rsp for received PLOGI. If pending plogi
476 * is not canceled here, the plogi will be rejected by
477 * remote port and will be retried. On a configuration with
478 * single discovery thread, this will cause a huge delay in
479 * discovery. Also this will cause multiple state machines
480 * running in parallel for this node.
482 if (ndlp->nlp_state == NLP_STE_PLOGI_ISSUE) {
483 /* software abort outstanding PLOGI */
484 lpfc_els_abort(phba, ndlp);
487 if ((vport->port_type == LPFC_NPIV_PORT &&
488 vport->cfg_restrict_login)) {
490 /* In order to preserve RPIs, we want to cleanup
491 * the default RPI the firmware created to rcv
492 * this ELS request. The only way to do this is
493 * to register, then unregister the RPI.
495 spin_lock_irq(shost->host_lock);
496 ndlp->nlp_flag |= NLP_RM_DFLT_RPI;
497 spin_unlock_irq(shost->host_lock);
498 stat.un.b.lsRjtRsnCode = LSRJT_INVALID_CMD;
499 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
500 rc = lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb,
503 mempool_free(mbox, phba->mbox_mem_pool);
506 rc = lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp, mbox);
508 mempool_free(mbox, phba->mbox_mem_pool);
511 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
512 stat.un.b.lsRjtRsnCodeExp = LSEXP_OUT_OF_RESOURCE;
513 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
518 * lpfc_mbx_cmpl_resume_rpi - Resume RPI completion routine
519 * @phba: pointer to lpfc hba data structure.
520 * @mboxq: pointer to mailbox object
522 * This routine is invoked to issue a completion to a rcv'ed
523 * ADISC or PDISC after the paused RPI has been resumed.
526 lpfc_mbx_cmpl_resume_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
528 struct lpfc_vport *vport;
529 struct lpfc_iocbq *elsiocb;
530 struct lpfc_nodelist *ndlp;
533 elsiocb = (struct lpfc_iocbq *)mboxq->context1;
534 ndlp = (struct lpfc_nodelist *) mboxq->context2;
535 vport = mboxq->vport;
536 cmd = elsiocb->drvrTimeout;
538 if (cmd == ELS_CMD_ADISC) {
539 lpfc_els_rsp_adisc_acc(vport, elsiocb, ndlp);
541 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, elsiocb,
545 mempool_free(mboxq, phba->mbox_mem_pool);
549 lpfc_rcv_padisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
550 struct lpfc_iocbq *cmdiocb)
552 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
553 struct lpfc_iocbq *elsiocb;
554 struct lpfc_dmabuf *pcmd;
555 struct serv_parm *sp;
556 struct lpfc_name *pnn, *ppn;
563 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
564 lp = (uint32_t *) pcmd->virt;
567 if (cmd == ELS_CMD_ADISC) {
569 pnn = (struct lpfc_name *) & ap->nodeName;
570 ppn = (struct lpfc_name *) & ap->portName;
572 sp = (struct serv_parm *) lp;
573 pnn = (struct lpfc_name *) & sp->nodeName;
574 ppn = (struct lpfc_name *) & sp->portName;
577 icmd = &cmdiocb->iocb;
578 if (icmd->ulpStatus == 0 && lpfc_check_adisc(vport, ndlp, pnn, ppn)) {
581 * As soon as we send ACC, the remote NPort can
582 * start sending us data. Thus, for SLI4 we must
583 * resume the RPI before the ACC goes out.
585 if (vport->phba->sli_rev == LPFC_SLI_REV4) {
586 elsiocb = kmalloc(sizeof(struct lpfc_iocbq),
590 /* Save info from cmd IOCB used in rsp */
591 memcpy((uint8_t *)elsiocb, (uint8_t *)cmdiocb,
592 sizeof(struct lpfc_iocbq));
594 /* Save the ELS cmd */
595 elsiocb->drvrTimeout = cmd;
597 lpfc_sli4_resume_rpi(ndlp,
598 lpfc_mbx_cmpl_resume_rpi, elsiocb);
603 if (cmd == ELS_CMD_ADISC) {
604 lpfc_els_rsp_adisc_acc(vport, cmdiocb, ndlp);
606 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb,
610 /* If we are authenticated, move to the proper state */
611 if (ndlp->nlp_type & NLP_FCP_TARGET)
612 lpfc_nlp_set_state(vport, ndlp, NLP_STE_MAPPED_NODE);
614 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
618 /* Reject this request because invalid parameters */
619 stat.un.b.lsRjtRsvd0 = 0;
620 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
621 stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
622 stat.un.b.vendorUnique = 0;
623 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
626 mod_timer(&ndlp->nlp_delayfunc, jiffies + msecs_to_jiffies(1000));
628 spin_lock_irq(shost->host_lock);
629 ndlp->nlp_flag |= NLP_DELAY_TMO;
630 spin_unlock_irq(shost->host_lock);
631 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
632 ndlp->nlp_prev_state = ndlp->nlp_state;
633 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
638 lpfc_rcv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
639 struct lpfc_iocbq *cmdiocb, uint32_t els_cmd)
641 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
642 struct lpfc_hba *phba = vport->phba;
643 struct lpfc_vport **vports;
644 int i, active_vlink_present = 0 ;
646 /* Put ndlp in NPR state with 1 sec timeout for plogi, ACC logo */
647 /* Only call LOGO ACC for first LOGO, this avoids sending unnecessary
648 * PLOGIs during LOGO storms from a device.
650 spin_lock_irq(shost->host_lock);
651 ndlp->nlp_flag |= NLP_LOGO_ACC;
652 spin_unlock_irq(shost->host_lock);
653 if (els_cmd == ELS_CMD_PRLO)
654 lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL);
656 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
657 if (ndlp->nlp_DID == Fabric_DID) {
658 if (vport->port_state <= LPFC_FDISC)
660 lpfc_linkdown_port(vport);
661 spin_lock_irq(shost->host_lock);
662 vport->fc_flag |= FC_VPORT_LOGO_RCVD;
663 spin_unlock_irq(shost->host_lock);
664 vports = lpfc_create_vport_work_array(phba);
666 for (i = 0; i <= phba->max_vports && vports[i] != NULL;
668 if ((!(vports[i]->fc_flag &
669 FC_VPORT_LOGO_RCVD)) &&
670 (vports[i]->port_state > LPFC_FDISC)) {
671 active_vlink_present = 1;
675 lpfc_destroy_vport_work_array(phba, vports);
679 * Don't re-instantiate if vport is marked for deletion.
680 * If we are here first then vport_delete is going to wait
681 * for discovery to complete.
683 if (!(vport->load_flag & FC_UNLOADING) &&
684 active_vlink_present) {
686 * If there are other active VLinks present,
687 * re-instantiate the Vlink using FDISC.
689 mod_timer(&ndlp->nlp_delayfunc,
690 jiffies + msecs_to_jiffies(1000));
691 spin_lock_irq(shost->host_lock);
692 ndlp->nlp_flag |= NLP_DELAY_TMO;
693 spin_unlock_irq(shost->host_lock);
694 ndlp->nlp_last_elscmd = ELS_CMD_FDISC;
695 vport->port_state = LPFC_FDISC;
697 spin_lock_irq(shost->host_lock);
698 phba->pport->fc_flag &= ~FC_LOGO_RCVD_DID_CHNG;
699 spin_unlock_irq(shost->host_lock);
700 lpfc_retry_pport_discovery(phba);
702 } else if ((!(ndlp->nlp_type & NLP_FABRIC) &&
703 ((ndlp->nlp_type & NLP_FCP_TARGET) ||
704 !(ndlp->nlp_type & NLP_FCP_INITIATOR))) ||
705 (ndlp->nlp_state == NLP_STE_ADISC_ISSUE)) {
706 /* Only try to re-login if this is NOT a Fabric Node */
707 mod_timer(&ndlp->nlp_delayfunc,
708 jiffies + msecs_to_jiffies(1000 * 1));
709 spin_lock_irq(shost->host_lock);
710 ndlp->nlp_flag |= NLP_DELAY_TMO;
711 spin_unlock_irq(shost->host_lock);
713 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
716 ndlp->nlp_prev_state = ndlp->nlp_state;
717 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
719 spin_lock_irq(shost->host_lock);
720 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
721 spin_unlock_irq(shost->host_lock);
722 /* The driver has to wait until the ACC completes before it continues
723 * processing the LOGO. The action will resume in
724 * lpfc_cmpl_els_logo_acc routine. Since part of processing includes an
725 * unreg_login, the driver waits so the ACC does not get aborted.
731 lpfc_rcv_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
732 struct lpfc_iocbq *cmdiocb)
734 struct lpfc_hba *phba = vport->phba;
735 struct lpfc_dmabuf *pcmd;
738 struct fc_rport *rport = ndlp->rport;
741 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
742 lp = (uint32_t *) pcmd->virt;
743 npr = (PRLI *) ((uint8_t *) lp + sizeof (uint32_t));
745 ndlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR);
746 ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
747 ndlp->nlp_flag &= ~NLP_FIRSTBURST;
748 if ((npr->prliType == PRLI_FCP_TYPE) ||
749 (npr->prliType == PRLI_NVME_TYPE)) {
750 if (npr->initiatorFunc) {
751 if (npr->prliType == PRLI_FCP_TYPE)
752 ndlp->nlp_type |= NLP_FCP_INITIATOR;
753 if (npr->prliType == PRLI_NVME_TYPE)
754 ndlp->nlp_type |= NLP_NVME_INITIATOR;
756 if (npr->targetFunc) {
757 if (npr->prliType == PRLI_FCP_TYPE)
758 ndlp->nlp_type |= NLP_FCP_TARGET;
759 if (npr->prliType == PRLI_NVME_TYPE)
760 ndlp->nlp_type |= NLP_NVME_TARGET;
761 if (npr->writeXferRdyDis)
762 ndlp->nlp_flag |= NLP_FIRSTBURST;
765 ndlp->nlp_fcp_info |= NLP_FCP_2_DEVICE;
767 /* If this driver is in nvme target mode, set the ndlp's fc4
768 * type to NVME provided the PRLI response claims NVME FC4
769 * type. Target mode does not issue gft_id so doesn't get
770 * the fc4 type set until now.
772 if ((phba->nvmet_support) && (npr->prliType == PRLI_NVME_TYPE))
773 ndlp->nlp_fc4_type |= NLP_FC4_NVME;
776 /* We need to update the rport role values */
777 roles = FC_RPORT_ROLE_UNKNOWN;
778 if (ndlp->nlp_type & NLP_FCP_INITIATOR)
779 roles |= FC_RPORT_ROLE_FCP_INITIATOR;
780 if (ndlp->nlp_type & NLP_FCP_TARGET)
781 roles |= FC_RPORT_ROLE_FCP_TARGET;
783 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
784 "rport rolechg: role:x%x did:x%x flg:x%x",
785 roles, ndlp->nlp_DID, ndlp->nlp_flag);
787 if (phba->cfg_enable_fc4_type != LPFC_ENABLE_NVME)
788 fc_remote_port_rolechg(rport, roles);
793 lpfc_disc_set_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
795 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
797 if (!(ndlp->nlp_flag & NLP_RPI_REGISTERED)) {
798 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
802 if (!(vport->fc_flag & FC_PT2PT)) {
803 /* Check config parameter use-adisc or FCP-2 */
804 if ((vport->cfg_use_adisc && (vport->fc_flag & FC_RSCN_MODE)) ||
805 ((ndlp->nlp_fcp_info & NLP_FCP_2_DEVICE) &&
806 (ndlp->nlp_type & NLP_FCP_TARGET))) {
807 spin_lock_irq(shost->host_lock);
808 ndlp->nlp_flag |= NLP_NPR_ADISC;
809 spin_unlock_irq(shost->host_lock);
813 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
814 lpfc_unreg_rpi(vport, ndlp);
819 * lpfc_release_rpi - Release a RPI by issuing unreg_login mailbox cmd.
820 * @phba : Pointer to lpfc_hba structure.
821 * @vport: Pointer to lpfc_vport structure.
822 * @rpi : rpi to be release.
824 * This function will send a unreg_login mailbox command to the firmware
828 lpfc_release_rpi(struct lpfc_hba *phba,
829 struct lpfc_vport *vport,
835 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
838 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
839 "2796 mailbox memory allocation failed \n");
841 lpfc_unreg_login(phba, vport->vpi, rpi, pmb);
842 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
843 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
844 if (rc == MBX_NOT_FINISHED)
845 mempool_free(pmb, phba->mbox_mem_pool);
850 lpfc_disc_illegal(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
851 void *arg, uint32_t evt)
853 struct lpfc_hba *phba;
854 LPFC_MBOXQ_t *pmb = (LPFC_MBOXQ_t *) arg;
858 /* Release the RPI if reglogin completing */
859 if (!(phba->pport->load_flag & FC_UNLOADING) &&
860 (evt == NLP_EVT_CMPL_REG_LOGIN) &&
861 (!pmb->u.mb.mbxStatus)) {
862 rpi = pmb->u.mb.un.varWords[0];
863 lpfc_release_rpi(phba, vport, rpi);
865 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
866 "0271 Illegal State Transition: node x%x "
867 "event x%x, state x%x Data: x%x x%x\n",
868 ndlp->nlp_DID, evt, ndlp->nlp_state, ndlp->nlp_rpi,
870 return ndlp->nlp_state;
874 lpfc_cmpl_plogi_illegal(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
875 void *arg, uint32_t evt)
877 /* This transition is only legal if we previously
878 * rcv'ed a PLOGI. Since we don't want 2 discovery threads
879 * working on the same NPortID, do nothing for this thread
882 if (!(ndlp->nlp_flag & NLP_RCV_PLOGI)) {
883 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
884 "0272 Illegal State Transition: node x%x "
885 "event x%x, state x%x Data: x%x x%x\n",
886 ndlp->nlp_DID, evt, ndlp->nlp_state, ndlp->nlp_rpi,
889 return ndlp->nlp_state;
892 /* Start of Discovery State Machine routines */
895 lpfc_rcv_plogi_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
896 void *arg, uint32_t evt)
898 struct lpfc_iocbq *cmdiocb;
900 cmdiocb = (struct lpfc_iocbq *) arg;
902 if (lpfc_rcv_plogi(vport, ndlp, cmdiocb)) {
903 return ndlp->nlp_state;
905 return NLP_STE_FREED_NODE;
909 lpfc_rcv_els_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
910 void *arg, uint32_t evt)
912 lpfc_issue_els_logo(vport, ndlp, 0);
913 return ndlp->nlp_state;
917 lpfc_rcv_logo_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
918 void *arg, uint32_t evt)
920 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
921 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
923 spin_lock_irq(shost->host_lock);
924 ndlp->nlp_flag |= NLP_LOGO_ACC;
925 spin_unlock_irq(shost->host_lock);
926 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
928 return ndlp->nlp_state;
932 lpfc_cmpl_logo_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_rm_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
940 void *arg, uint32_t evt)
942 return NLP_STE_FREED_NODE;
946 lpfc_device_recov_unused_node(struct lpfc_vport *vport,
947 struct lpfc_nodelist *ndlp,
948 void *arg, uint32_t evt)
950 return ndlp->nlp_state;
954 lpfc_rcv_plogi_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
955 void *arg, uint32_t evt)
957 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
958 struct lpfc_hba *phba = vport->phba;
959 struct lpfc_iocbq *cmdiocb = arg;
960 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
961 uint32_t *lp = (uint32_t *) pcmd->virt;
962 struct serv_parm *sp = (struct serv_parm *) (lp + 1);
966 memset(&stat, 0, sizeof (struct ls_rjt));
968 /* For a PLOGI, we only accept if our portname is less
969 * than the remote portname.
971 phba->fc_stat.elsLogiCol++;
972 port_cmp = memcmp(&vport->fc_portname, &sp->portName,
973 sizeof(struct lpfc_name));
976 /* Reject this request because the remote node will accept
978 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
979 stat.un.b.lsRjtRsnCodeExp = LSEXP_CMD_IN_PROGRESS;
980 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
983 if (lpfc_rcv_plogi(vport, ndlp, cmdiocb) &&
984 (ndlp->nlp_flag & NLP_NPR_2B_DISC) &&
985 (vport->num_disc_nodes)) {
986 spin_lock_irq(shost->host_lock);
987 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
988 spin_unlock_irq(shost->host_lock);
989 /* Check if there are more PLOGIs to be sent */
990 lpfc_more_plogi(vport);
991 if (vport->num_disc_nodes == 0) {
992 spin_lock_irq(shost->host_lock);
993 vport->fc_flag &= ~FC_NDISC_ACTIVE;
994 spin_unlock_irq(shost->host_lock);
995 lpfc_can_disctmo(vport);
996 lpfc_end_rscn(vport);
999 } /* If our portname was less */
1001 return ndlp->nlp_state;
1005 lpfc_rcv_prli_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1006 void *arg, uint32_t evt)
1008 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1011 memset(&stat, 0, sizeof (struct ls_rjt));
1012 stat.un.b.lsRjtRsnCode = LSRJT_LOGICAL_BSY;
1013 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
1014 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
1015 return ndlp->nlp_state;
1019 lpfc_rcv_logo_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1020 void *arg, uint32_t evt)
1022 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1024 /* software abort outstanding PLOGI */
1025 lpfc_els_abort(vport->phba, ndlp);
1027 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
1028 return ndlp->nlp_state;
1032 lpfc_rcv_els_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 = (struct lpfc_iocbq *) arg;
1039 /* software abort outstanding PLOGI */
1040 lpfc_els_abort(phba, ndlp);
1042 if (evt == NLP_EVT_RCV_LOGO) {
1043 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
1045 lpfc_issue_els_logo(vport, ndlp, 0);
1048 /* Put ndlp in npr state set plogi timer for 1 sec */
1049 mod_timer(&ndlp->nlp_delayfunc, jiffies + msecs_to_jiffies(1000 * 1));
1050 spin_lock_irq(shost->host_lock);
1051 ndlp->nlp_flag |= NLP_DELAY_TMO;
1052 spin_unlock_irq(shost->host_lock);
1053 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
1054 ndlp->nlp_prev_state = NLP_STE_PLOGI_ISSUE;
1055 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1057 return ndlp->nlp_state;
1061 lpfc_cmpl_plogi_plogi_issue(struct lpfc_vport *vport,
1062 struct lpfc_nodelist *ndlp,
1066 struct lpfc_hba *phba = vport->phba;
1067 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1068 struct lpfc_iocbq *cmdiocb, *rspiocb;
1069 struct lpfc_dmabuf *pcmd, *prsp, *mp;
1073 struct serv_parm *sp;
1078 cmdiocb = (struct lpfc_iocbq *) arg;
1079 rspiocb = cmdiocb->context_un.rsp_iocb;
1081 if (ndlp->nlp_flag & NLP_ACC_REGLOGIN) {
1082 /* Recovery from PLOGI collision logic */
1083 return ndlp->nlp_state;
1086 irsp = &rspiocb->iocb;
1088 if (irsp->ulpStatus)
1091 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
1093 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
1097 lp = (uint32_t *) prsp->virt;
1098 sp = (struct serv_parm *) ((uint8_t *) lp + sizeof (uint32_t));
1100 /* Some switches have FDMI servers returning 0 for WWN */
1101 if ((ndlp->nlp_DID != FDMI_DID) &&
1102 (wwn_to_u64(sp->portName.u.wwn) == 0 ||
1103 wwn_to_u64(sp->nodeName.u.wwn) == 0)) {
1104 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1105 "0142 PLOGI RSP: Invalid WWN.\n");
1108 if (!lpfc_check_sparm(vport, ndlp, sp, CLASS3, 0))
1110 /* PLOGI chkparm OK */
1111 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1112 "0121 PLOGI chkparm OK Data: x%x x%x x%x x%x\n",
1113 ndlp->nlp_DID, ndlp->nlp_state,
1114 ndlp->nlp_flag, ndlp->nlp_rpi);
1115 if (vport->cfg_fcp_class == 2 && (sp->cls2.classValid))
1116 ndlp->nlp_fcp_info |= CLASS2;
1118 ndlp->nlp_fcp_info |= CLASS3;
1120 ndlp->nlp_class_sup = 0;
1121 if (sp->cls1.classValid)
1122 ndlp->nlp_class_sup |= FC_COS_CLASS1;
1123 if (sp->cls2.classValid)
1124 ndlp->nlp_class_sup |= FC_COS_CLASS2;
1125 if (sp->cls3.classValid)
1126 ndlp->nlp_class_sup |= FC_COS_CLASS3;
1127 if (sp->cls4.classValid)
1128 ndlp->nlp_class_sup |= FC_COS_CLASS4;
1129 ndlp->nlp_maxframe =
1130 ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) | sp->cmn.bbRcvSizeLsb;
1132 if ((vport->fc_flag & FC_PT2PT) &&
1133 (vport->fc_flag & FC_PT2PT_PLOGI)) {
1134 ed_tov = be32_to_cpu(sp->cmn.e_d_tov);
1135 if (sp->cmn.edtovResolution) {
1136 /* E_D_TOV ticks are in nanoseconds */
1137 ed_tov = (phba->fc_edtov + 999999) / 1000000;
1140 ndlp->nlp_flag &= ~NLP_SUPPRESS_RSP;
1141 if ((phba->sli.sli_flag & LPFC_SLI_SUPPRESS_RSP) &&
1142 sp->cmn.valid_vendor_ver_level) {
1143 vid = be32_to_cpu(sp->un.vv.vid);
1144 flag = be32_to_cpu(sp->un.vv.flags);
1145 if ((vid == LPFC_VV_EMLX_ID) &&
1146 (flag & LPFC_VV_SUPPRESS_RSP))
1147 ndlp->nlp_flag |= NLP_SUPPRESS_RSP;
1151 * Use the larger EDTOV
1152 * RATOV = 2 * EDTOV for pt-to-pt
1154 if (ed_tov > phba->fc_edtov)
1155 phba->fc_edtov = ed_tov;
1156 phba->fc_ratov = (2 * phba->fc_edtov) / 1000;
1158 memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
1160 /* Issue config_link / reg_vfi to account for updated TOV's */
1161 if (phba->sli_rev == LPFC_SLI_REV4) {
1162 lpfc_issue_reg_vfi(vport);
1164 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1166 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1167 "0133 PLOGI: no memory "
1169 "Data: x%x x%x x%x x%x\n",
1170 ndlp->nlp_DID, ndlp->nlp_state,
1171 ndlp->nlp_flag, ndlp->nlp_rpi);
1175 lpfc_config_link(phba, mbox);
1177 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1178 mbox->vport = vport;
1179 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
1180 if (rc == MBX_NOT_FINISHED) {
1181 mempool_free(mbox, phba->mbox_mem_pool);
1187 lpfc_unreg_rpi(vport, ndlp);
1189 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1191 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1192 "0018 PLOGI: no memory for reg_login "
1193 "Data: x%x x%x x%x x%x\n",
1194 ndlp->nlp_DID, ndlp->nlp_state,
1195 ndlp->nlp_flag, ndlp->nlp_rpi);
1199 if (lpfc_reg_rpi(phba, vport->vpi, irsp->un.elsreq64.remoteID,
1200 (uint8_t *) sp, mbox, ndlp->nlp_rpi) == 0) {
1201 switch (ndlp->nlp_DID) {
1202 case NameServer_DID:
1203 mbox->mbox_cmpl = lpfc_mbx_cmpl_ns_reg_login;
1206 mbox->mbox_cmpl = lpfc_mbx_cmpl_fdmi_reg_login;
1209 ndlp->nlp_flag |= NLP_REG_LOGIN_SEND;
1210 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
1212 mbox->context2 = lpfc_nlp_get(ndlp);
1213 mbox->vport = vport;
1214 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
1215 != MBX_NOT_FINISHED) {
1216 lpfc_nlp_set_state(vport, ndlp,
1217 NLP_STE_REG_LOGIN_ISSUE);
1218 return ndlp->nlp_state;
1220 if (ndlp->nlp_flag & NLP_REG_LOGIN_SEND)
1221 ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND;
1222 /* decrement node reference count to the failed mbox
1226 mp = (struct lpfc_dmabuf *) mbox->context1;
1227 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1229 mempool_free(mbox, phba->mbox_mem_pool);
1231 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1232 "0134 PLOGI: cannot issue reg_login "
1233 "Data: x%x x%x x%x x%x\n",
1234 ndlp->nlp_DID, ndlp->nlp_state,
1235 ndlp->nlp_flag, ndlp->nlp_rpi);
1237 mempool_free(mbox, phba->mbox_mem_pool);
1239 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1240 "0135 PLOGI: cannot format reg_login "
1241 "Data: x%x x%x x%x x%x\n",
1242 ndlp->nlp_DID, ndlp->nlp_state,
1243 ndlp->nlp_flag, ndlp->nlp_rpi);
1248 if (ndlp->nlp_DID == NameServer_DID) {
1249 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
1250 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1251 "0261 Cannot Register NameServer login\n");
1255 ** In case the node reference counter does not go to zero, ensure that
1256 ** the stale state for the node is not processed.
1259 ndlp->nlp_prev_state = ndlp->nlp_state;
1260 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1261 spin_lock_irq(shost->host_lock);
1262 ndlp->nlp_flag |= NLP_DEFER_RM;
1263 spin_unlock_irq(shost->host_lock);
1264 return NLP_STE_FREED_NODE;
1268 lpfc_cmpl_logo_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1269 void *arg, uint32_t evt)
1271 return ndlp->nlp_state;
1275 lpfc_cmpl_reglogin_plogi_issue(struct lpfc_vport *vport,
1276 struct lpfc_nodelist *ndlp, void *arg, uint32_t evt)
1278 struct lpfc_hba *phba;
1279 LPFC_MBOXQ_t *pmb = (LPFC_MBOXQ_t *) arg;
1280 MAILBOX_t *mb = &pmb->u.mb;
1284 /* Release the RPI */
1285 if (!(phba->pport->load_flag & FC_UNLOADING) &&
1287 rpi = pmb->u.mb.un.varWords[0];
1288 lpfc_release_rpi(phba, vport, rpi);
1290 return ndlp->nlp_state;
1294 lpfc_device_rm_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1295 void *arg, uint32_t evt)
1297 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1299 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1300 spin_lock_irq(shost->host_lock);
1301 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
1302 spin_unlock_irq(shost->host_lock);
1303 return ndlp->nlp_state;
1305 /* software abort outstanding PLOGI */
1306 lpfc_els_abort(vport->phba, ndlp);
1308 lpfc_drop_node(vport, ndlp);
1309 return NLP_STE_FREED_NODE;
1314 lpfc_device_recov_plogi_issue(struct lpfc_vport *vport,
1315 struct lpfc_nodelist *ndlp,
1319 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1320 struct lpfc_hba *phba = vport->phba;
1322 /* Don't do anything that will mess up processing of the
1325 if (vport->fc_flag & FC_RSCN_DEFERRED)
1326 return ndlp->nlp_state;
1328 /* software abort outstanding PLOGI */
1329 lpfc_els_abort(phba, ndlp);
1331 ndlp->nlp_prev_state = NLP_STE_PLOGI_ISSUE;
1332 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1333 spin_lock_irq(shost->host_lock);
1334 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
1335 spin_unlock_irq(shost->host_lock);
1337 return ndlp->nlp_state;
1341 lpfc_rcv_plogi_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1342 void *arg, uint32_t evt)
1344 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1345 struct lpfc_hba *phba = vport->phba;
1346 struct lpfc_iocbq *cmdiocb;
1348 /* software abort outstanding ADISC */
1349 lpfc_els_abort(phba, ndlp);
1351 cmdiocb = (struct lpfc_iocbq *) arg;
1353 if (lpfc_rcv_plogi(vport, ndlp, cmdiocb)) {
1354 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1355 spin_lock_irq(shost->host_lock);
1356 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
1357 spin_unlock_irq(shost->host_lock);
1358 if (vport->num_disc_nodes)
1359 lpfc_more_adisc(vport);
1361 return ndlp->nlp_state;
1363 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
1364 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
1365 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
1367 return ndlp->nlp_state;
1371 lpfc_rcv_prli_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1372 void *arg, uint32_t evt)
1374 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1376 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
1377 return ndlp->nlp_state;
1381 lpfc_rcv_logo_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1382 void *arg, uint32_t evt)
1384 struct lpfc_hba *phba = vport->phba;
1385 struct lpfc_iocbq *cmdiocb;
1387 cmdiocb = (struct lpfc_iocbq *) arg;
1389 /* software abort outstanding ADISC */
1390 lpfc_els_abort(phba, ndlp);
1392 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
1393 return ndlp->nlp_state;
1397 lpfc_rcv_padisc_adisc_issue(struct lpfc_vport *vport,
1398 struct lpfc_nodelist *ndlp,
1399 void *arg, uint32_t evt)
1401 struct lpfc_iocbq *cmdiocb;
1403 cmdiocb = (struct lpfc_iocbq *) arg;
1405 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
1406 return ndlp->nlp_state;
1410 lpfc_rcv_prlo_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1411 void *arg, uint32_t evt)
1413 struct lpfc_iocbq *cmdiocb;
1415 cmdiocb = (struct lpfc_iocbq *) arg;
1417 /* Treat like rcv logo */
1418 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_PRLO);
1419 return ndlp->nlp_state;
1423 lpfc_cmpl_adisc_adisc_issue(struct lpfc_vport *vport,
1424 struct lpfc_nodelist *ndlp,
1425 void *arg, uint32_t evt)
1427 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1428 struct lpfc_hba *phba = vport->phba;
1429 struct lpfc_iocbq *cmdiocb, *rspiocb;
1434 cmdiocb = (struct lpfc_iocbq *) arg;
1435 rspiocb = cmdiocb->context_un.rsp_iocb;
1437 ap = (ADISC *)lpfc_check_elscmpl_iocb(phba, cmdiocb, rspiocb);
1438 irsp = &rspiocb->iocb;
1440 if ((irsp->ulpStatus) ||
1441 (!lpfc_check_adisc(vport, ndlp, &ap->nodeName, &ap->portName))) {
1443 mod_timer(&ndlp->nlp_delayfunc,
1444 jiffies + msecs_to_jiffies(1000));
1445 spin_lock_irq(shost->host_lock);
1446 ndlp->nlp_flag |= NLP_DELAY_TMO;
1447 spin_unlock_irq(shost->host_lock);
1448 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
1450 memset(&ndlp->nlp_nodename, 0, sizeof(struct lpfc_name));
1451 memset(&ndlp->nlp_portname, 0, sizeof(struct lpfc_name));
1453 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
1454 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1455 lpfc_unreg_rpi(vport, ndlp);
1456 return ndlp->nlp_state;
1459 if (phba->sli_rev == LPFC_SLI_REV4) {
1460 rc = lpfc_sli4_resume_rpi(ndlp, NULL, NULL);
1462 /* Stay in state and retry. */
1463 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
1464 return ndlp->nlp_state;
1468 if (ndlp->nlp_type & NLP_FCP_TARGET) {
1469 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
1470 lpfc_nlp_set_state(vport, ndlp, NLP_STE_MAPPED_NODE);
1472 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
1473 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
1476 return ndlp->nlp_state;
1480 lpfc_device_rm_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1481 void *arg, uint32_t evt)
1483 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1485 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1486 spin_lock_irq(shost->host_lock);
1487 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
1488 spin_unlock_irq(shost->host_lock);
1489 return ndlp->nlp_state;
1491 /* software abort outstanding ADISC */
1492 lpfc_els_abort(vport->phba, ndlp);
1494 lpfc_drop_node(vport, ndlp);
1495 return NLP_STE_FREED_NODE;
1500 lpfc_device_recov_adisc_issue(struct lpfc_vport *vport,
1501 struct lpfc_nodelist *ndlp,
1505 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1506 struct lpfc_hba *phba = vport->phba;
1508 /* Don't do anything that will mess up processing of the
1511 if (vport->fc_flag & FC_RSCN_DEFERRED)
1512 return ndlp->nlp_state;
1514 /* software abort outstanding ADISC */
1515 lpfc_els_abort(phba, ndlp);
1517 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
1518 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1519 spin_lock_irq(shost->host_lock);
1520 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
1521 spin_unlock_irq(shost->host_lock);
1522 lpfc_disc_set_adisc(vport, ndlp);
1523 return ndlp->nlp_state;
1527 lpfc_rcv_plogi_reglogin_issue(struct lpfc_vport *vport,
1528 struct lpfc_nodelist *ndlp,
1532 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1534 lpfc_rcv_plogi(vport, ndlp, cmdiocb);
1535 return ndlp->nlp_state;
1539 lpfc_rcv_prli_reglogin_issue(struct lpfc_vport *vport,
1540 struct lpfc_nodelist *ndlp,
1544 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1547 if (vport->phba->nvmet_support) {
1548 /* NVME Target mode. Handle and respond to the PRLI and
1549 * transition to UNMAPPED provided the RPI has completed
1552 if (ndlp->nlp_flag & NLP_RPI_REGISTERED) {
1553 lpfc_rcv_prli(vport, ndlp, cmdiocb);
1554 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
1555 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
1557 /* RPI registration has not completed. Reject the PRLI
1558 * to prevent an illegal state transition when the
1559 * rpi registration does complete.
1561 lpfc_printf_vlog(vport, KERN_WARNING, LOG_NVME_DISC,
1562 "6115 NVMET ndlp rpi %d state "
1563 "unknown, state x%x flags x%08x\n",
1564 ndlp->nlp_rpi, ndlp->nlp_state,
1566 memset(&stat, 0, sizeof(struct ls_rjt));
1567 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
1568 stat.un.b.lsRjtRsnCodeExp = LSEXP_CMD_IN_PROGRESS;
1569 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb,
1573 /* Initiator mode. */
1574 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
1577 return ndlp->nlp_state;
1581 lpfc_rcv_logo_reglogin_issue(struct lpfc_vport *vport,
1582 struct lpfc_nodelist *ndlp,
1586 struct lpfc_hba *phba = vport->phba;
1587 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1589 LPFC_MBOXQ_t *nextmb;
1590 struct lpfc_dmabuf *mp;
1592 cmdiocb = (struct lpfc_iocbq *) arg;
1594 /* cleanup any ndlp on mbox q waiting for reglogin cmpl */
1595 if ((mb = phba->sli.mbox_active)) {
1596 if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) &&
1597 (ndlp == (struct lpfc_nodelist *) mb->context2)) {
1598 ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND;
1600 mb->context2 = NULL;
1601 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1605 spin_lock_irq(&phba->hbalock);
1606 list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) {
1607 if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) &&
1608 (ndlp == (struct lpfc_nodelist *) mb->context2)) {
1609 mp = (struct lpfc_dmabuf *) (mb->context1);
1611 __lpfc_mbuf_free(phba, mp->virt, mp->phys);
1614 ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND;
1616 list_del(&mb->list);
1617 phba->sli.mboxq_cnt--;
1618 mempool_free(mb, phba->mbox_mem_pool);
1621 spin_unlock_irq(&phba->hbalock);
1623 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
1624 return ndlp->nlp_state;
1628 lpfc_rcv_padisc_reglogin_issue(struct lpfc_vport *vport,
1629 struct lpfc_nodelist *ndlp,
1633 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1635 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
1636 return ndlp->nlp_state;
1640 lpfc_rcv_prlo_reglogin_issue(struct lpfc_vport *vport,
1641 struct lpfc_nodelist *ndlp,
1645 struct lpfc_iocbq *cmdiocb;
1647 cmdiocb = (struct lpfc_iocbq *) arg;
1648 lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL);
1649 return ndlp->nlp_state;
1653 lpfc_cmpl_reglogin_reglogin_issue(struct lpfc_vport *vport,
1654 struct lpfc_nodelist *ndlp,
1658 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1659 struct lpfc_hba *phba = vport->phba;
1660 LPFC_MBOXQ_t *pmb = (LPFC_MBOXQ_t *) arg;
1661 MAILBOX_t *mb = &pmb->u.mb;
1662 uint32_t did = mb->un.varWords[1];
1665 if (mb->mbxStatus) {
1666 /* RegLogin failed */
1667 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
1668 "0246 RegLogin failed Data: x%x x%x x%x x%x "
1670 did, mb->mbxStatus, vport->port_state,
1671 mb->un.varRegLogin.vpi,
1672 mb->un.varRegLogin.rpi);
1674 * If RegLogin failed due to lack of HBA resources do not
1677 if (mb->mbxStatus == MBXERR_RPI_FULL) {
1678 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
1679 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1680 return ndlp->nlp_state;
1683 /* Put ndlp in npr state set plogi timer for 1 sec */
1684 mod_timer(&ndlp->nlp_delayfunc,
1685 jiffies + msecs_to_jiffies(1000 * 1));
1686 spin_lock_irq(shost->host_lock);
1687 ndlp->nlp_flag |= NLP_DELAY_TMO;
1688 spin_unlock_irq(shost->host_lock);
1689 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
1691 lpfc_issue_els_logo(vport, ndlp, 0);
1692 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
1693 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1694 return ndlp->nlp_state;
1697 /* SLI4 ports have preallocated logical rpis. */
1698 if (phba->sli_rev < LPFC_SLI_REV4)
1699 ndlp->nlp_rpi = mb->un.varWords[0];
1701 ndlp->nlp_flag |= NLP_RPI_REGISTERED;
1703 /* Only if we are not a fabric nport do we issue PRLI */
1704 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1705 "3066 RegLogin Complete on x%x x%x x%x\n",
1706 did, ndlp->nlp_type, ndlp->nlp_fc4_type);
1707 if (!(ndlp->nlp_type & NLP_FABRIC) &&
1708 (phba->nvmet_support == 0)) {
1709 /* The driver supports FCP and NVME concurrently. If the
1710 * ndlp's nlp_fc4_type is still zero, the driver doesn't
1711 * know what PRLI to send yet. Figure that out now and
1712 * call PRLI depending on the outcome.
1714 if (vport->fc_flag & FC_PT2PT) {
1715 /* If we are pt2pt, there is no Fabric to determine
1716 * the FC4 type of the remote nport. So if NVME
1717 * is configured try it.
1719 ndlp->nlp_fc4_type |= NLP_FC4_FCP;
1720 if ((phba->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
1721 (phba->cfg_enable_fc4_type == LPFC_ENABLE_NVME)) {
1722 ndlp->nlp_fc4_type |= NLP_FC4_NVME;
1723 /* We need to update the localport also */
1724 lpfc_nvme_update_localport(vport);
1727 } else if (ndlp->nlp_fc4_type == 0) {
1728 rc = lpfc_ns_cmd(vport, SLI_CTNS_GFT_ID,
1730 return ndlp->nlp_state;
1733 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
1734 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
1735 lpfc_issue_els_prli(vport, ndlp, 0);
1737 if ((vport->fc_flag & FC_PT2PT) && phba->nvmet_support)
1738 phba->targetport->port_id = vport->fc_myDID;
1740 /* Only Fabric ports should transition. NVME target
1741 * must complete PRLI.
1743 if (ndlp->nlp_type & NLP_FABRIC) {
1744 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
1745 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
1748 return ndlp->nlp_state;
1752 lpfc_device_rm_reglogin_issue(struct lpfc_vport *vport,
1753 struct lpfc_nodelist *ndlp,
1757 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1759 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1760 spin_lock_irq(shost->host_lock);
1761 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
1762 spin_unlock_irq(shost->host_lock);
1763 return ndlp->nlp_state;
1765 lpfc_drop_node(vport, ndlp);
1766 return NLP_STE_FREED_NODE;
1771 lpfc_device_recov_reglogin_issue(struct lpfc_vport *vport,
1772 struct lpfc_nodelist *ndlp,
1776 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1778 /* Don't do anything that will mess up processing of the
1781 if (vport->fc_flag & FC_RSCN_DEFERRED)
1782 return ndlp->nlp_state;
1784 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
1785 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1786 spin_lock_irq(shost->host_lock);
1788 /* If we are a target we won't immediately transition into PRLI,
1789 * so if REG_LOGIN already completed we don't need to ignore it.
1791 if (!(ndlp->nlp_flag & NLP_RPI_REGISTERED) ||
1792 !vport->phba->nvmet_support)
1793 ndlp->nlp_flag |= NLP_IGNR_REG_CMPL;
1795 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
1796 spin_unlock_irq(shost->host_lock);
1797 lpfc_disc_set_adisc(vport, ndlp);
1798 return ndlp->nlp_state;
1802 lpfc_rcv_plogi_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1803 void *arg, uint32_t evt)
1805 struct lpfc_iocbq *cmdiocb;
1807 cmdiocb = (struct lpfc_iocbq *) arg;
1809 lpfc_rcv_plogi(vport, ndlp, cmdiocb);
1810 return ndlp->nlp_state;
1814 lpfc_rcv_prli_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1815 void *arg, uint32_t evt)
1817 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1819 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
1820 return ndlp->nlp_state;
1824 lpfc_rcv_logo_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1825 void *arg, uint32_t evt)
1827 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1829 /* Software abort outstanding PRLI before sending acc */
1830 lpfc_els_abort(vport->phba, ndlp);
1832 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
1833 return ndlp->nlp_state;
1837 lpfc_rcv_padisc_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1838 void *arg, uint32_t evt)
1840 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1842 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
1843 return ndlp->nlp_state;
1846 /* This routine is envoked when we rcv a PRLO request from a nport
1847 * we are logged into. We should send back a PRLO rsp setting the
1849 * NEXT STATE = PRLI_ISSUE
1852 lpfc_rcv_prlo_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1853 void *arg, uint32_t evt)
1855 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1857 lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL);
1858 return ndlp->nlp_state;
1862 lpfc_cmpl_prli_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1863 void *arg, uint32_t evt)
1865 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1866 struct lpfc_iocbq *cmdiocb, *rspiocb;
1867 struct lpfc_hba *phba = vport->phba;
1870 struct lpfc_nvme_prli *nvpr;
1873 cmdiocb = (struct lpfc_iocbq *) arg;
1874 rspiocb = cmdiocb->context_un.rsp_iocb;
1876 /* A solicited PRLI is either FCP or NVME. The PRLI cmd/rsp
1877 * format is different so NULL the two PRLI types so that the
1878 * driver correctly gets the correct context.
1882 temp_ptr = lpfc_check_elscmpl_iocb(phba, cmdiocb, rspiocb);
1883 if (cmdiocb->iocb_flag & LPFC_PRLI_FCP_REQ)
1884 npr = (PRLI *) temp_ptr;
1885 else if (cmdiocb->iocb_flag & LPFC_PRLI_NVME_REQ)
1886 nvpr = (struct lpfc_nvme_prli *) temp_ptr;
1888 irsp = &rspiocb->iocb;
1889 if (irsp->ulpStatus) {
1890 if ((vport->port_type == LPFC_NPIV_PORT) &&
1891 vport->cfg_restrict_login) {
1895 /* The LS Req had some error. Don't let this be a
1898 if ((ndlp->fc4_prli_sent == 1) &&
1899 (ndlp->nlp_state == NLP_STE_PRLI_ISSUE) &&
1900 (ndlp->nlp_type & (NLP_FCP_TARGET | NLP_FCP_INITIATOR)))
1901 /* The FCP PRLI completed successfully but
1902 * the NVME PRLI failed. Since they are sent in
1903 * succession, allow the FCP to complete.
1907 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
1908 ndlp->nlp_type |= NLP_FCP_INITIATOR;
1909 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
1910 return ndlp->nlp_state;
1913 /* Check out PRLI rsp */
1914 ndlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR);
1915 ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
1917 /* NVME or FCP first burst must be negotiated for each PRLI. */
1918 ndlp->nlp_flag &= ~NLP_FIRSTBURST;
1919 ndlp->nvme_fb_size = 0;
1920 if (npr && (npr->acceptRspCode == PRLI_REQ_EXECUTED) &&
1921 (npr->prliType == PRLI_FCP_TYPE)) {
1922 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_DISC,
1923 "6028 FCP NPR PRLI Cmpl Init %d Target %d\n",
1926 if (npr->initiatorFunc)
1927 ndlp->nlp_type |= NLP_FCP_INITIATOR;
1928 if (npr->targetFunc) {
1929 ndlp->nlp_type |= NLP_FCP_TARGET;
1930 if (npr->writeXferRdyDis)
1931 ndlp->nlp_flag |= NLP_FIRSTBURST;
1934 ndlp->nlp_fcp_info |= NLP_FCP_2_DEVICE;
1936 /* PRLI completed. Decrement count. */
1937 ndlp->fc4_prli_sent--;
1939 (bf_get_be32(prli_acc_rsp_code, nvpr) ==
1940 PRLI_REQ_EXECUTED) &&
1941 (bf_get_be32(prli_type_code, nvpr) ==
1944 /* Complete setting up the remote ndlp personality. */
1945 if (bf_get_be32(prli_init, nvpr))
1946 ndlp->nlp_type |= NLP_NVME_INITIATOR;
1948 /* Target driver cannot solicit NVME FB. */
1949 if (bf_get_be32(prli_tgt, nvpr)) {
1950 /* Complete the nvme target roles. The transport
1951 * needs to know if the rport is capable of
1952 * discovery in addition to its role.
1954 ndlp->nlp_type |= NLP_NVME_TARGET;
1955 if (bf_get_be32(prli_disc, nvpr))
1956 ndlp->nlp_type |= NLP_NVME_DISCOVERY;
1957 if ((bf_get_be32(prli_fba, nvpr) == 1) &&
1958 (bf_get_be32(prli_fb_sz, nvpr) > 0) &&
1959 (phba->cfg_nvme_enable_fb) &&
1960 (!phba->nvmet_support)) {
1961 /* Both sides support FB. The target's first
1962 * burst size is a 512 byte encoded value.
1964 ndlp->nlp_flag |= NLP_FIRSTBURST;
1965 ndlp->nvme_fb_size = bf_get_be32(prli_fb_sz,
1970 if (bf_get_be32(prli_recov, nvpr))
1971 ndlp->nlp_fcp_info |= NLP_FCP_2_DEVICE;
1973 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_DISC,
1974 "6029 NVME PRLI Cmpl w1 x%08x "
1975 "w4 x%08x w5 x%08x flag x%x, "
1976 "fcp_info x%x nlp_type x%x\n",
1977 be32_to_cpu(nvpr->word1),
1978 be32_to_cpu(nvpr->word4),
1979 be32_to_cpu(nvpr->word5),
1980 ndlp->nlp_flag, ndlp->nlp_fcp_info,
1982 /* PRLI completed. Decrement count. */
1983 ndlp->fc4_prli_sent--;
1985 if (!(ndlp->nlp_type & NLP_FCP_TARGET) &&
1986 (vport->port_type == LPFC_NPIV_PORT) &&
1987 vport->cfg_restrict_login) {
1989 spin_lock_irq(shost->host_lock);
1990 ndlp->nlp_flag |= NLP_TARGET_REMOVE;
1991 spin_unlock_irq(shost->host_lock);
1992 lpfc_issue_els_logo(vport, ndlp, 0);
1994 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
1995 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1996 return ndlp->nlp_state;
2000 /* The ndlp state cannot move to MAPPED or UNMAPPED before all PRLIs
2003 if (ndlp->fc4_prli_sent == 0) {
2004 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
2005 if (ndlp->nlp_type & (NLP_FCP_TARGET | NLP_NVME_TARGET))
2006 lpfc_nlp_set_state(vport, ndlp, NLP_STE_MAPPED_NODE);
2008 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
2010 lpfc_printf_vlog(vport,
2012 "3067 PRLI's still outstanding "
2013 "on x%06x - count %d, Pend Node Mode "
2015 ndlp->nlp_DID, ndlp->fc4_prli_sent);
2017 return ndlp->nlp_state;
2020 /*! lpfc_device_rm_prli_issue
2031 * This routine is envoked when we a request to remove a nport we are in the
2032 * process of PRLIing. We should software abort outstanding prli, unreg
2033 * login, send a logout. We will change node state to UNUSED_NODE, put it
2034 * on plogi list so it can be freed when LOGO completes.
2039 lpfc_device_rm_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2040 void *arg, uint32_t evt)
2042 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2044 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
2045 spin_lock_irq(shost->host_lock);
2046 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
2047 spin_unlock_irq(shost->host_lock);
2048 return ndlp->nlp_state;
2050 /* software abort outstanding PLOGI */
2051 lpfc_els_abort(vport->phba, ndlp);
2053 lpfc_drop_node(vport, ndlp);
2054 return NLP_STE_FREED_NODE;
2059 /*! lpfc_device_recov_prli_issue
2070 * The routine is envoked when the state of a device is unknown, like
2071 * during a link down. We should remove the nodelist entry from the
2072 * unmapped list, issue a UNREG_LOGIN, do a software abort of the
2073 * outstanding PRLI command, then free the node entry.
2076 lpfc_device_recov_prli_issue(struct lpfc_vport *vport,
2077 struct lpfc_nodelist *ndlp,
2081 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2082 struct lpfc_hba *phba = vport->phba;
2084 /* Don't do anything that will mess up processing of the
2087 if (vport->fc_flag & FC_RSCN_DEFERRED)
2088 return ndlp->nlp_state;
2090 /* software abort outstanding PRLI */
2091 lpfc_els_abort(phba, ndlp);
2093 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
2094 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
2095 spin_lock_irq(shost->host_lock);
2096 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
2097 spin_unlock_irq(shost->host_lock);
2098 lpfc_disc_set_adisc(vport, ndlp);
2099 return ndlp->nlp_state;
2103 lpfc_rcv_plogi_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2104 void *arg, uint32_t evt)
2106 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *)arg;
2109 memset(&stat, 0, sizeof(struct ls_rjt));
2110 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
2111 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
2112 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
2113 return ndlp->nlp_state;
2117 lpfc_rcv_prli_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2118 void *arg, uint32_t evt)
2120 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *)arg;
2123 memset(&stat, 0, sizeof(struct ls_rjt));
2124 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
2125 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
2126 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
2127 return ndlp->nlp_state;
2131 lpfc_rcv_logo_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2132 void *arg, uint32_t evt)
2134 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2135 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *)arg;
2137 spin_lock_irq(shost->host_lock);
2138 ndlp->nlp_flag |= NLP_LOGO_ACC;
2139 spin_unlock_irq(shost->host_lock);
2140 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
2141 return ndlp->nlp_state;
2145 lpfc_rcv_padisc_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2146 void *arg, uint32_t evt)
2148 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *)arg;
2151 memset(&stat, 0, sizeof(struct ls_rjt));
2152 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
2153 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
2154 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
2155 return ndlp->nlp_state;
2159 lpfc_rcv_prlo_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2160 void *arg, uint32_t evt)
2162 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *)arg;
2165 memset(&stat, 0, sizeof(struct ls_rjt));
2166 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
2167 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
2168 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
2169 return ndlp->nlp_state;
2173 lpfc_cmpl_logo_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2174 void *arg, uint32_t evt)
2176 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2178 ndlp->nlp_prev_state = NLP_STE_LOGO_ISSUE;
2179 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
2180 spin_lock_irq(shost->host_lock);
2181 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
2182 spin_unlock_irq(shost->host_lock);
2183 lpfc_disc_set_adisc(vport, ndlp);
2184 return ndlp->nlp_state;
2188 lpfc_device_rm_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2189 void *arg, uint32_t evt)
2192 * Take no action. If a LOGO is outstanding, then possibly DevLoss has
2193 * timed out and is calling for Device Remove. In this case, the LOGO
2194 * must be allowed to complete in state LOGO_ISSUE so that the rpi
2195 * and other NLP flags are correctly cleaned up.
2197 return ndlp->nlp_state;
2201 lpfc_device_recov_logo_issue(struct lpfc_vport *vport,
2202 struct lpfc_nodelist *ndlp,
2203 void *arg, uint32_t evt)
2206 * Device Recovery events have no meaning for a node with a LOGO
2207 * outstanding. The LOGO has to complete first and handle the
2208 * node from that point.
2210 return ndlp->nlp_state;
2214 lpfc_rcv_plogi_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2215 void *arg, uint32_t evt)
2217 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2219 lpfc_rcv_plogi(vport, ndlp, cmdiocb);
2220 return ndlp->nlp_state;
2224 lpfc_rcv_prli_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2225 void *arg, uint32_t evt)
2227 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2229 lpfc_rcv_prli(vport, ndlp, cmdiocb);
2230 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
2231 return ndlp->nlp_state;
2235 lpfc_rcv_logo_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2236 void *arg, uint32_t evt)
2238 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2240 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
2241 return ndlp->nlp_state;
2245 lpfc_rcv_padisc_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2246 void *arg, uint32_t evt)
2248 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2250 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
2251 return ndlp->nlp_state;
2255 lpfc_rcv_prlo_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2256 void *arg, uint32_t evt)
2258 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2260 lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL);
2261 return ndlp->nlp_state;
2265 lpfc_device_recov_unmap_node(struct lpfc_vport *vport,
2266 struct lpfc_nodelist *ndlp,
2270 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2272 ndlp->nlp_prev_state = NLP_STE_UNMAPPED_NODE;
2273 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
2274 spin_lock_irq(shost->host_lock);
2275 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
2276 spin_unlock_irq(shost->host_lock);
2277 lpfc_disc_set_adisc(vport, ndlp);
2279 return ndlp->nlp_state;
2283 lpfc_rcv_plogi_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2284 void *arg, uint32_t evt)
2286 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2288 lpfc_rcv_plogi(vport, ndlp, cmdiocb);
2289 return ndlp->nlp_state;
2293 lpfc_rcv_prli_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2294 void *arg, uint32_t evt)
2296 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2298 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
2299 return ndlp->nlp_state;
2303 lpfc_rcv_logo_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2304 void *arg, uint32_t evt)
2306 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2308 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
2309 return ndlp->nlp_state;
2313 lpfc_rcv_padisc_mapped_node(struct lpfc_vport *vport,
2314 struct lpfc_nodelist *ndlp,
2315 void *arg, uint32_t evt)
2317 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2319 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
2320 return ndlp->nlp_state;
2324 lpfc_rcv_prlo_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2325 void *arg, uint32_t evt)
2327 struct lpfc_hba *phba = vport->phba;
2328 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2330 /* flush the target */
2331 lpfc_sli_abort_iocb(vport, &phba->sli.sli3_ring[LPFC_FCP_RING],
2332 ndlp->nlp_sid, 0, LPFC_CTX_TGT);
2334 /* Treat like rcv logo */
2335 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_PRLO);
2336 return ndlp->nlp_state;
2340 lpfc_device_recov_mapped_node(struct lpfc_vport *vport,
2341 struct lpfc_nodelist *ndlp,
2345 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2347 ndlp->nlp_prev_state = NLP_STE_MAPPED_NODE;
2348 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
2349 spin_lock_irq(shost->host_lock);
2350 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
2351 spin_unlock_irq(shost->host_lock);
2352 lpfc_disc_set_adisc(vport, ndlp);
2353 return ndlp->nlp_state;
2357 lpfc_rcv_plogi_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2358 void *arg, uint32_t evt)
2360 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2361 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2363 /* Ignore PLOGI if we have an outstanding LOGO */
2364 if (ndlp->nlp_flag & (NLP_LOGO_SND | NLP_LOGO_ACC))
2365 return ndlp->nlp_state;
2366 if (lpfc_rcv_plogi(vport, ndlp, cmdiocb)) {
2367 lpfc_cancel_retry_delay_tmo(vport, ndlp);
2368 spin_lock_irq(shost->host_lock);
2369 ndlp->nlp_flag &= ~(NLP_NPR_ADISC | NLP_NPR_2B_DISC);
2370 spin_unlock_irq(shost->host_lock);
2371 } else if (!(ndlp->nlp_flag & NLP_NPR_2B_DISC)) {
2372 /* send PLOGI immediately, move to PLOGI issue state */
2373 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
2374 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
2375 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
2376 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
2379 return ndlp->nlp_state;
2383 lpfc_rcv_prli_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2384 void *arg, uint32_t evt)
2386 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2387 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2390 memset(&stat, 0, sizeof (struct ls_rjt));
2391 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
2392 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
2393 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
2395 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
2396 if (ndlp->nlp_flag & NLP_NPR_ADISC) {
2397 spin_lock_irq(shost->host_lock);
2398 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
2399 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
2400 spin_unlock_irq(shost->host_lock);
2401 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
2402 lpfc_issue_els_adisc(vport, ndlp, 0);
2404 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
2405 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
2406 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
2409 return ndlp->nlp_state;
2413 lpfc_rcv_logo_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2414 void *arg, uint32_t evt)
2416 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2418 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
2419 return ndlp->nlp_state;
2423 lpfc_rcv_padisc_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2424 void *arg, uint32_t evt)
2426 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2428 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
2430 * Do not start discovery if discovery is about to start
2431 * or discovery in progress for this node. Starting discovery
2432 * here will affect the counting of discovery threads.
2434 if (!(ndlp->nlp_flag & NLP_DELAY_TMO) &&
2435 !(ndlp->nlp_flag & NLP_NPR_2B_DISC)) {
2436 if (ndlp->nlp_flag & NLP_NPR_ADISC) {
2437 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
2438 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
2439 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
2440 lpfc_issue_els_adisc(vport, ndlp, 0);
2442 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
2443 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
2444 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
2447 return ndlp->nlp_state;
2451 lpfc_rcv_prlo_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2452 void *arg, uint32_t evt)
2454 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2455 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2457 spin_lock_irq(shost->host_lock);
2458 ndlp->nlp_flag |= NLP_LOGO_ACC;
2459 spin_unlock_irq(shost->host_lock);
2461 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
2463 if ((ndlp->nlp_flag & NLP_DELAY_TMO) == 0) {
2464 mod_timer(&ndlp->nlp_delayfunc,
2465 jiffies + msecs_to_jiffies(1000 * 1));
2466 spin_lock_irq(shost->host_lock);
2467 ndlp->nlp_flag |= NLP_DELAY_TMO;
2468 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
2469 spin_unlock_irq(shost->host_lock);
2470 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
2472 spin_lock_irq(shost->host_lock);
2473 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
2474 spin_unlock_irq(shost->host_lock);
2476 return ndlp->nlp_state;
2480 lpfc_cmpl_plogi_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2481 void *arg, uint32_t evt)
2483 struct lpfc_iocbq *cmdiocb, *rspiocb;
2485 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2487 cmdiocb = (struct lpfc_iocbq *) arg;
2488 rspiocb = cmdiocb->context_un.rsp_iocb;
2490 irsp = &rspiocb->iocb;
2491 if (irsp->ulpStatus) {
2492 spin_lock_irq(shost->host_lock);
2493 ndlp->nlp_flag |= NLP_DEFER_RM;
2494 spin_unlock_irq(shost->host_lock);
2495 return NLP_STE_FREED_NODE;
2497 return ndlp->nlp_state;
2501 lpfc_cmpl_prli_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2502 void *arg, uint32_t evt)
2504 struct lpfc_iocbq *cmdiocb, *rspiocb;
2507 cmdiocb = (struct lpfc_iocbq *) arg;
2508 rspiocb = cmdiocb->context_un.rsp_iocb;
2510 irsp = &rspiocb->iocb;
2511 if (irsp->ulpStatus && (ndlp->nlp_flag & NLP_NODEV_REMOVE)) {
2512 lpfc_drop_node(vport, ndlp);
2513 return NLP_STE_FREED_NODE;
2515 return ndlp->nlp_state;
2519 lpfc_cmpl_logo_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2520 void *arg, uint32_t evt)
2522 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2524 /* For the fabric port just clear the fc flags. */
2525 if (ndlp->nlp_DID == Fabric_DID) {
2526 spin_lock_irq(shost->host_lock);
2527 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
2528 spin_unlock_irq(shost->host_lock);
2530 lpfc_unreg_rpi(vport, ndlp);
2531 return ndlp->nlp_state;
2535 lpfc_cmpl_adisc_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2536 void *arg, uint32_t evt)
2538 struct lpfc_iocbq *cmdiocb, *rspiocb;
2541 cmdiocb = (struct lpfc_iocbq *) arg;
2542 rspiocb = cmdiocb->context_un.rsp_iocb;
2544 irsp = &rspiocb->iocb;
2545 if (irsp->ulpStatus && (ndlp->nlp_flag & NLP_NODEV_REMOVE)) {
2546 lpfc_drop_node(vport, ndlp);
2547 return NLP_STE_FREED_NODE;
2549 return ndlp->nlp_state;
2553 lpfc_cmpl_reglogin_npr_node(struct lpfc_vport *vport,
2554 struct lpfc_nodelist *ndlp,
2555 void *arg, uint32_t evt)
2557 LPFC_MBOXQ_t *pmb = (LPFC_MBOXQ_t *) arg;
2558 MAILBOX_t *mb = &pmb->u.mb;
2560 if (!mb->mbxStatus) {
2561 /* SLI4 ports have preallocated logical rpis. */
2562 if (vport->phba->sli_rev < LPFC_SLI_REV4)
2563 ndlp->nlp_rpi = mb->un.varWords[0];
2564 ndlp->nlp_flag |= NLP_RPI_REGISTERED;
2565 if (ndlp->nlp_flag & NLP_LOGO_ACC) {
2566 lpfc_unreg_rpi(vport, ndlp);
2569 if (ndlp->nlp_flag & NLP_NODEV_REMOVE) {
2570 lpfc_drop_node(vport, ndlp);
2571 return NLP_STE_FREED_NODE;
2574 return ndlp->nlp_state;
2578 lpfc_device_rm_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2579 void *arg, uint32_t evt)
2581 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2583 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
2584 spin_lock_irq(shost->host_lock);
2585 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
2586 spin_unlock_irq(shost->host_lock);
2587 return ndlp->nlp_state;
2589 lpfc_drop_node(vport, ndlp);
2590 return NLP_STE_FREED_NODE;
2594 lpfc_device_recov_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2595 void *arg, uint32_t evt)
2597 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2599 /* Don't do anything that will mess up processing of the
2602 if (vport->fc_flag & FC_RSCN_DEFERRED)
2603 return ndlp->nlp_state;
2605 lpfc_cancel_retry_delay_tmo(vport, ndlp);
2606 spin_lock_irq(shost->host_lock);
2607 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
2608 spin_unlock_irq(shost->host_lock);
2609 return ndlp->nlp_state;
2613 /* This next section defines the NPort Discovery State Machine */
2615 /* There are 4 different double linked lists nodelist entries can reside on.
2616 * The plogi list and adisc list are used when Link Up discovery or RSCN
2617 * processing is needed. Each list holds the nodes that we will send PLOGI
2618 * or ADISC on. These lists will keep track of what nodes will be effected
2619 * by an RSCN, or a Link Up (Typically, all nodes are effected on Link Up).
2620 * The unmapped_list will contain all nodes that we have successfully logged
2621 * into at the Fibre Channel level. The mapped_list will contain all nodes
2622 * that are mapped FCP targets.
2625 * The bind list is a list of undiscovered (potentially non-existent) nodes
2626 * that we have saved binding information on. This information is used when
2627 * nodes transition from the unmapped to the mapped list.
2629 /* For UNUSED_NODE state, the node has just been allocated .
2630 * For PLOGI_ISSUE and REG_LOGIN_ISSUE, the node is on
2631 * the PLOGI list. For REG_LOGIN_COMPL, the node is taken off the PLOGI list
2632 * and put on the unmapped list. For ADISC processing, the node is taken off
2633 * the ADISC list and placed on either the mapped or unmapped list (depending
2634 * on its previous state). Once on the unmapped list, a PRLI is issued and the
2635 * state changed to PRLI_ISSUE. When the PRLI completion occurs, the state is
2636 * changed to UNMAPPED_NODE. If the completion indicates a mapped
2637 * node, the node is taken off the unmapped list. The binding list is checked
2638 * for a valid binding, or a binding is automatically assigned. If binding
2639 * assignment is unsuccessful, the node is left on the unmapped list. If
2640 * binding assignment is successful, the associated binding list entry (if
2641 * any) is removed, and the node is placed on the mapped list.
2644 * For a Link Down, all nodes on the ADISC, PLOGI, unmapped or mapped
2645 * lists will receive a DEVICE_RECOVERY event. If the linkdown or devloss timers
2646 * expire, all effected nodes will receive a DEVICE_RM event.
2649 * For a Link Up or RSCN, all nodes will move from the mapped / unmapped lists
2650 * to either the ADISC or PLOGI list. After a Nameserver query or ALPA loopmap
2651 * check, additional nodes may be added or removed (via DEVICE_RM) to / from
2652 * the PLOGI or ADISC lists. Once the PLOGI and ADISC lists are populated,
2653 * we will first process the ADISC list. 32 entries are processed initially and
2654 * ADISC is initited for each one. Completions / Events for each node are
2655 * funnelled thru the state machine. As each node finishes ADISC processing, it
2656 * starts ADISC for any nodes waiting for ADISC processing. If no nodes are
2657 * waiting, and the ADISC list count is identically 0, then we are done. For
2658 * Link Up discovery, since all nodes on the PLOGI list are UNREG_LOGIN'ed, we
2659 * can issue a CLEAR_LA and reenable Link Events. Next we will process the PLOGI
2660 * list. 32 entries are processed initially and PLOGI is initited for each one.
2661 * Completions / Events for each node are funnelled thru the state machine. As
2662 * each node finishes PLOGI processing, it starts PLOGI for any nodes waiting
2663 * for PLOGI processing. If no nodes are waiting, and the PLOGI list count is
2664 * indentically 0, then we are done. We have now completed discovery / RSCN
2665 * handling. Upon completion, ALL nodes should be on either the mapped or
2669 static uint32_t (*lpfc_disc_action[NLP_STE_MAX_STATE * NLP_EVT_MAX_EVENT])
2670 (struct lpfc_vport *, struct lpfc_nodelist *, void *, uint32_t) = {
2671 /* Action routine Event Current State */
2672 lpfc_rcv_plogi_unused_node, /* RCV_PLOGI UNUSED_NODE */
2673 lpfc_rcv_els_unused_node, /* RCV_PRLI */
2674 lpfc_rcv_logo_unused_node, /* RCV_LOGO */
2675 lpfc_rcv_els_unused_node, /* RCV_ADISC */
2676 lpfc_rcv_els_unused_node, /* RCV_PDISC */
2677 lpfc_rcv_els_unused_node, /* RCV_PRLO */
2678 lpfc_disc_illegal, /* CMPL_PLOGI */
2679 lpfc_disc_illegal, /* CMPL_PRLI */
2680 lpfc_cmpl_logo_unused_node, /* CMPL_LOGO */
2681 lpfc_disc_illegal, /* CMPL_ADISC */
2682 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2683 lpfc_device_rm_unused_node, /* DEVICE_RM */
2684 lpfc_device_recov_unused_node, /* DEVICE_RECOVERY */
2686 lpfc_rcv_plogi_plogi_issue, /* RCV_PLOGI PLOGI_ISSUE */
2687 lpfc_rcv_prli_plogi_issue, /* RCV_PRLI */
2688 lpfc_rcv_logo_plogi_issue, /* RCV_LOGO */
2689 lpfc_rcv_els_plogi_issue, /* RCV_ADISC */
2690 lpfc_rcv_els_plogi_issue, /* RCV_PDISC */
2691 lpfc_rcv_els_plogi_issue, /* RCV_PRLO */
2692 lpfc_cmpl_plogi_plogi_issue, /* CMPL_PLOGI */
2693 lpfc_disc_illegal, /* CMPL_PRLI */
2694 lpfc_cmpl_logo_plogi_issue, /* CMPL_LOGO */
2695 lpfc_disc_illegal, /* CMPL_ADISC */
2696 lpfc_cmpl_reglogin_plogi_issue,/* CMPL_REG_LOGIN */
2697 lpfc_device_rm_plogi_issue, /* DEVICE_RM */
2698 lpfc_device_recov_plogi_issue, /* DEVICE_RECOVERY */
2700 lpfc_rcv_plogi_adisc_issue, /* RCV_PLOGI ADISC_ISSUE */
2701 lpfc_rcv_prli_adisc_issue, /* RCV_PRLI */
2702 lpfc_rcv_logo_adisc_issue, /* RCV_LOGO */
2703 lpfc_rcv_padisc_adisc_issue, /* RCV_ADISC */
2704 lpfc_rcv_padisc_adisc_issue, /* RCV_PDISC */
2705 lpfc_rcv_prlo_adisc_issue, /* RCV_PRLO */
2706 lpfc_disc_illegal, /* CMPL_PLOGI */
2707 lpfc_disc_illegal, /* CMPL_PRLI */
2708 lpfc_disc_illegal, /* CMPL_LOGO */
2709 lpfc_cmpl_adisc_adisc_issue, /* CMPL_ADISC */
2710 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2711 lpfc_device_rm_adisc_issue, /* DEVICE_RM */
2712 lpfc_device_recov_adisc_issue, /* DEVICE_RECOVERY */
2714 lpfc_rcv_plogi_reglogin_issue, /* RCV_PLOGI REG_LOGIN_ISSUE */
2715 lpfc_rcv_prli_reglogin_issue, /* RCV_PLOGI */
2716 lpfc_rcv_logo_reglogin_issue, /* RCV_LOGO */
2717 lpfc_rcv_padisc_reglogin_issue, /* RCV_ADISC */
2718 lpfc_rcv_padisc_reglogin_issue, /* RCV_PDISC */
2719 lpfc_rcv_prlo_reglogin_issue, /* RCV_PRLO */
2720 lpfc_cmpl_plogi_illegal, /* CMPL_PLOGI */
2721 lpfc_disc_illegal, /* CMPL_PRLI */
2722 lpfc_disc_illegal, /* CMPL_LOGO */
2723 lpfc_disc_illegal, /* CMPL_ADISC */
2724 lpfc_cmpl_reglogin_reglogin_issue,/* CMPL_REG_LOGIN */
2725 lpfc_device_rm_reglogin_issue, /* DEVICE_RM */
2726 lpfc_device_recov_reglogin_issue,/* DEVICE_RECOVERY */
2728 lpfc_rcv_plogi_prli_issue, /* RCV_PLOGI PRLI_ISSUE */
2729 lpfc_rcv_prli_prli_issue, /* RCV_PRLI */
2730 lpfc_rcv_logo_prli_issue, /* RCV_LOGO */
2731 lpfc_rcv_padisc_prli_issue, /* RCV_ADISC */
2732 lpfc_rcv_padisc_prli_issue, /* RCV_PDISC */
2733 lpfc_rcv_prlo_prli_issue, /* RCV_PRLO */
2734 lpfc_cmpl_plogi_illegal, /* CMPL_PLOGI */
2735 lpfc_cmpl_prli_prli_issue, /* CMPL_PRLI */
2736 lpfc_disc_illegal, /* CMPL_LOGO */
2737 lpfc_disc_illegal, /* CMPL_ADISC */
2738 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2739 lpfc_device_rm_prli_issue, /* DEVICE_RM */
2740 lpfc_device_recov_prli_issue, /* DEVICE_RECOVERY */
2742 lpfc_rcv_plogi_logo_issue, /* RCV_PLOGI LOGO_ISSUE */
2743 lpfc_rcv_prli_logo_issue, /* RCV_PRLI */
2744 lpfc_rcv_logo_logo_issue, /* RCV_LOGO */
2745 lpfc_rcv_padisc_logo_issue, /* RCV_ADISC */
2746 lpfc_rcv_padisc_logo_issue, /* RCV_PDISC */
2747 lpfc_rcv_prlo_logo_issue, /* RCV_PRLO */
2748 lpfc_cmpl_plogi_illegal, /* CMPL_PLOGI */
2749 lpfc_disc_illegal, /* CMPL_PRLI */
2750 lpfc_cmpl_logo_logo_issue, /* CMPL_LOGO */
2751 lpfc_disc_illegal, /* CMPL_ADISC */
2752 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2753 lpfc_device_rm_logo_issue, /* DEVICE_RM */
2754 lpfc_device_recov_logo_issue, /* DEVICE_RECOVERY */
2756 lpfc_rcv_plogi_unmap_node, /* RCV_PLOGI UNMAPPED_NODE */
2757 lpfc_rcv_prli_unmap_node, /* RCV_PRLI */
2758 lpfc_rcv_logo_unmap_node, /* RCV_LOGO */
2759 lpfc_rcv_padisc_unmap_node, /* RCV_ADISC */
2760 lpfc_rcv_padisc_unmap_node, /* RCV_PDISC */
2761 lpfc_rcv_prlo_unmap_node, /* RCV_PRLO */
2762 lpfc_disc_illegal, /* CMPL_PLOGI */
2763 lpfc_disc_illegal, /* CMPL_PRLI */
2764 lpfc_disc_illegal, /* CMPL_LOGO */
2765 lpfc_disc_illegal, /* CMPL_ADISC */
2766 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2767 lpfc_disc_illegal, /* DEVICE_RM */
2768 lpfc_device_recov_unmap_node, /* DEVICE_RECOVERY */
2770 lpfc_rcv_plogi_mapped_node, /* RCV_PLOGI MAPPED_NODE */
2771 lpfc_rcv_prli_mapped_node, /* RCV_PRLI */
2772 lpfc_rcv_logo_mapped_node, /* RCV_LOGO */
2773 lpfc_rcv_padisc_mapped_node, /* RCV_ADISC */
2774 lpfc_rcv_padisc_mapped_node, /* RCV_PDISC */
2775 lpfc_rcv_prlo_mapped_node, /* RCV_PRLO */
2776 lpfc_disc_illegal, /* CMPL_PLOGI */
2777 lpfc_disc_illegal, /* CMPL_PRLI */
2778 lpfc_disc_illegal, /* CMPL_LOGO */
2779 lpfc_disc_illegal, /* CMPL_ADISC */
2780 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2781 lpfc_disc_illegal, /* DEVICE_RM */
2782 lpfc_device_recov_mapped_node, /* DEVICE_RECOVERY */
2784 lpfc_rcv_plogi_npr_node, /* RCV_PLOGI NPR_NODE */
2785 lpfc_rcv_prli_npr_node, /* RCV_PRLI */
2786 lpfc_rcv_logo_npr_node, /* RCV_LOGO */
2787 lpfc_rcv_padisc_npr_node, /* RCV_ADISC */
2788 lpfc_rcv_padisc_npr_node, /* RCV_PDISC */
2789 lpfc_rcv_prlo_npr_node, /* RCV_PRLO */
2790 lpfc_cmpl_plogi_npr_node, /* CMPL_PLOGI */
2791 lpfc_cmpl_prli_npr_node, /* CMPL_PRLI */
2792 lpfc_cmpl_logo_npr_node, /* CMPL_LOGO */
2793 lpfc_cmpl_adisc_npr_node, /* CMPL_ADISC */
2794 lpfc_cmpl_reglogin_npr_node, /* CMPL_REG_LOGIN */
2795 lpfc_device_rm_npr_node, /* DEVICE_RM */
2796 lpfc_device_recov_npr_node, /* DEVICE_RECOVERY */
2800 lpfc_disc_state_machine(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2801 void *arg, uint32_t evt)
2803 uint32_t cur_state, rc;
2804 uint32_t(*func) (struct lpfc_vport *, struct lpfc_nodelist *, void *,
2806 uint32_t got_ndlp = 0;
2808 if (lpfc_nlp_get(ndlp))
2811 cur_state = ndlp->nlp_state;
2813 /* DSM in event <evt> on NPort <nlp_DID> in state <cur_state> */
2814 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2815 "0211 DSM in event x%x on NPort x%x in "
2816 "state %d Data: x%x\n",
2817 evt, ndlp->nlp_DID, cur_state, ndlp->nlp_flag);
2819 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_DSM,
2820 "DSM in: evt:%d ste:%d did:x%x",
2821 evt, cur_state, ndlp->nlp_DID);
2823 func = lpfc_disc_action[(cur_state * NLP_EVT_MAX_EVENT) + evt];
2824 rc = (func) (vport, ndlp, arg, evt);
2826 /* DSM out state <rc> on NPort <nlp_DID> */
2828 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2829 "0212 DSM out state %d on NPort x%x Data: x%x\n",
2830 rc, ndlp->nlp_DID, ndlp->nlp_flag);
2832 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_DSM,
2833 "DSM out: ste:%d did:x%x flg:x%x",
2834 rc, ndlp->nlp_DID, ndlp->nlp_flag);
2835 /* Decrement the ndlp reference count held for this function */
2838 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2839 "0213 DSM out state %d on NPort free\n", rc);
2841 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_DSM,
2842 "DSM out: ste:%d did:x%x flg:x%x",