blob: 5cc1103d811e89520425cce6e444080488358675 [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 Smart92c13f22013-05-31 17:05:45 -04004 * Copyright (C) 2004-2013 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;
279 uint32_t *lp;
280 IOCB_t *icmd;
281 struct serv_parm *sp;
282 LPFC_MBOXQ_t *mbox;
283 struct ls_rjt stat;
284 int rc;
285
286 memset(&stat, 0, sizeof (struct ls_rjt));
James Smart695a8142010-01-26 23:08:03 -0500287 if (vport->port_state <= LPFC_FDISC) {
dea31012005-04-17 16:05:31 -0500288 /* Before responding to PLOGI, check for pt2pt mode.
289 * If we are pt2pt, with an outstanding FLOGI, abort
290 * the FLOGI and resend it first.
291 */
James Smart2e0fef82007-06-17 19:56:36 -0500292 if (vport->fc_flag & FC_PT2PT) {
James Smart92d7f7b2007-06-17 19:56:38 -0500293 lpfc_els_abort_flogi(phba);
James Smart2e0fef82007-06-17 19:56:36 -0500294 if (!(vport->fc_flag & FC_PT2PT_PLOGI)) {
dea31012005-04-17 16:05:31 -0500295 /* If the other side is supposed to initiate
296 * the PLOGI anyway, just ACC it now and
297 * move on with discovery.
298 */
299 phba->fc_edtov = FF_DEF_EDTOV;
300 phba->fc_ratov = FF_DEF_RATOV;
301 /* Start discovery - this should just do
302 CLEAR_LA */
James Smart2e0fef82007-06-17 19:56:36 -0500303 lpfc_disc_start(vport);
James Smarted957682007-06-17 19:56:37 -0500304 } else
James Smart2e0fef82007-06-17 19:56:36 -0500305 lpfc_initial_flogi(vport);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500306 } else {
dea31012005-04-17 16:05:31 -0500307 stat.un.b.lsRjtRsnCode = LSRJT_LOGICAL_BSY;
308 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
James Smart2e0fef82007-06-17 19:56:36 -0500309 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb,
James Smart858c9f62007-06-17 19:56:39 -0500310 ndlp, NULL);
dea31012005-04-17 16:05:31 -0500311 return 0;
312 }
313 }
314 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
315 lp = (uint32_t *) pcmd->virt;
316 sp = (struct serv_parm *) ((uint8_t *) lp + sizeof (uint32_t));
James Smarta8adb832007-10-27 13:37:53 -0400317 if (wwn_to_u64(sp->portName.u.wwn) == 0) {
318 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
319 "0140 PLOGI Reject: invalid nname\n");
320 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
321 stat.un.b.lsRjtRsnCodeExp = LSEXP_INVALID_PNAME;
322 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
323 NULL);
324 return 0;
325 }
326 if (wwn_to_u64(sp->nodeName.u.wwn) == 0) {
327 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
328 "0141 PLOGI Reject: invalid pname\n");
329 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
330 stat.un.b.lsRjtRsnCodeExp = LSEXP_INVALID_NNAME;
331 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
332 NULL);
333 return 0;
334 }
James Smart341af102010-01-26 23:07:37 -0500335 if ((lpfc_check_sparm(vport, ndlp, sp, CLASS3, 0) == 0)) {
dea31012005-04-17 16:05:31 -0500336 /* Reject this request because invalid parameters */
337 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
338 stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
James Smart858c9f62007-06-17 19:56:39 -0500339 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
340 NULL);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500341 return 0;
dea31012005-04-17 16:05:31 -0500342 }
343 icmd = &cmdiocb->iocb;
344
345 /* PLOGI chkparm OK */
James Smarte8b62012007-08-02 11:10:09 -0400346 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
James Smarte74c03c2013-04-17 20:15:19 -0400347 "0114 PLOGI chkparm OK Data: x%x x%x x%x "
348 "x%x x%x x%x\n",
James Smarte8b62012007-08-02 11:10:09 -0400349 ndlp->nlp_DID, ndlp->nlp_state, ndlp->nlp_flag,
James Smarte74c03c2013-04-17 20:15:19 -0400350 ndlp->nlp_rpi, vport->port_state,
351 vport->fc_flag);
dea31012005-04-17 16:05:31 -0500352
James Smart3de2a652007-08-02 11:09:59 -0400353 if (vport->cfg_fcp_class == 2 && sp->cls2.classValid)
dea31012005-04-17 16:05:31 -0500354 ndlp->nlp_fcp_info |= CLASS2;
James Smarted957682007-06-17 19:56:37 -0500355 else
dea31012005-04-17 16:05:31 -0500356 ndlp->nlp_fcp_info |= CLASS3;
James Smart2e0fef82007-06-17 19:56:36 -0500357
dea31012005-04-17 16:05:31 -0500358 ndlp->nlp_class_sup = 0;
359 if (sp->cls1.classValid)
360 ndlp->nlp_class_sup |= FC_COS_CLASS1;
361 if (sp->cls2.classValid)
362 ndlp->nlp_class_sup |= FC_COS_CLASS2;
363 if (sp->cls3.classValid)
364 ndlp->nlp_class_sup |= FC_COS_CLASS3;
365 if (sp->cls4.classValid)
366 ndlp->nlp_class_sup |= FC_COS_CLASS4;
367 ndlp->nlp_maxframe =
368 ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) | sp->cmn.bbRcvSizeLsb;
369
James Smart05580562011-05-24 11:40:48 -0400370 /* no need to reg_login if we are already in one of these states */
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500371 switch (ndlp->nlp_state) {
dea31012005-04-17 16:05:31 -0500372 case NLP_STE_NPR_NODE:
373 if (!(ndlp->nlp_flag & NLP_NPR_ADISC))
374 break;
375 case NLP_STE_REG_LOGIN_ISSUE:
376 case NLP_STE_PRLI_ISSUE:
377 case NLP_STE_UNMAPPED_NODE:
378 case NLP_STE_MAPPED_NODE:
James Smart05580562011-05-24 11:40:48 -0400379 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp, NULL);
380 return 1;
dea31012005-04-17 16:05:31 -0500381 }
382
James Smart939723a2012-05-09 21:19:03 -0400383 /* Check for Nport to NPort pt2pt protocol */
James Smart92d7f7b2007-06-17 19:56:38 -0500384 if ((vport->fc_flag & FC_PT2PT) &&
385 !(vport->fc_flag & FC_PT2PT_PLOGI)) {
James Smart939723a2012-05-09 21:19:03 -0400386
dea31012005-04-17 16:05:31 -0500387 /* rcv'ed PLOGI decides what our NPortId will be */
James Smart2e0fef82007-06-17 19:56:36 -0500388 vport->fc_myDID = icmd->un.rcvels.parmRo;
dea31012005-04-17 16:05:31 -0500389 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
390 if (mbox == NULL)
391 goto out;
392 lpfc_config_link(phba, mbox);
393 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smarted957682007-06-17 19:56:37 -0500394 mbox->vport = vport;
James Smart0b727fe2007-10-27 13:37:25 -0400395 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
dea31012005-04-17 16:05:31 -0500396 if (rc == MBX_NOT_FINISHED) {
James Smart92d7f7b2007-06-17 19:56:38 -0500397 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -0500398 goto out;
399 }
James Smart939723a2012-05-09 21:19:03 -0400400 /*
401 * For SLI4, the VFI/VPI are registered AFTER the
402 * Nport with the higher WWPN sends us a PLOGI with
403 * our assigned NPortId.
404 */
405 if (phba->sli_rev == LPFC_SLI_REV4)
406 lpfc_issue_reg_vfi(vport);
dea31012005-04-17 16:05:31 -0500407
James Smart2e0fef82007-06-17 19:56:36 -0500408 lpfc_can_disctmo(vport);
dea31012005-04-17 16:05:31 -0500409 }
410 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
James Smart2e0fef82007-06-17 19:56:36 -0500411 if (!mbox)
dea31012005-04-17 16:05:31 -0500412 goto out;
413
James Smart6b5151f2012-01-18 16:24:06 -0500414 /* Registering an existing RPI behaves differently for SLI3 vs SLI4 */
415 if (phba->sli_rev == LPFC_SLI_REV4)
416 lpfc_unreg_rpi(vport, ndlp);
417
James Smart6fb120a2009-05-22 14:52:59 -0400418 rc = lpfc_reg_rpi(phba, vport->vpi, icmd->un.rcvels.remoteID,
James Smart40426292010-12-15 17:58:10 -0500419 (uint8_t *) sp, mbox, ndlp->nlp_rpi);
James Smart2e0fef82007-06-17 19:56:36 -0500420 if (rc) {
421 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -0500422 goto out;
423 }
424
425 /* ACC PLOGI rsp command needs to execute first,
426 * queue this mbox command to be processed later.
427 */
428 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
James Smart329f9bc2007-04-25 09:53:01 -0400429 /*
430 * mbox->context2 = lpfc_nlp_get(ndlp) deferred until mailbox
431 * command issued in lpfc_cmpl_els_acc().
432 */
James Smart2e0fef82007-06-17 19:56:36 -0500433 mbox->vport = vport;
434 spin_lock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -0500435 ndlp->nlp_flag |= (NLP_ACC_REGLOGIN | NLP_RCV_PLOGI);
James Smart2e0fef82007-06-17 19:56:36 -0500436 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500437
James Smart33ccf8d2006-08-17 11:57:58 -0400438 /*
439 * If there is an outstanding PLOGI issued, abort it before
440 * sending ACC rsp for received PLOGI. If pending plogi
441 * is not canceled here, the plogi will be rejected by
442 * remote port and will be retried. On a configuration with
443 * single discovery thread, this will cause a huge delay in
444 * discovery. Also this will cause multiple state machines
445 * running in parallel for this node.
446 */
447 if (ndlp->nlp_state == NLP_STE_PLOGI_ISSUE) {
448 /* software abort outstanding PLOGI */
James Smart07951072007-04-25 09:51:38 -0400449 lpfc_els_abort(phba, ndlp);
James Smart33ccf8d2006-08-17 11:57:58 -0400450 }
451
James Smart858c9f62007-06-17 19:56:39 -0500452 if ((vport->port_type == LPFC_NPIV_PORT &&
James Smart3de2a652007-08-02 11:09:59 -0400453 vport->cfg_restrict_login)) {
James Smart858c9f62007-06-17 19:56:39 -0500454
455 /* In order to preserve RPIs, we want to cleanup
456 * the default RPI the firmware created to rcv
457 * this ELS request. The only way to do this is
458 * to register, then unregister the RPI.
459 */
460 spin_lock_irq(shost->host_lock);
461 ndlp->nlp_flag |= NLP_RM_DFLT_RPI;
462 spin_unlock_irq(shost->host_lock);
463 stat.un.b.lsRjtRsnCode = LSRJT_INVALID_CMD;
464 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
James Smart0a8a86f2012-03-01 22:36:15 -0500465 rc = lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb,
James Smart858c9f62007-06-17 19:56:39 -0500466 ndlp, mbox);
James Smart0a8a86f2012-03-01 22:36:15 -0500467 if (rc)
468 mempool_free(mbox, phba->mbox_mem_pool);
James Smart858c9f62007-06-17 19:56:39 -0500469 return 1;
470 }
James Smart0a8a86f2012-03-01 22:36:15 -0500471 rc = lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp, mbox);
472 if (rc)
473 mempool_free(mbox, phba->mbox_mem_pool);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500474 return 1;
dea31012005-04-17 16:05:31 -0500475out:
476 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
477 stat.un.b.lsRjtRsnCodeExp = LSEXP_OUT_OF_RESOURCE;
James Smart858c9f62007-06-17 19:56:39 -0500478 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500479 return 0;
dea31012005-04-17 16:05:31 -0500480}
481
James Smart6b5151f2012-01-18 16:24:06 -0500482/**
483 * lpfc_mbx_cmpl_resume_rpi - Resume RPI completion routine
484 * @phba: pointer to lpfc hba data structure.
485 * @mboxq: pointer to mailbox object
486 *
487 * This routine is invoked to issue a completion to a rcv'ed
488 * ADISC or PDISC after the paused RPI has been resumed.
489 **/
490static void
491lpfc_mbx_cmpl_resume_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
492{
493 struct lpfc_vport *vport;
494 struct lpfc_iocbq *elsiocb;
495 struct lpfc_nodelist *ndlp;
496 uint32_t cmd;
497
498 elsiocb = (struct lpfc_iocbq *)mboxq->context1;
499 ndlp = (struct lpfc_nodelist *) mboxq->context2;
500 vport = mboxq->vport;
501 cmd = elsiocb->drvrTimeout;
502
503 if (cmd == ELS_CMD_ADISC) {
504 lpfc_els_rsp_adisc_acc(vport, elsiocb, ndlp);
505 } else {
506 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, elsiocb,
507 ndlp, NULL);
508 }
509 kfree(elsiocb);
James Smart72859902012-01-18 16:25:38 -0500510 mempool_free(mboxq, phba->mbox_mem_pool);
James Smart6b5151f2012-01-18 16:24:06 -0500511}
512
dea31012005-04-17 16:05:31 -0500513static int
James Smart2e0fef82007-06-17 19:56:36 -0500514lpfc_rcv_padisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -0500515 struct lpfc_iocbq *cmdiocb)
516{
James Smart2e0fef82007-06-17 19:56:36 -0500517 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart6b5151f2012-01-18 16:24:06 -0500518 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -0500519 struct lpfc_dmabuf *pcmd;
James Smart2e0fef82007-06-17 19:56:36 -0500520 struct serv_parm *sp;
521 struct lpfc_name *pnn, *ppn;
dea31012005-04-17 16:05:31 -0500522 struct ls_rjt stat;
523 ADISC *ap;
524 IOCB_t *icmd;
525 uint32_t *lp;
526 uint32_t cmd;
527
528 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
529 lp = (uint32_t *) pcmd->virt;
530
531 cmd = *lp++;
532 if (cmd == ELS_CMD_ADISC) {
533 ap = (ADISC *) lp;
534 pnn = (struct lpfc_name *) & ap->nodeName;
535 ppn = (struct lpfc_name *) & ap->portName;
536 } else {
537 sp = (struct serv_parm *) lp;
538 pnn = (struct lpfc_name *) & sp->nodeName;
539 ppn = (struct lpfc_name *) & sp->portName;
540 }
541
542 icmd = &cmdiocb->iocb;
James Smart2e0fef82007-06-17 19:56:36 -0500543 if (icmd->ulpStatus == 0 && lpfc_check_adisc(vport, ndlp, pnn, ppn)) {
James Smart6b5151f2012-01-18 16:24:06 -0500544
545 /*
546 * As soon as we send ACC, the remote NPort can
547 * start sending us data. Thus, for SLI4 we must
548 * resume the RPI before the ACC goes out.
549 */
550 if (vport->phba->sli_rev == LPFC_SLI_REV4) {
551 elsiocb = kmalloc(sizeof(struct lpfc_iocbq),
552 GFP_KERNEL);
553 if (elsiocb) {
554
555 /* Save info from cmd IOCB used in rsp */
556 memcpy((uint8_t *)elsiocb, (uint8_t *)cmdiocb,
557 sizeof(struct lpfc_iocbq));
558
559 /* Save the ELS cmd */
560 elsiocb->drvrTimeout = cmd;
561
562 lpfc_sli4_resume_rpi(ndlp,
563 lpfc_mbx_cmpl_resume_rpi, elsiocb);
564 goto out;
565 }
566 }
567
dea31012005-04-17 16:05:31 -0500568 if (cmd == ELS_CMD_ADISC) {
James Smart2e0fef82007-06-17 19:56:36 -0500569 lpfc_els_rsp_adisc_acc(vport, cmdiocb, ndlp);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500570 } else {
James Smart6b5151f2012-01-18 16:24:06 -0500571 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb,
572 ndlp, NULL);
dea31012005-04-17 16:05:31 -0500573 }
James Smart6b5151f2012-01-18 16:24:06 -0500574out:
575 /* If we are authenticated, move to the proper state */
576 if (ndlp->nlp_type & NLP_FCP_TARGET)
577 lpfc_nlp_set_state(vport, ndlp, NLP_STE_MAPPED_NODE);
578 else
579 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
580
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500581 return 1;
dea31012005-04-17 16:05:31 -0500582 }
583 /* Reject this request because invalid parameters */
584 stat.un.b.lsRjtRsvd0 = 0;
585 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
586 stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
587 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -0500588 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -0500589
dea31012005-04-17 16:05:31 -0500590 /* 1 sec timeout */
James Smart256ec0d2013-04-17 20:14:58 -0400591 mod_timer(&ndlp->nlp_delayfunc, jiffies + msecs_to_jiffies(1000));
dea31012005-04-17 16:05:31 -0500592
James Smart2e0fef82007-06-17 19:56:36 -0500593 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500594 ndlp->nlp_flag |= NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -0500595 spin_unlock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -0500596 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
597 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -0500598 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500599 return 0;
dea31012005-04-17 16:05:31 -0500600}
601
602static int
James Smart2e0fef82007-06-17 19:56:36 -0500603lpfc_rcv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
604 struct lpfc_iocbq *cmdiocb, uint32_t els_cmd)
dea31012005-04-17 16:05:31 -0500605{
James Smart2e0fef82007-06-17 19:56:36 -0500606 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart4b40c592010-03-15 11:25:44 -0400607 struct lpfc_hba *phba = vport->phba;
608 struct lpfc_vport **vports;
609 int i, active_vlink_present = 0 ;
James Smart2e0fef82007-06-17 19:56:36 -0500610
611 /* Put ndlp in NPR state with 1 sec timeout for plogi, ACC logo */
dea31012005-04-17 16:05:31 -0500612 /* Only call LOGO ACC for first LOGO, this avoids sending unnecessary
613 * PLOGIs during LOGO storms from a device.
614 */
James Smart2e0fef82007-06-17 19:56:36 -0500615 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500616 ndlp->nlp_flag |= NLP_LOGO_ACC;
James Smart2e0fef82007-06-17 19:56:36 -0500617 spin_unlock_irq(shost->host_lock);
James Smart82d9a2a2006-04-15 11:53:05 -0400618 if (els_cmd == ELS_CMD_PRLO)
James Smart51ef4c22007-08-02 11:10:31 -0400619 lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL);
James Smart82d9a2a2006-04-15 11:53:05 -0400620 else
James Smart51ef4c22007-08-02 11:10:31 -0400621 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
James Smart4b40c592010-03-15 11:25:44 -0400622 if (ndlp->nlp_DID == Fabric_DID) {
623 if (vport->port_state <= LPFC_FDISC)
624 goto out;
James Smart6fb120a2009-05-22 14:52:59 -0400625 lpfc_linkdown_port(vport);
James Smart6fb120a2009-05-22 14:52:59 -0400626 spin_lock_irq(shost->host_lock);
James Smart4b40c592010-03-15 11:25:44 -0400627 vport->fc_flag |= FC_VPORT_LOGO_RCVD;
James Smart6fb120a2009-05-22 14:52:59 -0400628 spin_unlock_irq(shost->host_lock);
James Smart4b40c592010-03-15 11:25:44 -0400629 vports = lpfc_create_vport_work_array(phba);
630 if (vports) {
631 for (i = 0; i <= phba->max_vports && vports[i] != NULL;
632 i++) {
633 if ((!(vports[i]->fc_flag &
634 FC_VPORT_LOGO_RCVD)) &&
635 (vports[i]->port_state > LPFC_FDISC)) {
636 active_vlink_present = 1;
637 break;
638 }
639 }
640 lpfc_destroy_vport_work_array(phba, vports);
641 }
dea31012005-04-17 16:05:31 -0500642
James Smart4b40c592010-03-15 11:25:44 -0400643 if (active_vlink_present) {
644 /*
645 * If there are other active VLinks present,
646 * re-instantiate the Vlink using FDISC.
647 */
James Smart256ec0d2013-04-17 20:14:58 -0400648 mod_timer(&ndlp->nlp_delayfunc,
649 jiffies + msecs_to_jiffies(1000));
James Smart4b40c592010-03-15 11:25:44 -0400650 spin_lock_irq(shost->host_lock);
651 ndlp->nlp_flag |= NLP_DELAY_TMO;
652 spin_unlock_irq(shost->host_lock);
653 ndlp->nlp_last_elscmd = ELS_CMD_FDISC;
654 vport->port_state = LPFC_FDISC;
655 } else {
656 spin_lock_irq(shost->host_lock);
657 phba->pport->fc_flag &= ~FC_LOGO_RCVD_DID_CHNG;
658 spin_unlock_irq(shost->host_lock);
659 lpfc_retry_pport_discovery(phba);
660 }
James Smart6fb120a2009-05-22 14:52:59 -0400661 } else if ((!(ndlp->nlp_type & NLP_FABRIC) &&
662 ((ndlp->nlp_type & NLP_FCP_TARGET) ||
663 !(ndlp->nlp_type & NLP_FCP_INITIATOR))) ||
664 (ndlp->nlp_state == NLP_STE_ADISC_ISSUE)) {
dea31012005-04-17 16:05:31 -0500665 /* Only try to re-login if this is NOT a Fabric Node */
James Smart256ec0d2013-04-17 20:14:58 -0400666 mod_timer(&ndlp->nlp_delayfunc,
667 jiffies + msecs_to_jiffies(1000 * 1));
James Smart2e0fef82007-06-17 19:56:36 -0500668 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500669 ndlp->nlp_flag |= NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -0500670 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500671
Jamie Wellnitz5024ab12006-02-28 19:25:28 -0500672 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
dea31012005-04-17 16:05:31 -0500673 }
James Smart4b40c592010-03-15 11:25:44 -0400674out:
James Smart87af33f2007-10-27 13:37:43 -0400675 ndlp->nlp_prev_state = ndlp->nlp_state;
676 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
dea31012005-04-17 16:05:31 -0500677
James Smart2e0fef82007-06-17 19:56:36 -0500678 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500679 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
James Smart2e0fef82007-06-17 19:56:36 -0500680 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500681 /* The driver has to wait until the ACC completes before it continues
682 * processing the LOGO. The action will resume in
683 * lpfc_cmpl_els_logo_acc routine. Since part of processing includes an
684 * unreg_login, the driver waits so the ACC does not get aborted.
685 */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500686 return 0;
dea31012005-04-17 16:05:31 -0500687}
688
689static void
James Smart2e0fef82007-06-17 19:56:36 -0500690lpfc_rcv_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
691 struct lpfc_iocbq *cmdiocb)
dea31012005-04-17 16:05:31 -0500692{
693 struct lpfc_dmabuf *pcmd;
694 uint32_t *lp;
695 PRLI *npr;
696 struct fc_rport *rport = ndlp->rport;
697 u32 roles;
698
699 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
700 lp = (uint32_t *) pcmd->virt;
701 npr = (PRLI *) ((uint8_t *) lp + sizeof (uint32_t));
702
703 ndlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR);
704 ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
James Smart3cb01c52013-07-15 18:35:04 -0400705 ndlp->nlp_flag &= ~NLP_FIRSTBURST;
James Smart92d7f7b2007-06-17 19:56:38 -0500706 if (npr->prliType == PRLI_FCP_TYPE) {
dea31012005-04-17 16:05:31 -0500707 if (npr->initiatorFunc)
708 ndlp->nlp_type |= NLP_FCP_INITIATOR;
James Smart3cb01c52013-07-15 18:35:04 -0400709 if (npr->targetFunc) {
dea31012005-04-17 16:05:31 -0500710 ndlp->nlp_type |= NLP_FCP_TARGET;
James Smart3cb01c52013-07-15 18:35:04 -0400711 if (npr->writeXferRdyDis)
712 ndlp->nlp_flag |= NLP_FIRSTBURST;
713 }
dea31012005-04-17 16:05:31 -0500714 if (npr->Retry)
715 ndlp->nlp_fcp_info |= NLP_FCP_2_DEVICE;
716 }
717 if (rport) {
718 /* We need to update the rport role values */
719 roles = FC_RPORT_ROLE_UNKNOWN;
720 if (ndlp->nlp_type & NLP_FCP_INITIATOR)
721 roles |= FC_RPORT_ROLE_FCP_INITIATOR;
722 if (ndlp->nlp_type & NLP_FCP_TARGET)
723 roles |= FC_RPORT_ROLE_FCP_TARGET;
James Smart858c9f62007-06-17 19:56:39 -0500724
725 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
726 "rport rolechg: role:x%x did:x%x flg:x%x",
727 roles, ndlp->nlp_DID, ndlp->nlp_flag);
728
dea31012005-04-17 16:05:31 -0500729 fc_remote_port_rolechg(rport, roles);
730 }
731}
732
733static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -0500734lpfc_disc_set_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -0500735{
James Smart2e0fef82007-06-17 19:56:36 -0500736 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart2e0fef82007-06-17 19:56:36 -0500737
James Smart40426292010-12-15 17:58:10 -0500738 if (!(ndlp->nlp_flag & NLP_RPI_REGISTERED)) {
James Smart51ef4c22007-08-02 11:10:31 -0400739 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
740 return 0;
741 }
742
James Smart1b32f6a2008-02-08 18:49:39 -0500743 if (!(vport->fc_flag & FC_PT2PT)) {
744 /* Check config parameter use-adisc or FCP-2 */
745 if ((vport->cfg_use_adisc && (vport->fc_flag & FC_RSCN_MODE)) ||
James Smartffc95492010-06-07 15:23:17 -0400746 ((ndlp->nlp_fcp_info & NLP_FCP_2_DEVICE) &&
747 (ndlp->nlp_type & NLP_FCP_TARGET))) {
James Smart1b32f6a2008-02-08 18:49:39 -0500748 spin_lock_irq(shost->host_lock);
749 ndlp->nlp_flag |= NLP_NPR_ADISC;
750 spin_unlock_irq(shost->host_lock);
751 return 1;
752 }
James Smart92d7f7b2007-06-17 19:56:38 -0500753 }
754 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
755 lpfc_unreg_rpi(vport, ndlp);
756 return 0;
dea31012005-04-17 16:05:31 -0500757}
James Smart6d368e52011-05-24 11:44:12 -0400758
James Smart78730cf2010-04-06 15:06:30 -0400759/**
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300760 * lpfc_release_rpi - Release a RPI by issuing unreg_login mailbox cmd.
James Smart78730cf2010-04-06 15:06:30 -0400761 * @phba : Pointer to lpfc_hba structure.
762 * @vport: Pointer to lpfc_vport structure.
763 * @rpi : rpi to be release.
764 *
765 * This function will send a unreg_login mailbox command to the firmware
766 * to release a rpi.
767 **/
768void
769lpfc_release_rpi(struct lpfc_hba *phba,
770 struct lpfc_vport *vport,
771 uint16_t rpi)
772{
773 LPFC_MBOXQ_t *pmb;
774 int rc;
775
776 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
777 GFP_KERNEL);
778 if (!pmb)
779 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
780 "2796 mailbox memory allocation failed \n");
781 else {
782 lpfc_unreg_login(phba, vport->vpi, rpi, pmb);
783 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
784 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
785 if (rc == MBX_NOT_FINISHED)
786 mempool_free(pmb, phba->mbox_mem_pool);
787 }
788}
dea31012005-04-17 16:05:31 -0500789
790static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -0500791lpfc_disc_illegal(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
792 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -0500793{
James Smart78730cf2010-04-06 15:06:30 -0400794 struct lpfc_hba *phba;
795 LPFC_MBOXQ_t *pmb = (LPFC_MBOXQ_t *) arg;
796 MAILBOX_t *mb;
797 uint16_t rpi;
798
799 phba = vport->phba;
800 /* Release the RPI if reglogin completing */
801 if (!(phba->pport->load_flag & FC_UNLOADING) &&
802 (evt == NLP_EVT_CMPL_REG_LOGIN) &&
803 (!pmb->u.mb.mbxStatus)) {
804 mb = &pmb->u.mb;
805 rpi = pmb->u.mb.un.varWords[0];
806 lpfc_release_rpi(phba, vport, rpi);
807 }
James Smarte8b62012007-08-02 11:10:09 -0400808 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
James Smarte47c9092008-02-08 18:49:26 -0500809 "0271 Illegal State Transition: node x%x "
James Smarte8b62012007-08-02 11:10:09 -0400810 "event x%x, state x%x Data: x%x x%x\n",
811 ndlp->nlp_DID, evt, ndlp->nlp_state, ndlp->nlp_rpi,
812 ndlp->nlp_flag);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500813 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -0500814}
815
James Smart87af33f2007-10-27 13:37:43 -0400816static uint32_t
817lpfc_cmpl_plogi_illegal(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
818 void *arg, uint32_t evt)
819{
820 /* This transition is only legal if we previously
821 * rcv'ed a PLOGI. Since we don't want 2 discovery threads
822 * working on the same NPortID, do nothing for this thread
823 * to stop it.
824 */
825 if (!(ndlp->nlp_flag & NLP_RCV_PLOGI)) {
826 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
James Smarte47c9092008-02-08 18:49:26 -0500827 "0272 Illegal State Transition: node x%x "
James Smart87af33f2007-10-27 13:37:43 -0400828 "event x%x, state x%x Data: x%x x%x\n",
829 ndlp->nlp_DID, evt, ndlp->nlp_state, ndlp->nlp_rpi,
830 ndlp->nlp_flag);
831 }
832 return ndlp->nlp_state;
833}
834
dea31012005-04-17 16:05:31 -0500835/* Start of Discovery State Machine routines */
836
837static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -0500838lpfc_rcv_plogi_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
839 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -0500840{
841 struct lpfc_iocbq *cmdiocb;
842
843 cmdiocb = (struct lpfc_iocbq *) arg;
844
James Smart2e0fef82007-06-17 19:56:36 -0500845 if (lpfc_rcv_plogi(vport, ndlp, cmdiocb)) {
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500846 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -0500847 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500848 return NLP_STE_FREED_NODE;
dea31012005-04-17 16:05:31 -0500849}
850
851static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -0500852lpfc_rcv_els_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
853 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -0500854{
James Smart2e0fef82007-06-17 19:56:36 -0500855 lpfc_issue_els_logo(vport, ndlp, 0);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500856 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -0500857}
858
859static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -0500860lpfc_rcv_logo_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
861 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -0500862{
James Smart2e0fef82007-06-17 19:56:36 -0500863 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
864 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -0500865
James Smart2e0fef82007-06-17 19:56:36 -0500866 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500867 ndlp->nlp_flag |= NLP_LOGO_ACC;
James Smart2e0fef82007-06-17 19:56:36 -0500868 spin_unlock_irq(shost->host_lock);
James Smart51ef4c22007-08-02 11:10:31 -0400869 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -0500870
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_cmpl_logo_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -0500876 void *arg, uint32_t evt)
877{
James Smart2e0fef82007-06-17 19:56:36 -0500878 return NLP_STE_FREED_NODE;
879}
880
881static uint32_t
882lpfc_device_rm_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
883 void *arg, uint32_t evt)
884{
James Smart2e0fef82007-06-17 19:56:36 -0500885 return NLP_STE_FREED_NODE;
886}
887
888static uint32_t
James Smartdf9e1b52011-12-13 13:22:17 -0500889lpfc_device_recov_unused_node(struct lpfc_vport *vport,
890 struct lpfc_nodelist *ndlp,
891 void *arg, uint32_t evt)
892{
893 return ndlp->nlp_state;
894}
895
896static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -0500897lpfc_rcv_plogi_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
898 void *arg, uint32_t evt)
899{
James Smart0d2b6b82008-06-14 22:52:47 -0400900 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart2e0fef82007-06-17 19:56:36 -0500901 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500902 struct lpfc_iocbq *cmdiocb = arg;
James Smart2e0fef82007-06-17 19:56:36 -0500903 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
904 uint32_t *lp = (uint32_t *) pcmd->virt;
905 struct serv_parm *sp = (struct serv_parm *) (lp + 1);
dea31012005-04-17 16:05:31 -0500906 struct ls_rjt stat;
907 int port_cmp;
908
dea31012005-04-17 16:05:31 -0500909 memset(&stat, 0, sizeof (struct ls_rjt));
910
911 /* For a PLOGI, we only accept if our portname is less
912 * than the remote portname.
913 */
914 phba->fc_stat.elsLogiCol++;
James Smart2e0fef82007-06-17 19:56:36 -0500915 port_cmp = memcmp(&vport->fc_portname, &sp->portName,
James Smart92d7f7b2007-06-17 19:56:38 -0500916 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -0500917
918 if (port_cmp >= 0) {
919 /* Reject this request because the remote node will accept
920 ours */
921 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
922 stat.un.b.lsRjtRsnCodeExp = LSEXP_CMD_IN_PROGRESS;
James Smart858c9f62007-06-17 19:56:39 -0500923 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
924 NULL);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500925 } else {
James Smart0d2b6b82008-06-14 22:52:47 -0400926 if (lpfc_rcv_plogi(vport, ndlp, cmdiocb) &&
927 (ndlp->nlp_flag & NLP_NPR_2B_DISC) &&
928 (vport->num_disc_nodes)) {
929 spin_lock_irq(shost->host_lock);
930 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
931 spin_unlock_irq(shost->host_lock);
932 /* Check if there are more PLOGIs to be sent */
933 lpfc_more_plogi(vport);
934 if (vport->num_disc_nodes == 0) {
935 spin_lock_irq(shost->host_lock);
936 vport->fc_flag &= ~FC_NDISC_ACTIVE;
937 spin_unlock_irq(shost->host_lock);
938 lpfc_can_disctmo(vport);
939 lpfc_end_rscn(vport);
940 }
941 }
James Smart2e0fef82007-06-17 19:56:36 -0500942 } /* If our portname was less */
dea31012005-04-17 16:05:31 -0500943
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500944 return ndlp->nlp_state;
945}
946
947static uint32_t
James Smart92d7f7b2007-06-17 19:56:38 -0500948lpfc_rcv_prli_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
949 void *arg, uint32_t evt)
950{
951 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
952 struct ls_rjt stat;
953
954 memset(&stat, 0, sizeof (struct ls_rjt));
955 stat.un.b.lsRjtRsnCode = LSRJT_LOGICAL_BSY;
956 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
James Smart858c9f62007-06-17 19:56:39 -0500957 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
James Smart92d7f7b2007-06-17 19:56:38 -0500958 return ndlp->nlp_state;
959}
960
961static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -0500962lpfc_rcv_logo_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
963 void *arg, uint32_t evt)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500964{
James Smart2e0fef82007-06-17 19:56:36 -0500965 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500966
James Smart92d7f7b2007-06-17 19:56:38 -0500967 /* software abort outstanding PLOGI */
James Smart2e0fef82007-06-17 19:56:36 -0500968 lpfc_els_abort(vport->phba, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500969
James Smart2e0fef82007-06-17 19:56:36 -0500970 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500971 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -0500972}
973
974static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -0500975lpfc_rcv_els_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
976 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -0500977{
James Smart2e0fef82007-06-17 19:56:36 -0500978 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
979 struct lpfc_hba *phba = vport->phba;
980 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -0500981
982 /* software abort outstanding PLOGI */
James Smart07951072007-04-25 09:51:38 -0400983 lpfc_els_abort(phba, ndlp);
dea31012005-04-17 16:05:31 -0500984
985 if (evt == NLP_EVT_RCV_LOGO) {
James Smart51ef4c22007-08-02 11:10:31 -0400986 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500987 } else {
James Smart2e0fef82007-06-17 19:56:36 -0500988 lpfc_issue_els_logo(vport, ndlp, 0);
dea31012005-04-17 16:05:31 -0500989 }
990
James Smart2e0fef82007-06-17 19:56:36 -0500991 /* Put ndlp in npr state set plogi timer for 1 sec */
James Smart256ec0d2013-04-17 20:14:58 -0400992 mod_timer(&ndlp->nlp_delayfunc, jiffies + msecs_to_jiffies(1000 * 1));
James Smart2e0fef82007-06-17 19:56:36 -0500993 spin_lock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -0500994 ndlp->nlp_flag |= NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -0500995 spin_unlock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -0500996 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
997 ndlp->nlp_prev_state = NLP_STE_PLOGI_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -0500998 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
dea31012005-04-17 16:05:31 -0500999
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001000 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001001}
1002
1003static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001004lpfc_cmpl_plogi_plogi_issue(struct lpfc_vport *vport,
1005 struct lpfc_nodelist *ndlp,
1006 void *arg,
dea31012005-04-17 16:05:31 -05001007 uint32_t evt)
1008{
James Smart2e0fef82007-06-17 19:56:36 -05001009 struct lpfc_hba *phba = vport->phba;
James Smart0ff10d42008-01-11 01:52:36 -05001010 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart2e0fef82007-06-17 19:56:36 -05001011 struct lpfc_iocbq *cmdiocb, *rspiocb;
James Smart14691152006-12-02 13:34:28 -05001012 struct lpfc_dmabuf *pcmd, *prsp, *mp;
dea31012005-04-17 16:05:31 -05001013 uint32_t *lp;
1014 IOCB_t *irsp;
1015 struct serv_parm *sp;
1016 LPFC_MBOXQ_t *mbox;
1017
1018 cmdiocb = (struct lpfc_iocbq *) arg;
1019 rspiocb = cmdiocb->context_un.rsp_iocb;
1020
1021 if (ndlp->nlp_flag & NLP_ACC_REGLOGIN) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001022 /* Recovery from PLOGI collision logic */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001023 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001024 }
1025
1026 irsp = &rspiocb->iocb;
1027
1028 if (irsp->ulpStatus)
1029 goto out;
1030
1031 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
1032
James Smart2e0fef82007-06-17 19:56:36 -05001033 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
James Smarta2fc4aef2014-09-03 12:57:55 -04001034 if (!prsp)
1035 goto out;
dea31012005-04-17 16:05:31 -05001036
James Smart2e0fef82007-06-17 19:56:36 -05001037 lp = (uint32_t *) prsp->virt;
dea31012005-04-17 16:05:31 -05001038 sp = (struct serv_parm *) ((uint8_t *) lp + sizeof (uint32_t));
James Smart58da1ff2008-04-07 10:15:56 -04001039
1040 /* Some switches have FDMI servers returning 0 for WWN */
1041 if ((ndlp->nlp_DID != FDMI_DID) &&
1042 (wwn_to_u64(sp->portName.u.wwn) == 0 ||
1043 wwn_to_u64(sp->nodeName.u.wwn) == 0)) {
James Smarta8adb832007-10-27 13:37:53 -04001044 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1045 "0142 PLOGI RSP: Invalid WWN.\n");
1046 goto out;
1047 }
James Smart341af102010-01-26 23:07:37 -05001048 if (!lpfc_check_sparm(vport, ndlp, sp, CLASS3, 0))
dea31012005-04-17 16:05:31 -05001049 goto out;
dea31012005-04-17 16:05:31 -05001050 /* PLOGI chkparm OK */
James Smarte8b62012007-08-02 11:10:09 -04001051 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1052 "0121 PLOGI chkparm OK Data: x%x x%x x%x x%x\n",
1053 ndlp->nlp_DID, ndlp->nlp_state,
1054 ndlp->nlp_flag, ndlp->nlp_rpi);
James Smart3de2a652007-08-02 11:09:59 -04001055 if (vport->cfg_fcp_class == 2 && (sp->cls2.classValid))
dea31012005-04-17 16:05:31 -05001056 ndlp->nlp_fcp_info |= CLASS2;
James Smart2e0fef82007-06-17 19:56:36 -05001057 else
dea31012005-04-17 16:05:31 -05001058 ndlp->nlp_fcp_info |= CLASS3;
James Smart2e0fef82007-06-17 19:56:36 -05001059
dea31012005-04-17 16:05:31 -05001060 ndlp->nlp_class_sup = 0;
1061 if (sp->cls1.classValid)
1062 ndlp->nlp_class_sup |= FC_COS_CLASS1;
1063 if (sp->cls2.classValid)
1064 ndlp->nlp_class_sup |= FC_COS_CLASS2;
1065 if (sp->cls3.classValid)
1066 ndlp->nlp_class_sup |= FC_COS_CLASS3;
1067 if (sp->cls4.classValid)
1068 ndlp->nlp_class_sup |= FC_COS_CLASS4;
1069 ndlp->nlp_maxframe =
James Smart2e0fef82007-06-17 19:56:36 -05001070 ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) | sp->cmn.bbRcvSizeLsb;
dea31012005-04-17 16:05:31 -05001071
James Smart2e0fef82007-06-17 19:56:36 -05001072 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
James Smart92d7f7b2007-06-17 19:56:38 -05001073 if (!mbox) {
James Smarte8b62012007-08-02 11:10:09 -04001074 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1075 "0133 PLOGI: no memory for reg_login "
James Smart92d7f7b2007-06-17 19:56:38 -05001076 "Data: x%x x%x x%x x%x\n",
James Smart92d7f7b2007-06-17 19:56:38 -05001077 ndlp->nlp_DID, ndlp->nlp_state,
1078 ndlp->nlp_flag, ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05001079 goto out;
James Smart92d7f7b2007-06-17 19:56:38 -05001080 }
dea31012005-04-17 16:05:31 -05001081
James Smart2e0fef82007-06-17 19:56:36 -05001082 lpfc_unreg_rpi(vport, ndlp);
1083
James Smart6fb120a2009-05-22 14:52:59 -04001084 if (lpfc_reg_rpi(phba, vport->vpi, irsp->un.elsreq64.remoteID,
James Smart40426292010-12-15 17:58:10 -05001085 (uint8_t *) sp, mbox, ndlp->nlp_rpi) == 0) {
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05001086 switch (ndlp->nlp_DID) {
dea31012005-04-17 16:05:31 -05001087 case NameServer_DID:
James Smartde0c5b32007-04-25 09:52:27 -04001088 mbox->mbox_cmpl = lpfc_mbx_cmpl_ns_reg_login;
dea31012005-04-17 16:05:31 -05001089 break;
1090 case FDMI_DID:
James Smartde0c5b32007-04-25 09:52:27 -04001091 mbox->mbox_cmpl = lpfc_mbx_cmpl_fdmi_reg_login;
dea31012005-04-17 16:05:31 -05001092 break;
1093 default:
James Smartffc95492010-06-07 15:23:17 -04001094 ndlp->nlp_flag |= NLP_REG_LOGIN_SEND;
James Smartde0c5b32007-04-25 09:52:27 -04001095 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
dea31012005-04-17 16:05:31 -05001096 }
James Smart329f9bc2007-04-25 09:53:01 -04001097 mbox->context2 = lpfc_nlp_get(ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05001098 mbox->vport = vport;
James Smart0b727fe2007-10-27 13:37:25 -04001099 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
dea31012005-04-17 16:05:31 -05001100 != MBX_NOT_FINISHED) {
James Smart2e0fef82007-06-17 19:56:36 -05001101 lpfc_nlp_set_state(vport, ndlp,
1102 NLP_STE_REG_LOGIN_ISSUE);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001103 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001104 }
James Smartffc95492010-06-07 15:23:17 -04001105 if (ndlp->nlp_flag & NLP_REG_LOGIN_SEND)
1106 ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND;
James Smartfa4066b2008-01-11 01:53:27 -05001107 /* decrement node reference count to the failed mbox
1108 * command
1109 */
James Smart329f9bc2007-04-25 09:53:01 -04001110 lpfc_nlp_put(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05001111 mp = (struct lpfc_dmabuf *) mbox->context1;
James Smart14691152006-12-02 13:34:28 -05001112 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1113 kfree(mp);
dea31012005-04-17 16:05:31 -05001114 mempool_free(mbox, phba->mbox_mem_pool);
James Smart92d7f7b2007-06-17 19:56:38 -05001115
James Smarte8b62012007-08-02 11:10:09 -04001116 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1117 "0134 PLOGI: cannot issue reg_login "
1118 "Data: x%x x%x x%x x%x\n",
1119 ndlp->nlp_DID, ndlp->nlp_state,
1120 ndlp->nlp_flag, ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05001121 } else {
1122 mempool_free(mbox, phba->mbox_mem_pool);
James Smart92d7f7b2007-06-17 19:56:38 -05001123
James Smarte8b62012007-08-02 11:10:09 -04001124 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1125 "0135 PLOGI: cannot format reg_login "
1126 "Data: x%x x%x x%x x%x\n",
1127 ndlp->nlp_DID, ndlp->nlp_state,
1128 ndlp->nlp_flag, ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05001129 }
1130
1131
James Smart92d7f7b2007-06-17 19:56:38 -05001132out:
1133 if (ndlp->nlp_DID == NameServer_DID) {
1134 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04001135 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1136 "0261 Cannot Register NameServer login\n");
James Smart92d7f7b2007-06-17 19:56:38 -05001137 }
1138
James Smart8b455cf2013-01-03 15:43:53 -05001139 /*
1140 ** In case the node reference counter does not go to zero, ensure that
1141 ** the stale state for the node is not processed.
1142 */
1143
1144 ndlp->nlp_prev_state = ndlp->nlp_state;
1145 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
James Smart0ff10d42008-01-11 01:52:36 -05001146 spin_lock_irq(shost->host_lock);
James Smarta8adb832007-10-27 13:37:53 -04001147 ndlp->nlp_flag |= NLP_DEFER_RM;
James Smart0ff10d42008-01-11 01:52:36 -05001148 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001149 return NLP_STE_FREED_NODE;
dea31012005-04-17 16:05:31 -05001150}
1151
1152static uint32_t
James Smart0ff10d42008-01-11 01:52:36 -05001153lpfc_cmpl_logo_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1154 void *arg, uint32_t evt)
1155{
1156 return ndlp->nlp_state;
1157}
1158
1159static uint32_t
1160lpfc_cmpl_reglogin_plogi_issue(struct lpfc_vport *vport,
1161 struct lpfc_nodelist *ndlp, void *arg, uint32_t evt)
1162{
James Smart78730cf2010-04-06 15:06:30 -04001163 struct lpfc_hba *phba;
1164 LPFC_MBOXQ_t *pmb = (LPFC_MBOXQ_t *) arg;
1165 MAILBOX_t *mb = &pmb->u.mb;
1166 uint16_t rpi;
1167
1168 phba = vport->phba;
1169 /* Release the RPI */
1170 if (!(phba->pport->load_flag & FC_UNLOADING) &&
1171 !mb->mbxStatus) {
1172 rpi = pmb->u.mb.un.varWords[0];
1173 lpfc_release_rpi(phba, vport, rpi);
1174 }
James Smart0ff10d42008-01-11 01:52:36 -05001175 return ndlp->nlp_state;
1176}
1177
1178static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001179lpfc_device_rm_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1180 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001181{
James Smart2e0fef82007-06-17 19:56:36 -05001182 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001183
James Smart2e0fef82007-06-17 19:56:36 -05001184 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1185 spin_lock_irq(shost->host_lock);
1186 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
1187 spin_unlock_irq(shost->host_lock);
1188 return ndlp->nlp_state;
1189 } else {
1190 /* software abort outstanding PLOGI */
1191 lpfc_els_abort(vport->phba, ndlp);
1192
1193 lpfc_drop_node(vport, ndlp);
James Smarta0f9b482006-04-15 11:52:56 -04001194 return NLP_STE_FREED_NODE;
1195 }
dea31012005-04-17 16:05:31 -05001196}
1197
1198static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001199lpfc_device_recov_plogi_issue(struct lpfc_vport *vport,
1200 struct lpfc_nodelist *ndlp,
1201 void *arg,
1202 uint32_t evt)
dea31012005-04-17 16:05:31 -05001203{
James Smart2e0fef82007-06-17 19:56:36 -05001204 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1205 struct lpfc_hba *phba = vport->phba;
1206
James Smart92d7f7b2007-06-17 19:56:38 -05001207 /* Don't do anything that will mess up processing of the
1208 * previous RSCN.
1209 */
1210 if (vport->fc_flag & FC_RSCN_DEFERRED)
1211 return ndlp->nlp_state;
1212
dea31012005-04-17 16:05:31 -05001213 /* software abort outstanding PLOGI */
James Smart07951072007-04-25 09:51:38 -04001214 lpfc_els_abort(phba, ndlp);
dea31012005-04-17 16:05:31 -05001215
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001216 ndlp->nlp_prev_state = NLP_STE_PLOGI_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -05001217 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
James Smart92d7f7b2007-06-17 19:56:38 -05001218 spin_lock_irq(shost->host_lock);
James Smarta0f9b482006-04-15 11:52:56 -04001219 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
James Smart2e0fef82007-06-17 19:56:36 -05001220 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001221
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001222 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001223}
1224
1225static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001226lpfc_rcv_plogi_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1227 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001228{
James Smart0d2b6b82008-06-14 22:52:47 -04001229 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart2e0fef82007-06-17 19:56:36 -05001230 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001231 struct lpfc_iocbq *cmdiocb;
1232
1233 /* software abort outstanding ADISC */
James Smart07951072007-04-25 09:51:38 -04001234 lpfc_els_abort(phba, ndlp);
dea31012005-04-17 16:05:31 -05001235
1236 cmdiocb = (struct lpfc_iocbq *) arg;
1237
James Smart0d2b6b82008-06-14 22:52:47 -04001238 if (lpfc_rcv_plogi(vport, ndlp, cmdiocb)) {
1239 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1240 spin_lock_irq(shost->host_lock);
1241 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
1242 spin_unlock_irq(shost->host_lock);
James Smart90160e02008-08-24 21:49:45 -04001243 if (vport->num_disc_nodes)
James Smart0d2b6b82008-06-14 22:52:47 -04001244 lpfc_more_adisc(vport);
James Smart0d2b6b82008-06-14 22:52:47 -04001245 }
1246 return ndlp->nlp_state;
1247 }
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001248 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -05001249 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
1250 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
dea31012005-04-17 16:05:31 -05001251
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001252 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001253}
1254
1255static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001256lpfc_rcv_prli_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1257 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001258{
James Smart2e0fef82007-06-17 19:56:36 -05001259 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001260
James Smart2e0fef82007-06-17 19:56:36 -05001261 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001262 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001263}
1264
1265static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001266lpfc_rcv_logo_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1267 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001268{
James Smart2e0fef82007-06-17 19:56:36 -05001269 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001270 struct lpfc_iocbq *cmdiocb;
1271
1272 cmdiocb = (struct lpfc_iocbq *) arg;
1273
1274 /* software abort outstanding ADISC */
James Smart07951072007-04-25 09:51:38 -04001275 lpfc_els_abort(phba, ndlp);
dea31012005-04-17 16:05:31 -05001276
James Smart2e0fef82007-06-17 19:56:36 -05001277 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001278 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001279}
1280
1281static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001282lpfc_rcv_padisc_adisc_issue(struct lpfc_vport *vport,
1283 struct lpfc_nodelist *ndlp,
1284 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001285{
1286 struct lpfc_iocbq *cmdiocb;
1287
1288 cmdiocb = (struct lpfc_iocbq *) arg;
1289
James Smart2e0fef82007-06-17 19:56:36 -05001290 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001291 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001292}
1293
1294static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001295lpfc_rcv_prlo_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1296 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001297{
1298 struct lpfc_iocbq *cmdiocb;
1299
1300 cmdiocb = (struct lpfc_iocbq *) arg;
1301
1302 /* Treat like rcv logo */
James Smart2e0fef82007-06-17 19:56:36 -05001303 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_PRLO);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001304 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001305}
1306
1307static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001308lpfc_cmpl_adisc_adisc_issue(struct lpfc_vport *vport,
1309 struct lpfc_nodelist *ndlp,
1310 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001311{
James Smart2e0fef82007-06-17 19:56:36 -05001312 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1313 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001314 struct lpfc_iocbq *cmdiocb, *rspiocb;
1315 IOCB_t *irsp;
1316 ADISC *ap;
James Smart6fb120a2009-05-22 14:52:59 -04001317 int rc;
dea31012005-04-17 16:05:31 -05001318
1319 cmdiocb = (struct lpfc_iocbq *) arg;
1320 rspiocb = cmdiocb->context_un.rsp_iocb;
1321
1322 ap = (ADISC *)lpfc_check_elscmpl_iocb(phba, cmdiocb, rspiocb);
1323 irsp = &rspiocb->iocb;
1324
1325 if ((irsp->ulpStatus) ||
James Smart92d7f7b2007-06-17 19:56:38 -05001326 (!lpfc_check_adisc(vport, ndlp, &ap->nodeName, &ap->portName))) {
dea31012005-04-17 16:05:31 -05001327 /* 1 sec timeout */
James Smart256ec0d2013-04-17 20:14:58 -04001328 mod_timer(&ndlp->nlp_delayfunc,
1329 jiffies + msecs_to_jiffies(1000));
James Smart2e0fef82007-06-17 19:56:36 -05001330 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001331 ndlp->nlp_flag |= NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05001332 spin_unlock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001333 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
dea31012005-04-17 16:05:31 -05001334
James Smart2e0fef82007-06-17 19:56:36 -05001335 memset(&ndlp->nlp_nodename, 0, sizeof(struct lpfc_name));
1336 memset(&ndlp->nlp_portname, 0, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05001337
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001338 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -05001339 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1340 lpfc_unreg_rpi(vport, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001341 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001342 }
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001343
James Smart6fb120a2009-05-22 14:52:59 -04001344 if (phba->sli_rev == LPFC_SLI_REV4) {
James Smart6b5151f2012-01-18 16:24:06 -05001345 rc = lpfc_sli4_resume_rpi(ndlp, NULL, NULL);
James Smart6fb120a2009-05-22 14:52:59 -04001346 if (rc) {
1347 /* Stay in state and retry. */
1348 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
1349 return ndlp->nlp_state;
1350 }
1351 }
1352
James.Smart@Emulex.Com25013222005-06-25 10:34:33 -04001353 if (ndlp->nlp_type & NLP_FCP_TARGET) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001354 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -05001355 lpfc_nlp_set_state(vport, ndlp, NLP_STE_MAPPED_NODE);
James.Smart@Emulex.Com25013222005-06-25 10:34:33 -04001356 } else {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001357 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -05001358 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
James.Smart@Emulex.Com25013222005-06-25 10:34:33 -04001359 }
James Smart6fb120a2009-05-22 14:52:59 -04001360
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001361 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001362}
1363
1364static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001365lpfc_device_rm_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1366 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001367{
James Smart2e0fef82007-06-17 19:56:36 -05001368 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001369
James Smart2e0fef82007-06-17 19:56:36 -05001370 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1371 spin_lock_irq(shost->host_lock);
1372 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
1373 spin_unlock_irq(shost->host_lock);
1374 return ndlp->nlp_state;
1375 } else {
1376 /* software abort outstanding ADISC */
1377 lpfc_els_abort(vport->phba, ndlp);
1378
1379 lpfc_drop_node(vport, ndlp);
James Smarta0f9b482006-04-15 11:52:56 -04001380 return NLP_STE_FREED_NODE;
1381 }
dea31012005-04-17 16:05:31 -05001382}
1383
1384static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001385lpfc_device_recov_adisc_issue(struct lpfc_vport *vport,
1386 struct lpfc_nodelist *ndlp,
1387 void *arg,
1388 uint32_t evt)
dea31012005-04-17 16:05:31 -05001389{
James Smart2e0fef82007-06-17 19:56:36 -05001390 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1391 struct lpfc_hba *phba = vport->phba;
1392
James Smart92d7f7b2007-06-17 19:56:38 -05001393 /* Don't do anything that will mess up processing of the
1394 * previous RSCN.
1395 */
1396 if (vport->fc_flag & FC_RSCN_DEFERRED)
1397 return ndlp->nlp_state;
1398
dea31012005-04-17 16:05:31 -05001399 /* software abort outstanding ADISC */
James Smart07951072007-04-25 09:51:38 -04001400 lpfc_els_abort(phba, ndlp);
dea31012005-04-17 16:05:31 -05001401
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001402 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -05001403 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1404 spin_lock_irq(shost->host_lock);
James Smarta0f9b482006-04-15 11:52:56 -04001405 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
James Smart2e0fef82007-06-17 19:56:36 -05001406 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05001407 lpfc_disc_set_adisc(vport, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001408 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001409}
1410
1411static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001412lpfc_rcv_plogi_reglogin_issue(struct lpfc_vport *vport,
1413 struct lpfc_nodelist *ndlp,
1414 void *arg,
dea31012005-04-17 16:05:31 -05001415 uint32_t evt)
1416{
James Smart2e0fef82007-06-17 19:56:36 -05001417 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001418
James Smart2e0fef82007-06-17 19:56:36 -05001419 lpfc_rcv_plogi(vport, ndlp, cmdiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001420 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001421}
1422
1423static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001424lpfc_rcv_prli_reglogin_issue(struct lpfc_vport *vport,
1425 struct lpfc_nodelist *ndlp,
1426 void *arg,
dea31012005-04-17 16:05:31 -05001427 uint32_t evt)
1428{
James Smart2e0fef82007-06-17 19:56:36 -05001429 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001430
James Smart2e0fef82007-06-17 19:56:36 -05001431 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001432 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001433}
1434
1435static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001436lpfc_rcv_logo_reglogin_issue(struct lpfc_vport *vport,
1437 struct lpfc_nodelist *ndlp,
1438 void *arg,
dea31012005-04-17 16:05:31 -05001439 uint32_t evt)
1440{
James Smart2e0fef82007-06-17 19:56:36 -05001441 struct lpfc_hba *phba = vport->phba;
1442 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
James Smart7054a602007-04-25 09:52:34 -04001443 LPFC_MBOXQ_t *mb;
1444 LPFC_MBOXQ_t *nextmb;
1445 struct lpfc_dmabuf *mp;
dea31012005-04-17 16:05:31 -05001446
1447 cmdiocb = (struct lpfc_iocbq *) arg;
1448
James Smart7054a602007-04-25 09:52:34 -04001449 /* cleanup any ndlp on mbox q waiting for reglogin cmpl */
1450 if ((mb = phba->sli.mbox_active)) {
James Smart04c68492009-05-22 14:52:52 -04001451 if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) &&
James Smart7054a602007-04-25 09:52:34 -04001452 (ndlp == (struct lpfc_nodelist *) mb->context2)) {
James Smart92d7f7b2007-06-17 19:56:38 -05001453 lpfc_nlp_put(ndlp);
James Smart7054a602007-04-25 09:52:34 -04001454 mb->context2 = NULL;
1455 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1456 }
1457 }
1458
James Smart2e0fef82007-06-17 19:56:36 -05001459 spin_lock_irq(&phba->hbalock);
James Smart7054a602007-04-25 09:52:34 -04001460 list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) {
James Smart04c68492009-05-22 14:52:52 -04001461 if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) &&
James Smart7054a602007-04-25 09:52:34 -04001462 (ndlp == (struct lpfc_nodelist *) mb->context2)) {
1463 mp = (struct lpfc_dmabuf *) (mb->context1);
1464 if (mp) {
James Smart98c9ea52007-10-27 13:37:33 -04001465 __lpfc_mbuf_free(phba, mp->virt, mp->phys);
James Smart7054a602007-04-25 09:52:34 -04001466 kfree(mp);
1467 }
James Smart92d7f7b2007-06-17 19:56:38 -05001468 lpfc_nlp_put(ndlp);
James Smart7054a602007-04-25 09:52:34 -04001469 list_del(&mb->list);
James Smart5ffc2662009-11-18 15:39:44 -05001470 phba->sli.mboxq_cnt--;
James Smart7054a602007-04-25 09:52:34 -04001471 mempool_free(mb, phba->mbox_mem_pool);
1472 }
1473 }
James Smart2e0fef82007-06-17 19:56:36 -05001474 spin_unlock_irq(&phba->hbalock);
James Smart7054a602007-04-25 09:52:34 -04001475
James Smart2e0fef82007-06-17 19:56:36 -05001476 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001477 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001478}
1479
1480static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001481lpfc_rcv_padisc_reglogin_issue(struct lpfc_vport *vport,
1482 struct lpfc_nodelist *ndlp,
1483 void *arg,
dea31012005-04-17 16:05:31 -05001484 uint32_t evt)
1485{
James Smart2e0fef82007-06-17 19:56:36 -05001486 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001487
James Smart2e0fef82007-06-17 19:56:36 -05001488 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001489 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001490}
1491
1492static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001493lpfc_rcv_prlo_reglogin_issue(struct lpfc_vport *vport,
1494 struct lpfc_nodelist *ndlp,
1495 void *arg,
dea31012005-04-17 16:05:31 -05001496 uint32_t evt)
1497{
1498 struct lpfc_iocbq *cmdiocb;
1499
1500 cmdiocb = (struct lpfc_iocbq *) arg;
James Smart51ef4c22007-08-02 11:10:31 -04001501 lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001502 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001503}
1504
1505static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001506lpfc_cmpl_reglogin_reglogin_issue(struct lpfc_vport *vport,
1507 struct lpfc_nodelist *ndlp,
1508 void *arg,
1509 uint32_t evt)
dea31012005-04-17 16:05:31 -05001510{
James Smart2e0fef82007-06-17 19:56:36 -05001511 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart2e0fef82007-06-17 19:56:36 -05001512 LPFC_MBOXQ_t *pmb = (LPFC_MBOXQ_t *) arg;
James Smart04c68492009-05-22 14:52:52 -04001513 MAILBOX_t *mb = &pmb->u.mb;
James Smart2e0fef82007-06-17 19:56:36 -05001514 uint32_t did = mb->un.varWords[1];
dea31012005-04-17 16:05:31 -05001515
dea31012005-04-17 16:05:31 -05001516 if (mb->mbxStatus) {
1517 /* RegLogin failed */
James Smarte8b62012007-08-02 11:10:09 -04001518 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
James Smart6d368e52011-05-24 11:44:12 -04001519 "0246 RegLogin failed Data: x%x x%x x%x x%x "
1520 "x%x\n",
1521 did, mb->mbxStatus, vport->port_state,
1522 mb->un.varRegLogin.vpi,
1523 mb->un.varRegLogin.rpi);
James Smartd0e56da2006-07-06 15:49:42 -04001524 /*
1525 * If RegLogin failed due to lack of HBA resources do not
1526 * retry discovery.
1527 */
1528 if (mb->mbxStatus == MBXERR_RPI_FULL) {
James Smart87af33f2007-10-27 13:37:43 -04001529 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
1530 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
James Smartd0e56da2006-07-06 15:49:42 -04001531 return ndlp->nlp_state;
1532 }
1533
James Smart2e0fef82007-06-17 19:56:36 -05001534 /* Put ndlp in npr state set plogi timer for 1 sec */
James Smart256ec0d2013-04-17 20:14:58 -04001535 mod_timer(&ndlp->nlp_delayfunc,
1536 jiffies + msecs_to_jiffies(1000 * 1));
James Smart2e0fef82007-06-17 19:56:36 -05001537 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001538 ndlp->nlp_flag |= NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05001539 spin_unlock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001540 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
dea31012005-04-17 16:05:31 -05001541
James Smart2e0fef82007-06-17 19:56:36 -05001542 lpfc_issue_els_logo(vport, ndlp, 0);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001543 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -05001544 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001545 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001546 }
1547
James Smart6d368e52011-05-24 11:44:12 -04001548 /* SLI4 ports have preallocated logical rpis. */
1549 if (vport->phba->sli_rev < LPFC_SLI_REV4)
1550 ndlp->nlp_rpi = mb->un.varWords[0];
1551
James Smart40426292010-12-15 17:58:10 -05001552 ndlp->nlp_flag |= NLP_RPI_REGISTERED;
dea31012005-04-17 16:05:31 -05001553
1554 /* Only if we are not a fabric nport do we issue PRLI */
1555 if (!(ndlp->nlp_type & NLP_FABRIC)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001556 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -05001557 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
1558 lpfc_issue_els_prli(vport, ndlp, 0);
dea31012005-04-17 16:05:31 -05001559 } else {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001560 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -05001561 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
dea31012005-04-17 16:05:31 -05001562 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001563 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001564}
1565
1566static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001567lpfc_device_rm_reglogin_issue(struct lpfc_vport *vport,
1568 struct lpfc_nodelist *ndlp,
1569 void *arg,
dea31012005-04-17 16:05:31 -05001570 uint32_t evt)
1571{
James Smart2e0fef82007-06-17 19:56:36 -05001572 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1573
1574 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1575 spin_lock_irq(shost->host_lock);
James Smarta0f9b482006-04-15 11:52:56 -04001576 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
James Smart2e0fef82007-06-17 19:56:36 -05001577 spin_unlock_irq(shost->host_lock);
James Smarta0f9b482006-04-15 11:52:56 -04001578 return ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05001579 } else {
1580 lpfc_drop_node(vport, ndlp);
James Smarta0f9b482006-04-15 11:52:56 -04001581 return NLP_STE_FREED_NODE;
1582 }
dea31012005-04-17 16:05:31 -05001583}
1584
1585static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001586lpfc_device_recov_reglogin_issue(struct lpfc_vport *vport,
1587 struct lpfc_nodelist *ndlp,
1588 void *arg,
1589 uint32_t evt)
dea31012005-04-17 16:05:31 -05001590{
James Smart2e0fef82007-06-17 19:56:36 -05001591 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1592
James Smart92d7f7b2007-06-17 19:56:38 -05001593 /* Don't do anything that will mess up processing of the
1594 * previous RSCN.
1595 */
1596 if (vport->fc_flag & FC_RSCN_DEFERRED)
1597 return ndlp->nlp_state;
1598
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001599 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -05001600 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1601 spin_lock_irq(shost->host_lock);
James Smartffc95492010-06-07 15:23:17 -04001602 ndlp->nlp_flag |= NLP_IGNR_REG_CMPL;
James Smarta0f9b482006-04-15 11:52:56 -04001603 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
James Smart2e0fef82007-06-17 19:56:36 -05001604 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05001605 lpfc_disc_set_adisc(vport, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001606 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001607}
1608
1609static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001610lpfc_rcv_plogi_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1611 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001612{
1613 struct lpfc_iocbq *cmdiocb;
1614
1615 cmdiocb = (struct lpfc_iocbq *) arg;
1616
James Smart2e0fef82007-06-17 19:56:36 -05001617 lpfc_rcv_plogi(vport, ndlp, cmdiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001618 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001619}
1620
1621static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001622lpfc_rcv_prli_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1623 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001624{
James Smart2e0fef82007-06-17 19:56:36 -05001625 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001626
James Smart2e0fef82007-06-17 19:56:36 -05001627 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001628 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001629}
1630
1631static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001632lpfc_rcv_logo_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1633 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001634{
James Smart2e0fef82007-06-17 19:56:36 -05001635 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001636
1637 /* Software abort outstanding PRLI before sending acc */
James Smart2e0fef82007-06-17 19:56:36 -05001638 lpfc_els_abort(vport->phba, ndlp);
dea31012005-04-17 16:05:31 -05001639
James Smart2e0fef82007-06-17 19:56:36 -05001640 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001641 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001642}
1643
1644static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001645lpfc_rcv_padisc_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1646 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001647{
James Smart2e0fef82007-06-17 19:56:36 -05001648 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001649
James Smart2e0fef82007-06-17 19:56:36 -05001650 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001651 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001652}
1653
1654/* This routine is envoked when we rcv a PRLO request from a nport
1655 * we are logged into. We should send back a PRLO rsp setting the
1656 * appropriate bits.
1657 * NEXT STATE = PRLI_ISSUE
1658 */
1659static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001660lpfc_rcv_prlo_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1661 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001662{
James Smart2e0fef82007-06-17 19:56:36 -05001663 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001664
James Smart51ef4c22007-08-02 11:10:31 -04001665 lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001666 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001667}
1668
1669static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001670lpfc_cmpl_prli_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1671 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001672{
James Smart92d7f7b2007-06-17 19:56:38 -05001673 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001674 struct lpfc_iocbq *cmdiocb, *rspiocb;
James Smart2e0fef82007-06-17 19:56:36 -05001675 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001676 IOCB_t *irsp;
1677 PRLI *npr;
1678
1679 cmdiocb = (struct lpfc_iocbq *) arg;
1680 rspiocb = cmdiocb->context_un.rsp_iocb;
1681 npr = (PRLI *)lpfc_check_elscmpl_iocb(phba, cmdiocb, rspiocb);
1682
1683 irsp = &rspiocb->iocb;
1684 if (irsp->ulpStatus) {
James Smart858c9f62007-06-17 19:56:39 -05001685 if ((vport->port_type == LPFC_NPIV_PORT) &&
James Smart3de2a652007-08-02 11:09:59 -04001686 vport->cfg_restrict_login) {
James Smart858c9f62007-06-17 19:56:39 -05001687 goto out;
1688 }
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001689 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -05001690 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001691 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001692 }
1693
1694 /* Check out PRLI rsp */
1695 ndlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR);
1696 ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
James Smart3cb01c52013-07-15 18:35:04 -04001697 ndlp->nlp_flag &= ~NLP_FIRSTBURST;
dea31012005-04-17 16:05:31 -05001698 if ((npr->acceptRspCode == PRLI_REQ_EXECUTED) &&
1699 (npr->prliType == PRLI_FCP_TYPE)) {
1700 if (npr->initiatorFunc)
1701 ndlp->nlp_type |= NLP_FCP_INITIATOR;
James Smart3cb01c52013-07-15 18:35:04 -04001702 if (npr->targetFunc) {
dea31012005-04-17 16:05:31 -05001703 ndlp->nlp_type |= NLP_FCP_TARGET;
James Smart3cb01c52013-07-15 18:35:04 -04001704 if (npr->writeXferRdyDis)
1705 ndlp->nlp_flag |= NLP_FIRSTBURST;
1706 }
dea31012005-04-17 16:05:31 -05001707 if (npr->Retry)
1708 ndlp->nlp_fcp_info |= NLP_FCP_2_DEVICE;
1709 }
James Smart92d7f7b2007-06-17 19:56:38 -05001710 if (!(ndlp->nlp_type & NLP_FCP_TARGET) &&
1711 (vport->port_type == LPFC_NPIV_PORT) &&
James Smart3de2a652007-08-02 11:09:59 -04001712 vport->cfg_restrict_login) {
James Smart858c9f62007-06-17 19:56:39 -05001713out:
James Smart92d7f7b2007-06-17 19:56:38 -05001714 spin_lock_irq(shost->host_lock);
1715 ndlp->nlp_flag |= NLP_TARGET_REMOVE;
1716 spin_unlock_irq(shost->host_lock);
1717 lpfc_issue_els_logo(vport, ndlp, 0);
1718
1719 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
James Smart87af33f2007-10-27 13:37:43 -04001720 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
James Smart92d7f7b2007-06-17 19:56:38 -05001721 return ndlp->nlp_state;
1722 }
dea31012005-04-17 16:05:31 -05001723
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001724 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
James Smart92d7f7b2007-06-17 19:56:38 -05001725 if (ndlp->nlp_type & NLP_FCP_TARGET)
1726 lpfc_nlp_set_state(vport, ndlp, NLP_STE_MAPPED_NODE);
1727 else
1728 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001729 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001730}
1731
1732/*! lpfc_device_rm_prli_issue
James Smart92d7f7b2007-06-17 19:56:38 -05001733 *
1734 * \pre
1735 * \post
1736 * \param phba
1737 * \param ndlp
1738 * \param arg
1739 * \param evt
1740 * \return uint32_t
1741 *
1742 * \b Description:
1743 * This routine is envoked when we a request to remove a nport we are in the
1744 * process of PRLIing. We should software abort outstanding prli, unreg
1745 * login, send a logout. We will change node state to UNUSED_NODE, put it
1746 * on plogi list so it can be freed when LOGO completes.
1747 *
1748 */
1749
dea31012005-04-17 16:05:31 -05001750static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001751lpfc_device_rm_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1752 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001753{
James Smart2e0fef82007-06-17 19:56:36 -05001754 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001755
James Smart2e0fef82007-06-17 19:56:36 -05001756 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1757 spin_lock_irq(shost->host_lock);
1758 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
1759 spin_unlock_irq(shost->host_lock);
1760 return ndlp->nlp_state;
1761 } else {
1762 /* software abort outstanding PLOGI */
1763 lpfc_els_abort(vport->phba, ndlp);
1764
1765 lpfc_drop_node(vport, ndlp);
James Smarta0f9b482006-04-15 11:52:56 -04001766 return NLP_STE_FREED_NODE;
1767 }
dea31012005-04-17 16:05:31 -05001768}
1769
1770
1771/*! lpfc_device_recov_prli_issue
James Smart92d7f7b2007-06-17 19:56:38 -05001772 *
1773 * \pre
1774 * \post
1775 * \param phba
1776 * \param ndlp
1777 * \param arg
1778 * \param evt
1779 * \return uint32_t
1780 *
1781 * \b Description:
1782 * The routine is envoked when the state of a device is unknown, like
1783 * during a link down. We should remove the nodelist entry from the
1784 * unmapped list, issue a UNREG_LOGIN, do a software abort of the
1785 * outstanding PRLI command, then free the node entry.
1786 */
dea31012005-04-17 16:05:31 -05001787static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001788lpfc_device_recov_prli_issue(struct lpfc_vport *vport,
1789 struct lpfc_nodelist *ndlp,
1790 void *arg,
1791 uint32_t evt)
dea31012005-04-17 16:05:31 -05001792{
James Smart2e0fef82007-06-17 19:56:36 -05001793 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1794 struct lpfc_hba *phba = vport->phba;
1795
James Smart92d7f7b2007-06-17 19:56:38 -05001796 /* Don't do anything that will mess up processing of the
1797 * previous RSCN.
1798 */
1799 if (vport->fc_flag & FC_RSCN_DEFERRED)
1800 return ndlp->nlp_state;
1801
dea31012005-04-17 16:05:31 -05001802 /* software abort outstanding PRLI */
James Smart07951072007-04-25 09:51:38 -04001803 lpfc_els_abort(phba, ndlp);
dea31012005-04-17 16:05:31 -05001804
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001805 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -05001806 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1807 spin_lock_irq(shost->host_lock);
James Smarta0f9b482006-04-15 11:52:56 -04001808 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
James Smart2e0fef82007-06-17 19:56:36 -05001809 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05001810 lpfc_disc_set_adisc(vport, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001811 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001812}
1813
1814static uint32_t
James Smart086a3452012-08-14 14:25:21 -04001815lpfc_rcv_plogi_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1816 void *arg, uint32_t evt)
1817{
1818 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *)arg;
1819 struct ls_rjt stat;
1820
1821 memset(&stat, 0, sizeof(struct ls_rjt));
1822 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
1823 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
1824 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
1825 return ndlp->nlp_state;
1826}
1827
1828static uint32_t
1829lpfc_rcv_prli_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1830 void *arg, uint32_t evt)
1831{
1832 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *)arg;
1833 struct ls_rjt stat;
1834
1835 memset(&stat, 0, sizeof(struct ls_rjt));
1836 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
1837 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
1838 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
1839 return ndlp->nlp_state;
1840}
1841
1842static uint32_t
1843lpfc_rcv_logo_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1844 void *arg, uint32_t evt)
1845{
1846 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1847 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *)arg;
1848
1849 spin_lock_irq(shost->host_lock);
1850 ndlp->nlp_flag &= NLP_LOGO_ACC;
1851 spin_unlock_irq(shost->host_lock);
1852 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
1853 return ndlp->nlp_state;
1854}
1855
1856static uint32_t
1857lpfc_rcv_padisc_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1858 void *arg, uint32_t evt)
1859{
1860 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *)arg;
1861 struct ls_rjt stat;
1862
1863 memset(&stat, 0, sizeof(struct ls_rjt));
1864 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
1865 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
1866 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
1867 return ndlp->nlp_state;
1868}
1869
1870static uint32_t
1871lpfc_rcv_prlo_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1872 void *arg, uint32_t evt)
1873{
1874 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *)arg;
1875 struct ls_rjt stat;
1876
1877 memset(&stat, 0, sizeof(struct ls_rjt));
1878 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
1879 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
1880 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
1881 return ndlp->nlp_state;
1882}
1883
1884static uint32_t
1885lpfc_cmpl_logo_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1886 void *arg, uint32_t evt)
1887{
1888 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1889
1890 ndlp->nlp_prev_state = NLP_STE_LOGO_ISSUE;
1891 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1892 spin_lock_irq(shost->host_lock);
1893 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
1894 spin_unlock_irq(shost->host_lock);
1895 lpfc_disc_set_adisc(vport, ndlp);
1896 return ndlp->nlp_state;
1897}
1898
1899static uint32_t
1900lpfc_device_rm_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1901 void *arg, uint32_t evt)
1902{
1903 /*
1904 * Take no action. If a LOGO is outstanding, then possibly DevLoss has
1905 * timed out and is calling for Device Remove. In this case, the LOGO
1906 * must be allowed to complete in state LOGO_ISSUE so that the rpi
1907 * and other NLP flags are correctly cleaned up.
1908 */
1909 return ndlp->nlp_state;
1910}
1911
1912static uint32_t
1913lpfc_device_recov_logo_issue(struct lpfc_vport *vport,
1914 struct lpfc_nodelist *ndlp,
1915 void *arg, uint32_t evt)
1916{
1917 /*
1918 * Device Recovery events have no meaning for a node with a LOGO
1919 * outstanding. The LOGO has to complete first and handle the
1920 * node from that point.
1921 */
1922 return ndlp->nlp_state;
1923}
1924
1925static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001926lpfc_rcv_plogi_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1927 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001928{
James Smart2e0fef82007-06-17 19:56:36 -05001929 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001930
James Smart2e0fef82007-06-17 19:56:36 -05001931 lpfc_rcv_plogi(vport, ndlp, cmdiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001932 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001933}
1934
1935static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001936lpfc_rcv_prli_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1937 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001938{
James Smart2e0fef82007-06-17 19:56:36 -05001939 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001940
James Smart2e0fef82007-06-17 19:56:36 -05001941 lpfc_rcv_prli(vport, ndlp, cmdiocb);
1942 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001943 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001944}
1945
1946static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001947lpfc_rcv_logo_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1948 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001949{
James Smart2e0fef82007-06-17 19:56:36 -05001950 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001951
James Smart2e0fef82007-06-17 19:56:36 -05001952 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001953 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001954}
1955
1956static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001957lpfc_rcv_padisc_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1958 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001959{
James Smart2e0fef82007-06-17 19:56:36 -05001960 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001961
James Smart2e0fef82007-06-17 19:56:36 -05001962 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001963 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001964}
1965
1966static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001967lpfc_rcv_prlo_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1968 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001969{
James Smart2e0fef82007-06-17 19:56:36 -05001970 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001971
James Smart51ef4c22007-08-02 11:10:31 -04001972 lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001973 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001974}
1975
1976static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001977lpfc_device_recov_unmap_node(struct lpfc_vport *vport,
1978 struct lpfc_nodelist *ndlp,
1979 void *arg,
1980 uint32_t evt)
dea31012005-04-17 16:05:31 -05001981{
James Smart2e0fef82007-06-17 19:56:36 -05001982 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1983
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001984 ndlp->nlp_prev_state = NLP_STE_UNMAPPED_NODE;
James Smart2e0fef82007-06-17 19:56:36 -05001985 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1986 spin_lock_irq(shost->host_lock);
James Smarta0f9b482006-04-15 11:52:56 -04001987 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
James Smart2e0fef82007-06-17 19:56:36 -05001988 spin_unlock_irq(shost->host_lock);
1989 lpfc_disc_set_adisc(vport, ndlp);
dea31012005-04-17 16:05:31 -05001990
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001991 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001992}
1993
1994static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001995lpfc_rcv_plogi_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1996 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001997{
James Smart2e0fef82007-06-17 19:56:36 -05001998 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001999
James Smart2e0fef82007-06-17 19:56:36 -05002000 lpfc_rcv_plogi(vport, ndlp, cmdiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002001 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05002002}
2003
2004static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05002005lpfc_rcv_prli_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2006 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05002007{
James Smart2e0fef82007-06-17 19:56:36 -05002008 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05002009
James Smart2e0fef82007-06-17 19:56:36 -05002010 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002011 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05002012}
2013
2014static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05002015lpfc_rcv_logo_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2016 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05002017{
James Smart2e0fef82007-06-17 19:56:36 -05002018 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05002019
James Smart2e0fef82007-06-17 19:56:36 -05002020 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002021 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05002022}
2023
2024static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05002025lpfc_rcv_padisc_mapped_node(struct lpfc_vport *vport,
2026 struct lpfc_nodelist *ndlp,
2027 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05002028{
James Smart2e0fef82007-06-17 19:56:36 -05002029 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05002030
James Smart2e0fef82007-06-17 19:56:36 -05002031 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002032 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05002033}
2034
2035static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05002036lpfc_rcv_prlo_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2037 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05002038{
James Smart2e0fef82007-06-17 19:56:36 -05002039 struct lpfc_hba *phba = vport->phba;
2040 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05002041
2042 /* flush the target */
James Smart51ef4c22007-08-02 11:10:31 -04002043 lpfc_sli_abort_iocb(vport, &phba->sli.ring[phba->sli.fcp_ring],
2044 ndlp->nlp_sid, 0, LPFC_CTX_TGT);
dea31012005-04-17 16:05:31 -05002045
2046 /* Treat like rcv logo */
James Smart2e0fef82007-06-17 19:56:36 -05002047 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_PRLO);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002048 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05002049}
2050
2051static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05002052lpfc_device_recov_mapped_node(struct lpfc_vport *vport,
2053 struct lpfc_nodelist *ndlp,
2054 void *arg,
2055 uint32_t evt)
dea31012005-04-17 16:05:31 -05002056{
James Smart2e0fef82007-06-17 19:56:36 -05002057 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2058
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002059 ndlp->nlp_prev_state = NLP_STE_MAPPED_NODE;
James Smart2e0fef82007-06-17 19:56:36 -05002060 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
2061 spin_lock_irq(shost->host_lock);
James Smarta0f9b482006-04-15 11:52:56 -04002062 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
James Smart2e0fef82007-06-17 19:56:36 -05002063 spin_unlock_irq(shost->host_lock);
2064 lpfc_disc_set_adisc(vport, ndlp);
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_plogi_npr_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 Scsi_Host *shost = lpfc_shost_from_vport(vport);
2073 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05002074
2075 /* Ignore PLOGI if we have an outstanding LOGO */
James Smart0d2b6b82008-06-14 22:52:47 -04002076 if (ndlp->nlp_flag & (NLP_LOGO_SND | NLP_LOGO_ACC))
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002077 return ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002078 if (lpfc_rcv_plogi(vport, ndlp, cmdiocb)) {
James Smart0d2b6b82008-06-14 22:52:47 -04002079 lpfc_cancel_retry_delay_tmo(vport, ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05002080 spin_lock_irq(shost->host_lock);
James Smart0d2b6b82008-06-14 22:52:47 -04002081 ndlp->nlp_flag &= ~(NLP_NPR_ADISC | NLP_NPR_2B_DISC);
James Smart2e0fef82007-06-17 19:56:36 -05002082 spin_unlock_irq(shost->host_lock);
James Smart0d2b6b82008-06-14 22:52:47 -04002083 } else if (!(ndlp->nlp_flag & NLP_NPR_2B_DISC)) {
2084 /* send PLOGI immediately, move to PLOGI issue state */
2085 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
2086 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
2087 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
2088 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
2089 }
dea31012005-04-17 16:05:31 -05002090 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002091 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05002092}
2093
2094static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05002095lpfc_rcv_prli_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2096 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05002097{
James Smart2e0fef82007-06-17 19:56:36 -05002098 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2099 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2100 struct ls_rjt stat;
dea31012005-04-17 16:05:31 -05002101
2102 memset(&stat, 0, sizeof (struct ls_rjt));
2103 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
2104 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
James Smart858c9f62007-06-17 19:56:39 -05002105 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05002106
2107 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
2108 if (ndlp->nlp_flag & NLP_NPR_ADISC) {
James Smart2e0fef82007-06-17 19:56:36 -05002109 spin_lock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002110 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002111 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
James Smart2e0fef82007-06-17 19:56:36 -05002112 spin_unlock_irq(shost->host_lock);
2113 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
2114 lpfc_issue_els_adisc(vport, ndlp, 0);
dea31012005-04-17 16:05:31 -05002115 } else {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002116 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
James Smart2e0fef82007-06-17 19:56:36 -05002117 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
2118 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
dea31012005-04-17 16:05:31 -05002119 }
2120 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002121 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05002122}
2123
2124static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05002125lpfc_rcv_logo_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2126 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05002127{
James Smart2e0fef82007-06-17 19:56:36 -05002128 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05002129
James Smart2e0fef82007-06-17 19:56:36 -05002130 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002131 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05002132}
2133
2134static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05002135lpfc_rcv_padisc_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2136 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05002137{
James Smart2e0fef82007-06-17 19:56:36 -05002138 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05002139
James Smart2e0fef82007-06-17 19:56:36 -05002140 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
James Smart33ccf8d2006-08-17 11:57:58 -04002141 /*
2142 * Do not start discovery if discovery is about to start
2143 * or discovery in progress for this node. Starting discovery
2144 * here will affect the counting of discovery threads.
2145 */
James Smart2fb9bd82006-12-02 13:33:57 -05002146 if (!(ndlp->nlp_flag & NLP_DELAY_TMO) &&
James Smart92d7f7b2007-06-17 19:56:38 -05002147 !(ndlp->nlp_flag & NLP_NPR_2B_DISC)) {
dea31012005-04-17 16:05:31 -05002148 if (ndlp->nlp_flag & NLP_NPR_ADISC) {
James Smart92d7f7b2007-06-17 19:56:38 -05002149 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002150 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
James Smart2e0fef82007-06-17 19:56:36 -05002151 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
2152 lpfc_issue_els_adisc(vport, ndlp, 0);
dea31012005-04-17 16:05:31 -05002153 } else {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002154 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
James Smart2e0fef82007-06-17 19:56:36 -05002155 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
2156 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
dea31012005-04-17 16:05:31 -05002157 }
2158 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002159 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05002160}
2161
2162static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05002163lpfc_rcv_prlo_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2164 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05002165{
James Smart2e0fef82007-06-17 19:56:36 -05002166 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2167 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05002168
James Smart2e0fef82007-06-17 19:56:36 -05002169 spin_lock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002170 ndlp->nlp_flag |= NLP_LOGO_ACC;
James Smart2e0fef82007-06-17 19:56:36 -05002171 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002172
James Smart51ef4c22007-08-02 11:10:31 -04002173 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05002174
James Smart2e0fef82007-06-17 19:56:36 -05002175 if ((ndlp->nlp_flag & NLP_DELAY_TMO) == 0) {
James Smart256ec0d2013-04-17 20:14:58 -04002176 mod_timer(&ndlp->nlp_delayfunc,
2177 jiffies + msecs_to_jiffies(1000 * 1));
James Smart2e0fef82007-06-17 19:56:36 -05002178 spin_lock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002179 ndlp->nlp_flag |= NLP_DELAY_TMO;
2180 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
James Smart2e0fef82007-06-17 19:56:36 -05002181 spin_unlock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002182 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002183 } else {
James Smart2e0fef82007-06-17 19:56:36 -05002184 spin_lock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002185 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
James Smart2e0fef82007-06-17 19:56:36 -05002186 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002187 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002188 return ndlp->nlp_state;
2189}
dea31012005-04-17 16:05:31 -05002190
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002191static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05002192lpfc_cmpl_plogi_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2193 void *arg, uint32_t evt)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002194{
2195 struct lpfc_iocbq *cmdiocb, *rspiocb;
James Smarta0f9b482006-04-15 11:52:56 -04002196 IOCB_t *irsp;
James Smart8b455cf2013-01-03 15:43:53 -05002197 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002198
2199 cmdiocb = (struct lpfc_iocbq *) arg;
2200 rspiocb = cmdiocb->context_un.rsp_iocb;
James Smarta0f9b482006-04-15 11:52:56 -04002201
2202 irsp = &rspiocb->iocb;
2203 if (irsp->ulpStatus) {
James Smart8b455cf2013-01-03 15:43:53 -05002204 spin_lock_irq(shost->host_lock);
James Smarta8adb832007-10-27 13:37:53 -04002205 ndlp->nlp_flag |= NLP_DEFER_RM;
James Smart8b455cf2013-01-03 15:43:53 -05002206 spin_unlock_irq(shost->host_lock);
James Smarta0f9b482006-04-15 11:52:56 -04002207 return NLP_STE_FREED_NODE;
2208 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002209 return ndlp->nlp_state;
2210}
2211
2212static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05002213lpfc_cmpl_prli_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2214 void *arg, uint32_t evt)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002215{
2216 struct lpfc_iocbq *cmdiocb, *rspiocb;
James Smarta0f9b482006-04-15 11:52:56 -04002217 IOCB_t *irsp;
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002218
2219 cmdiocb = (struct lpfc_iocbq *) arg;
2220 rspiocb = cmdiocb->context_un.rsp_iocb;
James Smarta0f9b482006-04-15 11:52:56 -04002221
2222 irsp = &rspiocb->iocb;
2223 if (irsp->ulpStatus && (ndlp->nlp_flag & NLP_NODEV_REMOVE)) {
James Smart2e0fef82007-06-17 19:56:36 -05002224 lpfc_drop_node(vport, ndlp);
James Smarta0f9b482006-04-15 11:52:56 -04002225 return NLP_STE_FREED_NODE;
2226 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002227 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05002228}
2229
2230static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05002231lpfc_cmpl_logo_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2232 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05002233{
James Smartd7c255b2008-08-24 21:50:00 -04002234 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart086a3452012-08-14 14:25:21 -04002235
2236 /* For the fabric port just clear the fc flags. */
James Smartd7c255b2008-08-24 21:50:00 -04002237 if (ndlp->nlp_DID == Fabric_DID) {
2238 spin_lock_irq(shost->host_lock);
2239 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
2240 spin_unlock_irq(shost->host_lock);
2241 }
James Smart2e0fef82007-06-17 19:56:36 -05002242 lpfc_unreg_rpi(vport, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002243 return ndlp->nlp_state;
2244}
2245
2246static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05002247lpfc_cmpl_adisc_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2248 void *arg, uint32_t evt)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002249{
2250 struct lpfc_iocbq *cmdiocb, *rspiocb;
James Smarta0f9b482006-04-15 11:52:56 -04002251 IOCB_t *irsp;
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002252
2253 cmdiocb = (struct lpfc_iocbq *) arg;
2254 rspiocb = cmdiocb->context_un.rsp_iocb;
James Smarta0f9b482006-04-15 11:52:56 -04002255
2256 irsp = &rspiocb->iocb;
2257 if (irsp->ulpStatus && (ndlp->nlp_flag & NLP_NODEV_REMOVE)) {
James Smart2e0fef82007-06-17 19:56:36 -05002258 lpfc_drop_node(vport, ndlp);
James Smarta0f9b482006-04-15 11:52:56 -04002259 return NLP_STE_FREED_NODE;
2260 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002261 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05002262}
2263
2264static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05002265lpfc_cmpl_reglogin_npr_node(struct lpfc_vport *vport,
2266 struct lpfc_nodelist *ndlp,
2267 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05002268{
James Smart2e0fef82007-06-17 19:56:36 -05002269 LPFC_MBOXQ_t *pmb = (LPFC_MBOXQ_t *) arg;
James Smart04c68492009-05-22 14:52:52 -04002270 MAILBOX_t *mb = &pmb->u.mb;
dea31012005-04-17 16:05:31 -05002271
James Smart04c68492009-05-22 14:52:52 -04002272 if (!mb->mbxStatus) {
James Smart6d368e52011-05-24 11:44:12 -04002273 /* SLI4 ports have preallocated logical rpis. */
2274 if (vport->phba->sli_rev < LPFC_SLI_REV4)
2275 ndlp->nlp_rpi = mb->un.varWords[0];
James Smart40426292010-12-15 17:58:10 -05002276 ndlp->nlp_flag |= NLP_RPI_REGISTERED;
James Smart04c68492009-05-22 14:52:52 -04002277 } else {
James Smarta0f9b482006-04-15 11:52:56 -04002278 if (ndlp->nlp_flag & NLP_NODEV_REMOVE) {
James Smart2e0fef82007-06-17 19:56:36 -05002279 lpfc_drop_node(vport, ndlp);
James Smarta0f9b482006-04-15 11:52:56 -04002280 return NLP_STE_FREED_NODE;
2281 }
2282 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002283 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05002284}
2285
2286static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05002287lpfc_device_rm_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2288 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05002289{
James Smart2e0fef82007-06-17 19:56:36 -05002290 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2291
James Smarta0f9b482006-04-15 11:52:56 -04002292 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
James Smart2e0fef82007-06-17 19:56:36 -05002293 spin_lock_irq(shost->host_lock);
James Smarta0f9b482006-04-15 11:52:56 -04002294 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
James Smart2e0fef82007-06-17 19:56:36 -05002295 spin_unlock_irq(shost->host_lock);
James Smarta0f9b482006-04-15 11:52:56 -04002296 return ndlp->nlp_state;
2297 }
James Smart2e0fef82007-06-17 19:56:36 -05002298 lpfc_drop_node(vport, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002299 return NLP_STE_FREED_NODE;
dea31012005-04-17 16:05:31 -05002300}
2301
2302static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05002303lpfc_device_recov_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2304 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05002305{
James Smart2e0fef82007-06-17 19:56:36 -05002306 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2307
James Smart92d7f7b2007-06-17 19:56:38 -05002308 /* Don't do anything that will mess up processing of the
2309 * previous RSCN.
2310 */
2311 if (vport->fc_flag & FC_RSCN_DEFERRED)
2312 return ndlp->nlp_state;
2313
James Smarteaf15d52008-12-04 22:39:29 -05002314 lpfc_cancel_retry_delay_tmo(vport, ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05002315 spin_lock_irq(shost->host_lock);
James Smarta0f9b482006-04-15 11:52:56 -04002316 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
James Smart2e0fef82007-06-17 19:56:36 -05002317 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002318 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05002319}
2320
2321
2322/* This next section defines the NPort Discovery State Machine */
2323
2324/* There are 4 different double linked lists nodelist entries can reside on.
2325 * The plogi list and adisc list are used when Link Up discovery or RSCN
2326 * processing is needed. Each list holds the nodes that we will send PLOGI
2327 * or ADISC on. These lists will keep track of what nodes will be effected
2328 * by an RSCN, or a Link Up (Typically, all nodes are effected on Link Up).
2329 * The unmapped_list will contain all nodes that we have successfully logged
2330 * into at the Fibre Channel level. The mapped_list will contain all nodes
2331 * that are mapped FCP targets.
2332 */
2333/*
2334 * The bind list is a list of undiscovered (potentially non-existent) nodes
2335 * that we have saved binding information on. This information is used when
2336 * nodes transition from the unmapped to the mapped list.
2337 */
2338/* For UNUSED_NODE state, the node has just been allocated .
2339 * For PLOGI_ISSUE and REG_LOGIN_ISSUE, the node is on
2340 * the PLOGI list. For REG_LOGIN_COMPL, the node is taken off the PLOGI list
2341 * and put on the unmapped list. For ADISC processing, the node is taken off
2342 * the ADISC list and placed on either the mapped or unmapped list (depending
2343 * on its previous state). Once on the unmapped list, a PRLI is issued and the
2344 * state changed to PRLI_ISSUE. When the PRLI completion occurs, the state is
2345 * changed to UNMAPPED_NODE. If the completion indicates a mapped
2346 * node, the node is taken off the unmapped list. The binding list is checked
2347 * for a valid binding, or a binding is automatically assigned. If binding
2348 * assignment is unsuccessful, the node is left on the unmapped list. If
2349 * binding assignment is successful, the associated binding list entry (if
2350 * any) is removed, and the node is placed on the mapped list.
2351 */
2352/*
2353 * For a Link Down, all nodes on the ADISC, PLOGI, unmapped or mapped
James Smartc01f3202006-08-18 17:47:08 -04002354 * lists will receive a DEVICE_RECOVERY event. If the linkdown or devloss timers
dea31012005-04-17 16:05:31 -05002355 * expire, all effected nodes will receive a DEVICE_RM event.
2356 */
2357/*
2358 * For a Link Up or RSCN, all nodes will move from the mapped / unmapped lists
2359 * to either the ADISC or PLOGI list. After a Nameserver query or ALPA loopmap
2360 * check, additional nodes may be added or removed (via DEVICE_RM) to / from
2361 * the PLOGI or ADISC lists. Once the PLOGI and ADISC lists are populated,
2362 * we will first process the ADISC list. 32 entries are processed initially and
2363 * ADISC is initited for each one. Completions / Events for each node are
2364 * funnelled thru the state machine. As each node finishes ADISC processing, it
2365 * starts ADISC for any nodes waiting for ADISC processing. If no nodes are
2366 * waiting, and the ADISC list count is identically 0, then we are done. For
2367 * Link Up discovery, since all nodes on the PLOGI list are UNREG_LOGIN'ed, we
2368 * can issue a CLEAR_LA and reenable Link Events. Next we will process the PLOGI
2369 * list. 32 entries are processed initially and PLOGI is initited for each one.
2370 * Completions / Events for each node are funnelled thru the state machine. As
2371 * each node finishes PLOGI processing, it starts PLOGI for any nodes waiting
2372 * for PLOGI processing. If no nodes are waiting, and the PLOGI list count is
2373 * indentically 0, then we are done. We have now completed discovery / RSCN
2374 * handling. Upon completion, ALL nodes should be on either the mapped or
2375 * unmapped lists.
2376 */
2377
2378static uint32_t (*lpfc_disc_action[NLP_STE_MAX_STATE * NLP_EVT_MAX_EVENT])
James Smart2e0fef82007-06-17 19:56:36 -05002379 (struct lpfc_vport *, struct lpfc_nodelist *, void *, uint32_t) = {
dea31012005-04-17 16:05:31 -05002380 /* Action routine Event Current State */
2381 lpfc_rcv_plogi_unused_node, /* RCV_PLOGI UNUSED_NODE */
2382 lpfc_rcv_els_unused_node, /* RCV_PRLI */
2383 lpfc_rcv_logo_unused_node, /* RCV_LOGO */
2384 lpfc_rcv_els_unused_node, /* RCV_ADISC */
2385 lpfc_rcv_els_unused_node, /* RCV_PDISC */
2386 lpfc_rcv_els_unused_node, /* RCV_PRLO */
2387 lpfc_disc_illegal, /* CMPL_PLOGI */
2388 lpfc_disc_illegal, /* CMPL_PRLI */
2389 lpfc_cmpl_logo_unused_node, /* CMPL_LOGO */
2390 lpfc_disc_illegal, /* CMPL_ADISC */
2391 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2392 lpfc_device_rm_unused_node, /* DEVICE_RM */
James Smartdf9e1b52011-12-13 13:22:17 -05002393 lpfc_device_recov_unused_node, /* DEVICE_RECOVERY */
dea31012005-04-17 16:05:31 -05002394
2395 lpfc_rcv_plogi_plogi_issue, /* RCV_PLOGI PLOGI_ISSUE */
James Smart92d7f7b2007-06-17 19:56:38 -05002396 lpfc_rcv_prli_plogi_issue, /* RCV_PRLI */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002397 lpfc_rcv_logo_plogi_issue, /* RCV_LOGO */
dea31012005-04-17 16:05:31 -05002398 lpfc_rcv_els_plogi_issue, /* RCV_ADISC */
2399 lpfc_rcv_els_plogi_issue, /* RCV_PDISC */
2400 lpfc_rcv_els_plogi_issue, /* RCV_PRLO */
2401 lpfc_cmpl_plogi_plogi_issue, /* CMPL_PLOGI */
2402 lpfc_disc_illegal, /* CMPL_PRLI */
James Smart0ff10d42008-01-11 01:52:36 -05002403 lpfc_cmpl_logo_plogi_issue, /* CMPL_LOGO */
dea31012005-04-17 16:05:31 -05002404 lpfc_disc_illegal, /* CMPL_ADISC */
James Smart0ff10d42008-01-11 01:52:36 -05002405 lpfc_cmpl_reglogin_plogi_issue,/* CMPL_REG_LOGIN */
dea31012005-04-17 16:05:31 -05002406 lpfc_device_rm_plogi_issue, /* DEVICE_RM */
2407 lpfc_device_recov_plogi_issue, /* DEVICE_RECOVERY */
2408
2409 lpfc_rcv_plogi_adisc_issue, /* RCV_PLOGI ADISC_ISSUE */
2410 lpfc_rcv_prli_adisc_issue, /* RCV_PRLI */
2411 lpfc_rcv_logo_adisc_issue, /* RCV_LOGO */
2412 lpfc_rcv_padisc_adisc_issue, /* RCV_ADISC */
2413 lpfc_rcv_padisc_adisc_issue, /* RCV_PDISC */
2414 lpfc_rcv_prlo_adisc_issue, /* RCV_PRLO */
2415 lpfc_disc_illegal, /* CMPL_PLOGI */
2416 lpfc_disc_illegal, /* CMPL_PRLI */
2417 lpfc_disc_illegal, /* CMPL_LOGO */
2418 lpfc_cmpl_adisc_adisc_issue, /* CMPL_ADISC */
2419 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2420 lpfc_device_rm_adisc_issue, /* DEVICE_RM */
2421 lpfc_device_recov_adisc_issue, /* DEVICE_RECOVERY */
2422
2423 lpfc_rcv_plogi_reglogin_issue, /* RCV_PLOGI REG_LOGIN_ISSUE */
2424 lpfc_rcv_prli_reglogin_issue, /* RCV_PLOGI */
2425 lpfc_rcv_logo_reglogin_issue, /* RCV_LOGO */
2426 lpfc_rcv_padisc_reglogin_issue, /* RCV_ADISC */
2427 lpfc_rcv_padisc_reglogin_issue, /* RCV_PDISC */
2428 lpfc_rcv_prlo_reglogin_issue, /* RCV_PRLO */
James Smart87af33f2007-10-27 13:37:43 -04002429 lpfc_cmpl_plogi_illegal, /* CMPL_PLOGI */
dea31012005-04-17 16:05:31 -05002430 lpfc_disc_illegal, /* CMPL_PRLI */
2431 lpfc_disc_illegal, /* CMPL_LOGO */
2432 lpfc_disc_illegal, /* CMPL_ADISC */
2433 lpfc_cmpl_reglogin_reglogin_issue,/* CMPL_REG_LOGIN */
2434 lpfc_device_rm_reglogin_issue, /* DEVICE_RM */
2435 lpfc_device_recov_reglogin_issue,/* DEVICE_RECOVERY */
2436
2437 lpfc_rcv_plogi_prli_issue, /* RCV_PLOGI PRLI_ISSUE */
2438 lpfc_rcv_prli_prli_issue, /* RCV_PRLI */
2439 lpfc_rcv_logo_prli_issue, /* RCV_LOGO */
2440 lpfc_rcv_padisc_prli_issue, /* RCV_ADISC */
2441 lpfc_rcv_padisc_prli_issue, /* RCV_PDISC */
2442 lpfc_rcv_prlo_prli_issue, /* RCV_PRLO */
James Smart87af33f2007-10-27 13:37:43 -04002443 lpfc_cmpl_plogi_illegal, /* CMPL_PLOGI */
dea31012005-04-17 16:05:31 -05002444 lpfc_cmpl_prli_prli_issue, /* CMPL_PRLI */
2445 lpfc_disc_illegal, /* CMPL_LOGO */
2446 lpfc_disc_illegal, /* CMPL_ADISC */
2447 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2448 lpfc_device_rm_prli_issue, /* DEVICE_RM */
2449 lpfc_device_recov_prli_issue, /* DEVICE_RECOVERY */
2450
James Smart086a3452012-08-14 14:25:21 -04002451 lpfc_rcv_plogi_logo_issue, /* RCV_PLOGI LOGO_ISSUE */
2452 lpfc_rcv_prli_logo_issue, /* RCV_PRLI */
2453 lpfc_rcv_logo_logo_issue, /* RCV_LOGO */
2454 lpfc_rcv_padisc_logo_issue, /* RCV_ADISC */
2455 lpfc_rcv_padisc_logo_issue, /* RCV_PDISC */
2456 lpfc_rcv_prlo_logo_issue, /* RCV_PRLO */
2457 lpfc_cmpl_plogi_illegal, /* CMPL_PLOGI */
2458 lpfc_disc_illegal, /* CMPL_PRLI */
2459 lpfc_cmpl_logo_logo_issue, /* CMPL_LOGO */
2460 lpfc_disc_illegal, /* CMPL_ADISC */
2461 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2462 lpfc_device_rm_logo_issue, /* DEVICE_RM */
2463 lpfc_device_recov_logo_issue, /* DEVICE_RECOVERY */
2464
dea31012005-04-17 16:05:31 -05002465 lpfc_rcv_plogi_unmap_node, /* RCV_PLOGI UNMAPPED_NODE */
2466 lpfc_rcv_prli_unmap_node, /* RCV_PRLI */
2467 lpfc_rcv_logo_unmap_node, /* RCV_LOGO */
2468 lpfc_rcv_padisc_unmap_node, /* RCV_ADISC */
2469 lpfc_rcv_padisc_unmap_node, /* RCV_PDISC */
2470 lpfc_rcv_prlo_unmap_node, /* RCV_PRLO */
2471 lpfc_disc_illegal, /* CMPL_PLOGI */
2472 lpfc_disc_illegal, /* CMPL_PRLI */
2473 lpfc_disc_illegal, /* CMPL_LOGO */
2474 lpfc_disc_illegal, /* CMPL_ADISC */
2475 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2476 lpfc_disc_illegal, /* DEVICE_RM */
2477 lpfc_device_recov_unmap_node, /* DEVICE_RECOVERY */
2478
2479 lpfc_rcv_plogi_mapped_node, /* RCV_PLOGI MAPPED_NODE */
2480 lpfc_rcv_prli_mapped_node, /* RCV_PRLI */
2481 lpfc_rcv_logo_mapped_node, /* RCV_LOGO */
2482 lpfc_rcv_padisc_mapped_node, /* RCV_ADISC */
2483 lpfc_rcv_padisc_mapped_node, /* RCV_PDISC */
2484 lpfc_rcv_prlo_mapped_node, /* RCV_PRLO */
2485 lpfc_disc_illegal, /* CMPL_PLOGI */
2486 lpfc_disc_illegal, /* CMPL_PRLI */
2487 lpfc_disc_illegal, /* CMPL_LOGO */
2488 lpfc_disc_illegal, /* CMPL_ADISC */
2489 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2490 lpfc_disc_illegal, /* DEVICE_RM */
2491 lpfc_device_recov_mapped_node, /* DEVICE_RECOVERY */
2492
2493 lpfc_rcv_plogi_npr_node, /* RCV_PLOGI NPR_NODE */
2494 lpfc_rcv_prli_npr_node, /* RCV_PRLI */
2495 lpfc_rcv_logo_npr_node, /* RCV_LOGO */
2496 lpfc_rcv_padisc_npr_node, /* RCV_ADISC */
2497 lpfc_rcv_padisc_npr_node, /* RCV_PDISC */
2498 lpfc_rcv_prlo_npr_node, /* RCV_PRLO */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002499 lpfc_cmpl_plogi_npr_node, /* CMPL_PLOGI */
2500 lpfc_cmpl_prli_npr_node, /* CMPL_PRLI */
dea31012005-04-17 16:05:31 -05002501 lpfc_cmpl_logo_npr_node, /* CMPL_LOGO */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002502 lpfc_cmpl_adisc_npr_node, /* CMPL_ADISC */
dea31012005-04-17 16:05:31 -05002503 lpfc_cmpl_reglogin_npr_node, /* CMPL_REG_LOGIN */
2504 lpfc_device_rm_npr_node, /* DEVICE_RM */
2505 lpfc_device_recov_npr_node, /* DEVICE_RECOVERY */
2506};
2507
2508int
James Smart2e0fef82007-06-17 19:56:36 -05002509lpfc_disc_state_machine(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2510 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05002511{
2512 uint32_t cur_state, rc;
James Smart2e0fef82007-06-17 19:56:36 -05002513 uint32_t(*func) (struct lpfc_vport *, struct lpfc_nodelist *, void *,
dea31012005-04-17 16:05:31 -05002514 uint32_t);
James Smarte47c9092008-02-08 18:49:26 -05002515 uint32_t got_ndlp = 0;
dea31012005-04-17 16:05:31 -05002516
James Smarte47c9092008-02-08 18:49:26 -05002517 if (lpfc_nlp_get(ndlp))
2518 got_ndlp = 1;
2519
dea31012005-04-17 16:05:31 -05002520 cur_state = ndlp->nlp_state;
2521
2522 /* DSM in event <evt> on NPort <nlp_DID> in state <cur_state> */
James Smarte8b62012007-08-02 11:10:09 -04002523 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2524 "0211 DSM in event x%x on NPort x%x in "
2525 "state %d Data: x%x\n",
2526 evt, ndlp->nlp_DID, cur_state, ndlp->nlp_flag);
dea31012005-04-17 16:05:31 -05002527
James Smart858c9f62007-06-17 19:56:39 -05002528 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_DSM,
2529 "DSM in: evt:%d ste:%d did:x%x",
2530 evt, cur_state, ndlp->nlp_DID);
2531
dea31012005-04-17 16:05:31 -05002532 func = lpfc_disc_action[(cur_state * NLP_EVT_MAX_EVENT) + evt];
James Smart2e0fef82007-06-17 19:56:36 -05002533 rc = (func) (vport, ndlp, arg, evt);
dea31012005-04-17 16:05:31 -05002534
2535 /* DSM out state <rc> on NPort <nlp_DID> */
James Smarte47c9092008-02-08 18:49:26 -05002536 if (got_ndlp) {
2537 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
James Smarte8b62012007-08-02 11:10:09 -04002538 "0212 DSM out state %d on NPort x%x Data: x%x\n",
2539 rc, ndlp->nlp_DID, ndlp->nlp_flag);
dea31012005-04-17 16:05:31 -05002540
James Smarte47c9092008-02-08 18:49:26 -05002541 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_DSM,
2542 "DSM out: ste:%d did:x%x flg:x%x",
2543 rc, ndlp->nlp_DID, ndlp->nlp_flag);
2544 /* Decrement the ndlp reference count held for this function */
2545 lpfc_nlp_put(ndlp);
2546 } else {
2547 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
James Smartd7c255b2008-08-24 21:50:00 -04002548 "0213 DSM out state %d on NPort free\n", rc);
James Smart858c9f62007-06-17 19:56:39 -05002549
James Smarte47c9092008-02-08 18:49:26 -05002550 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_DSM,
2551 "DSM out: ste:%d did:x%x flg:x%x",
2552 rc, 0, 0);
2553 }
dea31012005-04-17 16:05:31 -05002554
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002555 return rc;
dea31012005-04-17 16:05:31 -05002556}