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)
667 lpfc_linkdown_port(vport);
668 spin_lock_irq(shost->host_lock);
669 vport->fc_flag |= FC_VPORT_LOGO_RCVD;
670 spin_unlock_irq(shost->host_lock);
671 vports = lpfc_create_vport_work_array(phba);
673 for (i = 0; i <= phba->max_vports && vports[i] != NULL;
675 if ((!(vports[i]->fc_flag &
676 FC_VPORT_LOGO_RCVD)) &&
677 (vports[i]->port_state > LPFC_FDISC)) {
678 active_vlink_present = 1;
682 lpfc_destroy_vport_work_array(phba, vports);
686 * Don't re-instantiate if vport is marked for deletion.
687 * If we are here first then vport_delete is going to wait
688 * for discovery to complete.
690 if (!(vport->load_flag & FC_UNLOADING) &&
691 active_vlink_present) {
693 * If there are other active VLinks present,
694 * re-instantiate the Vlink using FDISC.
696 mod_timer(&ndlp->nlp_delayfunc,
697 jiffies + msecs_to_jiffies(1000));
698 spin_lock_irq(shost->host_lock);
699 ndlp->nlp_flag |= NLP_DELAY_TMO;
700 spin_unlock_irq(shost->host_lock);
701 ndlp->nlp_last_elscmd = ELS_CMD_FDISC;
702 vport->port_state = LPFC_FDISC;
704 spin_lock_irq(shost->host_lock);
705 phba->pport->fc_flag &= ~FC_LOGO_RCVD_DID_CHNG;
706 spin_unlock_irq(shost->host_lock);
707 lpfc_retry_pport_discovery(phba);
709 } else if ((!(ndlp->nlp_type & NLP_FABRIC) &&
710 ((ndlp->nlp_type & NLP_FCP_TARGET) ||
711 (ndlp->nlp_type & NLP_NVME_TARGET) ||
712 (vport->fc_flag & FC_PT2PT))) ||
713 (ndlp->nlp_state == NLP_STE_ADISC_ISSUE)) {
714 /* Only try to re-login if this is NOT a Fabric Node
715 * AND the remote NPORT is a FCP/NVME Target or we
716 * are in pt2pt mode. NLP_STE_ADISC_ISSUE is a special
717 * case for LOGO as a response to ADISC behavior.
719 mod_timer(&ndlp->nlp_delayfunc,
720 jiffies + msecs_to_jiffies(1000 * 1));
721 spin_lock_irq(shost->host_lock);
722 ndlp->nlp_flag |= NLP_DELAY_TMO;
723 spin_unlock_irq(shost->host_lock);
725 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
728 ndlp->nlp_prev_state = ndlp->nlp_state;
729 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
731 spin_lock_irq(shost->host_lock);
732 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
733 spin_unlock_irq(shost->host_lock);
734 /* The driver has to wait until the ACC completes before it continues
735 * processing the LOGO. The action will resume in
736 * lpfc_cmpl_els_logo_acc routine. Since part of processing includes an
737 * unreg_login, the driver waits so the ACC does not get aborted.
743 lpfc_rcv_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
744 struct lpfc_iocbq *cmdiocb)
746 struct lpfc_hba *phba = vport->phba;
747 struct lpfc_dmabuf *pcmd;
750 struct fc_rport *rport = ndlp->rport;
753 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
754 lp = (uint32_t *) pcmd->virt;
755 npr = (PRLI *) ((uint8_t *) lp + sizeof (uint32_t));
757 if ((npr->prliType == PRLI_FCP_TYPE) ||
758 (npr->prliType == PRLI_NVME_TYPE)) {
759 if (npr->initiatorFunc) {
760 if (npr->prliType == PRLI_FCP_TYPE)
761 ndlp->nlp_type |= NLP_FCP_INITIATOR;
762 if (npr->prliType == PRLI_NVME_TYPE)
763 ndlp->nlp_type |= NLP_NVME_INITIATOR;
765 if (npr->targetFunc) {
766 if (npr->prliType == PRLI_FCP_TYPE)
767 ndlp->nlp_type |= NLP_FCP_TARGET;
768 if (npr->prliType == PRLI_NVME_TYPE)
769 ndlp->nlp_type |= NLP_NVME_TARGET;
770 if (npr->writeXferRdyDis)
771 ndlp->nlp_flag |= NLP_FIRSTBURST;
774 ndlp->nlp_fcp_info |= NLP_FCP_2_DEVICE;
776 /* If this driver is in nvme target mode, set the ndlp's fc4
777 * type to NVME provided the PRLI response claims NVME FC4
778 * type. Target mode does not issue gft_id so doesn't get
779 * the fc4 type set until now.
781 if (phba->nvmet_support && (npr->prliType == PRLI_NVME_TYPE)) {
782 ndlp->nlp_fc4_type |= NLP_FC4_NVME;
783 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
785 if (npr->prliType == PRLI_FCP_TYPE)
786 ndlp->nlp_fc4_type |= NLP_FC4_FCP;
789 /* We need to update the rport role values */
790 roles = FC_RPORT_ROLE_UNKNOWN;
791 if (ndlp->nlp_type & NLP_FCP_INITIATOR)
792 roles |= FC_RPORT_ROLE_FCP_INITIATOR;
793 if (ndlp->nlp_type & NLP_FCP_TARGET)
794 roles |= FC_RPORT_ROLE_FCP_TARGET;
796 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
797 "rport rolechg: role:x%x did:x%x flg:x%x",
798 roles, ndlp->nlp_DID, ndlp->nlp_flag);
800 if (phba->cfg_enable_fc4_type != LPFC_ENABLE_NVME)
801 fc_remote_port_rolechg(rport, roles);
806 lpfc_disc_set_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
808 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
810 if (!(ndlp->nlp_flag & NLP_RPI_REGISTERED)) {
811 spin_lock_irq(shost->host_lock);
812 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
813 spin_unlock_irq(shost->host_lock);
817 if (!(vport->fc_flag & FC_PT2PT)) {
818 /* Check config parameter use-adisc or FCP-2 */
819 if (vport->cfg_use_adisc && ((vport->fc_flag & FC_RSCN_MODE) ||
820 ((ndlp->nlp_fcp_info & NLP_FCP_2_DEVICE) &&
821 (ndlp->nlp_type & NLP_FCP_TARGET)))) {
822 spin_lock_irq(shost->host_lock);
823 ndlp->nlp_flag |= NLP_NPR_ADISC;
824 spin_unlock_irq(shost->host_lock);
829 spin_lock_irq(shost->host_lock);
830 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
831 spin_unlock_irq(shost->host_lock);
832 lpfc_unreg_rpi(vport, ndlp);
837 * lpfc_release_rpi - Release a RPI by issuing unreg_login mailbox cmd.
838 * @phba : Pointer to lpfc_hba structure.
839 * @vport: Pointer to lpfc_vport structure.
840 * @rpi : rpi to be release.
842 * This function will send a unreg_login mailbox command to the firmware
846 lpfc_release_rpi(struct lpfc_hba *phba,
847 struct lpfc_vport *vport,
853 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
856 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
857 "2796 mailbox memory allocation failed \n");
859 lpfc_unreg_login(phba, vport->vpi, rpi, pmb);
860 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
861 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
862 if (rc == MBX_NOT_FINISHED)
863 mempool_free(pmb, phba->mbox_mem_pool);
868 lpfc_disc_illegal(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
869 void *arg, uint32_t evt)
871 struct lpfc_hba *phba;
872 LPFC_MBOXQ_t *pmb = (LPFC_MBOXQ_t *) arg;
876 /* Release the RPI if reglogin completing */
877 if (!(phba->pport->load_flag & FC_UNLOADING) &&
878 (evt == NLP_EVT_CMPL_REG_LOGIN) &&
879 (!pmb->u.mb.mbxStatus)) {
880 rpi = pmb->u.mb.un.varWords[0];
881 lpfc_release_rpi(phba, vport, rpi);
883 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
884 "0271 Illegal State Transition: node x%x "
885 "event x%x, state x%x Data: x%x x%x\n",
886 ndlp->nlp_DID, evt, ndlp->nlp_state, ndlp->nlp_rpi,
888 return ndlp->nlp_state;
892 lpfc_cmpl_plogi_illegal(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
893 void *arg, uint32_t evt)
895 /* This transition is only legal if we previously
896 * rcv'ed a PLOGI. Since we don't want 2 discovery threads
897 * working on the same NPortID, do nothing for this thread
900 if (!(ndlp->nlp_flag & NLP_RCV_PLOGI)) {
901 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
902 "0272 Illegal State Transition: node x%x "
903 "event x%x, state x%x Data: x%x x%x\n",
904 ndlp->nlp_DID, evt, ndlp->nlp_state, ndlp->nlp_rpi,
907 return ndlp->nlp_state;
910 /* Start of Discovery State Machine routines */
913 lpfc_rcv_plogi_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
914 void *arg, uint32_t evt)
916 struct lpfc_iocbq *cmdiocb;
918 cmdiocb = (struct lpfc_iocbq *) arg;
920 if (lpfc_rcv_plogi(vport, ndlp, cmdiocb)) {
921 return ndlp->nlp_state;
923 return NLP_STE_FREED_NODE;
927 lpfc_rcv_els_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
928 void *arg, uint32_t evt)
930 lpfc_issue_els_logo(vport, ndlp, 0);
931 return ndlp->nlp_state;
935 lpfc_rcv_logo_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
936 void *arg, uint32_t evt)
938 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
939 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
941 spin_lock_irq(shost->host_lock);
942 ndlp->nlp_flag |= NLP_LOGO_ACC;
943 spin_unlock_irq(shost->host_lock);
944 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
946 return ndlp->nlp_state;
950 lpfc_cmpl_logo_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
951 void *arg, uint32_t evt)
953 return NLP_STE_FREED_NODE;
957 lpfc_device_rm_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
958 void *arg, uint32_t evt)
960 return NLP_STE_FREED_NODE;
964 lpfc_device_recov_unused_node(struct lpfc_vport *vport,
965 struct lpfc_nodelist *ndlp,
966 void *arg, uint32_t evt)
968 return ndlp->nlp_state;
972 lpfc_rcv_plogi_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
973 void *arg, uint32_t evt)
975 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
976 struct lpfc_hba *phba = vport->phba;
977 struct lpfc_iocbq *cmdiocb = arg;
978 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
979 uint32_t *lp = (uint32_t *) pcmd->virt;
980 struct serv_parm *sp = (struct serv_parm *) (lp + 1);
984 memset(&stat, 0, sizeof (struct ls_rjt));
986 /* For a PLOGI, we only accept if our portname is less
987 * than the remote portname.
989 phba->fc_stat.elsLogiCol++;
990 port_cmp = memcmp(&vport->fc_portname, &sp->portName,
991 sizeof(struct lpfc_name));
994 /* Reject this request because the remote node will accept
996 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
997 stat.un.b.lsRjtRsnCodeExp = LSEXP_CMD_IN_PROGRESS;
998 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
1001 if (lpfc_rcv_plogi(vport, ndlp, cmdiocb) &&
1002 (ndlp->nlp_flag & NLP_NPR_2B_DISC) &&
1003 (vport->num_disc_nodes)) {
1004 spin_lock_irq(shost->host_lock);
1005 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
1006 spin_unlock_irq(shost->host_lock);
1007 /* Check if there are more PLOGIs to be sent */
1008 lpfc_more_plogi(vport);
1009 if (vport->num_disc_nodes == 0) {
1010 spin_lock_irq(shost->host_lock);
1011 vport->fc_flag &= ~FC_NDISC_ACTIVE;
1012 spin_unlock_irq(shost->host_lock);
1013 lpfc_can_disctmo(vport);
1014 lpfc_end_rscn(vport);
1017 } /* If our portname was less */
1019 return ndlp->nlp_state;
1023 lpfc_rcv_prli_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1024 void *arg, uint32_t evt)
1026 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1029 memset(&stat, 0, sizeof (struct ls_rjt));
1030 stat.un.b.lsRjtRsnCode = LSRJT_LOGICAL_BSY;
1031 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
1032 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
1033 return ndlp->nlp_state;
1037 lpfc_rcv_logo_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1038 void *arg, uint32_t evt)
1040 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1042 /* software abort outstanding PLOGI */
1043 lpfc_els_abort(vport->phba, ndlp);
1045 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
1046 return ndlp->nlp_state;
1050 lpfc_rcv_els_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1051 void *arg, uint32_t evt)
1053 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1054 struct lpfc_hba *phba = vport->phba;
1055 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1057 /* software abort outstanding PLOGI */
1058 lpfc_els_abort(phba, ndlp);
1060 if (evt == NLP_EVT_RCV_LOGO) {
1061 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
1063 lpfc_issue_els_logo(vport, ndlp, 0);
1066 /* Put ndlp in npr state set plogi timer for 1 sec */
1067 mod_timer(&ndlp->nlp_delayfunc, jiffies + msecs_to_jiffies(1000 * 1));
1068 spin_lock_irq(shost->host_lock);
1069 ndlp->nlp_flag |= NLP_DELAY_TMO;
1070 spin_unlock_irq(shost->host_lock);
1071 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
1072 ndlp->nlp_prev_state = NLP_STE_PLOGI_ISSUE;
1073 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1075 return ndlp->nlp_state;
1079 lpfc_cmpl_plogi_plogi_issue(struct lpfc_vport *vport,
1080 struct lpfc_nodelist *ndlp,
1084 struct lpfc_hba *phba = vport->phba;
1085 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1086 struct lpfc_iocbq *cmdiocb, *rspiocb;
1087 struct lpfc_dmabuf *pcmd, *prsp, *mp;
1091 struct serv_parm *sp;
1096 cmdiocb = (struct lpfc_iocbq *) arg;
1097 rspiocb = cmdiocb->context_un.rsp_iocb;
1099 if (ndlp->nlp_flag & NLP_ACC_REGLOGIN) {
1100 /* Recovery from PLOGI collision logic */
1101 return ndlp->nlp_state;
1104 irsp = &rspiocb->iocb;
1106 if (irsp->ulpStatus)
1109 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
1111 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
1115 lp = (uint32_t *) prsp->virt;
1116 sp = (struct serv_parm *) ((uint8_t *) lp + sizeof (uint32_t));
1118 /* Some switches have FDMI servers returning 0 for WWN */
1119 if ((ndlp->nlp_DID != FDMI_DID) &&
1120 (wwn_to_u64(sp->portName.u.wwn) == 0 ||
1121 wwn_to_u64(sp->nodeName.u.wwn) == 0)) {
1122 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1123 "0142 PLOGI RSP: Invalid WWN.\n");
1126 if (!lpfc_check_sparm(vport, ndlp, sp, CLASS3, 0))
1128 /* PLOGI chkparm OK */
1129 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1130 "0121 PLOGI chkparm OK Data: x%x x%x x%x x%x\n",
1131 ndlp->nlp_DID, ndlp->nlp_state,
1132 ndlp->nlp_flag, ndlp->nlp_rpi);
1133 if (vport->cfg_fcp_class == 2 && (sp->cls2.classValid))
1134 ndlp->nlp_fcp_info |= CLASS2;
1136 ndlp->nlp_fcp_info |= CLASS3;
1138 ndlp->nlp_class_sup = 0;
1139 if (sp->cls1.classValid)
1140 ndlp->nlp_class_sup |= FC_COS_CLASS1;
1141 if (sp->cls2.classValid)
1142 ndlp->nlp_class_sup |= FC_COS_CLASS2;
1143 if (sp->cls3.classValid)
1144 ndlp->nlp_class_sup |= FC_COS_CLASS3;
1145 if (sp->cls4.classValid)
1146 ndlp->nlp_class_sup |= FC_COS_CLASS4;
1147 ndlp->nlp_maxframe =
1148 ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) | sp->cmn.bbRcvSizeLsb;
1150 if ((vport->fc_flag & FC_PT2PT) &&
1151 (vport->fc_flag & FC_PT2PT_PLOGI)) {
1152 ed_tov = be32_to_cpu(sp->cmn.e_d_tov);
1153 if (sp->cmn.edtovResolution) {
1154 /* E_D_TOV ticks are in nanoseconds */
1155 ed_tov = (phba->fc_edtov + 999999) / 1000000;
1158 ndlp->nlp_flag &= ~NLP_SUPPRESS_RSP;
1159 if ((phba->sli.sli_flag & LPFC_SLI_SUPPRESS_RSP) &&
1160 sp->cmn.valid_vendor_ver_level) {
1161 vid = be32_to_cpu(sp->un.vv.vid);
1162 flag = be32_to_cpu(sp->un.vv.flags);
1163 if ((vid == LPFC_VV_EMLX_ID) &&
1164 (flag & LPFC_VV_SUPPRESS_RSP))
1165 ndlp->nlp_flag |= NLP_SUPPRESS_RSP;
1169 * Use the larger EDTOV
1170 * RATOV = 2 * EDTOV for pt-to-pt
1172 if (ed_tov > phba->fc_edtov)
1173 phba->fc_edtov = ed_tov;
1174 phba->fc_ratov = (2 * phba->fc_edtov) / 1000;
1176 memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
1178 /* Issue config_link / reg_vfi to account for updated TOV's */
1179 if (phba->sli_rev == LPFC_SLI_REV4) {
1180 lpfc_issue_reg_vfi(vport);
1182 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1184 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1185 "0133 PLOGI: no memory "
1187 "Data: x%x x%x x%x x%x\n",
1188 ndlp->nlp_DID, ndlp->nlp_state,
1189 ndlp->nlp_flag, ndlp->nlp_rpi);
1193 lpfc_config_link(phba, mbox);
1195 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1196 mbox->vport = vport;
1197 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
1198 if (rc == MBX_NOT_FINISHED) {
1199 mempool_free(mbox, phba->mbox_mem_pool);
1205 lpfc_unreg_rpi(vport, ndlp);
1207 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1209 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1210 "0018 PLOGI: no memory for reg_login "
1211 "Data: x%x x%x x%x x%x\n",
1212 ndlp->nlp_DID, ndlp->nlp_state,
1213 ndlp->nlp_flag, ndlp->nlp_rpi);
1217 if (lpfc_reg_rpi(phba, vport->vpi, irsp->un.elsreq64.remoteID,
1218 (uint8_t *) sp, mbox, ndlp->nlp_rpi) == 0) {
1219 switch (ndlp->nlp_DID) {
1220 case NameServer_DID:
1221 mbox->mbox_cmpl = lpfc_mbx_cmpl_ns_reg_login;
1224 mbox->mbox_cmpl = lpfc_mbx_cmpl_fdmi_reg_login;
1227 ndlp->nlp_flag |= NLP_REG_LOGIN_SEND;
1228 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
1230 mbox->context2 = lpfc_nlp_get(ndlp);
1231 mbox->vport = vport;
1232 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
1233 != MBX_NOT_FINISHED) {
1234 lpfc_nlp_set_state(vport, ndlp,
1235 NLP_STE_REG_LOGIN_ISSUE);
1236 return ndlp->nlp_state;
1238 if (ndlp->nlp_flag & NLP_REG_LOGIN_SEND)
1239 ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND;
1240 /* decrement node reference count to the failed mbox
1244 mp = (struct lpfc_dmabuf *) mbox->context1;
1245 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1247 mempool_free(mbox, phba->mbox_mem_pool);
1249 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1250 "0134 PLOGI: cannot issue reg_login "
1251 "Data: x%x x%x x%x x%x\n",
1252 ndlp->nlp_DID, ndlp->nlp_state,
1253 ndlp->nlp_flag, ndlp->nlp_rpi);
1255 mempool_free(mbox, phba->mbox_mem_pool);
1257 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1258 "0135 PLOGI: cannot format reg_login "
1259 "Data: x%x x%x x%x x%x\n",
1260 ndlp->nlp_DID, ndlp->nlp_state,
1261 ndlp->nlp_flag, ndlp->nlp_rpi);
1266 if (ndlp->nlp_DID == NameServer_DID) {
1267 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
1268 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1269 "0261 Cannot Register NameServer login\n");
1273 ** In case the node reference counter does not go to zero, ensure that
1274 ** the stale state for the node is not processed.
1277 ndlp->nlp_prev_state = ndlp->nlp_state;
1278 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1279 spin_lock_irq(shost->host_lock);
1280 ndlp->nlp_flag |= NLP_DEFER_RM;
1281 spin_unlock_irq(shost->host_lock);
1282 return NLP_STE_FREED_NODE;
1286 lpfc_cmpl_logo_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1287 void *arg, uint32_t evt)
1289 return ndlp->nlp_state;
1293 lpfc_cmpl_reglogin_plogi_issue(struct lpfc_vport *vport,
1294 struct lpfc_nodelist *ndlp, void *arg, uint32_t evt)
1296 struct lpfc_hba *phba;
1297 LPFC_MBOXQ_t *pmb = (LPFC_MBOXQ_t *) arg;
1298 MAILBOX_t *mb = &pmb->u.mb;
1302 /* Release the RPI */
1303 if (!(phba->pport->load_flag & FC_UNLOADING) &&
1305 rpi = pmb->u.mb.un.varWords[0];
1306 lpfc_release_rpi(phba, vport, rpi);
1308 return ndlp->nlp_state;
1312 lpfc_device_rm_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1313 void *arg, uint32_t evt)
1315 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1317 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1318 spin_lock_irq(shost->host_lock);
1319 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
1320 spin_unlock_irq(shost->host_lock);
1321 return ndlp->nlp_state;
1323 /* software abort outstanding PLOGI */
1324 lpfc_els_abort(vport->phba, ndlp);
1326 lpfc_drop_node(vport, ndlp);
1327 return NLP_STE_FREED_NODE;
1332 lpfc_device_recov_plogi_issue(struct lpfc_vport *vport,
1333 struct lpfc_nodelist *ndlp,
1337 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1338 struct lpfc_hba *phba = vport->phba;
1340 /* Don't do anything that will mess up processing of the
1343 if (vport->fc_flag & FC_RSCN_DEFERRED)
1344 return ndlp->nlp_state;
1346 /* software abort outstanding PLOGI */
1347 lpfc_els_abort(phba, ndlp);
1349 ndlp->nlp_prev_state = NLP_STE_PLOGI_ISSUE;
1350 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1351 spin_lock_irq(shost->host_lock);
1352 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
1353 spin_unlock_irq(shost->host_lock);
1355 return ndlp->nlp_state;
1359 lpfc_rcv_plogi_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1360 void *arg, uint32_t evt)
1362 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1363 struct lpfc_hba *phba = vport->phba;
1364 struct lpfc_iocbq *cmdiocb;
1366 /* software abort outstanding ADISC */
1367 lpfc_els_abort(phba, ndlp);
1369 cmdiocb = (struct lpfc_iocbq *) arg;
1371 if (lpfc_rcv_plogi(vport, ndlp, cmdiocb)) {
1372 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1373 spin_lock_irq(shost->host_lock);
1374 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
1375 spin_unlock_irq(shost->host_lock);
1376 if (vport->num_disc_nodes)
1377 lpfc_more_adisc(vport);
1379 return ndlp->nlp_state;
1381 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
1382 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
1383 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
1385 return ndlp->nlp_state;
1389 lpfc_rcv_prli_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1390 void *arg, uint32_t evt)
1392 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1394 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
1395 return ndlp->nlp_state;
1399 lpfc_rcv_logo_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1400 void *arg, uint32_t evt)
1402 struct lpfc_hba *phba = vport->phba;
1403 struct lpfc_iocbq *cmdiocb;
1405 cmdiocb = (struct lpfc_iocbq *) arg;
1407 /* software abort outstanding ADISC */
1408 lpfc_els_abort(phba, ndlp);
1410 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
1411 return ndlp->nlp_state;
1415 lpfc_rcv_padisc_adisc_issue(struct lpfc_vport *vport,
1416 struct lpfc_nodelist *ndlp,
1417 void *arg, uint32_t evt)
1419 struct lpfc_iocbq *cmdiocb;
1421 cmdiocb = (struct lpfc_iocbq *) arg;
1423 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
1424 return ndlp->nlp_state;
1428 lpfc_rcv_prlo_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1429 void *arg, uint32_t evt)
1431 struct lpfc_iocbq *cmdiocb;
1433 cmdiocb = (struct lpfc_iocbq *) arg;
1435 /* Treat like rcv logo */
1436 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_PRLO);
1437 return ndlp->nlp_state;
1441 lpfc_cmpl_adisc_adisc_issue(struct lpfc_vport *vport,
1442 struct lpfc_nodelist *ndlp,
1443 void *arg, uint32_t evt)
1445 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1446 struct lpfc_hba *phba = vport->phba;
1447 struct lpfc_iocbq *cmdiocb, *rspiocb;
1452 cmdiocb = (struct lpfc_iocbq *) arg;
1453 rspiocb = cmdiocb->context_un.rsp_iocb;
1455 ap = (ADISC *)lpfc_check_elscmpl_iocb(phba, cmdiocb, rspiocb);
1456 irsp = &rspiocb->iocb;
1458 if ((irsp->ulpStatus) ||
1459 (!lpfc_check_adisc(vport, ndlp, &ap->nodeName, &ap->portName))) {
1461 mod_timer(&ndlp->nlp_delayfunc,
1462 jiffies + msecs_to_jiffies(1000));
1463 spin_lock_irq(shost->host_lock);
1464 ndlp->nlp_flag |= NLP_DELAY_TMO;
1465 spin_unlock_irq(shost->host_lock);
1466 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
1468 memset(&ndlp->nlp_nodename, 0, sizeof(struct lpfc_name));
1469 memset(&ndlp->nlp_portname, 0, sizeof(struct lpfc_name));
1471 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
1472 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1473 lpfc_unreg_rpi(vport, ndlp);
1474 return ndlp->nlp_state;
1477 if (phba->sli_rev == LPFC_SLI_REV4) {
1478 rc = lpfc_sli4_resume_rpi(ndlp, NULL, NULL);
1480 /* Stay in state and retry. */
1481 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
1482 return ndlp->nlp_state;
1486 if (ndlp->nlp_type & NLP_FCP_TARGET) {
1487 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
1488 lpfc_nlp_set_state(vport, ndlp, NLP_STE_MAPPED_NODE);
1490 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
1491 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
1494 return ndlp->nlp_state;
1498 lpfc_device_rm_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1499 void *arg, uint32_t evt)
1501 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1503 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1504 spin_lock_irq(shost->host_lock);
1505 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
1506 spin_unlock_irq(shost->host_lock);
1507 return ndlp->nlp_state;
1509 /* software abort outstanding ADISC */
1510 lpfc_els_abort(vport->phba, ndlp);
1512 lpfc_drop_node(vport, ndlp);
1513 return NLP_STE_FREED_NODE;
1518 lpfc_device_recov_adisc_issue(struct lpfc_vport *vport,
1519 struct lpfc_nodelist *ndlp,
1523 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1524 struct lpfc_hba *phba = vport->phba;
1526 /* Don't do anything that will mess up processing of the
1529 if (vport->fc_flag & FC_RSCN_DEFERRED)
1530 return ndlp->nlp_state;
1532 /* software abort outstanding ADISC */
1533 lpfc_els_abort(phba, ndlp);
1535 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
1536 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1537 spin_lock_irq(shost->host_lock);
1538 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
1539 spin_unlock_irq(shost->host_lock);
1540 lpfc_disc_set_adisc(vport, ndlp);
1541 return ndlp->nlp_state;
1545 lpfc_rcv_plogi_reglogin_issue(struct lpfc_vport *vport,
1546 struct lpfc_nodelist *ndlp,
1550 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1552 lpfc_rcv_plogi(vport, ndlp, cmdiocb);
1553 return ndlp->nlp_state;
1557 lpfc_rcv_prli_reglogin_issue(struct lpfc_vport *vport,
1558 struct lpfc_nodelist *ndlp,
1562 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1565 if (vport->phba->nvmet_support) {
1566 /* NVME Target mode. Handle and respond to the PRLI and
1567 * transition to UNMAPPED provided the RPI has completed
1570 if (ndlp->nlp_flag & NLP_RPI_REGISTERED) {
1571 lpfc_rcv_prli(vport, ndlp, cmdiocb);
1572 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
1574 /* RPI registration has not completed. Reject the PRLI
1575 * to prevent an illegal state transition when the
1576 * rpi registration does complete.
1578 lpfc_printf_vlog(vport, KERN_WARNING, LOG_NVME_DISC,
1579 "6115 NVMET ndlp rpi %d state "
1580 "unknown, state x%x flags x%08x\n",
1581 ndlp->nlp_rpi, ndlp->nlp_state,
1583 memset(&stat, 0, sizeof(struct ls_rjt));
1584 stat.un.b.lsRjtRsnCode = LSRJT_LOGICAL_BSY;
1585 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
1586 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb,
1588 return ndlp->nlp_state;
1591 /* Initiator mode. */
1592 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
1595 return ndlp->nlp_state;
1599 lpfc_rcv_logo_reglogin_issue(struct lpfc_vport *vport,
1600 struct lpfc_nodelist *ndlp,
1604 struct lpfc_hba *phba = vport->phba;
1605 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1607 LPFC_MBOXQ_t *nextmb;
1608 struct lpfc_dmabuf *mp;
1610 cmdiocb = (struct lpfc_iocbq *) arg;
1612 /* cleanup any ndlp on mbox q waiting for reglogin cmpl */
1613 if ((mb = phba->sli.mbox_active)) {
1614 if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) &&
1615 (ndlp == (struct lpfc_nodelist *) mb->context2)) {
1616 ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND;
1618 mb->context2 = NULL;
1619 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1623 spin_lock_irq(&phba->hbalock);
1624 list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) {
1625 if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) &&
1626 (ndlp == (struct lpfc_nodelist *) mb->context2)) {
1627 mp = (struct lpfc_dmabuf *) (mb->context1);
1629 __lpfc_mbuf_free(phba, mp->virt, mp->phys);
1632 ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND;
1634 list_del(&mb->list);
1635 phba->sli.mboxq_cnt--;
1636 mempool_free(mb, phba->mbox_mem_pool);
1639 spin_unlock_irq(&phba->hbalock);
1641 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
1642 return ndlp->nlp_state;
1646 lpfc_rcv_padisc_reglogin_issue(struct lpfc_vport *vport,
1647 struct lpfc_nodelist *ndlp,
1651 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1653 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
1654 return ndlp->nlp_state;
1658 lpfc_rcv_prlo_reglogin_issue(struct lpfc_vport *vport,
1659 struct lpfc_nodelist *ndlp,
1663 struct lpfc_iocbq *cmdiocb;
1665 cmdiocb = (struct lpfc_iocbq *) arg;
1666 lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL);
1667 return ndlp->nlp_state;
1671 lpfc_cmpl_reglogin_reglogin_issue(struct lpfc_vport *vport,
1672 struct lpfc_nodelist *ndlp,
1676 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1677 struct lpfc_hba *phba = vport->phba;
1678 LPFC_MBOXQ_t *pmb = (LPFC_MBOXQ_t *) arg;
1679 MAILBOX_t *mb = &pmb->u.mb;
1680 uint32_t did = mb->un.varWords[1];
1683 if (mb->mbxStatus) {
1684 /* RegLogin failed */
1685 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
1686 "0246 RegLogin failed Data: x%x x%x x%x x%x "
1688 did, mb->mbxStatus, vport->port_state,
1689 mb->un.varRegLogin.vpi,
1690 mb->un.varRegLogin.rpi);
1692 * If RegLogin failed due to lack of HBA resources do not
1695 if (mb->mbxStatus == MBXERR_RPI_FULL) {
1696 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
1697 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1698 return ndlp->nlp_state;
1701 /* Put ndlp in npr state set plogi timer for 1 sec */
1702 mod_timer(&ndlp->nlp_delayfunc,
1703 jiffies + msecs_to_jiffies(1000 * 1));
1704 spin_lock_irq(shost->host_lock);
1705 ndlp->nlp_flag |= NLP_DELAY_TMO;
1706 spin_unlock_irq(shost->host_lock);
1707 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
1709 lpfc_issue_els_logo(vport, ndlp, 0);
1710 return ndlp->nlp_state;
1713 /* SLI4 ports have preallocated logical rpis. */
1714 if (phba->sli_rev < LPFC_SLI_REV4)
1715 ndlp->nlp_rpi = mb->un.varWords[0];
1717 ndlp->nlp_flag |= NLP_RPI_REGISTERED;
1719 /* Only if we are not a fabric nport do we issue PRLI */
1720 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1721 "3066 RegLogin Complete on x%x x%x x%x\n",
1722 did, ndlp->nlp_type, ndlp->nlp_fc4_type);
1723 if (!(ndlp->nlp_type & NLP_FABRIC) &&
1724 (phba->nvmet_support == 0)) {
1725 /* The driver supports FCP and NVME concurrently. If the
1726 * ndlp's nlp_fc4_type is still zero, the driver doesn't
1727 * know what PRLI to send yet. Figure that out now and
1728 * call PRLI depending on the outcome.
1730 if (vport->fc_flag & FC_PT2PT) {
1731 /* If we are pt2pt, there is no Fabric to determine
1732 * the FC4 type of the remote nport. So if NVME
1733 * is configured try it.
1735 ndlp->nlp_fc4_type |= NLP_FC4_FCP;
1736 if ((phba->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
1737 (phba->cfg_enable_fc4_type == LPFC_ENABLE_NVME)) {
1738 ndlp->nlp_fc4_type |= NLP_FC4_NVME;
1739 /* We need to update the localport also */
1740 lpfc_nvme_update_localport(vport);
1743 } else if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
1744 ndlp->nlp_fc4_type |= NLP_FC4_FCP;
1746 } else if (ndlp->nlp_fc4_type == 0) {
1747 rc = lpfc_ns_cmd(vport, SLI_CTNS_GFT_ID,
1749 return ndlp->nlp_state;
1752 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
1753 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
1754 lpfc_issue_els_prli(vport, ndlp, 0);
1756 if ((vport->fc_flag & FC_PT2PT) && phba->nvmet_support)
1757 phba->targetport->port_id = vport->fc_myDID;
1759 /* Only Fabric ports should transition. NVME target
1760 * must complete PRLI.
1762 if (ndlp->nlp_type & NLP_FABRIC) {
1763 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
1764 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
1767 return ndlp->nlp_state;
1771 lpfc_device_rm_reglogin_issue(struct lpfc_vport *vport,
1772 struct lpfc_nodelist *ndlp,
1776 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1778 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1779 spin_lock_irq(shost->host_lock);
1780 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
1781 spin_unlock_irq(shost->host_lock);
1782 return ndlp->nlp_state;
1784 lpfc_drop_node(vport, ndlp);
1785 return NLP_STE_FREED_NODE;
1790 lpfc_device_recov_reglogin_issue(struct lpfc_vport *vport,
1791 struct lpfc_nodelist *ndlp,
1795 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1797 /* Don't do anything that will mess up processing of the
1800 if (vport->fc_flag & FC_RSCN_DEFERRED)
1801 return ndlp->nlp_state;
1803 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
1804 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1805 spin_lock_irq(shost->host_lock);
1807 /* If we are a target we won't immediately transition into PRLI,
1808 * so if REG_LOGIN already completed we don't need to ignore it.
1810 if (!(ndlp->nlp_flag & NLP_RPI_REGISTERED) ||
1811 !vport->phba->nvmet_support)
1812 ndlp->nlp_flag |= NLP_IGNR_REG_CMPL;
1814 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
1815 spin_unlock_irq(shost->host_lock);
1816 lpfc_disc_set_adisc(vport, ndlp);
1817 return ndlp->nlp_state;
1821 lpfc_rcv_plogi_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1822 void *arg, uint32_t evt)
1824 struct lpfc_iocbq *cmdiocb;
1826 cmdiocb = (struct lpfc_iocbq *) arg;
1828 lpfc_rcv_plogi(vport, ndlp, cmdiocb);
1829 return ndlp->nlp_state;
1833 lpfc_rcv_prli_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1834 void *arg, uint32_t evt)
1836 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1838 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
1839 return ndlp->nlp_state;
1843 lpfc_rcv_logo_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1844 void *arg, uint32_t evt)
1846 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1848 /* Software abort outstanding PRLI before sending acc */
1849 lpfc_els_abort(vport->phba, ndlp);
1851 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
1852 return ndlp->nlp_state;
1856 lpfc_rcv_padisc_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1857 void *arg, uint32_t evt)
1859 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1861 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
1862 return ndlp->nlp_state;
1865 /* This routine is envoked when we rcv a PRLO request from a nport
1866 * we are logged into. We should send back a PRLO rsp setting the
1868 * NEXT STATE = PRLI_ISSUE
1871 lpfc_rcv_prlo_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1872 void *arg, uint32_t evt)
1874 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1876 lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL);
1877 return ndlp->nlp_state;
1881 lpfc_cmpl_prli_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1882 void *arg, uint32_t evt)
1884 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1885 struct lpfc_iocbq *cmdiocb, *rspiocb;
1886 struct lpfc_hba *phba = vport->phba;
1889 struct lpfc_nvme_prli *nvpr;
1892 cmdiocb = (struct lpfc_iocbq *) arg;
1893 rspiocb = cmdiocb->context_un.rsp_iocb;
1895 /* A solicited PRLI is either FCP or NVME. The PRLI cmd/rsp
1896 * format is different so NULL the two PRLI types so that the
1897 * driver correctly gets the correct context.
1901 temp_ptr = lpfc_check_elscmpl_iocb(phba, cmdiocb, rspiocb);
1902 if (cmdiocb->iocb_flag & LPFC_PRLI_FCP_REQ)
1903 npr = (PRLI *) temp_ptr;
1904 else if (cmdiocb->iocb_flag & LPFC_PRLI_NVME_REQ)
1905 nvpr = (struct lpfc_nvme_prli *) temp_ptr;
1907 irsp = &rspiocb->iocb;
1908 if (irsp->ulpStatus) {
1909 if ((vport->port_type == LPFC_NPIV_PORT) &&
1910 vport->cfg_restrict_login) {
1914 /* When the rport rejected the FCP PRLI as unsupported.
1915 * This should only happen in Pt2Pt so an NVME PRLI
1916 * should be outstanding still.
1918 if (npr && ndlp->nlp_flag & NLP_FCP_PRLI_RJT) {
1919 ndlp->nlp_fc4_type &= ~NLP_FC4_FCP;
1923 /* The LS Req had some error. Don't let this be a
1926 if ((ndlp->fc4_prli_sent == 1) &&
1927 (ndlp->nlp_state == NLP_STE_PRLI_ISSUE) &&
1928 (ndlp->nlp_type & (NLP_FCP_TARGET | NLP_FCP_INITIATOR)))
1929 /* The FCP PRLI completed successfully but
1930 * the NVME PRLI failed. Since they are sent in
1931 * succession, allow the FCP to complete.
1935 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
1936 ndlp->nlp_type |= NLP_FCP_INITIATOR;
1937 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
1938 return ndlp->nlp_state;
1941 if (npr && (npr->acceptRspCode == PRLI_REQ_EXECUTED) &&
1942 (npr->prliType == PRLI_FCP_TYPE)) {
1943 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_DISC,
1944 "6028 FCP NPR PRLI Cmpl Init %d Target %d\n",
1947 if (npr->initiatorFunc)
1948 ndlp->nlp_type |= NLP_FCP_INITIATOR;
1949 if (npr->targetFunc) {
1950 ndlp->nlp_type |= NLP_FCP_TARGET;
1951 if (npr->writeXferRdyDis)
1952 ndlp->nlp_flag |= NLP_FIRSTBURST;
1955 ndlp->nlp_fcp_info |= NLP_FCP_2_DEVICE;
1958 (bf_get_be32(prli_acc_rsp_code, nvpr) ==
1959 PRLI_REQ_EXECUTED) &&
1960 (bf_get_be32(prli_type_code, nvpr) ==
1963 /* Complete setting up the remote ndlp personality. */
1964 if (bf_get_be32(prli_init, nvpr))
1965 ndlp->nlp_type |= NLP_NVME_INITIATOR;
1967 /* Target driver cannot solicit NVME FB. */
1968 if (bf_get_be32(prli_tgt, nvpr)) {
1969 /* Complete the nvme target roles. The transport
1970 * needs to know if the rport is capable of
1971 * discovery in addition to its role.
1973 ndlp->nlp_type |= NLP_NVME_TARGET;
1974 if (bf_get_be32(prli_disc, nvpr))
1975 ndlp->nlp_type |= NLP_NVME_DISCOVERY;
1976 if ((bf_get_be32(prli_fba, nvpr) == 1) &&
1977 (bf_get_be32(prli_fb_sz, nvpr) > 0) &&
1978 (phba->cfg_nvme_enable_fb) &&
1979 (!phba->nvmet_support)) {
1980 /* Both sides support FB. The target's first
1981 * burst size is a 512 byte encoded value.
1983 ndlp->nlp_flag |= NLP_FIRSTBURST;
1984 ndlp->nvme_fb_size = bf_get_be32(prli_fb_sz,
1989 if (bf_get_be32(prli_recov, nvpr))
1990 ndlp->nlp_fcp_info |= NLP_FCP_2_DEVICE;
1992 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_DISC,
1993 "6029 NVME PRLI Cmpl w1 x%08x "
1994 "w4 x%08x w5 x%08x flag x%x, "
1995 "fcp_info x%x nlp_type x%x\n",
1996 be32_to_cpu(nvpr->word1),
1997 be32_to_cpu(nvpr->word4),
1998 be32_to_cpu(nvpr->word5),
1999 ndlp->nlp_flag, ndlp->nlp_fcp_info,
2002 if (!(ndlp->nlp_type & NLP_FCP_TARGET) &&
2003 (vport->port_type == LPFC_NPIV_PORT) &&
2004 vport->cfg_restrict_login) {
2006 spin_lock_irq(shost->host_lock);
2007 ndlp->nlp_flag |= NLP_TARGET_REMOVE;
2008 spin_unlock_irq(shost->host_lock);
2009 lpfc_issue_els_logo(vport, ndlp, 0);
2011 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
2012 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
2013 return ndlp->nlp_state;
2017 /* The ndlp state cannot move to MAPPED or UNMAPPED before all PRLIs
2020 if (ndlp->fc4_prli_sent == 0) {
2021 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
2022 if (ndlp->nlp_type & (NLP_FCP_TARGET | NLP_NVME_TARGET))
2023 lpfc_nlp_set_state(vport, ndlp, NLP_STE_MAPPED_NODE);
2024 else if (ndlp->nlp_type &
2025 (NLP_FCP_INITIATOR | NLP_NVME_INITIATOR))
2026 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
2028 lpfc_printf_vlog(vport,
2030 "3067 PRLI's still outstanding "
2031 "on x%06x - count %d, Pend Node Mode "
2033 ndlp->nlp_DID, ndlp->fc4_prli_sent);
2035 return ndlp->nlp_state;
2038 /*! lpfc_device_rm_prli_issue
2049 * This routine is envoked when we a request to remove a nport we are in the
2050 * process of PRLIing. We should software abort outstanding prli, unreg
2051 * login, send a logout. We will change node state to UNUSED_NODE, put it
2052 * on plogi list so it can be freed when LOGO completes.
2057 lpfc_device_rm_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2058 void *arg, uint32_t evt)
2060 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2062 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
2063 spin_lock_irq(shost->host_lock);
2064 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
2065 spin_unlock_irq(shost->host_lock);
2066 return ndlp->nlp_state;
2068 /* software abort outstanding PLOGI */
2069 lpfc_els_abort(vport->phba, ndlp);
2071 lpfc_drop_node(vport, ndlp);
2072 return NLP_STE_FREED_NODE;
2077 /*! lpfc_device_recov_prli_issue
2088 * The routine is envoked when the state of a device is unknown, like
2089 * during a link down. We should remove the nodelist entry from the
2090 * unmapped list, issue a UNREG_LOGIN, do a software abort of the
2091 * outstanding PRLI command, then free the node entry.
2094 lpfc_device_recov_prli_issue(struct lpfc_vport *vport,
2095 struct lpfc_nodelist *ndlp,
2099 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2100 struct lpfc_hba *phba = vport->phba;
2102 /* Don't do anything that will mess up processing of the
2105 if (vport->fc_flag & FC_RSCN_DEFERRED)
2106 return ndlp->nlp_state;
2108 /* software abort outstanding PRLI */
2109 lpfc_els_abort(phba, ndlp);
2111 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
2112 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
2113 spin_lock_irq(shost->host_lock);
2114 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
2115 spin_unlock_irq(shost->host_lock);
2116 lpfc_disc_set_adisc(vport, ndlp);
2117 return ndlp->nlp_state;
2121 lpfc_rcv_plogi_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2122 void *arg, uint32_t evt)
2124 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *)arg;
2127 memset(&stat, 0, sizeof(struct ls_rjt));
2128 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
2129 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
2130 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
2131 return ndlp->nlp_state;
2135 lpfc_rcv_prli_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2136 void *arg, uint32_t evt)
2138 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *)arg;
2141 memset(&stat, 0, sizeof(struct ls_rjt));
2142 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
2143 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
2144 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
2145 return ndlp->nlp_state;
2149 lpfc_rcv_logo_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2150 void *arg, uint32_t evt)
2152 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2153 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *)arg;
2155 spin_lock_irq(shost->host_lock);
2156 ndlp->nlp_flag |= NLP_LOGO_ACC;
2157 spin_unlock_irq(shost->host_lock);
2158 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
2159 return ndlp->nlp_state;
2163 lpfc_rcv_padisc_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2164 void *arg, uint32_t evt)
2166 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *)arg;
2169 memset(&stat, 0, sizeof(struct ls_rjt));
2170 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
2171 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
2172 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
2173 return ndlp->nlp_state;
2177 lpfc_rcv_prlo_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2178 void *arg, uint32_t evt)
2180 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *)arg;
2183 memset(&stat, 0, sizeof(struct ls_rjt));
2184 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
2185 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
2186 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
2187 return ndlp->nlp_state;
2191 lpfc_cmpl_logo_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2192 void *arg, uint32_t evt)
2194 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2196 ndlp->nlp_prev_state = NLP_STE_LOGO_ISSUE;
2197 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
2198 spin_lock_irq(shost->host_lock);
2199 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
2200 spin_unlock_irq(shost->host_lock);
2201 lpfc_disc_set_adisc(vport, ndlp);
2202 return ndlp->nlp_state;
2206 lpfc_device_rm_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2207 void *arg, uint32_t evt)
2210 * DevLoss has timed out and is calling for Device Remove.
2211 * In this case, abort the LOGO and cleanup the ndlp
2214 lpfc_unreg_rpi(vport, ndlp);
2215 /* software abort outstanding PLOGI */
2216 lpfc_els_abort(vport->phba, ndlp);
2217 lpfc_drop_node(vport, ndlp);
2218 return NLP_STE_FREED_NODE;
2222 lpfc_device_recov_logo_issue(struct lpfc_vport *vport,
2223 struct lpfc_nodelist *ndlp,
2224 void *arg, uint32_t evt)
2227 * Device Recovery events have no meaning for a node with a LOGO
2228 * outstanding. The LOGO has to complete first and handle the
2229 * node from that point.
2231 return ndlp->nlp_state;
2235 lpfc_rcv_plogi_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2236 void *arg, uint32_t evt)
2238 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2240 lpfc_rcv_plogi(vport, ndlp, cmdiocb);
2241 return ndlp->nlp_state;
2245 lpfc_rcv_prli_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2246 void *arg, uint32_t evt)
2248 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2250 lpfc_rcv_prli(vport, ndlp, cmdiocb);
2251 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
2252 return ndlp->nlp_state;
2256 lpfc_rcv_logo_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2257 void *arg, uint32_t evt)
2259 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2261 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
2262 return ndlp->nlp_state;
2266 lpfc_rcv_padisc_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2267 void *arg, uint32_t evt)
2269 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2271 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
2272 return ndlp->nlp_state;
2276 lpfc_rcv_prlo_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2277 void *arg, uint32_t evt)
2279 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2281 lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL);
2282 return ndlp->nlp_state;
2286 lpfc_device_recov_unmap_node(struct lpfc_vport *vport,
2287 struct lpfc_nodelist *ndlp,
2291 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2293 ndlp->nlp_prev_state = NLP_STE_UNMAPPED_NODE;
2294 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
2295 spin_lock_irq(shost->host_lock);
2296 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
2297 spin_unlock_irq(shost->host_lock);
2298 lpfc_disc_set_adisc(vport, ndlp);
2300 return ndlp->nlp_state;
2304 lpfc_rcv_plogi_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2305 void *arg, uint32_t evt)
2307 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2309 lpfc_rcv_plogi(vport, ndlp, cmdiocb);
2310 return ndlp->nlp_state;
2314 lpfc_rcv_prli_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2315 void *arg, uint32_t evt)
2317 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2319 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
2320 return ndlp->nlp_state;
2324 lpfc_rcv_logo_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2325 void *arg, uint32_t evt)
2327 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2329 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
2330 return ndlp->nlp_state;
2334 lpfc_rcv_padisc_mapped_node(struct lpfc_vport *vport,
2335 struct lpfc_nodelist *ndlp,
2336 void *arg, uint32_t evt)
2338 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2340 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
2341 return ndlp->nlp_state;
2345 lpfc_rcv_prlo_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2346 void *arg, uint32_t evt)
2348 struct lpfc_hba *phba = vport->phba;
2349 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2351 /* flush the target */
2352 lpfc_sli_abort_iocb(vport, &phba->sli.sli3_ring[LPFC_FCP_RING],
2353 ndlp->nlp_sid, 0, LPFC_CTX_TGT);
2355 /* Treat like rcv logo */
2356 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_PRLO);
2357 return ndlp->nlp_state;
2361 lpfc_device_recov_mapped_node(struct lpfc_vport *vport,
2362 struct lpfc_nodelist *ndlp,
2366 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2368 ndlp->nlp_prev_state = NLP_STE_MAPPED_NODE;
2369 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
2370 spin_lock_irq(shost->host_lock);
2371 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
2372 spin_unlock_irq(shost->host_lock);
2373 lpfc_disc_set_adisc(vport, ndlp);
2374 return ndlp->nlp_state;
2378 lpfc_rcv_plogi_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2379 void *arg, uint32_t evt)
2381 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2382 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2384 /* Ignore PLOGI if we have an outstanding LOGO */
2385 if (ndlp->nlp_flag & (NLP_LOGO_SND | NLP_LOGO_ACC))
2386 return ndlp->nlp_state;
2387 if (lpfc_rcv_plogi(vport, ndlp, cmdiocb)) {
2388 lpfc_cancel_retry_delay_tmo(vport, ndlp);
2389 spin_lock_irq(shost->host_lock);
2390 ndlp->nlp_flag &= ~(NLP_NPR_ADISC | NLP_NPR_2B_DISC);
2391 spin_unlock_irq(shost->host_lock);
2392 } else if (!(ndlp->nlp_flag & NLP_NPR_2B_DISC)) {
2393 /* send PLOGI immediately, move to PLOGI issue state */
2394 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
2395 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
2396 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
2397 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
2400 return ndlp->nlp_state;
2404 lpfc_rcv_prli_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2405 void *arg, uint32_t evt)
2407 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2408 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2411 memset(&stat, 0, sizeof (struct ls_rjt));
2412 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
2413 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
2414 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
2416 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
2417 if (ndlp->nlp_flag & NLP_NPR_ADISC) {
2418 spin_lock_irq(shost->host_lock);
2419 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
2420 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
2421 spin_unlock_irq(shost->host_lock);
2422 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
2423 lpfc_issue_els_adisc(vport, ndlp, 0);
2425 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
2426 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
2427 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
2430 return ndlp->nlp_state;
2434 lpfc_rcv_logo_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2435 void *arg, uint32_t evt)
2437 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2439 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
2440 return ndlp->nlp_state;
2444 lpfc_rcv_padisc_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2445 void *arg, uint32_t evt)
2447 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2449 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
2451 * Do not start discovery if discovery is about to start
2452 * or discovery in progress for this node. Starting discovery
2453 * here will affect the counting of discovery threads.
2455 if (!(ndlp->nlp_flag & NLP_DELAY_TMO) &&
2456 !(ndlp->nlp_flag & NLP_NPR_2B_DISC)) {
2457 if (ndlp->nlp_flag & NLP_NPR_ADISC) {
2458 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
2459 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
2460 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
2461 lpfc_issue_els_adisc(vport, ndlp, 0);
2463 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
2464 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
2465 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
2468 return ndlp->nlp_state;
2472 lpfc_rcv_prlo_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2473 void *arg, uint32_t evt)
2475 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2476 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2478 spin_lock_irq(shost->host_lock);
2479 ndlp->nlp_flag |= NLP_LOGO_ACC;
2480 spin_unlock_irq(shost->host_lock);
2482 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
2484 if ((ndlp->nlp_flag & NLP_DELAY_TMO) == 0) {
2485 mod_timer(&ndlp->nlp_delayfunc,
2486 jiffies + msecs_to_jiffies(1000 * 1));
2487 spin_lock_irq(shost->host_lock);
2488 ndlp->nlp_flag |= NLP_DELAY_TMO;
2489 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
2490 spin_unlock_irq(shost->host_lock);
2491 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
2493 spin_lock_irq(shost->host_lock);
2494 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
2495 spin_unlock_irq(shost->host_lock);
2497 return ndlp->nlp_state;
2501 lpfc_cmpl_plogi_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2502 void *arg, uint32_t evt)
2504 struct lpfc_iocbq *cmdiocb, *rspiocb;
2506 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2508 cmdiocb = (struct lpfc_iocbq *) arg;
2509 rspiocb = cmdiocb->context_un.rsp_iocb;
2511 irsp = &rspiocb->iocb;
2512 if (irsp->ulpStatus) {
2513 spin_lock_irq(shost->host_lock);
2514 ndlp->nlp_flag |= NLP_DEFER_RM;
2515 spin_unlock_irq(shost->host_lock);
2516 return NLP_STE_FREED_NODE;
2518 return ndlp->nlp_state;
2522 lpfc_cmpl_prli_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2523 void *arg, uint32_t evt)
2525 struct lpfc_iocbq *cmdiocb, *rspiocb;
2528 cmdiocb = (struct lpfc_iocbq *) arg;
2529 rspiocb = cmdiocb->context_un.rsp_iocb;
2531 irsp = &rspiocb->iocb;
2532 if (irsp->ulpStatus && (ndlp->nlp_flag & NLP_NODEV_REMOVE)) {
2533 lpfc_drop_node(vport, ndlp);
2534 return NLP_STE_FREED_NODE;
2536 return ndlp->nlp_state;
2540 lpfc_cmpl_logo_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2541 void *arg, uint32_t evt)
2543 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2545 /* For the fabric port just clear the fc flags. */
2546 if (ndlp->nlp_DID == Fabric_DID) {
2547 spin_lock_irq(shost->host_lock);
2548 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
2549 spin_unlock_irq(shost->host_lock);
2551 lpfc_unreg_rpi(vport, ndlp);
2552 return ndlp->nlp_state;
2556 lpfc_cmpl_adisc_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2557 void *arg, uint32_t evt)
2559 struct lpfc_iocbq *cmdiocb, *rspiocb;
2562 cmdiocb = (struct lpfc_iocbq *) arg;
2563 rspiocb = cmdiocb->context_un.rsp_iocb;
2565 irsp = &rspiocb->iocb;
2566 if (irsp->ulpStatus && (ndlp->nlp_flag & NLP_NODEV_REMOVE)) {
2567 lpfc_drop_node(vport, ndlp);
2568 return NLP_STE_FREED_NODE;
2570 return ndlp->nlp_state;
2574 lpfc_cmpl_reglogin_npr_node(struct lpfc_vport *vport,
2575 struct lpfc_nodelist *ndlp,
2576 void *arg, uint32_t evt)
2578 LPFC_MBOXQ_t *pmb = (LPFC_MBOXQ_t *) arg;
2579 MAILBOX_t *mb = &pmb->u.mb;
2581 if (!mb->mbxStatus) {
2582 /* SLI4 ports have preallocated logical rpis. */
2583 if (vport->phba->sli_rev < LPFC_SLI_REV4)
2584 ndlp->nlp_rpi = mb->un.varWords[0];
2585 ndlp->nlp_flag |= NLP_RPI_REGISTERED;
2586 if (ndlp->nlp_flag & NLP_LOGO_ACC) {
2587 lpfc_unreg_rpi(vport, ndlp);
2590 if (ndlp->nlp_flag & NLP_NODEV_REMOVE) {
2591 lpfc_drop_node(vport, ndlp);
2592 return NLP_STE_FREED_NODE;
2595 return ndlp->nlp_state;
2599 lpfc_device_rm_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2600 void *arg, uint32_t evt)
2602 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2604 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
2605 spin_lock_irq(shost->host_lock);
2606 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
2607 spin_unlock_irq(shost->host_lock);
2608 return ndlp->nlp_state;
2610 lpfc_drop_node(vport, ndlp);
2611 return NLP_STE_FREED_NODE;
2615 lpfc_device_recov_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2616 void *arg, uint32_t evt)
2618 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2620 /* Don't do anything that will mess up processing of the
2623 if (vport->fc_flag & FC_RSCN_DEFERRED)
2624 return ndlp->nlp_state;
2626 lpfc_cancel_retry_delay_tmo(vport, ndlp);
2627 spin_lock_irq(shost->host_lock);
2628 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
2629 spin_unlock_irq(shost->host_lock);
2630 return ndlp->nlp_state;
2634 /* This next section defines the NPort Discovery State Machine */
2636 /* There are 4 different double linked lists nodelist entries can reside on.
2637 * The plogi list and adisc list are used when Link Up discovery or RSCN
2638 * processing is needed. Each list holds the nodes that we will send PLOGI
2639 * or ADISC on. These lists will keep track of what nodes will be effected
2640 * by an RSCN, or a Link Up (Typically, all nodes are effected on Link Up).
2641 * The unmapped_list will contain all nodes that we have successfully logged
2642 * into at the Fibre Channel level. The mapped_list will contain all nodes
2643 * that are mapped FCP targets.
2646 * The bind list is a list of undiscovered (potentially non-existent) nodes
2647 * that we have saved binding information on. This information is used when
2648 * nodes transition from the unmapped to the mapped list.
2650 /* For UNUSED_NODE state, the node has just been allocated .
2651 * For PLOGI_ISSUE and REG_LOGIN_ISSUE, the node is on
2652 * the PLOGI list. For REG_LOGIN_COMPL, the node is taken off the PLOGI list
2653 * and put on the unmapped list. For ADISC processing, the node is taken off
2654 * the ADISC list and placed on either the mapped or unmapped list (depending
2655 * on its previous state). Once on the unmapped list, a PRLI is issued and the
2656 * state changed to PRLI_ISSUE. When the PRLI completion occurs, the state is
2657 * changed to UNMAPPED_NODE. If the completion indicates a mapped
2658 * node, the node is taken off the unmapped list. The binding list is checked
2659 * for a valid binding, or a binding is automatically assigned. If binding
2660 * assignment is unsuccessful, the node is left on the unmapped list. If
2661 * binding assignment is successful, the associated binding list entry (if
2662 * any) is removed, and the node is placed on the mapped list.
2665 * For a Link Down, all nodes on the ADISC, PLOGI, unmapped or mapped
2666 * lists will receive a DEVICE_RECOVERY event. If the linkdown or devloss timers
2667 * expire, all effected nodes will receive a DEVICE_RM event.
2670 * For a Link Up or RSCN, all nodes will move from the mapped / unmapped lists
2671 * to either the ADISC or PLOGI list. After a Nameserver query or ALPA loopmap
2672 * check, additional nodes may be added or removed (via DEVICE_RM) to / from
2673 * the PLOGI or ADISC lists. Once the PLOGI and ADISC lists are populated,
2674 * we will first process the ADISC list. 32 entries are processed initially and
2675 * ADISC is initited for each one. Completions / Events for each node are
2676 * funnelled thru the state machine. As each node finishes ADISC processing, it
2677 * starts ADISC for any nodes waiting for ADISC processing. If no nodes are
2678 * waiting, and the ADISC list count is identically 0, then we are done. For
2679 * Link Up discovery, since all nodes on the PLOGI list are UNREG_LOGIN'ed, we
2680 * can issue a CLEAR_LA and reenable Link Events. Next we will process the PLOGI
2681 * list. 32 entries are processed initially and PLOGI is initited for each one.
2682 * Completions / Events for each node are funnelled thru the state machine. As
2683 * each node finishes PLOGI processing, it starts PLOGI for any nodes waiting
2684 * for PLOGI processing. If no nodes are waiting, and the PLOGI list count is
2685 * indentically 0, then we are done. We have now completed discovery / RSCN
2686 * handling. Upon completion, ALL nodes should be on either the mapped or
2690 static uint32_t (*lpfc_disc_action[NLP_STE_MAX_STATE * NLP_EVT_MAX_EVENT])
2691 (struct lpfc_vport *, struct lpfc_nodelist *, void *, uint32_t) = {
2692 /* Action routine Event Current State */
2693 lpfc_rcv_plogi_unused_node, /* RCV_PLOGI UNUSED_NODE */
2694 lpfc_rcv_els_unused_node, /* RCV_PRLI */
2695 lpfc_rcv_logo_unused_node, /* RCV_LOGO */
2696 lpfc_rcv_els_unused_node, /* RCV_ADISC */
2697 lpfc_rcv_els_unused_node, /* RCV_PDISC */
2698 lpfc_rcv_els_unused_node, /* RCV_PRLO */
2699 lpfc_disc_illegal, /* CMPL_PLOGI */
2700 lpfc_disc_illegal, /* CMPL_PRLI */
2701 lpfc_cmpl_logo_unused_node, /* CMPL_LOGO */
2702 lpfc_disc_illegal, /* CMPL_ADISC */
2703 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2704 lpfc_device_rm_unused_node, /* DEVICE_RM */
2705 lpfc_device_recov_unused_node, /* DEVICE_RECOVERY */
2707 lpfc_rcv_plogi_plogi_issue, /* RCV_PLOGI PLOGI_ISSUE */
2708 lpfc_rcv_prli_plogi_issue, /* RCV_PRLI */
2709 lpfc_rcv_logo_plogi_issue, /* RCV_LOGO */
2710 lpfc_rcv_els_plogi_issue, /* RCV_ADISC */
2711 lpfc_rcv_els_plogi_issue, /* RCV_PDISC */
2712 lpfc_rcv_els_plogi_issue, /* RCV_PRLO */
2713 lpfc_cmpl_plogi_plogi_issue, /* CMPL_PLOGI */
2714 lpfc_disc_illegal, /* CMPL_PRLI */
2715 lpfc_cmpl_logo_plogi_issue, /* CMPL_LOGO */
2716 lpfc_disc_illegal, /* CMPL_ADISC */
2717 lpfc_cmpl_reglogin_plogi_issue,/* CMPL_REG_LOGIN */
2718 lpfc_device_rm_plogi_issue, /* DEVICE_RM */
2719 lpfc_device_recov_plogi_issue, /* DEVICE_RECOVERY */
2721 lpfc_rcv_plogi_adisc_issue, /* RCV_PLOGI ADISC_ISSUE */
2722 lpfc_rcv_prli_adisc_issue, /* RCV_PRLI */
2723 lpfc_rcv_logo_adisc_issue, /* RCV_LOGO */
2724 lpfc_rcv_padisc_adisc_issue, /* RCV_ADISC */
2725 lpfc_rcv_padisc_adisc_issue, /* RCV_PDISC */
2726 lpfc_rcv_prlo_adisc_issue, /* RCV_PRLO */
2727 lpfc_disc_illegal, /* CMPL_PLOGI */
2728 lpfc_disc_illegal, /* CMPL_PRLI */
2729 lpfc_disc_illegal, /* CMPL_LOGO */
2730 lpfc_cmpl_adisc_adisc_issue, /* CMPL_ADISC */
2731 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2732 lpfc_device_rm_adisc_issue, /* DEVICE_RM */
2733 lpfc_device_recov_adisc_issue, /* DEVICE_RECOVERY */
2735 lpfc_rcv_plogi_reglogin_issue, /* RCV_PLOGI REG_LOGIN_ISSUE */
2736 lpfc_rcv_prli_reglogin_issue, /* RCV_PLOGI */
2737 lpfc_rcv_logo_reglogin_issue, /* RCV_LOGO */
2738 lpfc_rcv_padisc_reglogin_issue, /* RCV_ADISC */
2739 lpfc_rcv_padisc_reglogin_issue, /* RCV_PDISC */
2740 lpfc_rcv_prlo_reglogin_issue, /* RCV_PRLO */
2741 lpfc_cmpl_plogi_illegal, /* CMPL_PLOGI */
2742 lpfc_disc_illegal, /* CMPL_PRLI */
2743 lpfc_disc_illegal, /* CMPL_LOGO */
2744 lpfc_disc_illegal, /* CMPL_ADISC */
2745 lpfc_cmpl_reglogin_reglogin_issue,/* CMPL_REG_LOGIN */
2746 lpfc_device_rm_reglogin_issue, /* DEVICE_RM */
2747 lpfc_device_recov_reglogin_issue,/* DEVICE_RECOVERY */
2749 lpfc_rcv_plogi_prli_issue, /* RCV_PLOGI PRLI_ISSUE */
2750 lpfc_rcv_prli_prli_issue, /* RCV_PRLI */
2751 lpfc_rcv_logo_prli_issue, /* RCV_LOGO */
2752 lpfc_rcv_padisc_prli_issue, /* RCV_ADISC */
2753 lpfc_rcv_padisc_prli_issue, /* RCV_PDISC */
2754 lpfc_rcv_prlo_prli_issue, /* RCV_PRLO */
2755 lpfc_cmpl_plogi_illegal, /* CMPL_PLOGI */
2756 lpfc_cmpl_prli_prli_issue, /* CMPL_PRLI */
2757 lpfc_disc_illegal, /* CMPL_LOGO */
2758 lpfc_disc_illegal, /* CMPL_ADISC */
2759 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2760 lpfc_device_rm_prli_issue, /* DEVICE_RM */
2761 lpfc_device_recov_prli_issue, /* DEVICE_RECOVERY */
2763 lpfc_rcv_plogi_logo_issue, /* RCV_PLOGI LOGO_ISSUE */
2764 lpfc_rcv_prli_logo_issue, /* RCV_PRLI */
2765 lpfc_rcv_logo_logo_issue, /* RCV_LOGO */
2766 lpfc_rcv_padisc_logo_issue, /* RCV_ADISC */
2767 lpfc_rcv_padisc_logo_issue, /* RCV_PDISC */
2768 lpfc_rcv_prlo_logo_issue, /* RCV_PRLO */
2769 lpfc_cmpl_plogi_illegal, /* CMPL_PLOGI */
2770 lpfc_disc_illegal, /* CMPL_PRLI */
2771 lpfc_cmpl_logo_logo_issue, /* CMPL_LOGO */
2772 lpfc_disc_illegal, /* CMPL_ADISC */
2773 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2774 lpfc_device_rm_logo_issue, /* DEVICE_RM */
2775 lpfc_device_recov_logo_issue, /* DEVICE_RECOVERY */
2777 lpfc_rcv_plogi_unmap_node, /* RCV_PLOGI UNMAPPED_NODE */
2778 lpfc_rcv_prli_unmap_node, /* RCV_PRLI */
2779 lpfc_rcv_logo_unmap_node, /* RCV_LOGO */
2780 lpfc_rcv_padisc_unmap_node, /* RCV_ADISC */
2781 lpfc_rcv_padisc_unmap_node, /* RCV_PDISC */
2782 lpfc_rcv_prlo_unmap_node, /* RCV_PRLO */
2783 lpfc_disc_illegal, /* CMPL_PLOGI */
2784 lpfc_disc_illegal, /* CMPL_PRLI */
2785 lpfc_disc_illegal, /* CMPL_LOGO */
2786 lpfc_disc_illegal, /* CMPL_ADISC */
2787 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2788 lpfc_disc_illegal, /* DEVICE_RM */
2789 lpfc_device_recov_unmap_node, /* DEVICE_RECOVERY */
2791 lpfc_rcv_plogi_mapped_node, /* RCV_PLOGI MAPPED_NODE */
2792 lpfc_rcv_prli_mapped_node, /* RCV_PRLI */
2793 lpfc_rcv_logo_mapped_node, /* RCV_LOGO */
2794 lpfc_rcv_padisc_mapped_node, /* RCV_ADISC */
2795 lpfc_rcv_padisc_mapped_node, /* RCV_PDISC */
2796 lpfc_rcv_prlo_mapped_node, /* RCV_PRLO */
2797 lpfc_disc_illegal, /* CMPL_PLOGI */
2798 lpfc_disc_illegal, /* CMPL_PRLI */
2799 lpfc_disc_illegal, /* CMPL_LOGO */
2800 lpfc_disc_illegal, /* CMPL_ADISC */
2801 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2802 lpfc_disc_illegal, /* DEVICE_RM */
2803 lpfc_device_recov_mapped_node, /* DEVICE_RECOVERY */
2805 lpfc_rcv_plogi_npr_node, /* RCV_PLOGI NPR_NODE */
2806 lpfc_rcv_prli_npr_node, /* RCV_PRLI */
2807 lpfc_rcv_logo_npr_node, /* RCV_LOGO */
2808 lpfc_rcv_padisc_npr_node, /* RCV_ADISC */
2809 lpfc_rcv_padisc_npr_node, /* RCV_PDISC */
2810 lpfc_rcv_prlo_npr_node, /* RCV_PRLO */
2811 lpfc_cmpl_plogi_npr_node, /* CMPL_PLOGI */
2812 lpfc_cmpl_prli_npr_node, /* CMPL_PRLI */
2813 lpfc_cmpl_logo_npr_node, /* CMPL_LOGO */
2814 lpfc_cmpl_adisc_npr_node, /* CMPL_ADISC */
2815 lpfc_cmpl_reglogin_npr_node, /* CMPL_REG_LOGIN */
2816 lpfc_device_rm_npr_node, /* DEVICE_RM */
2817 lpfc_device_recov_npr_node, /* DEVICE_RECOVERY */
2821 lpfc_disc_state_machine(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2822 void *arg, uint32_t evt)
2824 uint32_t cur_state, rc;
2825 uint32_t(*func) (struct lpfc_vport *, struct lpfc_nodelist *, void *,
2827 uint32_t got_ndlp = 0;
2829 if (lpfc_nlp_get(ndlp))
2832 cur_state = ndlp->nlp_state;
2834 /* DSM in event <evt> on NPort <nlp_DID> in state <cur_state> */
2835 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2836 "0211 DSM in event x%x on NPort x%x in "
2837 "state %d Data: x%x x%x\n",
2838 evt, ndlp->nlp_DID, cur_state,
2839 ndlp->nlp_flag, ndlp->nlp_fc4_type);
2841 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_DSM,
2842 "DSM in: evt:%d ste:%d did:x%x",
2843 evt, cur_state, ndlp->nlp_DID);
2845 func = lpfc_disc_action[(cur_state * NLP_EVT_MAX_EVENT) + evt];
2846 rc = (func) (vport, ndlp, arg, evt);
2848 /* DSM out state <rc> on NPort <nlp_DID> */
2850 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2851 "0212 DSM out state %d on NPort x%x Data: x%x\n",
2852 rc, ndlp->nlp_DID, ndlp->nlp_flag);
2854 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_DSM,
2855 "DSM out: ste:%d did:x%x flg:x%x",
2856 rc, ndlp->nlp_DID, ndlp->nlp_flag);
2857 /* Decrement the ndlp reference count held for this function */
2860 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2861 "0213 DSM out state %d on NPort free\n", rc);
2863 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_DSM,
2864 "DSM out: ste:%d did:x%x flg:x%x",