blob: 2ddd02f7c60336130e90f8a0eb5f0ba230484451 [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 Smart05580562011-05-24 11:40:48 -0400353 /* no need to reg_login if we are already in one of these states */
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500354 switch (ndlp->nlp_state) {
dea31012005-04-17 16:05:31 -0500355 case NLP_STE_NPR_NODE:
356 if (!(ndlp->nlp_flag & NLP_NPR_ADISC))
357 break;
358 case NLP_STE_REG_LOGIN_ISSUE:
359 case NLP_STE_PRLI_ISSUE:
360 case NLP_STE_UNMAPPED_NODE:
361 case NLP_STE_MAPPED_NODE:
James Smart05580562011-05-24 11:40:48 -0400362 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp, NULL);
363 return 1;
dea31012005-04-17 16:05:31 -0500364 }
365
James Smart92d7f7b2007-06-17 19:56:38 -0500366 if ((vport->fc_flag & FC_PT2PT) &&
367 !(vport->fc_flag & FC_PT2PT_PLOGI)) {
dea31012005-04-17 16:05:31 -0500368 /* rcv'ed PLOGI decides what our NPortId will be */
James Smart2e0fef82007-06-17 19:56:36 -0500369 vport->fc_myDID = icmd->un.rcvels.parmRo;
dea31012005-04-17 16:05:31 -0500370 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
371 if (mbox == NULL)
372 goto out;
373 lpfc_config_link(phba, mbox);
374 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smarted957682007-06-17 19:56:37 -0500375 mbox->vport = vport;
James Smart0b727fe2007-10-27 13:37:25 -0400376 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
dea31012005-04-17 16:05:31 -0500377 if (rc == MBX_NOT_FINISHED) {
James Smart92d7f7b2007-06-17 19:56:38 -0500378 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -0500379 goto out;
380 }
381
James Smart2e0fef82007-06-17 19:56:36 -0500382 lpfc_can_disctmo(vport);
dea31012005-04-17 16:05:31 -0500383 }
384 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
James Smart2e0fef82007-06-17 19:56:36 -0500385 if (!mbox)
dea31012005-04-17 16:05:31 -0500386 goto out;
387
James Smart6fb120a2009-05-22 14:52:59 -0400388 rc = lpfc_reg_rpi(phba, vport->vpi, icmd->un.rcvels.remoteID,
James Smart40426292010-12-15 17:58:10 -0500389 (uint8_t *) sp, mbox, ndlp->nlp_rpi);
James Smart2e0fef82007-06-17 19:56:36 -0500390 if (rc) {
391 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -0500392 goto out;
393 }
394
395 /* ACC PLOGI rsp command needs to execute first,
396 * queue this mbox command to be processed later.
397 */
398 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
James Smart329f9bc2007-04-25 09:53:01 -0400399 /*
400 * mbox->context2 = lpfc_nlp_get(ndlp) deferred until mailbox
401 * command issued in lpfc_cmpl_els_acc().
402 */
James Smart2e0fef82007-06-17 19:56:36 -0500403 mbox->vport = vport;
404 spin_lock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -0500405 ndlp->nlp_flag |= (NLP_ACC_REGLOGIN | NLP_RCV_PLOGI);
James Smart2e0fef82007-06-17 19:56:36 -0500406 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500407
James Smart33ccf8d2006-08-17 11:57:58 -0400408 /*
409 * If there is an outstanding PLOGI issued, abort it before
410 * sending ACC rsp for received PLOGI. If pending plogi
411 * is not canceled here, the plogi will be rejected by
412 * remote port and will be retried. On a configuration with
413 * single discovery thread, this will cause a huge delay in
414 * discovery. Also this will cause multiple state machines
415 * running in parallel for this node.
416 */
417 if (ndlp->nlp_state == NLP_STE_PLOGI_ISSUE) {
418 /* software abort outstanding PLOGI */
James Smart07951072007-04-25 09:51:38 -0400419 lpfc_els_abort(phba, ndlp);
James Smart33ccf8d2006-08-17 11:57:58 -0400420 }
421
James Smart858c9f62007-06-17 19:56:39 -0500422 if ((vport->port_type == LPFC_NPIV_PORT &&
James Smart3de2a652007-08-02 11:09:59 -0400423 vport->cfg_restrict_login)) {
James Smart858c9f62007-06-17 19:56:39 -0500424
425 /* In order to preserve RPIs, we want to cleanup
426 * the default RPI the firmware created to rcv
427 * this ELS request. The only way to do this is
428 * to register, then unregister the RPI.
429 */
430 spin_lock_irq(shost->host_lock);
431 ndlp->nlp_flag |= NLP_RM_DFLT_RPI;
432 spin_unlock_irq(shost->host_lock);
433 stat.un.b.lsRjtRsnCode = LSRJT_INVALID_CMD;
434 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
435 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb,
436 ndlp, mbox);
437 return 1;
438 }
James Smart51ef4c22007-08-02 11:10:31 -0400439 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp, mbox);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500440 return 1;
dea31012005-04-17 16:05:31 -0500441out:
442 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
443 stat.un.b.lsRjtRsnCodeExp = LSEXP_OUT_OF_RESOURCE;
James Smart858c9f62007-06-17 19:56:39 -0500444 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500445 return 0;
dea31012005-04-17 16:05:31 -0500446}
447
448static int
James Smart2e0fef82007-06-17 19:56:36 -0500449lpfc_rcv_padisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -0500450 struct lpfc_iocbq *cmdiocb)
451{
James Smart2e0fef82007-06-17 19:56:36 -0500452 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -0500453 struct lpfc_dmabuf *pcmd;
James Smart2e0fef82007-06-17 19:56:36 -0500454 struct serv_parm *sp;
455 struct lpfc_name *pnn, *ppn;
dea31012005-04-17 16:05:31 -0500456 struct ls_rjt stat;
457 ADISC *ap;
458 IOCB_t *icmd;
459 uint32_t *lp;
460 uint32_t cmd;
461
462 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
463 lp = (uint32_t *) pcmd->virt;
464
465 cmd = *lp++;
466 if (cmd == ELS_CMD_ADISC) {
467 ap = (ADISC *) lp;
468 pnn = (struct lpfc_name *) & ap->nodeName;
469 ppn = (struct lpfc_name *) & ap->portName;
470 } else {
471 sp = (struct serv_parm *) lp;
472 pnn = (struct lpfc_name *) & sp->nodeName;
473 ppn = (struct lpfc_name *) & sp->portName;
474 }
475
476 icmd = &cmdiocb->iocb;
James Smart2e0fef82007-06-17 19:56:36 -0500477 if (icmd->ulpStatus == 0 && lpfc_check_adisc(vport, ndlp, pnn, ppn)) {
dea31012005-04-17 16:05:31 -0500478 if (cmd == ELS_CMD_ADISC) {
James Smart2e0fef82007-06-17 19:56:36 -0500479 lpfc_els_rsp_adisc_acc(vport, cmdiocb, ndlp);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500480 } else {
James Smart2e0fef82007-06-17 19:56:36 -0500481 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp,
James Smart51ef4c22007-08-02 11:10:31 -0400482 NULL);
dea31012005-04-17 16:05:31 -0500483 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500484 return 1;
dea31012005-04-17 16:05:31 -0500485 }
486 /* Reject this request because invalid parameters */
487 stat.un.b.lsRjtRsvd0 = 0;
488 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
489 stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
490 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -0500491 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -0500492
dea31012005-04-17 16:05:31 -0500493 /* 1 sec timeout */
494 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ);
495
James Smart2e0fef82007-06-17 19:56:36 -0500496 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500497 ndlp->nlp_flag |= NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -0500498 spin_unlock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -0500499 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
500 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -0500501 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500502 return 0;
dea31012005-04-17 16:05:31 -0500503}
504
505static int
James Smart2e0fef82007-06-17 19:56:36 -0500506lpfc_rcv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
507 struct lpfc_iocbq *cmdiocb, uint32_t els_cmd)
dea31012005-04-17 16:05:31 -0500508{
James Smart2e0fef82007-06-17 19:56:36 -0500509 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart4b40c592010-03-15 11:25:44 -0400510 struct lpfc_hba *phba = vport->phba;
511 struct lpfc_vport **vports;
512 int i, active_vlink_present = 0 ;
James Smart2e0fef82007-06-17 19:56:36 -0500513
514 /* Put ndlp in NPR state with 1 sec timeout for plogi, ACC logo */
dea31012005-04-17 16:05:31 -0500515 /* Only call LOGO ACC for first LOGO, this avoids sending unnecessary
516 * PLOGIs during LOGO storms from a device.
517 */
James Smart2e0fef82007-06-17 19:56:36 -0500518 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500519 ndlp->nlp_flag |= NLP_LOGO_ACC;
James Smart2e0fef82007-06-17 19:56:36 -0500520 spin_unlock_irq(shost->host_lock);
James Smart82d9a2a2006-04-15 11:53:05 -0400521 if (els_cmd == ELS_CMD_PRLO)
James Smart51ef4c22007-08-02 11:10:31 -0400522 lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL);
James Smart82d9a2a2006-04-15 11:53:05 -0400523 else
James Smart51ef4c22007-08-02 11:10:31 -0400524 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
James Smart4b40c592010-03-15 11:25:44 -0400525 if (ndlp->nlp_DID == Fabric_DID) {
526 if (vport->port_state <= LPFC_FDISC)
527 goto out;
James Smart6fb120a2009-05-22 14:52:59 -0400528 lpfc_linkdown_port(vport);
James Smart6fb120a2009-05-22 14:52:59 -0400529 spin_lock_irq(shost->host_lock);
James Smart4b40c592010-03-15 11:25:44 -0400530 vport->fc_flag |= FC_VPORT_LOGO_RCVD;
James Smart6fb120a2009-05-22 14:52:59 -0400531 spin_unlock_irq(shost->host_lock);
James Smart4b40c592010-03-15 11:25:44 -0400532 vports = lpfc_create_vport_work_array(phba);
533 if (vports) {
534 for (i = 0; i <= phba->max_vports && vports[i] != NULL;
535 i++) {
536 if ((!(vports[i]->fc_flag &
537 FC_VPORT_LOGO_RCVD)) &&
538 (vports[i]->port_state > LPFC_FDISC)) {
539 active_vlink_present = 1;
540 break;
541 }
542 }
543 lpfc_destroy_vport_work_array(phba, vports);
544 }
dea31012005-04-17 16:05:31 -0500545
James Smart4b40c592010-03-15 11:25:44 -0400546 if (active_vlink_present) {
547 /*
548 * If there are other active VLinks present,
549 * re-instantiate the Vlink using FDISC.
550 */
551 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ);
552 spin_lock_irq(shost->host_lock);
553 ndlp->nlp_flag |= NLP_DELAY_TMO;
554 spin_unlock_irq(shost->host_lock);
555 ndlp->nlp_last_elscmd = ELS_CMD_FDISC;
556 vport->port_state = LPFC_FDISC;
557 } else {
558 spin_lock_irq(shost->host_lock);
559 phba->pport->fc_flag &= ~FC_LOGO_RCVD_DID_CHNG;
560 spin_unlock_irq(shost->host_lock);
561 lpfc_retry_pport_discovery(phba);
562 }
James Smart6fb120a2009-05-22 14:52:59 -0400563 } else if ((!(ndlp->nlp_type & NLP_FABRIC) &&
564 ((ndlp->nlp_type & NLP_FCP_TARGET) ||
565 !(ndlp->nlp_type & NLP_FCP_INITIATOR))) ||
566 (ndlp->nlp_state == NLP_STE_ADISC_ISSUE)) {
dea31012005-04-17 16:05:31 -0500567 /* Only try to re-login if this is NOT a Fabric Node */
dea31012005-04-17 16:05:31 -0500568 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ * 1);
James Smart2e0fef82007-06-17 19:56:36 -0500569 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500570 ndlp->nlp_flag |= NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -0500571 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500572
Jamie Wellnitz5024ab12006-02-28 19:25:28 -0500573 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
dea31012005-04-17 16:05:31 -0500574 }
James Smart4b40c592010-03-15 11:25:44 -0400575out:
James Smart87af33f2007-10-27 13:37:43 -0400576 ndlp->nlp_prev_state = ndlp->nlp_state;
577 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
dea31012005-04-17 16:05:31 -0500578
James Smart2e0fef82007-06-17 19:56:36 -0500579 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500580 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
James Smart2e0fef82007-06-17 19:56:36 -0500581 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500582 /* The driver has to wait until the ACC completes before it continues
583 * processing the LOGO. The action will resume in
584 * lpfc_cmpl_els_logo_acc routine. Since part of processing includes an
585 * unreg_login, the driver waits so the ACC does not get aborted.
586 */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500587 return 0;
dea31012005-04-17 16:05:31 -0500588}
589
590static void
James Smart2e0fef82007-06-17 19:56:36 -0500591lpfc_rcv_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
592 struct lpfc_iocbq *cmdiocb)
dea31012005-04-17 16:05:31 -0500593{
594 struct lpfc_dmabuf *pcmd;
595 uint32_t *lp;
596 PRLI *npr;
597 struct fc_rport *rport = ndlp->rport;
598 u32 roles;
599
600 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
601 lp = (uint32_t *) pcmd->virt;
602 npr = (PRLI *) ((uint8_t *) lp + sizeof (uint32_t));
603
604 ndlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR);
605 ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
James Smart92d7f7b2007-06-17 19:56:38 -0500606 if (npr->prliType == PRLI_FCP_TYPE) {
dea31012005-04-17 16:05:31 -0500607 if (npr->initiatorFunc)
608 ndlp->nlp_type |= NLP_FCP_INITIATOR;
609 if (npr->targetFunc)
610 ndlp->nlp_type |= NLP_FCP_TARGET;
611 if (npr->Retry)
612 ndlp->nlp_fcp_info |= NLP_FCP_2_DEVICE;
613 }
614 if (rport) {
615 /* We need to update the rport role values */
616 roles = FC_RPORT_ROLE_UNKNOWN;
617 if (ndlp->nlp_type & NLP_FCP_INITIATOR)
618 roles |= FC_RPORT_ROLE_FCP_INITIATOR;
619 if (ndlp->nlp_type & NLP_FCP_TARGET)
620 roles |= FC_RPORT_ROLE_FCP_TARGET;
James Smart858c9f62007-06-17 19:56:39 -0500621
622 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
623 "rport rolechg: role:x%x did:x%x flg:x%x",
624 roles, ndlp->nlp_DID, ndlp->nlp_flag);
625
dea31012005-04-17 16:05:31 -0500626 fc_remote_port_rolechg(rport, roles);
627 }
628}
629
630static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -0500631lpfc_disc_set_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -0500632{
James Smart2e0fef82007-06-17 19:56:36 -0500633 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart2e0fef82007-06-17 19:56:36 -0500634
James Smart40426292010-12-15 17:58:10 -0500635 if (!(ndlp->nlp_flag & NLP_RPI_REGISTERED)) {
James Smart51ef4c22007-08-02 11:10:31 -0400636 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
637 return 0;
638 }
639
James Smart1b32f6a2008-02-08 18:49:39 -0500640 if (!(vport->fc_flag & FC_PT2PT)) {
641 /* Check config parameter use-adisc or FCP-2 */
642 if ((vport->cfg_use_adisc && (vport->fc_flag & FC_RSCN_MODE)) ||
James Smartffc95492010-06-07 15:23:17 -0400643 ((ndlp->nlp_fcp_info & NLP_FCP_2_DEVICE) &&
644 (ndlp->nlp_type & NLP_FCP_TARGET))) {
James Smart1b32f6a2008-02-08 18:49:39 -0500645 spin_lock_irq(shost->host_lock);
646 ndlp->nlp_flag |= NLP_NPR_ADISC;
647 spin_unlock_irq(shost->host_lock);
648 return 1;
649 }
James Smart92d7f7b2007-06-17 19:56:38 -0500650 }
651 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
652 lpfc_unreg_rpi(vport, ndlp);
653 return 0;
dea31012005-04-17 16:05:31 -0500654}
James Smart6d368e52011-05-24 11:44:12 -0400655
James Smart78730cf2010-04-06 15:06:30 -0400656/**
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300657 * lpfc_release_rpi - Release a RPI by issuing unreg_login mailbox cmd.
James Smart78730cf2010-04-06 15:06:30 -0400658 * @phba : Pointer to lpfc_hba structure.
659 * @vport: Pointer to lpfc_vport structure.
660 * @rpi : rpi to be release.
661 *
662 * This function will send a unreg_login mailbox command to the firmware
663 * to release a rpi.
664 **/
665void
666lpfc_release_rpi(struct lpfc_hba *phba,
667 struct lpfc_vport *vport,
668 uint16_t rpi)
669{
670 LPFC_MBOXQ_t *pmb;
671 int rc;
672
673 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
674 GFP_KERNEL);
675 if (!pmb)
676 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
677 "2796 mailbox memory allocation failed \n");
678 else {
679 lpfc_unreg_login(phba, vport->vpi, rpi, pmb);
680 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
681 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
682 if (rc == MBX_NOT_FINISHED)
683 mempool_free(pmb, phba->mbox_mem_pool);
684 }
685}
dea31012005-04-17 16:05:31 -0500686
687static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -0500688lpfc_disc_illegal(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
689 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -0500690{
James Smart78730cf2010-04-06 15:06:30 -0400691 struct lpfc_hba *phba;
692 LPFC_MBOXQ_t *pmb = (LPFC_MBOXQ_t *) arg;
693 MAILBOX_t *mb;
694 uint16_t rpi;
695
696 phba = vport->phba;
697 /* Release the RPI if reglogin completing */
698 if (!(phba->pport->load_flag & FC_UNLOADING) &&
699 (evt == NLP_EVT_CMPL_REG_LOGIN) &&
700 (!pmb->u.mb.mbxStatus)) {
701 mb = &pmb->u.mb;
702 rpi = pmb->u.mb.un.varWords[0];
703 lpfc_release_rpi(phba, vport, rpi);
704 }
James Smarte8b62012007-08-02 11:10:09 -0400705 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
James Smarte47c9092008-02-08 18:49:26 -0500706 "0271 Illegal State Transition: node x%x "
James Smarte8b62012007-08-02 11:10:09 -0400707 "event x%x, state x%x Data: x%x x%x\n",
708 ndlp->nlp_DID, evt, ndlp->nlp_state, ndlp->nlp_rpi,
709 ndlp->nlp_flag);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500710 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -0500711}
712
James Smart87af33f2007-10-27 13:37:43 -0400713static uint32_t
714lpfc_cmpl_plogi_illegal(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
715 void *arg, uint32_t evt)
716{
717 /* This transition is only legal if we previously
718 * rcv'ed a PLOGI. Since we don't want 2 discovery threads
719 * working on the same NPortID, do nothing for this thread
720 * to stop it.
721 */
722 if (!(ndlp->nlp_flag & NLP_RCV_PLOGI)) {
723 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
James Smarte47c9092008-02-08 18:49:26 -0500724 "0272 Illegal State Transition: node x%x "
James Smart87af33f2007-10-27 13:37:43 -0400725 "event x%x, state x%x Data: x%x x%x\n",
726 ndlp->nlp_DID, evt, ndlp->nlp_state, ndlp->nlp_rpi,
727 ndlp->nlp_flag);
728 }
729 return ndlp->nlp_state;
730}
731
dea31012005-04-17 16:05:31 -0500732/* Start of Discovery State Machine routines */
733
734static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -0500735lpfc_rcv_plogi_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
736 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -0500737{
738 struct lpfc_iocbq *cmdiocb;
739
740 cmdiocb = (struct lpfc_iocbq *) arg;
741
James Smart2e0fef82007-06-17 19:56:36 -0500742 if (lpfc_rcv_plogi(vport, ndlp, cmdiocb)) {
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500743 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -0500744 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500745 return NLP_STE_FREED_NODE;
dea31012005-04-17 16:05:31 -0500746}
747
748static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -0500749lpfc_rcv_els_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
750 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -0500751{
James Smart2e0fef82007-06-17 19:56:36 -0500752 lpfc_issue_els_logo(vport, ndlp, 0);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500753 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -0500754}
755
756static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -0500757lpfc_rcv_logo_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
758 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -0500759{
James Smart2e0fef82007-06-17 19:56:36 -0500760 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
761 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -0500762
James Smart2e0fef82007-06-17 19:56:36 -0500763 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500764 ndlp->nlp_flag |= NLP_LOGO_ACC;
James Smart2e0fef82007-06-17 19:56:36 -0500765 spin_unlock_irq(shost->host_lock);
James Smart51ef4c22007-08-02 11:10:31 -0400766 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -0500767
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500768 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -0500769}
770
771static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -0500772lpfc_cmpl_logo_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -0500773 void *arg, uint32_t evt)
774{
James Smart2e0fef82007-06-17 19:56:36 -0500775 return NLP_STE_FREED_NODE;
776}
777
778static uint32_t
779lpfc_device_rm_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
780 void *arg, uint32_t evt)
781{
James Smart2e0fef82007-06-17 19:56:36 -0500782 return NLP_STE_FREED_NODE;
783}
784
785static uint32_t
786lpfc_rcv_plogi_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
787 void *arg, uint32_t evt)
788{
James Smart0d2b6b82008-06-14 22:52:47 -0400789 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart2e0fef82007-06-17 19:56:36 -0500790 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500791 struct lpfc_iocbq *cmdiocb = arg;
James Smart2e0fef82007-06-17 19:56:36 -0500792 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
793 uint32_t *lp = (uint32_t *) pcmd->virt;
794 struct serv_parm *sp = (struct serv_parm *) (lp + 1);
dea31012005-04-17 16:05:31 -0500795 struct ls_rjt stat;
796 int port_cmp;
797
dea31012005-04-17 16:05:31 -0500798 memset(&stat, 0, sizeof (struct ls_rjt));
799
800 /* For a PLOGI, we only accept if our portname is less
801 * than the remote portname.
802 */
803 phba->fc_stat.elsLogiCol++;
James Smart2e0fef82007-06-17 19:56:36 -0500804 port_cmp = memcmp(&vport->fc_portname, &sp->portName,
James Smart92d7f7b2007-06-17 19:56:38 -0500805 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -0500806
807 if (port_cmp >= 0) {
808 /* Reject this request because the remote node will accept
809 ours */
810 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
811 stat.un.b.lsRjtRsnCodeExp = LSEXP_CMD_IN_PROGRESS;
James Smart858c9f62007-06-17 19:56:39 -0500812 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
813 NULL);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500814 } else {
James Smart0d2b6b82008-06-14 22:52:47 -0400815 if (lpfc_rcv_plogi(vport, ndlp, cmdiocb) &&
816 (ndlp->nlp_flag & NLP_NPR_2B_DISC) &&
817 (vport->num_disc_nodes)) {
818 spin_lock_irq(shost->host_lock);
819 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
820 spin_unlock_irq(shost->host_lock);
821 /* Check if there are more PLOGIs to be sent */
822 lpfc_more_plogi(vport);
823 if (vport->num_disc_nodes == 0) {
824 spin_lock_irq(shost->host_lock);
825 vport->fc_flag &= ~FC_NDISC_ACTIVE;
826 spin_unlock_irq(shost->host_lock);
827 lpfc_can_disctmo(vport);
828 lpfc_end_rscn(vport);
829 }
830 }
James Smart2e0fef82007-06-17 19:56:36 -0500831 } /* If our portname was less */
dea31012005-04-17 16:05:31 -0500832
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500833 return ndlp->nlp_state;
834}
835
836static uint32_t
James Smart92d7f7b2007-06-17 19:56:38 -0500837lpfc_rcv_prli_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
838 void *arg, uint32_t evt)
839{
840 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
841 struct ls_rjt stat;
842
843 memset(&stat, 0, sizeof (struct ls_rjt));
844 stat.un.b.lsRjtRsnCode = LSRJT_LOGICAL_BSY;
845 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
James Smart858c9f62007-06-17 19:56:39 -0500846 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
James Smart92d7f7b2007-06-17 19:56:38 -0500847 return ndlp->nlp_state;
848}
849
850static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -0500851lpfc_rcv_logo_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
852 void *arg, uint32_t evt)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500853{
James Smart2e0fef82007-06-17 19:56:36 -0500854 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500855
James Smart92d7f7b2007-06-17 19:56:38 -0500856 /* software abort outstanding PLOGI */
James Smart2e0fef82007-06-17 19:56:36 -0500857 lpfc_els_abort(vport->phba, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500858
James Smart2e0fef82007-06-17 19:56:36 -0500859 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500860 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -0500861}
862
863static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -0500864lpfc_rcv_els_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
865 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -0500866{
James Smart2e0fef82007-06-17 19:56:36 -0500867 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
868 struct lpfc_hba *phba = vport->phba;
869 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -0500870
871 /* software abort outstanding PLOGI */
James Smart07951072007-04-25 09:51:38 -0400872 lpfc_els_abort(phba, ndlp);
dea31012005-04-17 16:05:31 -0500873
874 if (evt == NLP_EVT_RCV_LOGO) {
James Smart51ef4c22007-08-02 11:10:31 -0400875 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500876 } else {
James Smart2e0fef82007-06-17 19:56:36 -0500877 lpfc_issue_els_logo(vport, ndlp, 0);
dea31012005-04-17 16:05:31 -0500878 }
879
James Smart2e0fef82007-06-17 19:56:36 -0500880 /* Put ndlp in npr state set plogi timer for 1 sec */
Jamie Wellnitz5024ab12006-02-28 19:25:28 -0500881 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ * 1);
James Smart2e0fef82007-06-17 19:56:36 -0500882 spin_lock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -0500883 ndlp->nlp_flag |= NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -0500884 spin_unlock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -0500885 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
886 ndlp->nlp_prev_state = NLP_STE_PLOGI_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -0500887 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
dea31012005-04-17 16:05:31 -0500888
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500889 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -0500890}
891
892static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -0500893lpfc_cmpl_plogi_plogi_issue(struct lpfc_vport *vport,
894 struct lpfc_nodelist *ndlp,
895 void *arg,
dea31012005-04-17 16:05:31 -0500896 uint32_t evt)
897{
James Smart2e0fef82007-06-17 19:56:36 -0500898 struct lpfc_hba *phba = vport->phba;
James Smart0ff10d42008-01-11 01:52:36 -0500899 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart2e0fef82007-06-17 19:56:36 -0500900 struct lpfc_iocbq *cmdiocb, *rspiocb;
James Smart14691152006-12-02 13:34:28 -0500901 struct lpfc_dmabuf *pcmd, *prsp, *mp;
dea31012005-04-17 16:05:31 -0500902 uint32_t *lp;
903 IOCB_t *irsp;
904 struct serv_parm *sp;
905 LPFC_MBOXQ_t *mbox;
906
907 cmdiocb = (struct lpfc_iocbq *) arg;
908 rspiocb = cmdiocb->context_un.rsp_iocb;
909
910 if (ndlp->nlp_flag & NLP_ACC_REGLOGIN) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -0500911 /* Recovery from PLOGI collision logic */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500912 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -0500913 }
914
915 irsp = &rspiocb->iocb;
916
917 if (irsp->ulpStatus)
918 goto out;
919
920 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
921
James Smart2e0fef82007-06-17 19:56:36 -0500922 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
dea31012005-04-17 16:05:31 -0500923
James Smart2e0fef82007-06-17 19:56:36 -0500924 lp = (uint32_t *) prsp->virt;
dea31012005-04-17 16:05:31 -0500925 sp = (struct serv_parm *) ((uint8_t *) lp + sizeof (uint32_t));
James Smart58da1ff2008-04-07 10:15:56 -0400926
927 /* Some switches have FDMI servers returning 0 for WWN */
928 if ((ndlp->nlp_DID != FDMI_DID) &&
929 (wwn_to_u64(sp->portName.u.wwn) == 0 ||
930 wwn_to_u64(sp->nodeName.u.wwn) == 0)) {
James Smarta8adb832007-10-27 13:37:53 -0400931 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
932 "0142 PLOGI RSP: Invalid WWN.\n");
933 goto out;
934 }
James Smart341af102010-01-26 23:07:37 -0500935 if (!lpfc_check_sparm(vport, ndlp, sp, CLASS3, 0))
dea31012005-04-17 16:05:31 -0500936 goto out;
dea31012005-04-17 16:05:31 -0500937 /* PLOGI chkparm OK */
James Smarte8b62012007-08-02 11:10:09 -0400938 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
939 "0121 PLOGI chkparm OK Data: x%x x%x x%x x%x\n",
940 ndlp->nlp_DID, ndlp->nlp_state,
941 ndlp->nlp_flag, ndlp->nlp_rpi);
James Smart3de2a652007-08-02 11:09:59 -0400942 if (vport->cfg_fcp_class == 2 && (sp->cls2.classValid))
dea31012005-04-17 16:05:31 -0500943 ndlp->nlp_fcp_info |= CLASS2;
James Smart2e0fef82007-06-17 19:56:36 -0500944 else
dea31012005-04-17 16:05:31 -0500945 ndlp->nlp_fcp_info |= CLASS3;
James Smart2e0fef82007-06-17 19:56:36 -0500946
dea31012005-04-17 16:05:31 -0500947 ndlp->nlp_class_sup = 0;
948 if (sp->cls1.classValid)
949 ndlp->nlp_class_sup |= FC_COS_CLASS1;
950 if (sp->cls2.classValid)
951 ndlp->nlp_class_sup |= FC_COS_CLASS2;
952 if (sp->cls3.classValid)
953 ndlp->nlp_class_sup |= FC_COS_CLASS3;
954 if (sp->cls4.classValid)
955 ndlp->nlp_class_sup |= FC_COS_CLASS4;
956 ndlp->nlp_maxframe =
James Smart2e0fef82007-06-17 19:56:36 -0500957 ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) | sp->cmn.bbRcvSizeLsb;
dea31012005-04-17 16:05:31 -0500958
James Smart2e0fef82007-06-17 19:56:36 -0500959 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
James Smart92d7f7b2007-06-17 19:56:38 -0500960 if (!mbox) {
James Smarte8b62012007-08-02 11:10:09 -0400961 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
962 "0133 PLOGI: no memory for reg_login "
James Smart92d7f7b2007-06-17 19:56:38 -0500963 "Data: x%x x%x x%x x%x\n",
James Smart92d7f7b2007-06-17 19:56:38 -0500964 ndlp->nlp_DID, ndlp->nlp_state,
965 ndlp->nlp_flag, ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -0500966 goto out;
James Smart92d7f7b2007-06-17 19:56:38 -0500967 }
dea31012005-04-17 16:05:31 -0500968
James Smart2e0fef82007-06-17 19:56:36 -0500969 lpfc_unreg_rpi(vport, ndlp);
970
James Smart6fb120a2009-05-22 14:52:59 -0400971 if (lpfc_reg_rpi(phba, vport->vpi, irsp->un.elsreq64.remoteID,
James Smart40426292010-12-15 17:58:10 -0500972 (uint8_t *) sp, mbox, ndlp->nlp_rpi) == 0) {
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500973 switch (ndlp->nlp_DID) {
dea31012005-04-17 16:05:31 -0500974 case NameServer_DID:
James Smartde0c5b32007-04-25 09:52:27 -0400975 mbox->mbox_cmpl = lpfc_mbx_cmpl_ns_reg_login;
dea31012005-04-17 16:05:31 -0500976 break;
977 case FDMI_DID:
James Smartde0c5b32007-04-25 09:52:27 -0400978 mbox->mbox_cmpl = lpfc_mbx_cmpl_fdmi_reg_login;
dea31012005-04-17 16:05:31 -0500979 break;
980 default:
James Smartffc95492010-06-07 15:23:17 -0400981 ndlp->nlp_flag |= NLP_REG_LOGIN_SEND;
James Smartde0c5b32007-04-25 09:52:27 -0400982 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
dea31012005-04-17 16:05:31 -0500983 }
James Smart329f9bc2007-04-25 09:53:01 -0400984 mbox->context2 = lpfc_nlp_get(ndlp);
James Smart2e0fef82007-06-17 19:56:36 -0500985 mbox->vport = vport;
James Smart0b727fe2007-10-27 13:37:25 -0400986 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
dea31012005-04-17 16:05:31 -0500987 != MBX_NOT_FINISHED) {
James Smart2e0fef82007-06-17 19:56:36 -0500988 lpfc_nlp_set_state(vport, ndlp,
989 NLP_STE_REG_LOGIN_ISSUE);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500990 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -0500991 }
James Smartffc95492010-06-07 15:23:17 -0400992 if (ndlp->nlp_flag & NLP_REG_LOGIN_SEND)
993 ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND;
James Smartfa4066b2008-01-11 01:53:27 -0500994 /* decrement node reference count to the failed mbox
995 * command
996 */
James Smart329f9bc2007-04-25 09:53:01 -0400997 lpfc_nlp_put(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -0500998 mp = (struct lpfc_dmabuf *) mbox->context1;
James Smart14691152006-12-02 13:34:28 -0500999 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1000 kfree(mp);
dea31012005-04-17 16:05:31 -05001001 mempool_free(mbox, phba->mbox_mem_pool);
James Smart92d7f7b2007-06-17 19:56:38 -05001002
James Smarte8b62012007-08-02 11:10:09 -04001003 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1004 "0134 PLOGI: cannot issue reg_login "
1005 "Data: x%x x%x x%x x%x\n",
1006 ndlp->nlp_DID, ndlp->nlp_state,
1007 ndlp->nlp_flag, ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05001008 } else {
1009 mempool_free(mbox, phba->mbox_mem_pool);
James Smart92d7f7b2007-06-17 19:56:38 -05001010
James Smarte8b62012007-08-02 11:10:09 -04001011 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1012 "0135 PLOGI: cannot format reg_login "
1013 "Data: x%x x%x x%x x%x\n",
1014 ndlp->nlp_DID, ndlp->nlp_state,
1015 ndlp->nlp_flag, ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05001016 }
1017
1018
James Smart92d7f7b2007-06-17 19:56:38 -05001019out:
1020 if (ndlp->nlp_DID == NameServer_DID) {
1021 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04001022 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1023 "0261 Cannot Register NameServer login\n");
James Smart92d7f7b2007-06-17 19:56:38 -05001024 }
1025
James Smart0ff10d42008-01-11 01:52:36 -05001026 spin_lock_irq(shost->host_lock);
James Smarta8adb832007-10-27 13:37:53 -04001027 ndlp->nlp_flag |= NLP_DEFER_RM;
James Smart0ff10d42008-01-11 01:52:36 -05001028 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001029 return NLP_STE_FREED_NODE;
dea31012005-04-17 16:05:31 -05001030}
1031
1032static uint32_t
James Smart0ff10d42008-01-11 01:52:36 -05001033lpfc_cmpl_logo_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1034 void *arg, uint32_t evt)
1035{
1036 return ndlp->nlp_state;
1037}
1038
1039static uint32_t
1040lpfc_cmpl_reglogin_plogi_issue(struct lpfc_vport *vport,
1041 struct lpfc_nodelist *ndlp, void *arg, uint32_t evt)
1042{
James Smart78730cf2010-04-06 15:06:30 -04001043 struct lpfc_hba *phba;
1044 LPFC_MBOXQ_t *pmb = (LPFC_MBOXQ_t *) arg;
1045 MAILBOX_t *mb = &pmb->u.mb;
1046 uint16_t rpi;
1047
1048 phba = vport->phba;
1049 /* Release the RPI */
1050 if (!(phba->pport->load_flag & FC_UNLOADING) &&
1051 !mb->mbxStatus) {
1052 rpi = pmb->u.mb.un.varWords[0];
1053 lpfc_release_rpi(phba, vport, rpi);
1054 }
James Smart0ff10d42008-01-11 01:52:36 -05001055 return ndlp->nlp_state;
1056}
1057
1058static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001059lpfc_device_rm_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1060 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001061{
James Smart2e0fef82007-06-17 19:56:36 -05001062 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001063
James Smart2e0fef82007-06-17 19:56:36 -05001064 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1065 spin_lock_irq(shost->host_lock);
1066 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
1067 spin_unlock_irq(shost->host_lock);
1068 return ndlp->nlp_state;
1069 } else {
1070 /* software abort outstanding PLOGI */
1071 lpfc_els_abort(vport->phba, ndlp);
1072
1073 lpfc_drop_node(vport, ndlp);
James Smarta0f9b482006-04-15 11:52:56 -04001074 return NLP_STE_FREED_NODE;
1075 }
dea31012005-04-17 16:05:31 -05001076}
1077
1078static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001079lpfc_device_recov_plogi_issue(struct lpfc_vport *vport,
1080 struct lpfc_nodelist *ndlp,
1081 void *arg,
1082 uint32_t evt)
dea31012005-04-17 16:05:31 -05001083{
James Smart2e0fef82007-06-17 19:56:36 -05001084 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1085 struct lpfc_hba *phba = vport->phba;
1086
James Smart92d7f7b2007-06-17 19:56:38 -05001087 /* Don't do anything that will mess up processing of the
1088 * previous RSCN.
1089 */
1090 if (vport->fc_flag & FC_RSCN_DEFERRED)
1091 return ndlp->nlp_state;
1092
dea31012005-04-17 16:05:31 -05001093 /* software abort outstanding PLOGI */
James Smart07951072007-04-25 09:51:38 -04001094 lpfc_els_abort(phba, ndlp);
dea31012005-04-17 16:05:31 -05001095
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001096 ndlp->nlp_prev_state = NLP_STE_PLOGI_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -05001097 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
James Smart92d7f7b2007-06-17 19:56:38 -05001098 spin_lock_irq(shost->host_lock);
James Smarta0f9b482006-04-15 11:52:56 -04001099 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
James Smart2e0fef82007-06-17 19:56:36 -05001100 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001101
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001102 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001103}
1104
1105static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001106lpfc_rcv_plogi_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1107 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001108{
James Smart0d2b6b82008-06-14 22:52:47 -04001109 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart2e0fef82007-06-17 19:56:36 -05001110 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001111 struct lpfc_iocbq *cmdiocb;
1112
1113 /* software abort outstanding ADISC */
James Smart07951072007-04-25 09:51:38 -04001114 lpfc_els_abort(phba, ndlp);
dea31012005-04-17 16:05:31 -05001115
1116 cmdiocb = (struct lpfc_iocbq *) arg;
1117
James Smart0d2b6b82008-06-14 22:52:47 -04001118 if (lpfc_rcv_plogi(vport, ndlp, cmdiocb)) {
1119 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1120 spin_lock_irq(shost->host_lock);
1121 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
1122 spin_unlock_irq(shost->host_lock);
James Smart90160e02008-08-24 21:49:45 -04001123 if (vport->num_disc_nodes)
James Smart0d2b6b82008-06-14 22:52:47 -04001124 lpfc_more_adisc(vport);
James Smart0d2b6b82008-06-14 22:52:47 -04001125 }
1126 return ndlp->nlp_state;
1127 }
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001128 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -05001129 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
1130 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
dea31012005-04-17 16:05:31 -05001131
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001132 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001133}
1134
1135static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001136lpfc_rcv_prli_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1137 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001138{
James Smart2e0fef82007-06-17 19:56:36 -05001139 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001140
James Smart2e0fef82007-06-17 19:56:36 -05001141 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001142 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001143}
1144
1145static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001146lpfc_rcv_logo_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1147 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001148{
James Smart2e0fef82007-06-17 19:56:36 -05001149 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001150 struct lpfc_iocbq *cmdiocb;
1151
1152 cmdiocb = (struct lpfc_iocbq *) arg;
1153
1154 /* software abort outstanding ADISC */
James Smart07951072007-04-25 09:51:38 -04001155 lpfc_els_abort(phba, ndlp);
dea31012005-04-17 16:05:31 -05001156
James Smart2e0fef82007-06-17 19:56:36 -05001157 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001158 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001159}
1160
1161static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001162lpfc_rcv_padisc_adisc_issue(struct lpfc_vport *vport,
1163 struct lpfc_nodelist *ndlp,
1164 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001165{
1166 struct lpfc_iocbq *cmdiocb;
1167
1168 cmdiocb = (struct lpfc_iocbq *) arg;
1169
James Smart2e0fef82007-06-17 19:56:36 -05001170 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001171 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001172}
1173
1174static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001175lpfc_rcv_prlo_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1176 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001177{
1178 struct lpfc_iocbq *cmdiocb;
1179
1180 cmdiocb = (struct lpfc_iocbq *) arg;
1181
1182 /* Treat like rcv logo */
James Smart2e0fef82007-06-17 19:56:36 -05001183 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_PRLO);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001184 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001185}
1186
1187static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001188lpfc_cmpl_adisc_adisc_issue(struct lpfc_vport *vport,
1189 struct lpfc_nodelist *ndlp,
1190 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001191{
James Smart2e0fef82007-06-17 19:56:36 -05001192 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1193 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001194 struct lpfc_iocbq *cmdiocb, *rspiocb;
1195 IOCB_t *irsp;
1196 ADISC *ap;
James Smart6fb120a2009-05-22 14:52:59 -04001197 int rc;
dea31012005-04-17 16:05:31 -05001198
1199 cmdiocb = (struct lpfc_iocbq *) arg;
1200 rspiocb = cmdiocb->context_un.rsp_iocb;
1201
1202 ap = (ADISC *)lpfc_check_elscmpl_iocb(phba, cmdiocb, rspiocb);
1203 irsp = &rspiocb->iocb;
1204
1205 if ((irsp->ulpStatus) ||
James Smart92d7f7b2007-06-17 19:56:38 -05001206 (!lpfc_check_adisc(vport, ndlp, &ap->nodeName, &ap->portName))) {
dea31012005-04-17 16:05:31 -05001207 /* 1 sec timeout */
1208 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ);
James Smart2e0fef82007-06-17 19:56:36 -05001209 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001210 ndlp->nlp_flag |= NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05001211 spin_unlock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001212 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
dea31012005-04-17 16:05:31 -05001213
James Smart2e0fef82007-06-17 19:56:36 -05001214 memset(&ndlp->nlp_nodename, 0, sizeof(struct lpfc_name));
1215 memset(&ndlp->nlp_portname, 0, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05001216
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001217 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -05001218 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1219 lpfc_unreg_rpi(vport, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001220 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001221 }
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001222
James Smart6fb120a2009-05-22 14:52:59 -04001223 if (phba->sli_rev == LPFC_SLI_REV4) {
1224 rc = lpfc_sli4_resume_rpi(ndlp);
1225 if (rc) {
1226 /* Stay in state and retry. */
1227 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
1228 return ndlp->nlp_state;
1229 }
1230 }
1231
James.Smart@Emulex.Com25013222005-06-25 10:34:33 -04001232 if (ndlp->nlp_type & NLP_FCP_TARGET) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001233 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -05001234 lpfc_nlp_set_state(vport, ndlp, NLP_STE_MAPPED_NODE);
James.Smart@Emulex.Com25013222005-06-25 10:34:33 -04001235 } else {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001236 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -05001237 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
James.Smart@Emulex.Com25013222005-06-25 10:34:33 -04001238 }
James Smart6fb120a2009-05-22 14:52:59 -04001239
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001240 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001241}
1242
1243static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001244lpfc_device_rm_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1245 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001246{
James Smart2e0fef82007-06-17 19:56:36 -05001247 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001248
James Smart2e0fef82007-06-17 19:56:36 -05001249 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1250 spin_lock_irq(shost->host_lock);
1251 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
1252 spin_unlock_irq(shost->host_lock);
1253 return ndlp->nlp_state;
1254 } else {
1255 /* software abort outstanding ADISC */
1256 lpfc_els_abort(vport->phba, ndlp);
1257
1258 lpfc_drop_node(vport, ndlp);
James Smarta0f9b482006-04-15 11:52:56 -04001259 return NLP_STE_FREED_NODE;
1260 }
dea31012005-04-17 16:05:31 -05001261}
1262
1263static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001264lpfc_device_recov_adisc_issue(struct lpfc_vport *vport,
1265 struct lpfc_nodelist *ndlp,
1266 void *arg,
1267 uint32_t evt)
dea31012005-04-17 16:05:31 -05001268{
James Smart2e0fef82007-06-17 19:56:36 -05001269 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1270 struct lpfc_hba *phba = vport->phba;
1271
James Smart92d7f7b2007-06-17 19:56:38 -05001272 /* Don't do anything that will mess up processing of the
1273 * previous RSCN.
1274 */
1275 if (vport->fc_flag & FC_RSCN_DEFERRED)
1276 return ndlp->nlp_state;
1277
dea31012005-04-17 16:05:31 -05001278 /* software abort outstanding ADISC */
James Smart07951072007-04-25 09:51:38 -04001279 lpfc_els_abort(phba, ndlp);
dea31012005-04-17 16:05:31 -05001280
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001281 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -05001282 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1283 spin_lock_irq(shost->host_lock);
James Smarta0f9b482006-04-15 11:52:56 -04001284 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
James Smart2e0fef82007-06-17 19:56:36 -05001285 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05001286 lpfc_disc_set_adisc(vport, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001287 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001288}
1289
1290static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001291lpfc_rcv_plogi_reglogin_issue(struct lpfc_vport *vport,
1292 struct lpfc_nodelist *ndlp,
1293 void *arg,
dea31012005-04-17 16:05:31 -05001294 uint32_t evt)
1295{
James Smart2e0fef82007-06-17 19:56:36 -05001296 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001297
James Smart2e0fef82007-06-17 19:56:36 -05001298 lpfc_rcv_plogi(vport, ndlp, cmdiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001299 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001300}
1301
1302static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001303lpfc_rcv_prli_reglogin_issue(struct lpfc_vport *vport,
1304 struct lpfc_nodelist *ndlp,
1305 void *arg,
dea31012005-04-17 16:05:31 -05001306 uint32_t evt)
1307{
James Smart2e0fef82007-06-17 19:56:36 -05001308 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001309
James Smart2e0fef82007-06-17 19:56:36 -05001310 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001311 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001312}
1313
1314static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001315lpfc_rcv_logo_reglogin_issue(struct lpfc_vport *vport,
1316 struct lpfc_nodelist *ndlp,
1317 void *arg,
dea31012005-04-17 16:05:31 -05001318 uint32_t evt)
1319{
James Smart2e0fef82007-06-17 19:56:36 -05001320 struct lpfc_hba *phba = vport->phba;
1321 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
James Smart7054a602007-04-25 09:52:34 -04001322 LPFC_MBOXQ_t *mb;
1323 LPFC_MBOXQ_t *nextmb;
1324 struct lpfc_dmabuf *mp;
dea31012005-04-17 16:05:31 -05001325
1326 cmdiocb = (struct lpfc_iocbq *) arg;
1327
James Smart7054a602007-04-25 09:52:34 -04001328 /* cleanup any ndlp on mbox q waiting for reglogin cmpl */
1329 if ((mb = phba->sli.mbox_active)) {
James Smart04c68492009-05-22 14:52:52 -04001330 if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) &&
James Smart7054a602007-04-25 09:52:34 -04001331 (ndlp == (struct lpfc_nodelist *) mb->context2)) {
James Smart92d7f7b2007-06-17 19:56:38 -05001332 lpfc_nlp_put(ndlp);
James Smart7054a602007-04-25 09:52:34 -04001333 mb->context2 = NULL;
1334 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1335 }
1336 }
1337
James Smart2e0fef82007-06-17 19:56:36 -05001338 spin_lock_irq(&phba->hbalock);
James Smart7054a602007-04-25 09:52:34 -04001339 list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) {
James Smart04c68492009-05-22 14:52:52 -04001340 if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) &&
James Smart7054a602007-04-25 09:52:34 -04001341 (ndlp == (struct lpfc_nodelist *) mb->context2)) {
1342 mp = (struct lpfc_dmabuf *) (mb->context1);
1343 if (mp) {
James Smart98c9ea52007-10-27 13:37:33 -04001344 __lpfc_mbuf_free(phba, mp->virt, mp->phys);
James Smart7054a602007-04-25 09:52:34 -04001345 kfree(mp);
1346 }
James Smart92d7f7b2007-06-17 19:56:38 -05001347 lpfc_nlp_put(ndlp);
James Smart7054a602007-04-25 09:52:34 -04001348 list_del(&mb->list);
James Smart5ffc2662009-11-18 15:39:44 -05001349 phba->sli.mboxq_cnt--;
James Smart7054a602007-04-25 09:52:34 -04001350 mempool_free(mb, phba->mbox_mem_pool);
1351 }
1352 }
James Smart2e0fef82007-06-17 19:56:36 -05001353 spin_unlock_irq(&phba->hbalock);
James Smart7054a602007-04-25 09:52:34 -04001354
James Smart2e0fef82007-06-17 19:56:36 -05001355 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001356 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001357}
1358
1359static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001360lpfc_rcv_padisc_reglogin_issue(struct lpfc_vport *vport,
1361 struct lpfc_nodelist *ndlp,
1362 void *arg,
dea31012005-04-17 16:05:31 -05001363 uint32_t evt)
1364{
James Smart2e0fef82007-06-17 19:56:36 -05001365 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001366
James Smart2e0fef82007-06-17 19:56:36 -05001367 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001368 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001369}
1370
1371static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001372lpfc_rcv_prlo_reglogin_issue(struct lpfc_vport *vport,
1373 struct lpfc_nodelist *ndlp,
1374 void *arg,
dea31012005-04-17 16:05:31 -05001375 uint32_t evt)
1376{
1377 struct lpfc_iocbq *cmdiocb;
1378
1379 cmdiocb = (struct lpfc_iocbq *) arg;
James Smart51ef4c22007-08-02 11:10:31 -04001380 lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001381 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001382}
1383
1384static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001385lpfc_cmpl_reglogin_reglogin_issue(struct lpfc_vport *vport,
1386 struct lpfc_nodelist *ndlp,
1387 void *arg,
1388 uint32_t evt)
dea31012005-04-17 16:05:31 -05001389{
James Smart2e0fef82007-06-17 19:56:36 -05001390 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart2e0fef82007-06-17 19:56:36 -05001391 LPFC_MBOXQ_t *pmb = (LPFC_MBOXQ_t *) arg;
James Smart04c68492009-05-22 14:52:52 -04001392 MAILBOX_t *mb = &pmb->u.mb;
James Smart2e0fef82007-06-17 19:56:36 -05001393 uint32_t did = mb->un.varWords[1];
dea31012005-04-17 16:05:31 -05001394
dea31012005-04-17 16:05:31 -05001395 if (mb->mbxStatus) {
1396 /* RegLogin failed */
James Smarte8b62012007-08-02 11:10:09 -04001397 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
James Smart6d368e52011-05-24 11:44:12 -04001398 "0246 RegLogin failed Data: x%x x%x x%x x%x "
1399 "x%x\n",
1400 did, mb->mbxStatus, vport->port_state,
1401 mb->un.varRegLogin.vpi,
1402 mb->un.varRegLogin.rpi);
James Smartd0e56da2006-07-06 15:49:42 -04001403 /*
1404 * If RegLogin failed due to lack of HBA resources do not
1405 * retry discovery.
1406 */
1407 if (mb->mbxStatus == MBXERR_RPI_FULL) {
James Smart87af33f2007-10-27 13:37:43 -04001408 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
1409 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
James Smartd0e56da2006-07-06 15:49:42 -04001410 return ndlp->nlp_state;
1411 }
1412
James Smart2e0fef82007-06-17 19:56:36 -05001413 /* Put ndlp in npr state set plogi timer for 1 sec */
dea31012005-04-17 16:05:31 -05001414 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ * 1);
James Smart2e0fef82007-06-17 19:56:36 -05001415 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001416 ndlp->nlp_flag |= NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05001417 spin_unlock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001418 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
dea31012005-04-17 16:05:31 -05001419
James Smart2e0fef82007-06-17 19:56:36 -05001420 lpfc_issue_els_logo(vport, ndlp, 0);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001421 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -05001422 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001423 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001424 }
1425
James Smart6d368e52011-05-24 11:44:12 -04001426 /* SLI4 ports have preallocated logical rpis. */
1427 if (vport->phba->sli_rev < LPFC_SLI_REV4)
1428 ndlp->nlp_rpi = mb->un.varWords[0];
1429
James Smart40426292010-12-15 17:58:10 -05001430 ndlp->nlp_flag |= NLP_RPI_REGISTERED;
dea31012005-04-17 16:05:31 -05001431
1432 /* Only if we are not a fabric nport do we issue PRLI */
1433 if (!(ndlp->nlp_type & NLP_FABRIC)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001434 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -05001435 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
1436 lpfc_issue_els_prli(vport, ndlp, 0);
dea31012005-04-17 16:05:31 -05001437 } else {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001438 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -05001439 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
dea31012005-04-17 16:05:31 -05001440 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001441 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001442}
1443
1444static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001445lpfc_device_rm_reglogin_issue(struct lpfc_vport *vport,
1446 struct lpfc_nodelist *ndlp,
1447 void *arg,
dea31012005-04-17 16:05:31 -05001448 uint32_t evt)
1449{
James Smart2e0fef82007-06-17 19:56:36 -05001450 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1451
1452 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1453 spin_lock_irq(shost->host_lock);
James Smarta0f9b482006-04-15 11:52:56 -04001454 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
James Smart2e0fef82007-06-17 19:56:36 -05001455 spin_unlock_irq(shost->host_lock);
James Smarta0f9b482006-04-15 11:52:56 -04001456 return ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05001457 } else {
1458 lpfc_drop_node(vport, ndlp);
James Smarta0f9b482006-04-15 11:52:56 -04001459 return NLP_STE_FREED_NODE;
1460 }
dea31012005-04-17 16:05:31 -05001461}
1462
1463static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001464lpfc_device_recov_reglogin_issue(struct lpfc_vport *vport,
1465 struct lpfc_nodelist *ndlp,
1466 void *arg,
1467 uint32_t evt)
dea31012005-04-17 16:05:31 -05001468{
James Smart2e0fef82007-06-17 19:56:36 -05001469 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1470
James Smart92d7f7b2007-06-17 19:56:38 -05001471 /* Don't do anything that will mess up processing of the
1472 * previous RSCN.
1473 */
1474 if (vport->fc_flag & FC_RSCN_DEFERRED)
1475 return ndlp->nlp_state;
1476
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001477 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -05001478 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1479 spin_lock_irq(shost->host_lock);
James Smartffc95492010-06-07 15:23:17 -04001480 ndlp->nlp_flag |= NLP_IGNR_REG_CMPL;
James Smarta0f9b482006-04-15 11:52:56 -04001481 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
James Smart2e0fef82007-06-17 19:56:36 -05001482 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05001483 lpfc_disc_set_adisc(vport, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001484 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001485}
1486
1487static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001488lpfc_rcv_plogi_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1489 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001490{
1491 struct lpfc_iocbq *cmdiocb;
1492
1493 cmdiocb = (struct lpfc_iocbq *) arg;
1494
James Smart2e0fef82007-06-17 19:56:36 -05001495 lpfc_rcv_plogi(vport, ndlp, cmdiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001496 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001497}
1498
1499static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001500lpfc_rcv_prli_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1501 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001502{
James Smart2e0fef82007-06-17 19:56:36 -05001503 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001504
James Smart2e0fef82007-06-17 19:56:36 -05001505 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001506 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001507}
1508
1509static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001510lpfc_rcv_logo_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1511 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001512{
James Smart2e0fef82007-06-17 19:56:36 -05001513 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001514
1515 /* Software abort outstanding PRLI before sending acc */
James Smart2e0fef82007-06-17 19:56:36 -05001516 lpfc_els_abort(vport->phba, ndlp);
dea31012005-04-17 16:05:31 -05001517
James Smart2e0fef82007-06-17 19:56:36 -05001518 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001519 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001520}
1521
1522static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001523lpfc_rcv_padisc_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1524 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001525{
James Smart2e0fef82007-06-17 19:56:36 -05001526 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001527
James Smart2e0fef82007-06-17 19:56:36 -05001528 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001529 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001530}
1531
1532/* This routine is envoked when we rcv a PRLO request from a nport
1533 * we are logged into. We should send back a PRLO rsp setting the
1534 * appropriate bits.
1535 * NEXT STATE = PRLI_ISSUE
1536 */
1537static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001538lpfc_rcv_prlo_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1539 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001540{
James Smart2e0fef82007-06-17 19:56:36 -05001541 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001542
James Smart51ef4c22007-08-02 11:10:31 -04001543 lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001544 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001545}
1546
1547static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001548lpfc_cmpl_prli_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1549 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001550{
James Smart92d7f7b2007-06-17 19:56:38 -05001551 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001552 struct lpfc_iocbq *cmdiocb, *rspiocb;
James Smart2e0fef82007-06-17 19:56:36 -05001553 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001554 IOCB_t *irsp;
1555 PRLI *npr;
1556
1557 cmdiocb = (struct lpfc_iocbq *) arg;
1558 rspiocb = cmdiocb->context_un.rsp_iocb;
1559 npr = (PRLI *)lpfc_check_elscmpl_iocb(phba, cmdiocb, rspiocb);
1560
1561 irsp = &rspiocb->iocb;
1562 if (irsp->ulpStatus) {
James Smart858c9f62007-06-17 19:56:39 -05001563 if ((vport->port_type == LPFC_NPIV_PORT) &&
James Smart3de2a652007-08-02 11:09:59 -04001564 vport->cfg_restrict_login) {
James Smart858c9f62007-06-17 19:56:39 -05001565 goto out;
1566 }
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001567 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -05001568 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001569 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001570 }
1571
1572 /* Check out PRLI rsp */
1573 ndlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR);
1574 ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
1575 if ((npr->acceptRspCode == PRLI_REQ_EXECUTED) &&
1576 (npr->prliType == PRLI_FCP_TYPE)) {
1577 if (npr->initiatorFunc)
1578 ndlp->nlp_type |= NLP_FCP_INITIATOR;
1579 if (npr->targetFunc)
1580 ndlp->nlp_type |= NLP_FCP_TARGET;
1581 if (npr->Retry)
1582 ndlp->nlp_fcp_info |= NLP_FCP_2_DEVICE;
1583 }
James Smart92d7f7b2007-06-17 19:56:38 -05001584 if (!(ndlp->nlp_type & NLP_FCP_TARGET) &&
1585 (vport->port_type == LPFC_NPIV_PORT) &&
James Smart3de2a652007-08-02 11:09:59 -04001586 vport->cfg_restrict_login) {
James Smart858c9f62007-06-17 19:56:39 -05001587out:
James Smart92d7f7b2007-06-17 19:56:38 -05001588 spin_lock_irq(shost->host_lock);
1589 ndlp->nlp_flag |= NLP_TARGET_REMOVE;
1590 spin_unlock_irq(shost->host_lock);
1591 lpfc_issue_els_logo(vport, ndlp, 0);
1592
1593 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
James Smart87af33f2007-10-27 13:37:43 -04001594 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
James Smart92d7f7b2007-06-17 19:56:38 -05001595 return ndlp->nlp_state;
1596 }
dea31012005-04-17 16:05:31 -05001597
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001598 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
James Smart92d7f7b2007-06-17 19:56:38 -05001599 if (ndlp->nlp_type & NLP_FCP_TARGET)
1600 lpfc_nlp_set_state(vport, ndlp, NLP_STE_MAPPED_NODE);
1601 else
1602 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001603 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001604}
1605
1606/*! lpfc_device_rm_prli_issue
James Smart92d7f7b2007-06-17 19:56:38 -05001607 *
1608 * \pre
1609 * \post
1610 * \param phba
1611 * \param ndlp
1612 * \param arg
1613 * \param evt
1614 * \return uint32_t
1615 *
1616 * \b Description:
1617 * This routine is envoked when we a request to remove a nport we are in the
1618 * process of PRLIing. We should software abort outstanding prli, unreg
1619 * login, send a logout. We will change node state to UNUSED_NODE, put it
1620 * on plogi list so it can be freed when LOGO completes.
1621 *
1622 */
1623
dea31012005-04-17 16:05:31 -05001624static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001625lpfc_device_rm_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1626 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001627{
James Smart2e0fef82007-06-17 19:56:36 -05001628 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001629
James Smart2e0fef82007-06-17 19:56:36 -05001630 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1631 spin_lock_irq(shost->host_lock);
1632 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
1633 spin_unlock_irq(shost->host_lock);
1634 return ndlp->nlp_state;
1635 } else {
1636 /* software abort outstanding PLOGI */
1637 lpfc_els_abort(vport->phba, ndlp);
1638
1639 lpfc_drop_node(vport, ndlp);
James Smarta0f9b482006-04-15 11:52:56 -04001640 return NLP_STE_FREED_NODE;
1641 }
dea31012005-04-17 16:05:31 -05001642}
1643
1644
1645/*! lpfc_device_recov_prli_issue
James Smart92d7f7b2007-06-17 19:56:38 -05001646 *
1647 * \pre
1648 * \post
1649 * \param phba
1650 * \param ndlp
1651 * \param arg
1652 * \param evt
1653 * \return uint32_t
1654 *
1655 * \b Description:
1656 * The routine is envoked when the state of a device is unknown, like
1657 * during a link down. We should remove the nodelist entry from the
1658 * unmapped list, issue a UNREG_LOGIN, do a software abort of the
1659 * outstanding PRLI command, then free the node entry.
1660 */
dea31012005-04-17 16:05:31 -05001661static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001662lpfc_device_recov_prli_issue(struct lpfc_vport *vport,
1663 struct lpfc_nodelist *ndlp,
1664 void *arg,
1665 uint32_t evt)
dea31012005-04-17 16:05:31 -05001666{
James Smart2e0fef82007-06-17 19:56:36 -05001667 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1668 struct lpfc_hba *phba = vport->phba;
1669
James Smart92d7f7b2007-06-17 19:56:38 -05001670 /* Don't do anything that will mess up processing of the
1671 * previous RSCN.
1672 */
1673 if (vport->fc_flag & FC_RSCN_DEFERRED)
1674 return ndlp->nlp_state;
1675
dea31012005-04-17 16:05:31 -05001676 /* software abort outstanding PRLI */
James Smart07951072007-04-25 09:51:38 -04001677 lpfc_els_abort(phba, ndlp);
dea31012005-04-17 16:05:31 -05001678
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001679 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -05001680 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1681 spin_lock_irq(shost->host_lock);
James Smarta0f9b482006-04-15 11:52:56 -04001682 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
James Smart2e0fef82007-06-17 19:56:36 -05001683 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05001684 lpfc_disc_set_adisc(vport, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001685 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001686}
1687
1688static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001689lpfc_rcv_plogi_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1690 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001691{
James Smart2e0fef82007-06-17 19:56:36 -05001692 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001693
James Smart2e0fef82007-06-17 19:56:36 -05001694 lpfc_rcv_plogi(vport, ndlp, cmdiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001695 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001696}
1697
1698static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001699lpfc_rcv_prli_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1700 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001701{
James Smart2e0fef82007-06-17 19:56:36 -05001702 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001703
James Smart2e0fef82007-06-17 19:56:36 -05001704 lpfc_rcv_prli(vport, ndlp, cmdiocb);
1705 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001706 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001707}
1708
1709static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001710lpfc_rcv_logo_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1711 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001712{
James Smart2e0fef82007-06-17 19:56:36 -05001713 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001714
James Smart2e0fef82007-06-17 19:56:36 -05001715 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001716 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001717}
1718
1719static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001720lpfc_rcv_padisc_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1721 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001722{
James Smart2e0fef82007-06-17 19:56:36 -05001723 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001724
James Smart2e0fef82007-06-17 19:56:36 -05001725 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001726 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001727}
1728
1729static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001730lpfc_rcv_prlo_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1731 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001732{
James Smart2e0fef82007-06-17 19:56:36 -05001733 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001734
James Smart51ef4c22007-08-02 11:10:31 -04001735 lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001736 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001737}
1738
1739static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001740lpfc_device_recov_unmap_node(struct lpfc_vport *vport,
1741 struct lpfc_nodelist *ndlp,
1742 void *arg,
1743 uint32_t evt)
dea31012005-04-17 16:05:31 -05001744{
James Smart2e0fef82007-06-17 19:56:36 -05001745 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1746
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001747 ndlp->nlp_prev_state = NLP_STE_UNMAPPED_NODE;
James Smart2e0fef82007-06-17 19:56:36 -05001748 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1749 spin_lock_irq(shost->host_lock);
James Smarta0f9b482006-04-15 11:52:56 -04001750 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
James Smart2e0fef82007-06-17 19:56:36 -05001751 spin_unlock_irq(shost->host_lock);
1752 lpfc_disc_set_adisc(vport, ndlp);
dea31012005-04-17 16:05:31 -05001753
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001754 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001755}
1756
1757static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001758lpfc_rcv_plogi_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1759 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001760{
James Smart2e0fef82007-06-17 19:56:36 -05001761 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001762
James Smart2e0fef82007-06-17 19:56:36 -05001763 lpfc_rcv_plogi(vport, ndlp, cmdiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001764 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001765}
1766
1767static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001768lpfc_rcv_prli_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1769 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001770{
James Smart2e0fef82007-06-17 19:56:36 -05001771 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001772
James Smart2e0fef82007-06-17 19:56:36 -05001773 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001774 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001775}
1776
1777static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001778lpfc_rcv_logo_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1779 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001780{
James Smart2e0fef82007-06-17 19:56:36 -05001781 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001782
James Smart2e0fef82007-06-17 19:56:36 -05001783 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001784 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001785}
1786
1787static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001788lpfc_rcv_padisc_mapped_node(struct lpfc_vport *vport,
1789 struct lpfc_nodelist *ndlp,
1790 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001791{
James Smart2e0fef82007-06-17 19:56:36 -05001792 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001793
James Smart2e0fef82007-06-17 19:56:36 -05001794 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001795 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001796}
1797
1798static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001799lpfc_rcv_prlo_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1800 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001801{
James Smart2e0fef82007-06-17 19:56:36 -05001802 struct lpfc_hba *phba = vport->phba;
1803 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001804
1805 /* flush the target */
James Smart51ef4c22007-08-02 11:10:31 -04001806 lpfc_sli_abort_iocb(vport, &phba->sli.ring[phba->sli.fcp_ring],
1807 ndlp->nlp_sid, 0, LPFC_CTX_TGT);
dea31012005-04-17 16:05:31 -05001808
1809 /* Treat like rcv logo */
James Smart2e0fef82007-06-17 19:56:36 -05001810 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_PRLO);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001811 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001812}
1813
1814static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001815lpfc_device_recov_mapped_node(struct lpfc_vport *vport,
1816 struct lpfc_nodelist *ndlp,
1817 void *arg,
1818 uint32_t evt)
dea31012005-04-17 16:05:31 -05001819{
James Smart2e0fef82007-06-17 19:56:36 -05001820 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1821
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001822 ndlp->nlp_prev_state = NLP_STE_MAPPED_NODE;
James Smart2e0fef82007-06-17 19:56:36 -05001823 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1824 spin_lock_irq(shost->host_lock);
James Smarta0f9b482006-04-15 11:52:56 -04001825 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
James Smart2e0fef82007-06-17 19:56:36 -05001826 spin_unlock_irq(shost->host_lock);
1827 lpfc_disc_set_adisc(vport, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001828 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001829}
1830
1831static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001832lpfc_rcv_plogi_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1833 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001834{
James Smart2e0fef82007-06-17 19:56:36 -05001835 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1836 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001837
1838 /* Ignore PLOGI if we have an outstanding LOGO */
James Smart0d2b6b82008-06-14 22:52:47 -04001839 if (ndlp->nlp_flag & (NLP_LOGO_SND | NLP_LOGO_ACC))
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001840 return ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05001841 if (lpfc_rcv_plogi(vport, ndlp, cmdiocb)) {
James Smart0d2b6b82008-06-14 22:52:47 -04001842 lpfc_cancel_retry_delay_tmo(vport, ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05001843 spin_lock_irq(shost->host_lock);
James Smart0d2b6b82008-06-14 22:52:47 -04001844 ndlp->nlp_flag &= ~(NLP_NPR_ADISC | NLP_NPR_2B_DISC);
James Smart2e0fef82007-06-17 19:56:36 -05001845 spin_unlock_irq(shost->host_lock);
James Smart0d2b6b82008-06-14 22:52:47 -04001846 } else if (!(ndlp->nlp_flag & NLP_NPR_2B_DISC)) {
1847 /* send PLOGI immediately, move to PLOGI issue state */
1848 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
1849 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
1850 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
1851 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
1852 }
dea31012005-04-17 16:05:31 -05001853 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001854 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001855}
1856
1857static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001858lpfc_rcv_prli_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1859 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001860{
James Smart2e0fef82007-06-17 19:56:36 -05001861 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1862 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1863 struct ls_rjt stat;
dea31012005-04-17 16:05:31 -05001864
1865 memset(&stat, 0, sizeof (struct ls_rjt));
1866 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
1867 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
James Smart858c9f62007-06-17 19:56:39 -05001868 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05001869
1870 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
1871 if (ndlp->nlp_flag & NLP_NPR_ADISC) {
James Smart2e0fef82007-06-17 19:56:36 -05001872 spin_lock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001873 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001874 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
James Smart2e0fef82007-06-17 19:56:36 -05001875 spin_unlock_irq(shost->host_lock);
1876 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
1877 lpfc_issue_els_adisc(vport, ndlp, 0);
dea31012005-04-17 16:05:31 -05001878 } else {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001879 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
James Smart2e0fef82007-06-17 19:56:36 -05001880 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
1881 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
dea31012005-04-17 16:05:31 -05001882 }
1883 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001884 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001885}
1886
1887static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001888lpfc_rcv_logo_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1889 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001890{
James Smart2e0fef82007-06-17 19:56:36 -05001891 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001892
James Smart2e0fef82007-06-17 19:56:36 -05001893 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001894 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001895}
1896
1897static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001898lpfc_rcv_padisc_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1899 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001900{
James Smart2e0fef82007-06-17 19:56:36 -05001901 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001902
James Smart2e0fef82007-06-17 19:56:36 -05001903 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
James Smart33ccf8d2006-08-17 11:57:58 -04001904 /*
1905 * Do not start discovery if discovery is about to start
1906 * or discovery in progress for this node. Starting discovery
1907 * here will affect the counting of discovery threads.
1908 */
James Smart2fb9bd82006-12-02 13:33:57 -05001909 if (!(ndlp->nlp_flag & NLP_DELAY_TMO) &&
James Smart92d7f7b2007-06-17 19:56:38 -05001910 !(ndlp->nlp_flag & NLP_NPR_2B_DISC)) {
dea31012005-04-17 16:05:31 -05001911 if (ndlp->nlp_flag & NLP_NPR_ADISC) {
James Smart92d7f7b2007-06-17 19:56:38 -05001912 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001913 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
James Smart2e0fef82007-06-17 19:56:36 -05001914 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
1915 lpfc_issue_els_adisc(vport, ndlp, 0);
dea31012005-04-17 16:05:31 -05001916 } else {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001917 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
James Smart2e0fef82007-06-17 19:56:36 -05001918 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
1919 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
dea31012005-04-17 16:05:31 -05001920 }
1921 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001922 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001923}
1924
1925static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001926lpfc_rcv_prlo_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1927 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001928{
James Smart2e0fef82007-06-17 19:56:36 -05001929 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1930 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001931
James Smart2e0fef82007-06-17 19:56:36 -05001932 spin_lock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001933 ndlp->nlp_flag |= NLP_LOGO_ACC;
James Smart2e0fef82007-06-17 19:56:36 -05001934 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001935
James Smart51ef4c22007-08-02 11:10:31 -04001936 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05001937
James Smart2e0fef82007-06-17 19:56:36 -05001938 if ((ndlp->nlp_flag & NLP_DELAY_TMO) == 0) {
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001939 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ * 1);
James Smart2e0fef82007-06-17 19:56:36 -05001940 spin_lock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001941 ndlp->nlp_flag |= NLP_DELAY_TMO;
1942 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
James Smart2e0fef82007-06-17 19:56:36 -05001943 spin_unlock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001944 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001945 } else {
James Smart2e0fef82007-06-17 19:56:36 -05001946 spin_lock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001947 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
James Smart2e0fef82007-06-17 19:56:36 -05001948 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001949 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001950 return ndlp->nlp_state;
1951}
dea31012005-04-17 16:05:31 -05001952
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001953static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001954lpfc_cmpl_plogi_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1955 void *arg, uint32_t evt)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001956{
1957 struct lpfc_iocbq *cmdiocb, *rspiocb;
James Smarta0f9b482006-04-15 11:52:56 -04001958 IOCB_t *irsp;
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001959
1960 cmdiocb = (struct lpfc_iocbq *) arg;
1961 rspiocb = cmdiocb->context_un.rsp_iocb;
James Smarta0f9b482006-04-15 11:52:56 -04001962
1963 irsp = &rspiocb->iocb;
1964 if (irsp->ulpStatus) {
James Smarta8adb832007-10-27 13:37:53 -04001965 ndlp->nlp_flag |= NLP_DEFER_RM;
James Smarta0f9b482006-04-15 11:52:56 -04001966 return NLP_STE_FREED_NODE;
1967 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001968 return ndlp->nlp_state;
1969}
1970
1971static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001972lpfc_cmpl_prli_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1973 void *arg, uint32_t evt)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001974{
1975 struct lpfc_iocbq *cmdiocb, *rspiocb;
James Smarta0f9b482006-04-15 11:52:56 -04001976 IOCB_t *irsp;
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001977
1978 cmdiocb = (struct lpfc_iocbq *) arg;
1979 rspiocb = cmdiocb->context_un.rsp_iocb;
James Smarta0f9b482006-04-15 11:52:56 -04001980
1981 irsp = &rspiocb->iocb;
1982 if (irsp->ulpStatus && (ndlp->nlp_flag & NLP_NODEV_REMOVE)) {
James Smart2e0fef82007-06-17 19:56:36 -05001983 lpfc_drop_node(vport, ndlp);
James Smarta0f9b482006-04-15 11:52:56 -04001984 return NLP_STE_FREED_NODE;
1985 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001986 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001987}
1988
1989static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001990lpfc_cmpl_logo_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1991 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001992{
James Smartd7c255b2008-08-24 21:50:00 -04001993 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1994 if (ndlp->nlp_DID == Fabric_DID) {
1995 spin_lock_irq(shost->host_lock);
1996 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
1997 spin_unlock_irq(shost->host_lock);
1998 }
James Smart2e0fef82007-06-17 19:56:36 -05001999 lpfc_unreg_rpi(vport, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002000 return ndlp->nlp_state;
2001}
2002
2003static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05002004lpfc_cmpl_adisc_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2005 void *arg, uint32_t evt)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002006{
2007 struct lpfc_iocbq *cmdiocb, *rspiocb;
James Smarta0f9b482006-04-15 11:52:56 -04002008 IOCB_t *irsp;
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002009
2010 cmdiocb = (struct lpfc_iocbq *) arg;
2011 rspiocb = cmdiocb->context_un.rsp_iocb;
James Smarta0f9b482006-04-15 11:52:56 -04002012
2013 irsp = &rspiocb->iocb;
2014 if (irsp->ulpStatus && (ndlp->nlp_flag & NLP_NODEV_REMOVE)) {
James Smart2e0fef82007-06-17 19:56:36 -05002015 lpfc_drop_node(vport, ndlp);
James Smarta0f9b482006-04-15 11:52:56 -04002016 return NLP_STE_FREED_NODE;
2017 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002018 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05002019}
2020
2021static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05002022lpfc_cmpl_reglogin_npr_node(struct lpfc_vport *vport,
2023 struct lpfc_nodelist *ndlp,
2024 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05002025{
James Smart2e0fef82007-06-17 19:56:36 -05002026 LPFC_MBOXQ_t *pmb = (LPFC_MBOXQ_t *) arg;
James Smart04c68492009-05-22 14:52:52 -04002027 MAILBOX_t *mb = &pmb->u.mb;
dea31012005-04-17 16:05:31 -05002028
James Smart04c68492009-05-22 14:52:52 -04002029 if (!mb->mbxStatus) {
James Smart6d368e52011-05-24 11:44:12 -04002030 /* SLI4 ports have preallocated logical rpis. */
2031 if (vport->phba->sli_rev < LPFC_SLI_REV4)
2032 ndlp->nlp_rpi = mb->un.varWords[0];
James Smart40426292010-12-15 17:58:10 -05002033 ndlp->nlp_flag |= NLP_RPI_REGISTERED;
James Smart04c68492009-05-22 14:52:52 -04002034 } else {
James Smarta0f9b482006-04-15 11:52:56 -04002035 if (ndlp->nlp_flag & NLP_NODEV_REMOVE) {
James Smart2e0fef82007-06-17 19:56:36 -05002036 lpfc_drop_node(vport, ndlp);
James Smarta0f9b482006-04-15 11:52:56 -04002037 return NLP_STE_FREED_NODE;
2038 }
2039 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002040 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05002041}
2042
2043static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05002044lpfc_device_rm_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2045 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05002046{
James Smart2e0fef82007-06-17 19:56:36 -05002047 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2048
James Smarta0f9b482006-04-15 11:52:56 -04002049 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
James Smart2e0fef82007-06-17 19:56:36 -05002050 spin_lock_irq(shost->host_lock);
James Smarta0f9b482006-04-15 11:52:56 -04002051 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
James Smart2e0fef82007-06-17 19:56:36 -05002052 spin_unlock_irq(shost->host_lock);
James Smarta0f9b482006-04-15 11:52:56 -04002053 return ndlp->nlp_state;
2054 }
James Smart2e0fef82007-06-17 19:56:36 -05002055 lpfc_drop_node(vport, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002056 return NLP_STE_FREED_NODE;
dea31012005-04-17 16:05:31 -05002057}
2058
2059static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05002060lpfc_device_recov_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2061 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05002062{
James Smart2e0fef82007-06-17 19:56:36 -05002063 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2064
James Smart92d7f7b2007-06-17 19:56:38 -05002065 /* Don't do anything that will mess up processing of the
2066 * previous RSCN.
2067 */
2068 if (vport->fc_flag & FC_RSCN_DEFERRED)
2069 return ndlp->nlp_state;
2070
James Smarteaf15d52008-12-04 22:39:29 -05002071 lpfc_cancel_retry_delay_tmo(vport, ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05002072 spin_lock_irq(shost->host_lock);
James Smarta0f9b482006-04-15 11:52:56 -04002073 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
James Smart2e0fef82007-06-17 19:56:36 -05002074 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002075 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05002076}
2077
2078
2079/* This next section defines the NPort Discovery State Machine */
2080
2081/* There are 4 different double linked lists nodelist entries can reside on.
2082 * The plogi list and adisc list are used when Link Up discovery or RSCN
2083 * processing is needed. Each list holds the nodes that we will send PLOGI
2084 * or ADISC on. These lists will keep track of what nodes will be effected
2085 * by an RSCN, or a Link Up (Typically, all nodes are effected on Link Up).
2086 * The unmapped_list will contain all nodes that we have successfully logged
2087 * into at the Fibre Channel level. The mapped_list will contain all nodes
2088 * that are mapped FCP targets.
2089 */
2090/*
2091 * The bind list is a list of undiscovered (potentially non-existent) nodes
2092 * that we have saved binding information on. This information is used when
2093 * nodes transition from the unmapped to the mapped list.
2094 */
2095/* For UNUSED_NODE state, the node has just been allocated .
2096 * For PLOGI_ISSUE and REG_LOGIN_ISSUE, the node is on
2097 * the PLOGI list. For REG_LOGIN_COMPL, the node is taken off the PLOGI list
2098 * and put on the unmapped list. For ADISC processing, the node is taken off
2099 * the ADISC list and placed on either the mapped or unmapped list (depending
2100 * on its previous state). Once on the unmapped list, a PRLI is issued and the
2101 * state changed to PRLI_ISSUE. When the PRLI completion occurs, the state is
2102 * changed to UNMAPPED_NODE. If the completion indicates a mapped
2103 * node, the node is taken off the unmapped list. The binding list is checked
2104 * for a valid binding, or a binding is automatically assigned. If binding
2105 * assignment is unsuccessful, the node is left on the unmapped list. If
2106 * binding assignment is successful, the associated binding list entry (if
2107 * any) is removed, and the node is placed on the mapped list.
2108 */
2109/*
2110 * For a Link Down, all nodes on the ADISC, PLOGI, unmapped or mapped
James Smartc01f3202006-08-18 17:47:08 -04002111 * lists will receive a DEVICE_RECOVERY event. If the linkdown or devloss timers
dea31012005-04-17 16:05:31 -05002112 * expire, all effected nodes will receive a DEVICE_RM event.
2113 */
2114/*
2115 * For a Link Up or RSCN, all nodes will move from the mapped / unmapped lists
2116 * to either the ADISC or PLOGI list. After a Nameserver query or ALPA loopmap
2117 * check, additional nodes may be added or removed (via DEVICE_RM) to / from
2118 * the PLOGI or ADISC lists. Once the PLOGI and ADISC lists are populated,
2119 * we will first process the ADISC list. 32 entries are processed initially and
2120 * ADISC is initited for each one. Completions / Events for each node are
2121 * funnelled thru the state machine. As each node finishes ADISC processing, it
2122 * starts ADISC for any nodes waiting for ADISC processing. If no nodes are
2123 * waiting, and the ADISC list count is identically 0, then we are done. For
2124 * Link Up discovery, since all nodes on the PLOGI list are UNREG_LOGIN'ed, we
2125 * can issue a CLEAR_LA and reenable Link Events. Next we will process the PLOGI
2126 * list. 32 entries are processed initially and PLOGI is initited for each one.
2127 * Completions / Events for each node are funnelled thru the state machine. As
2128 * each node finishes PLOGI processing, it starts PLOGI for any nodes waiting
2129 * for PLOGI processing. If no nodes are waiting, and the PLOGI list count is
2130 * indentically 0, then we are done. We have now completed discovery / RSCN
2131 * handling. Upon completion, ALL nodes should be on either the mapped or
2132 * unmapped lists.
2133 */
2134
2135static uint32_t (*lpfc_disc_action[NLP_STE_MAX_STATE * NLP_EVT_MAX_EVENT])
James Smart2e0fef82007-06-17 19:56:36 -05002136 (struct lpfc_vport *, struct lpfc_nodelist *, void *, uint32_t) = {
dea31012005-04-17 16:05:31 -05002137 /* Action routine Event Current State */
2138 lpfc_rcv_plogi_unused_node, /* RCV_PLOGI UNUSED_NODE */
2139 lpfc_rcv_els_unused_node, /* RCV_PRLI */
2140 lpfc_rcv_logo_unused_node, /* RCV_LOGO */
2141 lpfc_rcv_els_unused_node, /* RCV_ADISC */
2142 lpfc_rcv_els_unused_node, /* RCV_PDISC */
2143 lpfc_rcv_els_unused_node, /* RCV_PRLO */
2144 lpfc_disc_illegal, /* CMPL_PLOGI */
2145 lpfc_disc_illegal, /* CMPL_PRLI */
2146 lpfc_cmpl_logo_unused_node, /* CMPL_LOGO */
2147 lpfc_disc_illegal, /* CMPL_ADISC */
2148 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2149 lpfc_device_rm_unused_node, /* DEVICE_RM */
2150 lpfc_disc_illegal, /* DEVICE_RECOVERY */
2151
2152 lpfc_rcv_plogi_plogi_issue, /* RCV_PLOGI PLOGI_ISSUE */
James Smart92d7f7b2007-06-17 19:56:38 -05002153 lpfc_rcv_prli_plogi_issue, /* RCV_PRLI */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002154 lpfc_rcv_logo_plogi_issue, /* RCV_LOGO */
dea31012005-04-17 16:05:31 -05002155 lpfc_rcv_els_plogi_issue, /* RCV_ADISC */
2156 lpfc_rcv_els_plogi_issue, /* RCV_PDISC */
2157 lpfc_rcv_els_plogi_issue, /* RCV_PRLO */
2158 lpfc_cmpl_plogi_plogi_issue, /* CMPL_PLOGI */
2159 lpfc_disc_illegal, /* CMPL_PRLI */
James Smart0ff10d42008-01-11 01:52:36 -05002160 lpfc_cmpl_logo_plogi_issue, /* CMPL_LOGO */
dea31012005-04-17 16:05:31 -05002161 lpfc_disc_illegal, /* CMPL_ADISC */
James Smart0ff10d42008-01-11 01:52:36 -05002162 lpfc_cmpl_reglogin_plogi_issue,/* CMPL_REG_LOGIN */
dea31012005-04-17 16:05:31 -05002163 lpfc_device_rm_plogi_issue, /* DEVICE_RM */
2164 lpfc_device_recov_plogi_issue, /* DEVICE_RECOVERY */
2165
2166 lpfc_rcv_plogi_adisc_issue, /* RCV_PLOGI ADISC_ISSUE */
2167 lpfc_rcv_prli_adisc_issue, /* RCV_PRLI */
2168 lpfc_rcv_logo_adisc_issue, /* RCV_LOGO */
2169 lpfc_rcv_padisc_adisc_issue, /* RCV_ADISC */
2170 lpfc_rcv_padisc_adisc_issue, /* RCV_PDISC */
2171 lpfc_rcv_prlo_adisc_issue, /* RCV_PRLO */
2172 lpfc_disc_illegal, /* CMPL_PLOGI */
2173 lpfc_disc_illegal, /* CMPL_PRLI */
2174 lpfc_disc_illegal, /* CMPL_LOGO */
2175 lpfc_cmpl_adisc_adisc_issue, /* CMPL_ADISC */
2176 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2177 lpfc_device_rm_adisc_issue, /* DEVICE_RM */
2178 lpfc_device_recov_adisc_issue, /* DEVICE_RECOVERY */
2179
2180 lpfc_rcv_plogi_reglogin_issue, /* RCV_PLOGI REG_LOGIN_ISSUE */
2181 lpfc_rcv_prli_reglogin_issue, /* RCV_PLOGI */
2182 lpfc_rcv_logo_reglogin_issue, /* RCV_LOGO */
2183 lpfc_rcv_padisc_reglogin_issue, /* RCV_ADISC */
2184 lpfc_rcv_padisc_reglogin_issue, /* RCV_PDISC */
2185 lpfc_rcv_prlo_reglogin_issue, /* RCV_PRLO */
James Smart87af33f2007-10-27 13:37:43 -04002186 lpfc_cmpl_plogi_illegal, /* CMPL_PLOGI */
dea31012005-04-17 16:05:31 -05002187 lpfc_disc_illegal, /* CMPL_PRLI */
2188 lpfc_disc_illegal, /* CMPL_LOGO */
2189 lpfc_disc_illegal, /* CMPL_ADISC */
2190 lpfc_cmpl_reglogin_reglogin_issue,/* CMPL_REG_LOGIN */
2191 lpfc_device_rm_reglogin_issue, /* DEVICE_RM */
2192 lpfc_device_recov_reglogin_issue,/* DEVICE_RECOVERY */
2193
2194 lpfc_rcv_plogi_prli_issue, /* RCV_PLOGI PRLI_ISSUE */
2195 lpfc_rcv_prli_prli_issue, /* RCV_PRLI */
2196 lpfc_rcv_logo_prli_issue, /* RCV_LOGO */
2197 lpfc_rcv_padisc_prli_issue, /* RCV_ADISC */
2198 lpfc_rcv_padisc_prli_issue, /* RCV_PDISC */
2199 lpfc_rcv_prlo_prli_issue, /* RCV_PRLO */
James Smart87af33f2007-10-27 13:37:43 -04002200 lpfc_cmpl_plogi_illegal, /* CMPL_PLOGI */
dea31012005-04-17 16:05:31 -05002201 lpfc_cmpl_prli_prli_issue, /* CMPL_PRLI */
2202 lpfc_disc_illegal, /* CMPL_LOGO */
2203 lpfc_disc_illegal, /* CMPL_ADISC */
2204 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2205 lpfc_device_rm_prli_issue, /* DEVICE_RM */
2206 lpfc_device_recov_prli_issue, /* DEVICE_RECOVERY */
2207
2208 lpfc_rcv_plogi_unmap_node, /* RCV_PLOGI UNMAPPED_NODE */
2209 lpfc_rcv_prli_unmap_node, /* RCV_PRLI */
2210 lpfc_rcv_logo_unmap_node, /* RCV_LOGO */
2211 lpfc_rcv_padisc_unmap_node, /* RCV_ADISC */
2212 lpfc_rcv_padisc_unmap_node, /* RCV_PDISC */
2213 lpfc_rcv_prlo_unmap_node, /* RCV_PRLO */
2214 lpfc_disc_illegal, /* CMPL_PLOGI */
2215 lpfc_disc_illegal, /* CMPL_PRLI */
2216 lpfc_disc_illegal, /* CMPL_LOGO */
2217 lpfc_disc_illegal, /* CMPL_ADISC */
2218 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2219 lpfc_disc_illegal, /* DEVICE_RM */
2220 lpfc_device_recov_unmap_node, /* DEVICE_RECOVERY */
2221
2222 lpfc_rcv_plogi_mapped_node, /* RCV_PLOGI MAPPED_NODE */
2223 lpfc_rcv_prli_mapped_node, /* RCV_PRLI */
2224 lpfc_rcv_logo_mapped_node, /* RCV_LOGO */
2225 lpfc_rcv_padisc_mapped_node, /* RCV_ADISC */
2226 lpfc_rcv_padisc_mapped_node, /* RCV_PDISC */
2227 lpfc_rcv_prlo_mapped_node, /* RCV_PRLO */
2228 lpfc_disc_illegal, /* CMPL_PLOGI */
2229 lpfc_disc_illegal, /* CMPL_PRLI */
2230 lpfc_disc_illegal, /* CMPL_LOGO */
2231 lpfc_disc_illegal, /* CMPL_ADISC */
2232 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2233 lpfc_disc_illegal, /* DEVICE_RM */
2234 lpfc_device_recov_mapped_node, /* DEVICE_RECOVERY */
2235
2236 lpfc_rcv_plogi_npr_node, /* RCV_PLOGI NPR_NODE */
2237 lpfc_rcv_prli_npr_node, /* RCV_PRLI */
2238 lpfc_rcv_logo_npr_node, /* RCV_LOGO */
2239 lpfc_rcv_padisc_npr_node, /* RCV_ADISC */
2240 lpfc_rcv_padisc_npr_node, /* RCV_PDISC */
2241 lpfc_rcv_prlo_npr_node, /* RCV_PRLO */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002242 lpfc_cmpl_plogi_npr_node, /* CMPL_PLOGI */
2243 lpfc_cmpl_prli_npr_node, /* CMPL_PRLI */
dea31012005-04-17 16:05:31 -05002244 lpfc_cmpl_logo_npr_node, /* CMPL_LOGO */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002245 lpfc_cmpl_adisc_npr_node, /* CMPL_ADISC */
dea31012005-04-17 16:05:31 -05002246 lpfc_cmpl_reglogin_npr_node, /* CMPL_REG_LOGIN */
2247 lpfc_device_rm_npr_node, /* DEVICE_RM */
2248 lpfc_device_recov_npr_node, /* DEVICE_RECOVERY */
2249};
2250
2251int
James Smart2e0fef82007-06-17 19:56:36 -05002252lpfc_disc_state_machine(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2253 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05002254{
2255 uint32_t cur_state, rc;
James Smart2e0fef82007-06-17 19:56:36 -05002256 uint32_t(*func) (struct lpfc_vport *, struct lpfc_nodelist *, void *,
dea31012005-04-17 16:05:31 -05002257 uint32_t);
James Smarte47c9092008-02-08 18:49:26 -05002258 uint32_t got_ndlp = 0;
dea31012005-04-17 16:05:31 -05002259
James Smarte47c9092008-02-08 18:49:26 -05002260 if (lpfc_nlp_get(ndlp))
2261 got_ndlp = 1;
2262
dea31012005-04-17 16:05:31 -05002263 cur_state = ndlp->nlp_state;
2264
2265 /* DSM in event <evt> on NPort <nlp_DID> in state <cur_state> */
James Smarte8b62012007-08-02 11:10:09 -04002266 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2267 "0211 DSM in event x%x on NPort x%x in "
2268 "state %d Data: x%x\n",
2269 evt, ndlp->nlp_DID, cur_state, ndlp->nlp_flag);
dea31012005-04-17 16:05:31 -05002270
James Smart858c9f62007-06-17 19:56:39 -05002271 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_DSM,
2272 "DSM in: evt:%d ste:%d did:x%x",
2273 evt, cur_state, ndlp->nlp_DID);
2274
dea31012005-04-17 16:05:31 -05002275 func = lpfc_disc_action[(cur_state * NLP_EVT_MAX_EVENT) + evt];
James Smart2e0fef82007-06-17 19:56:36 -05002276 rc = (func) (vport, ndlp, arg, evt);
dea31012005-04-17 16:05:31 -05002277
2278 /* DSM out state <rc> on NPort <nlp_DID> */
James Smarte47c9092008-02-08 18:49:26 -05002279 if (got_ndlp) {
2280 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
James Smarte8b62012007-08-02 11:10:09 -04002281 "0212 DSM out state %d on NPort x%x Data: x%x\n",
2282 rc, ndlp->nlp_DID, ndlp->nlp_flag);
dea31012005-04-17 16:05:31 -05002283
James Smarte47c9092008-02-08 18:49:26 -05002284 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_DSM,
2285 "DSM out: ste:%d did:x%x flg:x%x",
2286 rc, ndlp->nlp_DID, ndlp->nlp_flag);
2287 /* Decrement the ndlp reference count held for this function */
2288 lpfc_nlp_put(ndlp);
2289 } else {
2290 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
James Smartd7c255b2008-08-24 21:50:00 -04002291 "0213 DSM out state %d on NPort free\n", rc);
James Smart858c9f62007-06-17 19:56:39 -05002292
James Smarte47c9092008-02-08 18:49:26 -05002293 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_DSM,
2294 "DSM out: ste:%d did:x%x flg:x%x",
2295 rc, 0, 0);
2296 }
dea31012005-04-17 16:05:31 -05002297
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002298 return rc;
dea31012005-04-17 16:05:31 -05002299}