blob: 1a16ee9b2e87f8aa420108af14e71353856314e2 [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 Smart9413aff2007-04-25 09:53:35 -04004 * Copyright (C) 2004-2007 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
31#include "lpfc_hw.h"
32#include "lpfc_sli.h"
33#include "lpfc_disc.h"
34#include "lpfc_scsi.h"
35#include "lpfc.h"
36#include "lpfc_logmsg.h"
37#include "lpfc_crtn.h"
James Smart92d7f7b2007-06-17 19:56:38 -050038#include "lpfc_vport.h"
James Smart858c9f62007-06-17 19:56:39 -050039#include "lpfc_debugfs.h"
dea31012005-04-17 16:05:31 -050040
41
42/* Called to verify a rcv'ed ADISC was intended for us. */
43static int
James Smart2e0fef82007-06-17 19:56:36 -050044lpfc_check_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
45 struct lpfc_name *nn, struct lpfc_name *pn)
dea31012005-04-17 16:05:31 -050046{
47 /* Compare the ADISC rsp WWNN / WWPN matches our internal node
48 * table entry for that node.
49 */
James Smart2e0fef82007-06-17 19:56:36 -050050 if (memcmp(nn, &ndlp->nlp_nodename, sizeof (struct lpfc_name)))
Jamie Wellnitzc9f87352006-02-28 19:25:23 -050051 return 0;
dea31012005-04-17 16:05:31 -050052
James Smart2e0fef82007-06-17 19:56:36 -050053 if (memcmp(pn, &ndlp->nlp_portname, sizeof (struct lpfc_name)))
Jamie Wellnitzc9f87352006-02-28 19:25:23 -050054 return 0;
dea31012005-04-17 16:05:31 -050055
56 /* we match, return success */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -050057 return 1;
dea31012005-04-17 16:05:31 -050058}
59
dea31012005-04-17 16:05:31 -050060int
James Smart2e0fef82007-06-17 19:56:36 -050061lpfc_check_sparm(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
62 struct serv_parm * sp, uint32_t class)
dea31012005-04-17 16:05:31 -050063{
James Smart2e0fef82007-06-17 19:56:36 -050064 volatile struct serv_parm *hsp = &vport->fc_sparam;
James.Smart@Emulex.Com2fb70f72005-11-28 11:41:24 -050065 uint16_t hsp_value, ssp_value = 0;
dea31012005-04-17 16:05:31 -050066
James.Smart@Emulex.Com2fb70f72005-11-28 11:41:24 -050067 /*
68 * The receive data field size and buffer-to-buffer receive data field
69 * size entries are 16 bits but are represented as two 8-bit fields in
70 * the driver data structure to account for rsvd bits and other control
71 * bits. Reconstruct and compare the fields as a 16-bit values before
72 * correcting the byte values.
73 */
dea31012005-04-17 16:05:31 -050074 if (sp->cls1.classValid) {
James.Smart@Emulex.Com2fb70f72005-11-28 11:41:24 -050075 hsp_value = (hsp->cls1.rcvDataSizeMsb << 8) |
76 hsp->cls1.rcvDataSizeLsb;
77 ssp_value = (sp->cls1.rcvDataSizeMsb << 8) |
78 sp->cls1.rcvDataSizeLsb;
James Smart92d7f7b2007-06-17 19:56:38 -050079 if (!ssp_value)
80 goto bad_service_param;
James.Smart@Emulex.Com2fb70f72005-11-28 11:41:24 -050081 if (ssp_value > hsp_value) {
dea31012005-04-17 16:05:31 -050082 sp->cls1.rcvDataSizeLsb = hsp->cls1.rcvDataSizeLsb;
James.Smart@Emulex.Com2fb70f72005-11-28 11:41:24 -050083 sp->cls1.rcvDataSizeMsb = hsp->cls1.rcvDataSizeMsb;
84 }
dea31012005-04-17 16:05:31 -050085 } else if (class == CLASS1) {
James Smart92d7f7b2007-06-17 19:56:38 -050086 goto bad_service_param;
dea31012005-04-17 16:05:31 -050087 }
88
89 if (sp->cls2.classValid) {
James.Smart@Emulex.Com2fb70f72005-11-28 11:41:24 -050090 hsp_value = (hsp->cls2.rcvDataSizeMsb << 8) |
91 hsp->cls2.rcvDataSizeLsb;
92 ssp_value = (sp->cls2.rcvDataSizeMsb << 8) |
93 sp->cls2.rcvDataSizeLsb;
James Smart92d7f7b2007-06-17 19:56:38 -050094 if (!ssp_value)
95 goto bad_service_param;
James.Smart@Emulex.Com2fb70f72005-11-28 11:41:24 -050096 if (ssp_value > hsp_value) {
dea31012005-04-17 16:05:31 -050097 sp->cls2.rcvDataSizeLsb = hsp->cls2.rcvDataSizeLsb;
James.Smart@Emulex.Com2fb70f72005-11-28 11:41:24 -050098 sp->cls2.rcvDataSizeMsb = hsp->cls2.rcvDataSizeMsb;
99 }
dea31012005-04-17 16:05:31 -0500100 } else if (class == CLASS2) {
James Smart92d7f7b2007-06-17 19:56:38 -0500101 goto bad_service_param;
dea31012005-04-17 16:05:31 -0500102 }
103
104 if (sp->cls3.classValid) {
James.Smart@Emulex.Com2fb70f72005-11-28 11:41:24 -0500105 hsp_value = (hsp->cls3.rcvDataSizeMsb << 8) |
106 hsp->cls3.rcvDataSizeLsb;
107 ssp_value = (sp->cls3.rcvDataSizeMsb << 8) |
108 sp->cls3.rcvDataSizeLsb;
James Smart92d7f7b2007-06-17 19:56:38 -0500109 if (!ssp_value)
110 goto bad_service_param;
James.Smart@Emulex.Com2fb70f72005-11-28 11:41:24 -0500111 if (ssp_value > hsp_value) {
dea31012005-04-17 16:05:31 -0500112 sp->cls3.rcvDataSizeLsb = hsp->cls3.rcvDataSizeLsb;
James.Smart@Emulex.Com2fb70f72005-11-28 11:41:24 -0500113 sp->cls3.rcvDataSizeMsb = hsp->cls3.rcvDataSizeMsb;
114 }
dea31012005-04-17 16:05:31 -0500115 } else if (class == CLASS3) {
James Smart92d7f7b2007-06-17 19:56:38 -0500116 goto bad_service_param;
dea31012005-04-17 16:05:31 -0500117 }
118
James.Smart@Emulex.Com2fb70f72005-11-28 11:41:24 -0500119 /*
120 * Preserve the upper four bits of the MSB from the PLOGI response.
121 * These bits contain the Buffer-to-Buffer State Change Number
122 * from the target and need to be passed to the FW.
123 */
124 hsp_value = (hsp->cmn.bbRcvSizeMsb << 8) | hsp->cmn.bbRcvSizeLsb;
125 ssp_value = (sp->cmn.bbRcvSizeMsb << 8) | sp->cmn.bbRcvSizeLsb;
126 if (ssp_value > hsp_value) {
dea31012005-04-17 16:05:31 -0500127 sp->cmn.bbRcvSizeLsb = hsp->cmn.bbRcvSizeLsb;
James.Smart@Emulex.Com2fb70f72005-11-28 11:41:24 -0500128 sp->cmn.bbRcvSizeMsb = (sp->cmn.bbRcvSizeMsb & 0xF0) |
129 (hsp->cmn.bbRcvSizeMsb & 0x0F);
130 }
dea31012005-04-17 16:05:31 -0500131
dea31012005-04-17 16:05:31 -0500132 memcpy(&ndlp->nlp_nodename, &sp->nodeName, sizeof (struct lpfc_name));
133 memcpy(&ndlp->nlp_portname, &sp->portName, sizeof (struct lpfc_name));
James.Smart@Emulex.Com2fb70f72005-11-28 11:41:24 -0500134 return 1;
James Smart92d7f7b2007-06-17 19:56:38 -0500135bad_service_param:
James Smarte8b62012007-08-02 11:10:09 -0400136 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
137 "0207 Device %x "
138 "(%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x) sent "
139 "invalid service parameters. Ignoring device.\n",
140 ndlp->nlp_DID,
141 sp->nodeName.u.wwn[0], sp->nodeName.u.wwn[1],
142 sp->nodeName.u.wwn[2], sp->nodeName.u.wwn[3],
143 sp->nodeName.u.wwn[4], sp->nodeName.u.wwn[5],
144 sp->nodeName.u.wwn[6], sp->nodeName.u.wwn[7]);
James Smart92d7f7b2007-06-17 19:56:38 -0500145 return 0;
dea31012005-04-17 16:05:31 -0500146}
147
148static void *
James Smart2e0fef82007-06-17 19:56:36 -0500149lpfc_check_elscmpl_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -0500150 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -0500151{
152 struct lpfc_dmabuf *pcmd, *prsp;
153 uint32_t *lp;
154 void *ptr = NULL;
155 IOCB_t *irsp;
156
157 irsp = &rspiocb->iocb;
158 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
159
160 /* For lpfc_els_abort, context2 could be zero'ed to delay
161 * freeing associated memory till after ABTS completes.
162 */
163 if (pcmd) {
164 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf,
165 list);
166 if (prsp) {
167 lp = (uint32_t *) prsp->virt;
168 ptr = (void *)((uint8_t *)lp + sizeof(uint32_t));
169 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500170 } else {
dea31012005-04-17 16:05:31 -0500171 /* Force ulpStatus error since we are returning NULL ptr */
172 if (!(irsp->ulpStatus)) {
173 irsp->ulpStatus = IOSTAT_LOCAL_REJECT;
174 irsp->un.ulpWord[4] = IOERR_SLI_ABORTED;
175 }
176 ptr = NULL;
177 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500178 return ptr;
dea31012005-04-17 16:05:31 -0500179}
180
181
182/*
183 * Free resources / clean up outstanding I/Os
184 * associated with a LPFC_NODELIST entry. This
185 * routine effectively results in a "software abort".
186 */
187int
James Smart2e0fef82007-06-17 19:56:36 -0500188lpfc_els_abort(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -0500189{
James Smart2534ba72007-04-25 09:52:20 -0400190 LIST_HEAD(completions);
James Smart2e0fef82007-06-17 19:56:36 -0500191 struct lpfc_sli *psli = &phba->sli;
192 struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING];
dea31012005-04-17 16:05:31 -0500193 struct lpfc_iocbq *iocb, *next_iocb;
James Smart2534ba72007-04-25 09:52:20 -0400194 IOCB_t *cmd;
dea31012005-04-17 16:05:31 -0500195
196 /* Abort outstanding I/O on NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -0400197 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_DISCOVERY,
198 "0205 Abort outstanding I/O on NPort x%x "
199 "Data: x%x x%x x%x\n",
200 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
201 ndlp->nlp_rpi);
James Smart92d7f7b2007-06-17 19:56:38 -0500202
203 lpfc_fabric_abort_nport(ndlp);
dea31012005-04-17 16:05:31 -0500204
dea31012005-04-17 16:05:31 -0500205 /* First check the txq */
James Smart2e0fef82007-06-17 19:56:36 -0500206 spin_lock_irq(&phba->hbalock);
James Smart2534ba72007-04-25 09:52:20 -0400207 list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
James Smart858c9f62007-06-17 19:56:39 -0500208 /* Check to see if iocb matches the nport we are looking for */
James Smart2534ba72007-04-25 09:52:20 -0400209 if (lpfc_check_sli_ndlp(phba, pring, iocb, ndlp)) {
James Smart858c9f62007-06-17 19:56:39 -0500210 /* It matches, so deque and call compl with anp error */
James Smart2534ba72007-04-25 09:52:20 -0400211 list_move_tail(&iocb->list, &completions);
212 pring->txq_cnt--;
dea31012005-04-17 16:05:31 -0500213 }
James Smart2534ba72007-04-25 09:52:20 -0400214 }
dea31012005-04-17 16:05:31 -0500215
dea31012005-04-17 16:05:31 -0500216 /* Next check the txcmplq */
James Smart07951072007-04-25 09:51:38 -0400217 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
James Smart858c9f62007-06-17 19:56:39 -0500218 /* Check to see if iocb matches the nport we are looking for */
James Smart92d7f7b2007-06-17 19:56:38 -0500219 if (lpfc_check_sli_ndlp(phba, pring, iocb, ndlp)) {
James Smart07951072007-04-25 09:51:38 -0400220 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
James Smart92d7f7b2007-06-17 19:56:38 -0500221 }
James Smart07951072007-04-25 09:51:38 -0400222 }
James Smart2e0fef82007-06-17 19:56:36 -0500223 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500224
James Smart2534ba72007-04-25 09:52:20 -0400225 while (!list_empty(&completions)) {
226 iocb = list_get_first(&completions, struct lpfc_iocbq, list);
227 cmd = &iocb->iocb;
James Smart92d7f7b2007-06-17 19:56:38 -0500228 list_del_init(&iocb->list);
James Smart2534ba72007-04-25 09:52:20 -0400229
James Smart2e0fef82007-06-17 19:56:36 -0500230 if (!iocb->iocb_cmpl)
231 lpfc_sli_release_iocbq(phba, iocb);
232 else {
James Smart2534ba72007-04-25 09:52:20 -0400233 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
234 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
235 (iocb->iocb_cmpl) (phba, iocb, iocb);
James Smart2e0fef82007-06-17 19:56:36 -0500236 }
James Smart2534ba72007-04-25 09:52:20 -0400237 }
238
dea31012005-04-17 16:05:31 -0500239 /* If we are delaying issuing an ELS command, cancel it */
James Smartfdcebe22006-03-07 15:04:01 -0500240 if (ndlp->nlp_flag & NLP_DELAY_TMO)
James Smart2e0fef82007-06-17 19:56:36 -0500241 lpfc_cancel_retry_delay_tmo(phba->pport, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500242 return 0;
dea31012005-04-17 16:05:31 -0500243}
244
245static int
James Smart2e0fef82007-06-17 19:56:36 -0500246lpfc_rcv_plogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
James Smart92d7f7b2007-06-17 19:56:38 -0500247 struct lpfc_iocbq *cmdiocb)
dea31012005-04-17 16:05:31 -0500248{
James Smart2e0fef82007-06-17 19:56:36 -0500249 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
250 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500251 struct lpfc_dmabuf *pcmd;
252 uint32_t *lp;
253 IOCB_t *icmd;
254 struct serv_parm *sp;
255 LPFC_MBOXQ_t *mbox;
256 struct ls_rjt stat;
257 int rc;
258
259 memset(&stat, 0, sizeof (struct ls_rjt));
James Smart2e0fef82007-06-17 19:56:36 -0500260 if (vport->port_state <= LPFC_FLOGI) {
dea31012005-04-17 16:05:31 -0500261 /* Before responding to PLOGI, check for pt2pt mode.
262 * If we are pt2pt, with an outstanding FLOGI, abort
263 * the FLOGI and resend it first.
264 */
James Smart2e0fef82007-06-17 19:56:36 -0500265 if (vport->fc_flag & FC_PT2PT) {
James Smart92d7f7b2007-06-17 19:56:38 -0500266 lpfc_els_abort_flogi(phba);
James Smart2e0fef82007-06-17 19:56:36 -0500267 if (!(vport->fc_flag & FC_PT2PT_PLOGI)) {
dea31012005-04-17 16:05:31 -0500268 /* If the other side is supposed to initiate
269 * the PLOGI anyway, just ACC it now and
270 * move on with discovery.
271 */
272 phba->fc_edtov = FF_DEF_EDTOV;
273 phba->fc_ratov = FF_DEF_RATOV;
274 /* Start discovery - this should just do
275 CLEAR_LA */
James Smart2e0fef82007-06-17 19:56:36 -0500276 lpfc_disc_start(vport);
James Smarted957682007-06-17 19:56:37 -0500277 } else
James Smart2e0fef82007-06-17 19:56:36 -0500278 lpfc_initial_flogi(vport);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500279 } else {
dea31012005-04-17 16:05:31 -0500280 stat.un.b.lsRjtRsnCode = LSRJT_LOGICAL_BSY;
281 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
James Smart2e0fef82007-06-17 19:56:36 -0500282 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb,
James Smart858c9f62007-06-17 19:56:39 -0500283 ndlp, NULL);
dea31012005-04-17 16:05:31 -0500284 return 0;
285 }
286 }
287 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
288 lp = (uint32_t *) pcmd->virt;
289 sp = (struct serv_parm *) ((uint8_t *) lp + sizeof (uint32_t));
James Smart2e0fef82007-06-17 19:56:36 -0500290 if ((lpfc_check_sparm(vport, ndlp, sp, CLASS3) == 0)) {
dea31012005-04-17 16:05:31 -0500291 /* Reject this request because invalid parameters */
292 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
293 stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
James Smart858c9f62007-06-17 19:56:39 -0500294 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
295 NULL);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500296 return 0;
dea31012005-04-17 16:05:31 -0500297 }
298 icmd = &cmdiocb->iocb;
299
300 /* PLOGI chkparm OK */
James Smarte8b62012007-08-02 11:10:09 -0400301 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
302 "0114 PLOGI chkparm OK Data: x%x x%x x%x x%x\n",
303 ndlp->nlp_DID, ndlp->nlp_state, ndlp->nlp_flag,
304 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -0500305
James Smart3de2a652007-08-02 11:09:59 -0400306 if (vport->cfg_fcp_class == 2 && sp->cls2.classValid)
dea31012005-04-17 16:05:31 -0500307 ndlp->nlp_fcp_info |= CLASS2;
James Smarted957682007-06-17 19:56:37 -0500308 else
dea31012005-04-17 16:05:31 -0500309 ndlp->nlp_fcp_info |= CLASS3;
James Smart2e0fef82007-06-17 19:56:36 -0500310
dea31012005-04-17 16:05:31 -0500311 ndlp->nlp_class_sup = 0;
312 if (sp->cls1.classValid)
313 ndlp->nlp_class_sup |= FC_COS_CLASS1;
314 if (sp->cls2.classValid)
315 ndlp->nlp_class_sup |= FC_COS_CLASS2;
316 if (sp->cls3.classValid)
317 ndlp->nlp_class_sup |= FC_COS_CLASS3;
318 if (sp->cls4.classValid)
319 ndlp->nlp_class_sup |= FC_COS_CLASS4;
320 ndlp->nlp_maxframe =
321 ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) | sp->cmn.bbRcvSizeLsb;
322
323 /* no need to reg_login if we are already in one of these states */
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500324 switch (ndlp->nlp_state) {
dea31012005-04-17 16:05:31 -0500325 case NLP_STE_NPR_NODE:
326 if (!(ndlp->nlp_flag & NLP_NPR_ADISC))
327 break;
328 case NLP_STE_REG_LOGIN_ISSUE:
329 case NLP_STE_PRLI_ISSUE:
330 case NLP_STE_UNMAPPED_NODE:
331 case NLP_STE_MAPPED_NODE:
James Smart51ef4c22007-08-02 11:10:31 -0400332 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp, NULL);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500333 return 1;
dea31012005-04-17 16:05:31 -0500334 }
335
James Smart92d7f7b2007-06-17 19:56:38 -0500336 if ((vport->fc_flag & FC_PT2PT) &&
337 !(vport->fc_flag & FC_PT2PT_PLOGI)) {
dea31012005-04-17 16:05:31 -0500338 /* rcv'ed PLOGI decides what our NPortId will be */
James Smart2e0fef82007-06-17 19:56:36 -0500339 vport->fc_myDID = icmd->un.rcvels.parmRo;
dea31012005-04-17 16:05:31 -0500340 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
341 if (mbox == NULL)
342 goto out;
343 lpfc_config_link(phba, mbox);
344 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smarted957682007-06-17 19:56:37 -0500345 mbox->vport = vport;
James Smart0b727fe2007-10-27 13:37:25 -0400346 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
dea31012005-04-17 16:05:31 -0500347 if (rc == MBX_NOT_FINISHED) {
James Smart92d7f7b2007-06-17 19:56:38 -0500348 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -0500349 goto out;
350 }
351
James Smart2e0fef82007-06-17 19:56:36 -0500352 lpfc_can_disctmo(vport);
dea31012005-04-17 16:05:31 -0500353 }
354 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
James Smart2e0fef82007-06-17 19:56:36 -0500355 if (!mbox)
dea31012005-04-17 16:05:31 -0500356 goto out;
357
James Smart92d7f7b2007-06-17 19:56:38 -0500358 rc = lpfc_reg_login(phba, vport->vpi, icmd->un.rcvels.remoteID,
359 (uint8_t *) sp, mbox, 0);
James Smart2e0fef82007-06-17 19:56:36 -0500360 if (rc) {
361 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -0500362 goto out;
363 }
364
365 /* ACC PLOGI rsp command needs to execute first,
366 * queue this mbox command to be processed later.
367 */
368 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
James Smart329f9bc2007-04-25 09:53:01 -0400369 /*
370 * mbox->context2 = lpfc_nlp_get(ndlp) deferred until mailbox
371 * command issued in lpfc_cmpl_els_acc().
372 */
James Smart2e0fef82007-06-17 19:56:36 -0500373 mbox->vport = vport;
374 spin_lock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -0500375 ndlp->nlp_flag |= (NLP_ACC_REGLOGIN | NLP_RCV_PLOGI);
James Smart2e0fef82007-06-17 19:56:36 -0500376 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500377
James Smart33ccf8d2006-08-17 11:57:58 -0400378 /*
379 * If there is an outstanding PLOGI issued, abort it before
380 * sending ACC rsp for received PLOGI. If pending plogi
381 * is not canceled here, the plogi will be rejected by
382 * remote port and will be retried. On a configuration with
383 * single discovery thread, this will cause a huge delay in
384 * discovery. Also this will cause multiple state machines
385 * running in parallel for this node.
386 */
387 if (ndlp->nlp_state == NLP_STE_PLOGI_ISSUE) {
388 /* software abort outstanding PLOGI */
James Smart07951072007-04-25 09:51:38 -0400389 lpfc_els_abort(phba, ndlp);
James Smart33ccf8d2006-08-17 11:57:58 -0400390 }
391
James Smart858c9f62007-06-17 19:56:39 -0500392 if ((vport->port_type == LPFC_NPIV_PORT &&
James Smart3de2a652007-08-02 11:09:59 -0400393 vport->cfg_restrict_login)) {
James Smart858c9f62007-06-17 19:56:39 -0500394
395 /* In order to preserve RPIs, we want to cleanup
396 * the default RPI the firmware created to rcv
397 * this ELS request. The only way to do this is
398 * to register, then unregister the RPI.
399 */
400 spin_lock_irq(shost->host_lock);
401 ndlp->nlp_flag |= NLP_RM_DFLT_RPI;
402 spin_unlock_irq(shost->host_lock);
403 stat.un.b.lsRjtRsnCode = LSRJT_INVALID_CMD;
404 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
405 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb,
406 ndlp, mbox);
407 return 1;
408 }
James Smart51ef4c22007-08-02 11:10:31 -0400409 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp, mbox);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500410 return 1;
dea31012005-04-17 16:05:31 -0500411
412out:
413 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
414 stat.un.b.lsRjtRsnCodeExp = LSEXP_OUT_OF_RESOURCE;
James Smart858c9f62007-06-17 19:56:39 -0500415 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500416 return 0;
dea31012005-04-17 16:05:31 -0500417}
418
419static int
James Smart2e0fef82007-06-17 19:56:36 -0500420lpfc_rcv_padisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -0500421 struct lpfc_iocbq *cmdiocb)
422{
James Smart2e0fef82007-06-17 19:56:36 -0500423 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -0500424 struct lpfc_dmabuf *pcmd;
James Smart2e0fef82007-06-17 19:56:36 -0500425 struct serv_parm *sp;
426 struct lpfc_name *pnn, *ppn;
dea31012005-04-17 16:05:31 -0500427 struct ls_rjt stat;
428 ADISC *ap;
429 IOCB_t *icmd;
430 uint32_t *lp;
431 uint32_t cmd;
432
433 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
434 lp = (uint32_t *) pcmd->virt;
435
436 cmd = *lp++;
437 if (cmd == ELS_CMD_ADISC) {
438 ap = (ADISC *) lp;
439 pnn = (struct lpfc_name *) & ap->nodeName;
440 ppn = (struct lpfc_name *) & ap->portName;
441 } else {
442 sp = (struct serv_parm *) lp;
443 pnn = (struct lpfc_name *) & sp->nodeName;
444 ppn = (struct lpfc_name *) & sp->portName;
445 }
446
447 icmd = &cmdiocb->iocb;
James Smart2e0fef82007-06-17 19:56:36 -0500448 if (icmd->ulpStatus == 0 && lpfc_check_adisc(vport, ndlp, pnn, ppn)) {
dea31012005-04-17 16:05:31 -0500449 if (cmd == ELS_CMD_ADISC) {
James Smart2e0fef82007-06-17 19:56:36 -0500450 lpfc_els_rsp_adisc_acc(vport, cmdiocb, ndlp);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500451 } else {
James Smart2e0fef82007-06-17 19:56:36 -0500452 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp,
James Smart51ef4c22007-08-02 11:10:31 -0400453 NULL);
dea31012005-04-17 16:05:31 -0500454 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500455 return 1;
dea31012005-04-17 16:05:31 -0500456 }
457 /* Reject this request because invalid parameters */
458 stat.un.b.lsRjtRsvd0 = 0;
459 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
460 stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
461 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -0500462 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -0500463
dea31012005-04-17 16:05:31 -0500464 /* 1 sec timeout */
465 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ);
466
James Smart2e0fef82007-06-17 19:56:36 -0500467 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500468 ndlp->nlp_flag |= NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -0500469 spin_unlock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -0500470 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
471 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -0500472 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500473 return 0;
dea31012005-04-17 16:05:31 -0500474}
475
476static int
James Smart2e0fef82007-06-17 19:56:36 -0500477lpfc_rcv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
478 struct lpfc_iocbq *cmdiocb, uint32_t els_cmd)
dea31012005-04-17 16:05:31 -0500479{
James Smart2e0fef82007-06-17 19:56:36 -0500480 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
481
482 /* Put ndlp in NPR state with 1 sec timeout for plogi, ACC logo */
dea31012005-04-17 16:05:31 -0500483 /* Only call LOGO ACC for first LOGO, this avoids sending unnecessary
484 * PLOGIs during LOGO storms from a device.
485 */
James Smart2e0fef82007-06-17 19:56:36 -0500486 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500487 ndlp->nlp_flag |= NLP_LOGO_ACC;
James Smart2e0fef82007-06-17 19:56:36 -0500488 spin_unlock_irq(shost->host_lock);
James Smart82d9a2a2006-04-15 11:53:05 -0400489 if (els_cmd == ELS_CMD_PRLO)
James Smart51ef4c22007-08-02 11:10:31 -0400490 lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL);
James Smart82d9a2a2006-04-15 11:53:05 -0400491 else
James Smart51ef4c22007-08-02 11:10:31 -0400492 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -0500493
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500494 if (!(ndlp->nlp_type & NLP_FABRIC) ||
James Smart92d7f7b2007-06-17 19:56:38 -0500495 (ndlp->nlp_state == NLP_STE_ADISC_ISSUE)) {
dea31012005-04-17 16:05:31 -0500496 /* Only try to re-login if this is NOT a Fabric Node */
dea31012005-04-17 16:05:31 -0500497 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ * 1);
James Smart2e0fef82007-06-17 19:56:36 -0500498 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500499 ndlp->nlp_flag |= NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -0500500 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500501
Jamie Wellnitz5024ab12006-02-28 19:25:28 -0500502 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
503 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -0500504 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500505 } else {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -0500506 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -0500507 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNUSED_NODE);
dea31012005-04-17 16:05:31 -0500508 }
509
James Smart2e0fef82007-06-17 19:56:36 -0500510 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500511 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
James Smart2e0fef82007-06-17 19:56:36 -0500512 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500513 /* The driver has to wait until the ACC completes before it continues
514 * processing the LOGO. The action will resume in
515 * lpfc_cmpl_els_logo_acc routine. Since part of processing includes an
516 * unreg_login, the driver waits so the ACC does not get aborted.
517 */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500518 return 0;
dea31012005-04-17 16:05:31 -0500519}
520
521static void
James Smart2e0fef82007-06-17 19:56:36 -0500522lpfc_rcv_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
523 struct lpfc_iocbq *cmdiocb)
dea31012005-04-17 16:05:31 -0500524{
525 struct lpfc_dmabuf *pcmd;
526 uint32_t *lp;
527 PRLI *npr;
528 struct fc_rport *rport = ndlp->rport;
529 u32 roles;
530
531 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
532 lp = (uint32_t *) pcmd->virt;
533 npr = (PRLI *) ((uint8_t *) lp + sizeof (uint32_t));
534
535 ndlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR);
536 ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
James Smart92d7f7b2007-06-17 19:56:38 -0500537 if (npr->prliType == PRLI_FCP_TYPE) {
dea31012005-04-17 16:05:31 -0500538 if (npr->initiatorFunc)
539 ndlp->nlp_type |= NLP_FCP_INITIATOR;
540 if (npr->targetFunc)
541 ndlp->nlp_type |= NLP_FCP_TARGET;
542 if (npr->Retry)
543 ndlp->nlp_fcp_info |= NLP_FCP_2_DEVICE;
544 }
545 if (rport) {
546 /* We need to update the rport role values */
547 roles = FC_RPORT_ROLE_UNKNOWN;
548 if (ndlp->nlp_type & NLP_FCP_INITIATOR)
549 roles |= FC_RPORT_ROLE_FCP_INITIATOR;
550 if (ndlp->nlp_type & NLP_FCP_TARGET)
551 roles |= FC_RPORT_ROLE_FCP_TARGET;
James Smart858c9f62007-06-17 19:56:39 -0500552
553 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
554 "rport rolechg: role:x%x did:x%x flg:x%x",
555 roles, ndlp->nlp_DID, ndlp->nlp_flag);
556
dea31012005-04-17 16:05:31 -0500557 fc_remote_port_rolechg(rport, roles);
558 }
559}
560
561static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -0500562lpfc_disc_set_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -0500563{
James Smart2e0fef82007-06-17 19:56:36 -0500564 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart2e0fef82007-06-17 19:56:36 -0500565
James Smart51ef4c22007-08-02 11:10:31 -0400566 if (!ndlp->nlp_rpi) {
567 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
568 return 0;
569 }
570
dea31012005-04-17 16:05:31 -0500571 /* Check config parameter use-adisc or FCP-2 */
James Smart3de2a652007-08-02 11:09:59 -0400572 if ((vport->cfg_use_adisc && (vport->fc_flag & FC_RSCN_MODE)) ||
James Smart92d7f7b2007-06-17 19:56:38 -0500573 ndlp->nlp_fcp_info & NLP_FCP_2_DEVICE) {
574 spin_lock_irq(shost->host_lock);
575 ndlp->nlp_flag |= NLP_NPR_ADISC;
576 spin_unlock_irq(shost->host_lock);
577 return 1;
578 }
579 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
580 lpfc_unreg_rpi(vport, ndlp);
581 return 0;
dea31012005-04-17 16:05:31 -0500582}
583
584static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -0500585lpfc_disc_illegal(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
586 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -0500587{
James Smarte8b62012007-08-02 11:10:09 -0400588 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
589 "0253 Illegal State Transition: node x%x "
590 "event x%x, state x%x Data: x%x x%x\n",
591 ndlp->nlp_DID, evt, ndlp->nlp_state, ndlp->nlp_rpi,
592 ndlp->nlp_flag);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500593 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -0500594}
595
596/* Start of Discovery State Machine routines */
597
598static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -0500599lpfc_rcv_plogi_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
600 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -0500601{
602 struct lpfc_iocbq *cmdiocb;
603
604 cmdiocb = (struct lpfc_iocbq *) arg;
605
James Smart2e0fef82007-06-17 19:56:36 -0500606 if (lpfc_rcv_plogi(vport, ndlp, cmdiocb)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -0500607 ndlp->nlp_prev_state = NLP_STE_UNUSED_NODE;
James Smart2e0fef82007-06-17 19:56:36 -0500608 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNUSED_NODE);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500609 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -0500610 }
James Smart2e0fef82007-06-17 19:56:36 -0500611 lpfc_drop_node(vport, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500612 return NLP_STE_FREED_NODE;
dea31012005-04-17 16:05:31 -0500613}
614
615static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -0500616lpfc_rcv_els_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
617 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -0500618{
James Smart2e0fef82007-06-17 19:56:36 -0500619 lpfc_issue_els_logo(vport, ndlp, 0);
620 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNUSED_NODE);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500621 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -0500622}
623
624static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -0500625lpfc_rcv_logo_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
626 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -0500627{
James Smart2e0fef82007-06-17 19:56:36 -0500628 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
629 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -0500630
James Smart2e0fef82007-06-17 19:56:36 -0500631 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500632 ndlp->nlp_flag |= NLP_LOGO_ACC;
James Smart2e0fef82007-06-17 19:56:36 -0500633 spin_unlock_irq(shost->host_lock);
James Smart51ef4c22007-08-02 11:10:31 -0400634 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
James Smart2e0fef82007-06-17 19:56:36 -0500635 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNUSED_NODE);
dea31012005-04-17 16:05:31 -0500636
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500637 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -0500638}
639
640static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -0500641lpfc_cmpl_logo_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -0500642 void *arg, uint32_t evt)
643{
James Smart2e0fef82007-06-17 19:56:36 -0500644 lpfc_drop_node(vport, ndlp);
645 return NLP_STE_FREED_NODE;
646}
647
648static uint32_t
649lpfc_device_rm_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
650 void *arg, uint32_t evt)
651{
652 lpfc_drop_node(vport, ndlp);
653 return NLP_STE_FREED_NODE;
654}
655
656static uint32_t
657lpfc_rcv_plogi_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
658 void *arg, uint32_t evt)
659{
660 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500661 struct lpfc_iocbq *cmdiocb = arg;
James Smart2e0fef82007-06-17 19:56:36 -0500662 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
663 uint32_t *lp = (uint32_t *) pcmd->virt;
664 struct serv_parm *sp = (struct serv_parm *) (lp + 1);
dea31012005-04-17 16:05:31 -0500665 struct ls_rjt stat;
666 int port_cmp;
667
dea31012005-04-17 16:05:31 -0500668 memset(&stat, 0, sizeof (struct ls_rjt));
669
670 /* For a PLOGI, we only accept if our portname is less
671 * than the remote portname.
672 */
673 phba->fc_stat.elsLogiCol++;
James Smart2e0fef82007-06-17 19:56:36 -0500674 port_cmp = memcmp(&vport->fc_portname, &sp->portName,
James Smart92d7f7b2007-06-17 19:56:38 -0500675 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -0500676
677 if (port_cmp >= 0) {
678 /* Reject this request because the remote node will accept
679 ours */
680 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
681 stat.un.b.lsRjtRsnCodeExp = LSEXP_CMD_IN_PROGRESS;
James Smart858c9f62007-06-17 19:56:39 -0500682 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
683 NULL);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500684 } else {
James Smart2e0fef82007-06-17 19:56:36 -0500685 lpfc_rcv_plogi(vport, ndlp, cmdiocb);
686 } /* If our portname was less */
dea31012005-04-17 16:05:31 -0500687
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500688 return ndlp->nlp_state;
689}
690
691static uint32_t
James Smart92d7f7b2007-06-17 19:56:38 -0500692lpfc_rcv_prli_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
693 void *arg, uint32_t evt)
694{
695 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
696 struct ls_rjt stat;
697
698 memset(&stat, 0, sizeof (struct ls_rjt));
699 stat.un.b.lsRjtRsnCode = LSRJT_LOGICAL_BSY;
700 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
James Smart858c9f62007-06-17 19:56:39 -0500701 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
James Smart92d7f7b2007-06-17 19:56:38 -0500702 return ndlp->nlp_state;
703}
704
705static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -0500706lpfc_rcv_logo_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
707 void *arg, uint32_t evt)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500708{
James Smart2e0fef82007-06-17 19:56:36 -0500709 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500710
James Smart92d7f7b2007-06-17 19:56:38 -0500711 /* software abort outstanding PLOGI */
James Smart2e0fef82007-06-17 19:56:36 -0500712 lpfc_els_abort(vport->phba, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500713
James Smart2e0fef82007-06-17 19:56:36 -0500714 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500715 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -0500716}
717
718static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -0500719lpfc_rcv_els_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
720 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -0500721{
James Smart2e0fef82007-06-17 19:56:36 -0500722 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
723 struct lpfc_hba *phba = vport->phba;
724 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -0500725
726 /* software abort outstanding PLOGI */
James Smart07951072007-04-25 09:51:38 -0400727 lpfc_els_abort(phba, ndlp);
dea31012005-04-17 16:05:31 -0500728
729 if (evt == NLP_EVT_RCV_LOGO) {
James Smart51ef4c22007-08-02 11:10:31 -0400730 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500731 } else {
James Smart2e0fef82007-06-17 19:56:36 -0500732 lpfc_issue_els_logo(vport, ndlp, 0);
dea31012005-04-17 16:05:31 -0500733 }
734
James Smart2e0fef82007-06-17 19:56:36 -0500735 /* Put ndlp in npr state set plogi timer for 1 sec */
Jamie Wellnitz5024ab12006-02-28 19:25:28 -0500736 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ * 1);
James Smart2e0fef82007-06-17 19:56:36 -0500737 spin_lock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -0500738 ndlp->nlp_flag |= NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -0500739 spin_unlock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -0500740 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
741 ndlp->nlp_prev_state = NLP_STE_PLOGI_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -0500742 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
dea31012005-04-17 16:05:31 -0500743
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500744 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -0500745}
746
747static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -0500748lpfc_cmpl_plogi_plogi_issue(struct lpfc_vport *vport,
749 struct lpfc_nodelist *ndlp,
750 void *arg,
dea31012005-04-17 16:05:31 -0500751 uint32_t evt)
752{
James Smart2e0fef82007-06-17 19:56:36 -0500753 struct lpfc_hba *phba = vport->phba;
754 struct lpfc_iocbq *cmdiocb, *rspiocb;
James Smart14691152006-12-02 13:34:28 -0500755 struct lpfc_dmabuf *pcmd, *prsp, *mp;
dea31012005-04-17 16:05:31 -0500756 uint32_t *lp;
757 IOCB_t *irsp;
758 struct serv_parm *sp;
759 LPFC_MBOXQ_t *mbox;
760
761 cmdiocb = (struct lpfc_iocbq *) arg;
762 rspiocb = cmdiocb->context_un.rsp_iocb;
763
764 if (ndlp->nlp_flag & NLP_ACC_REGLOGIN) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -0500765 /* Recovery from PLOGI collision logic */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500766 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -0500767 }
768
769 irsp = &rspiocb->iocb;
770
771 if (irsp->ulpStatus)
772 goto out;
773
774 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
775
James Smart2e0fef82007-06-17 19:56:36 -0500776 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
dea31012005-04-17 16:05:31 -0500777
James Smart2e0fef82007-06-17 19:56:36 -0500778 lp = (uint32_t *) prsp->virt;
dea31012005-04-17 16:05:31 -0500779 sp = (struct serv_parm *) ((uint8_t *) lp + sizeof (uint32_t));
James Smart2e0fef82007-06-17 19:56:36 -0500780 if (!lpfc_check_sparm(vport, ndlp, sp, CLASS3))
dea31012005-04-17 16:05:31 -0500781 goto out;
dea31012005-04-17 16:05:31 -0500782 /* PLOGI chkparm OK */
James Smarte8b62012007-08-02 11:10:09 -0400783 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
784 "0121 PLOGI chkparm OK Data: x%x x%x x%x x%x\n",
785 ndlp->nlp_DID, ndlp->nlp_state,
786 ndlp->nlp_flag, ndlp->nlp_rpi);
James Smart3de2a652007-08-02 11:09:59 -0400787 if (vport->cfg_fcp_class == 2 && (sp->cls2.classValid))
dea31012005-04-17 16:05:31 -0500788 ndlp->nlp_fcp_info |= CLASS2;
James Smart2e0fef82007-06-17 19:56:36 -0500789 else
dea31012005-04-17 16:05:31 -0500790 ndlp->nlp_fcp_info |= CLASS3;
James Smart2e0fef82007-06-17 19:56:36 -0500791
dea31012005-04-17 16:05:31 -0500792 ndlp->nlp_class_sup = 0;
793 if (sp->cls1.classValid)
794 ndlp->nlp_class_sup |= FC_COS_CLASS1;
795 if (sp->cls2.classValid)
796 ndlp->nlp_class_sup |= FC_COS_CLASS2;
797 if (sp->cls3.classValid)
798 ndlp->nlp_class_sup |= FC_COS_CLASS3;
799 if (sp->cls4.classValid)
800 ndlp->nlp_class_sup |= FC_COS_CLASS4;
801 ndlp->nlp_maxframe =
James Smart2e0fef82007-06-17 19:56:36 -0500802 ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) | sp->cmn.bbRcvSizeLsb;
dea31012005-04-17 16:05:31 -0500803
James Smart2e0fef82007-06-17 19:56:36 -0500804 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
James Smart92d7f7b2007-06-17 19:56:38 -0500805 if (!mbox) {
James Smarte8b62012007-08-02 11:10:09 -0400806 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
807 "0133 PLOGI: no memory for reg_login "
James Smart92d7f7b2007-06-17 19:56:38 -0500808 "Data: x%x x%x x%x x%x\n",
James Smart92d7f7b2007-06-17 19:56:38 -0500809 ndlp->nlp_DID, ndlp->nlp_state,
810 ndlp->nlp_flag, ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -0500811 goto out;
James Smart92d7f7b2007-06-17 19:56:38 -0500812 }
dea31012005-04-17 16:05:31 -0500813
James Smart2e0fef82007-06-17 19:56:36 -0500814 lpfc_unreg_rpi(vport, ndlp);
815
James Smart92d7f7b2007-06-17 19:56:38 -0500816 if (lpfc_reg_login(phba, vport->vpi, irsp->un.elsreq64.remoteID,
817 (uint8_t *) sp, mbox, 0) == 0) {
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500818 switch (ndlp->nlp_DID) {
dea31012005-04-17 16:05:31 -0500819 case NameServer_DID:
James Smartde0c5b32007-04-25 09:52:27 -0400820 mbox->mbox_cmpl = lpfc_mbx_cmpl_ns_reg_login;
dea31012005-04-17 16:05:31 -0500821 break;
822 case FDMI_DID:
James Smartde0c5b32007-04-25 09:52:27 -0400823 mbox->mbox_cmpl = lpfc_mbx_cmpl_fdmi_reg_login;
dea31012005-04-17 16:05:31 -0500824 break;
825 default:
James Smartde0c5b32007-04-25 09:52:27 -0400826 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
dea31012005-04-17 16:05:31 -0500827 }
James Smart329f9bc2007-04-25 09:53:01 -0400828 mbox->context2 = lpfc_nlp_get(ndlp);
James Smart2e0fef82007-06-17 19:56:36 -0500829 mbox->vport = vport;
James Smart0b727fe2007-10-27 13:37:25 -0400830 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
dea31012005-04-17 16:05:31 -0500831 != MBX_NOT_FINISHED) {
James Smart2e0fef82007-06-17 19:56:36 -0500832 lpfc_nlp_set_state(vport, ndlp,
833 NLP_STE_REG_LOGIN_ISSUE);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500834 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -0500835 }
James Smart329f9bc2007-04-25 09:53:01 -0400836 lpfc_nlp_put(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -0500837 mp = (struct lpfc_dmabuf *) mbox->context1;
James Smart14691152006-12-02 13:34:28 -0500838 lpfc_mbuf_free(phba, mp->virt, mp->phys);
839 kfree(mp);
dea31012005-04-17 16:05:31 -0500840 mempool_free(mbox, phba->mbox_mem_pool);
James Smart92d7f7b2007-06-17 19:56:38 -0500841
James Smarte8b62012007-08-02 11:10:09 -0400842 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
843 "0134 PLOGI: cannot issue reg_login "
844 "Data: x%x x%x x%x x%x\n",
845 ndlp->nlp_DID, ndlp->nlp_state,
846 ndlp->nlp_flag, ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -0500847 } else {
848 mempool_free(mbox, phba->mbox_mem_pool);
James Smart92d7f7b2007-06-17 19:56:38 -0500849
James Smarte8b62012007-08-02 11:10:09 -0400850 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
851 "0135 PLOGI: cannot format reg_login "
852 "Data: x%x x%x x%x x%x\n",
853 ndlp->nlp_DID, ndlp->nlp_state,
854 ndlp->nlp_flag, ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -0500855 }
856
857
James Smart92d7f7b2007-06-17 19:56:38 -0500858out:
859 if (ndlp->nlp_DID == NameServer_DID) {
860 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -0400861 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
862 "0261 Cannot Register NameServer login\n");
James Smart92d7f7b2007-06-17 19:56:38 -0500863 }
864
dea31012005-04-17 16:05:31 -0500865 /* Free this node since the driver cannot login or has the wrong
866 sparm */
James Smart2e0fef82007-06-17 19:56:36 -0500867 lpfc_drop_node(vport, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500868 return NLP_STE_FREED_NODE;
dea31012005-04-17 16:05:31 -0500869}
870
871static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -0500872lpfc_device_rm_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
873 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -0500874{
James Smart2e0fef82007-06-17 19:56:36 -0500875 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -0500876
James Smart2e0fef82007-06-17 19:56:36 -0500877 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
878 spin_lock_irq(shost->host_lock);
879 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
880 spin_unlock_irq(shost->host_lock);
881 return ndlp->nlp_state;
882 } else {
883 /* software abort outstanding PLOGI */
884 lpfc_els_abort(vport->phba, ndlp);
885
886 lpfc_drop_node(vport, ndlp);
James Smarta0f9b482006-04-15 11:52:56 -0400887 return NLP_STE_FREED_NODE;
888 }
dea31012005-04-17 16:05:31 -0500889}
890
891static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -0500892lpfc_device_recov_plogi_issue(struct lpfc_vport *vport,
893 struct lpfc_nodelist *ndlp,
894 void *arg,
895 uint32_t evt)
dea31012005-04-17 16:05:31 -0500896{
James Smart2e0fef82007-06-17 19:56:36 -0500897 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
898 struct lpfc_hba *phba = vport->phba;
899
James Smart92d7f7b2007-06-17 19:56:38 -0500900 /* Don't do anything that will mess up processing of the
901 * previous RSCN.
902 */
903 if (vport->fc_flag & FC_RSCN_DEFERRED)
904 return ndlp->nlp_state;
905
dea31012005-04-17 16:05:31 -0500906 /* software abort outstanding PLOGI */
James Smart07951072007-04-25 09:51:38 -0400907 lpfc_els_abort(phba, ndlp);
dea31012005-04-17 16:05:31 -0500908
Jamie Wellnitz5024ab12006-02-28 19:25:28 -0500909 ndlp->nlp_prev_state = NLP_STE_PLOGI_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -0500910 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
James Smart92d7f7b2007-06-17 19:56:38 -0500911 spin_lock_irq(shost->host_lock);
James Smarta0f9b482006-04-15 11:52:56 -0400912 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
James Smart2e0fef82007-06-17 19:56:36 -0500913 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500914
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500915 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -0500916}
917
918static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -0500919lpfc_rcv_plogi_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
920 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -0500921{
James Smart2e0fef82007-06-17 19:56:36 -0500922 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500923 struct lpfc_iocbq *cmdiocb;
924
925 /* software abort outstanding ADISC */
James Smart07951072007-04-25 09:51:38 -0400926 lpfc_els_abort(phba, ndlp);
dea31012005-04-17 16:05:31 -0500927
928 cmdiocb = (struct lpfc_iocbq *) arg;
929
James Smart2e0fef82007-06-17 19:56:36 -0500930 if (lpfc_rcv_plogi(vport, ndlp, cmdiocb))
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500931 return ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -0500932
Jamie Wellnitz5024ab12006-02-28 19:25:28 -0500933 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -0500934 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
935 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
dea31012005-04-17 16:05:31 -0500936
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500937 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -0500938}
939
940static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -0500941lpfc_rcv_prli_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
942 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -0500943{
James Smart2e0fef82007-06-17 19:56:36 -0500944 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -0500945
James Smart2e0fef82007-06-17 19:56:36 -0500946 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500947 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -0500948}
949
950static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -0500951lpfc_rcv_logo_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
952 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -0500953{
James Smart2e0fef82007-06-17 19:56:36 -0500954 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500955 struct lpfc_iocbq *cmdiocb;
956
957 cmdiocb = (struct lpfc_iocbq *) arg;
958
959 /* software abort outstanding ADISC */
James Smart07951072007-04-25 09:51:38 -0400960 lpfc_els_abort(phba, ndlp);
dea31012005-04-17 16:05:31 -0500961
James Smart2e0fef82007-06-17 19:56:36 -0500962 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500963 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -0500964}
965
966static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -0500967lpfc_rcv_padisc_adisc_issue(struct lpfc_vport *vport,
968 struct lpfc_nodelist *ndlp,
969 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -0500970{
971 struct lpfc_iocbq *cmdiocb;
972
973 cmdiocb = (struct lpfc_iocbq *) arg;
974
James Smart2e0fef82007-06-17 19:56:36 -0500975 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500976 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -0500977}
978
979static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -0500980lpfc_rcv_prlo_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
981 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -0500982{
983 struct lpfc_iocbq *cmdiocb;
984
985 cmdiocb = (struct lpfc_iocbq *) arg;
986
987 /* Treat like rcv logo */
James Smart2e0fef82007-06-17 19:56:36 -0500988 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_PRLO);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500989 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -0500990}
991
992static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -0500993lpfc_cmpl_adisc_adisc_issue(struct lpfc_vport *vport,
994 struct lpfc_nodelist *ndlp,
995 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -0500996{
James Smart2e0fef82007-06-17 19:56:36 -0500997 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
998 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500999 struct lpfc_iocbq *cmdiocb, *rspiocb;
1000 IOCB_t *irsp;
1001 ADISC *ap;
1002
1003 cmdiocb = (struct lpfc_iocbq *) arg;
1004 rspiocb = cmdiocb->context_un.rsp_iocb;
1005
1006 ap = (ADISC *)lpfc_check_elscmpl_iocb(phba, cmdiocb, rspiocb);
1007 irsp = &rspiocb->iocb;
1008
1009 if ((irsp->ulpStatus) ||
James Smart92d7f7b2007-06-17 19:56:38 -05001010 (!lpfc_check_adisc(vport, ndlp, &ap->nodeName, &ap->portName))) {
dea31012005-04-17 16:05:31 -05001011 /* 1 sec timeout */
1012 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ);
James Smart2e0fef82007-06-17 19:56:36 -05001013 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001014 ndlp->nlp_flag |= NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05001015 spin_unlock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001016 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
dea31012005-04-17 16:05:31 -05001017
James Smart2e0fef82007-06-17 19:56:36 -05001018 memset(&ndlp->nlp_nodename, 0, sizeof(struct lpfc_name));
1019 memset(&ndlp->nlp_portname, 0, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05001020
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001021 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -05001022 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1023 lpfc_unreg_rpi(vport, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001024 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001025 }
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001026
James.Smart@Emulex.Com25013222005-06-25 10:34:33 -04001027 if (ndlp->nlp_type & NLP_FCP_TARGET) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001028 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -05001029 lpfc_nlp_set_state(vport, ndlp, NLP_STE_MAPPED_NODE);
James.Smart@Emulex.Com25013222005-06-25 10:34:33 -04001030 } else {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001031 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -05001032 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
James.Smart@Emulex.Com25013222005-06-25 10:34:33 -04001033 }
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_device_rm_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1039 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001040{
James Smart2e0fef82007-06-17 19:56:36 -05001041 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001042
James Smart2e0fef82007-06-17 19:56:36 -05001043 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1044 spin_lock_irq(shost->host_lock);
1045 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
1046 spin_unlock_irq(shost->host_lock);
1047 return ndlp->nlp_state;
1048 } else {
1049 /* software abort outstanding ADISC */
1050 lpfc_els_abort(vport->phba, ndlp);
1051
1052 lpfc_drop_node(vport, ndlp);
James Smarta0f9b482006-04-15 11:52:56 -04001053 return NLP_STE_FREED_NODE;
1054 }
dea31012005-04-17 16:05:31 -05001055}
1056
1057static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001058lpfc_device_recov_adisc_issue(struct lpfc_vport *vport,
1059 struct lpfc_nodelist *ndlp,
1060 void *arg,
1061 uint32_t evt)
dea31012005-04-17 16:05:31 -05001062{
James Smart2e0fef82007-06-17 19:56:36 -05001063 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1064 struct lpfc_hba *phba = vport->phba;
1065
James Smart92d7f7b2007-06-17 19:56:38 -05001066 /* Don't do anything that will mess up processing of the
1067 * previous RSCN.
1068 */
1069 if (vport->fc_flag & FC_RSCN_DEFERRED)
1070 return ndlp->nlp_state;
1071
dea31012005-04-17 16:05:31 -05001072 /* software abort outstanding ADISC */
James Smart07951072007-04-25 09:51:38 -04001073 lpfc_els_abort(phba, ndlp);
dea31012005-04-17 16:05:31 -05001074
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001075 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -05001076 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1077 spin_lock_irq(shost->host_lock);
James Smarta0f9b482006-04-15 11:52:56 -04001078 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
James Smart2e0fef82007-06-17 19:56:36 -05001079 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05001080 lpfc_disc_set_adisc(vport, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001081 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001082}
1083
1084static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001085lpfc_rcv_plogi_reglogin_issue(struct lpfc_vport *vport,
1086 struct lpfc_nodelist *ndlp,
1087 void *arg,
dea31012005-04-17 16:05:31 -05001088 uint32_t evt)
1089{
James Smart2e0fef82007-06-17 19:56:36 -05001090 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001091
James Smart2e0fef82007-06-17 19:56:36 -05001092 lpfc_rcv_plogi(vport, ndlp, cmdiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001093 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001094}
1095
1096static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001097lpfc_rcv_prli_reglogin_issue(struct lpfc_vport *vport,
1098 struct lpfc_nodelist *ndlp,
1099 void *arg,
dea31012005-04-17 16:05:31 -05001100 uint32_t evt)
1101{
James Smart2e0fef82007-06-17 19:56:36 -05001102 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001103
James Smart2e0fef82007-06-17 19:56:36 -05001104 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
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_rcv_logo_reglogin_issue(struct lpfc_vport *vport,
1110 struct lpfc_nodelist *ndlp,
1111 void *arg,
dea31012005-04-17 16:05:31 -05001112 uint32_t evt)
1113{
James Smart2e0fef82007-06-17 19:56:36 -05001114 struct lpfc_hba *phba = vport->phba;
1115 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
James Smart7054a602007-04-25 09:52:34 -04001116 LPFC_MBOXQ_t *mb;
1117 LPFC_MBOXQ_t *nextmb;
1118 struct lpfc_dmabuf *mp;
dea31012005-04-17 16:05:31 -05001119
1120 cmdiocb = (struct lpfc_iocbq *) arg;
1121
James Smart7054a602007-04-25 09:52:34 -04001122 /* cleanup any ndlp on mbox q waiting for reglogin cmpl */
1123 if ((mb = phba->sli.mbox_active)) {
1124 if ((mb->mb.mbxCommand == MBX_REG_LOGIN64) &&
1125 (ndlp == (struct lpfc_nodelist *) mb->context2)) {
James Smart92d7f7b2007-06-17 19:56:38 -05001126 lpfc_nlp_put(ndlp);
James Smart7054a602007-04-25 09:52:34 -04001127 mb->context2 = NULL;
1128 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1129 }
1130 }
1131
James Smart2e0fef82007-06-17 19:56:36 -05001132 spin_lock_irq(&phba->hbalock);
James Smart7054a602007-04-25 09:52:34 -04001133 list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) {
1134 if ((mb->mb.mbxCommand == MBX_REG_LOGIN64) &&
1135 (ndlp == (struct lpfc_nodelist *) mb->context2)) {
1136 mp = (struct lpfc_dmabuf *) (mb->context1);
1137 if (mp) {
James Smart98c9ea52007-10-27 13:37:33 -04001138 __lpfc_mbuf_free(phba, mp->virt, mp->phys);
James Smart7054a602007-04-25 09:52:34 -04001139 kfree(mp);
1140 }
James Smart92d7f7b2007-06-17 19:56:38 -05001141 lpfc_nlp_put(ndlp);
James Smart7054a602007-04-25 09:52:34 -04001142 list_del(&mb->list);
1143 mempool_free(mb, phba->mbox_mem_pool);
1144 }
1145 }
James Smart2e0fef82007-06-17 19:56:36 -05001146 spin_unlock_irq(&phba->hbalock);
James Smart7054a602007-04-25 09:52:34 -04001147
James Smart2e0fef82007-06-17 19:56:36 -05001148 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001149 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001150}
1151
1152static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001153lpfc_rcv_padisc_reglogin_issue(struct lpfc_vport *vport,
1154 struct lpfc_nodelist *ndlp,
1155 void *arg,
dea31012005-04-17 16:05:31 -05001156 uint32_t evt)
1157{
James Smart2e0fef82007-06-17 19:56:36 -05001158 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001159
James Smart2e0fef82007-06-17 19:56:36 -05001160 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001161 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001162}
1163
1164static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001165lpfc_rcv_prlo_reglogin_issue(struct lpfc_vport *vport,
1166 struct lpfc_nodelist *ndlp,
1167 void *arg,
dea31012005-04-17 16:05:31 -05001168 uint32_t evt)
1169{
1170 struct lpfc_iocbq *cmdiocb;
1171
1172 cmdiocb = (struct lpfc_iocbq *) arg;
James Smart51ef4c22007-08-02 11:10:31 -04001173 lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001174 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001175}
1176
1177static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001178lpfc_cmpl_reglogin_reglogin_issue(struct lpfc_vport *vport,
1179 struct lpfc_nodelist *ndlp,
1180 void *arg,
1181 uint32_t evt)
dea31012005-04-17 16:05:31 -05001182{
James Smart2e0fef82007-06-17 19:56:36 -05001183 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart2e0fef82007-06-17 19:56:36 -05001184 LPFC_MBOXQ_t *pmb = (LPFC_MBOXQ_t *) arg;
1185 MAILBOX_t *mb = &pmb->mb;
1186 uint32_t did = mb->un.varWords[1];
dea31012005-04-17 16:05:31 -05001187
dea31012005-04-17 16:05:31 -05001188 if (mb->mbxStatus) {
1189 /* RegLogin failed */
James Smarte8b62012007-08-02 11:10:09 -04001190 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
1191 "0246 RegLogin failed Data: x%x x%x x%x\n",
James Smart2e0fef82007-06-17 19:56:36 -05001192 did, mb->mbxStatus, vport->port_state);
James Smartd0e56da2006-07-06 15:49:42 -04001193 /*
1194 * If RegLogin failed due to lack of HBA resources do not
1195 * retry discovery.
1196 */
1197 if (mb->mbxStatus == MBXERR_RPI_FULL) {
1198 ndlp->nlp_prev_state = NLP_STE_UNUSED_NODE;
James Smart2e0fef82007-06-17 19:56:36 -05001199 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNUSED_NODE);
James Smartd0e56da2006-07-06 15:49:42 -04001200 return ndlp->nlp_state;
1201 }
1202
James Smart2e0fef82007-06-17 19:56:36 -05001203 /* Put ndlp in npr state set plogi timer for 1 sec */
dea31012005-04-17 16:05:31 -05001204 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ * 1);
James Smart2e0fef82007-06-17 19:56:36 -05001205 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001206 ndlp->nlp_flag |= NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05001207 spin_unlock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001208 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
dea31012005-04-17 16:05:31 -05001209
James Smart2e0fef82007-06-17 19:56:36 -05001210 lpfc_issue_els_logo(vport, ndlp, 0);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001211 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -05001212 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001213 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001214 }
1215
dea31012005-04-17 16:05:31 -05001216 ndlp->nlp_rpi = mb->un.varWords[0];
dea31012005-04-17 16:05:31 -05001217
1218 /* Only if we are not a fabric nport do we issue PRLI */
1219 if (!(ndlp->nlp_type & NLP_FABRIC)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001220 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -05001221 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
1222 lpfc_issue_els_prli(vport, ndlp, 0);
dea31012005-04-17 16:05:31 -05001223 } else {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001224 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -05001225 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
dea31012005-04-17 16:05:31 -05001226 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001227 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001228}
1229
1230static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001231lpfc_device_rm_reglogin_issue(struct lpfc_vport *vport,
1232 struct lpfc_nodelist *ndlp,
1233 void *arg,
dea31012005-04-17 16:05:31 -05001234 uint32_t evt)
1235{
James Smart2e0fef82007-06-17 19:56:36 -05001236 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1237
1238 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1239 spin_lock_irq(shost->host_lock);
James Smarta0f9b482006-04-15 11:52:56 -04001240 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
James Smart2e0fef82007-06-17 19:56:36 -05001241 spin_unlock_irq(shost->host_lock);
James Smarta0f9b482006-04-15 11:52:56 -04001242 return ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05001243 } else {
1244 lpfc_drop_node(vport, ndlp);
James Smarta0f9b482006-04-15 11:52:56 -04001245 return NLP_STE_FREED_NODE;
1246 }
dea31012005-04-17 16:05:31 -05001247}
1248
1249static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001250lpfc_device_recov_reglogin_issue(struct lpfc_vport *vport,
1251 struct lpfc_nodelist *ndlp,
1252 void *arg,
1253 uint32_t evt)
dea31012005-04-17 16:05:31 -05001254{
James Smart2e0fef82007-06-17 19:56:36 -05001255 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1256
James Smart92d7f7b2007-06-17 19:56:38 -05001257 /* Don't do anything that will mess up processing of the
1258 * previous RSCN.
1259 */
1260 if (vport->fc_flag & FC_RSCN_DEFERRED)
1261 return ndlp->nlp_state;
1262
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001263 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -05001264 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1265 spin_lock_irq(shost->host_lock);
James Smarta0f9b482006-04-15 11:52:56 -04001266 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
James Smart2e0fef82007-06-17 19:56:36 -05001267 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05001268 lpfc_disc_set_adisc(vport, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001269 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001270}
1271
1272static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001273lpfc_rcv_plogi_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1274 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001275{
1276 struct lpfc_iocbq *cmdiocb;
1277
1278 cmdiocb = (struct lpfc_iocbq *) arg;
1279
James Smart2e0fef82007-06-17 19:56:36 -05001280 lpfc_rcv_plogi(vport, ndlp, cmdiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001281 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001282}
1283
1284static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001285lpfc_rcv_prli_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1286 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001287{
James Smart2e0fef82007-06-17 19:56:36 -05001288 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001289
James Smart2e0fef82007-06-17 19:56:36 -05001290 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001291 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001292}
1293
1294static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001295lpfc_rcv_logo_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1296 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001297{
James Smart2e0fef82007-06-17 19:56:36 -05001298 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001299
1300 /* Software abort outstanding PRLI before sending acc */
James Smart2e0fef82007-06-17 19:56:36 -05001301 lpfc_els_abort(vport->phba, ndlp);
dea31012005-04-17 16:05:31 -05001302
James Smart2e0fef82007-06-17 19:56:36 -05001303 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001304 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001305}
1306
1307static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001308lpfc_rcv_padisc_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1309 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001310{
James Smart2e0fef82007-06-17 19:56:36 -05001311 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001312
James Smart2e0fef82007-06-17 19:56:36 -05001313 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001314 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001315}
1316
1317/* This routine is envoked when we rcv a PRLO request from a nport
1318 * we are logged into. We should send back a PRLO rsp setting the
1319 * appropriate bits.
1320 * NEXT STATE = PRLI_ISSUE
1321 */
1322static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001323lpfc_rcv_prlo_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1324 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001325{
James Smart2e0fef82007-06-17 19:56:36 -05001326 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001327
James Smart51ef4c22007-08-02 11:10:31 -04001328 lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001329 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001330}
1331
1332static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001333lpfc_cmpl_prli_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1334 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001335{
James Smart92d7f7b2007-06-17 19:56:38 -05001336 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001337 struct lpfc_iocbq *cmdiocb, *rspiocb;
James Smart2e0fef82007-06-17 19:56:36 -05001338 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001339 IOCB_t *irsp;
1340 PRLI *npr;
1341
1342 cmdiocb = (struct lpfc_iocbq *) arg;
1343 rspiocb = cmdiocb->context_un.rsp_iocb;
1344 npr = (PRLI *)lpfc_check_elscmpl_iocb(phba, cmdiocb, rspiocb);
1345
1346 irsp = &rspiocb->iocb;
1347 if (irsp->ulpStatus) {
James Smart858c9f62007-06-17 19:56:39 -05001348 if ((vport->port_type == LPFC_NPIV_PORT) &&
James Smart3de2a652007-08-02 11:09:59 -04001349 vport->cfg_restrict_login) {
James Smart858c9f62007-06-17 19:56:39 -05001350 goto out;
1351 }
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001352 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -05001353 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001354 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001355 }
1356
1357 /* Check out PRLI rsp */
1358 ndlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR);
1359 ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
1360 if ((npr->acceptRspCode == PRLI_REQ_EXECUTED) &&
1361 (npr->prliType == PRLI_FCP_TYPE)) {
1362 if (npr->initiatorFunc)
1363 ndlp->nlp_type |= NLP_FCP_INITIATOR;
1364 if (npr->targetFunc)
1365 ndlp->nlp_type |= NLP_FCP_TARGET;
1366 if (npr->Retry)
1367 ndlp->nlp_fcp_info |= NLP_FCP_2_DEVICE;
1368 }
James Smart92d7f7b2007-06-17 19:56:38 -05001369 if (!(ndlp->nlp_type & NLP_FCP_TARGET) &&
1370 (vport->port_type == LPFC_NPIV_PORT) &&
James Smart3de2a652007-08-02 11:09:59 -04001371 vport->cfg_restrict_login) {
James Smart858c9f62007-06-17 19:56:39 -05001372out:
James Smart92d7f7b2007-06-17 19:56:38 -05001373 spin_lock_irq(shost->host_lock);
1374 ndlp->nlp_flag |= NLP_TARGET_REMOVE;
1375 spin_unlock_irq(shost->host_lock);
1376 lpfc_issue_els_logo(vport, ndlp, 0);
1377
1378 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
1379 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNUSED_NODE);
1380 return ndlp->nlp_state;
1381 }
dea31012005-04-17 16:05:31 -05001382
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001383 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
James Smart92d7f7b2007-06-17 19:56:38 -05001384 if (ndlp->nlp_type & NLP_FCP_TARGET)
1385 lpfc_nlp_set_state(vport, ndlp, NLP_STE_MAPPED_NODE);
1386 else
1387 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001388 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001389}
1390
1391/*! lpfc_device_rm_prli_issue
James Smart92d7f7b2007-06-17 19:56:38 -05001392 *
1393 * \pre
1394 * \post
1395 * \param phba
1396 * \param ndlp
1397 * \param arg
1398 * \param evt
1399 * \return uint32_t
1400 *
1401 * \b Description:
1402 * This routine is envoked when we a request to remove a nport we are in the
1403 * process of PRLIing. We should software abort outstanding prli, unreg
1404 * login, send a logout. We will change node state to UNUSED_NODE, put it
1405 * on plogi list so it can be freed when LOGO completes.
1406 *
1407 */
1408
dea31012005-04-17 16:05:31 -05001409static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001410lpfc_device_rm_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1411 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001412{
James Smart2e0fef82007-06-17 19:56:36 -05001413 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001414
James Smart2e0fef82007-06-17 19:56:36 -05001415 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1416 spin_lock_irq(shost->host_lock);
1417 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
1418 spin_unlock_irq(shost->host_lock);
1419 return ndlp->nlp_state;
1420 } else {
1421 /* software abort outstanding PLOGI */
1422 lpfc_els_abort(vport->phba, ndlp);
1423
1424 lpfc_drop_node(vport, ndlp);
James Smarta0f9b482006-04-15 11:52:56 -04001425 return NLP_STE_FREED_NODE;
1426 }
dea31012005-04-17 16:05:31 -05001427}
1428
1429
1430/*! lpfc_device_recov_prli_issue
James Smart92d7f7b2007-06-17 19:56:38 -05001431 *
1432 * \pre
1433 * \post
1434 * \param phba
1435 * \param ndlp
1436 * \param arg
1437 * \param evt
1438 * \return uint32_t
1439 *
1440 * \b Description:
1441 * The routine is envoked when the state of a device is unknown, like
1442 * during a link down. We should remove the nodelist entry from the
1443 * unmapped list, issue a UNREG_LOGIN, do a software abort of the
1444 * outstanding PRLI command, then free the node entry.
1445 */
dea31012005-04-17 16:05:31 -05001446static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001447lpfc_device_recov_prli_issue(struct lpfc_vport *vport,
1448 struct lpfc_nodelist *ndlp,
1449 void *arg,
1450 uint32_t evt)
dea31012005-04-17 16:05:31 -05001451{
James Smart2e0fef82007-06-17 19:56:36 -05001452 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1453 struct lpfc_hba *phba = vport->phba;
1454
James Smart92d7f7b2007-06-17 19:56:38 -05001455 /* Don't do anything that will mess up processing of the
1456 * previous RSCN.
1457 */
1458 if (vport->fc_flag & FC_RSCN_DEFERRED)
1459 return ndlp->nlp_state;
1460
dea31012005-04-17 16:05:31 -05001461 /* software abort outstanding PRLI */
James Smart07951072007-04-25 09:51:38 -04001462 lpfc_els_abort(phba, ndlp);
dea31012005-04-17 16:05:31 -05001463
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001464 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -05001465 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1466 spin_lock_irq(shost->host_lock);
James Smarta0f9b482006-04-15 11:52:56 -04001467 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
James Smart2e0fef82007-06-17 19:56:36 -05001468 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05001469 lpfc_disc_set_adisc(vport, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001470 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001471}
1472
1473static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001474lpfc_rcv_plogi_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1475 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001476{
James Smart2e0fef82007-06-17 19:56:36 -05001477 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001478
James Smart2e0fef82007-06-17 19:56:36 -05001479 lpfc_rcv_plogi(vport, ndlp, cmdiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001480 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001481}
1482
1483static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001484lpfc_rcv_prli_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1485 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001486{
James Smart2e0fef82007-06-17 19:56:36 -05001487 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001488
James Smart2e0fef82007-06-17 19:56:36 -05001489 lpfc_rcv_prli(vport, ndlp, cmdiocb);
1490 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001491 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001492}
1493
1494static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001495lpfc_rcv_logo_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1496 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001497{
James Smart2e0fef82007-06-17 19:56:36 -05001498 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001499
James Smart2e0fef82007-06-17 19:56:36 -05001500 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001501 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001502}
1503
1504static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001505lpfc_rcv_padisc_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1506 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001507{
James Smart2e0fef82007-06-17 19:56:36 -05001508 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001509
James Smart2e0fef82007-06-17 19:56:36 -05001510 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001511 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001512}
1513
1514static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001515lpfc_rcv_prlo_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1516 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001517{
James Smart2e0fef82007-06-17 19:56:36 -05001518 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001519
James Smart51ef4c22007-08-02 11:10:31 -04001520 lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001521 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001522}
1523
1524static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001525lpfc_device_recov_unmap_node(struct lpfc_vport *vport,
1526 struct lpfc_nodelist *ndlp,
1527 void *arg,
1528 uint32_t evt)
dea31012005-04-17 16:05:31 -05001529{
James Smart2e0fef82007-06-17 19:56:36 -05001530 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1531
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001532 ndlp->nlp_prev_state = NLP_STE_UNMAPPED_NODE;
James Smart2e0fef82007-06-17 19:56:36 -05001533 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1534 spin_lock_irq(shost->host_lock);
James Smarta0f9b482006-04-15 11:52:56 -04001535 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
James Smart2e0fef82007-06-17 19:56:36 -05001536 spin_unlock_irq(shost->host_lock);
1537 lpfc_disc_set_adisc(vport, ndlp);
dea31012005-04-17 16:05:31 -05001538
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001539 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001540}
1541
1542static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001543lpfc_rcv_plogi_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1544 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001545{
James Smart2e0fef82007-06-17 19:56:36 -05001546 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001547
James Smart2e0fef82007-06-17 19:56:36 -05001548 lpfc_rcv_plogi(vport, ndlp, cmdiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001549 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001550}
1551
1552static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001553lpfc_rcv_prli_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1554 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001555{
James Smart2e0fef82007-06-17 19:56:36 -05001556 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001557
James Smart2e0fef82007-06-17 19:56:36 -05001558 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001559 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001560}
1561
1562static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001563lpfc_rcv_logo_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1564 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001565{
James Smart2e0fef82007-06-17 19:56:36 -05001566 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001567
James Smart2e0fef82007-06-17 19:56:36 -05001568 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001569 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001570}
1571
1572static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001573lpfc_rcv_padisc_mapped_node(struct lpfc_vport *vport,
1574 struct lpfc_nodelist *ndlp,
1575 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001576{
James Smart2e0fef82007-06-17 19:56:36 -05001577 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001578
James Smart2e0fef82007-06-17 19:56:36 -05001579 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001580 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001581}
1582
1583static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001584lpfc_rcv_prlo_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1585 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001586{
James Smart2e0fef82007-06-17 19:56:36 -05001587 struct lpfc_hba *phba = vport->phba;
1588 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001589
1590 /* flush the target */
James Smart51ef4c22007-08-02 11:10:31 -04001591 lpfc_sli_abort_iocb(vport, &phba->sli.ring[phba->sli.fcp_ring],
1592 ndlp->nlp_sid, 0, LPFC_CTX_TGT);
dea31012005-04-17 16:05:31 -05001593
1594 /* Treat like rcv logo */
James Smart2e0fef82007-06-17 19:56:36 -05001595 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_PRLO);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001596 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001597}
1598
1599static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001600lpfc_device_recov_mapped_node(struct lpfc_vport *vport,
1601 struct lpfc_nodelist *ndlp,
1602 void *arg,
1603 uint32_t evt)
dea31012005-04-17 16:05:31 -05001604{
James Smart2e0fef82007-06-17 19:56:36 -05001605 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1606
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001607 ndlp->nlp_prev_state = NLP_STE_MAPPED_NODE;
James Smart2e0fef82007-06-17 19:56:36 -05001608 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1609 spin_lock_irq(shost->host_lock);
James Smarta0f9b482006-04-15 11:52:56 -04001610 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
James Smart2e0fef82007-06-17 19:56:36 -05001611 spin_unlock_irq(shost->host_lock);
1612 lpfc_disc_set_adisc(vport, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001613 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001614}
1615
1616static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001617lpfc_rcv_plogi_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1618 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001619{
James Smart2e0fef82007-06-17 19:56:36 -05001620 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1621 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001622
1623 /* Ignore PLOGI if we have an outstanding LOGO */
James Smart858c9f62007-06-17 19:56:39 -05001624 if (ndlp->nlp_flag & (NLP_LOGO_SND | NLP_LOGO_ACC)) {
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001625 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001626 }
1627
James Smart2e0fef82007-06-17 19:56:36 -05001628 if (lpfc_rcv_plogi(vport, ndlp, cmdiocb)) {
1629 spin_lock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05001630 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
James Smart2e0fef82007-06-17 19:56:36 -05001631 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001632 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001633 }
1634
1635 /* send PLOGI immediately, move to PLOGI issue state */
1636 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
James Smart488d1462006-03-07 15:02:37 -05001637 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
James Smart2e0fef82007-06-17 19:56:36 -05001638 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
1639 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
dea31012005-04-17 16:05:31 -05001640 }
James Smart488d1462006-03-07 15:02:37 -05001641
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001642 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001643}
1644
1645static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001646lpfc_rcv_prli_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1647 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001648{
James Smart2e0fef82007-06-17 19:56:36 -05001649 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1650 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1651 struct ls_rjt stat;
dea31012005-04-17 16:05:31 -05001652
1653 memset(&stat, 0, sizeof (struct ls_rjt));
1654 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
1655 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
James Smart858c9f62007-06-17 19:56:39 -05001656 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05001657
1658 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
1659 if (ndlp->nlp_flag & NLP_NPR_ADISC) {
James Smart2e0fef82007-06-17 19:56:36 -05001660 spin_lock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001661 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001662 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
James Smart2e0fef82007-06-17 19:56:36 -05001663 spin_unlock_irq(shost->host_lock);
1664 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
1665 lpfc_issue_els_adisc(vport, ndlp, 0);
dea31012005-04-17 16:05:31 -05001666 } else {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001667 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
James Smart2e0fef82007-06-17 19:56:36 -05001668 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
1669 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
dea31012005-04-17 16:05:31 -05001670 }
1671 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001672 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001673}
1674
1675static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001676lpfc_rcv_logo_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1677 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001678{
James Smart2e0fef82007-06-17 19:56:36 -05001679 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001680
James Smart2e0fef82007-06-17 19:56:36 -05001681 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001682 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001683}
1684
1685static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001686lpfc_rcv_padisc_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1687 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001688{
James Smart2e0fef82007-06-17 19:56:36 -05001689 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001690
James Smart2e0fef82007-06-17 19:56:36 -05001691 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
dea31012005-04-17 16:05:31 -05001692
James Smart33ccf8d2006-08-17 11:57:58 -04001693 /*
1694 * Do not start discovery if discovery is about to start
1695 * or discovery in progress for this node. Starting discovery
1696 * here will affect the counting of discovery threads.
1697 */
James Smart2fb9bd82006-12-02 13:33:57 -05001698 if (!(ndlp->nlp_flag & NLP_DELAY_TMO) &&
James Smart92d7f7b2007-06-17 19:56:38 -05001699 !(ndlp->nlp_flag & NLP_NPR_2B_DISC)) {
dea31012005-04-17 16:05:31 -05001700 if (ndlp->nlp_flag & NLP_NPR_ADISC) {
James Smart92d7f7b2007-06-17 19:56:38 -05001701 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001702 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
James Smart2e0fef82007-06-17 19:56:36 -05001703 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
1704 lpfc_issue_els_adisc(vport, ndlp, 0);
dea31012005-04-17 16:05:31 -05001705 } else {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001706 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
James Smart2e0fef82007-06-17 19:56:36 -05001707 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
1708 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
dea31012005-04-17 16:05:31 -05001709 }
1710 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001711 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001712}
1713
1714static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001715lpfc_rcv_prlo_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1716 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001717{
James Smart2e0fef82007-06-17 19:56:36 -05001718 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1719 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001720
James Smart2e0fef82007-06-17 19:56:36 -05001721 spin_lock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001722 ndlp->nlp_flag |= NLP_LOGO_ACC;
James Smart2e0fef82007-06-17 19:56:36 -05001723 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001724
James Smart51ef4c22007-08-02 11:10:31 -04001725 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05001726
James Smart2e0fef82007-06-17 19:56:36 -05001727 if ((ndlp->nlp_flag & NLP_DELAY_TMO) == 0) {
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001728 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ * 1);
James Smart2e0fef82007-06-17 19:56:36 -05001729 spin_lock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001730 ndlp->nlp_flag |= NLP_DELAY_TMO;
1731 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
James Smart2e0fef82007-06-17 19:56:36 -05001732 spin_unlock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001733 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001734 } else {
James Smart2e0fef82007-06-17 19:56:36 -05001735 spin_lock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001736 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
James Smart2e0fef82007-06-17 19:56:36 -05001737 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001738 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001739 return ndlp->nlp_state;
1740}
dea31012005-04-17 16:05:31 -05001741
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001742static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001743lpfc_cmpl_plogi_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1744 void *arg, uint32_t evt)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001745{
1746 struct lpfc_iocbq *cmdiocb, *rspiocb;
James Smarta0f9b482006-04-15 11:52:56 -04001747 IOCB_t *irsp;
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001748
1749 cmdiocb = (struct lpfc_iocbq *) arg;
1750 rspiocb = cmdiocb->context_un.rsp_iocb;
James Smarta0f9b482006-04-15 11:52:56 -04001751
1752 irsp = &rspiocb->iocb;
1753 if (irsp->ulpStatus) {
James Smart2e0fef82007-06-17 19:56:36 -05001754 lpfc_drop_node(vport, ndlp);
James Smarta0f9b482006-04-15 11:52:56 -04001755 return NLP_STE_FREED_NODE;
1756 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001757 return ndlp->nlp_state;
1758}
1759
1760static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001761lpfc_cmpl_prli_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1762 void *arg, uint32_t evt)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001763{
1764 struct lpfc_iocbq *cmdiocb, *rspiocb;
James Smarta0f9b482006-04-15 11:52:56 -04001765 IOCB_t *irsp;
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001766
1767 cmdiocb = (struct lpfc_iocbq *) arg;
1768 rspiocb = cmdiocb->context_un.rsp_iocb;
James Smarta0f9b482006-04-15 11:52:56 -04001769
1770 irsp = &rspiocb->iocb;
1771 if (irsp->ulpStatus && (ndlp->nlp_flag & NLP_NODEV_REMOVE)) {
James Smart2e0fef82007-06-17 19:56:36 -05001772 lpfc_drop_node(vport, ndlp);
James Smarta0f9b482006-04-15 11:52:56 -04001773 return NLP_STE_FREED_NODE;
1774 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001775 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001776}
1777
1778static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001779lpfc_cmpl_logo_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1780 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001781{
James Smart2e0fef82007-06-17 19:56:36 -05001782 lpfc_unreg_rpi(vport, ndlp);
dea31012005-04-17 16:05:31 -05001783 /* This routine does nothing, just return the current state */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001784 return ndlp->nlp_state;
1785}
1786
1787static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001788lpfc_cmpl_adisc_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1789 void *arg, uint32_t evt)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001790{
1791 struct lpfc_iocbq *cmdiocb, *rspiocb;
James Smarta0f9b482006-04-15 11:52:56 -04001792 IOCB_t *irsp;
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001793
1794 cmdiocb = (struct lpfc_iocbq *) arg;
1795 rspiocb = cmdiocb->context_un.rsp_iocb;
James Smarta0f9b482006-04-15 11:52:56 -04001796
1797 irsp = &rspiocb->iocb;
1798 if (irsp->ulpStatus && (ndlp->nlp_flag & NLP_NODEV_REMOVE)) {
James Smart2e0fef82007-06-17 19:56:36 -05001799 lpfc_drop_node(vport, ndlp);
James Smarta0f9b482006-04-15 11:52:56 -04001800 return NLP_STE_FREED_NODE;
1801 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001802 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001803}
1804
1805static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001806lpfc_cmpl_reglogin_npr_node(struct lpfc_vport *vport,
1807 struct lpfc_nodelist *ndlp,
1808 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001809{
James Smart2e0fef82007-06-17 19:56:36 -05001810 LPFC_MBOXQ_t *pmb = (LPFC_MBOXQ_t *) arg;
1811 MAILBOX_t *mb = &pmb->mb;
dea31012005-04-17 16:05:31 -05001812
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001813 if (!mb->mbxStatus)
1814 ndlp->nlp_rpi = mb->un.varWords[0];
James Smarta0f9b482006-04-15 11:52:56 -04001815 else {
1816 if (ndlp->nlp_flag & NLP_NODEV_REMOVE) {
James Smart2e0fef82007-06-17 19:56:36 -05001817 lpfc_drop_node(vport, ndlp);
James Smarta0f9b482006-04-15 11:52:56 -04001818 return NLP_STE_FREED_NODE;
1819 }
1820 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001821 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001822}
1823
1824static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001825lpfc_device_rm_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1826 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001827{
James Smart2e0fef82007-06-17 19:56:36 -05001828 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1829
James Smarta0f9b482006-04-15 11:52:56 -04001830 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
James Smart2e0fef82007-06-17 19:56:36 -05001831 spin_lock_irq(shost->host_lock);
James Smarta0f9b482006-04-15 11:52:56 -04001832 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
James Smart2e0fef82007-06-17 19:56:36 -05001833 spin_unlock_irq(shost->host_lock);
James Smarta0f9b482006-04-15 11:52:56 -04001834 return ndlp->nlp_state;
1835 }
James Smart2e0fef82007-06-17 19:56:36 -05001836 lpfc_drop_node(vport, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001837 return NLP_STE_FREED_NODE;
dea31012005-04-17 16:05:31 -05001838}
1839
1840static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001841lpfc_device_recov_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1842 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001843{
James Smart2e0fef82007-06-17 19:56:36 -05001844 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1845
James Smart92d7f7b2007-06-17 19:56:38 -05001846 /* Don't do anything that will mess up processing of the
1847 * previous RSCN.
1848 */
1849 if (vport->fc_flag & FC_RSCN_DEFERRED)
1850 return ndlp->nlp_state;
1851
James Smart2e0fef82007-06-17 19:56:36 -05001852 spin_lock_irq(shost->host_lock);
James Smarta0f9b482006-04-15 11:52:56 -04001853 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
James Smart2e0fef82007-06-17 19:56:36 -05001854 spin_unlock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05001855 if (ndlp->nlp_flag & NLP_DELAY_TMO) {
James Smart2e0fef82007-06-17 19:56:36 -05001856 lpfc_cancel_retry_delay_tmo(vport, ndlp);
James Smartfdcebe22006-03-07 15:04:01 -05001857 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001858 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001859}
1860
1861
1862/* This next section defines the NPort Discovery State Machine */
1863
1864/* There are 4 different double linked lists nodelist entries can reside on.
1865 * The plogi list and adisc list are used when Link Up discovery or RSCN
1866 * processing is needed. Each list holds the nodes that we will send PLOGI
1867 * or ADISC on. These lists will keep track of what nodes will be effected
1868 * by an RSCN, or a Link Up (Typically, all nodes are effected on Link Up).
1869 * The unmapped_list will contain all nodes that we have successfully logged
1870 * into at the Fibre Channel level. The mapped_list will contain all nodes
1871 * that are mapped FCP targets.
1872 */
1873/*
1874 * The bind list is a list of undiscovered (potentially non-existent) nodes
1875 * that we have saved binding information on. This information is used when
1876 * nodes transition from the unmapped to the mapped list.
1877 */
1878/* For UNUSED_NODE state, the node has just been allocated .
1879 * For PLOGI_ISSUE and REG_LOGIN_ISSUE, the node is on
1880 * the PLOGI list. For REG_LOGIN_COMPL, the node is taken off the PLOGI list
1881 * and put on the unmapped list. For ADISC processing, the node is taken off
1882 * the ADISC list and placed on either the mapped or unmapped list (depending
1883 * on its previous state). Once on the unmapped list, a PRLI is issued and the
1884 * state changed to PRLI_ISSUE. When the PRLI completion occurs, the state is
1885 * changed to UNMAPPED_NODE. If the completion indicates a mapped
1886 * node, the node is taken off the unmapped list. The binding list is checked
1887 * for a valid binding, or a binding is automatically assigned. If binding
1888 * assignment is unsuccessful, the node is left on the unmapped list. If
1889 * binding assignment is successful, the associated binding list entry (if
1890 * any) is removed, and the node is placed on the mapped list.
1891 */
1892/*
1893 * For a Link Down, all nodes on the ADISC, PLOGI, unmapped or mapped
James Smartc01f3202006-08-18 17:47:08 -04001894 * lists will receive a DEVICE_RECOVERY event. If the linkdown or devloss timers
dea31012005-04-17 16:05:31 -05001895 * expire, all effected nodes will receive a DEVICE_RM event.
1896 */
1897/*
1898 * For a Link Up or RSCN, all nodes will move from the mapped / unmapped lists
1899 * to either the ADISC or PLOGI list. After a Nameserver query or ALPA loopmap
1900 * check, additional nodes may be added or removed (via DEVICE_RM) to / from
1901 * the PLOGI or ADISC lists. Once the PLOGI and ADISC lists are populated,
1902 * we will first process the ADISC list. 32 entries are processed initially and
1903 * ADISC is initited for each one. Completions / Events for each node are
1904 * funnelled thru the state machine. As each node finishes ADISC processing, it
1905 * starts ADISC for any nodes waiting for ADISC processing. If no nodes are
1906 * waiting, and the ADISC list count is identically 0, then we are done. For
1907 * Link Up discovery, since all nodes on the PLOGI list are UNREG_LOGIN'ed, we
1908 * can issue a CLEAR_LA and reenable Link Events. Next we will process the PLOGI
1909 * list. 32 entries are processed initially and PLOGI is initited for each one.
1910 * Completions / Events for each node are funnelled thru the state machine. As
1911 * each node finishes PLOGI processing, it starts PLOGI for any nodes waiting
1912 * for PLOGI processing. If no nodes are waiting, and the PLOGI list count is
1913 * indentically 0, then we are done. We have now completed discovery / RSCN
1914 * handling. Upon completion, ALL nodes should be on either the mapped or
1915 * unmapped lists.
1916 */
1917
1918static uint32_t (*lpfc_disc_action[NLP_STE_MAX_STATE * NLP_EVT_MAX_EVENT])
James Smart2e0fef82007-06-17 19:56:36 -05001919 (struct lpfc_vport *, struct lpfc_nodelist *, void *, uint32_t) = {
dea31012005-04-17 16:05:31 -05001920 /* Action routine Event Current State */
1921 lpfc_rcv_plogi_unused_node, /* RCV_PLOGI UNUSED_NODE */
1922 lpfc_rcv_els_unused_node, /* RCV_PRLI */
1923 lpfc_rcv_logo_unused_node, /* RCV_LOGO */
1924 lpfc_rcv_els_unused_node, /* RCV_ADISC */
1925 lpfc_rcv_els_unused_node, /* RCV_PDISC */
1926 lpfc_rcv_els_unused_node, /* RCV_PRLO */
1927 lpfc_disc_illegal, /* CMPL_PLOGI */
1928 lpfc_disc_illegal, /* CMPL_PRLI */
1929 lpfc_cmpl_logo_unused_node, /* CMPL_LOGO */
1930 lpfc_disc_illegal, /* CMPL_ADISC */
1931 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
1932 lpfc_device_rm_unused_node, /* DEVICE_RM */
1933 lpfc_disc_illegal, /* DEVICE_RECOVERY */
1934
1935 lpfc_rcv_plogi_plogi_issue, /* RCV_PLOGI PLOGI_ISSUE */
James Smart92d7f7b2007-06-17 19:56:38 -05001936 lpfc_rcv_prli_plogi_issue, /* RCV_PRLI */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001937 lpfc_rcv_logo_plogi_issue, /* RCV_LOGO */
dea31012005-04-17 16:05:31 -05001938 lpfc_rcv_els_plogi_issue, /* RCV_ADISC */
1939 lpfc_rcv_els_plogi_issue, /* RCV_PDISC */
1940 lpfc_rcv_els_plogi_issue, /* RCV_PRLO */
1941 lpfc_cmpl_plogi_plogi_issue, /* CMPL_PLOGI */
1942 lpfc_disc_illegal, /* CMPL_PRLI */
1943 lpfc_disc_illegal, /* CMPL_LOGO */
1944 lpfc_disc_illegal, /* CMPL_ADISC */
1945 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
1946 lpfc_device_rm_plogi_issue, /* DEVICE_RM */
1947 lpfc_device_recov_plogi_issue, /* DEVICE_RECOVERY */
1948
1949 lpfc_rcv_plogi_adisc_issue, /* RCV_PLOGI ADISC_ISSUE */
1950 lpfc_rcv_prli_adisc_issue, /* RCV_PRLI */
1951 lpfc_rcv_logo_adisc_issue, /* RCV_LOGO */
1952 lpfc_rcv_padisc_adisc_issue, /* RCV_ADISC */
1953 lpfc_rcv_padisc_adisc_issue, /* RCV_PDISC */
1954 lpfc_rcv_prlo_adisc_issue, /* RCV_PRLO */
1955 lpfc_disc_illegal, /* CMPL_PLOGI */
1956 lpfc_disc_illegal, /* CMPL_PRLI */
1957 lpfc_disc_illegal, /* CMPL_LOGO */
1958 lpfc_cmpl_adisc_adisc_issue, /* CMPL_ADISC */
1959 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
1960 lpfc_device_rm_adisc_issue, /* DEVICE_RM */
1961 lpfc_device_recov_adisc_issue, /* DEVICE_RECOVERY */
1962
1963 lpfc_rcv_plogi_reglogin_issue, /* RCV_PLOGI REG_LOGIN_ISSUE */
1964 lpfc_rcv_prli_reglogin_issue, /* RCV_PLOGI */
1965 lpfc_rcv_logo_reglogin_issue, /* RCV_LOGO */
1966 lpfc_rcv_padisc_reglogin_issue, /* RCV_ADISC */
1967 lpfc_rcv_padisc_reglogin_issue, /* RCV_PDISC */
1968 lpfc_rcv_prlo_reglogin_issue, /* RCV_PRLO */
1969 lpfc_disc_illegal, /* CMPL_PLOGI */
1970 lpfc_disc_illegal, /* CMPL_PRLI */
1971 lpfc_disc_illegal, /* CMPL_LOGO */
1972 lpfc_disc_illegal, /* CMPL_ADISC */
1973 lpfc_cmpl_reglogin_reglogin_issue,/* CMPL_REG_LOGIN */
1974 lpfc_device_rm_reglogin_issue, /* DEVICE_RM */
1975 lpfc_device_recov_reglogin_issue,/* DEVICE_RECOVERY */
1976
1977 lpfc_rcv_plogi_prli_issue, /* RCV_PLOGI PRLI_ISSUE */
1978 lpfc_rcv_prli_prli_issue, /* RCV_PRLI */
1979 lpfc_rcv_logo_prli_issue, /* RCV_LOGO */
1980 lpfc_rcv_padisc_prli_issue, /* RCV_ADISC */
1981 lpfc_rcv_padisc_prli_issue, /* RCV_PDISC */
1982 lpfc_rcv_prlo_prli_issue, /* RCV_PRLO */
1983 lpfc_disc_illegal, /* CMPL_PLOGI */
1984 lpfc_cmpl_prli_prli_issue, /* CMPL_PRLI */
1985 lpfc_disc_illegal, /* CMPL_LOGO */
1986 lpfc_disc_illegal, /* CMPL_ADISC */
1987 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
1988 lpfc_device_rm_prli_issue, /* DEVICE_RM */
1989 lpfc_device_recov_prli_issue, /* DEVICE_RECOVERY */
1990
1991 lpfc_rcv_plogi_unmap_node, /* RCV_PLOGI UNMAPPED_NODE */
1992 lpfc_rcv_prli_unmap_node, /* RCV_PRLI */
1993 lpfc_rcv_logo_unmap_node, /* RCV_LOGO */
1994 lpfc_rcv_padisc_unmap_node, /* RCV_ADISC */
1995 lpfc_rcv_padisc_unmap_node, /* RCV_PDISC */
1996 lpfc_rcv_prlo_unmap_node, /* RCV_PRLO */
1997 lpfc_disc_illegal, /* CMPL_PLOGI */
1998 lpfc_disc_illegal, /* CMPL_PRLI */
1999 lpfc_disc_illegal, /* CMPL_LOGO */
2000 lpfc_disc_illegal, /* CMPL_ADISC */
2001 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2002 lpfc_disc_illegal, /* DEVICE_RM */
2003 lpfc_device_recov_unmap_node, /* DEVICE_RECOVERY */
2004
2005 lpfc_rcv_plogi_mapped_node, /* RCV_PLOGI MAPPED_NODE */
2006 lpfc_rcv_prli_mapped_node, /* RCV_PRLI */
2007 lpfc_rcv_logo_mapped_node, /* RCV_LOGO */
2008 lpfc_rcv_padisc_mapped_node, /* RCV_ADISC */
2009 lpfc_rcv_padisc_mapped_node, /* RCV_PDISC */
2010 lpfc_rcv_prlo_mapped_node, /* RCV_PRLO */
2011 lpfc_disc_illegal, /* CMPL_PLOGI */
2012 lpfc_disc_illegal, /* CMPL_PRLI */
2013 lpfc_disc_illegal, /* CMPL_LOGO */
2014 lpfc_disc_illegal, /* CMPL_ADISC */
2015 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2016 lpfc_disc_illegal, /* DEVICE_RM */
2017 lpfc_device_recov_mapped_node, /* DEVICE_RECOVERY */
2018
2019 lpfc_rcv_plogi_npr_node, /* RCV_PLOGI NPR_NODE */
2020 lpfc_rcv_prli_npr_node, /* RCV_PRLI */
2021 lpfc_rcv_logo_npr_node, /* RCV_LOGO */
2022 lpfc_rcv_padisc_npr_node, /* RCV_ADISC */
2023 lpfc_rcv_padisc_npr_node, /* RCV_PDISC */
2024 lpfc_rcv_prlo_npr_node, /* RCV_PRLO */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002025 lpfc_cmpl_plogi_npr_node, /* CMPL_PLOGI */
2026 lpfc_cmpl_prli_npr_node, /* CMPL_PRLI */
dea31012005-04-17 16:05:31 -05002027 lpfc_cmpl_logo_npr_node, /* CMPL_LOGO */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002028 lpfc_cmpl_adisc_npr_node, /* CMPL_ADISC */
dea31012005-04-17 16:05:31 -05002029 lpfc_cmpl_reglogin_npr_node, /* CMPL_REG_LOGIN */
2030 lpfc_device_rm_npr_node, /* DEVICE_RM */
2031 lpfc_device_recov_npr_node, /* DEVICE_RECOVERY */
2032};
2033
2034int
James Smart2e0fef82007-06-17 19:56:36 -05002035lpfc_disc_state_machine(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2036 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05002037{
2038 uint32_t cur_state, rc;
James Smart2e0fef82007-06-17 19:56:36 -05002039 uint32_t(*func) (struct lpfc_vport *, struct lpfc_nodelist *, void *,
dea31012005-04-17 16:05:31 -05002040 uint32_t);
2041
James Smart329f9bc2007-04-25 09:53:01 -04002042 lpfc_nlp_get(ndlp);
dea31012005-04-17 16:05:31 -05002043 cur_state = ndlp->nlp_state;
2044
2045 /* DSM in event <evt> on NPort <nlp_DID> in state <cur_state> */
James Smarte8b62012007-08-02 11:10:09 -04002046 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2047 "0211 DSM in event x%x on NPort x%x in "
2048 "state %d Data: x%x\n",
2049 evt, ndlp->nlp_DID, cur_state, ndlp->nlp_flag);
dea31012005-04-17 16:05:31 -05002050
James Smart858c9f62007-06-17 19:56:39 -05002051 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_DSM,
2052 "DSM in: evt:%d ste:%d did:x%x",
2053 evt, cur_state, ndlp->nlp_DID);
2054
dea31012005-04-17 16:05:31 -05002055 func = lpfc_disc_action[(cur_state * NLP_EVT_MAX_EVENT) + evt];
James Smart2e0fef82007-06-17 19:56:36 -05002056 rc = (func) (vport, ndlp, arg, evt);
dea31012005-04-17 16:05:31 -05002057
2058 /* DSM out state <rc> on NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04002059 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2060 "0212 DSM out state %d on NPort x%x Data: x%x\n",
2061 rc, ndlp->nlp_DID, ndlp->nlp_flag);
dea31012005-04-17 16:05:31 -05002062
James Smart858c9f62007-06-17 19:56:39 -05002063 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_DSM,
2064 "DSM out: ste:%d did:x%x flg:x%x",
2065 rc, ndlp->nlp_DID, ndlp->nlp_flag);
2066
James Smart329f9bc2007-04-25 09:53:01 -04002067 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05002068
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002069 return rc;
dea31012005-04-17 16:05:31 -05002070}