blob: 9c159a8e6e8cd05274115461b4e11f36097bb63f [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:
136 lpfc_printf_log(vport->phba, KERN_ERR, LOG_DISCOVERY,
137 "%d (%d):0207 Device %x "
138 "(%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x) sent "
139 "invalid service parameters. Ignoring device.\n",
140 vport->phba->brd_no, ndlp->vport->vpi, 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]);
145 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> */
197 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
James Smart92d7f7b2007-06-17 19:56:38 -0500198 "%d (%d):0205 Abort outstanding I/O on NPort x%x "
dea31012005-04-17 16:05:31 -0500199 "Data: x%x x%x x%x\n",
James Smart92d7f7b2007-06-17 19:56:38 -0500200 phba->brd_no, ndlp->vport->vpi, ndlp->nlp_DID,
201 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
202
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 Smarted957682007-06-17 19:56:37 -0500301 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
James Smart92d7f7b2007-06-17 19:56:38 -0500302 "%d (%d):0114 PLOGI chkparm OK Data: x%x x%x x%x x%x\n",
303 phba->brd_no, vport->vpi,
dea31012005-04-17 16:05:31 -0500304 ndlp->nlp_DID, ndlp->nlp_state, ndlp->nlp_flag,
305 ndlp->nlp_rpi);
306
James Smart3de2a652007-08-02 11:09:59 -0400307 if (vport->cfg_fcp_class == 2 && sp->cls2.classValid)
dea31012005-04-17 16:05:31 -0500308 ndlp->nlp_fcp_info |= CLASS2;
James Smarted957682007-06-17 19:56:37 -0500309 else
dea31012005-04-17 16:05:31 -0500310 ndlp->nlp_fcp_info |= CLASS3;
James Smart2e0fef82007-06-17 19:56:36 -0500311
dea31012005-04-17 16:05:31 -0500312 ndlp->nlp_class_sup = 0;
313 if (sp->cls1.classValid)
314 ndlp->nlp_class_sup |= FC_COS_CLASS1;
315 if (sp->cls2.classValid)
316 ndlp->nlp_class_sup |= FC_COS_CLASS2;
317 if (sp->cls3.classValid)
318 ndlp->nlp_class_sup |= FC_COS_CLASS3;
319 if (sp->cls4.classValid)
320 ndlp->nlp_class_sup |= FC_COS_CLASS4;
321 ndlp->nlp_maxframe =
322 ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) | sp->cmn.bbRcvSizeLsb;
323
324 /* no need to reg_login if we are already in one of these states */
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500325 switch (ndlp->nlp_state) {
dea31012005-04-17 16:05:31 -0500326 case NLP_STE_NPR_NODE:
327 if (!(ndlp->nlp_flag & NLP_NPR_ADISC))
328 break;
329 case NLP_STE_REG_LOGIN_ISSUE:
330 case NLP_STE_PRLI_ISSUE:
331 case NLP_STE_UNMAPPED_NODE:
332 case NLP_STE_MAPPED_NODE:
James Smart2e0fef82007-06-17 19:56:36 -0500333 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp, NULL, 0);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500334 return 1;
dea31012005-04-17 16:05:31 -0500335 }
336
James Smart92d7f7b2007-06-17 19:56:38 -0500337 if ((vport->fc_flag & FC_PT2PT) &&
338 !(vport->fc_flag & FC_PT2PT_PLOGI)) {
dea31012005-04-17 16:05:31 -0500339 /* rcv'ed PLOGI decides what our NPortId will be */
James Smart2e0fef82007-06-17 19:56:36 -0500340 vport->fc_myDID = icmd->un.rcvels.parmRo;
dea31012005-04-17 16:05:31 -0500341 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
342 if (mbox == NULL)
343 goto out;
344 lpfc_config_link(phba, mbox);
345 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smarted957682007-06-17 19:56:37 -0500346 mbox->vport = vport;
dea31012005-04-17 16:05:31 -0500347 rc = lpfc_sli_issue_mbox
348 (phba, mbox, (MBX_NOWAIT | MBX_STOP_IOCB));
349 if (rc == MBX_NOT_FINISHED) {
James Smart92d7f7b2007-06-17 19:56:38 -0500350 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -0500351 goto out;
352 }
353
James Smart2e0fef82007-06-17 19:56:36 -0500354 lpfc_can_disctmo(vport);
dea31012005-04-17 16:05:31 -0500355 }
356 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
James Smart2e0fef82007-06-17 19:56:36 -0500357 if (!mbox)
dea31012005-04-17 16:05:31 -0500358 goto out;
359
James Smart92d7f7b2007-06-17 19:56:38 -0500360 rc = lpfc_reg_login(phba, vport->vpi, icmd->un.rcvels.remoteID,
361 (uint8_t *) sp, mbox, 0);
James Smart2e0fef82007-06-17 19:56:36 -0500362 if (rc) {
363 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -0500364 goto out;
365 }
366
367 /* ACC PLOGI rsp command needs to execute first,
368 * queue this mbox command to be processed later.
369 */
370 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
James Smart329f9bc2007-04-25 09:53:01 -0400371 /*
372 * mbox->context2 = lpfc_nlp_get(ndlp) deferred until mailbox
373 * command issued in lpfc_cmpl_els_acc().
374 */
James Smart2e0fef82007-06-17 19:56:36 -0500375 mbox->vport = vport;
376 spin_lock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -0500377 ndlp->nlp_flag |= (NLP_ACC_REGLOGIN | NLP_RCV_PLOGI);
James Smart2e0fef82007-06-17 19:56:36 -0500378 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500379
James Smart33ccf8d2006-08-17 11:57:58 -0400380 /*
381 * If there is an outstanding PLOGI issued, abort it before
382 * sending ACC rsp for received PLOGI. If pending plogi
383 * is not canceled here, the plogi will be rejected by
384 * remote port and will be retried. On a configuration with
385 * single discovery thread, this will cause a huge delay in
386 * discovery. Also this will cause multiple state machines
387 * running in parallel for this node.
388 */
389 if (ndlp->nlp_state == NLP_STE_PLOGI_ISSUE) {
390 /* software abort outstanding PLOGI */
James Smart07951072007-04-25 09:51:38 -0400391 lpfc_els_abort(phba, ndlp);
James Smart33ccf8d2006-08-17 11:57:58 -0400392 }
393
James Smart858c9f62007-06-17 19:56:39 -0500394 if ((vport->port_type == LPFC_NPIV_PORT &&
James Smart3de2a652007-08-02 11:09:59 -0400395 vport->cfg_restrict_login)) {
James Smart858c9f62007-06-17 19:56:39 -0500396
397 /* In order to preserve RPIs, we want to cleanup
398 * the default RPI the firmware created to rcv
399 * this ELS request. The only way to do this is
400 * to register, then unregister the RPI.
401 */
402 spin_lock_irq(shost->host_lock);
403 ndlp->nlp_flag |= NLP_RM_DFLT_RPI;
404 spin_unlock_irq(shost->host_lock);
405 stat.un.b.lsRjtRsnCode = LSRJT_INVALID_CMD;
406 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
407 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb,
408 ndlp, mbox);
409 return 1;
410 }
James Smart2e0fef82007-06-17 19:56:36 -0500411 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp, mbox, 0);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500412 return 1;
dea31012005-04-17 16:05:31 -0500413
414out:
415 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
416 stat.un.b.lsRjtRsnCodeExp = LSEXP_OUT_OF_RESOURCE;
James Smart858c9f62007-06-17 19:56:39 -0500417 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500418 return 0;
dea31012005-04-17 16:05:31 -0500419}
420
421static int
James Smart2e0fef82007-06-17 19:56:36 -0500422lpfc_rcv_padisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -0500423 struct lpfc_iocbq *cmdiocb)
424{
James Smart2e0fef82007-06-17 19:56:36 -0500425 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -0500426 struct lpfc_dmabuf *pcmd;
James Smart2e0fef82007-06-17 19:56:36 -0500427 struct serv_parm *sp;
428 struct lpfc_name *pnn, *ppn;
dea31012005-04-17 16:05:31 -0500429 struct ls_rjt stat;
430 ADISC *ap;
431 IOCB_t *icmd;
432 uint32_t *lp;
433 uint32_t cmd;
434
435 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
436 lp = (uint32_t *) pcmd->virt;
437
438 cmd = *lp++;
439 if (cmd == ELS_CMD_ADISC) {
440 ap = (ADISC *) lp;
441 pnn = (struct lpfc_name *) & ap->nodeName;
442 ppn = (struct lpfc_name *) & ap->portName;
443 } else {
444 sp = (struct serv_parm *) lp;
445 pnn = (struct lpfc_name *) & sp->nodeName;
446 ppn = (struct lpfc_name *) & sp->portName;
447 }
448
449 icmd = &cmdiocb->iocb;
James Smart2e0fef82007-06-17 19:56:36 -0500450 if (icmd->ulpStatus == 0 && lpfc_check_adisc(vport, ndlp, pnn, ppn)) {
dea31012005-04-17 16:05:31 -0500451 if (cmd == ELS_CMD_ADISC) {
James Smart2e0fef82007-06-17 19:56:36 -0500452 lpfc_els_rsp_adisc_acc(vport, cmdiocb, ndlp);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500453 } else {
James Smart2e0fef82007-06-17 19:56:36 -0500454 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp,
James Smart92d7f7b2007-06-17 19:56:38 -0500455 NULL, 0);
dea31012005-04-17 16:05:31 -0500456 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500457 return 1;
dea31012005-04-17 16:05:31 -0500458 }
459 /* Reject this request because invalid parameters */
460 stat.un.b.lsRjtRsvd0 = 0;
461 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
462 stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
463 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -0500464 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -0500465
dea31012005-04-17 16:05:31 -0500466 /* 1 sec timeout */
467 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ);
468
James Smart2e0fef82007-06-17 19:56:36 -0500469 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500470 ndlp->nlp_flag |= NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -0500471 spin_unlock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -0500472 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
473 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -0500474 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500475 return 0;
dea31012005-04-17 16:05:31 -0500476}
477
478static int
James Smart2e0fef82007-06-17 19:56:36 -0500479lpfc_rcv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
480 struct lpfc_iocbq *cmdiocb, uint32_t els_cmd)
dea31012005-04-17 16:05:31 -0500481{
James Smart2e0fef82007-06-17 19:56:36 -0500482 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
483
484 /* Put ndlp in NPR state with 1 sec timeout for plogi, ACC logo */
dea31012005-04-17 16:05:31 -0500485 /* Only call LOGO ACC for first LOGO, this avoids sending unnecessary
486 * PLOGIs during LOGO storms from a device.
487 */
James Smart2e0fef82007-06-17 19:56:36 -0500488 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500489 ndlp->nlp_flag |= NLP_LOGO_ACC;
James Smart2e0fef82007-06-17 19:56:36 -0500490 spin_unlock_irq(shost->host_lock);
James Smart82d9a2a2006-04-15 11:53:05 -0400491 if (els_cmd == ELS_CMD_PRLO)
James Smart2e0fef82007-06-17 19:56:36 -0500492 lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL, 0);
James Smart82d9a2a2006-04-15 11:53:05 -0400493 else
James Smart2e0fef82007-06-17 19:56:36 -0500494 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL, 0);
dea31012005-04-17 16:05:31 -0500495
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500496 if (!(ndlp->nlp_type & NLP_FABRIC) ||
James Smart92d7f7b2007-06-17 19:56:38 -0500497 (ndlp->nlp_state == NLP_STE_ADISC_ISSUE)) {
dea31012005-04-17 16:05:31 -0500498 /* Only try to re-login if this is NOT a Fabric Node */
dea31012005-04-17 16:05:31 -0500499 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ * 1);
James Smart2e0fef82007-06-17 19:56:36 -0500500 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500501 ndlp->nlp_flag |= NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -0500502 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500503
Jamie Wellnitz5024ab12006-02-28 19:25:28 -0500504 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
505 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -0500506 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500507 } else {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -0500508 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -0500509 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNUSED_NODE);
dea31012005-04-17 16:05:31 -0500510 }
511
James Smart2e0fef82007-06-17 19:56:36 -0500512 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500513 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
James Smart2e0fef82007-06-17 19:56:36 -0500514 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500515 /* The driver has to wait until the ACC completes before it continues
516 * processing the LOGO. The action will resume in
517 * lpfc_cmpl_els_logo_acc routine. Since part of processing includes an
518 * unreg_login, the driver waits so the ACC does not get aborted.
519 */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500520 return 0;
dea31012005-04-17 16:05:31 -0500521}
522
523static void
James Smart2e0fef82007-06-17 19:56:36 -0500524lpfc_rcv_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
525 struct lpfc_iocbq *cmdiocb)
dea31012005-04-17 16:05:31 -0500526{
527 struct lpfc_dmabuf *pcmd;
528 uint32_t *lp;
529 PRLI *npr;
530 struct fc_rport *rport = ndlp->rport;
531 u32 roles;
532
533 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
534 lp = (uint32_t *) pcmd->virt;
535 npr = (PRLI *) ((uint8_t *) lp + sizeof (uint32_t));
536
537 ndlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR);
538 ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
James Smart92d7f7b2007-06-17 19:56:38 -0500539 if (npr->prliType == PRLI_FCP_TYPE) {
dea31012005-04-17 16:05:31 -0500540 if (npr->initiatorFunc)
541 ndlp->nlp_type |= NLP_FCP_INITIATOR;
542 if (npr->targetFunc)
543 ndlp->nlp_type |= NLP_FCP_TARGET;
544 if (npr->Retry)
545 ndlp->nlp_fcp_info |= NLP_FCP_2_DEVICE;
546 }
547 if (rport) {
548 /* We need to update the rport role values */
549 roles = FC_RPORT_ROLE_UNKNOWN;
550 if (ndlp->nlp_type & NLP_FCP_INITIATOR)
551 roles |= FC_RPORT_ROLE_FCP_INITIATOR;
552 if (ndlp->nlp_type & NLP_FCP_TARGET)
553 roles |= FC_RPORT_ROLE_FCP_TARGET;
James Smart858c9f62007-06-17 19:56:39 -0500554
555 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
556 "rport rolechg: role:x%x did:x%x flg:x%x",
557 roles, ndlp->nlp_DID, ndlp->nlp_flag);
558
dea31012005-04-17 16:05:31 -0500559 fc_remote_port_rolechg(rport, roles);
560 }
561}
562
563static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -0500564lpfc_disc_set_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -0500565{
James Smart2e0fef82007-06-17 19:56:36 -0500566 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart2e0fef82007-06-17 19:56:36 -0500567
dea31012005-04-17 16:05:31 -0500568 /* Check config parameter use-adisc or FCP-2 */
James Smart3de2a652007-08-02 11:09:59 -0400569 if ((vport->cfg_use_adisc && (vport->fc_flag & FC_RSCN_MODE)) ||
James Smart92d7f7b2007-06-17 19:56:38 -0500570 ndlp->nlp_fcp_info & NLP_FCP_2_DEVICE) {
571 spin_lock_irq(shost->host_lock);
572 ndlp->nlp_flag |= NLP_NPR_ADISC;
573 spin_unlock_irq(shost->host_lock);
574 return 1;
575 }
576 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
577 lpfc_unreg_rpi(vport, ndlp);
578 return 0;
dea31012005-04-17 16:05:31 -0500579}
580
581static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -0500582lpfc_disc_illegal(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
583 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -0500584{
James Smarted957682007-06-17 19:56:37 -0500585 lpfc_printf_log(vport->phba, KERN_ERR, LOG_DISCOVERY,
James Smart92d7f7b2007-06-17 19:56:38 -0500586 "%d (%d):0253 Illegal State Transition: node x%x "
587 "event x%x, state x%x Data: x%x x%x\n",
588 vport->phba->brd_no, vport->vpi,
dea31012005-04-17 16:05:31 -0500589 ndlp->nlp_DID, evt, ndlp->nlp_state, ndlp->nlp_rpi,
590 ndlp->nlp_flag);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500591 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -0500592}
593
594/* Start of Discovery State Machine routines */
595
596static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -0500597lpfc_rcv_plogi_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
598 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -0500599{
600 struct lpfc_iocbq *cmdiocb;
601
602 cmdiocb = (struct lpfc_iocbq *) arg;
603
James Smart2e0fef82007-06-17 19:56:36 -0500604 if (lpfc_rcv_plogi(vport, ndlp, cmdiocb)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -0500605 ndlp->nlp_prev_state = NLP_STE_UNUSED_NODE;
James Smart2e0fef82007-06-17 19:56:36 -0500606 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNUSED_NODE);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500607 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -0500608 }
James Smart2e0fef82007-06-17 19:56:36 -0500609 lpfc_drop_node(vport, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500610 return NLP_STE_FREED_NODE;
dea31012005-04-17 16:05:31 -0500611}
612
613static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -0500614lpfc_rcv_els_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
615 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -0500616{
James Smart2e0fef82007-06-17 19:56:36 -0500617 lpfc_issue_els_logo(vport, ndlp, 0);
618 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNUSED_NODE);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500619 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -0500620}
621
622static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -0500623lpfc_rcv_logo_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
624 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -0500625{
James Smart2e0fef82007-06-17 19:56:36 -0500626 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
627 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -0500628
James Smart2e0fef82007-06-17 19:56:36 -0500629 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500630 ndlp->nlp_flag |= NLP_LOGO_ACC;
James Smart2e0fef82007-06-17 19:56:36 -0500631 spin_unlock_irq(shost->host_lock);
632 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL, 0);
633 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNUSED_NODE);
dea31012005-04-17 16:05:31 -0500634
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500635 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -0500636}
637
638static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -0500639lpfc_cmpl_logo_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -0500640 void *arg, uint32_t evt)
641{
James Smart2e0fef82007-06-17 19:56:36 -0500642 lpfc_drop_node(vport, ndlp);
643 return NLP_STE_FREED_NODE;
644}
645
646static uint32_t
647lpfc_device_rm_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
648 void *arg, uint32_t evt)
649{
650 lpfc_drop_node(vport, ndlp);
651 return NLP_STE_FREED_NODE;
652}
653
654static uint32_t
655lpfc_rcv_plogi_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
656 void *arg, uint32_t evt)
657{
658 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500659 struct lpfc_iocbq *cmdiocb = arg;
James Smart2e0fef82007-06-17 19:56:36 -0500660 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
661 uint32_t *lp = (uint32_t *) pcmd->virt;
662 struct serv_parm *sp = (struct serv_parm *) (lp + 1);
dea31012005-04-17 16:05:31 -0500663 struct ls_rjt stat;
664 int port_cmp;
665
dea31012005-04-17 16:05:31 -0500666 memset(&stat, 0, sizeof (struct ls_rjt));
667
668 /* For a PLOGI, we only accept if our portname is less
669 * than the remote portname.
670 */
671 phba->fc_stat.elsLogiCol++;
James Smart2e0fef82007-06-17 19:56:36 -0500672 port_cmp = memcmp(&vport->fc_portname, &sp->portName,
James Smart92d7f7b2007-06-17 19:56:38 -0500673 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -0500674
675 if (port_cmp >= 0) {
676 /* Reject this request because the remote node will accept
677 ours */
678 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
679 stat.un.b.lsRjtRsnCodeExp = LSEXP_CMD_IN_PROGRESS;
James Smart858c9f62007-06-17 19:56:39 -0500680 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
681 NULL);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500682 } else {
James Smart2e0fef82007-06-17 19:56:36 -0500683 lpfc_rcv_plogi(vport, ndlp, cmdiocb);
684 } /* If our portname was less */
dea31012005-04-17 16:05:31 -0500685
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500686 return ndlp->nlp_state;
687}
688
689static uint32_t
James Smart92d7f7b2007-06-17 19:56:38 -0500690lpfc_rcv_prli_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
691 void *arg, uint32_t evt)
692{
693 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
694 struct ls_rjt stat;
695
696 memset(&stat, 0, sizeof (struct ls_rjt));
697 stat.un.b.lsRjtRsnCode = LSRJT_LOGICAL_BSY;
698 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
James Smart858c9f62007-06-17 19:56:39 -0500699 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
James Smart92d7f7b2007-06-17 19:56:38 -0500700 return ndlp->nlp_state;
701}
702
703static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -0500704lpfc_rcv_logo_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
705 void *arg, uint32_t evt)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500706{
James Smart2e0fef82007-06-17 19:56:36 -0500707 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500708
James Smart92d7f7b2007-06-17 19:56:38 -0500709 /* software abort outstanding PLOGI */
James Smart2e0fef82007-06-17 19:56:36 -0500710 lpfc_els_abort(vport->phba, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500711
James Smart2e0fef82007-06-17 19:56:36 -0500712 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500713 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -0500714}
715
716static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -0500717lpfc_rcv_els_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
718 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -0500719{
James Smart2e0fef82007-06-17 19:56:36 -0500720 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
721 struct lpfc_hba *phba = vport->phba;
722 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -0500723
724 /* software abort outstanding PLOGI */
James Smart07951072007-04-25 09:51:38 -0400725 lpfc_els_abort(phba, ndlp);
dea31012005-04-17 16:05:31 -0500726
727 if (evt == NLP_EVT_RCV_LOGO) {
James Smart2e0fef82007-06-17 19:56:36 -0500728 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL, 0);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500729 } else {
James Smart2e0fef82007-06-17 19:56:36 -0500730 lpfc_issue_els_logo(vport, ndlp, 0);
dea31012005-04-17 16:05:31 -0500731 }
732
James Smart2e0fef82007-06-17 19:56:36 -0500733 /* Put ndlp in npr state set plogi timer for 1 sec */
Jamie Wellnitz5024ab12006-02-28 19:25:28 -0500734 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ * 1);
James Smart2e0fef82007-06-17 19:56:36 -0500735 spin_lock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -0500736 ndlp->nlp_flag |= NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -0500737 spin_unlock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -0500738 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
739 ndlp->nlp_prev_state = NLP_STE_PLOGI_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -0500740 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
dea31012005-04-17 16:05:31 -0500741
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500742 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -0500743}
744
745static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -0500746lpfc_cmpl_plogi_plogi_issue(struct lpfc_vport *vport,
747 struct lpfc_nodelist *ndlp,
748 void *arg,
dea31012005-04-17 16:05:31 -0500749 uint32_t evt)
750{
James Smart2e0fef82007-06-17 19:56:36 -0500751 struct lpfc_hba *phba = vport->phba;
752 struct lpfc_iocbq *cmdiocb, *rspiocb;
James Smart14691152006-12-02 13:34:28 -0500753 struct lpfc_dmabuf *pcmd, *prsp, *mp;
dea31012005-04-17 16:05:31 -0500754 uint32_t *lp;
755 IOCB_t *irsp;
756 struct serv_parm *sp;
757 LPFC_MBOXQ_t *mbox;
758
759 cmdiocb = (struct lpfc_iocbq *) arg;
760 rspiocb = cmdiocb->context_un.rsp_iocb;
761
762 if (ndlp->nlp_flag & NLP_ACC_REGLOGIN) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -0500763 /* Recovery from PLOGI collision logic */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500764 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -0500765 }
766
767 irsp = &rspiocb->iocb;
768
769 if (irsp->ulpStatus)
770 goto out;
771
772 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
773
James Smart2e0fef82007-06-17 19:56:36 -0500774 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
dea31012005-04-17 16:05:31 -0500775
James Smart2e0fef82007-06-17 19:56:36 -0500776 lp = (uint32_t *) prsp->virt;
dea31012005-04-17 16:05:31 -0500777 sp = (struct serv_parm *) ((uint8_t *) lp + sizeof (uint32_t));
James Smart2e0fef82007-06-17 19:56:36 -0500778 if (!lpfc_check_sparm(vport, ndlp, sp, CLASS3))
dea31012005-04-17 16:05:31 -0500779 goto out;
780
781 /* PLOGI chkparm OK */
James Smarted957682007-06-17 19:56:37 -0500782 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
James Smart92d7f7b2007-06-17 19:56:38 -0500783 "%d (%d):0121 PLOGI chkparm OK "
dea31012005-04-17 16:05:31 -0500784 "Data: x%x x%x x%x x%x\n",
James Smart92d7f7b2007-06-17 19:56:38 -0500785 phba->brd_no, vport->vpi,
dea31012005-04-17 16:05:31 -0500786 ndlp->nlp_DID, ndlp->nlp_state,
787 ndlp->nlp_flag, ndlp->nlp_rpi);
788
James Smart3de2a652007-08-02 11:09:59 -0400789 if (vport->cfg_fcp_class == 2 && (sp->cls2.classValid))
dea31012005-04-17 16:05:31 -0500790 ndlp->nlp_fcp_info |= CLASS2;
James Smart2e0fef82007-06-17 19:56:36 -0500791 else
dea31012005-04-17 16:05:31 -0500792 ndlp->nlp_fcp_info |= CLASS3;
James Smart2e0fef82007-06-17 19:56:36 -0500793
dea31012005-04-17 16:05:31 -0500794 ndlp->nlp_class_sup = 0;
795 if (sp->cls1.classValid)
796 ndlp->nlp_class_sup |= FC_COS_CLASS1;
797 if (sp->cls2.classValid)
798 ndlp->nlp_class_sup |= FC_COS_CLASS2;
799 if (sp->cls3.classValid)
800 ndlp->nlp_class_sup |= FC_COS_CLASS3;
801 if (sp->cls4.classValid)
802 ndlp->nlp_class_sup |= FC_COS_CLASS4;
803 ndlp->nlp_maxframe =
James Smart2e0fef82007-06-17 19:56:36 -0500804 ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) | sp->cmn.bbRcvSizeLsb;
dea31012005-04-17 16:05:31 -0500805
James Smart2e0fef82007-06-17 19:56:36 -0500806 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
James Smart92d7f7b2007-06-17 19:56:38 -0500807 if (!mbox) {
808 lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
809 "%d (%d):0133 PLOGI: no memory for reg_login "
810 "Data: x%x x%x x%x x%x\n",
811 phba->brd_no, vport->vpi,
812 ndlp->nlp_DID, ndlp->nlp_state,
813 ndlp->nlp_flag, ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -0500814 goto out;
James Smart92d7f7b2007-06-17 19:56:38 -0500815 }
dea31012005-04-17 16:05:31 -0500816
James Smart2e0fef82007-06-17 19:56:36 -0500817 lpfc_unreg_rpi(vport, ndlp);
818
James Smart92d7f7b2007-06-17 19:56:38 -0500819 if (lpfc_reg_login(phba, vport->vpi, irsp->un.elsreq64.remoteID,
820 (uint8_t *) sp, mbox, 0) == 0) {
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500821 switch (ndlp->nlp_DID) {
dea31012005-04-17 16:05:31 -0500822 case NameServer_DID:
James Smartde0c5b32007-04-25 09:52:27 -0400823 mbox->mbox_cmpl = lpfc_mbx_cmpl_ns_reg_login;
dea31012005-04-17 16:05:31 -0500824 break;
825 case FDMI_DID:
James Smartde0c5b32007-04-25 09:52:27 -0400826 mbox->mbox_cmpl = lpfc_mbx_cmpl_fdmi_reg_login;
dea31012005-04-17 16:05:31 -0500827 break;
828 default:
James Smartde0c5b32007-04-25 09:52:27 -0400829 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
dea31012005-04-17 16:05:31 -0500830 }
James Smart329f9bc2007-04-25 09:53:01 -0400831 mbox->context2 = lpfc_nlp_get(ndlp);
James Smart2e0fef82007-06-17 19:56:36 -0500832 mbox->vport = vport;
dea31012005-04-17 16:05:31 -0500833 if (lpfc_sli_issue_mbox(phba, mbox,
834 (MBX_NOWAIT | MBX_STOP_IOCB))
835 != MBX_NOT_FINISHED) {
James Smart2e0fef82007-06-17 19:56:36 -0500836 lpfc_nlp_set_state(vport, ndlp,
837 NLP_STE_REG_LOGIN_ISSUE);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500838 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -0500839 }
James Smart329f9bc2007-04-25 09:53:01 -0400840 lpfc_nlp_put(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -0500841 mp = (struct lpfc_dmabuf *) mbox->context1;
James Smart14691152006-12-02 13:34:28 -0500842 lpfc_mbuf_free(phba, mp->virt, mp->phys);
843 kfree(mp);
dea31012005-04-17 16:05:31 -0500844 mempool_free(mbox, phba->mbox_mem_pool);
James Smart92d7f7b2007-06-17 19:56:38 -0500845
846 lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
847 "%d (%d):0134 PLOGI: cannot issue reg_login "
848 "Data: x%x x%x x%x x%x\n",
849 phba->brd_no, vport->vpi,
850 ndlp->nlp_DID, ndlp->nlp_state,
851 ndlp->nlp_flag, ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -0500852 } else {
853 mempool_free(mbox, phba->mbox_mem_pool);
James Smart92d7f7b2007-06-17 19:56:38 -0500854
855 lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
856 "%d (%d):0135 PLOGI: cannot format reg_login "
857 "Data: x%x x%x x%x x%x\n",
858 phba->brd_no, vport->vpi,
859 ndlp->nlp_DID, ndlp->nlp_state,
860 ndlp->nlp_flag, ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -0500861 }
862
863
James Smart92d7f7b2007-06-17 19:56:38 -0500864out:
865 if (ndlp->nlp_DID == NameServer_DID) {
866 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
867 lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
868 "%d (%d):0261 Cannot Register NameServer login\n",
869 phba->brd_no, vport->vpi);
870 }
871
dea31012005-04-17 16:05:31 -0500872 /* Free this node since the driver cannot login or has the wrong
873 sparm */
James Smart2e0fef82007-06-17 19:56:36 -0500874 lpfc_drop_node(vport, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500875 return NLP_STE_FREED_NODE;
dea31012005-04-17 16:05:31 -0500876}
877
878static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -0500879lpfc_device_rm_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
880 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -0500881{
James Smart2e0fef82007-06-17 19:56:36 -0500882 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -0500883
James Smart2e0fef82007-06-17 19:56:36 -0500884 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
885 spin_lock_irq(shost->host_lock);
886 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
887 spin_unlock_irq(shost->host_lock);
888 return ndlp->nlp_state;
889 } else {
890 /* software abort outstanding PLOGI */
891 lpfc_els_abort(vport->phba, ndlp);
892
893 lpfc_drop_node(vport, ndlp);
James Smarta0f9b482006-04-15 11:52:56 -0400894 return NLP_STE_FREED_NODE;
895 }
dea31012005-04-17 16:05:31 -0500896}
897
898static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -0500899lpfc_device_recov_plogi_issue(struct lpfc_vport *vport,
900 struct lpfc_nodelist *ndlp,
901 void *arg,
902 uint32_t evt)
dea31012005-04-17 16:05:31 -0500903{
James Smart2e0fef82007-06-17 19:56:36 -0500904 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
905 struct lpfc_hba *phba = vport->phba;
906
James Smart92d7f7b2007-06-17 19:56:38 -0500907 /* Don't do anything that will mess up processing of the
908 * previous RSCN.
909 */
910 if (vport->fc_flag & FC_RSCN_DEFERRED)
911 return ndlp->nlp_state;
912
dea31012005-04-17 16:05:31 -0500913 /* software abort outstanding PLOGI */
James Smart07951072007-04-25 09:51:38 -0400914 lpfc_els_abort(phba, ndlp);
dea31012005-04-17 16:05:31 -0500915
Jamie Wellnitz5024ab12006-02-28 19:25:28 -0500916 ndlp->nlp_prev_state = NLP_STE_PLOGI_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -0500917 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
James Smart92d7f7b2007-06-17 19:56:38 -0500918 spin_lock_irq(shost->host_lock);
James Smarta0f9b482006-04-15 11:52:56 -0400919 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
James Smart2e0fef82007-06-17 19:56:36 -0500920 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500921
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500922 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -0500923}
924
925static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -0500926lpfc_rcv_plogi_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
927 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -0500928{
James Smart2e0fef82007-06-17 19:56:36 -0500929 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500930 struct lpfc_iocbq *cmdiocb;
931
932 /* software abort outstanding ADISC */
James Smart07951072007-04-25 09:51:38 -0400933 lpfc_els_abort(phba, ndlp);
dea31012005-04-17 16:05:31 -0500934
935 cmdiocb = (struct lpfc_iocbq *) arg;
936
James Smart2e0fef82007-06-17 19:56:36 -0500937 if (lpfc_rcv_plogi(vport, ndlp, cmdiocb))
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500938 return ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -0500939
Jamie Wellnitz5024ab12006-02-28 19:25:28 -0500940 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -0500941 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
942 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
dea31012005-04-17 16:05:31 -0500943
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500944 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -0500945}
946
947static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -0500948lpfc_rcv_prli_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
949 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -0500950{
James Smart2e0fef82007-06-17 19:56:36 -0500951 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -0500952
James Smart2e0fef82007-06-17 19:56:36 -0500953 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500954 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -0500955}
956
957static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -0500958lpfc_rcv_logo_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
959 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -0500960{
James Smart2e0fef82007-06-17 19:56:36 -0500961 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500962 struct lpfc_iocbq *cmdiocb;
963
964 cmdiocb = (struct lpfc_iocbq *) arg;
965
966 /* software abort outstanding ADISC */
James Smart07951072007-04-25 09:51:38 -0400967 lpfc_els_abort(phba, ndlp);
dea31012005-04-17 16:05:31 -0500968
James Smart2e0fef82007-06-17 19:56:36 -0500969 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500970 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -0500971}
972
973static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -0500974lpfc_rcv_padisc_adisc_issue(struct lpfc_vport *vport,
975 struct lpfc_nodelist *ndlp,
976 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -0500977{
978 struct lpfc_iocbq *cmdiocb;
979
980 cmdiocb = (struct lpfc_iocbq *) arg;
981
James Smart2e0fef82007-06-17 19:56:36 -0500982 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500983 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -0500984}
985
986static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -0500987lpfc_rcv_prlo_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
988 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -0500989{
990 struct lpfc_iocbq *cmdiocb;
991
992 cmdiocb = (struct lpfc_iocbq *) arg;
993
994 /* Treat like rcv logo */
James Smart2e0fef82007-06-17 19:56:36 -0500995 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_PRLO);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500996 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -0500997}
998
999static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001000lpfc_cmpl_adisc_adisc_issue(struct lpfc_vport *vport,
1001 struct lpfc_nodelist *ndlp,
1002 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001003{
James Smart2e0fef82007-06-17 19:56:36 -05001004 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1005 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001006 struct lpfc_iocbq *cmdiocb, *rspiocb;
1007 IOCB_t *irsp;
1008 ADISC *ap;
1009
1010 cmdiocb = (struct lpfc_iocbq *) arg;
1011 rspiocb = cmdiocb->context_un.rsp_iocb;
1012
1013 ap = (ADISC *)lpfc_check_elscmpl_iocb(phba, cmdiocb, rspiocb);
1014 irsp = &rspiocb->iocb;
1015
1016 if ((irsp->ulpStatus) ||
James Smart92d7f7b2007-06-17 19:56:38 -05001017 (!lpfc_check_adisc(vport, ndlp, &ap->nodeName, &ap->portName))) {
dea31012005-04-17 16:05:31 -05001018 /* 1 sec timeout */
1019 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ);
James Smart2e0fef82007-06-17 19:56:36 -05001020 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001021 ndlp->nlp_flag |= NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05001022 spin_unlock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001023 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
dea31012005-04-17 16:05:31 -05001024
James Smart2e0fef82007-06-17 19:56:36 -05001025 memset(&ndlp->nlp_nodename, 0, sizeof(struct lpfc_name));
1026 memset(&ndlp->nlp_portname, 0, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05001027
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_NPR_NODE);
1030 lpfc_unreg_rpi(vport, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001031 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001032 }
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001033
James.Smart@Emulex.Com25013222005-06-25 10:34:33 -04001034 if (ndlp->nlp_type & NLP_FCP_TARGET) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001035 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -05001036 lpfc_nlp_set_state(vport, ndlp, NLP_STE_MAPPED_NODE);
James.Smart@Emulex.Com25013222005-06-25 10:34:33 -04001037 } else {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001038 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -05001039 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
James.Smart@Emulex.Com25013222005-06-25 10:34:33 -04001040 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001041 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001042}
1043
1044static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001045lpfc_device_rm_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1046 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001047{
James Smart2e0fef82007-06-17 19:56:36 -05001048 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001049
James Smart2e0fef82007-06-17 19:56:36 -05001050 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1051 spin_lock_irq(shost->host_lock);
1052 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
1053 spin_unlock_irq(shost->host_lock);
1054 return ndlp->nlp_state;
1055 } else {
1056 /* software abort outstanding ADISC */
1057 lpfc_els_abort(vport->phba, ndlp);
1058
1059 lpfc_drop_node(vport, ndlp);
James Smarta0f9b482006-04-15 11:52:56 -04001060 return NLP_STE_FREED_NODE;
1061 }
dea31012005-04-17 16:05:31 -05001062}
1063
1064static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001065lpfc_device_recov_adisc_issue(struct lpfc_vport *vport,
1066 struct lpfc_nodelist *ndlp,
1067 void *arg,
1068 uint32_t evt)
dea31012005-04-17 16:05:31 -05001069{
James Smart2e0fef82007-06-17 19:56:36 -05001070 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1071 struct lpfc_hba *phba = vport->phba;
1072
James Smart92d7f7b2007-06-17 19:56:38 -05001073 /* Don't do anything that will mess up processing of the
1074 * previous RSCN.
1075 */
1076 if (vport->fc_flag & FC_RSCN_DEFERRED)
1077 return ndlp->nlp_state;
1078
dea31012005-04-17 16:05:31 -05001079 /* software abort outstanding ADISC */
James Smart07951072007-04-25 09:51:38 -04001080 lpfc_els_abort(phba, ndlp);
dea31012005-04-17 16:05:31 -05001081
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001082 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -05001083 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1084 spin_lock_irq(shost->host_lock);
James Smarta0f9b482006-04-15 11:52:56 -04001085 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
James Smart2e0fef82007-06-17 19:56:36 -05001086 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05001087 lpfc_disc_set_adisc(vport, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001088 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001089}
1090
1091static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001092lpfc_rcv_plogi_reglogin_issue(struct lpfc_vport *vport,
1093 struct lpfc_nodelist *ndlp,
1094 void *arg,
dea31012005-04-17 16:05:31 -05001095 uint32_t evt)
1096{
James Smart2e0fef82007-06-17 19:56:36 -05001097 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001098
James Smart2e0fef82007-06-17 19:56:36 -05001099 lpfc_rcv_plogi(vport, ndlp, cmdiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001100 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001101}
1102
1103static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001104lpfc_rcv_prli_reglogin_issue(struct lpfc_vport *vport,
1105 struct lpfc_nodelist *ndlp,
1106 void *arg,
dea31012005-04-17 16:05:31 -05001107 uint32_t evt)
1108{
James Smart2e0fef82007-06-17 19:56:36 -05001109 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001110
James Smart2e0fef82007-06-17 19:56:36 -05001111 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001112 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001113}
1114
1115static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001116lpfc_rcv_logo_reglogin_issue(struct lpfc_vport *vport,
1117 struct lpfc_nodelist *ndlp,
1118 void *arg,
dea31012005-04-17 16:05:31 -05001119 uint32_t evt)
1120{
James Smart2e0fef82007-06-17 19:56:36 -05001121 struct lpfc_hba *phba = vport->phba;
1122 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
James Smart7054a602007-04-25 09:52:34 -04001123 LPFC_MBOXQ_t *mb;
1124 LPFC_MBOXQ_t *nextmb;
1125 struct lpfc_dmabuf *mp;
dea31012005-04-17 16:05:31 -05001126
1127 cmdiocb = (struct lpfc_iocbq *) arg;
1128
James Smart7054a602007-04-25 09:52:34 -04001129 /* cleanup any ndlp on mbox q waiting for reglogin cmpl */
1130 if ((mb = phba->sli.mbox_active)) {
1131 if ((mb->mb.mbxCommand == MBX_REG_LOGIN64) &&
1132 (ndlp == (struct lpfc_nodelist *) mb->context2)) {
James Smart92d7f7b2007-06-17 19:56:38 -05001133 lpfc_nlp_put(ndlp);
James Smart7054a602007-04-25 09:52:34 -04001134 mb->context2 = NULL;
1135 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1136 }
1137 }
1138
James Smart2e0fef82007-06-17 19:56:36 -05001139 spin_lock_irq(&phba->hbalock);
James Smart7054a602007-04-25 09:52:34 -04001140 list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) {
1141 if ((mb->mb.mbxCommand == MBX_REG_LOGIN64) &&
1142 (ndlp == (struct lpfc_nodelist *) mb->context2)) {
1143 mp = (struct lpfc_dmabuf *) (mb->context1);
1144 if (mp) {
1145 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1146 kfree(mp);
1147 }
James Smart92d7f7b2007-06-17 19:56:38 -05001148 lpfc_nlp_put(ndlp);
James Smart7054a602007-04-25 09:52:34 -04001149 list_del(&mb->list);
1150 mempool_free(mb, phba->mbox_mem_pool);
1151 }
1152 }
James Smart2e0fef82007-06-17 19:56:36 -05001153 spin_unlock_irq(&phba->hbalock);
James Smart7054a602007-04-25 09:52:34 -04001154
James Smart2e0fef82007-06-17 19:56:36 -05001155 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001156 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001157}
1158
1159static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001160lpfc_rcv_padisc_reglogin_issue(struct lpfc_vport *vport,
1161 struct lpfc_nodelist *ndlp,
1162 void *arg,
dea31012005-04-17 16:05:31 -05001163 uint32_t evt)
1164{
James Smart2e0fef82007-06-17 19:56:36 -05001165 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001166
James Smart2e0fef82007-06-17 19:56:36 -05001167 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001168 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001169}
1170
1171static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001172lpfc_rcv_prlo_reglogin_issue(struct lpfc_vport *vport,
1173 struct lpfc_nodelist *ndlp,
1174 void *arg,
dea31012005-04-17 16:05:31 -05001175 uint32_t evt)
1176{
1177 struct lpfc_iocbq *cmdiocb;
1178
1179 cmdiocb = (struct lpfc_iocbq *) arg;
James Smart2e0fef82007-06-17 19:56:36 -05001180 lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL, 0);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001181 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001182}
1183
1184static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001185lpfc_cmpl_reglogin_reglogin_issue(struct lpfc_vport *vport,
1186 struct lpfc_nodelist *ndlp,
1187 void *arg,
1188 uint32_t evt)
dea31012005-04-17 16:05:31 -05001189{
James Smart2e0fef82007-06-17 19:56:36 -05001190 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1191 struct lpfc_hba *phba = vport->phba;
1192 LPFC_MBOXQ_t *pmb = (LPFC_MBOXQ_t *) arg;
1193 MAILBOX_t *mb = &pmb->mb;
1194 uint32_t did = mb->un.varWords[1];
dea31012005-04-17 16:05:31 -05001195
dea31012005-04-17 16:05:31 -05001196 if (mb->mbxStatus) {
1197 /* RegLogin failed */
James Smarted957682007-06-17 19:56:37 -05001198 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
James Smart92d7f7b2007-06-17 19:56:38 -05001199 "%d (%d):0246 RegLogin failed Data: x%x x%x "
1200 "x%x\n",
1201 phba->brd_no, vport->vpi,
James Smart2e0fef82007-06-17 19:56:36 -05001202 did, mb->mbxStatus, vport->port_state);
dea31012005-04-17 16:05:31 -05001203
James Smartd0e56da2006-07-06 15:49:42 -04001204 /*
1205 * If RegLogin failed due to lack of HBA resources do not
1206 * retry discovery.
1207 */
1208 if (mb->mbxStatus == MBXERR_RPI_FULL) {
1209 ndlp->nlp_prev_state = NLP_STE_UNUSED_NODE;
James Smart2e0fef82007-06-17 19:56:36 -05001210 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNUSED_NODE);
James Smartd0e56da2006-07-06 15:49:42 -04001211 return ndlp->nlp_state;
1212 }
1213
James Smart2e0fef82007-06-17 19:56:36 -05001214 /* Put ndlp in npr state set plogi timer for 1 sec */
dea31012005-04-17 16:05:31 -05001215 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ * 1);
James Smart2e0fef82007-06-17 19:56:36 -05001216 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001217 ndlp->nlp_flag |= NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05001218 spin_unlock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001219 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
dea31012005-04-17 16:05:31 -05001220
James Smart2e0fef82007-06-17 19:56:36 -05001221 lpfc_issue_els_logo(vport, ndlp, 0);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001222 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -05001223 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001224 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001225 }
1226
dea31012005-04-17 16:05:31 -05001227 ndlp->nlp_rpi = mb->un.varWords[0];
dea31012005-04-17 16:05:31 -05001228
1229 /* Only if we are not a fabric nport do we issue PRLI */
1230 if (!(ndlp->nlp_type & NLP_FABRIC)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001231 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -05001232 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
1233 lpfc_issue_els_prli(vport, ndlp, 0);
dea31012005-04-17 16:05:31 -05001234 } else {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001235 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -05001236 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
dea31012005-04-17 16:05:31 -05001237 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001238 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001239}
1240
1241static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001242lpfc_device_rm_reglogin_issue(struct lpfc_vport *vport,
1243 struct lpfc_nodelist *ndlp,
1244 void *arg,
dea31012005-04-17 16:05:31 -05001245 uint32_t evt)
1246{
James Smart2e0fef82007-06-17 19:56:36 -05001247 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1248
1249 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1250 spin_lock_irq(shost->host_lock);
James Smarta0f9b482006-04-15 11:52:56 -04001251 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
James Smart2e0fef82007-06-17 19:56:36 -05001252 spin_unlock_irq(shost->host_lock);
James Smarta0f9b482006-04-15 11:52:56 -04001253 return ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05001254 } else {
1255 lpfc_drop_node(vport, ndlp);
James Smarta0f9b482006-04-15 11:52:56 -04001256 return NLP_STE_FREED_NODE;
1257 }
dea31012005-04-17 16:05:31 -05001258}
1259
1260static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001261lpfc_device_recov_reglogin_issue(struct lpfc_vport *vport,
1262 struct lpfc_nodelist *ndlp,
1263 void *arg,
1264 uint32_t evt)
dea31012005-04-17 16:05:31 -05001265{
James Smart2e0fef82007-06-17 19:56:36 -05001266 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1267
James Smart92d7f7b2007-06-17 19:56:38 -05001268 /* Don't do anything that will mess up processing of the
1269 * previous RSCN.
1270 */
1271 if (vport->fc_flag & FC_RSCN_DEFERRED)
1272 return ndlp->nlp_state;
1273
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001274 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -05001275 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1276 spin_lock_irq(shost->host_lock);
James Smarta0f9b482006-04-15 11:52:56 -04001277 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
James Smart2e0fef82007-06-17 19:56:36 -05001278 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05001279 lpfc_disc_set_adisc(vport, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001280 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001281}
1282
1283static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001284lpfc_rcv_plogi_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1285 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001286{
1287 struct lpfc_iocbq *cmdiocb;
1288
1289 cmdiocb = (struct lpfc_iocbq *) arg;
1290
James Smart2e0fef82007-06-17 19:56:36 -05001291 lpfc_rcv_plogi(vport, ndlp, cmdiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001292 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001293}
1294
1295static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001296lpfc_rcv_prli_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1297 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001298{
James Smart2e0fef82007-06-17 19:56:36 -05001299 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001300
James Smart2e0fef82007-06-17 19:56:36 -05001301 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001302 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001303}
1304
1305static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001306lpfc_rcv_logo_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1307 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001308{
James Smart2e0fef82007-06-17 19:56:36 -05001309 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001310
1311 /* Software abort outstanding PRLI before sending acc */
James Smart2e0fef82007-06-17 19:56:36 -05001312 lpfc_els_abort(vport->phba, ndlp);
dea31012005-04-17 16:05:31 -05001313
James Smart2e0fef82007-06-17 19:56:36 -05001314 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001315 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001316}
1317
1318static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001319lpfc_rcv_padisc_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1320 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001321{
James Smart2e0fef82007-06-17 19:56:36 -05001322 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001323
James Smart2e0fef82007-06-17 19:56:36 -05001324 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001325 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001326}
1327
1328/* This routine is envoked when we rcv a PRLO request from a nport
1329 * we are logged into. We should send back a PRLO rsp setting the
1330 * appropriate bits.
1331 * NEXT STATE = PRLI_ISSUE
1332 */
1333static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001334lpfc_rcv_prlo_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1335 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001336{
James Smart2e0fef82007-06-17 19:56:36 -05001337 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001338
James Smart2e0fef82007-06-17 19:56:36 -05001339 lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL, 0);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001340 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001341}
1342
1343static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001344lpfc_cmpl_prli_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1345 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001346{
James Smart92d7f7b2007-06-17 19:56:38 -05001347 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001348 struct lpfc_iocbq *cmdiocb, *rspiocb;
James Smart2e0fef82007-06-17 19:56:36 -05001349 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001350 IOCB_t *irsp;
1351 PRLI *npr;
1352
1353 cmdiocb = (struct lpfc_iocbq *) arg;
1354 rspiocb = cmdiocb->context_un.rsp_iocb;
1355 npr = (PRLI *)lpfc_check_elscmpl_iocb(phba, cmdiocb, rspiocb);
1356
1357 irsp = &rspiocb->iocb;
1358 if (irsp->ulpStatus) {
James Smart858c9f62007-06-17 19:56:39 -05001359 if ((vport->port_type == LPFC_NPIV_PORT) &&
James Smart3de2a652007-08-02 11:09:59 -04001360 vport->cfg_restrict_login) {
James Smart858c9f62007-06-17 19:56:39 -05001361 goto out;
1362 }
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001363 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -05001364 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001365 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001366 }
1367
1368 /* Check out PRLI rsp */
1369 ndlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR);
1370 ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
1371 if ((npr->acceptRspCode == PRLI_REQ_EXECUTED) &&
1372 (npr->prliType == PRLI_FCP_TYPE)) {
1373 if (npr->initiatorFunc)
1374 ndlp->nlp_type |= NLP_FCP_INITIATOR;
1375 if (npr->targetFunc)
1376 ndlp->nlp_type |= NLP_FCP_TARGET;
1377 if (npr->Retry)
1378 ndlp->nlp_fcp_info |= NLP_FCP_2_DEVICE;
1379 }
James Smart92d7f7b2007-06-17 19:56:38 -05001380 if (!(ndlp->nlp_type & NLP_FCP_TARGET) &&
1381 (vport->port_type == LPFC_NPIV_PORT) &&
James Smart3de2a652007-08-02 11:09:59 -04001382 vport->cfg_restrict_login) {
James Smart858c9f62007-06-17 19:56:39 -05001383out:
James Smart92d7f7b2007-06-17 19:56:38 -05001384 spin_lock_irq(shost->host_lock);
1385 ndlp->nlp_flag |= NLP_TARGET_REMOVE;
1386 spin_unlock_irq(shost->host_lock);
1387 lpfc_issue_els_logo(vport, ndlp, 0);
1388
1389 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
1390 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNUSED_NODE);
1391 return ndlp->nlp_state;
1392 }
dea31012005-04-17 16:05:31 -05001393
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001394 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
James Smart92d7f7b2007-06-17 19:56:38 -05001395 if (ndlp->nlp_type & NLP_FCP_TARGET)
1396 lpfc_nlp_set_state(vport, ndlp, NLP_STE_MAPPED_NODE);
1397 else
1398 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001399 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001400}
1401
1402/*! lpfc_device_rm_prli_issue
James Smart92d7f7b2007-06-17 19:56:38 -05001403 *
1404 * \pre
1405 * \post
1406 * \param phba
1407 * \param ndlp
1408 * \param arg
1409 * \param evt
1410 * \return uint32_t
1411 *
1412 * \b Description:
1413 * This routine is envoked when we a request to remove a nport we are in the
1414 * process of PRLIing. We should software abort outstanding prli, unreg
1415 * login, send a logout. We will change node state to UNUSED_NODE, put it
1416 * on plogi list so it can be freed when LOGO completes.
1417 *
1418 */
1419
dea31012005-04-17 16:05:31 -05001420static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001421lpfc_device_rm_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1422 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001423{
James Smart2e0fef82007-06-17 19:56:36 -05001424 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001425
James Smart2e0fef82007-06-17 19:56:36 -05001426 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1427 spin_lock_irq(shost->host_lock);
1428 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
1429 spin_unlock_irq(shost->host_lock);
1430 return ndlp->nlp_state;
1431 } else {
1432 /* software abort outstanding PLOGI */
1433 lpfc_els_abort(vport->phba, ndlp);
1434
1435 lpfc_drop_node(vport, ndlp);
James Smarta0f9b482006-04-15 11:52:56 -04001436 return NLP_STE_FREED_NODE;
1437 }
dea31012005-04-17 16:05:31 -05001438}
1439
1440
1441/*! lpfc_device_recov_prli_issue
James Smart92d7f7b2007-06-17 19:56:38 -05001442 *
1443 * \pre
1444 * \post
1445 * \param phba
1446 * \param ndlp
1447 * \param arg
1448 * \param evt
1449 * \return uint32_t
1450 *
1451 * \b Description:
1452 * The routine is envoked when the state of a device is unknown, like
1453 * during a link down. We should remove the nodelist entry from the
1454 * unmapped list, issue a UNREG_LOGIN, do a software abort of the
1455 * outstanding PRLI command, then free the node entry.
1456 */
dea31012005-04-17 16:05:31 -05001457static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001458lpfc_device_recov_prli_issue(struct lpfc_vport *vport,
1459 struct lpfc_nodelist *ndlp,
1460 void *arg,
1461 uint32_t evt)
dea31012005-04-17 16:05:31 -05001462{
James Smart2e0fef82007-06-17 19:56:36 -05001463 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1464 struct lpfc_hba *phba = vport->phba;
1465
James Smart92d7f7b2007-06-17 19:56:38 -05001466 /* Don't do anything that will mess up processing of the
1467 * previous RSCN.
1468 */
1469 if (vport->fc_flag & FC_RSCN_DEFERRED)
1470 return ndlp->nlp_state;
1471
dea31012005-04-17 16:05:31 -05001472 /* software abort outstanding PRLI */
James Smart07951072007-04-25 09:51:38 -04001473 lpfc_els_abort(phba, ndlp);
dea31012005-04-17 16:05:31 -05001474
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001475 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -05001476 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1477 spin_lock_irq(shost->host_lock);
James Smarta0f9b482006-04-15 11:52:56 -04001478 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
James Smart2e0fef82007-06-17 19:56:36 -05001479 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05001480 lpfc_disc_set_adisc(vport, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001481 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001482}
1483
1484static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001485lpfc_rcv_plogi_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1486 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001487{
James Smart2e0fef82007-06-17 19:56:36 -05001488 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001489
James Smart2e0fef82007-06-17 19:56:36 -05001490 lpfc_rcv_plogi(vport, ndlp, cmdiocb);
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_prli_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_prli(vport, ndlp, cmdiocb);
1501 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001502 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001503}
1504
1505static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001506lpfc_rcv_logo_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1507 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001508{
James Smart2e0fef82007-06-17 19:56:36 -05001509 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001510
James Smart2e0fef82007-06-17 19:56:36 -05001511 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001512 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001513}
1514
1515static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001516lpfc_rcv_padisc_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1517 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001518{
James Smart2e0fef82007-06-17 19:56:36 -05001519 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001520
James Smart2e0fef82007-06-17 19:56:36 -05001521 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001522 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001523}
1524
1525static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001526lpfc_rcv_prlo_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1527 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001528{
James Smart2e0fef82007-06-17 19:56:36 -05001529 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001530
James Smart2e0fef82007-06-17 19:56:36 -05001531 lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL, 0);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001532 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001533}
1534
1535static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001536lpfc_device_recov_unmap_node(struct lpfc_vport *vport,
1537 struct lpfc_nodelist *ndlp,
1538 void *arg,
1539 uint32_t evt)
dea31012005-04-17 16:05:31 -05001540{
James Smart2e0fef82007-06-17 19:56:36 -05001541 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1542
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001543 ndlp->nlp_prev_state = NLP_STE_UNMAPPED_NODE;
James Smart2e0fef82007-06-17 19:56:36 -05001544 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1545 spin_lock_irq(shost->host_lock);
James Smarta0f9b482006-04-15 11:52:56 -04001546 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
James Smart2e0fef82007-06-17 19:56:36 -05001547 spin_unlock_irq(shost->host_lock);
1548 lpfc_disc_set_adisc(vport, ndlp);
dea31012005-04-17 16:05:31 -05001549
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001550 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001551}
1552
1553static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001554lpfc_rcv_plogi_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1555 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001556{
James Smart2e0fef82007-06-17 19:56:36 -05001557 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001558
James Smart2e0fef82007-06-17 19:56:36 -05001559 lpfc_rcv_plogi(vport, ndlp, cmdiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001560 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001561}
1562
1563static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001564lpfc_rcv_prli_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1565 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001566{
James Smart2e0fef82007-06-17 19:56:36 -05001567 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001568
James Smart2e0fef82007-06-17 19:56:36 -05001569 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001570 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001571}
1572
1573static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001574lpfc_rcv_logo_mapped_node(struct lpfc_vport *vport, 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_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
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_padisc_mapped_node(struct lpfc_vport *vport,
1585 struct lpfc_nodelist *ndlp,
1586 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001587{
James Smart2e0fef82007-06-17 19:56:36 -05001588 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001589
James Smart2e0fef82007-06-17 19:56:36 -05001590 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001591 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001592}
1593
1594static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001595lpfc_rcv_prlo_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1596 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001597{
James Smart2e0fef82007-06-17 19:56:36 -05001598 struct lpfc_hba *phba = vport->phba;
1599 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001600
1601 /* flush the target */
dea31012005-04-17 16:05:31 -05001602 lpfc_sli_abort_iocb(phba, &phba->sli.ring[phba->sli.fcp_ring],
James Smart92d7f7b2007-06-17 19:56:38 -05001603 ndlp->nlp_sid, 0, 0, LPFC_CTX_TGT);
dea31012005-04-17 16:05:31 -05001604
1605 /* Treat like rcv logo */
James Smart2e0fef82007-06-17 19:56:36 -05001606 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_PRLO);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001607 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001608}
1609
1610static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001611lpfc_device_recov_mapped_node(struct lpfc_vport *vport,
1612 struct lpfc_nodelist *ndlp,
1613 void *arg,
1614 uint32_t evt)
dea31012005-04-17 16:05:31 -05001615{
James Smart2e0fef82007-06-17 19:56:36 -05001616 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1617
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001618 ndlp->nlp_prev_state = NLP_STE_MAPPED_NODE;
James Smart2e0fef82007-06-17 19:56:36 -05001619 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1620 spin_lock_irq(shost->host_lock);
James Smarta0f9b482006-04-15 11:52:56 -04001621 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
James Smart2e0fef82007-06-17 19:56:36 -05001622 spin_unlock_irq(shost->host_lock);
1623 lpfc_disc_set_adisc(vport, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001624 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001625}
1626
1627static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001628lpfc_rcv_plogi_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1629 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001630{
James Smart2e0fef82007-06-17 19:56:36 -05001631 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1632 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001633
1634 /* Ignore PLOGI if we have an outstanding LOGO */
James Smart858c9f62007-06-17 19:56:39 -05001635 if (ndlp->nlp_flag & (NLP_LOGO_SND | NLP_LOGO_ACC)) {
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001636 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001637 }
1638
James Smart2e0fef82007-06-17 19:56:36 -05001639 if (lpfc_rcv_plogi(vport, ndlp, cmdiocb)) {
1640 spin_lock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05001641 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
James Smart2e0fef82007-06-17 19:56:36 -05001642 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001643 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001644 }
1645
1646 /* send PLOGI immediately, move to PLOGI issue state */
1647 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
James Smart488d1462006-03-07 15:02:37 -05001648 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
James Smart2e0fef82007-06-17 19:56:36 -05001649 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
1650 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
dea31012005-04-17 16:05:31 -05001651 }
James Smart488d1462006-03-07 15:02:37 -05001652
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001653 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001654}
1655
1656static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001657lpfc_rcv_prli_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1658 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001659{
James Smart2e0fef82007-06-17 19:56:36 -05001660 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1661 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1662 struct ls_rjt stat;
dea31012005-04-17 16:05:31 -05001663
1664 memset(&stat, 0, sizeof (struct ls_rjt));
1665 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
1666 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
James Smart858c9f62007-06-17 19:56:39 -05001667 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05001668
1669 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
1670 if (ndlp->nlp_flag & NLP_NPR_ADISC) {
James Smart2e0fef82007-06-17 19:56:36 -05001671 spin_lock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001672 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001673 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
James Smart2e0fef82007-06-17 19:56:36 -05001674 spin_unlock_irq(shost->host_lock);
1675 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
1676 lpfc_issue_els_adisc(vport, ndlp, 0);
dea31012005-04-17 16:05:31 -05001677 } else {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001678 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
James Smart2e0fef82007-06-17 19:56:36 -05001679 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
1680 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
dea31012005-04-17 16:05:31 -05001681 }
1682 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001683 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001684}
1685
1686static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001687lpfc_rcv_logo_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1688 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001689{
James Smart2e0fef82007-06-17 19:56:36 -05001690 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001691
James Smart2e0fef82007-06-17 19:56:36 -05001692 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001693 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001694}
1695
1696static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001697lpfc_rcv_padisc_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1698 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001699{
James Smart2e0fef82007-06-17 19:56:36 -05001700 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001701
James Smart2e0fef82007-06-17 19:56:36 -05001702 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
dea31012005-04-17 16:05:31 -05001703
James Smart33ccf8d2006-08-17 11:57:58 -04001704 /*
1705 * Do not start discovery if discovery is about to start
1706 * or discovery in progress for this node. Starting discovery
1707 * here will affect the counting of discovery threads.
1708 */
James Smart2fb9bd82006-12-02 13:33:57 -05001709 if (!(ndlp->nlp_flag & NLP_DELAY_TMO) &&
James Smart92d7f7b2007-06-17 19:56:38 -05001710 !(ndlp->nlp_flag & NLP_NPR_2B_DISC)) {
dea31012005-04-17 16:05:31 -05001711 if (ndlp->nlp_flag & NLP_NPR_ADISC) {
James Smart92d7f7b2007-06-17 19:56:38 -05001712 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001713 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
James Smart2e0fef82007-06-17 19:56:36 -05001714 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
1715 lpfc_issue_els_adisc(vport, ndlp, 0);
dea31012005-04-17 16:05:31 -05001716 } else {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001717 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
James Smart2e0fef82007-06-17 19:56:36 -05001718 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
1719 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
dea31012005-04-17 16:05:31 -05001720 }
1721 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001722 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001723}
1724
1725static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001726lpfc_rcv_prlo_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1727 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001728{
James Smart2e0fef82007-06-17 19:56:36 -05001729 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1730 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001731
James Smart2e0fef82007-06-17 19:56:36 -05001732 spin_lock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001733 ndlp->nlp_flag |= NLP_LOGO_ACC;
James Smart2e0fef82007-06-17 19:56:36 -05001734 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001735
James Smart2e0fef82007-06-17 19:56:36 -05001736 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL, 0);
dea31012005-04-17 16:05:31 -05001737
James Smart2e0fef82007-06-17 19:56:36 -05001738 if ((ndlp->nlp_flag & NLP_DELAY_TMO) == 0) {
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001739 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ * 1);
James Smart2e0fef82007-06-17 19:56:36 -05001740 spin_lock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001741 ndlp->nlp_flag |= NLP_DELAY_TMO;
1742 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
James Smart2e0fef82007-06-17 19:56:36 -05001743 spin_unlock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001744 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001745 } else {
James Smart2e0fef82007-06-17 19:56:36 -05001746 spin_lock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001747 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
James Smart2e0fef82007-06-17 19:56:36 -05001748 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001749 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001750 return ndlp->nlp_state;
1751}
dea31012005-04-17 16:05:31 -05001752
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001753static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001754lpfc_cmpl_plogi_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1755 void *arg, uint32_t evt)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001756{
1757 struct lpfc_iocbq *cmdiocb, *rspiocb;
James Smarta0f9b482006-04-15 11:52:56 -04001758 IOCB_t *irsp;
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001759
1760 cmdiocb = (struct lpfc_iocbq *) arg;
1761 rspiocb = cmdiocb->context_un.rsp_iocb;
James Smarta0f9b482006-04-15 11:52:56 -04001762
1763 irsp = &rspiocb->iocb;
1764 if (irsp->ulpStatus) {
James Smart2e0fef82007-06-17 19:56:36 -05001765 lpfc_drop_node(vport, ndlp);
James Smarta0f9b482006-04-15 11:52:56 -04001766 return NLP_STE_FREED_NODE;
1767 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001768 return ndlp->nlp_state;
1769}
1770
1771static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001772lpfc_cmpl_prli_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1773 void *arg, uint32_t evt)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001774{
1775 struct lpfc_iocbq *cmdiocb, *rspiocb;
James Smarta0f9b482006-04-15 11:52:56 -04001776 IOCB_t *irsp;
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001777
1778 cmdiocb = (struct lpfc_iocbq *) arg;
1779 rspiocb = cmdiocb->context_un.rsp_iocb;
James Smarta0f9b482006-04-15 11:52:56 -04001780
1781 irsp = &rspiocb->iocb;
1782 if (irsp->ulpStatus && (ndlp->nlp_flag & NLP_NODEV_REMOVE)) {
James Smart2e0fef82007-06-17 19:56:36 -05001783 lpfc_drop_node(vport, ndlp);
James Smarta0f9b482006-04-15 11:52:56 -04001784 return NLP_STE_FREED_NODE;
1785 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001786 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001787}
1788
1789static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001790lpfc_cmpl_logo_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1791 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001792{
James Smart2e0fef82007-06-17 19:56:36 -05001793 lpfc_unreg_rpi(vport, ndlp);
dea31012005-04-17 16:05:31 -05001794 /* This routine does nothing, just return the current state */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001795 return ndlp->nlp_state;
1796}
1797
1798static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001799lpfc_cmpl_adisc_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1800 void *arg, uint32_t evt)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001801{
1802 struct lpfc_iocbq *cmdiocb, *rspiocb;
James Smarta0f9b482006-04-15 11:52:56 -04001803 IOCB_t *irsp;
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001804
1805 cmdiocb = (struct lpfc_iocbq *) arg;
1806 rspiocb = cmdiocb->context_un.rsp_iocb;
James Smarta0f9b482006-04-15 11:52:56 -04001807
1808 irsp = &rspiocb->iocb;
1809 if (irsp->ulpStatus && (ndlp->nlp_flag & NLP_NODEV_REMOVE)) {
James Smart2e0fef82007-06-17 19:56:36 -05001810 lpfc_drop_node(vport, ndlp);
James Smarta0f9b482006-04-15 11:52:56 -04001811 return NLP_STE_FREED_NODE;
1812 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001813 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001814}
1815
1816static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001817lpfc_cmpl_reglogin_npr_node(struct lpfc_vport *vport,
1818 struct lpfc_nodelist *ndlp,
1819 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001820{
James Smart2e0fef82007-06-17 19:56:36 -05001821 LPFC_MBOXQ_t *pmb = (LPFC_MBOXQ_t *) arg;
1822 MAILBOX_t *mb = &pmb->mb;
dea31012005-04-17 16:05:31 -05001823
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001824 if (!mb->mbxStatus)
1825 ndlp->nlp_rpi = mb->un.varWords[0];
James Smarta0f9b482006-04-15 11:52:56 -04001826 else {
1827 if (ndlp->nlp_flag & NLP_NODEV_REMOVE) {
James Smart2e0fef82007-06-17 19:56:36 -05001828 lpfc_drop_node(vport, ndlp);
James Smarta0f9b482006-04-15 11:52:56 -04001829 return NLP_STE_FREED_NODE;
1830 }
1831 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001832 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001833}
1834
1835static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001836lpfc_device_rm_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1837 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001838{
James Smart2e0fef82007-06-17 19:56:36 -05001839 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1840
James Smarta0f9b482006-04-15 11:52:56 -04001841 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
James Smart2e0fef82007-06-17 19:56:36 -05001842 spin_lock_irq(shost->host_lock);
James Smarta0f9b482006-04-15 11:52:56 -04001843 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
James Smart2e0fef82007-06-17 19:56:36 -05001844 spin_unlock_irq(shost->host_lock);
James Smarta0f9b482006-04-15 11:52:56 -04001845 return ndlp->nlp_state;
1846 }
James Smart2e0fef82007-06-17 19:56:36 -05001847 lpfc_drop_node(vport, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001848 return NLP_STE_FREED_NODE;
dea31012005-04-17 16:05:31 -05001849}
1850
1851static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001852lpfc_device_recov_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1853 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001854{
James Smart2e0fef82007-06-17 19:56:36 -05001855 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1856
James Smart92d7f7b2007-06-17 19:56:38 -05001857 /* Don't do anything that will mess up processing of the
1858 * previous RSCN.
1859 */
1860 if (vport->fc_flag & FC_RSCN_DEFERRED)
1861 return ndlp->nlp_state;
1862
James Smart2e0fef82007-06-17 19:56:36 -05001863 spin_lock_irq(shost->host_lock);
James Smarta0f9b482006-04-15 11:52:56 -04001864 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
James Smart2e0fef82007-06-17 19:56:36 -05001865 spin_unlock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05001866 if (ndlp->nlp_flag & NLP_DELAY_TMO) {
James Smart2e0fef82007-06-17 19:56:36 -05001867 lpfc_cancel_retry_delay_tmo(vport, ndlp);
James Smartfdcebe22006-03-07 15:04:01 -05001868 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001869 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001870}
1871
1872
1873/* This next section defines the NPort Discovery State Machine */
1874
1875/* There are 4 different double linked lists nodelist entries can reside on.
1876 * The plogi list and adisc list are used when Link Up discovery or RSCN
1877 * processing is needed. Each list holds the nodes that we will send PLOGI
1878 * or ADISC on. These lists will keep track of what nodes will be effected
1879 * by an RSCN, or a Link Up (Typically, all nodes are effected on Link Up).
1880 * The unmapped_list will contain all nodes that we have successfully logged
1881 * into at the Fibre Channel level. The mapped_list will contain all nodes
1882 * that are mapped FCP targets.
1883 */
1884/*
1885 * The bind list is a list of undiscovered (potentially non-existent) nodes
1886 * that we have saved binding information on. This information is used when
1887 * nodes transition from the unmapped to the mapped list.
1888 */
1889/* For UNUSED_NODE state, the node has just been allocated .
1890 * For PLOGI_ISSUE and REG_LOGIN_ISSUE, the node is on
1891 * the PLOGI list. For REG_LOGIN_COMPL, the node is taken off the PLOGI list
1892 * and put on the unmapped list. For ADISC processing, the node is taken off
1893 * the ADISC list and placed on either the mapped or unmapped list (depending
1894 * on its previous state). Once on the unmapped list, a PRLI is issued and the
1895 * state changed to PRLI_ISSUE. When the PRLI completion occurs, the state is
1896 * changed to UNMAPPED_NODE. If the completion indicates a mapped
1897 * node, the node is taken off the unmapped list. The binding list is checked
1898 * for a valid binding, or a binding is automatically assigned. If binding
1899 * assignment is unsuccessful, the node is left on the unmapped list. If
1900 * binding assignment is successful, the associated binding list entry (if
1901 * any) is removed, and the node is placed on the mapped list.
1902 */
1903/*
1904 * For a Link Down, all nodes on the ADISC, PLOGI, unmapped or mapped
James Smartc01f3202006-08-18 17:47:08 -04001905 * lists will receive a DEVICE_RECOVERY event. If the linkdown or devloss timers
dea31012005-04-17 16:05:31 -05001906 * expire, all effected nodes will receive a DEVICE_RM event.
1907 */
1908/*
1909 * For a Link Up or RSCN, all nodes will move from the mapped / unmapped lists
1910 * to either the ADISC or PLOGI list. After a Nameserver query or ALPA loopmap
1911 * check, additional nodes may be added or removed (via DEVICE_RM) to / from
1912 * the PLOGI or ADISC lists. Once the PLOGI and ADISC lists are populated,
1913 * we will first process the ADISC list. 32 entries are processed initially and
1914 * ADISC is initited for each one. Completions / Events for each node are
1915 * funnelled thru the state machine. As each node finishes ADISC processing, it
1916 * starts ADISC for any nodes waiting for ADISC processing. If no nodes are
1917 * waiting, and the ADISC list count is identically 0, then we are done. For
1918 * Link Up discovery, since all nodes on the PLOGI list are UNREG_LOGIN'ed, we
1919 * can issue a CLEAR_LA and reenable Link Events. Next we will process the PLOGI
1920 * list. 32 entries are processed initially and PLOGI is initited for each one.
1921 * Completions / Events for each node are funnelled thru the state machine. As
1922 * each node finishes PLOGI processing, it starts PLOGI for any nodes waiting
1923 * for PLOGI processing. If no nodes are waiting, and the PLOGI list count is
1924 * indentically 0, then we are done. We have now completed discovery / RSCN
1925 * handling. Upon completion, ALL nodes should be on either the mapped or
1926 * unmapped lists.
1927 */
1928
1929static uint32_t (*lpfc_disc_action[NLP_STE_MAX_STATE * NLP_EVT_MAX_EVENT])
James Smart2e0fef82007-06-17 19:56:36 -05001930 (struct lpfc_vport *, struct lpfc_nodelist *, void *, uint32_t) = {
dea31012005-04-17 16:05:31 -05001931 /* Action routine Event Current State */
1932 lpfc_rcv_plogi_unused_node, /* RCV_PLOGI UNUSED_NODE */
1933 lpfc_rcv_els_unused_node, /* RCV_PRLI */
1934 lpfc_rcv_logo_unused_node, /* RCV_LOGO */
1935 lpfc_rcv_els_unused_node, /* RCV_ADISC */
1936 lpfc_rcv_els_unused_node, /* RCV_PDISC */
1937 lpfc_rcv_els_unused_node, /* RCV_PRLO */
1938 lpfc_disc_illegal, /* CMPL_PLOGI */
1939 lpfc_disc_illegal, /* CMPL_PRLI */
1940 lpfc_cmpl_logo_unused_node, /* CMPL_LOGO */
1941 lpfc_disc_illegal, /* CMPL_ADISC */
1942 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
1943 lpfc_device_rm_unused_node, /* DEVICE_RM */
1944 lpfc_disc_illegal, /* DEVICE_RECOVERY */
1945
1946 lpfc_rcv_plogi_plogi_issue, /* RCV_PLOGI PLOGI_ISSUE */
James Smart92d7f7b2007-06-17 19:56:38 -05001947 lpfc_rcv_prli_plogi_issue, /* RCV_PRLI */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001948 lpfc_rcv_logo_plogi_issue, /* RCV_LOGO */
dea31012005-04-17 16:05:31 -05001949 lpfc_rcv_els_plogi_issue, /* RCV_ADISC */
1950 lpfc_rcv_els_plogi_issue, /* RCV_PDISC */
1951 lpfc_rcv_els_plogi_issue, /* RCV_PRLO */
1952 lpfc_cmpl_plogi_plogi_issue, /* CMPL_PLOGI */
1953 lpfc_disc_illegal, /* CMPL_PRLI */
1954 lpfc_disc_illegal, /* CMPL_LOGO */
1955 lpfc_disc_illegal, /* CMPL_ADISC */
1956 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
1957 lpfc_device_rm_plogi_issue, /* DEVICE_RM */
1958 lpfc_device_recov_plogi_issue, /* DEVICE_RECOVERY */
1959
1960 lpfc_rcv_plogi_adisc_issue, /* RCV_PLOGI ADISC_ISSUE */
1961 lpfc_rcv_prli_adisc_issue, /* RCV_PRLI */
1962 lpfc_rcv_logo_adisc_issue, /* RCV_LOGO */
1963 lpfc_rcv_padisc_adisc_issue, /* RCV_ADISC */
1964 lpfc_rcv_padisc_adisc_issue, /* RCV_PDISC */
1965 lpfc_rcv_prlo_adisc_issue, /* RCV_PRLO */
1966 lpfc_disc_illegal, /* CMPL_PLOGI */
1967 lpfc_disc_illegal, /* CMPL_PRLI */
1968 lpfc_disc_illegal, /* CMPL_LOGO */
1969 lpfc_cmpl_adisc_adisc_issue, /* CMPL_ADISC */
1970 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
1971 lpfc_device_rm_adisc_issue, /* DEVICE_RM */
1972 lpfc_device_recov_adisc_issue, /* DEVICE_RECOVERY */
1973
1974 lpfc_rcv_plogi_reglogin_issue, /* RCV_PLOGI REG_LOGIN_ISSUE */
1975 lpfc_rcv_prli_reglogin_issue, /* RCV_PLOGI */
1976 lpfc_rcv_logo_reglogin_issue, /* RCV_LOGO */
1977 lpfc_rcv_padisc_reglogin_issue, /* RCV_ADISC */
1978 lpfc_rcv_padisc_reglogin_issue, /* RCV_PDISC */
1979 lpfc_rcv_prlo_reglogin_issue, /* RCV_PRLO */
1980 lpfc_disc_illegal, /* CMPL_PLOGI */
1981 lpfc_disc_illegal, /* CMPL_PRLI */
1982 lpfc_disc_illegal, /* CMPL_LOGO */
1983 lpfc_disc_illegal, /* CMPL_ADISC */
1984 lpfc_cmpl_reglogin_reglogin_issue,/* CMPL_REG_LOGIN */
1985 lpfc_device_rm_reglogin_issue, /* DEVICE_RM */
1986 lpfc_device_recov_reglogin_issue,/* DEVICE_RECOVERY */
1987
1988 lpfc_rcv_plogi_prli_issue, /* RCV_PLOGI PRLI_ISSUE */
1989 lpfc_rcv_prli_prli_issue, /* RCV_PRLI */
1990 lpfc_rcv_logo_prli_issue, /* RCV_LOGO */
1991 lpfc_rcv_padisc_prli_issue, /* RCV_ADISC */
1992 lpfc_rcv_padisc_prli_issue, /* RCV_PDISC */
1993 lpfc_rcv_prlo_prli_issue, /* RCV_PRLO */
1994 lpfc_disc_illegal, /* CMPL_PLOGI */
1995 lpfc_cmpl_prli_prli_issue, /* CMPL_PRLI */
1996 lpfc_disc_illegal, /* CMPL_LOGO */
1997 lpfc_disc_illegal, /* CMPL_ADISC */
1998 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
1999 lpfc_device_rm_prli_issue, /* DEVICE_RM */
2000 lpfc_device_recov_prli_issue, /* DEVICE_RECOVERY */
2001
2002 lpfc_rcv_plogi_unmap_node, /* RCV_PLOGI UNMAPPED_NODE */
2003 lpfc_rcv_prli_unmap_node, /* RCV_PRLI */
2004 lpfc_rcv_logo_unmap_node, /* RCV_LOGO */
2005 lpfc_rcv_padisc_unmap_node, /* RCV_ADISC */
2006 lpfc_rcv_padisc_unmap_node, /* RCV_PDISC */
2007 lpfc_rcv_prlo_unmap_node, /* RCV_PRLO */
2008 lpfc_disc_illegal, /* CMPL_PLOGI */
2009 lpfc_disc_illegal, /* CMPL_PRLI */
2010 lpfc_disc_illegal, /* CMPL_LOGO */
2011 lpfc_disc_illegal, /* CMPL_ADISC */
2012 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2013 lpfc_disc_illegal, /* DEVICE_RM */
2014 lpfc_device_recov_unmap_node, /* DEVICE_RECOVERY */
2015
2016 lpfc_rcv_plogi_mapped_node, /* RCV_PLOGI MAPPED_NODE */
2017 lpfc_rcv_prli_mapped_node, /* RCV_PRLI */
2018 lpfc_rcv_logo_mapped_node, /* RCV_LOGO */
2019 lpfc_rcv_padisc_mapped_node, /* RCV_ADISC */
2020 lpfc_rcv_padisc_mapped_node, /* RCV_PDISC */
2021 lpfc_rcv_prlo_mapped_node, /* RCV_PRLO */
2022 lpfc_disc_illegal, /* CMPL_PLOGI */
2023 lpfc_disc_illegal, /* CMPL_PRLI */
2024 lpfc_disc_illegal, /* CMPL_LOGO */
2025 lpfc_disc_illegal, /* CMPL_ADISC */
2026 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2027 lpfc_disc_illegal, /* DEVICE_RM */
2028 lpfc_device_recov_mapped_node, /* DEVICE_RECOVERY */
2029
2030 lpfc_rcv_plogi_npr_node, /* RCV_PLOGI NPR_NODE */
2031 lpfc_rcv_prli_npr_node, /* RCV_PRLI */
2032 lpfc_rcv_logo_npr_node, /* RCV_LOGO */
2033 lpfc_rcv_padisc_npr_node, /* RCV_ADISC */
2034 lpfc_rcv_padisc_npr_node, /* RCV_PDISC */
2035 lpfc_rcv_prlo_npr_node, /* RCV_PRLO */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002036 lpfc_cmpl_plogi_npr_node, /* CMPL_PLOGI */
2037 lpfc_cmpl_prli_npr_node, /* CMPL_PRLI */
dea31012005-04-17 16:05:31 -05002038 lpfc_cmpl_logo_npr_node, /* CMPL_LOGO */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002039 lpfc_cmpl_adisc_npr_node, /* CMPL_ADISC */
dea31012005-04-17 16:05:31 -05002040 lpfc_cmpl_reglogin_npr_node, /* CMPL_REG_LOGIN */
2041 lpfc_device_rm_npr_node, /* DEVICE_RM */
2042 lpfc_device_recov_npr_node, /* DEVICE_RECOVERY */
2043};
2044
2045int
James Smart2e0fef82007-06-17 19:56:36 -05002046lpfc_disc_state_machine(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2047 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05002048{
James Smart2e0fef82007-06-17 19:56:36 -05002049 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002050 uint32_t cur_state, rc;
James Smart2e0fef82007-06-17 19:56:36 -05002051 uint32_t(*func) (struct lpfc_vport *, struct lpfc_nodelist *, void *,
dea31012005-04-17 16:05:31 -05002052 uint32_t);
2053
James Smart329f9bc2007-04-25 09:53:01 -04002054 lpfc_nlp_get(ndlp);
dea31012005-04-17 16:05:31 -05002055 cur_state = ndlp->nlp_state;
2056
2057 /* DSM in event <evt> on NPort <nlp_DID> in state <cur_state> */
James Smarted957682007-06-17 19:56:37 -05002058 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
James Smart92d7f7b2007-06-17 19:56:38 -05002059 "%d (%d):0211 DSM in event x%x on NPort x%x in "
2060 "state %d Data: x%x\n",
2061 phba->brd_no, vport->vpi,
dea31012005-04-17 16:05:31 -05002062 evt, ndlp->nlp_DID, cur_state, ndlp->nlp_flag);
2063
James Smart858c9f62007-06-17 19:56:39 -05002064 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_DSM,
2065 "DSM in: evt:%d ste:%d did:x%x",
2066 evt, cur_state, ndlp->nlp_DID);
2067
dea31012005-04-17 16:05:31 -05002068 func = lpfc_disc_action[(cur_state * NLP_EVT_MAX_EVENT) + evt];
James Smart2e0fef82007-06-17 19:56:36 -05002069 rc = (func) (vport, ndlp, arg, evt);
dea31012005-04-17 16:05:31 -05002070
2071 /* DSM out state <rc> on NPort <nlp_DID> */
James Smarted957682007-06-17 19:56:37 -05002072 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
James Smart92d7f7b2007-06-17 19:56:38 -05002073 "%d (%d):0212 DSM out state %d on NPort x%x "
2074 "Data: x%x\n",
2075 phba->brd_no, vport->vpi,
2076 rc, ndlp->nlp_DID, ndlp->nlp_flag);
dea31012005-04-17 16:05:31 -05002077
James Smart858c9f62007-06-17 19:56:39 -05002078 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_DSM,
2079 "DSM out: ste:%d did:x%x flg:x%x",
2080 rc, ndlp->nlp_DID, ndlp->nlp_flag);
2081
James Smart329f9bc2007-04-25 09:53:01 -04002082 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05002083
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002084 return rc;
dea31012005-04-17 16:05:31 -05002085}