PageRenderTime 107ms CodeModel.GetById 15ms app.highlight 77ms RepoModel.GetById 1ms app.codeStats 1ms

/drivers/scsi/lpfc/lpfc_nportdisc.c

http://github.com/mirrors/linux
C | 3148 lines | 2316 code | 380 blank | 452 comment | 360 complexity | 5452b82a4b12fa7b6c6ff53dbee425c0 MD5 | raw file

Large files files are truncated, but you can click here to view the full file

   1/*******************************************************************
   2 * This file is part of the Emulex Linux Device Driver for         *
   3 * Fibre Channel Host Bus Adapters.                                *
   4 * Copyright (C) 2017-2019 Broadcom. All Rights Reserved. The term *
   5 * “Broadcom” refers to Broadcom Inc. and/or its subsidiaries.     *
   6 * Copyright (C) 2004-2016 Emulex.  All rights reserved.           *
   7 * EMULEX and SLI are trademarks of Emulex.                        *
   8 * www.broadcom.com                                                *
   9 * Portions Copyright (C) 2004-2005 Christoph Hellwig              *
  10 *                                                                 *
  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 *******************************************************************/
  23
  24#include <linux/blkdev.h>
  25#include <linux/pci.h>
  26#include <linux/slab.h>
  27#include <linux/interrupt.h>
  28
  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>
  34
  35#include <linux/nvme-fc-driver.h>
  36
  37#include "lpfc_hw4.h"
  38#include "lpfc_hw.h"
  39#include "lpfc_sli.h"
  40#include "lpfc_sli4.h"
  41#include "lpfc_nl.h"
  42#include "lpfc_disc.h"
  43#include "lpfc.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"
  50
  51
  52/* Called to verify a rcv'ed ADISC was intended for us. */
  53static int
  54lpfc_check_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  55		 struct lpfc_name *nn, struct lpfc_name *pn)
  56{
  57	/* First, we MUST have a RPI registered */
  58	if (!(ndlp->nlp_flag & NLP_RPI_REGISTERED))
  59		return 0;
  60
  61	/* Compare the ADISC rsp WWNN / WWPN matches our internal node
  62	 * table entry for that node.
  63	 */
  64	if (memcmp(nn, &ndlp->nlp_nodename, sizeof (struct lpfc_name)))
  65		return 0;
  66
  67	if (memcmp(pn, &ndlp->nlp_portname, sizeof (struct lpfc_name)))
  68		return 0;
  69
  70	/* we match, return success */
  71	return 1;
  72}
  73
  74int
  75lpfc_check_sparm(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  76		 struct serv_parm *sp, uint32_t class, int flogi)
  77{
  78	volatile struct serv_parm *hsp = &vport->fc_sparam;
  79	uint16_t hsp_value, ssp_value = 0;
  80
  81	/*
  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.
  87	 */
  88	if (sp->cls1.classValid) {
  89		if (!flogi) {
  90			hsp_value = ((hsp->cls1.rcvDataSizeMsb << 8) |
  91				     hsp->cls1.rcvDataSizeLsb);
  92			ssp_value = ((sp->cls1.rcvDataSizeMsb << 8) |
  93				     sp->cls1.rcvDataSizeLsb);
  94			if (!ssp_value)
  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;
 101			}
 102		}
 103	} else if (class == CLASS1)
 104		goto bad_service_param;
 105	if (sp->cls2.classValid) {
 106		if (!flogi) {
 107			hsp_value = ((hsp->cls2.rcvDataSizeMsb << 8) |
 108				     hsp->cls2.rcvDataSizeLsb);
 109			ssp_value = ((sp->cls2.rcvDataSizeMsb << 8) |
 110				     sp->cls2.rcvDataSizeLsb);
 111			if (!ssp_value)
 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;
 118			}
 119		}
 120	} else if (class == CLASS2)
 121		goto bad_service_param;
 122	if (sp->cls3.classValid) {
 123		if (!flogi) {
 124			hsp_value = ((hsp->cls3.rcvDataSizeMsb << 8) |
 125				     hsp->cls3.rcvDataSizeLsb);
 126			ssp_value = ((sp->cls3.rcvDataSizeMsb << 8) |
 127				     sp->cls3.rcvDataSizeLsb);
 128			if (!ssp_value)
 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;
 135			}
 136		}
 137	} else if (class == CLASS3)
 138		goto bad_service_param;
 139
 140	/*
 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.
 144	 */
 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);
 151	}
 152
 153	memcpy(&ndlp->nlp_nodename, &sp->nodeName, sizeof (struct lpfc_name));
 154	memcpy(&ndlp->nlp_portname, &sp->portName, sizeof (struct lpfc_name));
 155	return 1;
 156bad_service_param:
 157	lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
 158			 "0207 Device %x "
 159			 "(%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x) sent "
 160			 "invalid service parameters.  Ignoring device.\n",
 161			 ndlp->nlp_DID,
 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]);
 166	return 0;
 167}
 168
 169static void *
 170lpfc_check_elscmpl_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
 171			struct lpfc_iocbq *rspiocb)
 172{
 173	struct lpfc_dmabuf *pcmd, *prsp;
 174	uint32_t *lp;
 175	void     *ptr = NULL;
 176	IOCB_t   *irsp;
 177
 178	irsp = &rspiocb->iocb;
 179	pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
 180
 181	/* For lpfc_els_abort, context2 could be zero'ed to delay
 182	 * freeing associated memory till after ABTS completes.
 183	 */
 184	if (pcmd) {
 185		prsp =  list_get_first(&pcmd->list, struct lpfc_dmabuf,
 186				       list);
 187		if (prsp) {
 188			lp = (uint32_t *) prsp->virt;
 189			ptr = (void *)((uint8_t *)lp + sizeof(uint32_t));
 190		}
 191	} else {
 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;
 196		}
 197		ptr = NULL;
 198	}
 199	return ptr;
 200}
 201
 202
 203
 204/*
 205 * Free resources / clean up outstanding I/Os
 206 * associated with a LPFC_NODELIST entry. This
 207 * routine effectively results in a "software abort".
 208 */
 209void
 210lpfc_els_abort(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp)
 211{
 212	LIST_HEAD(abort_list);
 213	struct lpfc_sli_ring *pring;
 214	struct lpfc_iocbq *iocb, *next_iocb;
 215
 216	pring = lpfc_phba_elsring(phba);
 217
 218	/* In case of error recovery path, we might have a NULL pring here */
 219	if (unlikely(!pring))
 220		return;
 221
 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,
 227			 ndlp->nlp_rpi);
 228	/* Clean up all fabric IOs first.*/
 229	lpfc_fabric_abort_nport(ndlp);
 230
 231	/*
 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.
 235	 */
 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);
 243	}
 244	if (phba->sli_rev == LPFC_SLI_REV4)
 245		spin_unlock(&pring->ring_lock);
 246	spin_unlock_irq(&phba->hbalock);
 247
 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);
 254	}
 255
 256	INIT_LIST_HEAD(&abort_list);
 257
 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);
 262
 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);
 268		}
 269	}
 270
 271	if (phba->sli_rev == LPFC_SLI_REV4)
 272		spin_unlock(&pring->ring_lock);
 273	spin_unlock_irq(&phba->hbalock);
 274
 275	/* Cancel all the IOCBs from the completions list */
 276	lpfc_sli_cancel_iocbs(phba, &abort_list,
 277			      IOSTAT_LOCAL_REJECT, IOERR_SLI_ABORTED);
 278
 279	lpfc_cancel_retry_delay_tmo(phba->pport, ndlp);
 280}
 281
 282/* lpfc_defer_pt2pt_acc - Complete SLI3 pt2pt processing on link up
 283 * @phba: pointer to lpfc hba data structure.
 284 * @link_mbox: pointer to CONFIG_LINK mailbox object
 285 *
 286 * This routine is only called if we are SLI3, direct connect pt2pt
 287 * mode and the remote NPort issues the PLOGI after link up.
 288 */
 289static void
 290lpfc_defer_pt2pt_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *link_mbox)
 291{
 292	LPFC_MBOXQ_t *login_mbox;
 293	MAILBOX_t *mb = &link_mbox->u.mb;
 294	struct lpfc_iocbq *save_iocb;
 295	struct lpfc_nodelist *ndlp;
 296	int rc;
 297
 298	ndlp = link_mbox->ctx_ndlp;
 299	login_mbox = link_mbox->context3;
 300	save_iocb = login_mbox->context3;
 301	link_mbox->context3 = NULL;
 302	login_mbox->context3 = NULL;
 303
 304	/* Check for CONFIG_LINK error */
 305	if (mb->mbxStatus) {
 306		lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
 307				"4575 CONFIG_LINK fails pt2pt discovery: %x\n",
 308				mb->mbxStatus);
 309		mempool_free(login_mbox, phba->mbox_mem_pool);
 310		mempool_free(link_mbox, phba->mbox_mem_pool);
 311		kfree(save_iocb);
 312		return;
 313	}
 314
 315	/* Now that CONFIG_LINK completed, and our SID is configured,
 316	 * we can now proceed with sending the PLOGI ACC.
 317	 */
 318	rc = lpfc_els_rsp_acc(link_mbox->vport, ELS_CMD_PLOGI,
 319			      save_iocb, ndlp, login_mbox);
 320	if (rc) {
 321		lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
 322				"4576 PLOGI ACC fails pt2pt discovery: %x\n",
 323				rc);
 324		mempool_free(login_mbox, phba->mbox_mem_pool);
 325	}
 326
 327	mempool_free(link_mbox, phba->mbox_mem_pool);
 328	kfree(save_iocb);
 329}
 330
 331/**
 332 * lpfc_defer_tgt_acc - Progress SLI4 target rcv PLOGI handler
 333 * @phba: Pointer to HBA context object.
 334 * @pmb: Pointer to mailbox object.
 335 *
 336 * This function provides the unreg rpi mailbox completion handler for a tgt.
 337 * The routine frees the memory resources associated with the completed
 338 * mailbox command and transmits the ELS ACC.
 339 *
 340 * This routine is only called if we are SLI4, acting in target
 341 * mode and the remote NPort issues the PLOGI after link up.
 342 **/
 343static void
 344lpfc_defer_acc_rsp(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
 345{
 346	struct lpfc_vport *vport = pmb->vport;
 347	struct lpfc_nodelist *ndlp = pmb->ctx_ndlp;
 348	LPFC_MBOXQ_t *mbox = pmb->context3;
 349	struct lpfc_iocbq *piocb = NULL;
 350	int rc;
 351
 352	if (mbox) {
 353		pmb->context3 = NULL;
 354		piocb = mbox->context3;
 355		mbox->context3 = NULL;
 356	}
 357
 358	/*
 359	 * Complete the unreg rpi mbx request, and update flags.
 360	 * This will also restart any deferred events.
 361	 */
 362	lpfc_nlp_get(ndlp);
 363	lpfc_sli4_unreg_rpi_cmpl_clr(phba, pmb);
 364
 365	if (!piocb) {
 366		lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY | LOG_ELS,
 367				 "4578 PLOGI ACC fail\n");
 368		if (mbox)
 369			mempool_free(mbox, phba->mbox_mem_pool);
 370		goto out;
 371	}
 372
 373	rc = lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, piocb, ndlp, mbox);
 374	if (rc) {
 375		lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY | LOG_ELS,
 376				 "4579 PLOGI ACC fail %x\n", rc);
 377		if (mbox)
 378			mempool_free(mbox, phba->mbox_mem_pool);
 379	}
 380	kfree(piocb);
 381out:
 382	lpfc_nlp_put(ndlp);
 383}
 384
 385static int
 386lpfc_rcv_plogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
 387	       struct lpfc_iocbq *cmdiocb)
 388{
 389	struct Scsi_Host   *shost = lpfc_shost_from_vport(vport);
 390	struct lpfc_hba    *phba = vport->phba;
 391	struct lpfc_dmabuf *pcmd;
 392	uint64_t nlp_portwwn = 0;
 393	uint32_t *lp;
 394	IOCB_t *icmd;
 395	struct serv_parm *sp;
 396	uint32_t ed_tov;
 397	LPFC_MBOXQ_t *link_mbox;
 398	LPFC_MBOXQ_t *login_mbox;
 399	struct lpfc_iocbq *save_iocb;
 400	struct ls_rjt stat;
 401	uint32_t vid, flag;
 402	u16 rpi;
 403	int rc, defer_acc;
 404
 405	memset(&stat, 0, sizeof (struct ls_rjt));
 406	pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
 407	lp = (uint32_t *) pcmd->virt;
 408	sp = (struct serv_parm *) ((uint8_t *) lp + sizeof (uint32_t));
 409	if (wwn_to_u64(sp->portName.u.wwn) == 0) {
 410		lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
 411				 "0140 PLOGI Reject: invalid nname\n");
 412		stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
 413		stat.un.b.lsRjtRsnCodeExp = LSEXP_INVALID_PNAME;
 414		lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
 415			NULL);
 416		return 0;
 417	}
 418	if (wwn_to_u64(sp->nodeName.u.wwn) == 0) {
 419		lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
 420				 "0141 PLOGI Reject: invalid pname\n");
 421		stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
 422		stat.un.b.lsRjtRsnCodeExp = LSEXP_INVALID_NNAME;
 423		lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
 424			NULL);
 425		return 0;
 426	}
 427
 428	nlp_portwwn = wwn_to_u64(ndlp->nlp_portname.u.wwn);
 429	if ((lpfc_check_sparm(vport, ndlp, sp, CLASS3, 0) == 0)) {
 430		/* Reject this request because invalid parameters */
 431		stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
 432		stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
 433		lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
 434			NULL);
 435		return 0;
 436	}
 437	icmd = &cmdiocb->iocb;
 438
 439	/* PLOGI chkparm OK */
 440	lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
 441			 "0114 PLOGI chkparm OK Data: x%x x%x x%x "
 442			 "x%x x%x x%x\n",
 443			 ndlp->nlp_DID, ndlp->nlp_state, ndlp->nlp_flag,
 444			 ndlp->nlp_rpi, vport->port_state,
 445			 vport->fc_flag);
 446
 447	if (vport->cfg_fcp_class == 2 && sp->cls2.classValid)
 448		ndlp->nlp_fcp_info |= CLASS2;
 449	else
 450		ndlp->nlp_fcp_info |= CLASS3;
 451
 452	defer_acc = 0;
 453	ndlp->nlp_class_sup = 0;
 454	if (sp->cls1.classValid)
 455		ndlp->nlp_class_sup |= FC_COS_CLASS1;
 456	if (sp->cls2.classValid)
 457		ndlp->nlp_class_sup |= FC_COS_CLASS2;
 458	if (sp->cls3.classValid)
 459		ndlp->nlp_class_sup |= FC_COS_CLASS3;
 460	if (sp->cls4.classValid)
 461		ndlp->nlp_class_sup |= FC_COS_CLASS4;
 462	ndlp->nlp_maxframe =
 463		((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) | sp->cmn.bbRcvSizeLsb;
 464	/* if already logged in, do implicit logout */
 465	switch (ndlp->nlp_state) {
 466	case  NLP_STE_NPR_NODE:
 467		if (!(ndlp->nlp_flag & NLP_NPR_ADISC))
 468			break;
 469		/* fall through */
 470	case  NLP_STE_REG_LOGIN_ISSUE:
 471	case  NLP_STE_PRLI_ISSUE:
 472	case  NLP_STE_UNMAPPED_NODE:
 473	case  NLP_STE_MAPPED_NODE:
 474		/* For initiators, lpfc_plogi_confirm_nport skips fabric did.
 475		 * For target mode, execute implicit logo.
 476		 * Fabric nodes go into NPR.
 477		 */
 478		if (!(ndlp->nlp_type & NLP_FABRIC) &&
 479		    !(phba->nvmet_support)) {
 480			lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb,
 481					 ndlp, NULL);
 482			return 1;
 483		}
 484		if (nlp_portwwn != 0 &&
 485		    nlp_portwwn != wwn_to_u64(sp->portName.u.wwn))
 486			lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
 487					 "0143 PLOGI recv'd from DID: x%x "
 488					 "WWPN changed: old %llx new %llx\n",
 489					 ndlp->nlp_DID,
 490					 (unsigned long long)nlp_portwwn,
 491					 (unsigned long long)
 492					 wwn_to_u64(sp->portName.u.wwn));
 493
 494		ndlp->nlp_prev_state = ndlp->nlp_state;
 495		/* rport needs to be unregistered first */
 496		lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
 497		break;
 498	}
 499
 500	ndlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR);
 501	ndlp->nlp_type &= ~(NLP_NVME_TARGET | NLP_NVME_INITIATOR);
 502	ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
 503	ndlp->nlp_flag &= ~NLP_FIRSTBURST;
 504
 505	login_mbox = NULL;
 506	link_mbox = NULL;
 507	save_iocb = NULL;
 508
 509	/* Check for Nport to NPort pt2pt protocol */
 510	if ((vport->fc_flag & FC_PT2PT) &&
 511	    !(vport->fc_flag & FC_PT2PT_PLOGI)) {
 512		/* rcv'ed PLOGI decides what our NPortId will be */
 513		vport->fc_myDID = icmd->un.rcvels.parmRo;
 514
 515		ed_tov = be32_to_cpu(sp->cmn.e_d_tov);
 516		if (sp->cmn.edtovResolution) {
 517			/* E_D_TOV ticks are in nanoseconds */
 518			ed_tov = (phba->fc_edtov + 999999) / 1000000;
 519		}
 520
 521		/*
 522		 * For pt-to-pt, use the larger EDTOV
 523		 * RATOV = 2 * EDTOV
 524		 */
 525		if (ed_tov > phba->fc_edtov)
 526			phba->fc_edtov = ed_tov;
 527		phba->fc_ratov = (2 * phba->fc_edtov) / 1000;
 528
 529		memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
 530
 531		/* Issue config_link / reg_vfi to account for updated TOV's */
 532
 533		if (phba->sli_rev == LPFC_SLI_REV4)
 534			lpfc_issue_reg_vfi(vport);
 535		else {
 536			defer_acc = 1;
 537			link_mbox = mempool_alloc(phba->mbox_mem_pool,
 538						  GFP_KERNEL);
 539			if (!link_mbox)
 540				goto out;
 541			lpfc_config_link(phba, link_mbox);
 542			link_mbox->mbox_cmpl = lpfc_defer_pt2pt_acc;
 543			link_mbox->vport = vport;
 544			link_mbox->ctx_ndlp = ndlp;
 545
 546			save_iocb = kzalloc(sizeof(*save_iocb), GFP_KERNEL);
 547			if (!save_iocb)
 548				goto out;
 549			/* Save info from cmd IOCB used in rsp */
 550			memcpy((uint8_t *)save_iocb, (uint8_t *)cmdiocb,
 551			       sizeof(struct lpfc_iocbq));
 552		}
 553
 554		lpfc_can_disctmo(vport);
 555	}
 556
 557	ndlp->nlp_flag &= ~NLP_SUPPRESS_RSP;
 558	if ((phba->sli.sli_flag & LPFC_SLI_SUPPRESS_RSP) &&
 559	    sp->cmn.valid_vendor_ver_level) {
 560		vid = be32_to_cpu(sp->un.vv.vid);
 561		flag = be32_to_cpu(sp->un.vv.flags);
 562		if ((vid == LPFC_VV_EMLX_ID) && (flag & LPFC_VV_SUPPRESS_RSP))
 563			ndlp->nlp_flag |= NLP_SUPPRESS_RSP;
 564	}
 565
 566	login_mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
 567	if (!login_mbox)
 568		goto out;
 569
 570	/* Registering an existing RPI behaves differently for SLI3 vs SLI4 */
 571	if (phba->nvmet_support && !defer_acc) {
 572		link_mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
 573		if (!link_mbox)
 574			goto out;
 575
 576		/* As unique identifiers such as iotag would be overwritten
 577		 * with those from the cmdiocb, allocate separate temporary
 578		 * storage for the copy.
 579		 */
 580		save_iocb = kzalloc(sizeof(*save_iocb), GFP_KERNEL);
 581		if (!save_iocb)
 582			goto out;
 583
 584		/* Unreg RPI is required for SLI4. */
 585		rpi = phba->sli4_hba.rpi_ids[ndlp->nlp_rpi];
 586		lpfc_unreg_login(phba, vport->vpi, rpi, link_mbox);
 587		link_mbox->vport = vport;
 588		link_mbox->ctx_ndlp = ndlp;
 589		link_mbox->mbox_cmpl = lpfc_defer_acc_rsp;
 590
 591		if (((ndlp->nlp_DID & Fabric_DID_MASK) != Fabric_DID_MASK) &&
 592		    (!(vport->fc_flag & FC_OFFLINE_MODE)))
 593			ndlp->nlp_flag |= NLP_UNREG_INP;
 594
 595		/* Save info from cmd IOCB used in rsp */
 596		memcpy(save_iocb, cmdiocb, sizeof(*save_iocb));
 597
 598		/* Delay sending ACC till unreg RPI completes. */
 599		defer_acc = 1;
 600	} else if (phba->sli_rev == LPFC_SLI_REV4)
 601		lpfc_unreg_rpi(vport, ndlp);
 602
 603	rc = lpfc_reg_rpi(phba, vport->vpi, icmd->un.rcvels.remoteID,
 604			    (uint8_t *)sp, login_mbox, ndlp->nlp_rpi);
 605	if (rc)
 606		goto out;
 607
 608	/* ACC PLOGI rsp command needs to execute first,
 609	 * queue this login_mbox command to be processed later.
 610	 */
 611	login_mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
 612	/*
 613	 * login_mbox->ctx_ndlp = lpfc_nlp_get(ndlp) deferred until mailbox
 614	 * command issued in lpfc_cmpl_els_acc().
 615	 */
 616	login_mbox->vport = vport;
 617	spin_lock_irq(shost->host_lock);
 618	ndlp->nlp_flag |= (NLP_ACC_REGLOGIN | NLP_RCV_PLOGI);
 619	spin_unlock_irq(shost->host_lock);
 620
 621	/*
 622	 * If there is an outstanding PLOGI issued, abort it before
 623	 * sending ACC rsp for received PLOGI. If pending plogi
 624	 * is not canceled here, the plogi will be rejected by
 625	 * remote port and will be retried. On a configuration with
 626	 * single discovery thread, this will cause a huge delay in
 627	 * discovery. Also this will cause multiple state machines
 628	 * running in parallel for this node.
 629	 * This only applies to a fabric environment.
 630	 */
 631	if ((ndlp->nlp_state == NLP_STE_PLOGI_ISSUE) &&
 632	    (vport->fc_flag & FC_FABRIC)) {
 633		/* software abort outstanding PLOGI */
 634		lpfc_els_abort(phba, ndlp);
 635	}
 636
 637	if ((vport->port_type == LPFC_NPIV_PORT &&
 638	     vport->cfg_restrict_login)) {
 639
 640		/* no deferred ACC */
 641		kfree(save_iocb);
 642
 643		/* In order to preserve RPIs, we want to cleanup
 644		 * the default RPI the firmware created to rcv
 645		 * this ELS request. The only way to do this is
 646		 * to register, then unregister the RPI.
 647		 */
 648		spin_lock_irq(shost->host_lock);
 649		ndlp->nlp_flag |= NLP_RM_DFLT_RPI;
 650		spin_unlock_irq(shost->host_lock);
 651		stat.un.b.lsRjtRsnCode = LSRJT_INVALID_CMD;
 652		stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
 653		rc = lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb,
 654			ndlp, login_mbox);
 655		if (rc)
 656			mempool_free(login_mbox, phba->mbox_mem_pool);
 657		return 1;
 658	}
 659	if (defer_acc) {
 660		/* So the order here should be:
 661		 * SLI3 pt2pt
 662		 *   Issue CONFIG_LINK mbox
 663		 *   CONFIG_LINK cmpl
 664		 * SLI4 tgt
 665		 *   Issue UNREG RPI mbx
 666		 *   UNREG RPI cmpl
 667		 * Issue PLOGI ACC
 668		 * PLOGI ACC cmpl
 669		 * Issue REG_LOGIN mbox
 670		 */
 671
 672		/* Save the REG_LOGIN mbox for and rcv IOCB copy later */
 673		link_mbox->context3 = login_mbox;
 674		login_mbox->context3 = save_iocb;
 675
 676		/* Start the ball rolling by issuing CONFIG_LINK here */
 677		rc = lpfc_sli_issue_mbox(phba, link_mbox, MBX_NOWAIT);
 678		if (rc == MBX_NOT_FINISHED)
 679			goto out;
 680		return 1;
 681	}
 682
 683	rc = lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp, login_mbox);
 684	if (rc)
 685		mempool_free(login_mbox, phba->mbox_mem_pool);
 686	return 1;
 687out:
 688	if (defer_acc)
 689		lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
 690				"4577 discovery failure: %p %p %p\n",
 691				save_iocb, link_mbox, login_mbox);
 692	kfree(save_iocb);
 693	if (link_mbox)
 694		mempool_free(link_mbox, phba->mbox_mem_pool);
 695	if (login_mbox)
 696		mempool_free(login_mbox, phba->mbox_mem_pool);
 697
 698	stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
 699	stat.un.b.lsRjtRsnCodeExp = LSEXP_OUT_OF_RESOURCE;
 700	lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
 701	return 0;
 702}
 703
 704/**
 705 * lpfc_mbx_cmpl_resume_rpi - Resume RPI completion routine
 706 * @phba: pointer to lpfc hba data structure.
 707 * @mboxq: pointer to mailbox object
 708 *
 709 * This routine is invoked to issue a completion to a rcv'ed
 710 * ADISC or PDISC after the paused RPI has been resumed.
 711 **/
 712static void
 713lpfc_mbx_cmpl_resume_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
 714{
 715	struct lpfc_vport *vport;
 716	struct lpfc_iocbq *elsiocb;
 717	struct lpfc_nodelist *ndlp;
 718	uint32_t cmd;
 719
 720	elsiocb = (struct lpfc_iocbq *)mboxq->ctx_buf;
 721	ndlp = (struct lpfc_nodelist *)mboxq->ctx_ndlp;
 722	vport = mboxq->vport;
 723	cmd = elsiocb->drvrTimeout;
 724
 725	if (cmd == ELS_CMD_ADISC) {
 726		lpfc_els_rsp_adisc_acc(vport, elsiocb, ndlp);
 727	} else {
 728		lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, elsiocb,
 729			ndlp, NULL);
 730	}
 731	kfree(elsiocb);
 732	mempool_free(mboxq, phba->mbox_mem_pool);
 733}
 734
 735static int
 736lpfc_rcv_padisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
 737		struct lpfc_iocbq *cmdiocb)
 738{
 739	struct Scsi_Host   *shost = lpfc_shost_from_vport(vport);
 740	struct lpfc_iocbq  *elsiocb;
 741	struct lpfc_dmabuf *pcmd;
 742	struct serv_parm   *sp;
 743	struct lpfc_name   *pnn, *ppn;
 744	struct ls_rjt stat;
 745	ADISC *ap;
 746	IOCB_t *icmd;
 747	uint32_t *lp;
 748	uint32_t cmd;
 749
 750	pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
 751	lp = (uint32_t *) pcmd->virt;
 752
 753	cmd = *lp++;
 754	if (cmd == ELS_CMD_ADISC) {
 755		ap = (ADISC *) lp;
 756		pnn = (struct lpfc_name *) & ap->nodeName;
 757		ppn = (struct lpfc_name *) & ap->portName;
 758	} else {
 759		sp = (struct serv_parm *) lp;
 760		pnn = (struct lpfc_name *) & sp->nodeName;
 761		ppn = (struct lpfc_name *) & sp->portName;
 762	}
 763
 764	icmd = &cmdiocb->iocb;
 765	if (icmd->ulpStatus == 0 && lpfc_check_adisc(vport, ndlp, pnn, ppn)) {
 766
 767		/*
 768		 * As soon as  we send ACC, the remote NPort can
 769		 * start sending us data. Thus, for SLI4 we must
 770		 * resume the RPI before the ACC goes out.
 771		 */
 772		if (vport->phba->sli_rev == LPFC_SLI_REV4) {
 773			elsiocb = kmalloc(sizeof(struct lpfc_iocbq),
 774				GFP_KERNEL);
 775			if (elsiocb) {
 776
 777				/* Save info from cmd IOCB used in rsp */
 778				memcpy((uint8_t *)elsiocb, (uint8_t *)cmdiocb,
 779					sizeof(struct lpfc_iocbq));
 780
 781				/* Save the ELS cmd */
 782				elsiocb->drvrTimeout = cmd;
 783
 784				lpfc_sli4_resume_rpi(ndlp,
 785					lpfc_mbx_cmpl_resume_rpi, elsiocb);
 786				goto out;
 787			}
 788		}
 789
 790		if (cmd == ELS_CMD_ADISC) {
 791			lpfc_els_rsp_adisc_acc(vport, cmdiocb, ndlp);
 792		} else {
 793			lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb,
 794				ndlp, NULL);
 795		}
 796out:
 797		/* If we are authenticated, move to the proper state */
 798		if (ndlp->nlp_type & (NLP_FCP_TARGET | NLP_NVME_TARGET))
 799			lpfc_nlp_set_state(vport, ndlp, NLP_STE_MAPPED_NODE);
 800		else
 801			lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
 802
 803		return 1;
 804	}
 805	/* Reject this request because invalid parameters */
 806	stat.un.b.lsRjtRsvd0 = 0;
 807	stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
 808	stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
 809	stat.un.b.vendorUnique = 0;
 810	lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
 811
 812	/* 1 sec timeout */
 813	mod_timer(&ndlp->nlp_delayfunc, jiffies + msecs_to_jiffies(1000));
 814
 815	spin_lock_irq(shost->host_lock);
 816	ndlp->nlp_flag |= NLP_DELAY_TMO;
 817	spin_unlock_irq(shost->host_lock);
 818	ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
 819	ndlp->nlp_prev_state = ndlp->nlp_state;
 820	lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
 821	return 0;
 822}
 823
 824static int
 825lpfc_rcv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
 826	      struct lpfc_iocbq *cmdiocb, uint32_t els_cmd)
 827{
 828	struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
 829	struct lpfc_hba    *phba = vport->phba;
 830	struct lpfc_vport **vports;
 831	int i, active_vlink_present = 0 ;
 832
 833	/* Put ndlp in NPR state with 1 sec timeout for plogi, ACC logo */
 834	/* Only call LOGO ACC for first LOGO, this avoids sending unnecessary
 835	 * PLOGIs during LOGO storms from a device.
 836	 */
 837	spin_lock_irq(shost->host_lock);
 838	ndlp->nlp_flag |= NLP_LOGO_ACC;
 839	spin_unlock_irq(shost->host_lock);
 840	if (els_cmd == ELS_CMD_PRLO)
 841		lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL);
 842	else
 843		lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
 844	if (ndlp->nlp_DID == Fabric_DID) {
 845		if (vport->port_state <= LPFC_FDISC)
 846			goto out;
 847		lpfc_linkdown_port(vport);
 848		spin_lock_irq(shost->host_lock);
 849		vport->fc_flag |= FC_VPORT_LOGO_RCVD;
 850		spin_unlock_irq(shost->host_lock);
 851		vports = lpfc_create_vport_work_array(phba);
 852		if (vports) {
 853			for (i = 0; i <= phba->max_vports && vports[i] != NULL;
 854					i++) {
 855				if ((!(vports[i]->fc_flag &
 856					FC_VPORT_LOGO_RCVD)) &&
 857					(vports[i]->port_state > LPFC_FDISC)) {
 858					active_vlink_present = 1;
 859					break;
 860				}
 861			}
 862			lpfc_destroy_vport_work_array(phba, vports);
 863		}
 864
 865		/*
 866		 * Don't re-instantiate if vport is marked for deletion.
 867		 * If we are here first then vport_delete is going to wait
 868		 * for discovery to complete.
 869		 */
 870		if (!(vport->load_flag & FC_UNLOADING) &&
 871					active_vlink_present) {
 872			/*
 873			 * If there are other active VLinks present,
 874			 * re-instantiate the Vlink using FDISC.
 875			 */
 876			mod_timer(&ndlp->nlp_delayfunc,
 877				  jiffies + msecs_to_jiffies(1000));
 878			spin_lock_irq(shost->host_lock);
 879			ndlp->nlp_flag |= NLP_DELAY_TMO;
 880			spin_unlock_irq(shost->host_lock);
 881			ndlp->nlp_last_elscmd = ELS_CMD_FDISC;
 882			vport->port_state = LPFC_FDISC;
 883		} else {
 884			spin_lock_irq(shost->host_lock);
 885			phba->pport->fc_flag &= ~FC_LOGO_RCVD_DID_CHNG;
 886			spin_unlock_irq(shost->host_lock);
 887			lpfc_retry_pport_discovery(phba);
 888		}
 889	} else if ((!(ndlp->nlp_type & NLP_FABRIC) &&
 890		((ndlp->nlp_type & NLP_FCP_TARGET) ||
 891		!(ndlp->nlp_type & NLP_FCP_INITIATOR))) ||
 892		(ndlp->nlp_state == NLP_STE_ADISC_ISSUE)) {
 893		/* Only try to re-login if this is NOT a Fabric Node */
 894		mod_timer(&ndlp->nlp_delayfunc,
 895			  jiffies + msecs_to_jiffies(1000 * 1));
 896		spin_lock_irq(shost->host_lock);
 897		ndlp->nlp_flag |= NLP_DELAY_TMO;
 898		spin_unlock_irq(shost->host_lock);
 899
 900		ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
 901	}
 902out:
 903	ndlp->nlp_prev_state = ndlp->nlp_state;
 904	lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
 905
 906	spin_lock_irq(shost->host_lock);
 907	ndlp->nlp_flag &= ~NLP_NPR_ADISC;
 908	spin_unlock_irq(shost->host_lock);
 909	/* The driver has to wait until the ACC completes before it continues
 910	 * processing the LOGO.  The action will resume in
 911	 * lpfc_cmpl_els_logo_acc routine. Since part of processing includes an
 912	 * unreg_login, the driver waits so the ACC does not get aborted.
 913	 */
 914	return 0;
 915}
 916
 917static uint32_t
 918lpfc_rcv_prli_support_check(struct lpfc_vport *vport,
 919			    struct lpfc_nodelist *ndlp,
 920			    struct lpfc_iocbq *cmdiocb)
 921{
 922	struct ls_rjt stat;
 923	uint32_t *payload;
 924	uint32_t cmd;
 925
 926	payload = ((struct lpfc_dmabuf *)cmdiocb->context2)->virt;
 927	cmd = *payload;
 928	if (vport->phba->nvmet_support) {
 929		/* Must be a NVME PRLI */
 930		if (cmd ==  ELS_CMD_PRLI)
 931			goto out;
 932	} else {
 933		/* Initiator mode. */
 934		if (!vport->nvmei_support && (cmd == ELS_CMD_NVMEPRLI))
 935			goto out;
 936	}
 937	return 1;
 938out:
 939	lpfc_printf_vlog(vport, KERN_WARNING, LOG_NVME_DISC,
 940			 "6115 Rcv PRLI (%x) check failed: ndlp rpi %d "
 941			 "state x%x flags x%x\n",
 942			 cmd, ndlp->nlp_rpi, ndlp->nlp_state,
 943			 ndlp->nlp_flag);
 944	memset(&stat, 0, sizeof(struct ls_rjt));
 945	stat.un.b.lsRjtRsnCode = LSRJT_CMD_UNSUPPORTED;
 946	stat.un.b.lsRjtRsnCodeExp = LSEXP_REQ_UNSUPPORTED;
 947	lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb,
 948			    ndlp, NULL);
 949	return 0;
 950}
 951
 952static void
 953lpfc_rcv_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
 954	      struct lpfc_iocbq *cmdiocb)
 955{
 956	struct lpfc_hba  *phba = vport->phba;
 957	struct lpfc_dmabuf *pcmd;
 958	uint32_t *lp;
 959	PRLI *npr;
 960	struct fc_rport *rport = ndlp->rport;
 961	u32 roles;
 962
 963	pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
 964	lp = (uint32_t *) pcmd->virt;
 965	npr = (PRLI *) ((uint8_t *) lp + sizeof (uint32_t));
 966
 967	if ((npr->prliType == PRLI_FCP_TYPE) ||
 968	    (npr->prliType == PRLI_NVME_TYPE)) {
 969		if (npr->initiatorFunc) {
 970			if (npr->prliType == PRLI_FCP_TYPE)
 971				ndlp->nlp_type |= NLP_FCP_INITIATOR;
 972			if (npr->prliType == PRLI_NVME_TYPE)
 973				ndlp->nlp_type |= NLP_NVME_INITIATOR;
 974		}
 975		if (npr->targetFunc) {
 976			if (npr->prliType == PRLI_FCP_TYPE)
 977				ndlp->nlp_type |= NLP_FCP_TARGET;
 978			if (npr->prliType == PRLI_NVME_TYPE)
 979				ndlp->nlp_type |= NLP_NVME_TARGET;
 980			if (npr->writeXferRdyDis)
 981				ndlp->nlp_flag |= NLP_FIRSTBURST;
 982		}
 983		if (npr->Retry && ndlp->nlp_type &
 984					(NLP_FCP_INITIATOR | NLP_FCP_TARGET))
 985			ndlp->nlp_fcp_info |= NLP_FCP_2_DEVICE;
 986
 987		if (npr->Retry && phba->nsler &&
 988		    ndlp->nlp_type & (NLP_NVME_INITIATOR | NLP_NVME_TARGET))
 989			ndlp->nlp_nvme_info |= NLP_NVME_NSLER;
 990
 991
 992		/* If this driver is in nvme target mode, set the ndlp's fc4
 993		 * type to NVME provided the PRLI response claims NVME FC4
 994		 * type.  Target mode does not issue gft_id so doesn't get
 995		 * the fc4 type set until now.
 996		 */
 997		if (phba->nvmet_support && (npr->prliType == PRLI_NVME_TYPE)) {
 998			ndlp->nlp_fc4_type |= NLP_FC4_NVME;
 999			lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
1000		}
1001		if (npr->prliType == PRLI_FCP_TYPE)
1002			ndlp->nlp_fc4_type |= NLP_FC4_FCP;
1003	}
1004	if (rport) {
1005		/* We need to update the rport role values */
1006		roles = FC_RPORT_ROLE_UNKNOWN;
1007		if (ndlp->nlp_type & NLP_FCP_INITIATOR)
1008			roles |= FC_RPORT_ROLE_FCP_INITIATOR;
1009		if (ndlp->nlp_type & NLP_FCP_TARGET)
1010			roles |= FC_RPORT_ROLE_FCP_TARGET;
1011
1012		lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
1013			"rport rolechg:   role:x%x did:x%x flg:x%x",
1014			roles, ndlp->nlp_DID, ndlp->nlp_flag);
1015
1016		if (vport->cfg_enable_fc4_type != LPFC_ENABLE_NVME)
1017			fc_remote_port_rolechg(rport, roles);
1018	}
1019}
1020
1021static uint32_t
1022lpfc_disc_set_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
1023{
1024	struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1025
1026	if (!(ndlp->nlp_flag & NLP_RPI_REGISTERED)) {
1027		spin_lock_irq(shost->host_lock);
1028		ndlp->nlp_flag &= ~NLP_NPR_ADISC;
1029		spin_unlock_irq(shost->host_lock);
1030		return 0;
1031	}
1032
1033	if (!(vport->fc_flag & FC_PT2PT)) {
1034		/* Check config parameter use-adisc or FCP-2 */
1035		if (vport->cfg_use_adisc && ((vport->fc_flag & FC_RSCN_MODE) ||
1036		    ((ndlp->nlp_fcp_info & NLP_FCP_2_DEVICE) &&
1037		     (ndlp->nlp_type & NLP_FCP_TARGET)))) {
1038			spin_lock_irq(shost->host_lock);
1039			ndlp->nlp_flag |= NLP_NPR_ADISC;
1040			spin_unlock_irq(shost->host_lock);
1041			return 1;
1042		}
1043	}
1044
1045	spin_lock_irq(shost->host_lock);
1046	ndlp->nlp_flag &= ~NLP_NPR_ADISC;
1047	spin_unlock_irq(shost->host_lock);
1048	lpfc_unreg_rpi(vport, ndlp);
1049	return 0;
1050}
1051
1052/**
1053 * lpfc_release_rpi - Release a RPI by issuing unreg_login mailbox cmd.
1054 * @phba : Pointer to lpfc_hba structure.
1055 * @vport: Pointer to lpfc_vport structure.
1056 * @rpi  : rpi to be release.
1057 *
1058 * This function will send a unreg_login mailbox command to the firmware
1059 * to release a rpi.
1060 **/
1061static void
1062lpfc_release_rpi(struct lpfc_hba *phba, struct lpfc_vport *vport,
1063		 struct lpfc_nodelist *ndlp, uint16_t rpi)
1064{
1065	LPFC_MBOXQ_t *pmb;
1066	int rc;
1067
1068	/* If there is already an UNREG in progress for this ndlp,
1069	 * no need to queue up another one.
1070	 */
1071	if (ndlp->nlp_flag & NLP_UNREG_INP) {
1072		lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1073				 "1435 release_rpi SKIP UNREG x%x on "
1074				 "NPort x%x deferred x%x  flg x%x "
1075				 "Data: x%px\n",
1076				 ndlp->nlp_rpi, ndlp->nlp_DID,
1077				 ndlp->nlp_defer_did,
1078				 ndlp->nlp_flag, ndlp);
1079		return;
1080	}
1081
1082	pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
1083			GFP_KERNEL);
1084	if (!pmb)
1085		lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
1086			"2796 mailbox memory allocation failed \n");
1087	else {
1088		lpfc_unreg_login(phba, vport->vpi, rpi, pmb);
1089		pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1090		pmb->vport = vport;
1091		pmb->ctx_ndlp = ndlp;
1092
1093		if (((ndlp->nlp_DID & Fabric_DID_MASK) != Fabric_DID_MASK) &&
1094		    (!(vport->fc_flag & FC_OFFLINE_MODE)))
1095			ndlp->nlp_flag |= NLP_UNREG_INP;
1096
1097		lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1098				 "1437 release_rpi UNREG x%x "
1099				 "on NPort x%x flg x%x\n",
1100				 ndlp->nlp_rpi, ndlp->nlp_DID, ndlp->nlp_flag);
1101
1102		rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
1103		if (rc == MBX_NOT_FINISHED)
1104			mempool_free(pmb, phba->mbox_mem_pool);
1105	}
1106}
1107
1108static uint32_t
1109lpfc_disc_illegal(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1110		  void *arg, uint32_t evt)
1111{
1112	struct lpfc_hba *phba;
1113	LPFC_MBOXQ_t *pmb = (LPFC_MBOXQ_t *) arg;
1114	uint16_t rpi;
1115
1116	phba = vport->phba;
1117	/* Release the RPI if reglogin completing */
1118	if (!(phba->pport->load_flag & FC_UNLOADING) &&
1119		(evt == NLP_EVT_CMPL_REG_LOGIN) &&
1120		(!pmb->u.mb.mbxStatus)) {
1121		rpi = pmb->u.mb.un.varWords[0];
1122		lpfc_release_rpi(phba, vport, ndlp, rpi);
1123	}
1124	lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
1125			 "0271 Illegal State Transition: node x%x "
1126			 "event x%x, state x%x Data: x%x x%x\n",
1127			 ndlp->nlp_DID, evt, ndlp->nlp_state, ndlp->nlp_rpi,
1128			 ndlp->nlp_flag);
1129	return ndlp->nlp_state;
1130}
1131
1132static uint32_t
1133lpfc_cmpl_plogi_illegal(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1134		  void *arg, uint32_t evt)
1135{
1136	/* This transition is only legal if we previously
1137	 * rcv'ed a PLOGI. Since we don't want 2 discovery threads
1138	 * working on the same NPortID, do nothing for this thread
1139	 * to stop it.
1140	 */
1141	if (!(ndlp->nlp_flag & NLP_RCV_PLOGI)) {
1142		lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
1143			 "0272 Illegal State Transition: node x%x "
1144			 "event x%x, state x%x Data: x%x x%x\n",
1145			 ndlp->nlp_DID, evt, ndlp->nlp_state, ndlp->nlp_rpi,
1146			 ndlp->nlp_flag);
1147	}
1148	return ndlp->nlp_state;
1149}
1150
1151/* Start of Discovery State Machine routines */
1152
1153static uint32_t
1154lpfc_rcv_plogi_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1155			   void *arg, uint32_t evt)
1156{
1157	struct lpfc_iocbq *cmdiocb;
1158
1159	cmdiocb = (struct lpfc_iocbq *) arg;
1160
1161	if (lpfc_rcv_plogi(vport, ndlp, cmdiocb)) {
1162		return ndlp->nlp_state;
1163	}
1164	return NLP_STE_FREED_NODE;
1165}
1166
1167static uint32_t
1168lpfc_rcv_els_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1169			 void *arg, uint32_t evt)
1170{
1171	lpfc_issue_els_logo(vport, ndlp, 0);
1172	return ndlp->nlp_state;
1173}
1174
1175static uint32_t
1176lpfc_rcv_logo_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1177			  void *arg, uint32_t evt)
1178{
1179	struct Scsi_Host  *shost = lpfc_shost_from_vport(vport);
1180	struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1181
1182	spin_lock_irq(shost->host_lock);
1183	ndlp->nlp_flag |= NLP_LOGO_ACC;
1184	spin_unlock_irq(shost->host_lock);
1185	lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
1186
1187	return ndlp->nlp_state;
1188}
1189
1190static uint32_t
1191lpfc_cmpl_logo_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1192			   void *arg, uint32_t evt)
1193{
1194	return NLP_STE_FREED_NODE;
1195}
1196
1197static uint32_t
1198lpfc_device_rm_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1199			   void *arg, uint32_t evt)
1200{
1201	return NLP_STE_FREED_NODE;
1202}
1203
1204static uint32_t
1205lpfc_device_recov_unused_node(struct lpfc_vport *vport,
1206			struct lpfc_nodelist *ndlp,
1207			   void *arg, uint32_t evt)
1208{
1209	return ndlp->nlp_state;
1210}
1211
1212static uint32_t
1213lpfc_rcv_plogi_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1214			   void *arg, uint32_t evt)
1215{
1216	struct Scsi_Host   *shost = lpfc_shost_from_vport(vport);
1217	struct lpfc_hba   *phba = vport->phba;
1218	struct lpfc_iocbq *cmdiocb = arg;
1219	struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
1220	uint32_t *lp = (uint32_t *) pcmd->virt;
1221	struct serv_parm *sp = (struct serv_parm *) (lp + 1);
1222	struct ls_rjt stat;
1223	int port_cmp;
1224
1225	memset(&stat, 0, sizeof (struct ls_rjt));
1226
1227	/* For a PLOGI, we only accept if our portname is less
1228	 * than the remote portname.
1229	 */
1230	phba->fc_stat.elsLogiCol++;
1231	port_cmp = memcmp(&vport->fc_portname, &sp->portName,
1232			  sizeof(struct lpfc_name));
1233
1234	if (port_cmp >= 0) {
1235		/* Reject this request because the remote node will accept
1236		   ours */
1237		stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
1238		stat.un.b.lsRjtRsnCodeExp = LSEXP_CMD_IN_PROGRESS;
1239		lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
1240			NULL);
1241	} else {
1242		if (lpfc_rcv_plogi(vport, ndlp, cmdiocb) &&
1243		    (ndlp->nlp_flag & NLP_NPR_2B_DISC) &&
1244		    (vport->num_disc_nodes)) {
1245			spin_lock_irq(shost->host_lock);
1246			ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
1247			spin_unlock_irq(shost->host_lock);
1248			/* Check if there are more PLOGIs to be sent */
1249			lpfc_more_plogi(vport);
1250			if (vport->num_disc_nodes == 0) {
1251				spin_lock_irq(shost->host_lock);
1252				vport->fc_flag &= ~FC_NDISC_ACTIVE;
1253				spin_unlock_irq(shost->host_lock);
1254				lpfc_can_disctmo(vport);
1255				lpfc_end_rscn(vport);
1256			}
1257		}
1258	} /* If our portname was less */
1259
1260	return ndlp->nlp_state;
1261}
1262
1263static uint32_t
1264lpfc_rcv_prli_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1265			  void *arg, uint32_t evt)
1266{
1267	struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1268	struct ls_rjt     stat;
1269
1270	memset(&stat, 0, sizeof (struct ls_rjt));
1271	stat.un.b.lsRjtRsnCode = LSRJT_LOGICAL_BSY;
1272	stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
1273	lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
1274	return ndlp->nlp_state;
1275}
1276
1277static uint32_t
1278lpfc_rcv_logo_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1279			  void *arg, uint32_t evt)
1280{
1281	struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1282
1283	/* Retrieve RPI from LOGO IOCB. RPI is used for CMD_ABORT_XRI_CN */
1284	if (vport->phba->sli_rev == LPFC_SLI_REV3)
1285		ndlp->nlp_rpi = cmdiocb->iocb.ulpIoTag;
1286				/* software abort outstanding PLOGI */
1287	lpfc_els_abort(vport->phba, ndlp);
1288
1289	lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
1290	return ndlp->nlp_state;
1291}
1292
1293static uint32_t
1294lpfc_rcv_els_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1295			 void *arg, uint32_t evt)
1296{
1297	struct Scsi_Host  *shost = lpfc_shost_from_vport(vport);
1298	struct lpfc_hba   *phba = vport->phba;
1299	struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1300
1301	/* software abort outstanding PLOGI */
1302	lpfc_els_abort(phba, ndlp);
1303
1304	if (evt == NLP_EVT_RCV_LOGO) {
1305		lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
1306	} else {
1307		lpfc_issue_els_logo(vport, ndlp, 0);
1308	}
1309
1310	/* Put ndlp in npr state set plogi timer for 1 sec */
1311	mod_timer(&ndlp->nlp_delayfunc, jiffies + msecs_to_jiffies(1000 * 1));
1312	spin_lock_irq(shost->host_lock);
1313	ndlp->nlp_flag |= NLP_DELAY_TMO;
1314	spin_unlock_irq(shost->host_lock);
1315	ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
1316	ndlp->nlp_prev_state = NLP_STE_PLOGI_ISSUE;
1317	lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1318
1319	return ndlp->nlp_state;
1320}
1321
1322static uint32_t
1323lpfc_cmpl_plogi_plogi_issue(struct lpfc_vport *vport,
1324			    struct lpfc_nodelist *ndlp,
1325			    void *arg,
1326			    uint32_t evt)
1327{
1328	struct lpfc_hba    *phba = vport->phba;
1329	struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1330	struct lpfc_iocbq  *cmdiocb, *rspiocb;
1331	struct lpfc_dmabuf *pcmd, *prsp, *mp;
1332	uint32_t *lp;
1333	uint32_t vid, flag;
1334	IOCB_t *irsp;
1335	struct serv_parm *sp;
1336	uint32_t ed_tov;
1337	LPFC_MBOXQ_t *mbox;
1338	int rc;
1339
1340	cmdiocb = (struct lpfc_iocbq *) arg;
1341	rspiocb = cmdiocb->context_un.rsp_iocb;
1342
1343	if (ndlp->nlp_flag & NLP_ACC_REGLOGIN) {
1344		/* Recovery from PLOGI collision logic */
1345		return ndlp->nlp_state;
1346	}
1347
1348	irsp = &rspiocb->iocb;
1349
1350	if (irsp->ulpStatus)
1351		goto out;
1352
1353	pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
1354
1355	prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
1356	if (!prsp)
1357		goto out;
1358
1359	lp = (uint32_t *) prsp->virt;
1360	sp = (struct serv_parm *) ((uint8_t *) lp + sizeof (uint32_t));
1361
1362	/* Some switches have FDMI servers returning 0 for WWN */
1363	if ((ndlp->nlp_DID != FDMI_DID) &&
1364		(wwn_to_u64(sp->portName.u.wwn) == 0 ||
1365		wwn_to_u64(sp->nodeName.u.wwn) == 0)) {
1366		lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1367				 "0142 PLOGI RSP: Invalid WWN.\n");
1368		goto out;
1369	}
1370	if (!lpfc_check_sparm(vport, ndlp, sp, CLASS3, 0))
1371		goto out;
1372	/* PLOGI chkparm OK */
1373	lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1374			 "0121 PLOGI chkparm OK Data: x%x x%x x%x x%x\n",
1375			 ndlp->nlp_DID, ndlp->nlp_state,
1376			 ndlp->nlp_flag, ndlp->nlp_rpi);
1377	if (vport->cfg_fcp_class == 2 && (sp->cls2.classValid))
1378		ndlp->nlp_fcp_info |= CLASS2;
1379	else
1380		ndlp->nlp_fcp_info |= CLASS3;
1381
1382	ndlp->nlp_class_sup = 0;
1383	if (sp->cls1.classValid)
1384		ndlp->nlp_class_sup |= FC_COS_CLASS1;
1385	if (sp->cls2.classValid)
1386		ndlp->nlp_class_sup |= FC_COS_CLASS2;
1387	if (sp->cls3.classValid)
1388		ndlp->nlp_class_sup |= FC_COS_CLASS3;
1389	if (sp->cls4.classValid)
1390		ndlp->nlp_class_sup |= FC_COS_CLASS4;
1391	ndlp->nlp_maxframe =
1392		((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) | sp->cmn.bbRcvSizeLsb;
1393
1394	if ((vport->fc_flag & FC_PT2PT) &&
1395	    (vport->fc_flag & FC_PT2PT_PLOGI)) {
1396		ed_tov = be32_to_cpu(sp->cmn.e_d_tov);
1397		if (sp->cmn.edtovResolution) {
1398			/* E_D_TOV ticks are in nanoseconds */
1399			ed_tov = (phba->fc_edtov + 999999) / 1000000;
1400		}
1401
1402		ndlp->nlp_flag &= ~NLP_SUPPRESS_RSP;
1403		if ((phba->sli.sli_flag & LPFC_SLI_SUPPRESS_RSP) &&
1404		    sp->cmn.valid_vendor_ver_level) {
1405			vid = be32_to_cpu(sp->un.vv.vid);
1406			flag = be32_to_cpu(sp->un.vv.flags);
1407			if ((vid == LPFC_VV_EMLX_ID) &&
1408			    (flag & LPFC_VV_SUPPRESS_RSP))
1409				ndlp->nlp_flag |= NLP_SUPPRESS_RSP;
1410		}
1411
1412		/*
1413		 * Use the larger EDTOV
1414		 * RATOV = 2 * EDTOV for pt-to-pt
1415		 */
1416		if (ed_tov > phba->fc_edtov)
1417			phba->fc_edtov = ed_tov;
1418		phba->fc_ratov = (2 * phba->fc_edtov) / 1000;
1419
1420		memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
1421
1422		/* Issue config_link / reg_vfi to account for updated TOV's */
1423		if (phba->sli_rev == LPFC_SLI_REV4) {
1424			lpfc_issue_reg_vfi(vport);
1425		} else {
1426			mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1427			if (!mbox) {
1428				lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1429						 "0133 PLOGI: no memory "
1430						 "for config_link "
1431						 "Data: x%x x%x x%x x%x\n",
1432						 ndlp->nlp_DID, ndlp->nlp_state,
1433						 ndlp->nlp_flag, ndlp->nlp_rpi);
1434				goto out;
1435			}
1436
1437			lpfc_config_link(phba, mbox);
1438
1439			mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1440			mbox->vport = vport;
1441			rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
1442			if (rc == MBX_NOT_FINISHED) {
1443				mempool_free(mbox, phba->mbox_mem_pool);
1444				goto out;
1445			}
1446		}
1447	}
1448
1449	lpfc_unreg_rpi(vport, ndlp);
1450
1451	mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1452	if (!mbox) {
1453		lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1454				 "0018 PLOGI: no memory for reg_login "
1455				 "Data: x%x x%x x%x x%x\n",
1456				 ndlp->nlp_DID, ndlp->nlp_state,
1457				 ndlp->nlp_flag, ndlp->nlp_rpi);
1458		goto out;
1459	}
1460
1461	if (lpfc_reg_rpi(phba, vport->vpi, irsp->un.elsreq64.remoteID,
1462			 (uint8_t *) sp, mbox, ndlp->nlp_rpi) == 0) {
1463		switch (ndlp->nlp_DID) {
1464		case NameServer_DID:
1465			mbox->mbox_cmpl = lpfc_mbx_cmpl_ns_reg_login;
1466			break;
1467		case FDMI_DID:
1468			mbox->mbox_cmpl = lpfc_mbx_cmpl_fdmi_reg_login;
1469			break;
1470		default:
1471			ndlp->nlp_flag |= NLP_REG_LOGIN_SEND;
1472			mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
1473		}
1474		mbox->ctx_ndlp = lpfc_nlp_get(ndlp);
1475		mbox->vport = vport;
1476		if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
1477		    != MBX_NOT_FINISHED) {
1478			lpfc_nlp_set_state(vport, ndlp,
1479					   NLP_STE_REG_LOGIN_ISSUE);
1480			return ndlp->nlp_state;
1481		}
1482		if (ndlp->nlp_flag & NLP_REG_LOGIN_SEND)
1483			ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND;
1484		/* decrement node reference count to the failed mbox
1485		 * command
1486		 */
1487		lpfc_nlp_put(ndlp);
1488		mp = (struct lpfc_dmabuf *)mbox->ctx_buf;
1489		lpfc_mbuf_free(phba, mp->virt, mp->phys);
1490		kfree(mp);
1491		mempool_free(mbox, phba->mbox_mem_pool);
1492
1493		lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1494				 "0134 PLOGI: cannot issue reg_login "
1495				 "Data: x%x x%x x%x x%x\n",
1496				 ndlp->nlp_DID, ndlp->nlp_state,
1497				 ndlp->nlp_flag, ndlp->nlp_rpi);
1498	} else {
1499		mempool_free(mbox, phba->mbox_mem_pool);
1500
1501		lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1502				 "0135 PLOGI: cannot format reg_login "
1503				 "Data: x%x x%x x%x x%x\n",
1504				 ndlp->nlp_DID, ndlp->nlp_state,
1505				 ndlp->nlp_flag, ndlp->nlp_rpi);
1506	}
1507
1508
1509out:
1510	if (ndlp->nlp_DID == NameServer_DID) {
1511		lpfc_vport_set_state(vport, FC_VPORT_FAILED);
1512		lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1513				 "0261 Cannot Register NameServer login\n");
1514	}
1515
1516	/*
1517	** In case the node reference counter does not go to zero, ensure that
1518	** the stale state for the node is not processed.
1519	*/
1520
1521	ndlp->nlp_prev_state = ndlp->nlp_state;
1522	lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1523	spin_lock_irq(shost->host_lock);
1524	ndlp->nlp_flag |= NLP_DEFER_RM;
1525	spin_unlock_irq(shost->host_lock);
1526	return NLP_STE_FREED_NODE;
1527}
1528
1529static uint32_t
1530lpfc_cmpl_logo_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1531			   void *arg, uint32_t evt)
1532{
1533	return ndlp->nlp_state;
1534}
1535
1536static uint32_t
1537lpfc_cmpl_reglogin_plogi_issue(struct lpfc_vport *vport,
1538	struct lpfc_nodelist *ndlp, void *arg, uint32_t evt)
1539{
1540	struct lpfc_hba *phba;
1541	LPFC_MBOXQ_t *pmb = (LPFC_MBOXQ_t *) arg;
1542	MAILBOX_t *mb = &pmb->u.mb;
1543	uint16_t rpi;
1544
1545	phba = vport->phba;
1546	/* Release the RPI */
1547	if (!(phba->pport->load_flag & FC_UNLOADING) &&
1548		!mb->mbxStatus) {
1549		rpi = pmb->u.mb.un.varWords[0];
1550		lpfc_release_rpi(phba, vport, ndlp, rpi);
1551	}
1552	return ndlp->nlp_state;
1553}
1554
1555static uint32_t
1556lpfc_device_rm_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1557			   void *arg, uint32_t evt)
1558{
1559	struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1560
1561	if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1562		spin_lock_irq(shost->host_lock);
1563		ndlp->nlp_flag |= NLP_NODEV_REMOVE;
1564		spin_unlock_irq(shost->host_lock);
1565		return ndlp->nlp_state;
1566	} else {
1567		/* software abort outstanding PLOGI */
1568		lpfc_els_abort(vport->phba, ndlp);
1569
1570		lpfc_drop_node(vport, ndlp);
1571		return NLP_STE_FREED_NODE;
1572	}
1573}
1574
1575static uint32_t
1576lpfc_device_recov_plogi_issue(struct lpfc_vport *vport,
1577			      struct lpfc_nodelist *ndlp,
1578			      void *arg,
1579			      uint32_t evt)
1580{
1581	struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1582	struct lpfc_hba  *phba = vport->phba;
1583
1584	/* Don't do anything that will mess up processing of the
1585	 * previous RSCN.
1586	 */
1587	if (vport->fc_flag & FC_RSCN_DEFERRED)
1588		return ndlp->nlp_state;
1589
1590	/* software abort outstanding PLOGI */
1591	lpfc_els_abort(phba, ndlp);
1592
1593	ndlp->nlp_prev_state = NLP_STE_PLOGI_ISSUE;
1594	lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1595	spin_lock_irq(shost->host_lock);
1596	ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
1597	spin_unlock_irq(shost->host_lock);
1598
1599	return ndlp->nlp_state;
1600}
1601
1602static uint32_t
1603lpfc_rcv_plogi_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1604			   void *arg, uint32_t evt)
1605{
1606	struct Scsi_Host   *shost = lpfc_shost_from_vport(vport);
1607	struct lpfc_hba   *phba = vport->phba;
1608	struct lpfc_iocbq *cmdiocb;
1609
1610	/* software abort outstanding ADISC */
1611	lpfc_els_abort(phba, ndlp);
1612
1613	cmdiocb = (struct lpfc_iocbq *) arg;
1614
1615	if (lpfc_rcv_plogi(vport, ndlp, cmdiocb)) {
1616		if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1617			spin_lock_irq(shost->host_lock);
1618			ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
1619			spin_unlock_irq(shost->host_lock);
1620			if (vport->num_disc_nodes)
1621				lpfc_more_adisc(vport);
1622		}
1623		return ndlp->nlp_state;
1624	}
1625	ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
1626	lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
1627	lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
1628
1629	return ndlp->nlp_state;
1630}
1631
1632static uint32_t
1633lpfc_rcv_prli_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1634			  void *arg, uint32_t evt)
1635{
1636	struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1637
1638	if (lpfc_rcv_prli_support_check(vport, ndlp, cmdiocb))
1639		lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
1640	return ndlp->nlp_state;
1641}
1642
1643static uint32_t
1644lpfc_rcv_logo_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1645			  void *arg, uint32_t evt)
1646{
1647	struct lpfc_hba *phba = vport->phba;
1648	struct lpfc_iocbq *cmdiocb;
1649
1650	cmdiocb = (struct lpfc_iocbq *) arg;
1651
1652	/* software abort outstanding ADISC */
1653	lpfc_els_abort(phba, ndlp);
1654
1655	lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
1656	return ndlp->nlp_state;
1657}
1658
1659static uint32_t
1660lpfc_rcv_padisc_adisc_issue(struct lpfc_vport *vport,
1661			    struct lpfc_nodelist *ndlp,
1662			    void *arg, uint32_t evt)
1663{
1664	struct lpfc_iocbq *cmdiocb;
1665
1666	cmdiocb = (struct lpfc_iocbq *) arg;
1667
1668	lpfc_rcv_padisc(vport, ndlp, cmdiocb);
1669	return ndlp->nlp_state;
1670}
1671
1672static uint32_t
1673lpfc_rcv_prlo_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1674			  void *arg, uint32_t evt)
1675{
1676	struct lpfc_iocbq *cmdiocb;
1677
1678	cmdiocb = (struct lpfc_iocbq *) arg;
1679
1680	/* Treat like rcv logo */
1681	lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_PRLO);
1682	return ndlp->nlp_state;
1683}
1684
1685static uint32_t
1686lpfc_cmpl_adisc_adisc_issue(struct lpfc_vport *vport,
1687			    struct lpfc_nodelist *ndlp,
1688			    void *arg, uint32_t evt)
1689{
1690	struct Scsi_Host  *shost = lpfc_shost_from_vport(vport);
1691	struct lpfc_hba   *phba = vport->phba;
1692	struct lpfc_iocbq *cmdiocb, *rspiocb;
1693	IOCB_t *irsp;
1694	ADISC *ap;
1695	int rc;
1696
1697	cmdiocb = (struct lpfc_iocbq *) arg;
1698	rspiocb = cmdiocb->context_un.rsp_iocb;
1699
1700	ap = (ADISC *)lpfc_check_elscmpl_iocb(phba, cmdiocb, rspiocb);
1701	irsp = &rspiocb->iocb;
1702
1703	if ((irsp->ulpStatus

Large files files are truncated, but you can click here to view the full file