blob: bccc9c66fa37b3679e0348272c9511a961fc4436 [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 Smartd8e93df2009-05-22 14:53:05 -04004 * Copyright (C) 2004-2009 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{
51 /* Compare the ADISC rsp WWNN / WWPN matches our internal node
52 * table entry for that node.
53 */
James Smart2e0fef82007-06-17 19:56:36 -050054 if (memcmp(nn, &ndlp->nlp_nodename, sizeof (struct lpfc_name)))
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -050055 return 0;
dea31012005-04-17 16:05:31 -050056
James Smart2e0fef82007-06-17 19:56:36 -050057 if (memcmp(pn, &ndlp->nlp_portname, sizeof (struct lpfc_name)))
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -050058 return 0;
dea31012005-04-17 16:05:31 -050059
60 /* we match, return success */
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -050061 return 1;
dea31012005-04-17 16:05:31 -050062}
63
dea31012005-04-17 16:05:31 -050064int
James Smart2e0fef82007-06-17 19:56:36 -050065lpfc_check_sparm(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
James Smart341af102010-01-26 23:07:37 -050066 struct serv_parm *sp, uint32_t class, int flogi)
dea31012005-04-17 16:05:31 -050067{
James Smart2e0fef82007-06-17 19:56:36 -050068 volatile struct serv_parm *hsp = &vport->fc_sparam;
James.Smart@Emulex.Com2fb70f72005-11-28 11:41:24 -050069 uint16_t hsp_value, ssp_value = 0;
dea31012005-04-17 16:05:31 -050070
James.Smart@Emulex.Com2fb70f72005-11-28 11:41:24 -050071 /*
72 * The receive data field size and buffer-to-buffer receive data field
73 * size entries are 16 bits but are represented as two 8-bit fields in
74 * the driver data structure to account for rsvd bits and other control
75 * bits. Reconstruct and compare the fields as a 16-bit values before
76 * correcting the byte values.
77 */
dea31012005-04-17 16:05:31 -050078 if (sp->cls1.classValid) {
James Smart341af102010-01-26 23:07:37 -050079 if (!flogi) {
80 hsp_value = ((hsp->cls1.rcvDataSizeMsb << 8) |
81 hsp->cls1.rcvDataSizeLsb);
82 ssp_value = ((sp->cls1.rcvDataSizeMsb << 8) |
83 sp->cls1.rcvDataSizeLsb);
84 if (!ssp_value)
85 goto bad_service_param;
86 if (ssp_value > hsp_value) {
87 sp->cls1.rcvDataSizeLsb =
88 hsp->cls1.rcvDataSizeLsb;
89 sp->cls1.rcvDataSizeMsb =
90 hsp->cls1.rcvDataSizeMsb;
91 }
James.Smart@Emulex.Com2fb70f72005-11-28 11:41:24 -050092 }
James Smart341af102010-01-26 23:07:37 -050093 } else if (class == CLASS1)
James Smart92d7f7b2007-06-17 19:56:38 -050094 goto bad_service_param;
dea31012005-04-17 16:05:31 -050095 if (sp->cls2.classValid) {
James Smart341af102010-01-26 23:07:37 -050096 if (!flogi) {
97 hsp_value = ((hsp->cls2.rcvDataSizeMsb << 8) |
98 hsp->cls2.rcvDataSizeLsb);
99 ssp_value = ((sp->cls2.rcvDataSizeMsb << 8) |
100 sp->cls2.rcvDataSizeLsb);
101 if (!ssp_value)
102 goto bad_service_param;
103 if (ssp_value > hsp_value) {
104 sp->cls2.rcvDataSizeLsb =
105 hsp->cls2.rcvDataSizeLsb;
106 sp->cls2.rcvDataSizeMsb =
107 hsp->cls2.rcvDataSizeMsb;
108 }
James.Smart@Emulex.Com2fb70f72005-11-28 11:41:24 -0500109 }
James Smart341af102010-01-26 23:07:37 -0500110 } else if (class == CLASS2)
James Smart92d7f7b2007-06-17 19:56:38 -0500111 goto bad_service_param;
dea31012005-04-17 16:05:31 -0500112 if (sp->cls3.classValid) {
James Smart341af102010-01-26 23:07:37 -0500113 if (!flogi) {
114 hsp_value = ((hsp->cls3.rcvDataSizeMsb << 8) |
115 hsp->cls3.rcvDataSizeLsb);
116 ssp_value = ((sp->cls3.rcvDataSizeMsb << 8) |
117 sp->cls3.rcvDataSizeLsb);
118 if (!ssp_value)
119 goto bad_service_param;
120 if (ssp_value > hsp_value) {
121 sp->cls3.rcvDataSizeLsb =
122 hsp->cls3.rcvDataSizeLsb;
123 sp->cls3.rcvDataSizeMsb =
124 hsp->cls3.rcvDataSizeMsb;
125 }
James.Smart@Emulex.Com2fb70f72005-11-28 11:41:24 -0500126 }
James Smart341af102010-01-26 23:07:37 -0500127 } else if (class == CLASS3)
James Smart92d7f7b2007-06-17 19:56:38 -0500128 goto bad_service_param;
dea31012005-04-17 16:05:31 -0500129
James.Smart@Emulex.Com2fb70f72005-11-28 11:41:24 -0500130 /*
131 * Preserve the upper four bits of the MSB from the PLOGI response.
132 * These bits contain the Buffer-to-Buffer State Change Number
133 * from the target and need to be passed to the FW.
134 */
135 hsp_value = (hsp->cmn.bbRcvSizeMsb << 8) | hsp->cmn.bbRcvSizeLsb;
136 ssp_value = (sp->cmn.bbRcvSizeMsb << 8) | sp->cmn.bbRcvSizeLsb;
137 if (ssp_value > hsp_value) {
dea31012005-04-17 16:05:31 -0500138 sp->cmn.bbRcvSizeLsb = hsp->cmn.bbRcvSizeLsb;
James.Smart@Emulex.Com2fb70f72005-11-28 11:41:24 -0500139 sp->cmn.bbRcvSizeMsb = (sp->cmn.bbRcvSizeMsb & 0xF0) |
140 (hsp->cmn.bbRcvSizeMsb & 0x0F);
141 }
dea31012005-04-17 16:05:31 -0500142
dea31012005-04-17 16:05:31 -0500143 memcpy(&ndlp->nlp_nodename, &sp->nodeName, sizeof (struct lpfc_name));
144 memcpy(&ndlp->nlp_portname, &sp->portName, sizeof (struct lpfc_name));
James.Smart@Emulex.Com2fb70f72005-11-28 11:41:24 -0500145 return 1;
James Smart92d7f7b2007-06-17 19:56:38 -0500146bad_service_param:
James Smarte8b62012007-08-02 11:10:09 -0400147 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
148 "0207 Device %x "
149 "(%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x) sent "
150 "invalid service parameters. Ignoring device.\n",
151 ndlp->nlp_DID,
152 sp->nodeName.u.wwn[0], sp->nodeName.u.wwn[1],
153 sp->nodeName.u.wwn[2], sp->nodeName.u.wwn[3],
154 sp->nodeName.u.wwn[4], sp->nodeName.u.wwn[5],
155 sp->nodeName.u.wwn[6], sp->nodeName.u.wwn[7]);
James Smart92d7f7b2007-06-17 19:56:38 -0500156 return 0;
dea31012005-04-17 16:05:31 -0500157}
158
159static void *
James Smart2e0fef82007-06-17 19:56:36 -0500160lpfc_check_elscmpl_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -0500161 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -0500162{
163 struct lpfc_dmabuf *pcmd, *prsp;
164 uint32_t *lp;
165 void *ptr = NULL;
166 IOCB_t *irsp;
167
168 irsp = &rspiocb->iocb;
169 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
170
171 /* For lpfc_els_abort, context2 could be zero'ed to delay
172 * freeing associated memory till after ABTS completes.
173 */
174 if (pcmd) {
175 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf,
176 list);
177 if (prsp) {
178 lp = (uint32_t *) prsp->virt;
179 ptr = (void *)((uint8_t *)lp + sizeof(uint32_t));
180 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500181 } else {
dea31012005-04-17 16:05:31 -0500182 /* Force ulpStatus error since we are returning NULL ptr */
183 if (!(irsp->ulpStatus)) {
184 irsp->ulpStatus = IOSTAT_LOCAL_REJECT;
185 irsp->un.ulpWord[4] = IOERR_SLI_ABORTED;
186 }
187 ptr = NULL;
188 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -0500189 return ptr;
dea31012005-04-17 16:05:31 -0500190}
191
192
James Smart2a9bf3d2010-06-07 15:24:45 -0400193
dea31012005-04-17 16:05:31 -0500194/*
195 * Free resources / clean up outstanding I/Os
196 * associated with a LPFC_NODELIST entry. This
197 * routine effectively results in a "software abort".
198 */
199int
James Smart2e0fef82007-06-17 19:56:36 -0500200lpfc_els_abort(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -0500201{
James Smart2534ba72007-04-25 09:52:20 -0400202 LIST_HEAD(completions);
James Smart2a9bf3d2010-06-07 15:24:45 -0400203 LIST_HEAD(txcmplq_completions);
204 LIST_HEAD(abort_list);
James Smart2e0fef82007-06-17 19:56:36 -0500205 struct lpfc_sli *psli = &phba->sli;
206 struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING];
dea31012005-04-17 16:05:31 -0500207 struct lpfc_iocbq *iocb, *next_iocb;
dea31012005-04-17 16:05:31 -0500208
209 /* Abort outstanding I/O on NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -0400210 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_DISCOVERY,
James Smart2a9bf3d2010-06-07 15:24:45 -0400211 "2819 Abort outstanding I/O on NPort x%x "
James Smarte8b62012007-08-02 11:10:09 -0400212 "Data: x%x x%x x%x\n",
213 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
214 ndlp->nlp_rpi);
James Smart92d7f7b2007-06-17 19:56:38 -0500215
216 lpfc_fabric_abort_nport(ndlp);
dea31012005-04-17 16:05:31 -0500217
dea31012005-04-17 16:05:31 -0500218 /* First check the txq */
James Smart2e0fef82007-06-17 19:56:36 -0500219 spin_lock_irq(&phba->hbalock);
James Smart2534ba72007-04-25 09:52:20 -0400220 list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
James Smart858c9f62007-06-17 19:56:39 -0500221 /* Check to see if iocb matches the nport we are looking for */
James Smart2534ba72007-04-25 09:52:20 -0400222 if (lpfc_check_sli_ndlp(phba, pring, iocb, ndlp)) {
James Smart858c9f62007-06-17 19:56:39 -0500223 /* It matches, so deque and call compl with anp error */
James Smart2534ba72007-04-25 09:52:20 -0400224 list_move_tail(&iocb->list, &completions);
225 pring->txq_cnt--;
dea31012005-04-17 16:05:31 -0500226 }
James Smart2534ba72007-04-25 09:52:20 -0400227 }
dea31012005-04-17 16:05:31 -0500228
dea31012005-04-17 16:05:31 -0500229 /* Next check the txcmplq */
James Smart2a9bf3d2010-06-07 15:24:45 -0400230 list_splice_init(&pring->txcmplq, &txcmplq_completions);
James Smart2e0fef82007-06-17 19:56:36 -0500231 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500232
James Smart2a9bf3d2010-06-07 15:24:45 -0400233 list_for_each_entry_safe(iocb, next_iocb, &txcmplq_completions, list) {
234 /* Check to see if iocb matches the nport we are looking for */
235 if (lpfc_check_sli_ndlp(phba, pring, iocb, ndlp))
236 list_add_tail(&iocb->dlist, &abort_list);
237 }
238 spin_lock_irq(&phba->hbalock);
239 list_splice(&txcmplq_completions, &pring->txcmplq);
240 spin_unlock_irq(&phba->hbalock);
241
242 list_for_each_entry_safe(iocb, next_iocb, &abort_list, dlist) {
243 spin_lock_irq(&phba->hbalock);
244 list_del_init(&iocb->dlist);
245 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
246 spin_unlock_irq(&phba->hbalock);
247 }
248
James Smarta257bf92009-04-06 18:48:10 -0400249 /* Cancel all the IOCBs from the completions list */
250 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
251 IOERR_SLI_ABORTED);
James Smart2534ba72007-04-25 09:52:20 -0400252
James Smart0d2b6b82008-06-14 22:52:47 -0400253 lpfc_cancel_retry_delay_tmo(phba->pport, ndlp);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -0500254 return 0;
dea31012005-04-17 16:05:31 -0500255}
256
257static int
James Smart2e0fef82007-06-17 19:56:36 -0500258lpfc_rcv_plogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
James Smart92d7f7b2007-06-17 19:56:38 -0500259 struct lpfc_iocbq *cmdiocb)
dea31012005-04-17 16:05:31 -0500260{
James Smart2e0fef82007-06-17 19:56:36 -0500261 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
262 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500263 struct lpfc_dmabuf *pcmd;
264 uint32_t *lp;
265 IOCB_t *icmd;
266 struct serv_parm *sp;
267 LPFC_MBOXQ_t *mbox;
268 struct ls_rjt stat;
269 int rc;
270
271 memset(&stat, 0, sizeof (struct ls_rjt));
James Smart695a8142010-01-26 23:08:03 -0500272 if (vport->port_state <= LPFC_FDISC) {
dea31012005-04-17 16:05:31 -0500273 /* Before responding to PLOGI, check for pt2pt mode.
274 * If we are pt2pt, with an outstanding FLOGI, abort
275 * the FLOGI and resend it first.
276 */
James Smart2e0fef82007-06-17 19:56:36 -0500277 if (vport->fc_flag & FC_PT2PT) {
James Smart92d7f7b2007-06-17 19:56:38 -0500278 lpfc_els_abort_flogi(phba);
James Smart2e0fef82007-06-17 19:56:36 -0500279 if (!(vport->fc_flag & FC_PT2PT_PLOGI)) {
dea31012005-04-17 16:05:31 -0500280 /* If the other side is supposed to initiate
281 * the PLOGI anyway, just ACC it now and
282 * move on with discovery.
283 */
284 phba->fc_edtov = FF_DEF_EDTOV;
285 phba->fc_ratov = FF_DEF_RATOV;
286 /* Start discovery - this should just do
287 CLEAR_LA */
James Smart2e0fef82007-06-17 19:56:36 -0500288 lpfc_disc_start(vport);
James Smarted957682007-06-17 19:56:37 -0500289 } else
James Smart2e0fef82007-06-17 19:56:36 -0500290 lpfc_initial_flogi(vport);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500291 } else {
dea31012005-04-17 16:05:31 -0500292 stat.un.b.lsRjtRsnCode = LSRJT_LOGICAL_BSY;
293 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
James Smart2e0fef82007-06-17 19:56:36 -0500294 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb,
James Smart858c9f62007-06-17 19:56:39 -0500295 ndlp, NULL);
dea31012005-04-17 16:05:31 -0500296 return 0;
297 }
298 }
299 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
300 lp = (uint32_t *) pcmd->virt;
301 sp = (struct serv_parm *) ((uint8_t *) lp + sizeof (uint32_t));
James Smarta8adb832007-10-27 13:37:53 -0400302 if (wwn_to_u64(sp->portName.u.wwn) == 0) {
303 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
304 "0140 PLOGI Reject: invalid nname\n");
305 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
306 stat.un.b.lsRjtRsnCodeExp = LSEXP_INVALID_PNAME;
307 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
308 NULL);
309 return 0;
310 }
311 if (wwn_to_u64(sp->nodeName.u.wwn) == 0) {
312 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
313 "0141 PLOGI Reject: invalid pname\n");
314 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
315 stat.un.b.lsRjtRsnCodeExp = LSEXP_INVALID_NNAME;
316 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
317 NULL);
318 return 0;
319 }
James Smart341af102010-01-26 23:07:37 -0500320 if ((lpfc_check_sparm(vport, ndlp, sp, CLASS3, 0) == 0)) {
dea31012005-04-17 16:05:31 -0500321 /* Reject this request because invalid parameters */
322 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
323 stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
James Smart858c9f62007-06-17 19:56:39 -0500324 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
325 NULL);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -0500326 return 0;
dea31012005-04-17 16:05:31 -0500327 }
328 icmd = &cmdiocb->iocb;
329
330 /* PLOGI chkparm OK */
James Smarte8b62012007-08-02 11:10:09 -0400331 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
332 "0114 PLOGI chkparm OK Data: x%x x%x x%x x%x\n",
333 ndlp->nlp_DID, ndlp->nlp_state, ndlp->nlp_flag,
334 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -0500335
James Smart3de2a652007-08-02 11:09:59 -0400336 if (vport->cfg_fcp_class == 2 && sp->cls2.classValid)
dea31012005-04-17 16:05:31 -0500337 ndlp->nlp_fcp_info |= CLASS2;
James Smarted957682007-06-17 19:56:37 -0500338 else
dea31012005-04-17 16:05:31 -0500339 ndlp->nlp_fcp_info |= CLASS3;
James Smart2e0fef82007-06-17 19:56:36 -0500340
dea31012005-04-17 16:05:31 -0500341 ndlp->nlp_class_sup = 0;
342 if (sp->cls1.classValid)
343 ndlp->nlp_class_sup |= FC_COS_CLASS1;
344 if (sp->cls2.classValid)
345 ndlp->nlp_class_sup |= FC_COS_CLASS2;
346 if (sp->cls3.classValid)
347 ndlp->nlp_class_sup |= FC_COS_CLASS3;
348 if (sp->cls4.classValid)
349 ndlp->nlp_class_sup |= FC_COS_CLASS4;
350 ndlp->nlp_maxframe =
351 ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) | sp->cmn.bbRcvSizeLsb;
352
353 /* no need to reg_login if we are already in one of these states */
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500354 switch (ndlp->nlp_state) {
dea31012005-04-17 16:05:31 -0500355 case NLP_STE_NPR_NODE:
356 if (!(ndlp->nlp_flag & NLP_NPR_ADISC))
357 break;
358 case NLP_STE_REG_LOGIN_ISSUE:
359 case NLP_STE_PRLI_ISSUE:
360 case NLP_STE_UNMAPPED_NODE:
361 case NLP_STE_MAPPED_NODE:
James Smart51ef4c22007-08-02 11:10:31 -0400362 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp, NULL);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -0500363 return 1;
dea31012005-04-17 16:05:31 -0500364 }
365
James Smart92d7f7b2007-06-17 19:56:38 -0500366 if ((vport->fc_flag & FC_PT2PT) &&
367 !(vport->fc_flag & FC_PT2PT_PLOGI)) {
dea31012005-04-17 16:05:31 -0500368 /* rcv'ed PLOGI decides what our NPortId will be */
James Smart2e0fef82007-06-17 19:56:36 -0500369 vport->fc_myDID = icmd->un.rcvels.parmRo;
dea31012005-04-17 16:05:31 -0500370 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
371 if (mbox == NULL)
372 goto out;
373 lpfc_config_link(phba, mbox);
374 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smarted957682007-06-17 19:56:37 -0500375 mbox->vport = vport;
James Smart0b727fe2007-10-27 13:37:25 -0400376 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
dea31012005-04-17 16:05:31 -0500377 if (rc == MBX_NOT_FINISHED) {
James Smart92d7f7b2007-06-17 19:56:38 -0500378 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -0500379 goto out;
380 }
381
James Smart2e0fef82007-06-17 19:56:36 -0500382 lpfc_can_disctmo(vport);
dea31012005-04-17 16:05:31 -0500383 }
384 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
James Smart2e0fef82007-06-17 19:56:36 -0500385 if (!mbox)
dea31012005-04-17 16:05:31 -0500386 goto out;
387
James Smart6fb120a2009-05-22 14:52:59 -0400388 rc = lpfc_reg_rpi(phba, vport->vpi, icmd->un.rcvels.remoteID,
James Smart92d7f7b2007-06-17 19:56:38 -0500389 (uint8_t *) sp, mbox, 0);
James Smart2e0fef82007-06-17 19:56:36 -0500390 if (rc) {
391 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -0500392 goto out;
393 }
394
395 /* ACC PLOGI rsp command needs to execute first,
396 * queue this mbox command to be processed later.
397 */
398 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
James Smart329f9bc2007-04-25 09:53:01 -0400399 /*
400 * mbox->context2 = lpfc_nlp_get(ndlp) deferred until mailbox
401 * command issued in lpfc_cmpl_els_acc().
402 */
James Smart2e0fef82007-06-17 19:56:36 -0500403 mbox->vport = vport;
404 spin_lock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -0500405 ndlp->nlp_flag |= (NLP_ACC_REGLOGIN | NLP_RCV_PLOGI);
James Smart2e0fef82007-06-17 19:56:36 -0500406 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500407
James Smart33ccf8d2006-08-17 11:57:58 -0400408 /*
409 * If there is an outstanding PLOGI issued, abort it before
410 * sending ACC rsp for received PLOGI. If pending plogi
411 * is not canceled here, the plogi will be rejected by
412 * remote port and will be retried. On a configuration with
413 * single discovery thread, this will cause a huge delay in
414 * discovery. Also this will cause multiple state machines
415 * running in parallel for this node.
416 */
417 if (ndlp->nlp_state == NLP_STE_PLOGI_ISSUE) {
418 /* software abort outstanding PLOGI */
James Smart07951072007-04-25 09:51:38 -0400419 lpfc_els_abort(phba, ndlp);
James Smart33ccf8d2006-08-17 11:57:58 -0400420 }
421
James Smart858c9f62007-06-17 19:56:39 -0500422 if ((vport->port_type == LPFC_NPIV_PORT &&
James Smart3de2a652007-08-02 11:09:59 -0400423 vport->cfg_restrict_login)) {
James Smart858c9f62007-06-17 19:56:39 -0500424
425 /* In order to preserve RPIs, we want to cleanup
426 * the default RPI the firmware created to rcv
427 * this ELS request. The only way to do this is
428 * to register, then unregister the RPI.
429 */
430 spin_lock_irq(shost->host_lock);
431 ndlp->nlp_flag |= NLP_RM_DFLT_RPI;
432 spin_unlock_irq(shost->host_lock);
433 stat.un.b.lsRjtRsnCode = LSRJT_INVALID_CMD;
434 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
435 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb,
436 ndlp, mbox);
437 return 1;
438 }
James Smart51ef4c22007-08-02 11:10:31 -0400439 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp, mbox);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -0500440 return 1;
dea31012005-04-17 16:05:31 -0500441out:
442 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
443 stat.un.b.lsRjtRsnCodeExp = LSEXP_OUT_OF_RESOURCE;
James Smart858c9f62007-06-17 19:56:39 -0500444 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -0500445 return 0;
dea31012005-04-17 16:05:31 -0500446}
447
448static int
James Smart2e0fef82007-06-17 19:56:36 -0500449lpfc_rcv_padisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -0500450 struct lpfc_iocbq *cmdiocb)
451{
James Smart2e0fef82007-06-17 19:56:36 -0500452 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -0500453 struct lpfc_dmabuf *pcmd;
James Smart2e0fef82007-06-17 19:56:36 -0500454 struct serv_parm *sp;
455 struct lpfc_name *pnn, *ppn;
dea31012005-04-17 16:05:31 -0500456 struct ls_rjt stat;
457 ADISC *ap;
458 IOCB_t *icmd;
459 uint32_t *lp;
460 uint32_t cmd;
461
462 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
463 lp = (uint32_t *) pcmd->virt;
464
465 cmd = *lp++;
466 if (cmd == ELS_CMD_ADISC) {
467 ap = (ADISC *) lp;
468 pnn = (struct lpfc_name *) & ap->nodeName;
469 ppn = (struct lpfc_name *) & ap->portName;
470 } else {
471 sp = (struct serv_parm *) lp;
472 pnn = (struct lpfc_name *) & sp->nodeName;
473 ppn = (struct lpfc_name *) & sp->portName;
474 }
475
476 icmd = &cmdiocb->iocb;
James Smart2e0fef82007-06-17 19:56:36 -0500477 if (icmd->ulpStatus == 0 && lpfc_check_adisc(vport, ndlp, pnn, ppn)) {
dea31012005-04-17 16:05:31 -0500478 if (cmd == ELS_CMD_ADISC) {
James Smart2e0fef82007-06-17 19:56:36 -0500479 lpfc_els_rsp_adisc_acc(vport, cmdiocb, ndlp);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500480 } else {
James Smart2e0fef82007-06-17 19:56:36 -0500481 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp,
James Smart51ef4c22007-08-02 11:10:31 -0400482 NULL);
dea31012005-04-17 16:05:31 -0500483 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -0500484 return 1;
dea31012005-04-17 16:05:31 -0500485 }
486 /* Reject this request because invalid parameters */
487 stat.un.b.lsRjtRsvd0 = 0;
488 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
489 stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
490 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -0500491 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -0500492
dea31012005-04-17 16:05:31 -0500493 /* 1 sec timeout */
494 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ);
495
James Smart2e0fef82007-06-17 19:56:36 -0500496 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500497 ndlp->nlp_flag |= NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -0500498 spin_unlock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -0500499 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
500 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -0500501 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -0500502 return 0;
dea31012005-04-17 16:05:31 -0500503}
504
505static int
James Smart2e0fef82007-06-17 19:56:36 -0500506lpfc_rcv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
507 struct lpfc_iocbq *cmdiocb, uint32_t els_cmd)
dea31012005-04-17 16:05:31 -0500508{
James Smart2e0fef82007-06-17 19:56:36 -0500509 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart4b40c592010-03-15 11:25:44 -0400510 struct lpfc_hba *phba = vport->phba;
511 struct lpfc_vport **vports;
512 int i, active_vlink_present = 0 ;
James Smart2e0fef82007-06-17 19:56:36 -0500513
514 /* Put ndlp in NPR state with 1 sec timeout for plogi, ACC logo */
dea31012005-04-17 16:05:31 -0500515 /* Only call LOGO ACC for first LOGO, this avoids sending unnecessary
516 * PLOGIs during LOGO storms from a device.
517 */
James Smart2e0fef82007-06-17 19:56:36 -0500518 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500519 ndlp->nlp_flag |= NLP_LOGO_ACC;
James Smart2e0fef82007-06-17 19:56:36 -0500520 spin_unlock_irq(shost->host_lock);
James Smart82d9a2a2006-04-15 11:53:05 -0400521 if (els_cmd == ELS_CMD_PRLO)
James Smart51ef4c22007-08-02 11:10:31 -0400522 lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL);
James Smart82d9a2a2006-04-15 11:53:05 -0400523 else
James Smart51ef4c22007-08-02 11:10:31 -0400524 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
James Smart4b40c592010-03-15 11:25:44 -0400525 if (ndlp->nlp_DID == Fabric_DID) {
526 if (vport->port_state <= LPFC_FDISC)
527 goto out;
James Smart6fb120a2009-05-22 14:52:59 -0400528 lpfc_linkdown_port(vport);
James Smart6fb120a2009-05-22 14:52:59 -0400529 spin_lock_irq(shost->host_lock);
James Smart4b40c592010-03-15 11:25:44 -0400530 vport->fc_flag |= FC_VPORT_LOGO_RCVD;
James Smart6fb120a2009-05-22 14:52:59 -0400531 spin_unlock_irq(shost->host_lock);
James Smart4b40c592010-03-15 11:25:44 -0400532 vports = lpfc_create_vport_work_array(phba);
533 if (vports) {
534 for (i = 0; i <= phba->max_vports && vports[i] != NULL;
535 i++) {
536 if ((!(vports[i]->fc_flag &
537 FC_VPORT_LOGO_RCVD)) &&
538 (vports[i]->port_state > LPFC_FDISC)) {
539 active_vlink_present = 1;
540 break;
541 }
542 }
543 lpfc_destroy_vport_work_array(phba, vports);
544 }
dea31012005-04-17 16:05:31 -0500545
James Smart4b40c592010-03-15 11:25:44 -0400546 if (active_vlink_present) {
547 /*
548 * If there are other active VLinks present,
549 * re-instantiate the Vlink using FDISC.
550 */
551 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ);
552 spin_lock_irq(shost->host_lock);
553 ndlp->nlp_flag |= NLP_DELAY_TMO;
554 spin_unlock_irq(shost->host_lock);
555 ndlp->nlp_last_elscmd = ELS_CMD_FDISC;
556 vport->port_state = LPFC_FDISC;
557 } else {
558 spin_lock_irq(shost->host_lock);
559 phba->pport->fc_flag &= ~FC_LOGO_RCVD_DID_CHNG;
560 spin_unlock_irq(shost->host_lock);
561 lpfc_retry_pport_discovery(phba);
562 }
James Smart6fb120a2009-05-22 14:52:59 -0400563 } else if ((!(ndlp->nlp_type & NLP_FABRIC) &&
564 ((ndlp->nlp_type & NLP_FCP_TARGET) ||
565 !(ndlp->nlp_type & NLP_FCP_INITIATOR))) ||
566 (ndlp->nlp_state == NLP_STE_ADISC_ISSUE)) {
dea31012005-04-17 16:05:31 -0500567 /* Only try to re-login if this is NOT a Fabric Node */
dea31012005-04-17 16:05:31 -0500568 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ * 1);
James Smart2e0fef82007-06-17 19:56:36 -0500569 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500570 ndlp->nlp_flag |= NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -0500571 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -0500572
Jamie Wellnitz5024ab12006-02-28 19:25:28 -0500573 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
dea31012005-04-17 16:05:31 -0500574 }
James Smart4b40c592010-03-15 11:25:44 -0400575out:
James Smart87af33f2007-10-27 13:37:43 -0400576 ndlp->nlp_prev_state = ndlp->nlp_state;
577 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
dea31012005-04-17 16:05:31 -0500578
James Smart2e0fef82007-06-17 19:56:36 -0500579 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500580 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
James Smart2e0fef82007-06-17 19:56:36 -0500581 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500582 /* The driver has to wait until the ACC completes before it continues
583 * processing the LOGO. The action will resume in
584 * lpfc_cmpl_els_logo_acc routine. Since part of processing includes an
585 * unreg_login, the driver waits so the ACC does not get aborted.
586 */
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -0500587 return 0;
dea31012005-04-17 16:05:31 -0500588}
589
590static void
James Smart2e0fef82007-06-17 19:56:36 -0500591lpfc_rcv_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
592 struct lpfc_iocbq *cmdiocb)
dea31012005-04-17 16:05:31 -0500593{
594 struct lpfc_dmabuf *pcmd;
595 uint32_t *lp;
596 PRLI *npr;
597 struct fc_rport *rport = ndlp->rport;
598 u32 roles;
599
600 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
601 lp = (uint32_t *) pcmd->virt;
602 npr = (PRLI *) ((uint8_t *) lp + sizeof (uint32_t));
603
604 ndlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR);
605 ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
James Smart92d7f7b2007-06-17 19:56:38 -0500606 if (npr->prliType == PRLI_FCP_TYPE) {
dea31012005-04-17 16:05:31 -0500607 if (npr->initiatorFunc)
608 ndlp->nlp_type |= NLP_FCP_INITIATOR;
609 if (npr->targetFunc)
610 ndlp->nlp_type |= NLP_FCP_TARGET;
611 if (npr->Retry)
612 ndlp->nlp_fcp_info |= NLP_FCP_2_DEVICE;
613 }
614 if (rport) {
615 /* We need to update the rport role values */
616 roles = FC_RPORT_ROLE_UNKNOWN;
617 if (ndlp->nlp_type & NLP_FCP_INITIATOR)
618 roles |= FC_RPORT_ROLE_FCP_INITIATOR;
619 if (ndlp->nlp_type & NLP_FCP_TARGET)
620 roles |= FC_RPORT_ROLE_FCP_TARGET;
James Smart858c9f62007-06-17 19:56:39 -0500621
622 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
623 "rport rolechg: role:x%x did:x%x flg:x%x",
624 roles, ndlp->nlp_DID, ndlp->nlp_flag);
625
dea31012005-04-17 16:05:31 -0500626 fc_remote_port_rolechg(rport, roles);
627 }
628}
629
630static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -0500631lpfc_disc_set_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -0500632{
James Smart2e0fef82007-06-17 19:56:36 -0500633 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart2e0fef82007-06-17 19:56:36 -0500634
James Smart6fb120a2009-05-22 14:52:59 -0400635 if (!(ndlp->nlp_flag & NLP_RPI_VALID)) {
James Smart51ef4c22007-08-02 11:10:31 -0400636 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
637 return 0;
638 }
639
James Smart1b32f6a2008-02-08 18:49:39 -0500640 if (!(vport->fc_flag & FC_PT2PT)) {
641 /* Check config parameter use-adisc or FCP-2 */
642 if ((vport->cfg_use_adisc && (vport->fc_flag & FC_RSCN_MODE)) ||
James Smartffc95492010-06-07 15:23:17 -0400643 ((ndlp->nlp_fcp_info & NLP_FCP_2_DEVICE) &&
644 (ndlp->nlp_type & NLP_FCP_TARGET))) {
James Smart1b32f6a2008-02-08 18:49:39 -0500645 spin_lock_irq(shost->host_lock);
646 ndlp->nlp_flag |= NLP_NPR_ADISC;
647 spin_unlock_irq(shost->host_lock);
648 return 1;
649 }
James Smart92d7f7b2007-06-17 19:56:38 -0500650 }
651 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
652 lpfc_unreg_rpi(vport, ndlp);
653 return 0;
dea31012005-04-17 16:05:31 -0500654}
James Smart78730cf2010-04-06 15:06:30 -0400655/**
656 * lpfc_release_rpi - Release a RPI by issueing unreg_login mailbox cmd.
657 * @phba : Pointer to lpfc_hba structure.
658 * @vport: Pointer to lpfc_vport structure.
659 * @rpi : rpi to be release.
660 *
661 * This function will send a unreg_login mailbox command to the firmware
662 * to release a rpi.
663 **/
664void
665lpfc_release_rpi(struct lpfc_hba *phba,
666 struct lpfc_vport *vport,
667 uint16_t rpi)
668{
669 LPFC_MBOXQ_t *pmb;
670 int rc;
671
672 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
673 GFP_KERNEL);
674 if (!pmb)
675 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
676 "2796 mailbox memory allocation failed \n");
677 else {
678 lpfc_unreg_login(phba, vport->vpi, rpi, pmb);
679 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
680 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
681 if (rc == MBX_NOT_FINISHED)
682 mempool_free(pmb, phba->mbox_mem_pool);
683 }
684}
dea31012005-04-17 16:05:31 -0500685
686static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -0500687lpfc_disc_illegal(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
688 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -0500689{
James Smart78730cf2010-04-06 15:06:30 -0400690 struct lpfc_hba *phba;
691 LPFC_MBOXQ_t *pmb = (LPFC_MBOXQ_t *) arg;
692 MAILBOX_t *mb;
693 uint16_t rpi;
694
695 phba = vport->phba;
696 /* Release the RPI if reglogin completing */
697 if (!(phba->pport->load_flag & FC_UNLOADING) &&
698 (evt == NLP_EVT_CMPL_REG_LOGIN) &&
699 (!pmb->u.mb.mbxStatus)) {
700 mb = &pmb->u.mb;
701 rpi = pmb->u.mb.un.varWords[0];
702 lpfc_release_rpi(phba, vport, rpi);
703 }
James Smarte8b62012007-08-02 11:10:09 -0400704 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
James Smarte47c9092008-02-08 18:49:26 -0500705 "0271 Illegal State Transition: node x%x "
James Smarte8b62012007-08-02 11:10:09 -0400706 "event x%x, state x%x Data: x%x x%x\n",
707 ndlp->nlp_DID, evt, ndlp->nlp_state, ndlp->nlp_rpi,
708 ndlp->nlp_flag);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -0500709 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -0500710}
711
James Smart87af33f2007-10-27 13:37:43 -0400712static uint32_t
713lpfc_cmpl_plogi_illegal(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
714 void *arg, uint32_t evt)
715{
716 /* This transition is only legal if we previously
717 * rcv'ed a PLOGI. Since we don't want 2 discovery threads
718 * working on the same NPortID, do nothing for this thread
719 * to stop it.
720 */
721 if (!(ndlp->nlp_flag & NLP_RCV_PLOGI)) {
722 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
James Smarte47c9092008-02-08 18:49:26 -0500723 "0272 Illegal State Transition: node x%x "
James Smart87af33f2007-10-27 13:37:43 -0400724 "event x%x, state x%x Data: x%x x%x\n",
725 ndlp->nlp_DID, evt, ndlp->nlp_state, ndlp->nlp_rpi,
726 ndlp->nlp_flag);
727 }
728 return ndlp->nlp_state;
729}
730
dea31012005-04-17 16:05:31 -0500731/* Start of Discovery State Machine routines */
732
733static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -0500734lpfc_rcv_plogi_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
735 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -0500736{
737 struct lpfc_iocbq *cmdiocb;
738
739 cmdiocb = (struct lpfc_iocbq *) arg;
740
James Smart2e0fef82007-06-17 19:56:36 -0500741 if (lpfc_rcv_plogi(vport, ndlp, cmdiocb)) {
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -0500742 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -0500743 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -0500744 return NLP_STE_FREED_NODE;
dea31012005-04-17 16:05:31 -0500745}
746
747static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -0500748lpfc_rcv_els_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
749 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -0500750{
James Smart2e0fef82007-06-17 19:56:36 -0500751 lpfc_issue_els_logo(vport, ndlp, 0);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -0500752 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -0500753}
754
755static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -0500756lpfc_rcv_logo_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
757 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -0500758{
James Smart2e0fef82007-06-17 19:56:36 -0500759 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
760 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -0500761
James Smart2e0fef82007-06-17 19:56:36 -0500762 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500763 ndlp->nlp_flag |= NLP_LOGO_ACC;
James Smart2e0fef82007-06-17 19:56:36 -0500764 spin_unlock_irq(shost->host_lock);
James Smart51ef4c22007-08-02 11:10:31 -0400765 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -0500766
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -0500767 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -0500768}
769
770static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -0500771lpfc_cmpl_logo_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -0500772 void *arg, uint32_t evt)
773{
James Smart2e0fef82007-06-17 19:56:36 -0500774 return NLP_STE_FREED_NODE;
775}
776
777static uint32_t
778lpfc_device_rm_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
779 void *arg, uint32_t evt)
780{
James Smart2e0fef82007-06-17 19:56:36 -0500781 return NLP_STE_FREED_NODE;
782}
783
784static uint32_t
785lpfc_rcv_plogi_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
786 void *arg, uint32_t evt)
787{
James Smart0d2b6b82008-06-14 22:52:47 -0400788 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart2e0fef82007-06-17 19:56:36 -0500789 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500790 struct lpfc_iocbq *cmdiocb = arg;
James Smart2e0fef82007-06-17 19:56:36 -0500791 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
792 uint32_t *lp = (uint32_t *) pcmd->virt;
793 struct serv_parm *sp = (struct serv_parm *) (lp + 1);
dea31012005-04-17 16:05:31 -0500794 struct ls_rjt stat;
795 int port_cmp;
796
dea31012005-04-17 16:05:31 -0500797 memset(&stat, 0, sizeof (struct ls_rjt));
798
799 /* For a PLOGI, we only accept if our portname is less
800 * than the remote portname.
801 */
802 phba->fc_stat.elsLogiCol++;
James Smart2e0fef82007-06-17 19:56:36 -0500803 port_cmp = memcmp(&vport->fc_portname, &sp->portName,
James Smart92d7f7b2007-06-17 19:56:38 -0500804 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -0500805
806 if (port_cmp >= 0) {
807 /* Reject this request because the remote node will accept
808 ours */
809 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
810 stat.un.b.lsRjtRsnCodeExp = LSEXP_CMD_IN_PROGRESS;
James Smart858c9f62007-06-17 19:56:39 -0500811 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
812 NULL);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500813 } else {
James Smart0d2b6b82008-06-14 22:52:47 -0400814 if (lpfc_rcv_plogi(vport, ndlp, cmdiocb) &&
815 (ndlp->nlp_flag & NLP_NPR_2B_DISC) &&
816 (vport->num_disc_nodes)) {
817 spin_lock_irq(shost->host_lock);
818 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
819 spin_unlock_irq(shost->host_lock);
820 /* Check if there are more PLOGIs to be sent */
821 lpfc_more_plogi(vport);
822 if (vport->num_disc_nodes == 0) {
823 spin_lock_irq(shost->host_lock);
824 vport->fc_flag &= ~FC_NDISC_ACTIVE;
825 spin_unlock_irq(shost->host_lock);
826 lpfc_can_disctmo(vport);
827 lpfc_end_rscn(vport);
828 }
829 }
James Smart2e0fef82007-06-17 19:56:36 -0500830 } /* If our portname was less */
dea31012005-04-17 16:05:31 -0500831
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -0500832 return ndlp->nlp_state;
833}
834
835static uint32_t
James Smart92d7f7b2007-06-17 19:56:38 -0500836lpfc_rcv_prli_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
837 void *arg, uint32_t evt)
838{
839 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
840 struct ls_rjt stat;
841
842 memset(&stat, 0, sizeof (struct ls_rjt));
843 stat.un.b.lsRjtRsnCode = LSRJT_LOGICAL_BSY;
844 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
James Smart858c9f62007-06-17 19:56:39 -0500845 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
James Smart92d7f7b2007-06-17 19:56:38 -0500846 return ndlp->nlp_state;
847}
848
849static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -0500850lpfc_rcv_logo_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
851 void *arg, uint32_t evt)
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -0500852{
James Smart2e0fef82007-06-17 19:56:36 -0500853 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -0500854
James Smart92d7f7b2007-06-17 19:56:38 -0500855 /* software abort outstanding PLOGI */
James Smart2e0fef82007-06-17 19:56:36 -0500856 lpfc_els_abort(vport->phba, ndlp);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -0500857
James Smart2e0fef82007-06-17 19:56:36 -0500858 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -0500859 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -0500860}
861
862static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -0500863lpfc_rcv_els_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
864 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -0500865{
James Smart2e0fef82007-06-17 19:56:36 -0500866 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
867 struct lpfc_hba *phba = vport->phba;
868 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -0500869
870 /* software abort outstanding PLOGI */
James Smart07951072007-04-25 09:51:38 -0400871 lpfc_els_abort(phba, ndlp);
dea31012005-04-17 16:05:31 -0500872
873 if (evt == NLP_EVT_RCV_LOGO) {
James Smart51ef4c22007-08-02 11:10:31 -0400874 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500875 } else {
James Smart2e0fef82007-06-17 19:56:36 -0500876 lpfc_issue_els_logo(vport, ndlp, 0);
dea31012005-04-17 16:05:31 -0500877 }
878
James Smart2e0fef82007-06-17 19:56:36 -0500879 /* Put ndlp in npr state set plogi timer for 1 sec */
Jamie Wellnitz5024ab12006-02-28 19:25:28 -0500880 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ * 1);
James Smart2e0fef82007-06-17 19:56:36 -0500881 spin_lock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -0500882 ndlp->nlp_flag |= NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -0500883 spin_unlock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -0500884 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
885 ndlp->nlp_prev_state = NLP_STE_PLOGI_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -0500886 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
dea31012005-04-17 16:05:31 -0500887
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -0500888 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -0500889}
890
891static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -0500892lpfc_cmpl_plogi_plogi_issue(struct lpfc_vport *vport,
893 struct lpfc_nodelist *ndlp,
894 void *arg,
dea31012005-04-17 16:05:31 -0500895 uint32_t evt)
896{
James Smart2e0fef82007-06-17 19:56:36 -0500897 struct lpfc_hba *phba = vport->phba;
James Smart0ff10d42008-01-11 01:52:36 -0500898 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart2e0fef82007-06-17 19:56:36 -0500899 struct lpfc_iocbq *cmdiocb, *rspiocb;
James Smart14691152006-12-02 13:34:28 -0500900 struct lpfc_dmabuf *pcmd, *prsp, *mp;
dea31012005-04-17 16:05:31 -0500901 uint32_t *lp;
902 IOCB_t *irsp;
903 struct serv_parm *sp;
904 LPFC_MBOXQ_t *mbox;
905
906 cmdiocb = (struct lpfc_iocbq *) arg;
907 rspiocb = cmdiocb->context_un.rsp_iocb;
908
909 if (ndlp->nlp_flag & NLP_ACC_REGLOGIN) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -0500910 /* Recovery from PLOGI collision logic */
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -0500911 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -0500912 }
913
914 irsp = &rspiocb->iocb;
915
916 if (irsp->ulpStatus)
917 goto out;
918
919 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
920
James Smart2e0fef82007-06-17 19:56:36 -0500921 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
dea31012005-04-17 16:05:31 -0500922
James Smart2e0fef82007-06-17 19:56:36 -0500923 lp = (uint32_t *) prsp->virt;
dea31012005-04-17 16:05:31 -0500924 sp = (struct serv_parm *) ((uint8_t *) lp + sizeof (uint32_t));
James Smart58da1ff2008-04-07 10:15:56 -0400925
926 /* Some switches have FDMI servers returning 0 for WWN */
927 if ((ndlp->nlp_DID != FDMI_DID) &&
928 (wwn_to_u64(sp->portName.u.wwn) == 0 ||
929 wwn_to_u64(sp->nodeName.u.wwn) == 0)) {
James Smarta8adb832007-10-27 13:37:53 -0400930 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
931 "0142 PLOGI RSP: Invalid WWN.\n");
932 goto out;
933 }
James Smart341af102010-01-26 23:07:37 -0500934 if (!lpfc_check_sparm(vport, ndlp, sp, CLASS3, 0))
dea31012005-04-17 16:05:31 -0500935 goto out;
dea31012005-04-17 16:05:31 -0500936 /* PLOGI chkparm OK */
James Smarte8b62012007-08-02 11:10:09 -0400937 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
938 "0121 PLOGI chkparm OK Data: x%x x%x x%x x%x\n",
939 ndlp->nlp_DID, ndlp->nlp_state,
940 ndlp->nlp_flag, ndlp->nlp_rpi);
James Smart3de2a652007-08-02 11:09:59 -0400941 if (vport->cfg_fcp_class == 2 && (sp->cls2.classValid))
dea31012005-04-17 16:05:31 -0500942 ndlp->nlp_fcp_info |= CLASS2;
James Smart2e0fef82007-06-17 19:56:36 -0500943 else
dea31012005-04-17 16:05:31 -0500944 ndlp->nlp_fcp_info |= CLASS3;
James Smart2e0fef82007-06-17 19:56:36 -0500945
dea31012005-04-17 16:05:31 -0500946 ndlp->nlp_class_sup = 0;
947 if (sp->cls1.classValid)
948 ndlp->nlp_class_sup |= FC_COS_CLASS1;
949 if (sp->cls2.classValid)
950 ndlp->nlp_class_sup |= FC_COS_CLASS2;
951 if (sp->cls3.classValid)
952 ndlp->nlp_class_sup |= FC_COS_CLASS3;
953 if (sp->cls4.classValid)
954 ndlp->nlp_class_sup |= FC_COS_CLASS4;
955 ndlp->nlp_maxframe =
James Smart2e0fef82007-06-17 19:56:36 -0500956 ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) | sp->cmn.bbRcvSizeLsb;
dea31012005-04-17 16:05:31 -0500957
James Smart2e0fef82007-06-17 19:56:36 -0500958 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
James Smart92d7f7b2007-06-17 19:56:38 -0500959 if (!mbox) {
James Smarte8b62012007-08-02 11:10:09 -0400960 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
961 "0133 PLOGI: no memory for reg_login "
James Smart92d7f7b2007-06-17 19:56:38 -0500962 "Data: x%x x%x x%x x%x\n",
James Smart92d7f7b2007-06-17 19:56:38 -0500963 ndlp->nlp_DID, ndlp->nlp_state,
964 ndlp->nlp_flag, ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -0500965 goto out;
James Smart92d7f7b2007-06-17 19:56:38 -0500966 }
dea31012005-04-17 16:05:31 -0500967
James Smart2e0fef82007-06-17 19:56:36 -0500968 lpfc_unreg_rpi(vport, ndlp);
969
James Smart6fb120a2009-05-22 14:52:59 -0400970 if (lpfc_reg_rpi(phba, vport->vpi, irsp->un.elsreq64.remoteID,
James Smart92d7f7b2007-06-17 19:56:38 -0500971 (uint8_t *) sp, mbox, 0) == 0) {
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500972 switch (ndlp->nlp_DID) {
dea31012005-04-17 16:05:31 -0500973 case NameServer_DID:
James Smartde0c5b32007-04-25 09:52:27 -0400974 mbox->mbox_cmpl = lpfc_mbx_cmpl_ns_reg_login;
dea31012005-04-17 16:05:31 -0500975 break;
976 case FDMI_DID:
James Smartde0c5b32007-04-25 09:52:27 -0400977 mbox->mbox_cmpl = lpfc_mbx_cmpl_fdmi_reg_login;
dea31012005-04-17 16:05:31 -0500978 break;
979 default:
James Smartffc95492010-06-07 15:23:17 -0400980 ndlp->nlp_flag |= NLP_REG_LOGIN_SEND;
James Smartde0c5b32007-04-25 09:52:27 -0400981 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
dea31012005-04-17 16:05:31 -0500982 }
James Smart329f9bc2007-04-25 09:53:01 -0400983 mbox->context2 = lpfc_nlp_get(ndlp);
James Smart2e0fef82007-06-17 19:56:36 -0500984 mbox->vport = vport;
James Smart0b727fe2007-10-27 13:37:25 -0400985 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
dea31012005-04-17 16:05:31 -0500986 != MBX_NOT_FINISHED) {
James Smart2e0fef82007-06-17 19:56:36 -0500987 lpfc_nlp_set_state(vport, ndlp,
988 NLP_STE_REG_LOGIN_ISSUE);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -0500989 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -0500990 }
James Smartffc95492010-06-07 15:23:17 -0400991 if (ndlp->nlp_flag & NLP_REG_LOGIN_SEND)
992 ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND;
James Smartfa4066b2008-01-11 01:53:27 -0500993 /* decrement node reference count to the failed mbox
994 * command
995 */
James Smart329f9bc2007-04-25 09:53:01 -0400996 lpfc_nlp_put(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -0500997 mp = (struct lpfc_dmabuf *) mbox->context1;
James Smart14691152006-12-02 13:34:28 -0500998 lpfc_mbuf_free(phba, mp->virt, mp->phys);
999 kfree(mp);
dea31012005-04-17 16:05:31 -05001000 mempool_free(mbox, phba->mbox_mem_pool);
James Smart92d7f7b2007-06-17 19:56:38 -05001001
James Smarte8b62012007-08-02 11:10:09 -04001002 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1003 "0134 PLOGI: cannot issue reg_login "
1004 "Data: x%x x%x x%x x%x\n",
1005 ndlp->nlp_DID, ndlp->nlp_state,
1006 ndlp->nlp_flag, ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05001007 } else {
1008 mempool_free(mbox, phba->mbox_mem_pool);
James Smart92d7f7b2007-06-17 19:56:38 -05001009
James Smarte8b62012007-08-02 11:10:09 -04001010 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1011 "0135 PLOGI: cannot format reg_login "
1012 "Data: x%x x%x x%x x%x\n",
1013 ndlp->nlp_DID, ndlp->nlp_state,
1014 ndlp->nlp_flag, ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05001015 }
1016
1017
James Smart92d7f7b2007-06-17 19:56:38 -05001018out:
1019 if (ndlp->nlp_DID == NameServer_DID) {
1020 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04001021 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1022 "0261 Cannot Register NameServer login\n");
James Smart92d7f7b2007-06-17 19:56:38 -05001023 }
1024
James Smart0ff10d42008-01-11 01:52:36 -05001025 spin_lock_irq(shost->host_lock);
James Smarta8adb832007-10-27 13:37:53 -04001026 ndlp->nlp_flag |= NLP_DEFER_RM;
James Smart0ff10d42008-01-11 01:52:36 -05001027 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001028 return NLP_STE_FREED_NODE;
dea31012005-04-17 16:05:31 -05001029}
1030
1031static uint32_t
James Smart0ff10d42008-01-11 01:52:36 -05001032lpfc_cmpl_logo_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1033 void *arg, uint32_t evt)
1034{
1035 return ndlp->nlp_state;
1036}
1037
1038static uint32_t
1039lpfc_cmpl_reglogin_plogi_issue(struct lpfc_vport *vport,
1040 struct lpfc_nodelist *ndlp, void *arg, uint32_t evt)
1041{
James Smart78730cf2010-04-06 15:06:30 -04001042 struct lpfc_hba *phba;
1043 LPFC_MBOXQ_t *pmb = (LPFC_MBOXQ_t *) arg;
1044 MAILBOX_t *mb = &pmb->u.mb;
1045 uint16_t rpi;
1046
1047 phba = vport->phba;
1048 /* Release the RPI */
1049 if (!(phba->pport->load_flag & FC_UNLOADING) &&
1050 !mb->mbxStatus) {
1051 rpi = pmb->u.mb.un.varWords[0];
1052 lpfc_release_rpi(phba, vport, rpi);
1053 }
James Smart0ff10d42008-01-11 01:52:36 -05001054 return ndlp->nlp_state;
1055}
1056
1057static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001058lpfc_device_rm_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1059 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001060{
James Smart2e0fef82007-06-17 19:56:36 -05001061 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001062
James Smart2e0fef82007-06-17 19:56:36 -05001063 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1064 spin_lock_irq(shost->host_lock);
1065 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
1066 spin_unlock_irq(shost->host_lock);
1067 return ndlp->nlp_state;
1068 } else {
1069 /* software abort outstanding PLOGI */
1070 lpfc_els_abort(vport->phba, ndlp);
1071
1072 lpfc_drop_node(vport, ndlp);
James Smarta0f9b482006-04-15 11:52:56 -04001073 return NLP_STE_FREED_NODE;
1074 }
dea31012005-04-17 16:05:31 -05001075}
1076
1077static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001078lpfc_device_recov_plogi_issue(struct lpfc_vport *vport,
1079 struct lpfc_nodelist *ndlp,
1080 void *arg,
1081 uint32_t evt)
dea31012005-04-17 16:05:31 -05001082{
James Smart2e0fef82007-06-17 19:56:36 -05001083 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1084 struct lpfc_hba *phba = vport->phba;
1085
James Smart92d7f7b2007-06-17 19:56:38 -05001086 /* Don't do anything that will mess up processing of the
1087 * previous RSCN.
1088 */
1089 if (vport->fc_flag & FC_RSCN_DEFERRED)
1090 return ndlp->nlp_state;
1091
dea31012005-04-17 16:05:31 -05001092 /* software abort outstanding PLOGI */
James Smart07951072007-04-25 09:51:38 -04001093 lpfc_els_abort(phba, ndlp);
dea31012005-04-17 16:05:31 -05001094
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001095 ndlp->nlp_prev_state = NLP_STE_PLOGI_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -05001096 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
James Smart92d7f7b2007-06-17 19:56:38 -05001097 spin_lock_irq(shost->host_lock);
James Smarta0f9b482006-04-15 11:52:56 -04001098 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
James Smart2e0fef82007-06-17 19:56:36 -05001099 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001100
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001101 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001102}
1103
1104static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001105lpfc_rcv_plogi_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1106 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001107{
James Smart0d2b6b82008-06-14 22:52:47 -04001108 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart2e0fef82007-06-17 19:56:36 -05001109 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001110 struct lpfc_iocbq *cmdiocb;
1111
1112 /* software abort outstanding ADISC */
James Smart07951072007-04-25 09:51:38 -04001113 lpfc_els_abort(phba, ndlp);
dea31012005-04-17 16:05:31 -05001114
1115 cmdiocb = (struct lpfc_iocbq *) arg;
1116
James Smart0d2b6b82008-06-14 22:52:47 -04001117 if (lpfc_rcv_plogi(vport, ndlp, cmdiocb)) {
1118 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1119 spin_lock_irq(shost->host_lock);
1120 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
1121 spin_unlock_irq(shost->host_lock);
James Smart90160e02008-08-24 21:49:45 -04001122 if (vport->num_disc_nodes)
James Smart0d2b6b82008-06-14 22:52:47 -04001123 lpfc_more_adisc(vport);
James Smart0d2b6b82008-06-14 22:52:47 -04001124 }
1125 return ndlp->nlp_state;
1126 }
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001127 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -05001128 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
1129 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
dea31012005-04-17 16:05:31 -05001130
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001131 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001132}
1133
1134static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001135lpfc_rcv_prli_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1136 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001137{
James Smart2e0fef82007-06-17 19:56:36 -05001138 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001139
James Smart2e0fef82007-06-17 19:56:36 -05001140 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001141 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001142}
1143
1144static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001145lpfc_rcv_logo_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1146 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001147{
James Smart2e0fef82007-06-17 19:56:36 -05001148 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001149 struct lpfc_iocbq *cmdiocb;
1150
1151 cmdiocb = (struct lpfc_iocbq *) arg;
1152
1153 /* software abort outstanding ADISC */
James Smart07951072007-04-25 09:51:38 -04001154 lpfc_els_abort(phba, ndlp);
dea31012005-04-17 16:05:31 -05001155
James Smart2e0fef82007-06-17 19:56:36 -05001156 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001157 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001158}
1159
1160static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001161lpfc_rcv_padisc_adisc_issue(struct lpfc_vport *vport,
1162 struct lpfc_nodelist *ndlp,
1163 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001164{
1165 struct lpfc_iocbq *cmdiocb;
1166
1167 cmdiocb = (struct lpfc_iocbq *) arg;
1168
James Smart2e0fef82007-06-17 19:56:36 -05001169 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001170 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001171}
1172
1173static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001174lpfc_rcv_prlo_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1175 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001176{
1177 struct lpfc_iocbq *cmdiocb;
1178
1179 cmdiocb = (struct lpfc_iocbq *) arg;
1180
1181 /* Treat like rcv logo */
James Smart2e0fef82007-06-17 19:56:36 -05001182 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_PRLO);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001183 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001184}
1185
1186static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001187lpfc_cmpl_adisc_adisc_issue(struct lpfc_vport *vport,
1188 struct lpfc_nodelist *ndlp,
1189 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001190{
James Smart2e0fef82007-06-17 19:56:36 -05001191 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1192 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001193 struct lpfc_iocbq *cmdiocb, *rspiocb;
1194 IOCB_t *irsp;
1195 ADISC *ap;
James Smart6fb120a2009-05-22 14:52:59 -04001196 int rc;
dea31012005-04-17 16:05:31 -05001197
1198 cmdiocb = (struct lpfc_iocbq *) arg;
1199 rspiocb = cmdiocb->context_un.rsp_iocb;
1200
1201 ap = (ADISC *)lpfc_check_elscmpl_iocb(phba, cmdiocb, rspiocb);
1202 irsp = &rspiocb->iocb;
1203
1204 if ((irsp->ulpStatus) ||
James Smart92d7f7b2007-06-17 19:56:38 -05001205 (!lpfc_check_adisc(vport, ndlp, &ap->nodeName, &ap->portName))) {
dea31012005-04-17 16:05:31 -05001206 /* 1 sec timeout */
1207 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ);
James Smart2e0fef82007-06-17 19:56:36 -05001208 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001209 ndlp->nlp_flag |= NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05001210 spin_unlock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001211 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
dea31012005-04-17 16:05:31 -05001212
James Smart2e0fef82007-06-17 19:56:36 -05001213 memset(&ndlp->nlp_nodename, 0, sizeof(struct lpfc_name));
1214 memset(&ndlp->nlp_portname, 0, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05001215
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001216 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -05001217 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1218 lpfc_unreg_rpi(vport, ndlp);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001219 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001220 }
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001221
James Smart6fb120a2009-05-22 14:52:59 -04001222 if (phba->sli_rev == LPFC_SLI_REV4) {
1223 rc = lpfc_sli4_resume_rpi(ndlp);
1224 if (rc) {
1225 /* Stay in state and retry. */
1226 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
1227 return ndlp->nlp_state;
1228 }
1229 }
1230
James.Smart@Emulex.Com25013222005-06-25 10:34:33 -04001231 if (ndlp->nlp_type & NLP_FCP_TARGET) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001232 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -05001233 lpfc_nlp_set_state(vport, ndlp, NLP_STE_MAPPED_NODE);
James.Smart@Emulex.Com25013222005-06-25 10:34:33 -04001234 } else {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001235 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -05001236 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
James.Smart@Emulex.Com25013222005-06-25 10:34:33 -04001237 }
James Smart6fb120a2009-05-22 14:52:59 -04001238
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001239 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001240}
1241
1242static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001243lpfc_device_rm_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1244 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001245{
James Smart2e0fef82007-06-17 19:56:36 -05001246 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001247
James Smart2e0fef82007-06-17 19:56:36 -05001248 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1249 spin_lock_irq(shost->host_lock);
1250 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
1251 spin_unlock_irq(shost->host_lock);
1252 return ndlp->nlp_state;
1253 } else {
1254 /* software abort outstanding ADISC */
1255 lpfc_els_abort(vport->phba, ndlp);
1256
1257 lpfc_drop_node(vport, ndlp);
James Smarta0f9b482006-04-15 11:52:56 -04001258 return NLP_STE_FREED_NODE;
1259 }
dea31012005-04-17 16:05:31 -05001260}
1261
1262static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001263lpfc_device_recov_adisc_issue(struct lpfc_vport *vport,
1264 struct lpfc_nodelist *ndlp,
1265 void *arg,
1266 uint32_t evt)
dea31012005-04-17 16:05:31 -05001267{
James Smart2e0fef82007-06-17 19:56:36 -05001268 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1269 struct lpfc_hba *phba = vport->phba;
1270
James Smart92d7f7b2007-06-17 19:56:38 -05001271 /* Don't do anything that will mess up processing of the
1272 * previous RSCN.
1273 */
1274 if (vport->fc_flag & FC_RSCN_DEFERRED)
1275 return ndlp->nlp_state;
1276
dea31012005-04-17 16:05:31 -05001277 /* software abort outstanding ADISC */
James Smart07951072007-04-25 09:51:38 -04001278 lpfc_els_abort(phba, ndlp);
dea31012005-04-17 16:05:31 -05001279
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001280 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -05001281 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1282 spin_lock_irq(shost->host_lock);
James Smarta0f9b482006-04-15 11:52:56 -04001283 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
James Smart2e0fef82007-06-17 19:56:36 -05001284 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05001285 lpfc_disc_set_adisc(vport, ndlp);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001286 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001287}
1288
1289static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001290lpfc_rcv_plogi_reglogin_issue(struct lpfc_vport *vport,
1291 struct lpfc_nodelist *ndlp,
1292 void *arg,
dea31012005-04-17 16:05:31 -05001293 uint32_t evt)
1294{
James Smart2e0fef82007-06-17 19:56:36 -05001295 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001296
James Smart2e0fef82007-06-17 19:56:36 -05001297 lpfc_rcv_plogi(vport, ndlp, cmdiocb);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001298 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001299}
1300
1301static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001302lpfc_rcv_prli_reglogin_issue(struct lpfc_vport *vport,
1303 struct lpfc_nodelist *ndlp,
1304 void *arg,
dea31012005-04-17 16:05:31 -05001305 uint32_t evt)
1306{
James Smart2e0fef82007-06-17 19:56:36 -05001307 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001308
James Smart2e0fef82007-06-17 19:56:36 -05001309 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001310 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001311}
1312
1313static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001314lpfc_rcv_logo_reglogin_issue(struct lpfc_vport *vport,
1315 struct lpfc_nodelist *ndlp,
1316 void *arg,
dea31012005-04-17 16:05:31 -05001317 uint32_t evt)
1318{
James Smart2e0fef82007-06-17 19:56:36 -05001319 struct lpfc_hba *phba = vport->phba;
1320 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
James Smart7054a602007-04-25 09:52:34 -04001321 LPFC_MBOXQ_t *mb;
1322 LPFC_MBOXQ_t *nextmb;
1323 struct lpfc_dmabuf *mp;
dea31012005-04-17 16:05:31 -05001324
1325 cmdiocb = (struct lpfc_iocbq *) arg;
1326
James Smart7054a602007-04-25 09:52:34 -04001327 /* cleanup any ndlp on mbox q waiting for reglogin cmpl */
1328 if ((mb = phba->sli.mbox_active)) {
James Smart04c68492009-05-22 14:52:52 -04001329 if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) &&
James Smart7054a602007-04-25 09:52:34 -04001330 (ndlp == (struct lpfc_nodelist *) mb->context2)) {
James Smart92d7f7b2007-06-17 19:56:38 -05001331 lpfc_nlp_put(ndlp);
James Smart7054a602007-04-25 09:52:34 -04001332 mb->context2 = NULL;
1333 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1334 }
1335 }
1336
James Smart2e0fef82007-06-17 19:56:36 -05001337 spin_lock_irq(&phba->hbalock);
James Smart7054a602007-04-25 09:52:34 -04001338 list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) {
James Smart04c68492009-05-22 14:52:52 -04001339 if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) &&
James Smart7054a602007-04-25 09:52:34 -04001340 (ndlp == (struct lpfc_nodelist *) mb->context2)) {
James Smart5ffc2662009-11-18 15:39:44 -05001341 if (phba->sli_rev == LPFC_SLI_REV4) {
1342 spin_unlock_irq(&phba->hbalock);
1343 lpfc_sli4_free_rpi(phba,
1344 mb->u.mb.un.varRegLogin.rpi);
1345 spin_lock_irq(&phba->hbalock);
1346 }
James Smart7054a602007-04-25 09:52:34 -04001347 mp = (struct lpfc_dmabuf *) (mb->context1);
1348 if (mp) {
James Smart98c9ea52007-10-27 13:37:33 -04001349 __lpfc_mbuf_free(phba, mp->virt, mp->phys);
James Smart7054a602007-04-25 09:52:34 -04001350 kfree(mp);
1351 }
James Smart92d7f7b2007-06-17 19:56:38 -05001352 lpfc_nlp_put(ndlp);
James Smart7054a602007-04-25 09:52:34 -04001353 list_del(&mb->list);
James Smart5ffc2662009-11-18 15:39:44 -05001354 phba->sli.mboxq_cnt--;
James Smart7054a602007-04-25 09:52:34 -04001355 mempool_free(mb, phba->mbox_mem_pool);
1356 }
1357 }
James Smart2e0fef82007-06-17 19:56:36 -05001358 spin_unlock_irq(&phba->hbalock);
James Smart7054a602007-04-25 09:52:34 -04001359
James Smart2e0fef82007-06-17 19:56:36 -05001360 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001361 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001362}
1363
1364static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001365lpfc_rcv_padisc_reglogin_issue(struct lpfc_vport *vport,
1366 struct lpfc_nodelist *ndlp,
1367 void *arg,
dea31012005-04-17 16:05:31 -05001368 uint32_t evt)
1369{
James Smart2e0fef82007-06-17 19:56:36 -05001370 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001371
James Smart2e0fef82007-06-17 19:56:36 -05001372 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001373 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001374}
1375
1376static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001377lpfc_rcv_prlo_reglogin_issue(struct lpfc_vport *vport,
1378 struct lpfc_nodelist *ndlp,
1379 void *arg,
dea31012005-04-17 16:05:31 -05001380 uint32_t evt)
1381{
1382 struct lpfc_iocbq *cmdiocb;
1383
1384 cmdiocb = (struct lpfc_iocbq *) arg;
James Smart51ef4c22007-08-02 11:10:31 -04001385 lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001386 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001387}
1388
1389static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001390lpfc_cmpl_reglogin_reglogin_issue(struct lpfc_vport *vport,
1391 struct lpfc_nodelist *ndlp,
1392 void *arg,
1393 uint32_t evt)
dea31012005-04-17 16:05:31 -05001394{
James Smart2e0fef82007-06-17 19:56:36 -05001395 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart2e0fef82007-06-17 19:56:36 -05001396 LPFC_MBOXQ_t *pmb = (LPFC_MBOXQ_t *) arg;
James Smart04c68492009-05-22 14:52:52 -04001397 MAILBOX_t *mb = &pmb->u.mb;
James Smart2e0fef82007-06-17 19:56:36 -05001398 uint32_t did = mb->un.varWords[1];
dea31012005-04-17 16:05:31 -05001399
dea31012005-04-17 16:05:31 -05001400 if (mb->mbxStatus) {
1401 /* RegLogin failed */
James Smarte8b62012007-08-02 11:10:09 -04001402 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
1403 "0246 RegLogin failed Data: x%x x%x x%x\n",
James Smart2e0fef82007-06-17 19:56:36 -05001404 did, mb->mbxStatus, vport->port_state);
James Smartd0e56da2006-07-06 15:49:42 -04001405 /*
1406 * If RegLogin failed due to lack of HBA resources do not
1407 * retry discovery.
1408 */
1409 if (mb->mbxStatus == MBXERR_RPI_FULL) {
James Smart87af33f2007-10-27 13:37:43 -04001410 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
1411 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
James Smartd0e56da2006-07-06 15:49:42 -04001412 return ndlp->nlp_state;
1413 }
1414
James Smart2e0fef82007-06-17 19:56:36 -05001415 /* Put ndlp in npr state set plogi timer for 1 sec */
dea31012005-04-17 16:05:31 -05001416 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ * 1);
James Smart2e0fef82007-06-17 19:56:36 -05001417 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001418 ndlp->nlp_flag |= NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05001419 spin_unlock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001420 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
dea31012005-04-17 16:05:31 -05001421
James Smart2e0fef82007-06-17 19:56:36 -05001422 lpfc_issue_els_logo(vport, ndlp, 0);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001423 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -05001424 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001425 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001426 }
1427
dea31012005-04-17 16:05:31 -05001428 ndlp->nlp_rpi = mb->un.varWords[0];
James Smart6fb120a2009-05-22 14:52:59 -04001429 ndlp->nlp_flag |= NLP_RPI_VALID;
dea31012005-04-17 16:05:31 -05001430
1431 /* Only if we are not a fabric nport do we issue PRLI */
1432 if (!(ndlp->nlp_type & NLP_FABRIC)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001433 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -05001434 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
1435 lpfc_issue_els_prli(vport, ndlp, 0);
dea31012005-04-17 16:05:31 -05001436 } else {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001437 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -05001438 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
dea31012005-04-17 16:05:31 -05001439 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001440 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001441}
1442
1443static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001444lpfc_device_rm_reglogin_issue(struct lpfc_vport *vport,
1445 struct lpfc_nodelist *ndlp,
1446 void *arg,
dea31012005-04-17 16:05:31 -05001447 uint32_t evt)
1448{
James Smart2e0fef82007-06-17 19:56:36 -05001449 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1450
1451 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1452 spin_lock_irq(shost->host_lock);
James Smarta0f9b482006-04-15 11:52:56 -04001453 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
James Smart2e0fef82007-06-17 19:56:36 -05001454 spin_unlock_irq(shost->host_lock);
James Smarta0f9b482006-04-15 11:52:56 -04001455 return ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05001456 } else {
1457 lpfc_drop_node(vport, ndlp);
James Smarta0f9b482006-04-15 11:52:56 -04001458 return NLP_STE_FREED_NODE;
1459 }
dea31012005-04-17 16:05:31 -05001460}
1461
1462static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001463lpfc_device_recov_reglogin_issue(struct lpfc_vport *vport,
1464 struct lpfc_nodelist *ndlp,
1465 void *arg,
1466 uint32_t evt)
dea31012005-04-17 16:05:31 -05001467{
James Smart2e0fef82007-06-17 19:56:36 -05001468 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1469
James Smart92d7f7b2007-06-17 19:56:38 -05001470 /* Don't do anything that will mess up processing of the
1471 * previous RSCN.
1472 */
1473 if (vport->fc_flag & FC_RSCN_DEFERRED)
1474 return ndlp->nlp_state;
1475
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001476 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -05001477 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1478 spin_lock_irq(shost->host_lock);
James Smartffc95492010-06-07 15:23:17 -04001479 ndlp->nlp_flag |= NLP_IGNR_REG_CMPL;
James Smarta0f9b482006-04-15 11:52:56 -04001480 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
James Smart2e0fef82007-06-17 19:56:36 -05001481 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05001482 lpfc_disc_set_adisc(vport, ndlp);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001483 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001484}
1485
1486static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001487lpfc_rcv_plogi_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1488 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001489{
1490 struct lpfc_iocbq *cmdiocb;
1491
1492 cmdiocb = (struct lpfc_iocbq *) arg;
1493
James Smart2e0fef82007-06-17 19:56:36 -05001494 lpfc_rcv_plogi(vport, ndlp, cmdiocb);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001495 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001496}
1497
1498static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001499lpfc_rcv_prli_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1500 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001501{
James Smart2e0fef82007-06-17 19:56:36 -05001502 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001503
James Smart2e0fef82007-06-17 19:56:36 -05001504 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001505 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001506}
1507
1508static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001509lpfc_rcv_logo_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1510 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001511{
James Smart2e0fef82007-06-17 19:56:36 -05001512 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001513
1514 /* Software abort outstanding PRLI before sending acc */
James Smart2e0fef82007-06-17 19:56:36 -05001515 lpfc_els_abort(vport->phba, ndlp);
dea31012005-04-17 16:05:31 -05001516
James Smart2e0fef82007-06-17 19:56:36 -05001517 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001518 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001519}
1520
1521static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001522lpfc_rcv_padisc_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1523 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001524{
James Smart2e0fef82007-06-17 19:56:36 -05001525 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001526
James Smart2e0fef82007-06-17 19:56:36 -05001527 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001528 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001529}
1530
1531/* This routine is envoked when we rcv a PRLO request from a nport
1532 * we are logged into. We should send back a PRLO rsp setting the
1533 * appropriate bits.
1534 * NEXT STATE = PRLI_ISSUE
1535 */
1536static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001537lpfc_rcv_prlo_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1538 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001539{
James Smart2e0fef82007-06-17 19:56:36 -05001540 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001541
James Smart51ef4c22007-08-02 11:10:31 -04001542 lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001543 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001544}
1545
1546static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001547lpfc_cmpl_prli_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1548 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001549{
James Smart92d7f7b2007-06-17 19:56:38 -05001550 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001551 struct lpfc_iocbq *cmdiocb, *rspiocb;
James Smart2e0fef82007-06-17 19:56:36 -05001552 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001553 IOCB_t *irsp;
1554 PRLI *npr;
1555
1556 cmdiocb = (struct lpfc_iocbq *) arg;
1557 rspiocb = cmdiocb->context_un.rsp_iocb;
1558 npr = (PRLI *)lpfc_check_elscmpl_iocb(phba, cmdiocb, rspiocb);
1559
1560 irsp = &rspiocb->iocb;
1561 if (irsp->ulpStatus) {
James Smart858c9f62007-06-17 19:56:39 -05001562 if ((vport->port_type == LPFC_NPIV_PORT) &&
James Smart3de2a652007-08-02 11:09:59 -04001563 vport->cfg_restrict_login) {
James Smart858c9f62007-06-17 19:56:39 -05001564 goto out;
1565 }
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001566 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -05001567 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001568 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001569 }
1570
1571 /* Check out PRLI rsp */
1572 ndlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR);
1573 ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
1574 if ((npr->acceptRspCode == PRLI_REQ_EXECUTED) &&
1575 (npr->prliType == PRLI_FCP_TYPE)) {
1576 if (npr->initiatorFunc)
1577 ndlp->nlp_type |= NLP_FCP_INITIATOR;
1578 if (npr->targetFunc)
1579 ndlp->nlp_type |= NLP_FCP_TARGET;
1580 if (npr->Retry)
1581 ndlp->nlp_fcp_info |= NLP_FCP_2_DEVICE;
1582 }
James Smart92d7f7b2007-06-17 19:56:38 -05001583 if (!(ndlp->nlp_type & NLP_FCP_TARGET) &&
1584 (vport->port_type == LPFC_NPIV_PORT) &&
James Smart3de2a652007-08-02 11:09:59 -04001585 vport->cfg_restrict_login) {
James Smart858c9f62007-06-17 19:56:39 -05001586out:
James Smart92d7f7b2007-06-17 19:56:38 -05001587 spin_lock_irq(shost->host_lock);
1588 ndlp->nlp_flag |= NLP_TARGET_REMOVE;
1589 spin_unlock_irq(shost->host_lock);
1590 lpfc_issue_els_logo(vport, ndlp, 0);
1591
1592 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
James Smart87af33f2007-10-27 13:37:43 -04001593 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
James Smart92d7f7b2007-06-17 19:56:38 -05001594 return ndlp->nlp_state;
1595 }
dea31012005-04-17 16:05:31 -05001596
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001597 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
James Smart92d7f7b2007-06-17 19:56:38 -05001598 if (ndlp->nlp_type & NLP_FCP_TARGET)
1599 lpfc_nlp_set_state(vport, ndlp, NLP_STE_MAPPED_NODE);
1600 else
1601 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001602 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001603}
1604
1605/*! lpfc_device_rm_prli_issue
James Smart92d7f7b2007-06-17 19:56:38 -05001606 *
1607 * \pre
1608 * \post
1609 * \param phba
1610 * \param ndlp
1611 * \param arg
1612 * \param evt
1613 * \return uint32_t
1614 *
1615 * \b Description:
1616 * This routine is envoked when we a request to remove a nport we are in the
1617 * process of PRLIing. We should software abort outstanding prli, unreg
1618 * login, send a logout. We will change node state to UNUSED_NODE, put it
1619 * on plogi list so it can be freed when LOGO completes.
1620 *
1621 */
1622
dea31012005-04-17 16:05:31 -05001623static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001624lpfc_device_rm_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1625 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001626{
James Smart2e0fef82007-06-17 19:56:36 -05001627 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001628
James Smart2e0fef82007-06-17 19:56:36 -05001629 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1630 spin_lock_irq(shost->host_lock);
1631 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
1632 spin_unlock_irq(shost->host_lock);
1633 return ndlp->nlp_state;
1634 } else {
1635 /* software abort outstanding PLOGI */
1636 lpfc_els_abort(vport->phba, ndlp);
1637
1638 lpfc_drop_node(vport, ndlp);
James Smarta0f9b482006-04-15 11:52:56 -04001639 return NLP_STE_FREED_NODE;
1640 }
dea31012005-04-17 16:05:31 -05001641}
1642
1643
1644/*! lpfc_device_recov_prli_issue
James Smart92d7f7b2007-06-17 19:56:38 -05001645 *
1646 * \pre
1647 * \post
1648 * \param phba
1649 * \param ndlp
1650 * \param arg
1651 * \param evt
1652 * \return uint32_t
1653 *
1654 * \b Description:
1655 * The routine is envoked when the state of a device is unknown, like
1656 * during a link down. We should remove the nodelist entry from the
1657 * unmapped list, issue a UNREG_LOGIN, do a software abort of the
1658 * outstanding PRLI command, then free the node entry.
1659 */
dea31012005-04-17 16:05:31 -05001660static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001661lpfc_device_recov_prli_issue(struct lpfc_vport *vport,
1662 struct lpfc_nodelist *ndlp,
1663 void *arg,
1664 uint32_t evt)
dea31012005-04-17 16:05:31 -05001665{
James Smart2e0fef82007-06-17 19:56:36 -05001666 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1667 struct lpfc_hba *phba = vport->phba;
1668
James Smart92d7f7b2007-06-17 19:56:38 -05001669 /* Don't do anything that will mess up processing of the
1670 * previous RSCN.
1671 */
1672 if (vport->fc_flag & FC_RSCN_DEFERRED)
1673 return ndlp->nlp_state;
1674
dea31012005-04-17 16:05:31 -05001675 /* software abort outstanding PRLI */
James Smart07951072007-04-25 09:51:38 -04001676 lpfc_els_abort(phba, ndlp);
dea31012005-04-17 16:05:31 -05001677
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001678 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -05001679 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1680 spin_lock_irq(shost->host_lock);
James Smarta0f9b482006-04-15 11:52:56 -04001681 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
James Smart2e0fef82007-06-17 19:56:36 -05001682 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05001683 lpfc_disc_set_adisc(vport, ndlp);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001684 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001685}
1686
1687static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001688lpfc_rcv_plogi_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1689 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001690{
James Smart2e0fef82007-06-17 19:56:36 -05001691 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001692
James Smart2e0fef82007-06-17 19:56:36 -05001693 lpfc_rcv_plogi(vport, ndlp, cmdiocb);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001694 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001695}
1696
1697static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001698lpfc_rcv_prli_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1699 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001700{
James Smart2e0fef82007-06-17 19:56:36 -05001701 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001702
James Smart2e0fef82007-06-17 19:56:36 -05001703 lpfc_rcv_prli(vport, ndlp, cmdiocb);
1704 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001705 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001706}
1707
1708static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001709lpfc_rcv_logo_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1710 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001711{
James Smart2e0fef82007-06-17 19:56:36 -05001712 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001713
James Smart2e0fef82007-06-17 19:56:36 -05001714 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001715 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001716}
1717
1718static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001719lpfc_rcv_padisc_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1720 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001721{
James Smart2e0fef82007-06-17 19:56:36 -05001722 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001723
James Smart2e0fef82007-06-17 19:56:36 -05001724 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001725 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001726}
1727
1728static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001729lpfc_rcv_prlo_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1730 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001731{
James Smart2e0fef82007-06-17 19:56:36 -05001732 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001733
James Smart51ef4c22007-08-02 11:10:31 -04001734 lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001735 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001736}
1737
1738static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001739lpfc_device_recov_unmap_node(struct lpfc_vport *vport,
1740 struct lpfc_nodelist *ndlp,
1741 void *arg,
1742 uint32_t evt)
dea31012005-04-17 16:05:31 -05001743{
James Smart2e0fef82007-06-17 19:56:36 -05001744 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1745
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001746 ndlp->nlp_prev_state = NLP_STE_UNMAPPED_NODE;
James Smart2e0fef82007-06-17 19:56:36 -05001747 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1748 spin_lock_irq(shost->host_lock);
James Smarta0f9b482006-04-15 11:52:56 -04001749 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
James Smart2e0fef82007-06-17 19:56:36 -05001750 spin_unlock_irq(shost->host_lock);
1751 lpfc_disc_set_adisc(vport, ndlp);
dea31012005-04-17 16:05:31 -05001752
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001753 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001754}
1755
1756static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001757lpfc_rcv_plogi_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1758 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001759{
James Smart2e0fef82007-06-17 19:56:36 -05001760 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001761
James Smart2e0fef82007-06-17 19:56:36 -05001762 lpfc_rcv_plogi(vport, ndlp, cmdiocb);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001763 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001764}
1765
1766static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001767lpfc_rcv_prli_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1768 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001769{
James Smart2e0fef82007-06-17 19:56:36 -05001770 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001771
James Smart2e0fef82007-06-17 19:56:36 -05001772 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001773 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001774}
1775
1776static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001777lpfc_rcv_logo_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1778 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001779{
James Smart2e0fef82007-06-17 19:56:36 -05001780 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001781
James Smart2e0fef82007-06-17 19:56:36 -05001782 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001783 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001784}
1785
1786static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001787lpfc_rcv_padisc_mapped_node(struct lpfc_vport *vport,
1788 struct lpfc_nodelist *ndlp,
1789 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001790{
James Smart2e0fef82007-06-17 19:56:36 -05001791 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001792
James Smart2e0fef82007-06-17 19:56:36 -05001793 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001794 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001795}
1796
1797static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001798lpfc_rcv_prlo_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1799 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001800{
James Smart2e0fef82007-06-17 19:56:36 -05001801 struct lpfc_hba *phba = vport->phba;
1802 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001803
1804 /* flush the target */
James Smart51ef4c22007-08-02 11:10:31 -04001805 lpfc_sli_abort_iocb(vport, &phba->sli.ring[phba->sli.fcp_ring],
1806 ndlp->nlp_sid, 0, LPFC_CTX_TGT);
dea31012005-04-17 16:05:31 -05001807
1808 /* Treat like rcv logo */
James Smart2e0fef82007-06-17 19:56:36 -05001809 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_PRLO);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001810 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001811}
1812
1813static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001814lpfc_device_recov_mapped_node(struct lpfc_vport *vport,
1815 struct lpfc_nodelist *ndlp,
1816 void *arg,
1817 uint32_t evt)
dea31012005-04-17 16:05:31 -05001818{
James Smart2e0fef82007-06-17 19:56:36 -05001819 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1820
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001821 ndlp->nlp_prev_state = NLP_STE_MAPPED_NODE;
James Smart2e0fef82007-06-17 19:56:36 -05001822 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1823 spin_lock_irq(shost->host_lock);
James Smarta0f9b482006-04-15 11:52:56 -04001824 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
James Smart2e0fef82007-06-17 19:56:36 -05001825 spin_unlock_irq(shost->host_lock);
1826 lpfc_disc_set_adisc(vport, ndlp);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001827 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001828}
1829
1830static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001831lpfc_rcv_plogi_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1832 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001833{
James Smart2e0fef82007-06-17 19:56:36 -05001834 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1835 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001836
1837 /* Ignore PLOGI if we have an outstanding LOGO */
James Smart0d2b6b82008-06-14 22:52:47 -04001838 if (ndlp->nlp_flag & (NLP_LOGO_SND | NLP_LOGO_ACC))
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001839 return ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05001840 if (lpfc_rcv_plogi(vport, ndlp, cmdiocb)) {
James Smart0d2b6b82008-06-14 22:52:47 -04001841 lpfc_cancel_retry_delay_tmo(vport, ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05001842 spin_lock_irq(shost->host_lock);
James Smart0d2b6b82008-06-14 22:52:47 -04001843 ndlp->nlp_flag &= ~(NLP_NPR_ADISC | NLP_NPR_2B_DISC);
James Smart2e0fef82007-06-17 19:56:36 -05001844 spin_unlock_irq(shost->host_lock);
James Smart0d2b6b82008-06-14 22:52:47 -04001845 } else if (!(ndlp->nlp_flag & NLP_NPR_2B_DISC)) {
1846 /* send PLOGI immediately, move to PLOGI issue state */
1847 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
1848 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
1849 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
1850 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
1851 }
dea31012005-04-17 16:05:31 -05001852 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001853 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001854}
1855
1856static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001857lpfc_rcv_prli_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1858 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001859{
James Smart2e0fef82007-06-17 19:56:36 -05001860 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1861 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1862 struct ls_rjt stat;
dea31012005-04-17 16:05:31 -05001863
1864 memset(&stat, 0, sizeof (struct ls_rjt));
1865 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
1866 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
James Smart858c9f62007-06-17 19:56:39 -05001867 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05001868
1869 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
1870 if (ndlp->nlp_flag & NLP_NPR_ADISC) {
James Smart2e0fef82007-06-17 19:56:36 -05001871 spin_lock_irq(shost->host_lock);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001872 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001873 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
James Smart2e0fef82007-06-17 19:56:36 -05001874 spin_unlock_irq(shost->host_lock);
1875 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
1876 lpfc_issue_els_adisc(vport, ndlp, 0);
dea31012005-04-17 16:05:31 -05001877 } else {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001878 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
James Smart2e0fef82007-06-17 19:56:36 -05001879 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
1880 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
dea31012005-04-17 16:05:31 -05001881 }
1882 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001883 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001884}
1885
1886static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001887lpfc_rcv_logo_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1888 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001889{
James Smart2e0fef82007-06-17 19:56:36 -05001890 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001891
James Smart2e0fef82007-06-17 19:56:36 -05001892 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001893 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001894}
1895
1896static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001897lpfc_rcv_padisc_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1898 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001899{
James Smart2e0fef82007-06-17 19:56:36 -05001900 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001901
James Smart2e0fef82007-06-17 19:56:36 -05001902 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
James Smart33ccf8d2006-08-17 11:57:58 -04001903 /*
1904 * Do not start discovery if discovery is about to start
1905 * or discovery in progress for this node. Starting discovery
1906 * here will affect the counting of discovery threads.
1907 */
James Smart2fb9bd82006-12-02 13:33:57 -05001908 if (!(ndlp->nlp_flag & NLP_DELAY_TMO) &&
James Smart92d7f7b2007-06-17 19:56:38 -05001909 !(ndlp->nlp_flag & NLP_NPR_2B_DISC)) {
dea31012005-04-17 16:05:31 -05001910 if (ndlp->nlp_flag & NLP_NPR_ADISC) {
James Smart92d7f7b2007-06-17 19:56:38 -05001911 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001912 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
James Smart2e0fef82007-06-17 19:56:36 -05001913 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
1914 lpfc_issue_els_adisc(vport, ndlp, 0);
dea31012005-04-17 16:05:31 -05001915 } else {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001916 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
James Smart2e0fef82007-06-17 19:56:36 -05001917 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
1918 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
dea31012005-04-17 16:05:31 -05001919 }
1920 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001921 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001922}
1923
1924static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001925lpfc_rcv_prlo_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1926 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001927{
James Smart2e0fef82007-06-17 19:56:36 -05001928 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1929 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001930
James Smart2e0fef82007-06-17 19:56:36 -05001931 spin_lock_irq(shost->host_lock);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001932 ndlp->nlp_flag |= NLP_LOGO_ACC;
James Smart2e0fef82007-06-17 19:56:36 -05001933 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001934
James Smart51ef4c22007-08-02 11:10:31 -04001935 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05001936
James Smart2e0fef82007-06-17 19:56:36 -05001937 if ((ndlp->nlp_flag & NLP_DELAY_TMO) == 0) {
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001938 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ * 1);
James Smart2e0fef82007-06-17 19:56:36 -05001939 spin_lock_irq(shost->host_lock);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001940 ndlp->nlp_flag |= NLP_DELAY_TMO;
1941 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
James Smart2e0fef82007-06-17 19:56:36 -05001942 spin_unlock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001943 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001944 } else {
James Smart2e0fef82007-06-17 19:56:36 -05001945 spin_lock_irq(shost->host_lock);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001946 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
James Smart2e0fef82007-06-17 19:56:36 -05001947 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001948 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001949 return ndlp->nlp_state;
1950}
dea31012005-04-17 16:05:31 -05001951
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001952static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001953lpfc_cmpl_plogi_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1954 void *arg, uint32_t evt)
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001955{
1956 struct lpfc_iocbq *cmdiocb, *rspiocb;
James Smarta0f9b482006-04-15 11:52:56 -04001957 IOCB_t *irsp;
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001958
1959 cmdiocb = (struct lpfc_iocbq *) arg;
1960 rspiocb = cmdiocb->context_un.rsp_iocb;
James Smarta0f9b482006-04-15 11:52:56 -04001961
1962 irsp = &rspiocb->iocb;
1963 if (irsp->ulpStatus) {
James Smarta8adb832007-10-27 13:37:53 -04001964 ndlp->nlp_flag |= NLP_DEFER_RM;
James Smarta0f9b482006-04-15 11:52:56 -04001965 return NLP_STE_FREED_NODE;
1966 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001967 return ndlp->nlp_state;
1968}
1969
1970static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001971lpfc_cmpl_prli_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1972 void *arg, uint32_t evt)
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001973{
1974 struct lpfc_iocbq *cmdiocb, *rspiocb;
James Smarta0f9b482006-04-15 11:52:56 -04001975 IOCB_t *irsp;
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001976
1977 cmdiocb = (struct lpfc_iocbq *) arg;
1978 rspiocb = cmdiocb->context_un.rsp_iocb;
James Smarta0f9b482006-04-15 11:52:56 -04001979
1980 irsp = &rspiocb->iocb;
1981 if (irsp->ulpStatus && (ndlp->nlp_flag & NLP_NODEV_REMOVE)) {
James Smart2e0fef82007-06-17 19:56:36 -05001982 lpfc_drop_node(vport, ndlp);
James Smarta0f9b482006-04-15 11:52:56 -04001983 return NLP_STE_FREED_NODE;
1984 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001985 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001986}
1987
1988static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001989lpfc_cmpl_logo_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1990 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001991{
James Smartd7c255b2008-08-24 21:50:00 -04001992 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1993 if (ndlp->nlp_DID == Fabric_DID) {
1994 spin_lock_irq(shost->host_lock);
1995 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
1996 spin_unlock_irq(shost->host_lock);
1997 }
James Smart2e0fef82007-06-17 19:56:36 -05001998 lpfc_unreg_rpi(vport, ndlp);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001999 return ndlp->nlp_state;
2000}
2001
2002static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05002003lpfc_cmpl_adisc_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2004 void *arg, uint32_t evt)
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002005{
2006 struct lpfc_iocbq *cmdiocb, *rspiocb;
James Smarta0f9b482006-04-15 11:52:56 -04002007 IOCB_t *irsp;
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002008
2009 cmdiocb = (struct lpfc_iocbq *) arg;
2010 rspiocb = cmdiocb->context_un.rsp_iocb;
James Smarta0f9b482006-04-15 11:52:56 -04002011
2012 irsp = &rspiocb->iocb;
2013 if (irsp->ulpStatus && (ndlp->nlp_flag & NLP_NODEV_REMOVE)) {
James Smart2e0fef82007-06-17 19:56:36 -05002014 lpfc_drop_node(vport, ndlp);
James Smarta0f9b482006-04-15 11:52:56 -04002015 return NLP_STE_FREED_NODE;
2016 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002017 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05002018}
2019
2020static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05002021lpfc_cmpl_reglogin_npr_node(struct lpfc_vport *vport,
2022 struct lpfc_nodelist *ndlp,
2023 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05002024{
James Smart2e0fef82007-06-17 19:56:36 -05002025 LPFC_MBOXQ_t *pmb = (LPFC_MBOXQ_t *) arg;
James Smart04c68492009-05-22 14:52:52 -04002026 MAILBOX_t *mb = &pmb->u.mb;
dea31012005-04-17 16:05:31 -05002027
James Smart04c68492009-05-22 14:52:52 -04002028 if (!mb->mbxStatus) {
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002029 ndlp->nlp_rpi = mb->un.varWords[0];
James Smart04c68492009-05-22 14:52:52 -04002030 ndlp->nlp_flag |= NLP_RPI_VALID;
2031 } else {
James Smarta0f9b482006-04-15 11:52:56 -04002032 if (ndlp->nlp_flag & NLP_NODEV_REMOVE) {
James Smart2e0fef82007-06-17 19:56:36 -05002033 lpfc_drop_node(vport, ndlp);
James Smarta0f9b482006-04-15 11:52:56 -04002034 return NLP_STE_FREED_NODE;
2035 }
2036 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002037 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05002038}
2039
2040static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05002041lpfc_device_rm_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2042 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05002043{
James Smart2e0fef82007-06-17 19:56:36 -05002044 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2045
James Smarta0f9b482006-04-15 11:52:56 -04002046 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
James Smart2e0fef82007-06-17 19:56:36 -05002047 spin_lock_irq(shost->host_lock);
James Smarta0f9b482006-04-15 11:52:56 -04002048 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
James Smart2e0fef82007-06-17 19:56:36 -05002049 spin_unlock_irq(shost->host_lock);
James Smarta0f9b482006-04-15 11:52:56 -04002050 return ndlp->nlp_state;
2051 }
James Smart2e0fef82007-06-17 19:56:36 -05002052 lpfc_drop_node(vport, ndlp);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002053 return NLP_STE_FREED_NODE;
dea31012005-04-17 16:05:31 -05002054}
2055
2056static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05002057lpfc_device_recov_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2058 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05002059{
James Smart2e0fef82007-06-17 19:56:36 -05002060 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2061
James Smart92d7f7b2007-06-17 19:56:38 -05002062 /* Don't do anything that will mess up processing of the
2063 * previous RSCN.
2064 */
2065 if (vport->fc_flag & FC_RSCN_DEFERRED)
2066 return ndlp->nlp_state;
2067
James Smarteaf15d52008-12-04 22:39:29 -05002068 lpfc_cancel_retry_delay_tmo(vport, ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05002069 spin_lock_irq(shost->host_lock);
James Smarta0f9b482006-04-15 11:52:56 -04002070 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
James Smart2e0fef82007-06-17 19:56:36 -05002071 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002072 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05002073}
2074
2075
2076/* This next section defines the NPort Discovery State Machine */
2077
2078/* There are 4 different double linked lists nodelist entries can reside on.
2079 * The plogi list and adisc list are used when Link Up discovery or RSCN
2080 * processing is needed. Each list holds the nodes that we will send PLOGI
2081 * or ADISC on. These lists will keep track of what nodes will be effected
2082 * by an RSCN, or a Link Up (Typically, all nodes are effected on Link Up).
2083 * The unmapped_list will contain all nodes that we have successfully logged
2084 * into at the Fibre Channel level. The mapped_list will contain all nodes
2085 * that are mapped FCP targets.
2086 */
2087/*
2088 * The bind list is a list of undiscovered (potentially non-existent) nodes
2089 * that we have saved binding information on. This information is used when
2090 * nodes transition from the unmapped to the mapped list.
2091 */
2092/* For UNUSED_NODE state, the node has just been allocated .
2093 * For PLOGI_ISSUE and REG_LOGIN_ISSUE, the node is on
2094 * the PLOGI list. For REG_LOGIN_COMPL, the node is taken off the PLOGI list
2095 * and put on the unmapped list. For ADISC processing, the node is taken off
2096 * the ADISC list and placed on either the mapped or unmapped list (depending
2097 * on its previous state). Once on the unmapped list, a PRLI is issued and the
2098 * state changed to PRLI_ISSUE. When the PRLI completion occurs, the state is
2099 * changed to UNMAPPED_NODE. If the completion indicates a mapped
2100 * node, the node is taken off the unmapped list. The binding list is checked
2101 * for a valid binding, or a binding is automatically assigned. If binding
2102 * assignment is unsuccessful, the node is left on the unmapped list. If
2103 * binding assignment is successful, the associated binding list entry (if
2104 * any) is removed, and the node is placed on the mapped list.
2105 */
2106/*
2107 * For a Link Down, all nodes on the ADISC, PLOGI, unmapped or mapped
James Smartc01f3202006-08-18 17:47:08 -04002108 * lists will receive a DEVICE_RECOVERY event. If the linkdown or devloss timers
dea31012005-04-17 16:05:31 -05002109 * expire, all effected nodes will receive a DEVICE_RM event.
2110 */
2111/*
2112 * For a Link Up or RSCN, all nodes will move from the mapped / unmapped lists
2113 * to either the ADISC or PLOGI list. After a Nameserver query or ALPA loopmap
2114 * check, additional nodes may be added or removed (via DEVICE_RM) to / from
2115 * the PLOGI or ADISC lists. Once the PLOGI and ADISC lists are populated,
2116 * we will first process the ADISC list. 32 entries are processed initially and
2117 * ADISC is initited for each one. Completions / Events for each node are
2118 * funnelled thru the state machine. As each node finishes ADISC processing, it
2119 * starts ADISC for any nodes waiting for ADISC processing. If no nodes are
2120 * waiting, and the ADISC list count is identically 0, then we are done. For
2121 * Link Up discovery, since all nodes on the PLOGI list are UNREG_LOGIN'ed, we
2122 * can issue a CLEAR_LA and reenable Link Events. Next we will process the PLOGI
2123 * list. 32 entries are processed initially and PLOGI is initited for each one.
2124 * Completions / Events for each node are funnelled thru the state machine. As
2125 * each node finishes PLOGI processing, it starts PLOGI for any nodes waiting
2126 * for PLOGI processing. If no nodes are waiting, and the PLOGI list count is
2127 * indentically 0, then we are done. We have now completed discovery / RSCN
2128 * handling. Upon completion, ALL nodes should be on either the mapped or
2129 * unmapped lists.
2130 */
2131
2132static uint32_t (*lpfc_disc_action[NLP_STE_MAX_STATE * NLP_EVT_MAX_EVENT])
James Smart2e0fef82007-06-17 19:56:36 -05002133 (struct lpfc_vport *, struct lpfc_nodelist *, void *, uint32_t) = {
dea31012005-04-17 16:05:31 -05002134 /* Action routine Event Current State */
2135 lpfc_rcv_plogi_unused_node, /* RCV_PLOGI UNUSED_NODE */
2136 lpfc_rcv_els_unused_node, /* RCV_PRLI */
2137 lpfc_rcv_logo_unused_node, /* RCV_LOGO */
2138 lpfc_rcv_els_unused_node, /* RCV_ADISC */
2139 lpfc_rcv_els_unused_node, /* RCV_PDISC */
2140 lpfc_rcv_els_unused_node, /* RCV_PRLO */
2141 lpfc_disc_illegal, /* CMPL_PLOGI */
2142 lpfc_disc_illegal, /* CMPL_PRLI */
2143 lpfc_cmpl_logo_unused_node, /* CMPL_LOGO */
2144 lpfc_disc_illegal, /* CMPL_ADISC */
2145 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2146 lpfc_device_rm_unused_node, /* DEVICE_RM */
2147 lpfc_disc_illegal, /* DEVICE_RECOVERY */
2148
2149 lpfc_rcv_plogi_plogi_issue, /* RCV_PLOGI PLOGI_ISSUE */
James Smart92d7f7b2007-06-17 19:56:38 -05002150 lpfc_rcv_prli_plogi_issue, /* RCV_PRLI */
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002151 lpfc_rcv_logo_plogi_issue, /* RCV_LOGO */
dea31012005-04-17 16:05:31 -05002152 lpfc_rcv_els_plogi_issue, /* RCV_ADISC */
2153 lpfc_rcv_els_plogi_issue, /* RCV_PDISC */
2154 lpfc_rcv_els_plogi_issue, /* RCV_PRLO */
2155 lpfc_cmpl_plogi_plogi_issue, /* CMPL_PLOGI */
2156 lpfc_disc_illegal, /* CMPL_PRLI */
James Smart0ff10d42008-01-11 01:52:36 -05002157 lpfc_cmpl_logo_plogi_issue, /* CMPL_LOGO */
dea31012005-04-17 16:05:31 -05002158 lpfc_disc_illegal, /* CMPL_ADISC */
James Smart0ff10d42008-01-11 01:52:36 -05002159 lpfc_cmpl_reglogin_plogi_issue,/* CMPL_REG_LOGIN */
dea31012005-04-17 16:05:31 -05002160 lpfc_device_rm_plogi_issue, /* DEVICE_RM */
2161 lpfc_device_recov_plogi_issue, /* DEVICE_RECOVERY */
2162
2163 lpfc_rcv_plogi_adisc_issue, /* RCV_PLOGI ADISC_ISSUE */
2164 lpfc_rcv_prli_adisc_issue, /* RCV_PRLI */
2165 lpfc_rcv_logo_adisc_issue, /* RCV_LOGO */
2166 lpfc_rcv_padisc_adisc_issue, /* RCV_ADISC */
2167 lpfc_rcv_padisc_adisc_issue, /* RCV_PDISC */
2168 lpfc_rcv_prlo_adisc_issue, /* RCV_PRLO */
2169 lpfc_disc_illegal, /* CMPL_PLOGI */
2170 lpfc_disc_illegal, /* CMPL_PRLI */
2171 lpfc_disc_illegal, /* CMPL_LOGO */
2172 lpfc_cmpl_adisc_adisc_issue, /* CMPL_ADISC */
2173 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2174 lpfc_device_rm_adisc_issue, /* DEVICE_RM */
2175 lpfc_device_recov_adisc_issue, /* DEVICE_RECOVERY */
2176
2177 lpfc_rcv_plogi_reglogin_issue, /* RCV_PLOGI REG_LOGIN_ISSUE */
2178 lpfc_rcv_prli_reglogin_issue, /* RCV_PLOGI */
2179 lpfc_rcv_logo_reglogin_issue, /* RCV_LOGO */
2180 lpfc_rcv_padisc_reglogin_issue, /* RCV_ADISC */
2181 lpfc_rcv_padisc_reglogin_issue, /* RCV_PDISC */
2182 lpfc_rcv_prlo_reglogin_issue, /* RCV_PRLO */
James Smart87af33f2007-10-27 13:37:43 -04002183 lpfc_cmpl_plogi_illegal, /* CMPL_PLOGI */
dea31012005-04-17 16:05:31 -05002184 lpfc_disc_illegal, /* CMPL_PRLI */
2185 lpfc_disc_illegal, /* CMPL_LOGO */
2186 lpfc_disc_illegal, /* CMPL_ADISC */
2187 lpfc_cmpl_reglogin_reglogin_issue,/* CMPL_REG_LOGIN */
2188 lpfc_device_rm_reglogin_issue, /* DEVICE_RM */
2189 lpfc_device_recov_reglogin_issue,/* DEVICE_RECOVERY */
2190
2191 lpfc_rcv_plogi_prli_issue, /* RCV_PLOGI PRLI_ISSUE */
2192 lpfc_rcv_prli_prli_issue, /* RCV_PRLI */
2193 lpfc_rcv_logo_prli_issue, /* RCV_LOGO */
2194 lpfc_rcv_padisc_prli_issue, /* RCV_ADISC */
2195 lpfc_rcv_padisc_prli_issue, /* RCV_PDISC */
2196 lpfc_rcv_prlo_prli_issue, /* RCV_PRLO */
James Smart87af33f2007-10-27 13:37:43 -04002197 lpfc_cmpl_plogi_illegal, /* CMPL_PLOGI */
dea31012005-04-17 16:05:31 -05002198 lpfc_cmpl_prli_prli_issue, /* CMPL_PRLI */
2199 lpfc_disc_illegal, /* CMPL_LOGO */
2200 lpfc_disc_illegal, /* CMPL_ADISC */
2201 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2202 lpfc_device_rm_prli_issue, /* DEVICE_RM */
2203 lpfc_device_recov_prli_issue, /* DEVICE_RECOVERY */
2204
2205 lpfc_rcv_plogi_unmap_node, /* RCV_PLOGI UNMAPPED_NODE */
2206 lpfc_rcv_prli_unmap_node, /* RCV_PRLI */
2207 lpfc_rcv_logo_unmap_node, /* RCV_LOGO */
2208 lpfc_rcv_padisc_unmap_node, /* RCV_ADISC */
2209 lpfc_rcv_padisc_unmap_node, /* RCV_PDISC */
2210 lpfc_rcv_prlo_unmap_node, /* RCV_PRLO */
2211 lpfc_disc_illegal, /* CMPL_PLOGI */
2212 lpfc_disc_illegal, /* CMPL_PRLI */
2213 lpfc_disc_illegal, /* CMPL_LOGO */
2214 lpfc_disc_illegal, /* CMPL_ADISC */
2215 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2216 lpfc_disc_illegal, /* DEVICE_RM */
2217 lpfc_device_recov_unmap_node, /* DEVICE_RECOVERY */
2218
2219 lpfc_rcv_plogi_mapped_node, /* RCV_PLOGI MAPPED_NODE */
2220 lpfc_rcv_prli_mapped_node, /* RCV_PRLI */
2221 lpfc_rcv_logo_mapped_node, /* RCV_LOGO */
2222 lpfc_rcv_padisc_mapped_node, /* RCV_ADISC */
2223 lpfc_rcv_padisc_mapped_node, /* RCV_PDISC */
2224 lpfc_rcv_prlo_mapped_node, /* RCV_PRLO */
2225 lpfc_disc_illegal, /* CMPL_PLOGI */
2226 lpfc_disc_illegal, /* CMPL_PRLI */
2227 lpfc_disc_illegal, /* CMPL_LOGO */
2228 lpfc_disc_illegal, /* CMPL_ADISC */
2229 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2230 lpfc_disc_illegal, /* DEVICE_RM */
2231 lpfc_device_recov_mapped_node, /* DEVICE_RECOVERY */
2232
2233 lpfc_rcv_plogi_npr_node, /* RCV_PLOGI NPR_NODE */
2234 lpfc_rcv_prli_npr_node, /* RCV_PRLI */
2235 lpfc_rcv_logo_npr_node, /* RCV_LOGO */
2236 lpfc_rcv_padisc_npr_node, /* RCV_ADISC */
2237 lpfc_rcv_padisc_npr_node, /* RCV_PDISC */
2238 lpfc_rcv_prlo_npr_node, /* RCV_PRLO */
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002239 lpfc_cmpl_plogi_npr_node, /* CMPL_PLOGI */
2240 lpfc_cmpl_prli_npr_node, /* CMPL_PRLI */
dea31012005-04-17 16:05:31 -05002241 lpfc_cmpl_logo_npr_node, /* CMPL_LOGO */
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002242 lpfc_cmpl_adisc_npr_node, /* CMPL_ADISC */
dea31012005-04-17 16:05:31 -05002243 lpfc_cmpl_reglogin_npr_node, /* CMPL_REG_LOGIN */
2244 lpfc_device_rm_npr_node, /* DEVICE_RM */
2245 lpfc_device_recov_npr_node, /* DEVICE_RECOVERY */
2246};
2247
2248int
James Smart2e0fef82007-06-17 19:56:36 -05002249lpfc_disc_state_machine(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2250 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05002251{
2252 uint32_t cur_state, rc;
James Smart2e0fef82007-06-17 19:56:36 -05002253 uint32_t(*func) (struct lpfc_vport *, struct lpfc_nodelist *, void *,
dea31012005-04-17 16:05:31 -05002254 uint32_t);
James Smarte47c9092008-02-08 18:49:26 -05002255 uint32_t got_ndlp = 0;
dea31012005-04-17 16:05:31 -05002256
James Smarte47c9092008-02-08 18:49:26 -05002257 if (lpfc_nlp_get(ndlp))
2258 got_ndlp = 1;
2259
dea31012005-04-17 16:05:31 -05002260 cur_state = ndlp->nlp_state;
2261
2262 /* DSM in event <evt> on NPort <nlp_DID> in state <cur_state> */
James Smarte8b62012007-08-02 11:10:09 -04002263 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2264 "0211 DSM in event x%x on NPort x%x in "
2265 "state %d Data: x%x\n",
2266 evt, ndlp->nlp_DID, cur_state, ndlp->nlp_flag);
dea31012005-04-17 16:05:31 -05002267
James Smart858c9f62007-06-17 19:56:39 -05002268 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_DSM,
2269 "DSM in: evt:%d ste:%d did:x%x",
2270 evt, cur_state, ndlp->nlp_DID);
2271
dea31012005-04-17 16:05:31 -05002272 func = lpfc_disc_action[(cur_state * NLP_EVT_MAX_EVENT) + evt];
James Smart2e0fef82007-06-17 19:56:36 -05002273 rc = (func) (vport, ndlp, arg, evt);
dea31012005-04-17 16:05:31 -05002274
2275 /* DSM out state <rc> on NPort <nlp_DID> */
James Smarte47c9092008-02-08 18:49:26 -05002276 if (got_ndlp) {
2277 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
James Smarte8b62012007-08-02 11:10:09 -04002278 "0212 DSM out state %d on NPort x%x Data: x%x\n",
2279 rc, ndlp->nlp_DID, ndlp->nlp_flag);
dea31012005-04-17 16:05:31 -05002280
James Smarte47c9092008-02-08 18:49:26 -05002281 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_DSM,
2282 "DSM out: ste:%d did:x%x flg:x%x",
2283 rc, ndlp->nlp_DID, ndlp->nlp_flag);
2284 /* Decrement the ndlp reference count held for this function */
2285 lpfc_nlp_put(ndlp);
2286 } else {
2287 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
James Smartd7c255b2008-08-24 21:50:00 -04002288 "0213 DSM out state %d on NPort free\n", rc);
James Smart858c9f62007-06-17 19:56:39 -05002289
James Smarte47c9092008-02-08 18:49:26 -05002290 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_DSM,
2291 "DSM out: ste:%d did:x%x flg:x%x",
2292 rc, 0, 0);
2293 }
dea31012005-04-17 16:05:31 -05002294
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002295 return rc;
dea31012005-04-17 16:05:31 -05002296}