blob: d8fadcb2db73d1794b1ef9d481a6c65e35ff971d [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 Smartd4379ac2012-03-01 22:37:07 -05004 * Copyright (C) 2004-2012 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 Smart2534ba72007-04-25 09:52:20 -0400206 LIST_HEAD(completions);
James Smart2a9bf3d2010-06-07 15:24:45 -0400207 LIST_HEAD(txcmplq_completions);
208 LIST_HEAD(abort_list);
James Smart2e0fef82007-06-17 19:56:36 -0500209 struct lpfc_sli *psli = &phba->sli;
210 struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING];
dea31012005-04-17 16:05:31 -0500211 struct lpfc_iocbq *iocb, *next_iocb;
dea31012005-04-17 16:05:31 -0500212
213 /* Abort outstanding I/O on NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -0400214 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_DISCOVERY,
James Smart2a9bf3d2010-06-07 15:24:45 -0400215 "2819 Abort outstanding I/O on NPort x%x "
James Smarte8b62012007-08-02 11:10:09 -0400216 "Data: x%x x%x x%x\n",
217 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
218 ndlp->nlp_rpi);
James Smart92d7f7b2007-06-17 19:56:38 -0500219
220 lpfc_fabric_abort_nport(ndlp);
dea31012005-04-17 16:05:31 -0500221
dea31012005-04-17 16:05:31 -0500222 /* First check the txq */
James Smart2e0fef82007-06-17 19:56:36 -0500223 spin_lock_irq(&phba->hbalock);
James Smart2534ba72007-04-25 09:52:20 -0400224 list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
James Smart858c9f62007-06-17 19:56:39 -0500225 /* Check to see if iocb matches the nport we are looking for */
James Smart2534ba72007-04-25 09:52:20 -0400226 if (lpfc_check_sli_ndlp(phba, pring, iocb, ndlp)) {
James Smart858c9f62007-06-17 19:56:39 -0500227 /* It matches, so deque and call compl with anp error */
James Smart2534ba72007-04-25 09:52:20 -0400228 list_move_tail(&iocb->list, &completions);
229 pring->txq_cnt--;
dea31012005-04-17 16:05:31 -0500230 }
James Smart2534ba72007-04-25 09:52:20 -0400231 }
dea31012005-04-17 16:05:31 -0500232
dea31012005-04-17 16:05:31 -0500233 /* Next check the txcmplq */
James Smart2a9bf3d2010-06-07 15:24:45 -0400234 list_splice_init(&pring->txcmplq, &txcmplq_completions);
James Smart2e0fef82007-06-17 19:56:36 -0500235 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500236
James Smart2a9bf3d2010-06-07 15:24:45 -0400237 list_for_each_entry_safe(iocb, next_iocb, &txcmplq_completions, list) {
238 /* Check to see if iocb matches the nport we are looking for */
239 if (lpfc_check_sli_ndlp(phba, pring, iocb, ndlp))
240 list_add_tail(&iocb->dlist, &abort_list);
241 }
242 spin_lock_irq(&phba->hbalock);
243 list_splice(&txcmplq_completions, &pring->txcmplq);
244 spin_unlock_irq(&phba->hbalock);
245
246 list_for_each_entry_safe(iocb, next_iocb, &abort_list, dlist) {
247 spin_lock_irq(&phba->hbalock);
248 list_del_init(&iocb->dlist);
249 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
250 spin_unlock_irq(&phba->hbalock);
251 }
252
James Smarta257bf92009-04-06 18:48:10 -0400253 /* Cancel all the IOCBs from the completions list */
254 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
255 IOERR_SLI_ABORTED);
James Smart2534ba72007-04-25 09:52:20 -0400256
James Smart0d2b6b82008-06-14 22:52:47 -0400257 lpfc_cancel_retry_delay_tmo(phba->pport, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500258 return 0;
dea31012005-04-17 16:05:31 -0500259}
260
261static int
James Smart2e0fef82007-06-17 19:56:36 -0500262lpfc_rcv_plogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
James Smart92d7f7b2007-06-17 19:56:38 -0500263 struct lpfc_iocbq *cmdiocb)
dea31012005-04-17 16:05:31 -0500264{
James Smart2e0fef82007-06-17 19:56:36 -0500265 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
266 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500267 struct lpfc_dmabuf *pcmd;
268 uint32_t *lp;
269 IOCB_t *icmd;
270 struct serv_parm *sp;
271 LPFC_MBOXQ_t *mbox;
272 struct ls_rjt stat;
273 int rc;
274
275 memset(&stat, 0, sizeof (struct ls_rjt));
James Smart695a8142010-01-26 23:08:03 -0500276 if (vport->port_state <= LPFC_FDISC) {
dea31012005-04-17 16:05:31 -0500277 /* Before responding to PLOGI, check for pt2pt mode.
278 * If we are pt2pt, with an outstanding FLOGI, abort
279 * the FLOGI and resend it first.
280 */
James Smart2e0fef82007-06-17 19:56:36 -0500281 if (vport->fc_flag & FC_PT2PT) {
James Smart92d7f7b2007-06-17 19:56:38 -0500282 lpfc_els_abort_flogi(phba);
James Smart2e0fef82007-06-17 19:56:36 -0500283 if (!(vport->fc_flag & FC_PT2PT_PLOGI)) {
dea31012005-04-17 16:05:31 -0500284 /* If the other side is supposed to initiate
285 * the PLOGI anyway, just ACC it now and
286 * move on with discovery.
287 */
288 phba->fc_edtov = FF_DEF_EDTOV;
289 phba->fc_ratov = FF_DEF_RATOV;
290 /* Start discovery - this should just do
291 CLEAR_LA */
James Smart2e0fef82007-06-17 19:56:36 -0500292 lpfc_disc_start(vport);
James Smarted957682007-06-17 19:56:37 -0500293 } else
James Smart2e0fef82007-06-17 19:56:36 -0500294 lpfc_initial_flogi(vport);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500295 } else {
dea31012005-04-17 16:05:31 -0500296 stat.un.b.lsRjtRsnCode = LSRJT_LOGICAL_BSY;
297 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
James Smart2e0fef82007-06-17 19:56:36 -0500298 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb,
James Smart858c9f62007-06-17 19:56:39 -0500299 ndlp, NULL);
dea31012005-04-17 16:05:31 -0500300 return 0;
301 }
302 }
303 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
304 lp = (uint32_t *) pcmd->virt;
305 sp = (struct serv_parm *) ((uint8_t *) lp + sizeof (uint32_t));
James Smarta8adb832007-10-27 13:37:53 -0400306 if (wwn_to_u64(sp->portName.u.wwn) == 0) {
307 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
308 "0140 PLOGI Reject: invalid nname\n");
309 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
310 stat.un.b.lsRjtRsnCodeExp = LSEXP_INVALID_PNAME;
311 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
312 NULL);
313 return 0;
314 }
315 if (wwn_to_u64(sp->nodeName.u.wwn) == 0) {
316 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
317 "0141 PLOGI Reject: invalid pname\n");
318 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
319 stat.un.b.lsRjtRsnCodeExp = LSEXP_INVALID_NNAME;
320 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
321 NULL);
322 return 0;
323 }
James Smart341af102010-01-26 23:07:37 -0500324 if ((lpfc_check_sparm(vport, ndlp, sp, CLASS3, 0) == 0)) {
dea31012005-04-17 16:05:31 -0500325 /* Reject this request because invalid parameters */
326 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
327 stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
James Smart858c9f62007-06-17 19:56:39 -0500328 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
329 NULL);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500330 return 0;
dea31012005-04-17 16:05:31 -0500331 }
332 icmd = &cmdiocb->iocb;
333
334 /* PLOGI chkparm OK */
James Smarte8b62012007-08-02 11:10:09 -0400335 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
336 "0114 PLOGI chkparm OK Data: x%x x%x x%x x%x\n",
337 ndlp->nlp_DID, ndlp->nlp_state, ndlp->nlp_flag,
338 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -0500339
James Smart3de2a652007-08-02 11:09:59 -0400340 if (vport->cfg_fcp_class == 2 && sp->cls2.classValid)
dea31012005-04-17 16:05:31 -0500341 ndlp->nlp_fcp_info |= CLASS2;
James Smarted957682007-06-17 19:56:37 -0500342 else
dea31012005-04-17 16:05:31 -0500343 ndlp->nlp_fcp_info |= CLASS3;
James Smart2e0fef82007-06-17 19:56:36 -0500344
dea31012005-04-17 16:05:31 -0500345 ndlp->nlp_class_sup = 0;
346 if (sp->cls1.classValid)
347 ndlp->nlp_class_sup |= FC_COS_CLASS1;
348 if (sp->cls2.classValid)
349 ndlp->nlp_class_sup |= FC_COS_CLASS2;
350 if (sp->cls3.classValid)
351 ndlp->nlp_class_sup |= FC_COS_CLASS3;
352 if (sp->cls4.classValid)
353 ndlp->nlp_class_sup |= FC_COS_CLASS4;
354 ndlp->nlp_maxframe =
355 ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) | sp->cmn.bbRcvSizeLsb;
356
James Smart05580562011-05-24 11:40:48 -0400357 /* no need to reg_login if we are already in one of these states */
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500358 switch (ndlp->nlp_state) {
dea31012005-04-17 16:05:31 -0500359 case NLP_STE_NPR_NODE:
360 if (!(ndlp->nlp_flag & NLP_NPR_ADISC))
361 break;
362 case NLP_STE_REG_LOGIN_ISSUE:
363 case NLP_STE_PRLI_ISSUE:
364 case NLP_STE_UNMAPPED_NODE:
365 case NLP_STE_MAPPED_NODE:
James Smart05580562011-05-24 11:40:48 -0400366 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp, NULL);
367 return 1;
dea31012005-04-17 16:05:31 -0500368 }
369
James Smart939723a2012-05-09 21:19:03 -0400370 /* Check for Nport to NPort pt2pt protocol */
James Smart92d7f7b2007-06-17 19:56:38 -0500371 if ((vport->fc_flag & FC_PT2PT) &&
372 !(vport->fc_flag & FC_PT2PT_PLOGI)) {
James Smart939723a2012-05-09 21:19:03 -0400373
dea31012005-04-17 16:05:31 -0500374 /* rcv'ed PLOGI decides what our NPortId will be */
James Smart2e0fef82007-06-17 19:56:36 -0500375 vport->fc_myDID = icmd->un.rcvels.parmRo;
dea31012005-04-17 16:05:31 -0500376 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
377 if (mbox == NULL)
378 goto out;
379 lpfc_config_link(phba, mbox);
380 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smarted957682007-06-17 19:56:37 -0500381 mbox->vport = vport;
James Smart0b727fe2007-10-27 13:37:25 -0400382 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
dea31012005-04-17 16:05:31 -0500383 if (rc == MBX_NOT_FINISHED) {
James Smart92d7f7b2007-06-17 19:56:38 -0500384 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -0500385 goto out;
386 }
James Smart939723a2012-05-09 21:19:03 -0400387 /*
388 * For SLI4, the VFI/VPI are registered AFTER the
389 * Nport with the higher WWPN sends us a PLOGI with
390 * our assigned NPortId.
391 */
392 if (phba->sli_rev == LPFC_SLI_REV4)
393 lpfc_issue_reg_vfi(vport);
dea31012005-04-17 16:05:31 -0500394
James Smart2e0fef82007-06-17 19:56:36 -0500395 lpfc_can_disctmo(vport);
dea31012005-04-17 16:05:31 -0500396 }
397 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
James Smart2e0fef82007-06-17 19:56:36 -0500398 if (!mbox)
dea31012005-04-17 16:05:31 -0500399 goto out;
400
James Smart6b5151f2012-01-18 16:24:06 -0500401 /* Registering an existing RPI behaves differently for SLI3 vs SLI4 */
402 if (phba->sli_rev == LPFC_SLI_REV4)
403 lpfc_unreg_rpi(vport, ndlp);
404
James Smart6fb120a2009-05-22 14:52:59 -0400405 rc = lpfc_reg_rpi(phba, vport->vpi, icmd->un.rcvels.remoteID,
James Smart40426292010-12-15 17:58:10 -0500406 (uint8_t *) sp, mbox, ndlp->nlp_rpi);
James Smart2e0fef82007-06-17 19:56:36 -0500407 if (rc) {
408 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -0500409 goto out;
410 }
411
412 /* ACC PLOGI rsp command needs to execute first,
413 * queue this mbox command to be processed later.
414 */
415 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
James Smart329f9bc2007-04-25 09:53:01 -0400416 /*
417 * mbox->context2 = lpfc_nlp_get(ndlp) deferred until mailbox
418 * command issued in lpfc_cmpl_els_acc().
419 */
James Smart2e0fef82007-06-17 19:56:36 -0500420 mbox->vport = vport;
421 spin_lock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -0500422 ndlp->nlp_flag |= (NLP_ACC_REGLOGIN | NLP_RCV_PLOGI);
James Smart2e0fef82007-06-17 19:56:36 -0500423 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500424
James Smart33ccf8d2006-08-17 11:57:58 -0400425 /*
426 * If there is an outstanding PLOGI issued, abort it before
427 * sending ACC rsp for received PLOGI. If pending plogi
428 * is not canceled here, the plogi will be rejected by
429 * remote port and will be retried. On a configuration with
430 * single discovery thread, this will cause a huge delay in
431 * discovery. Also this will cause multiple state machines
432 * running in parallel for this node.
433 */
434 if (ndlp->nlp_state == NLP_STE_PLOGI_ISSUE) {
435 /* software abort outstanding PLOGI */
James Smart07951072007-04-25 09:51:38 -0400436 lpfc_els_abort(phba, ndlp);
James Smart33ccf8d2006-08-17 11:57:58 -0400437 }
438
James Smart858c9f62007-06-17 19:56:39 -0500439 if ((vport->port_type == LPFC_NPIV_PORT &&
James Smart3de2a652007-08-02 11:09:59 -0400440 vport->cfg_restrict_login)) {
James Smart858c9f62007-06-17 19:56:39 -0500441
442 /* In order to preserve RPIs, we want to cleanup
443 * the default RPI the firmware created to rcv
444 * this ELS request. The only way to do this is
445 * to register, then unregister the RPI.
446 */
447 spin_lock_irq(shost->host_lock);
448 ndlp->nlp_flag |= NLP_RM_DFLT_RPI;
449 spin_unlock_irq(shost->host_lock);
450 stat.un.b.lsRjtRsnCode = LSRJT_INVALID_CMD;
451 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
James Smart0a8a86f2012-03-01 22:36:15 -0500452 rc = lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb,
James Smart858c9f62007-06-17 19:56:39 -0500453 ndlp, mbox);
James Smart0a8a86f2012-03-01 22:36:15 -0500454 if (rc)
455 mempool_free(mbox, phba->mbox_mem_pool);
James Smart858c9f62007-06-17 19:56:39 -0500456 return 1;
457 }
James Smart0a8a86f2012-03-01 22:36:15 -0500458 rc = lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp, mbox);
459 if (rc)
460 mempool_free(mbox, phba->mbox_mem_pool);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500461 return 1;
dea31012005-04-17 16:05:31 -0500462out:
463 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
464 stat.un.b.lsRjtRsnCodeExp = LSEXP_OUT_OF_RESOURCE;
James Smart858c9f62007-06-17 19:56:39 -0500465 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500466 return 0;
dea31012005-04-17 16:05:31 -0500467}
468
James Smart6b5151f2012-01-18 16:24:06 -0500469/**
470 * lpfc_mbx_cmpl_resume_rpi - Resume RPI completion routine
471 * @phba: pointer to lpfc hba data structure.
472 * @mboxq: pointer to mailbox object
473 *
474 * This routine is invoked to issue a completion to a rcv'ed
475 * ADISC or PDISC after the paused RPI has been resumed.
476 **/
477static void
478lpfc_mbx_cmpl_resume_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
479{
480 struct lpfc_vport *vport;
481 struct lpfc_iocbq *elsiocb;
482 struct lpfc_nodelist *ndlp;
483 uint32_t cmd;
484
485 elsiocb = (struct lpfc_iocbq *)mboxq->context1;
486 ndlp = (struct lpfc_nodelist *) mboxq->context2;
487 vport = mboxq->vport;
488 cmd = elsiocb->drvrTimeout;
489
490 if (cmd == ELS_CMD_ADISC) {
491 lpfc_els_rsp_adisc_acc(vport, elsiocb, ndlp);
492 } else {
493 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, elsiocb,
494 ndlp, NULL);
495 }
496 kfree(elsiocb);
James Smart72859902012-01-18 16:25:38 -0500497 mempool_free(mboxq, phba->mbox_mem_pool);
James Smart6b5151f2012-01-18 16:24:06 -0500498}
499
dea31012005-04-17 16:05:31 -0500500static int
James Smart2e0fef82007-06-17 19:56:36 -0500501lpfc_rcv_padisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -0500502 struct lpfc_iocbq *cmdiocb)
503{
James Smart2e0fef82007-06-17 19:56:36 -0500504 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart6b5151f2012-01-18 16:24:06 -0500505 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -0500506 struct lpfc_dmabuf *pcmd;
James Smart2e0fef82007-06-17 19:56:36 -0500507 struct serv_parm *sp;
508 struct lpfc_name *pnn, *ppn;
dea31012005-04-17 16:05:31 -0500509 struct ls_rjt stat;
510 ADISC *ap;
511 IOCB_t *icmd;
512 uint32_t *lp;
513 uint32_t cmd;
514
515 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
516 lp = (uint32_t *) pcmd->virt;
517
518 cmd = *lp++;
519 if (cmd == ELS_CMD_ADISC) {
520 ap = (ADISC *) lp;
521 pnn = (struct lpfc_name *) & ap->nodeName;
522 ppn = (struct lpfc_name *) & ap->portName;
523 } else {
524 sp = (struct serv_parm *) lp;
525 pnn = (struct lpfc_name *) & sp->nodeName;
526 ppn = (struct lpfc_name *) & sp->portName;
527 }
528
529 icmd = &cmdiocb->iocb;
James Smart2e0fef82007-06-17 19:56:36 -0500530 if (icmd->ulpStatus == 0 && lpfc_check_adisc(vport, ndlp, pnn, ppn)) {
James Smart6b5151f2012-01-18 16:24:06 -0500531
532 /*
533 * As soon as we send ACC, the remote NPort can
534 * start sending us data. Thus, for SLI4 we must
535 * resume the RPI before the ACC goes out.
536 */
537 if (vport->phba->sli_rev == LPFC_SLI_REV4) {
538 elsiocb = kmalloc(sizeof(struct lpfc_iocbq),
539 GFP_KERNEL);
540 if (elsiocb) {
541
542 /* Save info from cmd IOCB used in rsp */
543 memcpy((uint8_t *)elsiocb, (uint8_t *)cmdiocb,
544 sizeof(struct lpfc_iocbq));
545
546 /* Save the ELS cmd */
547 elsiocb->drvrTimeout = cmd;
548
549 lpfc_sli4_resume_rpi(ndlp,
550 lpfc_mbx_cmpl_resume_rpi, elsiocb);
551 goto out;
552 }
553 }
554
dea31012005-04-17 16:05:31 -0500555 if (cmd == ELS_CMD_ADISC) {
James Smart2e0fef82007-06-17 19:56:36 -0500556 lpfc_els_rsp_adisc_acc(vport, cmdiocb, ndlp);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500557 } else {
James Smart6b5151f2012-01-18 16:24:06 -0500558 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb,
559 ndlp, NULL);
dea31012005-04-17 16:05:31 -0500560 }
James Smart6b5151f2012-01-18 16:24:06 -0500561out:
562 /* If we are authenticated, move to the proper state */
563 if (ndlp->nlp_type & NLP_FCP_TARGET)
564 lpfc_nlp_set_state(vport, ndlp, NLP_STE_MAPPED_NODE);
565 else
566 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
567
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500568 return 1;
dea31012005-04-17 16:05:31 -0500569 }
570 /* Reject this request because invalid parameters */
571 stat.un.b.lsRjtRsvd0 = 0;
572 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
573 stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
574 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -0500575 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -0500576
dea31012005-04-17 16:05:31 -0500577 /* 1 sec timeout */
578 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ);
579
James Smart2e0fef82007-06-17 19:56:36 -0500580 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500581 ndlp->nlp_flag |= NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -0500582 spin_unlock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -0500583 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
584 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -0500585 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500586 return 0;
dea31012005-04-17 16:05:31 -0500587}
588
589static int
James Smart2e0fef82007-06-17 19:56:36 -0500590lpfc_rcv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
591 struct lpfc_iocbq *cmdiocb, uint32_t els_cmd)
dea31012005-04-17 16:05:31 -0500592{
James Smart2e0fef82007-06-17 19:56:36 -0500593 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart4b40c592010-03-15 11:25:44 -0400594 struct lpfc_hba *phba = vport->phba;
595 struct lpfc_vport **vports;
596 int i, active_vlink_present = 0 ;
James Smart2e0fef82007-06-17 19:56:36 -0500597
598 /* Put ndlp in NPR state with 1 sec timeout for plogi, ACC logo */
dea31012005-04-17 16:05:31 -0500599 /* Only call LOGO ACC for first LOGO, this avoids sending unnecessary
600 * PLOGIs during LOGO storms from a device.
601 */
James Smart2e0fef82007-06-17 19:56:36 -0500602 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500603 ndlp->nlp_flag |= NLP_LOGO_ACC;
James Smart2e0fef82007-06-17 19:56:36 -0500604 spin_unlock_irq(shost->host_lock);
James Smart82d9a2a2006-04-15 11:53:05 -0400605 if (els_cmd == ELS_CMD_PRLO)
James Smart51ef4c22007-08-02 11:10:31 -0400606 lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL);
James Smart82d9a2a2006-04-15 11:53:05 -0400607 else
James Smart51ef4c22007-08-02 11:10:31 -0400608 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
James Smart4b40c592010-03-15 11:25:44 -0400609 if (ndlp->nlp_DID == Fabric_DID) {
610 if (vport->port_state <= LPFC_FDISC)
611 goto out;
James Smart6fb120a2009-05-22 14:52:59 -0400612 lpfc_linkdown_port(vport);
James Smart6fb120a2009-05-22 14:52:59 -0400613 spin_lock_irq(shost->host_lock);
James Smart4b40c592010-03-15 11:25:44 -0400614 vport->fc_flag |= FC_VPORT_LOGO_RCVD;
James Smart6fb120a2009-05-22 14:52:59 -0400615 spin_unlock_irq(shost->host_lock);
James Smart4b40c592010-03-15 11:25:44 -0400616 vports = lpfc_create_vport_work_array(phba);
617 if (vports) {
618 for (i = 0; i <= phba->max_vports && vports[i] != NULL;
619 i++) {
620 if ((!(vports[i]->fc_flag &
621 FC_VPORT_LOGO_RCVD)) &&
622 (vports[i]->port_state > LPFC_FDISC)) {
623 active_vlink_present = 1;
624 break;
625 }
626 }
627 lpfc_destroy_vport_work_array(phba, vports);
628 }
dea31012005-04-17 16:05:31 -0500629
James Smart4b40c592010-03-15 11:25:44 -0400630 if (active_vlink_present) {
631 /*
632 * If there are other active VLinks present,
633 * re-instantiate the Vlink using FDISC.
634 */
635 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ);
636 spin_lock_irq(shost->host_lock);
637 ndlp->nlp_flag |= NLP_DELAY_TMO;
638 spin_unlock_irq(shost->host_lock);
639 ndlp->nlp_last_elscmd = ELS_CMD_FDISC;
640 vport->port_state = LPFC_FDISC;
641 } else {
642 spin_lock_irq(shost->host_lock);
643 phba->pport->fc_flag &= ~FC_LOGO_RCVD_DID_CHNG;
644 spin_unlock_irq(shost->host_lock);
645 lpfc_retry_pport_discovery(phba);
646 }
James Smart6fb120a2009-05-22 14:52:59 -0400647 } else if ((!(ndlp->nlp_type & NLP_FABRIC) &&
648 ((ndlp->nlp_type & NLP_FCP_TARGET) ||
649 !(ndlp->nlp_type & NLP_FCP_INITIATOR))) ||
650 (ndlp->nlp_state == NLP_STE_ADISC_ISSUE)) {
dea31012005-04-17 16:05:31 -0500651 /* Only try to re-login if this is NOT a Fabric Node */
dea31012005-04-17 16:05:31 -0500652 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ * 1);
James Smart2e0fef82007-06-17 19:56:36 -0500653 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500654 ndlp->nlp_flag |= NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -0500655 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500656
Jamie Wellnitz5024ab12006-02-28 19:25:28 -0500657 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
dea31012005-04-17 16:05:31 -0500658 }
James Smart4b40c592010-03-15 11:25:44 -0400659out:
James Smart87af33f2007-10-27 13:37:43 -0400660 ndlp->nlp_prev_state = ndlp->nlp_state;
661 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
dea31012005-04-17 16:05:31 -0500662
James Smart2e0fef82007-06-17 19:56:36 -0500663 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500664 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
James Smart2e0fef82007-06-17 19:56:36 -0500665 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500666 /* The driver has to wait until the ACC completes before it continues
667 * processing the LOGO. The action will resume in
668 * lpfc_cmpl_els_logo_acc routine. Since part of processing includes an
669 * unreg_login, the driver waits so the ACC does not get aborted.
670 */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500671 return 0;
dea31012005-04-17 16:05:31 -0500672}
673
674static void
James Smart2e0fef82007-06-17 19:56:36 -0500675lpfc_rcv_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
676 struct lpfc_iocbq *cmdiocb)
dea31012005-04-17 16:05:31 -0500677{
678 struct lpfc_dmabuf *pcmd;
679 uint32_t *lp;
680 PRLI *npr;
681 struct fc_rport *rport = ndlp->rport;
682 u32 roles;
683
684 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
685 lp = (uint32_t *) pcmd->virt;
686 npr = (PRLI *) ((uint8_t *) lp + sizeof (uint32_t));
687
688 ndlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR);
689 ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
James Smart92d7f7b2007-06-17 19:56:38 -0500690 if (npr->prliType == PRLI_FCP_TYPE) {
dea31012005-04-17 16:05:31 -0500691 if (npr->initiatorFunc)
692 ndlp->nlp_type |= NLP_FCP_INITIATOR;
693 if (npr->targetFunc)
694 ndlp->nlp_type |= NLP_FCP_TARGET;
695 if (npr->Retry)
696 ndlp->nlp_fcp_info |= NLP_FCP_2_DEVICE;
697 }
698 if (rport) {
699 /* We need to update the rport role values */
700 roles = FC_RPORT_ROLE_UNKNOWN;
701 if (ndlp->nlp_type & NLP_FCP_INITIATOR)
702 roles |= FC_RPORT_ROLE_FCP_INITIATOR;
703 if (ndlp->nlp_type & NLP_FCP_TARGET)
704 roles |= FC_RPORT_ROLE_FCP_TARGET;
James Smart858c9f62007-06-17 19:56:39 -0500705
706 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
707 "rport rolechg: role:x%x did:x%x flg:x%x",
708 roles, ndlp->nlp_DID, ndlp->nlp_flag);
709
dea31012005-04-17 16:05:31 -0500710 fc_remote_port_rolechg(rport, roles);
711 }
712}
713
714static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -0500715lpfc_disc_set_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -0500716{
James Smart2e0fef82007-06-17 19:56:36 -0500717 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart2e0fef82007-06-17 19:56:36 -0500718
James Smart40426292010-12-15 17:58:10 -0500719 if (!(ndlp->nlp_flag & NLP_RPI_REGISTERED)) {
James Smart51ef4c22007-08-02 11:10:31 -0400720 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
721 return 0;
722 }
723
James Smart1b32f6a2008-02-08 18:49:39 -0500724 if (!(vport->fc_flag & FC_PT2PT)) {
725 /* Check config parameter use-adisc or FCP-2 */
726 if ((vport->cfg_use_adisc && (vport->fc_flag & FC_RSCN_MODE)) ||
James Smartffc95492010-06-07 15:23:17 -0400727 ((ndlp->nlp_fcp_info & NLP_FCP_2_DEVICE) &&
728 (ndlp->nlp_type & NLP_FCP_TARGET))) {
James Smart1b32f6a2008-02-08 18:49:39 -0500729 spin_lock_irq(shost->host_lock);
730 ndlp->nlp_flag |= NLP_NPR_ADISC;
731 spin_unlock_irq(shost->host_lock);
732 return 1;
733 }
James Smart92d7f7b2007-06-17 19:56:38 -0500734 }
735 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
736 lpfc_unreg_rpi(vport, ndlp);
737 return 0;
dea31012005-04-17 16:05:31 -0500738}
James Smart6d368e52011-05-24 11:44:12 -0400739
James Smart78730cf2010-04-06 15:06:30 -0400740/**
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300741 * lpfc_release_rpi - Release a RPI by issuing unreg_login mailbox cmd.
James Smart78730cf2010-04-06 15:06:30 -0400742 * @phba : Pointer to lpfc_hba structure.
743 * @vport: Pointer to lpfc_vport structure.
744 * @rpi : rpi to be release.
745 *
746 * This function will send a unreg_login mailbox command to the firmware
747 * to release a rpi.
748 **/
749void
750lpfc_release_rpi(struct lpfc_hba *phba,
751 struct lpfc_vport *vport,
752 uint16_t rpi)
753{
754 LPFC_MBOXQ_t *pmb;
755 int rc;
756
757 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
758 GFP_KERNEL);
759 if (!pmb)
760 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
761 "2796 mailbox memory allocation failed \n");
762 else {
763 lpfc_unreg_login(phba, vport->vpi, rpi, pmb);
764 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
765 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
766 if (rc == MBX_NOT_FINISHED)
767 mempool_free(pmb, phba->mbox_mem_pool);
768 }
769}
dea31012005-04-17 16:05:31 -0500770
771static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -0500772lpfc_disc_illegal(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
773 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -0500774{
James Smart78730cf2010-04-06 15:06:30 -0400775 struct lpfc_hba *phba;
776 LPFC_MBOXQ_t *pmb = (LPFC_MBOXQ_t *) arg;
777 MAILBOX_t *mb;
778 uint16_t rpi;
779
780 phba = vport->phba;
781 /* Release the RPI if reglogin completing */
782 if (!(phba->pport->load_flag & FC_UNLOADING) &&
783 (evt == NLP_EVT_CMPL_REG_LOGIN) &&
784 (!pmb->u.mb.mbxStatus)) {
785 mb = &pmb->u.mb;
786 rpi = pmb->u.mb.un.varWords[0];
787 lpfc_release_rpi(phba, vport, rpi);
788 }
James Smarte8b62012007-08-02 11:10:09 -0400789 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
James Smarte47c9092008-02-08 18:49:26 -0500790 "0271 Illegal State Transition: node x%x "
James Smarte8b62012007-08-02 11:10:09 -0400791 "event x%x, state x%x Data: x%x x%x\n",
792 ndlp->nlp_DID, evt, ndlp->nlp_state, ndlp->nlp_rpi,
793 ndlp->nlp_flag);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500794 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -0500795}
796
James Smart87af33f2007-10-27 13:37:43 -0400797static uint32_t
798lpfc_cmpl_plogi_illegal(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
799 void *arg, uint32_t evt)
800{
801 /* This transition is only legal if we previously
802 * rcv'ed a PLOGI. Since we don't want 2 discovery threads
803 * working on the same NPortID, do nothing for this thread
804 * to stop it.
805 */
806 if (!(ndlp->nlp_flag & NLP_RCV_PLOGI)) {
807 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
James Smarte47c9092008-02-08 18:49:26 -0500808 "0272 Illegal State Transition: node x%x "
James Smart87af33f2007-10-27 13:37:43 -0400809 "event x%x, state x%x Data: x%x x%x\n",
810 ndlp->nlp_DID, evt, ndlp->nlp_state, ndlp->nlp_rpi,
811 ndlp->nlp_flag);
812 }
813 return ndlp->nlp_state;
814}
815
dea31012005-04-17 16:05:31 -0500816/* Start of Discovery State Machine routines */
817
818static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -0500819lpfc_rcv_plogi_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
820 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -0500821{
822 struct lpfc_iocbq *cmdiocb;
823
824 cmdiocb = (struct lpfc_iocbq *) arg;
825
James Smart2e0fef82007-06-17 19:56:36 -0500826 if (lpfc_rcv_plogi(vport, ndlp, cmdiocb)) {
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500827 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -0500828 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500829 return NLP_STE_FREED_NODE;
dea31012005-04-17 16:05:31 -0500830}
831
832static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -0500833lpfc_rcv_els_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
834 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -0500835{
James Smart2e0fef82007-06-17 19:56:36 -0500836 lpfc_issue_els_logo(vport, ndlp, 0);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500837 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -0500838}
839
840static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -0500841lpfc_rcv_logo_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
842 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -0500843{
James Smart2e0fef82007-06-17 19:56:36 -0500844 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
845 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -0500846
James Smart2e0fef82007-06-17 19:56:36 -0500847 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500848 ndlp->nlp_flag |= NLP_LOGO_ACC;
James Smart2e0fef82007-06-17 19:56:36 -0500849 spin_unlock_irq(shost->host_lock);
James Smart51ef4c22007-08-02 11:10:31 -0400850 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -0500851
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500852 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -0500853}
854
855static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -0500856lpfc_cmpl_logo_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -0500857 void *arg, uint32_t evt)
858{
James Smart2e0fef82007-06-17 19:56:36 -0500859 return NLP_STE_FREED_NODE;
860}
861
862static uint32_t
863lpfc_device_rm_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
864 void *arg, uint32_t evt)
865{
James Smart2e0fef82007-06-17 19:56:36 -0500866 return NLP_STE_FREED_NODE;
867}
868
869static uint32_t
James Smartdf9e1b52011-12-13 13:22:17 -0500870lpfc_device_recov_unused_node(struct lpfc_vport *vport,
871 struct lpfc_nodelist *ndlp,
872 void *arg, uint32_t evt)
873{
874 return ndlp->nlp_state;
875}
876
877static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -0500878lpfc_rcv_plogi_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
879 void *arg, uint32_t evt)
880{
James Smart0d2b6b82008-06-14 22:52:47 -0400881 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart2e0fef82007-06-17 19:56:36 -0500882 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500883 struct lpfc_iocbq *cmdiocb = arg;
James Smart2e0fef82007-06-17 19:56:36 -0500884 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
885 uint32_t *lp = (uint32_t *) pcmd->virt;
886 struct serv_parm *sp = (struct serv_parm *) (lp + 1);
dea31012005-04-17 16:05:31 -0500887 struct ls_rjt stat;
888 int port_cmp;
889
dea31012005-04-17 16:05:31 -0500890 memset(&stat, 0, sizeof (struct ls_rjt));
891
892 /* For a PLOGI, we only accept if our portname is less
893 * than the remote portname.
894 */
895 phba->fc_stat.elsLogiCol++;
James Smart2e0fef82007-06-17 19:56:36 -0500896 port_cmp = memcmp(&vport->fc_portname, &sp->portName,
James Smart92d7f7b2007-06-17 19:56:38 -0500897 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -0500898
899 if (port_cmp >= 0) {
900 /* Reject this request because the remote node will accept
901 ours */
902 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
903 stat.un.b.lsRjtRsnCodeExp = LSEXP_CMD_IN_PROGRESS;
James Smart858c9f62007-06-17 19:56:39 -0500904 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
905 NULL);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500906 } else {
James Smart0d2b6b82008-06-14 22:52:47 -0400907 if (lpfc_rcv_plogi(vport, ndlp, cmdiocb) &&
908 (ndlp->nlp_flag & NLP_NPR_2B_DISC) &&
909 (vport->num_disc_nodes)) {
910 spin_lock_irq(shost->host_lock);
911 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
912 spin_unlock_irq(shost->host_lock);
913 /* Check if there are more PLOGIs to be sent */
914 lpfc_more_plogi(vport);
915 if (vport->num_disc_nodes == 0) {
916 spin_lock_irq(shost->host_lock);
917 vport->fc_flag &= ~FC_NDISC_ACTIVE;
918 spin_unlock_irq(shost->host_lock);
919 lpfc_can_disctmo(vport);
920 lpfc_end_rscn(vport);
921 }
922 }
James Smart2e0fef82007-06-17 19:56:36 -0500923 } /* If our portname was less */
dea31012005-04-17 16:05:31 -0500924
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500925 return ndlp->nlp_state;
926}
927
928static uint32_t
James Smart92d7f7b2007-06-17 19:56:38 -0500929lpfc_rcv_prli_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
930 void *arg, uint32_t evt)
931{
932 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
933 struct ls_rjt stat;
934
935 memset(&stat, 0, sizeof (struct ls_rjt));
936 stat.un.b.lsRjtRsnCode = LSRJT_LOGICAL_BSY;
937 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
James Smart858c9f62007-06-17 19:56:39 -0500938 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
James Smart92d7f7b2007-06-17 19:56:38 -0500939 return ndlp->nlp_state;
940}
941
942static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -0500943lpfc_rcv_logo_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
944 void *arg, uint32_t evt)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500945{
James Smart2e0fef82007-06-17 19:56:36 -0500946 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500947
James Smart92d7f7b2007-06-17 19:56:38 -0500948 /* software abort outstanding PLOGI */
James Smart2e0fef82007-06-17 19:56:36 -0500949 lpfc_els_abort(vport->phba, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500950
James Smart2e0fef82007-06-17 19:56:36 -0500951 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500952 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -0500953}
954
955static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -0500956lpfc_rcv_els_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
957 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -0500958{
James Smart2e0fef82007-06-17 19:56:36 -0500959 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
960 struct lpfc_hba *phba = vport->phba;
961 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -0500962
963 /* software abort outstanding PLOGI */
James Smart07951072007-04-25 09:51:38 -0400964 lpfc_els_abort(phba, ndlp);
dea31012005-04-17 16:05:31 -0500965
966 if (evt == NLP_EVT_RCV_LOGO) {
James Smart51ef4c22007-08-02 11:10:31 -0400967 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500968 } else {
James Smart2e0fef82007-06-17 19:56:36 -0500969 lpfc_issue_els_logo(vport, ndlp, 0);
dea31012005-04-17 16:05:31 -0500970 }
971
James Smart2e0fef82007-06-17 19:56:36 -0500972 /* Put ndlp in npr state set plogi timer for 1 sec */
Jamie Wellnitz5024ab12006-02-28 19:25:28 -0500973 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ * 1);
James Smart2e0fef82007-06-17 19:56:36 -0500974 spin_lock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -0500975 ndlp->nlp_flag |= NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -0500976 spin_unlock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -0500977 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
978 ndlp->nlp_prev_state = NLP_STE_PLOGI_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -0500979 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
dea31012005-04-17 16:05:31 -0500980
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500981 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -0500982}
983
984static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -0500985lpfc_cmpl_plogi_plogi_issue(struct lpfc_vport *vport,
986 struct lpfc_nodelist *ndlp,
987 void *arg,
dea31012005-04-17 16:05:31 -0500988 uint32_t evt)
989{
James Smart2e0fef82007-06-17 19:56:36 -0500990 struct lpfc_hba *phba = vport->phba;
James Smart0ff10d42008-01-11 01:52:36 -0500991 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart2e0fef82007-06-17 19:56:36 -0500992 struct lpfc_iocbq *cmdiocb, *rspiocb;
James Smart14691152006-12-02 13:34:28 -0500993 struct lpfc_dmabuf *pcmd, *prsp, *mp;
dea31012005-04-17 16:05:31 -0500994 uint32_t *lp;
995 IOCB_t *irsp;
996 struct serv_parm *sp;
997 LPFC_MBOXQ_t *mbox;
998
999 cmdiocb = (struct lpfc_iocbq *) arg;
1000 rspiocb = cmdiocb->context_un.rsp_iocb;
1001
1002 if (ndlp->nlp_flag & NLP_ACC_REGLOGIN) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001003 /* Recovery from PLOGI collision logic */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001004 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001005 }
1006
1007 irsp = &rspiocb->iocb;
1008
1009 if (irsp->ulpStatus)
1010 goto out;
1011
1012 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
1013
James Smart2e0fef82007-06-17 19:56:36 -05001014 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
dea31012005-04-17 16:05:31 -05001015
James Smart2e0fef82007-06-17 19:56:36 -05001016 lp = (uint32_t *) prsp->virt;
dea31012005-04-17 16:05:31 -05001017 sp = (struct serv_parm *) ((uint8_t *) lp + sizeof (uint32_t));
James Smart58da1ff2008-04-07 10:15:56 -04001018
1019 /* Some switches have FDMI servers returning 0 for WWN */
1020 if ((ndlp->nlp_DID != FDMI_DID) &&
1021 (wwn_to_u64(sp->portName.u.wwn) == 0 ||
1022 wwn_to_u64(sp->nodeName.u.wwn) == 0)) {
James Smarta8adb832007-10-27 13:37:53 -04001023 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1024 "0142 PLOGI RSP: Invalid WWN.\n");
1025 goto out;
1026 }
James Smart341af102010-01-26 23:07:37 -05001027 if (!lpfc_check_sparm(vport, ndlp, sp, CLASS3, 0))
dea31012005-04-17 16:05:31 -05001028 goto out;
dea31012005-04-17 16:05:31 -05001029 /* PLOGI chkparm OK */
James Smarte8b62012007-08-02 11:10:09 -04001030 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1031 "0121 PLOGI chkparm OK Data: x%x x%x x%x x%x\n",
1032 ndlp->nlp_DID, ndlp->nlp_state,
1033 ndlp->nlp_flag, ndlp->nlp_rpi);
James Smart3de2a652007-08-02 11:09:59 -04001034 if (vport->cfg_fcp_class == 2 && (sp->cls2.classValid))
dea31012005-04-17 16:05:31 -05001035 ndlp->nlp_fcp_info |= CLASS2;
James Smart2e0fef82007-06-17 19:56:36 -05001036 else
dea31012005-04-17 16:05:31 -05001037 ndlp->nlp_fcp_info |= CLASS3;
James Smart2e0fef82007-06-17 19:56:36 -05001038
dea31012005-04-17 16:05:31 -05001039 ndlp->nlp_class_sup = 0;
1040 if (sp->cls1.classValid)
1041 ndlp->nlp_class_sup |= FC_COS_CLASS1;
1042 if (sp->cls2.classValid)
1043 ndlp->nlp_class_sup |= FC_COS_CLASS2;
1044 if (sp->cls3.classValid)
1045 ndlp->nlp_class_sup |= FC_COS_CLASS3;
1046 if (sp->cls4.classValid)
1047 ndlp->nlp_class_sup |= FC_COS_CLASS4;
1048 ndlp->nlp_maxframe =
James Smart2e0fef82007-06-17 19:56:36 -05001049 ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) | sp->cmn.bbRcvSizeLsb;
dea31012005-04-17 16:05:31 -05001050
James Smart2e0fef82007-06-17 19:56:36 -05001051 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
James Smart92d7f7b2007-06-17 19:56:38 -05001052 if (!mbox) {
James Smarte8b62012007-08-02 11:10:09 -04001053 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1054 "0133 PLOGI: no memory for reg_login "
James Smart92d7f7b2007-06-17 19:56:38 -05001055 "Data: x%x x%x x%x x%x\n",
James Smart92d7f7b2007-06-17 19:56:38 -05001056 ndlp->nlp_DID, ndlp->nlp_state,
1057 ndlp->nlp_flag, ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05001058 goto out;
James Smart92d7f7b2007-06-17 19:56:38 -05001059 }
dea31012005-04-17 16:05:31 -05001060
James Smart2e0fef82007-06-17 19:56:36 -05001061 lpfc_unreg_rpi(vport, ndlp);
1062
James Smart6fb120a2009-05-22 14:52:59 -04001063 if (lpfc_reg_rpi(phba, vport->vpi, irsp->un.elsreq64.remoteID,
James Smart40426292010-12-15 17:58:10 -05001064 (uint8_t *) sp, mbox, ndlp->nlp_rpi) == 0) {
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05001065 switch (ndlp->nlp_DID) {
dea31012005-04-17 16:05:31 -05001066 case NameServer_DID:
James Smartde0c5b32007-04-25 09:52:27 -04001067 mbox->mbox_cmpl = lpfc_mbx_cmpl_ns_reg_login;
dea31012005-04-17 16:05:31 -05001068 break;
1069 case FDMI_DID:
James Smartde0c5b32007-04-25 09:52:27 -04001070 mbox->mbox_cmpl = lpfc_mbx_cmpl_fdmi_reg_login;
dea31012005-04-17 16:05:31 -05001071 break;
1072 default:
James Smartffc95492010-06-07 15:23:17 -04001073 ndlp->nlp_flag |= NLP_REG_LOGIN_SEND;
James Smartde0c5b32007-04-25 09:52:27 -04001074 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
dea31012005-04-17 16:05:31 -05001075 }
James Smart329f9bc2007-04-25 09:53:01 -04001076 mbox->context2 = lpfc_nlp_get(ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05001077 mbox->vport = vport;
James Smart0b727fe2007-10-27 13:37:25 -04001078 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
dea31012005-04-17 16:05:31 -05001079 != MBX_NOT_FINISHED) {
James Smart2e0fef82007-06-17 19:56:36 -05001080 lpfc_nlp_set_state(vport, ndlp,
1081 NLP_STE_REG_LOGIN_ISSUE);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001082 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001083 }
James Smartffc95492010-06-07 15:23:17 -04001084 if (ndlp->nlp_flag & NLP_REG_LOGIN_SEND)
1085 ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND;
James Smartfa4066b2008-01-11 01:53:27 -05001086 /* decrement node reference count to the failed mbox
1087 * command
1088 */
James Smart329f9bc2007-04-25 09:53:01 -04001089 lpfc_nlp_put(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05001090 mp = (struct lpfc_dmabuf *) mbox->context1;
James Smart14691152006-12-02 13:34:28 -05001091 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1092 kfree(mp);
dea31012005-04-17 16:05:31 -05001093 mempool_free(mbox, phba->mbox_mem_pool);
James Smart92d7f7b2007-06-17 19:56:38 -05001094
James Smarte8b62012007-08-02 11:10:09 -04001095 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1096 "0134 PLOGI: cannot issue reg_login "
1097 "Data: x%x x%x x%x x%x\n",
1098 ndlp->nlp_DID, ndlp->nlp_state,
1099 ndlp->nlp_flag, ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05001100 } else {
1101 mempool_free(mbox, phba->mbox_mem_pool);
James Smart92d7f7b2007-06-17 19:56:38 -05001102
James Smarte8b62012007-08-02 11:10:09 -04001103 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1104 "0135 PLOGI: cannot format reg_login "
1105 "Data: x%x x%x x%x x%x\n",
1106 ndlp->nlp_DID, ndlp->nlp_state,
1107 ndlp->nlp_flag, ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05001108 }
1109
1110
James Smart92d7f7b2007-06-17 19:56:38 -05001111out:
1112 if (ndlp->nlp_DID == NameServer_DID) {
1113 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04001114 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1115 "0261 Cannot Register NameServer login\n");
James Smart92d7f7b2007-06-17 19:56:38 -05001116 }
1117
James Smart0ff10d42008-01-11 01:52:36 -05001118 spin_lock_irq(shost->host_lock);
James Smarta8adb832007-10-27 13:37:53 -04001119 ndlp->nlp_flag |= NLP_DEFER_RM;
James Smart0ff10d42008-01-11 01:52:36 -05001120 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001121 return NLP_STE_FREED_NODE;
dea31012005-04-17 16:05:31 -05001122}
1123
1124static uint32_t
James Smart0ff10d42008-01-11 01:52:36 -05001125lpfc_cmpl_logo_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1126 void *arg, uint32_t evt)
1127{
1128 return ndlp->nlp_state;
1129}
1130
1131static uint32_t
1132lpfc_cmpl_reglogin_plogi_issue(struct lpfc_vport *vport,
1133 struct lpfc_nodelist *ndlp, void *arg, uint32_t evt)
1134{
James Smart78730cf2010-04-06 15:06:30 -04001135 struct lpfc_hba *phba;
1136 LPFC_MBOXQ_t *pmb = (LPFC_MBOXQ_t *) arg;
1137 MAILBOX_t *mb = &pmb->u.mb;
1138 uint16_t rpi;
1139
1140 phba = vport->phba;
1141 /* Release the RPI */
1142 if (!(phba->pport->load_flag & FC_UNLOADING) &&
1143 !mb->mbxStatus) {
1144 rpi = pmb->u.mb.un.varWords[0];
1145 lpfc_release_rpi(phba, vport, rpi);
1146 }
James Smart0ff10d42008-01-11 01:52:36 -05001147 return ndlp->nlp_state;
1148}
1149
1150static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001151lpfc_device_rm_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1152 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001153{
James Smart2e0fef82007-06-17 19:56:36 -05001154 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001155
James Smart2e0fef82007-06-17 19:56:36 -05001156 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1157 spin_lock_irq(shost->host_lock);
1158 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
1159 spin_unlock_irq(shost->host_lock);
1160 return ndlp->nlp_state;
1161 } else {
1162 /* software abort outstanding PLOGI */
1163 lpfc_els_abort(vport->phba, ndlp);
1164
1165 lpfc_drop_node(vport, ndlp);
James Smarta0f9b482006-04-15 11:52:56 -04001166 return NLP_STE_FREED_NODE;
1167 }
dea31012005-04-17 16:05:31 -05001168}
1169
1170static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001171lpfc_device_recov_plogi_issue(struct lpfc_vport *vport,
1172 struct lpfc_nodelist *ndlp,
1173 void *arg,
1174 uint32_t evt)
dea31012005-04-17 16:05:31 -05001175{
James Smart2e0fef82007-06-17 19:56:36 -05001176 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1177 struct lpfc_hba *phba = vport->phba;
1178
James Smart92d7f7b2007-06-17 19:56:38 -05001179 /* Don't do anything that will mess up processing of the
1180 * previous RSCN.
1181 */
1182 if (vport->fc_flag & FC_RSCN_DEFERRED)
1183 return ndlp->nlp_state;
1184
dea31012005-04-17 16:05:31 -05001185 /* software abort outstanding PLOGI */
James Smart07951072007-04-25 09:51:38 -04001186 lpfc_els_abort(phba, ndlp);
dea31012005-04-17 16:05:31 -05001187
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001188 ndlp->nlp_prev_state = NLP_STE_PLOGI_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -05001189 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
James Smart92d7f7b2007-06-17 19:56:38 -05001190 spin_lock_irq(shost->host_lock);
James Smarta0f9b482006-04-15 11:52:56 -04001191 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
James Smart2e0fef82007-06-17 19:56:36 -05001192 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001193
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001194 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001195}
1196
1197static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001198lpfc_rcv_plogi_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1199 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001200{
James Smart0d2b6b82008-06-14 22:52:47 -04001201 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart2e0fef82007-06-17 19:56:36 -05001202 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001203 struct lpfc_iocbq *cmdiocb;
1204
1205 /* software abort outstanding ADISC */
James Smart07951072007-04-25 09:51:38 -04001206 lpfc_els_abort(phba, ndlp);
dea31012005-04-17 16:05:31 -05001207
1208 cmdiocb = (struct lpfc_iocbq *) arg;
1209
James Smart0d2b6b82008-06-14 22:52:47 -04001210 if (lpfc_rcv_plogi(vport, ndlp, cmdiocb)) {
1211 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1212 spin_lock_irq(shost->host_lock);
1213 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
1214 spin_unlock_irq(shost->host_lock);
James Smart90160e02008-08-24 21:49:45 -04001215 if (vport->num_disc_nodes)
James Smart0d2b6b82008-06-14 22:52:47 -04001216 lpfc_more_adisc(vport);
James Smart0d2b6b82008-06-14 22:52:47 -04001217 }
1218 return ndlp->nlp_state;
1219 }
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001220 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -05001221 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
1222 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
dea31012005-04-17 16:05:31 -05001223
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001224 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001225}
1226
1227static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001228lpfc_rcv_prli_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1229 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001230{
James Smart2e0fef82007-06-17 19:56:36 -05001231 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001232
James Smart2e0fef82007-06-17 19:56:36 -05001233 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001234 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001235}
1236
1237static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001238lpfc_rcv_logo_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1239 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001240{
James Smart2e0fef82007-06-17 19:56:36 -05001241 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001242 struct lpfc_iocbq *cmdiocb;
1243
1244 cmdiocb = (struct lpfc_iocbq *) arg;
1245
1246 /* software abort outstanding ADISC */
James Smart07951072007-04-25 09:51:38 -04001247 lpfc_els_abort(phba, ndlp);
dea31012005-04-17 16:05:31 -05001248
James Smart2e0fef82007-06-17 19:56:36 -05001249 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001250 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001251}
1252
1253static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001254lpfc_rcv_padisc_adisc_issue(struct lpfc_vport *vport,
1255 struct lpfc_nodelist *ndlp,
1256 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001257{
1258 struct lpfc_iocbq *cmdiocb;
1259
1260 cmdiocb = (struct lpfc_iocbq *) arg;
1261
James Smart2e0fef82007-06-17 19:56:36 -05001262 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001263 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001264}
1265
1266static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001267lpfc_rcv_prlo_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1268 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001269{
1270 struct lpfc_iocbq *cmdiocb;
1271
1272 cmdiocb = (struct lpfc_iocbq *) arg;
1273
1274 /* Treat like rcv logo */
James Smart2e0fef82007-06-17 19:56:36 -05001275 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_PRLO);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001276 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001277}
1278
1279static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001280lpfc_cmpl_adisc_adisc_issue(struct lpfc_vport *vport,
1281 struct lpfc_nodelist *ndlp,
1282 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001283{
James Smart2e0fef82007-06-17 19:56:36 -05001284 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1285 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001286 struct lpfc_iocbq *cmdiocb, *rspiocb;
1287 IOCB_t *irsp;
1288 ADISC *ap;
James Smart6fb120a2009-05-22 14:52:59 -04001289 int rc;
dea31012005-04-17 16:05:31 -05001290
1291 cmdiocb = (struct lpfc_iocbq *) arg;
1292 rspiocb = cmdiocb->context_un.rsp_iocb;
1293
1294 ap = (ADISC *)lpfc_check_elscmpl_iocb(phba, cmdiocb, rspiocb);
1295 irsp = &rspiocb->iocb;
1296
1297 if ((irsp->ulpStatus) ||
James Smart92d7f7b2007-06-17 19:56:38 -05001298 (!lpfc_check_adisc(vport, ndlp, &ap->nodeName, &ap->portName))) {
dea31012005-04-17 16:05:31 -05001299 /* 1 sec timeout */
1300 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ);
James Smart2e0fef82007-06-17 19:56:36 -05001301 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001302 ndlp->nlp_flag |= NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05001303 spin_unlock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001304 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
dea31012005-04-17 16:05:31 -05001305
James Smart2e0fef82007-06-17 19:56:36 -05001306 memset(&ndlp->nlp_nodename, 0, sizeof(struct lpfc_name));
1307 memset(&ndlp->nlp_portname, 0, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05001308
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001309 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -05001310 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1311 lpfc_unreg_rpi(vport, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001312 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001313 }
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001314
James Smart6fb120a2009-05-22 14:52:59 -04001315 if (phba->sli_rev == LPFC_SLI_REV4) {
James Smart6b5151f2012-01-18 16:24:06 -05001316 rc = lpfc_sli4_resume_rpi(ndlp, NULL, NULL);
James Smart6fb120a2009-05-22 14:52:59 -04001317 if (rc) {
1318 /* Stay in state and retry. */
1319 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
1320 return ndlp->nlp_state;
1321 }
1322 }
1323
James.Smart@Emulex.Com25013222005-06-25 10:34:33 -04001324 if (ndlp->nlp_type & NLP_FCP_TARGET) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001325 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -05001326 lpfc_nlp_set_state(vport, ndlp, NLP_STE_MAPPED_NODE);
James.Smart@Emulex.Com25013222005-06-25 10:34:33 -04001327 } else {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001328 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -05001329 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
James.Smart@Emulex.Com25013222005-06-25 10:34:33 -04001330 }
James Smart6fb120a2009-05-22 14:52:59 -04001331
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001332 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001333}
1334
1335static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001336lpfc_device_rm_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1337 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001338{
James Smart2e0fef82007-06-17 19:56:36 -05001339 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001340
James Smart2e0fef82007-06-17 19:56:36 -05001341 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1342 spin_lock_irq(shost->host_lock);
1343 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
1344 spin_unlock_irq(shost->host_lock);
1345 return ndlp->nlp_state;
1346 } else {
1347 /* software abort outstanding ADISC */
1348 lpfc_els_abort(vport->phba, ndlp);
1349
1350 lpfc_drop_node(vport, ndlp);
James Smarta0f9b482006-04-15 11:52:56 -04001351 return NLP_STE_FREED_NODE;
1352 }
dea31012005-04-17 16:05:31 -05001353}
1354
1355static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001356lpfc_device_recov_adisc_issue(struct lpfc_vport *vport,
1357 struct lpfc_nodelist *ndlp,
1358 void *arg,
1359 uint32_t evt)
dea31012005-04-17 16:05:31 -05001360{
James Smart2e0fef82007-06-17 19:56:36 -05001361 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1362 struct lpfc_hba *phba = vport->phba;
1363
James Smart92d7f7b2007-06-17 19:56:38 -05001364 /* Don't do anything that will mess up processing of the
1365 * previous RSCN.
1366 */
1367 if (vport->fc_flag & FC_RSCN_DEFERRED)
1368 return ndlp->nlp_state;
1369
dea31012005-04-17 16:05:31 -05001370 /* software abort outstanding ADISC */
James Smart07951072007-04-25 09:51:38 -04001371 lpfc_els_abort(phba, ndlp);
dea31012005-04-17 16:05:31 -05001372
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001373 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -05001374 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1375 spin_lock_irq(shost->host_lock);
James Smarta0f9b482006-04-15 11:52:56 -04001376 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
James Smart2e0fef82007-06-17 19:56:36 -05001377 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05001378 lpfc_disc_set_adisc(vport, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001379 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001380}
1381
1382static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001383lpfc_rcv_plogi_reglogin_issue(struct lpfc_vport *vport,
1384 struct lpfc_nodelist *ndlp,
1385 void *arg,
dea31012005-04-17 16:05:31 -05001386 uint32_t evt)
1387{
James Smart2e0fef82007-06-17 19:56:36 -05001388 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001389
James Smart2e0fef82007-06-17 19:56:36 -05001390 lpfc_rcv_plogi(vport, ndlp, cmdiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001391 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001392}
1393
1394static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001395lpfc_rcv_prli_reglogin_issue(struct lpfc_vport *vport,
1396 struct lpfc_nodelist *ndlp,
1397 void *arg,
dea31012005-04-17 16:05:31 -05001398 uint32_t evt)
1399{
James Smart2e0fef82007-06-17 19:56:36 -05001400 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001401
James Smart2e0fef82007-06-17 19:56:36 -05001402 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001403 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001404}
1405
1406static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001407lpfc_rcv_logo_reglogin_issue(struct lpfc_vport *vport,
1408 struct lpfc_nodelist *ndlp,
1409 void *arg,
dea31012005-04-17 16:05:31 -05001410 uint32_t evt)
1411{
James Smart2e0fef82007-06-17 19:56:36 -05001412 struct lpfc_hba *phba = vport->phba;
1413 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
James Smart7054a602007-04-25 09:52:34 -04001414 LPFC_MBOXQ_t *mb;
1415 LPFC_MBOXQ_t *nextmb;
1416 struct lpfc_dmabuf *mp;
dea31012005-04-17 16:05:31 -05001417
1418 cmdiocb = (struct lpfc_iocbq *) arg;
1419
James Smart7054a602007-04-25 09:52:34 -04001420 /* cleanup any ndlp on mbox q waiting for reglogin cmpl */
1421 if ((mb = phba->sli.mbox_active)) {
James Smart04c68492009-05-22 14:52:52 -04001422 if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) &&
James Smart7054a602007-04-25 09:52:34 -04001423 (ndlp == (struct lpfc_nodelist *) mb->context2)) {
James Smart92d7f7b2007-06-17 19:56:38 -05001424 lpfc_nlp_put(ndlp);
James Smart7054a602007-04-25 09:52:34 -04001425 mb->context2 = NULL;
1426 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1427 }
1428 }
1429
James Smart2e0fef82007-06-17 19:56:36 -05001430 spin_lock_irq(&phba->hbalock);
James Smart7054a602007-04-25 09:52:34 -04001431 list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) {
James Smart04c68492009-05-22 14:52:52 -04001432 if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) &&
James Smart7054a602007-04-25 09:52:34 -04001433 (ndlp == (struct lpfc_nodelist *) mb->context2)) {
1434 mp = (struct lpfc_dmabuf *) (mb->context1);
1435 if (mp) {
James Smart98c9ea52007-10-27 13:37:33 -04001436 __lpfc_mbuf_free(phba, mp->virt, mp->phys);
James Smart7054a602007-04-25 09:52:34 -04001437 kfree(mp);
1438 }
James Smart92d7f7b2007-06-17 19:56:38 -05001439 lpfc_nlp_put(ndlp);
James Smart7054a602007-04-25 09:52:34 -04001440 list_del(&mb->list);
James Smart5ffc2662009-11-18 15:39:44 -05001441 phba->sli.mboxq_cnt--;
James Smart7054a602007-04-25 09:52:34 -04001442 mempool_free(mb, phba->mbox_mem_pool);
1443 }
1444 }
James Smart2e0fef82007-06-17 19:56:36 -05001445 spin_unlock_irq(&phba->hbalock);
James Smart7054a602007-04-25 09:52:34 -04001446
James Smart2e0fef82007-06-17 19:56:36 -05001447 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001448 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001449}
1450
1451static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001452lpfc_rcv_padisc_reglogin_issue(struct lpfc_vport *vport,
1453 struct lpfc_nodelist *ndlp,
1454 void *arg,
dea31012005-04-17 16:05:31 -05001455 uint32_t evt)
1456{
James Smart2e0fef82007-06-17 19:56:36 -05001457 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001458
James Smart2e0fef82007-06-17 19:56:36 -05001459 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001460 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001461}
1462
1463static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001464lpfc_rcv_prlo_reglogin_issue(struct lpfc_vport *vport,
1465 struct lpfc_nodelist *ndlp,
1466 void *arg,
dea31012005-04-17 16:05:31 -05001467 uint32_t evt)
1468{
1469 struct lpfc_iocbq *cmdiocb;
1470
1471 cmdiocb = (struct lpfc_iocbq *) arg;
James Smart51ef4c22007-08-02 11:10:31 -04001472 lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001473 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001474}
1475
1476static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001477lpfc_cmpl_reglogin_reglogin_issue(struct lpfc_vport *vport,
1478 struct lpfc_nodelist *ndlp,
1479 void *arg,
1480 uint32_t evt)
dea31012005-04-17 16:05:31 -05001481{
James Smart2e0fef82007-06-17 19:56:36 -05001482 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart2e0fef82007-06-17 19:56:36 -05001483 LPFC_MBOXQ_t *pmb = (LPFC_MBOXQ_t *) arg;
James Smart04c68492009-05-22 14:52:52 -04001484 MAILBOX_t *mb = &pmb->u.mb;
James Smart2e0fef82007-06-17 19:56:36 -05001485 uint32_t did = mb->un.varWords[1];
dea31012005-04-17 16:05:31 -05001486
dea31012005-04-17 16:05:31 -05001487 if (mb->mbxStatus) {
1488 /* RegLogin failed */
James Smarte8b62012007-08-02 11:10:09 -04001489 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
James Smart6d368e52011-05-24 11:44:12 -04001490 "0246 RegLogin failed Data: x%x x%x x%x x%x "
1491 "x%x\n",
1492 did, mb->mbxStatus, vport->port_state,
1493 mb->un.varRegLogin.vpi,
1494 mb->un.varRegLogin.rpi);
James Smartd0e56da2006-07-06 15:49:42 -04001495 /*
1496 * If RegLogin failed due to lack of HBA resources do not
1497 * retry discovery.
1498 */
1499 if (mb->mbxStatus == MBXERR_RPI_FULL) {
James Smart87af33f2007-10-27 13:37:43 -04001500 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
1501 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
James Smartd0e56da2006-07-06 15:49:42 -04001502 return ndlp->nlp_state;
1503 }
1504
James Smart2e0fef82007-06-17 19:56:36 -05001505 /* Put ndlp in npr state set plogi timer for 1 sec */
dea31012005-04-17 16:05:31 -05001506 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ * 1);
James Smart2e0fef82007-06-17 19:56:36 -05001507 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001508 ndlp->nlp_flag |= NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05001509 spin_unlock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001510 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
dea31012005-04-17 16:05:31 -05001511
James Smart2e0fef82007-06-17 19:56:36 -05001512 lpfc_issue_els_logo(vport, ndlp, 0);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001513 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -05001514 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001515 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001516 }
1517
James Smart6d368e52011-05-24 11:44:12 -04001518 /* SLI4 ports have preallocated logical rpis. */
1519 if (vport->phba->sli_rev < LPFC_SLI_REV4)
1520 ndlp->nlp_rpi = mb->un.varWords[0];
1521
James Smart40426292010-12-15 17:58:10 -05001522 ndlp->nlp_flag |= NLP_RPI_REGISTERED;
dea31012005-04-17 16:05:31 -05001523
1524 /* Only if we are not a fabric nport do we issue PRLI */
1525 if (!(ndlp->nlp_type & NLP_FABRIC)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001526 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -05001527 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
1528 lpfc_issue_els_prli(vport, ndlp, 0);
dea31012005-04-17 16:05:31 -05001529 } else {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001530 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -05001531 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
dea31012005-04-17 16:05:31 -05001532 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001533 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001534}
1535
1536static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001537lpfc_device_rm_reglogin_issue(struct lpfc_vport *vport,
1538 struct lpfc_nodelist *ndlp,
1539 void *arg,
dea31012005-04-17 16:05:31 -05001540 uint32_t evt)
1541{
James Smart2e0fef82007-06-17 19:56:36 -05001542 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1543
1544 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1545 spin_lock_irq(shost->host_lock);
James Smarta0f9b482006-04-15 11:52:56 -04001546 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
James Smart2e0fef82007-06-17 19:56:36 -05001547 spin_unlock_irq(shost->host_lock);
James Smarta0f9b482006-04-15 11:52:56 -04001548 return ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05001549 } else {
1550 lpfc_drop_node(vport, ndlp);
James Smarta0f9b482006-04-15 11:52:56 -04001551 return NLP_STE_FREED_NODE;
1552 }
dea31012005-04-17 16:05:31 -05001553}
1554
1555static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001556lpfc_device_recov_reglogin_issue(struct lpfc_vport *vport,
1557 struct lpfc_nodelist *ndlp,
1558 void *arg,
1559 uint32_t evt)
dea31012005-04-17 16:05:31 -05001560{
James Smart2e0fef82007-06-17 19:56:36 -05001561 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1562
James Smart92d7f7b2007-06-17 19:56:38 -05001563 /* Don't do anything that will mess up processing of the
1564 * previous RSCN.
1565 */
1566 if (vport->fc_flag & FC_RSCN_DEFERRED)
1567 return ndlp->nlp_state;
1568
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001569 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -05001570 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1571 spin_lock_irq(shost->host_lock);
James Smartffc95492010-06-07 15:23:17 -04001572 ndlp->nlp_flag |= NLP_IGNR_REG_CMPL;
James Smarta0f9b482006-04-15 11:52:56 -04001573 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
James Smart2e0fef82007-06-17 19:56:36 -05001574 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05001575 lpfc_disc_set_adisc(vport, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001576 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001577}
1578
1579static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001580lpfc_rcv_plogi_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1581 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001582{
1583 struct lpfc_iocbq *cmdiocb;
1584
1585 cmdiocb = (struct lpfc_iocbq *) arg;
1586
James Smart2e0fef82007-06-17 19:56:36 -05001587 lpfc_rcv_plogi(vport, ndlp, cmdiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001588 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001589}
1590
1591static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001592lpfc_rcv_prli_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1593 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001594{
James Smart2e0fef82007-06-17 19:56:36 -05001595 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001596
James Smart2e0fef82007-06-17 19:56:36 -05001597 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001598 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001599}
1600
1601static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001602lpfc_rcv_logo_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1603 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001604{
James Smart2e0fef82007-06-17 19:56:36 -05001605 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001606
1607 /* Software abort outstanding PRLI before sending acc */
James Smart2e0fef82007-06-17 19:56:36 -05001608 lpfc_els_abort(vport->phba, ndlp);
dea31012005-04-17 16:05:31 -05001609
James Smart2e0fef82007-06-17 19:56:36 -05001610 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001611 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001612}
1613
1614static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001615lpfc_rcv_padisc_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1616 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001617{
James Smart2e0fef82007-06-17 19:56:36 -05001618 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001619
James Smart2e0fef82007-06-17 19:56:36 -05001620 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001621 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001622}
1623
1624/* This routine is envoked when we rcv a PRLO request from a nport
1625 * we are logged into. We should send back a PRLO rsp setting the
1626 * appropriate bits.
1627 * NEXT STATE = PRLI_ISSUE
1628 */
1629static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001630lpfc_rcv_prlo_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1631 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001632{
James Smart2e0fef82007-06-17 19:56:36 -05001633 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001634
James Smart51ef4c22007-08-02 11:10:31 -04001635 lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001636 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001637}
1638
1639static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001640lpfc_cmpl_prli_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1641 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001642{
James Smart92d7f7b2007-06-17 19:56:38 -05001643 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001644 struct lpfc_iocbq *cmdiocb, *rspiocb;
James Smart2e0fef82007-06-17 19:56:36 -05001645 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001646 IOCB_t *irsp;
1647 PRLI *npr;
1648
1649 cmdiocb = (struct lpfc_iocbq *) arg;
1650 rspiocb = cmdiocb->context_un.rsp_iocb;
1651 npr = (PRLI *)lpfc_check_elscmpl_iocb(phba, cmdiocb, rspiocb);
1652
1653 irsp = &rspiocb->iocb;
1654 if (irsp->ulpStatus) {
James Smart858c9f62007-06-17 19:56:39 -05001655 if ((vport->port_type == LPFC_NPIV_PORT) &&
James Smart3de2a652007-08-02 11:09:59 -04001656 vport->cfg_restrict_login) {
James Smart858c9f62007-06-17 19:56:39 -05001657 goto out;
1658 }
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001659 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -05001660 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001661 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001662 }
1663
1664 /* Check out PRLI rsp */
1665 ndlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR);
1666 ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
1667 if ((npr->acceptRspCode == PRLI_REQ_EXECUTED) &&
1668 (npr->prliType == PRLI_FCP_TYPE)) {
1669 if (npr->initiatorFunc)
1670 ndlp->nlp_type |= NLP_FCP_INITIATOR;
1671 if (npr->targetFunc)
1672 ndlp->nlp_type |= NLP_FCP_TARGET;
1673 if (npr->Retry)
1674 ndlp->nlp_fcp_info |= NLP_FCP_2_DEVICE;
1675 }
James Smart92d7f7b2007-06-17 19:56:38 -05001676 if (!(ndlp->nlp_type & NLP_FCP_TARGET) &&
1677 (vport->port_type == LPFC_NPIV_PORT) &&
James Smart3de2a652007-08-02 11:09:59 -04001678 vport->cfg_restrict_login) {
James Smart858c9f62007-06-17 19:56:39 -05001679out:
James Smart92d7f7b2007-06-17 19:56:38 -05001680 spin_lock_irq(shost->host_lock);
1681 ndlp->nlp_flag |= NLP_TARGET_REMOVE;
1682 spin_unlock_irq(shost->host_lock);
1683 lpfc_issue_els_logo(vport, ndlp, 0);
1684
1685 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
James Smart87af33f2007-10-27 13:37:43 -04001686 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
James Smart92d7f7b2007-06-17 19:56:38 -05001687 return ndlp->nlp_state;
1688 }
dea31012005-04-17 16:05:31 -05001689
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001690 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
James Smart92d7f7b2007-06-17 19:56:38 -05001691 if (ndlp->nlp_type & NLP_FCP_TARGET)
1692 lpfc_nlp_set_state(vport, ndlp, NLP_STE_MAPPED_NODE);
1693 else
1694 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001695 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001696}
1697
1698/*! lpfc_device_rm_prli_issue
James Smart92d7f7b2007-06-17 19:56:38 -05001699 *
1700 * \pre
1701 * \post
1702 * \param phba
1703 * \param ndlp
1704 * \param arg
1705 * \param evt
1706 * \return uint32_t
1707 *
1708 * \b Description:
1709 * This routine is envoked when we a request to remove a nport we are in the
1710 * process of PRLIing. We should software abort outstanding prli, unreg
1711 * login, send a logout. We will change node state to UNUSED_NODE, put it
1712 * on plogi list so it can be freed when LOGO completes.
1713 *
1714 */
1715
dea31012005-04-17 16:05:31 -05001716static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001717lpfc_device_rm_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1718 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001719{
James Smart2e0fef82007-06-17 19:56:36 -05001720 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001721
James Smart2e0fef82007-06-17 19:56:36 -05001722 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1723 spin_lock_irq(shost->host_lock);
1724 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
1725 spin_unlock_irq(shost->host_lock);
1726 return ndlp->nlp_state;
1727 } else {
1728 /* software abort outstanding PLOGI */
1729 lpfc_els_abort(vport->phba, ndlp);
1730
1731 lpfc_drop_node(vport, ndlp);
James Smarta0f9b482006-04-15 11:52:56 -04001732 return NLP_STE_FREED_NODE;
1733 }
dea31012005-04-17 16:05:31 -05001734}
1735
1736
1737/*! lpfc_device_recov_prli_issue
James Smart92d7f7b2007-06-17 19:56:38 -05001738 *
1739 * \pre
1740 * \post
1741 * \param phba
1742 * \param ndlp
1743 * \param arg
1744 * \param evt
1745 * \return uint32_t
1746 *
1747 * \b Description:
1748 * The routine is envoked when the state of a device is unknown, like
1749 * during a link down. We should remove the nodelist entry from the
1750 * unmapped list, issue a UNREG_LOGIN, do a software abort of the
1751 * outstanding PRLI command, then free the node entry.
1752 */
dea31012005-04-17 16:05:31 -05001753static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001754lpfc_device_recov_prli_issue(struct lpfc_vport *vport,
1755 struct lpfc_nodelist *ndlp,
1756 void *arg,
1757 uint32_t evt)
dea31012005-04-17 16:05:31 -05001758{
James Smart2e0fef82007-06-17 19:56:36 -05001759 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1760 struct lpfc_hba *phba = vport->phba;
1761
James Smart92d7f7b2007-06-17 19:56:38 -05001762 /* Don't do anything that will mess up processing of the
1763 * previous RSCN.
1764 */
1765 if (vport->fc_flag & FC_RSCN_DEFERRED)
1766 return ndlp->nlp_state;
1767
dea31012005-04-17 16:05:31 -05001768 /* software abort outstanding PRLI */
James Smart07951072007-04-25 09:51:38 -04001769 lpfc_els_abort(phba, ndlp);
dea31012005-04-17 16:05:31 -05001770
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001771 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -05001772 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1773 spin_lock_irq(shost->host_lock);
James Smarta0f9b482006-04-15 11:52:56 -04001774 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
James Smart2e0fef82007-06-17 19:56:36 -05001775 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05001776 lpfc_disc_set_adisc(vport, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001777 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001778}
1779
1780static uint32_t
James Smart086a3452012-08-14 14:25:21 -04001781lpfc_rcv_plogi_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1782 void *arg, uint32_t evt)
1783{
1784 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *)arg;
1785 struct ls_rjt stat;
1786
1787 memset(&stat, 0, sizeof(struct ls_rjt));
1788 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
1789 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
1790 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
1791 return ndlp->nlp_state;
1792}
1793
1794static uint32_t
1795lpfc_rcv_prli_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1796 void *arg, uint32_t evt)
1797{
1798 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *)arg;
1799 struct ls_rjt stat;
1800
1801 memset(&stat, 0, sizeof(struct ls_rjt));
1802 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
1803 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
1804 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
1805 return ndlp->nlp_state;
1806}
1807
1808static uint32_t
1809lpfc_rcv_logo_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1810 void *arg, uint32_t evt)
1811{
1812 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1813 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *)arg;
1814
1815 spin_lock_irq(shost->host_lock);
1816 ndlp->nlp_flag &= NLP_LOGO_ACC;
1817 spin_unlock_irq(shost->host_lock);
1818 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
1819 return ndlp->nlp_state;
1820}
1821
1822static uint32_t
1823lpfc_rcv_padisc_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1824 void *arg, uint32_t evt)
1825{
1826 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *)arg;
1827 struct ls_rjt stat;
1828
1829 memset(&stat, 0, sizeof(struct ls_rjt));
1830 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
1831 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
1832 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
1833 return ndlp->nlp_state;
1834}
1835
1836static uint32_t
1837lpfc_rcv_prlo_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1838 void *arg, uint32_t evt)
1839{
1840 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *)arg;
1841 struct ls_rjt stat;
1842
1843 memset(&stat, 0, sizeof(struct ls_rjt));
1844 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
1845 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
1846 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
1847 return ndlp->nlp_state;
1848}
1849
1850static uint32_t
1851lpfc_cmpl_logo_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1852 void *arg, uint32_t evt)
1853{
1854 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1855
1856 ndlp->nlp_prev_state = NLP_STE_LOGO_ISSUE;
1857 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1858 spin_lock_irq(shost->host_lock);
1859 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
1860 spin_unlock_irq(shost->host_lock);
1861 lpfc_disc_set_adisc(vport, ndlp);
1862 return ndlp->nlp_state;
1863}
1864
1865static uint32_t
1866lpfc_device_rm_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1867 void *arg, uint32_t evt)
1868{
1869 /*
1870 * Take no action. If a LOGO is outstanding, then possibly DevLoss has
1871 * timed out and is calling for Device Remove. In this case, the LOGO
1872 * must be allowed to complete in state LOGO_ISSUE so that the rpi
1873 * and other NLP flags are correctly cleaned up.
1874 */
1875 return ndlp->nlp_state;
1876}
1877
1878static uint32_t
1879lpfc_device_recov_logo_issue(struct lpfc_vport *vport,
1880 struct lpfc_nodelist *ndlp,
1881 void *arg, uint32_t evt)
1882{
1883 /*
1884 * Device Recovery events have no meaning for a node with a LOGO
1885 * outstanding. The LOGO has to complete first and handle the
1886 * node from that point.
1887 */
1888 return ndlp->nlp_state;
1889}
1890
1891static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001892lpfc_rcv_plogi_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1893 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001894{
James Smart2e0fef82007-06-17 19:56:36 -05001895 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001896
James Smart2e0fef82007-06-17 19:56:36 -05001897 lpfc_rcv_plogi(vport, ndlp, cmdiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001898 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001899}
1900
1901static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001902lpfc_rcv_prli_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1903 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001904{
James Smart2e0fef82007-06-17 19:56:36 -05001905 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001906
James Smart2e0fef82007-06-17 19:56:36 -05001907 lpfc_rcv_prli(vport, ndlp, cmdiocb);
1908 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001909 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001910}
1911
1912static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001913lpfc_rcv_logo_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1914 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001915{
James Smart2e0fef82007-06-17 19:56:36 -05001916 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001917
James Smart2e0fef82007-06-17 19:56:36 -05001918 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001919 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001920}
1921
1922static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001923lpfc_rcv_padisc_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1924 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001925{
James Smart2e0fef82007-06-17 19:56:36 -05001926 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001927
James Smart2e0fef82007-06-17 19:56:36 -05001928 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001929 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001930}
1931
1932static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001933lpfc_rcv_prlo_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1934 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001935{
James Smart2e0fef82007-06-17 19:56:36 -05001936 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001937
James Smart51ef4c22007-08-02 11:10:31 -04001938 lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001939 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001940}
1941
1942static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001943lpfc_device_recov_unmap_node(struct lpfc_vport *vport,
1944 struct lpfc_nodelist *ndlp,
1945 void *arg,
1946 uint32_t evt)
dea31012005-04-17 16:05:31 -05001947{
James Smart2e0fef82007-06-17 19:56:36 -05001948 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1949
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001950 ndlp->nlp_prev_state = NLP_STE_UNMAPPED_NODE;
James Smart2e0fef82007-06-17 19:56:36 -05001951 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1952 spin_lock_irq(shost->host_lock);
James Smarta0f9b482006-04-15 11:52:56 -04001953 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
James Smart2e0fef82007-06-17 19:56:36 -05001954 spin_unlock_irq(shost->host_lock);
1955 lpfc_disc_set_adisc(vport, ndlp);
dea31012005-04-17 16:05:31 -05001956
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001957 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001958}
1959
1960static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001961lpfc_rcv_plogi_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1962 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001963{
James Smart2e0fef82007-06-17 19:56:36 -05001964 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001965
James Smart2e0fef82007-06-17 19:56:36 -05001966 lpfc_rcv_plogi(vport, ndlp, cmdiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001967 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001968}
1969
1970static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001971lpfc_rcv_prli_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1972 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001973{
James Smart2e0fef82007-06-17 19:56:36 -05001974 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001975
James Smart2e0fef82007-06-17 19:56:36 -05001976 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001977 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001978}
1979
1980static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001981lpfc_rcv_logo_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1982 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001983{
James Smart2e0fef82007-06-17 19:56:36 -05001984 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001985
James Smart2e0fef82007-06-17 19:56:36 -05001986 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001987 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001988}
1989
1990static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001991lpfc_rcv_padisc_mapped_node(struct lpfc_vport *vport,
1992 struct lpfc_nodelist *ndlp,
1993 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001994{
James Smart2e0fef82007-06-17 19:56:36 -05001995 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001996
James Smart2e0fef82007-06-17 19:56:36 -05001997 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001998 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001999}
2000
2001static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05002002lpfc_rcv_prlo_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2003 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05002004{
James Smart2e0fef82007-06-17 19:56:36 -05002005 struct lpfc_hba *phba = vport->phba;
2006 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05002007
2008 /* flush the target */
James Smart51ef4c22007-08-02 11:10:31 -04002009 lpfc_sli_abort_iocb(vport, &phba->sli.ring[phba->sli.fcp_ring],
2010 ndlp->nlp_sid, 0, LPFC_CTX_TGT);
dea31012005-04-17 16:05:31 -05002011
2012 /* Treat like rcv logo */
James Smart2e0fef82007-06-17 19:56:36 -05002013 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_PRLO);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002014 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05002015}
2016
2017static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05002018lpfc_device_recov_mapped_node(struct lpfc_vport *vport,
2019 struct lpfc_nodelist *ndlp,
2020 void *arg,
2021 uint32_t evt)
dea31012005-04-17 16:05:31 -05002022{
James Smart2e0fef82007-06-17 19:56:36 -05002023 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2024
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002025 ndlp->nlp_prev_state = NLP_STE_MAPPED_NODE;
James Smart2e0fef82007-06-17 19:56:36 -05002026 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
2027 spin_lock_irq(shost->host_lock);
James Smarta0f9b482006-04-15 11:52:56 -04002028 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
James Smart2e0fef82007-06-17 19:56:36 -05002029 spin_unlock_irq(shost->host_lock);
2030 lpfc_disc_set_adisc(vport, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002031 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05002032}
2033
2034static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05002035lpfc_rcv_plogi_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2036 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05002037{
James Smart2e0fef82007-06-17 19:56:36 -05002038 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2039 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05002040
2041 /* Ignore PLOGI if we have an outstanding LOGO */
James Smart0d2b6b82008-06-14 22:52:47 -04002042 if (ndlp->nlp_flag & (NLP_LOGO_SND | NLP_LOGO_ACC))
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002043 return ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002044 if (lpfc_rcv_plogi(vport, ndlp, cmdiocb)) {
James Smart0d2b6b82008-06-14 22:52:47 -04002045 lpfc_cancel_retry_delay_tmo(vport, ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05002046 spin_lock_irq(shost->host_lock);
James Smart0d2b6b82008-06-14 22:52:47 -04002047 ndlp->nlp_flag &= ~(NLP_NPR_ADISC | NLP_NPR_2B_DISC);
James Smart2e0fef82007-06-17 19:56:36 -05002048 spin_unlock_irq(shost->host_lock);
James Smart0d2b6b82008-06-14 22:52:47 -04002049 } else if (!(ndlp->nlp_flag & NLP_NPR_2B_DISC)) {
2050 /* send PLOGI immediately, move to PLOGI issue state */
2051 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
2052 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
2053 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
2054 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
2055 }
dea31012005-04-17 16:05:31 -05002056 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002057 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05002058}
2059
2060static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05002061lpfc_rcv_prli_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2062 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05002063{
James Smart2e0fef82007-06-17 19:56:36 -05002064 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2065 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2066 struct ls_rjt stat;
dea31012005-04-17 16:05:31 -05002067
2068 memset(&stat, 0, sizeof (struct ls_rjt));
2069 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
2070 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
James Smart858c9f62007-06-17 19:56:39 -05002071 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05002072
2073 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
2074 if (ndlp->nlp_flag & NLP_NPR_ADISC) {
James Smart2e0fef82007-06-17 19:56:36 -05002075 spin_lock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002076 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002077 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
James Smart2e0fef82007-06-17 19:56:36 -05002078 spin_unlock_irq(shost->host_lock);
2079 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
2080 lpfc_issue_els_adisc(vport, ndlp, 0);
dea31012005-04-17 16:05:31 -05002081 } else {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002082 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
James Smart2e0fef82007-06-17 19:56:36 -05002083 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
2084 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
dea31012005-04-17 16:05:31 -05002085 }
2086 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002087 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05002088}
2089
2090static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05002091lpfc_rcv_logo_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2092 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05002093{
James Smart2e0fef82007-06-17 19:56:36 -05002094 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05002095
James Smart2e0fef82007-06-17 19:56:36 -05002096 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002097 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05002098}
2099
2100static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05002101lpfc_rcv_padisc_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2102 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05002103{
James Smart2e0fef82007-06-17 19:56:36 -05002104 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05002105
James Smart2e0fef82007-06-17 19:56:36 -05002106 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
James Smart33ccf8d2006-08-17 11:57:58 -04002107 /*
2108 * Do not start discovery if discovery is about to start
2109 * or discovery in progress for this node. Starting discovery
2110 * here will affect the counting of discovery threads.
2111 */
James Smart2fb9bd82006-12-02 13:33:57 -05002112 if (!(ndlp->nlp_flag & NLP_DELAY_TMO) &&
James Smart92d7f7b2007-06-17 19:56:38 -05002113 !(ndlp->nlp_flag & NLP_NPR_2B_DISC)) {
dea31012005-04-17 16:05:31 -05002114 if (ndlp->nlp_flag & NLP_NPR_ADISC) {
James Smart92d7f7b2007-06-17 19:56:38 -05002115 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
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_ADISC_ISSUE);
2118 lpfc_issue_els_adisc(vport, ndlp, 0);
dea31012005-04-17 16:05:31 -05002119 } else {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002120 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
James Smart2e0fef82007-06-17 19:56:36 -05002121 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
2122 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
dea31012005-04-17 16:05:31 -05002123 }
2124 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002125 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05002126}
2127
2128static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05002129lpfc_rcv_prlo_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2130 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05002131{
James Smart2e0fef82007-06-17 19:56:36 -05002132 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2133 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05002134
James Smart2e0fef82007-06-17 19:56:36 -05002135 spin_lock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002136 ndlp->nlp_flag |= NLP_LOGO_ACC;
James Smart2e0fef82007-06-17 19:56:36 -05002137 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002138
James Smart51ef4c22007-08-02 11:10:31 -04002139 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05002140
James Smart2e0fef82007-06-17 19:56:36 -05002141 if ((ndlp->nlp_flag & NLP_DELAY_TMO) == 0) {
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002142 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ * 1);
James Smart2e0fef82007-06-17 19:56:36 -05002143 spin_lock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002144 ndlp->nlp_flag |= NLP_DELAY_TMO;
2145 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
James Smart2e0fef82007-06-17 19:56:36 -05002146 spin_unlock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002147 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002148 } else {
James Smart2e0fef82007-06-17 19:56:36 -05002149 spin_lock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002150 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
James Smart2e0fef82007-06-17 19:56:36 -05002151 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002152 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002153 return ndlp->nlp_state;
2154}
dea31012005-04-17 16:05:31 -05002155
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002156static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05002157lpfc_cmpl_plogi_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2158 void *arg, uint32_t evt)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002159{
2160 struct lpfc_iocbq *cmdiocb, *rspiocb;
James Smarta0f9b482006-04-15 11:52:56 -04002161 IOCB_t *irsp;
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002162
2163 cmdiocb = (struct lpfc_iocbq *) arg;
2164 rspiocb = cmdiocb->context_un.rsp_iocb;
James Smarta0f9b482006-04-15 11:52:56 -04002165
2166 irsp = &rspiocb->iocb;
2167 if (irsp->ulpStatus) {
James Smarta8adb832007-10-27 13:37:53 -04002168 ndlp->nlp_flag |= NLP_DEFER_RM;
James Smarta0f9b482006-04-15 11:52:56 -04002169 return NLP_STE_FREED_NODE;
2170 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002171 return ndlp->nlp_state;
2172}
2173
2174static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05002175lpfc_cmpl_prli_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2176 void *arg, uint32_t evt)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002177{
2178 struct lpfc_iocbq *cmdiocb, *rspiocb;
James Smarta0f9b482006-04-15 11:52:56 -04002179 IOCB_t *irsp;
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002180
2181 cmdiocb = (struct lpfc_iocbq *) arg;
2182 rspiocb = cmdiocb->context_un.rsp_iocb;
James Smarta0f9b482006-04-15 11:52:56 -04002183
2184 irsp = &rspiocb->iocb;
2185 if (irsp->ulpStatus && (ndlp->nlp_flag & NLP_NODEV_REMOVE)) {
James Smart2e0fef82007-06-17 19:56:36 -05002186 lpfc_drop_node(vport, ndlp);
James Smarta0f9b482006-04-15 11:52:56 -04002187 return NLP_STE_FREED_NODE;
2188 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002189 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05002190}
2191
2192static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05002193lpfc_cmpl_logo_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2194 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05002195{
James Smartd7c255b2008-08-24 21:50:00 -04002196 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart086a3452012-08-14 14:25:21 -04002197
2198 /* For the fabric port just clear the fc flags. */
James Smartd7c255b2008-08-24 21:50:00 -04002199 if (ndlp->nlp_DID == Fabric_DID) {
2200 spin_lock_irq(shost->host_lock);
2201 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
2202 spin_unlock_irq(shost->host_lock);
2203 }
James Smart2e0fef82007-06-17 19:56:36 -05002204 lpfc_unreg_rpi(vport, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002205 return ndlp->nlp_state;
2206}
2207
2208static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05002209lpfc_cmpl_adisc_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2210 void *arg, uint32_t evt)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002211{
2212 struct lpfc_iocbq *cmdiocb, *rspiocb;
James Smarta0f9b482006-04-15 11:52:56 -04002213 IOCB_t *irsp;
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002214
2215 cmdiocb = (struct lpfc_iocbq *) arg;
2216 rspiocb = cmdiocb->context_un.rsp_iocb;
James Smarta0f9b482006-04-15 11:52:56 -04002217
2218 irsp = &rspiocb->iocb;
2219 if (irsp->ulpStatus && (ndlp->nlp_flag & NLP_NODEV_REMOVE)) {
James Smart2e0fef82007-06-17 19:56:36 -05002220 lpfc_drop_node(vport, ndlp);
James Smarta0f9b482006-04-15 11:52:56 -04002221 return NLP_STE_FREED_NODE;
2222 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002223 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05002224}
2225
2226static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05002227lpfc_cmpl_reglogin_npr_node(struct lpfc_vport *vport,
2228 struct lpfc_nodelist *ndlp,
2229 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05002230{
James Smart2e0fef82007-06-17 19:56:36 -05002231 LPFC_MBOXQ_t *pmb = (LPFC_MBOXQ_t *) arg;
James Smart04c68492009-05-22 14:52:52 -04002232 MAILBOX_t *mb = &pmb->u.mb;
dea31012005-04-17 16:05:31 -05002233
James Smart04c68492009-05-22 14:52:52 -04002234 if (!mb->mbxStatus) {
James Smart6d368e52011-05-24 11:44:12 -04002235 /* SLI4 ports have preallocated logical rpis. */
2236 if (vport->phba->sli_rev < LPFC_SLI_REV4)
2237 ndlp->nlp_rpi = mb->un.varWords[0];
James Smart40426292010-12-15 17:58:10 -05002238 ndlp->nlp_flag |= NLP_RPI_REGISTERED;
James Smart04c68492009-05-22 14:52:52 -04002239 } else {
James Smarta0f9b482006-04-15 11:52:56 -04002240 if (ndlp->nlp_flag & NLP_NODEV_REMOVE) {
James Smart2e0fef82007-06-17 19:56:36 -05002241 lpfc_drop_node(vport, ndlp);
James Smarta0f9b482006-04-15 11:52:56 -04002242 return NLP_STE_FREED_NODE;
2243 }
2244 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002245 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05002246}
2247
2248static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05002249lpfc_device_rm_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2250 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05002251{
James Smart2e0fef82007-06-17 19:56:36 -05002252 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2253
James Smarta0f9b482006-04-15 11:52:56 -04002254 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
James Smart2e0fef82007-06-17 19:56:36 -05002255 spin_lock_irq(shost->host_lock);
James Smarta0f9b482006-04-15 11:52:56 -04002256 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
James Smart2e0fef82007-06-17 19:56:36 -05002257 spin_unlock_irq(shost->host_lock);
James Smarta0f9b482006-04-15 11:52:56 -04002258 return ndlp->nlp_state;
2259 }
James Smart2e0fef82007-06-17 19:56:36 -05002260 lpfc_drop_node(vport, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002261 return NLP_STE_FREED_NODE;
dea31012005-04-17 16:05:31 -05002262}
2263
2264static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05002265lpfc_device_recov_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2266 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05002267{
James Smart2e0fef82007-06-17 19:56:36 -05002268 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2269
James Smart92d7f7b2007-06-17 19:56:38 -05002270 /* Don't do anything that will mess up processing of the
2271 * previous RSCN.
2272 */
2273 if (vport->fc_flag & FC_RSCN_DEFERRED)
2274 return ndlp->nlp_state;
2275
James Smarteaf15d52008-12-04 22:39:29 -05002276 lpfc_cancel_retry_delay_tmo(vport, ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05002277 spin_lock_irq(shost->host_lock);
James Smarta0f9b482006-04-15 11:52:56 -04002278 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
James Smart2e0fef82007-06-17 19:56:36 -05002279 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002280 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05002281}
2282
2283
2284/* This next section defines the NPort Discovery State Machine */
2285
2286/* There are 4 different double linked lists nodelist entries can reside on.
2287 * The plogi list and adisc list are used when Link Up discovery or RSCN
2288 * processing is needed. Each list holds the nodes that we will send PLOGI
2289 * or ADISC on. These lists will keep track of what nodes will be effected
2290 * by an RSCN, or a Link Up (Typically, all nodes are effected on Link Up).
2291 * The unmapped_list will contain all nodes that we have successfully logged
2292 * into at the Fibre Channel level. The mapped_list will contain all nodes
2293 * that are mapped FCP targets.
2294 */
2295/*
2296 * The bind list is a list of undiscovered (potentially non-existent) nodes
2297 * that we have saved binding information on. This information is used when
2298 * nodes transition from the unmapped to the mapped list.
2299 */
2300/* For UNUSED_NODE state, the node has just been allocated .
2301 * For PLOGI_ISSUE and REG_LOGIN_ISSUE, the node is on
2302 * the PLOGI list. For REG_LOGIN_COMPL, the node is taken off the PLOGI list
2303 * and put on the unmapped list. For ADISC processing, the node is taken off
2304 * the ADISC list and placed on either the mapped or unmapped list (depending
2305 * on its previous state). Once on the unmapped list, a PRLI is issued and the
2306 * state changed to PRLI_ISSUE. When the PRLI completion occurs, the state is
2307 * changed to UNMAPPED_NODE. If the completion indicates a mapped
2308 * node, the node is taken off the unmapped list. The binding list is checked
2309 * for a valid binding, or a binding is automatically assigned. If binding
2310 * assignment is unsuccessful, the node is left on the unmapped list. If
2311 * binding assignment is successful, the associated binding list entry (if
2312 * any) is removed, and the node is placed on the mapped list.
2313 */
2314/*
2315 * For a Link Down, all nodes on the ADISC, PLOGI, unmapped or mapped
James Smartc01f3202006-08-18 17:47:08 -04002316 * lists will receive a DEVICE_RECOVERY event. If the linkdown or devloss timers
dea31012005-04-17 16:05:31 -05002317 * expire, all effected nodes will receive a DEVICE_RM event.
2318 */
2319/*
2320 * For a Link Up or RSCN, all nodes will move from the mapped / unmapped lists
2321 * to either the ADISC or PLOGI list. After a Nameserver query or ALPA loopmap
2322 * check, additional nodes may be added or removed (via DEVICE_RM) to / from
2323 * the PLOGI or ADISC lists. Once the PLOGI and ADISC lists are populated,
2324 * we will first process the ADISC list. 32 entries are processed initially and
2325 * ADISC is initited for each one. Completions / Events for each node are
2326 * funnelled thru the state machine. As each node finishes ADISC processing, it
2327 * starts ADISC for any nodes waiting for ADISC processing. If no nodes are
2328 * waiting, and the ADISC list count is identically 0, then we are done. For
2329 * Link Up discovery, since all nodes on the PLOGI list are UNREG_LOGIN'ed, we
2330 * can issue a CLEAR_LA and reenable Link Events. Next we will process the PLOGI
2331 * list. 32 entries are processed initially and PLOGI is initited for each one.
2332 * Completions / Events for each node are funnelled thru the state machine. As
2333 * each node finishes PLOGI processing, it starts PLOGI for any nodes waiting
2334 * for PLOGI processing. If no nodes are waiting, and the PLOGI list count is
2335 * indentically 0, then we are done. We have now completed discovery / RSCN
2336 * handling. Upon completion, ALL nodes should be on either the mapped or
2337 * unmapped lists.
2338 */
2339
2340static uint32_t (*lpfc_disc_action[NLP_STE_MAX_STATE * NLP_EVT_MAX_EVENT])
James Smart2e0fef82007-06-17 19:56:36 -05002341 (struct lpfc_vport *, struct lpfc_nodelist *, void *, uint32_t) = {
dea31012005-04-17 16:05:31 -05002342 /* Action routine Event Current State */
2343 lpfc_rcv_plogi_unused_node, /* RCV_PLOGI UNUSED_NODE */
2344 lpfc_rcv_els_unused_node, /* RCV_PRLI */
2345 lpfc_rcv_logo_unused_node, /* RCV_LOGO */
2346 lpfc_rcv_els_unused_node, /* RCV_ADISC */
2347 lpfc_rcv_els_unused_node, /* RCV_PDISC */
2348 lpfc_rcv_els_unused_node, /* RCV_PRLO */
2349 lpfc_disc_illegal, /* CMPL_PLOGI */
2350 lpfc_disc_illegal, /* CMPL_PRLI */
2351 lpfc_cmpl_logo_unused_node, /* CMPL_LOGO */
2352 lpfc_disc_illegal, /* CMPL_ADISC */
2353 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2354 lpfc_device_rm_unused_node, /* DEVICE_RM */
James Smartdf9e1b52011-12-13 13:22:17 -05002355 lpfc_device_recov_unused_node, /* DEVICE_RECOVERY */
dea31012005-04-17 16:05:31 -05002356
2357 lpfc_rcv_plogi_plogi_issue, /* RCV_PLOGI PLOGI_ISSUE */
James Smart92d7f7b2007-06-17 19:56:38 -05002358 lpfc_rcv_prli_plogi_issue, /* RCV_PRLI */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002359 lpfc_rcv_logo_plogi_issue, /* RCV_LOGO */
dea31012005-04-17 16:05:31 -05002360 lpfc_rcv_els_plogi_issue, /* RCV_ADISC */
2361 lpfc_rcv_els_plogi_issue, /* RCV_PDISC */
2362 lpfc_rcv_els_plogi_issue, /* RCV_PRLO */
2363 lpfc_cmpl_plogi_plogi_issue, /* CMPL_PLOGI */
2364 lpfc_disc_illegal, /* CMPL_PRLI */
James Smart0ff10d42008-01-11 01:52:36 -05002365 lpfc_cmpl_logo_plogi_issue, /* CMPL_LOGO */
dea31012005-04-17 16:05:31 -05002366 lpfc_disc_illegal, /* CMPL_ADISC */
James Smart0ff10d42008-01-11 01:52:36 -05002367 lpfc_cmpl_reglogin_plogi_issue,/* CMPL_REG_LOGIN */
dea31012005-04-17 16:05:31 -05002368 lpfc_device_rm_plogi_issue, /* DEVICE_RM */
2369 lpfc_device_recov_plogi_issue, /* DEVICE_RECOVERY */
2370
2371 lpfc_rcv_plogi_adisc_issue, /* RCV_PLOGI ADISC_ISSUE */
2372 lpfc_rcv_prli_adisc_issue, /* RCV_PRLI */
2373 lpfc_rcv_logo_adisc_issue, /* RCV_LOGO */
2374 lpfc_rcv_padisc_adisc_issue, /* RCV_ADISC */
2375 lpfc_rcv_padisc_adisc_issue, /* RCV_PDISC */
2376 lpfc_rcv_prlo_adisc_issue, /* RCV_PRLO */
2377 lpfc_disc_illegal, /* CMPL_PLOGI */
2378 lpfc_disc_illegal, /* CMPL_PRLI */
2379 lpfc_disc_illegal, /* CMPL_LOGO */
2380 lpfc_cmpl_adisc_adisc_issue, /* CMPL_ADISC */
2381 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2382 lpfc_device_rm_adisc_issue, /* DEVICE_RM */
2383 lpfc_device_recov_adisc_issue, /* DEVICE_RECOVERY */
2384
2385 lpfc_rcv_plogi_reglogin_issue, /* RCV_PLOGI REG_LOGIN_ISSUE */
2386 lpfc_rcv_prli_reglogin_issue, /* RCV_PLOGI */
2387 lpfc_rcv_logo_reglogin_issue, /* RCV_LOGO */
2388 lpfc_rcv_padisc_reglogin_issue, /* RCV_ADISC */
2389 lpfc_rcv_padisc_reglogin_issue, /* RCV_PDISC */
2390 lpfc_rcv_prlo_reglogin_issue, /* RCV_PRLO */
James Smart87af33f2007-10-27 13:37:43 -04002391 lpfc_cmpl_plogi_illegal, /* CMPL_PLOGI */
dea31012005-04-17 16:05:31 -05002392 lpfc_disc_illegal, /* CMPL_PRLI */
2393 lpfc_disc_illegal, /* CMPL_LOGO */
2394 lpfc_disc_illegal, /* CMPL_ADISC */
2395 lpfc_cmpl_reglogin_reglogin_issue,/* CMPL_REG_LOGIN */
2396 lpfc_device_rm_reglogin_issue, /* DEVICE_RM */
2397 lpfc_device_recov_reglogin_issue,/* DEVICE_RECOVERY */
2398
2399 lpfc_rcv_plogi_prli_issue, /* RCV_PLOGI PRLI_ISSUE */
2400 lpfc_rcv_prli_prli_issue, /* RCV_PRLI */
2401 lpfc_rcv_logo_prli_issue, /* RCV_LOGO */
2402 lpfc_rcv_padisc_prli_issue, /* RCV_ADISC */
2403 lpfc_rcv_padisc_prli_issue, /* RCV_PDISC */
2404 lpfc_rcv_prlo_prli_issue, /* RCV_PRLO */
James Smart87af33f2007-10-27 13:37:43 -04002405 lpfc_cmpl_plogi_illegal, /* CMPL_PLOGI */
dea31012005-04-17 16:05:31 -05002406 lpfc_cmpl_prli_prli_issue, /* CMPL_PRLI */
2407 lpfc_disc_illegal, /* CMPL_LOGO */
2408 lpfc_disc_illegal, /* CMPL_ADISC */
2409 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2410 lpfc_device_rm_prli_issue, /* DEVICE_RM */
2411 lpfc_device_recov_prli_issue, /* DEVICE_RECOVERY */
2412
James Smart086a3452012-08-14 14:25:21 -04002413 lpfc_rcv_plogi_logo_issue, /* RCV_PLOGI LOGO_ISSUE */
2414 lpfc_rcv_prli_logo_issue, /* RCV_PRLI */
2415 lpfc_rcv_logo_logo_issue, /* RCV_LOGO */
2416 lpfc_rcv_padisc_logo_issue, /* RCV_ADISC */
2417 lpfc_rcv_padisc_logo_issue, /* RCV_PDISC */
2418 lpfc_rcv_prlo_logo_issue, /* RCV_PRLO */
2419 lpfc_cmpl_plogi_illegal, /* CMPL_PLOGI */
2420 lpfc_disc_illegal, /* CMPL_PRLI */
2421 lpfc_cmpl_logo_logo_issue, /* CMPL_LOGO */
2422 lpfc_disc_illegal, /* CMPL_ADISC */
2423 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2424 lpfc_device_rm_logo_issue, /* DEVICE_RM */
2425 lpfc_device_recov_logo_issue, /* DEVICE_RECOVERY */
2426
dea31012005-04-17 16:05:31 -05002427 lpfc_rcv_plogi_unmap_node, /* RCV_PLOGI UNMAPPED_NODE */
2428 lpfc_rcv_prli_unmap_node, /* RCV_PRLI */
2429 lpfc_rcv_logo_unmap_node, /* RCV_LOGO */
2430 lpfc_rcv_padisc_unmap_node, /* RCV_ADISC */
2431 lpfc_rcv_padisc_unmap_node, /* RCV_PDISC */
2432 lpfc_rcv_prlo_unmap_node, /* RCV_PRLO */
2433 lpfc_disc_illegal, /* CMPL_PLOGI */
2434 lpfc_disc_illegal, /* CMPL_PRLI */
2435 lpfc_disc_illegal, /* CMPL_LOGO */
2436 lpfc_disc_illegal, /* CMPL_ADISC */
2437 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2438 lpfc_disc_illegal, /* DEVICE_RM */
2439 lpfc_device_recov_unmap_node, /* DEVICE_RECOVERY */
2440
2441 lpfc_rcv_plogi_mapped_node, /* RCV_PLOGI MAPPED_NODE */
2442 lpfc_rcv_prli_mapped_node, /* RCV_PRLI */
2443 lpfc_rcv_logo_mapped_node, /* RCV_LOGO */
2444 lpfc_rcv_padisc_mapped_node, /* RCV_ADISC */
2445 lpfc_rcv_padisc_mapped_node, /* RCV_PDISC */
2446 lpfc_rcv_prlo_mapped_node, /* RCV_PRLO */
2447 lpfc_disc_illegal, /* CMPL_PLOGI */
2448 lpfc_disc_illegal, /* CMPL_PRLI */
2449 lpfc_disc_illegal, /* CMPL_LOGO */
2450 lpfc_disc_illegal, /* CMPL_ADISC */
2451 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2452 lpfc_disc_illegal, /* DEVICE_RM */
2453 lpfc_device_recov_mapped_node, /* DEVICE_RECOVERY */
2454
2455 lpfc_rcv_plogi_npr_node, /* RCV_PLOGI NPR_NODE */
2456 lpfc_rcv_prli_npr_node, /* RCV_PRLI */
2457 lpfc_rcv_logo_npr_node, /* RCV_LOGO */
2458 lpfc_rcv_padisc_npr_node, /* RCV_ADISC */
2459 lpfc_rcv_padisc_npr_node, /* RCV_PDISC */
2460 lpfc_rcv_prlo_npr_node, /* RCV_PRLO */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002461 lpfc_cmpl_plogi_npr_node, /* CMPL_PLOGI */
2462 lpfc_cmpl_prli_npr_node, /* CMPL_PRLI */
dea31012005-04-17 16:05:31 -05002463 lpfc_cmpl_logo_npr_node, /* CMPL_LOGO */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002464 lpfc_cmpl_adisc_npr_node, /* CMPL_ADISC */
dea31012005-04-17 16:05:31 -05002465 lpfc_cmpl_reglogin_npr_node, /* CMPL_REG_LOGIN */
2466 lpfc_device_rm_npr_node, /* DEVICE_RM */
2467 lpfc_device_recov_npr_node, /* DEVICE_RECOVERY */
2468};
2469
2470int
James Smart2e0fef82007-06-17 19:56:36 -05002471lpfc_disc_state_machine(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2472 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05002473{
2474 uint32_t cur_state, rc;
James Smart2e0fef82007-06-17 19:56:36 -05002475 uint32_t(*func) (struct lpfc_vport *, struct lpfc_nodelist *, void *,
dea31012005-04-17 16:05:31 -05002476 uint32_t);
James Smarte47c9092008-02-08 18:49:26 -05002477 uint32_t got_ndlp = 0;
dea31012005-04-17 16:05:31 -05002478
James Smarte47c9092008-02-08 18:49:26 -05002479 if (lpfc_nlp_get(ndlp))
2480 got_ndlp = 1;
2481
dea31012005-04-17 16:05:31 -05002482 cur_state = ndlp->nlp_state;
2483
2484 /* DSM in event <evt> on NPort <nlp_DID> in state <cur_state> */
James Smarte8b62012007-08-02 11:10:09 -04002485 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2486 "0211 DSM in event x%x on NPort x%x in "
2487 "state %d Data: x%x\n",
2488 evt, ndlp->nlp_DID, cur_state, ndlp->nlp_flag);
dea31012005-04-17 16:05:31 -05002489
James Smart858c9f62007-06-17 19:56:39 -05002490 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_DSM,
2491 "DSM in: evt:%d ste:%d did:x%x",
2492 evt, cur_state, ndlp->nlp_DID);
2493
dea31012005-04-17 16:05:31 -05002494 func = lpfc_disc_action[(cur_state * NLP_EVT_MAX_EVENT) + evt];
James Smart2e0fef82007-06-17 19:56:36 -05002495 rc = (func) (vport, ndlp, arg, evt);
dea31012005-04-17 16:05:31 -05002496
2497 /* DSM out state <rc> on NPort <nlp_DID> */
James Smarte47c9092008-02-08 18:49:26 -05002498 if (got_ndlp) {
2499 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
James Smarte8b62012007-08-02 11:10:09 -04002500 "0212 DSM out state %d on NPort x%x Data: x%x\n",
2501 rc, ndlp->nlp_DID, ndlp->nlp_flag);
dea31012005-04-17 16:05:31 -05002502
James Smarte47c9092008-02-08 18:49:26 -05002503 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_DSM,
2504 "DSM out: ste:%d did:x%x flg:x%x",
2505 rc, ndlp->nlp_DID, ndlp->nlp_flag);
2506 /* Decrement the ndlp reference count held for this function */
2507 lpfc_nlp_put(ndlp);
2508 } else {
2509 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
James Smartd7c255b2008-08-24 21:50:00 -04002510 "0213 DSM out state %d on NPort free\n", rc);
James Smart858c9f62007-06-17 19:56:39 -05002511
James Smarte47c9092008-02-08 18:49:26 -05002512 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_DSM,
2513 "DSM out: ste:%d did:x%x flg:x%x",
2514 rc, 0, 0);
2515 }
dea31012005-04-17 16:05:31 -05002516
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002517 return rc;
dea31012005-04-17 16:05:31 -05002518}