blob: 56a3df4fddb05e3e8c15fb170d6938e382920717 [file] [log] [blame]
James Smart92d7f7b2007-06-17 19:56:38 -05001 /*******************************************************************
dea31012005-04-17 16:05:31 -05002 * This file is part of the Emulex Linux Device Driver for *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04003 * Fibre Channel Host Bus Adapters. *
James Smart50611572016-03-31 14:12:34 -07004 * Copyright (C) 2004-2016 Emulex. All rights reserved. *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04005 * EMULEX and SLI are trademarks of Emulex. *
dea31012005-04-17 16:05:31 -05006 * www.emulex.com *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04007 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
dea31012005-04-17 16:05:31 -05008 * *
9 * This program is free software; you can redistribute it and/or *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -040010 * modify it under the terms of version 2 of the GNU General *
11 * Public License as published by the Free Software Foundation. *
12 * This program is distributed in the hope that it will be useful. *
13 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
14 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
15 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
16 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
17 * TO BE LEGALLY INVALID. See the GNU General Public License for *
18 * more details, a copy of which can be found in the file COPYING *
19 * included with this package. *
dea31012005-04-17 16:05:31 -050020 *******************************************************************/
21
dea31012005-04-17 16:05:31 -050022#include <linux/blkdev.h>
23#include <linux/pci.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090024#include <linux/slab.h>
dea31012005-04-17 16:05:31 -050025#include <linux/interrupt.h>
26
James.Smart@Emulex.Com91886522005-08-10 15:03:09 -040027#include <scsi/scsi.h>
dea31012005-04-17 16:05:31 -050028#include <scsi/scsi_device.h>
29#include <scsi/scsi_host.h>
30#include <scsi/scsi_transport_fc.h>
31
James Smartda0436e2009-05-22 14:51:39 -040032#include "lpfc_hw4.h"
dea31012005-04-17 16:05:31 -050033#include "lpfc_hw.h"
34#include "lpfc_sli.h"
James Smartda0436e2009-05-22 14:51:39 -040035#include "lpfc_sli4.h"
James Smartea2151b2008-09-07 11:52:10 -040036#include "lpfc_nl.h"
dea31012005-04-17 16:05:31 -050037#include "lpfc_disc.h"
38#include "lpfc_scsi.h"
39#include "lpfc.h"
40#include "lpfc_logmsg.h"
41#include "lpfc_crtn.h"
James Smart92d7f7b2007-06-17 19:56:38 -050042#include "lpfc_vport.h"
James Smart858c9f62007-06-17 19:56:39 -050043#include "lpfc_debugfs.h"
dea31012005-04-17 16:05:31 -050044
45
46/* Called to verify a rcv'ed ADISC was intended for us. */
47static int
James Smart2e0fef82007-06-17 19:56:36 -050048lpfc_check_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
49 struct lpfc_name *nn, struct lpfc_name *pn)
dea31012005-04-17 16:05:31 -050050{
James Smart6b5151f2012-01-18 16:24:06 -050051 /* First, we MUST have a RPI registered */
52 if (!(ndlp->nlp_flag & NLP_RPI_REGISTERED))
53 return 0;
54
dea31012005-04-17 16:05:31 -050055 /* Compare the ADISC rsp WWNN / WWPN matches our internal node
56 * table entry for that node.
57 */
James Smart2e0fef82007-06-17 19:56:36 -050058 if (memcmp(nn, &ndlp->nlp_nodename, sizeof (struct lpfc_name)))
Jamie Wellnitzc9f87352006-02-28 19:25:23 -050059 return 0;
dea31012005-04-17 16:05:31 -050060
James Smart2e0fef82007-06-17 19:56:36 -050061 if (memcmp(pn, &ndlp->nlp_portname, sizeof (struct lpfc_name)))
Jamie Wellnitzc9f87352006-02-28 19:25:23 -050062 return 0;
dea31012005-04-17 16:05:31 -050063
64 /* we match, return success */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -050065 return 1;
dea31012005-04-17 16:05:31 -050066}
67
dea31012005-04-17 16:05:31 -050068int
James Smart2e0fef82007-06-17 19:56:36 -050069lpfc_check_sparm(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
James Smart341af102010-01-26 23:07:37 -050070 struct serv_parm *sp, uint32_t class, int flogi)
dea31012005-04-17 16:05:31 -050071{
James Smart2e0fef82007-06-17 19:56:36 -050072 volatile struct serv_parm *hsp = &vport->fc_sparam;
James.Smart@Emulex.Com2fb70f72005-11-28 11:41:24 -050073 uint16_t hsp_value, ssp_value = 0;
dea31012005-04-17 16:05:31 -050074
James.Smart@Emulex.Com2fb70f72005-11-28 11:41:24 -050075 /*
76 * The receive data field size and buffer-to-buffer receive data field
77 * size entries are 16 bits but are represented as two 8-bit fields in
78 * the driver data structure to account for rsvd bits and other control
79 * bits. Reconstruct and compare the fields as a 16-bit values before
80 * correcting the byte values.
81 */
dea31012005-04-17 16:05:31 -050082 if (sp->cls1.classValid) {
James Smart341af102010-01-26 23:07:37 -050083 if (!flogi) {
84 hsp_value = ((hsp->cls1.rcvDataSizeMsb << 8) |
85 hsp->cls1.rcvDataSizeLsb);
86 ssp_value = ((sp->cls1.rcvDataSizeMsb << 8) |
87 sp->cls1.rcvDataSizeLsb);
88 if (!ssp_value)
89 goto bad_service_param;
90 if (ssp_value > hsp_value) {
91 sp->cls1.rcvDataSizeLsb =
92 hsp->cls1.rcvDataSizeLsb;
93 sp->cls1.rcvDataSizeMsb =
94 hsp->cls1.rcvDataSizeMsb;
95 }
James.Smart@Emulex.Com2fb70f72005-11-28 11:41:24 -050096 }
James Smart341af102010-01-26 23:07:37 -050097 } else if (class == CLASS1)
James Smart92d7f7b2007-06-17 19:56:38 -050098 goto bad_service_param;
dea31012005-04-17 16:05:31 -050099 if (sp->cls2.classValid) {
James Smart341af102010-01-26 23:07:37 -0500100 if (!flogi) {
101 hsp_value = ((hsp->cls2.rcvDataSizeMsb << 8) |
102 hsp->cls2.rcvDataSizeLsb);
103 ssp_value = ((sp->cls2.rcvDataSizeMsb << 8) |
104 sp->cls2.rcvDataSizeLsb);
105 if (!ssp_value)
106 goto bad_service_param;
107 if (ssp_value > hsp_value) {
108 sp->cls2.rcvDataSizeLsb =
109 hsp->cls2.rcvDataSizeLsb;
110 sp->cls2.rcvDataSizeMsb =
111 hsp->cls2.rcvDataSizeMsb;
112 }
James.Smart@Emulex.Com2fb70f72005-11-28 11:41:24 -0500113 }
James Smart341af102010-01-26 23:07:37 -0500114 } else if (class == CLASS2)
James Smart92d7f7b2007-06-17 19:56:38 -0500115 goto bad_service_param;
dea31012005-04-17 16:05:31 -0500116 if (sp->cls3.classValid) {
James Smart341af102010-01-26 23:07:37 -0500117 if (!flogi) {
118 hsp_value = ((hsp->cls3.rcvDataSizeMsb << 8) |
119 hsp->cls3.rcvDataSizeLsb);
120 ssp_value = ((sp->cls3.rcvDataSizeMsb << 8) |
121 sp->cls3.rcvDataSizeLsb);
122 if (!ssp_value)
123 goto bad_service_param;
124 if (ssp_value > hsp_value) {
125 sp->cls3.rcvDataSizeLsb =
126 hsp->cls3.rcvDataSizeLsb;
127 sp->cls3.rcvDataSizeMsb =
128 hsp->cls3.rcvDataSizeMsb;
129 }
James.Smart@Emulex.Com2fb70f72005-11-28 11:41:24 -0500130 }
James Smart341af102010-01-26 23:07:37 -0500131 } else if (class == CLASS3)
James Smart92d7f7b2007-06-17 19:56:38 -0500132 goto bad_service_param;
dea31012005-04-17 16:05:31 -0500133
James.Smart@Emulex.Com2fb70f72005-11-28 11:41:24 -0500134 /*
135 * Preserve the upper four bits of the MSB from the PLOGI response.
136 * These bits contain the Buffer-to-Buffer State Change Number
137 * from the target and need to be passed to the FW.
138 */
139 hsp_value = (hsp->cmn.bbRcvSizeMsb << 8) | hsp->cmn.bbRcvSizeLsb;
140 ssp_value = (sp->cmn.bbRcvSizeMsb << 8) | sp->cmn.bbRcvSizeLsb;
141 if (ssp_value > hsp_value) {
dea31012005-04-17 16:05:31 -0500142 sp->cmn.bbRcvSizeLsb = hsp->cmn.bbRcvSizeLsb;
James.Smart@Emulex.Com2fb70f72005-11-28 11:41:24 -0500143 sp->cmn.bbRcvSizeMsb = (sp->cmn.bbRcvSizeMsb & 0xF0) |
144 (hsp->cmn.bbRcvSizeMsb & 0x0F);
145 }
dea31012005-04-17 16:05:31 -0500146
dea31012005-04-17 16:05:31 -0500147 memcpy(&ndlp->nlp_nodename, &sp->nodeName, sizeof (struct lpfc_name));
148 memcpy(&ndlp->nlp_portname, &sp->portName, sizeof (struct lpfc_name));
James.Smart@Emulex.Com2fb70f72005-11-28 11:41:24 -0500149 return 1;
James Smart92d7f7b2007-06-17 19:56:38 -0500150bad_service_param:
James Smarte8b62012007-08-02 11:10:09 -0400151 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
152 "0207 Device %x "
153 "(%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x) sent "
154 "invalid service parameters. Ignoring device.\n",
155 ndlp->nlp_DID,
156 sp->nodeName.u.wwn[0], sp->nodeName.u.wwn[1],
157 sp->nodeName.u.wwn[2], sp->nodeName.u.wwn[3],
158 sp->nodeName.u.wwn[4], sp->nodeName.u.wwn[5],
159 sp->nodeName.u.wwn[6], sp->nodeName.u.wwn[7]);
James Smart92d7f7b2007-06-17 19:56:38 -0500160 return 0;
dea31012005-04-17 16:05:31 -0500161}
162
163static void *
James Smart2e0fef82007-06-17 19:56:36 -0500164lpfc_check_elscmpl_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -0500165 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -0500166{
167 struct lpfc_dmabuf *pcmd, *prsp;
168 uint32_t *lp;
169 void *ptr = NULL;
170 IOCB_t *irsp;
171
172 irsp = &rspiocb->iocb;
173 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
174
175 /* For lpfc_els_abort, context2 could be zero'ed to delay
176 * freeing associated memory till after ABTS completes.
177 */
178 if (pcmd) {
179 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf,
180 list);
181 if (prsp) {
182 lp = (uint32_t *) prsp->virt;
183 ptr = (void *)((uint8_t *)lp + sizeof(uint32_t));
184 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500185 } else {
dea31012005-04-17 16:05:31 -0500186 /* Force ulpStatus error since we are returning NULL ptr */
187 if (!(irsp->ulpStatus)) {
188 irsp->ulpStatus = IOSTAT_LOCAL_REJECT;
189 irsp->un.ulpWord[4] = IOERR_SLI_ABORTED;
190 }
191 ptr = NULL;
192 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500193 return ptr;
dea31012005-04-17 16:05:31 -0500194}
195
196
James Smart2a9bf3d2010-06-07 15:24:45 -0400197
dea31012005-04-17 16:05:31 -0500198/*
199 * Free resources / clean up outstanding I/Os
200 * associated with a LPFC_NODELIST entry. This
201 * routine effectively results in a "software abort".
202 */
203int
James Smart2e0fef82007-06-17 19:56:36 -0500204lpfc_els_abort(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -0500205{
James Smart2a9bf3d2010-06-07 15:24:45 -0400206 LIST_HEAD(abort_list);
James Smart2e0fef82007-06-17 19:56:36 -0500207 struct lpfc_sli *psli = &phba->sli;
208 struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING];
dea31012005-04-17 16:05:31 -0500209 struct lpfc_iocbq *iocb, *next_iocb;
dea31012005-04-17 16:05:31 -0500210
211 /* Abort outstanding I/O on NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -0400212 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_DISCOVERY,
James Smart2a9bf3d2010-06-07 15:24:45 -0400213 "2819 Abort outstanding I/O on NPort x%x "
James Smarte8b62012007-08-02 11:10:09 -0400214 "Data: x%x x%x x%x\n",
215 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
216 ndlp->nlp_rpi);
James Smart0976e1a2013-12-17 20:29:36 -0500217 /* Clean up all fabric IOs first.*/
James Smart92d7f7b2007-06-17 19:56:38 -0500218 lpfc_fabric_abort_nport(ndlp);
dea31012005-04-17 16:05:31 -0500219
James Smart0976e1a2013-12-17 20:29:36 -0500220 /*
221 * Lock the ELS ring txcmplq for SLI3/SLI4 and build a local list
222 * of all ELS IOs that need an ABTS. The IOs need to stay on the
223 * txcmplq so that the abort operation completes them successfully.
224 */
James Smart2e0fef82007-06-17 19:56:36 -0500225 spin_lock_irq(&phba->hbalock);
James Smart0976e1a2013-12-17 20:29:36 -0500226 if (phba->sli_rev == LPFC_SLI_REV4)
227 spin_lock(&pring->ring_lock);
228 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
229 /* Add to abort_list on on NDLP match. */
James Smart2a9bf3d2010-06-07 15:24:45 -0400230 if (lpfc_check_sli_ndlp(phba, pring, iocb, ndlp))
231 list_add_tail(&iocb->dlist, &abort_list);
232 }
James Smart0976e1a2013-12-17 20:29:36 -0500233 if (phba->sli_rev == LPFC_SLI_REV4)
234 spin_unlock(&pring->ring_lock);
James Smart2a9bf3d2010-06-07 15:24:45 -0400235 spin_unlock_irq(&phba->hbalock);
236
James Smart0976e1a2013-12-17 20:29:36 -0500237 /* Abort the targeted IOs and remove them from the abort list. */
James Smart2a9bf3d2010-06-07 15:24:45 -0400238 list_for_each_entry_safe(iocb, next_iocb, &abort_list, dlist) {
239 spin_lock_irq(&phba->hbalock);
240 list_del_init(&iocb->dlist);
241 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
242 spin_unlock_irq(&phba->hbalock);
243 }
244
James Smart0976e1a2013-12-17 20:29:36 -0500245 INIT_LIST_HEAD(&abort_list);
246
247 /* Now process the txq */
248 spin_lock_irq(&phba->hbalock);
249 if (phba->sli_rev == LPFC_SLI_REV4)
250 spin_lock(&pring->ring_lock);
251
252 list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
253 /* Check to see if iocb matches the nport we are looking for */
254 if (lpfc_check_sli_ndlp(phba, pring, iocb, ndlp)) {
255 list_del_init(&iocb->list);
256 list_add_tail(&iocb->list, &abort_list);
257 }
258 }
259
260 if (phba->sli_rev == LPFC_SLI_REV4)
261 spin_unlock(&pring->ring_lock);
262 spin_unlock_irq(&phba->hbalock);
263
James Smarta257bf92009-04-06 18:48:10 -0400264 /* Cancel all the IOCBs from the completions list */
James Smart0976e1a2013-12-17 20:29:36 -0500265 lpfc_sli_cancel_iocbs(phba, &abort_list,
266 IOSTAT_LOCAL_REJECT, IOERR_SLI_ABORTED);
James Smart2534ba72007-04-25 09:52:20 -0400267
James Smart0d2b6b82008-06-14 22:52:47 -0400268 lpfc_cancel_retry_delay_tmo(phba->pport, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500269 return 0;
dea31012005-04-17 16:05:31 -0500270}
271
272static int
James Smart2e0fef82007-06-17 19:56:36 -0500273lpfc_rcv_plogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
James Smart92d7f7b2007-06-17 19:56:38 -0500274 struct lpfc_iocbq *cmdiocb)
dea31012005-04-17 16:05:31 -0500275{
James Smart2e0fef82007-06-17 19:56:36 -0500276 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
277 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500278 struct lpfc_dmabuf *pcmd;
James Smarted4afe72015-04-07 15:07:11 -0400279 uint64_t nlp_portwwn = 0;
dea31012005-04-17 16:05:31 -0500280 uint32_t *lp;
281 IOCB_t *icmd;
282 struct serv_parm *sp;
James Smartd6de08c2015-12-16 18:11:53 -0500283 uint32_t ed_tov;
dea31012005-04-17 16:05:31 -0500284 LPFC_MBOXQ_t *mbox;
285 struct ls_rjt stat;
286 int rc;
287
288 memset(&stat, 0, sizeof (struct ls_rjt));
dea31012005-04-17 16:05:31 -0500289 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
290 lp = (uint32_t *) pcmd->virt;
291 sp = (struct serv_parm *) ((uint8_t *) lp + sizeof (uint32_t));
James Smarta8adb832007-10-27 13:37:53 -0400292 if (wwn_to_u64(sp->portName.u.wwn) == 0) {
293 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
294 "0140 PLOGI Reject: invalid nname\n");
295 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
296 stat.un.b.lsRjtRsnCodeExp = LSEXP_INVALID_PNAME;
297 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
298 NULL);
299 return 0;
300 }
301 if (wwn_to_u64(sp->nodeName.u.wwn) == 0) {
302 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
303 "0141 PLOGI Reject: invalid pname\n");
304 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
305 stat.un.b.lsRjtRsnCodeExp = LSEXP_INVALID_NNAME;
306 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
307 NULL);
308 return 0;
309 }
James Smarted4afe72015-04-07 15:07:11 -0400310
311 nlp_portwwn = wwn_to_u64(ndlp->nlp_portname.u.wwn);
James Smart341af102010-01-26 23:07:37 -0500312 if ((lpfc_check_sparm(vport, ndlp, sp, CLASS3, 0) == 0)) {
dea31012005-04-17 16:05:31 -0500313 /* Reject this request because invalid parameters */
314 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
315 stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
James Smart858c9f62007-06-17 19:56:39 -0500316 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
317 NULL);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500318 return 0;
dea31012005-04-17 16:05:31 -0500319 }
320 icmd = &cmdiocb->iocb;
321
322 /* PLOGI chkparm OK */
James Smarte8b62012007-08-02 11:10:09 -0400323 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
James Smarte74c03c2013-04-17 20:15:19 -0400324 "0114 PLOGI chkparm OK Data: x%x x%x x%x "
325 "x%x x%x x%x\n",
James Smarte8b62012007-08-02 11:10:09 -0400326 ndlp->nlp_DID, ndlp->nlp_state, ndlp->nlp_flag,
James Smarte74c03c2013-04-17 20:15:19 -0400327 ndlp->nlp_rpi, vport->port_state,
328 vport->fc_flag);
dea31012005-04-17 16:05:31 -0500329
James Smart3de2a652007-08-02 11:09:59 -0400330 if (vport->cfg_fcp_class == 2 && sp->cls2.classValid)
dea31012005-04-17 16:05:31 -0500331 ndlp->nlp_fcp_info |= CLASS2;
James Smarted957682007-06-17 19:56:37 -0500332 else
dea31012005-04-17 16:05:31 -0500333 ndlp->nlp_fcp_info |= CLASS3;
James Smart2e0fef82007-06-17 19:56:36 -0500334
dea31012005-04-17 16:05:31 -0500335 ndlp->nlp_class_sup = 0;
336 if (sp->cls1.classValid)
337 ndlp->nlp_class_sup |= FC_COS_CLASS1;
338 if (sp->cls2.classValid)
339 ndlp->nlp_class_sup |= FC_COS_CLASS2;
340 if (sp->cls3.classValid)
341 ndlp->nlp_class_sup |= FC_COS_CLASS3;
342 if (sp->cls4.classValid)
343 ndlp->nlp_class_sup |= FC_COS_CLASS4;
344 ndlp->nlp_maxframe =
345 ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) | sp->cmn.bbRcvSizeLsb;
346
James Smarted4afe72015-04-07 15:07:11 -0400347 /* if already logged in, do implicit logout */
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500348 switch (ndlp->nlp_state) {
dea31012005-04-17 16:05:31 -0500349 case NLP_STE_NPR_NODE:
350 if (!(ndlp->nlp_flag & NLP_NPR_ADISC))
351 break;
352 case NLP_STE_REG_LOGIN_ISSUE:
353 case NLP_STE_PRLI_ISSUE:
354 case NLP_STE_UNMAPPED_NODE:
355 case NLP_STE_MAPPED_NODE:
James Smarted4afe72015-04-07 15:07:11 -0400356 /* lpfc_plogi_confirm_nport skips fabric did, handle it here */
357 if (!(ndlp->nlp_type & NLP_FABRIC)) {
358 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb,
359 ndlp, NULL);
360 return 1;
361 }
362 if (nlp_portwwn != 0 &&
363 nlp_portwwn != wwn_to_u64(sp->portName.u.wwn))
364 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
365 "0143 PLOGI recv'd from DID: x%x "
366 "WWPN changed: old %llx new %llx\n",
367 ndlp->nlp_DID,
368 (unsigned long long)nlp_portwwn,
369 (unsigned long long)
370 wwn_to_u64(sp->portName.u.wwn));
371
372 ndlp->nlp_prev_state = ndlp->nlp_state;
373 /* rport needs to be unregistered first */
374 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
375 break;
dea31012005-04-17 16:05:31 -0500376 }
377
James Smart939723a2012-05-09 21:19:03 -0400378 /* Check for Nport to NPort pt2pt protocol */
James Smart92d7f7b2007-06-17 19:56:38 -0500379 if ((vport->fc_flag & FC_PT2PT) &&
380 !(vport->fc_flag & FC_PT2PT_PLOGI)) {
dea31012005-04-17 16:05:31 -0500381 /* rcv'ed PLOGI decides what our NPortId will be */
James Smart2e0fef82007-06-17 19:56:36 -0500382 vport->fc_myDID = icmd->un.rcvels.parmRo;
James Smartd6de08c2015-12-16 18:11:53 -0500383
384 ed_tov = be32_to_cpu(sp->cmn.e_d_tov);
385 if (sp->cmn.edtovResolution) {
386 /* E_D_TOV ticks are in nanoseconds */
387 ed_tov = (phba->fc_edtov + 999999) / 1000000;
dea31012005-04-17 16:05:31 -0500388 }
James Smartd6de08c2015-12-16 18:11:53 -0500389
James Smart939723a2012-05-09 21:19:03 -0400390 /*
James Smartd6de08c2015-12-16 18:11:53 -0500391 * For pt-to-pt, use the larger EDTOV
392 * RATOV = 2 * EDTOV
James Smart939723a2012-05-09 21:19:03 -0400393 */
James Smartd6de08c2015-12-16 18:11:53 -0500394 if (ed_tov > phba->fc_edtov)
395 phba->fc_edtov = ed_tov;
396 phba->fc_ratov = (2 * phba->fc_edtov) / 1000;
397
398 memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
399
400 /* Issue config_link / reg_vfi to account for updated TOV's */
401
James Smart939723a2012-05-09 21:19:03 -0400402 if (phba->sli_rev == LPFC_SLI_REV4)
403 lpfc_issue_reg_vfi(vport);
James Smartd6de08c2015-12-16 18:11:53 -0500404 else {
405 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
406 if (mbox == NULL)
407 goto out;
408 lpfc_config_link(phba, mbox);
409 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
410 mbox->vport = vport;
411 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
412 if (rc == MBX_NOT_FINISHED) {
413 mempool_free(mbox, phba->mbox_mem_pool);
414 goto out;
415 }
416 }
dea31012005-04-17 16:05:31 -0500417
James Smart2e0fef82007-06-17 19:56:36 -0500418 lpfc_can_disctmo(vport);
dea31012005-04-17 16:05:31 -0500419 }
James Smartd6de08c2015-12-16 18:11:53 -0500420
dea31012005-04-17 16:05:31 -0500421 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
James Smart2e0fef82007-06-17 19:56:36 -0500422 if (!mbox)
dea31012005-04-17 16:05:31 -0500423 goto out;
424
James Smart6b5151f2012-01-18 16:24:06 -0500425 /* Registering an existing RPI behaves differently for SLI3 vs SLI4 */
426 if (phba->sli_rev == LPFC_SLI_REV4)
427 lpfc_unreg_rpi(vport, ndlp);
428
James Smart6fb120a2009-05-22 14:52:59 -0400429 rc = lpfc_reg_rpi(phba, vport->vpi, icmd->un.rcvels.remoteID,
James Smart40426292010-12-15 17:58:10 -0500430 (uint8_t *) sp, mbox, ndlp->nlp_rpi);
James Smart2e0fef82007-06-17 19:56:36 -0500431 if (rc) {
432 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -0500433 goto out;
434 }
435
436 /* ACC PLOGI rsp command needs to execute first,
437 * queue this mbox command to be processed later.
438 */
439 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
James Smart329f9bc2007-04-25 09:53:01 -0400440 /*
441 * mbox->context2 = lpfc_nlp_get(ndlp) deferred until mailbox
442 * command issued in lpfc_cmpl_els_acc().
443 */
James Smart2e0fef82007-06-17 19:56:36 -0500444 mbox->vport = vport;
445 spin_lock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -0500446 ndlp->nlp_flag |= (NLP_ACC_REGLOGIN | NLP_RCV_PLOGI);
James Smart2e0fef82007-06-17 19:56:36 -0500447 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500448
James Smart33ccf8d2006-08-17 11:57:58 -0400449 /*
450 * If there is an outstanding PLOGI issued, abort it before
451 * sending ACC rsp for received PLOGI. If pending plogi
452 * is not canceled here, the plogi will be rejected by
453 * remote port and will be retried. On a configuration with
454 * single discovery thread, this will cause a huge delay in
455 * discovery. Also this will cause multiple state machines
456 * running in parallel for this node.
457 */
458 if (ndlp->nlp_state == NLP_STE_PLOGI_ISSUE) {
459 /* software abort outstanding PLOGI */
James Smart07951072007-04-25 09:51:38 -0400460 lpfc_els_abort(phba, ndlp);
James Smart33ccf8d2006-08-17 11:57:58 -0400461 }
462
James Smart858c9f62007-06-17 19:56:39 -0500463 if ((vport->port_type == LPFC_NPIV_PORT &&
James Smart3de2a652007-08-02 11:09:59 -0400464 vport->cfg_restrict_login)) {
James Smart858c9f62007-06-17 19:56:39 -0500465
466 /* In order to preserve RPIs, we want to cleanup
467 * the default RPI the firmware created to rcv
468 * this ELS request. The only way to do this is
469 * to register, then unregister the RPI.
470 */
471 spin_lock_irq(shost->host_lock);
472 ndlp->nlp_flag |= NLP_RM_DFLT_RPI;
473 spin_unlock_irq(shost->host_lock);
474 stat.un.b.lsRjtRsnCode = LSRJT_INVALID_CMD;
475 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
James Smart0a8a86f2012-03-01 22:36:15 -0500476 rc = lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb,
James Smart858c9f62007-06-17 19:56:39 -0500477 ndlp, mbox);
James Smart0a8a86f2012-03-01 22:36:15 -0500478 if (rc)
479 mempool_free(mbox, phba->mbox_mem_pool);
James Smart858c9f62007-06-17 19:56:39 -0500480 return 1;
481 }
James Smart0a8a86f2012-03-01 22:36:15 -0500482 rc = lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp, mbox);
483 if (rc)
484 mempool_free(mbox, phba->mbox_mem_pool);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500485 return 1;
dea31012005-04-17 16:05:31 -0500486out:
487 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
488 stat.un.b.lsRjtRsnCodeExp = LSEXP_OUT_OF_RESOURCE;
James Smart858c9f62007-06-17 19:56:39 -0500489 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500490 return 0;
dea31012005-04-17 16:05:31 -0500491}
492
James Smart6b5151f2012-01-18 16:24:06 -0500493/**
494 * lpfc_mbx_cmpl_resume_rpi - Resume RPI completion routine
495 * @phba: pointer to lpfc hba data structure.
496 * @mboxq: pointer to mailbox object
497 *
498 * This routine is invoked to issue a completion to a rcv'ed
499 * ADISC or PDISC after the paused RPI has been resumed.
500 **/
501static void
502lpfc_mbx_cmpl_resume_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
503{
504 struct lpfc_vport *vport;
505 struct lpfc_iocbq *elsiocb;
506 struct lpfc_nodelist *ndlp;
507 uint32_t cmd;
508
509 elsiocb = (struct lpfc_iocbq *)mboxq->context1;
510 ndlp = (struct lpfc_nodelist *) mboxq->context2;
511 vport = mboxq->vport;
512 cmd = elsiocb->drvrTimeout;
513
514 if (cmd == ELS_CMD_ADISC) {
515 lpfc_els_rsp_adisc_acc(vport, elsiocb, ndlp);
516 } else {
517 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, elsiocb,
518 ndlp, NULL);
519 }
520 kfree(elsiocb);
James Smart72859902012-01-18 16:25:38 -0500521 mempool_free(mboxq, phba->mbox_mem_pool);
James Smart6b5151f2012-01-18 16:24:06 -0500522}
523
dea31012005-04-17 16:05:31 -0500524static int
James Smart2e0fef82007-06-17 19:56:36 -0500525lpfc_rcv_padisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -0500526 struct lpfc_iocbq *cmdiocb)
527{
James Smart2e0fef82007-06-17 19:56:36 -0500528 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart6b5151f2012-01-18 16:24:06 -0500529 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -0500530 struct lpfc_dmabuf *pcmd;
James Smart2e0fef82007-06-17 19:56:36 -0500531 struct serv_parm *sp;
532 struct lpfc_name *pnn, *ppn;
dea31012005-04-17 16:05:31 -0500533 struct ls_rjt stat;
534 ADISC *ap;
535 IOCB_t *icmd;
536 uint32_t *lp;
537 uint32_t cmd;
538
539 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
540 lp = (uint32_t *) pcmd->virt;
541
542 cmd = *lp++;
543 if (cmd == ELS_CMD_ADISC) {
544 ap = (ADISC *) lp;
545 pnn = (struct lpfc_name *) & ap->nodeName;
546 ppn = (struct lpfc_name *) & ap->portName;
547 } else {
548 sp = (struct serv_parm *) lp;
549 pnn = (struct lpfc_name *) & sp->nodeName;
550 ppn = (struct lpfc_name *) & sp->portName;
551 }
552
553 icmd = &cmdiocb->iocb;
James Smart2e0fef82007-06-17 19:56:36 -0500554 if (icmd->ulpStatus == 0 && lpfc_check_adisc(vport, ndlp, pnn, ppn)) {
James Smart6b5151f2012-01-18 16:24:06 -0500555
556 /*
557 * As soon as we send ACC, the remote NPort can
558 * start sending us data. Thus, for SLI4 we must
559 * resume the RPI before the ACC goes out.
560 */
561 if (vport->phba->sli_rev == LPFC_SLI_REV4) {
562 elsiocb = kmalloc(sizeof(struct lpfc_iocbq),
563 GFP_KERNEL);
564 if (elsiocb) {
565
566 /* Save info from cmd IOCB used in rsp */
567 memcpy((uint8_t *)elsiocb, (uint8_t *)cmdiocb,
568 sizeof(struct lpfc_iocbq));
569
570 /* Save the ELS cmd */
571 elsiocb->drvrTimeout = cmd;
572
573 lpfc_sli4_resume_rpi(ndlp,
574 lpfc_mbx_cmpl_resume_rpi, elsiocb);
575 goto out;
576 }
577 }
578
dea31012005-04-17 16:05:31 -0500579 if (cmd == ELS_CMD_ADISC) {
James Smart2e0fef82007-06-17 19:56:36 -0500580 lpfc_els_rsp_adisc_acc(vport, cmdiocb, ndlp);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500581 } else {
James Smart6b5151f2012-01-18 16:24:06 -0500582 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb,
583 ndlp, NULL);
dea31012005-04-17 16:05:31 -0500584 }
James Smart6b5151f2012-01-18 16:24:06 -0500585out:
586 /* If we are authenticated, move to the proper state */
587 if (ndlp->nlp_type & NLP_FCP_TARGET)
588 lpfc_nlp_set_state(vport, ndlp, NLP_STE_MAPPED_NODE);
589 else
590 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
591
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500592 return 1;
dea31012005-04-17 16:05:31 -0500593 }
594 /* Reject this request because invalid parameters */
595 stat.un.b.lsRjtRsvd0 = 0;
596 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
597 stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
598 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -0500599 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -0500600
dea31012005-04-17 16:05:31 -0500601 /* 1 sec timeout */
James Smart256ec0d2013-04-17 20:14:58 -0400602 mod_timer(&ndlp->nlp_delayfunc, jiffies + msecs_to_jiffies(1000));
dea31012005-04-17 16:05:31 -0500603
James Smart2e0fef82007-06-17 19:56:36 -0500604 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500605 ndlp->nlp_flag |= NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -0500606 spin_unlock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -0500607 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
608 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -0500609 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500610 return 0;
dea31012005-04-17 16:05:31 -0500611}
612
613static int
James Smart2e0fef82007-06-17 19:56:36 -0500614lpfc_rcv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
615 struct lpfc_iocbq *cmdiocb, uint32_t els_cmd)
dea31012005-04-17 16:05:31 -0500616{
James Smart2e0fef82007-06-17 19:56:36 -0500617 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart4b40c592010-03-15 11:25:44 -0400618 struct lpfc_hba *phba = vport->phba;
619 struct lpfc_vport **vports;
620 int i, active_vlink_present = 0 ;
James Smart2e0fef82007-06-17 19:56:36 -0500621
622 /* Put ndlp in NPR state with 1 sec timeout for plogi, ACC logo */
dea31012005-04-17 16:05:31 -0500623 /* Only call LOGO ACC for first LOGO, this avoids sending unnecessary
624 * PLOGIs during LOGO storms from a device.
625 */
James Smart2e0fef82007-06-17 19:56:36 -0500626 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500627 ndlp->nlp_flag |= NLP_LOGO_ACC;
James Smart2e0fef82007-06-17 19:56:36 -0500628 spin_unlock_irq(shost->host_lock);
James Smart82d9a2a2006-04-15 11:53:05 -0400629 if (els_cmd == ELS_CMD_PRLO)
James Smart51ef4c22007-08-02 11:10:31 -0400630 lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL);
James Smart82d9a2a2006-04-15 11:53:05 -0400631 else
James Smart51ef4c22007-08-02 11:10:31 -0400632 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
James Smart4b40c592010-03-15 11:25:44 -0400633 if (ndlp->nlp_DID == Fabric_DID) {
634 if (vport->port_state <= LPFC_FDISC)
635 goto out;
James Smart6fb120a2009-05-22 14:52:59 -0400636 lpfc_linkdown_port(vport);
James Smart6fb120a2009-05-22 14:52:59 -0400637 spin_lock_irq(shost->host_lock);
James Smart4b40c592010-03-15 11:25:44 -0400638 vport->fc_flag |= FC_VPORT_LOGO_RCVD;
James Smart6fb120a2009-05-22 14:52:59 -0400639 spin_unlock_irq(shost->host_lock);
James Smart4b40c592010-03-15 11:25:44 -0400640 vports = lpfc_create_vport_work_array(phba);
641 if (vports) {
642 for (i = 0; i <= phba->max_vports && vports[i] != NULL;
643 i++) {
644 if ((!(vports[i]->fc_flag &
645 FC_VPORT_LOGO_RCVD)) &&
646 (vports[i]->port_state > LPFC_FDISC)) {
647 active_vlink_present = 1;
648 break;
649 }
650 }
651 lpfc_destroy_vport_work_array(phba, vports);
652 }
dea31012005-04-17 16:05:31 -0500653
James Smartcc823552015-05-21 13:55:26 -0400654 /*
655 * Don't re-instantiate if vport is marked for deletion.
656 * If we are here first then vport_delete is going to wait
657 * for discovery to complete.
658 */
659 if (!(vport->load_flag & FC_UNLOADING) &&
660 active_vlink_present) {
James Smart4b40c592010-03-15 11:25:44 -0400661 /*
662 * If there are other active VLinks present,
663 * re-instantiate the Vlink using FDISC.
664 */
James Smart256ec0d2013-04-17 20:14:58 -0400665 mod_timer(&ndlp->nlp_delayfunc,
666 jiffies + msecs_to_jiffies(1000));
James Smart4b40c592010-03-15 11:25:44 -0400667 spin_lock_irq(shost->host_lock);
668 ndlp->nlp_flag |= NLP_DELAY_TMO;
669 spin_unlock_irq(shost->host_lock);
670 ndlp->nlp_last_elscmd = ELS_CMD_FDISC;
671 vport->port_state = LPFC_FDISC;
672 } else {
673 spin_lock_irq(shost->host_lock);
674 phba->pport->fc_flag &= ~FC_LOGO_RCVD_DID_CHNG;
675 spin_unlock_irq(shost->host_lock);
676 lpfc_retry_pport_discovery(phba);
677 }
James Smart6fb120a2009-05-22 14:52:59 -0400678 } else if ((!(ndlp->nlp_type & NLP_FABRIC) &&
679 ((ndlp->nlp_type & NLP_FCP_TARGET) ||
680 !(ndlp->nlp_type & NLP_FCP_INITIATOR))) ||
681 (ndlp->nlp_state == NLP_STE_ADISC_ISSUE)) {
dea31012005-04-17 16:05:31 -0500682 /* Only try to re-login if this is NOT a Fabric Node */
James Smart256ec0d2013-04-17 20:14:58 -0400683 mod_timer(&ndlp->nlp_delayfunc,
684 jiffies + msecs_to_jiffies(1000 * 1));
James Smart2e0fef82007-06-17 19:56:36 -0500685 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500686 ndlp->nlp_flag |= NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -0500687 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500688
Jamie Wellnitz5024ab12006-02-28 19:25:28 -0500689 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
dea31012005-04-17 16:05:31 -0500690 }
James Smart4b40c592010-03-15 11:25:44 -0400691out:
James Smart87af33f2007-10-27 13:37:43 -0400692 ndlp->nlp_prev_state = ndlp->nlp_state;
693 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
dea31012005-04-17 16:05:31 -0500694
James Smart2e0fef82007-06-17 19:56:36 -0500695 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500696 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
James Smart2e0fef82007-06-17 19:56:36 -0500697 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500698 /* The driver has to wait until the ACC completes before it continues
699 * processing the LOGO. The action will resume in
700 * lpfc_cmpl_els_logo_acc routine. Since part of processing includes an
701 * unreg_login, the driver waits so the ACC does not get aborted.
702 */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500703 return 0;
dea31012005-04-17 16:05:31 -0500704}
705
706static void
James Smart2e0fef82007-06-17 19:56:36 -0500707lpfc_rcv_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
708 struct lpfc_iocbq *cmdiocb)
dea31012005-04-17 16:05:31 -0500709{
710 struct lpfc_dmabuf *pcmd;
711 uint32_t *lp;
712 PRLI *npr;
713 struct fc_rport *rport = ndlp->rport;
714 u32 roles;
715
716 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
717 lp = (uint32_t *) pcmd->virt;
718 npr = (PRLI *) ((uint8_t *) lp + sizeof (uint32_t));
719
720 ndlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR);
721 ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
James Smart3cb01c52013-07-15 18:35:04 -0400722 ndlp->nlp_flag &= ~NLP_FIRSTBURST;
James Smart92d7f7b2007-06-17 19:56:38 -0500723 if (npr->prliType == PRLI_FCP_TYPE) {
dea31012005-04-17 16:05:31 -0500724 if (npr->initiatorFunc)
725 ndlp->nlp_type |= NLP_FCP_INITIATOR;
James Smart3cb01c52013-07-15 18:35:04 -0400726 if (npr->targetFunc) {
dea31012005-04-17 16:05:31 -0500727 ndlp->nlp_type |= NLP_FCP_TARGET;
James Smart3cb01c52013-07-15 18:35:04 -0400728 if (npr->writeXferRdyDis)
729 ndlp->nlp_flag |= NLP_FIRSTBURST;
730 }
dea31012005-04-17 16:05:31 -0500731 if (npr->Retry)
732 ndlp->nlp_fcp_info |= NLP_FCP_2_DEVICE;
733 }
734 if (rport) {
735 /* We need to update the rport role values */
736 roles = FC_RPORT_ROLE_UNKNOWN;
737 if (ndlp->nlp_type & NLP_FCP_INITIATOR)
738 roles |= FC_RPORT_ROLE_FCP_INITIATOR;
739 if (ndlp->nlp_type & NLP_FCP_TARGET)
740 roles |= FC_RPORT_ROLE_FCP_TARGET;
James Smart858c9f62007-06-17 19:56:39 -0500741
742 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
743 "rport rolechg: role:x%x did:x%x flg:x%x",
744 roles, ndlp->nlp_DID, ndlp->nlp_flag);
745
dea31012005-04-17 16:05:31 -0500746 fc_remote_port_rolechg(rport, roles);
747 }
748}
749
750static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -0500751lpfc_disc_set_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -0500752{
James Smart2e0fef82007-06-17 19:56:36 -0500753 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart2e0fef82007-06-17 19:56:36 -0500754
James Smart40426292010-12-15 17:58:10 -0500755 if (!(ndlp->nlp_flag & NLP_RPI_REGISTERED)) {
James Smart51ef4c22007-08-02 11:10:31 -0400756 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
757 return 0;
758 }
759
James Smart1b32f6a2008-02-08 18:49:39 -0500760 if (!(vport->fc_flag & FC_PT2PT)) {
761 /* Check config parameter use-adisc or FCP-2 */
762 if ((vport->cfg_use_adisc && (vport->fc_flag & FC_RSCN_MODE)) ||
James Smartffc95492010-06-07 15:23:17 -0400763 ((ndlp->nlp_fcp_info & NLP_FCP_2_DEVICE) &&
764 (ndlp->nlp_type & NLP_FCP_TARGET))) {
James Smart1b32f6a2008-02-08 18:49:39 -0500765 spin_lock_irq(shost->host_lock);
766 ndlp->nlp_flag |= NLP_NPR_ADISC;
767 spin_unlock_irq(shost->host_lock);
768 return 1;
769 }
James Smart92d7f7b2007-06-17 19:56:38 -0500770 }
771 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
772 lpfc_unreg_rpi(vport, ndlp);
773 return 0;
dea31012005-04-17 16:05:31 -0500774}
James Smart6d368e52011-05-24 11:44:12 -0400775
James Smart78730cf2010-04-06 15:06:30 -0400776/**
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300777 * lpfc_release_rpi - Release a RPI by issuing unreg_login mailbox cmd.
James Smart78730cf2010-04-06 15:06:30 -0400778 * @phba : Pointer to lpfc_hba structure.
779 * @vport: Pointer to lpfc_vport structure.
780 * @rpi : rpi to be release.
781 *
782 * This function will send a unreg_login mailbox command to the firmware
783 * to release a rpi.
784 **/
785void
786lpfc_release_rpi(struct lpfc_hba *phba,
787 struct lpfc_vport *vport,
788 uint16_t rpi)
789{
790 LPFC_MBOXQ_t *pmb;
791 int rc;
792
793 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
794 GFP_KERNEL);
795 if (!pmb)
796 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
797 "2796 mailbox memory allocation failed \n");
798 else {
799 lpfc_unreg_login(phba, vport->vpi, rpi, pmb);
800 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
801 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
802 if (rc == MBX_NOT_FINISHED)
803 mempool_free(pmb, phba->mbox_mem_pool);
804 }
805}
dea31012005-04-17 16:05:31 -0500806
807static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -0500808lpfc_disc_illegal(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
809 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -0500810{
James Smart78730cf2010-04-06 15:06:30 -0400811 struct lpfc_hba *phba;
812 LPFC_MBOXQ_t *pmb = (LPFC_MBOXQ_t *) arg;
James Smart78730cf2010-04-06 15:06:30 -0400813 uint16_t rpi;
814
815 phba = vport->phba;
816 /* Release the RPI if reglogin completing */
817 if (!(phba->pport->load_flag & FC_UNLOADING) &&
818 (evt == NLP_EVT_CMPL_REG_LOGIN) &&
819 (!pmb->u.mb.mbxStatus)) {
James Smart78730cf2010-04-06 15:06:30 -0400820 rpi = pmb->u.mb.un.varWords[0];
821 lpfc_release_rpi(phba, vport, rpi);
822 }
James Smarte8b62012007-08-02 11:10:09 -0400823 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
James Smarte47c9092008-02-08 18:49:26 -0500824 "0271 Illegal State Transition: node x%x "
James Smarte8b62012007-08-02 11:10:09 -0400825 "event x%x, state x%x Data: x%x x%x\n",
826 ndlp->nlp_DID, evt, ndlp->nlp_state, ndlp->nlp_rpi,
827 ndlp->nlp_flag);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500828 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -0500829}
830
James Smart87af33f2007-10-27 13:37:43 -0400831static uint32_t
832lpfc_cmpl_plogi_illegal(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
833 void *arg, uint32_t evt)
834{
835 /* This transition is only legal if we previously
836 * rcv'ed a PLOGI. Since we don't want 2 discovery threads
837 * working on the same NPortID, do nothing for this thread
838 * to stop it.
839 */
840 if (!(ndlp->nlp_flag & NLP_RCV_PLOGI)) {
841 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
James Smarte47c9092008-02-08 18:49:26 -0500842 "0272 Illegal State Transition: node x%x "
James Smart87af33f2007-10-27 13:37:43 -0400843 "event x%x, state x%x Data: x%x x%x\n",
844 ndlp->nlp_DID, evt, ndlp->nlp_state, ndlp->nlp_rpi,
845 ndlp->nlp_flag);
846 }
847 return ndlp->nlp_state;
848}
849
dea31012005-04-17 16:05:31 -0500850/* Start of Discovery State Machine routines */
851
852static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -0500853lpfc_rcv_plogi_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
854 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -0500855{
856 struct lpfc_iocbq *cmdiocb;
857
858 cmdiocb = (struct lpfc_iocbq *) arg;
859
James Smart2e0fef82007-06-17 19:56:36 -0500860 if (lpfc_rcv_plogi(vport, ndlp, cmdiocb)) {
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500861 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -0500862 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500863 return NLP_STE_FREED_NODE;
dea31012005-04-17 16:05:31 -0500864}
865
866static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -0500867lpfc_rcv_els_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
868 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -0500869{
James Smart2e0fef82007-06-17 19:56:36 -0500870 lpfc_issue_els_logo(vport, ndlp, 0);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500871 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -0500872}
873
874static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -0500875lpfc_rcv_logo_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
876 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -0500877{
James Smart2e0fef82007-06-17 19:56:36 -0500878 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
879 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -0500880
James Smart2e0fef82007-06-17 19:56:36 -0500881 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500882 ndlp->nlp_flag |= NLP_LOGO_ACC;
James Smart2e0fef82007-06-17 19:56:36 -0500883 spin_unlock_irq(shost->host_lock);
James Smart51ef4c22007-08-02 11:10:31 -0400884 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -0500885
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500886 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -0500887}
888
889static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -0500890lpfc_cmpl_logo_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -0500891 void *arg, uint32_t evt)
892{
James Smart2e0fef82007-06-17 19:56:36 -0500893 return NLP_STE_FREED_NODE;
894}
895
896static uint32_t
897lpfc_device_rm_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
898 void *arg, uint32_t evt)
899{
James Smart2e0fef82007-06-17 19:56:36 -0500900 return NLP_STE_FREED_NODE;
901}
902
903static uint32_t
James Smartdf9e1b52011-12-13 13:22:17 -0500904lpfc_device_recov_unused_node(struct lpfc_vport *vport,
905 struct lpfc_nodelist *ndlp,
906 void *arg, uint32_t evt)
907{
908 return ndlp->nlp_state;
909}
910
911static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -0500912lpfc_rcv_plogi_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
913 void *arg, uint32_t evt)
914{
James Smart0d2b6b82008-06-14 22:52:47 -0400915 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart2e0fef82007-06-17 19:56:36 -0500916 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500917 struct lpfc_iocbq *cmdiocb = arg;
James Smart2e0fef82007-06-17 19:56:36 -0500918 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
919 uint32_t *lp = (uint32_t *) pcmd->virt;
920 struct serv_parm *sp = (struct serv_parm *) (lp + 1);
dea31012005-04-17 16:05:31 -0500921 struct ls_rjt stat;
922 int port_cmp;
923
dea31012005-04-17 16:05:31 -0500924 memset(&stat, 0, sizeof (struct ls_rjt));
925
926 /* For a PLOGI, we only accept if our portname is less
927 * than the remote portname.
928 */
929 phba->fc_stat.elsLogiCol++;
James Smart2e0fef82007-06-17 19:56:36 -0500930 port_cmp = memcmp(&vport->fc_portname, &sp->portName,
James Smart92d7f7b2007-06-17 19:56:38 -0500931 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -0500932
933 if (port_cmp >= 0) {
934 /* Reject this request because the remote node will accept
935 ours */
936 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
937 stat.un.b.lsRjtRsnCodeExp = LSEXP_CMD_IN_PROGRESS;
James Smart858c9f62007-06-17 19:56:39 -0500938 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
939 NULL);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500940 } else {
James Smart0d2b6b82008-06-14 22:52:47 -0400941 if (lpfc_rcv_plogi(vport, ndlp, cmdiocb) &&
942 (ndlp->nlp_flag & NLP_NPR_2B_DISC) &&
943 (vport->num_disc_nodes)) {
944 spin_lock_irq(shost->host_lock);
945 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
946 spin_unlock_irq(shost->host_lock);
947 /* Check if there are more PLOGIs to be sent */
948 lpfc_more_plogi(vport);
949 if (vport->num_disc_nodes == 0) {
950 spin_lock_irq(shost->host_lock);
951 vport->fc_flag &= ~FC_NDISC_ACTIVE;
952 spin_unlock_irq(shost->host_lock);
953 lpfc_can_disctmo(vport);
954 lpfc_end_rscn(vport);
955 }
956 }
James Smart2e0fef82007-06-17 19:56:36 -0500957 } /* If our portname was less */
dea31012005-04-17 16:05:31 -0500958
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500959 return ndlp->nlp_state;
960}
961
962static uint32_t
James Smart92d7f7b2007-06-17 19:56:38 -0500963lpfc_rcv_prli_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
964 void *arg, uint32_t evt)
965{
966 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
967 struct ls_rjt stat;
968
969 memset(&stat, 0, sizeof (struct ls_rjt));
970 stat.un.b.lsRjtRsnCode = LSRJT_LOGICAL_BSY;
971 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
James Smart858c9f62007-06-17 19:56:39 -0500972 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
James Smart92d7f7b2007-06-17 19:56:38 -0500973 return ndlp->nlp_state;
974}
975
976static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -0500977lpfc_rcv_logo_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
978 void *arg, uint32_t evt)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500979{
James Smart2e0fef82007-06-17 19:56:36 -0500980 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500981
James Smart92d7f7b2007-06-17 19:56:38 -0500982 /* software abort outstanding PLOGI */
James Smart2e0fef82007-06-17 19:56:36 -0500983 lpfc_els_abort(vport->phba, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500984
James Smart2e0fef82007-06-17 19:56:36 -0500985 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500986 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -0500987}
988
989static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -0500990lpfc_rcv_els_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
991 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -0500992{
James Smart2e0fef82007-06-17 19:56:36 -0500993 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
994 struct lpfc_hba *phba = vport->phba;
995 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -0500996
997 /* software abort outstanding PLOGI */
James Smart07951072007-04-25 09:51:38 -0400998 lpfc_els_abort(phba, ndlp);
dea31012005-04-17 16:05:31 -0500999
1000 if (evt == NLP_EVT_RCV_LOGO) {
James Smart51ef4c22007-08-02 11:10:31 -04001001 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05001002 } else {
James Smart2e0fef82007-06-17 19:56:36 -05001003 lpfc_issue_els_logo(vport, ndlp, 0);
dea31012005-04-17 16:05:31 -05001004 }
1005
James Smart2e0fef82007-06-17 19:56:36 -05001006 /* Put ndlp in npr state set plogi timer for 1 sec */
James Smart256ec0d2013-04-17 20:14:58 -04001007 mod_timer(&ndlp->nlp_delayfunc, jiffies + msecs_to_jiffies(1000 * 1));
James Smart2e0fef82007-06-17 19:56:36 -05001008 spin_lock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001009 ndlp->nlp_flag |= NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05001010 spin_unlock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001011 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
1012 ndlp->nlp_prev_state = NLP_STE_PLOGI_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -05001013 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
dea31012005-04-17 16:05:31 -05001014
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001015 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001016}
1017
1018static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001019lpfc_cmpl_plogi_plogi_issue(struct lpfc_vport *vport,
1020 struct lpfc_nodelist *ndlp,
1021 void *arg,
dea31012005-04-17 16:05:31 -05001022 uint32_t evt)
1023{
James Smart2e0fef82007-06-17 19:56:36 -05001024 struct lpfc_hba *phba = vport->phba;
James Smart0ff10d42008-01-11 01:52:36 -05001025 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart2e0fef82007-06-17 19:56:36 -05001026 struct lpfc_iocbq *cmdiocb, *rspiocb;
James Smart14691152006-12-02 13:34:28 -05001027 struct lpfc_dmabuf *pcmd, *prsp, *mp;
dea31012005-04-17 16:05:31 -05001028 uint32_t *lp;
1029 IOCB_t *irsp;
1030 struct serv_parm *sp;
James Smartd6de08c2015-12-16 18:11:53 -05001031 uint32_t ed_tov;
dea31012005-04-17 16:05:31 -05001032 LPFC_MBOXQ_t *mbox;
James Smartd6de08c2015-12-16 18:11:53 -05001033 int rc;
dea31012005-04-17 16:05:31 -05001034
1035 cmdiocb = (struct lpfc_iocbq *) arg;
1036 rspiocb = cmdiocb->context_un.rsp_iocb;
1037
1038 if (ndlp->nlp_flag & NLP_ACC_REGLOGIN) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001039 /* Recovery from PLOGI collision logic */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001040 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001041 }
1042
1043 irsp = &rspiocb->iocb;
1044
1045 if (irsp->ulpStatus)
1046 goto out;
1047
1048 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
1049
James Smart2e0fef82007-06-17 19:56:36 -05001050 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
James Smarta2fc4aef2014-09-03 12:57:55 -04001051 if (!prsp)
1052 goto out;
dea31012005-04-17 16:05:31 -05001053
James Smart2e0fef82007-06-17 19:56:36 -05001054 lp = (uint32_t *) prsp->virt;
dea31012005-04-17 16:05:31 -05001055 sp = (struct serv_parm *) ((uint8_t *) lp + sizeof (uint32_t));
James Smart58da1ff2008-04-07 10:15:56 -04001056
1057 /* Some switches have FDMI servers returning 0 for WWN */
1058 if ((ndlp->nlp_DID != FDMI_DID) &&
1059 (wwn_to_u64(sp->portName.u.wwn) == 0 ||
1060 wwn_to_u64(sp->nodeName.u.wwn) == 0)) {
James Smarta8adb832007-10-27 13:37:53 -04001061 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1062 "0142 PLOGI RSP: Invalid WWN.\n");
1063 goto out;
1064 }
James Smart341af102010-01-26 23:07:37 -05001065 if (!lpfc_check_sparm(vport, ndlp, sp, CLASS3, 0))
dea31012005-04-17 16:05:31 -05001066 goto out;
dea31012005-04-17 16:05:31 -05001067 /* PLOGI chkparm OK */
James Smarte8b62012007-08-02 11:10:09 -04001068 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1069 "0121 PLOGI chkparm OK Data: x%x x%x x%x x%x\n",
1070 ndlp->nlp_DID, ndlp->nlp_state,
1071 ndlp->nlp_flag, ndlp->nlp_rpi);
James Smart3de2a652007-08-02 11:09:59 -04001072 if (vport->cfg_fcp_class == 2 && (sp->cls2.classValid))
dea31012005-04-17 16:05:31 -05001073 ndlp->nlp_fcp_info |= CLASS2;
James Smart2e0fef82007-06-17 19:56:36 -05001074 else
dea31012005-04-17 16:05:31 -05001075 ndlp->nlp_fcp_info |= CLASS3;
James Smart2e0fef82007-06-17 19:56:36 -05001076
dea31012005-04-17 16:05:31 -05001077 ndlp->nlp_class_sup = 0;
1078 if (sp->cls1.classValid)
1079 ndlp->nlp_class_sup |= FC_COS_CLASS1;
1080 if (sp->cls2.classValid)
1081 ndlp->nlp_class_sup |= FC_COS_CLASS2;
1082 if (sp->cls3.classValid)
1083 ndlp->nlp_class_sup |= FC_COS_CLASS3;
1084 if (sp->cls4.classValid)
1085 ndlp->nlp_class_sup |= FC_COS_CLASS4;
1086 ndlp->nlp_maxframe =
James Smart2e0fef82007-06-17 19:56:36 -05001087 ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) | sp->cmn.bbRcvSizeLsb;
dea31012005-04-17 16:05:31 -05001088
James Smartd6de08c2015-12-16 18:11:53 -05001089 if ((vport->fc_flag & FC_PT2PT) &&
1090 (vport->fc_flag & FC_PT2PT_PLOGI)) {
1091 ed_tov = be32_to_cpu(sp->cmn.e_d_tov);
1092 if (sp->cmn.edtovResolution) {
1093 /* E_D_TOV ticks are in nanoseconds */
1094 ed_tov = (phba->fc_edtov + 999999) / 1000000;
1095 }
1096
1097 /*
1098 * Use the larger EDTOV
1099 * RATOV = 2 * EDTOV for pt-to-pt
1100 */
1101 if (ed_tov > phba->fc_edtov)
1102 phba->fc_edtov = ed_tov;
1103 phba->fc_ratov = (2 * phba->fc_edtov) / 1000;
1104
1105 memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
1106
1107 /* Issue config_link / reg_vfi to account for updated TOV's */
1108 if (phba->sli_rev == LPFC_SLI_REV4) {
1109 lpfc_issue_reg_vfi(vport);
1110 } else {
James Smart01c73bb2015-12-16 18:12:03 -05001111 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1112 if (!mbox) {
1113 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1114 "0133 PLOGI: no memory "
1115 "for config_link "
1116 "Data: x%x x%x x%x x%x\n",
1117 ndlp->nlp_DID, ndlp->nlp_state,
1118 ndlp->nlp_flag, ndlp->nlp_rpi);
1119 goto out;
1120 }
1121
James Smartd6de08c2015-12-16 18:11:53 -05001122 lpfc_config_link(phba, mbox);
1123
1124 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1125 mbox->vport = vport;
1126 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
1127 if (rc == MBX_NOT_FINISHED) {
1128 mempool_free(mbox, phba->mbox_mem_pool);
1129 goto out;
1130 }
1131 }
James Smart92d7f7b2007-06-17 19:56:38 -05001132 }
dea31012005-04-17 16:05:31 -05001133
James Smart2e0fef82007-06-17 19:56:36 -05001134 lpfc_unreg_rpi(vport, ndlp);
1135
James Smart01c73bb2015-12-16 18:12:03 -05001136 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1137 if (!mbox) {
1138 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1139 "0018 PLOGI: no memory for reg_login "
1140 "Data: x%x x%x x%x x%x\n",
1141 ndlp->nlp_DID, ndlp->nlp_state,
1142 ndlp->nlp_flag, ndlp->nlp_rpi);
1143 goto out;
1144 }
1145
James Smart6fb120a2009-05-22 14:52:59 -04001146 if (lpfc_reg_rpi(phba, vport->vpi, irsp->un.elsreq64.remoteID,
James Smart40426292010-12-15 17:58:10 -05001147 (uint8_t *) sp, mbox, ndlp->nlp_rpi) == 0) {
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05001148 switch (ndlp->nlp_DID) {
dea31012005-04-17 16:05:31 -05001149 case NameServer_DID:
James Smartde0c5b32007-04-25 09:52:27 -04001150 mbox->mbox_cmpl = lpfc_mbx_cmpl_ns_reg_login;
dea31012005-04-17 16:05:31 -05001151 break;
1152 case FDMI_DID:
James Smartde0c5b32007-04-25 09:52:27 -04001153 mbox->mbox_cmpl = lpfc_mbx_cmpl_fdmi_reg_login;
dea31012005-04-17 16:05:31 -05001154 break;
1155 default:
James Smartffc95492010-06-07 15:23:17 -04001156 ndlp->nlp_flag |= NLP_REG_LOGIN_SEND;
James Smartde0c5b32007-04-25 09:52:27 -04001157 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
dea31012005-04-17 16:05:31 -05001158 }
James Smart329f9bc2007-04-25 09:53:01 -04001159 mbox->context2 = lpfc_nlp_get(ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05001160 mbox->vport = vport;
James Smart0b727fe2007-10-27 13:37:25 -04001161 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
dea31012005-04-17 16:05:31 -05001162 != MBX_NOT_FINISHED) {
James Smart2e0fef82007-06-17 19:56:36 -05001163 lpfc_nlp_set_state(vport, ndlp,
1164 NLP_STE_REG_LOGIN_ISSUE);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001165 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001166 }
James Smartffc95492010-06-07 15:23:17 -04001167 if (ndlp->nlp_flag & NLP_REG_LOGIN_SEND)
1168 ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND;
James Smartfa4066b2008-01-11 01:53:27 -05001169 /* decrement node reference count to the failed mbox
1170 * command
1171 */
James Smart329f9bc2007-04-25 09:53:01 -04001172 lpfc_nlp_put(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05001173 mp = (struct lpfc_dmabuf *) mbox->context1;
James Smart14691152006-12-02 13:34:28 -05001174 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1175 kfree(mp);
dea31012005-04-17 16:05:31 -05001176 mempool_free(mbox, phba->mbox_mem_pool);
James Smart92d7f7b2007-06-17 19:56:38 -05001177
James Smarte8b62012007-08-02 11:10:09 -04001178 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1179 "0134 PLOGI: cannot issue reg_login "
1180 "Data: x%x x%x x%x x%x\n",
1181 ndlp->nlp_DID, ndlp->nlp_state,
1182 ndlp->nlp_flag, ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05001183 } else {
1184 mempool_free(mbox, phba->mbox_mem_pool);
James Smart92d7f7b2007-06-17 19:56:38 -05001185
James Smarte8b62012007-08-02 11:10:09 -04001186 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1187 "0135 PLOGI: cannot format reg_login "
1188 "Data: x%x x%x x%x x%x\n",
1189 ndlp->nlp_DID, ndlp->nlp_state,
1190 ndlp->nlp_flag, ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05001191 }
1192
1193
James Smart92d7f7b2007-06-17 19:56:38 -05001194out:
1195 if (ndlp->nlp_DID == NameServer_DID) {
1196 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04001197 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1198 "0261 Cannot Register NameServer login\n");
James Smart92d7f7b2007-06-17 19:56:38 -05001199 }
1200
James Smart8b455cf2013-01-03 15:43:53 -05001201 /*
1202 ** In case the node reference counter does not go to zero, ensure that
1203 ** the stale state for the node is not processed.
1204 */
1205
1206 ndlp->nlp_prev_state = ndlp->nlp_state;
1207 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
James Smart0ff10d42008-01-11 01:52:36 -05001208 spin_lock_irq(shost->host_lock);
James Smarta8adb832007-10-27 13:37:53 -04001209 ndlp->nlp_flag |= NLP_DEFER_RM;
James Smart0ff10d42008-01-11 01:52:36 -05001210 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001211 return NLP_STE_FREED_NODE;
dea31012005-04-17 16:05:31 -05001212}
1213
1214static uint32_t
James Smart0ff10d42008-01-11 01:52:36 -05001215lpfc_cmpl_logo_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1216 void *arg, uint32_t evt)
1217{
1218 return ndlp->nlp_state;
1219}
1220
1221static uint32_t
1222lpfc_cmpl_reglogin_plogi_issue(struct lpfc_vport *vport,
1223 struct lpfc_nodelist *ndlp, void *arg, uint32_t evt)
1224{
James Smart78730cf2010-04-06 15:06:30 -04001225 struct lpfc_hba *phba;
1226 LPFC_MBOXQ_t *pmb = (LPFC_MBOXQ_t *) arg;
1227 MAILBOX_t *mb = &pmb->u.mb;
1228 uint16_t rpi;
1229
1230 phba = vport->phba;
1231 /* Release the RPI */
1232 if (!(phba->pport->load_flag & FC_UNLOADING) &&
1233 !mb->mbxStatus) {
1234 rpi = pmb->u.mb.un.varWords[0];
1235 lpfc_release_rpi(phba, vport, rpi);
1236 }
James Smart0ff10d42008-01-11 01:52:36 -05001237 return ndlp->nlp_state;
1238}
1239
1240static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001241lpfc_device_rm_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1242 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001243{
James Smart2e0fef82007-06-17 19:56:36 -05001244 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001245
James Smart2e0fef82007-06-17 19:56:36 -05001246 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1247 spin_lock_irq(shost->host_lock);
1248 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
1249 spin_unlock_irq(shost->host_lock);
1250 return ndlp->nlp_state;
1251 } else {
1252 /* software abort outstanding PLOGI */
1253 lpfc_els_abort(vport->phba, ndlp);
1254
1255 lpfc_drop_node(vport, ndlp);
James Smarta0f9b482006-04-15 11:52:56 -04001256 return NLP_STE_FREED_NODE;
1257 }
dea31012005-04-17 16:05:31 -05001258}
1259
1260static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001261lpfc_device_recov_plogi_issue(struct lpfc_vport *vport,
1262 struct lpfc_nodelist *ndlp,
1263 void *arg,
1264 uint32_t evt)
dea31012005-04-17 16:05:31 -05001265{
James Smart2e0fef82007-06-17 19:56:36 -05001266 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1267 struct lpfc_hba *phba = vport->phba;
1268
James Smart92d7f7b2007-06-17 19:56:38 -05001269 /* Don't do anything that will mess up processing of the
1270 * previous RSCN.
1271 */
1272 if (vport->fc_flag & FC_RSCN_DEFERRED)
1273 return ndlp->nlp_state;
1274
dea31012005-04-17 16:05:31 -05001275 /* software abort outstanding PLOGI */
James Smart07951072007-04-25 09:51:38 -04001276 lpfc_els_abort(phba, ndlp);
dea31012005-04-17 16:05:31 -05001277
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001278 ndlp->nlp_prev_state = NLP_STE_PLOGI_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -05001279 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
James Smart92d7f7b2007-06-17 19:56:38 -05001280 spin_lock_irq(shost->host_lock);
James Smarta0f9b482006-04-15 11:52:56 -04001281 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
James Smart2e0fef82007-06-17 19:56:36 -05001282 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001283
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001284 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001285}
1286
1287static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001288lpfc_rcv_plogi_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1289 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001290{
James Smart0d2b6b82008-06-14 22:52:47 -04001291 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart2e0fef82007-06-17 19:56:36 -05001292 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001293 struct lpfc_iocbq *cmdiocb;
1294
1295 /* software abort outstanding ADISC */
James Smart07951072007-04-25 09:51:38 -04001296 lpfc_els_abort(phba, ndlp);
dea31012005-04-17 16:05:31 -05001297
1298 cmdiocb = (struct lpfc_iocbq *) arg;
1299
James Smart0d2b6b82008-06-14 22:52:47 -04001300 if (lpfc_rcv_plogi(vport, ndlp, cmdiocb)) {
1301 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1302 spin_lock_irq(shost->host_lock);
1303 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
1304 spin_unlock_irq(shost->host_lock);
James Smart90160e02008-08-24 21:49:45 -04001305 if (vport->num_disc_nodes)
James Smart0d2b6b82008-06-14 22:52:47 -04001306 lpfc_more_adisc(vport);
James Smart0d2b6b82008-06-14 22:52:47 -04001307 }
1308 return ndlp->nlp_state;
1309 }
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001310 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -05001311 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
1312 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
dea31012005-04-17 16:05:31 -05001313
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001314 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001315}
1316
1317static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001318lpfc_rcv_prli_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1319 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001320{
James Smart2e0fef82007-06-17 19:56:36 -05001321 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001322
James Smart2e0fef82007-06-17 19:56:36 -05001323 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001324 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001325}
1326
1327static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001328lpfc_rcv_logo_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1329 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001330{
James Smart2e0fef82007-06-17 19:56:36 -05001331 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001332 struct lpfc_iocbq *cmdiocb;
1333
1334 cmdiocb = (struct lpfc_iocbq *) arg;
1335
1336 /* software abort outstanding ADISC */
James Smart07951072007-04-25 09:51:38 -04001337 lpfc_els_abort(phba, ndlp);
dea31012005-04-17 16:05:31 -05001338
James Smart2e0fef82007-06-17 19:56:36 -05001339 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001340 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001341}
1342
1343static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001344lpfc_rcv_padisc_adisc_issue(struct lpfc_vport *vport,
1345 struct lpfc_nodelist *ndlp,
1346 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001347{
1348 struct lpfc_iocbq *cmdiocb;
1349
1350 cmdiocb = (struct lpfc_iocbq *) arg;
1351
James Smart2e0fef82007-06-17 19:56:36 -05001352 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001353 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001354}
1355
1356static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001357lpfc_rcv_prlo_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1358 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001359{
1360 struct lpfc_iocbq *cmdiocb;
1361
1362 cmdiocb = (struct lpfc_iocbq *) arg;
1363
1364 /* Treat like rcv logo */
James Smart2e0fef82007-06-17 19:56:36 -05001365 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_PRLO);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001366 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001367}
1368
1369static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001370lpfc_cmpl_adisc_adisc_issue(struct lpfc_vport *vport,
1371 struct lpfc_nodelist *ndlp,
1372 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001373{
James Smart2e0fef82007-06-17 19:56:36 -05001374 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1375 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001376 struct lpfc_iocbq *cmdiocb, *rspiocb;
1377 IOCB_t *irsp;
1378 ADISC *ap;
James Smart6fb120a2009-05-22 14:52:59 -04001379 int rc;
dea31012005-04-17 16:05:31 -05001380
1381 cmdiocb = (struct lpfc_iocbq *) arg;
1382 rspiocb = cmdiocb->context_un.rsp_iocb;
1383
1384 ap = (ADISC *)lpfc_check_elscmpl_iocb(phba, cmdiocb, rspiocb);
1385 irsp = &rspiocb->iocb;
1386
1387 if ((irsp->ulpStatus) ||
James Smart92d7f7b2007-06-17 19:56:38 -05001388 (!lpfc_check_adisc(vport, ndlp, &ap->nodeName, &ap->portName))) {
dea31012005-04-17 16:05:31 -05001389 /* 1 sec timeout */
James Smart256ec0d2013-04-17 20:14:58 -04001390 mod_timer(&ndlp->nlp_delayfunc,
1391 jiffies + msecs_to_jiffies(1000));
James Smart2e0fef82007-06-17 19:56:36 -05001392 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001393 ndlp->nlp_flag |= NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05001394 spin_unlock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001395 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
dea31012005-04-17 16:05:31 -05001396
James Smart2e0fef82007-06-17 19:56:36 -05001397 memset(&ndlp->nlp_nodename, 0, sizeof(struct lpfc_name));
1398 memset(&ndlp->nlp_portname, 0, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05001399
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001400 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -05001401 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1402 lpfc_unreg_rpi(vport, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001403 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001404 }
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001405
James Smart6fb120a2009-05-22 14:52:59 -04001406 if (phba->sli_rev == LPFC_SLI_REV4) {
James Smart6b5151f2012-01-18 16:24:06 -05001407 rc = lpfc_sli4_resume_rpi(ndlp, NULL, NULL);
James Smart6fb120a2009-05-22 14:52:59 -04001408 if (rc) {
1409 /* Stay in state and retry. */
1410 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
1411 return ndlp->nlp_state;
1412 }
1413 }
1414
James.Smart@Emulex.Com25013222005-06-25 10:34:33 -04001415 if (ndlp->nlp_type & NLP_FCP_TARGET) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001416 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -05001417 lpfc_nlp_set_state(vport, ndlp, NLP_STE_MAPPED_NODE);
James.Smart@Emulex.Com25013222005-06-25 10:34:33 -04001418 } else {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001419 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -05001420 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
James.Smart@Emulex.Com25013222005-06-25 10:34:33 -04001421 }
James Smart6fb120a2009-05-22 14:52:59 -04001422
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001423 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001424}
1425
1426static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001427lpfc_device_rm_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1428 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001429{
James Smart2e0fef82007-06-17 19:56:36 -05001430 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001431
James Smart2e0fef82007-06-17 19:56:36 -05001432 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1433 spin_lock_irq(shost->host_lock);
1434 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
1435 spin_unlock_irq(shost->host_lock);
1436 return ndlp->nlp_state;
1437 } else {
1438 /* software abort outstanding ADISC */
1439 lpfc_els_abort(vport->phba, ndlp);
1440
1441 lpfc_drop_node(vport, ndlp);
James Smarta0f9b482006-04-15 11:52:56 -04001442 return NLP_STE_FREED_NODE;
1443 }
dea31012005-04-17 16:05:31 -05001444}
1445
1446static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001447lpfc_device_recov_adisc_issue(struct lpfc_vport *vport,
1448 struct lpfc_nodelist *ndlp,
1449 void *arg,
1450 uint32_t evt)
dea31012005-04-17 16:05:31 -05001451{
James Smart2e0fef82007-06-17 19:56:36 -05001452 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1453 struct lpfc_hba *phba = vport->phba;
1454
James Smart92d7f7b2007-06-17 19:56:38 -05001455 /* Don't do anything that will mess up processing of the
1456 * previous RSCN.
1457 */
1458 if (vport->fc_flag & FC_RSCN_DEFERRED)
1459 return ndlp->nlp_state;
1460
dea31012005-04-17 16:05:31 -05001461 /* software abort outstanding ADISC */
James Smart07951072007-04-25 09:51:38 -04001462 lpfc_els_abort(phba, ndlp);
dea31012005-04-17 16:05:31 -05001463
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001464 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -05001465 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1466 spin_lock_irq(shost->host_lock);
James Smarta0f9b482006-04-15 11:52:56 -04001467 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
James Smart2e0fef82007-06-17 19:56:36 -05001468 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05001469 lpfc_disc_set_adisc(vport, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001470 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001471}
1472
1473static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001474lpfc_rcv_plogi_reglogin_issue(struct lpfc_vport *vport,
1475 struct lpfc_nodelist *ndlp,
1476 void *arg,
dea31012005-04-17 16:05:31 -05001477 uint32_t evt)
1478{
James Smart2e0fef82007-06-17 19:56:36 -05001479 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001480
James Smart2e0fef82007-06-17 19:56:36 -05001481 lpfc_rcv_plogi(vport, ndlp, cmdiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001482 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001483}
1484
1485static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001486lpfc_rcv_prli_reglogin_issue(struct lpfc_vport *vport,
1487 struct lpfc_nodelist *ndlp,
1488 void *arg,
dea31012005-04-17 16:05:31 -05001489 uint32_t evt)
1490{
James Smart2e0fef82007-06-17 19:56:36 -05001491 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001492
James Smart2e0fef82007-06-17 19:56:36 -05001493 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001494 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001495}
1496
1497static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001498lpfc_rcv_logo_reglogin_issue(struct lpfc_vport *vport,
1499 struct lpfc_nodelist *ndlp,
1500 void *arg,
dea31012005-04-17 16:05:31 -05001501 uint32_t evt)
1502{
James Smart2e0fef82007-06-17 19:56:36 -05001503 struct lpfc_hba *phba = vport->phba;
1504 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
James Smart7054a602007-04-25 09:52:34 -04001505 LPFC_MBOXQ_t *mb;
1506 LPFC_MBOXQ_t *nextmb;
1507 struct lpfc_dmabuf *mp;
dea31012005-04-17 16:05:31 -05001508
1509 cmdiocb = (struct lpfc_iocbq *) arg;
1510
James Smart7054a602007-04-25 09:52:34 -04001511 /* cleanup any ndlp on mbox q waiting for reglogin cmpl */
1512 if ((mb = phba->sli.mbox_active)) {
James Smart04c68492009-05-22 14:52:52 -04001513 if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) &&
James Smart7054a602007-04-25 09:52:34 -04001514 (ndlp == (struct lpfc_nodelist *) mb->context2)) {
James Smartde96e9c2016-03-31 14:12:27 -07001515 ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND;
James Smart92d7f7b2007-06-17 19:56:38 -05001516 lpfc_nlp_put(ndlp);
James Smart7054a602007-04-25 09:52:34 -04001517 mb->context2 = NULL;
1518 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1519 }
1520 }
1521
James Smart2e0fef82007-06-17 19:56:36 -05001522 spin_lock_irq(&phba->hbalock);
James Smart7054a602007-04-25 09:52:34 -04001523 list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) {
James Smart04c68492009-05-22 14:52:52 -04001524 if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) &&
James Smart7054a602007-04-25 09:52:34 -04001525 (ndlp == (struct lpfc_nodelist *) mb->context2)) {
1526 mp = (struct lpfc_dmabuf *) (mb->context1);
1527 if (mp) {
James Smart98c9ea52007-10-27 13:37:33 -04001528 __lpfc_mbuf_free(phba, mp->virt, mp->phys);
James Smart7054a602007-04-25 09:52:34 -04001529 kfree(mp);
1530 }
James Smartde96e9c2016-03-31 14:12:27 -07001531 ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND;
James Smart92d7f7b2007-06-17 19:56:38 -05001532 lpfc_nlp_put(ndlp);
James Smart7054a602007-04-25 09:52:34 -04001533 list_del(&mb->list);
James Smart5ffc2662009-11-18 15:39:44 -05001534 phba->sli.mboxq_cnt--;
James Smart7054a602007-04-25 09:52:34 -04001535 mempool_free(mb, phba->mbox_mem_pool);
1536 }
1537 }
James Smart2e0fef82007-06-17 19:56:36 -05001538 spin_unlock_irq(&phba->hbalock);
James Smart7054a602007-04-25 09:52:34 -04001539
James Smart2e0fef82007-06-17 19:56:36 -05001540 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001541 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001542}
1543
1544static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001545lpfc_rcv_padisc_reglogin_issue(struct lpfc_vport *vport,
1546 struct lpfc_nodelist *ndlp,
1547 void *arg,
dea31012005-04-17 16:05:31 -05001548 uint32_t evt)
1549{
James Smart2e0fef82007-06-17 19:56:36 -05001550 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001551
James Smart2e0fef82007-06-17 19:56:36 -05001552 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001553 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001554}
1555
1556static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001557lpfc_rcv_prlo_reglogin_issue(struct lpfc_vport *vport,
1558 struct lpfc_nodelist *ndlp,
1559 void *arg,
dea31012005-04-17 16:05:31 -05001560 uint32_t evt)
1561{
1562 struct lpfc_iocbq *cmdiocb;
1563
1564 cmdiocb = (struct lpfc_iocbq *) arg;
James Smart51ef4c22007-08-02 11:10:31 -04001565 lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001566 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001567}
1568
1569static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001570lpfc_cmpl_reglogin_reglogin_issue(struct lpfc_vport *vport,
1571 struct lpfc_nodelist *ndlp,
1572 void *arg,
1573 uint32_t evt)
dea31012005-04-17 16:05:31 -05001574{
James Smart2e0fef82007-06-17 19:56:36 -05001575 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart2e0fef82007-06-17 19:56:36 -05001576 LPFC_MBOXQ_t *pmb = (LPFC_MBOXQ_t *) arg;
James Smart04c68492009-05-22 14:52:52 -04001577 MAILBOX_t *mb = &pmb->u.mb;
James Smart2e0fef82007-06-17 19:56:36 -05001578 uint32_t did = mb->un.varWords[1];
dea31012005-04-17 16:05:31 -05001579
dea31012005-04-17 16:05:31 -05001580 if (mb->mbxStatus) {
1581 /* RegLogin failed */
James Smarte8b62012007-08-02 11:10:09 -04001582 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
James Smart6d368e52011-05-24 11:44:12 -04001583 "0246 RegLogin failed Data: x%x x%x x%x x%x "
1584 "x%x\n",
1585 did, mb->mbxStatus, vport->port_state,
1586 mb->un.varRegLogin.vpi,
1587 mb->un.varRegLogin.rpi);
James Smartd0e56da2006-07-06 15:49:42 -04001588 /*
1589 * If RegLogin failed due to lack of HBA resources do not
1590 * retry discovery.
1591 */
1592 if (mb->mbxStatus == MBXERR_RPI_FULL) {
James Smart87af33f2007-10-27 13:37:43 -04001593 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
1594 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
James Smartd0e56da2006-07-06 15:49:42 -04001595 return ndlp->nlp_state;
1596 }
1597
James Smart2e0fef82007-06-17 19:56:36 -05001598 /* Put ndlp in npr state set plogi timer for 1 sec */
James Smart256ec0d2013-04-17 20:14:58 -04001599 mod_timer(&ndlp->nlp_delayfunc,
1600 jiffies + msecs_to_jiffies(1000 * 1));
James Smart2e0fef82007-06-17 19:56:36 -05001601 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001602 ndlp->nlp_flag |= NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05001603 spin_unlock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001604 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
dea31012005-04-17 16:05:31 -05001605
James Smart2e0fef82007-06-17 19:56:36 -05001606 lpfc_issue_els_logo(vport, ndlp, 0);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001607 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -05001608 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001609 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001610 }
1611
James Smart6d368e52011-05-24 11:44:12 -04001612 /* SLI4 ports have preallocated logical rpis. */
1613 if (vport->phba->sli_rev < LPFC_SLI_REV4)
1614 ndlp->nlp_rpi = mb->un.varWords[0];
1615
James Smart40426292010-12-15 17:58:10 -05001616 ndlp->nlp_flag |= NLP_RPI_REGISTERED;
dea31012005-04-17 16:05:31 -05001617
1618 /* Only if we are not a fabric nport do we issue PRLI */
1619 if (!(ndlp->nlp_type & NLP_FABRIC)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001620 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -05001621 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
1622 lpfc_issue_els_prli(vport, ndlp, 0);
dea31012005-04-17 16:05:31 -05001623 } else {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001624 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -05001625 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
dea31012005-04-17 16:05:31 -05001626 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001627 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001628}
1629
1630static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001631lpfc_device_rm_reglogin_issue(struct lpfc_vport *vport,
1632 struct lpfc_nodelist *ndlp,
1633 void *arg,
dea31012005-04-17 16:05:31 -05001634 uint32_t evt)
1635{
James Smart2e0fef82007-06-17 19:56:36 -05001636 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1637
1638 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1639 spin_lock_irq(shost->host_lock);
James Smarta0f9b482006-04-15 11:52:56 -04001640 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
James Smart2e0fef82007-06-17 19:56:36 -05001641 spin_unlock_irq(shost->host_lock);
James Smarta0f9b482006-04-15 11:52:56 -04001642 return ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05001643 } else {
1644 lpfc_drop_node(vport, ndlp);
James Smarta0f9b482006-04-15 11:52:56 -04001645 return NLP_STE_FREED_NODE;
1646 }
dea31012005-04-17 16:05:31 -05001647}
1648
1649static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001650lpfc_device_recov_reglogin_issue(struct lpfc_vport *vport,
1651 struct lpfc_nodelist *ndlp,
1652 void *arg,
1653 uint32_t evt)
dea31012005-04-17 16:05:31 -05001654{
James Smart2e0fef82007-06-17 19:56:36 -05001655 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1656
James Smart92d7f7b2007-06-17 19:56:38 -05001657 /* Don't do anything that will mess up processing of the
1658 * previous RSCN.
1659 */
1660 if (vport->fc_flag & FC_RSCN_DEFERRED)
1661 return ndlp->nlp_state;
1662
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001663 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -05001664 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1665 spin_lock_irq(shost->host_lock);
James Smartffc95492010-06-07 15:23:17 -04001666 ndlp->nlp_flag |= NLP_IGNR_REG_CMPL;
James Smarta0f9b482006-04-15 11:52:56 -04001667 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
James Smart2e0fef82007-06-17 19:56:36 -05001668 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05001669 lpfc_disc_set_adisc(vport, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001670 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001671}
1672
1673static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001674lpfc_rcv_plogi_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1675 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001676{
1677 struct lpfc_iocbq *cmdiocb;
1678
1679 cmdiocb = (struct lpfc_iocbq *) arg;
1680
James Smart2e0fef82007-06-17 19:56:36 -05001681 lpfc_rcv_plogi(vport, ndlp, cmdiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001682 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001683}
1684
1685static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001686lpfc_rcv_prli_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1687 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001688{
James Smart2e0fef82007-06-17 19:56:36 -05001689 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001690
James Smart2e0fef82007-06-17 19:56:36 -05001691 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001692 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001693}
1694
1695static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001696lpfc_rcv_logo_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1697 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001698{
James Smart2e0fef82007-06-17 19:56:36 -05001699 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001700
1701 /* Software abort outstanding PRLI before sending acc */
James Smart2e0fef82007-06-17 19:56:36 -05001702 lpfc_els_abort(vport->phba, ndlp);
dea31012005-04-17 16:05:31 -05001703
James Smart2e0fef82007-06-17 19:56:36 -05001704 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001705 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001706}
1707
1708static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001709lpfc_rcv_padisc_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1710 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001711{
James Smart2e0fef82007-06-17 19:56:36 -05001712 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001713
James Smart2e0fef82007-06-17 19:56:36 -05001714 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001715 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001716}
1717
1718/* This routine is envoked when we rcv a PRLO request from a nport
1719 * we are logged into. We should send back a PRLO rsp setting the
1720 * appropriate bits.
1721 * NEXT STATE = PRLI_ISSUE
1722 */
1723static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001724lpfc_rcv_prlo_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1725 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001726{
James Smart2e0fef82007-06-17 19:56:36 -05001727 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001728
James Smart51ef4c22007-08-02 11:10:31 -04001729 lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001730 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001731}
1732
1733static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001734lpfc_cmpl_prli_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1735 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001736{
James Smart92d7f7b2007-06-17 19:56:38 -05001737 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001738 struct lpfc_iocbq *cmdiocb, *rspiocb;
James Smart2e0fef82007-06-17 19:56:36 -05001739 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001740 IOCB_t *irsp;
1741 PRLI *npr;
1742
1743 cmdiocb = (struct lpfc_iocbq *) arg;
1744 rspiocb = cmdiocb->context_un.rsp_iocb;
1745 npr = (PRLI *)lpfc_check_elscmpl_iocb(phba, cmdiocb, rspiocb);
1746
1747 irsp = &rspiocb->iocb;
1748 if (irsp->ulpStatus) {
James Smart858c9f62007-06-17 19:56:39 -05001749 if ((vport->port_type == LPFC_NPIV_PORT) &&
James Smart3de2a652007-08-02 11:09:59 -04001750 vport->cfg_restrict_login) {
James Smart858c9f62007-06-17 19:56:39 -05001751 goto out;
1752 }
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001753 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -05001754 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001755 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001756 }
1757
1758 /* Check out PRLI rsp */
1759 ndlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR);
1760 ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
James Smart3cb01c52013-07-15 18:35:04 -04001761 ndlp->nlp_flag &= ~NLP_FIRSTBURST;
dea31012005-04-17 16:05:31 -05001762 if ((npr->acceptRspCode == PRLI_REQ_EXECUTED) &&
1763 (npr->prliType == PRLI_FCP_TYPE)) {
1764 if (npr->initiatorFunc)
1765 ndlp->nlp_type |= NLP_FCP_INITIATOR;
James Smart3cb01c52013-07-15 18:35:04 -04001766 if (npr->targetFunc) {
dea31012005-04-17 16:05:31 -05001767 ndlp->nlp_type |= NLP_FCP_TARGET;
James Smart3cb01c52013-07-15 18:35:04 -04001768 if (npr->writeXferRdyDis)
1769 ndlp->nlp_flag |= NLP_FIRSTBURST;
1770 }
dea31012005-04-17 16:05:31 -05001771 if (npr->Retry)
1772 ndlp->nlp_fcp_info |= NLP_FCP_2_DEVICE;
1773 }
James Smart92d7f7b2007-06-17 19:56:38 -05001774 if (!(ndlp->nlp_type & NLP_FCP_TARGET) &&
1775 (vport->port_type == LPFC_NPIV_PORT) &&
James Smart3de2a652007-08-02 11:09:59 -04001776 vport->cfg_restrict_login) {
James Smart858c9f62007-06-17 19:56:39 -05001777out:
James Smart92d7f7b2007-06-17 19:56:38 -05001778 spin_lock_irq(shost->host_lock);
1779 ndlp->nlp_flag |= NLP_TARGET_REMOVE;
1780 spin_unlock_irq(shost->host_lock);
1781 lpfc_issue_els_logo(vport, ndlp, 0);
1782
1783 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
James Smart87af33f2007-10-27 13:37:43 -04001784 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
James Smart92d7f7b2007-06-17 19:56:38 -05001785 return ndlp->nlp_state;
1786 }
dea31012005-04-17 16:05:31 -05001787
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001788 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
James Smart92d7f7b2007-06-17 19:56:38 -05001789 if (ndlp->nlp_type & NLP_FCP_TARGET)
1790 lpfc_nlp_set_state(vport, ndlp, NLP_STE_MAPPED_NODE);
1791 else
1792 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001793 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001794}
1795
1796/*! lpfc_device_rm_prli_issue
James Smart92d7f7b2007-06-17 19:56:38 -05001797 *
1798 * \pre
1799 * \post
1800 * \param phba
1801 * \param ndlp
1802 * \param arg
1803 * \param evt
1804 * \return uint32_t
1805 *
1806 * \b Description:
1807 * This routine is envoked when we a request to remove a nport we are in the
1808 * process of PRLIing. We should software abort outstanding prli, unreg
1809 * login, send a logout. We will change node state to UNUSED_NODE, put it
1810 * on plogi list so it can be freed when LOGO completes.
1811 *
1812 */
1813
dea31012005-04-17 16:05:31 -05001814static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001815lpfc_device_rm_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1816 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001817{
James Smart2e0fef82007-06-17 19:56:36 -05001818 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001819
James Smart2e0fef82007-06-17 19:56:36 -05001820 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1821 spin_lock_irq(shost->host_lock);
1822 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
1823 spin_unlock_irq(shost->host_lock);
1824 return ndlp->nlp_state;
1825 } else {
1826 /* software abort outstanding PLOGI */
1827 lpfc_els_abort(vport->phba, ndlp);
1828
1829 lpfc_drop_node(vport, ndlp);
James Smarta0f9b482006-04-15 11:52:56 -04001830 return NLP_STE_FREED_NODE;
1831 }
dea31012005-04-17 16:05:31 -05001832}
1833
1834
1835/*! lpfc_device_recov_prli_issue
James Smart92d7f7b2007-06-17 19:56:38 -05001836 *
1837 * \pre
1838 * \post
1839 * \param phba
1840 * \param ndlp
1841 * \param arg
1842 * \param evt
1843 * \return uint32_t
1844 *
1845 * \b Description:
1846 * The routine is envoked when the state of a device is unknown, like
1847 * during a link down. We should remove the nodelist entry from the
1848 * unmapped list, issue a UNREG_LOGIN, do a software abort of the
1849 * outstanding PRLI command, then free the node entry.
1850 */
dea31012005-04-17 16:05:31 -05001851static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001852lpfc_device_recov_prli_issue(struct lpfc_vport *vport,
1853 struct lpfc_nodelist *ndlp,
1854 void *arg,
1855 uint32_t evt)
dea31012005-04-17 16:05:31 -05001856{
James Smart2e0fef82007-06-17 19:56:36 -05001857 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1858 struct lpfc_hba *phba = vport->phba;
1859
James Smart92d7f7b2007-06-17 19:56:38 -05001860 /* Don't do anything that will mess up processing of the
1861 * previous RSCN.
1862 */
1863 if (vport->fc_flag & FC_RSCN_DEFERRED)
1864 return ndlp->nlp_state;
1865
dea31012005-04-17 16:05:31 -05001866 /* software abort outstanding PRLI */
James Smart07951072007-04-25 09:51:38 -04001867 lpfc_els_abort(phba, ndlp);
dea31012005-04-17 16:05:31 -05001868
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001869 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -05001870 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1871 spin_lock_irq(shost->host_lock);
James Smarta0f9b482006-04-15 11:52:56 -04001872 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
James Smart2e0fef82007-06-17 19:56:36 -05001873 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05001874 lpfc_disc_set_adisc(vport, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001875 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001876}
1877
1878static uint32_t
James Smart086a3452012-08-14 14:25:21 -04001879lpfc_rcv_plogi_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1880 void *arg, uint32_t evt)
1881{
1882 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *)arg;
1883 struct ls_rjt stat;
1884
1885 memset(&stat, 0, sizeof(struct ls_rjt));
1886 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
1887 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
1888 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
1889 return ndlp->nlp_state;
1890}
1891
1892static uint32_t
1893lpfc_rcv_prli_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1894 void *arg, uint32_t evt)
1895{
1896 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *)arg;
1897 struct ls_rjt stat;
1898
1899 memset(&stat, 0, sizeof(struct ls_rjt));
1900 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
1901 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
1902 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
1903 return ndlp->nlp_state;
1904}
1905
1906static uint32_t
1907lpfc_rcv_logo_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1908 void *arg, uint32_t evt)
1909{
1910 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1911 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *)arg;
1912
1913 spin_lock_irq(shost->host_lock);
James Smart7c5e5182015-05-22 10:42:43 -04001914 ndlp->nlp_flag |= NLP_LOGO_ACC;
James Smart086a3452012-08-14 14:25:21 -04001915 spin_unlock_irq(shost->host_lock);
1916 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
1917 return ndlp->nlp_state;
1918}
1919
1920static uint32_t
1921lpfc_rcv_padisc_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1922 void *arg, uint32_t evt)
1923{
1924 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *)arg;
1925 struct ls_rjt stat;
1926
1927 memset(&stat, 0, sizeof(struct ls_rjt));
1928 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
1929 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
1930 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
1931 return ndlp->nlp_state;
1932}
1933
1934static uint32_t
1935lpfc_rcv_prlo_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1936 void *arg, uint32_t evt)
1937{
1938 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *)arg;
1939 struct ls_rjt stat;
1940
1941 memset(&stat, 0, sizeof(struct ls_rjt));
1942 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
1943 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
1944 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
1945 return ndlp->nlp_state;
1946}
1947
1948static uint32_t
1949lpfc_cmpl_logo_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1950 void *arg, uint32_t evt)
1951{
1952 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1953
1954 ndlp->nlp_prev_state = NLP_STE_LOGO_ISSUE;
1955 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1956 spin_lock_irq(shost->host_lock);
1957 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
1958 spin_unlock_irq(shost->host_lock);
1959 lpfc_disc_set_adisc(vport, ndlp);
1960 return ndlp->nlp_state;
1961}
1962
1963static uint32_t
1964lpfc_device_rm_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1965 void *arg, uint32_t evt)
1966{
1967 /*
1968 * Take no action. If a LOGO is outstanding, then possibly DevLoss has
1969 * timed out and is calling for Device Remove. In this case, the LOGO
1970 * must be allowed to complete in state LOGO_ISSUE so that the rpi
1971 * and other NLP flags are correctly cleaned up.
1972 */
1973 return ndlp->nlp_state;
1974}
1975
1976static uint32_t
1977lpfc_device_recov_logo_issue(struct lpfc_vport *vport,
1978 struct lpfc_nodelist *ndlp,
1979 void *arg, uint32_t evt)
1980{
1981 /*
1982 * Device Recovery events have no meaning for a node with a LOGO
1983 * outstanding. The LOGO has to complete first and handle the
1984 * node from that point.
1985 */
1986 return ndlp->nlp_state;
1987}
1988
1989static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001990lpfc_rcv_plogi_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1991 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001992{
James Smart2e0fef82007-06-17 19:56:36 -05001993 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001994
James Smart2e0fef82007-06-17 19:56:36 -05001995 lpfc_rcv_plogi(vport, ndlp, cmdiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001996 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001997}
1998
1999static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05002000lpfc_rcv_prli_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2001 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05002002{
James Smart2e0fef82007-06-17 19:56:36 -05002003 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05002004
James Smart2e0fef82007-06-17 19:56:36 -05002005 lpfc_rcv_prli(vport, ndlp, cmdiocb);
2006 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002007 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05002008}
2009
2010static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05002011lpfc_rcv_logo_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2012 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05002013{
James Smart2e0fef82007-06-17 19:56:36 -05002014 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05002015
James Smart2e0fef82007-06-17 19:56:36 -05002016 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002017 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05002018}
2019
2020static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05002021lpfc_rcv_padisc_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2022 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05002023{
James Smart2e0fef82007-06-17 19:56:36 -05002024 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05002025
James Smart2e0fef82007-06-17 19:56:36 -05002026 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002027 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05002028}
2029
2030static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05002031lpfc_rcv_prlo_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2032 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05002033{
James Smart2e0fef82007-06-17 19:56:36 -05002034 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05002035
James Smart51ef4c22007-08-02 11:10:31 -04002036 lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002037 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05002038}
2039
2040static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05002041lpfc_device_recov_unmap_node(struct lpfc_vport *vport,
2042 struct lpfc_nodelist *ndlp,
2043 void *arg,
2044 uint32_t evt)
dea31012005-04-17 16:05:31 -05002045{
James Smart2e0fef82007-06-17 19:56:36 -05002046 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2047
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002048 ndlp->nlp_prev_state = NLP_STE_UNMAPPED_NODE;
James Smart2e0fef82007-06-17 19:56:36 -05002049 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
2050 spin_lock_irq(shost->host_lock);
James Smarta0f9b482006-04-15 11:52:56 -04002051 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
James Smart2e0fef82007-06-17 19:56:36 -05002052 spin_unlock_irq(shost->host_lock);
2053 lpfc_disc_set_adisc(vport, ndlp);
dea31012005-04-17 16:05:31 -05002054
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002055 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05002056}
2057
2058static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05002059lpfc_rcv_plogi_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2060 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05002061{
James Smart2e0fef82007-06-17 19:56:36 -05002062 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05002063
James Smart2e0fef82007-06-17 19:56:36 -05002064 lpfc_rcv_plogi(vport, ndlp, cmdiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002065 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05002066}
2067
2068static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05002069lpfc_rcv_prli_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2070 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05002071{
James Smart2e0fef82007-06-17 19:56:36 -05002072 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05002073
James Smart2e0fef82007-06-17 19:56:36 -05002074 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002075 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05002076}
2077
2078static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05002079lpfc_rcv_logo_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2080 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05002081{
James Smart2e0fef82007-06-17 19:56:36 -05002082 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05002083
James Smart2e0fef82007-06-17 19:56:36 -05002084 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002085 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05002086}
2087
2088static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05002089lpfc_rcv_padisc_mapped_node(struct lpfc_vport *vport,
2090 struct lpfc_nodelist *ndlp,
2091 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05002092{
James Smart2e0fef82007-06-17 19:56:36 -05002093 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05002094
James Smart2e0fef82007-06-17 19:56:36 -05002095 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002096 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05002097}
2098
2099static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05002100lpfc_rcv_prlo_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2101 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05002102{
James Smart2e0fef82007-06-17 19:56:36 -05002103 struct lpfc_hba *phba = vport->phba;
2104 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05002105
2106 /* flush the target */
James Smart51ef4c22007-08-02 11:10:31 -04002107 lpfc_sli_abort_iocb(vport, &phba->sli.ring[phba->sli.fcp_ring],
2108 ndlp->nlp_sid, 0, LPFC_CTX_TGT);
dea31012005-04-17 16:05:31 -05002109
2110 /* Treat like rcv logo */
James Smart2e0fef82007-06-17 19:56:36 -05002111 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_PRLO);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002112 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05002113}
2114
2115static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05002116lpfc_device_recov_mapped_node(struct lpfc_vport *vport,
2117 struct lpfc_nodelist *ndlp,
2118 void *arg,
2119 uint32_t evt)
dea31012005-04-17 16:05:31 -05002120{
James Smart2e0fef82007-06-17 19:56:36 -05002121 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2122
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002123 ndlp->nlp_prev_state = NLP_STE_MAPPED_NODE;
James Smart2e0fef82007-06-17 19:56:36 -05002124 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
2125 spin_lock_irq(shost->host_lock);
James Smarta0f9b482006-04-15 11:52:56 -04002126 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
James Smart2e0fef82007-06-17 19:56:36 -05002127 spin_unlock_irq(shost->host_lock);
2128 lpfc_disc_set_adisc(vport, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002129 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05002130}
2131
2132static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05002133lpfc_rcv_plogi_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2134 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05002135{
James Smart2e0fef82007-06-17 19:56:36 -05002136 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2137 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05002138
2139 /* Ignore PLOGI if we have an outstanding LOGO */
James Smart0d2b6b82008-06-14 22:52:47 -04002140 if (ndlp->nlp_flag & (NLP_LOGO_SND | NLP_LOGO_ACC))
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002141 return ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002142 if (lpfc_rcv_plogi(vport, ndlp, cmdiocb)) {
James Smart0d2b6b82008-06-14 22:52:47 -04002143 lpfc_cancel_retry_delay_tmo(vport, ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05002144 spin_lock_irq(shost->host_lock);
James Smart0d2b6b82008-06-14 22:52:47 -04002145 ndlp->nlp_flag &= ~(NLP_NPR_ADISC | NLP_NPR_2B_DISC);
James Smart2e0fef82007-06-17 19:56:36 -05002146 spin_unlock_irq(shost->host_lock);
James Smart0d2b6b82008-06-14 22:52:47 -04002147 } else if (!(ndlp->nlp_flag & NLP_NPR_2B_DISC)) {
2148 /* send PLOGI immediately, move to PLOGI issue state */
2149 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
2150 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
2151 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
2152 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
2153 }
dea31012005-04-17 16:05:31 -05002154 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002155 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05002156}
2157
2158static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05002159lpfc_rcv_prli_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2160 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05002161{
James Smart2e0fef82007-06-17 19:56:36 -05002162 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2163 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2164 struct ls_rjt stat;
dea31012005-04-17 16:05:31 -05002165
2166 memset(&stat, 0, sizeof (struct ls_rjt));
2167 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
2168 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
James Smart858c9f62007-06-17 19:56:39 -05002169 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05002170
2171 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
2172 if (ndlp->nlp_flag & NLP_NPR_ADISC) {
James Smart2e0fef82007-06-17 19:56:36 -05002173 spin_lock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002174 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002175 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
James Smart2e0fef82007-06-17 19:56:36 -05002176 spin_unlock_irq(shost->host_lock);
2177 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
2178 lpfc_issue_els_adisc(vport, ndlp, 0);
dea31012005-04-17 16:05:31 -05002179 } else {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002180 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
James Smart2e0fef82007-06-17 19:56:36 -05002181 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
2182 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
dea31012005-04-17 16:05:31 -05002183 }
2184 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002185 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05002186}
2187
2188static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05002189lpfc_rcv_logo_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2190 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05002191{
James Smart2e0fef82007-06-17 19:56:36 -05002192 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05002193
James Smart2e0fef82007-06-17 19:56:36 -05002194 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002195 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05002196}
2197
2198static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05002199lpfc_rcv_padisc_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2200 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05002201{
James Smart2e0fef82007-06-17 19:56:36 -05002202 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05002203
James Smart2e0fef82007-06-17 19:56:36 -05002204 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
James Smart33ccf8d2006-08-17 11:57:58 -04002205 /*
2206 * Do not start discovery if discovery is about to start
2207 * or discovery in progress for this node. Starting discovery
2208 * here will affect the counting of discovery threads.
2209 */
James Smart2fb9bd82006-12-02 13:33:57 -05002210 if (!(ndlp->nlp_flag & NLP_DELAY_TMO) &&
James Smart92d7f7b2007-06-17 19:56:38 -05002211 !(ndlp->nlp_flag & NLP_NPR_2B_DISC)) {
dea31012005-04-17 16:05:31 -05002212 if (ndlp->nlp_flag & NLP_NPR_ADISC) {
James Smart92d7f7b2007-06-17 19:56:38 -05002213 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002214 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
James Smart2e0fef82007-06-17 19:56:36 -05002215 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
2216 lpfc_issue_els_adisc(vport, ndlp, 0);
dea31012005-04-17 16:05:31 -05002217 } else {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002218 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
James Smart2e0fef82007-06-17 19:56:36 -05002219 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
2220 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
dea31012005-04-17 16:05:31 -05002221 }
2222 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002223 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05002224}
2225
2226static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05002227lpfc_rcv_prlo_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2228 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05002229{
James Smart2e0fef82007-06-17 19:56:36 -05002230 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2231 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05002232
James Smart2e0fef82007-06-17 19:56:36 -05002233 spin_lock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002234 ndlp->nlp_flag |= NLP_LOGO_ACC;
James Smart2e0fef82007-06-17 19:56:36 -05002235 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002236
James Smart51ef4c22007-08-02 11:10:31 -04002237 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05002238
James Smart2e0fef82007-06-17 19:56:36 -05002239 if ((ndlp->nlp_flag & NLP_DELAY_TMO) == 0) {
James Smart256ec0d2013-04-17 20:14:58 -04002240 mod_timer(&ndlp->nlp_delayfunc,
2241 jiffies + msecs_to_jiffies(1000 * 1));
James Smart2e0fef82007-06-17 19:56:36 -05002242 spin_lock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002243 ndlp->nlp_flag |= NLP_DELAY_TMO;
2244 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
James Smart2e0fef82007-06-17 19:56:36 -05002245 spin_unlock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002246 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002247 } else {
James Smart2e0fef82007-06-17 19:56:36 -05002248 spin_lock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002249 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
James Smart2e0fef82007-06-17 19:56:36 -05002250 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002251 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002252 return ndlp->nlp_state;
2253}
dea31012005-04-17 16:05:31 -05002254
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002255static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05002256lpfc_cmpl_plogi_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2257 void *arg, uint32_t evt)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002258{
2259 struct lpfc_iocbq *cmdiocb, *rspiocb;
James Smarta0f9b482006-04-15 11:52:56 -04002260 IOCB_t *irsp;
James Smart8b455cf2013-01-03 15:43:53 -05002261 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002262
2263 cmdiocb = (struct lpfc_iocbq *) arg;
2264 rspiocb = cmdiocb->context_un.rsp_iocb;
James Smarta0f9b482006-04-15 11:52:56 -04002265
2266 irsp = &rspiocb->iocb;
2267 if (irsp->ulpStatus) {
James Smart8b455cf2013-01-03 15:43:53 -05002268 spin_lock_irq(shost->host_lock);
James Smarta8adb832007-10-27 13:37:53 -04002269 ndlp->nlp_flag |= NLP_DEFER_RM;
James Smart8b455cf2013-01-03 15:43:53 -05002270 spin_unlock_irq(shost->host_lock);
James Smarta0f9b482006-04-15 11:52:56 -04002271 return NLP_STE_FREED_NODE;
2272 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002273 return ndlp->nlp_state;
2274}
2275
2276static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05002277lpfc_cmpl_prli_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2278 void *arg, uint32_t evt)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002279{
2280 struct lpfc_iocbq *cmdiocb, *rspiocb;
James Smarta0f9b482006-04-15 11:52:56 -04002281 IOCB_t *irsp;
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002282
2283 cmdiocb = (struct lpfc_iocbq *) arg;
2284 rspiocb = cmdiocb->context_un.rsp_iocb;
James Smarta0f9b482006-04-15 11:52:56 -04002285
2286 irsp = &rspiocb->iocb;
2287 if (irsp->ulpStatus && (ndlp->nlp_flag & NLP_NODEV_REMOVE)) {
James Smart2e0fef82007-06-17 19:56:36 -05002288 lpfc_drop_node(vport, ndlp);
James Smarta0f9b482006-04-15 11:52:56 -04002289 return NLP_STE_FREED_NODE;
2290 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002291 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05002292}
2293
2294static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05002295lpfc_cmpl_logo_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2296 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05002297{
James Smartd7c255b2008-08-24 21:50:00 -04002298 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart086a3452012-08-14 14:25:21 -04002299
2300 /* For the fabric port just clear the fc flags. */
James Smartd7c255b2008-08-24 21:50:00 -04002301 if (ndlp->nlp_DID == Fabric_DID) {
2302 spin_lock_irq(shost->host_lock);
2303 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
2304 spin_unlock_irq(shost->host_lock);
2305 }
James Smart2e0fef82007-06-17 19:56:36 -05002306 lpfc_unreg_rpi(vport, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002307 return ndlp->nlp_state;
2308}
2309
2310static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05002311lpfc_cmpl_adisc_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2312 void *arg, uint32_t evt)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002313{
2314 struct lpfc_iocbq *cmdiocb, *rspiocb;
James Smarta0f9b482006-04-15 11:52:56 -04002315 IOCB_t *irsp;
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002316
2317 cmdiocb = (struct lpfc_iocbq *) arg;
2318 rspiocb = cmdiocb->context_un.rsp_iocb;
James Smarta0f9b482006-04-15 11:52:56 -04002319
2320 irsp = &rspiocb->iocb;
2321 if (irsp->ulpStatus && (ndlp->nlp_flag & NLP_NODEV_REMOVE)) {
James Smart2e0fef82007-06-17 19:56:36 -05002322 lpfc_drop_node(vport, ndlp);
James Smarta0f9b482006-04-15 11:52:56 -04002323 return NLP_STE_FREED_NODE;
2324 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002325 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05002326}
2327
2328static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05002329lpfc_cmpl_reglogin_npr_node(struct lpfc_vport *vport,
2330 struct lpfc_nodelist *ndlp,
2331 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05002332{
James Smart2e0fef82007-06-17 19:56:36 -05002333 LPFC_MBOXQ_t *pmb = (LPFC_MBOXQ_t *) arg;
James Smart04c68492009-05-22 14:52:52 -04002334 MAILBOX_t *mb = &pmb->u.mb;
dea31012005-04-17 16:05:31 -05002335
James Smart04c68492009-05-22 14:52:52 -04002336 if (!mb->mbxStatus) {
James Smart6d368e52011-05-24 11:44:12 -04002337 /* SLI4 ports have preallocated logical rpis. */
2338 if (vport->phba->sli_rev < LPFC_SLI_REV4)
2339 ndlp->nlp_rpi = mb->un.varWords[0];
James Smart40426292010-12-15 17:58:10 -05002340 ndlp->nlp_flag |= NLP_RPI_REGISTERED;
James Smart4b7789b2015-12-16 18:11:55 -05002341 if (ndlp->nlp_flag & NLP_LOGO_ACC) {
2342 lpfc_unreg_rpi(vport, ndlp);
2343 }
James Smart04c68492009-05-22 14:52:52 -04002344 } else {
James Smarta0f9b482006-04-15 11:52:56 -04002345 if (ndlp->nlp_flag & NLP_NODEV_REMOVE) {
James Smart2e0fef82007-06-17 19:56:36 -05002346 lpfc_drop_node(vport, ndlp);
James Smarta0f9b482006-04-15 11:52:56 -04002347 return NLP_STE_FREED_NODE;
2348 }
2349 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002350 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05002351}
2352
2353static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05002354lpfc_device_rm_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2355 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05002356{
James Smart2e0fef82007-06-17 19:56:36 -05002357 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2358
James Smarta0f9b482006-04-15 11:52:56 -04002359 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
James Smart2e0fef82007-06-17 19:56:36 -05002360 spin_lock_irq(shost->host_lock);
James Smarta0f9b482006-04-15 11:52:56 -04002361 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
James Smart2e0fef82007-06-17 19:56:36 -05002362 spin_unlock_irq(shost->host_lock);
James Smarta0f9b482006-04-15 11:52:56 -04002363 return ndlp->nlp_state;
2364 }
James Smart2e0fef82007-06-17 19:56:36 -05002365 lpfc_drop_node(vport, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002366 return NLP_STE_FREED_NODE;
dea31012005-04-17 16:05:31 -05002367}
2368
2369static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05002370lpfc_device_recov_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2371 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05002372{
James Smart2e0fef82007-06-17 19:56:36 -05002373 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2374
James Smart92d7f7b2007-06-17 19:56:38 -05002375 /* Don't do anything that will mess up processing of the
2376 * previous RSCN.
2377 */
2378 if (vport->fc_flag & FC_RSCN_DEFERRED)
2379 return ndlp->nlp_state;
2380
James Smarteaf15d52008-12-04 22:39:29 -05002381 lpfc_cancel_retry_delay_tmo(vport, ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05002382 spin_lock_irq(shost->host_lock);
James Smarta0f9b482006-04-15 11:52:56 -04002383 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
James Smart2e0fef82007-06-17 19:56:36 -05002384 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002385 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05002386}
2387
2388
2389/* This next section defines the NPort Discovery State Machine */
2390
2391/* There are 4 different double linked lists nodelist entries can reside on.
2392 * The plogi list and adisc list are used when Link Up discovery or RSCN
2393 * processing is needed. Each list holds the nodes that we will send PLOGI
2394 * or ADISC on. These lists will keep track of what nodes will be effected
2395 * by an RSCN, or a Link Up (Typically, all nodes are effected on Link Up).
2396 * The unmapped_list will contain all nodes that we have successfully logged
2397 * into at the Fibre Channel level. The mapped_list will contain all nodes
2398 * that are mapped FCP targets.
2399 */
2400/*
2401 * The bind list is a list of undiscovered (potentially non-existent) nodes
2402 * that we have saved binding information on. This information is used when
2403 * nodes transition from the unmapped to the mapped list.
2404 */
2405/* For UNUSED_NODE state, the node has just been allocated .
2406 * For PLOGI_ISSUE and REG_LOGIN_ISSUE, the node is on
2407 * the PLOGI list. For REG_LOGIN_COMPL, the node is taken off the PLOGI list
2408 * and put on the unmapped list. For ADISC processing, the node is taken off
2409 * the ADISC list and placed on either the mapped or unmapped list (depending
2410 * on its previous state). Once on the unmapped list, a PRLI is issued and the
2411 * state changed to PRLI_ISSUE. When the PRLI completion occurs, the state is
2412 * changed to UNMAPPED_NODE. If the completion indicates a mapped
2413 * node, the node is taken off the unmapped list. The binding list is checked
2414 * for a valid binding, or a binding is automatically assigned. If binding
2415 * assignment is unsuccessful, the node is left on the unmapped list. If
2416 * binding assignment is successful, the associated binding list entry (if
2417 * any) is removed, and the node is placed on the mapped list.
2418 */
2419/*
2420 * For a Link Down, all nodes on the ADISC, PLOGI, unmapped or mapped
James Smartc01f3202006-08-18 17:47:08 -04002421 * lists will receive a DEVICE_RECOVERY event. If the linkdown or devloss timers
dea31012005-04-17 16:05:31 -05002422 * expire, all effected nodes will receive a DEVICE_RM event.
2423 */
2424/*
2425 * For a Link Up or RSCN, all nodes will move from the mapped / unmapped lists
2426 * to either the ADISC or PLOGI list. After a Nameserver query or ALPA loopmap
2427 * check, additional nodes may be added or removed (via DEVICE_RM) to / from
2428 * the PLOGI or ADISC lists. Once the PLOGI and ADISC lists are populated,
2429 * we will first process the ADISC list. 32 entries are processed initially and
2430 * ADISC is initited for each one. Completions / Events for each node are
2431 * funnelled thru the state machine. As each node finishes ADISC processing, it
2432 * starts ADISC for any nodes waiting for ADISC processing. If no nodes are
2433 * waiting, and the ADISC list count is identically 0, then we are done. For
2434 * Link Up discovery, since all nodes on the PLOGI list are UNREG_LOGIN'ed, we
2435 * can issue a CLEAR_LA and reenable Link Events. Next we will process the PLOGI
2436 * list. 32 entries are processed initially and PLOGI is initited for each one.
2437 * Completions / Events for each node are funnelled thru the state machine. As
2438 * each node finishes PLOGI processing, it starts PLOGI for any nodes waiting
2439 * for PLOGI processing. If no nodes are waiting, and the PLOGI list count is
2440 * indentically 0, then we are done. We have now completed discovery / RSCN
2441 * handling. Upon completion, ALL nodes should be on either the mapped or
2442 * unmapped lists.
2443 */
2444
2445static uint32_t (*lpfc_disc_action[NLP_STE_MAX_STATE * NLP_EVT_MAX_EVENT])
James Smart2e0fef82007-06-17 19:56:36 -05002446 (struct lpfc_vport *, struct lpfc_nodelist *, void *, uint32_t) = {
dea31012005-04-17 16:05:31 -05002447 /* Action routine Event Current State */
2448 lpfc_rcv_plogi_unused_node, /* RCV_PLOGI UNUSED_NODE */
2449 lpfc_rcv_els_unused_node, /* RCV_PRLI */
2450 lpfc_rcv_logo_unused_node, /* RCV_LOGO */
2451 lpfc_rcv_els_unused_node, /* RCV_ADISC */
2452 lpfc_rcv_els_unused_node, /* RCV_PDISC */
2453 lpfc_rcv_els_unused_node, /* RCV_PRLO */
2454 lpfc_disc_illegal, /* CMPL_PLOGI */
2455 lpfc_disc_illegal, /* CMPL_PRLI */
2456 lpfc_cmpl_logo_unused_node, /* CMPL_LOGO */
2457 lpfc_disc_illegal, /* CMPL_ADISC */
2458 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2459 lpfc_device_rm_unused_node, /* DEVICE_RM */
James Smartdf9e1b52011-12-13 13:22:17 -05002460 lpfc_device_recov_unused_node, /* DEVICE_RECOVERY */
dea31012005-04-17 16:05:31 -05002461
2462 lpfc_rcv_plogi_plogi_issue, /* RCV_PLOGI PLOGI_ISSUE */
James Smart92d7f7b2007-06-17 19:56:38 -05002463 lpfc_rcv_prli_plogi_issue, /* RCV_PRLI */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002464 lpfc_rcv_logo_plogi_issue, /* RCV_LOGO */
dea31012005-04-17 16:05:31 -05002465 lpfc_rcv_els_plogi_issue, /* RCV_ADISC */
2466 lpfc_rcv_els_plogi_issue, /* RCV_PDISC */
2467 lpfc_rcv_els_plogi_issue, /* RCV_PRLO */
2468 lpfc_cmpl_plogi_plogi_issue, /* CMPL_PLOGI */
2469 lpfc_disc_illegal, /* CMPL_PRLI */
James Smart0ff10d42008-01-11 01:52:36 -05002470 lpfc_cmpl_logo_plogi_issue, /* CMPL_LOGO */
dea31012005-04-17 16:05:31 -05002471 lpfc_disc_illegal, /* CMPL_ADISC */
James Smart0ff10d42008-01-11 01:52:36 -05002472 lpfc_cmpl_reglogin_plogi_issue,/* CMPL_REG_LOGIN */
dea31012005-04-17 16:05:31 -05002473 lpfc_device_rm_plogi_issue, /* DEVICE_RM */
2474 lpfc_device_recov_plogi_issue, /* DEVICE_RECOVERY */
2475
2476 lpfc_rcv_plogi_adisc_issue, /* RCV_PLOGI ADISC_ISSUE */
2477 lpfc_rcv_prli_adisc_issue, /* RCV_PRLI */
2478 lpfc_rcv_logo_adisc_issue, /* RCV_LOGO */
2479 lpfc_rcv_padisc_adisc_issue, /* RCV_ADISC */
2480 lpfc_rcv_padisc_adisc_issue, /* RCV_PDISC */
2481 lpfc_rcv_prlo_adisc_issue, /* RCV_PRLO */
2482 lpfc_disc_illegal, /* CMPL_PLOGI */
2483 lpfc_disc_illegal, /* CMPL_PRLI */
2484 lpfc_disc_illegal, /* CMPL_LOGO */
2485 lpfc_cmpl_adisc_adisc_issue, /* CMPL_ADISC */
2486 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2487 lpfc_device_rm_adisc_issue, /* DEVICE_RM */
2488 lpfc_device_recov_adisc_issue, /* DEVICE_RECOVERY */
2489
2490 lpfc_rcv_plogi_reglogin_issue, /* RCV_PLOGI REG_LOGIN_ISSUE */
2491 lpfc_rcv_prli_reglogin_issue, /* RCV_PLOGI */
2492 lpfc_rcv_logo_reglogin_issue, /* RCV_LOGO */
2493 lpfc_rcv_padisc_reglogin_issue, /* RCV_ADISC */
2494 lpfc_rcv_padisc_reglogin_issue, /* RCV_PDISC */
2495 lpfc_rcv_prlo_reglogin_issue, /* RCV_PRLO */
James Smart87af33f2007-10-27 13:37:43 -04002496 lpfc_cmpl_plogi_illegal, /* CMPL_PLOGI */
dea31012005-04-17 16:05:31 -05002497 lpfc_disc_illegal, /* CMPL_PRLI */
2498 lpfc_disc_illegal, /* CMPL_LOGO */
2499 lpfc_disc_illegal, /* CMPL_ADISC */
2500 lpfc_cmpl_reglogin_reglogin_issue,/* CMPL_REG_LOGIN */
2501 lpfc_device_rm_reglogin_issue, /* DEVICE_RM */
2502 lpfc_device_recov_reglogin_issue,/* DEVICE_RECOVERY */
2503
2504 lpfc_rcv_plogi_prli_issue, /* RCV_PLOGI PRLI_ISSUE */
2505 lpfc_rcv_prli_prli_issue, /* RCV_PRLI */
2506 lpfc_rcv_logo_prli_issue, /* RCV_LOGO */
2507 lpfc_rcv_padisc_prli_issue, /* RCV_ADISC */
2508 lpfc_rcv_padisc_prli_issue, /* RCV_PDISC */
2509 lpfc_rcv_prlo_prli_issue, /* RCV_PRLO */
James Smart87af33f2007-10-27 13:37:43 -04002510 lpfc_cmpl_plogi_illegal, /* CMPL_PLOGI */
dea31012005-04-17 16:05:31 -05002511 lpfc_cmpl_prli_prli_issue, /* CMPL_PRLI */
2512 lpfc_disc_illegal, /* CMPL_LOGO */
2513 lpfc_disc_illegal, /* CMPL_ADISC */
2514 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2515 lpfc_device_rm_prli_issue, /* DEVICE_RM */
2516 lpfc_device_recov_prli_issue, /* DEVICE_RECOVERY */
2517
James Smart086a3452012-08-14 14:25:21 -04002518 lpfc_rcv_plogi_logo_issue, /* RCV_PLOGI LOGO_ISSUE */
2519 lpfc_rcv_prli_logo_issue, /* RCV_PRLI */
2520 lpfc_rcv_logo_logo_issue, /* RCV_LOGO */
2521 lpfc_rcv_padisc_logo_issue, /* RCV_ADISC */
2522 lpfc_rcv_padisc_logo_issue, /* RCV_PDISC */
2523 lpfc_rcv_prlo_logo_issue, /* RCV_PRLO */
2524 lpfc_cmpl_plogi_illegal, /* CMPL_PLOGI */
2525 lpfc_disc_illegal, /* CMPL_PRLI */
2526 lpfc_cmpl_logo_logo_issue, /* CMPL_LOGO */
2527 lpfc_disc_illegal, /* CMPL_ADISC */
2528 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2529 lpfc_device_rm_logo_issue, /* DEVICE_RM */
2530 lpfc_device_recov_logo_issue, /* DEVICE_RECOVERY */
2531
dea31012005-04-17 16:05:31 -05002532 lpfc_rcv_plogi_unmap_node, /* RCV_PLOGI UNMAPPED_NODE */
2533 lpfc_rcv_prli_unmap_node, /* RCV_PRLI */
2534 lpfc_rcv_logo_unmap_node, /* RCV_LOGO */
2535 lpfc_rcv_padisc_unmap_node, /* RCV_ADISC */
2536 lpfc_rcv_padisc_unmap_node, /* RCV_PDISC */
2537 lpfc_rcv_prlo_unmap_node, /* RCV_PRLO */
2538 lpfc_disc_illegal, /* CMPL_PLOGI */
2539 lpfc_disc_illegal, /* CMPL_PRLI */
2540 lpfc_disc_illegal, /* CMPL_LOGO */
2541 lpfc_disc_illegal, /* CMPL_ADISC */
2542 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2543 lpfc_disc_illegal, /* DEVICE_RM */
2544 lpfc_device_recov_unmap_node, /* DEVICE_RECOVERY */
2545
2546 lpfc_rcv_plogi_mapped_node, /* RCV_PLOGI MAPPED_NODE */
2547 lpfc_rcv_prli_mapped_node, /* RCV_PRLI */
2548 lpfc_rcv_logo_mapped_node, /* RCV_LOGO */
2549 lpfc_rcv_padisc_mapped_node, /* RCV_ADISC */
2550 lpfc_rcv_padisc_mapped_node, /* RCV_PDISC */
2551 lpfc_rcv_prlo_mapped_node, /* RCV_PRLO */
2552 lpfc_disc_illegal, /* CMPL_PLOGI */
2553 lpfc_disc_illegal, /* CMPL_PRLI */
2554 lpfc_disc_illegal, /* CMPL_LOGO */
2555 lpfc_disc_illegal, /* CMPL_ADISC */
2556 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2557 lpfc_disc_illegal, /* DEVICE_RM */
2558 lpfc_device_recov_mapped_node, /* DEVICE_RECOVERY */
2559
2560 lpfc_rcv_plogi_npr_node, /* RCV_PLOGI NPR_NODE */
2561 lpfc_rcv_prli_npr_node, /* RCV_PRLI */
2562 lpfc_rcv_logo_npr_node, /* RCV_LOGO */
2563 lpfc_rcv_padisc_npr_node, /* RCV_ADISC */
2564 lpfc_rcv_padisc_npr_node, /* RCV_PDISC */
2565 lpfc_rcv_prlo_npr_node, /* RCV_PRLO */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002566 lpfc_cmpl_plogi_npr_node, /* CMPL_PLOGI */
2567 lpfc_cmpl_prli_npr_node, /* CMPL_PRLI */
dea31012005-04-17 16:05:31 -05002568 lpfc_cmpl_logo_npr_node, /* CMPL_LOGO */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002569 lpfc_cmpl_adisc_npr_node, /* CMPL_ADISC */
dea31012005-04-17 16:05:31 -05002570 lpfc_cmpl_reglogin_npr_node, /* CMPL_REG_LOGIN */
2571 lpfc_device_rm_npr_node, /* DEVICE_RM */
2572 lpfc_device_recov_npr_node, /* DEVICE_RECOVERY */
2573};
2574
2575int
James Smart2e0fef82007-06-17 19:56:36 -05002576lpfc_disc_state_machine(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2577 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05002578{
2579 uint32_t cur_state, rc;
James Smart2e0fef82007-06-17 19:56:36 -05002580 uint32_t(*func) (struct lpfc_vport *, struct lpfc_nodelist *, void *,
dea31012005-04-17 16:05:31 -05002581 uint32_t);
James Smarte47c9092008-02-08 18:49:26 -05002582 uint32_t got_ndlp = 0;
dea31012005-04-17 16:05:31 -05002583
James Smarte47c9092008-02-08 18:49:26 -05002584 if (lpfc_nlp_get(ndlp))
2585 got_ndlp = 1;
2586
dea31012005-04-17 16:05:31 -05002587 cur_state = ndlp->nlp_state;
2588
2589 /* DSM in event <evt> on NPort <nlp_DID> in state <cur_state> */
James Smarte8b62012007-08-02 11:10:09 -04002590 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2591 "0211 DSM in event x%x on NPort x%x in "
2592 "state %d Data: x%x\n",
2593 evt, ndlp->nlp_DID, cur_state, ndlp->nlp_flag);
dea31012005-04-17 16:05:31 -05002594
James Smart858c9f62007-06-17 19:56:39 -05002595 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_DSM,
2596 "DSM in: evt:%d ste:%d did:x%x",
2597 evt, cur_state, ndlp->nlp_DID);
2598
dea31012005-04-17 16:05:31 -05002599 func = lpfc_disc_action[(cur_state * NLP_EVT_MAX_EVENT) + evt];
James Smart2e0fef82007-06-17 19:56:36 -05002600 rc = (func) (vport, ndlp, arg, evt);
dea31012005-04-17 16:05:31 -05002601
2602 /* DSM out state <rc> on NPort <nlp_DID> */
James Smarte47c9092008-02-08 18:49:26 -05002603 if (got_ndlp) {
2604 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
James Smarte8b62012007-08-02 11:10:09 -04002605 "0212 DSM out state %d on NPort x%x Data: x%x\n",
2606 rc, ndlp->nlp_DID, ndlp->nlp_flag);
dea31012005-04-17 16:05:31 -05002607
James Smarte47c9092008-02-08 18:49:26 -05002608 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_DSM,
2609 "DSM out: ste:%d did:x%x flg:x%x",
2610 rc, ndlp->nlp_DID, ndlp->nlp_flag);
2611 /* Decrement the ndlp reference count held for this function */
2612 lpfc_nlp_put(ndlp);
2613 } else {
2614 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
James Smartd7c255b2008-08-24 21:50:00 -04002615 "0213 DSM out state %d on NPort free\n", rc);
James Smart858c9f62007-06-17 19:56:39 -05002616
James Smarte47c9092008-02-08 18:49:26 -05002617 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_DSM,
2618 "DSM out: ste:%d did:x%x flg:x%x",
2619 rc, 0, 0);
2620 }
dea31012005-04-17 16:05:31 -05002621
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002622 return rc;
dea31012005-04-17 16:05:31 -05002623}