blob: 0d92d4205ea617908efad357da8ddf3aeb5229ae [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 Wellnitzc9f87352006-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 Wellnitzc9f87352006-02-28 19:25:23 -050058 return 0;
dea31012005-04-17 16:05:31 -050059
60 /* we match, return success */
Jamie Wellnitzc9f87352006-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 Wellnitzc9f87352006-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 Wellnitzc9f87352006-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 Wellnitzc9f87352006-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
James Smart92494142011-02-16 12:39:44 -0500353 /*
354 * Need to unreg_login if we are already in one of these states and
355 * change to NPR state. This will block the port until after the ACC
356 * completes and the reg_login is issued and completed.
357 */
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500358 switch (ndlp->nlp_state) {
dea31012005-04-17 16:05:31 -0500359 case NLP_STE_NPR_NODE:
360 if (!(ndlp->nlp_flag & NLP_NPR_ADISC))
361 break;
362 case NLP_STE_REG_LOGIN_ISSUE:
363 case NLP_STE_PRLI_ISSUE:
364 case NLP_STE_UNMAPPED_NODE:
365 case NLP_STE_MAPPED_NODE:
James Smart92494142011-02-16 12:39:44 -0500366 lpfc_unreg_rpi(vport, ndlp);
367 ndlp->nlp_prev_state = ndlp->nlp_state;
368 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
dea31012005-04-17 16:05:31 -0500369 }
370
James Smart92d7f7b2007-06-17 19:56:38 -0500371 if ((vport->fc_flag & FC_PT2PT) &&
372 !(vport->fc_flag & FC_PT2PT_PLOGI)) {
dea31012005-04-17 16:05:31 -0500373 /* rcv'ed PLOGI decides what our NPortId will be */
James Smart2e0fef82007-06-17 19:56:36 -0500374 vport->fc_myDID = icmd->un.rcvels.parmRo;
dea31012005-04-17 16:05:31 -0500375 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
376 if (mbox == NULL)
377 goto out;
378 lpfc_config_link(phba, mbox);
379 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smarted957682007-06-17 19:56:37 -0500380 mbox->vport = vport;
James Smart0b727fe2007-10-27 13:37:25 -0400381 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
dea31012005-04-17 16:05:31 -0500382 if (rc == MBX_NOT_FINISHED) {
James Smart92d7f7b2007-06-17 19:56:38 -0500383 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -0500384 goto out;
385 }
386
James Smart2e0fef82007-06-17 19:56:36 -0500387 lpfc_can_disctmo(vport);
dea31012005-04-17 16:05:31 -0500388 }
389 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
James Smart2e0fef82007-06-17 19:56:36 -0500390 if (!mbox)
dea31012005-04-17 16:05:31 -0500391 goto out;
392
James Smart6fb120a2009-05-22 14:52:59 -0400393 rc = lpfc_reg_rpi(phba, vport->vpi, icmd->un.rcvels.remoteID,
James Smart40426292010-12-15 17:58:10 -0500394 (uint8_t *) sp, mbox, ndlp->nlp_rpi);
James Smart2e0fef82007-06-17 19:56:36 -0500395 if (rc) {
396 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -0500397 goto out;
398 }
399
400 /* ACC PLOGI rsp command needs to execute first,
401 * queue this mbox command to be processed later.
402 */
403 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
James Smart329f9bc2007-04-25 09:53:01 -0400404 /*
405 * mbox->context2 = lpfc_nlp_get(ndlp) deferred until mailbox
406 * command issued in lpfc_cmpl_els_acc().
407 */
James Smart2e0fef82007-06-17 19:56:36 -0500408 mbox->vport = vport;
409 spin_lock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -0500410 ndlp->nlp_flag |= (NLP_ACC_REGLOGIN | NLP_RCV_PLOGI);
James Smart2e0fef82007-06-17 19:56:36 -0500411 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500412
James Smart33ccf8d2006-08-17 11:57:58 -0400413 /*
414 * If there is an outstanding PLOGI issued, abort it before
415 * sending ACC rsp for received PLOGI. If pending plogi
416 * is not canceled here, the plogi will be rejected by
417 * remote port and will be retried. On a configuration with
418 * single discovery thread, this will cause a huge delay in
419 * discovery. Also this will cause multiple state machines
420 * running in parallel for this node.
421 */
422 if (ndlp->nlp_state == NLP_STE_PLOGI_ISSUE) {
423 /* software abort outstanding PLOGI */
James Smart07951072007-04-25 09:51:38 -0400424 lpfc_els_abort(phba, ndlp);
James Smart33ccf8d2006-08-17 11:57:58 -0400425 }
426
James Smart858c9f62007-06-17 19:56:39 -0500427 if ((vport->port_type == LPFC_NPIV_PORT &&
James Smart3de2a652007-08-02 11:09:59 -0400428 vport->cfg_restrict_login)) {
James Smart858c9f62007-06-17 19:56:39 -0500429
430 /* In order to preserve RPIs, we want to cleanup
431 * the default RPI the firmware created to rcv
432 * this ELS request. The only way to do this is
433 * to register, then unregister the RPI.
434 */
435 spin_lock_irq(shost->host_lock);
436 ndlp->nlp_flag |= NLP_RM_DFLT_RPI;
437 spin_unlock_irq(shost->host_lock);
438 stat.un.b.lsRjtRsnCode = LSRJT_INVALID_CMD;
439 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
440 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb,
441 ndlp, mbox);
442 return 1;
443 }
James Smart51ef4c22007-08-02 11:10:31 -0400444 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp, mbox);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500445 return 1;
dea31012005-04-17 16:05:31 -0500446out:
447 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
448 stat.un.b.lsRjtRsnCodeExp = LSEXP_OUT_OF_RESOURCE;
James Smart858c9f62007-06-17 19:56:39 -0500449 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500450 return 0;
dea31012005-04-17 16:05:31 -0500451}
452
453static int
James Smart2e0fef82007-06-17 19:56:36 -0500454lpfc_rcv_padisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -0500455 struct lpfc_iocbq *cmdiocb)
456{
James Smart2e0fef82007-06-17 19:56:36 -0500457 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -0500458 struct lpfc_dmabuf *pcmd;
James Smart2e0fef82007-06-17 19:56:36 -0500459 struct serv_parm *sp;
460 struct lpfc_name *pnn, *ppn;
dea31012005-04-17 16:05:31 -0500461 struct ls_rjt stat;
462 ADISC *ap;
463 IOCB_t *icmd;
464 uint32_t *lp;
465 uint32_t cmd;
466
467 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
468 lp = (uint32_t *) pcmd->virt;
469
470 cmd = *lp++;
471 if (cmd == ELS_CMD_ADISC) {
472 ap = (ADISC *) lp;
473 pnn = (struct lpfc_name *) & ap->nodeName;
474 ppn = (struct lpfc_name *) & ap->portName;
475 } else {
476 sp = (struct serv_parm *) lp;
477 pnn = (struct lpfc_name *) & sp->nodeName;
478 ppn = (struct lpfc_name *) & sp->portName;
479 }
480
481 icmd = &cmdiocb->iocb;
James Smart2e0fef82007-06-17 19:56:36 -0500482 if (icmd->ulpStatus == 0 && lpfc_check_adisc(vport, ndlp, pnn, ppn)) {
dea31012005-04-17 16:05:31 -0500483 if (cmd == ELS_CMD_ADISC) {
James Smart2e0fef82007-06-17 19:56:36 -0500484 lpfc_els_rsp_adisc_acc(vport, cmdiocb, ndlp);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500485 } else {
James Smart2e0fef82007-06-17 19:56:36 -0500486 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp,
James Smart51ef4c22007-08-02 11:10:31 -0400487 NULL);
dea31012005-04-17 16:05:31 -0500488 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500489 return 1;
dea31012005-04-17 16:05:31 -0500490 }
491 /* Reject this request because invalid parameters */
492 stat.un.b.lsRjtRsvd0 = 0;
493 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
494 stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
495 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -0500496 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -0500497
dea31012005-04-17 16:05:31 -0500498 /* 1 sec timeout */
499 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ);
500
James Smart2e0fef82007-06-17 19:56:36 -0500501 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500502 ndlp->nlp_flag |= NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -0500503 spin_unlock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -0500504 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
505 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -0500506 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500507 return 0;
dea31012005-04-17 16:05:31 -0500508}
509
510static int
James Smart2e0fef82007-06-17 19:56:36 -0500511lpfc_rcv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
512 struct lpfc_iocbq *cmdiocb, uint32_t els_cmd)
dea31012005-04-17 16:05:31 -0500513{
James Smart2e0fef82007-06-17 19:56:36 -0500514 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart4b40c592010-03-15 11:25:44 -0400515 struct lpfc_hba *phba = vport->phba;
516 struct lpfc_vport **vports;
517 int i, active_vlink_present = 0 ;
James Smart2e0fef82007-06-17 19:56:36 -0500518
519 /* Put ndlp in NPR state with 1 sec timeout for plogi, ACC logo */
dea31012005-04-17 16:05:31 -0500520 /* Only call LOGO ACC for first LOGO, this avoids sending unnecessary
521 * PLOGIs during LOGO storms from a device.
522 */
James Smart2e0fef82007-06-17 19:56:36 -0500523 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500524 ndlp->nlp_flag |= NLP_LOGO_ACC;
James Smart2e0fef82007-06-17 19:56:36 -0500525 spin_unlock_irq(shost->host_lock);
James Smart82d9a2a2006-04-15 11:53:05 -0400526 if (els_cmd == ELS_CMD_PRLO)
James Smart51ef4c22007-08-02 11:10:31 -0400527 lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL);
James Smart82d9a2a2006-04-15 11:53:05 -0400528 else
James Smart51ef4c22007-08-02 11:10:31 -0400529 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
James Smart4b40c592010-03-15 11:25:44 -0400530 if (ndlp->nlp_DID == Fabric_DID) {
531 if (vport->port_state <= LPFC_FDISC)
532 goto out;
James Smart6fb120a2009-05-22 14:52:59 -0400533 lpfc_linkdown_port(vport);
James Smart6fb120a2009-05-22 14:52:59 -0400534 spin_lock_irq(shost->host_lock);
James Smart4b40c592010-03-15 11:25:44 -0400535 vport->fc_flag |= FC_VPORT_LOGO_RCVD;
James Smart6fb120a2009-05-22 14:52:59 -0400536 spin_unlock_irq(shost->host_lock);
James Smart4b40c592010-03-15 11:25:44 -0400537 vports = lpfc_create_vport_work_array(phba);
538 if (vports) {
539 for (i = 0; i <= phba->max_vports && vports[i] != NULL;
540 i++) {
541 if ((!(vports[i]->fc_flag &
542 FC_VPORT_LOGO_RCVD)) &&
543 (vports[i]->port_state > LPFC_FDISC)) {
544 active_vlink_present = 1;
545 break;
546 }
547 }
548 lpfc_destroy_vport_work_array(phba, vports);
549 }
dea31012005-04-17 16:05:31 -0500550
James Smart4b40c592010-03-15 11:25:44 -0400551 if (active_vlink_present) {
552 /*
553 * If there are other active VLinks present,
554 * re-instantiate the Vlink using FDISC.
555 */
556 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ);
557 spin_lock_irq(shost->host_lock);
558 ndlp->nlp_flag |= NLP_DELAY_TMO;
559 spin_unlock_irq(shost->host_lock);
560 ndlp->nlp_last_elscmd = ELS_CMD_FDISC;
561 vport->port_state = LPFC_FDISC;
562 } else {
563 spin_lock_irq(shost->host_lock);
564 phba->pport->fc_flag &= ~FC_LOGO_RCVD_DID_CHNG;
565 spin_unlock_irq(shost->host_lock);
566 lpfc_retry_pport_discovery(phba);
567 }
James Smart6fb120a2009-05-22 14:52:59 -0400568 } else if ((!(ndlp->nlp_type & NLP_FABRIC) &&
569 ((ndlp->nlp_type & NLP_FCP_TARGET) ||
570 !(ndlp->nlp_type & NLP_FCP_INITIATOR))) ||
571 (ndlp->nlp_state == NLP_STE_ADISC_ISSUE)) {
dea31012005-04-17 16:05:31 -0500572 /* Only try to re-login if this is NOT a Fabric Node */
dea31012005-04-17 16:05:31 -0500573 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ * 1);
James Smart2e0fef82007-06-17 19:56:36 -0500574 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500575 ndlp->nlp_flag |= NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -0500576 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500577
Jamie Wellnitz5024ab12006-02-28 19:25:28 -0500578 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
dea31012005-04-17 16:05:31 -0500579 }
James Smart4b40c592010-03-15 11:25:44 -0400580out:
James Smart87af33f2007-10-27 13:37:43 -0400581 ndlp->nlp_prev_state = ndlp->nlp_state;
582 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
dea31012005-04-17 16:05:31 -0500583
James Smart2e0fef82007-06-17 19:56:36 -0500584 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500585 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
James Smart2e0fef82007-06-17 19:56:36 -0500586 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500587 /* The driver has to wait until the ACC completes before it continues
588 * processing the LOGO. The action will resume in
589 * lpfc_cmpl_els_logo_acc routine. Since part of processing includes an
590 * unreg_login, the driver waits so the ACC does not get aborted.
591 */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500592 return 0;
dea31012005-04-17 16:05:31 -0500593}
594
595static void
James Smart2e0fef82007-06-17 19:56:36 -0500596lpfc_rcv_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
597 struct lpfc_iocbq *cmdiocb)
dea31012005-04-17 16:05:31 -0500598{
599 struct lpfc_dmabuf *pcmd;
600 uint32_t *lp;
601 PRLI *npr;
602 struct fc_rport *rport = ndlp->rport;
603 u32 roles;
604
605 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
606 lp = (uint32_t *) pcmd->virt;
607 npr = (PRLI *) ((uint8_t *) lp + sizeof (uint32_t));
608
609 ndlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR);
610 ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
James Smart92d7f7b2007-06-17 19:56:38 -0500611 if (npr->prliType == PRLI_FCP_TYPE) {
dea31012005-04-17 16:05:31 -0500612 if (npr->initiatorFunc)
613 ndlp->nlp_type |= NLP_FCP_INITIATOR;
614 if (npr->targetFunc)
615 ndlp->nlp_type |= NLP_FCP_TARGET;
616 if (npr->Retry)
617 ndlp->nlp_fcp_info |= NLP_FCP_2_DEVICE;
618 }
619 if (rport) {
620 /* We need to update the rport role values */
621 roles = FC_RPORT_ROLE_UNKNOWN;
622 if (ndlp->nlp_type & NLP_FCP_INITIATOR)
623 roles |= FC_RPORT_ROLE_FCP_INITIATOR;
624 if (ndlp->nlp_type & NLP_FCP_TARGET)
625 roles |= FC_RPORT_ROLE_FCP_TARGET;
James Smart858c9f62007-06-17 19:56:39 -0500626
627 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
628 "rport rolechg: role:x%x did:x%x flg:x%x",
629 roles, ndlp->nlp_DID, ndlp->nlp_flag);
630
dea31012005-04-17 16:05:31 -0500631 fc_remote_port_rolechg(rport, roles);
632 }
633}
634
635static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -0500636lpfc_disc_set_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -0500637{
James Smart2e0fef82007-06-17 19:56:36 -0500638 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart2e0fef82007-06-17 19:56:36 -0500639
James Smart40426292010-12-15 17:58:10 -0500640 if (!(ndlp->nlp_flag & NLP_RPI_REGISTERED)) {
James Smart51ef4c22007-08-02 11:10:31 -0400641 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
642 return 0;
643 }
644
James Smart1b32f6a2008-02-08 18:49:39 -0500645 if (!(vport->fc_flag & FC_PT2PT)) {
646 /* Check config parameter use-adisc or FCP-2 */
647 if ((vport->cfg_use_adisc && (vport->fc_flag & FC_RSCN_MODE)) ||
James Smartffc95492010-06-07 15:23:17 -0400648 ((ndlp->nlp_fcp_info & NLP_FCP_2_DEVICE) &&
649 (ndlp->nlp_type & NLP_FCP_TARGET))) {
James Smart1b32f6a2008-02-08 18:49:39 -0500650 spin_lock_irq(shost->host_lock);
651 ndlp->nlp_flag |= NLP_NPR_ADISC;
652 spin_unlock_irq(shost->host_lock);
653 return 1;
654 }
James Smart92d7f7b2007-06-17 19:56:38 -0500655 }
656 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
657 lpfc_unreg_rpi(vport, ndlp);
658 return 0;
dea31012005-04-17 16:05:31 -0500659}
James Smart78730cf2010-04-06 15:06:30 -0400660/**
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300661 * lpfc_release_rpi - Release a RPI by issuing unreg_login mailbox cmd.
James Smart78730cf2010-04-06 15:06:30 -0400662 * @phba : Pointer to lpfc_hba structure.
663 * @vport: Pointer to lpfc_vport structure.
664 * @rpi : rpi to be release.
665 *
666 * This function will send a unreg_login mailbox command to the firmware
667 * to release a rpi.
668 **/
669void
670lpfc_release_rpi(struct lpfc_hba *phba,
671 struct lpfc_vport *vport,
672 uint16_t rpi)
673{
674 LPFC_MBOXQ_t *pmb;
675 int rc;
676
677 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
678 GFP_KERNEL);
679 if (!pmb)
680 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
681 "2796 mailbox memory allocation failed \n");
682 else {
683 lpfc_unreg_login(phba, vport->vpi, rpi, pmb);
684 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
685 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
686 if (rc == MBX_NOT_FINISHED)
687 mempool_free(pmb, phba->mbox_mem_pool);
688 }
689}
dea31012005-04-17 16:05:31 -0500690
691static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -0500692lpfc_disc_illegal(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
693 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -0500694{
James Smart78730cf2010-04-06 15:06:30 -0400695 struct lpfc_hba *phba;
696 LPFC_MBOXQ_t *pmb = (LPFC_MBOXQ_t *) arg;
697 MAILBOX_t *mb;
698 uint16_t rpi;
699
700 phba = vport->phba;
701 /* Release the RPI if reglogin completing */
702 if (!(phba->pport->load_flag & FC_UNLOADING) &&
703 (evt == NLP_EVT_CMPL_REG_LOGIN) &&
704 (!pmb->u.mb.mbxStatus)) {
705 mb = &pmb->u.mb;
706 rpi = pmb->u.mb.un.varWords[0];
707 lpfc_release_rpi(phba, vport, rpi);
708 }
James Smarte8b62012007-08-02 11:10:09 -0400709 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
James Smarte47c9092008-02-08 18:49:26 -0500710 "0271 Illegal State Transition: node x%x "
James Smarte8b62012007-08-02 11:10:09 -0400711 "event x%x, state x%x Data: x%x x%x\n",
712 ndlp->nlp_DID, evt, ndlp->nlp_state, ndlp->nlp_rpi,
713 ndlp->nlp_flag);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500714 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -0500715}
716
James Smart87af33f2007-10-27 13:37:43 -0400717static uint32_t
718lpfc_cmpl_plogi_illegal(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
719 void *arg, uint32_t evt)
720{
721 /* This transition is only legal if we previously
722 * rcv'ed a PLOGI. Since we don't want 2 discovery threads
723 * working on the same NPortID, do nothing for this thread
724 * to stop it.
725 */
726 if (!(ndlp->nlp_flag & NLP_RCV_PLOGI)) {
727 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
James Smarte47c9092008-02-08 18:49:26 -0500728 "0272 Illegal State Transition: node x%x "
James Smart87af33f2007-10-27 13:37:43 -0400729 "event x%x, state x%x Data: x%x x%x\n",
730 ndlp->nlp_DID, evt, ndlp->nlp_state, ndlp->nlp_rpi,
731 ndlp->nlp_flag);
732 }
733 return ndlp->nlp_state;
734}
735
dea31012005-04-17 16:05:31 -0500736/* Start of Discovery State Machine routines */
737
738static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -0500739lpfc_rcv_plogi_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
740 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -0500741{
742 struct lpfc_iocbq *cmdiocb;
743
744 cmdiocb = (struct lpfc_iocbq *) arg;
745
James Smart2e0fef82007-06-17 19:56:36 -0500746 if (lpfc_rcv_plogi(vport, ndlp, cmdiocb)) {
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500747 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -0500748 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500749 return NLP_STE_FREED_NODE;
dea31012005-04-17 16:05:31 -0500750}
751
752static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -0500753lpfc_rcv_els_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
754 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -0500755{
James Smart2e0fef82007-06-17 19:56:36 -0500756 lpfc_issue_els_logo(vport, ndlp, 0);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500757 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -0500758}
759
760static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -0500761lpfc_rcv_logo_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
762 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -0500763{
James Smart2e0fef82007-06-17 19:56:36 -0500764 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
765 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -0500766
James Smart2e0fef82007-06-17 19:56:36 -0500767 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500768 ndlp->nlp_flag |= NLP_LOGO_ACC;
James Smart2e0fef82007-06-17 19:56:36 -0500769 spin_unlock_irq(shost->host_lock);
James Smart51ef4c22007-08-02 11:10:31 -0400770 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -0500771
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500772 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -0500773}
774
775static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -0500776lpfc_cmpl_logo_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -0500777 void *arg, uint32_t evt)
778{
James Smart2e0fef82007-06-17 19:56:36 -0500779 return NLP_STE_FREED_NODE;
780}
781
782static uint32_t
783lpfc_device_rm_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
784 void *arg, uint32_t evt)
785{
James Smart2e0fef82007-06-17 19:56:36 -0500786 return NLP_STE_FREED_NODE;
787}
788
789static uint32_t
790lpfc_rcv_plogi_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
791 void *arg, uint32_t evt)
792{
James Smart0d2b6b82008-06-14 22:52:47 -0400793 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart2e0fef82007-06-17 19:56:36 -0500794 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500795 struct lpfc_iocbq *cmdiocb = arg;
James Smart2e0fef82007-06-17 19:56:36 -0500796 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
797 uint32_t *lp = (uint32_t *) pcmd->virt;
798 struct serv_parm *sp = (struct serv_parm *) (lp + 1);
dea31012005-04-17 16:05:31 -0500799 struct ls_rjt stat;
800 int port_cmp;
801
dea31012005-04-17 16:05:31 -0500802 memset(&stat, 0, sizeof (struct ls_rjt));
803
804 /* For a PLOGI, we only accept if our portname is less
805 * than the remote portname.
806 */
807 phba->fc_stat.elsLogiCol++;
James Smart2e0fef82007-06-17 19:56:36 -0500808 port_cmp = memcmp(&vport->fc_portname, &sp->portName,
James Smart92d7f7b2007-06-17 19:56:38 -0500809 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -0500810
811 if (port_cmp >= 0) {
812 /* Reject this request because the remote node will accept
813 ours */
814 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
815 stat.un.b.lsRjtRsnCodeExp = LSEXP_CMD_IN_PROGRESS;
James Smart858c9f62007-06-17 19:56:39 -0500816 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
817 NULL);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500818 } else {
James Smart0d2b6b82008-06-14 22:52:47 -0400819 if (lpfc_rcv_plogi(vport, ndlp, cmdiocb) &&
820 (ndlp->nlp_flag & NLP_NPR_2B_DISC) &&
821 (vport->num_disc_nodes)) {
822 spin_lock_irq(shost->host_lock);
823 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
824 spin_unlock_irq(shost->host_lock);
825 /* Check if there are more PLOGIs to be sent */
826 lpfc_more_plogi(vport);
827 if (vport->num_disc_nodes == 0) {
828 spin_lock_irq(shost->host_lock);
829 vport->fc_flag &= ~FC_NDISC_ACTIVE;
830 spin_unlock_irq(shost->host_lock);
831 lpfc_can_disctmo(vport);
832 lpfc_end_rscn(vport);
833 }
834 }
James Smart2e0fef82007-06-17 19:56:36 -0500835 } /* If our portname was less */
dea31012005-04-17 16:05:31 -0500836
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500837 return ndlp->nlp_state;
838}
839
840static uint32_t
James Smart92d7f7b2007-06-17 19:56:38 -0500841lpfc_rcv_prli_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
842 void *arg, uint32_t evt)
843{
844 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
845 struct ls_rjt stat;
846
847 memset(&stat, 0, sizeof (struct ls_rjt));
848 stat.un.b.lsRjtRsnCode = LSRJT_LOGICAL_BSY;
849 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
James Smart858c9f62007-06-17 19:56:39 -0500850 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
James Smart92d7f7b2007-06-17 19:56:38 -0500851 return ndlp->nlp_state;
852}
853
854static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -0500855lpfc_rcv_logo_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
856 void *arg, uint32_t evt)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500857{
James Smart2e0fef82007-06-17 19:56:36 -0500858 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500859
James Smart92d7f7b2007-06-17 19:56:38 -0500860 /* software abort outstanding PLOGI */
James Smart2e0fef82007-06-17 19:56:36 -0500861 lpfc_els_abort(vport->phba, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500862
James Smart2e0fef82007-06-17 19:56:36 -0500863 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500864 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -0500865}
866
867static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -0500868lpfc_rcv_els_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
869 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -0500870{
James Smart2e0fef82007-06-17 19:56:36 -0500871 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
872 struct lpfc_hba *phba = vport->phba;
873 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -0500874
875 /* software abort outstanding PLOGI */
James Smart07951072007-04-25 09:51:38 -0400876 lpfc_els_abort(phba, ndlp);
dea31012005-04-17 16:05:31 -0500877
878 if (evt == NLP_EVT_RCV_LOGO) {
James Smart51ef4c22007-08-02 11:10:31 -0400879 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500880 } else {
James Smart2e0fef82007-06-17 19:56:36 -0500881 lpfc_issue_els_logo(vport, ndlp, 0);
dea31012005-04-17 16:05:31 -0500882 }
883
James Smart2e0fef82007-06-17 19:56:36 -0500884 /* Put ndlp in npr state set plogi timer for 1 sec */
Jamie Wellnitz5024ab12006-02-28 19:25:28 -0500885 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ * 1);
James Smart2e0fef82007-06-17 19:56:36 -0500886 spin_lock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -0500887 ndlp->nlp_flag |= NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -0500888 spin_unlock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -0500889 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
890 ndlp->nlp_prev_state = NLP_STE_PLOGI_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -0500891 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
dea31012005-04-17 16:05:31 -0500892
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500893 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -0500894}
895
896static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -0500897lpfc_cmpl_plogi_plogi_issue(struct lpfc_vport *vport,
898 struct lpfc_nodelist *ndlp,
899 void *arg,
dea31012005-04-17 16:05:31 -0500900 uint32_t evt)
901{
James Smart2e0fef82007-06-17 19:56:36 -0500902 struct lpfc_hba *phba = vport->phba;
James Smart0ff10d42008-01-11 01:52:36 -0500903 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart2e0fef82007-06-17 19:56:36 -0500904 struct lpfc_iocbq *cmdiocb, *rspiocb;
James Smart14691152006-12-02 13:34:28 -0500905 struct lpfc_dmabuf *pcmd, *prsp, *mp;
dea31012005-04-17 16:05:31 -0500906 uint32_t *lp;
907 IOCB_t *irsp;
908 struct serv_parm *sp;
909 LPFC_MBOXQ_t *mbox;
910
911 cmdiocb = (struct lpfc_iocbq *) arg;
912 rspiocb = cmdiocb->context_un.rsp_iocb;
913
914 if (ndlp->nlp_flag & NLP_ACC_REGLOGIN) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -0500915 /* Recovery from PLOGI collision logic */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500916 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -0500917 }
918
919 irsp = &rspiocb->iocb;
920
921 if (irsp->ulpStatus)
922 goto out;
923
924 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
925
James Smart2e0fef82007-06-17 19:56:36 -0500926 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
dea31012005-04-17 16:05:31 -0500927
James Smart2e0fef82007-06-17 19:56:36 -0500928 lp = (uint32_t *) prsp->virt;
dea31012005-04-17 16:05:31 -0500929 sp = (struct serv_parm *) ((uint8_t *) lp + sizeof (uint32_t));
James Smart58da1ff2008-04-07 10:15:56 -0400930
931 /* Some switches have FDMI servers returning 0 for WWN */
932 if ((ndlp->nlp_DID != FDMI_DID) &&
933 (wwn_to_u64(sp->portName.u.wwn) == 0 ||
934 wwn_to_u64(sp->nodeName.u.wwn) == 0)) {
James Smarta8adb832007-10-27 13:37:53 -0400935 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
936 "0142 PLOGI RSP: Invalid WWN.\n");
937 goto out;
938 }
James Smart341af102010-01-26 23:07:37 -0500939 if (!lpfc_check_sparm(vport, ndlp, sp, CLASS3, 0))
dea31012005-04-17 16:05:31 -0500940 goto out;
dea31012005-04-17 16:05:31 -0500941 /* PLOGI chkparm OK */
James Smarte8b62012007-08-02 11:10:09 -0400942 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
943 "0121 PLOGI chkparm OK Data: x%x x%x x%x x%x\n",
944 ndlp->nlp_DID, ndlp->nlp_state,
945 ndlp->nlp_flag, ndlp->nlp_rpi);
James Smart3de2a652007-08-02 11:09:59 -0400946 if (vport->cfg_fcp_class == 2 && (sp->cls2.classValid))
dea31012005-04-17 16:05:31 -0500947 ndlp->nlp_fcp_info |= CLASS2;
James Smart2e0fef82007-06-17 19:56:36 -0500948 else
dea31012005-04-17 16:05:31 -0500949 ndlp->nlp_fcp_info |= CLASS3;
James Smart2e0fef82007-06-17 19:56:36 -0500950
dea31012005-04-17 16:05:31 -0500951 ndlp->nlp_class_sup = 0;
952 if (sp->cls1.classValid)
953 ndlp->nlp_class_sup |= FC_COS_CLASS1;
954 if (sp->cls2.classValid)
955 ndlp->nlp_class_sup |= FC_COS_CLASS2;
956 if (sp->cls3.classValid)
957 ndlp->nlp_class_sup |= FC_COS_CLASS3;
958 if (sp->cls4.classValid)
959 ndlp->nlp_class_sup |= FC_COS_CLASS4;
960 ndlp->nlp_maxframe =
James Smart2e0fef82007-06-17 19:56:36 -0500961 ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) | sp->cmn.bbRcvSizeLsb;
dea31012005-04-17 16:05:31 -0500962
James Smart2e0fef82007-06-17 19:56:36 -0500963 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
James Smart92d7f7b2007-06-17 19:56:38 -0500964 if (!mbox) {
James Smarte8b62012007-08-02 11:10:09 -0400965 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
966 "0133 PLOGI: no memory for reg_login "
James Smart92d7f7b2007-06-17 19:56:38 -0500967 "Data: x%x x%x x%x x%x\n",
James Smart92d7f7b2007-06-17 19:56:38 -0500968 ndlp->nlp_DID, ndlp->nlp_state,
969 ndlp->nlp_flag, ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -0500970 goto out;
James Smart92d7f7b2007-06-17 19:56:38 -0500971 }
dea31012005-04-17 16:05:31 -0500972
James Smart2e0fef82007-06-17 19:56:36 -0500973 lpfc_unreg_rpi(vport, ndlp);
974
James Smart6fb120a2009-05-22 14:52:59 -0400975 if (lpfc_reg_rpi(phba, vport->vpi, irsp->un.elsreq64.remoteID,
James Smart40426292010-12-15 17:58:10 -0500976 (uint8_t *) sp, mbox, ndlp->nlp_rpi) == 0) {
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500977 switch (ndlp->nlp_DID) {
dea31012005-04-17 16:05:31 -0500978 case NameServer_DID:
James Smartde0c5b32007-04-25 09:52:27 -0400979 mbox->mbox_cmpl = lpfc_mbx_cmpl_ns_reg_login;
dea31012005-04-17 16:05:31 -0500980 break;
981 case FDMI_DID:
James Smartde0c5b32007-04-25 09:52:27 -0400982 mbox->mbox_cmpl = lpfc_mbx_cmpl_fdmi_reg_login;
dea31012005-04-17 16:05:31 -0500983 break;
984 default:
James Smartffc95492010-06-07 15:23:17 -0400985 ndlp->nlp_flag |= NLP_REG_LOGIN_SEND;
James Smartde0c5b32007-04-25 09:52:27 -0400986 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
dea31012005-04-17 16:05:31 -0500987 }
James Smart329f9bc2007-04-25 09:53:01 -0400988 mbox->context2 = lpfc_nlp_get(ndlp);
James Smart2e0fef82007-06-17 19:56:36 -0500989 mbox->vport = vport;
James Smart0b727fe2007-10-27 13:37:25 -0400990 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
dea31012005-04-17 16:05:31 -0500991 != MBX_NOT_FINISHED) {
James Smart2e0fef82007-06-17 19:56:36 -0500992 lpfc_nlp_set_state(vport, ndlp,
993 NLP_STE_REG_LOGIN_ISSUE);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500994 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -0500995 }
James Smartffc95492010-06-07 15:23:17 -0400996 if (ndlp->nlp_flag & NLP_REG_LOGIN_SEND)
997 ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND;
James Smartfa4066b2008-01-11 01:53:27 -0500998 /* decrement node reference count to the failed mbox
999 * command
1000 */
James Smart329f9bc2007-04-25 09:53:01 -04001001 lpfc_nlp_put(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05001002 mp = (struct lpfc_dmabuf *) mbox->context1;
James Smart14691152006-12-02 13:34:28 -05001003 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1004 kfree(mp);
dea31012005-04-17 16:05:31 -05001005 mempool_free(mbox, phba->mbox_mem_pool);
James Smart92d7f7b2007-06-17 19:56:38 -05001006
James Smarte8b62012007-08-02 11:10:09 -04001007 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1008 "0134 PLOGI: cannot issue reg_login "
1009 "Data: x%x x%x x%x x%x\n",
1010 ndlp->nlp_DID, ndlp->nlp_state,
1011 ndlp->nlp_flag, ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05001012 } else {
1013 mempool_free(mbox, phba->mbox_mem_pool);
James Smart92d7f7b2007-06-17 19:56:38 -05001014
James Smarte8b62012007-08-02 11:10:09 -04001015 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1016 "0135 PLOGI: cannot format reg_login "
1017 "Data: x%x x%x x%x x%x\n",
1018 ndlp->nlp_DID, ndlp->nlp_state,
1019 ndlp->nlp_flag, ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05001020 }
1021
1022
James Smart92d7f7b2007-06-17 19:56:38 -05001023out:
1024 if (ndlp->nlp_DID == NameServer_DID) {
1025 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04001026 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1027 "0261 Cannot Register NameServer login\n");
James Smart92d7f7b2007-06-17 19:56:38 -05001028 }
1029
James Smart0ff10d42008-01-11 01:52:36 -05001030 spin_lock_irq(shost->host_lock);
James Smarta8adb832007-10-27 13:37:53 -04001031 ndlp->nlp_flag |= NLP_DEFER_RM;
James Smart0ff10d42008-01-11 01:52:36 -05001032 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001033 return NLP_STE_FREED_NODE;
dea31012005-04-17 16:05:31 -05001034}
1035
1036static uint32_t
James Smart0ff10d42008-01-11 01:52:36 -05001037lpfc_cmpl_logo_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1038 void *arg, uint32_t evt)
1039{
1040 return ndlp->nlp_state;
1041}
1042
1043static uint32_t
1044lpfc_cmpl_reglogin_plogi_issue(struct lpfc_vport *vport,
1045 struct lpfc_nodelist *ndlp, void *arg, uint32_t evt)
1046{
James Smart78730cf2010-04-06 15:06:30 -04001047 struct lpfc_hba *phba;
1048 LPFC_MBOXQ_t *pmb = (LPFC_MBOXQ_t *) arg;
1049 MAILBOX_t *mb = &pmb->u.mb;
1050 uint16_t rpi;
1051
1052 phba = vport->phba;
1053 /* Release the RPI */
1054 if (!(phba->pport->load_flag & FC_UNLOADING) &&
1055 !mb->mbxStatus) {
1056 rpi = pmb->u.mb.un.varWords[0];
1057 lpfc_release_rpi(phba, vport, rpi);
1058 }
James Smart0ff10d42008-01-11 01:52:36 -05001059 return ndlp->nlp_state;
1060}
1061
1062static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001063lpfc_device_rm_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1064 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001065{
James Smart2e0fef82007-06-17 19:56:36 -05001066 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001067
James Smart2e0fef82007-06-17 19:56:36 -05001068 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1069 spin_lock_irq(shost->host_lock);
1070 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
1071 spin_unlock_irq(shost->host_lock);
1072 return ndlp->nlp_state;
1073 } else {
1074 /* software abort outstanding PLOGI */
1075 lpfc_els_abort(vport->phba, ndlp);
1076
1077 lpfc_drop_node(vport, ndlp);
James Smarta0f9b482006-04-15 11:52:56 -04001078 return NLP_STE_FREED_NODE;
1079 }
dea31012005-04-17 16:05:31 -05001080}
1081
1082static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001083lpfc_device_recov_plogi_issue(struct lpfc_vport *vport,
1084 struct lpfc_nodelist *ndlp,
1085 void *arg,
1086 uint32_t evt)
dea31012005-04-17 16:05:31 -05001087{
James Smart2e0fef82007-06-17 19:56:36 -05001088 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1089 struct lpfc_hba *phba = vport->phba;
1090
James Smart92d7f7b2007-06-17 19:56:38 -05001091 /* Don't do anything that will mess up processing of the
1092 * previous RSCN.
1093 */
1094 if (vport->fc_flag & FC_RSCN_DEFERRED)
1095 return ndlp->nlp_state;
1096
dea31012005-04-17 16:05:31 -05001097 /* software abort outstanding PLOGI */
James Smart07951072007-04-25 09:51:38 -04001098 lpfc_els_abort(phba, ndlp);
dea31012005-04-17 16:05:31 -05001099
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001100 ndlp->nlp_prev_state = NLP_STE_PLOGI_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -05001101 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
James Smart92d7f7b2007-06-17 19:56:38 -05001102 spin_lock_irq(shost->host_lock);
James Smarta0f9b482006-04-15 11:52:56 -04001103 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
James Smart2e0fef82007-06-17 19:56:36 -05001104 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001105
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001106 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001107}
1108
1109static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001110lpfc_rcv_plogi_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1111 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001112{
James Smart0d2b6b82008-06-14 22:52:47 -04001113 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart2e0fef82007-06-17 19:56:36 -05001114 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001115 struct lpfc_iocbq *cmdiocb;
1116
1117 /* software abort outstanding ADISC */
James Smart07951072007-04-25 09:51:38 -04001118 lpfc_els_abort(phba, ndlp);
dea31012005-04-17 16:05:31 -05001119
1120 cmdiocb = (struct lpfc_iocbq *) arg;
1121
James Smart0d2b6b82008-06-14 22:52:47 -04001122 if (lpfc_rcv_plogi(vport, ndlp, cmdiocb)) {
1123 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1124 spin_lock_irq(shost->host_lock);
1125 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
1126 spin_unlock_irq(shost->host_lock);
James Smart90160e02008-08-24 21:49:45 -04001127 if (vport->num_disc_nodes)
James Smart0d2b6b82008-06-14 22:52:47 -04001128 lpfc_more_adisc(vport);
James Smart0d2b6b82008-06-14 22:52:47 -04001129 }
1130 return ndlp->nlp_state;
1131 }
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001132 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -05001133 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
1134 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
dea31012005-04-17 16:05:31 -05001135
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001136 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001137}
1138
1139static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001140lpfc_rcv_prli_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1141 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001142{
James Smart2e0fef82007-06-17 19:56:36 -05001143 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001144
James Smart2e0fef82007-06-17 19:56:36 -05001145 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001146 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001147}
1148
1149static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001150lpfc_rcv_logo_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1151 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001152{
James Smart2e0fef82007-06-17 19:56:36 -05001153 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001154 struct lpfc_iocbq *cmdiocb;
1155
1156 cmdiocb = (struct lpfc_iocbq *) arg;
1157
1158 /* software abort outstanding ADISC */
James Smart07951072007-04-25 09:51:38 -04001159 lpfc_els_abort(phba, ndlp);
dea31012005-04-17 16:05:31 -05001160
James Smart2e0fef82007-06-17 19:56:36 -05001161 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001162 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001163}
1164
1165static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001166lpfc_rcv_padisc_adisc_issue(struct lpfc_vport *vport,
1167 struct lpfc_nodelist *ndlp,
1168 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001169{
1170 struct lpfc_iocbq *cmdiocb;
1171
1172 cmdiocb = (struct lpfc_iocbq *) arg;
1173
James Smart2e0fef82007-06-17 19:56:36 -05001174 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001175 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001176}
1177
1178static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001179lpfc_rcv_prlo_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1180 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001181{
1182 struct lpfc_iocbq *cmdiocb;
1183
1184 cmdiocb = (struct lpfc_iocbq *) arg;
1185
1186 /* Treat like rcv logo */
James Smart2e0fef82007-06-17 19:56:36 -05001187 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_PRLO);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001188 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001189}
1190
1191static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001192lpfc_cmpl_adisc_adisc_issue(struct lpfc_vport *vport,
1193 struct lpfc_nodelist *ndlp,
1194 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001195{
James Smart2e0fef82007-06-17 19:56:36 -05001196 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1197 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001198 struct lpfc_iocbq *cmdiocb, *rspiocb;
1199 IOCB_t *irsp;
1200 ADISC *ap;
James Smart6fb120a2009-05-22 14:52:59 -04001201 int rc;
dea31012005-04-17 16:05:31 -05001202
1203 cmdiocb = (struct lpfc_iocbq *) arg;
1204 rspiocb = cmdiocb->context_un.rsp_iocb;
1205
1206 ap = (ADISC *)lpfc_check_elscmpl_iocb(phba, cmdiocb, rspiocb);
1207 irsp = &rspiocb->iocb;
1208
1209 if ((irsp->ulpStatus) ||
James Smart92d7f7b2007-06-17 19:56:38 -05001210 (!lpfc_check_adisc(vport, ndlp, &ap->nodeName, &ap->portName))) {
dea31012005-04-17 16:05:31 -05001211 /* 1 sec timeout */
1212 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ);
James Smart2e0fef82007-06-17 19:56:36 -05001213 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001214 ndlp->nlp_flag |= NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05001215 spin_unlock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001216 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
dea31012005-04-17 16:05:31 -05001217
James Smart2e0fef82007-06-17 19:56:36 -05001218 memset(&ndlp->nlp_nodename, 0, sizeof(struct lpfc_name));
1219 memset(&ndlp->nlp_portname, 0, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05001220
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001221 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -05001222 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1223 lpfc_unreg_rpi(vport, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001224 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001225 }
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001226
James Smart6fb120a2009-05-22 14:52:59 -04001227 if (phba->sli_rev == LPFC_SLI_REV4) {
1228 rc = lpfc_sli4_resume_rpi(ndlp);
1229 if (rc) {
1230 /* Stay in state and retry. */
1231 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
1232 return ndlp->nlp_state;
1233 }
1234 }
1235
James.Smart@Emulex.Com25013222005-06-25 10:34:33 -04001236 if (ndlp->nlp_type & NLP_FCP_TARGET) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001237 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -05001238 lpfc_nlp_set_state(vport, ndlp, NLP_STE_MAPPED_NODE);
James.Smart@Emulex.Com25013222005-06-25 10:34:33 -04001239 } else {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001240 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -05001241 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
James.Smart@Emulex.Com25013222005-06-25 10:34:33 -04001242 }
James Smart6fb120a2009-05-22 14:52:59 -04001243
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001244 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001245}
1246
1247static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001248lpfc_device_rm_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1249 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001250{
James Smart2e0fef82007-06-17 19:56:36 -05001251 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001252
James Smart2e0fef82007-06-17 19:56:36 -05001253 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1254 spin_lock_irq(shost->host_lock);
1255 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
1256 spin_unlock_irq(shost->host_lock);
1257 return ndlp->nlp_state;
1258 } else {
1259 /* software abort outstanding ADISC */
1260 lpfc_els_abort(vport->phba, ndlp);
1261
1262 lpfc_drop_node(vport, ndlp);
James Smarta0f9b482006-04-15 11:52:56 -04001263 return NLP_STE_FREED_NODE;
1264 }
dea31012005-04-17 16:05:31 -05001265}
1266
1267static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001268lpfc_device_recov_adisc_issue(struct lpfc_vport *vport,
1269 struct lpfc_nodelist *ndlp,
1270 void *arg,
1271 uint32_t evt)
dea31012005-04-17 16:05:31 -05001272{
James Smart2e0fef82007-06-17 19:56:36 -05001273 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1274 struct lpfc_hba *phba = vport->phba;
1275
James Smart92d7f7b2007-06-17 19:56:38 -05001276 /* Don't do anything that will mess up processing of the
1277 * previous RSCN.
1278 */
1279 if (vport->fc_flag & FC_RSCN_DEFERRED)
1280 return ndlp->nlp_state;
1281
dea31012005-04-17 16:05:31 -05001282 /* software abort outstanding ADISC */
James Smart07951072007-04-25 09:51:38 -04001283 lpfc_els_abort(phba, ndlp);
dea31012005-04-17 16:05:31 -05001284
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001285 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -05001286 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1287 spin_lock_irq(shost->host_lock);
James Smarta0f9b482006-04-15 11:52:56 -04001288 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
James Smart2e0fef82007-06-17 19:56:36 -05001289 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05001290 lpfc_disc_set_adisc(vport, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001291 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001292}
1293
1294static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001295lpfc_rcv_plogi_reglogin_issue(struct lpfc_vport *vport,
1296 struct lpfc_nodelist *ndlp,
1297 void *arg,
dea31012005-04-17 16:05:31 -05001298 uint32_t evt)
1299{
James Smart2e0fef82007-06-17 19:56:36 -05001300 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001301
James Smart2e0fef82007-06-17 19:56:36 -05001302 lpfc_rcv_plogi(vport, ndlp, cmdiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001303 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001304}
1305
1306static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001307lpfc_rcv_prli_reglogin_issue(struct lpfc_vport *vport,
1308 struct lpfc_nodelist *ndlp,
1309 void *arg,
dea31012005-04-17 16:05:31 -05001310 uint32_t evt)
1311{
James Smart2e0fef82007-06-17 19:56:36 -05001312 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001313
James Smart2e0fef82007-06-17 19:56:36 -05001314 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001315 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001316}
1317
1318static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001319lpfc_rcv_logo_reglogin_issue(struct lpfc_vport *vport,
1320 struct lpfc_nodelist *ndlp,
1321 void *arg,
dea31012005-04-17 16:05:31 -05001322 uint32_t evt)
1323{
James Smart2e0fef82007-06-17 19:56:36 -05001324 struct lpfc_hba *phba = vport->phba;
1325 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
James Smart7054a602007-04-25 09:52:34 -04001326 LPFC_MBOXQ_t *mb;
1327 LPFC_MBOXQ_t *nextmb;
1328 struct lpfc_dmabuf *mp;
dea31012005-04-17 16:05:31 -05001329
1330 cmdiocb = (struct lpfc_iocbq *) arg;
1331
James Smart7054a602007-04-25 09:52:34 -04001332 /* cleanup any ndlp on mbox q waiting for reglogin cmpl */
1333 if ((mb = phba->sli.mbox_active)) {
James Smart04c68492009-05-22 14:52:52 -04001334 if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) &&
James Smart7054a602007-04-25 09:52:34 -04001335 (ndlp == (struct lpfc_nodelist *) mb->context2)) {
James Smart92d7f7b2007-06-17 19:56:38 -05001336 lpfc_nlp_put(ndlp);
James Smart7054a602007-04-25 09:52:34 -04001337 mb->context2 = NULL;
1338 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1339 }
1340 }
1341
James Smart2e0fef82007-06-17 19:56:36 -05001342 spin_lock_irq(&phba->hbalock);
James Smart7054a602007-04-25 09:52:34 -04001343 list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) {
James Smart04c68492009-05-22 14:52:52 -04001344 if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) &&
James Smart7054a602007-04-25 09:52:34 -04001345 (ndlp == (struct lpfc_nodelist *) mb->context2)) {
1346 mp = (struct lpfc_dmabuf *) (mb->context1);
1347 if (mp) {
James Smart98c9ea52007-10-27 13:37:33 -04001348 __lpfc_mbuf_free(phba, mp->virt, mp->phys);
James Smart7054a602007-04-25 09:52:34 -04001349 kfree(mp);
1350 }
James Smart92d7f7b2007-06-17 19:56:38 -05001351 lpfc_nlp_put(ndlp);
James Smart7054a602007-04-25 09:52:34 -04001352 list_del(&mb->list);
James Smart5ffc2662009-11-18 15:39:44 -05001353 phba->sli.mboxq_cnt--;
James Smart7054a602007-04-25 09:52:34 -04001354 mempool_free(mb, phba->mbox_mem_pool);
1355 }
1356 }
James Smart2e0fef82007-06-17 19:56:36 -05001357 spin_unlock_irq(&phba->hbalock);
James Smart7054a602007-04-25 09:52:34 -04001358
James Smart2e0fef82007-06-17 19:56:36 -05001359 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001360 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001361}
1362
1363static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001364lpfc_rcv_padisc_reglogin_issue(struct lpfc_vport *vport,
1365 struct lpfc_nodelist *ndlp,
1366 void *arg,
dea31012005-04-17 16:05:31 -05001367 uint32_t evt)
1368{
James Smart2e0fef82007-06-17 19:56:36 -05001369 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001370
James Smart2e0fef82007-06-17 19:56:36 -05001371 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001372 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001373}
1374
1375static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001376lpfc_rcv_prlo_reglogin_issue(struct lpfc_vport *vport,
1377 struct lpfc_nodelist *ndlp,
1378 void *arg,
dea31012005-04-17 16:05:31 -05001379 uint32_t evt)
1380{
1381 struct lpfc_iocbq *cmdiocb;
1382
1383 cmdiocb = (struct lpfc_iocbq *) arg;
James Smart51ef4c22007-08-02 11:10:31 -04001384 lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001385 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001386}
1387
1388static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001389lpfc_cmpl_reglogin_reglogin_issue(struct lpfc_vport *vport,
1390 struct lpfc_nodelist *ndlp,
1391 void *arg,
1392 uint32_t evt)
dea31012005-04-17 16:05:31 -05001393{
James Smart2e0fef82007-06-17 19:56:36 -05001394 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart2e0fef82007-06-17 19:56:36 -05001395 LPFC_MBOXQ_t *pmb = (LPFC_MBOXQ_t *) arg;
James Smart04c68492009-05-22 14:52:52 -04001396 MAILBOX_t *mb = &pmb->u.mb;
James Smart2e0fef82007-06-17 19:56:36 -05001397 uint32_t did = mb->un.varWords[1];
dea31012005-04-17 16:05:31 -05001398
dea31012005-04-17 16:05:31 -05001399 if (mb->mbxStatus) {
1400 /* RegLogin failed */
James Smarte8b62012007-08-02 11:10:09 -04001401 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
1402 "0246 RegLogin failed Data: x%x x%x x%x\n",
James Smart2e0fef82007-06-17 19:56:36 -05001403 did, mb->mbxStatus, vport->port_state);
James Smartd0e56da2006-07-06 15:49:42 -04001404 /*
1405 * If RegLogin failed due to lack of HBA resources do not
1406 * retry discovery.
1407 */
1408 if (mb->mbxStatus == MBXERR_RPI_FULL) {
James Smart87af33f2007-10-27 13:37:43 -04001409 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
1410 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
James Smartd0e56da2006-07-06 15:49:42 -04001411 return ndlp->nlp_state;
1412 }
1413
James Smart2e0fef82007-06-17 19:56:36 -05001414 /* Put ndlp in npr state set plogi timer for 1 sec */
dea31012005-04-17 16:05:31 -05001415 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ * 1);
James Smart2e0fef82007-06-17 19:56:36 -05001416 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001417 ndlp->nlp_flag |= NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05001418 spin_unlock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001419 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
dea31012005-04-17 16:05:31 -05001420
James Smart2e0fef82007-06-17 19:56:36 -05001421 lpfc_issue_els_logo(vport, ndlp, 0);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001422 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -05001423 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001424 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001425 }
1426
dea31012005-04-17 16:05:31 -05001427 ndlp->nlp_rpi = mb->un.varWords[0];
James Smart40426292010-12-15 17:58:10 -05001428 ndlp->nlp_flag |= NLP_RPI_REGISTERED;
dea31012005-04-17 16:05:31 -05001429
1430 /* Only if we are not a fabric nport do we issue PRLI */
1431 if (!(ndlp->nlp_type & NLP_FABRIC)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001432 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -05001433 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
1434 lpfc_issue_els_prli(vport, ndlp, 0);
dea31012005-04-17 16:05:31 -05001435 } else {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001436 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -05001437 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
dea31012005-04-17 16:05:31 -05001438 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001439 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001440}
1441
1442static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001443lpfc_device_rm_reglogin_issue(struct lpfc_vport *vport,
1444 struct lpfc_nodelist *ndlp,
1445 void *arg,
dea31012005-04-17 16:05:31 -05001446 uint32_t evt)
1447{
James Smart2e0fef82007-06-17 19:56:36 -05001448 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1449
1450 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1451 spin_lock_irq(shost->host_lock);
James Smarta0f9b482006-04-15 11:52:56 -04001452 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
James Smart2e0fef82007-06-17 19:56:36 -05001453 spin_unlock_irq(shost->host_lock);
James Smarta0f9b482006-04-15 11:52:56 -04001454 return ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05001455 } else {
1456 lpfc_drop_node(vport, ndlp);
James Smarta0f9b482006-04-15 11:52:56 -04001457 return NLP_STE_FREED_NODE;
1458 }
dea31012005-04-17 16:05:31 -05001459}
1460
1461static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001462lpfc_device_recov_reglogin_issue(struct lpfc_vport *vport,
1463 struct lpfc_nodelist *ndlp,
1464 void *arg,
1465 uint32_t evt)
dea31012005-04-17 16:05:31 -05001466{
James Smart2e0fef82007-06-17 19:56:36 -05001467 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1468
James Smart92d7f7b2007-06-17 19:56:38 -05001469 /* Don't do anything that will mess up processing of the
1470 * previous RSCN.
1471 */
1472 if (vport->fc_flag & FC_RSCN_DEFERRED)
1473 return ndlp->nlp_state;
1474
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001475 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -05001476 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1477 spin_lock_irq(shost->host_lock);
James Smartffc95492010-06-07 15:23:17 -04001478 ndlp->nlp_flag |= NLP_IGNR_REG_CMPL;
James Smarta0f9b482006-04-15 11:52:56 -04001479 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
James Smart2e0fef82007-06-17 19:56:36 -05001480 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05001481 lpfc_disc_set_adisc(vport, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001482 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001483}
1484
1485static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001486lpfc_rcv_plogi_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1487 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001488{
1489 struct lpfc_iocbq *cmdiocb;
1490
1491 cmdiocb = (struct lpfc_iocbq *) arg;
1492
James Smart2e0fef82007-06-17 19:56:36 -05001493 lpfc_rcv_plogi(vport, ndlp, cmdiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001494 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001495}
1496
1497static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001498lpfc_rcv_prli_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1499 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001500{
James Smart2e0fef82007-06-17 19:56:36 -05001501 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001502
James Smart2e0fef82007-06-17 19:56:36 -05001503 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001504 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001505}
1506
1507static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001508lpfc_rcv_logo_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1509 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001510{
James Smart2e0fef82007-06-17 19:56:36 -05001511 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001512
1513 /* Software abort outstanding PRLI before sending acc */
James Smart2e0fef82007-06-17 19:56:36 -05001514 lpfc_els_abort(vport->phba, ndlp);
dea31012005-04-17 16:05:31 -05001515
James Smart2e0fef82007-06-17 19:56:36 -05001516 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001517 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001518}
1519
1520static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001521lpfc_rcv_padisc_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1522 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001523{
James Smart2e0fef82007-06-17 19:56:36 -05001524 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001525
James Smart2e0fef82007-06-17 19:56:36 -05001526 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001527 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001528}
1529
1530/* This routine is envoked when we rcv a PRLO request from a nport
1531 * we are logged into. We should send back a PRLO rsp setting the
1532 * appropriate bits.
1533 * NEXT STATE = PRLI_ISSUE
1534 */
1535static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001536lpfc_rcv_prlo_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1537 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001538{
James Smart2e0fef82007-06-17 19:56:36 -05001539 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001540
James Smart51ef4c22007-08-02 11:10:31 -04001541 lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001542 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001543}
1544
1545static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001546lpfc_cmpl_prli_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1547 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001548{
James Smart92d7f7b2007-06-17 19:56:38 -05001549 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001550 struct lpfc_iocbq *cmdiocb, *rspiocb;
James Smart2e0fef82007-06-17 19:56:36 -05001551 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001552 IOCB_t *irsp;
1553 PRLI *npr;
1554
1555 cmdiocb = (struct lpfc_iocbq *) arg;
1556 rspiocb = cmdiocb->context_un.rsp_iocb;
1557 npr = (PRLI *)lpfc_check_elscmpl_iocb(phba, cmdiocb, rspiocb);
1558
1559 irsp = &rspiocb->iocb;
1560 if (irsp->ulpStatus) {
James Smart858c9f62007-06-17 19:56:39 -05001561 if ((vport->port_type == LPFC_NPIV_PORT) &&
James Smart3de2a652007-08-02 11:09:59 -04001562 vport->cfg_restrict_login) {
James Smart858c9f62007-06-17 19:56:39 -05001563 goto out;
1564 }
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001565 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -05001566 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001567 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001568 }
1569
1570 /* Check out PRLI rsp */
1571 ndlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR);
1572 ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
1573 if ((npr->acceptRspCode == PRLI_REQ_EXECUTED) &&
1574 (npr->prliType == PRLI_FCP_TYPE)) {
1575 if (npr->initiatorFunc)
1576 ndlp->nlp_type |= NLP_FCP_INITIATOR;
1577 if (npr->targetFunc)
1578 ndlp->nlp_type |= NLP_FCP_TARGET;
1579 if (npr->Retry)
1580 ndlp->nlp_fcp_info |= NLP_FCP_2_DEVICE;
1581 }
James Smart92d7f7b2007-06-17 19:56:38 -05001582 if (!(ndlp->nlp_type & NLP_FCP_TARGET) &&
1583 (vport->port_type == LPFC_NPIV_PORT) &&
James Smart3de2a652007-08-02 11:09:59 -04001584 vport->cfg_restrict_login) {
James Smart858c9f62007-06-17 19:56:39 -05001585out:
James Smart92d7f7b2007-06-17 19:56:38 -05001586 spin_lock_irq(shost->host_lock);
1587 ndlp->nlp_flag |= NLP_TARGET_REMOVE;
1588 spin_unlock_irq(shost->host_lock);
1589 lpfc_issue_els_logo(vport, ndlp, 0);
1590
1591 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
James Smart87af33f2007-10-27 13:37:43 -04001592 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
James Smart92d7f7b2007-06-17 19:56:38 -05001593 return ndlp->nlp_state;
1594 }
dea31012005-04-17 16:05:31 -05001595
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001596 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
James Smart92d7f7b2007-06-17 19:56:38 -05001597 if (ndlp->nlp_type & NLP_FCP_TARGET)
1598 lpfc_nlp_set_state(vport, ndlp, NLP_STE_MAPPED_NODE);
1599 else
1600 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001601 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001602}
1603
1604/*! lpfc_device_rm_prli_issue
James Smart92d7f7b2007-06-17 19:56:38 -05001605 *
1606 * \pre
1607 * \post
1608 * \param phba
1609 * \param ndlp
1610 * \param arg
1611 * \param evt
1612 * \return uint32_t
1613 *
1614 * \b Description:
1615 * This routine is envoked when we a request to remove a nport we are in the
1616 * process of PRLIing. We should software abort outstanding prli, unreg
1617 * login, send a logout. We will change node state to UNUSED_NODE, put it
1618 * on plogi list so it can be freed when LOGO completes.
1619 *
1620 */
1621
dea31012005-04-17 16:05:31 -05001622static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001623lpfc_device_rm_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1624 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001625{
James Smart2e0fef82007-06-17 19:56:36 -05001626 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001627
James Smart2e0fef82007-06-17 19:56:36 -05001628 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1629 spin_lock_irq(shost->host_lock);
1630 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
1631 spin_unlock_irq(shost->host_lock);
1632 return ndlp->nlp_state;
1633 } else {
1634 /* software abort outstanding PLOGI */
1635 lpfc_els_abort(vport->phba, ndlp);
1636
1637 lpfc_drop_node(vport, ndlp);
James Smarta0f9b482006-04-15 11:52:56 -04001638 return NLP_STE_FREED_NODE;
1639 }
dea31012005-04-17 16:05:31 -05001640}
1641
1642
1643/*! lpfc_device_recov_prli_issue
James Smart92d7f7b2007-06-17 19:56:38 -05001644 *
1645 * \pre
1646 * \post
1647 * \param phba
1648 * \param ndlp
1649 * \param arg
1650 * \param evt
1651 * \return uint32_t
1652 *
1653 * \b Description:
1654 * The routine is envoked when the state of a device is unknown, like
1655 * during a link down. We should remove the nodelist entry from the
1656 * unmapped list, issue a UNREG_LOGIN, do a software abort of the
1657 * outstanding PRLI command, then free the node entry.
1658 */
dea31012005-04-17 16:05:31 -05001659static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001660lpfc_device_recov_prli_issue(struct lpfc_vport *vport,
1661 struct lpfc_nodelist *ndlp,
1662 void *arg,
1663 uint32_t evt)
dea31012005-04-17 16:05:31 -05001664{
James Smart2e0fef82007-06-17 19:56:36 -05001665 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1666 struct lpfc_hba *phba = vport->phba;
1667
James Smart92d7f7b2007-06-17 19:56:38 -05001668 /* Don't do anything that will mess up processing of the
1669 * previous RSCN.
1670 */
1671 if (vport->fc_flag & FC_RSCN_DEFERRED)
1672 return ndlp->nlp_state;
1673
dea31012005-04-17 16:05:31 -05001674 /* software abort outstanding PRLI */
James Smart07951072007-04-25 09:51:38 -04001675 lpfc_els_abort(phba, ndlp);
dea31012005-04-17 16:05:31 -05001676
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001677 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -05001678 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1679 spin_lock_irq(shost->host_lock);
James Smarta0f9b482006-04-15 11:52:56 -04001680 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
James Smart2e0fef82007-06-17 19:56:36 -05001681 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05001682 lpfc_disc_set_adisc(vport, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001683 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001684}
1685
1686static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001687lpfc_rcv_plogi_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1688 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001689{
James Smart2e0fef82007-06-17 19:56:36 -05001690 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001691
James Smart2e0fef82007-06-17 19:56:36 -05001692 lpfc_rcv_plogi(vport, ndlp, cmdiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001693 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001694}
1695
1696static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001697lpfc_rcv_prli_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1698 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001699{
James Smart2e0fef82007-06-17 19:56:36 -05001700 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001701
James Smart2e0fef82007-06-17 19:56:36 -05001702 lpfc_rcv_prli(vport, ndlp, cmdiocb);
1703 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001704 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001705}
1706
1707static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001708lpfc_rcv_logo_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1709 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001710{
James Smart2e0fef82007-06-17 19:56:36 -05001711 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001712
James Smart2e0fef82007-06-17 19:56:36 -05001713 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001714 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001715}
1716
1717static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001718lpfc_rcv_padisc_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1719 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001720{
James Smart2e0fef82007-06-17 19:56:36 -05001721 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001722
James Smart2e0fef82007-06-17 19:56:36 -05001723 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001724 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001725}
1726
1727static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001728lpfc_rcv_prlo_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1729 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001730{
James Smart2e0fef82007-06-17 19:56:36 -05001731 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001732
James Smart51ef4c22007-08-02 11:10:31 -04001733 lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001734 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001735}
1736
1737static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001738lpfc_device_recov_unmap_node(struct lpfc_vport *vport,
1739 struct lpfc_nodelist *ndlp,
1740 void *arg,
1741 uint32_t evt)
dea31012005-04-17 16:05:31 -05001742{
James Smart2e0fef82007-06-17 19:56:36 -05001743 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1744
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001745 ndlp->nlp_prev_state = NLP_STE_UNMAPPED_NODE;
James Smart2e0fef82007-06-17 19:56:36 -05001746 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1747 spin_lock_irq(shost->host_lock);
James Smarta0f9b482006-04-15 11:52:56 -04001748 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
James Smart2e0fef82007-06-17 19:56:36 -05001749 spin_unlock_irq(shost->host_lock);
1750 lpfc_disc_set_adisc(vport, ndlp);
dea31012005-04-17 16:05:31 -05001751
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001752 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001753}
1754
1755static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001756lpfc_rcv_plogi_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1757 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001758{
James Smart2e0fef82007-06-17 19:56:36 -05001759 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001760
James Smart2e0fef82007-06-17 19:56:36 -05001761 lpfc_rcv_plogi(vport, ndlp, cmdiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001762 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001763}
1764
1765static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001766lpfc_rcv_prli_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1767 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001768{
James Smart2e0fef82007-06-17 19:56:36 -05001769 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001770
James Smart2e0fef82007-06-17 19:56:36 -05001771 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001772 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001773}
1774
1775static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001776lpfc_rcv_logo_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1777 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001778{
James Smart2e0fef82007-06-17 19:56:36 -05001779 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001780
James Smart2e0fef82007-06-17 19:56:36 -05001781 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001782 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001783}
1784
1785static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001786lpfc_rcv_padisc_mapped_node(struct lpfc_vport *vport,
1787 struct lpfc_nodelist *ndlp,
1788 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001789{
James Smart2e0fef82007-06-17 19:56:36 -05001790 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001791
James Smart2e0fef82007-06-17 19:56:36 -05001792 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001793 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001794}
1795
1796static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001797lpfc_rcv_prlo_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1798 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001799{
James Smart2e0fef82007-06-17 19:56:36 -05001800 struct lpfc_hba *phba = vport->phba;
1801 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001802
1803 /* flush the target */
James Smart51ef4c22007-08-02 11:10:31 -04001804 lpfc_sli_abort_iocb(vport, &phba->sli.ring[phba->sli.fcp_ring],
1805 ndlp->nlp_sid, 0, LPFC_CTX_TGT);
dea31012005-04-17 16:05:31 -05001806
1807 /* Treat like rcv logo */
James Smart2e0fef82007-06-17 19:56:36 -05001808 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_PRLO);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001809 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001810}
1811
1812static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001813lpfc_device_recov_mapped_node(struct lpfc_vport *vport,
1814 struct lpfc_nodelist *ndlp,
1815 void *arg,
1816 uint32_t evt)
dea31012005-04-17 16:05:31 -05001817{
James Smart2e0fef82007-06-17 19:56:36 -05001818 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1819
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001820 ndlp->nlp_prev_state = NLP_STE_MAPPED_NODE;
James Smart2e0fef82007-06-17 19:56:36 -05001821 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1822 spin_lock_irq(shost->host_lock);
James Smarta0f9b482006-04-15 11:52:56 -04001823 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
James Smart2e0fef82007-06-17 19:56:36 -05001824 spin_unlock_irq(shost->host_lock);
1825 lpfc_disc_set_adisc(vport, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001826 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001827}
1828
1829static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001830lpfc_rcv_plogi_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1831 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001832{
James Smart2e0fef82007-06-17 19:56:36 -05001833 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1834 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001835
1836 /* Ignore PLOGI if we have an outstanding LOGO */
James Smart0d2b6b82008-06-14 22:52:47 -04001837 if (ndlp->nlp_flag & (NLP_LOGO_SND | NLP_LOGO_ACC))
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001838 return ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05001839 if (lpfc_rcv_plogi(vport, ndlp, cmdiocb)) {
James Smart0d2b6b82008-06-14 22:52:47 -04001840 lpfc_cancel_retry_delay_tmo(vport, ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05001841 spin_lock_irq(shost->host_lock);
James Smart0d2b6b82008-06-14 22:52:47 -04001842 ndlp->nlp_flag &= ~(NLP_NPR_ADISC | NLP_NPR_2B_DISC);
James Smart2e0fef82007-06-17 19:56:36 -05001843 spin_unlock_irq(shost->host_lock);
James Smart0d2b6b82008-06-14 22:52:47 -04001844 } else if (!(ndlp->nlp_flag & NLP_NPR_2B_DISC)) {
1845 /* send PLOGI immediately, move to PLOGI issue state */
1846 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
1847 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
1848 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
1849 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
1850 }
dea31012005-04-17 16:05:31 -05001851 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001852 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001853}
1854
1855static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001856lpfc_rcv_prli_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1857 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001858{
James Smart2e0fef82007-06-17 19:56:36 -05001859 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1860 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1861 struct ls_rjt stat;
dea31012005-04-17 16:05:31 -05001862
1863 memset(&stat, 0, sizeof (struct ls_rjt));
1864 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
1865 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
James Smart858c9f62007-06-17 19:56:39 -05001866 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05001867
1868 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
1869 if (ndlp->nlp_flag & NLP_NPR_ADISC) {
James Smart2e0fef82007-06-17 19:56:36 -05001870 spin_lock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001871 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001872 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
James Smart2e0fef82007-06-17 19:56:36 -05001873 spin_unlock_irq(shost->host_lock);
1874 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
1875 lpfc_issue_els_adisc(vport, ndlp, 0);
dea31012005-04-17 16:05:31 -05001876 } else {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001877 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
James Smart2e0fef82007-06-17 19:56:36 -05001878 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
1879 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
dea31012005-04-17 16:05:31 -05001880 }
1881 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001882 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001883}
1884
1885static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001886lpfc_rcv_logo_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1887 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001888{
James Smart2e0fef82007-06-17 19:56:36 -05001889 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001890
James Smart2e0fef82007-06-17 19:56:36 -05001891 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001892 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001893}
1894
1895static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001896lpfc_rcv_padisc_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1897 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001898{
James Smart2e0fef82007-06-17 19:56:36 -05001899 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001900
James Smart2e0fef82007-06-17 19:56:36 -05001901 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
James Smart33ccf8d2006-08-17 11:57:58 -04001902 /*
1903 * Do not start discovery if discovery is about to start
1904 * or discovery in progress for this node. Starting discovery
1905 * here will affect the counting of discovery threads.
1906 */
James Smart2fb9bd82006-12-02 13:33:57 -05001907 if (!(ndlp->nlp_flag & NLP_DELAY_TMO) &&
James Smart92d7f7b2007-06-17 19:56:38 -05001908 !(ndlp->nlp_flag & NLP_NPR_2B_DISC)) {
dea31012005-04-17 16:05:31 -05001909 if (ndlp->nlp_flag & NLP_NPR_ADISC) {
James Smart92d7f7b2007-06-17 19:56:38 -05001910 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001911 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
James Smart2e0fef82007-06-17 19:56:36 -05001912 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
1913 lpfc_issue_els_adisc(vport, ndlp, 0);
dea31012005-04-17 16:05:31 -05001914 } else {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001915 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
James Smart2e0fef82007-06-17 19:56:36 -05001916 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
1917 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
dea31012005-04-17 16:05:31 -05001918 }
1919 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001920 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001921}
1922
1923static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001924lpfc_rcv_prlo_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1925 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001926{
James Smart2e0fef82007-06-17 19:56:36 -05001927 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1928 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001929
James Smart2e0fef82007-06-17 19:56:36 -05001930 spin_lock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001931 ndlp->nlp_flag |= NLP_LOGO_ACC;
James Smart2e0fef82007-06-17 19:56:36 -05001932 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001933
James Smart51ef4c22007-08-02 11:10:31 -04001934 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05001935
James Smart2e0fef82007-06-17 19:56:36 -05001936 if ((ndlp->nlp_flag & NLP_DELAY_TMO) == 0) {
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001937 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ * 1);
James Smart2e0fef82007-06-17 19:56:36 -05001938 spin_lock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001939 ndlp->nlp_flag |= NLP_DELAY_TMO;
1940 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
James Smart2e0fef82007-06-17 19:56:36 -05001941 spin_unlock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001942 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001943 } else {
James Smart2e0fef82007-06-17 19:56:36 -05001944 spin_lock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001945 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
James Smart2e0fef82007-06-17 19:56:36 -05001946 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001947 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001948 return ndlp->nlp_state;
1949}
dea31012005-04-17 16:05:31 -05001950
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001951static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001952lpfc_cmpl_plogi_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1953 void *arg, uint32_t evt)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001954{
1955 struct lpfc_iocbq *cmdiocb, *rspiocb;
James Smarta0f9b482006-04-15 11:52:56 -04001956 IOCB_t *irsp;
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001957
1958 cmdiocb = (struct lpfc_iocbq *) arg;
1959 rspiocb = cmdiocb->context_un.rsp_iocb;
James Smarta0f9b482006-04-15 11:52:56 -04001960
1961 irsp = &rspiocb->iocb;
1962 if (irsp->ulpStatus) {
James Smarta8adb832007-10-27 13:37:53 -04001963 ndlp->nlp_flag |= NLP_DEFER_RM;
James Smarta0f9b482006-04-15 11:52:56 -04001964 return NLP_STE_FREED_NODE;
1965 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001966 return ndlp->nlp_state;
1967}
1968
1969static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001970lpfc_cmpl_prli_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1971 void *arg, uint32_t evt)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001972{
1973 struct lpfc_iocbq *cmdiocb, *rspiocb;
James Smarta0f9b482006-04-15 11:52:56 -04001974 IOCB_t *irsp;
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001975
1976 cmdiocb = (struct lpfc_iocbq *) arg;
1977 rspiocb = cmdiocb->context_un.rsp_iocb;
James Smarta0f9b482006-04-15 11:52:56 -04001978
1979 irsp = &rspiocb->iocb;
1980 if (irsp->ulpStatus && (ndlp->nlp_flag & NLP_NODEV_REMOVE)) {
James Smart2e0fef82007-06-17 19:56:36 -05001981 lpfc_drop_node(vport, ndlp);
James Smarta0f9b482006-04-15 11:52:56 -04001982 return NLP_STE_FREED_NODE;
1983 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001984 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001985}
1986
1987static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001988lpfc_cmpl_logo_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1989 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001990{
James Smartd7c255b2008-08-24 21:50:00 -04001991 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1992 if (ndlp->nlp_DID == Fabric_DID) {
1993 spin_lock_irq(shost->host_lock);
1994 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
1995 spin_unlock_irq(shost->host_lock);
1996 }
James Smart2e0fef82007-06-17 19:56:36 -05001997 lpfc_unreg_rpi(vport, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001998 return ndlp->nlp_state;
1999}
2000
2001static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05002002lpfc_cmpl_adisc_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2003 void *arg, uint32_t evt)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002004{
2005 struct lpfc_iocbq *cmdiocb, *rspiocb;
James Smarta0f9b482006-04-15 11:52:56 -04002006 IOCB_t *irsp;
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002007
2008 cmdiocb = (struct lpfc_iocbq *) arg;
2009 rspiocb = cmdiocb->context_un.rsp_iocb;
James Smarta0f9b482006-04-15 11:52:56 -04002010
2011 irsp = &rspiocb->iocb;
2012 if (irsp->ulpStatus && (ndlp->nlp_flag & NLP_NODEV_REMOVE)) {
James Smart2e0fef82007-06-17 19:56:36 -05002013 lpfc_drop_node(vport, ndlp);
James Smarta0f9b482006-04-15 11:52:56 -04002014 return NLP_STE_FREED_NODE;
2015 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002016 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05002017}
2018
2019static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05002020lpfc_cmpl_reglogin_npr_node(struct lpfc_vport *vport,
2021 struct lpfc_nodelist *ndlp,
2022 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05002023{
James Smart2e0fef82007-06-17 19:56:36 -05002024 LPFC_MBOXQ_t *pmb = (LPFC_MBOXQ_t *) arg;
James Smart04c68492009-05-22 14:52:52 -04002025 MAILBOX_t *mb = &pmb->u.mb;
dea31012005-04-17 16:05:31 -05002026
James Smart04c68492009-05-22 14:52:52 -04002027 if (!mb->mbxStatus) {
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002028 ndlp->nlp_rpi = mb->un.varWords[0];
James Smart40426292010-12-15 17:58:10 -05002029 ndlp->nlp_flag |= NLP_RPI_REGISTERED;
James Smart04c68492009-05-22 14:52:52 -04002030 } else {
James Smarta0f9b482006-04-15 11:52:56 -04002031 if (ndlp->nlp_flag & NLP_NODEV_REMOVE) {
James Smart2e0fef82007-06-17 19:56:36 -05002032 lpfc_drop_node(vport, ndlp);
James Smarta0f9b482006-04-15 11:52:56 -04002033 return NLP_STE_FREED_NODE;
2034 }
2035 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002036 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05002037}
2038
2039static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05002040lpfc_device_rm_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2041 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05002042{
James Smart2e0fef82007-06-17 19:56:36 -05002043 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2044
James Smarta0f9b482006-04-15 11:52:56 -04002045 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
James Smart2e0fef82007-06-17 19:56:36 -05002046 spin_lock_irq(shost->host_lock);
James Smarta0f9b482006-04-15 11:52:56 -04002047 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
James Smart2e0fef82007-06-17 19:56:36 -05002048 spin_unlock_irq(shost->host_lock);
James Smarta0f9b482006-04-15 11:52:56 -04002049 return ndlp->nlp_state;
2050 }
James Smart2e0fef82007-06-17 19:56:36 -05002051 lpfc_drop_node(vport, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002052 return NLP_STE_FREED_NODE;
dea31012005-04-17 16:05:31 -05002053}
2054
2055static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05002056lpfc_device_recov_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2057 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05002058{
James Smart2e0fef82007-06-17 19:56:36 -05002059 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2060
James Smart92d7f7b2007-06-17 19:56:38 -05002061 /* Don't do anything that will mess up processing of the
2062 * previous RSCN.
2063 */
2064 if (vport->fc_flag & FC_RSCN_DEFERRED)
2065 return ndlp->nlp_state;
2066
James Smarteaf15d52008-12-04 22:39:29 -05002067 lpfc_cancel_retry_delay_tmo(vport, ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05002068 spin_lock_irq(shost->host_lock);
James Smarta0f9b482006-04-15 11:52:56 -04002069 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
James Smart2e0fef82007-06-17 19:56:36 -05002070 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002071 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05002072}
2073
2074
2075/* This next section defines the NPort Discovery State Machine */
2076
2077/* There are 4 different double linked lists nodelist entries can reside on.
2078 * The plogi list and adisc list are used when Link Up discovery or RSCN
2079 * processing is needed. Each list holds the nodes that we will send PLOGI
2080 * or ADISC on. These lists will keep track of what nodes will be effected
2081 * by an RSCN, or a Link Up (Typically, all nodes are effected on Link Up).
2082 * The unmapped_list will contain all nodes that we have successfully logged
2083 * into at the Fibre Channel level. The mapped_list will contain all nodes
2084 * that are mapped FCP targets.
2085 */
2086/*
2087 * The bind list is a list of undiscovered (potentially non-existent) nodes
2088 * that we have saved binding information on. This information is used when
2089 * nodes transition from the unmapped to the mapped list.
2090 */
2091/* For UNUSED_NODE state, the node has just been allocated .
2092 * For PLOGI_ISSUE and REG_LOGIN_ISSUE, the node is on
2093 * the PLOGI list. For REG_LOGIN_COMPL, the node is taken off the PLOGI list
2094 * and put on the unmapped list. For ADISC processing, the node is taken off
2095 * the ADISC list and placed on either the mapped or unmapped list (depending
2096 * on its previous state). Once on the unmapped list, a PRLI is issued and the
2097 * state changed to PRLI_ISSUE. When the PRLI completion occurs, the state is
2098 * changed to UNMAPPED_NODE. If the completion indicates a mapped
2099 * node, the node is taken off the unmapped list. The binding list is checked
2100 * for a valid binding, or a binding is automatically assigned. If binding
2101 * assignment is unsuccessful, the node is left on the unmapped list. If
2102 * binding assignment is successful, the associated binding list entry (if
2103 * any) is removed, and the node is placed on the mapped list.
2104 */
2105/*
2106 * For a Link Down, all nodes on the ADISC, PLOGI, unmapped or mapped
James Smartc01f3202006-08-18 17:47:08 -04002107 * lists will receive a DEVICE_RECOVERY event. If the linkdown or devloss timers
dea31012005-04-17 16:05:31 -05002108 * expire, all effected nodes will receive a DEVICE_RM event.
2109 */
2110/*
2111 * For a Link Up or RSCN, all nodes will move from the mapped / unmapped lists
2112 * to either the ADISC or PLOGI list. After a Nameserver query or ALPA loopmap
2113 * check, additional nodes may be added or removed (via DEVICE_RM) to / from
2114 * the PLOGI or ADISC lists. Once the PLOGI and ADISC lists are populated,
2115 * we will first process the ADISC list. 32 entries are processed initially and
2116 * ADISC is initited for each one. Completions / Events for each node are
2117 * funnelled thru the state machine. As each node finishes ADISC processing, it
2118 * starts ADISC for any nodes waiting for ADISC processing. If no nodes are
2119 * waiting, and the ADISC list count is identically 0, then we are done. For
2120 * Link Up discovery, since all nodes on the PLOGI list are UNREG_LOGIN'ed, we
2121 * can issue a CLEAR_LA and reenable Link Events. Next we will process the PLOGI
2122 * list. 32 entries are processed initially and PLOGI is initited for each one.
2123 * Completions / Events for each node are funnelled thru the state machine. As
2124 * each node finishes PLOGI processing, it starts PLOGI for any nodes waiting
2125 * for PLOGI processing. If no nodes are waiting, and the PLOGI list count is
2126 * indentically 0, then we are done. We have now completed discovery / RSCN
2127 * handling. Upon completion, ALL nodes should be on either the mapped or
2128 * unmapped lists.
2129 */
2130
2131static uint32_t (*lpfc_disc_action[NLP_STE_MAX_STATE * NLP_EVT_MAX_EVENT])
James Smart2e0fef82007-06-17 19:56:36 -05002132 (struct lpfc_vport *, struct lpfc_nodelist *, void *, uint32_t) = {
dea31012005-04-17 16:05:31 -05002133 /* Action routine Event Current State */
2134 lpfc_rcv_plogi_unused_node, /* RCV_PLOGI UNUSED_NODE */
2135 lpfc_rcv_els_unused_node, /* RCV_PRLI */
2136 lpfc_rcv_logo_unused_node, /* RCV_LOGO */
2137 lpfc_rcv_els_unused_node, /* RCV_ADISC */
2138 lpfc_rcv_els_unused_node, /* RCV_PDISC */
2139 lpfc_rcv_els_unused_node, /* RCV_PRLO */
2140 lpfc_disc_illegal, /* CMPL_PLOGI */
2141 lpfc_disc_illegal, /* CMPL_PRLI */
2142 lpfc_cmpl_logo_unused_node, /* CMPL_LOGO */
2143 lpfc_disc_illegal, /* CMPL_ADISC */
2144 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2145 lpfc_device_rm_unused_node, /* DEVICE_RM */
2146 lpfc_disc_illegal, /* DEVICE_RECOVERY */
2147
2148 lpfc_rcv_plogi_plogi_issue, /* RCV_PLOGI PLOGI_ISSUE */
James Smart92d7f7b2007-06-17 19:56:38 -05002149 lpfc_rcv_prli_plogi_issue, /* RCV_PRLI */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002150 lpfc_rcv_logo_plogi_issue, /* RCV_LOGO */
dea31012005-04-17 16:05:31 -05002151 lpfc_rcv_els_plogi_issue, /* RCV_ADISC */
2152 lpfc_rcv_els_plogi_issue, /* RCV_PDISC */
2153 lpfc_rcv_els_plogi_issue, /* RCV_PRLO */
2154 lpfc_cmpl_plogi_plogi_issue, /* CMPL_PLOGI */
2155 lpfc_disc_illegal, /* CMPL_PRLI */
James Smart0ff10d42008-01-11 01:52:36 -05002156 lpfc_cmpl_logo_plogi_issue, /* CMPL_LOGO */
dea31012005-04-17 16:05:31 -05002157 lpfc_disc_illegal, /* CMPL_ADISC */
James Smart0ff10d42008-01-11 01:52:36 -05002158 lpfc_cmpl_reglogin_plogi_issue,/* CMPL_REG_LOGIN */
dea31012005-04-17 16:05:31 -05002159 lpfc_device_rm_plogi_issue, /* DEVICE_RM */
2160 lpfc_device_recov_plogi_issue, /* DEVICE_RECOVERY */
2161
2162 lpfc_rcv_plogi_adisc_issue, /* RCV_PLOGI ADISC_ISSUE */
2163 lpfc_rcv_prli_adisc_issue, /* RCV_PRLI */
2164 lpfc_rcv_logo_adisc_issue, /* RCV_LOGO */
2165 lpfc_rcv_padisc_adisc_issue, /* RCV_ADISC */
2166 lpfc_rcv_padisc_adisc_issue, /* RCV_PDISC */
2167 lpfc_rcv_prlo_adisc_issue, /* RCV_PRLO */
2168 lpfc_disc_illegal, /* CMPL_PLOGI */
2169 lpfc_disc_illegal, /* CMPL_PRLI */
2170 lpfc_disc_illegal, /* CMPL_LOGO */
2171 lpfc_cmpl_adisc_adisc_issue, /* CMPL_ADISC */
2172 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2173 lpfc_device_rm_adisc_issue, /* DEVICE_RM */
2174 lpfc_device_recov_adisc_issue, /* DEVICE_RECOVERY */
2175
2176 lpfc_rcv_plogi_reglogin_issue, /* RCV_PLOGI REG_LOGIN_ISSUE */
2177 lpfc_rcv_prli_reglogin_issue, /* RCV_PLOGI */
2178 lpfc_rcv_logo_reglogin_issue, /* RCV_LOGO */
2179 lpfc_rcv_padisc_reglogin_issue, /* RCV_ADISC */
2180 lpfc_rcv_padisc_reglogin_issue, /* RCV_PDISC */
2181 lpfc_rcv_prlo_reglogin_issue, /* RCV_PRLO */
James Smart87af33f2007-10-27 13:37:43 -04002182 lpfc_cmpl_plogi_illegal, /* CMPL_PLOGI */
dea31012005-04-17 16:05:31 -05002183 lpfc_disc_illegal, /* CMPL_PRLI */
2184 lpfc_disc_illegal, /* CMPL_LOGO */
2185 lpfc_disc_illegal, /* CMPL_ADISC */
2186 lpfc_cmpl_reglogin_reglogin_issue,/* CMPL_REG_LOGIN */
2187 lpfc_device_rm_reglogin_issue, /* DEVICE_RM */
2188 lpfc_device_recov_reglogin_issue,/* DEVICE_RECOVERY */
2189
2190 lpfc_rcv_plogi_prli_issue, /* RCV_PLOGI PRLI_ISSUE */
2191 lpfc_rcv_prli_prli_issue, /* RCV_PRLI */
2192 lpfc_rcv_logo_prli_issue, /* RCV_LOGO */
2193 lpfc_rcv_padisc_prli_issue, /* RCV_ADISC */
2194 lpfc_rcv_padisc_prli_issue, /* RCV_PDISC */
2195 lpfc_rcv_prlo_prli_issue, /* RCV_PRLO */
James Smart87af33f2007-10-27 13:37:43 -04002196 lpfc_cmpl_plogi_illegal, /* CMPL_PLOGI */
dea31012005-04-17 16:05:31 -05002197 lpfc_cmpl_prli_prli_issue, /* CMPL_PRLI */
2198 lpfc_disc_illegal, /* CMPL_LOGO */
2199 lpfc_disc_illegal, /* CMPL_ADISC */
2200 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2201 lpfc_device_rm_prli_issue, /* DEVICE_RM */
2202 lpfc_device_recov_prli_issue, /* DEVICE_RECOVERY */
2203
2204 lpfc_rcv_plogi_unmap_node, /* RCV_PLOGI UNMAPPED_NODE */
2205 lpfc_rcv_prli_unmap_node, /* RCV_PRLI */
2206 lpfc_rcv_logo_unmap_node, /* RCV_LOGO */
2207 lpfc_rcv_padisc_unmap_node, /* RCV_ADISC */
2208 lpfc_rcv_padisc_unmap_node, /* RCV_PDISC */
2209 lpfc_rcv_prlo_unmap_node, /* RCV_PRLO */
2210 lpfc_disc_illegal, /* CMPL_PLOGI */
2211 lpfc_disc_illegal, /* CMPL_PRLI */
2212 lpfc_disc_illegal, /* CMPL_LOGO */
2213 lpfc_disc_illegal, /* CMPL_ADISC */
2214 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2215 lpfc_disc_illegal, /* DEVICE_RM */
2216 lpfc_device_recov_unmap_node, /* DEVICE_RECOVERY */
2217
2218 lpfc_rcv_plogi_mapped_node, /* RCV_PLOGI MAPPED_NODE */
2219 lpfc_rcv_prli_mapped_node, /* RCV_PRLI */
2220 lpfc_rcv_logo_mapped_node, /* RCV_LOGO */
2221 lpfc_rcv_padisc_mapped_node, /* RCV_ADISC */
2222 lpfc_rcv_padisc_mapped_node, /* RCV_PDISC */
2223 lpfc_rcv_prlo_mapped_node, /* RCV_PRLO */
2224 lpfc_disc_illegal, /* CMPL_PLOGI */
2225 lpfc_disc_illegal, /* CMPL_PRLI */
2226 lpfc_disc_illegal, /* CMPL_LOGO */
2227 lpfc_disc_illegal, /* CMPL_ADISC */
2228 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2229 lpfc_disc_illegal, /* DEVICE_RM */
2230 lpfc_device_recov_mapped_node, /* DEVICE_RECOVERY */
2231
2232 lpfc_rcv_plogi_npr_node, /* RCV_PLOGI NPR_NODE */
2233 lpfc_rcv_prli_npr_node, /* RCV_PRLI */
2234 lpfc_rcv_logo_npr_node, /* RCV_LOGO */
2235 lpfc_rcv_padisc_npr_node, /* RCV_ADISC */
2236 lpfc_rcv_padisc_npr_node, /* RCV_PDISC */
2237 lpfc_rcv_prlo_npr_node, /* RCV_PRLO */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002238 lpfc_cmpl_plogi_npr_node, /* CMPL_PLOGI */
2239 lpfc_cmpl_prli_npr_node, /* CMPL_PRLI */
dea31012005-04-17 16:05:31 -05002240 lpfc_cmpl_logo_npr_node, /* CMPL_LOGO */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002241 lpfc_cmpl_adisc_npr_node, /* CMPL_ADISC */
dea31012005-04-17 16:05:31 -05002242 lpfc_cmpl_reglogin_npr_node, /* CMPL_REG_LOGIN */
2243 lpfc_device_rm_npr_node, /* DEVICE_RM */
2244 lpfc_device_recov_npr_node, /* DEVICE_RECOVERY */
2245};
2246
2247int
James Smart2e0fef82007-06-17 19:56:36 -05002248lpfc_disc_state_machine(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2249 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05002250{
2251 uint32_t cur_state, rc;
James Smart2e0fef82007-06-17 19:56:36 -05002252 uint32_t(*func) (struct lpfc_vport *, struct lpfc_nodelist *, void *,
dea31012005-04-17 16:05:31 -05002253 uint32_t);
James Smarte47c9092008-02-08 18:49:26 -05002254 uint32_t got_ndlp = 0;
dea31012005-04-17 16:05:31 -05002255
James Smarte47c9092008-02-08 18:49:26 -05002256 if (lpfc_nlp_get(ndlp))
2257 got_ndlp = 1;
2258
dea31012005-04-17 16:05:31 -05002259 cur_state = ndlp->nlp_state;
2260
2261 /* DSM in event <evt> on NPort <nlp_DID> in state <cur_state> */
James Smarte8b62012007-08-02 11:10:09 -04002262 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2263 "0211 DSM in event x%x on NPort x%x in "
2264 "state %d Data: x%x\n",
2265 evt, ndlp->nlp_DID, cur_state, ndlp->nlp_flag);
dea31012005-04-17 16:05:31 -05002266
James Smart858c9f62007-06-17 19:56:39 -05002267 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_DSM,
2268 "DSM in: evt:%d ste:%d did:x%x",
2269 evt, cur_state, ndlp->nlp_DID);
2270
dea31012005-04-17 16:05:31 -05002271 func = lpfc_disc_action[(cur_state * NLP_EVT_MAX_EVENT) + evt];
James Smart2e0fef82007-06-17 19:56:36 -05002272 rc = (func) (vport, ndlp, arg, evt);
dea31012005-04-17 16:05:31 -05002273
2274 /* DSM out state <rc> on NPort <nlp_DID> */
James Smarte47c9092008-02-08 18:49:26 -05002275 if (got_ndlp) {
2276 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
James Smarte8b62012007-08-02 11:10:09 -04002277 "0212 DSM out state %d on NPort x%x Data: x%x\n",
2278 rc, ndlp->nlp_DID, ndlp->nlp_flag);
dea31012005-04-17 16:05:31 -05002279
James Smarte47c9092008-02-08 18:49:26 -05002280 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_DSM,
2281 "DSM out: ste:%d did:x%x flg:x%x",
2282 rc, ndlp->nlp_DID, ndlp->nlp_flag);
2283 /* Decrement the ndlp reference count held for this function */
2284 lpfc_nlp_put(ndlp);
2285 } else {
2286 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
James Smartd7c255b2008-08-24 21:50:00 -04002287 "0213 DSM out state %d on NPort free\n", rc);
James Smart858c9f62007-06-17 19:56:39 -05002288
James Smarte47c9092008-02-08 18:49:26 -05002289 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_DSM,
2290 "DSM out: ste:%d did:x%x flg:x%x",
2291 rc, 0, 0);
2292 }
dea31012005-04-17 16:05:31 -05002293
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002294 return rc;
dea31012005-04-17 16:05:31 -05002295}