• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "lpfc_hw4.h"
36 #include "lpfc_hw.h"
37 #include "lpfc_sli.h"
38 #include "lpfc_sli4.h"
39 #include "lpfc_nl.h"
40 #include "lpfc_disc.h"
41 #include "lpfc.h"
42 #include "lpfc_scsi.h"
43 #include "lpfc_nvme.h"
44 #include "lpfc_logmsg.h"
45 #include "lpfc_crtn.h"
46 #include "lpfc_vport.h"
47 #include "lpfc_debugfs.h"
48 
49 
50 /* Called to verify a rcv'ed ADISC was intended for us. */
51 static int
lpfc_check_adisc(struct lpfc_vport * vport,struct lpfc_nodelist * ndlp,struct lpfc_name * nn,struct lpfc_name * pn)52 lpfc_check_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
53 		 struct lpfc_name *nn, struct lpfc_name *pn)
54 {
55 	/* First, we MUST have a RPI registered */
56 	if (!(ndlp->nlp_flag & NLP_RPI_REGISTERED))
57 		return 0;
58 
59 	/* Compare the ADISC rsp WWNN / WWPN matches our internal node
60 	 * table entry for that node.
61 	 */
62 	if (memcmp(nn, &ndlp->nlp_nodename, sizeof (struct lpfc_name)))
63 		return 0;
64 
65 	if (memcmp(pn, &ndlp->nlp_portname, sizeof (struct lpfc_name)))
66 		return 0;
67 
68 	/* we match, return success */
69 	return 1;
70 }
71 
72 int
lpfc_check_sparm(struct lpfc_vport * vport,struct lpfc_nodelist * ndlp,struct serv_parm * sp,uint32_t class,int flogi)73 lpfc_check_sparm(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
74 		 struct serv_parm *sp, uint32_t class, int flogi)
75 {
76 	volatile struct serv_parm *hsp = &vport->fc_sparam;
77 	uint16_t hsp_value, ssp_value = 0;
78 
79 	/*
80 	 * The receive data field size and buffer-to-buffer receive data field
81 	 * size entries are 16 bits but are represented as two 8-bit fields in
82 	 * the driver data structure to account for rsvd bits and other control
83 	 * bits.  Reconstruct and compare the fields as a 16-bit values before
84 	 * correcting the byte values.
85 	 */
86 	if (sp->cls1.classValid) {
87 		if (!flogi) {
88 			hsp_value = ((hsp->cls1.rcvDataSizeMsb << 8) |
89 				     hsp->cls1.rcvDataSizeLsb);
90 			ssp_value = ((sp->cls1.rcvDataSizeMsb << 8) |
91 				     sp->cls1.rcvDataSizeLsb);
92 			if (!ssp_value)
93 				goto bad_service_param;
94 			if (ssp_value > hsp_value) {
95 				sp->cls1.rcvDataSizeLsb =
96 					hsp->cls1.rcvDataSizeLsb;
97 				sp->cls1.rcvDataSizeMsb =
98 					hsp->cls1.rcvDataSizeMsb;
99 			}
100 		}
101 	} else if (class == CLASS1)
102 		goto bad_service_param;
103 	if (sp->cls2.classValid) {
104 		if (!flogi) {
105 			hsp_value = ((hsp->cls2.rcvDataSizeMsb << 8) |
106 				     hsp->cls2.rcvDataSizeLsb);
107 			ssp_value = ((sp->cls2.rcvDataSizeMsb << 8) |
108 				     sp->cls2.rcvDataSizeLsb);
109 			if (!ssp_value)
110 				goto bad_service_param;
111 			if (ssp_value > hsp_value) {
112 				sp->cls2.rcvDataSizeLsb =
113 					hsp->cls2.rcvDataSizeLsb;
114 				sp->cls2.rcvDataSizeMsb =
115 					hsp->cls2.rcvDataSizeMsb;
116 			}
117 		}
118 	} else if (class == CLASS2)
119 		goto bad_service_param;
120 	if (sp->cls3.classValid) {
121 		if (!flogi) {
122 			hsp_value = ((hsp->cls3.rcvDataSizeMsb << 8) |
123 				     hsp->cls3.rcvDataSizeLsb);
124 			ssp_value = ((sp->cls3.rcvDataSizeMsb << 8) |
125 				     sp->cls3.rcvDataSizeLsb);
126 			if (!ssp_value)
127 				goto bad_service_param;
128 			if (ssp_value > hsp_value) {
129 				sp->cls3.rcvDataSizeLsb =
130 					hsp->cls3.rcvDataSizeLsb;
131 				sp->cls3.rcvDataSizeMsb =
132 					hsp->cls3.rcvDataSizeMsb;
133 			}
134 		}
135 	} else if (class == CLASS3)
136 		goto bad_service_param;
137 
138 	/*
139 	 * Preserve the upper four bits of the MSB from the PLOGI response.
140 	 * These bits contain the Buffer-to-Buffer State Change Number
141 	 * from the target and need to be passed to the FW.
142 	 */
143 	hsp_value = (hsp->cmn.bbRcvSizeMsb << 8) | hsp->cmn.bbRcvSizeLsb;
144 	ssp_value = (sp->cmn.bbRcvSizeMsb << 8) | sp->cmn.bbRcvSizeLsb;
145 	if (ssp_value > hsp_value) {
146 		sp->cmn.bbRcvSizeLsb = hsp->cmn.bbRcvSizeLsb;
147 		sp->cmn.bbRcvSizeMsb = (sp->cmn.bbRcvSizeMsb & 0xF0) |
148 				       (hsp->cmn.bbRcvSizeMsb & 0x0F);
149 	}
150 
151 	memcpy(&ndlp->nlp_nodename, &sp->nodeName, sizeof (struct lpfc_name));
152 	memcpy(&ndlp->nlp_portname, &sp->portName, sizeof (struct lpfc_name));
153 	return 1;
154 bad_service_param:
155 	lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
156 			 "0207 Device %x "
157 			 "(%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x) sent "
158 			 "invalid service parameters.  Ignoring device.\n",
159 			 ndlp->nlp_DID,
160 			 sp->nodeName.u.wwn[0], sp->nodeName.u.wwn[1],
161 			 sp->nodeName.u.wwn[2], sp->nodeName.u.wwn[3],
162 			 sp->nodeName.u.wwn[4], sp->nodeName.u.wwn[5],
163 			 sp->nodeName.u.wwn[6], sp->nodeName.u.wwn[7]);
164 	return 0;
165 }
166 
167 static void *
lpfc_check_elscmpl_iocb(struct lpfc_hba * phba,struct lpfc_iocbq * cmdiocb,struct lpfc_iocbq * rspiocb)168 lpfc_check_elscmpl_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
169 			struct lpfc_iocbq *rspiocb)
170 {
171 	struct lpfc_dmabuf *pcmd, *prsp;
172 	uint32_t *lp;
173 	void     *ptr = NULL;
174 	IOCB_t   *irsp;
175 
176 	irsp = &rspiocb->iocb;
177 	pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
178 
179 	/* For lpfc_els_abort, context2 could be zero'ed to delay
180 	 * freeing associated memory till after ABTS completes.
181 	 */
182 	if (pcmd) {
183 		prsp =  list_get_first(&pcmd->list, struct lpfc_dmabuf,
184 				       list);
185 		if (prsp) {
186 			lp = (uint32_t *) prsp->virt;
187 			ptr = (void *)((uint8_t *)lp + sizeof(uint32_t));
188 		}
189 	} else {
190 		/* Force ulpStatus error since we are returning NULL ptr */
191 		if (!(irsp->ulpStatus)) {
192 			irsp->ulpStatus = IOSTAT_LOCAL_REJECT;
193 			irsp->un.ulpWord[4] = IOERR_SLI_ABORTED;
194 		}
195 		ptr = NULL;
196 	}
197 	return ptr;
198 }
199 
200 
201 
202 /*
203  * Free resources / clean up outstanding I/Os
204  * associated with a LPFC_NODELIST entry. This
205  * routine effectively results in a "software abort".
206  */
207 void
lpfc_els_abort(struct lpfc_hba * phba,struct lpfc_nodelist * ndlp)208 lpfc_els_abort(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp)
209 {
210 	LIST_HEAD(abort_list);
211 	struct lpfc_sli_ring *pring;
212 	struct lpfc_iocbq *iocb, *next_iocb;
213 
214 	pring = lpfc_phba_elsring(phba);
215 
216 	/* In case of error recovery path, we might have a NULL pring here */
217 	if (unlikely(!pring))
218 		return;
219 
220 	/* Abort outstanding I/O on NPort <nlp_DID> */
221 	lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_DISCOVERY,
222 			 "2819 Abort outstanding I/O on NPort x%x "
223 			 "Data: x%x x%x x%x\n",
224 			 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
225 			 ndlp->nlp_rpi);
226 	/* Clean up all fabric IOs first.*/
227 	lpfc_fabric_abort_nport(ndlp);
228 
229 	/*
230 	 * Lock the ELS ring txcmplq for SLI3/SLI4 and build a local list
231 	 * of all ELS IOs that need an ABTS.  The IOs need to stay on the
232 	 * txcmplq so that the abort operation completes them successfully.
233 	 */
234 	spin_lock_irq(&phba->hbalock);
235 	if (phba->sli_rev == LPFC_SLI_REV4)
236 		spin_lock(&pring->ring_lock);
237 	list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
238 	/* Add to abort_list on on NDLP match. */
239 		if (lpfc_check_sli_ndlp(phba, pring, iocb, ndlp))
240 			list_add_tail(&iocb->dlist, &abort_list);
241 	}
242 	if (phba->sli_rev == LPFC_SLI_REV4)
243 		spin_unlock(&pring->ring_lock);
244 	spin_unlock_irq(&phba->hbalock);
245 
246 	/* Abort the targeted IOs and remove them from the abort list. */
247 	list_for_each_entry_safe(iocb, next_iocb, &abort_list, dlist) {
248 			spin_lock_irq(&phba->hbalock);
249 			list_del_init(&iocb->dlist);
250 			lpfc_sli_issue_abort_iotag(phba, pring, iocb);
251 			spin_unlock_irq(&phba->hbalock);
252 	}
253 
254 	INIT_LIST_HEAD(&abort_list);
255 
256 	/* Now process the txq */
257 	spin_lock_irq(&phba->hbalock);
258 	if (phba->sli_rev == LPFC_SLI_REV4)
259 		spin_lock(&pring->ring_lock);
260 
261 	list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
262 		/* Check to see if iocb matches the nport we are looking for */
263 		if (lpfc_check_sli_ndlp(phba, pring, iocb, ndlp)) {
264 			list_del_init(&iocb->list);
265 			list_add_tail(&iocb->list, &abort_list);
266 		}
267 	}
268 
269 	if (phba->sli_rev == LPFC_SLI_REV4)
270 		spin_unlock(&pring->ring_lock);
271 	spin_unlock_irq(&phba->hbalock);
272 
273 	/* Cancel all the IOCBs from the completions list */
274 	lpfc_sli_cancel_iocbs(phba, &abort_list,
275 			      IOSTAT_LOCAL_REJECT, IOERR_SLI_ABORTED);
276 
277 	lpfc_cancel_retry_delay_tmo(phba->pport, ndlp);
278 }
279 
280 /* lpfc_defer_pt2pt_acc - Complete SLI3 pt2pt processing on link up
281  * @phba: pointer to lpfc hba data structure.
282  * @link_mbox: pointer to CONFIG_LINK mailbox object
283  *
284  * This routine is only called if we are SLI3, direct connect pt2pt
285  * mode and the remote NPort issues the PLOGI after link up.
286  */
287 static void
lpfc_defer_pt2pt_acc(struct lpfc_hba * phba,LPFC_MBOXQ_t * link_mbox)288 lpfc_defer_pt2pt_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *link_mbox)
289 {
290 	LPFC_MBOXQ_t *login_mbox;
291 	MAILBOX_t *mb = &link_mbox->u.mb;
292 	struct lpfc_iocbq *save_iocb;
293 	struct lpfc_nodelist *ndlp;
294 	int rc;
295 
296 	ndlp = link_mbox->ctx_ndlp;
297 	login_mbox = link_mbox->context3;
298 	save_iocb = login_mbox->context3;
299 	link_mbox->context3 = NULL;
300 	login_mbox->context3 = NULL;
301 
302 	/* Check for CONFIG_LINK error */
303 	if (mb->mbxStatus) {
304 		lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
305 				"4575 CONFIG_LINK fails pt2pt discovery: %x\n",
306 				mb->mbxStatus);
307 		mempool_free(login_mbox, phba->mbox_mem_pool);
308 		mempool_free(link_mbox, phba->mbox_mem_pool);
309 		kfree(save_iocb);
310 		return;
311 	}
312 
313 	/* Now that CONFIG_LINK completed, and our SID is configured,
314 	 * we can now proceed with sending the PLOGI ACC.
315 	 */
316 	rc = lpfc_els_rsp_acc(link_mbox->vport, ELS_CMD_PLOGI,
317 			      save_iocb, ndlp, login_mbox);
318 	if (rc) {
319 		lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
320 				"4576 PLOGI ACC fails pt2pt discovery: %x\n",
321 				rc);
322 		mempool_free(login_mbox, phba->mbox_mem_pool);
323 	}
324 
325 	mempool_free(link_mbox, phba->mbox_mem_pool);
326 	kfree(save_iocb);
327 }
328 
329 /**
330  * lpfc_defer_tgt_acc - Progress SLI4 target rcv PLOGI handler
331  * @phba: Pointer to HBA context object.
332  * @pmb: Pointer to mailbox object.
333  *
334  * This function provides the unreg rpi mailbox completion handler for a tgt.
335  * The routine frees the memory resources associated with the completed
336  * mailbox command and transmits the ELS ACC.
337  *
338  * This routine is only called if we are SLI4, acting in target
339  * mode and the remote NPort issues the PLOGI after link up.
340  **/
341 static void
lpfc_defer_acc_rsp(struct lpfc_hba * phba,LPFC_MBOXQ_t * pmb)342 lpfc_defer_acc_rsp(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
343 {
344 	struct lpfc_vport *vport = pmb->vport;
345 	struct lpfc_nodelist *ndlp = pmb->ctx_ndlp;
346 	LPFC_MBOXQ_t *mbox = pmb->context3;
347 	struct lpfc_iocbq *piocb = NULL;
348 	int rc;
349 
350 	if (mbox) {
351 		pmb->context3 = NULL;
352 		piocb = mbox->context3;
353 		mbox->context3 = NULL;
354 	}
355 
356 	/*
357 	 * Complete the unreg rpi mbx request, and update flags.
358 	 * This will also restart any deferred events.
359 	 */
360 	lpfc_nlp_get(ndlp);
361 	lpfc_sli4_unreg_rpi_cmpl_clr(phba, pmb);
362 
363 	if (!piocb) {
364 		lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
365 				 "4578 PLOGI ACC fail\n");
366 		if (mbox)
367 			mempool_free(mbox, phba->mbox_mem_pool);
368 		goto out;
369 	}
370 
371 	rc = lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, piocb, ndlp, mbox);
372 	if (rc) {
373 		lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
374 				 "4579 PLOGI ACC fail %x\n", rc);
375 		if (mbox)
376 			mempool_free(mbox, phba->mbox_mem_pool);
377 	}
378 	kfree(piocb);
379 out:
380 	lpfc_nlp_put(ndlp);
381 }
382 
383 static int
lpfc_rcv_plogi(struct lpfc_vport * vport,struct lpfc_nodelist * ndlp,struct lpfc_iocbq * cmdiocb)384 lpfc_rcv_plogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
385 	       struct lpfc_iocbq *cmdiocb)
386 {
387 	struct Scsi_Host   *shost = lpfc_shost_from_vport(vport);
388 	struct lpfc_hba    *phba = vport->phba;
389 	struct lpfc_dmabuf *pcmd;
390 	uint64_t nlp_portwwn = 0;
391 	uint32_t *lp;
392 	IOCB_t *icmd;
393 	struct serv_parm *sp;
394 	uint32_t ed_tov;
395 	LPFC_MBOXQ_t *link_mbox;
396 	LPFC_MBOXQ_t *login_mbox;
397 	struct lpfc_iocbq *save_iocb;
398 	struct ls_rjt stat;
399 	uint32_t vid, flag;
400 	u16 rpi;
401 	int rc, defer_acc;
402 
403 	memset(&stat, 0, sizeof (struct ls_rjt));
404 	pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
405 	lp = (uint32_t *) pcmd->virt;
406 	sp = (struct serv_parm *) ((uint8_t *) lp + sizeof (uint32_t));
407 	if (wwn_to_u64(sp->portName.u.wwn) == 0) {
408 		lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
409 				 "0140 PLOGI Reject: invalid nname\n");
410 		stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
411 		stat.un.b.lsRjtRsnCodeExp = LSEXP_INVALID_PNAME;
412 		lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
413 			NULL);
414 		return 0;
415 	}
416 	if (wwn_to_u64(sp->nodeName.u.wwn) == 0) {
417 		lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
418 				 "0141 PLOGI Reject: invalid pname\n");
419 		stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
420 		stat.un.b.lsRjtRsnCodeExp = LSEXP_INVALID_NNAME;
421 		lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
422 			NULL);
423 		return 0;
424 	}
425 
426 	nlp_portwwn = wwn_to_u64(ndlp->nlp_portname.u.wwn);
427 	if ((lpfc_check_sparm(vport, ndlp, sp, CLASS3, 0) == 0)) {
428 		/* Reject this request because invalid parameters */
429 		stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
430 		stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
431 		lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
432 			NULL);
433 		return 0;
434 	}
435 	icmd = &cmdiocb->iocb;
436 
437 	/* PLOGI chkparm OK */
438 	lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
439 			 "0114 PLOGI chkparm OK Data: x%x x%x x%x "
440 			 "x%x x%x x%x\n",
441 			 ndlp->nlp_DID, ndlp->nlp_state, ndlp->nlp_flag,
442 			 ndlp->nlp_rpi, vport->port_state,
443 			 vport->fc_flag);
444 
445 	if (vport->cfg_fcp_class == 2 && sp->cls2.classValid)
446 		ndlp->nlp_fcp_info |= CLASS2;
447 	else
448 		ndlp->nlp_fcp_info |= CLASS3;
449 
450 	defer_acc = 0;
451 	ndlp->nlp_class_sup = 0;
452 	if (sp->cls1.classValid)
453 		ndlp->nlp_class_sup |= FC_COS_CLASS1;
454 	if (sp->cls2.classValid)
455 		ndlp->nlp_class_sup |= FC_COS_CLASS2;
456 	if (sp->cls3.classValid)
457 		ndlp->nlp_class_sup |= FC_COS_CLASS3;
458 	if (sp->cls4.classValid)
459 		ndlp->nlp_class_sup |= FC_COS_CLASS4;
460 	ndlp->nlp_maxframe =
461 		((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) | sp->cmn.bbRcvSizeLsb;
462 	/* if already logged in, do implicit logout */
463 	switch (ndlp->nlp_state) {
464 	case  NLP_STE_NPR_NODE:
465 		if (!(ndlp->nlp_flag & NLP_NPR_ADISC))
466 			break;
467 		fallthrough;
468 	case  NLP_STE_REG_LOGIN_ISSUE:
469 	case  NLP_STE_PRLI_ISSUE:
470 	case  NLP_STE_UNMAPPED_NODE:
471 	case  NLP_STE_MAPPED_NODE:
472 		/* For initiators, lpfc_plogi_confirm_nport skips fabric did.
473 		 * For target mode, execute implicit logo.
474 		 * Fabric nodes go into NPR.
475 		 */
476 		if (!(ndlp->nlp_type & NLP_FABRIC) &&
477 		    !(phba->nvmet_support)) {
478 			lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb,
479 					 ndlp, NULL);
480 			return 1;
481 		}
482 		if (nlp_portwwn != 0 &&
483 		    nlp_portwwn != wwn_to_u64(sp->portName.u.wwn))
484 			lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
485 					 "0143 PLOGI recv'd from DID: x%x "
486 					 "WWPN changed: old %llx new %llx\n",
487 					 ndlp->nlp_DID,
488 					 (unsigned long long)nlp_portwwn,
489 					 (unsigned long long)
490 					 wwn_to_u64(sp->portName.u.wwn));
491 
492 		/* Notify transport of connectivity loss to trigger cleanup. */
493 		if (phba->nvmet_support &&
494 		    ndlp->nlp_state == NLP_STE_UNMAPPED_NODE)
495 			lpfc_nvmet_invalidate_host(phba, ndlp);
496 
497 		ndlp->nlp_prev_state = ndlp->nlp_state;
498 		/* rport needs to be unregistered first */
499 		lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
500 		break;
501 	}
502 
503 	ndlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR);
504 	ndlp->nlp_type &= ~(NLP_NVME_TARGET | NLP_NVME_INITIATOR);
505 	ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
506 	ndlp->nlp_flag &= ~NLP_FIRSTBURST;
507 
508 	login_mbox = NULL;
509 	link_mbox = NULL;
510 	save_iocb = NULL;
511 
512 	/* Check for Nport to NPort pt2pt protocol */
513 	if ((vport->fc_flag & FC_PT2PT) &&
514 	    !(vport->fc_flag & FC_PT2PT_PLOGI)) {
515 		/* rcv'ed PLOGI decides what our NPortId will be */
516 		vport->fc_myDID = icmd->un.rcvels.parmRo;
517 
518 		ed_tov = be32_to_cpu(sp->cmn.e_d_tov);
519 		if (sp->cmn.edtovResolution) {
520 			/* E_D_TOV ticks are in nanoseconds */
521 			ed_tov = (phba->fc_edtov + 999999) / 1000000;
522 		}
523 
524 		/*
525 		 * For pt-to-pt, use the larger EDTOV
526 		 * RATOV = 2 * EDTOV
527 		 */
528 		if (ed_tov > phba->fc_edtov)
529 			phba->fc_edtov = ed_tov;
530 		phba->fc_ratov = (2 * phba->fc_edtov) / 1000;
531 
532 		memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
533 
534 		/* Issue config_link / reg_vfi to account for updated TOV's */
535 
536 		if (phba->sli_rev == LPFC_SLI_REV4)
537 			lpfc_issue_reg_vfi(vport);
538 		else {
539 			defer_acc = 1;
540 			link_mbox = mempool_alloc(phba->mbox_mem_pool,
541 						  GFP_KERNEL);
542 			if (!link_mbox)
543 				goto out;
544 			lpfc_config_link(phba, link_mbox);
545 			link_mbox->mbox_cmpl = lpfc_defer_pt2pt_acc;
546 			link_mbox->vport = vport;
547 			link_mbox->ctx_ndlp = ndlp;
548 
549 			save_iocb = kzalloc(sizeof(*save_iocb), GFP_KERNEL);
550 			if (!save_iocb)
551 				goto out;
552 			/* Save info from cmd IOCB used in rsp */
553 			memcpy((uint8_t *)save_iocb, (uint8_t *)cmdiocb,
554 			       sizeof(struct lpfc_iocbq));
555 		}
556 
557 		lpfc_can_disctmo(vport);
558 	}
559 
560 	ndlp->nlp_flag &= ~NLP_SUPPRESS_RSP;
561 	if ((phba->sli.sli_flag & LPFC_SLI_SUPPRESS_RSP) &&
562 	    sp->cmn.valid_vendor_ver_level) {
563 		vid = be32_to_cpu(sp->un.vv.vid);
564 		flag = be32_to_cpu(sp->un.vv.flags);
565 		if ((vid == LPFC_VV_EMLX_ID) && (flag & LPFC_VV_SUPPRESS_RSP))
566 			ndlp->nlp_flag |= NLP_SUPPRESS_RSP;
567 	}
568 
569 	login_mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
570 	if (!login_mbox)
571 		goto out;
572 
573 	/* Registering an existing RPI behaves differently for SLI3 vs SLI4 */
574 	if (phba->nvmet_support && !defer_acc) {
575 		link_mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
576 		if (!link_mbox)
577 			goto out;
578 
579 		/* As unique identifiers such as iotag would be overwritten
580 		 * with those from the cmdiocb, allocate separate temporary
581 		 * storage for the copy.
582 		 */
583 		save_iocb = kzalloc(sizeof(*save_iocb), GFP_KERNEL);
584 		if (!save_iocb)
585 			goto out;
586 
587 		/* Unreg RPI is required for SLI4. */
588 		rpi = phba->sli4_hba.rpi_ids[ndlp->nlp_rpi];
589 		lpfc_unreg_login(phba, vport->vpi, rpi, link_mbox);
590 		link_mbox->vport = vport;
591 		link_mbox->ctx_ndlp = ndlp;
592 		link_mbox->mbox_cmpl = lpfc_defer_acc_rsp;
593 
594 		if (((ndlp->nlp_DID & Fabric_DID_MASK) != Fabric_DID_MASK) &&
595 		    (!(vport->fc_flag & FC_OFFLINE_MODE)))
596 			ndlp->nlp_flag |= NLP_UNREG_INP;
597 
598 		/* Save info from cmd IOCB used in rsp */
599 		memcpy(save_iocb, cmdiocb, sizeof(*save_iocb));
600 
601 		/* Delay sending ACC till unreg RPI completes. */
602 		defer_acc = 1;
603 	} else if (phba->sli_rev == LPFC_SLI_REV4)
604 		lpfc_unreg_rpi(vport, ndlp);
605 
606 	rc = lpfc_reg_rpi(phba, vport->vpi, icmd->un.rcvels.remoteID,
607 			    (uint8_t *)sp, login_mbox, ndlp->nlp_rpi);
608 	if (rc)
609 		goto out;
610 
611 	/* ACC PLOGI rsp command needs to execute first,
612 	 * queue this login_mbox command to be processed later.
613 	 */
614 	login_mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
615 	/*
616 	 * login_mbox->ctx_ndlp = lpfc_nlp_get(ndlp) deferred until mailbox
617 	 * command issued in lpfc_cmpl_els_acc().
618 	 */
619 	login_mbox->vport = vport;
620 	spin_lock_irq(shost->host_lock);
621 	ndlp->nlp_flag |= (NLP_ACC_REGLOGIN | NLP_RCV_PLOGI);
622 	spin_unlock_irq(shost->host_lock);
623 
624 	/*
625 	 * If there is an outstanding PLOGI issued, abort it before
626 	 * sending ACC rsp for received PLOGI. If pending plogi
627 	 * is not canceled here, the plogi will be rejected by
628 	 * remote port and will be retried. On a configuration with
629 	 * single discovery thread, this will cause a huge delay in
630 	 * discovery. Also this will cause multiple state machines
631 	 * running in parallel for this node.
632 	 * This only applies to a fabric environment.
633 	 */
634 	if ((ndlp->nlp_state == NLP_STE_PLOGI_ISSUE) &&
635 	    (vport->fc_flag & FC_FABRIC)) {
636 		/* software abort outstanding PLOGI */
637 		lpfc_els_abort(phba, ndlp);
638 	}
639 
640 	if ((vport->port_type == LPFC_NPIV_PORT &&
641 	     vport->cfg_restrict_login)) {
642 
643 		/* no deferred ACC */
644 		kfree(save_iocb);
645 
646 		/* In order to preserve RPIs, we want to cleanup
647 		 * the default RPI the firmware created to rcv
648 		 * this ELS request. The only way to do this is
649 		 * to register, then unregister the RPI.
650 		 */
651 		spin_lock_irq(shost->host_lock);
652 		ndlp->nlp_flag |= NLP_RM_DFLT_RPI;
653 		spin_unlock_irq(shost->host_lock);
654 		stat.un.b.lsRjtRsnCode = LSRJT_INVALID_CMD;
655 		stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
656 		rc = lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb,
657 			ndlp, login_mbox);
658 		if (rc)
659 			mempool_free(login_mbox, phba->mbox_mem_pool);
660 		return 1;
661 	}
662 	if (defer_acc) {
663 		/* So the order here should be:
664 		 * SLI3 pt2pt
665 		 *   Issue CONFIG_LINK mbox
666 		 *   CONFIG_LINK cmpl
667 		 * SLI4 tgt
668 		 *   Issue UNREG RPI mbx
669 		 *   UNREG RPI cmpl
670 		 * Issue PLOGI ACC
671 		 * PLOGI ACC cmpl
672 		 * Issue REG_LOGIN mbox
673 		 */
674 
675 		/* Save the REG_LOGIN mbox for and rcv IOCB copy later */
676 		link_mbox->context3 = login_mbox;
677 		login_mbox->context3 = save_iocb;
678 
679 		/* Start the ball rolling by issuing CONFIG_LINK here */
680 		rc = lpfc_sli_issue_mbox(phba, link_mbox, MBX_NOWAIT);
681 		if (rc == MBX_NOT_FINISHED)
682 			goto out;
683 		return 1;
684 	}
685 
686 	rc = lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp, login_mbox);
687 	if (rc)
688 		mempool_free(login_mbox, phba->mbox_mem_pool);
689 	return 1;
690 out:
691 	if (defer_acc)
692 		lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
693 				"4577 discovery failure: %p %p %p\n",
694 				save_iocb, link_mbox, login_mbox);
695 	kfree(save_iocb);
696 	if (link_mbox)
697 		mempool_free(link_mbox, phba->mbox_mem_pool);
698 	if (login_mbox)
699 		mempool_free(login_mbox, phba->mbox_mem_pool);
700 
701 	stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
702 	stat.un.b.lsRjtRsnCodeExp = LSEXP_OUT_OF_RESOURCE;
703 	lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
704 	return 0;
705 }
706 
707 /**
708  * lpfc_mbx_cmpl_resume_rpi - Resume RPI completion routine
709  * @phba: pointer to lpfc hba data structure.
710  * @mboxq: pointer to mailbox object
711  *
712  * This routine is invoked to issue a completion to a rcv'ed
713  * ADISC or PDISC after the paused RPI has been resumed.
714  **/
715 static void
lpfc_mbx_cmpl_resume_rpi(struct lpfc_hba * phba,LPFC_MBOXQ_t * mboxq)716 lpfc_mbx_cmpl_resume_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
717 {
718 	struct lpfc_vport *vport;
719 	struct lpfc_iocbq *elsiocb;
720 	struct lpfc_nodelist *ndlp;
721 	uint32_t cmd;
722 
723 	elsiocb = (struct lpfc_iocbq *)mboxq->ctx_buf;
724 	ndlp = (struct lpfc_nodelist *)mboxq->ctx_ndlp;
725 	vport = mboxq->vport;
726 	cmd = elsiocb->drvrTimeout;
727 
728 	if (cmd == ELS_CMD_ADISC) {
729 		lpfc_els_rsp_adisc_acc(vport, elsiocb, ndlp);
730 	} else {
731 		lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, elsiocb,
732 			ndlp, NULL);
733 	}
734 	kfree(elsiocb);
735 	mempool_free(mboxq, phba->mbox_mem_pool);
736 }
737 
738 static int
lpfc_rcv_padisc(struct lpfc_vport * vport,struct lpfc_nodelist * ndlp,struct lpfc_iocbq * cmdiocb)739 lpfc_rcv_padisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
740 		struct lpfc_iocbq *cmdiocb)
741 {
742 	struct Scsi_Host   *shost = lpfc_shost_from_vport(vport);
743 	struct lpfc_iocbq  *elsiocb;
744 	struct lpfc_dmabuf *pcmd;
745 	struct serv_parm   *sp;
746 	struct lpfc_name   *pnn, *ppn;
747 	struct ls_rjt stat;
748 	ADISC *ap;
749 	IOCB_t *icmd;
750 	uint32_t *lp;
751 	uint32_t cmd;
752 
753 	pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
754 	lp = (uint32_t *) pcmd->virt;
755 
756 	cmd = *lp++;
757 	if (cmd == ELS_CMD_ADISC) {
758 		ap = (ADISC *) lp;
759 		pnn = (struct lpfc_name *) & ap->nodeName;
760 		ppn = (struct lpfc_name *) & ap->portName;
761 	} else {
762 		sp = (struct serv_parm *) lp;
763 		pnn = (struct lpfc_name *) & sp->nodeName;
764 		ppn = (struct lpfc_name *) & sp->portName;
765 	}
766 
767 	icmd = &cmdiocb->iocb;
768 	if (icmd->ulpStatus == 0 && lpfc_check_adisc(vport, ndlp, pnn, ppn)) {
769 
770 		/*
771 		 * As soon as  we send ACC, the remote NPort can
772 		 * start sending us data. Thus, for SLI4 we must
773 		 * resume the RPI before the ACC goes out.
774 		 */
775 		if (vport->phba->sli_rev == LPFC_SLI_REV4) {
776 			elsiocb = kmalloc(sizeof(struct lpfc_iocbq),
777 				GFP_KERNEL);
778 			if (elsiocb) {
779 
780 				/* Save info from cmd IOCB used in rsp */
781 				memcpy((uint8_t *)elsiocb, (uint8_t *)cmdiocb,
782 					sizeof(struct lpfc_iocbq));
783 
784 				/* Save the ELS cmd */
785 				elsiocb->drvrTimeout = cmd;
786 
787 				lpfc_sli4_resume_rpi(ndlp,
788 					lpfc_mbx_cmpl_resume_rpi, elsiocb);
789 				goto out;
790 			}
791 		}
792 
793 		if (cmd == ELS_CMD_ADISC) {
794 			lpfc_els_rsp_adisc_acc(vport, cmdiocb, ndlp);
795 		} else {
796 			lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb,
797 				ndlp, NULL);
798 		}
799 out:
800 		/* If we are authenticated, move to the proper state.
801 		 * It is possible an ADISC arrived and the remote nport
802 		 * is already in MAPPED or UNMAPPED state.  Catch this
803 		 * condition and don't set the nlp_state again because
804 		 * it causes an unnecessary transport unregister/register.
805 		 */
806 		if (ndlp->nlp_type & (NLP_FCP_TARGET | NLP_NVME_TARGET)) {
807 			if (ndlp->nlp_state != NLP_STE_MAPPED_NODE)
808 				lpfc_nlp_set_state(vport, ndlp,
809 						   NLP_STE_MAPPED_NODE);
810 		}
811 
812 		return 1;
813 	}
814 	/* Reject this request because invalid parameters */
815 	stat.un.b.lsRjtRsvd0 = 0;
816 	stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
817 	stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
818 	stat.un.b.vendorUnique = 0;
819 	lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
820 
821 	/* 1 sec timeout */
822 	mod_timer(&ndlp->nlp_delayfunc, jiffies + msecs_to_jiffies(1000));
823 
824 	spin_lock_irq(shost->host_lock);
825 	ndlp->nlp_flag |= NLP_DELAY_TMO;
826 	spin_unlock_irq(shost->host_lock);
827 	ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
828 	ndlp->nlp_prev_state = ndlp->nlp_state;
829 	lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
830 	return 0;
831 }
832 
833 static int
lpfc_rcv_logo(struct lpfc_vport * vport,struct lpfc_nodelist * ndlp,struct lpfc_iocbq * cmdiocb,uint32_t els_cmd)834 lpfc_rcv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
835 	      struct lpfc_iocbq *cmdiocb, uint32_t els_cmd)
836 {
837 	struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
838 	struct lpfc_hba    *phba = vport->phba;
839 	struct lpfc_vport **vports;
840 	int i, active_vlink_present = 0 ;
841 
842 	/* Put ndlp in NPR state with 1 sec timeout for plogi, ACC logo */
843 	/* Only call LOGO ACC for first LOGO, this avoids sending unnecessary
844 	 * PLOGIs during LOGO storms from a device.
845 	 */
846 	spin_lock_irq(shost->host_lock);
847 	ndlp->nlp_flag |= NLP_LOGO_ACC;
848 	spin_unlock_irq(shost->host_lock);
849 	if (els_cmd == ELS_CMD_PRLO)
850 		lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL);
851 	else
852 		lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
853 
854 	/* Notify transport of connectivity loss to trigger cleanup. */
855 	if (phba->nvmet_support &&
856 	    ndlp->nlp_state == NLP_STE_UNMAPPED_NODE)
857 		lpfc_nvmet_invalidate_host(phba, ndlp);
858 
859 	if (ndlp->nlp_DID == Fabric_DID) {
860 		if (vport->port_state <= LPFC_FDISC)
861 			goto out;
862 		lpfc_linkdown_port(vport);
863 		spin_lock_irq(shost->host_lock);
864 		vport->fc_flag |= FC_VPORT_LOGO_RCVD;
865 		spin_unlock_irq(shost->host_lock);
866 		vports = lpfc_create_vport_work_array(phba);
867 		if (vports) {
868 			for (i = 0; i <= phba->max_vports && vports[i] != NULL;
869 					i++) {
870 				if ((!(vports[i]->fc_flag &
871 					FC_VPORT_LOGO_RCVD)) &&
872 					(vports[i]->port_state > LPFC_FDISC)) {
873 					active_vlink_present = 1;
874 					break;
875 				}
876 			}
877 			lpfc_destroy_vport_work_array(phba, vports);
878 		}
879 
880 		/*
881 		 * Don't re-instantiate if vport is marked for deletion.
882 		 * If we are here first then vport_delete is going to wait
883 		 * for discovery to complete.
884 		 */
885 		if (!(vport->load_flag & FC_UNLOADING) &&
886 					active_vlink_present) {
887 			/*
888 			 * If there are other active VLinks present,
889 			 * re-instantiate the Vlink using FDISC.
890 			 */
891 			mod_timer(&ndlp->nlp_delayfunc,
892 				  jiffies + msecs_to_jiffies(1000));
893 			spin_lock_irq(shost->host_lock);
894 			ndlp->nlp_flag |= NLP_DELAY_TMO;
895 			spin_unlock_irq(shost->host_lock);
896 			ndlp->nlp_last_elscmd = ELS_CMD_FDISC;
897 			vport->port_state = LPFC_FDISC;
898 		} else {
899 			spin_lock_irq(shost->host_lock);
900 			phba->pport->fc_flag &= ~FC_LOGO_RCVD_DID_CHNG;
901 			spin_unlock_irq(shost->host_lock);
902 			lpfc_retry_pport_discovery(phba);
903 		}
904 	} else if ((!(ndlp->nlp_type & NLP_FABRIC) &&
905 		((ndlp->nlp_type & NLP_FCP_TARGET) ||
906 		(ndlp->nlp_type & NLP_NVME_TARGET) ||
907 		(vport->fc_flag & FC_PT2PT))) ||
908 		(ndlp->nlp_state == NLP_STE_ADISC_ISSUE)) {
909 		/* Only try to re-login if this is NOT a Fabric Node
910 		 * AND the remote NPORT is a FCP/NVME Target or we
911 		 * are in pt2pt mode. NLP_STE_ADISC_ISSUE is a special
912 		 * case for LOGO as a response to ADISC behavior.
913 		 */
914 		mod_timer(&ndlp->nlp_delayfunc,
915 			  jiffies + msecs_to_jiffies(1000 * 1));
916 		spin_lock_irq(shost->host_lock);
917 		ndlp->nlp_flag |= NLP_DELAY_TMO;
918 		spin_unlock_irq(shost->host_lock);
919 
920 		ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
921 	}
922 out:
923 	ndlp->nlp_prev_state = ndlp->nlp_state;
924 	lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
925 
926 	spin_lock_irq(shost->host_lock);
927 	ndlp->nlp_flag &= ~NLP_NPR_ADISC;
928 	spin_unlock_irq(shost->host_lock);
929 	/* The driver has to wait until the ACC completes before it continues
930 	 * processing the LOGO.  The action will resume in
931 	 * lpfc_cmpl_els_logo_acc routine. Since part of processing includes an
932 	 * unreg_login, the driver waits so the ACC does not get aborted.
933 	 */
934 	return 0;
935 }
936 
937 static uint32_t
lpfc_rcv_prli_support_check(struct lpfc_vport * vport,struct lpfc_nodelist * ndlp,struct lpfc_iocbq * cmdiocb)938 lpfc_rcv_prli_support_check(struct lpfc_vport *vport,
939 			    struct lpfc_nodelist *ndlp,
940 			    struct lpfc_iocbq *cmdiocb)
941 {
942 	struct ls_rjt stat;
943 	uint32_t *payload;
944 	uint32_t cmd;
945 
946 	payload = ((struct lpfc_dmabuf *)cmdiocb->context2)->virt;
947 	cmd = *payload;
948 	if (vport->phba->nvmet_support) {
949 		/* Must be a NVME PRLI */
950 		if (cmd ==  ELS_CMD_PRLI)
951 			goto out;
952 	} else {
953 		/* Initiator mode. */
954 		if (!vport->nvmei_support && (cmd == ELS_CMD_NVMEPRLI))
955 			goto out;
956 	}
957 	return 1;
958 out:
959 	lpfc_printf_vlog(vport, KERN_WARNING, LOG_NVME_DISC,
960 			 "6115 Rcv PRLI (%x) check failed: ndlp rpi %d "
961 			 "state x%x flags x%x\n",
962 			 cmd, ndlp->nlp_rpi, ndlp->nlp_state,
963 			 ndlp->nlp_flag);
964 	memset(&stat, 0, sizeof(struct ls_rjt));
965 	stat.un.b.lsRjtRsnCode = LSRJT_CMD_UNSUPPORTED;
966 	stat.un.b.lsRjtRsnCodeExp = LSEXP_REQ_UNSUPPORTED;
967 	lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb,
968 			    ndlp, NULL);
969 	return 0;
970 }
971 
972 static void
lpfc_rcv_prli(struct lpfc_vport * vport,struct lpfc_nodelist * ndlp,struct lpfc_iocbq * cmdiocb)973 lpfc_rcv_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
974 	      struct lpfc_iocbq *cmdiocb)
975 {
976 	struct lpfc_hba  *phba = vport->phba;
977 	struct lpfc_dmabuf *pcmd;
978 	uint32_t *lp;
979 	PRLI *npr;
980 	struct fc_rport *rport = ndlp->rport;
981 	u32 roles;
982 
983 	pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
984 	lp = (uint32_t *) pcmd->virt;
985 	npr = (PRLI *) ((uint8_t *) lp + sizeof (uint32_t));
986 
987 	if ((npr->prliType == PRLI_FCP_TYPE) ||
988 	    (npr->prliType == PRLI_NVME_TYPE)) {
989 		if (npr->initiatorFunc) {
990 			if (npr->prliType == PRLI_FCP_TYPE)
991 				ndlp->nlp_type |= NLP_FCP_INITIATOR;
992 			if (npr->prliType == PRLI_NVME_TYPE)
993 				ndlp->nlp_type |= NLP_NVME_INITIATOR;
994 		}
995 		if (npr->targetFunc) {
996 			if (npr->prliType == PRLI_FCP_TYPE)
997 				ndlp->nlp_type |= NLP_FCP_TARGET;
998 			if (npr->prliType == PRLI_NVME_TYPE)
999 				ndlp->nlp_type |= NLP_NVME_TARGET;
1000 			if (npr->writeXferRdyDis)
1001 				ndlp->nlp_flag |= NLP_FIRSTBURST;
1002 		}
1003 		if (npr->Retry && ndlp->nlp_type &
1004 					(NLP_FCP_INITIATOR | NLP_FCP_TARGET))
1005 			ndlp->nlp_fcp_info |= NLP_FCP_2_DEVICE;
1006 
1007 		if (npr->Retry && phba->nsler &&
1008 		    ndlp->nlp_type & (NLP_NVME_INITIATOR | NLP_NVME_TARGET))
1009 			ndlp->nlp_nvme_info |= NLP_NVME_NSLER;
1010 
1011 
1012 		/* If this driver is in nvme target mode, set the ndlp's fc4
1013 		 * type to NVME provided the PRLI response claims NVME FC4
1014 		 * type.  Target mode does not issue gft_id so doesn't get
1015 		 * the fc4 type set until now.
1016 		 */
1017 		if (phba->nvmet_support && (npr->prliType == PRLI_NVME_TYPE)) {
1018 			ndlp->nlp_fc4_type |= NLP_FC4_NVME;
1019 			lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
1020 		}
1021 		if (npr->prliType == PRLI_FCP_TYPE)
1022 			ndlp->nlp_fc4_type |= NLP_FC4_FCP;
1023 	}
1024 	if (rport) {
1025 		/* We need to update the rport role values */
1026 		roles = FC_RPORT_ROLE_UNKNOWN;
1027 		if (ndlp->nlp_type & NLP_FCP_INITIATOR)
1028 			roles |= FC_RPORT_ROLE_FCP_INITIATOR;
1029 		if (ndlp->nlp_type & NLP_FCP_TARGET)
1030 			roles |= FC_RPORT_ROLE_FCP_TARGET;
1031 
1032 		lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
1033 			"rport rolechg:   role:x%x did:x%x flg:x%x",
1034 			roles, ndlp->nlp_DID, ndlp->nlp_flag);
1035 
1036 		if (vport->cfg_enable_fc4_type != LPFC_ENABLE_NVME)
1037 			fc_remote_port_rolechg(rport, roles);
1038 	}
1039 }
1040 
1041 static uint32_t
lpfc_disc_set_adisc(struct lpfc_vport * vport,struct lpfc_nodelist * ndlp)1042 lpfc_disc_set_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
1043 {
1044 	struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1045 
1046 	if (!(ndlp->nlp_flag & NLP_RPI_REGISTERED)) {
1047 		spin_lock_irq(shost->host_lock);
1048 		ndlp->nlp_flag &= ~NLP_NPR_ADISC;
1049 		spin_unlock_irq(shost->host_lock);
1050 		return 0;
1051 	}
1052 
1053 	if (!(vport->fc_flag & FC_PT2PT)) {
1054 		/* Check config parameter use-adisc or FCP-2 */
1055 		if (vport->cfg_use_adisc && ((vport->fc_flag & FC_RSCN_MODE) ||
1056 		    ((ndlp->nlp_fcp_info & NLP_FCP_2_DEVICE) &&
1057 		     (ndlp->nlp_type & NLP_FCP_TARGET)))) {
1058 			spin_lock_irq(shost->host_lock);
1059 			ndlp->nlp_flag |= NLP_NPR_ADISC;
1060 			spin_unlock_irq(shost->host_lock);
1061 			return 1;
1062 		}
1063 	}
1064 
1065 	spin_lock_irq(shost->host_lock);
1066 	ndlp->nlp_flag &= ~NLP_NPR_ADISC;
1067 	spin_unlock_irq(shost->host_lock);
1068 	lpfc_unreg_rpi(vport, ndlp);
1069 	return 0;
1070 }
1071 
1072 /**
1073  * lpfc_release_rpi - Release a RPI by issuing unreg_login mailbox cmd.
1074  * @phba : Pointer to lpfc_hba structure.
1075  * @vport: Pointer to lpfc_vport structure.
1076  * @ndlp: Pointer to lpfc_nodelist structure.
1077  * @rpi  : rpi to be release.
1078  *
1079  * This function will send a unreg_login mailbox command to the firmware
1080  * to release a rpi.
1081  **/
1082 static void
lpfc_release_rpi(struct lpfc_hba * phba,struct lpfc_vport * vport,struct lpfc_nodelist * ndlp,uint16_t rpi)1083 lpfc_release_rpi(struct lpfc_hba *phba, struct lpfc_vport *vport,
1084 		 struct lpfc_nodelist *ndlp, uint16_t rpi)
1085 {
1086 	LPFC_MBOXQ_t *pmb;
1087 	int rc;
1088 
1089 	/* If there is already an UNREG in progress for this ndlp,
1090 	 * no need to queue up another one.
1091 	 */
1092 	if (ndlp->nlp_flag & NLP_UNREG_INP) {
1093 		lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1094 				 "1435 release_rpi SKIP UNREG x%x on "
1095 				 "NPort x%x deferred x%x  flg x%x "
1096 				 "Data: x%px\n",
1097 				 ndlp->nlp_rpi, ndlp->nlp_DID,
1098 				 ndlp->nlp_defer_did,
1099 				 ndlp->nlp_flag, ndlp);
1100 		return;
1101 	}
1102 
1103 	pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
1104 			GFP_KERNEL);
1105 	if (!pmb)
1106 		lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1107 				 "2796 mailbox memory allocation failed \n");
1108 	else {
1109 		lpfc_unreg_login(phba, vport->vpi, rpi, pmb);
1110 		pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1111 		pmb->vport = vport;
1112 		pmb->ctx_ndlp = ndlp;
1113 
1114 		if (((ndlp->nlp_DID & Fabric_DID_MASK) != Fabric_DID_MASK) &&
1115 		    (!(vport->fc_flag & FC_OFFLINE_MODE)))
1116 			ndlp->nlp_flag |= NLP_UNREG_INP;
1117 
1118 		lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1119 				 "1437 release_rpi UNREG x%x "
1120 				 "on NPort x%x flg x%x\n",
1121 				 ndlp->nlp_rpi, ndlp->nlp_DID, ndlp->nlp_flag);
1122 
1123 		rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
1124 		if (rc == MBX_NOT_FINISHED)
1125 			mempool_free(pmb, phba->mbox_mem_pool);
1126 	}
1127 }
1128 
1129 static uint32_t
lpfc_disc_illegal(struct lpfc_vport * vport,struct lpfc_nodelist * ndlp,void * arg,uint32_t evt)1130 lpfc_disc_illegal(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1131 		  void *arg, uint32_t evt)
1132 {
1133 	struct lpfc_hba *phba;
1134 	LPFC_MBOXQ_t *pmb = (LPFC_MBOXQ_t *) arg;
1135 	uint16_t rpi;
1136 
1137 	phba = vport->phba;
1138 	/* Release the RPI if reglogin completing */
1139 	if (!(phba->pport->load_flag & FC_UNLOADING) &&
1140 		(evt == NLP_EVT_CMPL_REG_LOGIN) &&
1141 		(!pmb->u.mb.mbxStatus)) {
1142 		rpi = pmb->u.mb.un.varWords[0];
1143 		lpfc_release_rpi(phba, vport, ndlp, rpi);
1144 	}
1145 	lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1146 			 "0271 Illegal State Transition: node x%x "
1147 			 "event x%x, state x%x Data: x%x x%x\n",
1148 			 ndlp->nlp_DID, evt, ndlp->nlp_state, ndlp->nlp_rpi,
1149 			 ndlp->nlp_flag);
1150 	return ndlp->nlp_state;
1151 }
1152 
1153 static uint32_t
lpfc_cmpl_plogi_illegal(struct lpfc_vport * vport,struct lpfc_nodelist * ndlp,void * arg,uint32_t evt)1154 lpfc_cmpl_plogi_illegal(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1155 		  void *arg, uint32_t evt)
1156 {
1157 	/* This transition is only legal if we previously
1158 	 * rcv'ed a PLOGI. Since we don't want 2 discovery threads
1159 	 * working on the same NPortID, do nothing for this thread
1160 	 * to stop it.
1161 	 */
1162 	if (!(ndlp->nlp_flag & NLP_RCV_PLOGI)) {
1163 		lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1164 				 "0272 Illegal State Transition: node x%x "
1165 				 "event x%x, state x%x Data: x%x x%x\n",
1166 				  ndlp->nlp_DID, evt, ndlp->nlp_state,
1167 				  ndlp->nlp_rpi, ndlp->nlp_flag);
1168 	}
1169 	return ndlp->nlp_state;
1170 }
1171 
1172 /* Start of Discovery State Machine routines */
1173 
1174 static uint32_t
lpfc_rcv_plogi_unused_node(struct lpfc_vport * vport,struct lpfc_nodelist * ndlp,void * arg,uint32_t evt)1175 lpfc_rcv_plogi_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1176 			   void *arg, uint32_t evt)
1177 {
1178 	struct lpfc_iocbq *cmdiocb;
1179 
1180 	cmdiocb = (struct lpfc_iocbq *) arg;
1181 
1182 	if (lpfc_rcv_plogi(vport, ndlp, cmdiocb)) {
1183 		return ndlp->nlp_state;
1184 	}
1185 	return NLP_STE_FREED_NODE;
1186 }
1187 
1188 static uint32_t
lpfc_rcv_els_unused_node(struct lpfc_vport * vport,struct lpfc_nodelist * ndlp,void * arg,uint32_t evt)1189 lpfc_rcv_els_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1190 			 void *arg, uint32_t evt)
1191 {
1192 	lpfc_issue_els_logo(vport, ndlp, 0);
1193 	return ndlp->nlp_state;
1194 }
1195 
1196 static uint32_t
lpfc_rcv_logo_unused_node(struct lpfc_vport * vport,struct lpfc_nodelist * ndlp,void * arg,uint32_t evt)1197 lpfc_rcv_logo_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1198 			  void *arg, uint32_t evt)
1199 {
1200 	struct Scsi_Host  *shost = lpfc_shost_from_vport(vport);
1201 	struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1202 
1203 	spin_lock_irq(shost->host_lock);
1204 	ndlp->nlp_flag |= NLP_LOGO_ACC;
1205 	spin_unlock_irq(shost->host_lock);
1206 	lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
1207 
1208 	return ndlp->nlp_state;
1209 }
1210 
1211 static uint32_t
lpfc_cmpl_logo_unused_node(struct lpfc_vport * vport,struct lpfc_nodelist * ndlp,void * arg,uint32_t evt)1212 lpfc_cmpl_logo_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1213 			   void *arg, uint32_t evt)
1214 {
1215 	return NLP_STE_FREED_NODE;
1216 }
1217 
1218 static uint32_t
lpfc_device_rm_unused_node(struct lpfc_vport * vport,struct lpfc_nodelist * ndlp,void * arg,uint32_t evt)1219 lpfc_device_rm_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1220 			   void *arg, uint32_t evt)
1221 {
1222 	return NLP_STE_FREED_NODE;
1223 }
1224 
1225 static uint32_t
lpfc_device_recov_unused_node(struct lpfc_vport * vport,struct lpfc_nodelist * ndlp,void * arg,uint32_t evt)1226 lpfc_device_recov_unused_node(struct lpfc_vport *vport,
1227 			struct lpfc_nodelist *ndlp,
1228 			   void *arg, uint32_t evt)
1229 {
1230 	return ndlp->nlp_state;
1231 }
1232 
1233 static uint32_t
lpfc_rcv_plogi_plogi_issue(struct lpfc_vport * vport,struct lpfc_nodelist * ndlp,void * arg,uint32_t evt)1234 lpfc_rcv_plogi_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1235 			   void *arg, uint32_t evt)
1236 {
1237 	struct Scsi_Host   *shost = lpfc_shost_from_vport(vport);
1238 	struct lpfc_hba   *phba = vport->phba;
1239 	struct lpfc_iocbq *cmdiocb = arg;
1240 	struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
1241 	uint32_t *lp = (uint32_t *) pcmd->virt;
1242 	struct serv_parm *sp = (struct serv_parm *) (lp + 1);
1243 	struct ls_rjt stat;
1244 	int port_cmp;
1245 
1246 	memset(&stat, 0, sizeof (struct ls_rjt));
1247 
1248 	/* For a PLOGI, we only accept if our portname is less
1249 	 * than the remote portname.
1250 	 */
1251 	phba->fc_stat.elsLogiCol++;
1252 	port_cmp = memcmp(&vport->fc_portname, &sp->portName,
1253 			  sizeof(struct lpfc_name));
1254 
1255 	if (port_cmp >= 0) {
1256 		/* Reject this request because the remote node will accept
1257 		   ours */
1258 		stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
1259 		stat.un.b.lsRjtRsnCodeExp = LSEXP_CMD_IN_PROGRESS;
1260 		lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
1261 			NULL);
1262 	} else {
1263 		if (lpfc_rcv_plogi(vport, ndlp, cmdiocb) &&
1264 		    (ndlp->nlp_flag & NLP_NPR_2B_DISC) &&
1265 		    (vport->num_disc_nodes)) {
1266 			spin_lock_irq(shost->host_lock);
1267 			ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
1268 			spin_unlock_irq(shost->host_lock);
1269 			/* Check if there are more PLOGIs to be sent */
1270 			lpfc_more_plogi(vport);
1271 			if (vport->num_disc_nodes == 0) {
1272 				spin_lock_irq(shost->host_lock);
1273 				vport->fc_flag &= ~FC_NDISC_ACTIVE;
1274 				spin_unlock_irq(shost->host_lock);
1275 				lpfc_can_disctmo(vport);
1276 				lpfc_end_rscn(vport);
1277 			}
1278 		}
1279 	} /* If our portname was less */
1280 
1281 	return ndlp->nlp_state;
1282 }
1283 
1284 static uint32_t
lpfc_rcv_prli_plogi_issue(struct lpfc_vport * vport,struct lpfc_nodelist * ndlp,void * arg,uint32_t evt)1285 lpfc_rcv_prli_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1286 			  void *arg, uint32_t evt)
1287 {
1288 	struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1289 	struct ls_rjt     stat;
1290 
1291 	memset(&stat, 0, sizeof (struct ls_rjt));
1292 	stat.un.b.lsRjtRsnCode = LSRJT_LOGICAL_BSY;
1293 	stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
1294 	lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
1295 	return ndlp->nlp_state;
1296 }
1297 
1298 static uint32_t
lpfc_rcv_logo_plogi_issue(struct lpfc_vport * vport,struct lpfc_nodelist * ndlp,void * arg,uint32_t evt)1299 lpfc_rcv_logo_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1300 			  void *arg, uint32_t evt)
1301 {
1302 	struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1303 
1304 	/* Retrieve RPI from LOGO IOCB. RPI is used for CMD_ABORT_XRI_CN */
1305 	if (vport->phba->sli_rev == LPFC_SLI_REV3)
1306 		ndlp->nlp_rpi = cmdiocb->iocb.ulpIoTag;
1307 				/* software abort outstanding PLOGI */
1308 	lpfc_els_abort(vport->phba, ndlp);
1309 
1310 	lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
1311 	return ndlp->nlp_state;
1312 }
1313 
1314 static uint32_t
lpfc_rcv_els_plogi_issue(struct lpfc_vport * vport,struct lpfc_nodelist * ndlp,void * arg,uint32_t evt)1315 lpfc_rcv_els_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1316 			 void *arg, uint32_t evt)
1317 {
1318 	struct Scsi_Host  *shost = lpfc_shost_from_vport(vport);
1319 	struct lpfc_hba   *phba = vport->phba;
1320 	struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1321 
1322 	/* software abort outstanding PLOGI */
1323 	lpfc_els_abort(phba, ndlp);
1324 
1325 	if (evt == NLP_EVT_RCV_LOGO) {
1326 		lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
1327 	} else {
1328 		lpfc_issue_els_logo(vport, ndlp, 0);
1329 	}
1330 
1331 	/* Put ndlp in npr state set plogi timer for 1 sec */
1332 	mod_timer(&ndlp->nlp_delayfunc, jiffies + msecs_to_jiffies(1000 * 1));
1333 	spin_lock_irq(shost->host_lock);
1334 	ndlp->nlp_flag |= NLP_DELAY_TMO;
1335 	spin_unlock_irq(shost->host_lock);
1336 	ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
1337 	ndlp->nlp_prev_state = NLP_STE_PLOGI_ISSUE;
1338 	lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1339 
1340 	return ndlp->nlp_state;
1341 }
1342 
1343 static uint32_t
lpfc_cmpl_plogi_plogi_issue(struct lpfc_vport * vport,struct lpfc_nodelist * ndlp,void * arg,uint32_t evt)1344 lpfc_cmpl_plogi_plogi_issue(struct lpfc_vport *vport,
1345 			    struct lpfc_nodelist *ndlp,
1346 			    void *arg,
1347 			    uint32_t evt)
1348 {
1349 	struct lpfc_hba    *phba = vport->phba;
1350 	struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1351 	struct lpfc_iocbq  *cmdiocb, *rspiocb;
1352 	struct lpfc_dmabuf *pcmd, *prsp, *mp;
1353 	uint32_t *lp;
1354 	uint32_t vid, flag;
1355 	IOCB_t *irsp;
1356 	struct serv_parm *sp;
1357 	uint32_t ed_tov;
1358 	LPFC_MBOXQ_t *mbox;
1359 	int rc;
1360 
1361 	cmdiocb = (struct lpfc_iocbq *) arg;
1362 	rspiocb = cmdiocb->context_un.rsp_iocb;
1363 
1364 	if (ndlp->nlp_flag & NLP_ACC_REGLOGIN) {
1365 		/* Recovery from PLOGI collision logic */
1366 		return ndlp->nlp_state;
1367 	}
1368 
1369 	irsp = &rspiocb->iocb;
1370 
1371 	if (irsp->ulpStatus)
1372 		goto out;
1373 
1374 	pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
1375 
1376 	prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
1377 	if (!prsp)
1378 		goto out;
1379 
1380 	lp = (uint32_t *) prsp->virt;
1381 	sp = (struct serv_parm *) ((uint8_t *) lp + sizeof (uint32_t));
1382 
1383 	/* Some switches have FDMI servers returning 0 for WWN */
1384 	if ((ndlp->nlp_DID != FDMI_DID) &&
1385 		(wwn_to_u64(sp->portName.u.wwn) == 0 ||
1386 		wwn_to_u64(sp->nodeName.u.wwn) == 0)) {
1387 		lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1388 				 "0142 PLOGI RSP: Invalid WWN.\n");
1389 		goto out;
1390 	}
1391 	if (!lpfc_check_sparm(vport, ndlp, sp, CLASS3, 0))
1392 		goto out;
1393 	/* PLOGI chkparm OK */
1394 	lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1395 			 "0121 PLOGI chkparm OK Data: x%x x%x x%x x%x\n",
1396 			 ndlp->nlp_DID, ndlp->nlp_state,
1397 			 ndlp->nlp_flag, ndlp->nlp_rpi);
1398 	if (vport->cfg_fcp_class == 2 && (sp->cls2.classValid))
1399 		ndlp->nlp_fcp_info |= CLASS2;
1400 	else
1401 		ndlp->nlp_fcp_info |= CLASS3;
1402 
1403 	ndlp->nlp_class_sup = 0;
1404 	if (sp->cls1.classValid)
1405 		ndlp->nlp_class_sup |= FC_COS_CLASS1;
1406 	if (sp->cls2.classValid)
1407 		ndlp->nlp_class_sup |= FC_COS_CLASS2;
1408 	if (sp->cls3.classValid)
1409 		ndlp->nlp_class_sup |= FC_COS_CLASS3;
1410 	if (sp->cls4.classValid)
1411 		ndlp->nlp_class_sup |= FC_COS_CLASS4;
1412 	ndlp->nlp_maxframe =
1413 		((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) | sp->cmn.bbRcvSizeLsb;
1414 
1415 	if ((vport->fc_flag & FC_PT2PT) &&
1416 	    (vport->fc_flag & FC_PT2PT_PLOGI)) {
1417 		ed_tov = be32_to_cpu(sp->cmn.e_d_tov);
1418 		if (sp->cmn.edtovResolution) {
1419 			/* E_D_TOV ticks are in nanoseconds */
1420 			ed_tov = (phba->fc_edtov + 999999) / 1000000;
1421 		}
1422 
1423 		ndlp->nlp_flag &= ~NLP_SUPPRESS_RSP;
1424 		if ((phba->sli.sli_flag & LPFC_SLI_SUPPRESS_RSP) &&
1425 		    sp->cmn.valid_vendor_ver_level) {
1426 			vid = be32_to_cpu(sp->un.vv.vid);
1427 			flag = be32_to_cpu(sp->un.vv.flags);
1428 			if ((vid == LPFC_VV_EMLX_ID) &&
1429 			    (flag & LPFC_VV_SUPPRESS_RSP))
1430 				ndlp->nlp_flag |= NLP_SUPPRESS_RSP;
1431 		}
1432 
1433 		/*
1434 		 * Use the larger EDTOV
1435 		 * RATOV = 2 * EDTOV for pt-to-pt
1436 		 */
1437 		if (ed_tov > phba->fc_edtov)
1438 			phba->fc_edtov = ed_tov;
1439 		phba->fc_ratov = (2 * phba->fc_edtov) / 1000;
1440 
1441 		memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
1442 
1443 		/* Issue config_link / reg_vfi to account for updated TOV's */
1444 		if (phba->sli_rev == LPFC_SLI_REV4) {
1445 			lpfc_issue_reg_vfi(vport);
1446 		} else {
1447 			mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1448 			if (!mbox) {
1449 				lpfc_printf_vlog(vport, KERN_ERR,
1450 						 LOG_TRACE_EVENT,
1451 						 "0133 PLOGI: no memory "
1452 						 "for config_link "
1453 						 "Data: x%x x%x x%x x%x\n",
1454 						 ndlp->nlp_DID, ndlp->nlp_state,
1455 						 ndlp->nlp_flag, ndlp->nlp_rpi);
1456 				goto out;
1457 			}
1458 
1459 			lpfc_config_link(phba, mbox);
1460 
1461 			mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1462 			mbox->vport = vport;
1463 			rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
1464 			if (rc == MBX_NOT_FINISHED) {
1465 				mempool_free(mbox, phba->mbox_mem_pool);
1466 				goto out;
1467 			}
1468 		}
1469 	}
1470 
1471 	lpfc_unreg_rpi(vport, ndlp);
1472 
1473 	mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1474 	if (!mbox) {
1475 		lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1476 				 "0018 PLOGI: no memory for reg_login "
1477 				 "Data: x%x x%x x%x x%x\n",
1478 				 ndlp->nlp_DID, ndlp->nlp_state,
1479 				 ndlp->nlp_flag, ndlp->nlp_rpi);
1480 		goto out;
1481 	}
1482 
1483 	if (lpfc_reg_rpi(phba, vport->vpi, irsp->un.elsreq64.remoteID,
1484 			 (uint8_t *) sp, mbox, ndlp->nlp_rpi) == 0) {
1485 		switch (ndlp->nlp_DID) {
1486 		case NameServer_DID:
1487 			mbox->mbox_cmpl = lpfc_mbx_cmpl_ns_reg_login;
1488 			break;
1489 		case FDMI_DID:
1490 			mbox->mbox_cmpl = lpfc_mbx_cmpl_fdmi_reg_login;
1491 			break;
1492 		default:
1493 			ndlp->nlp_flag |= NLP_REG_LOGIN_SEND;
1494 			mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
1495 		}
1496 		mbox->ctx_ndlp = lpfc_nlp_get(ndlp);
1497 		mbox->vport = vport;
1498 		if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
1499 		    != MBX_NOT_FINISHED) {
1500 			lpfc_nlp_set_state(vport, ndlp,
1501 					   NLP_STE_REG_LOGIN_ISSUE);
1502 			return ndlp->nlp_state;
1503 		}
1504 		if (ndlp->nlp_flag & NLP_REG_LOGIN_SEND)
1505 			ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND;
1506 		/* decrement node reference count to the failed mbox
1507 		 * command
1508 		 */
1509 		lpfc_nlp_put(ndlp);
1510 		mp = (struct lpfc_dmabuf *)mbox->ctx_buf;
1511 		lpfc_mbuf_free(phba, mp->virt, mp->phys);
1512 		kfree(mp);
1513 		mempool_free(mbox, phba->mbox_mem_pool);
1514 
1515 		lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1516 				 "0134 PLOGI: cannot issue reg_login "
1517 				 "Data: x%x x%x x%x x%x\n",
1518 				 ndlp->nlp_DID, ndlp->nlp_state,
1519 				 ndlp->nlp_flag, ndlp->nlp_rpi);
1520 	} else {
1521 		mempool_free(mbox, phba->mbox_mem_pool);
1522 
1523 		lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1524 				 "0135 PLOGI: cannot format reg_login "
1525 				 "Data: x%x x%x x%x x%x\n",
1526 				 ndlp->nlp_DID, ndlp->nlp_state,
1527 				 ndlp->nlp_flag, ndlp->nlp_rpi);
1528 	}
1529 
1530 
1531 out:
1532 	if (ndlp->nlp_DID == NameServer_DID) {
1533 		lpfc_vport_set_state(vport, FC_VPORT_FAILED);
1534 		lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1535 				 "0261 Cannot Register NameServer login\n");
1536 	}
1537 
1538 	/*
1539 	** In case the node reference counter does not go to zero, ensure that
1540 	** the stale state for the node is not processed.
1541 	*/
1542 
1543 	ndlp->nlp_prev_state = ndlp->nlp_state;
1544 	lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1545 	spin_lock_irq(shost->host_lock);
1546 	ndlp->nlp_flag |= NLP_DEFER_RM;
1547 	spin_unlock_irq(shost->host_lock);
1548 	return NLP_STE_FREED_NODE;
1549 }
1550 
1551 static uint32_t
lpfc_cmpl_logo_plogi_issue(struct lpfc_vport * vport,struct lpfc_nodelist * ndlp,void * arg,uint32_t evt)1552 lpfc_cmpl_logo_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1553 			   void *arg, uint32_t evt)
1554 {
1555 	return ndlp->nlp_state;
1556 }
1557 
1558 static uint32_t
lpfc_cmpl_reglogin_plogi_issue(struct lpfc_vport * vport,struct lpfc_nodelist * ndlp,void * arg,uint32_t evt)1559 lpfc_cmpl_reglogin_plogi_issue(struct lpfc_vport *vport,
1560 	struct lpfc_nodelist *ndlp, void *arg, uint32_t evt)
1561 {
1562 	struct lpfc_hba *phba;
1563 	LPFC_MBOXQ_t *pmb = (LPFC_MBOXQ_t *) arg;
1564 	MAILBOX_t *mb = &pmb->u.mb;
1565 	uint16_t rpi;
1566 
1567 	phba = vport->phba;
1568 	/* Release the RPI */
1569 	if (!(phba->pport->load_flag & FC_UNLOADING) &&
1570 		!mb->mbxStatus) {
1571 		rpi = pmb->u.mb.un.varWords[0];
1572 		lpfc_release_rpi(phba, vport, ndlp, rpi);
1573 	}
1574 	return ndlp->nlp_state;
1575 }
1576 
1577 static uint32_t
lpfc_device_rm_plogi_issue(struct lpfc_vport * vport,struct lpfc_nodelist * ndlp,void * arg,uint32_t evt)1578 lpfc_device_rm_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1579 			   void *arg, uint32_t evt)
1580 {
1581 	struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1582 
1583 	if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1584 		spin_lock_irq(shost->host_lock);
1585 		ndlp->nlp_flag |= NLP_NODEV_REMOVE;
1586 		spin_unlock_irq(shost->host_lock);
1587 		return ndlp->nlp_state;
1588 	} else {
1589 		/* software abort outstanding PLOGI */
1590 		lpfc_els_abort(vport->phba, ndlp);
1591 
1592 		lpfc_drop_node(vport, ndlp);
1593 		return NLP_STE_FREED_NODE;
1594 	}
1595 }
1596 
1597 static uint32_t
lpfc_device_recov_plogi_issue(struct lpfc_vport * vport,struct lpfc_nodelist * ndlp,void * arg,uint32_t evt)1598 lpfc_device_recov_plogi_issue(struct lpfc_vport *vport,
1599 			      struct lpfc_nodelist *ndlp,
1600 			      void *arg,
1601 			      uint32_t evt)
1602 {
1603 	struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1604 	struct lpfc_hba  *phba = vport->phba;
1605 
1606 	/* Don't do anything that will mess up processing of the
1607 	 * previous RSCN.
1608 	 */
1609 	if (vport->fc_flag & FC_RSCN_DEFERRED)
1610 		return ndlp->nlp_state;
1611 
1612 	/* software abort outstanding PLOGI */
1613 	lpfc_els_abort(phba, ndlp);
1614 
1615 	ndlp->nlp_prev_state = NLP_STE_PLOGI_ISSUE;
1616 	lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1617 	spin_lock_irq(shost->host_lock);
1618 	ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
1619 	spin_unlock_irq(shost->host_lock);
1620 
1621 	return ndlp->nlp_state;
1622 }
1623 
1624 static uint32_t
lpfc_rcv_plogi_adisc_issue(struct lpfc_vport * vport,struct lpfc_nodelist * ndlp,void * arg,uint32_t evt)1625 lpfc_rcv_plogi_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1626 			   void *arg, uint32_t evt)
1627 {
1628 	struct Scsi_Host   *shost = lpfc_shost_from_vport(vport);
1629 	struct lpfc_hba   *phba = vport->phba;
1630 	struct lpfc_iocbq *cmdiocb;
1631 
1632 	/* software abort outstanding ADISC */
1633 	lpfc_els_abort(phba, ndlp);
1634 
1635 	cmdiocb = (struct lpfc_iocbq *) arg;
1636 
1637 	if (lpfc_rcv_plogi(vport, ndlp, cmdiocb)) {
1638 		if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1639 			spin_lock_irq(shost->host_lock);
1640 			ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
1641 			spin_unlock_irq(shost->host_lock);
1642 			if (vport->num_disc_nodes)
1643 				lpfc_more_adisc(vport);
1644 		}
1645 		return ndlp->nlp_state;
1646 	}
1647 	ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
1648 	lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
1649 	lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
1650 
1651 	return ndlp->nlp_state;
1652 }
1653 
1654 static uint32_t
lpfc_rcv_prli_adisc_issue(struct lpfc_vport * vport,struct lpfc_nodelist * ndlp,void * arg,uint32_t evt)1655 lpfc_rcv_prli_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1656 			  void *arg, uint32_t evt)
1657 {
1658 	struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1659 
1660 	if (lpfc_rcv_prli_support_check(vport, ndlp, cmdiocb))
1661 		lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
1662 	return ndlp->nlp_state;
1663 }
1664 
1665 static uint32_t
lpfc_rcv_logo_adisc_issue(struct lpfc_vport * vport,struct lpfc_nodelist * ndlp,void * arg,uint32_t evt)1666 lpfc_rcv_logo_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1667 			  void *arg, uint32_t evt)
1668 {
1669 	struct lpfc_hba *phba = vport->phba;
1670 	struct lpfc_iocbq *cmdiocb;
1671 
1672 	cmdiocb = (struct lpfc_iocbq *) arg;
1673 
1674 	/* software abort outstanding ADISC */
1675 	lpfc_els_abort(phba, ndlp);
1676 
1677 	lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
1678 	return ndlp->nlp_state;
1679 }
1680 
1681 static uint32_t
lpfc_rcv_padisc_adisc_issue(struct lpfc_vport * vport,struct lpfc_nodelist * ndlp,void * arg,uint32_t evt)1682 lpfc_rcv_padisc_adisc_issue(struct lpfc_vport *vport,
1683 			    struct lpfc_nodelist *ndlp,
1684 			    void *arg, uint32_t evt)
1685 {
1686 	struct lpfc_iocbq *cmdiocb;
1687 
1688 	cmdiocb = (struct lpfc_iocbq *) arg;
1689 
1690 	lpfc_rcv_padisc(vport, ndlp, cmdiocb);
1691 	return ndlp->nlp_state;
1692 }
1693 
1694 static uint32_t
lpfc_rcv_prlo_adisc_issue(struct lpfc_vport * vport,struct lpfc_nodelist * ndlp,void * arg,uint32_t evt)1695 lpfc_rcv_prlo_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1696 			  void *arg, uint32_t evt)
1697 {
1698 	struct lpfc_iocbq *cmdiocb;
1699 
1700 	cmdiocb = (struct lpfc_iocbq *) arg;
1701 
1702 	/* Treat like rcv logo */
1703 	lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_PRLO);
1704 	return ndlp->nlp_state;
1705 }
1706 
1707 static uint32_t
lpfc_cmpl_adisc_adisc_issue(struct lpfc_vport * vport,struct lpfc_nodelist * ndlp,void * arg,uint32_t evt)1708 lpfc_cmpl_adisc_adisc_issue(struct lpfc_vport *vport,
1709 			    struct lpfc_nodelist *ndlp,
1710 			    void *arg, uint32_t evt)
1711 {
1712 	struct Scsi_Host  *shost = lpfc_shost_from_vport(vport);
1713 	struct lpfc_hba   *phba = vport->phba;
1714 	struct lpfc_iocbq *cmdiocb, *rspiocb;
1715 	IOCB_t *irsp;
1716 	ADISC *ap;
1717 	int rc;
1718 
1719 	cmdiocb = (struct lpfc_iocbq *) arg;
1720 	rspiocb = cmdiocb->context_un.rsp_iocb;
1721 
1722 	ap = (ADISC *)lpfc_check_elscmpl_iocb(phba, cmdiocb, rspiocb);
1723 	irsp = &rspiocb->iocb;
1724 
1725 	if ((irsp->ulpStatus) ||
1726 	    (!lpfc_check_adisc(vport, ndlp, &ap->nodeName, &ap->portName))) {
1727 		/* 1 sec timeout */
1728 		mod_timer(&ndlp->nlp_delayfunc,
1729 			  jiffies + msecs_to_jiffies(1000));
1730 		spin_lock_irq(shost->host_lock);
1731 		ndlp->nlp_flag |= NLP_DELAY_TMO;
1732 		spin_unlock_irq(shost->host_lock);
1733 		ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
1734 
1735 		memset(&ndlp->nlp_nodename, 0, sizeof(struct lpfc_name));
1736 		memset(&ndlp->nlp_portname, 0, sizeof(struct lpfc_name));
1737 
1738 		ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
1739 		lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1740 		lpfc_unreg_rpi(vport, ndlp);
1741 		return ndlp->nlp_state;
1742 	}
1743 
1744 	if (phba->sli_rev == LPFC_SLI_REV4) {
1745 		rc = lpfc_sli4_resume_rpi(ndlp, NULL, NULL);
1746 		if (rc) {
1747 			/* Stay in state and retry. */
1748 			ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
1749 			return ndlp->nlp_state;
1750 		}
1751 	}
1752 
1753 	if (ndlp->nlp_type & NLP_FCP_TARGET)
1754 		ndlp->nlp_fc4_type |= NLP_FC4_FCP;
1755 
1756 	if (ndlp->nlp_type & NLP_NVME_TARGET)
1757 		ndlp->nlp_fc4_type |= NLP_FC4_NVME;
1758 
1759 	if (ndlp->nlp_type & (NLP_FCP_TARGET | NLP_NVME_TARGET)) {
1760 		ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
1761 		lpfc_nlp_set_state(vport, ndlp, NLP_STE_MAPPED_NODE);
1762 	} else {
1763 		ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
1764 		lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
1765 	}
1766 
1767 	return ndlp->nlp_state;
1768 }
1769 
1770 static uint32_t
lpfc_device_rm_adisc_issue(struct lpfc_vport * vport,struct lpfc_nodelist * ndlp,void * arg,uint32_t evt)1771 lpfc_device_rm_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1772 			   void *arg, uint32_t evt)
1773 {
1774 	struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1775 
1776 	if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1777 		spin_lock_irq(shost->host_lock);
1778 		ndlp->nlp_flag |= NLP_NODEV_REMOVE;
1779 		spin_unlock_irq(shost->host_lock);
1780 		return ndlp->nlp_state;
1781 	} else {
1782 		/* software abort outstanding ADISC */
1783 		lpfc_els_abort(vport->phba, ndlp);
1784 
1785 		lpfc_drop_node(vport, ndlp);
1786 		return NLP_STE_FREED_NODE;
1787 	}
1788 }
1789 
1790 static uint32_t
lpfc_device_recov_adisc_issue(struct lpfc_vport * vport,struct lpfc_nodelist * ndlp,void * arg,uint32_t evt)1791 lpfc_device_recov_adisc_issue(struct lpfc_vport *vport,
1792 			      struct lpfc_nodelist *ndlp,
1793 			      void *arg,
1794 			      uint32_t evt)
1795 {
1796 	struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1797 	struct lpfc_hba  *phba = vport->phba;
1798 
1799 	/* Don't do anything that will mess up processing of the
1800 	 * previous RSCN.
1801 	 */
1802 	if (vport->fc_flag & FC_RSCN_DEFERRED)
1803 		return ndlp->nlp_state;
1804 
1805 	/* software abort outstanding ADISC */
1806 	lpfc_els_abort(phba, ndlp);
1807 
1808 	ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
1809 	lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1810 	spin_lock_irq(shost->host_lock);
1811 	ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
1812 	spin_unlock_irq(shost->host_lock);
1813 	lpfc_disc_set_adisc(vport, ndlp);
1814 	return ndlp->nlp_state;
1815 }
1816 
1817 static uint32_t
lpfc_rcv_plogi_reglogin_issue(struct lpfc_vport * vport,struct lpfc_nodelist * ndlp,void * arg,uint32_t evt)1818 lpfc_rcv_plogi_reglogin_issue(struct lpfc_vport *vport,
1819 			      struct lpfc_nodelist *ndlp,
1820 			      void *arg,
1821 			      uint32_t evt)
1822 {
1823 	struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1824 
1825 	lpfc_rcv_plogi(vport, ndlp, cmdiocb);
1826 	return ndlp->nlp_state;
1827 }
1828 
1829 static uint32_t
lpfc_rcv_prli_reglogin_issue(struct lpfc_vport * vport,struct lpfc_nodelist * ndlp,void * arg,uint32_t evt)1830 lpfc_rcv_prli_reglogin_issue(struct lpfc_vport *vport,
1831 			     struct lpfc_nodelist *ndlp,
1832 			     void *arg,
1833 			     uint32_t evt)
1834 {
1835 	struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1836 	struct ls_rjt     stat;
1837 
1838 	if (!lpfc_rcv_prli_support_check(vport, ndlp, cmdiocb)) {
1839 		return ndlp->nlp_state;
1840 	}
1841 	if (vport->phba->nvmet_support) {
1842 		/* NVME Target mode.  Handle and respond to the PRLI and
1843 		 * transition to UNMAPPED provided the RPI has completed
1844 		 * registration.
1845 		 */
1846 		if (ndlp->nlp_flag & NLP_RPI_REGISTERED) {
1847 			lpfc_rcv_prli(vport, ndlp, cmdiocb);
1848 			lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
1849 		} else {
1850 			/* RPI registration has not completed. Reject the PRLI
1851 			 * to prevent an illegal state transition when the
1852 			 * rpi registration does complete.
1853 			 */
1854 			memset(&stat, 0, sizeof(struct ls_rjt));
1855 			stat.un.b.lsRjtRsnCode = LSRJT_LOGICAL_BSY;
1856 			stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
1857 			lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb,
1858 					    ndlp, NULL);
1859 			return ndlp->nlp_state;
1860 		}
1861 	} else {
1862 		/* Initiator mode. */
1863 		lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
1864 	}
1865 	return ndlp->nlp_state;
1866 }
1867 
1868 static uint32_t
lpfc_rcv_logo_reglogin_issue(struct lpfc_vport * vport,struct lpfc_nodelist * ndlp,void * arg,uint32_t evt)1869 lpfc_rcv_logo_reglogin_issue(struct lpfc_vport *vport,
1870 			     struct lpfc_nodelist *ndlp,
1871 			     void *arg,
1872 			     uint32_t evt)
1873 {
1874 	struct lpfc_hba   *phba = vport->phba;
1875 	struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1876 	LPFC_MBOXQ_t	  *mb;
1877 	LPFC_MBOXQ_t	  *nextmb;
1878 	struct lpfc_dmabuf *mp;
1879 	struct lpfc_nodelist *ns_ndlp;
1880 
1881 	cmdiocb = (struct lpfc_iocbq *) arg;
1882 
1883 	/* cleanup any ndlp on mbox q waiting for reglogin cmpl */
1884 	if ((mb = phba->sli.mbox_active)) {
1885 		if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) &&
1886 		   (ndlp == (struct lpfc_nodelist *)mb->ctx_ndlp)) {
1887 			ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND;
1888 			lpfc_nlp_put(ndlp);
1889 			mb->ctx_ndlp = NULL;
1890 			mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1891 		}
1892 	}
1893 
1894 	spin_lock_irq(&phba->hbalock);
1895 	list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) {
1896 		if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) &&
1897 		   (ndlp == (struct lpfc_nodelist *)mb->ctx_ndlp)) {
1898 			mp = (struct lpfc_dmabuf *)(mb->ctx_buf);
1899 			if (mp) {
1900 				__lpfc_mbuf_free(phba, mp->virt, mp->phys);
1901 				kfree(mp);
1902 			}
1903 			ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND;
1904 			lpfc_nlp_put(ndlp);
1905 			list_del(&mb->list);
1906 			phba->sli.mboxq_cnt--;
1907 			mempool_free(mb, phba->mbox_mem_pool);
1908 		}
1909 	}
1910 	spin_unlock_irq(&phba->hbalock);
1911 
1912 	/* software abort if any GID_FT is outstanding */
1913 	if (vport->cfg_enable_fc4_type != LPFC_ENABLE_FCP) {
1914 		ns_ndlp = lpfc_findnode_did(vport, NameServer_DID);
1915 		if (ns_ndlp && NLP_CHK_NODE_ACT(ns_ndlp))
1916 			lpfc_els_abort(phba, ns_ndlp);
1917 	}
1918 
1919 	lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
1920 	return ndlp->nlp_state;
1921 }
1922 
1923 static uint32_t
lpfc_rcv_padisc_reglogin_issue(struct lpfc_vport * vport,struct lpfc_nodelist * ndlp,void * arg,uint32_t evt)1924 lpfc_rcv_padisc_reglogin_issue(struct lpfc_vport *vport,
1925 			       struct lpfc_nodelist *ndlp,
1926 			       void *arg,
1927 			       uint32_t evt)
1928 {
1929 	struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1930 
1931 	lpfc_rcv_padisc(vport, ndlp, cmdiocb);
1932 	return ndlp->nlp_state;
1933 }
1934 
1935 static uint32_t
lpfc_rcv_prlo_reglogin_issue(struct lpfc_vport * vport,struct lpfc_nodelist * ndlp,void * arg,uint32_t evt)1936 lpfc_rcv_prlo_reglogin_issue(struct lpfc_vport *vport,
1937 			     struct lpfc_nodelist *ndlp,
1938 			     void *arg,
1939 			     uint32_t evt)
1940 {
1941 	struct lpfc_iocbq *cmdiocb;
1942 
1943 	cmdiocb = (struct lpfc_iocbq *) arg;
1944 	lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL);
1945 	return ndlp->nlp_state;
1946 }
1947 
1948 static uint32_t
lpfc_cmpl_reglogin_reglogin_issue(struct lpfc_vport * vport,struct lpfc_nodelist * ndlp,void * arg,uint32_t evt)1949 lpfc_cmpl_reglogin_reglogin_issue(struct lpfc_vport *vport,
1950 				  struct lpfc_nodelist *ndlp,
1951 				  void *arg,
1952 				  uint32_t evt)
1953 {
1954 	struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1955 	struct lpfc_hba *phba = vport->phba;
1956 	LPFC_MBOXQ_t *pmb = (LPFC_MBOXQ_t *) arg;
1957 	MAILBOX_t *mb = &pmb->u.mb;
1958 	uint32_t did  = mb->un.varWords[1];
1959 
1960 	if (mb->mbxStatus) {
1961 		/* RegLogin failed */
1962 		lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1963 				 "0246 RegLogin failed Data: x%x x%x x%x x%x "
1964 				 "x%x\n",
1965 				 did, mb->mbxStatus, vport->port_state,
1966 				 mb->un.varRegLogin.vpi,
1967 				 mb->un.varRegLogin.rpi);
1968 		/*
1969 		 * If RegLogin failed due to lack of HBA resources do not
1970 		 * retry discovery.
1971 		 */
1972 		if (mb->mbxStatus == MBXERR_RPI_FULL) {
1973 			ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
1974 			lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1975 			return ndlp->nlp_state;
1976 		}
1977 
1978 		/* Put ndlp in npr state set plogi timer for 1 sec */
1979 		mod_timer(&ndlp->nlp_delayfunc,
1980 			  jiffies + msecs_to_jiffies(1000 * 1));
1981 		spin_lock_irq(shost->host_lock);
1982 		ndlp->nlp_flag |= NLP_DELAY_TMO;
1983 		spin_unlock_irq(shost->host_lock);
1984 		ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
1985 
1986 		lpfc_issue_els_logo(vport, ndlp, 0);
1987 		return ndlp->nlp_state;
1988 	}
1989 
1990 	/* SLI4 ports have preallocated logical rpis. */
1991 	if (phba->sli_rev < LPFC_SLI_REV4)
1992 		ndlp->nlp_rpi = mb->un.varWords[0];
1993 
1994 	ndlp->nlp_flag |= NLP_RPI_REGISTERED;
1995 
1996 	/* Only if we are not a fabric nport do we issue PRLI */
1997 	lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1998 			 "3066 RegLogin Complete on x%x x%x x%x\n",
1999 			 did, ndlp->nlp_type, ndlp->nlp_fc4_type);
2000 	if (!(ndlp->nlp_type & NLP_FABRIC) &&
2001 	    (phba->nvmet_support == 0)) {
2002 		/* The driver supports FCP and NVME concurrently.  If the
2003 		 * ndlp's nlp_fc4_type is still zero, the driver doesn't
2004 		 * know what PRLI to send yet.  Figure that out now and
2005 		 * call PRLI depending on the outcome.
2006 		 */
2007 		if (vport->fc_flag & FC_PT2PT) {
2008 			/* If we are pt2pt, there is no Fabric to determine
2009 			 * the FC4 type of the remote nport. So if NVME
2010 			 * is configured try it.
2011 			 */
2012 			ndlp->nlp_fc4_type |= NLP_FC4_FCP;
2013 			if ((vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
2014 			    (vport->cfg_enable_fc4_type == LPFC_ENABLE_NVME)) {
2015 				ndlp->nlp_fc4_type |= NLP_FC4_NVME;
2016 				/* We need to update the localport also */
2017 				lpfc_nvme_update_localport(vport);
2018 			}
2019 
2020 		} else if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
2021 			ndlp->nlp_fc4_type |= NLP_FC4_FCP;
2022 
2023 		} else if (ndlp->nlp_fc4_type == 0) {
2024 			/* If we are only configured for FCP, the driver
2025 			 * should just issue PRLI for FCP. Otherwise issue
2026 			 * GFT_ID to determine if remote port supports NVME.
2027 			 */
2028 			if (vport->cfg_enable_fc4_type != LPFC_ENABLE_FCP) {
2029 				lpfc_ns_cmd(vport, SLI_CTNS_GFT_ID, 0,
2030 					    ndlp->nlp_DID);
2031 				return ndlp->nlp_state;
2032 			}
2033 			ndlp->nlp_fc4_type = NLP_FC4_FCP;
2034 		}
2035 
2036 		ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
2037 		lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
2038 		if (lpfc_issue_els_prli(vport, ndlp, 0)) {
2039 			lpfc_issue_els_logo(vport, ndlp, 0);
2040 			ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
2041 			lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
2042 		}
2043 	} else {
2044 		if ((vport->fc_flag & FC_PT2PT) && phba->nvmet_support)
2045 			phba->targetport->port_id = vport->fc_myDID;
2046 
2047 		/* Only Fabric ports should transition. NVME target
2048 		 * must complete PRLI.
2049 		 */
2050 		if (ndlp->nlp_type & NLP_FABRIC) {
2051 			ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
2052 			lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
2053 		}
2054 	}
2055 	return ndlp->nlp_state;
2056 }
2057 
2058 static uint32_t
lpfc_device_rm_reglogin_issue(struct lpfc_vport * vport,struct lpfc_nodelist * ndlp,void * arg,uint32_t evt)2059 lpfc_device_rm_reglogin_issue(struct lpfc_vport *vport,
2060 			      struct lpfc_nodelist *ndlp,
2061 			      void *arg,
2062 			      uint32_t evt)
2063 {
2064 	struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2065 
2066 	if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
2067 		spin_lock_irq(shost->host_lock);
2068 		ndlp->nlp_flag |= NLP_NODEV_REMOVE;
2069 		spin_unlock_irq(shost->host_lock);
2070 		return ndlp->nlp_state;
2071 	} else {
2072 		lpfc_drop_node(vport, ndlp);
2073 		return NLP_STE_FREED_NODE;
2074 	}
2075 }
2076 
2077 static uint32_t
lpfc_device_recov_reglogin_issue(struct lpfc_vport * vport,struct lpfc_nodelist * ndlp,void * arg,uint32_t evt)2078 lpfc_device_recov_reglogin_issue(struct lpfc_vport *vport,
2079 				 struct lpfc_nodelist *ndlp,
2080 				 void *arg,
2081 				 uint32_t evt)
2082 {
2083 	struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2084 
2085 	/* Don't do anything that will mess up processing of the
2086 	 * previous RSCN.
2087 	 */
2088 	if (vport->fc_flag & FC_RSCN_DEFERRED)
2089 		return ndlp->nlp_state;
2090 
2091 	ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
2092 	lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
2093 	spin_lock_irq(shost->host_lock);
2094 
2095 	/* If we are a target we won't immediately transition into PRLI,
2096 	 * so if REG_LOGIN already completed we don't need to ignore it.
2097 	 */
2098 	if (!(ndlp->nlp_flag & NLP_RPI_REGISTERED) ||
2099 	    !vport->phba->nvmet_support)
2100 		ndlp->nlp_flag |= NLP_IGNR_REG_CMPL;
2101 
2102 	ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
2103 	spin_unlock_irq(shost->host_lock);
2104 	lpfc_disc_set_adisc(vport, ndlp);
2105 	return ndlp->nlp_state;
2106 }
2107 
2108 static uint32_t
lpfc_rcv_plogi_prli_issue(struct lpfc_vport * vport,struct lpfc_nodelist * ndlp,void * arg,uint32_t evt)2109 lpfc_rcv_plogi_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2110 			  void *arg, uint32_t evt)
2111 {
2112 	struct lpfc_iocbq *cmdiocb;
2113 
2114 	cmdiocb = (struct lpfc_iocbq *) arg;
2115 
2116 	lpfc_rcv_plogi(vport, ndlp, cmdiocb);
2117 	return ndlp->nlp_state;
2118 }
2119 
2120 static uint32_t
lpfc_rcv_prli_prli_issue(struct lpfc_vport * vport,struct lpfc_nodelist * ndlp,void * arg,uint32_t evt)2121 lpfc_rcv_prli_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2122 			 void *arg, uint32_t evt)
2123 {
2124 	struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2125 
2126 	if (!lpfc_rcv_prli_support_check(vport, ndlp, cmdiocb))
2127 		return ndlp->nlp_state;
2128 	lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
2129 	return ndlp->nlp_state;
2130 }
2131 
2132 static uint32_t
lpfc_rcv_logo_prli_issue(struct lpfc_vport * vport,struct lpfc_nodelist * ndlp,void * arg,uint32_t evt)2133 lpfc_rcv_logo_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2134 			 void *arg, uint32_t evt)
2135 {
2136 	struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2137 
2138 	/* Software abort outstanding PRLI before sending acc */
2139 	lpfc_els_abort(vport->phba, ndlp);
2140 
2141 	lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
2142 	return ndlp->nlp_state;
2143 }
2144 
2145 static uint32_t
lpfc_rcv_padisc_prli_issue(struct lpfc_vport * vport,struct lpfc_nodelist * ndlp,void * arg,uint32_t evt)2146 lpfc_rcv_padisc_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2147 			   void *arg, uint32_t evt)
2148 {
2149 	struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2150 
2151 	lpfc_rcv_padisc(vport, ndlp, cmdiocb);
2152 	return ndlp->nlp_state;
2153 }
2154 
2155 /* This routine is envoked when we rcv a PRLO request from a nport
2156  * we are logged into.  We should send back a PRLO rsp setting the
2157  * appropriate bits.
2158  * NEXT STATE = PRLI_ISSUE
2159  */
2160 static uint32_t
lpfc_rcv_prlo_prli_issue(struct lpfc_vport * vport,struct lpfc_nodelist * ndlp,void * arg,uint32_t evt)2161 lpfc_rcv_prlo_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2162 			 void *arg, uint32_t evt)
2163 {
2164 	struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2165 
2166 	lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL);
2167 	return ndlp->nlp_state;
2168 }
2169 
2170 static uint32_t
lpfc_cmpl_prli_prli_issue(struct lpfc_vport * vport,struct lpfc_nodelist * ndlp,void * arg,uint32_t evt)2171 lpfc_cmpl_prli_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2172 			  void *arg, uint32_t evt)
2173 {
2174 	struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2175 	struct lpfc_iocbq *cmdiocb, *rspiocb;
2176 	struct lpfc_hba   *phba = vport->phba;
2177 	IOCB_t *irsp;
2178 	PRLI *npr;
2179 	struct lpfc_nvme_prli *nvpr;
2180 	void *temp_ptr;
2181 
2182 	cmdiocb = (struct lpfc_iocbq *) arg;
2183 	rspiocb = cmdiocb->context_un.rsp_iocb;
2184 
2185 	/* A solicited PRLI is either FCP or NVME.  The PRLI cmd/rsp
2186 	 * format is different so NULL the two PRLI types so that the
2187 	 * driver correctly gets the correct context.
2188 	 */
2189 	npr = NULL;
2190 	nvpr = NULL;
2191 	temp_ptr = lpfc_check_elscmpl_iocb(phba, cmdiocb, rspiocb);
2192 	if (cmdiocb->iocb_flag & LPFC_PRLI_FCP_REQ)
2193 		npr = (PRLI *) temp_ptr;
2194 	else if (cmdiocb->iocb_flag & LPFC_PRLI_NVME_REQ)
2195 		nvpr = (struct lpfc_nvme_prli *) temp_ptr;
2196 
2197 	irsp = &rspiocb->iocb;
2198 	if (irsp->ulpStatus) {
2199 		if ((vport->port_type == LPFC_NPIV_PORT) &&
2200 		    vport->cfg_restrict_login) {
2201 			goto out;
2202 		}
2203 
2204 		/* Adjust the nlp_type accordingly if the PRLI failed */
2205 		if (npr)
2206 			ndlp->nlp_fc4_type &= ~NLP_FC4_FCP;
2207 		if (nvpr)
2208 			ndlp->nlp_fc4_type &= ~NLP_FC4_NVME;
2209 
2210 		/* We can't set the DSM state till BOTH PRLIs complete */
2211 		goto out_err;
2212 	}
2213 
2214 	if (npr && (npr->acceptRspCode == PRLI_REQ_EXECUTED) &&
2215 	    (npr->prliType == PRLI_FCP_TYPE)) {
2216 		lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_DISC,
2217 				 "6028 FCP NPR PRLI Cmpl Init %d Target %d\n",
2218 				 npr->initiatorFunc,
2219 				 npr->targetFunc);
2220 		if (npr->initiatorFunc)
2221 			ndlp->nlp_type |= NLP_FCP_INITIATOR;
2222 		if (npr->targetFunc) {
2223 			ndlp->nlp_type |= NLP_FCP_TARGET;
2224 			if (npr->writeXferRdyDis)
2225 				ndlp->nlp_flag |= NLP_FIRSTBURST;
2226 		}
2227 		if (npr->Retry)
2228 			ndlp->nlp_fcp_info |= NLP_FCP_2_DEVICE;
2229 
2230 	} else if (nvpr &&
2231 		   (bf_get_be32(prli_acc_rsp_code, nvpr) ==
2232 		    PRLI_REQ_EXECUTED) &&
2233 		   (bf_get_be32(prli_type_code, nvpr) ==
2234 		    PRLI_NVME_TYPE)) {
2235 
2236 		/* Complete setting up the remote ndlp personality. */
2237 		if (bf_get_be32(prli_init, nvpr))
2238 			ndlp->nlp_type |= NLP_NVME_INITIATOR;
2239 
2240 		if (phba->nsler && bf_get_be32(prli_nsler, nvpr) &&
2241 		    bf_get_be32(prli_conf, nvpr))
2242 
2243 			ndlp->nlp_nvme_info |= NLP_NVME_NSLER;
2244 		else
2245 			ndlp->nlp_nvme_info &= ~NLP_NVME_NSLER;
2246 
2247 		/* Target driver cannot solicit NVME FB. */
2248 		if (bf_get_be32(prli_tgt, nvpr)) {
2249 			/* Complete the nvme target roles.  The transport
2250 			 * needs to know if the rport is capable of
2251 			 * discovery in addition to its role.
2252 			 */
2253 			ndlp->nlp_type |= NLP_NVME_TARGET;
2254 			if (bf_get_be32(prli_disc, nvpr))
2255 				ndlp->nlp_type |= NLP_NVME_DISCOVERY;
2256 
2257 			/*
2258 			 * If prli_fba is set, the Target supports FirstBurst.
2259 			 * If prli_fb_sz is 0, the FirstBurst size is unlimited,
2260 			 * otherwise it defines the actual size supported by
2261 			 * the NVME Target.
2262 			 */
2263 			if ((bf_get_be32(prli_fba, nvpr) == 1) &&
2264 			    (phba->cfg_nvme_enable_fb) &&
2265 			    (!phba->nvmet_support)) {
2266 				/* Both sides support FB. The target's first
2267 				 * burst size is a 512 byte encoded value.
2268 				 */
2269 				ndlp->nlp_flag |= NLP_FIRSTBURST;
2270 				ndlp->nvme_fb_size = bf_get_be32(prli_fb_sz,
2271 								 nvpr);
2272 
2273 				/* Expressed in units of 512 bytes */
2274 				if (ndlp->nvme_fb_size)
2275 					ndlp->nvme_fb_size <<=
2276 						LPFC_NVME_FB_SHIFT;
2277 				else
2278 					ndlp->nvme_fb_size = LPFC_NVME_MAX_FB;
2279 			}
2280 		}
2281 
2282 		lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_DISC,
2283 				 "6029 NVME PRLI Cmpl w1 x%08x "
2284 				 "w4 x%08x w5 x%08x flag x%x, "
2285 				 "fcp_info x%x nlp_type x%x\n",
2286 				 be32_to_cpu(nvpr->word1),
2287 				 be32_to_cpu(nvpr->word4),
2288 				 be32_to_cpu(nvpr->word5),
2289 				 ndlp->nlp_flag, ndlp->nlp_fcp_info,
2290 				 ndlp->nlp_type);
2291 	}
2292 	if (!(ndlp->nlp_type & NLP_FCP_TARGET) &&
2293 	    (vport->port_type == LPFC_NPIV_PORT) &&
2294 	     vport->cfg_restrict_login) {
2295 out:
2296 		spin_lock_irq(shost->host_lock);
2297 		ndlp->nlp_flag |= NLP_TARGET_REMOVE;
2298 		spin_unlock_irq(shost->host_lock);
2299 		lpfc_issue_els_logo(vport, ndlp, 0);
2300 
2301 		ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
2302 		lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
2303 		return ndlp->nlp_state;
2304 	}
2305 
2306 out_err:
2307 	/* The ndlp state cannot move to MAPPED or UNMAPPED before all PRLIs
2308 	 * are complete.
2309 	 */
2310 	if (ndlp->fc4_prli_sent == 0) {
2311 		ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
2312 		if (ndlp->nlp_type & (NLP_FCP_TARGET | NLP_NVME_TARGET))
2313 			lpfc_nlp_set_state(vport, ndlp, NLP_STE_MAPPED_NODE);
2314 		else if (ndlp->nlp_type &
2315 			 (NLP_FCP_INITIATOR | NLP_NVME_INITIATOR))
2316 			lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
2317 	} else
2318 		lpfc_printf_vlog(vport,
2319 				 KERN_INFO, LOG_ELS,
2320 				 "3067 PRLI's still outstanding "
2321 				 "on x%06x - count %d, Pend Node Mode "
2322 				 "transition...\n",
2323 				 ndlp->nlp_DID, ndlp->fc4_prli_sent);
2324 
2325 	return ndlp->nlp_state;
2326 }
2327 
2328 /*! lpfc_device_rm_prli_issue
2329  *
2330  * \pre
2331  * \post
2332  * \param   phba
2333  * \param   ndlp
2334  * \param   arg
2335  * \param   evt
2336  * \return  uint32_t
2337  *
2338  * \b Description:
2339  *    This routine is envoked when we a request to remove a nport we are in the
2340  *    process of PRLIing. We should software abort outstanding prli, unreg
2341  *    login, send a logout. We will change node state to UNUSED_NODE, put it
2342  *    on plogi list so it can be freed when LOGO completes.
2343  *
2344  */
2345 
2346 static uint32_t
lpfc_device_rm_prli_issue(struct lpfc_vport * vport,struct lpfc_nodelist * ndlp,void * arg,uint32_t evt)2347 lpfc_device_rm_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2348 			  void *arg, uint32_t evt)
2349 {
2350 	struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2351 
2352 	if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
2353 		spin_lock_irq(shost->host_lock);
2354 		ndlp->nlp_flag |= NLP_NODEV_REMOVE;
2355 		spin_unlock_irq(shost->host_lock);
2356 		return ndlp->nlp_state;
2357 	} else {
2358 		/* software abort outstanding PLOGI */
2359 		lpfc_els_abort(vport->phba, ndlp);
2360 
2361 		lpfc_drop_node(vport, ndlp);
2362 		return NLP_STE_FREED_NODE;
2363 	}
2364 }
2365 
2366 
2367 /*! lpfc_device_recov_prli_issue
2368  *
2369  * \pre
2370  * \post
2371  * \param   phba
2372  * \param   ndlp
2373  * \param   arg
2374  * \param   evt
2375  * \return  uint32_t
2376  *
2377  * \b Description:
2378  *    The routine is envoked when the state of a device is unknown, like
2379  *    during a link down. We should remove the nodelist entry from the
2380  *    unmapped list, issue a UNREG_LOGIN, do a software abort of the
2381  *    outstanding PRLI command, then free the node entry.
2382  */
2383 static uint32_t
lpfc_device_recov_prli_issue(struct lpfc_vport * vport,struct lpfc_nodelist * ndlp,void * arg,uint32_t evt)2384 lpfc_device_recov_prli_issue(struct lpfc_vport *vport,
2385 			     struct lpfc_nodelist *ndlp,
2386 			     void *arg,
2387 			     uint32_t evt)
2388 {
2389 	struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2390 	struct lpfc_hba  *phba = vport->phba;
2391 
2392 	/* Don't do anything that will mess up processing of the
2393 	 * previous RSCN.
2394 	 */
2395 	if (vport->fc_flag & FC_RSCN_DEFERRED)
2396 		return ndlp->nlp_state;
2397 
2398 	/* software abort outstanding PRLI */
2399 	lpfc_els_abort(phba, ndlp);
2400 
2401 	ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
2402 	lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
2403 	spin_lock_irq(shost->host_lock);
2404 	ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
2405 	spin_unlock_irq(shost->host_lock);
2406 	lpfc_disc_set_adisc(vport, ndlp);
2407 	return ndlp->nlp_state;
2408 }
2409 
2410 static uint32_t
lpfc_rcv_plogi_logo_issue(struct lpfc_vport * vport,struct lpfc_nodelist * ndlp,void * arg,uint32_t evt)2411 lpfc_rcv_plogi_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2412 			  void *arg, uint32_t evt)
2413 {
2414 	struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *)arg;
2415 	struct ls_rjt     stat;
2416 
2417 	memset(&stat, 0, sizeof(struct ls_rjt));
2418 	stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
2419 	stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
2420 	lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
2421 	return ndlp->nlp_state;
2422 }
2423 
2424 static uint32_t
lpfc_rcv_prli_logo_issue(struct lpfc_vport * vport,struct lpfc_nodelist * ndlp,void * arg,uint32_t evt)2425 lpfc_rcv_prli_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2426 			 void *arg, uint32_t evt)
2427 {
2428 	struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *)arg;
2429 	struct ls_rjt     stat;
2430 
2431 	memset(&stat, 0, sizeof(struct ls_rjt));
2432 	stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
2433 	stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
2434 	lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
2435 	return ndlp->nlp_state;
2436 }
2437 
2438 static uint32_t
lpfc_rcv_logo_logo_issue(struct lpfc_vport * vport,struct lpfc_nodelist * ndlp,void * arg,uint32_t evt)2439 lpfc_rcv_logo_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2440 			 void *arg, uint32_t evt)
2441 {
2442 	struct Scsi_Host  *shost = lpfc_shost_from_vport(vport);
2443 	struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *)arg;
2444 
2445 	spin_lock_irq(shost->host_lock);
2446 	ndlp->nlp_flag |= NLP_LOGO_ACC;
2447 	spin_unlock_irq(shost->host_lock);
2448 	lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
2449 	return ndlp->nlp_state;
2450 }
2451 
2452 static uint32_t
lpfc_rcv_padisc_logo_issue(struct lpfc_vport * vport,struct lpfc_nodelist * ndlp,void * arg,uint32_t evt)2453 lpfc_rcv_padisc_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2454 			   void *arg, uint32_t evt)
2455 {
2456 	struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *)arg;
2457 	struct ls_rjt     stat;
2458 
2459 	memset(&stat, 0, sizeof(struct ls_rjt));
2460 	stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
2461 	stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
2462 	lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
2463 	return ndlp->nlp_state;
2464 }
2465 
2466 static uint32_t
lpfc_rcv_prlo_logo_issue(struct lpfc_vport * vport,struct lpfc_nodelist * ndlp,void * arg,uint32_t evt)2467 lpfc_rcv_prlo_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2468 			 void *arg, uint32_t evt)
2469 {
2470 	struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *)arg;
2471 	struct ls_rjt     stat;
2472 
2473 	memset(&stat, 0, sizeof(struct ls_rjt));
2474 	stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
2475 	stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
2476 	lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
2477 	return ndlp->nlp_state;
2478 }
2479 
2480 static uint32_t
lpfc_cmpl_logo_logo_issue(struct lpfc_vport * vport,struct lpfc_nodelist * ndlp,void * arg,uint32_t evt)2481 lpfc_cmpl_logo_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2482 			  void *arg, uint32_t evt)
2483 {
2484 	struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2485 
2486 	ndlp->nlp_prev_state = NLP_STE_LOGO_ISSUE;
2487 	lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
2488 	spin_lock_irq(shost->host_lock);
2489 	ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
2490 	spin_unlock_irq(shost->host_lock);
2491 	lpfc_disc_set_adisc(vport, ndlp);
2492 	return ndlp->nlp_state;
2493 }
2494 
2495 static uint32_t
lpfc_device_rm_logo_issue(struct lpfc_vport * vport,struct lpfc_nodelist * ndlp,void * arg,uint32_t evt)2496 lpfc_device_rm_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2497 			  void *arg, uint32_t evt)
2498 {
2499 	/*
2500 	 * DevLoss has timed out and is calling for Device Remove.
2501 	 * In this case, abort the LOGO and cleanup the ndlp
2502 	 */
2503 
2504 	lpfc_unreg_rpi(vport, ndlp);
2505 	/* software abort outstanding PLOGI */
2506 	lpfc_els_abort(vport->phba, ndlp);
2507 	lpfc_drop_node(vport, ndlp);
2508 	return NLP_STE_FREED_NODE;
2509 }
2510 
2511 static uint32_t
lpfc_device_recov_logo_issue(struct lpfc_vport * vport,struct lpfc_nodelist * ndlp,void * arg,uint32_t evt)2512 lpfc_device_recov_logo_issue(struct lpfc_vport *vport,
2513 			     struct lpfc_nodelist *ndlp,
2514 			     void *arg, uint32_t evt)
2515 {
2516 	/*
2517 	 * Device Recovery events have no meaning for a node with a LOGO
2518 	 * outstanding.  The LOGO has to complete first and handle the
2519 	 * node from that point.
2520 	 */
2521 	return ndlp->nlp_state;
2522 }
2523 
2524 static uint32_t
lpfc_rcv_plogi_unmap_node(struct lpfc_vport * vport,struct lpfc_nodelist * ndlp,void * arg,uint32_t evt)2525 lpfc_rcv_plogi_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2526 			  void *arg, uint32_t evt)
2527 {
2528 	struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2529 
2530 	lpfc_rcv_plogi(vport, ndlp, cmdiocb);
2531 	return ndlp->nlp_state;
2532 }
2533 
2534 static uint32_t
lpfc_rcv_prli_unmap_node(struct lpfc_vport * vport,struct lpfc_nodelist * ndlp,void * arg,uint32_t evt)2535 lpfc_rcv_prli_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2536 			 void *arg, uint32_t evt)
2537 {
2538 	struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2539 
2540 	if (!lpfc_rcv_prli_support_check(vport, ndlp, cmdiocb))
2541 		return ndlp->nlp_state;
2542 
2543 	lpfc_rcv_prli(vport, ndlp, cmdiocb);
2544 	lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
2545 	return ndlp->nlp_state;
2546 }
2547 
2548 static uint32_t
lpfc_rcv_logo_unmap_node(struct lpfc_vport * vport,struct lpfc_nodelist * ndlp,void * arg,uint32_t evt)2549 lpfc_rcv_logo_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2550 			 void *arg, uint32_t evt)
2551 {
2552 	struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2553 
2554 	lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
2555 	return ndlp->nlp_state;
2556 }
2557 
2558 static uint32_t
lpfc_rcv_padisc_unmap_node(struct lpfc_vport * vport,struct lpfc_nodelist * ndlp,void * arg,uint32_t evt)2559 lpfc_rcv_padisc_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2560 			   void *arg, uint32_t evt)
2561 {
2562 	struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2563 
2564 	lpfc_rcv_padisc(vport, ndlp, cmdiocb);
2565 	return ndlp->nlp_state;
2566 }
2567 
2568 static uint32_t
lpfc_rcv_prlo_unmap_node(struct lpfc_vport * vport,struct lpfc_nodelist * ndlp,void * arg,uint32_t evt)2569 lpfc_rcv_prlo_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2570 			 void *arg, uint32_t evt)
2571 {
2572 	struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2573 
2574 	lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL);
2575 	return ndlp->nlp_state;
2576 }
2577 
2578 static uint32_t
lpfc_device_recov_unmap_node(struct lpfc_vport * vport,struct lpfc_nodelist * ndlp,void * arg,uint32_t evt)2579 lpfc_device_recov_unmap_node(struct lpfc_vport *vport,
2580 			     struct lpfc_nodelist *ndlp,
2581 			     void *arg,
2582 			     uint32_t evt)
2583 {
2584 	struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2585 
2586 	ndlp->nlp_prev_state = NLP_STE_UNMAPPED_NODE;
2587 	lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
2588 	spin_lock_irq(shost->host_lock);
2589 	ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
2590 	ndlp->nlp_fc4_type &= ~(NLP_FC4_FCP | NLP_FC4_NVME);
2591 	spin_unlock_irq(shost->host_lock);
2592 	lpfc_disc_set_adisc(vport, ndlp);
2593 
2594 	return ndlp->nlp_state;
2595 }
2596 
2597 static uint32_t
lpfc_rcv_plogi_mapped_node(struct lpfc_vport * vport,struct lpfc_nodelist * ndlp,void * arg,uint32_t evt)2598 lpfc_rcv_plogi_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2599 			   void *arg, uint32_t evt)
2600 {
2601 	struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2602 
2603 	lpfc_rcv_plogi(vport, ndlp, cmdiocb);
2604 	return ndlp->nlp_state;
2605 }
2606 
2607 static uint32_t
lpfc_rcv_prli_mapped_node(struct lpfc_vport * vport,struct lpfc_nodelist * ndlp,void * arg,uint32_t evt)2608 lpfc_rcv_prli_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2609 			  void *arg, uint32_t evt)
2610 {
2611 	struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2612 
2613 	if (!lpfc_rcv_prli_support_check(vport, ndlp, cmdiocb))
2614 		return ndlp->nlp_state;
2615 	lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
2616 	return ndlp->nlp_state;
2617 }
2618 
2619 static uint32_t
lpfc_rcv_logo_mapped_node(struct lpfc_vport * vport,struct lpfc_nodelist * ndlp,void * arg,uint32_t evt)2620 lpfc_rcv_logo_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2621 			  void *arg, uint32_t evt)
2622 {
2623 	struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2624 
2625 	lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
2626 	return ndlp->nlp_state;
2627 }
2628 
2629 static uint32_t
lpfc_rcv_padisc_mapped_node(struct lpfc_vport * vport,struct lpfc_nodelist * ndlp,void * arg,uint32_t evt)2630 lpfc_rcv_padisc_mapped_node(struct lpfc_vport *vport,
2631 			    struct lpfc_nodelist *ndlp,
2632 			    void *arg, uint32_t evt)
2633 {
2634 	struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2635 
2636 	lpfc_rcv_padisc(vport, ndlp, cmdiocb);
2637 	return ndlp->nlp_state;
2638 }
2639 
2640 static uint32_t
lpfc_rcv_prlo_mapped_node(struct lpfc_vport * vport,struct lpfc_nodelist * ndlp,void * arg,uint32_t evt)2641 lpfc_rcv_prlo_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2642 			  void *arg, uint32_t evt)
2643 {
2644 	struct lpfc_hba  *phba = vport->phba;
2645 	struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2646 
2647 	/* flush the target */
2648 	lpfc_sli_abort_iocb(vport, &phba->sli.sli3_ring[LPFC_FCP_RING],
2649 			    ndlp->nlp_sid, 0, LPFC_CTX_TGT);
2650 
2651 	/* Treat like rcv logo */
2652 	lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_PRLO);
2653 	return ndlp->nlp_state;
2654 }
2655 
2656 static uint32_t
lpfc_device_recov_mapped_node(struct lpfc_vport * vport,struct lpfc_nodelist * ndlp,void * arg,uint32_t evt)2657 lpfc_device_recov_mapped_node(struct lpfc_vport *vport,
2658 			      struct lpfc_nodelist *ndlp,
2659 			      void *arg,
2660 			      uint32_t evt)
2661 {
2662 	struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2663 
2664 	ndlp->nlp_prev_state = NLP_STE_MAPPED_NODE;
2665 	lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
2666 	spin_lock_irq(shost->host_lock);
2667 	ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
2668 	ndlp->nlp_fc4_type &= ~(NLP_FC4_FCP | NLP_FC4_NVME);
2669 	spin_unlock_irq(shost->host_lock);
2670 	lpfc_disc_set_adisc(vport, ndlp);
2671 	return ndlp->nlp_state;
2672 }
2673 
2674 static uint32_t
lpfc_rcv_plogi_npr_node(struct lpfc_vport * vport,struct lpfc_nodelist * ndlp,void * arg,uint32_t evt)2675 lpfc_rcv_plogi_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2676 			void *arg, uint32_t evt)
2677 {
2678 	struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2679 	struct lpfc_iocbq *cmdiocb  = (struct lpfc_iocbq *) arg;
2680 
2681 	/* Ignore PLOGI if we have an outstanding LOGO */
2682 	if (ndlp->nlp_flag & (NLP_LOGO_SND | NLP_LOGO_ACC))
2683 		return ndlp->nlp_state;
2684 	if (lpfc_rcv_plogi(vport, ndlp, cmdiocb)) {
2685 		lpfc_cancel_retry_delay_tmo(vport, ndlp);
2686 		spin_lock_irq(shost->host_lock);
2687 		ndlp->nlp_flag &= ~(NLP_NPR_ADISC | NLP_NPR_2B_DISC);
2688 		spin_unlock_irq(shost->host_lock);
2689 	} else if (!(ndlp->nlp_flag & NLP_NPR_2B_DISC)) {
2690 		/* send PLOGI immediately, move to PLOGI issue state */
2691 		if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
2692 			ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
2693 			lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
2694 			lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
2695 		}
2696 	}
2697 	return ndlp->nlp_state;
2698 }
2699 
2700 static uint32_t
lpfc_rcv_prli_npr_node(struct lpfc_vport * vport,struct lpfc_nodelist * ndlp,void * arg,uint32_t evt)2701 lpfc_rcv_prli_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2702 		       void *arg, uint32_t evt)
2703 {
2704 	struct Scsi_Host  *shost = lpfc_shost_from_vport(vport);
2705 	struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2706 	struct ls_rjt     stat;
2707 
2708 	memset(&stat, 0, sizeof (struct ls_rjt));
2709 	stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
2710 	stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
2711 	lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
2712 
2713 	if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
2714 		if (ndlp->nlp_flag & NLP_NPR_ADISC) {
2715 			spin_lock_irq(shost->host_lock);
2716 			ndlp->nlp_flag &= ~NLP_NPR_ADISC;
2717 			ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
2718 			spin_unlock_irq(shost->host_lock);
2719 			lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
2720 			lpfc_issue_els_adisc(vport, ndlp, 0);
2721 		} else {
2722 			ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
2723 			lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
2724 			lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
2725 		}
2726 	}
2727 	return ndlp->nlp_state;
2728 }
2729 
2730 static uint32_t
lpfc_rcv_logo_npr_node(struct lpfc_vport * vport,struct lpfc_nodelist * ndlp,void * arg,uint32_t evt)2731 lpfc_rcv_logo_npr_node(struct lpfc_vport *vport,  struct lpfc_nodelist *ndlp,
2732 		       void *arg, uint32_t evt)
2733 {
2734 	struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2735 
2736 	lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
2737 	return ndlp->nlp_state;
2738 }
2739 
2740 static uint32_t
lpfc_rcv_padisc_npr_node(struct lpfc_vport * vport,struct lpfc_nodelist * ndlp,void * arg,uint32_t evt)2741 lpfc_rcv_padisc_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2742 			 void *arg, uint32_t evt)
2743 {
2744 	struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2745 
2746 	lpfc_rcv_padisc(vport, ndlp, cmdiocb);
2747 	/*
2748 	 * Do not start discovery if discovery is about to start
2749 	 * or discovery in progress for this node. Starting discovery
2750 	 * here will affect the counting of discovery threads.
2751 	 */
2752 	if (!(ndlp->nlp_flag & NLP_DELAY_TMO) &&
2753 	    !(ndlp->nlp_flag & NLP_NPR_2B_DISC)) {
2754 		if (ndlp->nlp_flag & NLP_NPR_ADISC) {
2755 			ndlp->nlp_flag &= ~NLP_NPR_ADISC;
2756 			ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
2757 			lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
2758 			lpfc_issue_els_adisc(vport, ndlp, 0);
2759 		} else {
2760 			ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
2761 			lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
2762 			lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
2763 		}
2764 	}
2765 	return ndlp->nlp_state;
2766 }
2767 
2768 static uint32_t
lpfc_rcv_prlo_npr_node(struct lpfc_vport * vport,struct lpfc_nodelist * ndlp,void * arg,uint32_t evt)2769 lpfc_rcv_prlo_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2770 		       void *arg, uint32_t evt)
2771 {
2772 	struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2773 	struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2774 
2775 	spin_lock_irq(shost->host_lock);
2776 	ndlp->nlp_flag |= NLP_LOGO_ACC;
2777 	spin_unlock_irq(shost->host_lock);
2778 
2779 	lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
2780 
2781 	if ((ndlp->nlp_flag & NLP_DELAY_TMO) == 0) {
2782 		mod_timer(&ndlp->nlp_delayfunc,
2783 			  jiffies + msecs_to_jiffies(1000 * 1));
2784 		spin_lock_irq(shost->host_lock);
2785 		ndlp->nlp_flag |= NLP_DELAY_TMO;
2786 		ndlp->nlp_flag &= ~NLP_NPR_ADISC;
2787 		spin_unlock_irq(shost->host_lock);
2788 		ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
2789 	} else {
2790 		spin_lock_irq(shost->host_lock);
2791 		ndlp->nlp_flag &= ~NLP_NPR_ADISC;
2792 		spin_unlock_irq(shost->host_lock);
2793 	}
2794 	return ndlp->nlp_state;
2795 }
2796 
2797 static uint32_t
lpfc_cmpl_plogi_npr_node(struct lpfc_vport * vport,struct lpfc_nodelist * ndlp,void * arg,uint32_t evt)2798 lpfc_cmpl_plogi_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2799 			 void *arg, uint32_t evt)
2800 {
2801 	struct lpfc_iocbq *cmdiocb, *rspiocb;
2802 	IOCB_t *irsp;
2803 	struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2804 
2805 	cmdiocb = (struct lpfc_iocbq *) arg;
2806 	rspiocb = cmdiocb->context_un.rsp_iocb;
2807 
2808 	irsp = &rspiocb->iocb;
2809 	if (irsp->ulpStatus) {
2810 		spin_lock_irq(shost->host_lock);
2811 		ndlp->nlp_flag |= NLP_DEFER_RM;
2812 		spin_unlock_irq(shost->host_lock);
2813 		return NLP_STE_FREED_NODE;
2814 	}
2815 	return ndlp->nlp_state;
2816 }
2817 
2818 static uint32_t
lpfc_cmpl_prli_npr_node(struct lpfc_vport * vport,struct lpfc_nodelist * ndlp,void * arg,uint32_t evt)2819 lpfc_cmpl_prli_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2820 			void *arg, uint32_t evt)
2821 {
2822 	struct lpfc_iocbq *cmdiocb, *rspiocb;
2823 	IOCB_t *irsp;
2824 
2825 	cmdiocb = (struct lpfc_iocbq *) arg;
2826 	rspiocb = cmdiocb->context_un.rsp_iocb;
2827 
2828 	irsp = &rspiocb->iocb;
2829 	if (irsp->ulpStatus && (ndlp->nlp_flag & NLP_NODEV_REMOVE)) {
2830 		lpfc_drop_node(vport, ndlp);
2831 		return NLP_STE_FREED_NODE;
2832 	}
2833 	return ndlp->nlp_state;
2834 }
2835 
2836 static uint32_t
lpfc_cmpl_logo_npr_node(struct lpfc_vport * vport,struct lpfc_nodelist * ndlp,void * arg,uint32_t evt)2837 lpfc_cmpl_logo_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2838 			void *arg, uint32_t evt)
2839 {
2840 	struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2841 
2842 	/* For the fabric port just clear the fc flags. */
2843 	if (ndlp->nlp_DID == Fabric_DID) {
2844 		spin_lock_irq(shost->host_lock);
2845 		vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
2846 		spin_unlock_irq(shost->host_lock);
2847 	}
2848 	lpfc_unreg_rpi(vport, ndlp);
2849 	return ndlp->nlp_state;
2850 }
2851 
2852 static uint32_t
lpfc_cmpl_adisc_npr_node(struct lpfc_vport * vport,struct lpfc_nodelist * ndlp,void * arg,uint32_t evt)2853 lpfc_cmpl_adisc_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2854 			 void *arg, uint32_t evt)
2855 {
2856 	struct lpfc_iocbq *cmdiocb, *rspiocb;
2857 	IOCB_t *irsp;
2858 
2859 	cmdiocb = (struct lpfc_iocbq *) arg;
2860 	rspiocb = cmdiocb->context_un.rsp_iocb;
2861 
2862 	irsp = &rspiocb->iocb;
2863 	if (irsp->ulpStatus && (ndlp->nlp_flag & NLP_NODEV_REMOVE)) {
2864 		lpfc_drop_node(vport, ndlp);
2865 		return NLP_STE_FREED_NODE;
2866 	}
2867 	return ndlp->nlp_state;
2868 }
2869 
2870 static uint32_t
lpfc_cmpl_reglogin_npr_node(struct lpfc_vport * vport,struct lpfc_nodelist * ndlp,void * arg,uint32_t evt)2871 lpfc_cmpl_reglogin_npr_node(struct lpfc_vport *vport,
2872 			    struct lpfc_nodelist *ndlp,
2873 			    void *arg, uint32_t evt)
2874 {
2875 	LPFC_MBOXQ_t *pmb = (LPFC_MBOXQ_t *) arg;
2876 	MAILBOX_t    *mb = &pmb->u.mb;
2877 
2878 	if (!mb->mbxStatus) {
2879 		/* SLI4 ports have preallocated logical rpis. */
2880 		if (vport->phba->sli_rev < LPFC_SLI_REV4)
2881 			ndlp->nlp_rpi = mb->un.varWords[0];
2882 		ndlp->nlp_flag |= NLP_RPI_REGISTERED;
2883 		if (ndlp->nlp_flag & NLP_LOGO_ACC) {
2884 			lpfc_unreg_rpi(vport, ndlp);
2885 		}
2886 	} else {
2887 		if (ndlp->nlp_flag & NLP_NODEV_REMOVE) {
2888 			lpfc_drop_node(vport, ndlp);
2889 			return NLP_STE_FREED_NODE;
2890 		}
2891 	}
2892 	return ndlp->nlp_state;
2893 }
2894 
2895 static uint32_t
lpfc_device_rm_npr_node(struct lpfc_vport * vport,struct lpfc_nodelist * ndlp,void * arg,uint32_t evt)2896 lpfc_device_rm_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2897 			void *arg, uint32_t evt)
2898 {
2899 	struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2900 
2901 	if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
2902 		spin_lock_irq(shost->host_lock);
2903 		ndlp->nlp_flag |= NLP_NODEV_REMOVE;
2904 		spin_unlock_irq(shost->host_lock);
2905 		return ndlp->nlp_state;
2906 	}
2907 	lpfc_drop_node(vport, ndlp);
2908 	return NLP_STE_FREED_NODE;
2909 }
2910 
2911 static uint32_t
lpfc_device_recov_npr_node(struct lpfc_vport * vport,struct lpfc_nodelist * ndlp,void * arg,uint32_t evt)2912 lpfc_device_recov_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2913 			   void *arg, uint32_t evt)
2914 {
2915 	struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2916 
2917 	/* Don't do anything that will mess up processing of the
2918 	 * previous RSCN.
2919 	 */
2920 	if (vport->fc_flag & FC_RSCN_DEFERRED)
2921 		return ndlp->nlp_state;
2922 
2923 	lpfc_cancel_retry_delay_tmo(vport, ndlp);
2924 	spin_lock_irq(shost->host_lock);
2925 	ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
2926 	ndlp->nlp_fc4_type &= ~(NLP_FC4_FCP | NLP_FC4_NVME);
2927 	spin_unlock_irq(shost->host_lock);
2928 	return ndlp->nlp_state;
2929 }
2930 
2931 
2932 /* This next section defines the NPort Discovery State Machine */
2933 
2934 /* There are 4 different double linked lists nodelist entries can reside on.
2935  * The plogi list and adisc list are used when Link Up discovery or RSCN
2936  * processing is needed. Each list holds the nodes that we will send PLOGI
2937  * or ADISC on. These lists will keep track of what nodes will be effected
2938  * by an RSCN, or a Link Up (Typically, all nodes are effected on Link Up).
2939  * The unmapped_list will contain all nodes that we have successfully logged
2940  * into at the Fibre Channel level. The mapped_list will contain all nodes
2941  * that are mapped FCP targets.
2942  */
2943 /*
2944  * The bind list is a list of undiscovered (potentially non-existent) nodes
2945  * that we have saved binding information on. This information is used when
2946  * nodes transition from the unmapped to the mapped list.
2947  */
2948 /* For UNUSED_NODE state, the node has just been allocated .
2949  * For PLOGI_ISSUE and REG_LOGIN_ISSUE, the node is on
2950  * the PLOGI list. For REG_LOGIN_COMPL, the node is taken off the PLOGI list
2951  * and put on the unmapped list. For ADISC processing, the node is taken off
2952  * the ADISC list and placed on either the mapped or unmapped list (depending
2953  * on its previous state). Once on the unmapped list, a PRLI is issued and the
2954  * state changed to PRLI_ISSUE. When the PRLI completion occurs, the state is
2955  * changed to UNMAPPED_NODE. If the completion indicates a mapped
2956  * node, the node is taken off the unmapped list. The binding list is checked
2957  * for a valid binding, or a binding is automatically assigned. If binding
2958  * assignment is unsuccessful, the node is left on the unmapped list. If
2959  * binding assignment is successful, the associated binding list entry (if
2960  * any) is removed, and the node is placed on the mapped list.
2961  */
2962 /*
2963  * For a Link Down, all nodes on the ADISC, PLOGI, unmapped or mapped
2964  * lists will receive a DEVICE_RECOVERY event. If the linkdown or devloss timers
2965  * expire, all effected nodes will receive a DEVICE_RM event.
2966  */
2967 /*
2968  * For a Link Up or RSCN, all nodes will move from the mapped / unmapped lists
2969  * to either the ADISC or PLOGI list.  After a Nameserver query or ALPA loopmap
2970  * check, additional nodes may be added or removed (via DEVICE_RM) to / from
2971  * the PLOGI or ADISC lists. Once the PLOGI and ADISC lists are populated,
2972  * we will first process the ADISC list.  32 entries are processed initially and
2973  * ADISC is initited for each one.  Completions / Events for each node are
2974  * funnelled thru the state machine.  As each node finishes ADISC processing, it
2975  * starts ADISC for any nodes waiting for ADISC processing. If no nodes are
2976  * waiting, and the ADISC list count is identically 0, then we are done. For
2977  * Link Up discovery, since all nodes on the PLOGI list are UNREG_LOGIN'ed, we
2978  * can issue a CLEAR_LA and reenable Link Events. Next we will process the PLOGI
2979  * list.  32 entries are processed initially and PLOGI is initited for each one.
2980  * Completions / Events for each node are funnelled thru the state machine.  As
2981  * each node finishes PLOGI processing, it starts PLOGI for any nodes waiting
2982  * for PLOGI processing. If no nodes are waiting, and the PLOGI list count is
2983  * indentically 0, then we are done. We have now completed discovery / RSCN
2984  * handling. Upon completion, ALL nodes should be on either the mapped or
2985  * unmapped lists.
2986  */
2987 
2988 static uint32_t (*lpfc_disc_action[NLP_STE_MAX_STATE * NLP_EVT_MAX_EVENT])
2989      (struct lpfc_vport *, struct lpfc_nodelist *, void *, uint32_t) = {
2990 	/* Action routine                  Event       Current State  */
2991 	lpfc_rcv_plogi_unused_node,	/* RCV_PLOGI   UNUSED_NODE    */
2992 	lpfc_rcv_els_unused_node,	/* RCV_PRLI        */
2993 	lpfc_rcv_logo_unused_node,	/* RCV_LOGO        */
2994 	lpfc_rcv_els_unused_node,	/* RCV_ADISC       */
2995 	lpfc_rcv_els_unused_node,	/* RCV_PDISC       */
2996 	lpfc_rcv_els_unused_node,	/* RCV_PRLO        */
2997 	lpfc_disc_illegal,		/* CMPL_PLOGI      */
2998 	lpfc_disc_illegal,		/* CMPL_PRLI       */
2999 	lpfc_cmpl_logo_unused_node,	/* CMPL_LOGO       */
3000 	lpfc_disc_illegal,		/* CMPL_ADISC      */
3001 	lpfc_disc_illegal,		/* CMPL_REG_LOGIN  */
3002 	lpfc_device_rm_unused_node,	/* DEVICE_RM       */
3003 	lpfc_device_recov_unused_node,	/* DEVICE_RECOVERY */
3004 
3005 	lpfc_rcv_plogi_plogi_issue,	/* RCV_PLOGI   PLOGI_ISSUE    */
3006 	lpfc_rcv_prli_plogi_issue,	/* RCV_PRLI        */
3007 	lpfc_rcv_logo_plogi_issue,	/* RCV_LOGO        */
3008 	lpfc_rcv_els_plogi_issue,	/* RCV_ADISC       */
3009 	lpfc_rcv_els_plogi_issue,	/* RCV_PDISC       */
3010 	lpfc_rcv_els_plogi_issue,	/* RCV_PRLO        */
3011 	lpfc_cmpl_plogi_plogi_issue,	/* CMPL_PLOGI      */
3012 	lpfc_disc_illegal,		/* CMPL_PRLI       */
3013 	lpfc_cmpl_logo_plogi_issue,	/* CMPL_LOGO       */
3014 	lpfc_disc_illegal,		/* CMPL_ADISC      */
3015 	lpfc_cmpl_reglogin_plogi_issue,/* CMPL_REG_LOGIN  */
3016 	lpfc_device_rm_plogi_issue,	/* DEVICE_RM       */
3017 	lpfc_device_recov_plogi_issue,	/* DEVICE_RECOVERY */
3018 
3019 	lpfc_rcv_plogi_adisc_issue,	/* RCV_PLOGI   ADISC_ISSUE    */
3020 	lpfc_rcv_prli_adisc_issue,	/* RCV_PRLI        */
3021 	lpfc_rcv_logo_adisc_issue,	/* RCV_LOGO        */
3022 	lpfc_rcv_padisc_adisc_issue,	/* RCV_ADISC       */
3023 	lpfc_rcv_padisc_adisc_issue,	/* RCV_PDISC       */
3024 	lpfc_rcv_prlo_adisc_issue,	/* RCV_PRLO        */
3025 	lpfc_disc_illegal,		/* CMPL_PLOGI      */
3026 	lpfc_disc_illegal,		/* CMPL_PRLI       */
3027 	lpfc_disc_illegal,		/* CMPL_LOGO       */
3028 	lpfc_cmpl_adisc_adisc_issue,	/* CMPL_ADISC      */
3029 	lpfc_disc_illegal,		/* CMPL_REG_LOGIN  */
3030 	lpfc_device_rm_adisc_issue,	/* DEVICE_RM       */
3031 	lpfc_device_recov_adisc_issue,	/* DEVICE_RECOVERY */
3032 
3033 	lpfc_rcv_plogi_reglogin_issue,	/* RCV_PLOGI  REG_LOGIN_ISSUE */
3034 	lpfc_rcv_prli_reglogin_issue,	/* RCV_PLOGI       */
3035 	lpfc_rcv_logo_reglogin_issue,	/* RCV_LOGO        */
3036 	lpfc_rcv_padisc_reglogin_issue,	/* RCV_ADISC       */
3037 	lpfc_rcv_padisc_reglogin_issue,	/* RCV_PDISC       */
3038 	lpfc_rcv_prlo_reglogin_issue,	/* RCV_PRLO        */
3039 	lpfc_cmpl_plogi_illegal,	/* CMPL_PLOGI      */
3040 	lpfc_disc_illegal,		/* CMPL_PRLI       */
3041 	lpfc_disc_illegal,		/* CMPL_LOGO       */
3042 	lpfc_disc_illegal,		/* CMPL_ADISC      */
3043 	lpfc_cmpl_reglogin_reglogin_issue,/* CMPL_REG_LOGIN  */
3044 	lpfc_device_rm_reglogin_issue,	/* DEVICE_RM       */
3045 	lpfc_device_recov_reglogin_issue,/* DEVICE_RECOVERY */
3046 
3047 	lpfc_rcv_plogi_prli_issue,	/* RCV_PLOGI   PRLI_ISSUE     */
3048 	lpfc_rcv_prli_prli_issue,	/* RCV_PRLI        */
3049 	lpfc_rcv_logo_prli_issue,	/* RCV_LOGO        */
3050 	lpfc_rcv_padisc_prli_issue,	/* RCV_ADISC       */
3051 	lpfc_rcv_padisc_prli_issue,	/* RCV_PDISC       */
3052 	lpfc_rcv_prlo_prli_issue,	/* RCV_PRLO        */
3053 	lpfc_cmpl_plogi_illegal,	/* CMPL_PLOGI      */
3054 	lpfc_cmpl_prli_prli_issue,	/* CMPL_PRLI       */
3055 	lpfc_disc_illegal,		/* CMPL_LOGO       */
3056 	lpfc_disc_illegal,		/* CMPL_ADISC      */
3057 	lpfc_disc_illegal,		/* CMPL_REG_LOGIN  */
3058 	lpfc_device_rm_prli_issue,	/* DEVICE_RM       */
3059 	lpfc_device_recov_prli_issue,	/* DEVICE_RECOVERY */
3060 
3061 	lpfc_rcv_plogi_logo_issue,	/* RCV_PLOGI   LOGO_ISSUE     */
3062 	lpfc_rcv_prli_logo_issue,	/* RCV_PRLI        */
3063 	lpfc_rcv_logo_logo_issue,	/* RCV_LOGO        */
3064 	lpfc_rcv_padisc_logo_issue,	/* RCV_ADISC       */
3065 	lpfc_rcv_padisc_logo_issue,	/* RCV_PDISC       */
3066 	lpfc_rcv_prlo_logo_issue,	/* RCV_PRLO        */
3067 	lpfc_cmpl_plogi_illegal,	/* CMPL_PLOGI      */
3068 	lpfc_disc_illegal,		/* CMPL_PRLI       */
3069 	lpfc_cmpl_logo_logo_issue,	/* CMPL_LOGO       */
3070 	lpfc_disc_illegal,		/* CMPL_ADISC      */
3071 	lpfc_disc_illegal,		/* CMPL_REG_LOGIN  */
3072 	lpfc_device_rm_logo_issue,	/* DEVICE_RM       */
3073 	lpfc_device_recov_logo_issue,	/* DEVICE_RECOVERY */
3074 
3075 	lpfc_rcv_plogi_unmap_node,	/* RCV_PLOGI   UNMAPPED_NODE  */
3076 	lpfc_rcv_prli_unmap_node,	/* RCV_PRLI        */
3077 	lpfc_rcv_logo_unmap_node,	/* RCV_LOGO        */
3078 	lpfc_rcv_padisc_unmap_node,	/* RCV_ADISC       */
3079 	lpfc_rcv_padisc_unmap_node,	/* RCV_PDISC       */
3080 	lpfc_rcv_prlo_unmap_node,	/* RCV_PRLO        */
3081 	lpfc_disc_illegal,		/* CMPL_PLOGI      */
3082 	lpfc_disc_illegal,		/* CMPL_PRLI       */
3083 	lpfc_disc_illegal,		/* CMPL_LOGO       */
3084 	lpfc_disc_illegal,		/* CMPL_ADISC      */
3085 	lpfc_disc_illegal,		/* CMPL_REG_LOGIN  */
3086 	lpfc_disc_illegal,		/* DEVICE_RM       */
3087 	lpfc_device_recov_unmap_node,	/* DEVICE_RECOVERY */
3088 
3089 	lpfc_rcv_plogi_mapped_node,	/* RCV_PLOGI   MAPPED_NODE    */
3090 	lpfc_rcv_prli_mapped_node,	/* RCV_PRLI        */
3091 	lpfc_rcv_logo_mapped_node,	/* RCV_LOGO        */
3092 	lpfc_rcv_padisc_mapped_node,	/* RCV_ADISC       */
3093 	lpfc_rcv_padisc_mapped_node,	/* RCV_PDISC       */
3094 	lpfc_rcv_prlo_mapped_node,	/* RCV_PRLO        */
3095 	lpfc_disc_illegal,		/* CMPL_PLOGI      */
3096 	lpfc_disc_illegal,		/* CMPL_PRLI       */
3097 	lpfc_disc_illegal,		/* CMPL_LOGO       */
3098 	lpfc_disc_illegal,		/* CMPL_ADISC      */
3099 	lpfc_disc_illegal,		/* CMPL_REG_LOGIN  */
3100 	lpfc_disc_illegal,		/* DEVICE_RM       */
3101 	lpfc_device_recov_mapped_node,	/* DEVICE_RECOVERY */
3102 
3103 	lpfc_rcv_plogi_npr_node,        /* RCV_PLOGI   NPR_NODE    */
3104 	lpfc_rcv_prli_npr_node,         /* RCV_PRLI        */
3105 	lpfc_rcv_logo_npr_node,         /* RCV_LOGO        */
3106 	lpfc_rcv_padisc_npr_node,       /* RCV_ADISC       */
3107 	lpfc_rcv_padisc_npr_node,       /* RCV_PDISC       */
3108 	lpfc_rcv_prlo_npr_node,         /* RCV_PRLO        */
3109 	lpfc_cmpl_plogi_npr_node,	/* CMPL_PLOGI      */
3110 	lpfc_cmpl_prli_npr_node,	/* CMPL_PRLI       */
3111 	lpfc_cmpl_logo_npr_node,        /* CMPL_LOGO       */
3112 	lpfc_cmpl_adisc_npr_node,       /* CMPL_ADISC      */
3113 	lpfc_cmpl_reglogin_npr_node,    /* CMPL_REG_LOGIN  */
3114 	lpfc_device_rm_npr_node,        /* DEVICE_RM       */
3115 	lpfc_device_recov_npr_node,     /* DEVICE_RECOVERY */
3116 };
3117 
3118 int
lpfc_disc_state_machine(struct lpfc_vport * vport,struct lpfc_nodelist * ndlp,void * arg,uint32_t evt)3119 lpfc_disc_state_machine(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
3120 			void *arg, uint32_t evt)
3121 {
3122 	uint32_t cur_state, rc;
3123 	uint32_t(*func) (struct lpfc_vport *, struct lpfc_nodelist *, void *,
3124 			 uint32_t);
3125 	uint32_t got_ndlp = 0;
3126 	uint32_t data1;
3127 
3128 	if (lpfc_nlp_get(ndlp))
3129 		got_ndlp = 1;
3130 
3131 	cur_state = ndlp->nlp_state;
3132 
3133 	data1 = (((uint32_t)ndlp->nlp_fc4_type << 16) |
3134 		((uint32_t)ndlp->nlp_type));
3135 	/* DSM in event <evt> on NPort <nlp_DID> in state <cur_state> */
3136 	lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
3137 			 "0211 DSM in event x%x on NPort x%x in "
3138 			 "state %d rpi x%x Data: x%x x%x\n",
3139 			 evt, ndlp->nlp_DID, cur_state, ndlp->nlp_rpi,
3140 			 ndlp->nlp_flag, data1);
3141 
3142 	lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_DSM,
3143 		 "DSM in:          evt:%d ste:%d did:x%x",
3144 		evt, cur_state, ndlp->nlp_DID);
3145 
3146 	func = lpfc_disc_action[(cur_state * NLP_EVT_MAX_EVENT) + evt];
3147 	rc = (func) (vport, ndlp, arg, evt);
3148 
3149 	/* DSM out state <rc> on NPort <nlp_DID> */
3150 	if (got_ndlp) {
3151 		data1 = (((uint32_t)ndlp->nlp_fc4_type << 16) |
3152 			((uint32_t)ndlp->nlp_type));
3153 		lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
3154 			 "0212 DSM out state %d on NPort x%x "
3155 			 "rpi x%x Data: x%x x%x\n",
3156 			 rc, ndlp->nlp_DID, ndlp->nlp_rpi, ndlp->nlp_flag,
3157 			 data1);
3158 
3159 		lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_DSM,
3160 			"DSM out:         ste:%d did:x%x flg:x%x",
3161 			rc, ndlp->nlp_DID, ndlp->nlp_flag);
3162 		/* Decrement the ndlp reference count held for this function */
3163 		lpfc_nlp_put(ndlp);
3164 	} else {
3165 		lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
3166 			"0213 DSM out state %d on NPort free\n", rc);
3167 
3168 		lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_DSM,
3169 			"DSM out:         ste:%d did:x%x flg:x%x",
3170 			rc, 0, 0);
3171 	}
3172 
3173 	return rc;
3174 }
3175