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 /* For initiators, lpfc_plogi_confirm_nport skips fabric did.
365 * For target mode, execute implicit logo.
366 * Fabric nodes go into NPR.
368 if (!(ndlp->nlp_type & NLP_FABRIC) &&
369 !(phba->nvmet_support)) {
370 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb,
374 if (nlp_portwwn != 0 &&
375 nlp_portwwn != wwn_to_u64(sp->portName.u.wwn))
376 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
377 "0143 PLOGI recv'd from DID: x%x "
378 "WWPN changed: old %llx new %llx\n",
380 (unsigned long long)nlp_portwwn,
382 wwn_to_u64(sp->portName.u.wwn));
384 ndlp->nlp_prev_state = ndlp->nlp_state;
385 /* rport needs to be unregistered first */
386 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
390 /* Check for Nport to NPort pt2pt protocol */
391 if ((vport->fc_flag & FC_PT2PT) &&
392 !(vport->fc_flag & FC_PT2PT_PLOGI)) {
393 /* rcv'ed PLOGI decides what our NPortId will be */
394 vport->fc_myDID = icmd->un.rcvels.parmRo;
396 ed_tov = be32_to_cpu(sp->cmn.e_d_tov);
397 if (sp->cmn.edtovResolution) {
398 /* E_D_TOV ticks are in nanoseconds */
399 ed_tov = (phba->fc_edtov + 999999) / 1000000;
403 * For pt-to-pt, use the larger EDTOV
406 if (ed_tov > phba->fc_edtov)
407 phba->fc_edtov = ed_tov;
408 phba->fc_ratov = (2 * phba->fc_edtov) / 1000;
410 memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
412 /* Issue config_link / reg_vfi to account for updated TOV's */
414 if (phba->sli_rev == LPFC_SLI_REV4)
415 lpfc_issue_reg_vfi(vport);
417 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
420 lpfc_config_link(phba, mbox);
421 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
423 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
424 if (rc == MBX_NOT_FINISHED) {
425 mempool_free(mbox, phba->mbox_mem_pool);
430 lpfc_can_disctmo(vport);
433 ndlp->nlp_flag &= ~NLP_SUPPRESS_RSP;
434 if ((phba->sli.sli_flag & LPFC_SLI_SUPPRESS_RSP) &&
435 sp->cmn.valid_vendor_ver_level) {
436 vid = be32_to_cpu(sp->un.vv.vid);
437 flag = be32_to_cpu(sp->un.vv.flags);
438 if ((vid == LPFC_VV_EMLX_ID) && (flag & LPFC_VV_SUPPRESS_RSP))
439 ndlp->nlp_flag |= NLP_SUPPRESS_RSP;
442 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
446 /* Registering an existing RPI behaves differently for SLI3 vs SLI4 */
447 if (phba->sli_rev == LPFC_SLI_REV4)
448 lpfc_unreg_rpi(vport, ndlp);
450 rc = lpfc_reg_rpi(phba, vport->vpi, icmd->un.rcvels.remoteID,
451 (uint8_t *) sp, mbox, ndlp->nlp_rpi);
453 mempool_free(mbox, phba->mbox_mem_pool);
457 /* ACC PLOGI rsp command needs to execute first,
458 * queue this mbox command to be processed later.
460 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
462 * mbox->context2 = lpfc_nlp_get(ndlp) deferred until mailbox
463 * command issued in lpfc_cmpl_els_acc().
466 spin_lock_irq(shost->host_lock);
467 ndlp->nlp_flag |= (NLP_ACC_REGLOGIN | NLP_RCV_PLOGI);
468 spin_unlock_irq(shost->host_lock);
471 * If there is an outstanding PLOGI issued, abort it before
472 * sending ACC rsp for received PLOGI. If pending plogi
473 * is not canceled here, the plogi will be rejected by
474 * remote port and will be retried. On a configuration with
475 * single discovery thread, this will cause a huge delay in
476 * discovery. Also this will cause multiple state machines
477 * running in parallel for this node.
479 if (ndlp->nlp_state == NLP_STE_PLOGI_ISSUE) {
480 /* software abort outstanding PLOGI */
481 lpfc_els_abort(phba, ndlp);
484 if ((vport->port_type == LPFC_NPIV_PORT &&
485 vport->cfg_restrict_login)) {
487 /* In order to preserve RPIs, we want to cleanup
488 * the default RPI the firmware created to rcv
489 * this ELS request. The only way to do this is
490 * to register, then unregister the RPI.
492 spin_lock_irq(shost->host_lock);
493 ndlp->nlp_flag |= NLP_RM_DFLT_RPI;
494 spin_unlock_irq(shost->host_lock);
495 stat.un.b.lsRjtRsnCode = LSRJT_INVALID_CMD;
496 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
497 rc = lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb,
500 mempool_free(mbox, phba->mbox_mem_pool);
503 rc = lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp, mbox);
505 mempool_free(mbox, phba->mbox_mem_pool);
508 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
509 stat.un.b.lsRjtRsnCodeExp = LSEXP_OUT_OF_RESOURCE;
510 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
515 * lpfc_mbx_cmpl_resume_rpi - Resume RPI completion routine
516 * @phba: pointer to lpfc hba data structure.
517 * @mboxq: pointer to mailbox object
519 * This routine is invoked to issue a completion to a rcv'ed
520 * ADISC or PDISC after the paused RPI has been resumed.
523 lpfc_mbx_cmpl_resume_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
525 struct lpfc_vport *vport;
526 struct lpfc_iocbq *elsiocb;
527 struct lpfc_nodelist *ndlp;
530 elsiocb = (struct lpfc_iocbq *)mboxq->context1;
531 ndlp = (struct lpfc_nodelist *) mboxq->context2;
532 vport = mboxq->vport;
533 cmd = elsiocb->drvrTimeout;
535 if (cmd == ELS_CMD_ADISC) {
536 lpfc_els_rsp_adisc_acc(vport, elsiocb, ndlp);
538 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, elsiocb,
542 mempool_free(mboxq, phba->mbox_mem_pool);
546 lpfc_rcv_padisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
547 struct lpfc_iocbq *cmdiocb)
549 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
550 struct lpfc_iocbq *elsiocb;
551 struct lpfc_dmabuf *pcmd;
552 struct serv_parm *sp;
553 struct lpfc_name *pnn, *ppn;
560 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
561 lp = (uint32_t *) pcmd->virt;
564 if (cmd == ELS_CMD_ADISC) {
566 pnn = (struct lpfc_name *) & ap->nodeName;
567 ppn = (struct lpfc_name *) & ap->portName;
569 sp = (struct serv_parm *) lp;
570 pnn = (struct lpfc_name *) & sp->nodeName;
571 ppn = (struct lpfc_name *) & sp->portName;
574 icmd = &cmdiocb->iocb;
575 if (icmd->ulpStatus == 0 && lpfc_check_adisc(vport, ndlp, pnn, ppn)) {
578 * As soon as we send ACC, the remote NPort can
579 * start sending us data. Thus, for SLI4 we must
580 * resume the RPI before the ACC goes out.
582 if (vport->phba->sli_rev == LPFC_SLI_REV4) {
583 elsiocb = kmalloc(sizeof(struct lpfc_iocbq),
587 /* Save info from cmd IOCB used in rsp */
588 memcpy((uint8_t *)elsiocb, (uint8_t *)cmdiocb,
589 sizeof(struct lpfc_iocbq));
591 /* Save the ELS cmd */
592 elsiocb->drvrTimeout = cmd;
594 lpfc_sli4_resume_rpi(ndlp,
595 lpfc_mbx_cmpl_resume_rpi, elsiocb);
600 if (cmd == ELS_CMD_ADISC) {
601 lpfc_els_rsp_adisc_acc(vport, cmdiocb, ndlp);
603 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb,
607 /* If we are authenticated, move to the proper state */
608 if (ndlp->nlp_type & NLP_FCP_TARGET)
609 lpfc_nlp_set_state(vport, ndlp, NLP_STE_MAPPED_NODE);
611 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
615 /* Reject this request because invalid parameters */
616 stat.un.b.lsRjtRsvd0 = 0;
617 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
618 stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
619 stat.un.b.vendorUnique = 0;
620 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
623 mod_timer(&ndlp->nlp_delayfunc, jiffies + msecs_to_jiffies(1000));
625 spin_lock_irq(shost->host_lock);
626 ndlp->nlp_flag |= NLP_DELAY_TMO;
627 spin_unlock_irq(shost->host_lock);
628 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
629 ndlp->nlp_prev_state = ndlp->nlp_state;
630 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
635 lpfc_rcv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
636 struct lpfc_iocbq *cmdiocb, uint32_t els_cmd)
638 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
639 struct lpfc_hba *phba = vport->phba;
640 struct lpfc_vport **vports;
641 int i, active_vlink_present = 0 ;
643 /* Put ndlp in NPR state with 1 sec timeout for plogi, ACC logo */
644 /* Only call LOGO ACC for first LOGO, this avoids sending unnecessary
645 * PLOGIs during LOGO storms from a device.
647 spin_lock_irq(shost->host_lock);
648 ndlp->nlp_flag |= NLP_LOGO_ACC;
649 spin_unlock_irq(shost->host_lock);
650 if (els_cmd == ELS_CMD_PRLO)
651 lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL);
653 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
654 if (ndlp->nlp_DID == Fabric_DID) {
655 if (vport->port_state <= LPFC_FDISC)
657 lpfc_linkdown_port(vport);
658 spin_lock_irq(shost->host_lock);
659 vport->fc_flag |= FC_VPORT_LOGO_RCVD;
660 spin_unlock_irq(shost->host_lock);
661 vports = lpfc_create_vport_work_array(phba);
663 for (i = 0; i <= phba->max_vports && vports[i] != NULL;
665 if ((!(vports[i]->fc_flag &
666 FC_VPORT_LOGO_RCVD)) &&
667 (vports[i]->port_state > LPFC_FDISC)) {
668 active_vlink_present = 1;
672 lpfc_destroy_vport_work_array(phba, vports);
676 * Don't re-instantiate if vport is marked for deletion.
677 * If we are here first then vport_delete is going to wait
678 * for discovery to complete.
680 if (!(vport->load_flag & FC_UNLOADING) &&
681 active_vlink_present) {
683 * If there are other active VLinks present,
684 * re-instantiate the Vlink using FDISC.
686 mod_timer(&ndlp->nlp_delayfunc,
687 jiffies + msecs_to_jiffies(1000));
688 spin_lock_irq(shost->host_lock);
689 ndlp->nlp_flag |= NLP_DELAY_TMO;
690 spin_unlock_irq(shost->host_lock);
691 ndlp->nlp_last_elscmd = ELS_CMD_FDISC;
692 vport->port_state = LPFC_FDISC;
694 spin_lock_irq(shost->host_lock);
695 phba->pport->fc_flag &= ~FC_LOGO_RCVD_DID_CHNG;
696 spin_unlock_irq(shost->host_lock);
697 lpfc_retry_pport_discovery(phba);
699 } else if ((!(ndlp->nlp_type & NLP_FABRIC) &&
700 ((ndlp->nlp_type & NLP_FCP_TARGET) ||
701 !(ndlp->nlp_type & NLP_FCP_INITIATOR))) ||
702 (ndlp->nlp_state == NLP_STE_ADISC_ISSUE)) {
703 /* Only try to re-login if this is NOT a Fabric Node */
704 mod_timer(&ndlp->nlp_delayfunc,
705 jiffies + msecs_to_jiffies(1000 * 1));
706 spin_lock_irq(shost->host_lock);
707 ndlp->nlp_flag |= NLP_DELAY_TMO;
708 spin_unlock_irq(shost->host_lock);
710 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
713 ndlp->nlp_prev_state = ndlp->nlp_state;
714 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
716 spin_lock_irq(shost->host_lock);
717 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
718 spin_unlock_irq(shost->host_lock);
719 /* The driver has to wait until the ACC completes before it continues
720 * processing the LOGO. The action will resume in
721 * lpfc_cmpl_els_logo_acc routine. Since part of processing includes an
722 * unreg_login, the driver waits so the ACC does not get aborted.
728 lpfc_rcv_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
729 struct lpfc_iocbq *cmdiocb)
731 struct lpfc_hba *phba = vport->phba;
732 struct lpfc_dmabuf *pcmd;
735 struct fc_rport *rport = ndlp->rport;
738 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
739 lp = (uint32_t *) pcmd->virt;
740 npr = (PRLI *) ((uint8_t *) lp + sizeof (uint32_t));
742 ndlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR);
743 ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
744 ndlp->nlp_flag &= ~NLP_FIRSTBURST;
745 if ((npr->prliType == PRLI_FCP_TYPE) ||
746 (npr->prliType == PRLI_NVME_TYPE)) {
747 if (npr->initiatorFunc) {
748 if (npr->prliType == PRLI_FCP_TYPE)
749 ndlp->nlp_type |= NLP_FCP_INITIATOR;
750 if (npr->prliType == PRLI_NVME_TYPE)
751 ndlp->nlp_type |= NLP_NVME_INITIATOR;
753 if (npr->targetFunc) {
754 if (npr->prliType == PRLI_FCP_TYPE)
755 ndlp->nlp_type |= NLP_FCP_TARGET;
756 if (npr->prliType == PRLI_NVME_TYPE)
757 ndlp->nlp_type |= NLP_NVME_TARGET;
758 if (npr->writeXferRdyDis)
759 ndlp->nlp_flag |= NLP_FIRSTBURST;
762 ndlp->nlp_fcp_info |= NLP_FCP_2_DEVICE;
764 /* If this driver is in nvme target mode, set the ndlp's fc4
765 * type to NVME provided the PRLI response claims NVME FC4
766 * type. Target mode does not issue gft_id so doesn't get
767 * the fc4 type set until now.
769 if ((phba->nvmet_support) && (npr->prliType == PRLI_NVME_TYPE))
770 ndlp->nlp_fc4_type |= NLP_FC4_NVME;
773 /* We need to update the rport role values */
774 roles = FC_RPORT_ROLE_UNKNOWN;
775 if (ndlp->nlp_type & NLP_FCP_INITIATOR)
776 roles |= FC_RPORT_ROLE_FCP_INITIATOR;
777 if (ndlp->nlp_type & NLP_FCP_TARGET)
778 roles |= FC_RPORT_ROLE_FCP_TARGET;
780 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
781 "rport rolechg: role:x%x did:x%x flg:x%x",
782 roles, ndlp->nlp_DID, ndlp->nlp_flag);
784 if (phba->cfg_enable_fc4_type != LPFC_ENABLE_NVME)
785 fc_remote_port_rolechg(rport, roles);
790 lpfc_disc_set_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
792 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
794 if (!(ndlp->nlp_flag & NLP_RPI_REGISTERED)) {
795 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
799 if (!(vport->fc_flag & FC_PT2PT)) {
800 /* Check config parameter use-adisc or FCP-2 */
801 if ((vport->cfg_use_adisc && (vport->fc_flag & FC_RSCN_MODE)) ||
802 ((ndlp->nlp_fcp_info & NLP_FCP_2_DEVICE) &&
803 (ndlp->nlp_type & NLP_FCP_TARGET))) {
804 spin_lock_irq(shost->host_lock);
805 ndlp->nlp_flag |= NLP_NPR_ADISC;
806 spin_unlock_irq(shost->host_lock);
810 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
811 lpfc_unreg_rpi(vport, ndlp);
816 * lpfc_release_rpi - Release a RPI by issuing unreg_login mailbox cmd.
817 * @phba : Pointer to lpfc_hba structure.
818 * @vport: Pointer to lpfc_vport structure.
819 * @rpi : rpi to be release.
821 * This function will send a unreg_login mailbox command to the firmware
825 lpfc_release_rpi(struct lpfc_hba *phba,
826 struct lpfc_vport *vport,
832 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
835 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
836 "2796 mailbox memory allocation failed \n");
838 lpfc_unreg_login(phba, vport->vpi, rpi, pmb);
839 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
840 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
841 if (rc == MBX_NOT_FINISHED)
842 mempool_free(pmb, phba->mbox_mem_pool);
847 lpfc_disc_illegal(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
848 void *arg, uint32_t evt)
850 struct lpfc_hba *phba;
851 LPFC_MBOXQ_t *pmb = (LPFC_MBOXQ_t *) arg;
855 /* Release the RPI if reglogin completing */
856 if (!(phba->pport->load_flag & FC_UNLOADING) &&
857 (evt == NLP_EVT_CMPL_REG_LOGIN) &&
858 (!pmb->u.mb.mbxStatus)) {
859 rpi = pmb->u.mb.un.varWords[0];
860 lpfc_release_rpi(phba, vport, rpi);
862 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
863 "0271 Illegal State Transition: node x%x "
864 "event x%x, state x%x Data: x%x x%x\n",
865 ndlp->nlp_DID, evt, ndlp->nlp_state, ndlp->nlp_rpi,
867 return ndlp->nlp_state;
871 lpfc_cmpl_plogi_illegal(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
872 void *arg, uint32_t evt)
874 /* This transition is only legal if we previously
875 * rcv'ed a PLOGI. Since we don't want 2 discovery threads
876 * working on the same NPortID, do nothing for this thread
879 if (!(ndlp->nlp_flag & NLP_RCV_PLOGI)) {
880 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
881 "0272 Illegal State Transition: node x%x "
882 "event x%x, state x%x Data: x%x x%x\n",
883 ndlp->nlp_DID, evt, ndlp->nlp_state, ndlp->nlp_rpi,
886 return ndlp->nlp_state;
889 /* Start of Discovery State Machine routines */
892 lpfc_rcv_plogi_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
893 void *arg, uint32_t evt)
895 struct lpfc_iocbq *cmdiocb;
897 cmdiocb = (struct lpfc_iocbq *) arg;
899 if (lpfc_rcv_plogi(vport, ndlp, cmdiocb)) {
900 return ndlp->nlp_state;
902 return NLP_STE_FREED_NODE;
906 lpfc_rcv_els_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
907 void *arg, uint32_t evt)
909 lpfc_issue_els_logo(vport, ndlp, 0);
910 return ndlp->nlp_state;
914 lpfc_rcv_logo_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
915 void *arg, uint32_t evt)
917 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
918 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
920 spin_lock_irq(shost->host_lock);
921 ndlp->nlp_flag |= NLP_LOGO_ACC;
922 spin_unlock_irq(shost->host_lock);
923 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
925 return ndlp->nlp_state;
929 lpfc_cmpl_logo_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
930 void *arg, uint32_t evt)
932 return NLP_STE_FREED_NODE;
936 lpfc_device_rm_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
937 void *arg, uint32_t evt)
939 return NLP_STE_FREED_NODE;
943 lpfc_device_recov_unused_node(struct lpfc_vport *vport,
944 struct lpfc_nodelist *ndlp,
945 void *arg, uint32_t evt)
947 return ndlp->nlp_state;
951 lpfc_rcv_plogi_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
952 void *arg, uint32_t evt)
954 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
955 struct lpfc_hba *phba = vport->phba;
956 struct lpfc_iocbq *cmdiocb = arg;
957 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
958 uint32_t *lp = (uint32_t *) pcmd->virt;
959 struct serv_parm *sp = (struct serv_parm *) (lp + 1);
963 memset(&stat, 0, sizeof (struct ls_rjt));
965 /* For a PLOGI, we only accept if our portname is less
966 * than the remote portname.
968 phba->fc_stat.elsLogiCol++;
969 port_cmp = memcmp(&vport->fc_portname, &sp->portName,
970 sizeof(struct lpfc_name));
973 /* Reject this request because the remote node will accept
975 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
976 stat.un.b.lsRjtRsnCodeExp = LSEXP_CMD_IN_PROGRESS;
977 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
980 if (lpfc_rcv_plogi(vport, ndlp, cmdiocb) &&
981 (ndlp->nlp_flag & NLP_NPR_2B_DISC) &&
982 (vport->num_disc_nodes)) {
983 spin_lock_irq(shost->host_lock);
984 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
985 spin_unlock_irq(shost->host_lock);
986 /* Check if there are more PLOGIs to be sent */
987 lpfc_more_plogi(vport);
988 if (vport->num_disc_nodes == 0) {
989 spin_lock_irq(shost->host_lock);
990 vport->fc_flag &= ~FC_NDISC_ACTIVE;
991 spin_unlock_irq(shost->host_lock);
992 lpfc_can_disctmo(vport);
993 lpfc_end_rscn(vport);
996 } /* If our portname was less */
998 return ndlp->nlp_state;
1002 lpfc_rcv_prli_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1003 void *arg, uint32_t evt)
1005 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1008 memset(&stat, 0, sizeof (struct ls_rjt));
1009 stat.un.b.lsRjtRsnCode = LSRJT_LOGICAL_BSY;
1010 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
1011 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
1012 return ndlp->nlp_state;
1016 lpfc_rcv_logo_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1017 void *arg, uint32_t evt)
1019 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1021 /* software abort outstanding PLOGI */
1022 lpfc_els_abort(vport->phba, ndlp);
1024 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
1025 return ndlp->nlp_state;
1029 lpfc_rcv_els_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1030 void *arg, uint32_t evt)
1032 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1033 struct lpfc_hba *phba = vport->phba;
1034 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1036 /* software abort outstanding PLOGI */
1037 lpfc_els_abort(phba, ndlp);
1039 if (evt == NLP_EVT_RCV_LOGO) {
1040 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
1042 lpfc_issue_els_logo(vport, ndlp, 0);
1045 /* Put ndlp in npr state set plogi timer for 1 sec */
1046 mod_timer(&ndlp->nlp_delayfunc, jiffies + msecs_to_jiffies(1000 * 1));
1047 spin_lock_irq(shost->host_lock);
1048 ndlp->nlp_flag |= NLP_DELAY_TMO;
1049 spin_unlock_irq(shost->host_lock);
1050 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
1051 ndlp->nlp_prev_state = NLP_STE_PLOGI_ISSUE;
1052 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1054 return ndlp->nlp_state;
1058 lpfc_cmpl_plogi_plogi_issue(struct lpfc_vport *vport,
1059 struct lpfc_nodelist *ndlp,
1063 struct lpfc_hba *phba = vport->phba;
1064 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1065 struct lpfc_iocbq *cmdiocb, *rspiocb;
1066 struct lpfc_dmabuf *pcmd, *prsp, *mp;
1070 struct serv_parm *sp;
1075 cmdiocb = (struct lpfc_iocbq *) arg;
1076 rspiocb = cmdiocb->context_un.rsp_iocb;
1078 if (ndlp->nlp_flag & NLP_ACC_REGLOGIN) {
1079 /* Recovery from PLOGI collision logic */
1080 return ndlp->nlp_state;
1083 irsp = &rspiocb->iocb;
1085 if (irsp->ulpStatus)
1088 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
1090 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
1094 lp = (uint32_t *) prsp->virt;
1095 sp = (struct serv_parm *) ((uint8_t *) lp + sizeof (uint32_t));
1097 /* Some switches have FDMI servers returning 0 for WWN */
1098 if ((ndlp->nlp_DID != FDMI_DID) &&
1099 (wwn_to_u64(sp->portName.u.wwn) == 0 ||
1100 wwn_to_u64(sp->nodeName.u.wwn) == 0)) {
1101 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1102 "0142 PLOGI RSP: Invalid WWN.\n");
1105 if (!lpfc_check_sparm(vport, ndlp, sp, CLASS3, 0))
1107 /* PLOGI chkparm OK */
1108 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1109 "0121 PLOGI chkparm OK Data: x%x x%x x%x x%x\n",
1110 ndlp->nlp_DID, ndlp->nlp_state,
1111 ndlp->nlp_flag, ndlp->nlp_rpi);
1112 if (vport->cfg_fcp_class == 2 && (sp->cls2.classValid))
1113 ndlp->nlp_fcp_info |= CLASS2;
1115 ndlp->nlp_fcp_info |= CLASS3;
1117 ndlp->nlp_class_sup = 0;
1118 if (sp->cls1.classValid)
1119 ndlp->nlp_class_sup |= FC_COS_CLASS1;
1120 if (sp->cls2.classValid)
1121 ndlp->nlp_class_sup |= FC_COS_CLASS2;
1122 if (sp->cls3.classValid)
1123 ndlp->nlp_class_sup |= FC_COS_CLASS3;
1124 if (sp->cls4.classValid)
1125 ndlp->nlp_class_sup |= FC_COS_CLASS4;
1126 ndlp->nlp_maxframe =
1127 ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) | sp->cmn.bbRcvSizeLsb;
1129 if ((vport->fc_flag & FC_PT2PT) &&
1130 (vport->fc_flag & FC_PT2PT_PLOGI)) {
1131 ed_tov = be32_to_cpu(sp->cmn.e_d_tov);
1132 if (sp->cmn.edtovResolution) {
1133 /* E_D_TOV ticks are in nanoseconds */
1134 ed_tov = (phba->fc_edtov + 999999) / 1000000;
1137 ndlp->nlp_flag &= ~NLP_SUPPRESS_RSP;
1138 if ((phba->sli.sli_flag & LPFC_SLI_SUPPRESS_RSP) &&
1139 sp->cmn.valid_vendor_ver_level) {
1140 vid = be32_to_cpu(sp->un.vv.vid);
1141 flag = be32_to_cpu(sp->un.vv.flags);
1142 if ((vid == LPFC_VV_EMLX_ID) &&
1143 (flag & LPFC_VV_SUPPRESS_RSP))
1144 ndlp->nlp_flag |= NLP_SUPPRESS_RSP;
1148 * Use the larger EDTOV
1149 * RATOV = 2 * EDTOV for pt-to-pt
1151 if (ed_tov > phba->fc_edtov)
1152 phba->fc_edtov = ed_tov;
1153 phba->fc_ratov = (2 * phba->fc_edtov) / 1000;
1155 memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
1157 /* Issue config_link / reg_vfi to account for updated TOV's */
1158 if (phba->sli_rev == LPFC_SLI_REV4) {
1159 lpfc_issue_reg_vfi(vport);
1161 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1163 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1164 "0133 PLOGI: no memory "
1166 "Data: x%x x%x x%x x%x\n",
1167 ndlp->nlp_DID, ndlp->nlp_state,
1168 ndlp->nlp_flag, ndlp->nlp_rpi);
1172 lpfc_config_link(phba, mbox);
1174 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1175 mbox->vport = vport;
1176 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
1177 if (rc == MBX_NOT_FINISHED) {
1178 mempool_free(mbox, phba->mbox_mem_pool);
1184 lpfc_unreg_rpi(vport, ndlp);
1186 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1188 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1189 "0018 PLOGI: no memory for reg_login "
1190 "Data: x%x x%x x%x x%x\n",
1191 ndlp->nlp_DID, ndlp->nlp_state,
1192 ndlp->nlp_flag, ndlp->nlp_rpi);
1196 if (lpfc_reg_rpi(phba, vport->vpi, irsp->un.elsreq64.remoteID,
1197 (uint8_t *) sp, mbox, ndlp->nlp_rpi) == 0) {
1198 switch (ndlp->nlp_DID) {
1199 case NameServer_DID:
1200 mbox->mbox_cmpl = lpfc_mbx_cmpl_ns_reg_login;
1203 mbox->mbox_cmpl = lpfc_mbx_cmpl_fdmi_reg_login;
1206 ndlp->nlp_flag |= NLP_REG_LOGIN_SEND;
1207 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
1209 mbox->context2 = lpfc_nlp_get(ndlp);
1210 mbox->vport = vport;
1211 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
1212 != MBX_NOT_FINISHED) {
1213 lpfc_nlp_set_state(vport, ndlp,
1214 NLP_STE_REG_LOGIN_ISSUE);
1215 return ndlp->nlp_state;
1217 if (ndlp->nlp_flag & NLP_REG_LOGIN_SEND)
1218 ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND;
1219 /* decrement node reference count to the failed mbox
1223 mp = (struct lpfc_dmabuf *) mbox->context1;
1224 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1226 mempool_free(mbox, phba->mbox_mem_pool);
1228 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1229 "0134 PLOGI: cannot issue reg_login "
1230 "Data: x%x x%x x%x x%x\n",
1231 ndlp->nlp_DID, ndlp->nlp_state,
1232 ndlp->nlp_flag, ndlp->nlp_rpi);
1234 mempool_free(mbox, phba->mbox_mem_pool);
1236 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1237 "0135 PLOGI: cannot format reg_login "
1238 "Data: x%x x%x x%x x%x\n",
1239 ndlp->nlp_DID, ndlp->nlp_state,
1240 ndlp->nlp_flag, ndlp->nlp_rpi);
1245 if (ndlp->nlp_DID == NameServer_DID) {
1246 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
1247 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1248 "0261 Cannot Register NameServer login\n");
1252 ** In case the node reference counter does not go to zero, ensure that
1253 ** the stale state for the node is not processed.
1256 ndlp->nlp_prev_state = ndlp->nlp_state;
1257 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1258 spin_lock_irq(shost->host_lock);
1259 ndlp->nlp_flag |= NLP_DEFER_RM;
1260 spin_unlock_irq(shost->host_lock);
1261 return NLP_STE_FREED_NODE;
1265 lpfc_cmpl_logo_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1266 void *arg, uint32_t evt)
1268 return ndlp->nlp_state;
1272 lpfc_cmpl_reglogin_plogi_issue(struct lpfc_vport *vport,
1273 struct lpfc_nodelist *ndlp, void *arg, uint32_t evt)
1275 struct lpfc_hba *phba;
1276 LPFC_MBOXQ_t *pmb = (LPFC_MBOXQ_t *) arg;
1277 MAILBOX_t *mb = &pmb->u.mb;
1281 /* Release the RPI */
1282 if (!(phba->pport->load_flag & FC_UNLOADING) &&
1284 rpi = pmb->u.mb.un.varWords[0];
1285 lpfc_release_rpi(phba, vport, rpi);
1287 return ndlp->nlp_state;
1291 lpfc_device_rm_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1292 void *arg, uint32_t evt)
1294 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1296 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1297 spin_lock_irq(shost->host_lock);
1298 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
1299 spin_unlock_irq(shost->host_lock);
1300 return ndlp->nlp_state;
1302 /* software abort outstanding PLOGI */
1303 lpfc_els_abort(vport->phba, ndlp);
1305 lpfc_drop_node(vport, ndlp);
1306 return NLP_STE_FREED_NODE;
1311 lpfc_device_recov_plogi_issue(struct lpfc_vport *vport,
1312 struct lpfc_nodelist *ndlp,
1316 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1317 struct lpfc_hba *phba = vport->phba;
1319 /* Don't do anything that will mess up processing of the
1322 if (vport->fc_flag & FC_RSCN_DEFERRED)
1323 return ndlp->nlp_state;
1325 /* software abort outstanding PLOGI */
1326 lpfc_els_abort(phba, ndlp);
1328 ndlp->nlp_prev_state = NLP_STE_PLOGI_ISSUE;
1329 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1330 spin_lock_irq(shost->host_lock);
1331 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
1332 spin_unlock_irq(shost->host_lock);
1334 return ndlp->nlp_state;
1338 lpfc_rcv_plogi_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1339 void *arg, uint32_t evt)
1341 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1342 struct lpfc_hba *phba = vport->phba;
1343 struct lpfc_iocbq *cmdiocb;
1345 /* software abort outstanding ADISC */
1346 lpfc_els_abort(phba, ndlp);
1348 cmdiocb = (struct lpfc_iocbq *) arg;
1350 if (lpfc_rcv_plogi(vport, ndlp, cmdiocb)) {
1351 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1352 spin_lock_irq(shost->host_lock);
1353 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
1354 spin_unlock_irq(shost->host_lock);
1355 if (vport->num_disc_nodes)
1356 lpfc_more_adisc(vport);
1358 return ndlp->nlp_state;
1360 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
1361 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
1362 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
1364 return ndlp->nlp_state;
1368 lpfc_rcv_prli_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1369 void *arg, uint32_t evt)
1371 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1373 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
1374 return ndlp->nlp_state;
1378 lpfc_rcv_logo_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1379 void *arg, uint32_t evt)
1381 struct lpfc_hba *phba = vport->phba;
1382 struct lpfc_iocbq *cmdiocb;
1384 cmdiocb = (struct lpfc_iocbq *) arg;
1386 /* software abort outstanding ADISC */
1387 lpfc_els_abort(phba, ndlp);
1389 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
1390 return ndlp->nlp_state;
1394 lpfc_rcv_padisc_adisc_issue(struct lpfc_vport *vport,
1395 struct lpfc_nodelist *ndlp,
1396 void *arg, uint32_t evt)
1398 struct lpfc_iocbq *cmdiocb;
1400 cmdiocb = (struct lpfc_iocbq *) arg;
1402 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
1403 return ndlp->nlp_state;
1407 lpfc_rcv_prlo_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1408 void *arg, uint32_t evt)
1410 struct lpfc_iocbq *cmdiocb;
1412 cmdiocb = (struct lpfc_iocbq *) arg;
1414 /* Treat like rcv logo */
1415 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_PRLO);
1416 return ndlp->nlp_state;
1420 lpfc_cmpl_adisc_adisc_issue(struct lpfc_vport *vport,
1421 struct lpfc_nodelist *ndlp,
1422 void *arg, uint32_t evt)
1424 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1425 struct lpfc_hba *phba = vport->phba;
1426 struct lpfc_iocbq *cmdiocb, *rspiocb;
1431 cmdiocb = (struct lpfc_iocbq *) arg;
1432 rspiocb = cmdiocb->context_un.rsp_iocb;
1434 ap = (ADISC *)lpfc_check_elscmpl_iocb(phba, cmdiocb, rspiocb);
1435 irsp = &rspiocb->iocb;
1437 if ((irsp->ulpStatus) ||
1438 (!lpfc_check_adisc(vport, ndlp, &ap->nodeName, &ap->portName))) {
1440 mod_timer(&ndlp->nlp_delayfunc,
1441 jiffies + msecs_to_jiffies(1000));
1442 spin_lock_irq(shost->host_lock);
1443 ndlp->nlp_flag |= NLP_DELAY_TMO;
1444 spin_unlock_irq(shost->host_lock);
1445 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
1447 memset(&ndlp->nlp_nodename, 0, sizeof(struct lpfc_name));
1448 memset(&ndlp->nlp_portname, 0, sizeof(struct lpfc_name));
1450 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
1451 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1452 lpfc_unreg_rpi(vport, ndlp);
1453 return ndlp->nlp_state;
1456 if (phba->sli_rev == LPFC_SLI_REV4) {
1457 rc = lpfc_sli4_resume_rpi(ndlp, NULL, NULL);
1459 /* Stay in state and retry. */
1460 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
1461 return ndlp->nlp_state;
1465 if (ndlp->nlp_type & NLP_FCP_TARGET) {
1466 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
1467 lpfc_nlp_set_state(vport, ndlp, NLP_STE_MAPPED_NODE);
1469 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
1470 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
1473 return ndlp->nlp_state;
1477 lpfc_device_rm_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1478 void *arg, uint32_t evt)
1480 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1482 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1483 spin_lock_irq(shost->host_lock);
1484 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
1485 spin_unlock_irq(shost->host_lock);
1486 return ndlp->nlp_state;
1488 /* software abort outstanding ADISC */
1489 lpfc_els_abort(vport->phba, ndlp);
1491 lpfc_drop_node(vport, ndlp);
1492 return NLP_STE_FREED_NODE;
1497 lpfc_device_recov_adisc_issue(struct lpfc_vport *vport,
1498 struct lpfc_nodelist *ndlp,
1502 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1503 struct lpfc_hba *phba = vport->phba;
1505 /* Don't do anything that will mess up processing of the
1508 if (vport->fc_flag & FC_RSCN_DEFERRED)
1509 return ndlp->nlp_state;
1511 /* software abort outstanding ADISC */
1512 lpfc_els_abort(phba, ndlp);
1514 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
1515 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1516 spin_lock_irq(shost->host_lock);
1517 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
1518 spin_unlock_irq(shost->host_lock);
1519 lpfc_disc_set_adisc(vport, ndlp);
1520 return ndlp->nlp_state;
1524 lpfc_rcv_plogi_reglogin_issue(struct lpfc_vport *vport,
1525 struct lpfc_nodelist *ndlp,
1529 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1531 lpfc_rcv_plogi(vport, ndlp, cmdiocb);
1532 return ndlp->nlp_state;
1536 lpfc_rcv_prli_reglogin_issue(struct lpfc_vport *vport,
1537 struct lpfc_nodelist *ndlp,
1541 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1544 if (vport->phba->nvmet_support) {
1545 /* NVME Target mode. Handle and respond to the PRLI and
1546 * transition to UNMAPPED provided the RPI has completed
1549 if (ndlp->nlp_flag & NLP_RPI_REGISTERED) {
1550 lpfc_rcv_prli(vport, ndlp, cmdiocb);
1551 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
1552 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
1554 /* RPI registration has not completed. Reject the PRLI
1555 * to prevent an illegal state transition when the
1556 * rpi registration does complete.
1558 lpfc_printf_vlog(vport, KERN_WARNING, LOG_NVME_DISC,
1559 "6115 NVMET ndlp rpi %d state "
1560 "unknown, state x%x flags x%08x\n",
1561 ndlp->nlp_rpi, ndlp->nlp_state,
1563 memset(&stat, 0, sizeof(struct ls_rjt));
1564 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
1565 stat.un.b.lsRjtRsnCodeExp = LSEXP_CMD_IN_PROGRESS;
1566 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb,
1570 /* Initiator mode. */
1571 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
1574 return ndlp->nlp_state;
1578 lpfc_rcv_logo_reglogin_issue(struct lpfc_vport *vport,
1579 struct lpfc_nodelist *ndlp,
1583 struct lpfc_hba *phba = vport->phba;
1584 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1586 LPFC_MBOXQ_t *nextmb;
1587 struct lpfc_dmabuf *mp;
1589 cmdiocb = (struct lpfc_iocbq *) arg;
1591 /* cleanup any ndlp on mbox q waiting for reglogin cmpl */
1592 if ((mb = phba->sli.mbox_active)) {
1593 if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) &&
1594 (ndlp == (struct lpfc_nodelist *) mb->context2)) {
1595 ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND;
1597 mb->context2 = NULL;
1598 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1602 spin_lock_irq(&phba->hbalock);
1603 list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) {
1604 if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) &&
1605 (ndlp == (struct lpfc_nodelist *) mb->context2)) {
1606 mp = (struct lpfc_dmabuf *) (mb->context1);
1608 __lpfc_mbuf_free(phba, mp->virt, mp->phys);
1611 ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND;
1613 list_del(&mb->list);
1614 phba->sli.mboxq_cnt--;
1615 mempool_free(mb, phba->mbox_mem_pool);
1618 spin_unlock_irq(&phba->hbalock);
1620 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
1621 return ndlp->nlp_state;
1625 lpfc_rcv_padisc_reglogin_issue(struct lpfc_vport *vport,
1626 struct lpfc_nodelist *ndlp,
1630 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1632 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
1633 return ndlp->nlp_state;
1637 lpfc_rcv_prlo_reglogin_issue(struct lpfc_vport *vport,
1638 struct lpfc_nodelist *ndlp,
1642 struct lpfc_iocbq *cmdiocb;
1644 cmdiocb = (struct lpfc_iocbq *) arg;
1645 lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL);
1646 return ndlp->nlp_state;
1650 lpfc_cmpl_reglogin_reglogin_issue(struct lpfc_vport *vport,
1651 struct lpfc_nodelist *ndlp,
1655 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1656 struct lpfc_hba *phba = vport->phba;
1657 LPFC_MBOXQ_t *pmb = (LPFC_MBOXQ_t *) arg;
1658 MAILBOX_t *mb = &pmb->u.mb;
1659 uint32_t did = mb->un.varWords[1];
1662 if (mb->mbxStatus) {
1663 /* RegLogin failed */
1664 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
1665 "0246 RegLogin failed Data: x%x x%x x%x x%x "
1667 did, mb->mbxStatus, vport->port_state,
1668 mb->un.varRegLogin.vpi,
1669 mb->un.varRegLogin.rpi);
1671 * If RegLogin failed due to lack of HBA resources do not
1674 if (mb->mbxStatus == MBXERR_RPI_FULL) {
1675 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
1676 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1677 return ndlp->nlp_state;
1680 /* Put ndlp in npr state set plogi timer for 1 sec */
1681 mod_timer(&ndlp->nlp_delayfunc,
1682 jiffies + msecs_to_jiffies(1000 * 1));
1683 spin_lock_irq(shost->host_lock);
1684 ndlp->nlp_flag |= NLP_DELAY_TMO;
1685 spin_unlock_irq(shost->host_lock);
1686 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
1688 lpfc_issue_els_logo(vport, ndlp, 0);
1689 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
1690 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1691 return ndlp->nlp_state;
1694 /* SLI4 ports have preallocated logical rpis. */
1695 if (phba->sli_rev < LPFC_SLI_REV4)
1696 ndlp->nlp_rpi = mb->un.varWords[0];
1698 ndlp->nlp_flag |= NLP_RPI_REGISTERED;
1700 /* Only if we are not a fabric nport do we issue PRLI */
1701 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1702 "3066 RegLogin Complete on x%x x%x x%x\n",
1703 did, ndlp->nlp_type, ndlp->nlp_fc4_type);
1704 if (!(ndlp->nlp_type & NLP_FABRIC) &&
1705 (phba->nvmet_support == 0)) {
1706 /* The driver supports FCP and NVME concurrently. If the
1707 * ndlp's nlp_fc4_type is still zero, the driver doesn't
1708 * know what PRLI to send yet. Figure that out now and
1709 * call PRLI depending on the outcome.
1711 if (vport->fc_flag & FC_PT2PT) {
1712 /* If we are pt2pt, there is no Fabric to determine
1713 * the FC4 type of the remote nport. So if NVME
1714 * is configured try it.
1716 ndlp->nlp_fc4_type |= NLP_FC4_FCP;
1717 if ((phba->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
1718 (phba->cfg_enable_fc4_type == LPFC_ENABLE_NVME)) {
1719 ndlp->nlp_fc4_type |= NLP_FC4_NVME;
1720 /* We need to update the localport also */
1721 lpfc_nvme_update_localport(vport);
1724 } else if (ndlp->nlp_fc4_type == 0) {
1725 rc = lpfc_ns_cmd(vport, SLI_CTNS_GFT_ID,
1727 return ndlp->nlp_state;
1730 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
1731 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
1732 lpfc_issue_els_prli(vport, ndlp, 0);
1734 if ((vport->fc_flag & FC_PT2PT) && phba->nvmet_support)
1735 phba->targetport->port_id = vport->fc_myDID;
1737 /* Only Fabric ports should transition. NVME target
1738 * must complete PRLI.
1740 if (ndlp->nlp_type & NLP_FABRIC) {
1741 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
1742 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
1745 return ndlp->nlp_state;
1749 lpfc_device_rm_reglogin_issue(struct lpfc_vport *vport,
1750 struct lpfc_nodelist *ndlp,
1754 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1756 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1757 spin_lock_irq(shost->host_lock);
1758 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
1759 spin_unlock_irq(shost->host_lock);
1760 return ndlp->nlp_state;
1762 lpfc_drop_node(vport, ndlp);
1763 return NLP_STE_FREED_NODE;
1768 lpfc_device_recov_reglogin_issue(struct lpfc_vport *vport,
1769 struct lpfc_nodelist *ndlp,
1773 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1775 /* Don't do anything that will mess up processing of the
1778 if (vport->fc_flag & FC_RSCN_DEFERRED)
1779 return ndlp->nlp_state;
1781 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
1782 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1783 spin_lock_irq(shost->host_lock);
1785 /* If we are a target we won't immediately transition into PRLI,
1786 * so if REG_LOGIN already completed we don't need to ignore it.
1788 if (!(ndlp->nlp_flag & NLP_RPI_REGISTERED) ||
1789 !vport->phba->nvmet_support)
1790 ndlp->nlp_flag |= NLP_IGNR_REG_CMPL;
1792 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
1793 spin_unlock_irq(shost->host_lock);
1794 lpfc_disc_set_adisc(vport, ndlp);
1795 return ndlp->nlp_state;
1799 lpfc_rcv_plogi_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1800 void *arg, uint32_t evt)
1802 struct lpfc_iocbq *cmdiocb;
1804 cmdiocb = (struct lpfc_iocbq *) arg;
1806 lpfc_rcv_plogi(vport, ndlp, cmdiocb);
1807 return ndlp->nlp_state;
1811 lpfc_rcv_prli_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1812 void *arg, uint32_t evt)
1814 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1816 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
1817 return ndlp->nlp_state;
1821 lpfc_rcv_logo_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1822 void *arg, uint32_t evt)
1824 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1826 /* Software abort outstanding PRLI before sending acc */
1827 lpfc_els_abort(vport->phba, ndlp);
1829 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
1830 return ndlp->nlp_state;
1834 lpfc_rcv_padisc_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1835 void *arg, uint32_t evt)
1837 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1839 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
1840 return ndlp->nlp_state;
1843 /* This routine is envoked when we rcv a PRLO request from a nport
1844 * we are logged into. We should send back a PRLO rsp setting the
1846 * NEXT STATE = PRLI_ISSUE
1849 lpfc_rcv_prlo_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1850 void *arg, uint32_t evt)
1852 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1854 lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL);
1855 return ndlp->nlp_state;
1859 lpfc_cmpl_prli_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1860 void *arg, uint32_t evt)
1862 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1863 struct lpfc_iocbq *cmdiocb, *rspiocb;
1864 struct lpfc_hba *phba = vport->phba;
1867 struct lpfc_nvme_prli *nvpr;
1870 cmdiocb = (struct lpfc_iocbq *) arg;
1871 rspiocb = cmdiocb->context_un.rsp_iocb;
1873 /* A solicited PRLI is either FCP or NVME. The PRLI cmd/rsp
1874 * format is different so NULL the two PRLI types so that the
1875 * driver correctly gets the correct context.
1879 temp_ptr = lpfc_check_elscmpl_iocb(phba, cmdiocb, rspiocb);
1880 if (cmdiocb->iocb_flag & LPFC_PRLI_FCP_REQ)
1881 npr = (PRLI *) temp_ptr;
1882 else if (cmdiocb->iocb_flag & LPFC_PRLI_NVME_REQ)
1883 nvpr = (struct lpfc_nvme_prli *) temp_ptr;
1885 irsp = &rspiocb->iocb;
1886 if (irsp->ulpStatus) {
1887 if ((vport->port_type == LPFC_NPIV_PORT) &&
1888 vport->cfg_restrict_login) {
1892 /* The LS Req had some error. Don't let this be a
1895 if ((ndlp->fc4_prli_sent == 1) &&
1896 (ndlp->nlp_state == NLP_STE_PRLI_ISSUE) &&
1897 (ndlp->nlp_type & (NLP_FCP_TARGET | NLP_FCP_INITIATOR)))
1898 /* The FCP PRLI completed successfully but
1899 * the NVME PRLI failed. Since they are sent in
1900 * succession, allow the FCP to complete.
1904 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
1905 ndlp->nlp_type |= NLP_FCP_INITIATOR;
1906 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
1907 return ndlp->nlp_state;
1910 /* Check out PRLI rsp */
1911 ndlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR);
1912 ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
1914 /* NVME or FCP first burst must be negotiated for each PRLI. */
1915 ndlp->nlp_flag &= ~NLP_FIRSTBURST;
1916 ndlp->nvme_fb_size = 0;
1917 if (npr && (npr->acceptRspCode == PRLI_REQ_EXECUTED) &&
1918 (npr->prliType == PRLI_FCP_TYPE)) {
1919 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_DISC,
1920 "6028 FCP NPR PRLI Cmpl Init %d Target %d\n",
1923 if (npr->initiatorFunc)
1924 ndlp->nlp_type |= NLP_FCP_INITIATOR;
1925 if (npr->targetFunc) {
1926 ndlp->nlp_type |= NLP_FCP_TARGET;
1927 if (npr->writeXferRdyDis)
1928 ndlp->nlp_flag |= NLP_FIRSTBURST;
1931 ndlp->nlp_fcp_info |= NLP_FCP_2_DEVICE;
1933 /* PRLI completed. Decrement count. */
1934 ndlp->fc4_prli_sent--;
1936 (bf_get_be32(prli_acc_rsp_code, nvpr) ==
1937 PRLI_REQ_EXECUTED) &&
1938 (bf_get_be32(prli_type_code, nvpr) ==
1941 /* Complete setting up the remote ndlp personality. */
1942 if (bf_get_be32(prli_init, nvpr))
1943 ndlp->nlp_type |= NLP_NVME_INITIATOR;
1945 /* Target driver cannot solicit NVME FB. */
1946 if (bf_get_be32(prli_tgt, nvpr)) {
1947 /* Complete the nvme target roles. The transport
1948 * needs to know if the rport is capable of
1949 * discovery in addition to its role.
1951 ndlp->nlp_type |= NLP_NVME_TARGET;
1952 if (bf_get_be32(prli_disc, nvpr))
1953 ndlp->nlp_type |= NLP_NVME_DISCOVERY;
1954 if ((bf_get_be32(prli_fba, nvpr) == 1) &&
1955 (bf_get_be32(prli_fb_sz, nvpr) > 0) &&
1956 (phba->cfg_nvme_enable_fb) &&
1957 (!phba->nvmet_support)) {
1958 /* Both sides support FB. The target's first
1959 * burst size is a 512 byte encoded value.
1961 ndlp->nlp_flag |= NLP_FIRSTBURST;
1962 ndlp->nvme_fb_size = bf_get_be32(prli_fb_sz,
1967 if (bf_get_be32(prli_recov, nvpr))
1968 ndlp->nlp_fcp_info |= NLP_FCP_2_DEVICE;
1970 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_DISC,
1971 "6029 NVME PRLI Cmpl w1 x%08x "
1972 "w4 x%08x w5 x%08x flag x%x, "
1973 "fcp_info x%x nlp_type x%x\n",
1974 be32_to_cpu(nvpr->word1),
1975 be32_to_cpu(nvpr->word4),
1976 be32_to_cpu(nvpr->word5),
1977 ndlp->nlp_flag, ndlp->nlp_fcp_info,
1979 /* PRLI completed. Decrement count. */
1980 ndlp->fc4_prli_sent--;
1982 if (!(ndlp->nlp_type & NLP_FCP_TARGET) &&
1983 (vport->port_type == LPFC_NPIV_PORT) &&
1984 vport->cfg_restrict_login) {
1986 spin_lock_irq(shost->host_lock);
1987 ndlp->nlp_flag |= NLP_TARGET_REMOVE;
1988 spin_unlock_irq(shost->host_lock);
1989 lpfc_issue_els_logo(vport, ndlp, 0);
1991 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
1992 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1993 return ndlp->nlp_state;
1997 /* The ndlp state cannot move to MAPPED or UNMAPPED before all PRLIs
2000 if (ndlp->fc4_prli_sent == 0) {
2001 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
2002 if (ndlp->nlp_type & (NLP_FCP_TARGET | NLP_NVME_TARGET))
2003 lpfc_nlp_set_state(vport, ndlp, NLP_STE_MAPPED_NODE);
2005 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
2007 lpfc_printf_vlog(vport,
2009 "3067 PRLI's still outstanding "
2010 "on x%06x - count %d, Pend Node Mode "
2012 ndlp->nlp_DID, ndlp->fc4_prli_sent);
2014 return ndlp->nlp_state;
2017 /*! lpfc_device_rm_prli_issue
2028 * This routine is envoked when we a request to remove a nport we are in the
2029 * process of PRLIing. We should software abort outstanding prli, unreg
2030 * login, send a logout. We will change node state to UNUSED_NODE, put it
2031 * on plogi list so it can be freed when LOGO completes.
2036 lpfc_device_rm_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2037 void *arg, uint32_t evt)
2039 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2041 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
2042 spin_lock_irq(shost->host_lock);
2043 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
2044 spin_unlock_irq(shost->host_lock);
2045 return ndlp->nlp_state;
2047 /* software abort outstanding PLOGI */
2048 lpfc_els_abort(vport->phba, ndlp);
2050 lpfc_drop_node(vport, ndlp);
2051 return NLP_STE_FREED_NODE;
2056 /*! lpfc_device_recov_prli_issue
2067 * The routine is envoked when the state of a device is unknown, like
2068 * during a link down. We should remove the nodelist entry from the
2069 * unmapped list, issue a UNREG_LOGIN, do a software abort of the
2070 * outstanding PRLI command, then free the node entry.
2073 lpfc_device_recov_prli_issue(struct lpfc_vport *vport,
2074 struct lpfc_nodelist *ndlp,
2078 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2079 struct lpfc_hba *phba = vport->phba;
2081 /* Don't do anything that will mess up processing of the
2084 if (vport->fc_flag & FC_RSCN_DEFERRED)
2085 return ndlp->nlp_state;
2087 /* software abort outstanding PRLI */
2088 lpfc_els_abort(phba, ndlp);
2090 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
2091 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
2092 spin_lock_irq(shost->host_lock);
2093 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
2094 spin_unlock_irq(shost->host_lock);
2095 lpfc_disc_set_adisc(vport, ndlp);
2096 return ndlp->nlp_state;
2100 lpfc_rcv_plogi_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2101 void *arg, uint32_t evt)
2103 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *)arg;
2106 memset(&stat, 0, sizeof(struct ls_rjt));
2107 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
2108 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
2109 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
2110 return ndlp->nlp_state;
2114 lpfc_rcv_prli_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2115 void *arg, uint32_t evt)
2117 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *)arg;
2120 memset(&stat, 0, sizeof(struct ls_rjt));
2121 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
2122 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
2123 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
2124 return ndlp->nlp_state;
2128 lpfc_rcv_logo_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2129 void *arg, uint32_t evt)
2131 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2132 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *)arg;
2134 spin_lock_irq(shost->host_lock);
2135 ndlp->nlp_flag |= NLP_LOGO_ACC;
2136 spin_unlock_irq(shost->host_lock);
2137 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
2138 return ndlp->nlp_state;
2142 lpfc_rcv_padisc_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2143 void *arg, uint32_t evt)
2145 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *)arg;
2148 memset(&stat, 0, sizeof(struct ls_rjt));
2149 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
2150 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
2151 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
2152 return ndlp->nlp_state;
2156 lpfc_rcv_prlo_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2157 void *arg, uint32_t evt)
2159 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *)arg;
2162 memset(&stat, 0, sizeof(struct ls_rjt));
2163 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
2164 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
2165 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
2166 return ndlp->nlp_state;
2170 lpfc_cmpl_logo_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2171 void *arg, uint32_t evt)
2173 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2175 ndlp->nlp_prev_state = NLP_STE_LOGO_ISSUE;
2176 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
2177 spin_lock_irq(shost->host_lock);
2178 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
2179 spin_unlock_irq(shost->host_lock);
2180 lpfc_disc_set_adisc(vport, ndlp);
2181 return ndlp->nlp_state;
2185 lpfc_device_rm_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2186 void *arg, uint32_t evt)
2189 * Take no action. If a LOGO is outstanding, then possibly DevLoss has
2190 * timed out and is calling for Device Remove. In this case, the LOGO
2191 * must be allowed to complete in state LOGO_ISSUE so that the rpi
2192 * and other NLP flags are correctly cleaned up.
2194 return ndlp->nlp_state;
2198 lpfc_device_recov_logo_issue(struct lpfc_vport *vport,
2199 struct lpfc_nodelist *ndlp,
2200 void *arg, uint32_t evt)
2203 * Device Recovery events have no meaning for a node with a LOGO
2204 * outstanding. The LOGO has to complete first and handle the
2205 * node from that point.
2207 return ndlp->nlp_state;
2211 lpfc_rcv_plogi_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_plogi(vport, ndlp, cmdiocb);
2217 return ndlp->nlp_state;
2221 lpfc_rcv_prli_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2222 void *arg, uint32_t evt)
2224 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2226 lpfc_rcv_prli(vport, ndlp, cmdiocb);
2227 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
2228 return ndlp->nlp_state;
2232 lpfc_rcv_logo_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_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
2238 return ndlp->nlp_state;
2242 lpfc_rcv_padisc_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_rcv_padisc(vport, ndlp, cmdiocb);
2248 return ndlp->nlp_state;
2252 lpfc_rcv_prlo_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2253 void *arg, uint32_t evt)
2255 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2257 lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL);
2258 return ndlp->nlp_state;
2262 lpfc_device_recov_unmap_node(struct lpfc_vport *vport,
2263 struct lpfc_nodelist *ndlp,
2267 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2269 ndlp->nlp_prev_state = NLP_STE_UNMAPPED_NODE;
2270 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
2271 spin_lock_irq(shost->host_lock);
2272 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
2273 spin_unlock_irq(shost->host_lock);
2274 lpfc_disc_set_adisc(vport, ndlp);
2276 return ndlp->nlp_state;
2280 lpfc_rcv_plogi_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_rcv_plogi(vport, ndlp, cmdiocb);
2286 return ndlp->nlp_state;
2290 lpfc_rcv_prli_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_els_rsp_prli_acc(vport, cmdiocb, ndlp);
2296 return ndlp->nlp_state;
2300 lpfc_rcv_logo_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2301 void *arg, uint32_t evt)
2303 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2305 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
2306 return ndlp->nlp_state;
2310 lpfc_rcv_padisc_mapped_node(struct lpfc_vport *vport,
2311 struct lpfc_nodelist *ndlp,
2312 void *arg, uint32_t evt)
2314 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2316 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
2317 return ndlp->nlp_state;
2321 lpfc_rcv_prlo_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2322 void *arg, uint32_t evt)
2324 struct lpfc_hba *phba = vport->phba;
2325 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2327 /* flush the target */
2328 lpfc_sli_abort_iocb(vport, &phba->sli.sli3_ring[LPFC_FCP_RING],
2329 ndlp->nlp_sid, 0, LPFC_CTX_TGT);
2331 /* Treat like rcv logo */
2332 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_PRLO);
2333 return ndlp->nlp_state;
2337 lpfc_device_recov_mapped_node(struct lpfc_vport *vport,
2338 struct lpfc_nodelist *ndlp,
2342 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2344 ndlp->nlp_prev_state = NLP_STE_MAPPED_NODE;
2345 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
2346 spin_lock_irq(shost->host_lock);
2347 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
2348 spin_unlock_irq(shost->host_lock);
2349 lpfc_disc_set_adisc(vport, ndlp);
2350 return ndlp->nlp_state;
2354 lpfc_rcv_plogi_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2355 void *arg, uint32_t evt)
2357 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2358 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2360 /* Ignore PLOGI if we have an outstanding LOGO */
2361 if (ndlp->nlp_flag & (NLP_LOGO_SND | NLP_LOGO_ACC))
2362 return ndlp->nlp_state;
2363 if (lpfc_rcv_plogi(vport, ndlp, cmdiocb)) {
2364 lpfc_cancel_retry_delay_tmo(vport, ndlp);
2365 spin_lock_irq(shost->host_lock);
2366 ndlp->nlp_flag &= ~(NLP_NPR_ADISC | NLP_NPR_2B_DISC);
2367 spin_unlock_irq(shost->host_lock);
2368 } else if (!(ndlp->nlp_flag & NLP_NPR_2B_DISC)) {
2369 /* send PLOGI immediately, move to PLOGI issue state */
2370 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
2371 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
2372 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
2373 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
2376 return ndlp->nlp_state;
2380 lpfc_rcv_prli_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2381 void *arg, uint32_t evt)
2383 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2384 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2387 memset(&stat, 0, sizeof (struct ls_rjt));
2388 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
2389 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
2390 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
2392 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
2393 if (ndlp->nlp_flag & NLP_NPR_ADISC) {
2394 spin_lock_irq(shost->host_lock);
2395 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
2396 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
2397 spin_unlock_irq(shost->host_lock);
2398 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
2399 lpfc_issue_els_adisc(vport, ndlp, 0);
2401 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
2402 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
2403 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
2406 return ndlp->nlp_state;
2410 lpfc_rcv_logo_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_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
2416 return ndlp->nlp_state;
2420 lpfc_rcv_padisc_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2421 void *arg, uint32_t evt)
2423 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2425 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
2427 * Do not start discovery if discovery is about to start
2428 * or discovery in progress for this node. Starting discovery
2429 * here will affect the counting of discovery threads.
2431 if (!(ndlp->nlp_flag & NLP_DELAY_TMO) &&
2432 !(ndlp->nlp_flag & NLP_NPR_2B_DISC)) {
2433 if (ndlp->nlp_flag & NLP_NPR_ADISC) {
2434 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
2435 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
2436 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
2437 lpfc_issue_els_adisc(vport, ndlp, 0);
2439 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
2440 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
2441 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
2444 return ndlp->nlp_state;
2448 lpfc_rcv_prlo_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2449 void *arg, uint32_t evt)
2451 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2452 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2454 spin_lock_irq(shost->host_lock);
2455 ndlp->nlp_flag |= NLP_LOGO_ACC;
2456 spin_unlock_irq(shost->host_lock);
2458 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
2460 if ((ndlp->nlp_flag & NLP_DELAY_TMO) == 0) {
2461 mod_timer(&ndlp->nlp_delayfunc,
2462 jiffies + msecs_to_jiffies(1000 * 1));
2463 spin_lock_irq(shost->host_lock);
2464 ndlp->nlp_flag |= NLP_DELAY_TMO;
2465 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
2466 spin_unlock_irq(shost->host_lock);
2467 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
2469 spin_lock_irq(shost->host_lock);
2470 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
2471 spin_unlock_irq(shost->host_lock);
2473 return ndlp->nlp_state;
2477 lpfc_cmpl_plogi_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2478 void *arg, uint32_t evt)
2480 struct lpfc_iocbq *cmdiocb, *rspiocb;
2482 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2484 cmdiocb = (struct lpfc_iocbq *) arg;
2485 rspiocb = cmdiocb->context_un.rsp_iocb;
2487 irsp = &rspiocb->iocb;
2488 if (irsp->ulpStatus) {
2489 spin_lock_irq(shost->host_lock);
2490 ndlp->nlp_flag |= NLP_DEFER_RM;
2491 spin_unlock_irq(shost->host_lock);
2492 return NLP_STE_FREED_NODE;
2494 return ndlp->nlp_state;
2498 lpfc_cmpl_prli_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2499 void *arg, uint32_t evt)
2501 struct lpfc_iocbq *cmdiocb, *rspiocb;
2504 cmdiocb = (struct lpfc_iocbq *) arg;
2505 rspiocb = cmdiocb->context_un.rsp_iocb;
2507 irsp = &rspiocb->iocb;
2508 if (irsp->ulpStatus && (ndlp->nlp_flag & NLP_NODEV_REMOVE)) {
2509 lpfc_drop_node(vport, ndlp);
2510 return NLP_STE_FREED_NODE;
2512 return ndlp->nlp_state;
2516 lpfc_cmpl_logo_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2517 void *arg, uint32_t evt)
2519 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2521 /* For the fabric port just clear the fc flags. */
2522 if (ndlp->nlp_DID == Fabric_DID) {
2523 spin_lock_irq(shost->host_lock);
2524 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
2525 spin_unlock_irq(shost->host_lock);
2527 lpfc_unreg_rpi(vport, ndlp);
2528 return ndlp->nlp_state;
2532 lpfc_cmpl_adisc_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2533 void *arg, uint32_t evt)
2535 struct lpfc_iocbq *cmdiocb, *rspiocb;
2538 cmdiocb = (struct lpfc_iocbq *) arg;
2539 rspiocb = cmdiocb->context_un.rsp_iocb;
2541 irsp = &rspiocb->iocb;
2542 if (irsp->ulpStatus && (ndlp->nlp_flag & NLP_NODEV_REMOVE)) {
2543 lpfc_drop_node(vport, ndlp);
2544 return NLP_STE_FREED_NODE;
2546 return ndlp->nlp_state;
2550 lpfc_cmpl_reglogin_npr_node(struct lpfc_vport *vport,
2551 struct lpfc_nodelist *ndlp,
2552 void *arg, uint32_t evt)
2554 LPFC_MBOXQ_t *pmb = (LPFC_MBOXQ_t *) arg;
2555 MAILBOX_t *mb = &pmb->u.mb;
2557 if (!mb->mbxStatus) {
2558 /* SLI4 ports have preallocated logical rpis. */
2559 if (vport->phba->sli_rev < LPFC_SLI_REV4)
2560 ndlp->nlp_rpi = mb->un.varWords[0];
2561 ndlp->nlp_flag |= NLP_RPI_REGISTERED;
2562 if (ndlp->nlp_flag & NLP_LOGO_ACC) {
2563 lpfc_unreg_rpi(vport, ndlp);
2566 if (ndlp->nlp_flag & NLP_NODEV_REMOVE) {
2567 lpfc_drop_node(vport, ndlp);
2568 return NLP_STE_FREED_NODE;
2571 return ndlp->nlp_state;
2575 lpfc_device_rm_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2576 void *arg, uint32_t evt)
2578 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2580 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
2581 spin_lock_irq(shost->host_lock);
2582 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
2583 spin_unlock_irq(shost->host_lock);
2584 return ndlp->nlp_state;
2586 lpfc_drop_node(vport, ndlp);
2587 return NLP_STE_FREED_NODE;
2591 lpfc_device_recov_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2592 void *arg, uint32_t evt)
2594 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2596 /* Don't do anything that will mess up processing of the
2599 if (vport->fc_flag & FC_RSCN_DEFERRED)
2600 return ndlp->nlp_state;
2602 lpfc_cancel_retry_delay_tmo(vport, ndlp);
2603 spin_lock_irq(shost->host_lock);
2604 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
2605 spin_unlock_irq(shost->host_lock);
2606 return ndlp->nlp_state;
2610 /* This next section defines the NPort Discovery State Machine */
2612 /* There are 4 different double linked lists nodelist entries can reside on.
2613 * The plogi list and adisc list are used when Link Up discovery or RSCN
2614 * processing is needed. Each list holds the nodes that we will send PLOGI
2615 * or ADISC on. These lists will keep track of what nodes will be effected
2616 * by an RSCN, or a Link Up (Typically, all nodes are effected on Link Up).
2617 * The unmapped_list will contain all nodes that we have successfully logged
2618 * into at the Fibre Channel level. The mapped_list will contain all nodes
2619 * that are mapped FCP targets.
2622 * The bind list is a list of undiscovered (potentially non-existent) nodes
2623 * that we have saved binding information on. This information is used when
2624 * nodes transition from the unmapped to the mapped list.
2626 /* For UNUSED_NODE state, the node has just been allocated .
2627 * For PLOGI_ISSUE and REG_LOGIN_ISSUE, the node is on
2628 * the PLOGI list. For REG_LOGIN_COMPL, the node is taken off the PLOGI list
2629 * and put on the unmapped list. For ADISC processing, the node is taken off
2630 * the ADISC list and placed on either the mapped or unmapped list (depending
2631 * on its previous state). Once on the unmapped list, a PRLI is issued and the
2632 * state changed to PRLI_ISSUE. When the PRLI completion occurs, the state is
2633 * changed to UNMAPPED_NODE. If the completion indicates a mapped
2634 * node, the node is taken off the unmapped list. The binding list is checked
2635 * for a valid binding, or a binding is automatically assigned. If binding
2636 * assignment is unsuccessful, the node is left on the unmapped list. If
2637 * binding assignment is successful, the associated binding list entry (if
2638 * any) is removed, and the node is placed on the mapped list.
2641 * For a Link Down, all nodes on the ADISC, PLOGI, unmapped or mapped
2642 * lists will receive a DEVICE_RECOVERY event. If the linkdown or devloss timers
2643 * expire, all effected nodes will receive a DEVICE_RM event.
2646 * For a Link Up or RSCN, all nodes will move from the mapped / unmapped lists
2647 * to either the ADISC or PLOGI list. After a Nameserver query or ALPA loopmap
2648 * check, additional nodes may be added or removed (via DEVICE_RM) to / from
2649 * the PLOGI or ADISC lists. Once the PLOGI and ADISC lists are populated,
2650 * we will first process the ADISC list. 32 entries are processed initially and
2651 * ADISC is initited for each one. Completions / Events for each node are
2652 * funnelled thru the state machine. As each node finishes ADISC processing, it
2653 * starts ADISC for any nodes waiting for ADISC processing. If no nodes are
2654 * waiting, and the ADISC list count is identically 0, then we are done. For
2655 * Link Up discovery, since all nodes on the PLOGI list are UNREG_LOGIN'ed, we
2656 * can issue a CLEAR_LA and reenable Link Events. Next we will process the PLOGI
2657 * list. 32 entries are processed initially and PLOGI is initited for each one.
2658 * Completions / Events for each node are funnelled thru the state machine. As
2659 * each node finishes PLOGI processing, it starts PLOGI for any nodes waiting
2660 * for PLOGI processing. If no nodes are waiting, and the PLOGI list count is
2661 * indentically 0, then we are done. We have now completed discovery / RSCN
2662 * handling. Upon completion, ALL nodes should be on either the mapped or
2666 static uint32_t (*lpfc_disc_action[NLP_STE_MAX_STATE * NLP_EVT_MAX_EVENT])
2667 (struct lpfc_vport *, struct lpfc_nodelist *, void *, uint32_t) = {
2668 /* Action routine Event Current State */
2669 lpfc_rcv_plogi_unused_node, /* RCV_PLOGI UNUSED_NODE */
2670 lpfc_rcv_els_unused_node, /* RCV_PRLI */
2671 lpfc_rcv_logo_unused_node, /* RCV_LOGO */
2672 lpfc_rcv_els_unused_node, /* RCV_ADISC */
2673 lpfc_rcv_els_unused_node, /* RCV_PDISC */
2674 lpfc_rcv_els_unused_node, /* RCV_PRLO */
2675 lpfc_disc_illegal, /* CMPL_PLOGI */
2676 lpfc_disc_illegal, /* CMPL_PRLI */
2677 lpfc_cmpl_logo_unused_node, /* CMPL_LOGO */
2678 lpfc_disc_illegal, /* CMPL_ADISC */
2679 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2680 lpfc_device_rm_unused_node, /* DEVICE_RM */
2681 lpfc_device_recov_unused_node, /* DEVICE_RECOVERY */
2683 lpfc_rcv_plogi_plogi_issue, /* RCV_PLOGI PLOGI_ISSUE */
2684 lpfc_rcv_prli_plogi_issue, /* RCV_PRLI */
2685 lpfc_rcv_logo_plogi_issue, /* RCV_LOGO */
2686 lpfc_rcv_els_plogi_issue, /* RCV_ADISC */
2687 lpfc_rcv_els_plogi_issue, /* RCV_PDISC */
2688 lpfc_rcv_els_plogi_issue, /* RCV_PRLO */
2689 lpfc_cmpl_plogi_plogi_issue, /* CMPL_PLOGI */
2690 lpfc_disc_illegal, /* CMPL_PRLI */
2691 lpfc_cmpl_logo_plogi_issue, /* CMPL_LOGO */
2692 lpfc_disc_illegal, /* CMPL_ADISC */
2693 lpfc_cmpl_reglogin_plogi_issue,/* CMPL_REG_LOGIN */
2694 lpfc_device_rm_plogi_issue, /* DEVICE_RM */
2695 lpfc_device_recov_plogi_issue, /* DEVICE_RECOVERY */
2697 lpfc_rcv_plogi_adisc_issue, /* RCV_PLOGI ADISC_ISSUE */
2698 lpfc_rcv_prli_adisc_issue, /* RCV_PRLI */
2699 lpfc_rcv_logo_adisc_issue, /* RCV_LOGO */
2700 lpfc_rcv_padisc_adisc_issue, /* RCV_ADISC */
2701 lpfc_rcv_padisc_adisc_issue, /* RCV_PDISC */
2702 lpfc_rcv_prlo_adisc_issue, /* RCV_PRLO */
2703 lpfc_disc_illegal, /* CMPL_PLOGI */
2704 lpfc_disc_illegal, /* CMPL_PRLI */
2705 lpfc_disc_illegal, /* CMPL_LOGO */
2706 lpfc_cmpl_adisc_adisc_issue, /* CMPL_ADISC */
2707 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2708 lpfc_device_rm_adisc_issue, /* DEVICE_RM */
2709 lpfc_device_recov_adisc_issue, /* DEVICE_RECOVERY */
2711 lpfc_rcv_plogi_reglogin_issue, /* RCV_PLOGI REG_LOGIN_ISSUE */
2712 lpfc_rcv_prli_reglogin_issue, /* RCV_PLOGI */
2713 lpfc_rcv_logo_reglogin_issue, /* RCV_LOGO */
2714 lpfc_rcv_padisc_reglogin_issue, /* RCV_ADISC */
2715 lpfc_rcv_padisc_reglogin_issue, /* RCV_PDISC */
2716 lpfc_rcv_prlo_reglogin_issue, /* RCV_PRLO */
2717 lpfc_cmpl_plogi_illegal, /* CMPL_PLOGI */
2718 lpfc_disc_illegal, /* CMPL_PRLI */
2719 lpfc_disc_illegal, /* CMPL_LOGO */
2720 lpfc_disc_illegal, /* CMPL_ADISC */
2721 lpfc_cmpl_reglogin_reglogin_issue,/* CMPL_REG_LOGIN */
2722 lpfc_device_rm_reglogin_issue, /* DEVICE_RM */
2723 lpfc_device_recov_reglogin_issue,/* DEVICE_RECOVERY */
2725 lpfc_rcv_plogi_prli_issue, /* RCV_PLOGI PRLI_ISSUE */
2726 lpfc_rcv_prli_prli_issue, /* RCV_PRLI */
2727 lpfc_rcv_logo_prli_issue, /* RCV_LOGO */
2728 lpfc_rcv_padisc_prli_issue, /* RCV_ADISC */
2729 lpfc_rcv_padisc_prli_issue, /* RCV_PDISC */
2730 lpfc_rcv_prlo_prli_issue, /* RCV_PRLO */
2731 lpfc_cmpl_plogi_illegal, /* CMPL_PLOGI */
2732 lpfc_cmpl_prli_prli_issue, /* CMPL_PRLI */
2733 lpfc_disc_illegal, /* CMPL_LOGO */
2734 lpfc_disc_illegal, /* CMPL_ADISC */
2735 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2736 lpfc_device_rm_prli_issue, /* DEVICE_RM */
2737 lpfc_device_recov_prli_issue, /* DEVICE_RECOVERY */
2739 lpfc_rcv_plogi_logo_issue, /* RCV_PLOGI LOGO_ISSUE */
2740 lpfc_rcv_prli_logo_issue, /* RCV_PRLI */
2741 lpfc_rcv_logo_logo_issue, /* RCV_LOGO */
2742 lpfc_rcv_padisc_logo_issue, /* RCV_ADISC */
2743 lpfc_rcv_padisc_logo_issue, /* RCV_PDISC */
2744 lpfc_rcv_prlo_logo_issue, /* RCV_PRLO */
2745 lpfc_cmpl_plogi_illegal, /* CMPL_PLOGI */
2746 lpfc_disc_illegal, /* CMPL_PRLI */
2747 lpfc_cmpl_logo_logo_issue, /* CMPL_LOGO */
2748 lpfc_disc_illegal, /* CMPL_ADISC */
2749 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2750 lpfc_device_rm_logo_issue, /* DEVICE_RM */
2751 lpfc_device_recov_logo_issue, /* DEVICE_RECOVERY */
2753 lpfc_rcv_plogi_unmap_node, /* RCV_PLOGI UNMAPPED_NODE */
2754 lpfc_rcv_prli_unmap_node, /* RCV_PRLI */
2755 lpfc_rcv_logo_unmap_node, /* RCV_LOGO */
2756 lpfc_rcv_padisc_unmap_node, /* RCV_ADISC */
2757 lpfc_rcv_padisc_unmap_node, /* RCV_PDISC */
2758 lpfc_rcv_prlo_unmap_node, /* RCV_PRLO */
2759 lpfc_disc_illegal, /* CMPL_PLOGI */
2760 lpfc_disc_illegal, /* CMPL_PRLI */
2761 lpfc_disc_illegal, /* CMPL_LOGO */
2762 lpfc_disc_illegal, /* CMPL_ADISC */
2763 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2764 lpfc_disc_illegal, /* DEVICE_RM */
2765 lpfc_device_recov_unmap_node, /* DEVICE_RECOVERY */
2767 lpfc_rcv_plogi_mapped_node, /* RCV_PLOGI MAPPED_NODE */
2768 lpfc_rcv_prli_mapped_node, /* RCV_PRLI */
2769 lpfc_rcv_logo_mapped_node, /* RCV_LOGO */
2770 lpfc_rcv_padisc_mapped_node, /* RCV_ADISC */
2771 lpfc_rcv_padisc_mapped_node, /* RCV_PDISC */
2772 lpfc_rcv_prlo_mapped_node, /* RCV_PRLO */
2773 lpfc_disc_illegal, /* CMPL_PLOGI */
2774 lpfc_disc_illegal, /* CMPL_PRLI */
2775 lpfc_disc_illegal, /* CMPL_LOGO */
2776 lpfc_disc_illegal, /* CMPL_ADISC */
2777 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2778 lpfc_disc_illegal, /* DEVICE_RM */
2779 lpfc_device_recov_mapped_node, /* DEVICE_RECOVERY */
2781 lpfc_rcv_plogi_npr_node, /* RCV_PLOGI NPR_NODE */
2782 lpfc_rcv_prli_npr_node, /* RCV_PRLI */
2783 lpfc_rcv_logo_npr_node, /* RCV_LOGO */
2784 lpfc_rcv_padisc_npr_node, /* RCV_ADISC */
2785 lpfc_rcv_padisc_npr_node, /* RCV_PDISC */
2786 lpfc_rcv_prlo_npr_node, /* RCV_PRLO */
2787 lpfc_cmpl_plogi_npr_node, /* CMPL_PLOGI */
2788 lpfc_cmpl_prli_npr_node, /* CMPL_PRLI */
2789 lpfc_cmpl_logo_npr_node, /* CMPL_LOGO */
2790 lpfc_cmpl_adisc_npr_node, /* CMPL_ADISC */
2791 lpfc_cmpl_reglogin_npr_node, /* CMPL_REG_LOGIN */
2792 lpfc_device_rm_npr_node, /* DEVICE_RM */
2793 lpfc_device_recov_npr_node, /* DEVICE_RECOVERY */
2797 lpfc_disc_state_machine(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2798 void *arg, uint32_t evt)
2800 uint32_t cur_state, rc;
2801 uint32_t(*func) (struct lpfc_vport *, struct lpfc_nodelist *, void *,
2803 uint32_t got_ndlp = 0;
2805 if (lpfc_nlp_get(ndlp))
2808 cur_state = ndlp->nlp_state;
2810 /* DSM in event <evt> on NPort <nlp_DID> in state <cur_state> */
2811 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2812 "0211 DSM in event x%x on NPort x%x in "
2813 "state %d Data: x%x\n",
2814 evt, ndlp->nlp_DID, cur_state, ndlp->nlp_flag);
2816 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_DSM,
2817 "DSM in: evt:%d ste:%d did:x%x",
2818 evt, cur_state, ndlp->nlp_DID);
2820 func = lpfc_disc_action[(cur_state * NLP_EVT_MAX_EVENT) + evt];
2821 rc = (func) (vport, ndlp, arg, evt);
2823 /* DSM out state <rc> on NPort <nlp_DID> */
2825 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2826 "0212 DSM out state %d on NPort x%x Data: x%x\n",
2827 rc, ndlp->nlp_DID, ndlp->nlp_flag);
2829 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_DSM,
2830 "DSM out: ste:%d did:x%x flg:x%x",
2831 rc, ndlp->nlp_DID, ndlp->nlp_flag);
2832 /* Decrement the ndlp reference count held for this function */
2835 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2836 "0213 DSM out state %d on NPort free\n", rc);
2838 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_DSM,
2839 "DSM out: ste:%d did:x%x flg:x%x",