blob: 46128c679202199537be8053089f08d1f8835a24 [file] [log] [blame]
James Smart92d7f7b2007-06-17 19:56:38 -05001 /*******************************************************************
dea31012005-04-17 16:05:31 -05002 * This file is part of the Emulex Linux Device Driver for *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04003 * Fibre Channel Host Bus Adapters. *
James Smartd4379ac2012-03-01 22:37:07 -05004 * Copyright (C) 2004-2012 Emulex. All rights reserved. *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04005 * EMULEX and SLI are trademarks of Emulex. *
dea31012005-04-17 16:05:31 -05006 * www.emulex.com *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04007 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
dea31012005-04-17 16:05:31 -05008 * *
9 * This program is free software; you can redistribute it and/or *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -040010 * modify it under the terms of version 2 of the GNU General *
11 * Public License as published by the Free Software Foundation. *
12 * This program is distributed in the hope that it will be useful. *
13 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
14 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
15 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
16 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
17 * TO BE LEGALLY INVALID. See the GNU General Public License for *
18 * more details, a copy of which can be found in the file COPYING *
19 * included with this package. *
dea31012005-04-17 16:05:31 -050020 *******************************************************************/
21
dea31012005-04-17 16:05:31 -050022#include <linux/blkdev.h>
23#include <linux/pci.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090024#include <linux/slab.h>
dea31012005-04-17 16:05:31 -050025#include <linux/interrupt.h>
26
James.Smart@Emulex.Com91886522005-08-10 15:03:09 -040027#include <scsi/scsi.h>
dea31012005-04-17 16:05:31 -050028#include <scsi/scsi_device.h>
29#include <scsi/scsi_host.h>
30#include <scsi/scsi_transport_fc.h>
31
James Smartda0436e2009-05-22 14:51:39 -040032#include "lpfc_hw4.h"
dea31012005-04-17 16:05:31 -050033#include "lpfc_hw.h"
34#include "lpfc_sli.h"
James Smartda0436e2009-05-22 14:51:39 -040035#include "lpfc_sli4.h"
James Smartea2151b2008-09-07 11:52:10 -040036#include "lpfc_nl.h"
dea31012005-04-17 16:05:31 -050037#include "lpfc_disc.h"
38#include "lpfc_scsi.h"
39#include "lpfc.h"
40#include "lpfc_logmsg.h"
41#include "lpfc_crtn.h"
James Smart92d7f7b2007-06-17 19:56:38 -050042#include "lpfc_vport.h"
James Smart858c9f62007-06-17 19:56:39 -050043#include "lpfc_debugfs.h"
dea31012005-04-17 16:05:31 -050044
45
46/* Called to verify a rcv'ed ADISC was intended for us. */
47static int
James Smart2e0fef82007-06-17 19:56:36 -050048lpfc_check_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
49 struct lpfc_name *nn, struct lpfc_name *pn)
dea31012005-04-17 16:05:31 -050050{
James Smart6b5151f2012-01-18 16:24:06 -050051 /* First, we MUST have a RPI registered */
52 if (!(ndlp->nlp_flag & NLP_RPI_REGISTERED))
53 return 0;
54
dea31012005-04-17 16:05:31 -050055 /* Compare the ADISC rsp WWNN / WWPN matches our internal node
56 * table entry for that node.
57 */
James Smart2e0fef82007-06-17 19:56:36 -050058 if (memcmp(nn, &ndlp->nlp_nodename, sizeof (struct lpfc_name)))
Jamie Wellnitzc9f87352006-02-28 19:25:23 -050059 return 0;
dea31012005-04-17 16:05:31 -050060
James Smart2e0fef82007-06-17 19:56:36 -050061 if (memcmp(pn, &ndlp->nlp_portname, sizeof (struct lpfc_name)))
Jamie Wellnitzc9f87352006-02-28 19:25:23 -050062 return 0;
dea31012005-04-17 16:05:31 -050063
64 /* we match, return success */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -050065 return 1;
dea31012005-04-17 16:05:31 -050066}
67
dea31012005-04-17 16:05:31 -050068int
James Smart2e0fef82007-06-17 19:56:36 -050069lpfc_check_sparm(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
James Smart341af102010-01-26 23:07:37 -050070 struct serv_parm *sp, uint32_t class, int flogi)
dea31012005-04-17 16:05:31 -050071{
James Smart2e0fef82007-06-17 19:56:36 -050072 volatile struct serv_parm *hsp = &vport->fc_sparam;
James.Smart@Emulex.Com2fb70f72005-11-28 11:41:24 -050073 uint16_t hsp_value, ssp_value = 0;
dea31012005-04-17 16:05:31 -050074
James.Smart@Emulex.Com2fb70f72005-11-28 11:41:24 -050075 /*
76 * The receive data field size and buffer-to-buffer receive data field
77 * size entries are 16 bits but are represented as two 8-bit fields in
78 * the driver data structure to account for rsvd bits and other control
79 * bits. Reconstruct and compare the fields as a 16-bit values before
80 * correcting the byte values.
81 */
dea31012005-04-17 16:05:31 -050082 if (sp->cls1.classValid) {
James Smart341af102010-01-26 23:07:37 -050083 if (!flogi) {
84 hsp_value = ((hsp->cls1.rcvDataSizeMsb << 8) |
85 hsp->cls1.rcvDataSizeLsb);
86 ssp_value = ((sp->cls1.rcvDataSizeMsb << 8) |
87 sp->cls1.rcvDataSizeLsb);
88 if (!ssp_value)
89 goto bad_service_param;
90 if (ssp_value > hsp_value) {
91 sp->cls1.rcvDataSizeLsb =
92 hsp->cls1.rcvDataSizeLsb;
93 sp->cls1.rcvDataSizeMsb =
94 hsp->cls1.rcvDataSizeMsb;
95 }
James.Smart@Emulex.Com2fb70f72005-11-28 11:41:24 -050096 }
James Smart341af102010-01-26 23:07:37 -050097 } else if (class == CLASS1)
James Smart92d7f7b2007-06-17 19:56:38 -050098 goto bad_service_param;
dea31012005-04-17 16:05:31 -050099 if (sp->cls2.classValid) {
James Smart341af102010-01-26 23:07:37 -0500100 if (!flogi) {
101 hsp_value = ((hsp->cls2.rcvDataSizeMsb << 8) |
102 hsp->cls2.rcvDataSizeLsb);
103 ssp_value = ((sp->cls2.rcvDataSizeMsb << 8) |
104 sp->cls2.rcvDataSizeLsb);
105 if (!ssp_value)
106 goto bad_service_param;
107 if (ssp_value > hsp_value) {
108 sp->cls2.rcvDataSizeLsb =
109 hsp->cls2.rcvDataSizeLsb;
110 sp->cls2.rcvDataSizeMsb =
111 hsp->cls2.rcvDataSizeMsb;
112 }
James.Smart@Emulex.Com2fb70f72005-11-28 11:41:24 -0500113 }
James Smart341af102010-01-26 23:07:37 -0500114 } else if (class == CLASS2)
James Smart92d7f7b2007-06-17 19:56:38 -0500115 goto bad_service_param;
dea31012005-04-17 16:05:31 -0500116 if (sp->cls3.classValid) {
James Smart341af102010-01-26 23:07:37 -0500117 if (!flogi) {
118 hsp_value = ((hsp->cls3.rcvDataSizeMsb << 8) |
119 hsp->cls3.rcvDataSizeLsb);
120 ssp_value = ((sp->cls3.rcvDataSizeMsb << 8) |
121 sp->cls3.rcvDataSizeLsb);
122 if (!ssp_value)
123 goto bad_service_param;
124 if (ssp_value > hsp_value) {
125 sp->cls3.rcvDataSizeLsb =
126 hsp->cls3.rcvDataSizeLsb;
127 sp->cls3.rcvDataSizeMsb =
128 hsp->cls3.rcvDataSizeMsb;
129 }
James.Smart@Emulex.Com2fb70f72005-11-28 11:41:24 -0500130 }
James Smart341af102010-01-26 23:07:37 -0500131 } else if (class == CLASS3)
James Smart92d7f7b2007-06-17 19:56:38 -0500132 goto bad_service_param;
dea31012005-04-17 16:05:31 -0500133
James.Smart@Emulex.Com2fb70f72005-11-28 11:41:24 -0500134 /*
135 * Preserve the upper four bits of the MSB from the PLOGI response.
136 * These bits contain the Buffer-to-Buffer State Change Number
137 * from the target and need to be passed to the FW.
138 */
139 hsp_value = (hsp->cmn.bbRcvSizeMsb << 8) | hsp->cmn.bbRcvSizeLsb;
140 ssp_value = (sp->cmn.bbRcvSizeMsb << 8) | sp->cmn.bbRcvSizeLsb;
141 if (ssp_value > hsp_value) {
dea31012005-04-17 16:05:31 -0500142 sp->cmn.bbRcvSizeLsb = hsp->cmn.bbRcvSizeLsb;
James.Smart@Emulex.Com2fb70f72005-11-28 11:41:24 -0500143 sp->cmn.bbRcvSizeMsb = (sp->cmn.bbRcvSizeMsb & 0xF0) |
144 (hsp->cmn.bbRcvSizeMsb & 0x0F);
145 }
dea31012005-04-17 16:05:31 -0500146
dea31012005-04-17 16:05:31 -0500147 memcpy(&ndlp->nlp_nodename, &sp->nodeName, sizeof (struct lpfc_name));
148 memcpy(&ndlp->nlp_portname, &sp->portName, sizeof (struct lpfc_name));
James.Smart@Emulex.Com2fb70f72005-11-28 11:41:24 -0500149 return 1;
James Smart92d7f7b2007-06-17 19:56:38 -0500150bad_service_param:
James Smarte8b62012007-08-02 11:10:09 -0400151 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
152 "0207 Device %x "
153 "(%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x) sent "
154 "invalid service parameters. Ignoring device.\n",
155 ndlp->nlp_DID,
156 sp->nodeName.u.wwn[0], sp->nodeName.u.wwn[1],
157 sp->nodeName.u.wwn[2], sp->nodeName.u.wwn[3],
158 sp->nodeName.u.wwn[4], sp->nodeName.u.wwn[5],
159 sp->nodeName.u.wwn[6], sp->nodeName.u.wwn[7]);
James Smart92d7f7b2007-06-17 19:56:38 -0500160 return 0;
dea31012005-04-17 16:05:31 -0500161}
162
163static void *
James Smart2e0fef82007-06-17 19:56:36 -0500164lpfc_check_elscmpl_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -0500165 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -0500166{
167 struct lpfc_dmabuf *pcmd, *prsp;
168 uint32_t *lp;
169 void *ptr = NULL;
170 IOCB_t *irsp;
171
172 irsp = &rspiocb->iocb;
173 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
174
175 /* For lpfc_els_abort, context2 could be zero'ed to delay
176 * freeing associated memory till after ABTS completes.
177 */
178 if (pcmd) {
179 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf,
180 list);
181 if (prsp) {
182 lp = (uint32_t *) prsp->virt;
183 ptr = (void *)((uint8_t *)lp + sizeof(uint32_t));
184 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500185 } else {
dea31012005-04-17 16:05:31 -0500186 /* Force ulpStatus error since we are returning NULL ptr */
187 if (!(irsp->ulpStatus)) {
188 irsp->ulpStatus = IOSTAT_LOCAL_REJECT;
189 irsp->un.ulpWord[4] = IOERR_SLI_ABORTED;
190 }
191 ptr = NULL;
192 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500193 return ptr;
dea31012005-04-17 16:05:31 -0500194}
195
196
James Smart2a9bf3d2010-06-07 15:24:45 -0400197
dea31012005-04-17 16:05:31 -0500198/*
199 * Free resources / clean up outstanding I/Os
200 * associated with a LPFC_NODELIST entry. This
201 * routine effectively results in a "software abort".
202 */
203int
James Smart2e0fef82007-06-17 19:56:36 -0500204lpfc_els_abort(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -0500205{
James Smart2534ba72007-04-25 09:52:20 -0400206 LIST_HEAD(completions);
James Smart2a9bf3d2010-06-07 15:24:45 -0400207 LIST_HEAD(txcmplq_completions);
208 LIST_HEAD(abort_list);
James Smart2e0fef82007-06-17 19:56:36 -0500209 struct lpfc_sli *psli = &phba->sli;
210 struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING];
dea31012005-04-17 16:05:31 -0500211 struct lpfc_iocbq *iocb, *next_iocb;
dea31012005-04-17 16:05:31 -0500212
213 /* Abort outstanding I/O on NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -0400214 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_DISCOVERY,
James Smart2a9bf3d2010-06-07 15:24:45 -0400215 "2819 Abort outstanding I/O on NPort x%x "
James Smarte8b62012007-08-02 11:10:09 -0400216 "Data: x%x x%x x%x\n",
217 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
218 ndlp->nlp_rpi);
James Smart92d7f7b2007-06-17 19:56:38 -0500219
220 lpfc_fabric_abort_nport(ndlp);
dea31012005-04-17 16:05:31 -0500221
dea31012005-04-17 16:05:31 -0500222 /* First check the txq */
James Smart2e0fef82007-06-17 19:56:36 -0500223 spin_lock_irq(&phba->hbalock);
James Smart2534ba72007-04-25 09:52:20 -0400224 list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
James Smart858c9f62007-06-17 19:56:39 -0500225 /* Check to see if iocb matches the nport we are looking for */
James Smart2534ba72007-04-25 09:52:20 -0400226 if (lpfc_check_sli_ndlp(phba, pring, iocb, ndlp)) {
James Smart858c9f62007-06-17 19:56:39 -0500227 /* It matches, so deque and call compl with anp error */
James Smart2534ba72007-04-25 09:52:20 -0400228 list_move_tail(&iocb->list, &completions);
229 pring->txq_cnt--;
dea31012005-04-17 16:05:31 -0500230 }
James Smart2534ba72007-04-25 09:52:20 -0400231 }
dea31012005-04-17 16:05:31 -0500232
dea31012005-04-17 16:05:31 -0500233 /* Next check the txcmplq */
James Smart2a9bf3d2010-06-07 15:24:45 -0400234 list_splice_init(&pring->txcmplq, &txcmplq_completions);
James Smart2e0fef82007-06-17 19:56:36 -0500235 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500236
James Smart2a9bf3d2010-06-07 15:24:45 -0400237 list_for_each_entry_safe(iocb, next_iocb, &txcmplq_completions, list) {
238 /* Check to see if iocb matches the nport we are looking for */
239 if (lpfc_check_sli_ndlp(phba, pring, iocb, ndlp))
240 list_add_tail(&iocb->dlist, &abort_list);
241 }
242 spin_lock_irq(&phba->hbalock);
243 list_splice(&txcmplq_completions, &pring->txcmplq);
244 spin_unlock_irq(&phba->hbalock);
245
246 list_for_each_entry_safe(iocb, next_iocb, &abort_list, dlist) {
247 spin_lock_irq(&phba->hbalock);
248 list_del_init(&iocb->dlist);
249 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
250 spin_unlock_irq(&phba->hbalock);
251 }
252
James Smarta257bf92009-04-06 18:48:10 -0400253 /* Cancel all the IOCBs from the completions list */
254 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
255 IOERR_SLI_ABORTED);
James Smart2534ba72007-04-25 09:52:20 -0400256
James Smart0d2b6b82008-06-14 22:52:47 -0400257 lpfc_cancel_retry_delay_tmo(phba->pport, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500258 return 0;
dea31012005-04-17 16:05:31 -0500259}
260
261static int
James Smart2e0fef82007-06-17 19:56:36 -0500262lpfc_rcv_plogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
James Smart92d7f7b2007-06-17 19:56:38 -0500263 struct lpfc_iocbq *cmdiocb)
dea31012005-04-17 16:05:31 -0500264{
James Smart2e0fef82007-06-17 19:56:36 -0500265 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
266 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500267 struct lpfc_dmabuf *pcmd;
268 uint32_t *lp;
269 IOCB_t *icmd;
270 struct serv_parm *sp;
271 LPFC_MBOXQ_t *mbox;
272 struct ls_rjt stat;
273 int rc;
274
275 memset(&stat, 0, sizeof (struct ls_rjt));
James Smart695a8142010-01-26 23:08:03 -0500276 if (vport->port_state <= LPFC_FDISC) {
dea31012005-04-17 16:05:31 -0500277 /* Before responding to PLOGI, check for pt2pt mode.
278 * If we are pt2pt, with an outstanding FLOGI, abort
279 * the FLOGI and resend it first.
280 */
James Smart2e0fef82007-06-17 19:56:36 -0500281 if (vport->fc_flag & FC_PT2PT) {
James Smart92d7f7b2007-06-17 19:56:38 -0500282 lpfc_els_abort_flogi(phba);
James Smart2e0fef82007-06-17 19:56:36 -0500283 if (!(vport->fc_flag & FC_PT2PT_PLOGI)) {
dea31012005-04-17 16:05:31 -0500284 /* If the other side is supposed to initiate
285 * the PLOGI anyway, just ACC it now and
286 * move on with discovery.
287 */
288 phba->fc_edtov = FF_DEF_EDTOV;
289 phba->fc_ratov = FF_DEF_RATOV;
290 /* Start discovery - this should just do
291 CLEAR_LA */
James Smart2e0fef82007-06-17 19:56:36 -0500292 lpfc_disc_start(vport);
James Smarted957682007-06-17 19:56:37 -0500293 } else
James Smart2e0fef82007-06-17 19:56:36 -0500294 lpfc_initial_flogi(vport);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500295 } else {
dea31012005-04-17 16:05:31 -0500296 stat.un.b.lsRjtRsnCode = LSRJT_LOGICAL_BSY;
297 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
James Smart2e0fef82007-06-17 19:56:36 -0500298 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb,
James Smart858c9f62007-06-17 19:56:39 -0500299 ndlp, NULL);
dea31012005-04-17 16:05:31 -0500300 return 0;
301 }
302 }
303 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
304 lp = (uint32_t *) pcmd->virt;
305 sp = (struct serv_parm *) ((uint8_t *) lp + sizeof (uint32_t));
James Smarta8adb832007-10-27 13:37:53 -0400306 if (wwn_to_u64(sp->portName.u.wwn) == 0) {
307 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
308 "0140 PLOGI Reject: invalid nname\n");
309 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
310 stat.un.b.lsRjtRsnCodeExp = LSEXP_INVALID_PNAME;
311 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
312 NULL);
313 return 0;
314 }
315 if (wwn_to_u64(sp->nodeName.u.wwn) == 0) {
316 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
317 "0141 PLOGI Reject: invalid pname\n");
318 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
319 stat.un.b.lsRjtRsnCodeExp = LSEXP_INVALID_NNAME;
320 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
321 NULL);
322 return 0;
323 }
James Smart341af102010-01-26 23:07:37 -0500324 if ((lpfc_check_sparm(vport, ndlp, sp, CLASS3, 0) == 0)) {
dea31012005-04-17 16:05:31 -0500325 /* Reject this request because invalid parameters */
326 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
327 stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
James Smart858c9f62007-06-17 19:56:39 -0500328 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
329 NULL);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500330 return 0;
dea31012005-04-17 16:05:31 -0500331 }
332 icmd = &cmdiocb->iocb;
333
334 /* PLOGI chkparm OK */
James Smarte8b62012007-08-02 11:10:09 -0400335 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
336 "0114 PLOGI chkparm OK Data: x%x x%x x%x x%x\n",
337 ndlp->nlp_DID, ndlp->nlp_state, ndlp->nlp_flag,
338 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -0500339
James Smart3de2a652007-08-02 11:09:59 -0400340 if (vport->cfg_fcp_class == 2 && sp->cls2.classValid)
dea31012005-04-17 16:05:31 -0500341 ndlp->nlp_fcp_info |= CLASS2;
James Smarted957682007-06-17 19:56:37 -0500342 else
dea31012005-04-17 16:05:31 -0500343 ndlp->nlp_fcp_info |= CLASS3;
James Smart2e0fef82007-06-17 19:56:36 -0500344
dea31012005-04-17 16:05:31 -0500345 ndlp->nlp_class_sup = 0;
346 if (sp->cls1.classValid)
347 ndlp->nlp_class_sup |= FC_COS_CLASS1;
348 if (sp->cls2.classValid)
349 ndlp->nlp_class_sup |= FC_COS_CLASS2;
350 if (sp->cls3.classValid)
351 ndlp->nlp_class_sup |= FC_COS_CLASS3;
352 if (sp->cls4.classValid)
353 ndlp->nlp_class_sup |= FC_COS_CLASS4;
354 ndlp->nlp_maxframe =
355 ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) | sp->cmn.bbRcvSizeLsb;
356
James Smart05580562011-05-24 11:40:48 -0400357 /* no need to reg_login if we are already in one of these states */
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500358 switch (ndlp->nlp_state) {
dea31012005-04-17 16:05:31 -0500359 case NLP_STE_NPR_NODE:
360 if (!(ndlp->nlp_flag & NLP_NPR_ADISC))
361 break;
362 case NLP_STE_REG_LOGIN_ISSUE:
363 case NLP_STE_PRLI_ISSUE:
364 case NLP_STE_UNMAPPED_NODE:
365 case NLP_STE_MAPPED_NODE:
James Smart05580562011-05-24 11:40:48 -0400366 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp, NULL);
367 return 1;
dea31012005-04-17 16:05:31 -0500368 }
369
James Smart939723a2012-05-09 21:19:03 -0400370 /* Check for Nport to NPort pt2pt protocol */
James Smart92d7f7b2007-06-17 19:56:38 -0500371 if ((vport->fc_flag & FC_PT2PT) &&
372 !(vport->fc_flag & FC_PT2PT_PLOGI)) {
James Smart939723a2012-05-09 21:19:03 -0400373
dea31012005-04-17 16:05:31 -0500374 /* rcv'ed PLOGI decides what our NPortId will be */
James Smart2e0fef82007-06-17 19:56:36 -0500375 vport->fc_myDID = icmd->un.rcvels.parmRo;
dea31012005-04-17 16:05:31 -0500376 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
377 if (mbox == NULL)
378 goto out;
379 lpfc_config_link(phba, mbox);
380 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smarted957682007-06-17 19:56:37 -0500381 mbox->vport = vport;
James Smart0b727fe2007-10-27 13:37:25 -0400382 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
dea31012005-04-17 16:05:31 -0500383 if (rc == MBX_NOT_FINISHED) {
James Smart92d7f7b2007-06-17 19:56:38 -0500384 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -0500385 goto out;
386 }
James Smart939723a2012-05-09 21:19:03 -0400387 /*
388 * For SLI4, the VFI/VPI are registered AFTER the
389 * Nport with the higher WWPN sends us a PLOGI with
390 * our assigned NPortId.
391 */
392 if (phba->sli_rev == LPFC_SLI_REV4)
393 lpfc_issue_reg_vfi(vport);
dea31012005-04-17 16:05:31 -0500394
James Smart2e0fef82007-06-17 19:56:36 -0500395 lpfc_can_disctmo(vport);
dea31012005-04-17 16:05:31 -0500396 }
397 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
James Smart2e0fef82007-06-17 19:56:36 -0500398 if (!mbox)
dea31012005-04-17 16:05:31 -0500399 goto out;
400
James Smart6b5151f2012-01-18 16:24:06 -0500401 /* Registering an existing RPI behaves differently for SLI3 vs SLI4 */
402 if (phba->sli_rev == LPFC_SLI_REV4)
403 lpfc_unreg_rpi(vport, ndlp);
404
James Smart6fb120a2009-05-22 14:52:59 -0400405 rc = lpfc_reg_rpi(phba, vport->vpi, icmd->un.rcvels.remoteID,
James Smart40426292010-12-15 17:58:10 -0500406 (uint8_t *) sp, mbox, ndlp->nlp_rpi);
James Smart2e0fef82007-06-17 19:56:36 -0500407 if (rc) {
408 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -0500409 goto out;
410 }
411
412 /* ACC PLOGI rsp command needs to execute first,
413 * queue this mbox command to be processed later.
414 */
415 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
James Smart329f9bc2007-04-25 09:53:01 -0400416 /*
417 * mbox->context2 = lpfc_nlp_get(ndlp) deferred until mailbox
418 * command issued in lpfc_cmpl_els_acc().
419 */
James Smart2e0fef82007-06-17 19:56:36 -0500420 mbox->vport = vport;
421 spin_lock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -0500422 ndlp->nlp_flag |= (NLP_ACC_REGLOGIN | NLP_RCV_PLOGI);
James Smart2e0fef82007-06-17 19:56:36 -0500423 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500424
James Smart33ccf8d2006-08-17 11:57:58 -0400425 /*
426 * If there is an outstanding PLOGI issued, abort it before
427 * sending ACC rsp for received PLOGI. If pending plogi
428 * is not canceled here, the plogi will be rejected by
429 * remote port and will be retried. On a configuration with
430 * single discovery thread, this will cause a huge delay in
431 * discovery. Also this will cause multiple state machines
432 * running in parallel for this node.
433 */
434 if (ndlp->nlp_state == NLP_STE_PLOGI_ISSUE) {
435 /* software abort outstanding PLOGI */
James Smart07951072007-04-25 09:51:38 -0400436 lpfc_els_abort(phba, ndlp);
James Smart33ccf8d2006-08-17 11:57:58 -0400437 }
438
James Smart858c9f62007-06-17 19:56:39 -0500439 if ((vport->port_type == LPFC_NPIV_PORT &&
James Smart3de2a652007-08-02 11:09:59 -0400440 vport->cfg_restrict_login)) {
James Smart858c9f62007-06-17 19:56:39 -0500441
442 /* In order to preserve RPIs, we want to cleanup
443 * the default RPI the firmware created to rcv
444 * this ELS request. The only way to do this is
445 * to register, then unregister the RPI.
446 */
447 spin_lock_irq(shost->host_lock);
448 ndlp->nlp_flag |= NLP_RM_DFLT_RPI;
449 spin_unlock_irq(shost->host_lock);
450 stat.un.b.lsRjtRsnCode = LSRJT_INVALID_CMD;
451 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
James Smart0a8a86f2012-03-01 22:36:15 -0500452 rc = lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb,
James Smart858c9f62007-06-17 19:56:39 -0500453 ndlp, mbox);
James Smart0a8a86f2012-03-01 22:36:15 -0500454 if (rc)
455 mempool_free(mbox, phba->mbox_mem_pool);
James Smart858c9f62007-06-17 19:56:39 -0500456 return 1;
457 }
James Smart0a8a86f2012-03-01 22:36:15 -0500458 rc = lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp, mbox);
459 if (rc)
460 mempool_free(mbox, phba->mbox_mem_pool);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500461 return 1;
dea31012005-04-17 16:05:31 -0500462out:
463 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
464 stat.un.b.lsRjtRsnCodeExp = LSEXP_OUT_OF_RESOURCE;
James Smart858c9f62007-06-17 19:56:39 -0500465 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500466 return 0;
dea31012005-04-17 16:05:31 -0500467}
468
James Smart6b5151f2012-01-18 16:24:06 -0500469/**
470 * lpfc_mbx_cmpl_resume_rpi - Resume RPI completion routine
471 * @phba: pointer to lpfc hba data structure.
472 * @mboxq: pointer to mailbox object
473 *
474 * This routine is invoked to issue a completion to a rcv'ed
475 * ADISC or PDISC after the paused RPI has been resumed.
476 **/
477static void
478lpfc_mbx_cmpl_resume_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
479{
480 struct lpfc_vport *vport;
481 struct lpfc_iocbq *elsiocb;
482 struct lpfc_nodelist *ndlp;
483 uint32_t cmd;
484
485 elsiocb = (struct lpfc_iocbq *)mboxq->context1;
486 ndlp = (struct lpfc_nodelist *) mboxq->context2;
487 vport = mboxq->vport;
488 cmd = elsiocb->drvrTimeout;
489
490 if (cmd == ELS_CMD_ADISC) {
491 lpfc_els_rsp_adisc_acc(vport, elsiocb, ndlp);
492 } else {
493 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, elsiocb,
494 ndlp, NULL);
495 }
496 kfree(elsiocb);
James Smart72859902012-01-18 16:25:38 -0500497 mempool_free(mboxq, phba->mbox_mem_pool);
James Smart6b5151f2012-01-18 16:24:06 -0500498}
499
dea31012005-04-17 16:05:31 -0500500static int
James Smart2e0fef82007-06-17 19:56:36 -0500501lpfc_rcv_padisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -0500502 struct lpfc_iocbq *cmdiocb)
503{
James Smart2e0fef82007-06-17 19:56:36 -0500504 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart6b5151f2012-01-18 16:24:06 -0500505 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -0500506 struct lpfc_dmabuf *pcmd;
James Smart2e0fef82007-06-17 19:56:36 -0500507 struct serv_parm *sp;
508 struct lpfc_name *pnn, *ppn;
dea31012005-04-17 16:05:31 -0500509 struct ls_rjt stat;
510 ADISC *ap;
511 IOCB_t *icmd;
512 uint32_t *lp;
513 uint32_t cmd;
514
515 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
516 lp = (uint32_t *) pcmd->virt;
517
518 cmd = *lp++;
519 if (cmd == ELS_CMD_ADISC) {
520 ap = (ADISC *) lp;
521 pnn = (struct lpfc_name *) & ap->nodeName;
522 ppn = (struct lpfc_name *) & ap->portName;
523 } else {
524 sp = (struct serv_parm *) lp;
525 pnn = (struct lpfc_name *) & sp->nodeName;
526 ppn = (struct lpfc_name *) & sp->portName;
527 }
528
529 icmd = &cmdiocb->iocb;
James Smart2e0fef82007-06-17 19:56:36 -0500530 if (icmd->ulpStatus == 0 && lpfc_check_adisc(vport, ndlp, pnn, ppn)) {
James Smart6b5151f2012-01-18 16:24:06 -0500531
532 /*
533 * As soon as we send ACC, the remote NPort can
534 * start sending us data. Thus, for SLI4 we must
535 * resume the RPI before the ACC goes out.
536 */
537 if (vport->phba->sli_rev == LPFC_SLI_REV4) {
538 elsiocb = kmalloc(sizeof(struct lpfc_iocbq),
539 GFP_KERNEL);
540 if (elsiocb) {
541
542 /* Save info from cmd IOCB used in rsp */
543 memcpy((uint8_t *)elsiocb, (uint8_t *)cmdiocb,
544 sizeof(struct lpfc_iocbq));
545
546 /* Save the ELS cmd */
547 elsiocb->drvrTimeout = cmd;
548
549 lpfc_sli4_resume_rpi(ndlp,
550 lpfc_mbx_cmpl_resume_rpi, elsiocb);
551 goto out;
552 }
553 }
554
dea31012005-04-17 16:05:31 -0500555 if (cmd == ELS_CMD_ADISC) {
James Smart2e0fef82007-06-17 19:56:36 -0500556 lpfc_els_rsp_adisc_acc(vport, cmdiocb, ndlp);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500557 } else {
James Smart6b5151f2012-01-18 16:24:06 -0500558 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb,
559 ndlp, NULL);
dea31012005-04-17 16:05:31 -0500560 }
James Smart6b5151f2012-01-18 16:24:06 -0500561out:
562 /* If we are authenticated, move to the proper state */
563 if (ndlp->nlp_type & NLP_FCP_TARGET)
564 lpfc_nlp_set_state(vport, ndlp, NLP_STE_MAPPED_NODE);
565 else
566 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
567
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500568 return 1;
dea31012005-04-17 16:05:31 -0500569 }
570 /* Reject this request because invalid parameters */
571 stat.un.b.lsRjtRsvd0 = 0;
572 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
573 stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
574 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -0500575 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -0500576
dea31012005-04-17 16:05:31 -0500577 /* 1 sec timeout */
578 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ);
579
James Smart2e0fef82007-06-17 19:56:36 -0500580 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500581 ndlp->nlp_flag |= NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -0500582 spin_unlock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -0500583 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
584 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -0500585 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500586 return 0;
dea31012005-04-17 16:05:31 -0500587}
588
589static int
James Smart2e0fef82007-06-17 19:56:36 -0500590lpfc_rcv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
591 struct lpfc_iocbq *cmdiocb, uint32_t els_cmd)
dea31012005-04-17 16:05:31 -0500592{
James Smart2e0fef82007-06-17 19:56:36 -0500593 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart4b40c592010-03-15 11:25:44 -0400594 struct lpfc_hba *phba = vport->phba;
595 struct lpfc_vport **vports;
596 int i, active_vlink_present = 0 ;
James Smart2e0fef82007-06-17 19:56:36 -0500597
598 /* Put ndlp in NPR state with 1 sec timeout for plogi, ACC logo */
dea31012005-04-17 16:05:31 -0500599 /* Only call LOGO ACC for first LOGO, this avoids sending unnecessary
600 * PLOGIs during LOGO storms from a device.
601 */
James Smart2e0fef82007-06-17 19:56:36 -0500602 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500603 ndlp->nlp_flag |= NLP_LOGO_ACC;
James Smart2e0fef82007-06-17 19:56:36 -0500604 spin_unlock_irq(shost->host_lock);
James Smart82d9a2a2006-04-15 11:53:05 -0400605 if (els_cmd == ELS_CMD_PRLO)
James Smart51ef4c22007-08-02 11:10:31 -0400606 lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL);
James Smart82d9a2a2006-04-15 11:53:05 -0400607 else
James Smart51ef4c22007-08-02 11:10:31 -0400608 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
James Smart4b40c592010-03-15 11:25:44 -0400609 if (ndlp->nlp_DID == Fabric_DID) {
610 if (vport->port_state <= LPFC_FDISC)
611 goto out;
James Smart6fb120a2009-05-22 14:52:59 -0400612 lpfc_linkdown_port(vport);
James Smart6fb120a2009-05-22 14:52:59 -0400613 spin_lock_irq(shost->host_lock);
James Smart4b40c592010-03-15 11:25:44 -0400614 vport->fc_flag |= FC_VPORT_LOGO_RCVD;
James Smart6fb120a2009-05-22 14:52:59 -0400615 spin_unlock_irq(shost->host_lock);
James Smart4b40c592010-03-15 11:25:44 -0400616 vports = lpfc_create_vport_work_array(phba);
617 if (vports) {
618 for (i = 0; i <= phba->max_vports && vports[i] != NULL;
619 i++) {
620 if ((!(vports[i]->fc_flag &
621 FC_VPORT_LOGO_RCVD)) &&
622 (vports[i]->port_state > LPFC_FDISC)) {
623 active_vlink_present = 1;
624 break;
625 }
626 }
627 lpfc_destroy_vport_work_array(phba, vports);
628 }
dea31012005-04-17 16:05:31 -0500629
James Smart4b40c592010-03-15 11:25:44 -0400630 if (active_vlink_present) {
631 /*
632 * If there are other active VLinks present,
633 * re-instantiate the Vlink using FDISC.
634 */
635 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ);
636 spin_lock_irq(shost->host_lock);
637 ndlp->nlp_flag |= NLP_DELAY_TMO;
638 spin_unlock_irq(shost->host_lock);
639 ndlp->nlp_last_elscmd = ELS_CMD_FDISC;
640 vport->port_state = LPFC_FDISC;
641 } else {
642 spin_lock_irq(shost->host_lock);
643 phba->pport->fc_flag &= ~FC_LOGO_RCVD_DID_CHNG;
644 spin_unlock_irq(shost->host_lock);
645 lpfc_retry_pport_discovery(phba);
646 }
James Smart6fb120a2009-05-22 14:52:59 -0400647 } else if ((!(ndlp->nlp_type & NLP_FABRIC) &&
648 ((ndlp->nlp_type & NLP_FCP_TARGET) ||
649 !(ndlp->nlp_type & NLP_FCP_INITIATOR))) ||
650 (ndlp->nlp_state == NLP_STE_ADISC_ISSUE)) {
dea31012005-04-17 16:05:31 -0500651 /* Only try to re-login if this is NOT a Fabric Node */
dea31012005-04-17 16:05:31 -0500652 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ * 1);
James Smart2e0fef82007-06-17 19:56:36 -0500653 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500654 ndlp->nlp_flag |= NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -0500655 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500656
Jamie Wellnitz5024ab12006-02-28 19:25:28 -0500657 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
dea31012005-04-17 16:05:31 -0500658 }
James Smart4b40c592010-03-15 11:25:44 -0400659out:
James Smart87af33f2007-10-27 13:37:43 -0400660 ndlp->nlp_prev_state = ndlp->nlp_state;
661 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
dea31012005-04-17 16:05:31 -0500662
James Smart2e0fef82007-06-17 19:56:36 -0500663 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500664 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
James Smart2e0fef82007-06-17 19:56:36 -0500665 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500666 /* The driver has to wait until the ACC completes before it continues
667 * processing the LOGO. The action will resume in
668 * lpfc_cmpl_els_logo_acc routine. Since part of processing includes an
669 * unreg_login, the driver waits so the ACC does not get aborted.
670 */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500671 return 0;
dea31012005-04-17 16:05:31 -0500672}
673
674static void
James Smart2e0fef82007-06-17 19:56:36 -0500675lpfc_rcv_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
676 struct lpfc_iocbq *cmdiocb)
dea31012005-04-17 16:05:31 -0500677{
678 struct lpfc_dmabuf *pcmd;
679 uint32_t *lp;
680 PRLI *npr;
681 struct fc_rport *rport = ndlp->rport;
682 u32 roles;
683
684 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
685 lp = (uint32_t *) pcmd->virt;
686 npr = (PRLI *) ((uint8_t *) lp + sizeof (uint32_t));
687
688 ndlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR);
689 ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
James Smart92d7f7b2007-06-17 19:56:38 -0500690 if (npr->prliType == PRLI_FCP_TYPE) {
dea31012005-04-17 16:05:31 -0500691 if (npr->initiatorFunc)
692 ndlp->nlp_type |= NLP_FCP_INITIATOR;
693 if (npr->targetFunc)
694 ndlp->nlp_type |= NLP_FCP_TARGET;
695 if (npr->Retry)
696 ndlp->nlp_fcp_info |= NLP_FCP_2_DEVICE;
697 }
698 if (rport) {
699 /* We need to update the rport role values */
700 roles = FC_RPORT_ROLE_UNKNOWN;
701 if (ndlp->nlp_type & NLP_FCP_INITIATOR)
702 roles |= FC_RPORT_ROLE_FCP_INITIATOR;
703 if (ndlp->nlp_type & NLP_FCP_TARGET)
704 roles |= FC_RPORT_ROLE_FCP_TARGET;
James Smart858c9f62007-06-17 19:56:39 -0500705
706 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
707 "rport rolechg: role:x%x did:x%x flg:x%x",
708 roles, ndlp->nlp_DID, ndlp->nlp_flag);
709
dea31012005-04-17 16:05:31 -0500710 fc_remote_port_rolechg(rport, roles);
711 }
712}
713
714static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -0500715lpfc_disc_set_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -0500716{
James Smart2e0fef82007-06-17 19:56:36 -0500717 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart2e0fef82007-06-17 19:56:36 -0500718
James Smart40426292010-12-15 17:58:10 -0500719 if (!(ndlp->nlp_flag & NLP_RPI_REGISTERED)) {
James Smart51ef4c22007-08-02 11:10:31 -0400720 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
721 return 0;
722 }
723
James Smart1b32f6a2008-02-08 18:49:39 -0500724 if (!(vport->fc_flag & FC_PT2PT)) {
725 /* Check config parameter use-adisc or FCP-2 */
726 if ((vport->cfg_use_adisc && (vport->fc_flag & FC_RSCN_MODE)) ||
James Smartffc95492010-06-07 15:23:17 -0400727 ((ndlp->nlp_fcp_info & NLP_FCP_2_DEVICE) &&
728 (ndlp->nlp_type & NLP_FCP_TARGET))) {
James Smart1b32f6a2008-02-08 18:49:39 -0500729 spin_lock_irq(shost->host_lock);
730 ndlp->nlp_flag |= NLP_NPR_ADISC;
731 spin_unlock_irq(shost->host_lock);
732 return 1;
733 }
James Smart92d7f7b2007-06-17 19:56:38 -0500734 }
735 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
736 lpfc_unreg_rpi(vport, ndlp);
737 return 0;
dea31012005-04-17 16:05:31 -0500738}
James Smart6d368e52011-05-24 11:44:12 -0400739
James Smart78730cf2010-04-06 15:06:30 -0400740/**
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300741 * lpfc_release_rpi - Release a RPI by issuing unreg_login mailbox cmd.
James Smart78730cf2010-04-06 15:06:30 -0400742 * @phba : Pointer to lpfc_hba structure.
743 * @vport: Pointer to lpfc_vport structure.
744 * @rpi : rpi to be release.
745 *
746 * This function will send a unreg_login mailbox command to the firmware
747 * to release a rpi.
748 **/
749void
750lpfc_release_rpi(struct lpfc_hba *phba,
751 struct lpfc_vport *vport,
752 uint16_t rpi)
753{
754 LPFC_MBOXQ_t *pmb;
755 int rc;
756
757 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
758 GFP_KERNEL);
759 if (!pmb)
760 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
761 "2796 mailbox memory allocation failed \n");
762 else {
763 lpfc_unreg_login(phba, vport->vpi, rpi, pmb);
764 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
765 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
766 if (rc == MBX_NOT_FINISHED)
767 mempool_free(pmb, phba->mbox_mem_pool);
768 }
769}
dea31012005-04-17 16:05:31 -0500770
771static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -0500772lpfc_disc_illegal(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
773 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -0500774{
James Smart78730cf2010-04-06 15:06:30 -0400775 struct lpfc_hba *phba;
776 LPFC_MBOXQ_t *pmb = (LPFC_MBOXQ_t *) arg;
777 MAILBOX_t *mb;
778 uint16_t rpi;
779
780 phba = vport->phba;
781 /* Release the RPI if reglogin completing */
782 if (!(phba->pport->load_flag & FC_UNLOADING) &&
783 (evt == NLP_EVT_CMPL_REG_LOGIN) &&
784 (!pmb->u.mb.mbxStatus)) {
785 mb = &pmb->u.mb;
786 rpi = pmb->u.mb.un.varWords[0];
787 lpfc_release_rpi(phba, vport, rpi);
788 }
James Smarte8b62012007-08-02 11:10:09 -0400789 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
James Smarte47c9092008-02-08 18:49:26 -0500790 "0271 Illegal State Transition: node x%x "
James Smarte8b62012007-08-02 11:10:09 -0400791 "event x%x, state x%x Data: x%x x%x\n",
792 ndlp->nlp_DID, evt, ndlp->nlp_state, ndlp->nlp_rpi,
793 ndlp->nlp_flag);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500794 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -0500795}
796
James Smart87af33f2007-10-27 13:37:43 -0400797static uint32_t
798lpfc_cmpl_plogi_illegal(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
799 void *arg, uint32_t evt)
800{
801 /* This transition is only legal if we previously
802 * rcv'ed a PLOGI. Since we don't want 2 discovery threads
803 * working on the same NPortID, do nothing for this thread
804 * to stop it.
805 */
806 if (!(ndlp->nlp_flag & NLP_RCV_PLOGI)) {
807 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
James Smarte47c9092008-02-08 18:49:26 -0500808 "0272 Illegal State Transition: node x%x "
James Smart87af33f2007-10-27 13:37:43 -0400809 "event x%x, state x%x Data: x%x x%x\n",
810 ndlp->nlp_DID, evt, ndlp->nlp_state, ndlp->nlp_rpi,
811 ndlp->nlp_flag);
812 }
813 return ndlp->nlp_state;
814}
815
dea31012005-04-17 16:05:31 -0500816/* Start of Discovery State Machine routines */
817
818static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -0500819lpfc_rcv_plogi_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
820 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -0500821{
822 struct lpfc_iocbq *cmdiocb;
823
824 cmdiocb = (struct lpfc_iocbq *) arg;
825
James Smart2e0fef82007-06-17 19:56:36 -0500826 if (lpfc_rcv_plogi(vport, ndlp, cmdiocb)) {
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500827 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -0500828 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500829 return NLP_STE_FREED_NODE;
dea31012005-04-17 16:05:31 -0500830}
831
832static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -0500833lpfc_rcv_els_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
834 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -0500835{
James Smart2e0fef82007-06-17 19:56:36 -0500836 lpfc_issue_els_logo(vport, ndlp, 0);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500837 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -0500838}
839
840static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -0500841lpfc_rcv_logo_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
842 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -0500843{
James Smart2e0fef82007-06-17 19:56:36 -0500844 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
845 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -0500846
James Smart2e0fef82007-06-17 19:56:36 -0500847 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500848 ndlp->nlp_flag |= NLP_LOGO_ACC;
James Smart2e0fef82007-06-17 19:56:36 -0500849 spin_unlock_irq(shost->host_lock);
James Smart51ef4c22007-08-02 11:10:31 -0400850 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -0500851
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500852 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -0500853}
854
855static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -0500856lpfc_cmpl_logo_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -0500857 void *arg, uint32_t evt)
858{
James Smart2e0fef82007-06-17 19:56:36 -0500859 return NLP_STE_FREED_NODE;
860}
861
862static uint32_t
863lpfc_device_rm_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
864 void *arg, uint32_t evt)
865{
James Smart2e0fef82007-06-17 19:56:36 -0500866 return NLP_STE_FREED_NODE;
867}
868
869static uint32_t
James Smartdf9e1b52011-12-13 13:22:17 -0500870lpfc_device_recov_unused_node(struct lpfc_vport *vport,
871 struct lpfc_nodelist *ndlp,
872 void *arg, uint32_t evt)
873{
874 return ndlp->nlp_state;
875}
876
877static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -0500878lpfc_rcv_plogi_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
879 void *arg, uint32_t evt)
880{
James Smart0d2b6b82008-06-14 22:52:47 -0400881 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart2e0fef82007-06-17 19:56:36 -0500882 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500883 struct lpfc_iocbq *cmdiocb = arg;
James Smart2e0fef82007-06-17 19:56:36 -0500884 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
885 uint32_t *lp = (uint32_t *) pcmd->virt;
886 struct serv_parm *sp = (struct serv_parm *) (lp + 1);
dea31012005-04-17 16:05:31 -0500887 struct ls_rjt stat;
888 int port_cmp;
889
dea31012005-04-17 16:05:31 -0500890 memset(&stat, 0, sizeof (struct ls_rjt));
891
892 /* For a PLOGI, we only accept if our portname is less
893 * than the remote portname.
894 */
895 phba->fc_stat.elsLogiCol++;
James Smart2e0fef82007-06-17 19:56:36 -0500896 port_cmp = memcmp(&vport->fc_portname, &sp->portName,
James Smart92d7f7b2007-06-17 19:56:38 -0500897 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -0500898
899 if (port_cmp >= 0) {
900 /* Reject this request because the remote node will accept
901 ours */
902 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
903 stat.un.b.lsRjtRsnCodeExp = LSEXP_CMD_IN_PROGRESS;
James Smart858c9f62007-06-17 19:56:39 -0500904 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
905 NULL);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500906 } else {
James Smart0d2b6b82008-06-14 22:52:47 -0400907 if (lpfc_rcv_plogi(vport, ndlp, cmdiocb) &&
908 (ndlp->nlp_flag & NLP_NPR_2B_DISC) &&
909 (vport->num_disc_nodes)) {
910 spin_lock_irq(shost->host_lock);
911 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
912 spin_unlock_irq(shost->host_lock);
913 /* Check if there are more PLOGIs to be sent */
914 lpfc_more_plogi(vport);
915 if (vport->num_disc_nodes == 0) {
916 spin_lock_irq(shost->host_lock);
917 vport->fc_flag &= ~FC_NDISC_ACTIVE;
918 spin_unlock_irq(shost->host_lock);
919 lpfc_can_disctmo(vport);
920 lpfc_end_rscn(vport);
921 }
922 }
James Smart2e0fef82007-06-17 19:56:36 -0500923 } /* If our portname was less */
dea31012005-04-17 16:05:31 -0500924
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500925 return ndlp->nlp_state;
926}
927
928static uint32_t
James Smart92d7f7b2007-06-17 19:56:38 -0500929lpfc_rcv_prli_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
930 void *arg, uint32_t evt)
931{
932 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
933 struct ls_rjt stat;
934
935 memset(&stat, 0, sizeof (struct ls_rjt));
936 stat.un.b.lsRjtRsnCode = LSRJT_LOGICAL_BSY;
937 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
James Smart858c9f62007-06-17 19:56:39 -0500938 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
James Smart92d7f7b2007-06-17 19:56:38 -0500939 return ndlp->nlp_state;
940}
941
942static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -0500943lpfc_rcv_logo_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
944 void *arg, uint32_t evt)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500945{
James Smart2e0fef82007-06-17 19:56:36 -0500946 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500947
James Smart92d7f7b2007-06-17 19:56:38 -0500948 /* software abort outstanding PLOGI */
James Smart2e0fef82007-06-17 19:56:36 -0500949 lpfc_els_abort(vport->phba, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500950
James Smart2e0fef82007-06-17 19:56:36 -0500951 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500952 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -0500953}
954
955static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -0500956lpfc_rcv_els_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
957 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -0500958{
James Smart2e0fef82007-06-17 19:56:36 -0500959 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
960 struct lpfc_hba *phba = vport->phba;
961 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -0500962
963 /* software abort outstanding PLOGI */
James Smart07951072007-04-25 09:51:38 -0400964 lpfc_els_abort(phba, ndlp);
dea31012005-04-17 16:05:31 -0500965
966 if (evt == NLP_EVT_RCV_LOGO) {
James Smart51ef4c22007-08-02 11:10:31 -0400967 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500968 } else {
James Smart2e0fef82007-06-17 19:56:36 -0500969 lpfc_issue_els_logo(vport, ndlp, 0);
dea31012005-04-17 16:05:31 -0500970 }
971
James Smart2e0fef82007-06-17 19:56:36 -0500972 /* Put ndlp in npr state set plogi timer for 1 sec */
Jamie Wellnitz5024ab12006-02-28 19:25:28 -0500973 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ * 1);
James Smart2e0fef82007-06-17 19:56:36 -0500974 spin_lock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -0500975 ndlp->nlp_flag |= NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -0500976 spin_unlock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -0500977 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
978 ndlp->nlp_prev_state = NLP_STE_PLOGI_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -0500979 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
dea31012005-04-17 16:05:31 -0500980
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500981 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -0500982}
983
984static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -0500985lpfc_cmpl_plogi_plogi_issue(struct lpfc_vport *vport,
986 struct lpfc_nodelist *ndlp,
987 void *arg,
dea31012005-04-17 16:05:31 -0500988 uint32_t evt)
989{
James Smart2e0fef82007-06-17 19:56:36 -0500990 struct lpfc_hba *phba = vport->phba;
James Smart0ff10d42008-01-11 01:52:36 -0500991 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart2e0fef82007-06-17 19:56:36 -0500992 struct lpfc_iocbq *cmdiocb, *rspiocb;
James Smart14691152006-12-02 13:34:28 -0500993 struct lpfc_dmabuf *pcmd, *prsp, *mp;
dea31012005-04-17 16:05:31 -0500994 uint32_t *lp;
995 IOCB_t *irsp;
996 struct serv_parm *sp;
997 LPFC_MBOXQ_t *mbox;
998
999 cmdiocb = (struct lpfc_iocbq *) arg;
1000 rspiocb = cmdiocb->context_un.rsp_iocb;
1001
1002 if (ndlp->nlp_flag & NLP_ACC_REGLOGIN) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001003 /* Recovery from PLOGI collision logic */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001004 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001005 }
1006
1007 irsp = &rspiocb->iocb;
1008
1009 if (irsp->ulpStatus)
1010 goto out;
1011
1012 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
1013
James Smart2e0fef82007-06-17 19:56:36 -05001014 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
dea31012005-04-17 16:05:31 -05001015
James Smart2e0fef82007-06-17 19:56:36 -05001016 lp = (uint32_t *) prsp->virt;
dea31012005-04-17 16:05:31 -05001017 sp = (struct serv_parm *) ((uint8_t *) lp + sizeof (uint32_t));
James Smart58da1ff2008-04-07 10:15:56 -04001018
1019 /* Some switches have FDMI servers returning 0 for WWN */
1020 if ((ndlp->nlp_DID != FDMI_DID) &&
1021 (wwn_to_u64(sp->portName.u.wwn) == 0 ||
1022 wwn_to_u64(sp->nodeName.u.wwn) == 0)) {
James Smarta8adb832007-10-27 13:37:53 -04001023 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1024 "0142 PLOGI RSP: Invalid WWN.\n");
1025 goto out;
1026 }
James Smart341af102010-01-26 23:07:37 -05001027 if (!lpfc_check_sparm(vport, ndlp, sp, CLASS3, 0))
dea31012005-04-17 16:05:31 -05001028 goto out;
dea31012005-04-17 16:05:31 -05001029 /* PLOGI chkparm OK */
James Smarte8b62012007-08-02 11:10:09 -04001030 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1031 "0121 PLOGI chkparm OK Data: x%x x%x x%x x%x\n",
1032 ndlp->nlp_DID, ndlp->nlp_state,
1033 ndlp->nlp_flag, ndlp->nlp_rpi);
James Smart3de2a652007-08-02 11:09:59 -04001034 if (vport->cfg_fcp_class == 2 && (sp->cls2.classValid))
dea31012005-04-17 16:05:31 -05001035 ndlp->nlp_fcp_info |= CLASS2;
James Smart2e0fef82007-06-17 19:56:36 -05001036 else
dea31012005-04-17 16:05:31 -05001037 ndlp->nlp_fcp_info |= CLASS3;
James Smart2e0fef82007-06-17 19:56:36 -05001038
dea31012005-04-17 16:05:31 -05001039 ndlp->nlp_class_sup = 0;
1040 if (sp->cls1.classValid)
1041 ndlp->nlp_class_sup |= FC_COS_CLASS1;
1042 if (sp->cls2.classValid)
1043 ndlp->nlp_class_sup |= FC_COS_CLASS2;
1044 if (sp->cls3.classValid)
1045 ndlp->nlp_class_sup |= FC_COS_CLASS3;
1046 if (sp->cls4.classValid)
1047 ndlp->nlp_class_sup |= FC_COS_CLASS4;
1048 ndlp->nlp_maxframe =
James Smart2e0fef82007-06-17 19:56:36 -05001049 ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) | sp->cmn.bbRcvSizeLsb;
dea31012005-04-17 16:05:31 -05001050
James Smart2e0fef82007-06-17 19:56:36 -05001051 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
James Smart92d7f7b2007-06-17 19:56:38 -05001052 if (!mbox) {
James Smarte8b62012007-08-02 11:10:09 -04001053 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1054 "0133 PLOGI: no memory for reg_login "
James Smart92d7f7b2007-06-17 19:56:38 -05001055 "Data: x%x x%x x%x x%x\n",
James Smart92d7f7b2007-06-17 19:56:38 -05001056 ndlp->nlp_DID, ndlp->nlp_state,
1057 ndlp->nlp_flag, ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05001058 goto out;
James Smart92d7f7b2007-06-17 19:56:38 -05001059 }
dea31012005-04-17 16:05:31 -05001060
James Smart2e0fef82007-06-17 19:56:36 -05001061 lpfc_unreg_rpi(vport, ndlp);
1062
James Smart6fb120a2009-05-22 14:52:59 -04001063 if (lpfc_reg_rpi(phba, vport->vpi, irsp->un.elsreq64.remoteID,
James Smart40426292010-12-15 17:58:10 -05001064 (uint8_t *) sp, mbox, ndlp->nlp_rpi) == 0) {
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05001065 switch (ndlp->nlp_DID) {
dea31012005-04-17 16:05:31 -05001066 case NameServer_DID:
James Smartde0c5b32007-04-25 09:52:27 -04001067 mbox->mbox_cmpl = lpfc_mbx_cmpl_ns_reg_login;
dea31012005-04-17 16:05:31 -05001068 break;
1069 case FDMI_DID:
James Smartde0c5b32007-04-25 09:52:27 -04001070 mbox->mbox_cmpl = lpfc_mbx_cmpl_fdmi_reg_login;
dea31012005-04-17 16:05:31 -05001071 break;
1072 default:
James Smartffc95492010-06-07 15:23:17 -04001073 ndlp->nlp_flag |= NLP_REG_LOGIN_SEND;
James Smartde0c5b32007-04-25 09:52:27 -04001074 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
dea31012005-04-17 16:05:31 -05001075 }
James Smart329f9bc2007-04-25 09:53:01 -04001076 mbox->context2 = lpfc_nlp_get(ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05001077 mbox->vport = vport;
James Smart0b727fe2007-10-27 13:37:25 -04001078 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
dea31012005-04-17 16:05:31 -05001079 != MBX_NOT_FINISHED) {
James Smart2e0fef82007-06-17 19:56:36 -05001080 lpfc_nlp_set_state(vport, ndlp,
1081 NLP_STE_REG_LOGIN_ISSUE);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001082 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001083 }
James Smartffc95492010-06-07 15:23:17 -04001084 if (ndlp->nlp_flag & NLP_REG_LOGIN_SEND)
1085 ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND;
James Smartfa4066b2008-01-11 01:53:27 -05001086 /* decrement node reference count to the failed mbox
1087 * command
1088 */
James Smart329f9bc2007-04-25 09:53:01 -04001089 lpfc_nlp_put(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05001090 mp = (struct lpfc_dmabuf *) mbox->context1;
James Smart14691152006-12-02 13:34:28 -05001091 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1092 kfree(mp);
dea31012005-04-17 16:05:31 -05001093 mempool_free(mbox, phba->mbox_mem_pool);
James Smart92d7f7b2007-06-17 19:56:38 -05001094
James Smarte8b62012007-08-02 11:10:09 -04001095 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1096 "0134 PLOGI: cannot issue reg_login "
1097 "Data: x%x x%x x%x x%x\n",
1098 ndlp->nlp_DID, ndlp->nlp_state,
1099 ndlp->nlp_flag, ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05001100 } else {
1101 mempool_free(mbox, phba->mbox_mem_pool);
James Smart92d7f7b2007-06-17 19:56:38 -05001102
James Smarte8b62012007-08-02 11:10:09 -04001103 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1104 "0135 PLOGI: cannot format reg_login "
1105 "Data: x%x x%x x%x x%x\n",
1106 ndlp->nlp_DID, ndlp->nlp_state,
1107 ndlp->nlp_flag, ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05001108 }
1109
1110
James Smart92d7f7b2007-06-17 19:56:38 -05001111out:
1112 if (ndlp->nlp_DID == NameServer_DID) {
1113 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04001114 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1115 "0261 Cannot Register NameServer login\n");
James Smart92d7f7b2007-06-17 19:56:38 -05001116 }
1117
James Smart8b455cf2013-01-03 15:43:53 -05001118 /*
1119 ** In case the node reference counter does not go to zero, ensure that
1120 ** the stale state for the node is not processed.
1121 */
1122
1123 ndlp->nlp_prev_state = ndlp->nlp_state;
1124 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
James Smart0ff10d42008-01-11 01:52:36 -05001125 spin_lock_irq(shost->host_lock);
James Smarta8adb832007-10-27 13:37:53 -04001126 ndlp->nlp_flag |= NLP_DEFER_RM;
James Smart0ff10d42008-01-11 01:52:36 -05001127 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001128 return NLP_STE_FREED_NODE;
dea31012005-04-17 16:05:31 -05001129}
1130
1131static uint32_t
James Smart0ff10d42008-01-11 01:52:36 -05001132lpfc_cmpl_logo_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1133 void *arg, uint32_t evt)
1134{
1135 return ndlp->nlp_state;
1136}
1137
1138static uint32_t
1139lpfc_cmpl_reglogin_plogi_issue(struct lpfc_vport *vport,
1140 struct lpfc_nodelist *ndlp, void *arg, uint32_t evt)
1141{
James Smart78730cf2010-04-06 15:06:30 -04001142 struct lpfc_hba *phba;
1143 LPFC_MBOXQ_t *pmb = (LPFC_MBOXQ_t *) arg;
1144 MAILBOX_t *mb = &pmb->u.mb;
1145 uint16_t rpi;
1146
1147 phba = vport->phba;
1148 /* Release the RPI */
1149 if (!(phba->pport->load_flag & FC_UNLOADING) &&
1150 !mb->mbxStatus) {
1151 rpi = pmb->u.mb.un.varWords[0];
1152 lpfc_release_rpi(phba, vport, rpi);
1153 }
James Smart0ff10d42008-01-11 01:52:36 -05001154 return ndlp->nlp_state;
1155}
1156
1157static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001158lpfc_device_rm_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1159 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001160{
James Smart2e0fef82007-06-17 19:56:36 -05001161 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001162
James Smart2e0fef82007-06-17 19:56:36 -05001163 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1164 spin_lock_irq(shost->host_lock);
1165 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
1166 spin_unlock_irq(shost->host_lock);
1167 return ndlp->nlp_state;
1168 } else {
1169 /* software abort outstanding PLOGI */
1170 lpfc_els_abort(vport->phba, ndlp);
1171
1172 lpfc_drop_node(vport, ndlp);
James Smarta0f9b482006-04-15 11:52:56 -04001173 return NLP_STE_FREED_NODE;
1174 }
dea31012005-04-17 16:05:31 -05001175}
1176
1177static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001178lpfc_device_recov_plogi_issue(struct lpfc_vport *vport,
1179 struct lpfc_nodelist *ndlp,
1180 void *arg,
1181 uint32_t evt)
dea31012005-04-17 16:05:31 -05001182{
James Smart2e0fef82007-06-17 19:56:36 -05001183 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1184 struct lpfc_hba *phba = vport->phba;
1185
James Smart92d7f7b2007-06-17 19:56:38 -05001186 /* Don't do anything that will mess up processing of the
1187 * previous RSCN.
1188 */
1189 if (vport->fc_flag & FC_RSCN_DEFERRED)
1190 return ndlp->nlp_state;
1191
dea31012005-04-17 16:05:31 -05001192 /* software abort outstanding PLOGI */
James Smart07951072007-04-25 09:51:38 -04001193 lpfc_els_abort(phba, ndlp);
dea31012005-04-17 16:05:31 -05001194
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001195 ndlp->nlp_prev_state = NLP_STE_PLOGI_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -05001196 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
James Smart92d7f7b2007-06-17 19:56:38 -05001197 spin_lock_irq(shost->host_lock);
James Smarta0f9b482006-04-15 11:52:56 -04001198 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
James Smart2e0fef82007-06-17 19:56:36 -05001199 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001200
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001201 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001202}
1203
1204static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001205lpfc_rcv_plogi_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1206 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001207{
James Smart0d2b6b82008-06-14 22:52:47 -04001208 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart2e0fef82007-06-17 19:56:36 -05001209 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001210 struct lpfc_iocbq *cmdiocb;
1211
1212 /* software abort outstanding ADISC */
James Smart07951072007-04-25 09:51:38 -04001213 lpfc_els_abort(phba, ndlp);
dea31012005-04-17 16:05:31 -05001214
1215 cmdiocb = (struct lpfc_iocbq *) arg;
1216
James Smart0d2b6b82008-06-14 22:52:47 -04001217 if (lpfc_rcv_plogi(vport, ndlp, cmdiocb)) {
1218 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1219 spin_lock_irq(shost->host_lock);
1220 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
1221 spin_unlock_irq(shost->host_lock);
James Smart90160e02008-08-24 21:49:45 -04001222 if (vport->num_disc_nodes)
James Smart0d2b6b82008-06-14 22:52:47 -04001223 lpfc_more_adisc(vport);
James Smart0d2b6b82008-06-14 22:52:47 -04001224 }
1225 return ndlp->nlp_state;
1226 }
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001227 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -05001228 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
1229 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
dea31012005-04-17 16:05:31 -05001230
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001231 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001232}
1233
1234static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001235lpfc_rcv_prli_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1236 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001237{
James Smart2e0fef82007-06-17 19:56:36 -05001238 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001239
James Smart2e0fef82007-06-17 19:56:36 -05001240 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001241 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001242}
1243
1244static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001245lpfc_rcv_logo_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1246 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001247{
James Smart2e0fef82007-06-17 19:56:36 -05001248 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001249 struct lpfc_iocbq *cmdiocb;
1250
1251 cmdiocb = (struct lpfc_iocbq *) arg;
1252
1253 /* software abort outstanding ADISC */
James Smart07951072007-04-25 09:51:38 -04001254 lpfc_els_abort(phba, ndlp);
dea31012005-04-17 16:05:31 -05001255
James Smart2e0fef82007-06-17 19:56:36 -05001256 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001257 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001258}
1259
1260static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001261lpfc_rcv_padisc_adisc_issue(struct lpfc_vport *vport,
1262 struct lpfc_nodelist *ndlp,
1263 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001264{
1265 struct lpfc_iocbq *cmdiocb;
1266
1267 cmdiocb = (struct lpfc_iocbq *) arg;
1268
James Smart2e0fef82007-06-17 19:56:36 -05001269 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001270 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001271}
1272
1273static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001274lpfc_rcv_prlo_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1275 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001276{
1277 struct lpfc_iocbq *cmdiocb;
1278
1279 cmdiocb = (struct lpfc_iocbq *) arg;
1280
1281 /* Treat like rcv logo */
James Smart2e0fef82007-06-17 19:56:36 -05001282 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_PRLO);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001283 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001284}
1285
1286static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001287lpfc_cmpl_adisc_adisc_issue(struct lpfc_vport *vport,
1288 struct lpfc_nodelist *ndlp,
1289 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001290{
James Smart2e0fef82007-06-17 19:56:36 -05001291 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1292 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001293 struct lpfc_iocbq *cmdiocb, *rspiocb;
1294 IOCB_t *irsp;
1295 ADISC *ap;
James Smart6fb120a2009-05-22 14:52:59 -04001296 int rc;
dea31012005-04-17 16:05:31 -05001297
1298 cmdiocb = (struct lpfc_iocbq *) arg;
1299 rspiocb = cmdiocb->context_un.rsp_iocb;
1300
1301 ap = (ADISC *)lpfc_check_elscmpl_iocb(phba, cmdiocb, rspiocb);
1302 irsp = &rspiocb->iocb;
1303
1304 if ((irsp->ulpStatus) ||
James Smart92d7f7b2007-06-17 19:56:38 -05001305 (!lpfc_check_adisc(vport, ndlp, &ap->nodeName, &ap->portName))) {
dea31012005-04-17 16:05:31 -05001306 /* 1 sec timeout */
1307 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ);
James Smart2e0fef82007-06-17 19:56:36 -05001308 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001309 ndlp->nlp_flag |= NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05001310 spin_unlock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001311 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
dea31012005-04-17 16:05:31 -05001312
James Smart2e0fef82007-06-17 19:56:36 -05001313 memset(&ndlp->nlp_nodename, 0, sizeof(struct lpfc_name));
1314 memset(&ndlp->nlp_portname, 0, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05001315
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001316 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -05001317 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1318 lpfc_unreg_rpi(vport, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001319 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001320 }
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001321
James Smart6fb120a2009-05-22 14:52:59 -04001322 if (phba->sli_rev == LPFC_SLI_REV4) {
James Smart6b5151f2012-01-18 16:24:06 -05001323 rc = lpfc_sli4_resume_rpi(ndlp, NULL, NULL);
James Smart6fb120a2009-05-22 14:52:59 -04001324 if (rc) {
1325 /* Stay in state and retry. */
1326 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
1327 return ndlp->nlp_state;
1328 }
1329 }
1330
James.Smart@Emulex.Com25013222005-06-25 10:34:33 -04001331 if (ndlp->nlp_type & NLP_FCP_TARGET) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001332 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -05001333 lpfc_nlp_set_state(vport, ndlp, NLP_STE_MAPPED_NODE);
James.Smart@Emulex.Com25013222005-06-25 10:34:33 -04001334 } else {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001335 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -05001336 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
James.Smart@Emulex.Com25013222005-06-25 10:34:33 -04001337 }
James Smart6fb120a2009-05-22 14:52:59 -04001338
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001339 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001340}
1341
1342static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001343lpfc_device_rm_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1344 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001345{
James Smart2e0fef82007-06-17 19:56:36 -05001346 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001347
James Smart2e0fef82007-06-17 19:56:36 -05001348 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1349 spin_lock_irq(shost->host_lock);
1350 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
1351 spin_unlock_irq(shost->host_lock);
1352 return ndlp->nlp_state;
1353 } else {
1354 /* software abort outstanding ADISC */
1355 lpfc_els_abort(vport->phba, ndlp);
1356
1357 lpfc_drop_node(vport, ndlp);
James Smarta0f9b482006-04-15 11:52:56 -04001358 return NLP_STE_FREED_NODE;
1359 }
dea31012005-04-17 16:05:31 -05001360}
1361
1362static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001363lpfc_device_recov_adisc_issue(struct lpfc_vport *vport,
1364 struct lpfc_nodelist *ndlp,
1365 void *arg,
1366 uint32_t evt)
dea31012005-04-17 16:05:31 -05001367{
James Smart2e0fef82007-06-17 19:56:36 -05001368 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1369 struct lpfc_hba *phba = vport->phba;
1370
James Smart92d7f7b2007-06-17 19:56:38 -05001371 /* Don't do anything that will mess up processing of the
1372 * previous RSCN.
1373 */
1374 if (vport->fc_flag & FC_RSCN_DEFERRED)
1375 return ndlp->nlp_state;
1376
dea31012005-04-17 16:05:31 -05001377 /* software abort outstanding ADISC */
James Smart07951072007-04-25 09:51:38 -04001378 lpfc_els_abort(phba, ndlp);
dea31012005-04-17 16:05:31 -05001379
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001380 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -05001381 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1382 spin_lock_irq(shost->host_lock);
James Smarta0f9b482006-04-15 11:52:56 -04001383 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
James Smart2e0fef82007-06-17 19:56:36 -05001384 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05001385 lpfc_disc_set_adisc(vport, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001386 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001387}
1388
1389static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001390lpfc_rcv_plogi_reglogin_issue(struct lpfc_vport *vport,
1391 struct lpfc_nodelist *ndlp,
1392 void *arg,
dea31012005-04-17 16:05:31 -05001393 uint32_t evt)
1394{
James Smart2e0fef82007-06-17 19:56:36 -05001395 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001396
James Smart2e0fef82007-06-17 19:56:36 -05001397 lpfc_rcv_plogi(vport, ndlp, cmdiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001398 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001399}
1400
1401static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001402lpfc_rcv_prli_reglogin_issue(struct lpfc_vport *vport,
1403 struct lpfc_nodelist *ndlp,
1404 void *arg,
dea31012005-04-17 16:05:31 -05001405 uint32_t evt)
1406{
James Smart2e0fef82007-06-17 19:56:36 -05001407 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001408
James Smart2e0fef82007-06-17 19:56:36 -05001409 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001410 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001411}
1412
1413static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001414lpfc_rcv_logo_reglogin_issue(struct lpfc_vport *vport,
1415 struct lpfc_nodelist *ndlp,
1416 void *arg,
dea31012005-04-17 16:05:31 -05001417 uint32_t evt)
1418{
James Smart2e0fef82007-06-17 19:56:36 -05001419 struct lpfc_hba *phba = vport->phba;
1420 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
James Smart7054a602007-04-25 09:52:34 -04001421 LPFC_MBOXQ_t *mb;
1422 LPFC_MBOXQ_t *nextmb;
1423 struct lpfc_dmabuf *mp;
dea31012005-04-17 16:05:31 -05001424
1425 cmdiocb = (struct lpfc_iocbq *) arg;
1426
James Smart7054a602007-04-25 09:52:34 -04001427 /* cleanup any ndlp on mbox q waiting for reglogin cmpl */
1428 if ((mb = phba->sli.mbox_active)) {
James Smart04c68492009-05-22 14:52:52 -04001429 if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) &&
James Smart7054a602007-04-25 09:52:34 -04001430 (ndlp == (struct lpfc_nodelist *) mb->context2)) {
James Smart92d7f7b2007-06-17 19:56:38 -05001431 lpfc_nlp_put(ndlp);
James Smart7054a602007-04-25 09:52:34 -04001432 mb->context2 = NULL;
1433 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1434 }
1435 }
1436
James Smart2e0fef82007-06-17 19:56:36 -05001437 spin_lock_irq(&phba->hbalock);
James Smart7054a602007-04-25 09:52:34 -04001438 list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) {
James Smart04c68492009-05-22 14:52:52 -04001439 if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) &&
James Smart7054a602007-04-25 09:52:34 -04001440 (ndlp == (struct lpfc_nodelist *) mb->context2)) {
1441 mp = (struct lpfc_dmabuf *) (mb->context1);
1442 if (mp) {
James Smart98c9ea52007-10-27 13:37:33 -04001443 __lpfc_mbuf_free(phba, mp->virt, mp->phys);
James Smart7054a602007-04-25 09:52:34 -04001444 kfree(mp);
1445 }
James Smart92d7f7b2007-06-17 19:56:38 -05001446 lpfc_nlp_put(ndlp);
James Smart7054a602007-04-25 09:52:34 -04001447 list_del(&mb->list);
James Smart5ffc2662009-11-18 15:39:44 -05001448 phba->sli.mboxq_cnt--;
James Smart7054a602007-04-25 09:52:34 -04001449 mempool_free(mb, phba->mbox_mem_pool);
1450 }
1451 }
James Smart2e0fef82007-06-17 19:56:36 -05001452 spin_unlock_irq(&phba->hbalock);
James Smart7054a602007-04-25 09:52:34 -04001453
James Smart2e0fef82007-06-17 19:56:36 -05001454 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001455 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001456}
1457
1458static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001459lpfc_rcv_padisc_reglogin_issue(struct lpfc_vport *vport,
1460 struct lpfc_nodelist *ndlp,
1461 void *arg,
dea31012005-04-17 16:05:31 -05001462 uint32_t evt)
1463{
James Smart2e0fef82007-06-17 19:56:36 -05001464 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001465
James Smart2e0fef82007-06-17 19:56:36 -05001466 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001467 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001468}
1469
1470static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001471lpfc_rcv_prlo_reglogin_issue(struct lpfc_vport *vport,
1472 struct lpfc_nodelist *ndlp,
1473 void *arg,
dea31012005-04-17 16:05:31 -05001474 uint32_t evt)
1475{
1476 struct lpfc_iocbq *cmdiocb;
1477
1478 cmdiocb = (struct lpfc_iocbq *) arg;
James Smart51ef4c22007-08-02 11:10:31 -04001479 lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001480 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001481}
1482
1483static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001484lpfc_cmpl_reglogin_reglogin_issue(struct lpfc_vport *vport,
1485 struct lpfc_nodelist *ndlp,
1486 void *arg,
1487 uint32_t evt)
dea31012005-04-17 16:05:31 -05001488{
James Smart2e0fef82007-06-17 19:56:36 -05001489 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart2e0fef82007-06-17 19:56:36 -05001490 LPFC_MBOXQ_t *pmb = (LPFC_MBOXQ_t *) arg;
James Smart04c68492009-05-22 14:52:52 -04001491 MAILBOX_t *mb = &pmb->u.mb;
James Smart2e0fef82007-06-17 19:56:36 -05001492 uint32_t did = mb->un.varWords[1];
dea31012005-04-17 16:05:31 -05001493
dea31012005-04-17 16:05:31 -05001494 if (mb->mbxStatus) {
1495 /* RegLogin failed */
James Smarte8b62012007-08-02 11:10:09 -04001496 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
James Smart6d368e52011-05-24 11:44:12 -04001497 "0246 RegLogin failed Data: x%x x%x x%x x%x "
1498 "x%x\n",
1499 did, mb->mbxStatus, vport->port_state,
1500 mb->un.varRegLogin.vpi,
1501 mb->un.varRegLogin.rpi);
James Smartd0e56da2006-07-06 15:49:42 -04001502 /*
1503 * If RegLogin failed due to lack of HBA resources do not
1504 * retry discovery.
1505 */
1506 if (mb->mbxStatus == MBXERR_RPI_FULL) {
James Smart87af33f2007-10-27 13:37:43 -04001507 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
1508 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
James Smartd0e56da2006-07-06 15:49:42 -04001509 return ndlp->nlp_state;
1510 }
1511
James Smart2e0fef82007-06-17 19:56:36 -05001512 /* Put ndlp in npr state set plogi timer for 1 sec */
dea31012005-04-17 16:05:31 -05001513 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ * 1);
James Smart2e0fef82007-06-17 19:56:36 -05001514 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001515 ndlp->nlp_flag |= NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05001516 spin_unlock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001517 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
dea31012005-04-17 16:05:31 -05001518
James Smart2e0fef82007-06-17 19:56:36 -05001519 lpfc_issue_els_logo(vport, ndlp, 0);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001520 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -05001521 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001522 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001523 }
1524
James Smart6d368e52011-05-24 11:44:12 -04001525 /* SLI4 ports have preallocated logical rpis. */
1526 if (vport->phba->sli_rev < LPFC_SLI_REV4)
1527 ndlp->nlp_rpi = mb->un.varWords[0];
1528
James Smart40426292010-12-15 17:58:10 -05001529 ndlp->nlp_flag |= NLP_RPI_REGISTERED;
dea31012005-04-17 16:05:31 -05001530
1531 /* Only if we are not a fabric nport do we issue PRLI */
1532 if (!(ndlp->nlp_type & NLP_FABRIC)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001533 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -05001534 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
1535 lpfc_issue_els_prli(vport, ndlp, 0);
dea31012005-04-17 16:05:31 -05001536 } else {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001537 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -05001538 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
dea31012005-04-17 16:05:31 -05001539 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001540 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001541}
1542
1543static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001544lpfc_device_rm_reglogin_issue(struct lpfc_vport *vport,
1545 struct lpfc_nodelist *ndlp,
1546 void *arg,
dea31012005-04-17 16:05:31 -05001547 uint32_t evt)
1548{
James Smart2e0fef82007-06-17 19:56:36 -05001549 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1550
1551 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1552 spin_lock_irq(shost->host_lock);
James Smarta0f9b482006-04-15 11:52:56 -04001553 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
James Smart2e0fef82007-06-17 19:56:36 -05001554 spin_unlock_irq(shost->host_lock);
James Smarta0f9b482006-04-15 11:52:56 -04001555 return ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05001556 } else {
1557 lpfc_drop_node(vport, ndlp);
James Smarta0f9b482006-04-15 11:52:56 -04001558 return NLP_STE_FREED_NODE;
1559 }
dea31012005-04-17 16:05:31 -05001560}
1561
1562static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001563lpfc_device_recov_reglogin_issue(struct lpfc_vport *vport,
1564 struct lpfc_nodelist *ndlp,
1565 void *arg,
1566 uint32_t evt)
dea31012005-04-17 16:05:31 -05001567{
James Smart2e0fef82007-06-17 19:56:36 -05001568 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1569
James Smart92d7f7b2007-06-17 19:56:38 -05001570 /* Don't do anything that will mess up processing of the
1571 * previous RSCN.
1572 */
1573 if (vport->fc_flag & FC_RSCN_DEFERRED)
1574 return ndlp->nlp_state;
1575
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001576 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -05001577 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1578 spin_lock_irq(shost->host_lock);
James Smartffc95492010-06-07 15:23:17 -04001579 ndlp->nlp_flag |= NLP_IGNR_REG_CMPL;
James Smarta0f9b482006-04-15 11:52:56 -04001580 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
James Smart2e0fef82007-06-17 19:56:36 -05001581 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05001582 lpfc_disc_set_adisc(vport, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001583 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001584}
1585
1586static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001587lpfc_rcv_plogi_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1588 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001589{
1590 struct lpfc_iocbq *cmdiocb;
1591
1592 cmdiocb = (struct lpfc_iocbq *) arg;
1593
James Smart2e0fef82007-06-17 19:56:36 -05001594 lpfc_rcv_plogi(vport, ndlp, cmdiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001595 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001596}
1597
1598static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001599lpfc_rcv_prli_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1600 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001601{
James Smart2e0fef82007-06-17 19:56:36 -05001602 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001603
James Smart2e0fef82007-06-17 19:56:36 -05001604 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001605 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001606}
1607
1608static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001609lpfc_rcv_logo_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1610 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001611{
James Smart2e0fef82007-06-17 19:56:36 -05001612 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001613
1614 /* Software abort outstanding PRLI before sending acc */
James Smart2e0fef82007-06-17 19:56:36 -05001615 lpfc_els_abort(vport->phba, ndlp);
dea31012005-04-17 16:05:31 -05001616
James Smart2e0fef82007-06-17 19:56:36 -05001617 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001618 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001619}
1620
1621static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001622lpfc_rcv_padisc_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1623 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001624{
James Smart2e0fef82007-06-17 19:56:36 -05001625 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001626
James Smart2e0fef82007-06-17 19:56:36 -05001627 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001628 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001629}
1630
1631/* This routine is envoked when we rcv a PRLO request from a nport
1632 * we are logged into. We should send back a PRLO rsp setting the
1633 * appropriate bits.
1634 * NEXT STATE = PRLI_ISSUE
1635 */
1636static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001637lpfc_rcv_prlo_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1638 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001639{
James Smart2e0fef82007-06-17 19:56:36 -05001640 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001641
James Smart51ef4c22007-08-02 11:10:31 -04001642 lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001643 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001644}
1645
1646static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001647lpfc_cmpl_prli_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1648 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001649{
James Smart92d7f7b2007-06-17 19:56:38 -05001650 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001651 struct lpfc_iocbq *cmdiocb, *rspiocb;
James Smart2e0fef82007-06-17 19:56:36 -05001652 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001653 IOCB_t *irsp;
1654 PRLI *npr;
1655
1656 cmdiocb = (struct lpfc_iocbq *) arg;
1657 rspiocb = cmdiocb->context_un.rsp_iocb;
1658 npr = (PRLI *)lpfc_check_elscmpl_iocb(phba, cmdiocb, rspiocb);
1659
1660 irsp = &rspiocb->iocb;
1661 if (irsp->ulpStatus) {
James Smart858c9f62007-06-17 19:56:39 -05001662 if ((vport->port_type == LPFC_NPIV_PORT) &&
James Smart3de2a652007-08-02 11:09:59 -04001663 vport->cfg_restrict_login) {
James Smart858c9f62007-06-17 19:56:39 -05001664 goto out;
1665 }
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001666 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -05001667 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001668 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001669 }
1670
1671 /* Check out PRLI rsp */
1672 ndlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR);
1673 ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
1674 if ((npr->acceptRspCode == PRLI_REQ_EXECUTED) &&
1675 (npr->prliType == PRLI_FCP_TYPE)) {
1676 if (npr->initiatorFunc)
1677 ndlp->nlp_type |= NLP_FCP_INITIATOR;
1678 if (npr->targetFunc)
1679 ndlp->nlp_type |= NLP_FCP_TARGET;
1680 if (npr->Retry)
1681 ndlp->nlp_fcp_info |= NLP_FCP_2_DEVICE;
1682 }
James Smart92d7f7b2007-06-17 19:56:38 -05001683 if (!(ndlp->nlp_type & NLP_FCP_TARGET) &&
1684 (vport->port_type == LPFC_NPIV_PORT) &&
James Smart3de2a652007-08-02 11:09:59 -04001685 vport->cfg_restrict_login) {
James Smart858c9f62007-06-17 19:56:39 -05001686out:
James Smart92d7f7b2007-06-17 19:56:38 -05001687 spin_lock_irq(shost->host_lock);
1688 ndlp->nlp_flag |= NLP_TARGET_REMOVE;
1689 spin_unlock_irq(shost->host_lock);
1690 lpfc_issue_els_logo(vport, ndlp, 0);
1691
1692 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
James Smart87af33f2007-10-27 13:37:43 -04001693 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
James Smart92d7f7b2007-06-17 19:56:38 -05001694 return ndlp->nlp_state;
1695 }
dea31012005-04-17 16:05:31 -05001696
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001697 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
James Smart92d7f7b2007-06-17 19:56:38 -05001698 if (ndlp->nlp_type & NLP_FCP_TARGET)
1699 lpfc_nlp_set_state(vport, ndlp, NLP_STE_MAPPED_NODE);
1700 else
1701 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001702 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001703}
1704
1705/*! lpfc_device_rm_prli_issue
James Smart92d7f7b2007-06-17 19:56:38 -05001706 *
1707 * \pre
1708 * \post
1709 * \param phba
1710 * \param ndlp
1711 * \param arg
1712 * \param evt
1713 * \return uint32_t
1714 *
1715 * \b Description:
1716 * This routine is envoked when we a request to remove a nport we are in the
1717 * process of PRLIing. We should software abort outstanding prli, unreg
1718 * login, send a logout. We will change node state to UNUSED_NODE, put it
1719 * on plogi list so it can be freed when LOGO completes.
1720 *
1721 */
1722
dea31012005-04-17 16:05:31 -05001723static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001724lpfc_device_rm_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1725 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001726{
James Smart2e0fef82007-06-17 19:56:36 -05001727 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001728
James Smart2e0fef82007-06-17 19:56:36 -05001729 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1730 spin_lock_irq(shost->host_lock);
1731 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
1732 spin_unlock_irq(shost->host_lock);
1733 return ndlp->nlp_state;
1734 } else {
1735 /* software abort outstanding PLOGI */
1736 lpfc_els_abort(vport->phba, ndlp);
1737
1738 lpfc_drop_node(vport, ndlp);
James Smarta0f9b482006-04-15 11:52:56 -04001739 return NLP_STE_FREED_NODE;
1740 }
dea31012005-04-17 16:05:31 -05001741}
1742
1743
1744/*! lpfc_device_recov_prli_issue
James Smart92d7f7b2007-06-17 19:56:38 -05001745 *
1746 * \pre
1747 * \post
1748 * \param phba
1749 * \param ndlp
1750 * \param arg
1751 * \param evt
1752 * \return uint32_t
1753 *
1754 * \b Description:
1755 * The routine is envoked when the state of a device is unknown, like
1756 * during a link down. We should remove the nodelist entry from the
1757 * unmapped list, issue a UNREG_LOGIN, do a software abort of the
1758 * outstanding PRLI command, then free the node entry.
1759 */
dea31012005-04-17 16:05:31 -05001760static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001761lpfc_device_recov_prli_issue(struct lpfc_vport *vport,
1762 struct lpfc_nodelist *ndlp,
1763 void *arg,
1764 uint32_t evt)
dea31012005-04-17 16:05:31 -05001765{
James Smart2e0fef82007-06-17 19:56:36 -05001766 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1767 struct lpfc_hba *phba = vport->phba;
1768
James Smart92d7f7b2007-06-17 19:56:38 -05001769 /* Don't do anything that will mess up processing of the
1770 * previous RSCN.
1771 */
1772 if (vport->fc_flag & FC_RSCN_DEFERRED)
1773 return ndlp->nlp_state;
1774
dea31012005-04-17 16:05:31 -05001775 /* software abort outstanding PRLI */
James Smart07951072007-04-25 09:51:38 -04001776 lpfc_els_abort(phba, ndlp);
dea31012005-04-17 16:05:31 -05001777
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001778 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -05001779 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1780 spin_lock_irq(shost->host_lock);
James Smarta0f9b482006-04-15 11:52:56 -04001781 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
James Smart2e0fef82007-06-17 19:56:36 -05001782 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05001783 lpfc_disc_set_adisc(vport, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001784 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001785}
1786
1787static uint32_t
James Smart086a3452012-08-14 14:25:21 -04001788lpfc_rcv_plogi_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1789 void *arg, uint32_t evt)
1790{
1791 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *)arg;
1792 struct ls_rjt stat;
1793
1794 memset(&stat, 0, sizeof(struct ls_rjt));
1795 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
1796 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
1797 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
1798 return ndlp->nlp_state;
1799}
1800
1801static uint32_t
1802lpfc_rcv_prli_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1803 void *arg, uint32_t evt)
1804{
1805 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *)arg;
1806 struct ls_rjt stat;
1807
1808 memset(&stat, 0, sizeof(struct ls_rjt));
1809 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
1810 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
1811 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
1812 return ndlp->nlp_state;
1813}
1814
1815static uint32_t
1816lpfc_rcv_logo_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1817 void *arg, uint32_t evt)
1818{
1819 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1820 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *)arg;
1821
1822 spin_lock_irq(shost->host_lock);
1823 ndlp->nlp_flag &= NLP_LOGO_ACC;
1824 spin_unlock_irq(shost->host_lock);
1825 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
1826 return ndlp->nlp_state;
1827}
1828
1829static uint32_t
1830lpfc_rcv_padisc_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1831 void *arg, uint32_t evt)
1832{
1833 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *)arg;
1834 struct ls_rjt stat;
1835
1836 memset(&stat, 0, sizeof(struct ls_rjt));
1837 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
1838 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
1839 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
1840 return ndlp->nlp_state;
1841}
1842
1843static uint32_t
1844lpfc_rcv_prlo_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1845 void *arg, uint32_t evt)
1846{
1847 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *)arg;
1848 struct ls_rjt stat;
1849
1850 memset(&stat, 0, sizeof(struct ls_rjt));
1851 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
1852 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
1853 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
1854 return ndlp->nlp_state;
1855}
1856
1857static uint32_t
1858lpfc_cmpl_logo_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1859 void *arg, uint32_t evt)
1860{
1861 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1862
1863 ndlp->nlp_prev_state = NLP_STE_LOGO_ISSUE;
1864 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1865 spin_lock_irq(shost->host_lock);
1866 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
1867 spin_unlock_irq(shost->host_lock);
1868 lpfc_disc_set_adisc(vport, ndlp);
1869 return ndlp->nlp_state;
1870}
1871
1872static uint32_t
1873lpfc_device_rm_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1874 void *arg, uint32_t evt)
1875{
1876 /*
1877 * Take no action. If a LOGO is outstanding, then possibly DevLoss has
1878 * timed out and is calling for Device Remove. In this case, the LOGO
1879 * must be allowed to complete in state LOGO_ISSUE so that the rpi
1880 * and other NLP flags are correctly cleaned up.
1881 */
1882 return ndlp->nlp_state;
1883}
1884
1885static uint32_t
1886lpfc_device_recov_logo_issue(struct lpfc_vport *vport,
1887 struct lpfc_nodelist *ndlp,
1888 void *arg, uint32_t evt)
1889{
1890 /*
1891 * Device Recovery events have no meaning for a node with a LOGO
1892 * outstanding. The LOGO has to complete first and handle the
1893 * node from that point.
1894 */
1895 return ndlp->nlp_state;
1896}
1897
1898static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001899lpfc_rcv_plogi_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1900 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001901{
James Smart2e0fef82007-06-17 19:56:36 -05001902 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001903
James Smart2e0fef82007-06-17 19:56:36 -05001904 lpfc_rcv_plogi(vport, ndlp, cmdiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001905 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001906}
1907
1908static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001909lpfc_rcv_prli_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1910 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001911{
James Smart2e0fef82007-06-17 19:56:36 -05001912 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001913
James Smart2e0fef82007-06-17 19:56:36 -05001914 lpfc_rcv_prli(vport, ndlp, cmdiocb);
1915 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001916 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001917}
1918
1919static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001920lpfc_rcv_logo_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1921 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001922{
James Smart2e0fef82007-06-17 19:56:36 -05001923 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001924
James Smart2e0fef82007-06-17 19:56:36 -05001925 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001926 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001927}
1928
1929static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001930lpfc_rcv_padisc_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1931 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001932{
James Smart2e0fef82007-06-17 19:56:36 -05001933 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001934
James Smart2e0fef82007-06-17 19:56:36 -05001935 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001936 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001937}
1938
1939static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001940lpfc_rcv_prlo_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1941 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001942{
James Smart2e0fef82007-06-17 19:56:36 -05001943 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001944
James Smart51ef4c22007-08-02 11:10:31 -04001945 lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001946 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001947}
1948
1949static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001950lpfc_device_recov_unmap_node(struct lpfc_vport *vport,
1951 struct lpfc_nodelist *ndlp,
1952 void *arg,
1953 uint32_t evt)
dea31012005-04-17 16:05:31 -05001954{
James Smart2e0fef82007-06-17 19:56:36 -05001955 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1956
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001957 ndlp->nlp_prev_state = NLP_STE_UNMAPPED_NODE;
James Smart2e0fef82007-06-17 19:56:36 -05001958 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1959 spin_lock_irq(shost->host_lock);
James Smarta0f9b482006-04-15 11:52:56 -04001960 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
James Smart2e0fef82007-06-17 19:56:36 -05001961 spin_unlock_irq(shost->host_lock);
1962 lpfc_disc_set_adisc(vport, ndlp);
dea31012005-04-17 16:05:31 -05001963
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001964 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001965}
1966
1967static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001968lpfc_rcv_plogi_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1969 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001970{
James Smart2e0fef82007-06-17 19:56:36 -05001971 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001972
James Smart2e0fef82007-06-17 19:56:36 -05001973 lpfc_rcv_plogi(vport, ndlp, cmdiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001974 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001975}
1976
1977static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001978lpfc_rcv_prli_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1979 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001980{
James Smart2e0fef82007-06-17 19:56:36 -05001981 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001982
James Smart2e0fef82007-06-17 19:56:36 -05001983 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001984 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001985}
1986
1987static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001988lpfc_rcv_logo_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1989 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001990{
James Smart2e0fef82007-06-17 19:56:36 -05001991 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001992
James Smart2e0fef82007-06-17 19:56:36 -05001993 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001994 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001995}
1996
1997static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001998lpfc_rcv_padisc_mapped_node(struct lpfc_vport *vport,
1999 struct lpfc_nodelist *ndlp,
2000 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05002001{
James Smart2e0fef82007-06-17 19:56:36 -05002002 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05002003
James Smart2e0fef82007-06-17 19:56:36 -05002004 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002005 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05002006}
2007
2008static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05002009lpfc_rcv_prlo_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2010 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05002011{
James Smart2e0fef82007-06-17 19:56:36 -05002012 struct lpfc_hba *phba = vport->phba;
2013 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05002014
2015 /* flush the target */
James Smart51ef4c22007-08-02 11:10:31 -04002016 lpfc_sli_abort_iocb(vport, &phba->sli.ring[phba->sli.fcp_ring],
2017 ndlp->nlp_sid, 0, LPFC_CTX_TGT);
dea31012005-04-17 16:05:31 -05002018
2019 /* Treat like rcv logo */
James Smart2e0fef82007-06-17 19:56:36 -05002020 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_PRLO);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002021 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05002022}
2023
2024static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05002025lpfc_device_recov_mapped_node(struct lpfc_vport *vport,
2026 struct lpfc_nodelist *ndlp,
2027 void *arg,
2028 uint32_t evt)
dea31012005-04-17 16:05:31 -05002029{
James Smart2e0fef82007-06-17 19:56:36 -05002030 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2031
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002032 ndlp->nlp_prev_state = NLP_STE_MAPPED_NODE;
James Smart2e0fef82007-06-17 19:56:36 -05002033 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
2034 spin_lock_irq(shost->host_lock);
James Smarta0f9b482006-04-15 11:52:56 -04002035 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
James Smart2e0fef82007-06-17 19:56:36 -05002036 spin_unlock_irq(shost->host_lock);
2037 lpfc_disc_set_adisc(vport, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002038 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05002039}
2040
2041static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05002042lpfc_rcv_plogi_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2043 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05002044{
James Smart2e0fef82007-06-17 19:56:36 -05002045 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2046 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05002047
2048 /* Ignore PLOGI if we have an outstanding LOGO */
James Smart0d2b6b82008-06-14 22:52:47 -04002049 if (ndlp->nlp_flag & (NLP_LOGO_SND | NLP_LOGO_ACC))
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002050 return ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002051 if (lpfc_rcv_plogi(vport, ndlp, cmdiocb)) {
James Smart0d2b6b82008-06-14 22:52:47 -04002052 lpfc_cancel_retry_delay_tmo(vport, ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05002053 spin_lock_irq(shost->host_lock);
James Smart0d2b6b82008-06-14 22:52:47 -04002054 ndlp->nlp_flag &= ~(NLP_NPR_ADISC | NLP_NPR_2B_DISC);
James Smart2e0fef82007-06-17 19:56:36 -05002055 spin_unlock_irq(shost->host_lock);
James Smart0d2b6b82008-06-14 22:52:47 -04002056 } else if (!(ndlp->nlp_flag & NLP_NPR_2B_DISC)) {
2057 /* send PLOGI immediately, move to PLOGI issue state */
2058 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
2059 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
2060 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
2061 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
2062 }
dea31012005-04-17 16:05:31 -05002063 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002064 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05002065}
2066
2067static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05002068lpfc_rcv_prli_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2069 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05002070{
James Smart2e0fef82007-06-17 19:56:36 -05002071 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2072 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2073 struct ls_rjt stat;
dea31012005-04-17 16:05:31 -05002074
2075 memset(&stat, 0, sizeof (struct ls_rjt));
2076 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
2077 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
James Smart858c9f62007-06-17 19:56:39 -05002078 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05002079
2080 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
2081 if (ndlp->nlp_flag & NLP_NPR_ADISC) {
James Smart2e0fef82007-06-17 19:56:36 -05002082 spin_lock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002083 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002084 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
James Smart2e0fef82007-06-17 19:56:36 -05002085 spin_unlock_irq(shost->host_lock);
2086 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
2087 lpfc_issue_els_adisc(vport, ndlp, 0);
dea31012005-04-17 16:05:31 -05002088 } else {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002089 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
James Smart2e0fef82007-06-17 19:56:36 -05002090 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
2091 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
dea31012005-04-17 16:05:31 -05002092 }
2093 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002094 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05002095}
2096
2097static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05002098lpfc_rcv_logo_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2099 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05002100{
James Smart2e0fef82007-06-17 19:56:36 -05002101 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05002102
James Smart2e0fef82007-06-17 19:56:36 -05002103 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002104 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05002105}
2106
2107static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05002108lpfc_rcv_padisc_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2109 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05002110{
James Smart2e0fef82007-06-17 19:56:36 -05002111 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05002112
James Smart2e0fef82007-06-17 19:56:36 -05002113 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
James Smart33ccf8d2006-08-17 11:57:58 -04002114 /*
2115 * Do not start discovery if discovery is about to start
2116 * or discovery in progress for this node. Starting discovery
2117 * here will affect the counting of discovery threads.
2118 */
James Smart2fb9bd82006-12-02 13:33:57 -05002119 if (!(ndlp->nlp_flag & NLP_DELAY_TMO) &&
James Smart92d7f7b2007-06-17 19:56:38 -05002120 !(ndlp->nlp_flag & NLP_NPR_2B_DISC)) {
dea31012005-04-17 16:05:31 -05002121 if (ndlp->nlp_flag & NLP_NPR_ADISC) {
James Smart92d7f7b2007-06-17 19:56:38 -05002122 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002123 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
James Smart2e0fef82007-06-17 19:56:36 -05002124 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
2125 lpfc_issue_els_adisc(vport, ndlp, 0);
dea31012005-04-17 16:05:31 -05002126 } else {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002127 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
James Smart2e0fef82007-06-17 19:56:36 -05002128 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
2129 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
dea31012005-04-17 16:05:31 -05002130 }
2131 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002132 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05002133}
2134
2135static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05002136lpfc_rcv_prlo_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2137 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05002138{
James Smart2e0fef82007-06-17 19:56:36 -05002139 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2140 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05002141
James Smart2e0fef82007-06-17 19:56:36 -05002142 spin_lock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002143 ndlp->nlp_flag |= NLP_LOGO_ACC;
James Smart2e0fef82007-06-17 19:56:36 -05002144 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002145
James Smart51ef4c22007-08-02 11:10:31 -04002146 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05002147
James Smart2e0fef82007-06-17 19:56:36 -05002148 if ((ndlp->nlp_flag & NLP_DELAY_TMO) == 0) {
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002149 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ * 1);
James Smart2e0fef82007-06-17 19:56:36 -05002150 spin_lock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002151 ndlp->nlp_flag |= NLP_DELAY_TMO;
2152 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
James Smart2e0fef82007-06-17 19:56:36 -05002153 spin_unlock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002154 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002155 } else {
James Smart2e0fef82007-06-17 19:56:36 -05002156 spin_lock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002157 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
James Smart2e0fef82007-06-17 19:56:36 -05002158 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002159 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002160 return ndlp->nlp_state;
2161}
dea31012005-04-17 16:05:31 -05002162
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002163static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05002164lpfc_cmpl_plogi_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2165 void *arg, uint32_t evt)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002166{
2167 struct lpfc_iocbq *cmdiocb, *rspiocb;
James Smarta0f9b482006-04-15 11:52:56 -04002168 IOCB_t *irsp;
James Smart8b455cf2013-01-03 15:43:53 -05002169 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002170
2171 cmdiocb = (struct lpfc_iocbq *) arg;
2172 rspiocb = cmdiocb->context_un.rsp_iocb;
James Smarta0f9b482006-04-15 11:52:56 -04002173
2174 irsp = &rspiocb->iocb;
2175 if (irsp->ulpStatus) {
James Smart8b455cf2013-01-03 15:43:53 -05002176 spin_lock_irq(shost->host_lock);
James Smarta8adb832007-10-27 13:37:53 -04002177 ndlp->nlp_flag |= NLP_DEFER_RM;
James Smart8b455cf2013-01-03 15:43:53 -05002178 spin_unlock_irq(shost->host_lock);
James Smarta0f9b482006-04-15 11:52:56 -04002179 return NLP_STE_FREED_NODE;
2180 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002181 return ndlp->nlp_state;
2182}
2183
2184static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05002185lpfc_cmpl_prli_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2186 void *arg, uint32_t evt)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002187{
2188 struct lpfc_iocbq *cmdiocb, *rspiocb;
James Smarta0f9b482006-04-15 11:52:56 -04002189 IOCB_t *irsp;
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002190
2191 cmdiocb = (struct lpfc_iocbq *) arg;
2192 rspiocb = cmdiocb->context_un.rsp_iocb;
James Smarta0f9b482006-04-15 11:52:56 -04002193
2194 irsp = &rspiocb->iocb;
2195 if (irsp->ulpStatus && (ndlp->nlp_flag & NLP_NODEV_REMOVE)) {
James Smart2e0fef82007-06-17 19:56:36 -05002196 lpfc_drop_node(vport, ndlp);
James Smarta0f9b482006-04-15 11:52:56 -04002197 return NLP_STE_FREED_NODE;
2198 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002199 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05002200}
2201
2202static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05002203lpfc_cmpl_logo_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2204 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05002205{
James Smartd7c255b2008-08-24 21:50:00 -04002206 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart086a3452012-08-14 14:25:21 -04002207
2208 /* For the fabric port just clear the fc flags. */
James Smartd7c255b2008-08-24 21:50:00 -04002209 if (ndlp->nlp_DID == Fabric_DID) {
2210 spin_lock_irq(shost->host_lock);
2211 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
2212 spin_unlock_irq(shost->host_lock);
2213 }
James Smart2e0fef82007-06-17 19:56:36 -05002214 lpfc_unreg_rpi(vport, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002215 return ndlp->nlp_state;
2216}
2217
2218static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05002219lpfc_cmpl_adisc_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2220 void *arg, uint32_t evt)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002221{
2222 struct lpfc_iocbq *cmdiocb, *rspiocb;
James Smarta0f9b482006-04-15 11:52:56 -04002223 IOCB_t *irsp;
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002224
2225 cmdiocb = (struct lpfc_iocbq *) arg;
2226 rspiocb = cmdiocb->context_un.rsp_iocb;
James Smarta0f9b482006-04-15 11:52:56 -04002227
2228 irsp = &rspiocb->iocb;
2229 if (irsp->ulpStatus && (ndlp->nlp_flag & NLP_NODEV_REMOVE)) {
James Smart2e0fef82007-06-17 19:56:36 -05002230 lpfc_drop_node(vport, ndlp);
James Smarta0f9b482006-04-15 11:52:56 -04002231 return NLP_STE_FREED_NODE;
2232 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002233 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05002234}
2235
2236static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05002237lpfc_cmpl_reglogin_npr_node(struct lpfc_vport *vport,
2238 struct lpfc_nodelist *ndlp,
2239 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05002240{
James Smart2e0fef82007-06-17 19:56:36 -05002241 LPFC_MBOXQ_t *pmb = (LPFC_MBOXQ_t *) arg;
James Smart04c68492009-05-22 14:52:52 -04002242 MAILBOX_t *mb = &pmb->u.mb;
dea31012005-04-17 16:05:31 -05002243
James Smart04c68492009-05-22 14:52:52 -04002244 if (!mb->mbxStatus) {
James Smart6d368e52011-05-24 11:44:12 -04002245 /* SLI4 ports have preallocated logical rpis. */
2246 if (vport->phba->sli_rev < LPFC_SLI_REV4)
2247 ndlp->nlp_rpi = mb->un.varWords[0];
James Smart40426292010-12-15 17:58:10 -05002248 ndlp->nlp_flag |= NLP_RPI_REGISTERED;
James Smart04c68492009-05-22 14:52:52 -04002249 } else {
James Smarta0f9b482006-04-15 11:52:56 -04002250 if (ndlp->nlp_flag & NLP_NODEV_REMOVE) {
James Smart2e0fef82007-06-17 19:56:36 -05002251 lpfc_drop_node(vport, ndlp);
James Smarta0f9b482006-04-15 11:52:56 -04002252 return NLP_STE_FREED_NODE;
2253 }
2254 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002255 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05002256}
2257
2258static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05002259lpfc_device_rm_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2260 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05002261{
James Smart2e0fef82007-06-17 19:56:36 -05002262 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2263
James Smarta0f9b482006-04-15 11:52:56 -04002264 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
James Smart2e0fef82007-06-17 19:56:36 -05002265 spin_lock_irq(shost->host_lock);
James Smarta0f9b482006-04-15 11:52:56 -04002266 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
James Smart2e0fef82007-06-17 19:56:36 -05002267 spin_unlock_irq(shost->host_lock);
James Smarta0f9b482006-04-15 11:52:56 -04002268 return ndlp->nlp_state;
2269 }
James Smart2e0fef82007-06-17 19:56:36 -05002270 lpfc_drop_node(vport, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002271 return NLP_STE_FREED_NODE;
dea31012005-04-17 16:05:31 -05002272}
2273
2274static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05002275lpfc_device_recov_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2276 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05002277{
James Smart2e0fef82007-06-17 19:56:36 -05002278 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2279
James Smart92d7f7b2007-06-17 19:56:38 -05002280 /* Don't do anything that will mess up processing of the
2281 * previous RSCN.
2282 */
2283 if (vport->fc_flag & FC_RSCN_DEFERRED)
2284 return ndlp->nlp_state;
2285
James Smarteaf15d52008-12-04 22:39:29 -05002286 lpfc_cancel_retry_delay_tmo(vport, ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05002287 spin_lock_irq(shost->host_lock);
James Smarta0f9b482006-04-15 11:52:56 -04002288 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
James Smart2e0fef82007-06-17 19:56:36 -05002289 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002290 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05002291}
2292
2293
2294/* This next section defines the NPort Discovery State Machine */
2295
2296/* There are 4 different double linked lists nodelist entries can reside on.
2297 * The plogi list and adisc list are used when Link Up discovery or RSCN
2298 * processing is needed. Each list holds the nodes that we will send PLOGI
2299 * or ADISC on. These lists will keep track of what nodes will be effected
2300 * by an RSCN, or a Link Up (Typically, all nodes are effected on Link Up).
2301 * The unmapped_list will contain all nodes that we have successfully logged
2302 * into at the Fibre Channel level. The mapped_list will contain all nodes
2303 * that are mapped FCP targets.
2304 */
2305/*
2306 * The bind list is a list of undiscovered (potentially non-existent) nodes
2307 * that we have saved binding information on. This information is used when
2308 * nodes transition from the unmapped to the mapped list.
2309 */
2310/* For UNUSED_NODE state, the node has just been allocated .
2311 * For PLOGI_ISSUE and REG_LOGIN_ISSUE, the node is on
2312 * the PLOGI list. For REG_LOGIN_COMPL, the node is taken off the PLOGI list
2313 * and put on the unmapped list. For ADISC processing, the node is taken off
2314 * the ADISC list and placed on either the mapped or unmapped list (depending
2315 * on its previous state). Once on the unmapped list, a PRLI is issued and the
2316 * state changed to PRLI_ISSUE. When the PRLI completion occurs, the state is
2317 * changed to UNMAPPED_NODE. If the completion indicates a mapped
2318 * node, the node is taken off the unmapped list. The binding list is checked
2319 * for a valid binding, or a binding is automatically assigned. If binding
2320 * assignment is unsuccessful, the node is left on the unmapped list. If
2321 * binding assignment is successful, the associated binding list entry (if
2322 * any) is removed, and the node is placed on the mapped list.
2323 */
2324/*
2325 * For a Link Down, all nodes on the ADISC, PLOGI, unmapped or mapped
James Smartc01f3202006-08-18 17:47:08 -04002326 * lists will receive a DEVICE_RECOVERY event. If the linkdown or devloss timers
dea31012005-04-17 16:05:31 -05002327 * expire, all effected nodes will receive a DEVICE_RM event.
2328 */
2329/*
2330 * For a Link Up or RSCN, all nodes will move from the mapped / unmapped lists
2331 * to either the ADISC or PLOGI list. After a Nameserver query or ALPA loopmap
2332 * check, additional nodes may be added or removed (via DEVICE_RM) to / from
2333 * the PLOGI or ADISC lists. Once the PLOGI and ADISC lists are populated,
2334 * we will first process the ADISC list. 32 entries are processed initially and
2335 * ADISC is initited for each one. Completions / Events for each node are
2336 * funnelled thru the state machine. As each node finishes ADISC processing, it
2337 * starts ADISC for any nodes waiting for ADISC processing. If no nodes are
2338 * waiting, and the ADISC list count is identically 0, then we are done. For
2339 * Link Up discovery, since all nodes on the PLOGI list are UNREG_LOGIN'ed, we
2340 * can issue a CLEAR_LA and reenable Link Events. Next we will process the PLOGI
2341 * list. 32 entries are processed initially and PLOGI is initited for each one.
2342 * Completions / Events for each node are funnelled thru the state machine. As
2343 * each node finishes PLOGI processing, it starts PLOGI for any nodes waiting
2344 * for PLOGI processing. If no nodes are waiting, and the PLOGI list count is
2345 * indentically 0, then we are done. We have now completed discovery / RSCN
2346 * handling. Upon completion, ALL nodes should be on either the mapped or
2347 * unmapped lists.
2348 */
2349
2350static uint32_t (*lpfc_disc_action[NLP_STE_MAX_STATE * NLP_EVT_MAX_EVENT])
James Smart2e0fef82007-06-17 19:56:36 -05002351 (struct lpfc_vport *, struct lpfc_nodelist *, void *, uint32_t) = {
dea31012005-04-17 16:05:31 -05002352 /* Action routine Event Current State */
2353 lpfc_rcv_plogi_unused_node, /* RCV_PLOGI UNUSED_NODE */
2354 lpfc_rcv_els_unused_node, /* RCV_PRLI */
2355 lpfc_rcv_logo_unused_node, /* RCV_LOGO */
2356 lpfc_rcv_els_unused_node, /* RCV_ADISC */
2357 lpfc_rcv_els_unused_node, /* RCV_PDISC */
2358 lpfc_rcv_els_unused_node, /* RCV_PRLO */
2359 lpfc_disc_illegal, /* CMPL_PLOGI */
2360 lpfc_disc_illegal, /* CMPL_PRLI */
2361 lpfc_cmpl_logo_unused_node, /* CMPL_LOGO */
2362 lpfc_disc_illegal, /* CMPL_ADISC */
2363 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2364 lpfc_device_rm_unused_node, /* DEVICE_RM */
James Smartdf9e1b52011-12-13 13:22:17 -05002365 lpfc_device_recov_unused_node, /* DEVICE_RECOVERY */
dea31012005-04-17 16:05:31 -05002366
2367 lpfc_rcv_plogi_plogi_issue, /* RCV_PLOGI PLOGI_ISSUE */
James Smart92d7f7b2007-06-17 19:56:38 -05002368 lpfc_rcv_prli_plogi_issue, /* RCV_PRLI */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002369 lpfc_rcv_logo_plogi_issue, /* RCV_LOGO */
dea31012005-04-17 16:05:31 -05002370 lpfc_rcv_els_plogi_issue, /* RCV_ADISC */
2371 lpfc_rcv_els_plogi_issue, /* RCV_PDISC */
2372 lpfc_rcv_els_plogi_issue, /* RCV_PRLO */
2373 lpfc_cmpl_plogi_plogi_issue, /* CMPL_PLOGI */
2374 lpfc_disc_illegal, /* CMPL_PRLI */
James Smart0ff10d42008-01-11 01:52:36 -05002375 lpfc_cmpl_logo_plogi_issue, /* CMPL_LOGO */
dea31012005-04-17 16:05:31 -05002376 lpfc_disc_illegal, /* CMPL_ADISC */
James Smart0ff10d42008-01-11 01:52:36 -05002377 lpfc_cmpl_reglogin_plogi_issue,/* CMPL_REG_LOGIN */
dea31012005-04-17 16:05:31 -05002378 lpfc_device_rm_plogi_issue, /* DEVICE_RM */
2379 lpfc_device_recov_plogi_issue, /* DEVICE_RECOVERY */
2380
2381 lpfc_rcv_plogi_adisc_issue, /* RCV_PLOGI ADISC_ISSUE */
2382 lpfc_rcv_prli_adisc_issue, /* RCV_PRLI */
2383 lpfc_rcv_logo_adisc_issue, /* RCV_LOGO */
2384 lpfc_rcv_padisc_adisc_issue, /* RCV_ADISC */
2385 lpfc_rcv_padisc_adisc_issue, /* RCV_PDISC */
2386 lpfc_rcv_prlo_adisc_issue, /* RCV_PRLO */
2387 lpfc_disc_illegal, /* CMPL_PLOGI */
2388 lpfc_disc_illegal, /* CMPL_PRLI */
2389 lpfc_disc_illegal, /* CMPL_LOGO */
2390 lpfc_cmpl_adisc_adisc_issue, /* CMPL_ADISC */
2391 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2392 lpfc_device_rm_adisc_issue, /* DEVICE_RM */
2393 lpfc_device_recov_adisc_issue, /* DEVICE_RECOVERY */
2394
2395 lpfc_rcv_plogi_reglogin_issue, /* RCV_PLOGI REG_LOGIN_ISSUE */
2396 lpfc_rcv_prli_reglogin_issue, /* RCV_PLOGI */
2397 lpfc_rcv_logo_reglogin_issue, /* RCV_LOGO */
2398 lpfc_rcv_padisc_reglogin_issue, /* RCV_ADISC */
2399 lpfc_rcv_padisc_reglogin_issue, /* RCV_PDISC */
2400 lpfc_rcv_prlo_reglogin_issue, /* RCV_PRLO */
James Smart87af33f2007-10-27 13:37:43 -04002401 lpfc_cmpl_plogi_illegal, /* CMPL_PLOGI */
dea31012005-04-17 16:05:31 -05002402 lpfc_disc_illegal, /* CMPL_PRLI */
2403 lpfc_disc_illegal, /* CMPL_LOGO */
2404 lpfc_disc_illegal, /* CMPL_ADISC */
2405 lpfc_cmpl_reglogin_reglogin_issue,/* CMPL_REG_LOGIN */
2406 lpfc_device_rm_reglogin_issue, /* DEVICE_RM */
2407 lpfc_device_recov_reglogin_issue,/* DEVICE_RECOVERY */
2408
2409 lpfc_rcv_plogi_prli_issue, /* RCV_PLOGI PRLI_ISSUE */
2410 lpfc_rcv_prli_prli_issue, /* RCV_PRLI */
2411 lpfc_rcv_logo_prli_issue, /* RCV_LOGO */
2412 lpfc_rcv_padisc_prli_issue, /* RCV_ADISC */
2413 lpfc_rcv_padisc_prli_issue, /* RCV_PDISC */
2414 lpfc_rcv_prlo_prli_issue, /* RCV_PRLO */
James Smart87af33f2007-10-27 13:37:43 -04002415 lpfc_cmpl_plogi_illegal, /* CMPL_PLOGI */
dea31012005-04-17 16:05:31 -05002416 lpfc_cmpl_prli_prli_issue, /* CMPL_PRLI */
2417 lpfc_disc_illegal, /* CMPL_LOGO */
2418 lpfc_disc_illegal, /* CMPL_ADISC */
2419 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2420 lpfc_device_rm_prli_issue, /* DEVICE_RM */
2421 lpfc_device_recov_prli_issue, /* DEVICE_RECOVERY */
2422
James Smart086a3452012-08-14 14:25:21 -04002423 lpfc_rcv_plogi_logo_issue, /* RCV_PLOGI LOGO_ISSUE */
2424 lpfc_rcv_prli_logo_issue, /* RCV_PRLI */
2425 lpfc_rcv_logo_logo_issue, /* RCV_LOGO */
2426 lpfc_rcv_padisc_logo_issue, /* RCV_ADISC */
2427 lpfc_rcv_padisc_logo_issue, /* RCV_PDISC */
2428 lpfc_rcv_prlo_logo_issue, /* RCV_PRLO */
2429 lpfc_cmpl_plogi_illegal, /* CMPL_PLOGI */
2430 lpfc_disc_illegal, /* CMPL_PRLI */
2431 lpfc_cmpl_logo_logo_issue, /* CMPL_LOGO */
2432 lpfc_disc_illegal, /* CMPL_ADISC */
2433 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2434 lpfc_device_rm_logo_issue, /* DEVICE_RM */
2435 lpfc_device_recov_logo_issue, /* DEVICE_RECOVERY */
2436
dea31012005-04-17 16:05:31 -05002437 lpfc_rcv_plogi_unmap_node, /* RCV_PLOGI UNMAPPED_NODE */
2438 lpfc_rcv_prli_unmap_node, /* RCV_PRLI */
2439 lpfc_rcv_logo_unmap_node, /* RCV_LOGO */
2440 lpfc_rcv_padisc_unmap_node, /* RCV_ADISC */
2441 lpfc_rcv_padisc_unmap_node, /* RCV_PDISC */
2442 lpfc_rcv_prlo_unmap_node, /* RCV_PRLO */
2443 lpfc_disc_illegal, /* CMPL_PLOGI */
2444 lpfc_disc_illegal, /* CMPL_PRLI */
2445 lpfc_disc_illegal, /* CMPL_LOGO */
2446 lpfc_disc_illegal, /* CMPL_ADISC */
2447 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2448 lpfc_disc_illegal, /* DEVICE_RM */
2449 lpfc_device_recov_unmap_node, /* DEVICE_RECOVERY */
2450
2451 lpfc_rcv_plogi_mapped_node, /* RCV_PLOGI MAPPED_NODE */
2452 lpfc_rcv_prli_mapped_node, /* RCV_PRLI */
2453 lpfc_rcv_logo_mapped_node, /* RCV_LOGO */
2454 lpfc_rcv_padisc_mapped_node, /* RCV_ADISC */
2455 lpfc_rcv_padisc_mapped_node, /* RCV_PDISC */
2456 lpfc_rcv_prlo_mapped_node, /* RCV_PRLO */
2457 lpfc_disc_illegal, /* CMPL_PLOGI */
2458 lpfc_disc_illegal, /* CMPL_PRLI */
2459 lpfc_disc_illegal, /* CMPL_LOGO */
2460 lpfc_disc_illegal, /* CMPL_ADISC */
2461 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2462 lpfc_disc_illegal, /* DEVICE_RM */
2463 lpfc_device_recov_mapped_node, /* DEVICE_RECOVERY */
2464
2465 lpfc_rcv_plogi_npr_node, /* RCV_PLOGI NPR_NODE */
2466 lpfc_rcv_prli_npr_node, /* RCV_PRLI */
2467 lpfc_rcv_logo_npr_node, /* RCV_LOGO */
2468 lpfc_rcv_padisc_npr_node, /* RCV_ADISC */
2469 lpfc_rcv_padisc_npr_node, /* RCV_PDISC */
2470 lpfc_rcv_prlo_npr_node, /* RCV_PRLO */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002471 lpfc_cmpl_plogi_npr_node, /* CMPL_PLOGI */
2472 lpfc_cmpl_prli_npr_node, /* CMPL_PRLI */
dea31012005-04-17 16:05:31 -05002473 lpfc_cmpl_logo_npr_node, /* CMPL_LOGO */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002474 lpfc_cmpl_adisc_npr_node, /* CMPL_ADISC */
dea31012005-04-17 16:05:31 -05002475 lpfc_cmpl_reglogin_npr_node, /* CMPL_REG_LOGIN */
2476 lpfc_device_rm_npr_node, /* DEVICE_RM */
2477 lpfc_device_recov_npr_node, /* DEVICE_RECOVERY */
2478};
2479
2480int
James Smart2e0fef82007-06-17 19:56:36 -05002481lpfc_disc_state_machine(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2482 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05002483{
2484 uint32_t cur_state, rc;
James Smart2e0fef82007-06-17 19:56:36 -05002485 uint32_t(*func) (struct lpfc_vport *, struct lpfc_nodelist *, void *,
dea31012005-04-17 16:05:31 -05002486 uint32_t);
James Smarte47c9092008-02-08 18:49:26 -05002487 uint32_t got_ndlp = 0;
dea31012005-04-17 16:05:31 -05002488
James Smarte47c9092008-02-08 18:49:26 -05002489 if (lpfc_nlp_get(ndlp))
2490 got_ndlp = 1;
2491
dea31012005-04-17 16:05:31 -05002492 cur_state = ndlp->nlp_state;
2493
2494 /* DSM in event <evt> on NPort <nlp_DID> in state <cur_state> */
James Smarte8b62012007-08-02 11:10:09 -04002495 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2496 "0211 DSM in event x%x on NPort x%x in "
2497 "state %d Data: x%x\n",
2498 evt, ndlp->nlp_DID, cur_state, ndlp->nlp_flag);
dea31012005-04-17 16:05:31 -05002499
James Smart858c9f62007-06-17 19:56:39 -05002500 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_DSM,
2501 "DSM in: evt:%d ste:%d did:x%x",
2502 evt, cur_state, ndlp->nlp_DID);
2503
dea31012005-04-17 16:05:31 -05002504 func = lpfc_disc_action[(cur_state * NLP_EVT_MAX_EVENT) + evt];
James Smart2e0fef82007-06-17 19:56:36 -05002505 rc = (func) (vport, ndlp, arg, evt);
dea31012005-04-17 16:05:31 -05002506
2507 /* DSM out state <rc> on NPort <nlp_DID> */
James Smarte47c9092008-02-08 18:49:26 -05002508 if (got_ndlp) {
2509 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
James Smarte8b62012007-08-02 11:10:09 -04002510 "0212 DSM out state %d on NPort x%x Data: x%x\n",
2511 rc, ndlp->nlp_DID, ndlp->nlp_flag);
dea31012005-04-17 16:05:31 -05002512
James Smarte47c9092008-02-08 18:49:26 -05002513 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_DSM,
2514 "DSM out: ste:%d did:x%x flg:x%x",
2515 rc, ndlp->nlp_DID, ndlp->nlp_flag);
2516 /* Decrement the ndlp reference count held for this function */
2517 lpfc_nlp_put(ndlp);
2518 } else {
2519 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
James Smartd7c255b2008-08-24 21:50:00 -04002520 "0213 DSM out state %d on NPort free\n", rc);
James Smart858c9f62007-06-17 19:56:39 -05002521
James Smarte47c9092008-02-08 18:49:26 -05002522 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_DSM,
2523 "DSM out: ste:%d did:x%x flg:x%x",
2524 rc, 0, 0);
2525 }
dea31012005-04-17 16:05:31 -05002526
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002527 return rc;
dea31012005-04-17 16:05:31 -05002528}