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 */
219 if (unlikely(!pring))
222 /* Abort outstanding I/O on NPort <nlp_DID> */
223 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_DISCOVERY,
224 "2819 Abort outstanding I/O on NPort x%x "
225 "Data: x%x x%x x%x\n",
226 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
228 /* Clean up all fabric IOs first.*/
229 lpfc_fabric_abort_nport(ndlp);
232 * Lock the ELS ring txcmplq for SLI3/SLI4 and build a local list
233 * of all ELS IOs that need an ABTS. The IOs need to stay on the
234 * txcmplq so that the abort operation completes them successfully.
236 spin_lock_irq(&phba->hbalock);
237 if (phba->sli_rev == LPFC_SLI_REV4)
238 spin_lock(&pring->ring_lock);
239 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
240 /* Add to abort_list on on NDLP match. */
241 if (lpfc_check_sli_ndlp(phba, pring, iocb, ndlp))
242 list_add_tail(&iocb->dlist, &abort_list);
244 if (phba->sli_rev == LPFC_SLI_REV4)
245 spin_unlock(&pring->ring_lock);
246 spin_unlock_irq(&phba->hbalock);
248 /* Abort the targeted IOs and remove them from the abort list. */
249 list_for_each_entry_safe(iocb, next_iocb, &abort_list, dlist) {
250 spin_lock_irq(&phba->hbalock);
251 list_del_init(&iocb->dlist);
252 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
253 spin_unlock_irq(&phba->hbalock);
256 INIT_LIST_HEAD(&abort_list);
258 /* Now process the txq */
259 spin_lock_irq(&phba->hbalock);
260 if (phba->sli_rev == LPFC_SLI_REV4)
261 spin_lock(&pring->ring_lock);
263 list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
264 /* Check to see if iocb matches the nport we are looking for */
265 if (lpfc_check_sli_ndlp(phba, pring, iocb, ndlp)) {
266 list_del_init(&iocb->list);
267 list_add_tail(&iocb->list, &abort_list);
271 if (phba->sli_rev == LPFC_SLI_REV4)
272 spin_unlock(&pring->ring_lock);
273 spin_unlock_irq(&phba->hbalock);
275 /* Cancel all the IOCBs from the completions list */
276 lpfc_sli_cancel_iocbs(phba, &abort_list,
277 IOSTAT_LOCAL_REJECT, IOERR_SLI_ABORTED);
279 lpfc_cancel_retry_delay_tmo(phba->pport, ndlp);
283 lpfc_rcv_plogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
284 struct lpfc_iocbq *cmdiocb)
286 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
287 struct lpfc_hba *phba = vport->phba;
288 struct lpfc_dmabuf *pcmd;
289 uint64_t nlp_portwwn = 0;
292 struct serv_parm *sp;
299 memset(&stat, 0, sizeof (struct ls_rjt));
300 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
301 lp = (uint32_t *) pcmd->virt;
302 sp = (struct serv_parm *) ((uint8_t *) lp + sizeof (uint32_t));
303 if (wwn_to_u64(sp->portName.u.wwn) == 0) {
304 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
305 "0140 PLOGI Reject: invalid nname\n");
306 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
307 stat.un.b.lsRjtRsnCodeExp = LSEXP_INVALID_PNAME;
308 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
312 if (wwn_to_u64(sp->nodeName.u.wwn) == 0) {
313 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
314 "0141 PLOGI Reject: invalid pname\n");
315 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
316 stat.un.b.lsRjtRsnCodeExp = LSEXP_INVALID_NNAME;
317 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
322 nlp_portwwn = wwn_to_u64(ndlp->nlp_portname.u.wwn);
323 if ((lpfc_check_sparm(vport, ndlp, sp, CLASS3, 0) == 0)) {
324 /* Reject this request because invalid parameters */
325 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
326 stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
327 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
331 icmd = &cmdiocb->iocb;
333 /* PLOGI chkparm OK */
334 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
335 "0114 PLOGI chkparm OK Data: x%x x%x x%x "
337 ndlp->nlp_DID, ndlp->nlp_state, ndlp->nlp_flag,
338 ndlp->nlp_rpi, vport->port_state,
341 if (vport->cfg_fcp_class == 2 && sp->cls2.classValid)
342 ndlp->nlp_fcp_info |= CLASS2;
344 ndlp->nlp_fcp_info |= CLASS3;
346 ndlp->nlp_class_sup = 0;
347 if (sp->cls1.classValid)
348 ndlp->nlp_class_sup |= FC_COS_CLASS1;
349 if (sp->cls2.classValid)
350 ndlp->nlp_class_sup |= FC_COS_CLASS2;
351 if (sp->cls3.classValid)
352 ndlp->nlp_class_sup |= FC_COS_CLASS3;
353 if (sp->cls4.classValid)
354 ndlp->nlp_class_sup |= FC_COS_CLASS4;
356 ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) | sp->cmn.bbRcvSizeLsb;
358 /* if already logged in, do implicit logout */
359 switch (ndlp->nlp_state) {
360 case NLP_STE_NPR_NODE:
361 if (!(ndlp->nlp_flag & NLP_NPR_ADISC))
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 ndlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR);
394 ndlp->nlp_type &= ~(NLP_NVME_TARGET | NLP_NVME_INITIATOR);
395 ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
396 ndlp->nlp_flag &= ~NLP_FIRSTBURST;
398 /* Check for Nport to NPort pt2pt protocol */
399 if ((vport->fc_flag & FC_PT2PT) &&
400 !(vport->fc_flag & FC_PT2PT_PLOGI)) {
401 /* rcv'ed PLOGI decides what our NPortId will be */
402 vport->fc_myDID = icmd->un.rcvels.parmRo;
404 ed_tov = be32_to_cpu(sp->cmn.e_d_tov);
405 if (sp->cmn.edtovResolution) {
406 /* E_D_TOV ticks are in nanoseconds */
407 ed_tov = (phba->fc_edtov + 999999) / 1000000;
411 * For pt-to-pt, use the larger EDTOV
414 if (ed_tov > phba->fc_edtov)
415 phba->fc_edtov = ed_tov;
416 phba->fc_ratov = (2 * phba->fc_edtov) / 1000;
418 memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
420 /* Issue config_link / reg_vfi to account for updated TOV's */
422 if (phba->sli_rev == LPFC_SLI_REV4)
423 lpfc_issue_reg_vfi(vport);
425 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
428 lpfc_config_link(phba, mbox);
429 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
431 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
432 if (rc == MBX_NOT_FINISHED) {
433 mempool_free(mbox, phba->mbox_mem_pool);
438 lpfc_can_disctmo(vport);
441 ndlp->nlp_flag &= ~NLP_SUPPRESS_RSP;
442 if ((phba->sli.sli_flag & LPFC_SLI_SUPPRESS_RSP) &&
443 sp->cmn.valid_vendor_ver_level) {
444 vid = be32_to_cpu(sp->un.vv.vid);
445 flag = be32_to_cpu(sp->un.vv.flags);
446 if ((vid == LPFC_VV_EMLX_ID) && (flag & LPFC_VV_SUPPRESS_RSP))
447 ndlp->nlp_flag |= NLP_SUPPRESS_RSP;
450 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
454 /* Registering an existing RPI behaves differently for SLI3 vs SLI4 */
455 if (phba->sli_rev == LPFC_SLI_REV4)
456 lpfc_unreg_rpi(vport, ndlp);
458 rc = lpfc_reg_rpi(phba, vport->vpi, icmd->un.rcvels.remoteID,
459 (uint8_t *) sp, mbox, ndlp->nlp_rpi);
461 mempool_free(mbox, phba->mbox_mem_pool);
465 /* ACC PLOGI rsp command needs to execute first,
466 * queue this mbox command to be processed later.
468 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
470 * mbox->context2 = lpfc_nlp_get(ndlp) deferred until mailbox
471 * command issued in lpfc_cmpl_els_acc().
474 spin_lock_irq(shost->host_lock);
475 ndlp->nlp_flag |= (NLP_ACC_REGLOGIN | NLP_RCV_PLOGI);
476 spin_unlock_irq(shost->host_lock);
479 * If there is an outstanding PLOGI issued, abort it before
480 * sending ACC rsp for received PLOGI. If pending plogi
481 * is not canceled here, the plogi will be rejected by
482 * remote port and will be retried. On a configuration with
483 * single discovery thread, this will cause a huge delay in
484 * discovery. Also this will cause multiple state machines
485 * running in parallel for this node.
486 * This only applies to a fabric environment.
488 if ((ndlp->nlp_state == NLP_STE_PLOGI_ISSUE) &&
489 (vport->fc_flag & FC_FABRIC)) {
490 /* software abort outstanding PLOGI */
491 lpfc_els_abort(phba, ndlp);
494 if ((vport->port_type == LPFC_NPIV_PORT &&
495 vport->cfg_restrict_login)) {
497 /* In order to preserve RPIs, we want to cleanup
498 * the default RPI the firmware created to rcv
499 * this ELS request. The only way to do this is
500 * to register, then unregister the RPI.
502 spin_lock_irq(shost->host_lock);
503 ndlp->nlp_flag |= NLP_RM_DFLT_RPI;
504 spin_unlock_irq(shost->host_lock);
505 stat.un.b.lsRjtRsnCode = LSRJT_INVALID_CMD;
506 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
507 rc = lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb,
510 mempool_free(mbox, phba->mbox_mem_pool);
513 rc = lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp, mbox);
515 mempool_free(mbox, phba->mbox_mem_pool);
518 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
519 stat.un.b.lsRjtRsnCodeExp = LSEXP_OUT_OF_RESOURCE;
520 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
525 * lpfc_mbx_cmpl_resume_rpi - Resume RPI completion routine
526 * @phba: pointer to lpfc hba data structure.
527 * @mboxq: pointer to mailbox object
529 * This routine is invoked to issue a completion to a rcv'ed
530 * ADISC or PDISC after the paused RPI has been resumed.
533 lpfc_mbx_cmpl_resume_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
535 struct lpfc_vport *vport;
536 struct lpfc_iocbq *elsiocb;
537 struct lpfc_nodelist *ndlp;
540 elsiocb = (struct lpfc_iocbq *)mboxq->context1;
541 ndlp = (struct lpfc_nodelist *) mboxq->context2;
542 vport = mboxq->vport;
543 cmd = elsiocb->drvrTimeout;
545 if (cmd == ELS_CMD_ADISC) {
546 lpfc_els_rsp_adisc_acc(vport, elsiocb, ndlp);
548 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, elsiocb,
552 mempool_free(mboxq, phba->mbox_mem_pool);
556 lpfc_rcv_padisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
557 struct lpfc_iocbq *cmdiocb)
559 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
560 struct lpfc_iocbq *elsiocb;
561 struct lpfc_dmabuf *pcmd;
562 struct serv_parm *sp;
563 struct lpfc_name *pnn, *ppn;
570 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
571 lp = (uint32_t *) pcmd->virt;
574 if (cmd == ELS_CMD_ADISC) {
576 pnn = (struct lpfc_name *) & ap->nodeName;
577 ppn = (struct lpfc_name *) & ap->portName;
579 sp = (struct serv_parm *) lp;
580 pnn = (struct lpfc_name *) & sp->nodeName;
581 ppn = (struct lpfc_name *) & sp->portName;
584 icmd = &cmdiocb->iocb;
585 if (icmd->ulpStatus == 0 && lpfc_check_adisc(vport, ndlp, pnn, ppn)) {
588 * As soon as we send ACC, the remote NPort can
589 * start sending us data. Thus, for SLI4 we must
590 * resume the RPI before the ACC goes out.
592 if (vport->phba->sli_rev == LPFC_SLI_REV4) {
593 elsiocb = kmalloc(sizeof(struct lpfc_iocbq),
597 /* Save info from cmd IOCB used in rsp */
598 memcpy((uint8_t *)elsiocb, (uint8_t *)cmdiocb,
599 sizeof(struct lpfc_iocbq));
601 /* Save the ELS cmd */
602 elsiocb->drvrTimeout = cmd;
604 lpfc_sli4_resume_rpi(ndlp,
605 lpfc_mbx_cmpl_resume_rpi, elsiocb);
610 if (cmd == ELS_CMD_ADISC) {
611 lpfc_els_rsp_adisc_acc(vport, cmdiocb, ndlp);
613 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb,
617 /* If we are authenticated, move to the proper state */
618 if (ndlp->nlp_type & NLP_FCP_TARGET)
619 lpfc_nlp_set_state(vport, ndlp, NLP_STE_MAPPED_NODE);
621 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
625 /* Reject this request because invalid parameters */
626 stat.un.b.lsRjtRsvd0 = 0;
627 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
628 stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
629 stat.un.b.vendorUnique = 0;
630 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
633 mod_timer(&ndlp->nlp_delayfunc, jiffies + msecs_to_jiffies(1000));
635 spin_lock_irq(shost->host_lock);
636 ndlp->nlp_flag |= NLP_DELAY_TMO;
637 spin_unlock_irq(shost->host_lock);
638 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
639 ndlp->nlp_prev_state = ndlp->nlp_state;
640 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
645 lpfc_rcv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
646 struct lpfc_iocbq *cmdiocb, uint32_t els_cmd)
648 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
649 struct lpfc_hba *phba = vport->phba;
650 struct lpfc_vport **vports;
651 int i, active_vlink_present = 0 ;
653 /* Put ndlp in NPR state with 1 sec timeout for plogi, ACC logo */
654 /* Only call LOGO ACC for first LOGO, this avoids sending unnecessary
655 * PLOGIs during LOGO storms from a device.
657 spin_lock_irq(shost->host_lock);
658 ndlp->nlp_flag |= NLP_LOGO_ACC;
659 spin_unlock_irq(shost->host_lock);
660 if (els_cmd == ELS_CMD_PRLO)
661 lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL);
663 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
664 if (ndlp->nlp_DID == Fabric_DID) {
665 if (vport->port_state <= LPFC_FDISC ||
666 vport->fc_flag & FC_PT2PT)
668 lpfc_linkdown_port(vport);
669 spin_lock_irq(shost->host_lock);
670 vport->fc_flag |= FC_VPORT_LOGO_RCVD;
671 spin_unlock_irq(shost->host_lock);
672 vports = lpfc_create_vport_work_array(phba);
674 for (i = 0; i <= phba->max_vports && vports[i] != NULL;
676 if ((!(vports[i]->fc_flag &
677 FC_VPORT_LOGO_RCVD)) &&
678 (vports[i]->port_state > LPFC_FDISC)) {
679 active_vlink_present = 1;
683 lpfc_destroy_vport_work_array(phba, vports);
687 * Don't re-instantiate if vport is marked for deletion.
688 * If we are here first then vport_delete is going to wait
689 * for discovery to complete.
691 if (!(vport->load_flag & FC_UNLOADING) &&
692 active_vlink_present) {
694 * If there are other active VLinks present,
695 * re-instantiate the Vlink using FDISC.
697 mod_timer(&ndlp->nlp_delayfunc,
698 jiffies + msecs_to_jiffies(1000));
699 spin_lock_irq(shost->host_lock);
700 ndlp->nlp_flag |= NLP_DELAY_TMO;
701 spin_unlock_irq(shost->host_lock);
702 ndlp->nlp_last_elscmd = ELS_CMD_FDISC;
703 vport->port_state = LPFC_FDISC;
705 spin_lock_irq(shost->host_lock);
706 phba->pport->fc_flag &= ~FC_LOGO_RCVD_DID_CHNG;
707 spin_unlock_irq(shost->host_lock);
708 lpfc_retry_pport_discovery(phba);
710 } else if ((!(ndlp->nlp_type & NLP_FABRIC) &&
711 ((ndlp->nlp_type & NLP_FCP_TARGET) ||
712 (ndlp->nlp_type & NLP_NVME_TARGET) ||
713 (vport->fc_flag & FC_PT2PT))) ||
714 (ndlp->nlp_state == NLP_STE_ADISC_ISSUE)) {
715 /* Only try to re-login if this is NOT a Fabric Node
716 * AND the remote NPORT is a FCP/NVME Target or we
717 * are in pt2pt mode. NLP_STE_ADISC_ISSUE is a special
718 * case for LOGO as a response to ADISC behavior.
720 mod_timer(&ndlp->nlp_delayfunc,
721 jiffies + msecs_to_jiffies(1000 * 1));
722 spin_lock_irq(shost->host_lock);
723 ndlp->nlp_flag |= NLP_DELAY_TMO;
724 spin_unlock_irq(shost->host_lock);
726 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
729 ndlp->nlp_prev_state = ndlp->nlp_state;
730 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
732 spin_lock_irq(shost->host_lock);
733 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
734 spin_unlock_irq(shost->host_lock);
735 /* The driver has to wait until the ACC completes before it continues
736 * processing the LOGO. The action will resume in
737 * lpfc_cmpl_els_logo_acc routine. Since part of processing includes an
738 * unreg_login, the driver waits so the ACC does not get aborted.
744 lpfc_rcv_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
745 struct lpfc_iocbq *cmdiocb)
747 struct lpfc_hba *phba = vport->phba;
748 struct lpfc_dmabuf *pcmd;
751 struct fc_rport *rport = ndlp->rport;
754 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
755 lp = (uint32_t *) pcmd->virt;
756 npr = (PRLI *) ((uint8_t *) lp + sizeof (uint32_t));
758 if ((npr->prliType == PRLI_FCP_TYPE) ||
759 (npr->prliType == PRLI_NVME_TYPE)) {
760 if (npr->initiatorFunc) {
761 if (npr->prliType == PRLI_FCP_TYPE)
762 ndlp->nlp_type |= NLP_FCP_INITIATOR;
763 if (npr->prliType == PRLI_NVME_TYPE)
764 ndlp->nlp_type |= NLP_NVME_INITIATOR;
766 if (npr->targetFunc) {
767 if (npr->prliType == PRLI_FCP_TYPE)
768 ndlp->nlp_type |= NLP_FCP_TARGET;
769 if (npr->prliType == PRLI_NVME_TYPE)
770 ndlp->nlp_type |= NLP_NVME_TARGET;
771 if (npr->writeXferRdyDis)
772 ndlp->nlp_flag |= NLP_FIRSTBURST;
775 ndlp->nlp_fcp_info |= NLP_FCP_2_DEVICE;
777 /* If this driver is in nvme target mode, set the ndlp's fc4
778 * type to NVME provided the PRLI response claims NVME FC4
779 * type. Target mode does not issue gft_id so doesn't get
780 * the fc4 type set until now.
782 if (phba->nvmet_support && (npr->prliType == PRLI_NVME_TYPE)) {
783 ndlp->nlp_fc4_type |= NLP_FC4_NVME;
784 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
786 if (npr->prliType == PRLI_FCP_TYPE)
787 ndlp->nlp_fc4_type |= NLP_FC4_FCP;
790 /* We need to update the rport role values */
791 roles = FC_RPORT_ROLE_UNKNOWN;
792 if (ndlp->nlp_type & NLP_FCP_INITIATOR)
793 roles |= FC_RPORT_ROLE_FCP_INITIATOR;
794 if (ndlp->nlp_type & NLP_FCP_TARGET)
795 roles |= FC_RPORT_ROLE_FCP_TARGET;
797 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
798 "rport rolechg: role:x%x did:x%x flg:x%x",
799 roles, ndlp->nlp_DID, ndlp->nlp_flag);
801 if (phba->cfg_enable_fc4_type != LPFC_ENABLE_NVME)
802 fc_remote_port_rolechg(rport, roles);
807 lpfc_disc_set_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
809 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
811 if (!(ndlp->nlp_flag & NLP_RPI_REGISTERED)) {
812 spin_lock_irq(shost->host_lock);
813 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
814 spin_unlock_irq(shost->host_lock);
818 if (!(vport->fc_flag & FC_PT2PT)) {
819 /* Check config parameter use-adisc or FCP-2 */
820 if (vport->cfg_use_adisc && ((vport->fc_flag & FC_RSCN_MODE) ||
821 ((ndlp->nlp_fcp_info & NLP_FCP_2_DEVICE) &&
822 (ndlp->nlp_type & NLP_FCP_TARGET)))) {
823 spin_lock_irq(shost->host_lock);
824 ndlp->nlp_flag |= NLP_NPR_ADISC;
825 spin_unlock_irq(shost->host_lock);
830 spin_lock_irq(shost->host_lock);
831 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
832 spin_unlock_irq(shost->host_lock);
833 lpfc_unreg_rpi(vport, ndlp);
838 * lpfc_release_rpi - Release a RPI by issuing unreg_login mailbox cmd.
839 * @phba : Pointer to lpfc_hba structure.
840 * @vport: Pointer to lpfc_vport structure.
841 * @rpi : rpi to be release.
843 * This function will send a unreg_login mailbox command to the firmware
847 lpfc_release_rpi(struct lpfc_hba *phba,
848 struct lpfc_vport *vport,
854 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
857 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
858 "2796 mailbox memory allocation failed \n");
860 lpfc_unreg_login(phba, vport->vpi, rpi, pmb);
861 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
862 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
863 if (rc == MBX_NOT_FINISHED)
864 mempool_free(pmb, phba->mbox_mem_pool);
869 lpfc_disc_illegal(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
870 void *arg, uint32_t evt)
872 struct lpfc_hba *phba;
873 LPFC_MBOXQ_t *pmb = (LPFC_MBOXQ_t *) arg;
877 /* Release the RPI if reglogin completing */
878 if (!(phba->pport->load_flag & FC_UNLOADING) &&
879 (evt == NLP_EVT_CMPL_REG_LOGIN) &&
880 (!pmb->u.mb.mbxStatus)) {
881 rpi = pmb->u.mb.un.varWords[0];
882 lpfc_release_rpi(phba, vport, rpi);
884 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
885 "0271 Illegal State Transition: node x%x "
886 "event x%x, state x%x Data: x%x x%x\n",
887 ndlp->nlp_DID, evt, ndlp->nlp_state, ndlp->nlp_rpi,
889 return ndlp->nlp_state;
893 lpfc_cmpl_plogi_illegal(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
894 void *arg, uint32_t evt)
896 /* This transition is only legal if we previously
897 * rcv'ed a PLOGI. Since we don't want 2 discovery threads
898 * working on the same NPortID, do nothing for this thread
901 if (!(ndlp->nlp_flag & NLP_RCV_PLOGI)) {
902 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
903 "0272 Illegal State Transition: node x%x "
904 "event x%x, state x%x Data: x%x x%x\n",
905 ndlp->nlp_DID, evt, ndlp->nlp_state, ndlp->nlp_rpi,
908 return ndlp->nlp_state;
911 /* Start of Discovery State Machine routines */
914 lpfc_rcv_plogi_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
915 void *arg, uint32_t evt)
917 struct lpfc_iocbq *cmdiocb;
919 cmdiocb = (struct lpfc_iocbq *) arg;
921 if (lpfc_rcv_plogi(vport, ndlp, cmdiocb)) {
922 return ndlp->nlp_state;
924 return NLP_STE_FREED_NODE;
928 lpfc_rcv_els_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
929 void *arg, uint32_t evt)
931 lpfc_issue_els_logo(vport, ndlp, 0);
932 return ndlp->nlp_state;
936 lpfc_rcv_logo_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
937 void *arg, uint32_t evt)
939 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
940 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
942 spin_lock_irq(shost->host_lock);
943 ndlp->nlp_flag |= NLP_LOGO_ACC;
944 spin_unlock_irq(shost->host_lock);
945 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
947 return ndlp->nlp_state;
951 lpfc_cmpl_logo_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
952 void *arg, uint32_t evt)
954 return NLP_STE_FREED_NODE;
958 lpfc_device_rm_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
959 void *arg, uint32_t evt)
961 return NLP_STE_FREED_NODE;
965 lpfc_device_recov_unused_node(struct lpfc_vport *vport,
966 struct lpfc_nodelist *ndlp,
967 void *arg, uint32_t evt)
969 return ndlp->nlp_state;
973 lpfc_rcv_plogi_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
974 void *arg, uint32_t evt)
976 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
977 struct lpfc_hba *phba = vport->phba;
978 struct lpfc_iocbq *cmdiocb = arg;
979 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
980 uint32_t *lp = (uint32_t *) pcmd->virt;
981 struct serv_parm *sp = (struct serv_parm *) (lp + 1);
985 memset(&stat, 0, sizeof (struct ls_rjt));
987 /* For a PLOGI, we only accept if our portname is less
988 * than the remote portname.
990 phba->fc_stat.elsLogiCol++;
991 port_cmp = memcmp(&vport->fc_portname, &sp->portName,
992 sizeof(struct lpfc_name));
995 /* Reject this request because the remote node will accept
997 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
998 stat.un.b.lsRjtRsnCodeExp = LSEXP_CMD_IN_PROGRESS;
999 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
1002 if (lpfc_rcv_plogi(vport, ndlp, cmdiocb) &&
1003 (ndlp->nlp_flag & NLP_NPR_2B_DISC) &&
1004 (vport->num_disc_nodes)) {
1005 spin_lock_irq(shost->host_lock);
1006 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
1007 spin_unlock_irq(shost->host_lock);
1008 /* Check if there are more PLOGIs to be sent */
1009 lpfc_more_plogi(vport);
1010 if (vport->num_disc_nodes == 0) {
1011 spin_lock_irq(shost->host_lock);
1012 vport->fc_flag &= ~FC_NDISC_ACTIVE;
1013 spin_unlock_irq(shost->host_lock);
1014 lpfc_can_disctmo(vport);
1015 lpfc_end_rscn(vport);
1018 } /* If our portname was less */
1020 return ndlp->nlp_state;
1024 lpfc_rcv_prli_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1025 void *arg, uint32_t evt)
1027 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1030 memset(&stat, 0, sizeof (struct ls_rjt));
1031 stat.un.b.lsRjtRsnCode = LSRJT_LOGICAL_BSY;
1032 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
1033 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
1034 return ndlp->nlp_state;
1038 lpfc_rcv_logo_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1039 void *arg, uint32_t evt)
1041 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1043 /* software abort outstanding PLOGI */
1044 lpfc_els_abort(vport->phba, ndlp);
1046 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
1047 return ndlp->nlp_state;
1051 lpfc_rcv_els_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1052 void *arg, uint32_t evt)
1054 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1055 struct lpfc_hba *phba = vport->phba;
1056 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1058 /* software abort outstanding PLOGI */
1059 lpfc_els_abort(phba, ndlp);
1061 if (evt == NLP_EVT_RCV_LOGO) {
1062 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
1064 lpfc_issue_els_logo(vport, ndlp, 0);
1067 /* Put ndlp in npr state set plogi timer for 1 sec */
1068 mod_timer(&ndlp->nlp_delayfunc, jiffies + msecs_to_jiffies(1000 * 1));
1069 spin_lock_irq(shost->host_lock);
1070 ndlp->nlp_flag |= NLP_DELAY_TMO;
1071 spin_unlock_irq(shost->host_lock);
1072 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
1073 ndlp->nlp_prev_state = NLP_STE_PLOGI_ISSUE;
1074 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1076 return ndlp->nlp_state;
1080 lpfc_cmpl_plogi_plogi_issue(struct lpfc_vport *vport,
1081 struct lpfc_nodelist *ndlp,
1085 struct lpfc_hba *phba = vport->phba;
1086 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1087 struct lpfc_iocbq *cmdiocb, *rspiocb;
1088 struct lpfc_dmabuf *pcmd, *prsp, *mp;
1092 struct serv_parm *sp;
1097 cmdiocb = (struct lpfc_iocbq *) arg;
1098 rspiocb = cmdiocb->context_un.rsp_iocb;
1100 if (ndlp->nlp_flag & NLP_ACC_REGLOGIN) {
1101 /* Recovery from PLOGI collision logic */
1102 return ndlp->nlp_state;
1105 irsp = &rspiocb->iocb;
1107 if (irsp->ulpStatus)
1110 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
1112 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
1116 lp = (uint32_t *) prsp->virt;
1117 sp = (struct serv_parm *) ((uint8_t *) lp + sizeof (uint32_t));
1119 /* Some switches have FDMI servers returning 0 for WWN */
1120 if ((ndlp->nlp_DID != FDMI_DID) &&
1121 (wwn_to_u64(sp->portName.u.wwn) == 0 ||
1122 wwn_to_u64(sp->nodeName.u.wwn) == 0)) {
1123 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1124 "0142 PLOGI RSP: Invalid WWN.\n");
1127 if (!lpfc_check_sparm(vport, ndlp, sp, CLASS3, 0))
1129 /* PLOGI chkparm OK */
1130 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1131 "0121 PLOGI chkparm OK Data: x%x x%x x%x x%x\n",
1132 ndlp->nlp_DID, ndlp->nlp_state,
1133 ndlp->nlp_flag, ndlp->nlp_rpi);
1134 if (vport->cfg_fcp_class == 2 && (sp->cls2.classValid))
1135 ndlp->nlp_fcp_info |= CLASS2;
1137 ndlp->nlp_fcp_info |= CLASS3;
1139 ndlp->nlp_class_sup = 0;
1140 if (sp->cls1.classValid)
1141 ndlp->nlp_class_sup |= FC_COS_CLASS1;
1142 if (sp->cls2.classValid)
1143 ndlp->nlp_class_sup |= FC_COS_CLASS2;
1144 if (sp->cls3.classValid)
1145 ndlp->nlp_class_sup |= FC_COS_CLASS3;
1146 if (sp->cls4.classValid)
1147 ndlp->nlp_class_sup |= FC_COS_CLASS4;
1148 ndlp->nlp_maxframe =
1149 ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) | sp->cmn.bbRcvSizeLsb;
1151 if ((vport->fc_flag & FC_PT2PT) &&
1152 (vport->fc_flag & FC_PT2PT_PLOGI)) {
1153 ed_tov = be32_to_cpu(sp->cmn.e_d_tov);
1154 if (sp->cmn.edtovResolution) {
1155 /* E_D_TOV ticks are in nanoseconds */
1156 ed_tov = (phba->fc_edtov + 999999) / 1000000;
1159 ndlp->nlp_flag &= ~NLP_SUPPRESS_RSP;
1160 if ((phba->sli.sli_flag & LPFC_SLI_SUPPRESS_RSP) &&
1161 sp->cmn.valid_vendor_ver_level) {
1162 vid = be32_to_cpu(sp->un.vv.vid);
1163 flag = be32_to_cpu(sp->un.vv.flags);
1164 if ((vid == LPFC_VV_EMLX_ID) &&
1165 (flag & LPFC_VV_SUPPRESS_RSP))
1166 ndlp->nlp_flag |= NLP_SUPPRESS_RSP;
1170 * Use the larger EDTOV
1171 * RATOV = 2 * EDTOV for pt-to-pt
1173 if (ed_tov > phba->fc_edtov)
1174 phba->fc_edtov = ed_tov;
1175 phba->fc_ratov = (2 * phba->fc_edtov) / 1000;
1177 memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
1179 /* Issue config_link / reg_vfi to account for updated TOV's */
1180 if (phba->sli_rev == LPFC_SLI_REV4) {
1181 lpfc_issue_reg_vfi(vport);
1183 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1185 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1186 "0133 PLOGI: no memory "
1188 "Data: x%x x%x x%x x%x\n",
1189 ndlp->nlp_DID, ndlp->nlp_state,
1190 ndlp->nlp_flag, ndlp->nlp_rpi);
1194 lpfc_config_link(phba, mbox);
1196 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1197 mbox->vport = vport;
1198 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
1199 if (rc == MBX_NOT_FINISHED) {
1200 mempool_free(mbox, phba->mbox_mem_pool);
1206 lpfc_unreg_rpi(vport, ndlp);
1208 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1210 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1211 "0018 PLOGI: no memory for reg_login "
1212 "Data: x%x x%x x%x x%x\n",
1213 ndlp->nlp_DID, ndlp->nlp_state,
1214 ndlp->nlp_flag, ndlp->nlp_rpi);
1218 if (lpfc_reg_rpi(phba, vport->vpi, irsp->un.elsreq64.remoteID,
1219 (uint8_t *) sp, mbox, ndlp->nlp_rpi) == 0) {
1220 switch (ndlp->nlp_DID) {
1221 case NameServer_DID:
1222 mbox->mbox_cmpl = lpfc_mbx_cmpl_ns_reg_login;
1225 mbox->mbox_cmpl = lpfc_mbx_cmpl_fdmi_reg_login;
1228 ndlp->nlp_flag |= NLP_REG_LOGIN_SEND;
1229 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
1231 mbox->context2 = lpfc_nlp_get(ndlp);
1232 mbox->vport = vport;
1233 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
1234 != MBX_NOT_FINISHED) {
1235 lpfc_nlp_set_state(vport, ndlp,
1236 NLP_STE_REG_LOGIN_ISSUE);
1237 return ndlp->nlp_state;
1239 if (ndlp->nlp_flag & NLP_REG_LOGIN_SEND)
1240 ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND;
1241 /* decrement node reference count to the failed mbox
1245 mp = (struct lpfc_dmabuf *) mbox->context1;
1246 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1248 mempool_free(mbox, phba->mbox_mem_pool);
1250 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1251 "0134 PLOGI: cannot issue reg_login "
1252 "Data: x%x x%x x%x x%x\n",
1253 ndlp->nlp_DID, ndlp->nlp_state,
1254 ndlp->nlp_flag, ndlp->nlp_rpi);
1256 mempool_free(mbox, phba->mbox_mem_pool);
1258 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1259 "0135 PLOGI: cannot format reg_login "
1260 "Data: x%x x%x x%x x%x\n",
1261 ndlp->nlp_DID, ndlp->nlp_state,
1262 ndlp->nlp_flag, ndlp->nlp_rpi);
1267 if (ndlp->nlp_DID == NameServer_DID) {
1268 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
1269 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1270 "0261 Cannot Register NameServer login\n");
1274 ** In case the node reference counter does not go to zero, ensure that
1275 ** the stale state for the node is not processed.
1278 ndlp->nlp_prev_state = ndlp->nlp_state;
1279 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1280 spin_lock_irq(shost->host_lock);
1281 ndlp->nlp_flag |= NLP_DEFER_RM;
1282 spin_unlock_irq(shost->host_lock);
1283 return NLP_STE_FREED_NODE;
1287 lpfc_cmpl_logo_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1288 void *arg, uint32_t evt)
1290 return ndlp->nlp_state;
1294 lpfc_cmpl_reglogin_plogi_issue(struct lpfc_vport *vport,
1295 struct lpfc_nodelist *ndlp, void *arg, uint32_t evt)
1297 struct lpfc_hba *phba;
1298 LPFC_MBOXQ_t *pmb = (LPFC_MBOXQ_t *) arg;
1299 MAILBOX_t *mb = &pmb->u.mb;
1303 /* Release the RPI */
1304 if (!(phba->pport->load_flag & FC_UNLOADING) &&
1306 rpi = pmb->u.mb.un.varWords[0];
1307 lpfc_release_rpi(phba, vport, rpi);
1309 return ndlp->nlp_state;
1313 lpfc_device_rm_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1314 void *arg, uint32_t evt)
1316 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1318 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1319 spin_lock_irq(shost->host_lock);
1320 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
1321 spin_unlock_irq(shost->host_lock);
1322 return ndlp->nlp_state;
1324 /* software abort outstanding PLOGI */
1325 lpfc_els_abort(vport->phba, ndlp);
1327 lpfc_drop_node(vport, ndlp);
1328 return NLP_STE_FREED_NODE;
1333 lpfc_device_recov_plogi_issue(struct lpfc_vport *vport,
1334 struct lpfc_nodelist *ndlp,
1338 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1339 struct lpfc_hba *phba = vport->phba;
1341 /* Don't do anything that will mess up processing of the
1344 if (vport->fc_flag & FC_RSCN_DEFERRED)
1345 return ndlp->nlp_state;
1347 /* software abort outstanding PLOGI */
1348 lpfc_els_abort(phba, ndlp);
1350 ndlp->nlp_prev_state = NLP_STE_PLOGI_ISSUE;
1351 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1352 spin_lock_irq(shost->host_lock);
1353 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
1354 spin_unlock_irq(shost->host_lock);
1356 return ndlp->nlp_state;
1360 lpfc_rcv_plogi_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1361 void *arg, uint32_t evt)
1363 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1364 struct lpfc_hba *phba = vport->phba;
1365 struct lpfc_iocbq *cmdiocb;
1367 /* software abort outstanding ADISC */
1368 lpfc_els_abort(phba, ndlp);
1370 cmdiocb = (struct lpfc_iocbq *) arg;
1372 if (lpfc_rcv_plogi(vport, ndlp, cmdiocb)) {
1373 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1374 spin_lock_irq(shost->host_lock);
1375 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
1376 spin_unlock_irq(shost->host_lock);
1377 if (vport->num_disc_nodes)
1378 lpfc_more_adisc(vport);
1380 return ndlp->nlp_state;
1382 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
1383 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
1384 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
1386 return ndlp->nlp_state;
1390 lpfc_rcv_prli_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1391 void *arg, uint32_t evt)
1393 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1395 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
1396 return ndlp->nlp_state;
1400 lpfc_rcv_logo_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1401 void *arg, uint32_t evt)
1403 struct lpfc_hba *phba = vport->phba;
1404 struct lpfc_iocbq *cmdiocb;
1406 cmdiocb = (struct lpfc_iocbq *) arg;
1408 /* software abort outstanding ADISC */
1409 lpfc_els_abort(phba, ndlp);
1411 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
1412 return ndlp->nlp_state;
1416 lpfc_rcv_padisc_adisc_issue(struct lpfc_vport *vport,
1417 struct lpfc_nodelist *ndlp,
1418 void *arg, uint32_t evt)
1420 struct lpfc_iocbq *cmdiocb;
1422 cmdiocb = (struct lpfc_iocbq *) arg;
1424 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
1425 return ndlp->nlp_state;
1429 lpfc_rcv_prlo_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1430 void *arg, uint32_t evt)
1432 struct lpfc_iocbq *cmdiocb;
1434 cmdiocb = (struct lpfc_iocbq *) arg;
1436 /* Treat like rcv logo */
1437 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_PRLO);
1438 return ndlp->nlp_state;
1442 lpfc_cmpl_adisc_adisc_issue(struct lpfc_vport *vport,
1443 struct lpfc_nodelist *ndlp,
1444 void *arg, uint32_t evt)
1446 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1447 struct lpfc_hba *phba = vport->phba;
1448 struct lpfc_iocbq *cmdiocb, *rspiocb;
1453 cmdiocb = (struct lpfc_iocbq *) arg;
1454 rspiocb = cmdiocb->context_un.rsp_iocb;
1456 ap = (ADISC *)lpfc_check_elscmpl_iocb(phba, cmdiocb, rspiocb);
1457 irsp = &rspiocb->iocb;
1459 if ((irsp->ulpStatus) ||
1460 (!lpfc_check_adisc(vport, ndlp, &ap->nodeName, &ap->portName))) {
1462 mod_timer(&ndlp->nlp_delayfunc,
1463 jiffies + msecs_to_jiffies(1000));
1464 spin_lock_irq(shost->host_lock);
1465 ndlp->nlp_flag |= NLP_DELAY_TMO;
1466 spin_unlock_irq(shost->host_lock);
1467 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
1469 memset(&ndlp->nlp_nodename, 0, sizeof(struct lpfc_name));
1470 memset(&ndlp->nlp_portname, 0, sizeof(struct lpfc_name));
1472 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
1473 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1474 lpfc_unreg_rpi(vport, ndlp);
1475 return ndlp->nlp_state;
1478 if (phba->sli_rev == LPFC_SLI_REV4) {
1479 rc = lpfc_sli4_resume_rpi(ndlp, NULL, NULL);
1481 /* Stay in state and retry. */
1482 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
1483 return ndlp->nlp_state;
1487 if (ndlp->nlp_type & NLP_FCP_TARGET) {
1488 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
1489 lpfc_nlp_set_state(vport, ndlp, NLP_STE_MAPPED_NODE);
1491 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
1492 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
1495 return ndlp->nlp_state;
1499 lpfc_device_rm_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1500 void *arg, uint32_t evt)
1502 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1504 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1505 spin_lock_irq(shost->host_lock);
1506 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
1507 spin_unlock_irq(shost->host_lock);
1508 return ndlp->nlp_state;
1510 /* software abort outstanding ADISC */
1511 lpfc_els_abort(vport->phba, ndlp);
1513 lpfc_drop_node(vport, ndlp);
1514 return NLP_STE_FREED_NODE;
1519 lpfc_device_recov_adisc_issue(struct lpfc_vport *vport,
1520 struct lpfc_nodelist *ndlp,
1524 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1525 struct lpfc_hba *phba = vport->phba;
1527 /* Don't do anything that will mess up processing of the
1530 if (vport->fc_flag & FC_RSCN_DEFERRED)
1531 return ndlp->nlp_state;
1533 /* software abort outstanding ADISC */
1534 lpfc_els_abort(phba, ndlp);
1536 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
1537 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1538 spin_lock_irq(shost->host_lock);
1539 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
1540 spin_unlock_irq(shost->host_lock);
1541 lpfc_disc_set_adisc(vport, ndlp);
1542 return ndlp->nlp_state;
1546 lpfc_rcv_plogi_reglogin_issue(struct lpfc_vport *vport,
1547 struct lpfc_nodelist *ndlp,
1551 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1553 lpfc_rcv_plogi(vport, ndlp, cmdiocb);
1554 return ndlp->nlp_state;
1558 lpfc_rcv_prli_reglogin_issue(struct lpfc_vport *vport,
1559 struct lpfc_nodelist *ndlp,
1563 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1566 if (vport->phba->nvmet_support) {
1567 /* NVME Target mode. Handle and respond to the PRLI and
1568 * transition to UNMAPPED provided the RPI has completed
1571 if (ndlp->nlp_flag & NLP_RPI_REGISTERED) {
1572 lpfc_rcv_prli(vport, ndlp, cmdiocb);
1573 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
1575 /* RPI registration has not completed. Reject the PRLI
1576 * to prevent an illegal state transition when the
1577 * rpi registration does complete.
1579 lpfc_printf_vlog(vport, KERN_WARNING, LOG_NVME_DISC,
1580 "6115 NVMET ndlp rpi %d state "
1581 "unknown, state x%x flags x%08x\n",
1582 ndlp->nlp_rpi, ndlp->nlp_state,
1584 memset(&stat, 0, sizeof(struct ls_rjt));
1585 stat.un.b.lsRjtRsnCode = LSRJT_LOGICAL_BSY;
1586 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
1587 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb,
1589 return ndlp->nlp_state;
1592 /* Initiator mode. */
1593 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
1596 return ndlp->nlp_state;
1600 lpfc_rcv_logo_reglogin_issue(struct lpfc_vport *vport,
1601 struct lpfc_nodelist *ndlp,
1605 struct lpfc_hba *phba = vport->phba;
1606 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1608 LPFC_MBOXQ_t *nextmb;
1609 struct lpfc_dmabuf *mp;
1611 cmdiocb = (struct lpfc_iocbq *) arg;
1613 /* cleanup any ndlp on mbox q waiting for reglogin cmpl */
1614 if ((mb = phba->sli.mbox_active)) {
1615 if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) &&
1616 (ndlp == (struct lpfc_nodelist *) mb->context2)) {
1617 ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND;
1619 mb->context2 = NULL;
1620 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1624 spin_lock_irq(&phba->hbalock);
1625 list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) {
1626 if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) &&
1627 (ndlp == (struct lpfc_nodelist *) mb->context2)) {
1628 mp = (struct lpfc_dmabuf *) (mb->context1);
1630 __lpfc_mbuf_free(phba, mp->virt, mp->phys);
1633 ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND;
1635 list_del(&mb->list);
1636 phba->sli.mboxq_cnt--;
1637 mempool_free(mb, phba->mbox_mem_pool);
1640 spin_unlock_irq(&phba->hbalock);
1642 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
1643 return ndlp->nlp_state;
1647 lpfc_rcv_padisc_reglogin_issue(struct lpfc_vport *vport,
1648 struct lpfc_nodelist *ndlp,
1652 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1654 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
1655 return ndlp->nlp_state;
1659 lpfc_rcv_prlo_reglogin_issue(struct lpfc_vport *vport,
1660 struct lpfc_nodelist *ndlp,
1664 struct lpfc_iocbq *cmdiocb;
1666 cmdiocb = (struct lpfc_iocbq *) arg;
1667 lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL);
1668 return ndlp->nlp_state;
1672 lpfc_cmpl_reglogin_reglogin_issue(struct lpfc_vport *vport,
1673 struct lpfc_nodelist *ndlp,
1677 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1678 struct lpfc_hba *phba = vport->phba;
1679 LPFC_MBOXQ_t *pmb = (LPFC_MBOXQ_t *) arg;
1680 MAILBOX_t *mb = &pmb->u.mb;
1681 uint32_t did = mb->un.varWords[1];
1684 if (mb->mbxStatus) {
1685 /* RegLogin failed */
1686 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
1687 "0246 RegLogin failed Data: x%x x%x x%x x%x "
1689 did, mb->mbxStatus, vport->port_state,
1690 mb->un.varRegLogin.vpi,
1691 mb->un.varRegLogin.rpi);
1693 * If RegLogin failed due to lack of HBA resources do not
1696 if (mb->mbxStatus == MBXERR_RPI_FULL) {
1697 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
1698 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1699 return ndlp->nlp_state;
1702 /* Put ndlp in npr state set plogi timer for 1 sec */
1703 mod_timer(&ndlp->nlp_delayfunc,
1704 jiffies + msecs_to_jiffies(1000 * 1));
1705 spin_lock_irq(shost->host_lock);
1706 ndlp->nlp_flag |= NLP_DELAY_TMO;
1707 spin_unlock_irq(shost->host_lock);
1708 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
1710 lpfc_issue_els_logo(vport, ndlp, 0);
1711 return ndlp->nlp_state;
1714 /* SLI4 ports have preallocated logical rpis. */
1715 if (phba->sli_rev < LPFC_SLI_REV4)
1716 ndlp->nlp_rpi = mb->un.varWords[0];
1718 ndlp->nlp_flag |= NLP_RPI_REGISTERED;
1720 /* Only if we are not a fabric nport do we issue PRLI */
1721 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1722 "3066 RegLogin Complete on x%x x%x x%x\n",
1723 did, ndlp->nlp_type, ndlp->nlp_fc4_type);
1724 if (!(ndlp->nlp_type & NLP_FABRIC) &&
1725 (phba->nvmet_support == 0)) {
1726 /* The driver supports FCP and NVME concurrently. If the
1727 * ndlp's nlp_fc4_type is still zero, the driver doesn't
1728 * know what PRLI to send yet. Figure that out now and
1729 * call PRLI depending on the outcome.
1731 if (vport->fc_flag & FC_PT2PT) {
1732 /* If we are pt2pt, there is no Fabric to determine
1733 * the FC4 type of the remote nport. So if NVME
1734 * is configured try it.
1736 ndlp->nlp_fc4_type |= NLP_FC4_FCP;
1737 if ((phba->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
1738 (phba->cfg_enable_fc4_type == LPFC_ENABLE_NVME)) {
1739 ndlp->nlp_fc4_type |= NLP_FC4_NVME;
1740 /* We need to update the localport also */
1741 lpfc_nvme_update_localport(vport);
1744 } else if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
1745 ndlp->nlp_fc4_type |= NLP_FC4_FCP;
1747 } else if (ndlp->nlp_fc4_type == 0) {
1748 rc = lpfc_ns_cmd(vport, SLI_CTNS_GFT_ID,
1750 return ndlp->nlp_state;
1753 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
1754 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
1755 lpfc_issue_els_prli(vport, ndlp, 0);
1757 if ((vport->fc_flag & FC_PT2PT) && phba->nvmet_support)
1758 phba->targetport->port_id = vport->fc_myDID;
1760 /* Only Fabric ports should transition. NVME target
1761 * must complete PRLI.
1763 if (ndlp->nlp_type & NLP_FABRIC) {
1764 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
1765 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
1768 return ndlp->nlp_state;
1772 lpfc_device_rm_reglogin_issue(struct lpfc_vport *vport,
1773 struct lpfc_nodelist *ndlp,
1777 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1779 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1780 spin_lock_irq(shost->host_lock);
1781 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
1782 spin_unlock_irq(shost->host_lock);
1783 return ndlp->nlp_state;
1785 lpfc_drop_node(vport, ndlp);
1786 return NLP_STE_FREED_NODE;
1791 lpfc_device_recov_reglogin_issue(struct lpfc_vport *vport,
1792 struct lpfc_nodelist *ndlp,
1796 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1798 /* Don't do anything that will mess up processing of the
1801 if (vport->fc_flag & FC_RSCN_DEFERRED)
1802 return ndlp->nlp_state;
1804 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
1805 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1806 spin_lock_irq(shost->host_lock);
1808 /* If we are a target we won't immediately transition into PRLI,
1809 * so if REG_LOGIN already completed we don't need to ignore it.
1811 if (!(ndlp->nlp_flag & NLP_RPI_REGISTERED) ||
1812 !vport->phba->nvmet_support)
1813 ndlp->nlp_flag |= NLP_IGNR_REG_CMPL;
1815 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
1816 spin_unlock_irq(shost->host_lock);
1817 lpfc_disc_set_adisc(vport, ndlp);
1818 return ndlp->nlp_state;
1822 lpfc_rcv_plogi_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1823 void *arg, uint32_t evt)
1825 struct lpfc_iocbq *cmdiocb;
1827 cmdiocb = (struct lpfc_iocbq *) arg;
1829 lpfc_rcv_plogi(vport, ndlp, cmdiocb);
1830 return ndlp->nlp_state;
1834 lpfc_rcv_prli_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_els_rsp_prli_acc(vport, cmdiocb, ndlp);
1840 return ndlp->nlp_state;
1844 lpfc_rcv_logo_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1845 void *arg, uint32_t evt)
1847 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1849 /* Software abort outstanding PRLI before sending acc */
1850 lpfc_els_abort(vport->phba, ndlp);
1852 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
1853 return ndlp->nlp_state;
1857 lpfc_rcv_padisc_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1858 void *arg, uint32_t evt)
1860 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1862 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
1863 return ndlp->nlp_state;
1866 /* This routine is envoked when we rcv a PRLO request from a nport
1867 * we are logged into. We should send back a PRLO rsp setting the
1869 * NEXT STATE = PRLI_ISSUE
1872 lpfc_rcv_prlo_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1873 void *arg, uint32_t evt)
1875 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1877 lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL);
1878 return ndlp->nlp_state;
1882 lpfc_cmpl_prli_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1883 void *arg, uint32_t evt)
1885 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1886 struct lpfc_iocbq *cmdiocb, *rspiocb;
1887 struct lpfc_hba *phba = vport->phba;
1890 struct lpfc_nvme_prli *nvpr;
1893 cmdiocb = (struct lpfc_iocbq *) arg;
1894 rspiocb = cmdiocb->context_un.rsp_iocb;
1896 /* A solicited PRLI is either FCP or NVME. The PRLI cmd/rsp
1897 * format is different so NULL the two PRLI types so that the
1898 * driver correctly gets the correct context.
1902 temp_ptr = lpfc_check_elscmpl_iocb(phba, cmdiocb, rspiocb);
1903 if (cmdiocb->iocb_flag & LPFC_PRLI_FCP_REQ)
1904 npr = (PRLI *) temp_ptr;
1905 else if (cmdiocb->iocb_flag & LPFC_PRLI_NVME_REQ)
1906 nvpr = (struct lpfc_nvme_prli *) temp_ptr;
1908 irsp = &rspiocb->iocb;
1909 if (irsp->ulpStatus) {
1910 if ((vport->port_type == LPFC_NPIV_PORT) &&
1911 vport->cfg_restrict_login) {
1915 /* When the rport rejected the FCP PRLI as unsupported.
1916 * This should only happen in Pt2Pt so an NVME PRLI
1917 * should be outstanding still.
1919 if (npr && ndlp->nlp_flag & NLP_FCP_PRLI_RJT) {
1920 ndlp->nlp_fc4_type &= ~NLP_FC4_FCP;
1924 /* The LS Req had some error. Don't let this be a
1927 if ((ndlp->fc4_prli_sent == 1) &&
1928 (ndlp->nlp_state == NLP_STE_PRLI_ISSUE) &&
1929 (ndlp->nlp_type & (NLP_FCP_TARGET | NLP_FCP_INITIATOR)))
1930 /* The FCP PRLI completed successfully but
1931 * the NVME PRLI failed. Since they are sent in
1932 * succession, allow the FCP to complete.
1936 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
1937 ndlp->nlp_type |= NLP_FCP_INITIATOR;
1938 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
1939 return ndlp->nlp_state;
1942 if (npr && (npr->acceptRspCode == PRLI_REQ_EXECUTED) &&
1943 (npr->prliType == PRLI_FCP_TYPE)) {
1944 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_DISC,
1945 "6028 FCP NPR PRLI Cmpl Init %d Target %d\n",
1948 if (npr->initiatorFunc)
1949 ndlp->nlp_type |= NLP_FCP_INITIATOR;
1950 if (npr->targetFunc) {
1951 ndlp->nlp_type |= NLP_FCP_TARGET;
1952 if (npr->writeXferRdyDis)
1953 ndlp->nlp_flag |= NLP_FIRSTBURST;
1956 ndlp->nlp_fcp_info |= NLP_FCP_2_DEVICE;
1959 (bf_get_be32(prli_acc_rsp_code, nvpr) ==
1960 PRLI_REQ_EXECUTED) &&
1961 (bf_get_be32(prli_type_code, nvpr) ==
1964 /* Complete setting up the remote ndlp personality. */
1965 if (bf_get_be32(prli_init, nvpr))
1966 ndlp->nlp_type |= NLP_NVME_INITIATOR;
1968 /* Target driver cannot solicit NVME FB. */
1969 if (bf_get_be32(prli_tgt, nvpr)) {
1970 /* Complete the nvme target roles. The transport
1971 * needs to know if the rport is capable of
1972 * discovery in addition to its role.
1974 ndlp->nlp_type |= NLP_NVME_TARGET;
1975 if (bf_get_be32(prli_disc, nvpr))
1976 ndlp->nlp_type |= NLP_NVME_DISCOVERY;
1977 if ((bf_get_be32(prli_fba, nvpr) == 1) &&
1978 (bf_get_be32(prli_fb_sz, nvpr) > 0) &&
1979 (phba->cfg_nvme_enable_fb) &&
1980 (!phba->nvmet_support)) {
1981 /* Both sides support FB. The target's first
1982 * burst size is a 512 byte encoded value.
1984 ndlp->nlp_flag |= NLP_FIRSTBURST;
1985 ndlp->nvme_fb_size = bf_get_be32(prli_fb_sz,
1990 if (bf_get_be32(prli_recov, nvpr))
1991 ndlp->nlp_fcp_info |= NLP_FCP_2_DEVICE;
1993 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_DISC,
1994 "6029 NVME PRLI Cmpl w1 x%08x "
1995 "w4 x%08x w5 x%08x flag x%x, "
1996 "fcp_info x%x nlp_type x%x\n",
1997 be32_to_cpu(nvpr->word1),
1998 be32_to_cpu(nvpr->word4),
1999 be32_to_cpu(nvpr->word5),
2000 ndlp->nlp_flag, ndlp->nlp_fcp_info,
2003 if (!(ndlp->nlp_type & NLP_FCP_TARGET) &&
2004 (vport->port_type == LPFC_NPIV_PORT) &&
2005 vport->cfg_restrict_login) {
2007 spin_lock_irq(shost->host_lock);
2008 ndlp->nlp_flag |= NLP_TARGET_REMOVE;
2009 spin_unlock_irq(shost->host_lock);
2010 lpfc_issue_els_logo(vport, ndlp, 0);
2012 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
2013 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
2014 return ndlp->nlp_state;
2018 /* The ndlp state cannot move to MAPPED or UNMAPPED before all PRLIs
2021 if (ndlp->fc4_prli_sent == 0) {
2022 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
2023 if (ndlp->nlp_type & (NLP_FCP_TARGET | NLP_NVME_TARGET))
2024 lpfc_nlp_set_state(vport, ndlp, NLP_STE_MAPPED_NODE);
2025 else if (ndlp->nlp_type &
2026 (NLP_FCP_INITIATOR | NLP_NVME_INITIATOR))
2027 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
2029 lpfc_printf_vlog(vport,
2031 "3067 PRLI's still outstanding "
2032 "on x%06x - count %d, Pend Node Mode "
2034 ndlp->nlp_DID, ndlp->fc4_prli_sent);
2036 return ndlp->nlp_state;
2039 /*! lpfc_device_rm_prli_issue
2050 * This routine is envoked when we a request to remove a nport we are in the
2051 * process of PRLIing. We should software abort outstanding prli, unreg
2052 * login, send a logout. We will change node state to UNUSED_NODE, put it
2053 * on plogi list so it can be freed when LOGO completes.
2058 lpfc_device_rm_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2059 void *arg, uint32_t evt)
2061 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2063 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
2064 spin_lock_irq(shost->host_lock);
2065 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
2066 spin_unlock_irq(shost->host_lock);
2067 return ndlp->nlp_state;
2069 /* software abort outstanding PLOGI */
2070 lpfc_els_abort(vport->phba, ndlp);
2072 lpfc_drop_node(vport, ndlp);
2073 return NLP_STE_FREED_NODE;
2078 /*! lpfc_device_recov_prli_issue
2089 * The routine is envoked when the state of a device is unknown, like
2090 * during a link down. We should remove the nodelist entry from the
2091 * unmapped list, issue a UNREG_LOGIN, do a software abort of the
2092 * outstanding PRLI command, then free the node entry.
2095 lpfc_device_recov_prli_issue(struct lpfc_vport *vport,
2096 struct lpfc_nodelist *ndlp,
2100 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2101 struct lpfc_hba *phba = vport->phba;
2103 /* Don't do anything that will mess up processing of the
2106 if (vport->fc_flag & FC_RSCN_DEFERRED)
2107 return ndlp->nlp_state;
2109 /* software abort outstanding PRLI */
2110 lpfc_els_abort(phba, ndlp);
2112 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
2113 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
2114 spin_lock_irq(shost->host_lock);
2115 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
2116 spin_unlock_irq(shost->host_lock);
2117 lpfc_disc_set_adisc(vport, ndlp);
2118 return ndlp->nlp_state;
2122 lpfc_rcv_plogi_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2123 void *arg, uint32_t evt)
2125 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *)arg;
2128 memset(&stat, 0, sizeof(struct ls_rjt));
2129 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
2130 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
2131 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
2132 return ndlp->nlp_state;
2136 lpfc_rcv_prli_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2137 void *arg, uint32_t evt)
2139 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *)arg;
2142 memset(&stat, 0, sizeof(struct ls_rjt));
2143 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
2144 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
2145 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
2146 return ndlp->nlp_state;
2150 lpfc_rcv_logo_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2151 void *arg, uint32_t evt)
2153 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2154 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *)arg;
2156 spin_lock_irq(shost->host_lock);
2157 ndlp->nlp_flag |= NLP_LOGO_ACC;
2158 spin_unlock_irq(shost->host_lock);
2159 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
2160 return ndlp->nlp_state;
2164 lpfc_rcv_padisc_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2165 void *arg, uint32_t evt)
2167 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *)arg;
2170 memset(&stat, 0, sizeof(struct ls_rjt));
2171 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
2172 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
2173 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
2174 return ndlp->nlp_state;
2178 lpfc_rcv_prlo_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2179 void *arg, uint32_t evt)
2181 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *)arg;
2184 memset(&stat, 0, sizeof(struct ls_rjt));
2185 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
2186 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
2187 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
2188 return ndlp->nlp_state;
2192 lpfc_cmpl_logo_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2193 void *arg, uint32_t evt)
2195 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2197 ndlp->nlp_prev_state = NLP_STE_LOGO_ISSUE;
2198 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
2199 spin_lock_irq(shost->host_lock);
2200 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
2201 spin_unlock_irq(shost->host_lock);
2202 lpfc_disc_set_adisc(vport, ndlp);
2203 return ndlp->nlp_state;
2207 lpfc_device_rm_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2208 void *arg, uint32_t evt)
2211 * DevLoss has timed out and is calling for Device Remove.
2212 * In this case, abort the LOGO and cleanup the ndlp
2215 lpfc_unreg_rpi(vport, ndlp);
2216 /* software abort outstanding PLOGI */
2217 lpfc_els_abort(vport->phba, ndlp);
2218 lpfc_drop_node(vport, ndlp);
2219 return NLP_STE_FREED_NODE;
2223 lpfc_device_recov_logo_issue(struct lpfc_vport *vport,
2224 struct lpfc_nodelist *ndlp,
2225 void *arg, uint32_t evt)
2228 * Device Recovery events have no meaning for a node with a LOGO
2229 * outstanding. The LOGO has to complete first and handle the
2230 * node from that point.
2232 return ndlp->nlp_state;
2236 lpfc_rcv_plogi_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2237 void *arg, uint32_t evt)
2239 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2241 lpfc_rcv_plogi(vport, ndlp, cmdiocb);
2242 return ndlp->nlp_state;
2246 lpfc_rcv_prli_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2247 void *arg, uint32_t evt)
2249 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2251 lpfc_rcv_prli(vport, ndlp, cmdiocb);
2252 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
2253 return ndlp->nlp_state;
2257 lpfc_rcv_logo_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2258 void *arg, uint32_t evt)
2260 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2262 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
2263 return ndlp->nlp_state;
2267 lpfc_rcv_padisc_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2268 void *arg, uint32_t evt)
2270 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2272 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
2273 return ndlp->nlp_state;
2277 lpfc_rcv_prlo_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2278 void *arg, uint32_t evt)
2280 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2282 lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL);
2283 return ndlp->nlp_state;
2287 lpfc_device_recov_unmap_node(struct lpfc_vport *vport,
2288 struct lpfc_nodelist *ndlp,
2292 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2294 ndlp->nlp_prev_state = NLP_STE_UNMAPPED_NODE;
2295 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
2296 spin_lock_irq(shost->host_lock);
2297 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
2298 spin_unlock_irq(shost->host_lock);
2299 lpfc_disc_set_adisc(vport, ndlp);
2301 return ndlp->nlp_state;
2305 lpfc_rcv_plogi_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2306 void *arg, uint32_t evt)
2308 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2310 lpfc_rcv_plogi(vport, ndlp, cmdiocb);
2311 return ndlp->nlp_state;
2315 lpfc_rcv_prli_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2316 void *arg, uint32_t evt)
2318 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2320 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
2321 return ndlp->nlp_state;
2325 lpfc_rcv_logo_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2326 void *arg, uint32_t evt)
2328 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2330 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
2331 return ndlp->nlp_state;
2335 lpfc_rcv_padisc_mapped_node(struct lpfc_vport *vport,
2336 struct lpfc_nodelist *ndlp,
2337 void *arg, uint32_t evt)
2339 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2341 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
2342 return ndlp->nlp_state;
2346 lpfc_rcv_prlo_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2347 void *arg, uint32_t evt)
2349 struct lpfc_hba *phba = vport->phba;
2350 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2352 /* flush the target */
2353 lpfc_sli_abort_iocb(vport, &phba->sli.sli3_ring[LPFC_FCP_RING],
2354 ndlp->nlp_sid, 0, LPFC_CTX_TGT);
2356 /* Treat like rcv logo */
2357 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_PRLO);
2358 return ndlp->nlp_state;
2362 lpfc_device_recov_mapped_node(struct lpfc_vport *vport,
2363 struct lpfc_nodelist *ndlp,
2367 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2369 ndlp->nlp_prev_state = NLP_STE_MAPPED_NODE;
2370 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
2371 spin_lock_irq(shost->host_lock);
2372 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
2373 spin_unlock_irq(shost->host_lock);
2374 lpfc_disc_set_adisc(vport, ndlp);
2375 return ndlp->nlp_state;
2379 lpfc_rcv_plogi_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2380 void *arg, uint32_t evt)
2382 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2383 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2385 /* Ignore PLOGI if we have an outstanding LOGO */
2386 if (ndlp->nlp_flag & (NLP_LOGO_SND | NLP_LOGO_ACC))
2387 return ndlp->nlp_state;
2388 if (lpfc_rcv_plogi(vport, ndlp, cmdiocb)) {
2389 lpfc_cancel_retry_delay_tmo(vport, ndlp);
2390 spin_lock_irq(shost->host_lock);
2391 ndlp->nlp_flag &= ~(NLP_NPR_ADISC | NLP_NPR_2B_DISC);
2392 spin_unlock_irq(shost->host_lock);
2393 } else if (!(ndlp->nlp_flag & NLP_NPR_2B_DISC)) {
2394 /* send PLOGI immediately, move to PLOGI issue state */
2395 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
2396 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
2397 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
2398 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
2401 return ndlp->nlp_state;
2405 lpfc_rcv_prli_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2406 void *arg, uint32_t evt)
2408 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2409 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2412 memset(&stat, 0, sizeof (struct ls_rjt));
2413 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
2414 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
2415 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
2417 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
2418 if (ndlp->nlp_flag & NLP_NPR_ADISC) {
2419 spin_lock_irq(shost->host_lock);
2420 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
2421 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
2422 spin_unlock_irq(shost->host_lock);
2423 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
2424 lpfc_issue_els_adisc(vport, ndlp, 0);
2426 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
2427 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
2428 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
2431 return ndlp->nlp_state;
2435 lpfc_rcv_logo_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2436 void *arg, uint32_t evt)
2438 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2440 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
2441 return ndlp->nlp_state;
2445 lpfc_rcv_padisc_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2446 void *arg, uint32_t evt)
2448 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2450 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
2452 * Do not start discovery if discovery is about to start
2453 * or discovery in progress for this node. Starting discovery
2454 * here will affect the counting of discovery threads.
2456 if (!(ndlp->nlp_flag & NLP_DELAY_TMO) &&
2457 !(ndlp->nlp_flag & NLP_NPR_2B_DISC)) {
2458 if (ndlp->nlp_flag & NLP_NPR_ADISC) {
2459 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
2460 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
2461 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
2462 lpfc_issue_els_adisc(vport, ndlp, 0);
2464 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
2465 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
2466 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
2469 return ndlp->nlp_state;
2473 lpfc_rcv_prlo_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2474 void *arg, uint32_t evt)
2476 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2477 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2479 spin_lock_irq(shost->host_lock);
2480 ndlp->nlp_flag |= NLP_LOGO_ACC;
2481 spin_unlock_irq(shost->host_lock);
2483 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
2485 if ((ndlp->nlp_flag & NLP_DELAY_TMO) == 0) {
2486 mod_timer(&ndlp->nlp_delayfunc,
2487 jiffies + msecs_to_jiffies(1000 * 1));
2488 spin_lock_irq(shost->host_lock);
2489 ndlp->nlp_flag |= NLP_DELAY_TMO;
2490 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
2491 spin_unlock_irq(shost->host_lock);
2492 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
2494 spin_lock_irq(shost->host_lock);
2495 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
2496 spin_unlock_irq(shost->host_lock);
2498 return ndlp->nlp_state;
2502 lpfc_cmpl_plogi_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2503 void *arg, uint32_t evt)
2505 struct lpfc_iocbq *cmdiocb, *rspiocb;
2507 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2509 cmdiocb = (struct lpfc_iocbq *) arg;
2510 rspiocb = cmdiocb->context_un.rsp_iocb;
2512 irsp = &rspiocb->iocb;
2513 if (irsp->ulpStatus) {
2514 spin_lock_irq(shost->host_lock);
2515 ndlp->nlp_flag |= NLP_DEFER_RM;
2516 spin_unlock_irq(shost->host_lock);
2517 return NLP_STE_FREED_NODE;
2519 return ndlp->nlp_state;
2523 lpfc_cmpl_prli_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2524 void *arg, uint32_t evt)
2526 struct lpfc_iocbq *cmdiocb, *rspiocb;
2529 cmdiocb = (struct lpfc_iocbq *) arg;
2530 rspiocb = cmdiocb->context_un.rsp_iocb;
2532 irsp = &rspiocb->iocb;
2533 if (irsp->ulpStatus && (ndlp->nlp_flag & NLP_NODEV_REMOVE)) {
2534 lpfc_drop_node(vport, ndlp);
2535 return NLP_STE_FREED_NODE;
2537 return ndlp->nlp_state;
2541 lpfc_cmpl_logo_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2542 void *arg, uint32_t evt)
2544 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2546 /* For the fabric port just clear the fc flags. */
2547 if (ndlp->nlp_DID == Fabric_DID) {
2548 spin_lock_irq(shost->host_lock);
2549 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
2550 spin_unlock_irq(shost->host_lock);
2552 lpfc_unreg_rpi(vport, ndlp);
2553 return ndlp->nlp_state;
2557 lpfc_cmpl_adisc_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2558 void *arg, uint32_t evt)
2560 struct lpfc_iocbq *cmdiocb, *rspiocb;
2563 cmdiocb = (struct lpfc_iocbq *) arg;
2564 rspiocb = cmdiocb->context_un.rsp_iocb;
2566 irsp = &rspiocb->iocb;
2567 if (irsp->ulpStatus && (ndlp->nlp_flag & NLP_NODEV_REMOVE)) {
2568 lpfc_drop_node(vport, ndlp);
2569 return NLP_STE_FREED_NODE;
2571 return ndlp->nlp_state;
2575 lpfc_cmpl_reglogin_npr_node(struct lpfc_vport *vport,
2576 struct lpfc_nodelist *ndlp,
2577 void *arg, uint32_t evt)
2579 LPFC_MBOXQ_t *pmb = (LPFC_MBOXQ_t *) arg;
2580 MAILBOX_t *mb = &pmb->u.mb;
2582 if (!mb->mbxStatus) {
2583 /* SLI4 ports have preallocated logical rpis. */
2584 if (vport->phba->sli_rev < LPFC_SLI_REV4)
2585 ndlp->nlp_rpi = mb->un.varWords[0];
2586 ndlp->nlp_flag |= NLP_RPI_REGISTERED;
2587 if (ndlp->nlp_flag & NLP_LOGO_ACC) {
2588 lpfc_unreg_rpi(vport, ndlp);
2591 if (ndlp->nlp_flag & NLP_NODEV_REMOVE) {
2592 lpfc_drop_node(vport, ndlp);
2593 return NLP_STE_FREED_NODE;
2596 return ndlp->nlp_state;
2600 lpfc_device_rm_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2601 void *arg, uint32_t evt)
2603 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2605 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
2606 spin_lock_irq(shost->host_lock);
2607 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
2608 spin_unlock_irq(shost->host_lock);
2609 return ndlp->nlp_state;
2611 lpfc_drop_node(vport, ndlp);
2612 return NLP_STE_FREED_NODE;
2616 lpfc_device_recov_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2617 void *arg, uint32_t evt)
2619 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2621 /* Don't do anything that will mess up processing of the
2624 if (vport->fc_flag & FC_RSCN_DEFERRED)
2625 return ndlp->nlp_state;
2627 lpfc_cancel_retry_delay_tmo(vport, ndlp);
2628 spin_lock_irq(shost->host_lock);
2629 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
2630 spin_unlock_irq(shost->host_lock);
2631 return ndlp->nlp_state;
2635 /* This next section defines the NPort Discovery State Machine */
2637 /* There are 4 different double linked lists nodelist entries can reside on.
2638 * The plogi list and adisc list are used when Link Up discovery or RSCN
2639 * processing is needed. Each list holds the nodes that we will send PLOGI
2640 * or ADISC on. These lists will keep track of what nodes will be effected
2641 * by an RSCN, or a Link Up (Typically, all nodes are effected on Link Up).
2642 * The unmapped_list will contain all nodes that we have successfully logged
2643 * into at the Fibre Channel level. The mapped_list will contain all nodes
2644 * that are mapped FCP targets.
2647 * The bind list is a list of undiscovered (potentially non-existent) nodes
2648 * that we have saved binding information on. This information is used when
2649 * nodes transition from the unmapped to the mapped list.
2651 /* For UNUSED_NODE state, the node has just been allocated .
2652 * For PLOGI_ISSUE and REG_LOGIN_ISSUE, the node is on
2653 * the PLOGI list. For REG_LOGIN_COMPL, the node is taken off the PLOGI list
2654 * and put on the unmapped list. For ADISC processing, the node is taken off
2655 * the ADISC list and placed on either the mapped or unmapped list (depending
2656 * on its previous state). Once on the unmapped list, a PRLI is issued and the
2657 * state changed to PRLI_ISSUE. When the PRLI completion occurs, the state is
2658 * changed to UNMAPPED_NODE. If the completion indicates a mapped
2659 * node, the node is taken off the unmapped list. The binding list is checked
2660 * for a valid binding, or a binding is automatically assigned. If binding
2661 * assignment is unsuccessful, the node is left on the unmapped list. If
2662 * binding assignment is successful, the associated binding list entry (if
2663 * any) is removed, and the node is placed on the mapped list.
2666 * For a Link Down, all nodes on the ADISC, PLOGI, unmapped or mapped
2667 * lists will receive a DEVICE_RECOVERY event. If the linkdown or devloss timers
2668 * expire, all effected nodes will receive a DEVICE_RM event.
2671 * For a Link Up or RSCN, all nodes will move from the mapped / unmapped lists
2672 * to either the ADISC or PLOGI list. After a Nameserver query or ALPA loopmap
2673 * check, additional nodes may be added or removed (via DEVICE_RM) to / from
2674 * the PLOGI or ADISC lists. Once the PLOGI and ADISC lists are populated,
2675 * we will first process the ADISC list. 32 entries are processed initially and
2676 * ADISC is initited for each one. Completions / Events for each node are
2677 * funnelled thru the state machine. As each node finishes ADISC processing, it
2678 * starts ADISC for any nodes waiting for ADISC processing. If no nodes are
2679 * waiting, and the ADISC list count is identically 0, then we are done. For
2680 * Link Up discovery, since all nodes on the PLOGI list are UNREG_LOGIN'ed, we
2681 * can issue a CLEAR_LA and reenable Link Events. Next we will process the PLOGI
2682 * list. 32 entries are processed initially and PLOGI is initited for each one.
2683 * Completions / Events for each node are funnelled thru the state machine. As
2684 * each node finishes PLOGI processing, it starts PLOGI for any nodes waiting
2685 * for PLOGI processing. If no nodes are waiting, and the PLOGI list count is
2686 * indentically 0, then we are done. We have now completed discovery / RSCN
2687 * handling. Upon completion, ALL nodes should be on either the mapped or
2691 static uint32_t (*lpfc_disc_action[NLP_STE_MAX_STATE * NLP_EVT_MAX_EVENT])
2692 (struct lpfc_vport *, struct lpfc_nodelist *, void *, uint32_t) = {
2693 /* Action routine Event Current State */
2694 lpfc_rcv_plogi_unused_node, /* RCV_PLOGI UNUSED_NODE */
2695 lpfc_rcv_els_unused_node, /* RCV_PRLI */
2696 lpfc_rcv_logo_unused_node, /* RCV_LOGO */
2697 lpfc_rcv_els_unused_node, /* RCV_ADISC */
2698 lpfc_rcv_els_unused_node, /* RCV_PDISC */
2699 lpfc_rcv_els_unused_node, /* RCV_PRLO */
2700 lpfc_disc_illegal, /* CMPL_PLOGI */
2701 lpfc_disc_illegal, /* CMPL_PRLI */
2702 lpfc_cmpl_logo_unused_node, /* CMPL_LOGO */
2703 lpfc_disc_illegal, /* CMPL_ADISC */
2704 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2705 lpfc_device_rm_unused_node, /* DEVICE_RM */
2706 lpfc_device_recov_unused_node, /* DEVICE_RECOVERY */
2708 lpfc_rcv_plogi_plogi_issue, /* RCV_PLOGI PLOGI_ISSUE */
2709 lpfc_rcv_prli_plogi_issue, /* RCV_PRLI */
2710 lpfc_rcv_logo_plogi_issue, /* RCV_LOGO */
2711 lpfc_rcv_els_plogi_issue, /* RCV_ADISC */
2712 lpfc_rcv_els_plogi_issue, /* RCV_PDISC */
2713 lpfc_rcv_els_plogi_issue, /* RCV_PRLO */
2714 lpfc_cmpl_plogi_plogi_issue, /* CMPL_PLOGI */
2715 lpfc_disc_illegal, /* CMPL_PRLI */
2716 lpfc_cmpl_logo_plogi_issue, /* CMPL_LOGO */
2717 lpfc_disc_illegal, /* CMPL_ADISC */
2718 lpfc_cmpl_reglogin_plogi_issue,/* CMPL_REG_LOGIN */
2719 lpfc_device_rm_plogi_issue, /* DEVICE_RM */
2720 lpfc_device_recov_plogi_issue, /* DEVICE_RECOVERY */
2722 lpfc_rcv_plogi_adisc_issue, /* RCV_PLOGI ADISC_ISSUE */
2723 lpfc_rcv_prli_adisc_issue, /* RCV_PRLI */
2724 lpfc_rcv_logo_adisc_issue, /* RCV_LOGO */
2725 lpfc_rcv_padisc_adisc_issue, /* RCV_ADISC */
2726 lpfc_rcv_padisc_adisc_issue, /* RCV_PDISC */
2727 lpfc_rcv_prlo_adisc_issue, /* RCV_PRLO */
2728 lpfc_disc_illegal, /* CMPL_PLOGI */
2729 lpfc_disc_illegal, /* CMPL_PRLI */
2730 lpfc_disc_illegal, /* CMPL_LOGO */
2731 lpfc_cmpl_adisc_adisc_issue, /* CMPL_ADISC */
2732 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2733 lpfc_device_rm_adisc_issue, /* DEVICE_RM */
2734 lpfc_device_recov_adisc_issue, /* DEVICE_RECOVERY */
2736 lpfc_rcv_plogi_reglogin_issue, /* RCV_PLOGI REG_LOGIN_ISSUE */
2737 lpfc_rcv_prli_reglogin_issue, /* RCV_PLOGI */
2738 lpfc_rcv_logo_reglogin_issue, /* RCV_LOGO */
2739 lpfc_rcv_padisc_reglogin_issue, /* RCV_ADISC */
2740 lpfc_rcv_padisc_reglogin_issue, /* RCV_PDISC */
2741 lpfc_rcv_prlo_reglogin_issue, /* RCV_PRLO */
2742 lpfc_cmpl_plogi_illegal, /* CMPL_PLOGI */
2743 lpfc_disc_illegal, /* CMPL_PRLI */
2744 lpfc_disc_illegal, /* CMPL_LOGO */
2745 lpfc_disc_illegal, /* CMPL_ADISC */
2746 lpfc_cmpl_reglogin_reglogin_issue,/* CMPL_REG_LOGIN */
2747 lpfc_device_rm_reglogin_issue, /* DEVICE_RM */
2748 lpfc_device_recov_reglogin_issue,/* DEVICE_RECOVERY */
2750 lpfc_rcv_plogi_prli_issue, /* RCV_PLOGI PRLI_ISSUE */
2751 lpfc_rcv_prli_prli_issue, /* RCV_PRLI */
2752 lpfc_rcv_logo_prli_issue, /* RCV_LOGO */
2753 lpfc_rcv_padisc_prli_issue, /* RCV_ADISC */
2754 lpfc_rcv_padisc_prli_issue, /* RCV_PDISC */
2755 lpfc_rcv_prlo_prli_issue, /* RCV_PRLO */
2756 lpfc_cmpl_plogi_illegal, /* CMPL_PLOGI */
2757 lpfc_cmpl_prli_prli_issue, /* CMPL_PRLI */
2758 lpfc_disc_illegal, /* CMPL_LOGO */
2759 lpfc_disc_illegal, /* CMPL_ADISC */
2760 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2761 lpfc_device_rm_prli_issue, /* DEVICE_RM */
2762 lpfc_device_recov_prli_issue, /* DEVICE_RECOVERY */
2764 lpfc_rcv_plogi_logo_issue, /* RCV_PLOGI LOGO_ISSUE */
2765 lpfc_rcv_prli_logo_issue, /* RCV_PRLI */
2766 lpfc_rcv_logo_logo_issue, /* RCV_LOGO */
2767 lpfc_rcv_padisc_logo_issue, /* RCV_ADISC */
2768 lpfc_rcv_padisc_logo_issue, /* RCV_PDISC */
2769 lpfc_rcv_prlo_logo_issue, /* RCV_PRLO */
2770 lpfc_cmpl_plogi_illegal, /* CMPL_PLOGI */
2771 lpfc_disc_illegal, /* CMPL_PRLI */
2772 lpfc_cmpl_logo_logo_issue, /* CMPL_LOGO */
2773 lpfc_disc_illegal, /* CMPL_ADISC */
2774 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2775 lpfc_device_rm_logo_issue, /* DEVICE_RM */
2776 lpfc_device_recov_logo_issue, /* DEVICE_RECOVERY */
2778 lpfc_rcv_plogi_unmap_node, /* RCV_PLOGI UNMAPPED_NODE */
2779 lpfc_rcv_prli_unmap_node, /* RCV_PRLI */
2780 lpfc_rcv_logo_unmap_node, /* RCV_LOGO */
2781 lpfc_rcv_padisc_unmap_node, /* RCV_ADISC */
2782 lpfc_rcv_padisc_unmap_node, /* RCV_PDISC */
2783 lpfc_rcv_prlo_unmap_node, /* RCV_PRLO */
2784 lpfc_disc_illegal, /* CMPL_PLOGI */
2785 lpfc_disc_illegal, /* CMPL_PRLI */
2786 lpfc_disc_illegal, /* CMPL_LOGO */
2787 lpfc_disc_illegal, /* CMPL_ADISC */
2788 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2789 lpfc_disc_illegal, /* DEVICE_RM */
2790 lpfc_device_recov_unmap_node, /* DEVICE_RECOVERY */
2792 lpfc_rcv_plogi_mapped_node, /* RCV_PLOGI MAPPED_NODE */
2793 lpfc_rcv_prli_mapped_node, /* RCV_PRLI */
2794 lpfc_rcv_logo_mapped_node, /* RCV_LOGO */
2795 lpfc_rcv_padisc_mapped_node, /* RCV_ADISC */
2796 lpfc_rcv_padisc_mapped_node, /* RCV_PDISC */
2797 lpfc_rcv_prlo_mapped_node, /* RCV_PRLO */
2798 lpfc_disc_illegal, /* CMPL_PLOGI */
2799 lpfc_disc_illegal, /* CMPL_PRLI */
2800 lpfc_disc_illegal, /* CMPL_LOGO */
2801 lpfc_disc_illegal, /* CMPL_ADISC */
2802 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2803 lpfc_disc_illegal, /* DEVICE_RM */
2804 lpfc_device_recov_mapped_node, /* DEVICE_RECOVERY */
2806 lpfc_rcv_plogi_npr_node, /* RCV_PLOGI NPR_NODE */
2807 lpfc_rcv_prli_npr_node, /* RCV_PRLI */
2808 lpfc_rcv_logo_npr_node, /* RCV_LOGO */
2809 lpfc_rcv_padisc_npr_node, /* RCV_ADISC */
2810 lpfc_rcv_padisc_npr_node, /* RCV_PDISC */
2811 lpfc_rcv_prlo_npr_node, /* RCV_PRLO */
2812 lpfc_cmpl_plogi_npr_node, /* CMPL_PLOGI */
2813 lpfc_cmpl_prli_npr_node, /* CMPL_PRLI */
2814 lpfc_cmpl_logo_npr_node, /* CMPL_LOGO */
2815 lpfc_cmpl_adisc_npr_node, /* CMPL_ADISC */
2816 lpfc_cmpl_reglogin_npr_node, /* CMPL_REG_LOGIN */
2817 lpfc_device_rm_npr_node, /* DEVICE_RM */
2818 lpfc_device_recov_npr_node, /* DEVICE_RECOVERY */
2822 lpfc_disc_state_machine(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2823 void *arg, uint32_t evt)
2825 uint32_t cur_state, rc;
2826 uint32_t(*func) (struct lpfc_vport *, struct lpfc_nodelist *, void *,
2828 uint32_t got_ndlp = 0;
2830 if (lpfc_nlp_get(ndlp))
2833 cur_state = ndlp->nlp_state;
2835 /* DSM in event <evt> on NPort <nlp_DID> in state <cur_state> */
2836 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2837 "0211 DSM in event x%x on NPort x%x in "
2838 "state %d Data: x%x x%x\n",
2839 evt, ndlp->nlp_DID, cur_state,
2840 ndlp->nlp_flag, ndlp->nlp_fc4_type);
2842 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_DSM,
2843 "DSM in: evt:%d ste:%d did:x%x",
2844 evt, cur_state, ndlp->nlp_DID);
2846 func = lpfc_disc_action[(cur_state * NLP_EVT_MAX_EVENT) + evt];
2847 rc = (func) (vport, ndlp, arg, evt);
2849 /* DSM out state <rc> on NPort <nlp_DID> */
2851 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2852 "0212 DSM out state %d on NPort x%x Data: x%x\n",
2853 rc, ndlp->nlp_DID, ndlp->nlp_flag);
2855 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_DSM,
2856 "DSM out: ste:%d did:x%x flg:x%x",
2857 rc, ndlp->nlp_DID, ndlp->nlp_flag);
2858 /* Decrement the ndlp reference count held for this function */
2861 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2862 "0213 DSM out state %d on NPort free\n", rc);
2864 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_DSM,
2865 "DSM out: ste:%d did:x%x flg:x%x",