blob: 6ba5a72f60497ebf51ff39706a48210b4a4e7878 [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 Smarte47c9092008-02-08 18:49:26 -05004 * Copyright (C) 2004-2008 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>
24#include <linux/interrupt.h>
25
James.Smart@Emulex.Com91886522005-08-10 15:03:09 -040026#include <scsi/scsi.h>
dea31012005-04-17 16:05:31 -050027#include <scsi/scsi_device.h>
28#include <scsi/scsi_host.h>
29#include <scsi/scsi_transport_fc.h>
30
James Smartda0436e2009-05-22 14:51:39 -040031#include "lpfc_hw4.h"
dea31012005-04-17 16:05:31 -050032#include "lpfc_hw.h"
33#include "lpfc_sli.h"
James Smartda0436e2009-05-22 14:51:39 -040034#include "lpfc_sli4.h"
James Smartea2151b2008-09-07 11:52:10 -040035#include "lpfc_nl.h"
dea31012005-04-17 16:05:31 -050036#include "lpfc_disc.h"
37#include "lpfc_scsi.h"
38#include "lpfc.h"
39#include "lpfc_logmsg.h"
40#include "lpfc_crtn.h"
James Smart92d7f7b2007-06-17 19:56:38 -050041#include "lpfc_vport.h"
James Smart858c9f62007-06-17 19:56:39 -050042#include "lpfc_debugfs.h"
dea31012005-04-17 16:05:31 -050043
44
45/* Called to verify a rcv'ed ADISC was intended for us. */
46static int
James Smart2e0fef82007-06-17 19:56:36 -050047lpfc_check_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
48 struct lpfc_name *nn, struct lpfc_name *pn)
dea31012005-04-17 16:05:31 -050049{
50 /* Compare the ADISC rsp WWNN / WWPN matches our internal node
51 * table entry for that node.
52 */
James Smart2e0fef82007-06-17 19:56:36 -050053 if (memcmp(nn, &ndlp->nlp_nodename, sizeof (struct lpfc_name)))
Jamie Wellnitzc9f87352006-02-28 19:25:23 -050054 return 0;
dea31012005-04-17 16:05:31 -050055
James Smart2e0fef82007-06-17 19:56:36 -050056 if (memcmp(pn, &ndlp->nlp_portname, sizeof (struct lpfc_name)))
Jamie Wellnitzc9f87352006-02-28 19:25:23 -050057 return 0;
dea31012005-04-17 16:05:31 -050058
59 /* we match, return success */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -050060 return 1;
dea31012005-04-17 16:05:31 -050061}
62
dea31012005-04-17 16:05:31 -050063int
James Smart2e0fef82007-06-17 19:56:36 -050064lpfc_check_sparm(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
65 struct serv_parm * sp, uint32_t class)
dea31012005-04-17 16:05:31 -050066{
James Smart2e0fef82007-06-17 19:56:36 -050067 volatile struct serv_parm *hsp = &vport->fc_sparam;
James.Smart@Emulex.Com2fb70f72005-11-28 11:41:24 -050068 uint16_t hsp_value, ssp_value = 0;
dea31012005-04-17 16:05:31 -050069
James.Smart@Emulex.Com2fb70f72005-11-28 11:41:24 -050070 /*
71 * The receive data field size and buffer-to-buffer receive data field
72 * size entries are 16 bits but are represented as two 8-bit fields in
73 * the driver data structure to account for rsvd bits and other control
74 * bits. Reconstruct and compare the fields as a 16-bit values before
75 * correcting the byte values.
76 */
dea31012005-04-17 16:05:31 -050077 if (sp->cls1.classValid) {
James.Smart@Emulex.Com2fb70f72005-11-28 11:41:24 -050078 hsp_value = (hsp->cls1.rcvDataSizeMsb << 8) |
79 hsp->cls1.rcvDataSizeLsb;
80 ssp_value = (sp->cls1.rcvDataSizeMsb << 8) |
81 sp->cls1.rcvDataSizeLsb;
James Smart92d7f7b2007-06-17 19:56:38 -050082 if (!ssp_value)
83 goto bad_service_param;
James.Smart@Emulex.Com2fb70f72005-11-28 11:41:24 -050084 if (ssp_value > hsp_value) {
dea31012005-04-17 16:05:31 -050085 sp->cls1.rcvDataSizeLsb = hsp->cls1.rcvDataSizeLsb;
James.Smart@Emulex.Com2fb70f72005-11-28 11:41:24 -050086 sp->cls1.rcvDataSizeMsb = hsp->cls1.rcvDataSizeMsb;
87 }
dea31012005-04-17 16:05:31 -050088 } else if (class == CLASS1) {
James Smart92d7f7b2007-06-17 19:56:38 -050089 goto bad_service_param;
dea31012005-04-17 16:05:31 -050090 }
91
92 if (sp->cls2.classValid) {
James.Smart@Emulex.Com2fb70f72005-11-28 11:41:24 -050093 hsp_value = (hsp->cls2.rcvDataSizeMsb << 8) |
94 hsp->cls2.rcvDataSizeLsb;
95 ssp_value = (sp->cls2.rcvDataSizeMsb << 8) |
96 sp->cls2.rcvDataSizeLsb;
James Smart92d7f7b2007-06-17 19:56:38 -050097 if (!ssp_value)
98 goto bad_service_param;
James.Smart@Emulex.Com2fb70f72005-11-28 11:41:24 -050099 if (ssp_value > hsp_value) {
dea31012005-04-17 16:05:31 -0500100 sp->cls2.rcvDataSizeLsb = hsp->cls2.rcvDataSizeLsb;
James.Smart@Emulex.Com2fb70f72005-11-28 11:41:24 -0500101 sp->cls2.rcvDataSizeMsb = hsp->cls2.rcvDataSizeMsb;
102 }
dea31012005-04-17 16:05:31 -0500103 } else if (class == CLASS2) {
James Smart92d7f7b2007-06-17 19:56:38 -0500104 goto bad_service_param;
dea31012005-04-17 16:05:31 -0500105 }
106
107 if (sp->cls3.classValid) {
James.Smart@Emulex.Com2fb70f72005-11-28 11:41:24 -0500108 hsp_value = (hsp->cls3.rcvDataSizeMsb << 8) |
109 hsp->cls3.rcvDataSizeLsb;
110 ssp_value = (sp->cls3.rcvDataSizeMsb << 8) |
111 sp->cls3.rcvDataSizeLsb;
James Smart92d7f7b2007-06-17 19:56:38 -0500112 if (!ssp_value)
113 goto bad_service_param;
James.Smart@Emulex.Com2fb70f72005-11-28 11:41:24 -0500114 if (ssp_value > hsp_value) {
dea31012005-04-17 16:05:31 -0500115 sp->cls3.rcvDataSizeLsb = hsp->cls3.rcvDataSizeLsb;
James.Smart@Emulex.Com2fb70f72005-11-28 11:41:24 -0500116 sp->cls3.rcvDataSizeMsb = hsp->cls3.rcvDataSizeMsb;
117 }
dea31012005-04-17 16:05:31 -0500118 } else if (class == CLASS3) {
James Smart92d7f7b2007-06-17 19:56:38 -0500119 goto bad_service_param;
dea31012005-04-17 16:05:31 -0500120 }
121
James.Smart@Emulex.Com2fb70f72005-11-28 11:41:24 -0500122 /*
123 * Preserve the upper four bits of the MSB from the PLOGI response.
124 * These bits contain the Buffer-to-Buffer State Change Number
125 * from the target and need to be passed to the FW.
126 */
127 hsp_value = (hsp->cmn.bbRcvSizeMsb << 8) | hsp->cmn.bbRcvSizeLsb;
128 ssp_value = (sp->cmn.bbRcvSizeMsb << 8) | sp->cmn.bbRcvSizeLsb;
129 if (ssp_value > hsp_value) {
dea31012005-04-17 16:05:31 -0500130 sp->cmn.bbRcvSizeLsb = hsp->cmn.bbRcvSizeLsb;
James.Smart@Emulex.Com2fb70f72005-11-28 11:41:24 -0500131 sp->cmn.bbRcvSizeMsb = (sp->cmn.bbRcvSizeMsb & 0xF0) |
132 (hsp->cmn.bbRcvSizeMsb & 0x0F);
133 }
dea31012005-04-17 16:05:31 -0500134
dea31012005-04-17 16:05:31 -0500135 memcpy(&ndlp->nlp_nodename, &sp->nodeName, sizeof (struct lpfc_name));
136 memcpy(&ndlp->nlp_portname, &sp->portName, sizeof (struct lpfc_name));
James.Smart@Emulex.Com2fb70f72005-11-28 11:41:24 -0500137 return 1;
James Smart92d7f7b2007-06-17 19:56:38 -0500138bad_service_param:
James Smarte8b62012007-08-02 11:10:09 -0400139 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
140 "0207 Device %x "
141 "(%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x) sent "
142 "invalid service parameters. Ignoring device.\n",
143 ndlp->nlp_DID,
144 sp->nodeName.u.wwn[0], sp->nodeName.u.wwn[1],
145 sp->nodeName.u.wwn[2], sp->nodeName.u.wwn[3],
146 sp->nodeName.u.wwn[4], sp->nodeName.u.wwn[5],
147 sp->nodeName.u.wwn[6], sp->nodeName.u.wwn[7]);
James Smart92d7f7b2007-06-17 19:56:38 -0500148 return 0;
dea31012005-04-17 16:05:31 -0500149}
150
151static void *
James Smart2e0fef82007-06-17 19:56:36 -0500152lpfc_check_elscmpl_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -0500153 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -0500154{
155 struct lpfc_dmabuf *pcmd, *prsp;
156 uint32_t *lp;
157 void *ptr = NULL;
158 IOCB_t *irsp;
159
160 irsp = &rspiocb->iocb;
161 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
162
163 /* For lpfc_els_abort, context2 could be zero'ed to delay
164 * freeing associated memory till after ABTS completes.
165 */
166 if (pcmd) {
167 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf,
168 list);
169 if (prsp) {
170 lp = (uint32_t *) prsp->virt;
171 ptr = (void *)((uint8_t *)lp + sizeof(uint32_t));
172 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500173 } else {
dea31012005-04-17 16:05:31 -0500174 /* Force ulpStatus error since we are returning NULL ptr */
175 if (!(irsp->ulpStatus)) {
176 irsp->ulpStatus = IOSTAT_LOCAL_REJECT;
177 irsp->un.ulpWord[4] = IOERR_SLI_ABORTED;
178 }
179 ptr = NULL;
180 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500181 return ptr;
dea31012005-04-17 16:05:31 -0500182}
183
184
185/*
186 * Free resources / clean up outstanding I/Os
187 * associated with a LPFC_NODELIST entry. This
188 * routine effectively results in a "software abort".
189 */
190int
James Smart2e0fef82007-06-17 19:56:36 -0500191lpfc_els_abort(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -0500192{
James Smart2534ba72007-04-25 09:52:20 -0400193 LIST_HEAD(completions);
James Smart2e0fef82007-06-17 19:56:36 -0500194 struct lpfc_sli *psli = &phba->sli;
195 struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING];
dea31012005-04-17 16:05:31 -0500196 struct lpfc_iocbq *iocb, *next_iocb;
dea31012005-04-17 16:05:31 -0500197
198 /* Abort outstanding I/O on NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -0400199 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_DISCOVERY,
200 "0205 Abort outstanding I/O on NPort x%x "
201 "Data: x%x x%x x%x\n",
202 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
203 ndlp->nlp_rpi);
James Smart92d7f7b2007-06-17 19:56:38 -0500204
205 lpfc_fabric_abort_nport(ndlp);
dea31012005-04-17 16:05:31 -0500206
dea31012005-04-17 16:05:31 -0500207 /* First check the txq */
James Smart2e0fef82007-06-17 19:56:36 -0500208 spin_lock_irq(&phba->hbalock);
James Smart2534ba72007-04-25 09:52:20 -0400209 list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
James Smart858c9f62007-06-17 19:56:39 -0500210 /* Check to see if iocb matches the nport we are looking for */
James Smart2534ba72007-04-25 09:52:20 -0400211 if (lpfc_check_sli_ndlp(phba, pring, iocb, ndlp)) {
James Smart858c9f62007-06-17 19:56:39 -0500212 /* It matches, so deque and call compl with anp error */
James Smart2534ba72007-04-25 09:52:20 -0400213 list_move_tail(&iocb->list, &completions);
214 pring->txq_cnt--;
dea31012005-04-17 16:05:31 -0500215 }
James Smart2534ba72007-04-25 09:52:20 -0400216 }
dea31012005-04-17 16:05:31 -0500217
dea31012005-04-17 16:05:31 -0500218 /* Next check the txcmplq */
James Smart07951072007-04-25 09:51:38 -0400219 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
James Smart858c9f62007-06-17 19:56:39 -0500220 /* Check to see if iocb matches the nport we are looking for */
James Smart92d7f7b2007-06-17 19:56:38 -0500221 if (lpfc_check_sli_ndlp(phba, pring, iocb, ndlp)) {
James Smart07951072007-04-25 09:51:38 -0400222 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
James Smart92d7f7b2007-06-17 19:56:38 -0500223 }
James Smart07951072007-04-25 09:51:38 -0400224 }
James Smart2e0fef82007-06-17 19:56:36 -0500225 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500226
James Smarta257bf92009-04-06 18:48:10 -0400227 /* Cancel all the IOCBs from the completions list */
228 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
229 IOERR_SLI_ABORTED);
James Smart2534ba72007-04-25 09:52:20 -0400230
James Smart0d2b6b82008-06-14 22:52:47 -0400231 lpfc_cancel_retry_delay_tmo(phba->pport, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500232 return 0;
dea31012005-04-17 16:05:31 -0500233}
234
235static int
James Smart2e0fef82007-06-17 19:56:36 -0500236lpfc_rcv_plogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
James Smart92d7f7b2007-06-17 19:56:38 -0500237 struct lpfc_iocbq *cmdiocb)
dea31012005-04-17 16:05:31 -0500238{
James Smart2e0fef82007-06-17 19:56:36 -0500239 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
240 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500241 struct lpfc_dmabuf *pcmd;
242 uint32_t *lp;
243 IOCB_t *icmd;
244 struct serv_parm *sp;
245 LPFC_MBOXQ_t *mbox;
246 struct ls_rjt stat;
247 int rc;
248
249 memset(&stat, 0, sizeof (struct ls_rjt));
James Smart2e0fef82007-06-17 19:56:36 -0500250 if (vport->port_state <= LPFC_FLOGI) {
dea31012005-04-17 16:05:31 -0500251 /* Before responding to PLOGI, check for pt2pt mode.
252 * If we are pt2pt, with an outstanding FLOGI, abort
253 * the FLOGI and resend it first.
254 */
James Smart2e0fef82007-06-17 19:56:36 -0500255 if (vport->fc_flag & FC_PT2PT) {
James Smart92d7f7b2007-06-17 19:56:38 -0500256 lpfc_els_abort_flogi(phba);
James Smart2e0fef82007-06-17 19:56:36 -0500257 if (!(vport->fc_flag & FC_PT2PT_PLOGI)) {
dea31012005-04-17 16:05:31 -0500258 /* If the other side is supposed to initiate
259 * the PLOGI anyway, just ACC it now and
260 * move on with discovery.
261 */
262 phba->fc_edtov = FF_DEF_EDTOV;
263 phba->fc_ratov = FF_DEF_RATOV;
264 /* Start discovery - this should just do
265 CLEAR_LA */
James Smart2e0fef82007-06-17 19:56:36 -0500266 lpfc_disc_start(vport);
James Smarted957682007-06-17 19:56:37 -0500267 } else
James Smart2e0fef82007-06-17 19:56:36 -0500268 lpfc_initial_flogi(vport);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500269 } else {
dea31012005-04-17 16:05:31 -0500270 stat.un.b.lsRjtRsnCode = LSRJT_LOGICAL_BSY;
271 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
James Smart2e0fef82007-06-17 19:56:36 -0500272 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb,
James Smart858c9f62007-06-17 19:56:39 -0500273 ndlp, NULL);
dea31012005-04-17 16:05:31 -0500274 return 0;
275 }
276 }
277 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
278 lp = (uint32_t *) pcmd->virt;
279 sp = (struct serv_parm *) ((uint8_t *) lp + sizeof (uint32_t));
James Smarta8adb832007-10-27 13:37:53 -0400280 if (wwn_to_u64(sp->portName.u.wwn) == 0) {
281 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
282 "0140 PLOGI Reject: invalid nname\n");
283 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
284 stat.un.b.lsRjtRsnCodeExp = LSEXP_INVALID_PNAME;
285 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
286 NULL);
287 return 0;
288 }
289 if (wwn_to_u64(sp->nodeName.u.wwn) == 0) {
290 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
291 "0141 PLOGI Reject: invalid pname\n");
292 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
293 stat.un.b.lsRjtRsnCodeExp = LSEXP_INVALID_NNAME;
294 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
295 NULL);
296 return 0;
297 }
James Smart2e0fef82007-06-17 19:56:36 -0500298 if ((lpfc_check_sparm(vport, ndlp, sp, CLASS3) == 0)) {
dea31012005-04-17 16:05:31 -0500299 /* Reject this request because invalid parameters */
300 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
301 stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
James Smart858c9f62007-06-17 19:56:39 -0500302 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
303 NULL);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500304 return 0;
dea31012005-04-17 16:05:31 -0500305 }
306 icmd = &cmdiocb->iocb;
307
308 /* PLOGI chkparm OK */
James Smarte8b62012007-08-02 11:10:09 -0400309 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
310 "0114 PLOGI chkparm OK Data: x%x x%x x%x x%x\n",
311 ndlp->nlp_DID, ndlp->nlp_state, ndlp->nlp_flag,
312 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -0500313
James Smart3de2a652007-08-02 11:09:59 -0400314 if (vport->cfg_fcp_class == 2 && sp->cls2.classValid)
dea31012005-04-17 16:05:31 -0500315 ndlp->nlp_fcp_info |= CLASS2;
James Smarted957682007-06-17 19:56:37 -0500316 else
dea31012005-04-17 16:05:31 -0500317 ndlp->nlp_fcp_info |= CLASS3;
James Smart2e0fef82007-06-17 19:56:36 -0500318
dea31012005-04-17 16:05:31 -0500319 ndlp->nlp_class_sup = 0;
320 if (sp->cls1.classValid)
321 ndlp->nlp_class_sup |= FC_COS_CLASS1;
322 if (sp->cls2.classValid)
323 ndlp->nlp_class_sup |= FC_COS_CLASS2;
324 if (sp->cls3.classValid)
325 ndlp->nlp_class_sup |= FC_COS_CLASS3;
326 if (sp->cls4.classValid)
327 ndlp->nlp_class_sup |= FC_COS_CLASS4;
328 ndlp->nlp_maxframe =
329 ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) | sp->cmn.bbRcvSizeLsb;
330
331 /* no need to reg_login if we are already in one of these states */
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500332 switch (ndlp->nlp_state) {
dea31012005-04-17 16:05:31 -0500333 case NLP_STE_NPR_NODE:
334 if (!(ndlp->nlp_flag & NLP_NPR_ADISC))
335 break;
336 case NLP_STE_REG_LOGIN_ISSUE:
337 case NLP_STE_PRLI_ISSUE:
338 case NLP_STE_UNMAPPED_NODE:
339 case NLP_STE_MAPPED_NODE:
James Smart51ef4c22007-08-02 11:10:31 -0400340 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp, NULL);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500341 return 1;
dea31012005-04-17 16:05:31 -0500342 }
343
James Smart92d7f7b2007-06-17 19:56:38 -0500344 if ((vport->fc_flag & FC_PT2PT) &&
345 !(vport->fc_flag & FC_PT2PT_PLOGI)) {
dea31012005-04-17 16:05:31 -0500346 /* rcv'ed PLOGI decides what our NPortId will be */
James Smart2e0fef82007-06-17 19:56:36 -0500347 vport->fc_myDID = icmd->un.rcvels.parmRo;
dea31012005-04-17 16:05:31 -0500348 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
349 if (mbox == NULL)
350 goto out;
351 lpfc_config_link(phba, mbox);
352 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smarted957682007-06-17 19:56:37 -0500353 mbox->vport = vport;
James Smart0b727fe2007-10-27 13:37:25 -0400354 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
dea31012005-04-17 16:05:31 -0500355 if (rc == MBX_NOT_FINISHED) {
James Smart92d7f7b2007-06-17 19:56:38 -0500356 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -0500357 goto out;
358 }
359
James Smart2e0fef82007-06-17 19:56:36 -0500360 lpfc_can_disctmo(vport);
dea31012005-04-17 16:05:31 -0500361 }
362 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
James Smart2e0fef82007-06-17 19:56:36 -0500363 if (!mbox)
dea31012005-04-17 16:05:31 -0500364 goto out;
365
James Smart92d7f7b2007-06-17 19:56:38 -0500366 rc = lpfc_reg_login(phba, vport->vpi, icmd->un.rcvels.remoteID,
367 (uint8_t *) sp, mbox, 0);
James Smart2e0fef82007-06-17 19:56:36 -0500368 if (rc) {
369 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -0500370 goto out;
371 }
372
373 /* ACC PLOGI rsp command needs to execute first,
374 * queue this mbox command to be processed later.
375 */
376 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
James Smart329f9bc2007-04-25 09:53:01 -0400377 /*
378 * mbox->context2 = lpfc_nlp_get(ndlp) deferred until mailbox
379 * command issued in lpfc_cmpl_els_acc().
380 */
James Smart2e0fef82007-06-17 19:56:36 -0500381 mbox->vport = vport;
382 spin_lock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -0500383 ndlp->nlp_flag |= (NLP_ACC_REGLOGIN | NLP_RCV_PLOGI);
James Smart2e0fef82007-06-17 19:56:36 -0500384 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500385
James Smart33ccf8d2006-08-17 11:57:58 -0400386 /*
387 * If there is an outstanding PLOGI issued, abort it before
388 * sending ACC rsp for received PLOGI. If pending plogi
389 * is not canceled here, the plogi will be rejected by
390 * remote port and will be retried. On a configuration with
391 * single discovery thread, this will cause a huge delay in
392 * discovery. Also this will cause multiple state machines
393 * running in parallel for this node.
394 */
395 if (ndlp->nlp_state == NLP_STE_PLOGI_ISSUE) {
396 /* software abort outstanding PLOGI */
James Smart07951072007-04-25 09:51:38 -0400397 lpfc_els_abort(phba, ndlp);
James Smart33ccf8d2006-08-17 11:57:58 -0400398 }
399
James Smart858c9f62007-06-17 19:56:39 -0500400 if ((vport->port_type == LPFC_NPIV_PORT &&
James Smart3de2a652007-08-02 11:09:59 -0400401 vport->cfg_restrict_login)) {
James Smart858c9f62007-06-17 19:56:39 -0500402
403 /* In order to preserve RPIs, we want to cleanup
404 * the default RPI the firmware created to rcv
405 * this ELS request. The only way to do this is
406 * to register, then unregister the RPI.
407 */
408 spin_lock_irq(shost->host_lock);
409 ndlp->nlp_flag |= NLP_RM_DFLT_RPI;
410 spin_unlock_irq(shost->host_lock);
411 stat.un.b.lsRjtRsnCode = LSRJT_INVALID_CMD;
412 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
413 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb,
414 ndlp, mbox);
415 return 1;
416 }
James Smart51ef4c22007-08-02 11:10:31 -0400417 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp, mbox);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500418 return 1;
dea31012005-04-17 16:05:31 -0500419out:
420 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
421 stat.un.b.lsRjtRsnCodeExp = LSEXP_OUT_OF_RESOURCE;
James Smart858c9f62007-06-17 19:56:39 -0500422 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500423 return 0;
dea31012005-04-17 16:05:31 -0500424}
425
426static int
James Smart2e0fef82007-06-17 19:56:36 -0500427lpfc_rcv_padisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -0500428 struct lpfc_iocbq *cmdiocb)
429{
James Smart2e0fef82007-06-17 19:56:36 -0500430 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -0500431 struct lpfc_dmabuf *pcmd;
James Smart2e0fef82007-06-17 19:56:36 -0500432 struct serv_parm *sp;
433 struct lpfc_name *pnn, *ppn;
dea31012005-04-17 16:05:31 -0500434 struct ls_rjt stat;
435 ADISC *ap;
436 IOCB_t *icmd;
437 uint32_t *lp;
438 uint32_t cmd;
439
440 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
441 lp = (uint32_t *) pcmd->virt;
442
443 cmd = *lp++;
444 if (cmd == ELS_CMD_ADISC) {
445 ap = (ADISC *) lp;
446 pnn = (struct lpfc_name *) & ap->nodeName;
447 ppn = (struct lpfc_name *) & ap->portName;
448 } else {
449 sp = (struct serv_parm *) lp;
450 pnn = (struct lpfc_name *) & sp->nodeName;
451 ppn = (struct lpfc_name *) & sp->portName;
452 }
453
454 icmd = &cmdiocb->iocb;
James Smart2e0fef82007-06-17 19:56:36 -0500455 if (icmd->ulpStatus == 0 && lpfc_check_adisc(vport, ndlp, pnn, ppn)) {
dea31012005-04-17 16:05:31 -0500456 if (cmd == ELS_CMD_ADISC) {
James Smart2e0fef82007-06-17 19:56:36 -0500457 lpfc_els_rsp_adisc_acc(vport, cmdiocb, ndlp);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500458 } else {
James Smart2e0fef82007-06-17 19:56:36 -0500459 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp,
James Smart51ef4c22007-08-02 11:10:31 -0400460 NULL);
dea31012005-04-17 16:05:31 -0500461 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500462 return 1;
dea31012005-04-17 16:05:31 -0500463 }
464 /* Reject this request because invalid parameters */
465 stat.un.b.lsRjtRsvd0 = 0;
466 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
467 stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
468 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -0500469 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -0500470
dea31012005-04-17 16:05:31 -0500471 /* 1 sec timeout */
472 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ);
473
James Smart2e0fef82007-06-17 19:56:36 -0500474 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500475 ndlp->nlp_flag |= NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -0500476 spin_unlock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -0500477 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
478 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -0500479 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500480 return 0;
dea31012005-04-17 16:05:31 -0500481}
482
483static int
James Smart2e0fef82007-06-17 19:56:36 -0500484lpfc_rcv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
485 struct lpfc_iocbq *cmdiocb, uint32_t els_cmd)
dea31012005-04-17 16:05:31 -0500486{
James Smart2e0fef82007-06-17 19:56:36 -0500487 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
488
489 /* Put ndlp in NPR state with 1 sec timeout for plogi, ACC logo */
dea31012005-04-17 16:05:31 -0500490 /* Only call LOGO ACC for first LOGO, this avoids sending unnecessary
491 * PLOGIs during LOGO storms from a device.
492 */
James Smart2e0fef82007-06-17 19:56:36 -0500493 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500494 ndlp->nlp_flag |= NLP_LOGO_ACC;
James Smart2e0fef82007-06-17 19:56:36 -0500495 spin_unlock_irq(shost->host_lock);
James Smart82d9a2a2006-04-15 11:53:05 -0400496 if (els_cmd == ELS_CMD_PRLO)
James Smart51ef4c22007-08-02 11:10:31 -0400497 lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL);
James Smart82d9a2a2006-04-15 11:53:05 -0400498 else
James Smart51ef4c22007-08-02 11:10:31 -0400499 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -0500500
James Smart0d2b6b82008-06-14 22:52:47 -0400501 if ((!(ndlp->nlp_type & NLP_FABRIC) &&
502 ((ndlp->nlp_type & NLP_FCP_TARGET) ||
503 !(ndlp->nlp_type & NLP_FCP_INITIATOR))) ||
James Smart92d7f7b2007-06-17 19:56:38 -0500504 (ndlp->nlp_state == NLP_STE_ADISC_ISSUE)) {
dea31012005-04-17 16:05:31 -0500505 /* Only try to re-login if this is NOT a Fabric Node */
dea31012005-04-17 16:05:31 -0500506 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ * 1);
James Smart2e0fef82007-06-17 19:56:36 -0500507 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500508 ndlp->nlp_flag |= NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -0500509 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500510
Jamie Wellnitz5024ab12006-02-28 19:25:28 -0500511 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
dea31012005-04-17 16:05:31 -0500512 }
James Smart87af33f2007-10-27 13:37:43 -0400513 ndlp->nlp_prev_state = ndlp->nlp_state;
514 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
dea31012005-04-17 16:05:31 -0500515
James Smart2e0fef82007-06-17 19:56:36 -0500516 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500517 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
James Smart2e0fef82007-06-17 19:56:36 -0500518 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500519 /* The driver has to wait until the ACC completes before it continues
520 * processing the LOGO. The action will resume in
521 * lpfc_cmpl_els_logo_acc routine. Since part of processing includes an
522 * unreg_login, the driver waits so the ACC does not get aborted.
523 */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500524 return 0;
dea31012005-04-17 16:05:31 -0500525}
526
527static void
James Smart2e0fef82007-06-17 19:56:36 -0500528lpfc_rcv_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
529 struct lpfc_iocbq *cmdiocb)
dea31012005-04-17 16:05:31 -0500530{
531 struct lpfc_dmabuf *pcmd;
532 uint32_t *lp;
533 PRLI *npr;
534 struct fc_rport *rport = ndlp->rport;
535 u32 roles;
536
537 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
538 lp = (uint32_t *) pcmd->virt;
539 npr = (PRLI *) ((uint8_t *) lp + sizeof (uint32_t));
540
541 ndlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR);
542 ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
James Smart92d7f7b2007-06-17 19:56:38 -0500543 if (npr->prliType == PRLI_FCP_TYPE) {
dea31012005-04-17 16:05:31 -0500544 if (npr->initiatorFunc)
545 ndlp->nlp_type |= NLP_FCP_INITIATOR;
546 if (npr->targetFunc)
547 ndlp->nlp_type |= NLP_FCP_TARGET;
548 if (npr->Retry)
549 ndlp->nlp_fcp_info |= NLP_FCP_2_DEVICE;
550 }
551 if (rport) {
552 /* We need to update the rport role values */
553 roles = FC_RPORT_ROLE_UNKNOWN;
554 if (ndlp->nlp_type & NLP_FCP_INITIATOR)
555 roles |= FC_RPORT_ROLE_FCP_INITIATOR;
556 if (ndlp->nlp_type & NLP_FCP_TARGET)
557 roles |= FC_RPORT_ROLE_FCP_TARGET;
James Smart858c9f62007-06-17 19:56:39 -0500558
559 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
560 "rport rolechg: role:x%x did:x%x flg:x%x",
561 roles, ndlp->nlp_DID, ndlp->nlp_flag);
562
dea31012005-04-17 16:05:31 -0500563 fc_remote_port_rolechg(rport, roles);
564 }
565}
566
567static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -0500568lpfc_disc_set_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -0500569{
James Smart2e0fef82007-06-17 19:56:36 -0500570 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart2e0fef82007-06-17 19:56:36 -0500571
James Smart51ef4c22007-08-02 11:10:31 -0400572 if (!ndlp->nlp_rpi) {
573 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
574 return 0;
575 }
576
James Smart1b32f6a2008-02-08 18:49:39 -0500577 if (!(vport->fc_flag & FC_PT2PT)) {
578 /* Check config parameter use-adisc or FCP-2 */
579 if ((vport->cfg_use_adisc && (vport->fc_flag & FC_RSCN_MODE)) ||
580 ndlp->nlp_fcp_info & NLP_FCP_2_DEVICE) {
581 spin_lock_irq(shost->host_lock);
582 ndlp->nlp_flag |= NLP_NPR_ADISC;
583 spin_unlock_irq(shost->host_lock);
584 return 1;
585 }
James Smart92d7f7b2007-06-17 19:56:38 -0500586 }
587 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
588 lpfc_unreg_rpi(vport, ndlp);
589 return 0;
dea31012005-04-17 16:05:31 -0500590}
591
592static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -0500593lpfc_disc_illegal(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
594 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -0500595{
James Smarte8b62012007-08-02 11:10:09 -0400596 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
James Smarte47c9092008-02-08 18:49:26 -0500597 "0271 Illegal State Transition: node x%x "
James Smarte8b62012007-08-02 11:10:09 -0400598 "event x%x, state x%x Data: x%x x%x\n",
599 ndlp->nlp_DID, evt, ndlp->nlp_state, ndlp->nlp_rpi,
600 ndlp->nlp_flag);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500601 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -0500602}
603
James Smart87af33f2007-10-27 13:37:43 -0400604static uint32_t
605lpfc_cmpl_plogi_illegal(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
606 void *arg, uint32_t evt)
607{
608 /* This transition is only legal if we previously
609 * rcv'ed a PLOGI. Since we don't want 2 discovery threads
610 * working on the same NPortID, do nothing for this thread
611 * to stop it.
612 */
613 if (!(ndlp->nlp_flag & NLP_RCV_PLOGI)) {
614 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
James Smarte47c9092008-02-08 18:49:26 -0500615 "0272 Illegal State Transition: node x%x "
James Smart87af33f2007-10-27 13:37:43 -0400616 "event x%x, state x%x Data: x%x x%x\n",
617 ndlp->nlp_DID, evt, ndlp->nlp_state, ndlp->nlp_rpi,
618 ndlp->nlp_flag);
619 }
620 return ndlp->nlp_state;
621}
622
dea31012005-04-17 16:05:31 -0500623/* Start of Discovery State Machine routines */
624
625static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -0500626lpfc_rcv_plogi_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
627 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -0500628{
629 struct lpfc_iocbq *cmdiocb;
630
631 cmdiocb = (struct lpfc_iocbq *) arg;
632
James Smart2e0fef82007-06-17 19:56:36 -0500633 if (lpfc_rcv_plogi(vport, ndlp, cmdiocb)) {
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500634 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -0500635 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500636 return NLP_STE_FREED_NODE;
dea31012005-04-17 16:05:31 -0500637}
638
639static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -0500640lpfc_rcv_els_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
641 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -0500642{
James Smart2e0fef82007-06-17 19:56:36 -0500643 lpfc_issue_els_logo(vport, ndlp, 0);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500644 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -0500645}
646
647static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -0500648lpfc_rcv_logo_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
649 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -0500650{
James Smart2e0fef82007-06-17 19:56:36 -0500651 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
652 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -0500653
James Smart2e0fef82007-06-17 19:56:36 -0500654 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500655 ndlp->nlp_flag |= NLP_LOGO_ACC;
James Smart2e0fef82007-06-17 19:56:36 -0500656 spin_unlock_irq(shost->host_lock);
James Smart51ef4c22007-08-02 11:10:31 -0400657 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -0500658
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500659 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -0500660}
661
662static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -0500663lpfc_cmpl_logo_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -0500664 void *arg, uint32_t evt)
665{
James Smart2e0fef82007-06-17 19:56:36 -0500666 return NLP_STE_FREED_NODE;
667}
668
669static uint32_t
670lpfc_device_rm_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
671 void *arg, uint32_t evt)
672{
James Smart2e0fef82007-06-17 19:56:36 -0500673 return NLP_STE_FREED_NODE;
674}
675
676static uint32_t
677lpfc_rcv_plogi_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
678 void *arg, uint32_t evt)
679{
James Smart0d2b6b82008-06-14 22:52:47 -0400680 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart2e0fef82007-06-17 19:56:36 -0500681 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500682 struct lpfc_iocbq *cmdiocb = arg;
James Smart2e0fef82007-06-17 19:56:36 -0500683 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
684 uint32_t *lp = (uint32_t *) pcmd->virt;
685 struct serv_parm *sp = (struct serv_parm *) (lp + 1);
dea31012005-04-17 16:05:31 -0500686 struct ls_rjt stat;
687 int port_cmp;
688
dea31012005-04-17 16:05:31 -0500689 memset(&stat, 0, sizeof (struct ls_rjt));
690
691 /* For a PLOGI, we only accept if our portname is less
692 * than the remote portname.
693 */
694 phba->fc_stat.elsLogiCol++;
James Smart2e0fef82007-06-17 19:56:36 -0500695 port_cmp = memcmp(&vport->fc_portname, &sp->portName,
James Smart92d7f7b2007-06-17 19:56:38 -0500696 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -0500697
698 if (port_cmp >= 0) {
699 /* Reject this request because the remote node will accept
700 ours */
701 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
702 stat.un.b.lsRjtRsnCodeExp = LSEXP_CMD_IN_PROGRESS;
James Smart858c9f62007-06-17 19:56:39 -0500703 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
704 NULL);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500705 } else {
James Smart0d2b6b82008-06-14 22:52:47 -0400706 if (lpfc_rcv_plogi(vport, ndlp, cmdiocb) &&
707 (ndlp->nlp_flag & NLP_NPR_2B_DISC) &&
708 (vport->num_disc_nodes)) {
709 spin_lock_irq(shost->host_lock);
710 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
711 spin_unlock_irq(shost->host_lock);
712 /* Check if there are more PLOGIs to be sent */
713 lpfc_more_plogi(vport);
714 if (vport->num_disc_nodes == 0) {
715 spin_lock_irq(shost->host_lock);
716 vport->fc_flag &= ~FC_NDISC_ACTIVE;
717 spin_unlock_irq(shost->host_lock);
718 lpfc_can_disctmo(vport);
719 lpfc_end_rscn(vport);
720 }
721 }
James Smart2e0fef82007-06-17 19:56:36 -0500722 } /* If our portname was less */
dea31012005-04-17 16:05:31 -0500723
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500724 return ndlp->nlp_state;
725}
726
727static uint32_t
James Smart92d7f7b2007-06-17 19:56:38 -0500728lpfc_rcv_prli_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
729 void *arg, uint32_t evt)
730{
731 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
732 struct ls_rjt stat;
733
734 memset(&stat, 0, sizeof (struct ls_rjt));
735 stat.un.b.lsRjtRsnCode = LSRJT_LOGICAL_BSY;
736 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
James Smart858c9f62007-06-17 19:56:39 -0500737 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
James Smart92d7f7b2007-06-17 19:56:38 -0500738 return ndlp->nlp_state;
739}
740
741static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -0500742lpfc_rcv_logo_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
743 void *arg, uint32_t evt)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500744{
James Smart2e0fef82007-06-17 19:56:36 -0500745 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500746
James Smart92d7f7b2007-06-17 19:56:38 -0500747 /* software abort outstanding PLOGI */
James Smart2e0fef82007-06-17 19:56:36 -0500748 lpfc_els_abort(vport->phba, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500749
James Smart2e0fef82007-06-17 19:56:36 -0500750 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500751 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -0500752}
753
754static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -0500755lpfc_rcv_els_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
756 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -0500757{
James Smart2e0fef82007-06-17 19:56:36 -0500758 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
759 struct lpfc_hba *phba = vport->phba;
760 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -0500761
762 /* software abort outstanding PLOGI */
James Smart07951072007-04-25 09:51:38 -0400763 lpfc_els_abort(phba, ndlp);
dea31012005-04-17 16:05:31 -0500764
765 if (evt == NLP_EVT_RCV_LOGO) {
James Smart51ef4c22007-08-02 11:10:31 -0400766 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500767 } else {
James Smart2e0fef82007-06-17 19:56:36 -0500768 lpfc_issue_els_logo(vport, ndlp, 0);
dea31012005-04-17 16:05:31 -0500769 }
770
James Smart2e0fef82007-06-17 19:56:36 -0500771 /* Put ndlp in npr state set plogi timer for 1 sec */
Jamie Wellnitz5024ab12006-02-28 19:25:28 -0500772 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ * 1);
James Smart2e0fef82007-06-17 19:56:36 -0500773 spin_lock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -0500774 ndlp->nlp_flag |= NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -0500775 spin_unlock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -0500776 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
777 ndlp->nlp_prev_state = NLP_STE_PLOGI_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -0500778 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
dea31012005-04-17 16:05:31 -0500779
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500780 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -0500781}
782
783static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -0500784lpfc_cmpl_plogi_plogi_issue(struct lpfc_vport *vport,
785 struct lpfc_nodelist *ndlp,
786 void *arg,
dea31012005-04-17 16:05:31 -0500787 uint32_t evt)
788{
James Smart2e0fef82007-06-17 19:56:36 -0500789 struct lpfc_hba *phba = vport->phba;
James Smart0ff10d42008-01-11 01:52:36 -0500790 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart2e0fef82007-06-17 19:56:36 -0500791 struct lpfc_iocbq *cmdiocb, *rspiocb;
James Smart14691152006-12-02 13:34:28 -0500792 struct lpfc_dmabuf *pcmd, *prsp, *mp;
dea31012005-04-17 16:05:31 -0500793 uint32_t *lp;
794 IOCB_t *irsp;
795 struct serv_parm *sp;
796 LPFC_MBOXQ_t *mbox;
797
798 cmdiocb = (struct lpfc_iocbq *) arg;
799 rspiocb = cmdiocb->context_un.rsp_iocb;
800
801 if (ndlp->nlp_flag & NLP_ACC_REGLOGIN) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -0500802 /* Recovery from PLOGI collision logic */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500803 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -0500804 }
805
806 irsp = &rspiocb->iocb;
807
808 if (irsp->ulpStatus)
809 goto out;
810
811 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
812
James Smart2e0fef82007-06-17 19:56:36 -0500813 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
dea31012005-04-17 16:05:31 -0500814
James Smart2e0fef82007-06-17 19:56:36 -0500815 lp = (uint32_t *) prsp->virt;
dea31012005-04-17 16:05:31 -0500816 sp = (struct serv_parm *) ((uint8_t *) lp + sizeof (uint32_t));
James Smart58da1ff2008-04-07 10:15:56 -0400817
818 /* Some switches have FDMI servers returning 0 for WWN */
819 if ((ndlp->nlp_DID != FDMI_DID) &&
820 (wwn_to_u64(sp->portName.u.wwn) == 0 ||
821 wwn_to_u64(sp->nodeName.u.wwn) == 0)) {
James Smarta8adb832007-10-27 13:37:53 -0400822 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
823 "0142 PLOGI RSP: Invalid WWN.\n");
824 goto out;
825 }
James Smart2e0fef82007-06-17 19:56:36 -0500826 if (!lpfc_check_sparm(vport, ndlp, sp, CLASS3))
dea31012005-04-17 16:05:31 -0500827 goto out;
dea31012005-04-17 16:05:31 -0500828 /* PLOGI chkparm OK */
James Smarte8b62012007-08-02 11:10:09 -0400829 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
830 "0121 PLOGI chkparm OK Data: x%x x%x x%x x%x\n",
831 ndlp->nlp_DID, ndlp->nlp_state,
832 ndlp->nlp_flag, ndlp->nlp_rpi);
James Smart3de2a652007-08-02 11:09:59 -0400833 if (vport->cfg_fcp_class == 2 && (sp->cls2.classValid))
dea31012005-04-17 16:05:31 -0500834 ndlp->nlp_fcp_info |= CLASS2;
James Smart2e0fef82007-06-17 19:56:36 -0500835 else
dea31012005-04-17 16:05:31 -0500836 ndlp->nlp_fcp_info |= CLASS3;
James Smart2e0fef82007-06-17 19:56:36 -0500837
dea31012005-04-17 16:05:31 -0500838 ndlp->nlp_class_sup = 0;
839 if (sp->cls1.classValid)
840 ndlp->nlp_class_sup |= FC_COS_CLASS1;
841 if (sp->cls2.classValid)
842 ndlp->nlp_class_sup |= FC_COS_CLASS2;
843 if (sp->cls3.classValid)
844 ndlp->nlp_class_sup |= FC_COS_CLASS3;
845 if (sp->cls4.classValid)
846 ndlp->nlp_class_sup |= FC_COS_CLASS4;
847 ndlp->nlp_maxframe =
James Smart2e0fef82007-06-17 19:56:36 -0500848 ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) | sp->cmn.bbRcvSizeLsb;
dea31012005-04-17 16:05:31 -0500849
James Smart2e0fef82007-06-17 19:56:36 -0500850 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
James Smart92d7f7b2007-06-17 19:56:38 -0500851 if (!mbox) {
James Smarte8b62012007-08-02 11:10:09 -0400852 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
853 "0133 PLOGI: no memory for reg_login "
James Smart92d7f7b2007-06-17 19:56:38 -0500854 "Data: x%x x%x x%x x%x\n",
James Smart92d7f7b2007-06-17 19:56:38 -0500855 ndlp->nlp_DID, ndlp->nlp_state,
856 ndlp->nlp_flag, ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -0500857 goto out;
James Smart92d7f7b2007-06-17 19:56:38 -0500858 }
dea31012005-04-17 16:05:31 -0500859
James Smart2e0fef82007-06-17 19:56:36 -0500860 lpfc_unreg_rpi(vport, ndlp);
861
James Smart92d7f7b2007-06-17 19:56:38 -0500862 if (lpfc_reg_login(phba, vport->vpi, irsp->un.elsreq64.remoteID,
863 (uint8_t *) sp, mbox, 0) == 0) {
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500864 switch (ndlp->nlp_DID) {
dea31012005-04-17 16:05:31 -0500865 case NameServer_DID:
James Smartde0c5b32007-04-25 09:52:27 -0400866 mbox->mbox_cmpl = lpfc_mbx_cmpl_ns_reg_login;
dea31012005-04-17 16:05:31 -0500867 break;
868 case FDMI_DID:
James Smartde0c5b32007-04-25 09:52:27 -0400869 mbox->mbox_cmpl = lpfc_mbx_cmpl_fdmi_reg_login;
dea31012005-04-17 16:05:31 -0500870 break;
871 default:
James Smartde0c5b32007-04-25 09:52:27 -0400872 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
dea31012005-04-17 16:05:31 -0500873 }
James Smart329f9bc2007-04-25 09:53:01 -0400874 mbox->context2 = lpfc_nlp_get(ndlp);
James Smart2e0fef82007-06-17 19:56:36 -0500875 mbox->vport = vport;
James Smart0b727fe2007-10-27 13:37:25 -0400876 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
dea31012005-04-17 16:05:31 -0500877 != MBX_NOT_FINISHED) {
James Smart2e0fef82007-06-17 19:56:36 -0500878 lpfc_nlp_set_state(vport, ndlp,
879 NLP_STE_REG_LOGIN_ISSUE);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500880 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -0500881 }
James Smartfa4066b2008-01-11 01:53:27 -0500882 /* decrement node reference count to the failed mbox
883 * command
884 */
James Smart329f9bc2007-04-25 09:53:01 -0400885 lpfc_nlp_put(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -0500886 mp = (struct lpfc_dmabuf *) mbox->context1;
James Smart14691152006-12-02 13:34:28 -0500887 lpfc_mbuf_free(phba, mp->virt, mp->phys);
888 kfree(mp);
dea31012005-04-17 16:05:31 -0500889 mempool_free(mbox, phba->mbox_mem_pool);
James Smart92d7f7b2007-06-17 19:56:38 -0500890
James Smarte8b62012007-08-02 11:10:09 -0400891 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
892 "0134 PLOGI: cannot issue reg_login "
893 "Data: x%x x%x x%x x%x\n",
894 ndlp->nlp_DID, ndlp->nlp_state,
895 ndlp->nlp_flag, ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -0500896 } else {
897 mempool_free(mbox, phba->mbox_mem_pool);
James Smart92d7f7b2007-06-17 19:56:38 -0500898
James Smarte8b62012007-08-02 11:10:09 -0400899 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
900 "0135 PLOGI: cannot format reg_login "
901 "Data: x%x x%x x%x x%x\n",
902 ndlp->nlp_DID, ndlp->nlp_state,
903 ndlp->nlp_flag, ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -0500904 }
905
906
James Smart92d7f7b2007-06-17 19:56:38 -0500907out:
908 if (ndlp->nlp_DID == NameServer_DID) {
909 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -0400910 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
911 "0261 Cannot Register NameServer login\n");
James Smart92d7f7b2007-06-17 19:56:38 -0500912 }
913
James Smart0ff10d42008-01-11 01:52:36 -0500914 spin_lock_irq(shost->host_lock);
James Smarta8adb832007-10-27 13:37:53 -0400915 ndlp->nlp_flag |= NLP_DEFER_RM;
James Smart0ff10d42008-01-11 01:52:36 -0500916 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500917 return NLP_STE_FREED_NODE;
dea31012005-04-17 16:05:31 -0500918}
919
920static uint32_t
James Smart0ff10d42008-01-11 01:52:36 -0500921lpfc_cmpl_logo_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
922 void *arg, uint32_t evt)
923{
924 return ndlp->nlp_state;
925}
926
927static uint32_t
928lpfc_cmpl_reglogin_plogi_issue(struct lpfc_vport *vport,
929 struct lpfc_nodelist *ndlp, void *arg, uint32_t evt)
930{
931 return ndlp->nlp_state;
932}
933
934static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -0500935lpfc_device_rm_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
936 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -0500937{
James Smart2e0fef82007-06-17 19:56:36 -0500938 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -0500939
James Smart2e0fef82007-06-17 19:56:36 -0500940 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
941 spin_lock_irq(shost->host_lock);
942 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
943 spin_unlock_irq(shost->host_lock);
944 return ndlp->nlp_state;
945 } else {
946 /* software abort outstanding PLOGI */
947 lpfc_els_abort(vport->phba, ndlp);
948
949 lpfc_drop_node(vport, ndlp);
James Smarta0f9b482006-04-15 11:52:56 -0400950 return NLP_STE_FREED_NODE;
951 }
dea31012005-04-17 16:05:31 -0500952}
953
954static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -0500955lpfc_device_recov_plogi_issue(struct lpfc_vport *vport,
956 struct lpfc_nodelist *ndlp,
957 void *arg,
958 uint32_t evt)
dea31012005-04-17 16:05:31 -0500959{
James Smart2e0fef82007-06-17 19:56:36 -0500960 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
961 struct lpfc_hba *phba = vport->phba;
962
James Smart92d7f7b2007-06-17 19:56:38 -0500963 /* Don't do anything that will mess up processing of the
964 * previous RSCN.
965 */
966 if (vport->fc_flag & FC_RSCN_DEFERRED)
967 return ndlp->nlp_state;
968
dea31012005-04-17 16:05:31 -0500969 /* software abort outstanding PLOGI */
James Smart07951072007-04-25 09:51:38 -0400970 lpfc_els_abort(phba, ndlp);
dea31012005-04-17 16:05:31 -0500971
Jamie Wellnitz5024ab12006-02-28 19:25:28 -0500972 ndlp->nlp_prev_state = NLP_STE_PLOGI_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -0500973 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
James Smart92d7f7b2007-06-17 19:56:38 -0500974 spin_lock_irq(shost->host_lock);
James Smarta0f9b482006-04-15 11:52:56 -0400975 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
James Smart2e0fef82007-06-17 19:56:36 -0500976 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500977
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500978 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -0500979}
980
981static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -0500982lpfc_rcv_plogi_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
983 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -0500984{
James Smart0d2b6b82008-06-14 22:52:47 -0400985 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart2e0fef82007-06-17 19:56:36 -0500986 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500987 struct lpfc_iocbq *cmdiocb;
988
989 /* software abort outstanding ADISC */
James Smart07951072007-04-25 09:51:38 -0400990 lpfc_els_abort(phba, ndlp);
dea31012005-04-17 16:05:31 -0500991
992 cmdiocb = (struct lpfc_iocbq *) arg;
993
James Smart0d2b6b82008-06-14 22:52:47 -0400994 if (lpfc_rcv_plogi(vport, ndlp, cmdiocb)) {
995 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
996 spin_lock_irq(shost->host_lock);
997 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
998 spin_unlock_irq(shost->host_lock);
James Smart90160e02008-08-24 21:49:45 -0400999 if (vport->num_disc_nodes)
James Smart0d2b6b82008-06-14 22:52:47 -04001000 lpfc_more_adisc(vport);
James Smart0d2b6b82008-06-14 22:52:47 -04001001 }
1002 return ndlp->nlp_state;
1003 }
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001004 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -05001005 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
1006 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
dea31012005-04-17 16:05:31 -05001007
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001008 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001009}
1010
1011static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001012lpfc_rcv_prli_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1013 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001014{
James Smart2e0fef82007-06-17 19:56:36 -05001015 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001016
James Smart2e0fef82007-06-17 19:56:36 -05001017 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001018 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001019}
1020
1021static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001022lpfc_rcv_logo_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1023 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001024{
James Smart2e0fef82007-06-17 19:56:36 -05001025 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001026 struct lpfc_iocbq *cmdiocb;
1027
1028 cmdiocb = (struct lpfc_iocbq *) arg;
1029
1030 /* software abort outstanding ADISC */
James Smart07951072007-04-25 09:51:38 -04001031 lpfc_els_abort(phba, ndlp);
dea31012005-04-17 16:05:31 -05001032
James Smart2e0fef82007-06-17 19:56:36 -05001033 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001034 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001035}
1036
1037static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001038lpfc_rcv_padisc_adisc_issue(struct lpfc_vport *vport,
1039 struct lpfc_nodelist *ndlp,
1040 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001041{
1042 struct lpfc_iocbq *cmdiocb;
1043
1044 cmdiocb = (struct lpfc_iocbq *) arg;
1045
James Smart2e0fef82007-06-17 19:56:36 -05001046 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001047 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001048}
1049
1050static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001051lpfc_rcv_prlo_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1052 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001053{
1054 struct lpfc_iocbq *cmdiocb;
1055
1056 cmdiocb = (struct lpfc_iocbq *) arg;
1057
1058 /* Treat like rcv logo */
James Smart2e0fef82007-06-17 19:56:36 -05001059 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_PRLO);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001060 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001061}
1062
1063static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001064lpfc_cmpl_adisc_adisc_issue(struct lpfc_vport *vport,
1065 struct lpfc_nodelist *ndlp,
1066 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001067{
James Smart2e0fef82007-06-17 19:56:36 -05001068 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1069 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001070 struct lpfc_iocbq *cmdiocb, *rspiocb;
1071 IOCB_t *irsp;
1072 ADISC *ap;
1073
1074 cmdiocb = (struct lpfc_iocbq *) arg;
1075 rspiocb = cmdiocb->context_un.rsp_iocb;
1076
1077 ap = (ADISC *)lpfc_check_elscmpl_iocb(phba, cmdiocb, rspiocb);
1078 irsp = &rspiocb->iocb;
1079
1080 if ((irsp->ulpStatus) ||
James Smart92d7f7b2007-06-17 19:56:38 -05001081 (!lpfc_check_adisc(vport, ndlp, &ap->nodeName, &ap->portName))) {
dea31012005-04-17 16:05:31 -05001082 /* 1 sec timeout */
1083 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ);
James Smart2e0fef82007-06-17 19:56:36 -05001084 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001085 ndlp->nlp_flag |= NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05001086 spin_unlock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001087 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
dea31012005-04-17 16:05:31 -05001088
James Smart2e0fef82007-06-17 19:56:36 -05001089 memset(&ndlp->nlp_nodename, 0, sizeof(struct lpfc_name));
1090 memset(&ndlp->nlp_portname, 0, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05001091
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001092 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -05001093 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1094 lpfc_unreg_rpi(vport, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001095 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001096 }
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001097
James.Smart@Emulex.Com25013222005-06-25 10:34:33 -04001098 if (ndlp->nlp_type & NLP_FCP_TARGET) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001099 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -05001100 lpfc_nlp_set_state(vport, ndlp, NLP_STE_MAPPED_NODE);
James.Smart@Emulex.Com25013222005-06-25 10:34:33 -04001101 } else {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001102 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -05001103 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
James.Smart@Emulex.Com25013222005-06-25 10:34:33 -04001104 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001105 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001106}
1107
1108static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001109lpfc_device_rm_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1110 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001111{
James Smart2e0fef82007-06-17 19:56:36 -05001112 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001113
James Smart2e0fef82007-06-17 19:56:36 -05001114 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1115 spin_lock_irq(shost->host_lock);
1116 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
1117 spin_unlock_irq(shost->host_lock);
1118 return ndlp->nlp_state;
1119 } else {
1120 /* software abort outstanding ADISC */
1121 lpfc_els_abort(vport->phba, ndlp);
1122
1123 lpfc_drop_node(vport, ndlp);
James Smarta0f9b482006-04-15 11:52:56 -04001124 return NLP_STE_FREED_NODE;
1125 }
dea31012005-04-17 16:05:31 -05001126}
1127
1128static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001129lpfc_device_recov_adisc_issue(struct lpfc_vport *vport,
1130 struct lpfc_nodelist *ndlp,
1131 void *arg,
1132 uint32_t evt)
dea31012005-04-17 16:05:31 -05001133{
James Smart2e0fef82007-06-17 19:56:36 -05001134 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1135 struct lpfc_hba *phba = vport->phba;
1136
James Smart92d7f7b2007-06-17 19:56:38 -05001137 /* Don't do anything that will mess up processing of the
1138 * previous RSCN.
1139 */
1140 if (vport->fc_flag & FC_RSCN_DEFERRED)
1141 return ndlp->nlp_state;
1142
dea31012005-04-17 16:05:31 -05001143 /* software abort outstanding ADISC */
James Smart07951072007-04-25 09:51:38 -04001144 lpfc_els_abort(phba, ndlp);
dea31012005-04-17 16:05:31 -05001145
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001146 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -05001147 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1148 spin_lock_irq(shost->host_lock);
James Smarta0f9b482006-04-15 11:52:56 -04001149 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
James Smart2e0fef82007-06-17 19:56:36 -05001150 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05001151 lpfc_disc_set_adisc(vport, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001152 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001153}
1154
1155static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001156lpfc_rcv_plogi_reglogin_issue(struct lpfc_vport *vport,
1157 struct lpfc_nodelist *ndlp,
1158 void *arg,
dea31012005-04-17 16:05:31 -05001159 uint32_t evt)
1160{
James Smart2e0fef82007-06-17 19:56:36 -05001161 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001162
James Smart2e0fef82007-06-17 19:56:36 -05001163 lpfc_rcv_plogi(vport, ndlp, cmdiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001164 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001165}
1166
1167static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001168lpfc_rcv_prli_reglogin_issue(struct lpfc_vport *vport,
1169 struct lpfc_nodelist *ndlp,
1170 void *arg,
dea31012005-04-17 16:05:31 -05001171 uint32_t evt)
1172{
James Smart2e0fef82007-06-17 19:56:36 -05001173 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001174
James Smart2e0fef82007-06-17 19:56:36 -05001175 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001176 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001177}
1178
1179static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001180lpfc_rcv_logo_reglogin_issue(struct lpfc_vport *vport,
1181 struct lpfc_nodelist *ndlp,
1182 void *arg,
dea31012005-04-17 16:05:31 -05001183 uint32_t evt)
1184{
James Smart2e0fef82007-06-17 19:56:36 -05001185 struct lpfc_hba *phba = vport->phba;
1186 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
James Smart7054a602007-04-25 09:52:34 -04001187 LPFC_MBOXQ_t *mb;
1188 LPFC_MBOXQ_t *nextmb;
1189 struct lpfc_dmabuf *mp;
dea31012005-04-17 16:05:31 -05001190
1191 cmdiocb = (struct lpfc_iocbq *) arg;
1192
James Smart7054a602007-04-25 09:52:34 -04001193 /* cleanup any ndlp on mbox q waiting for reglogin cmpl */
1194 if ((mb = phba->sli.mbox_active)) {
1195 if ((mb->mb.mbxCommand == MBX_REG_LOGIN64) &&
1196 (ndlp == (struct lpfc_nodelist *) mb->context2)) {
James Smart92d7f7b2007-06-17 19:56:38 -05001197 lpfc_nlp_put(ndlp);
James Smart7054a602007-04-25 09:52:34 -04001198 mb->context2 = NULL;
1199 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1200 }
1201 }
1202
James Smart2e0fef82007-06-17 19:56:36 -05001203 spin_lock_irq(&phba->hbalock);
James Smart7054a602007-04-25 09:52:34 -04001204 list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) {
1205 if ((mb->mb.mbxCommand == MBX_REG_LOGIN64) &&
1206 (ndlp == (struct lpfc_nodelist *) mb->context2)) {
1207 mp = (struct lpfc_dmabuf *) (mb->context1);
1208 if (mp) {
James Smart98c9ea52007-10-27 13:37:33 -04001209 __lpfc_mbuf_free(phba, mp->virt, mp->phys);
James Smart7054a602007-04-25 09:52:34 -04001210 kfree(mp);
1211 }
James Smart92d7f7b2007-06-17 19:56:38 -05001212 lpfc_nlp_put(ndlp);
James Smart7054a602007-04-25 09:52:34 -04001213 list_del(&mb->list);
1214 mempool_free(mb, phba->mbox_mem_pool);
1215 }
1216 }
James Smart2e0fef82007-06-17 19:56:36 -05001217 spin_unlock_irq(&phba->hbalock);
James Smart7054a602007-04-25 09:52:34 -04001218
James Smart2e0fef82007-06-17 19:56:36 -05001219 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001220 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001221}
1222
1223static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001224lpfc_rcv_padisc_reglogin_issue(struct lpfc_vport *vport,
1225 struct lpfc_nodelist *ndlp,
1226 void *arg,
dea31012005-04-17 16:05:31 -05001227 uint32_t evt)
1228{
James Smart2e0fef82007-06-17 19:56:36 -05001229 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001230
James Smart2e0fef82007-06-17 19:56:36 -05001231 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001232 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001233}
1234
1235static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001236lpfc_rcv_prlo_reglogin_issue(struct lpfc_vport *vport,
1237 struct lpfc_nodelist *ndlp,
1238 void *arg,
dea31012005-04-17 16:05:31 -05001239 uint32_t evt)
1240{
1241 struct lpfc_iocbq *cmdiocb;
1242
1243 cmdiocb = (struct lpfc_iocbq *) arg;
James Smart51ef4c22007-08-02 11:10:31 -04001244 lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001245 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001246}
1247
1248static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001249lpfc_cmpl_reglogin_reglogin_issue(struct lpfc_vport *vport,
1250 struct lpfc_nodelist *ndlp,
1251 void *arg,
1252 uint32_t evt)
dea31012005-04-17 16:05:31 -05001253{
James Smart2e0fef82007-06-17 19:56:36 -05001254 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart2e0fef82007-06-17 19:56:36 -05001255 LPFC_MBOXQ_t *pmb = (LPFC_MBOXQ_t *) arg;
1256 MAILBOX_t *mb = &pmb->mb;
1257 uint32_t did = mb->un.varWords[1];
dea31012005-04-17 16:05:31 -05001258
dea31012005-04-17 16:05:31 -05001259 if (mb->mbxStatus) {
1260 /* RegLogin failed */
James Smarte8b62012007-08-02 11:10:09 -04001261 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
1262 "0246 RegLogin failed Data: x%x x%x x%x\n",
James Smart2e0fef82007-06-17 19:56:36 -05001263 did, mb->mbxStatus, vport->port_state);
James Smartd0e56da2006-07-06 15:49:42 -04001264 /*
1265 * If RegLogin failed due to lack of HBA resources do not
1266 * retry discovery.
1267 */
1268 if (mb->mbxStatus == MBXERR_RPI_FULL) {
James Smart87af33f2007-10-27 13:37:43 -04001269 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
1270 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
James Smartd0e56da2006-07-06 15:49:42 -04001271 return ndlp->nlp_state;
1272 }
1273
James Smart2e0fef82007-06-17 19:56:36 -05001274 /* Put ndlp in npr state set plogi timer for 1 sec */
dea31012005-04-17 16:05:31 -05001275 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ * 1);
James Smart2e0fef82007-06-17 19:56:36 -05001276 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001277 ndlp->nlp_flag |= NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05001278 spin_unlock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001279 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
dea31012005-04-17 16:05:31 -05001280
James Smart2e0fef82007-06-17 19:56:36 -05001281 lpfc_issue_els_logo(vport, ndlp, 0);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001282 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -05001283 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001284 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001285 }
1286
dea31012005-04-17 16:05:31 -05001287 ndlp->nlp_rpi = mb->un.varWords[0];
dea31012005-04-17 16:05:31 -05001288
1289 /* Only if we are not a fabric nport do we issue PRLI */
1290 if (!(ndlp->nlp_type & NLP_FABRIC)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001291 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -05001292 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
1293 lpfc_issue_els_prli(vport, ndlp, 0);
dea31012005-04-17 16:05:31 -05001294 } else {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001295 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -05001296 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
dea31012005-04-17 16:05:31 -05001297 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001298 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001299}
1300
1301static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001302lpfc_device_rm_reglogin_issue(struct lpfc_vport *vport,
1303 struct lpfc_nodelist *ndlp,
1304 void *arg,
dea31012005-04-17 16:05:31 -05001305 uint32_t evt)
1306{
James Smart2e0fef82007-06-17 19:56:36 -05001307 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1308
1309 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1310 spin_lock_irq(shost->host_lock);
James Smarta0f9b482006-04-15 11:52:56 -04001311 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
James Smart2e0fef82007-06-17 19:56:36 -05001312 spin_unlock_irq(shost->host_lock);
James Smarta0f9b482006-04-15 11:52:56 -04001313 return ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05001314 } else {
1315 lpfc_drop_node(vport, ndlp);
James Smarta0f9b482006-04-15 11:52:56 -04001316 return NLP_STE_FREED_NODE;
1317 }
dea31012005-04-17 16:05:31 -05001318}
1319
1320static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001321lpfc_device_recov_reglogin_issue(struct lpfc_vport *vport,
1322 struct lpfc_nodelist *ndlp,
1323 void *arg,
1324 uint32_t evt)
dea31012005-04-17 16:05:31 -05001325{
James Smart2e0fef82007-06-17 19:56:36 -05001326 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1327
James Smart92d7f7b2007-06-17 19:56:38 -05001328 /* Don't do anything that will mess up processing of the
1329 * previous RSCN.
1330 */
1331 if (vport->fc_flag & FC_RSCN_DEFERRED)
1332 return ndlp->nlp_state;
1333
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001334 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -05001335 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1336 spin_lock_irq(shost->host_lock);
James Smarta0f9b482006-04-15 11:52:56 -04001337 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
James Smart2e0fef82007-06-17 19:56:36 -05001338 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05001339 lpfc_disc_set_adisc(vport, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001340 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001341}
1342
1343static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001344lpfc_rcv_plogi_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1345 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001346{
1347 struct lpfc_iocbq *cmdiocb;
1348
1349 cmdiocb = (struct lpfc_iocbq *) arg;
1350
James Smart2e0fef82007-06-17 19:56:36 -05001351 lpfc_rcv_plogi(vport, ndlp, cmdiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001352 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001353}
1354
1355static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001356lpfc_rcv_prli_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1357 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001358{
James Smart2e0fef82007-06-17 19:56:36 -05001359 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001360
James Smart2e0fef82007-06-17 19:56:36 -05001361 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001362 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001363}
1364
1365static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001366lpfc_rcv_logo_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1367 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001368{
James Smart2e0fef82007-06-17 19:56:36 -05001369 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001370
1371 /* Software abort outstanding PRLI before sending acc */
James Smart2e0fef82007-06-17 19:56:36 -05001372 lpfc_els_abort(vport->phba, ndlp);
dea31012005-04-17 16:05:31 -05001373
James Smart2e0fef82007-06-17 19:56:36 -05001374 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001375 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001376}
1377
1378static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001379lpfc_rcv_padisc_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1380 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001381{
James Smart2e0fef82007-06-17 19:56:36 -05001382 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001383
James Smart2e0fef82007-06-17 19:56:36 -05001384 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001385 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001386}
1387
1388/* This routine is envoked when we rcv a PRLO request from a nport
1389 * we are logged into. We should send back a PRLO rsp setting the
1390 * appropriate bits.
1391 * NEXT STATE = PRLI_ISSUE
1392 */
1393static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001394lpfc_rcv_prlo_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1395 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001396{
James Smart2e0fef82007-06-17 19:56:36 -05001397 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001398
James Smart51ef4c22007-08-02 11:10:31 -04001399 lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001400 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001401}
1402
1403static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001404lpfc_cmpl_prli_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1405 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001406{
James Smart92d7f7b2007-06-17 19:56:38 -05001407 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001408 struct lpfc_iocbq *cmdiocb, *rspiocb;
James Smart2e0fef82007-06-17 19:56:36 -05001409 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001410 IOCB_t *irsp;
1411 PRLI *npr;
1412
1413 cmdiocb = (struct lpfc_iocbq *) arg;
1414 rspiocb = cmdiocb->context_un.rsp_iocb;
1415 npr = (PRLI *)lpfc_check_elscmpl_iocb(phba, cmdiocb, rspiocb);
1416
1417 irsp = &rspiocb->iocb;
1418 if (irsp->ulpStatus) {
James Smart858c9f62007-06-17 19:56:39 -05001419 if ((vport->port_type == LPFC_NPIV_PORT) &&
James Smart3de2a652007-08-02 11:09:59 -04001420 vport->cfg_restrict_login) {
James Smart858c9f62007-06-17 19:56:39 -05001421 goto out;
1422 }
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001423 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -05001424 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001425 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001426 }
1427
1428 /* Check out PRLI rsp */
1429 ndlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR);
1430 ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
1431 if ((npr->acceptRspCode == PRLI_REQ_EXECUTED) &&
1432 (npr->prliType == PRLI_FCP_TYPE)) {
1433 if (npr->initiatorFunc)
1434 ndlp->nlp_type |= NLP_FCP_INITIATOR;
1435 if (npr->targetFunc)
1436 ndlp->nlp_type |= NLP_FCP_TARGET;
1437 if (npr->Retry)
1438 ndlp->nlp_fcp_info |= NLP_FCP_2_DEVICE;
1439 }
James Smart92d7f7b2007-06-17 19:56:38 -05001440 if (!(ndlp->nlp_type & NLP_FCP_TARGET) &&
1441 (vport->port_type == LPFC_NPIV_PORT) &&
James Smart3de2a652007-08-02 11:09:59 -04001442 vport->cfg_restrict_login) {
James Smart858c9f62007-06-17 19:56:39 -05001443out:
James Smart92d7f7b2007-06-17 19:56:38 -05001444 spin_lock_irq(shost->host_lock);
1445 ndlp->nlp_flag |= NLP_TARGET_REMOVE;
1446 spin_unlock_irq(shost->host_lock);
1447 lpfc_issue_els_logo(vport, ndlp, 0);
1448
1449 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
James Smart87af33f2007-10-27 13:37:43 -04001450 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
James Smart92d7f7b2007-06-17 19:56:38 -05001451 return ndlp->nlp_state;
1452 }
dea31012005-04-17 16:05:31 -05001453
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001454 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
James Smart92d7f7b2007-06-17 19:56:38 -05001455 if (ndlp->nlp_type & NLP_FCP_TARGET)
1456 lpfc_nlp_set_state(vport, ndlp, NLP_STE_MAPPED_NODE);
1457 else
1458 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001459 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001460}
1461
1462/*! lpfc_device_rm_prli_issue
James Smart92d7f7b2007-06-17 19:56:38 -05001463 *
1464 * \pre
1465 * \post
1466 * \param phba
1467 * \param ndlp
1468 * \param arg
1469 * \param evt
1470 * \return uint32_t
1471 *
1472 * \b Description:
1473 * This routine is envoked when we a request to remove a nport we are in the
1474 * process of PRLIing. We should software abort outstanding prli, unreg
1475 * login, send a logout. We will change node state to UNUSED_NODE, put it
1476 * on plogi list so it can be freed when LOGO completes.
1477 *
1478 */
1479
dea31012005-04-17 16:05:31 -05001480static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001481lpfc_device_rm_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1482 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001483{
James Smart2e0fef82007-06-17 19:56:36 -05001484 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001485
James Smart2e0fef82007-06-17 19:56:36 -05001486 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1487 spin_lock_irq(shost->host_lock);
1488 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
1489 spin_unlock_irq(shost->host_lock);
1490 return ndlp->nlp_state;
1491 } else {
1492 /* software abort outstanding PLOGI */
1493 lpfc_els_abort(vport->phba, ndlp);
1494
1495 lpfc_drop_node(vport, ndlp);
James Smarta0f9b482006-04-15 11:52:56 -04001496 return NLP_STE_FREED_NODE;
1497 }
dea31012005-04-17 16:05:31 -05001498}
1499
1500
1501/*! lpfc_device_recov_prli_issue
James Smart92d7f7b2007-06-17 19:56:38 -05001502 *
1503 * \pre
1504 * \post
1505 * \param phba
1506 * \param ndlp
1507 * \param arg
1508 * \param evt
1509 * \return uint32_t
1510 *
1511 * \b Description:
1512 * The routine is envoked when the state of a device is unknown, like
1513 * during a link down. We should remove the nodelist entry from the
1514 * unmapped list, issue a UNREG_LOGIN, do a software abort of the
1515 * outstanding PRLI command, then free the node entry.
1516 */
dea31012005-04-17 16:05:31 -05001517static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001518lpfc_device_recov_prli_issue(struct lpfc_vport *vport,
1519 struct lpfc_nodelist *ndlp,
1520 void *arg,
1521 uint32_t evt)
dea31012005-04-17 16:05:31 -05001522{
James Smart2e0fef82007-06-17 19:56:36 -05001523 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1524 struct lpfc_hba *phba = vport->phba;
1525
James Smart92d7f7b2007-06-17 19:56:38 -05001526 /* Don't do anything that will mess up processing of the
1527 * previous RSCN.
1528 */
1529 if (vport->fc_flag & FC_RSCN_DEFERRED)
1530 return ndlp->nlp_state;
1531
dea31012005-04-17 16:05:31 -05001532 /* software abort outstanding PRLI */
James Smart07951072007-04-25 09:51:38 -04001533 lpfc_els_abort(phba, ndlp);
dea31012005-04-17 16:05:31 -05001534
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001535 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -05001536 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1537 spin_lock_irq(shost->host_lock);
James Smarta0f9b482006-04-15 11:52:56 -04001538 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
James Smart2e0fef82007-06-17 19:56:36 -05001539 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05001540 lpfc_disc_set_adisc(vport, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001541 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001542}
1543
1544static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001545lpfc_rcv_plogi_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1546 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001547{
James Smart2e0fef82007-06-17 19:56:36 -05001548 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001549
James Smart2e0fef82007-06-17 19:56:36 -05001550 lpfc_rcv_plogi(vport, ndlp, cmdiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001551 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001552}
1553
1554static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001555lpfc_rcv_prli_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1556 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001557{
James Smart2e0fef82007-06-17 19:56:36 -05001558 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001559
James Smart2e0fef82007-06-17 19:56:36 -05001560 lpfc_rcv_prli(vport, ndlp, cmdiocb);
1561 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001562 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001563}
1564
1565static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001566lpfc_rcv_logo_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1567 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001568{
James Smart2e0fef82007-06-17 19:56:36 -05001569 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001570
James Smart2e0fef82007-06-17 19:56:36 -05001571 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001572 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001573}
1574
1575static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001576lpfc_rcv_padisc_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1577 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001578{
James Smart2e0fef82007-06-17 19:56:36 -05001579 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001580
James Smart2e0fef82007-06-17 19:56:36 -05001581 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001582 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001583}
1584
1585static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001586lpfc_rcv_prlo_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1587 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001588{
James Smart2e0fef82007-06-17 19:56:36 -05001589 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001590
James Smart51ef4c22007-08-02 11:10:31 -04001591 lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001592 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001593}
1594
1595static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001596lpfc_device_recov_unmap_node(struct lpfc_vport *vport,
1597 struct lpfc_nodelist *ndlp,
1598 void *arg,
1599 uint32_t evt)
dea31012005-04-17 16:05:31 -05001600{
James Smart2e0fef82007-06-17 19:56:36 -05001601 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1602
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001603 ndlp->nlp_prev_state = NLP_STE_UNMAPPED_NODE;
James Smart2e0fef82007-06-17 19:56:36 -05001604 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1605 spin_lock_irq(shost->host_lock);
James Smarta0f9b482006-04-15 11:52:56 -04001606 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
James Smart2e0fef82007-06-17 19:56:36 -05001607 spin_unlock_irq(shost->host_lock);
1608 lpfc_disc_set_adisc(vport, ndlp);
dea31012005-04-17 16:05:31 -05001609
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001610 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001611}
1612
1613static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001614lpfc_rcv_plogi_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1615 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001616{
James Smart2e0fef82007-06-17 19:56:36 -05001617 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001618
James Smart2e0fef82007-06-17 19:56:36 -05001619 lpfc_rcv_plogi(vport, ndlp, cmdiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001620 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001621}
1622
1623static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001624lpfc_rcv_prli_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1625 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001626{
James Smart2e0fef82007-06-17 19:56:36 -05001627 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001628
James Smart2e0fef82007-06-17 19:56:36 -05001629 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001630 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001631}
1632
1633static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001634lpfc_rcv_logo_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1635 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001636{
James Smart2e0fef82007-06-17 19:56:36 -05001637 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001638
James Smart2e0fef82007-06-17 19:56:36 -05001639 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001640 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001641}
1642
1643static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001644lpfc_rcv_padisc_mapped_node(struct lpfc_vport *vport,
1645 struct lpfc_nodelist *ndlp,
1646 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001647{
James Smart2e0fef82007-06-17 19:56:36 -05001648 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001649
James Smart2e0fef82007-06-17 19:56:36 -05001650 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001651 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001652}
1653
1654static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001655lpfc_rcv_prlo_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1656 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001657{
James Smart2e0fef82007-06-17 19:56:36 -05001658 struct lpfc_hba *phba = vport->phba;
1659 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001660
1661 /* flush the target */
James Smart51ef4c22007-08-02 11:10:31 -04001662 lpfc_sli_abort_iocb(vport, &phba->sli.ring[phba->sli.fcp_ring],
1663 ndlp->nlp_sid, 0, LPFC_CTX_TGT);
dea31012005-04-17 16:05:31 -05001664
1665 /* Treat like rcv logo */
James Smart2e0fef82007-06-17 19:56:36 -05001666 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_PRLO);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001667 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001668}
1669
1670static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001671lpfc_device_recov_mapped_node(struct lpfc_vport *vport,
1672 struct lpfc_nodelist *ndlp,
1673 void *arg,
1674 uint32_t evt)
dea31012005-04-17 16:05:31 -05001675{
James Smart2e0fef82007-06-17 19:56:36 -05001676 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1677
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001678 ndlp->nlp_prev_state = NLP_STE_MAPPED_NODE;
James Smart2e0fef82007-06-17 19:56:36 -05001679 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1680 spin_lock_irq(shost->host_lock);
James Smarta0f9b482006-04-15 11:52:56 -04001681 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
James Smart2e0fef82007-06-17 19:56:36 -05001682 spin_unlock_irq(shost->host_lock);
1683 lpfc_disc_set_adisc(vport, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001684 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001685}
1686
1687static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001688lpfc_rcv_plogi_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1689 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001690{
James Smart2e0fef82007-06-17 19:56:36 -05001691 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1692 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001693
1694 /* Ignore PLOGI if we have an outstanding LOGO */
James Smart0d2b6b82008-06-14 22:52:47 -04001695 if (ndlp->nlp_flag & (NLP_LOGO_SND | NLP_LOGO_ACC))
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001696 return ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05001697 if (lpfc_rcv_plogi(vport, ndlp, cmdiocb)) {
James Smart0d2b6b82008-06-14 22:52:47 -04001698 lpfc_cancel_retry_delay_tmo(vport, ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05001699 spin_lock_irq(shost->host_lock);
James Smart0d2b6b82008-06-14 22:52:47 -04001700 ndlp->nlp_flag &= ~(NLP_NPR_ADISC | NLP_NPR_2B_DISC);
James Smart2e0fef82007-06-17 19:56:36 -05001701 spin_unlock_irq(shost->host_lock);
James Smart0d2b6b82008-06-14 22:52:47 -04001702 } else if (!(ndlp->nlp_flag & NLP_NPR_2B_DISC)) {
1703 /* send PLOGI immediately, move to PLOGI issue state */
1704 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
1705 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
1706 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
1707 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
1708 }
dea31012005-04-17 16:05:31 -05001709 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001710 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001711}
1712
1713static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001714lpfc_rcv_prli_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1715 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001716{
James Smart2e0fef82007-06-17 19:56:36 -05001717 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1718 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1719 struct ls_rjt stat;
dea31012005-04-17 16:05:31 -05001720
1721 memset(&stat, 0, sizeof (struct ls_rjt));
1722 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
1723 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
James Smart858c9f62007-06-17 19:56:39 -05001724 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05001725
1726 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
1727 if (ndlp->nlp_flag & NLP_NPR_ADISC) {
James Smart2e0fef82007-06-17 19:56:36 -05001728 spin_lock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001729 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001730 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
James Smart2e0fef82007-06-17 19:56:36 -05001731 spin_unlock_irq(shost->host_lock);
1732 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
1733 lpfc_issue_els_adisc(vport, ndlp, 0);
dea31012005-04-17 16:05:31 -05001734 } else {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001735 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
James Smart2e0fef82007-06-17 19:56:36 -05001736 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
1737 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
dea31012005-04-17 16:05:31 -05001738 }
1739 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001740 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001741}
1742
1743static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001744lpfc_rcv_logo_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1745 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001746{
James Smart2e0fef82007-06-17 19:56:36 -05001747 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001748
James Smart2e0fef82007-06-17 19:56:36 -05001749 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001750 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001751}
1752
1753static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001754lpfc_rcv_padisc_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1755 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001756{
James Smart2e0fef82007-06-17 19:56:36 -05001757 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001758
James Smart2e0fef82007-06-17 19:56:36 -05001759 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
James Smart33ccf8d2006-08-17 11:57:58 -04001760 /*
1761 * Do not start discovery if discovery is about to start
1762 * or discovery in progress for this node. Starting discovery
1763 * here will affect the counting of discovery threads.
1764 */
James Smart2fb9bd82006-12-02 13:33:57 -05001765 if (!(ndlp->nlp_flag & NLP_DELAY_TMO) &&
James Smart92d7f7b2007-06-17 19:56:38 -05001766 !(ndlp->nlp_flag & NLP_NPR_2B_DISC)) {
dea31012005-04-17 16:05:31 -05001767 if (ndlp->nlp_flag & NLP_NPR_ADISC) {
James Smart92d7f7b2007-06-17 19:56:38 -05001768 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001769 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
James Smart2e0fef82007-06-17 19:56:36 -05001770 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
1771 lpfc_issue_els_adisc(vport, ndlp, 0);
dea31012005-04-17 16:05:31 -05001772 } else {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001773 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
James Smart2e0fef82007-06-17 19:56:36 -05001774 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
1775 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
dea31012005-04-17 16:05:31 -05001776 }
1777 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001778 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001779}
1780
1781static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001782lpfc_rcv_prlo_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1783 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001784{
James Smart2e0fef82007-06-17 19:56:36 -05001785 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1786 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001787
James Smart2e0fef82007-06-17 19:56:36 -05001788 spin_lock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001789 ndlp->nlp_flag |= NLP_LOGO_ACC;
James Smart2e0fef82007-06-17 19:56:36 -05001790 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001791
James Smart51ef4c22007-08-02 11:10:31 -04001792 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05001793
James Smart2e0fef82007-06-17 19:56:36 -05001794 if ((ndlp->nlp_flag & NLP_DELAY_TMO) == 0) {
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001795 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ * 1);
James Smart2e0fef82007-06-17 19:56:36 -05001796 spin_lock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001797 ndlp->nlp_flag |= NLP_DELAY_TMO;
1798 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
James Smart2e0fef82007-06-17 19:56:36 -05001799 spin_unlock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001800 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001801 } else {
James Smart2e0fef82007-06-17 19:56:36 -05001802 spin_lock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001803 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
James Smart2e0fef82007-06-17 19:56:36 -05001804 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001805 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001806 return ndlp->nlp_state;
1807}
dea31012005-04-17 16:05:31 -05001808
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001809static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001810lpfc_cmpl_plogi_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1811 void *arg, uint32_t evt)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001812{
1813 struct lpfc_iocbq *cmdiocb, *rspiocb;
James Smarta0f9b482006-04-15 11:52:56 -04001814 IOCB_t *irsp;
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001815
1816 cmdiocb = (struct lpfc_iocbq *) arg;
1817 rspiocb = cmdiocb->context_un.rsp_iocb;
James Smarta0f9b482006-04-15 11:52:56 -04001818
1819 irsp = &rspiocb->iocb;
1820 if (irsp->ulpStatus) {
James Smarta8adb832007-10-27 13:37:53 -04001821 ndlp->nlp_flag |= NLP_DEFER_RM;
James Smarta0f9b482006-04-15 11:52:56 -04001822 return NLP_STE_FREED_NODE;
1823 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001824 return ndlp->nlp_state;
1825}
1826
1827static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001828lpfc_cmpl_prli_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1829 void *arg, uint32_t evt)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001830{
1831 struct lpfc_iocbq *cmdiocb, *rspiocb;
James Smarta0f9b482006-04-15 11:52:56 -04001832 IOCB_t *irsp;
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001833
1834 cmdiocb = (struct lpfc_iocbq *) arg;
1835 rspiocb = cmdiocb->context_un.rsp_iocb;
James Smarta0f9b482006-04-15 11:52:56 -04001836
1837 irsp = &rspiocb->iocb;
1838 if (irsp->ulpStatus && (ndlp->nlp_flag & NLP_NODEV_REMOVE)) {
James Smart2e0fef82007-06-17 19:56:36 -05001839 lpfc_drop_node(vport, ndlp);
James Smarta0f9b482006-04-15 11:52:56 -04001840 return NLP_STE_FREED_NODE;
1841 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001842 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001843}
1844
1845static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001846lpfc_cmpl_logo_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1847 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001848{
James Smartd7c255b2008-08-24 21:50:00 -04001849 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1850 if (ndlp->nlp_DID == Fabric_DID) {
1851 spin_lock_irq(shost->host_lock);
1852 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
1853 spin_unlock_irq(shost->host_lock);
1854 }
James Smart2e0fef82007-06-17 19:56:36 -05001855 lpfc_unreg_rpi(vport, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001856 return ndlp->nlp_state;
1857}
1858
1859static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001860lpfc_cmpl_adisc_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1861 void *arg, uint32_t evt)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001862{
1863 struct lpfc_iocbq *cmdiocb, *rspiocb;
James Smarta0f9b482006-04-15 11:52:56 -04001864 IOCB_t *irsp;
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001865
1866 cmdiocb = (struct lpfc_iocbq *) arg;
1867 rspiocb = cmdiocb->context_un.rsp_iocb;
James Smarta0f9b482006-04-15 11:52:56 -04001868
1869 irsp = &rspiocb->iocb;
1870 if (irsp->ulpStatus && (ndlp->nlp_flag & NLP_NODEV_REMOVE)) {
James Smart2e0fef82007-06-17 19:56:36 -05001871 lpfc_drop_node(vport, ndlp);
James Smarta0f9b482006-04-15 11:52:56 -04001872 return NLP_STE_FREED_NODE;
1873 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001874 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001875}
1876
1877static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001878lpfc_cmpl_reglogin_npr_node(struct lpfc_vport *vport,
1879 struct lpfc_nodelist *ndlp,
1880 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001881{
James Smart2e0fef82007-06-17 19:56:36 -05001882 LPFC_MBOXQ_t *pmb = (LPFC_MBOXQ_t *) arg;
1883 MAILBOX_t *mb = &pmb->mb;
dea31012005-04-17 16:05:31 -05001884
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001885 if (!mb->mbxStatus)
1886 ndlp->nlp_rpi = mb->un.varWords[0];
James Smarta0f9b482006-04-15 11:52:56 -04001887 else {
1888 if (ndlp->nlp_flag & NLP_NODEV_REMOVE) {
James Smart2e0fef82007-06-17 19:56:36 -05001889 lpfc_drop_node(vport, ndlp);
James Smarta0f9b482006-04-15 11:52:56 -04001890 return NLP_STE_FREED_NODE;
1891 }
1892 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001893 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001894}
1895
1896static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001897lpfc_device_rm_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1898 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001899{
James Smart2e0fef82007-06-17 19:56:36 -05001900 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1901
James Smarta0f9b482006-04-15 11:52:56 -04001902 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
James Smart2e0fef82007-06-17 19:56:36 -05001903 spin_lock_irq(shost->host_lock);
James Smarta0f9b482006-04-15 11:52:56 -04001904 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
James Smart2e0fef82007-06-17 19:56:36 -05001905 spin_unlock_irq(shost->host_lock);
James Smarta0f9b482006-04-15 11:52:56 -04001906 return ndlp->nlp_state;
1907 }
James Smart2e0fef82007-06-17 19:56:36 -05001908 lpfc_drop_node(vport, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001909 return NLP_STE_FREED_NODE;
dea31012005-04-17 16:05:31 -05001910}
1911
1912static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001913lpfc_device_recov_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1914 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001915{
James Smart2e0fef82007-06-17 19:56:36 -05001916 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1917
James Smart92d7f7b2007-06-17 19:56:38 -05001918 /* Don't do anything that will mess up processing of the
1919 * previous RSCN.
1920 */
1921 if (vport->fc_flag & FC_RSCN_DEFERRED)
1922 return ndlp->nlp_state;
1923
James Smarteaf15d52008-12-04 22:39:29 -05001924 lpfc_cancel_retry_delay_tmo(vport, ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05001925 spin_lock_irq(shost->host_lock);
James Smarta0f9b482006-04-15 11:52:56 -04001926 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
James Smart2e0fef82007-06-17 19:56:36 -05001927 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001928 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001929}
1930
1931
1932/* This next section defines the NPort Discovery State Machine */
1933
1934/* There are 4 different double linked lists nodelist entries can reside on.
1935 * The plogi list and adisc list are used when Link Up discovery or RSCN
1936 * processing is needed. Each list holds the nodes that we will send PLOGI
1937 * or ADISC on. These lists will keep track of what nodes will be effected
1938 * by an RSCN, or a Link Up (Typically, all nodes are effected on Link Up).
1939 * The unmapped_list will contain all nodes that we have successfully logged
1940 * into at the Fibre Channel level. The mapped_list will contain all nodes
1941 * that are mapped FCP targets.
1942 */
1943/*
1944 * The bind list is a list of undiscovered (potentially non-existent) nodes
1945 * that we have saved binding information on. This information is used when
1946 * nodes transition from the unmapped to the mapped list.
1947 */
1948/* For UNUSED_NODE state, the node has just been allocated .
1949 * For PLOGI_ISSUE and REG_LOGIN_ISSUE, the node is on
1950 * the PLOGI list. For REG_LOGIN_COMPL, the node is taken off the PLOGI list
1951 * and put on the unmapped list. For ADISC processing, the node is taken off
1952 * the ADISC list and placed on either the mapped or unmapped list (depending
1953 * on its previous state). Once on the unmapped list, a PRLI is issued and the
1954 * state changed to PRLI_ISSUE. When the PRLI completion occurs, the state is
1955 * changed to UNMAPPED_NODE. If the completion indicates a mapped
1956 * node, the node is taken off the unmapped list. The binding list is checked
1957 * for a valid binding, or a binding is automatically assigned. If binding
1958 * assignment is unsuccessful, the node is left on the unmapped list. If
1959 * binding assignment is successful, the associated binding list entry (if
1960 * any) is removed, and the node is placed on the mapped list.
1961 */
1962/*
1963 * For a Link Down, all nodes on the ADISC, PLOGI, unmapped or mapped
James Smartc01f3202006-08-18 17:47:08 -04001964 * lists will receive a DEVICE_RECOVERY event. If the linkdown or devloss timers
dea31012005-04-17 16:05:31 -05001965 * expire, all effected nodes will receive a DEVICE_RM event.
1966 */
1967/*
1968 * For a Link Up or RSCN, all nodes will move from the mapped / unmapped lists
1969 * to either the ADISC or PLOGI list. After a Nameserver query or ALPA loopmap
1970 * check, additional nodes may be added or removed (via DEVICE_RM) to / from
1971 * the PLOGI or ADISC lists. Once the PLOGI and ADISC lists are populated,
1972 * we will first process the ADISC list. 32 entries are processed initially and
1973 * ADISC is initited for each one. Completions / Events for each node are
1974 * funnelled thru the state machine. As each node finishes ADISC processing, it
1975 * starts ADISC for any nodes waiting for ADISC processing. If no nodes are
1976 * waiting, and the ADISC list count is identically 0, then we are done. For
1977 * Link Up discovery, since all nodes on the PLOGI list are UNREG_LOGIN'ed, we
1978 * can issue a CLEAR_LA and reenable Link Events. Next we will process the PLOGI
1979 * list. 32 entries are processed initially and PLOGI is initited for each one.
1980 * Completions / Events for each node are funnelled thru the state machine. As
1981 * each node finishes PLOGI processing, it starts PLOGI for any nodes waiting
1982 * for PLOGI processing. If no nodes are waiting, and the PLOGI list count is
1983 * indentically 0, then we are done. We have now completed discovery / RSCN
1984 * handling. Upon completion, ALL nodes should be on either the mapped or
1985 * unmapped lists.
1986 */
1987
1988static uint32_t (*lpfc_disc_action[NLP_STE_MAX_STATE * NLP_EVT_MAX_EVENT])
James Smart2e0fef82007-06-17 19:56:36 -05001989 (struct lpfc_vport *, struct lpfc_nodelist *, void *, uint32_t) = {
dea31012005-04-17 16:05:31 -05001990 /* Action routine Event Current State */
1991 lpfc_rcv_plogi_unused_node, /* RCV_PLOGI UNUSED_NODE */
1992 lpfc_rcv_els_unused_node, /* RCV_PRLI */
1993 lpfc_rcv_logo_unused_node, /* RCV_LOGO */
1994 lpfc_rcv_els_unused_node, /* RCV_ADISC */
1995 lpfc_rcv_els_unused_node, /* RCV_PDISC */
1996 lpfc_rcv_els_unused_node, /* RCV_PRLO */
1997 lpfc_disc_illegal, /* CMPL_PLOGI */
1998 lpfc_disc_illegal, /* CMPL_PRLI */
1999 lpfc_cmpl_logo_unused_node, /* CMPL_LOGO */
2000 lpfc_disc_illegal, /* CMPL_ADISC */
2001 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2002 lpfc_device_rm_unused_node, /* DEVICE_RM */
2003 lpfc_disc_illegal, /* DEVICE_RECOVERY */
2004
2005 lpfc_rcv_plogi_plogi_issue, /* RCV_PLOGI PLOGI_ISSUE */
James Smart92d7f7b2007-06-17 19:56:38 -05002006 lpfc_rcv_prli_plogi_issue, /* RCV_PRLI */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002007 lpfc_rcv_logo_plogi_issue, /* RCV_LOGO */
dea31012005-04-17 16:05:31 -05002008 lpfc_rcv_els_plogi_issue, /* RCV_ADISC */
2009 lpfc_rcv_els_plogi_issue, /* RCV_PDISC */
2010 lpfc_rcv_els_plogi_issue, /* RCV_PRLO */
2011 lpfc_cmpl_plogi_plogi_issue, /* CMPL_PLOGI */
2012 lpfc_disc_illegal, /* CMPL_PRLI */
James Smart0ff10d42008-01-11 01:52:36 -05002013 lpfc_cmpl_logo_plogi_issue, /* CMPL_LOGO */
dea31012005-04-17 16:05:31 -05002014 lpfc_disc_illegal, /* CMPL_ADISC */
James Smart0ff10d42008-01-11 01:52:36 -05002015 lpfc_cmpl_reglogin_plogi_issue,/* CMPL_REG_LOGIN */
dea31012005-04-17 16:05:31 -05002016 lpfc_device_rm_plogi_issue, /* DEVICE_RM */
2017 lpfc_device_recov_plogi_issue, /* DEVICE_RECOVERY */
2018
2019 lpfc_rcv_plogi_adisc_issue, /* RCV_PLOGI ADISC_ISSUE */
2020 lpfc_rcv_prli_adisc_issue, /* RCV_PRLI */
2021 lpfc_rcv_logo_adisc_issue, /* RCV_LOGO */
2022 lpfc_rcv_padisc_adisc_issue, /* RCV_ADISC */
2023 lpfc_rcv_padisc_adisc_issue, /* RCV_PDISC */
2024 lpfc_rcv_prlo_adisc_issue, /* RCV_PRLO */
2025 lpfc_disc_illegal, /* CMPL_PLOGI */
2026 lpfc_disc_illegal, /* CMPL_PRLI */
2027 lpfc_disc_illegal, /* CMPL_LOGO */
2028 lpfc_cmpl_adisc_adisc_issue, /* CMPL_ADISC */
2029 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2030 lpfc_device_rm_adisc_issue, /* DEVICE_RM */
2031 lpfc_device_recov_adisc_issue, /* DEVICE_RECOVERY */
2032
2033 lpfc_rcv_plogi_reglogin_issue, /* RCV_PLOGI REG_LOGIN_ISSUE */
2034 lpfc_rcv_prli_reglogin_issue, /* RCV_PLOGI */
2035 lpfc_rcv_logo_reglogin_issue, /* RCV_LOGO */
2036 lpfc_rcv_padisc_reglogin_issue, /* RCV_ADISC */
2037 lpfc_rcv_padisc_reglogin_issue, /* RCV_PDISC */
2038 lpfc_rcv_prlo_reglogin_issue, /* RCV_PRLO */
James Smart87af33f2007-10-27 13:37:43 -04002039 lpfc_cmpl_plogi_illegal, /* CMPL_PLOGI */
dea31012005-04-17 16:05:31 -05002040 lpfc_disc_illegal, /* CMPL_PRLI */
2041 lpfc_disc_illegal, /* CMPL_LOGO */
2042 lpfc_disc_illegal, /* CMPL_ADISC */
2043 lpfc_cmpl_reglogin_reglogin_issue,/* CMPL_REG_LOGIN */
2044 lpfc_device_rm_reglogin_issue, /* DEVICE_RM */
2045 lpfc_device_recov_reglogin_issue,/* DEVICE_RECOVERY */
2046
2047 lpfc_rcv_plogi_prli_issue, /* RCV_PLOGI PRLI_ISSUE */
2048 lpfc_rcv_prli_prli_issue, /* RCV_PRLI */
2049 lpfc_rcv_logo_prli_issue, /* RCV_LOGO */
2050 lpfc_rcv_padisc_prli_issue, /* RCV_ADISC */
2051 lpfc_rcv_padisc_prli_issue, /* RCV_PDISC */
2052 lpfc_rcv_prlo_prli_issue, /* RCV_PRLO */
James Smart87af33f2007-10-27 13:37:43 -04002053 lpfc_cmpl_plogi_illegal, /* CMPL_PLOGI */
dea31012005-04-17 16:05:31 -05002054 lpfc_cmpl_prli_prli_issue, /* CMPL_PRLI */
2055 lpfc_disc_illegal, /* CMPL_LOGO */
2056 lpfc_disc_illegal, /* CMPL_ADISC */
2057 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2058 lpfc_device_rm_prli_issue, /* DEVICE_RM */
2059 lpfc_device_recov_prli_issue, /* DEVICE_RECOVERY */
2060
2061 lpfc_rcv_plogi_unmap_node, /* RCV_PLOGI UNMAPPED_NODE */
2062 lpfc_rcv_prli_unmap_node, /* RCV_PRLI */
2063 lpfc_rcv_logo_unmap_node, /* RCV_LOGO */
2064 lpfc_rcv_padisc_unmap_node, /* RCV_ADISC */
2065 lpfc_rcv_padisc_unmap_node, /* RCV_PDISC */
2066 lpfc_rcv_prlo_unmap_node, /* RCV_PRLO */
2067 lpfc_disc_illegal, /* CMPL_PLOGI */
2068 lpfc_disc_illegal, /* CMPL_PRLI */
2069 lpfc_disc_illegal, /* CMPL_LOGO */
2070 lpfc_disc_illegal, /* CMPL_ADISC */
2071 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2072 lpfc_disc_illegal, /* DEVICE_RM */
2073 lpfc_device_recov_unmap_node, /* DEVICE_RECOVERY */
2074
2075 lpfc_rcv_plogi_mapped_node, /* RCV_PLOGI MAPPED_NODE */
2076 lpfc_rcv_prli_mapped_node, /* RCV_PRLI */
2077 lpfc_rcv_logo_mapped_node, /* RCV_LOGO */
2078 lpfc_rcv_padisc_mapped_node, /* RCV_ADISC */
2079 lpfc_rcv_padisc_mapped_node, /* RCV_PDISC */
2080 lpfc_rcv_prlo_mapped_node, /* RCV_PRLO */
2081 lpfc_disc_illegal, /* CMPL_PLOGI */
2082 lpfc_disc_illegal, /* CMPL_PRLI */
2083 lpfc_disc_illegal, /* CMPL_LOGO */
2084 lpfc_disc_illegal, /* CMPL_ADISC */
2085 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2086 lpfc_disc_illegal, /* DEVICE_RM */
2087 lpfc_device_recov_mapped_node, /* DEVICE_RECOVERY */
2088
2089 lpfc_rcv_plogi_npr_node, /* RCV_PLOGI NPR_NODE */
2090 lpfc_rcv_prli_npr_node, /* RCV_PRLI */
2091 lpfc_rcv_logo_npr_node, /* RCV_LOGO */
2092 lpfc_rcv_padisc_npr_node, /* RCV_ADISC */
2093 lpfc_rcv_padisc_npr_node, /* RCV_PDISC */
2094 lpfc_rcv_prlo_npr_node, /* RCV_PRLO */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002095 lpfc_cmpl_plogi_npr_node, /* CMPL_PLOGI */
2096 lpfc_cmpl_prli_npr_node, /* CMPL_PRLI */
dea31012005-04-17 16:05:31 -05002097 lpfc_cmpl_logo_npr_node, /* CMPL_LOGO */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002098 lpfc_cmpl_adisc_npr_node, /* CMPL_ADISC */
dea31012005-04-17 16:05:31 -05002099 lpfc_cmpl_reglogin_npr_node, /* CMPL_REG_LOGIN */
2100 lpfc_device_rm_npr_node, /* DEVICE_RM */
2101 lpfc_device_recov_npr_node, /* DEVICE_RECOVERY */
2102};
2103
2104int
James Smart2e0fef82007-06-17 19:56:36 -05002105lpfc_disc_state_machine(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2106 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05002107{
2108 uint32_t cur_state, rc;
James Smart2e0fef82007-06-17 19:56:36 -05002109 uint32_t(*func) (struct lpfc_vport *, struct lpfc_nodelist *, void *,
dea31012005-04-17 16:05:31 -05002110 uint32_t);
James Smarte47c9092008-02-08 18:49:26 -05002111 uint32_t got_ndlp = 0;
dea31012005-04-17 16:05:31 -05002112
James Smarte47c9092008-02-08 18:49:26 -05002113 if (lpfc_nlp_get(ndlp))
2114 got_ndlp = 1;
2115
dea31012005-04-17 16:05:31 -05002116 cur_state = ndlp->nlp_state;
2117
2118 /* DSM in event <evt> on NPort <nlp_DID> in state <cur_state> */
James Smarte8b62012007-08-02 11:10:09 -04002119 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2120 "0211 DSM in event x%x on NPort x%x in "
2121 "state %d Data: x%x\n",
2122 evt, ndlp->nlp_DID, cur_state, ndlp->nlp_flag);
dea31012005-04-17 16:05:31 -05002123
James Smart858c9f62007-06-17 19:56:39 -05002124 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_DSM,
2125 "DSM in: evt:%d ste:%d did:x%x",
2126 evt, cur_state, ndlp->nlp_DID);
2127
dea31012005-04-17 16:05:31 -05002128 func = lpfc_disc_action[(cur_state * NLP_EVT_MAX_EVENT) + evt];
James Smart2e0fef82007-06-17 19:56:36 -05002129 rc = (func) (vport, ndlp, arg, evt);
dea31012005-04-17 16:05:31 -05002130
2131 /* DSM out state <rc> on NPort <nlp_DID> */
James Smarte47c9092008-02-08 18:49:26 -05002132 if (got_ndlp) {
2133 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
James Smarte8b62012007-08-02 11:10:09 -04002134 "0212 DSM out state %d on NPort x%x Data: x%x\n",
2135 rc, ndlp->nlp_DID, ndlp->nlp_flag);
dea31012005-04-17 16:05:31 -05002136
James Smarte47c9092008-02-08 18:49:26 -05002137 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_DSM,
2138 "DSM out: ste:%d did:x%x flg:x%x",
2139 rc, ndlp->nlp_DID, ndlp->nlp_flag);
2140 /* Decrement the ndlp reference count held for this function */
2141 lpfc_nlp_put(ndlp);
2142 } else {
2143 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
James Smartd7c255b2008-08-24 21:50:00 -04002144 "0213 DSM out state %d on NPort free\n", rc);
James Smart858c9f62007-06-17 19:56:39 -05002145
James Smarte47c9092008-02-08 18:49:26 -05002146 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_DSM,
2147 "DSM out: ste:%d did:x%x flg:x%x",
2148 rc, 0, 0);
2149 }
dea31012005-04-17 16:05:31 -05002150
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002151 return rc;
dea31012005-04-17 16:05:31 -05002152}