blob: 08cdc77af41c12f42f34ab2da799f1f678811d7b [file] [log] [blame]
James Smart92d7f7b2007-06-17 19:56:38 -05001 /*******************************************************************
dea31012005-04-17 16:05:31 -05002 * This file is part of the Emulex Linux Device Driver for *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04003 * Fibre Channel Host Bus Adapters. *
James Smarte47c9092008-02-08 18:49:26 -05004 * Copyright (C) 2004-2008 Emulex. All rights reserved. *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04005 * EMULEX and SLI are trademarks of Emulex. *
dea31012005-04-17 16:05:31 -05006 * www.emulex.com *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04007 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
dea31012005-04-17 16:05:31 -05008 * *
9 * This program is free software; you can redistribute it and/or *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -040010 * modify it under the terms of version 2 of the GNU General *
11 * Public License as published by the Free Software Foundation. *
12 * This program is distributed in the hope that it will be useful. *
13 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
14 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
15 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
16 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
17 * TO BE LEGALLY INVALID. See the GNU General Public License for *
18 * more details, a copy of which can be found in the file COPYING *
19 * included with this package. *
dea31012005-04-17 16:05:31 -050020 *******************************************************************/
21
dea31012005-04-17 16:05:31 -050022#include <linux/blkdev.h>
23#include <linux/pci.h>
24#include <linux/interrupt.h>
25
James.Smart@Emulex.Com91886522005-08-10 15:03:09 -040026#include <scsi/scsi.h>
dea31012005-04-17 16:05:31 -050027#include <scsi/scsi_device.h>
28#include <scsi/scsi_host.h>
29#include <scsi/scsi_transport_fc.h>
30
31#include "lpfc_hw.h"
32#include "lpfc_sli.h"
James Smartea2151b2008-09-07 11:52:10 -040033#include "lpfc_nl.h"
dea31012005-04-17 16:05:31 -050034#include "lpfc_disc.h"
35#include "lpfc_scsi.h"
36#include "lpfc.h"
37#include "lpfc_logmsg.h"
38#include "lpfc_crtn.h"
James Smart92d7f7b2007-06-17 19:56:38 -050039#include "lpfc_vport.h"
James Smart858c9f62007-06-17 19:56:39 -050040#include "lpfc_debugfs.h"
dea31012005-04-17 16:05:31 -050041
42
43/* Called to verify a rcv'ed ADISC was intended for us. */
44static int
James Smart2e0fef82007-06-17 19:56:36 -050045lpfc_check_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
46 struct lpfc_name *nn, struct lpfc_name *pn)
dea31012005-04-17 16:05:31 -050047{
48 /* Compare the ADISC rsp WWNN / WWPN matches our internal node
49 * table entry for that node.
50 */
James Smart2e0fef82007-06-17 19:56:36 -050051 if (memcmp(nn, &ndlp->nlp_nodename, sizeof (struct lpfc_name)))
Jamie Wellnitzc9f87352006-02-28 19:25:23 -050052 return 0;
dea31012005-04-17 16:05:31 -050053
James Smart2e0fef82007-06-17 19:56:36 -050054 if (memcmp(pn, &ndlp->nlp_portname, sizeof (struct lpfc_name)))
Jamie Wellnitzc9f87352006-02-28 19:25:23 -050055 return 0;
dea31012005-04-17 16:05:31 -050056
57 /* we match, return success */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -050058 return 1;
dea31012005-04-17 16:05:31 -050059}
60
dea31012005-04-17 16:05:31 -050061int
James Smart2e0fef82007-06-17 19:56:36 -050062lpfc_check_sparm(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
63 struct serv_parm * sp, uint32_t class)
dea31012005-04-17 16:05:31 -050064{
James Smart2e0fef82007-06-17 19:56:36 -050065 volatile struct serv_parm *hsp = &vport->fc_sparam;
James.Smart@Emulex.Com2fb70f72005-11-28 11:41:24 -050066 uint16_t hsp_value, ssp_value = 0;
dea31012005-04-17 16:05:31 -050067
James.Smart@Emulex.Com2fb70f72005-11-28 11:41:24 -050068 /*
69 * The receive data field size and buffer-to-buffer receive data field
70 * size entries are 16 bits but are represented as two 8-bit fields in
71 * the driver data structure to account for rsvd bits and other control
72 * bits. Reconstruct and compare the fields as a 16-bit values before
73 * correcting the byte values.
74 */
dea31012005-04-17 16:05:31 -050075 if (sp->cls1.classValid) {
James.Smart@Emulex.Com2fb70f72005-11-28 11:41:24 -050076 hsp_value = (hsp->cls1.rcvDataSizeMsb << 8) |
77 hsp->cls1.rcvDataSizeLsb;
78 ssp_value = (sp->cls1.rcvDataSizeMsb << 8) |
79 sp->cls1.rcvDataSizeLsb;
James Smart92d7f7b2007-06-17 19:56:38 -050080 if (!ssp_value)
81 goto bad_service_param;
James.Smart@Emulex.Com2fb70f72005-11-28 11:41:24 -050082 if (ssp_value > hsp_value) {
dea31012005-04-17 16:05:31 -050083 sp->cls1.rcvDataSizeLsb = hsp->cls1.rcvDataSizeLsb;
James.Smart@Emulex.Com2fb70f72005-11-28 11:41:24 -050084 sp->cls1.rcvDataSizeMsb = hsp->cls1.rcvDataSizeMsb;
85 }
dea31012005-04-17 16:05:31 -050086 } else if (class == CLASS1) {
James Smart92d7f7b2007-06-17 19:56:38 -050087 goto bad_service_param;
dea31012005-04-17 16:05:31 -050088 }
89
90 if (sp->cls2.classValid) {
James.Smart@Emulex.Com2fb70f72005-11-28 11:41:24 -050091 hsp_value = (hsp->cls2.rcvDataSizeMsb << 8) |
92 hsp->cls2.rcvDataSizeLsb;
93 ssp_value = (sp->cls2.rcvDataSizeMsb << 8) |
94 sp->cls2.rcvDataSizeLsb;
James Smart92d7f7b2007-06-17 19:56:38 -050095 if (!ssp_value)
96 goto bad_service_param;
James.Smart@Emulex.Com2fb70f72005-11-28 11:41:24 -050097 if (ssp_value > hsp_value) {
dea31012005-04-17 16:05:31 -050098 sp->cls2.rcvDataSizeLsb = hsp->cls2.rcvDataSizeLsb;
James.Smart@Emulex.Com2fb70f72005-11-28 11:41:24 -050099 sp->cls2.rcvDataSizeMsb = hsp->cls2.rcvDataSizeMsb;
100 }
dea31012005-04-17 16:05:31 -0500101 } else if (class == CLASS2) {
James Smart92d7f7b2007-06-17 19:56:38 -0500102 goto bad_service_param;
dea31012005-04-17 16:05:31 -0500103 }
104
105 if (sp->cls3.classValid) {
James.Smart@Emulex.Com2fb70f72005-11-28 11:41:24 -0500106 hsp_value = (hsp->cls3.rcvDataSizeMsb << 8) |
107 hsp->cls3.rcvDataSizeLsb;
108 ssp_value = (sp->cls3.rcvDataSizeMsb << 8) |
109 sp->cls3.rcvDataSizeLsb;
James Smart92d7f7b2007-06-17 19:56:38 -0500110 if (!ssp_value)
111 goto bad_service_param;
James.Smart@Emulex.Com2fb70f72005-11-28 11:41:24 -0500112 if (ssp_value > hsp_value) {
dea31012005-04-17 16:05:31 -0500113 sp->cls3.rcvDataSizeLsb = hsp->cls3.rcvDataSizeLsb;
James.Smart@Emulex.Com2fb70f72005-11-28 11:41:24 -0500114 sp->cls3.rcvDataSizeMsb = hsp->cls3.rcvDataSizeMsb;
115 }
dea31012005-04-17 16:05:31 -0500116 } else if (class == CLASS3) {
James Smart92d7f7b2007-06-17 19:56:38 -0500117 goto bad_service_param;
dea31012005-04-17 16:05:31 -0500118 }
119
James.Smart@Emulex.Com2fb70f72005-11-28 11:41:24 -0500120 /*
121 * Preserve the upper four bits of the MSB from the PLOGI response.
122 * These bits contain the Buffer-to-Buffer State Change Number
123 * from the target and need to be passed to the FW.
124 */
125 hsp_value = (hsp->cmn.bbRcvSizeMsb << 8) | hsp->cmn.bbRcvSizeLsb;
126 ssp_value = (sp->cmn.bbRcvSizeMsb << 8) | sp->cmn.bbRcvSizeLsb;
127 if (ssp_value > hsp_value) {
dea31012005-04-17 16:05:31 -0500128 sp->cmn.bbRcvSizeLsb = hsp->cmn.bbRcvSizeLsb;
James.Smart@Emulex.Com2fb70f72005-11-28 11:41:24 -0500129 sp->cmn.bbRcvSizeMsb = (sp->cmn.bbRcvSizeMsb & 0xF0) |
130 (hsp->cmn.bbRcvSizeMsb & 0x0F);
131 }
dea31012005-04-17 16:05:31 -0500132
dea31012005-04-17 16:05:31 -0500133 memcpy(&ndlp->nlp_nodename, &sp->nodeName, sizeof (struct lpfc_name));
134 memcpy(&ndlp->nlp_portname, &sp->portName, sizeof (struct lpfc_name));
James.Smart@Emulex.Com2fb70f72005-11-28 11:41:24 -0500135 return 1;
James Smart92d7f7b2007-06-17 19:56:38 -0500136bad_service_param:
James Smarte8b62012007-08-02 11:10:09 -0400137 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
138 "0207 Device %x "
139 "(%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x) sent "
140 "invalid service parameters. Ignoring device.\n",
141 ndlp->nlp_DID,
142 sp->nodeName.u.wwn[0], sp->nodeName.u.wwn[1],
143 sp->nodeName.u.wwn[2], sp->nodeName.u.wwn[3],
144 sp->nodeName.u.wwn[4], sp->nodeName.u.wwn[5],
145 sp->nodeName.u.wwn[6], sp->nodeName.u.wwn[7]);
James Smart92d7f7b2007-06-17 19:56:38 -0500146 return 0;
dea31012005-04-17 16:05:31 -0500147}
148
149static void *
James Smart2e0fef82007-06-17 19:56:36 -0500150lpfc_check_elscmpl_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -0500151 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -0500152{
153 struct lpfc_dmabuf *pcmd, *prsp;
154 uint32_t *lp;
155 void *ptr = NULL;
156 IOCB_t *irsp;
157
158 irsp = &rspiocb->iocb;
159 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
160
161 /* For lpfc_els_abort, context2 could be zero'ed to delay
162 * freeing associated memory till after ABTS completes.
163 */
164 if (pcmd) {
165 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf,
166 list);
167 if (prsp) {
168 lp = (uint32_t *) prsp->virt;
169 ptr = (void *)((uint8_t *)lp + sizeof(uint32_t));
170 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500171 } else {
dea31012005-04-17 16:05:31 -0500172 /* Force ulpStatus error since we are returning NULL ptr */
173 if (!(irsp->ulpStatus)) {
174 irsp->ulpStatus = IOSTAT_LOCAL_REJECT;
175 irsp->un.ulpWord[4] = IOERR_SLI_ABORTED;
176 }
177 ptr = NULL;
178 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500179 return ptr;
dea31012005-04-17 16:05:31 -0500180}
181
182
183/*
184 * Free resources / clean up outstanding I/Os
185 * associated with a LPFC_NODELIST entry. This
186 * routine effectively results in a "software abort".
187 */
188int
James Smart2e0fef82007-06-17 19:56:36 -0500189lpfc_els_abort(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -0500190{
James Smart2534ba72007-04-25 09:52:20 -0400191 LIST_HEAD(completions);
James Smart2e0fef82007-06-17 19:56:36 -0500192 struct lpfc_sli *psli = &phba->sli;
193 struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING];
dea31012005-04-17 16:05:31 -0500194 struct lpfc_iocbq *iocb, *next_iocb;
dea31012005-04-17 16:05:31 -0500195
196 /* Abort outstanding I/O on NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -0400197 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_DISCOVERY,
198 "0205 Abort outstanding I/O on NPort x%x "
199 "Data: x%x x%x x%x\n",
200 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
201 ndlp->nlp_rpi);
James Smart92d7f7b2007-06-17 19:56:38 -0500202
203 lpfc_fabric_abort_nport(ndlp);
dea31012005-04-17 16:05:31 -0500204
dea31012005-04-17 16:05:31 -0500205 /* First check the txq */
James Smart2e0fef82007-06-17 19:56:36 -0500206 spin_lock_irq(&phba->hbalock);
James Smart2534ba72007-04-25 09:52:20 -0400207 list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
James Smart858c9f62007-06-17 19:56:39 -0500208 /* Check to see if iocb matches the nport we are looking for */
James Smart2534ba72007-04-25 09:52:20 -0400209 if (lpfc_check_sli_ndlp(phba, pring, iocb, ndlp)) {
James Smart858c9f62007-06-17 19:56:39 -0500210 /* It matches, so deque and call compl with anp error */
James Smart2534ba72007-04-25 09:52:20 -0400211 list_move_tail(&iocb->list, &completions);
212 pring->txq_cnt--;
dea31012005-04-17 16:05:31 -0500213 }
James Smart2534ba72007-04-25 09:52:20 -0400214 }
dea31012005-04-17 16:05:31 -0500215
dea31012005-04-17 16:05:31 -0500216 /* Next check the txcmplq */
James Smart07951072007-04-25 09:51:38 -0400217 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
James Smart858c9f62007-06-17 19:56:39 -0500218 /* Check to see if iocb matches the nport we are looking for */
James Smart92d7f7b2007-06-17 19:56:38 -0500219 if (lpfc_check_sli_ndlp(phba, pring, iocb, ndlp)) {
James Smart07951072007-04-25 09:51:38 -0400220 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
James Smart92d7f7b2007-06-17 19:56:38 -0500221 }
James Smart07951072007-04-25 09:51:38 -0400222 }
James Smart2e0fef82007-06-17 19:56:36 -0500223 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500224
James Smarta257bf92009-04-06 18:48:10 -0400225 /* Cancel all the IOCBs from the completions list */
226 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
227 IOERR_SLI_ABORTED);
James Smart2534ba72007-04-25 09:52:20 -0400228
James Smart0d2b6b82008-06-14 22:52:47 -0400229 lpfc_cancel_retry_delay_tmo(phba->pport, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500230 return 0;
dea31012005-04-17 16:05:31 -0500231}
232
233static int
James Smart2e0fef82007-06-17 19:56:36 -0500234lpfc_rcv_plogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
James Smart92d7f7b2007-06-17 19:56:38 -0500235 struct lpfc_iocbq *cmdiocb)
dea31012005-04-17 16:05:31 -0500236{
James Smart2e0fef82007-06-17 19:56:36 -0500237 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
238 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500239 struct lpfc_dmabuf *pcmd;
240 uint32_t *lp;
241 IOCB_t *icmd;
242 struct serv_parm *sp;
243 LPFC_MBOXQ_t *mbox;
244 struct ls_rjt stat;
245 int rc;
246
247 memset(&stat, 0, sizeof (struct ls_rjt));
James Smart2e0fef82007-06-17 19:56:36 -0500248 if (vport->port_state <= LPFC_FLOGI) {
dea31012005-04-17 16:05:31 -0500249 /* Before responding to PLOGI, check for pt2pt mode.
250 * If we are pt2pt, with an outstanding FLOGI, abort
251 * the FLOGI and resend it first.
252 */
James Smart2e0fef82007-06-17 19:56:36 -0500253 if (vport->fc_flag & FC_PT2PT) {
James Smart92d7f7b2007-06-17 19:56:38 -0500254 lpfc_els_abort_flogi(phba);
James Smart2e0fef82007-06-17 19:56:36 -0500255 if (!(vport->fc_flag & FC_PT2PT_PLOGI)) {
dea31012005-04-17 16:05:31 -0500256 /* If the other side is supposed to initiate
257 * the PLOGI anyway, just ACC it now and
258 * move on with discovery.
259 */
260 phba->fc_edtov = FF_DEF_EDTOV;
261 phba->fc_ratov = FF_DEF_RATOV;
262 /* Start discovery - this should just do
263 CLEAR_LA */
James Smart2e0fef82007-06-17 19:56:36 -0500264 lpfc_disc_start(vport);
James Smarted957682007-06-17 19:56:37 -0500265 } else
James Smart2e0fef82007-06-17 19:56:36 -0500266 lpfc_initial_flogi(vport);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500267 } else {
dea31012005-04-17 16:05:31 -0500268 stat.un.b.lsRjtRsnCode = LSRJT_LOGICAL_BSY;
269 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
James Smart2e0fef82007-06-17 19:56:36 -0500270 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb,
James Smart858c9f62007-06-17 19:56:39 -0500271 ndlp, NULL);
dea31012005-04-17 16:05:31 -0500272 return 0;
273 }
274 }
275 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
276 lp = (uint32_t *) pcmd->virt;
277 sp = (struct serv_parm *) ((uint8_t *) lp + sizeof (uint32_t));
James Smarta8adb832007-10-27 13:37:53 -0400278 if (wwn_to_u64(sp->portName.u.wwn) == 0) {
279 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
280 "0140 PLOGI Reject: invalid nname\n");
281 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
282 stat.un.b.lsRjtRsnCodeExp = LSEXP_INVALID_PNAME;
283 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
284 NULL);
285 return 0;
286 }
287 if (wwn_to_u64(sp->nodeName.u.wwn) == 0) {
288 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
289 "0141 PLOGI Reject: invalid pname\n");
290 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
291 stat.un.b.lsRjtRsnCodeExp = LSEXP_INVALID_NNAME;
292 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
293 NULL);
294 return 0;
295 }
James Smart2e0fef82007-06-17 19:56:36 -0500296 if ((lpfc_check_sparm(vport, ndlp, sp, CLASS3) == 0)) {
dea31012005-04-17 16:05:31 -0500297 /* Reject this request because invalid parameters */
298 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
299 stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
James Smart858c9f62007-06-17 19:56:39 -0500300 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
301 NULL);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500302 return 0;
dea31012005-04-17 16:05:31 -0500303 }
304 icmd = &cmdiocb->iocb;
305
306 /* PLOGI chkparm OK */
James Smarte8b62012007-08-02 11:10:09 -0400307 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
308 "0114 PLOGI chkparm OK Data: x%x x%x x%x x%x\n",
309 ndlp->nlp_DID, ndlp->nlp_state, ndlp->nlp_flag,
310 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -0500311
James Smart3de2a652007-08-02 11:09:59 -0400312 if (vport->cfg_fcp_class == 2 && sp->cls2.classValid)
dea31012005-04-17 16:05:31 -0500313 ndlp->nlp_fcp_info |= CLASS2;
James Smarted957682007-06-17 19:56:37 -0500314 else
dea31012005-04-17 16:05:31 -0500315 ndlp->nlp_fcp_info |= CLASS3;
James Smart2e0fef82007-06-17 19:56:36 -0500316
dea31012005-04-17 16:05:31 -0500317 ndlp->nlp_class_sup = 0;
318 if (sp->cls1.classValid)
319 ndlp->nlp_class_sup |= FC_COS_CLASS1;
320 if (sp->cls2.classValid)
321 ndlp->nlp_class_sup |= FC_COS_CLASS2;
322 if (sp->cls3.classValid)
323 ndlp->nlp_class_sup |= FC_COS_CLASS3;
324 if (sp->cls4.classValid)
325 ndlp->nlp_class_sup |= FC_COS_CLASS4;
326 ndlp->nlp_maxframe =
327 ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) | sp->cmn.bbRcvSizeLsb;
328
329 /* no need to reg_login if we are already in one of these states */
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500330 switch (ndlp->nlp_state) {
dea31012005-04-17 16:05:31 -0500331 case NLP_STE_NPR_NODE:
332 if (!(ndlp->nlp_flag & NLP_NPR_ADISC))
333 break;
334 case NLP_STE_REG_LOGIN_ISSUE:
335 case NLP_STE_PRLI_ISSUE:
336 case NLP_STE_UNMAPPED_NODE:
337 case NLP_STE_MAPPED_NODE:
James Smart51ef4c22007-08-02 11:10:31 -0400338 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp, NULL);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500339 return 1;
dea31012005-04-17 16:05:31 -0500340 }
341
James Smart92d7f7b2007-06-17 19:56:38 -0500342 if ((vport->fc_flag & FC_PT2PT) &&
343 !(vport->fc_flag & FC_PT2PT_PLOGI)) {
dea31012005-04-17 16:05:31 -0500344 /* rcv'ed PLOGI decides what our NPortId will be */
James Smart2e0fef82007-06-17 19:56:36 -0500345 vport->fc_myDID = icmd->un.rcvels.parmRo;
dea31012005-04-17 16:05:31 -0500346 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
347 if (mbox == NULL)
348 goto out;
349 lpfc_config_link(phba, mbox);
350 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smarted957682007-06-17 19:56:37 -0500351 mbox->vport = vport;
James Smart0b727fe2007-10-27 13:37:25 -0400352 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
dea31012005-04-17 16:05:31 -0500353 if (rc == MBX_NOT_FINISHED) {
James Smart92d7f7b2007-06-17 19:56:38 -0500354 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -0500355 goto out;
356 }
357
James Smart2e0fef82007-06-17 19:56:36 -0500358 lpfc_can_disctmo(vport);
dea31012005-04-17 16:05:31 -0500359 }
360 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
James Smart2e0fef82007-06-17 19:56:36 -0500361 if (!mbox)
dea31012005-04-17 16:05:31 -0500362 goto out;
363
James Smart92d7f7b2007-06-17 19:56:38 -0500364 rc = lpfc_reg_login(phba, vport->vpi, icmd->un.rcvels.remoteID,
365 (uint8_t *) sp, mbox, 0);
James Smart2e0fef82007-06-17 19:56:36 -0500366 if (rc) {
367 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -0500368 goto out;
369 }
370
371 /* ACC PLOGI rsp command needs to execute first,
372 * queue this mbox command to be processed later.
373 */
374 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
James Smart329f9bc2007-04-25 09:53:01 -0400375 /*
376 * mbox->context2 = lpfc_nlp_get(ndlp) deferred until mailbox
377 * command issued in lpfc_cmpl_els_acc().
378 */
James Smart2e0fef82007-06-17 19:56:36 -0500379 mbox->vport = vport;
380 spin_lock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -0500381 ndlp->nlp_flag |= (NLP_ACC_REGLOGIN | NLP_RCV_PLOGI);
James Smart2e0fef82007-06-17 19:56:36 -0500382 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500383
James Smart33ccf8d2006-08-17 11:57:58 -0400384 /*
385 * If there is an outstanding PLOGI issued, abort it before
386 * sending ACC rsp for received PLOGI. If pending plogi
387 * is not canceled here, the plogi will be rejected by
388 * remote port and will be retried. On a configuration with
389 * single discovery thread, this will cause a huge delay in
390 * discovery. Also this will cause multiple state machines
391 * running in parallel for this node.
392 */
393 if (ndlp->nlp_state == NLP_STE_PLOGI_ISSUE) {
394 /* software abort outstanding PLOGI */
James Smart07951072007-04-25 09:51:38 -0400395 lpfc_els_abort(phba, ndlp);
James Smart33ccf8d2006-08-17 11:57:58 -0400396 }
397
James Smart858c9f62007-06-17 19:56:39 -0500398 if ((vport->port_type == LPFC_NPIV_PORT &&
James Smart3de2a652007-08-02 11:09:59 -0400399 vport->cfg_restrict_login)) {
James Smart858c9f62007-06-17 19:56:39 -0500400
401 /* In order to preserve RPIs, we want to cleanup
402 * the default RPI the firmware created to rcv
403 * this ELS request. The only way to do this is
404 * to register, then unregister the RPI.
405 */
406 spin_lock_irq(shost->host_lock);
407 ndlp->nlp_flag |= NLP_RM_DFLT_RPI;
408 spin_unlock_irq(shost->host_lock);
409 stat.un.b.lsRjtRsnCode = LSRJT_INVALID_CMD;
410 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
411 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb,
412 ndlp, mbox);
413 return 1;
414 }
James Smart51ef4c22007-08-02 11:10:31 -0400415 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp, mbox);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500416 return 1;
dea31012005-04-17 16:05:31 -0500417out:
418 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
419 stat.un.b.lsRjtRsnCodeExp = LSEXP_OUT_OF_RESOURCE;
James Smart858c9f62007-06-17 19:56:39 -0500420 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500421 return 0;
dea31012005-04-17 16:05:31 -0500422}
423
424static int
James Smart2e0fef82007-06-17 19:56:36 -0500425lpfc_rcv_padisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -0500426 struct lpfc_iocbq *cmdiocb)
427{
James Smart2e0fef82007-06-17 19:56:36 -0500428 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -0500429 struct lpfc_dmabuf *pcmd;
James Smart2e0fef82007-06-17 19:56:36 -0500430 struct serv_parm *sp;
431 struct lpfc_name *pnn, *ppn;
dea31012005-04-17 16:05:31 -0500432 struct ls_rjt stat;
433 ADISC *ap;
434 IOCB_t *icmd;
435 uint32_t *lp;
436 uint32_t cmd;
437
438 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
439 lp = (uint32_t *) pcmd->virt;
440
441 cmd = *lp++;
442 if (cmd == ELS_CMD_ADISC) {
443 ap = (ADISC *) lp;
444 pnn = (struct lpfc_name *) & ap->nodeName;
445 ppn = (struct lpfc_name *) & ap->portName;
446 } else {
447 sp = (struct serv_parm *) lp;
448 pnn = (struct lpfc_name *) & sp->nodeName;
449 ppn = (struct lpfc_name *) & sp->portName;
450 }
451
452 icmd = &cmdiocb->iocb;
James Smart2e0fef82007-06-17 19:56:36 -0500453 if (icmd->ulpStatus == 0 && lpfc_check_adisc(vport, ndlp, pnn, ppn)) {
dea31012005-04-17 16:05:31 -0500454 if (cmd == ELS_CMD_ADISC) {
James Smart2e0fef82007-06-17 19:56:36 -0500455 lpfc_els_rsp_adisc_acc(vport, cmdiocb, ndlp);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500456 } else {
James Smart2e0fef82007-06-17 19:56:36 -0500457 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp,
James Smart51ef4c22007-08-02 11:10:31 -0400458 NULL);
dea31012005-04-17 16:05:31 -0500459 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500460 return 1;
dea31012005-04-17 16:05:31 -0500461 }
462 /* Reject this request because invalid parameters */
463 stat.un.b.lsRjtRsvd0 = 0;
464 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
465 stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
466 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -0500467 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -0500468
dea31012005-04-17 16:05:31 -0500469 /* 1 sec timeout */
470 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ);
471
James Smart2e0fef82007-06-17 19:56:36 -0500472 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500473 ndlp->nlp_flag |= NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -0500474 spin_unlock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -0500475 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
476 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -0500477 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500478 return 0;
dea31012005-04-17 16:05:31 -0500479}
480
481static int
James Smart2e0fef82007-06-17 19:56:36 -0500482lpfc_rcv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
483 struct lpfc_iocbq *cmdiocb, uint32_t els_cmd)
dea31012005-04-17 16:05:31 -0500484{
James Smart2e0fef82007-06-17 19:56:36 -0500485 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
486
487 /* Put ndlp in NPR state with 1 sec timeout for plogi, ACC logo */
dea31012005-04-17 16:05:31 -0500488 /* Only call LOGO ACC for first LOGO, this avoids sending unnecessary
489 * PLOGIs during LOGO storms from a device.
490 */
James Smart2e0fef82007-06-17 19:56:36 -0500491 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500492 ndlp->nlp_flag |= NLP_LOGO_ACC;
James Smart2e0fef82007-06-17 19:56:36 -0500493 spin_unlock_irq(shost->host_lock);
James Smart82d9a2a2006-04-15 11:53:05 -0400494 if (els_cmd == ELS_CMD_PRLO)
James Smart51ef4c22007-08-02 11:10:31 -0400495 lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL);
James Smart82d9a2a2006-04-15 11:53:05 -0400496 else
James Smart51ef4c22007-08-02 11:10:31 -0400497 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -0500498
James Smart0d2b6b82008-06-14 22:52:47 -0400499 if ((!(ndlp->nlp_type & NLP_FABRIC) &&
500 ((ndlp->nlp_type & NLP_FCP_TARGET) ||
501 !(ndlp->nlp_type & NLP_FCP_INITIATOR))) ||
James Smart92d7f7b2007-06-17 19:56:38 -0500502 (ndlp->nlp_state == NLP_STE_ADISC_ISSUE)) {
dea31012005-04-17 16:05:31 -0500503 /* Only try to re-login if this is NOT a Fabric Node */
dea31012005-04-17 16:05:31 -0500504 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ * 1);
James Smart2e0fef82007-06-17 19:56:36 -0500505 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500506 ndlp->nlp_flag |= NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -0500507 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500508
Jamie Wellnitz5024ab12006-02-28 19:25:28 -0500509 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
dea31012005-04-17 16:05:31 -0500510 }
James Smart87af33f2007-10-27 13:37:43 -0400511 ndlp->nlp_prev_state = ndlp->nlp_state;
512 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
dea31012005-04-17 16:05:31 -0500513
James Smart2e0fef82007-06-17 19:56:36 -0500514 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500515 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
James Smart2e0fef82007-06-17 19:56:36 -0500516 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500517 /* The driver has to wait until the ACC completes before it continues
518 * processing the LOGO. The action will resume in
519 * lpfc_cmpl_els_logo_acc routine. Since part of processing includes an
520 * unreg_login, the driver waits so the ACC does not get aborted.
521 */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500522 return 0;
dea31012005-04-17 16:05:31 -0500523}
524
525static void
James Smart2e0fef82007-06-17 19:56:36 -0500526lpfc_rcv_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
527 struct lpfc_iocbq *cmdiocb)
dea31012005-04-17 16:05:31 -0500528{
529 struct lpfc_dmabuf *pcmd;
530 uint32_t *lp;
531 PRLI *npr;
532 struct fc_rport *rport = ndlp->rport;
533 u32 roles;
534
535 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
536 lp = (uint32_t *) pcmd->virt;
537 npr = (PRLI *) ((uint8_t *) lp + sizeof (uint32_t));
538
539 ndlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR);
540 ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
James Smart92d7f7b2007-06-17 19:56:38 -0500541 if (npr->prliType == PRLI_FCP_TYPE) {
dea31012005-04-17 16:05:31 -0500542 if (npr->initiatorFunc)
543 ndlp->nlp_type |= NLP_FCP_INITIATOR;
544 if (npr->targetFunc)
545 ndlp->nlp_type |= NLP_FCP_TARGET;
546 if (npr->Retry)
547 ndlp->nlp_fcp_info |= NLP_FCP_2_DEVICE;
548 }
549 if (rport) {
550 /* We need to update the rport role values */
551 roles = FC_RPORT_ROLE_UNKNOWN;
552 if (ndlp->nlp_type & NLP_FCP_INITIATOR)
553 roles |= FC_RPORT_ROLE_FCP_INITIATOR;
554 if (ndlp->nlp_type & NLP_FCP_TARGET)
555 roles |= FC_RPORT_ROLE_FCP_TARGET;
James Smart858c9f62007-06-17 19:56:39 -0500556
557 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
558 "rport rolechg: role:x%x did:x%x flg:x%x",
559 roles, ndlp->nlp_DID, ndlp->nlp_flag);
560
dea31012005-04-17 16:05:31 -0500561 fc_remote_port_rolechg(rport, roles);
562 }
563}
564
565static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -0500566lpfc_disc_set_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -0500567{
James Smart2e0fef82007-06-17 19:56:36 -0500568 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart2e0fef82007-06-17 19:56:36 -0500569
James Smart51ef4c22007-08-02 11:10:31 -0400570 if (!ndlp->nlp_rpi) {
571 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
572 return 0;
573 }
574
James Smart1b32f6a2008-02-08 18:49:39 -0500575 if (!(vport->fc_flag & FC_PT2PT)) {
576 /* Check config parameter use-adisc or FCP-2 */
577 if ((vport->cfg_use_adisc && (vport->fc_flag & FC_RSCN_MODE)) ||
578 ndlp->nlp_fcp_info & NLP_FCP_2_DEVICE) {
579 spin_lock_irq(shost->host_lock);
580 ndlp->nlp_flag |= NLP_NPR_ADISC;
581 spin_unlock_irq(shost->host_lock);
582 return 1;
583 }
James Smart92d7f7b2007-06-17 19:56:38 -0500584 }
585 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
586 lpfc_unreg_rpi(vport, ndlp);
587 return 0;
dea31012005-04-17 16:05:31 -0500588}
589
590static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -0500591lpfc_disc_illegal(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
592 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -0500593{
James Smarte8b62012007-08-02 11:10:09 -0400594 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
James Smarte47c9092008-02-08 18:49:26 -0500595 "0271 Illegal State Transition: node x%x "
James Smarte8b62012007-08-02 11:10:09 -0400596 "event x%x, state x%x Data: x%x x%x\n",
597 ndlp->nlp_DID, evt, ndlp->nlp_state, ndlp->nlp_rpi,
598 ndlp->nlp_flag);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500599 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -0500600}
601
James Smart87af33f2007-10-27 13:37:43 -0400602static uint32_t
603lpfc_cmpl_plogi_illegal(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
604 void *arg, uint32_t evt)
605{
606 /* This transition is only legal if we previously
607 * rcv'ed a PLOGI. Since we don't want 2 discovery threads
608 * working on the same NPortID, do nothing for this thread
609 * to stop it.
610 */
611 if (!(ndlp->nlp_flag & NLP_RCV_PLOGI)) {
612 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
James Smarte47c9092008-02-08 18:49:26 -0500613 "0272 Illegal State Transition: node x%x "
James Smart87af33f2007-10-27 13:37:43 -0400614 "event x%x, state x%x Data: x%x x%x\n",
615 ndlp->nlp_DID, evt, ndlp->nlp_state, ndlp->nlp_rpi,
616 ndlp->nlp_flag);
617 }
618 return ndlp->nlp_state;
619}
620
dea31012005-04-17 16:05:31 -0500621/* Start of Discovery State Machine routines */
622
623static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -0500624lpfc_rcv_plogi_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
625 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -0500626{
627 struct lpfc_iocbq *cmdiocb;
628
629 cmdiocb = (struct lpfc_iocbq *) arg;
630
James Smart2e0fef82007-06-17 19:56:36 -0500631 if (lpfc_rcv_plogi(vport, ndlp, cmdiocb)) {
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500632 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -0500633 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500634 return NLP_STE_FREED_NODE;
dea31012005-04-17 16:05:31 -0500635}
636
637static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -0500638lpfc_rcv_els_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
639 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -0500640{
James Smart2e0fef82007-06-17 19:56:36 -0500641 lpfc_issue_els_logo(vport, ndlp, 0);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500642 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -0500643}
644
645static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -0500646lpfc_rcv_logo_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
647 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -0500648{
James Smart2e0fef82007-06-17 19:56:36 -0500649 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
650 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -0500651
James Smart2e0fef82007-06-17 19:56:36 -0500652 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500653 ndlp->nlp_flag |= NLP_LOGO_ACC;
James Smart2e0fef82007-06-17 19:56:36 -0500654 spin_unlock_irq(shost->host_lock);
James Smart51ef4c22007-08-02 11:10:31 -0400655 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -0500656
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500657 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -0500658}
659
660static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -0500661lpfc_cmpl_logo_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -0500662 void *arg, uint32_t evt)
663{
James Smart2e0fef82007-06-17 19:56:36 -0500664 return NLP_STE_FREED_NODE;
665}
666
667static uint32_t
668lpfc_device_rm_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
669 void *arg, uint32_t evt)
670{
James Smart2e0fef82007-06-17 19:56:36 -0500671 return NLP_STE_FREED_NODE;
672}
673
674static uint32_t
675lpfc_rcv_plogi_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
676 void *arg, uint32_t evt)
677{
James Smart0d2b6b82008-06-14 22:52:47 -0400678 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart2e0fef82007-06-17 19:56:36 -0500679 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500680 struct lpfc_iocbq *cmdiocb = arg;
James Smart2e0fef82007-06-17 19:56:36 -0500681 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
682 uint32_t *lp = (uint32_t *) pcmd->virt;
683 struct serv_parm *sp = (struct serv_parm *) (lp + 1);
dea31012005-04-17 16:05:31 -0500684 struct ls_rjt stat;
685 int port_cmp;
686
dea31012005-04-17 16:05:31 -0500687 memset(&stat, 0, sizeof (struct ls_rjt));
688
689 /* For a PLOGI, we only accept if our portname is less
690 * than the remote portname.
691 */
692 phba->fc_stat.elsLogiCol++;
James Smart2e0fef82007-06-17 19:56:36 -0500693 port_cmp = memcmp(&vport->fc_portname, &sp->portName,
James Smart92d7f7b2007-06-17 19:56:38 -0500694 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -0500695
696 if (port_cmp >= 0) {
697 /* Reject this request because the remote node will accept
698 ours */
699 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
700 stat.un.b.lsRjtRsnCodeExp = LSEXP_CMD_IN_PROGRESS;
James Smart858c9f62007-06-17 19:56:39 -0500701 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
702 NULL);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500703 } else {
James Smart0d2b6b82008-06-14 22:52:47 -0400704 if (lpfc_rcv_plogi(vport, ndlp, cmdiocb) &&
705 (ndlp->nlp_flag & NLP_NPR_2B_DISC) &&
706 (vport->num_disc_nodes)) {
707 spin_lock_irq(shost->host_lock);
708 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
709 spin_unlock_irq(shost->host_lock);
710 /* Check if there are more PLOGIs to be sent */
711 lpfc_more_plogi(vport);
712 if (vport->num_disc_nodes == 0) {
713 spin_lock_irq(shost->host_lock);
714 vport->fc_flag &= ~FC_NDISC_ACTIVE;
715 spin_unlock_irq(shost->host_lock);
716 lpfc_can_disctmo(vport);
717 lpfc_end_rscn(vport);
718 }
719 }
James Smart2e0fef82007-06-17 19:56:36 -0500720 } /* If our portname was less */
dea31012005-04-17 16:05:31 -0500721
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500722 return ndlp->nlp_state;
723}
724
725static uint32_t
James Smart92d7f7b2007-06-17 19:56:38 -0500726lpfc_rcv_prli_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
727 void *arg, uint32_t evt)
728{
729 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
730 struct ls_rjt stat;
731
732 memset(&stat, 0, sizeof (struct ls_rjt));
733 stat.un.b.lsRjtRsnCode = LSRJT_LOGICAL_BSY;
734 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
James Smart858c9f62007-06-17 19:56:39 -0500735 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
James Smart92d7f7b2007-06-17 19:56:38 -0500736 return ndlp->nlp_state;
737}
738
739static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -0500740lpfc_rcv_logo_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
741 void *arg, uint32_t evt)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500742{
James Smart2e0fef82007-06-17 19:56:36 -0500743 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500744
James Smart92d7f7b2007-06-17 19:56:38 -0500745 /* software abort outstanding PLOGI */
James Smart2e0fef82007-06-17 19:56:36 -0500746 lpfc_els_abort(vport->phba, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500747
James Smart2e0fef82007-06-17 19:56:36 -0500748 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500749 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -0500750}
751
752static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -0500753lpfc_rcv_els_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
754 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -0500755{
James Smart2e0fef82007-06-17 19:56:36 -0500756 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
757 struct lpfc_hba *phba = vport->phba;
758 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -0500759
760 /* software abort outstanding PLOGI */
James Smart07951072007-04-25 09:51:38 -0400761 lpfc_els_abort(phba, ndlp);
dea31012005-04-17 16:05:31 -0500762
763 if (evt == NLP_EVT_RCV_LOGO) {
James Smart51ef4c22007-08-02 11:10:31 -0400764 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500765 } else {
James Smart2e0fef82007-06-17 19:56:36 -0500766 lpfc_issue_els_logo(vport, ndlp, 0);
dea31012005-04-17 16:05:31 -0500767 }
768
James Smart2e0fef82007-06-17 19:56:36 -0500769 /* Put ndlp in npr state set plogi timer for 1 sec */
Jamie Wellnitz5024ab12006-02-28 19:25:28 -0500770 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ * 1);
James Smart2e0fef82007-06-17 19:56:36 -0500771 spin_lock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -0500772 ndlp->nlp_flag |= NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -0500773 spin_unlock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -0500774 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
775 ndlp->nlp_prev_state = NLP_STE_PLOGI_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -0500776 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
dea31012005-04-17 16:05:31 -0500777
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500778 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -0500779}
780
781static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -0500782lpfc_cmpl_plogi_plogi_issue(struct lpfc_vport *vport,
783 struct lpfc_nodelist *ndlp,
784 void *arg,
dea31012005-04-17 16:05:31 -0500785 uint32_t evt)
786{
James Smart2e0fef82007-06-17 19:56:36 -0500787 struct lpfc_hba *phba = vport->phba;
James Smart0ff10d42008-01-11 01:52:36 -0500788 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart2e0fef82007-06-17 19:56:36 -0500789 struct lpfc_iocbq *cmdiocb, *rspiocb;
James Smart14691152006-12-02 13:34:28 -0500790 struct lpfc_dmabuf *pcmd, *prsp, *mp;
dea31012005-04-17 16:05:31 -0500791 uint32_t *lp;
792 IOCB_t *irsp;
793 struct serv_parm *sp;
794 LPFC_MBOXQ_t *mbox;
795
796 cmdiocb = (struct lpfc_iocbq *) arg;
797 rspiocb = cmdiocb->context_un.rsp_iocb;
798
799 if (ndlp->nlp_flag & NLP_ACC_REGLOGIN) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -0500800 /* Recovery from PLOGI collision logic */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500801 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -0500802 }
803
804 irsp = &rspiocb->iocb;
805
806 if (irsp->ulpStatus)
807 goto out;
808
809 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
810
James Smart2e0fef82007-06-17 19:56:36 -0500811 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
dea31012005-04-17 16:05:31 -0500812
James Smart2e0fef82007-06-17 19:56:36 -0500813 lp = (uint32_t *) prsp->virt;
dea31012005-04-17 16:05:31 -0500814 sp = (struct serv_parm *) ((uint8_t *) lp + sizeof (uint32_t));
James Smart58da1ff2008-04-07 10:15:56 -0400815
816 /* Some switches have FDMI servers returning 0 for WWN */
817 if ((ndlp->nlp_DID != FDMI_DID) &&
818 (wwn_to_u64(sp->portName.u.wwn) == 0 ||
819 wwn_to_u64(sp->nodeName.u.wwn) == 0)) {
James Smarta8adb832007-10-27 13:37:53 -0400820 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
821 "0142 PLOGI RSP: Invalid WWN.\n");
822 goto out;
823 }
James Smart2e0fef82007-06-17 19:56:36 -0500824 if (!lpfc_check_sparm(vport, ndlp, sp, CLASS3))
dea31012005-04-17 16:05:31 -0500825 goto out;
dea31012005-04-17 16:05:31 -0500826 /* PLOGI chkparm OK */
James Smarte8b62012007-08-02 11:10:09 -0400827 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
828 "0121 PLOGI chkparm OK Data: x%x x%x x%x x%x\n",
829 ndlp->nlp_DID, ndlp->nlp_state,
830 ndlp->nlp_flag, ndlp->nlp_rpi);
James Smart3de2a652007-08-02 11:09:59 -0400831 if (vport->cfg_fcp_class == 2 && (sp->cls2.classValid))
dea31012005-04-17 16:05:31 -0500832 ndlp->nlp_fcp_info |= CLASS2;
James Smart2e0fef82007-06-17 19:56:36 -0500833 else
dea31012005-04-17 16:05:31 -0500834 ndlp->nlp_fcp_info |= CLASS3;
James Smart2e0fef82007-06-17 19:56:36 -0500835
dea31012005-04-17 16:05:31 -0500836 ndlp->nlp_class_sup = 0;
837 if (sp->cls1.classValid)
838 ndlp->nlp_class_sup |= FC_COS_CLASS1;
839 if (sp->cls2.classValid)
840 ndlp->nlp_class_sup |= FC_COS_CLASS2;
841 if (sp->cls3.classValid)
842 ndlp->nlp_class_sup |= FC_COS_CLASS3;
843 if (sp->cls4.classValid)
844 ndlp->nlp_class_sup |= FC_COS_CLASS4;
845 ndlp->nlp_maxframe =
James Smart2e0fef82007-06-17 19:56:36 -0500846 ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) | sp->cmn.bbRcvSizeLsb;
dea31012005-04-17 16:05:31 -0500847
James Smart2e0fef82007-06-17 19:56:36 -0500848 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
James Smart92d7f7b2007-06-17 19:56:38 -0500849 if (!mbox) {
James Smarte8b62012007-08-02 11:10:09 -0400850 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
851 "0133 PLOGI: no memory for reg_login "
James Smart92d7f7b2007-06-17 19:56:38 -0500852 "Data: x%x x%x x%x x%x\n",
James Smart92d7f7b2007-06-17 19:56:38 -0500853 ndlp->nlp_DID, ndlp->nlp_state,
854 ndlp->nlp_flag, ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -0500855 goto out;
James Smart92d7f7b2007-06-17 19:56:38 -0500856 }
dea31012005-04-17 16:05:31 -0500857
James Smart2e0fef82007-06-17 19:56:36 -0500858 lpfc_unreg_rpi(vport, ndlp);
859
James Smart92d7f7b2007-06-17 19:56:38 -0500860 if (lpfc_reg_login(phba, vport->vpi, irsp->un.elsreq64.remoteID,
861 (uint8_t *) sp, mbox, 0) == 0) {
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500862 switch (ndlp->nlp_DID) {
dea31012005-04-17 16:05:31 -0500863 case NameServer_DID:
James Smartde0c5b32007-04-25 09:52:27 -0400864 mbox->mbox_cmpl = lpfc_mbx_cmpl_ns_reg_login;
dea31012005-04-17 16:05:31 -0500865 break;
866 case FDMI_DID:
James Smartde0c5b32007-04-25 09:52:27 -0400867 mbox->mbox_cmpl = lpfc_mbx_cmpl_fdmi_reg_login;
dea31012005-04-17 16:05:31 -0500868 break;
869 default:
James Smartde0c5b32007-04-25 09:52:27 -0400870 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
dea31012005-04-17 16:05:31 -0500871 }
James Smart329f9bc2007-04-25 09:53:01 -0400872 mbox->context2 = lpfc_nlp_get(ndlp);
James Smart2e0fef82007-06-17 19:56:36 -0500873 mbox->vport = vport;
James Smart0b727fe2007-10-27 13:37:25 -0400874 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
dea31012005-04-17 16:05:31 -0500875 != MBX_NOT_FINISHED) {
James Smart2e0fef82007-06-17 19:56:36 -0500876 lpfc_nlp_set_state(vport, ndlp,
877 NLP_STE_REG_LOGIN_ISSUE);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500878 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -0500879 }
James Smartfa4066b2008-01-11 01:53:27 -0500880 /* decrement node reference count to the failed mbox
881 * command
882 */
James Smart329f9bc2007-04-25 09:53:01 -0400883 lpfc_nlp_put(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -0500884 mp = (struct lpfc_dmabuf *) mbox->context1;
James Smart14691152006-12-02 13:34:28 -0500885 lpfc_mbuf_free(phba, mp->virt, mp->phys);
886 kfree(mp);
dea31012005-04-17 16:05:31 -0500887 mempool_free(mbox, phba->mbox_mem_pool);
James Smart92d7f7b2007-06-17 19:56:38 -0500888
James Smarte8b62012007-08-02 11:10:09 -0400889 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
890 "0134 PLOGI: cannot issue reg_login "
891 "Data: x%x x%x x%x x%x\n",
892 ndlp->nlp_DID, ndlp->nlp_state,
893 ndlp->nlp_flag, ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -0500894 } else {
895 mempool_free(mbox, phba->mbox_mem_pool);
James Smart92d7f7b2007-06-17 19:56:38 -0500896
James Smarte8b62012007-08-02 11:10:09 -0400897 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
898 "0135 PLOGI: cannot format reg_login "
899 "Data: x%x x%x x%x x%x\n",
900 ndlp->nlp_DID, ndlp->nlp_state,
901 ndlp->nlp_flag, ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -0500902 }
903
904
James Smart92d7f7b2007-06-17 19:56:38 -0500905out:
906 if (ndlp->nlp_DID == NameServer_DID) {
907 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -0400908 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
909 "0261 Cannot Register NameServer login\n");
James Smart92d7f7b2007-06-17 19:56:38 -0500910 }
911
James Smart0ff10d42008-01-11 01:52:36 -0500912 spin_lock_irq(shost->host_lock);
James Smarta8adb832007-10-27 13:37:53 -0400913 ndlp->nlp_flag |= NLP_DEFER_RM;
James Smart0ff10d42008-01-11 01:52:36 -0500914 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500915 return NLP_STE_FREED_NODE;
dea31012005-04-17 16:05:31 -0500916}
917
918static uint32_t
James Smart0ff10d42008-01-11 01:52:36 -0500919lpfc_cmpl_logo_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
920 void *arg, uint32_t evt)
921{
922 return ndlp->nlp_state;
923}
924
925static uint32_t
926lpfc_cmpl_reglogin_plogi_issue(struct lpfc_vport *vport,
927 struct lpfc_nodelist *ndlp, void *arg, uint32_t evt)
928{
929 return ndlp->nlp_state;
930}
931
932static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -0500933lpfc_device_rm_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
934 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -0500935{
James Smart2e0fef82007-06-17 19:56:36 -0500936 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -0500937
James Smart2e0fef82007-06-17 19:56:36 -0500938 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
939 spin_lock_irq(shost->host_lock);
940 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
941 spin_unlock_irq(shost->host_lock);
942 return ndlp->nlp_state;
943 } else {
944 /* software abort outstanding PLOGI */
945 lpfc_els_abort(vport->phba, ndlp);
946
947 lpfc_drop_node(vport, ndlp);
James Smarta0f9b482006-04-15 11:52:56 -0400948 return NLP_STE_FREED_NODE;
949 }
dea31012005-04-17 16:05:31 -0500950}
951
952static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -0500953lpfc_device_recov_plogi_issue(struct lpfc_vport *vport,
954 struct lpfc_nodelist *ndlp,
955 void *arg,
956 uint32_t evt)
dea31012005-04-17 16:05:31 -0500957{
James Smart2e0fef82007-06-17 19:56:36 -0500958 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
959 struct lpfc_hba *phba = vport->phba;
960
James Smart92d7f7b2007-06-17 19:56:38 -0500961 /* Don't do anything that will mess up processing of the
962 * previous RSCN.
963 */
964 if (vport->fc_flag & FC_RSCN_DEFERRED)
965 return ndlp->nlp_state;
966
dea31012005-04-17 16:05:31 -0500967 /* software abort outstanding PLOGI */
James Smart07951072007-04-25 09:51:38 -0400968 lpfc_els_abort(phba, ndlp);
dea31012005-04-17 16:05:31 -0500969
Jamie Wellnitz5024ab12006-02-28 19:25:28 -0500970 ndlp->nlp_prev_state = NLP_STE_PLOGI_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -0500971 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
James Smart92d7f7b2007-06-17 19:56:38 -0500972 spin_lock_irq(shost->host_lock);
James Smarta0f9b482006-04-15 11:52:56 -0400973 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
James Smart2e0fef82007-06-17 19:56:36 -0500974 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500975
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500976 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -0500977}
978
979static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -0500980lpfc_rcv_plogi_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
981 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -0500982{
James Smart0d2b6b82008-06-14 22:52:47 -0400983 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart2e0fef82007-06-17 19:56:36 -0500984 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500985 struct lpfc_iocbq *cmdiocb;
986
987 /* software abort outstanding ADISC */
James Smart07951072007-04-25 09:51:38 -0400988 lpfc_els_abort(phba, ndlp);
dea31012005-04-17 16:05:31 -0500989
990 cmdiocb = (struct lpfc_iocbq *) arg;
991
James Smart0d2b6b82008-06-14 22:52:47 -0400992 if (lpfc_rcv_plogi(vport, ndlp, cmdiocb)) {
993 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
994 spin_lock_irq(shost->host_lock);
995 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
996 spin_unlock_irq(shost->host_lock);
James Smart90160e02008-08-24 21:49:45 -0400997 if (vport->num_disc_nodes)
James Smart0d2b6b82008-06-14 22:52:47 -0400998 lpfc_more_adisc(vport);
James Smart0d2b6b82008-06-14 22:52:47 -0400999 }
1000 return ndlp->nlp_state;
1001 }
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001002 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -05001003 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
1004 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
dea31012005-04-17 16:05:31 -05001005
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001006 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001007}
1008
1009static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001010lpfc_rcv_prli_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1011 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001012{
James Smart2e0fef82007-06-17 19:56:36 -05001013 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001014
James Smart2e0fef82007-06-17 19:56:36 -05001015 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001016 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001017}
1018
1019static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001020lpfc_rcv_logo_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1021 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001022{
James Smart2e0fef82007-06-17 19:56:36 -05001023 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001024 struct lpfc_iocbq *cmdiocb;
1025
1026 cmdiocb = (struct lpfc_iocbq *) arg;
1027
1028 /* software abort outstanding ADISC */
James Smart07951072007-04-25 09:51:38 -04001029 lpfc_els_abort(phba, ndlp);
dea31012005-04-17 16:05:31 -05001030
James Smart2e0fef82007-06-17 19:56:36 -05001031 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001032 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001033}
1034
1035static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001036lpfc_rcv_padisc_adisc_issue(struct lpfc_vport *vport,
1037 struct lpfc_nodelist *ndlp,
1038 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001039{
1040 struct lpfc_iocbq *cmdiocb;
1041
1042 cmdiocb = (struct lpfc_iocbq *) arg;
1043
James Smart2e0fef82007-06-17 19:56:36 -05001044 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001045 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001046}
1047
1048static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001049lpfc_rcv_prlo_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1050 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001051{
1052 struct lpfc_iocbq *cmdiocb;
1053
1054 cmdiocb = (struct lpfc_iocbq *) arg;
1055
1056 /* Treat like rcv logo */
James Smart2e0fef82007-06-17 19:56:36 -05001057 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_PRLO);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001058 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001059}
1060
1061static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001062lpfc_cmpl_adisc_adisc_issue(struct lpfc_vport *vport,
1063 struct lpfc_nodelist *ndlp,
1064 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001065{
James Smart2e0fef82007-06-17 19:56:36 -05001066 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1067 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001068 struct lpfc_iocbq *cmdiocb, *rspiocb;
1069 IOCB_t *irsp;
1070 ADISC *ap;
1071
1072 cmdiocb = (struct lpfc_iocbq *) arg;
1073 rspiocb = cmdiocb->context_un.rsp_iocb;
1074
1075 ap = (ADISC *)lpfc_check_elscmpl_iocb(phba, cmdiocb, rspiocb);
1076 irsp = &rspiocb->iocb;
1077
1078 if ((irsp->ulpStatus) ||
James Smart92d7f7b2007-06-17 19:56:38 -05001079 (!lpfc_check_adisc(vport, ndlp, &ap->nodeName, &ap->portName))) {
dea31012005-04-17 16:05:31 -05001080 /* 1 sec timeout */
1081 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ);
James Smart2e0fef82007-06-17 19:56:36 -05001082 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001083 ndlp->nlp_flag |= NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05001084 spin_unlock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001085 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
dea31012005-04-17 16:05:31 -05001086
James Smart2e0fef82007-06-17 19:56:36 -05001087 memset(&ndlp->nlp_nodename, 0, sizeof(struct lpfc_name));
1088 memset(&ndlp->nlp_portname, 0, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05001089
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001090 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -05001091 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1092 lpfc_unreg_rpi(vport, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001093 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001094 }
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001095
James.Smart@Emulex.Com25013222005-06-25 10:34:33 -04001096 if (ndlp->nlp_type & NLP_FCP_TARGET) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001097 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -05001098 lpfc_nlp_set_state(vport, ndlp, NLP_STE_MAPPED_NODE);
James.Smart@Emulex.Com25013222005-06-25 10:34:33 -04001099 } else {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001100 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -05001101 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
James.Smart@Emulex.Com25013222005-06-25 10:34:33 -04001102 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001103 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001104}
1105
1106static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001107lpfc_device_rm_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1108 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001109{
James Smart2e0fef82007-06-17 19:56:36 -05001110 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001111
James Smart2e0fef82007-06-17 19:56:36 -05001112 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1113 spin_lock_irq(shost->host_lock);
1114 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
1115 spin_unlock_irq(shost->host_lock);
1116 return ndlp->nlp_state;
1117 } else {
1118 /* software abort outstanding ADISC */
1119 lpfc_els_abort(vport->phba, ndlp);
1120
1121 lpfc_drop_node(vport, ndlp);
James Smarta0f9b482006-04-15 11:52:56 -04001122 return NLP_STE_FREED_NODE;
1123 }
dea31012005-04-17 16:05:31 -05001124}
1125
1126static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001127lpfc_device_recov_adisc_issue(struct lpfc_vport *vport,
1128 struct lpfc_nodelist *ndlp,
1129 void *arg,
1130 uint32_t evt)
dea31012005-04-17 16:05:31 -05001131{
James Smart2e0fef82007-06-17 19:56:36 -05001132 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1133 struct lpfc_hba *phba = vport->phba;
1134
James Smart92d7f7b2007-06-17 19:56:38 -05001135 /* Don't do anything that will mess up processing of the
1136 * previous RSCN.
1137 */
1138 if (vport->fc_flag & FC_RSCN_DEFERRED)
1139 return ndlp->nlp_state;
1140
dea31012005-04-17 16:05:31 -05001141 /* software abort outstanding ADISC */
James Smart07951072007-04-25 09:51:38 -04001142 lpfc_els_abort(phba, ndlp);
dea31012005-04-17 16:05:31 -05001143
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001144 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -05001145 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1146 spin_lock_irq(shost->host_lock);
James Smarta0f9b482006-04-15 11:52:56 -04001147 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
James Smart2e0fef82007-06-17 19:56:36 -05001148 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05001149 lpfc_disc_set_adisc(vport, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001150 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001151}
1152
1153static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001154lpfc_rcv_plogi_reglogin_issue(struct lpfc_vport *vport,
1155 struct lpfc_nodelist *ndlp,
1156 void *arg,
dea31012005-04-17 16:05:31 -05001157 uint32_t evt)
1158{
James Smart2e0fef82007-06-17 19:56:36 -05001159 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001160
James Smart2e0fef82007-06-17 19:56:36 -05001161 lpfc_rcv_plogi(vport, ndlp, cmdiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001162 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001163}
1164
1165static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001166lpfc_rcv_prli_reglogin_issue(struct lpfc_vport *vport,
1167 struct lpfc_nodelist *ndlp,
1168 void *arg,
dea31012005-04-17 16:05:31 -05001169 uint32_t evt)
1170{
James Smart2e0fef82007-06-17 19:56:36 -05001171 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001172
James Smart2e0fef82007-06-17 19:56:36 -05001173 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001174 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001175}
1176
1177static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001178lpfc_rcv_logo_reglogin_issue(struct lpfc_vport *vport,
1179 struct lpfc_nodelist *ndlp,
1180 void *arg,
dea31012005-04-17 16:05:31 -05001181 uint32_t evt)
1182{
James Smart2e0fef82007-06-17 19:56:36 -05001183 struct lpfc_hba *phba = vport->phba;
1184 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
James Smart7054a602007-04-25 09:52:34 -04001185 LPFC_MBOXQ_t *mb;
1186 LPFC_MBOXQ_t *nextmb;
1187 struct lpfc_dmabuf *mp;
dea31012005-04-17 16:05:31 -05001188
1189 cmdiocb = (struct lpfc_iocbq *) arg;
1190
James Smart7054a602007-04-25 09:52:34 -04001191 /* cleanup any ndlp on mbox q waiting for reglogin cmpl */
1192 if ((mb = phba->sli.mbox_active)) {
1193 if ((mb->mb.mbxCommand == MBX_REG_LOGIN64) &&
1194 (ndlp == (struct lpfc_nodelist *) mb->context2)) {
James Smart92d7f7b2007-06-17 19:56:38 -05001195 lpfc_nlp_put(ndlp);
James Smart7054a602007-04-25 09:52:34 -04001196 mb->context2 = NULL;
1197 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1198 }
1199 }
1200
James Smart2e0fef82007-06-17 19:56:36 -05001201 spin_lock_irq(&phba->hbalock);
James Smart7054a602007-04-25 09:52:34 -04001202 list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) {
1203 if ((mb->mb.mbxCommand == MBX_REG_LOGIN64) &&
1204 (ndlp == (struct lpfc_nodelist *) mb->context2)) {
1205 mp = (struct lpfc_dmabuf *) (mb->context1);
1206 if (mp) {
James Smart98c9ea52007-10-27 13:37:33 -04001207 __lpfc_mbuf_free(phba, mp->virt, mp->phys);
James Smart7054a602007-04-25 09:52:34 -04001208 kfree(mp);
1209 }
James Smart92d7f7b2007-06-17 19:56:38 -05001210 lpfc_nlp_put(ndlp);
James Smart7054a602007-04-25 09:52:34 -04001211 list_del(&mb->list);
1212 mempool_free(mb, phba->mbox_mem_pool);
1213 }
1214 }
James Smart2e0fef82007-06-17 19:56:36 -05001215 spin_unlock_irq(&phba->hbalock);
James Smart7054a602007-04-25 09:52:34 -04001216
James Smart2e0fef82007-06-17 19:56:36 -05001217 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001218 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001219}
1220
1221static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001222lpfc_rcv_padisc_reglogin_issue(struct lpfc_vport *vport,
1223 struct lpfc_nodelist *ndlp,
1224 void *arg,
dea31012005-04-17 16:05:31 -05001225 uint32_t evt)
1226{
James Smart2e0fef82007-06-17 19:56:36 -05001227 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001228
James Smart2e0fef82007-06-17 19:56:36 -05001229 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001230 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001231}
1232
1233static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001234lpfc_rcv_prlo_reglogin_issue(struct lpfc_vport *vport,
1235 struct lpfc_nodelist *ndlp,
1236 void *arg,
dea31012005-04-17 16:05:31 -05001237 uint32_t evt)
1238{
1239 struct lpfc_iocbq *cmdiocb;
1240
1241 cmdiocb = (struct lpfc_iocbq *) arg;
James Smart51ef4c22007-08-02 11:10:31 -04001242 lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001243 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001244}
1245
1246static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001247lpfc_cmpl_reglogin_reglogin_issue(struct lpfc_vport *vport,
1248 struct lpfc_nodelist *ndlp,
1249 void *arg,
1250 uint32_t evt)
dea31012005-04-17 16:05:31 -05001251{
James Smart2e0fef82007-06-17 19:56:36 -05001252 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart2e0fef82007-06-17 19:56:36 -05001253 LPFC_MBOXQ_t *pmb = (LPFC_MBOXQ_t *) arg;
1254 MAILBOX_t *mb = &pmb->mb;
1255 uint32_t did = mb->un.varWords[1];
dea31012005-04-17 16:05:31 -05001256
dea31012005-04-17 16:05:31 -05001257 if (mb->mbxStatus) {
1258 /* RegLogin failed */
James Smarte8b62012007-08-02 11:10:09 -04001259 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
1260 "0246 RegLogin failed Data: x%x x%x x%x\n",
James Smart2e0fef82007-06-17 19:56:36 -05001261 did, mb->mbxStatus, vport->port_state);
James Smartd0e56da2006-07-06 15:49:42 -04001262 /*
1263 * If RegLogin failed due to lack of HBA resources do not
1264 * retry discovery.
1265 */
1266 if (mb->mbxStatus == MBXERR_RPI_FULL) {
James Smart87af33f2007-10-27 13:37:43 -04001267 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
1268 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
James Smartd0e56da2006-07-06 15:49:42 -04001269 return ndlp->nlp_state;
1270 }
1271
James Smart2e0fef82007-06-17 19:56:36 -05001272 /* Put ndlp in npr state set plogi timer for 1 sec */
dea31012005-04-17 16:05:31 -05001273 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ * 1);
James Smart2e0fef82007-06-17 19:56:36 -05001274 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001275 ndlp->nlp_flag |= NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05001276 spin_unlock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001277 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
dea31012005-04-17 16:05:31 -05001278
James Smart2e0fef82007-06-17 19:56:36 -05001279 lpfc_issue_els_logo(vport, ndlp, 0);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001280 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -05001281 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001282 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001283 }
1284
dea31012005-04-17 16:05:31 -05001285 ndlp->nlp_rpi = mb->un.varWords[0];
dea31012005-04-17 16:05:31 -05001286
1287 /* Only if we are not a fabric nport do we issue PRLI */
1288 if (!(ndlp->nlp_type & NLP_FABRIC)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001289 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -05001290 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
1291 lpfc_issue_els_prli(vport, ndlp, 0);
dea31012005-04-17 16:05:31 -05001292 } else {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001293 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -05001294 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
dea31012005-04-17 16:05:31 -05001295 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001296 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001297}
1298
1299static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001300lpfc_device_rm_reglogin_issue(struct lpfc_vport *vport,
1301 struct lpfc_nodelist *ndlp,
1302 void *arg,
dea31012005-04-17 16:05:31 -05001303 uint32_t evt)
1304{
James Smart2e0fef82007-06-17 19:56:36 -05001305 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1306
1307 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1308 spin_lock_irq(shost->host_lock);
James Smarta0f9b482006-04-15 11:52:56 -04001309 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
James Smart2e0fef82007-06-17 19:56:36 -05001310 spin_unlock_irq(shost->host_lock);
James Smarta0f9b482006-04-15 11:52:56 -04001311 return ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05001312 } else {
1313 lpfc_drop_node(vport, ndlp);
James Smarta0f9b482006-04-15 11:52:56 -04001314 return NLP_STE_FREED_NODE;
1315 }
dea31012005-04-17 16:05:31 -05001316}
1317
1318static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001319lpfc_device_recov_reglogin_issue(struct lpfc_vport *vport,
1320 struct lpfc_nodelist *ndlp,
1321 void *arg,
1322 uint32_t evt)
dea31012005-04-17 16:05:31 -05001323{
James Smart2e0fef82007-06-17 19:56:36 -05001324 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1325
James Smart92d7f7b2007-06-17 19:56:38 -05001326 /* Don't do anything that will mess up processing of the
1327 * previous RSCN.
1328 */
1329 if (vport->fc_flag & FC_RSCN_DEFERRED)
1330 return ndlp->nlp_state;
1331
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001332 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -05001333 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1334 spin_lock_irq(shost->host_lock);
James Smarta0f9b482006-04-15 11:52:56 -04001335 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
James Smart2e0fef82007-06-17 19:56:36 -05001336 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05001337 lpfc_disc_set_adisc(vport, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001338 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001339}
1340
1341static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001342lpfc_rcv_plogi_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1343 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001344{
1345 struct lpfc_iocbq *cmdiocb;
1346
1347 cmdiocb = (struct lpfc_iocbq *) arg;
1348
James Smart2e0fef82007-06-17 19:56:36 -05001349 lpfc_rcv_plogi(vport, ndlp, cmdiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001350 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001351}
1352
1353static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001354lpfc_rcv_prli_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1355 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001356{
James Smart2e0fef82007-06-17 19:56:36 -05001357 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001358
James Smart2e0fef82007-06-17 19:56:36 -05001359 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001360 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001361}
1362
1363static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001364lpfc_rcv_logo_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1365 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001366{
James Smart2e0fef82007-06-17 19:56:36 -05001367 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001368
1369 /* Software abort outstanding PRLI before sending acc */
James Smart2e0fef82007-06-17 19:56:36 -05001370 lpfc_els_abort(vport->phba, ndlp);
dea31012005-04-17 16:05:31 -05001371
James Smart2e0fef82007-06-17 19:56:36 -05001372 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001373 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001374}
1375
1376static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001377lpfc_rcv_padisc_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1378 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001379{
James Smart2e0fef82007-06-17 19:56:36 -05001380 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001381
James Smart2e0fef82007-06-17 19:56:36 -05001382 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001383 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001384}
1385
1386/* This routine is envoked when we rcv a PRLO request from a nport
1387 * we are logged into. We should send back a PRLO rsp setting the
1388 * appropriate bits.
1389 * NEXT STATE = PRLI_ISSUE
1390 */
1391static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001392lpfc_rcv_prlo_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1393 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001394{
James Smart2e0fef82007-06-17 19:56:36 -05001395 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001396
James Smart51ef4c22007-08-02 11:10:31 -04001397 lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001398 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001399}
1400
1401static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001402lpfc_cmpl_prli_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1403 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001404{
James Smart92d7f7b2007-06-17 19:56:38 -05001405 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001406 struct lpfc_iocbq *cmdiocb, *rspiocb;
James Smart2e0fef82007-06-17 19:56:36 -05001407 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001408 IOCB_t *irsp;
1409 PRLI *npr;
1410
1411 cmdiocb = (struct lpfc_iocbq *) arg;
1412 rspiocb = cmdiocb->context_un.rsp_iocb;
1413 npr = (PRLI *)lpfc_check_elscmpl_iocb(phba, cmdiocb, rspiocb);
1414
1415 irsp = &rspiocb->iocb;
1416 if (irsp->ulpStatus) {
James Smart858c9f62007-06-17 19:56:39 -05001417 if ((vport->port_type == LPFC_NPIV_PORT) &&
James Smart3de2a652007-08-02 11:09:59 -04001418 vport->cfg_restrict_login) {
James Smart858c9f62007-06-17 19:56:39 -05001419 goto out;
1420 }
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001421 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -05001422 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001423 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001424 }
1425
1426 /* Check out PRLI rsp */
1427 ndlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR);
1428 ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
1429 if ((npr->acceptRspCode == PRLI_REQ_EXECUTED) &&
1430 (npr->prliType == PRLI_FCP_TYPE)) {
1431 if (npr->initiatorFunc)
1432 ndlp->nlp_type |= NLP_FCP_INITIATOR;
1433 if (npr->targetFunc)
1434 ndlp->nlp_type |= NLP_FCP_TARGET;
1435 if (npr->Retry)
1436 ndlp->nlp_fcp_info |= NLP_FCP_2_DEVICE;
1437 }
James Smart92d7f7b2007-06-17 19:56:38 -05001438 if (!(ndlp->nlp_type & NLP_FCP_TARGET) &&
1439 (vport->port_type == LPFC_NPIV_PORT) &&
James Smart3de2a652007-08-02 11:09:59 -04001440 vport->cfg_restrict_login) {
James Smart858c9f62007-06-17 19:56:39 -05001441out:
James Smart92d7f7b2007-06-17 19:56:38 -05001442 spin_lock_irq(shost->host_lock);
1443 ndlp->nlp_flag |= NLP_TARGET_REMOVE;
1444 spin_unlock_irq(shost->host_lock);
1445 lpfc_issue_els_logo(vport, ndlp, 0);
1446
1447 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
James Smart87af33f2007-10-27 13:37:43 -04001448 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
James Smart92d7f7b2007-06-17 19:56:38 -05001449 return ndlp->nlp_state;
1450 }
dea31012005-04-17 16:05:31 -05001451
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001452 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
James Smart92d7f7b2007-06-17 19:56:38 -05001453 if (ndlp->nlp_type & NLP_FCP_TARGET)
1454 lpfc_nlp_set_state(vport, ndlp, NLP_STE_MAPPED_NODE);
1455 else
1456 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001457 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001458}
1459
1460/*! lpfc_device_rm_prli_issue
James Smart92d7f7b2007-06-17 19:56:38 -05001461 *
1462 * \pre
1463 * \post
1464 * \param phba
1465 * \param ndlp
1466 * \param arg
1467 * \param evt
1468 * \return uint32_t
1469 *
1470 * \b Description:
1471 * This routine is envoked when we a request to remove a nport we are in the
1472 * process of PRLIing. We should software abort outstanding prli, unreg
1473 * login, send a logout. We will change node state to UNUSED_NODE, put it
1474 * on plogi list so it can be freed when LOGO completes.
1475 *
1476 */
1477
dea31012005-04-17 16:05:31 -05001478static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001479lpfc_device_rm_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1480 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001481{
James Smart2e0fef82007-06-17 19:56:36 -05001482 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001483
James Smart2e0fef82007-06-17 19:56:36 -05001484 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1485 spin_lock_irq(shost->host_lock);
1486 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
1487 spin_unlock_irq(shost->host_lock);
1488 return ndlp->nlp_state;
1489 } else {
1490 /* software abort outstanding PLOGI */
1491 lpfc_els_abort(vport->phba, ndlp);
1492
1493 lpfc_drop_node(vport, ndlp);
James Smarta0f9b482006-04-15 11:52:56 -04001494 return NLP_STE_FREED_NODE;
1495 }
dea31012005-04-17 16:05:31 -05001496}
1497
1498
1499/*! lpfc_device_recov_prli_issue
James Smart92d7f7b2007-06-17 19:56:38 -05001500 *
1501 * \pre
1502 * \post
1503 * \param phba
1504 * \param ndlp
1505 * \param arg
1506 * \param evt
1507 * \return uint32_t
1508 *
1509 * \b Description:
1510 * The routine is envoked when the state of a device is unknown, like
1511 * during a link down. We should remove the nodelist entry from the
1512 * unmapped list, issue a UNREG_LOGIN, do a software abort of the
1513 * outstanding PRLI command, then free the node entry.
1514 */
dea31012005-04-17 16:05:31 -05001515static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001516lpfc_device_recov_prli_issue(struct lpfc_vport *vport,
1517 struct lpfc_nodelist *ndlp,
1518 void *arg,
1519 uint32_t evt)
dea31012005-04-17 16:05:31 -05001520{
James Smart2e0fef82007-06-17 19:56:36 -05001521 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1522 struct lpfc_hba *phba = vport->phba;
1523
James Smart92d7f7b2007-06-17 19:56:38 -05001524 /* Don't do anything that will mess up processing of the
1525 * previous RSCN.
1526 */
1527 if (vport->fc_flag & FC_RSCN_DEFERRED)
1528 return ndlp->nlp_state;
1529
dea31012005-04-17 16:05:31 -05001530 /* software abort outstanding PRLI */
James Smart07951072007-04-25 09:51:38 -04001531 lpfc_els_abort(phba, ndlp);
dea31012005-04-17 16:05:31 -05001532
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001533 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -05001534 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1535 spin_lock_irq(shost->host_lock);
James Smarta0f9b482006-04-15 11:52:56 -04001536 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
James Smart2e0fef82007-06-17 19:56:36 -05001537 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05001538 lpfc_disc_set_adisc(vport, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001539 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001540}
1541
1542static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001543lpfc_rcv_plogi_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1544 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001545{
James Smart2e0fef82007-06-17 19:56:36 -05001546 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001547
James Smart2e0fef82007-06-17 19:56:36 -05001548 lpfc_rcv_plogi(vport, ndlp, cmdiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001549 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001550}
1551
1552static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001553lpfc_rcv_prli_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1554 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001555{
James Smart2e0fef82007-06-17 19:56:36 -05001556 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001557
James Smart2e0fef82007-06-17 19:56:36 -05001558 lpfc_rcv_prli(vport, ndlp, cmdiocb);
1559 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
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_logo_unmap_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_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
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_padisc_unmap_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_padisc(vport, ndlp, cmdiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001580 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001581}
1582
1583static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001584lpfc_rcv_prlo_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1585 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001586{
James Smart2e0fef82007-06-17 19:56:36 -05001587 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001588
James Smart51ef4c22007-08-02 11:10:31 -04001589 lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001590 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001591}
1592
1593static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001594lpfc_device_recov_unmap_node(struct lpfc_vport *vport,
1595 struct lpfc_nodelist *ndlp,
1596 void *arg,
1597 uint32_t evt)
dea31012005-04-17 16:05:31 -05001598{
James Smart2e0fef82007-06-17 19:56:36 -05001599 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1600
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001601 ndlp->nlp_prev_state = NLP_STE_UNMAPPED_NODE;
James Smart2e0fef82007-06-17 19:56:36 -05001602 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1603 spin_lock_irq(shost->host_lock);
James Smarta0f9b482006-04-15 11:52:56 -04001604 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
James Smart2e0fef82007-06-17 19:56:36 -05001605 spin_unlock_irq(shost->host_lock);
1606 lpfc_disc_set_adisc(vport, ndlp);
dea31012005-04-17 16:05:31 -05001607
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001608 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001609}
1610
1611static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001612lpfc_rcv_plogi_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1613 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001614{
James Smart2e0fef82007-06-17 19:56:36 -05001615 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001616
James Smart2e0fef82007-06-17 19:56:36 -05001617 lpfc_rcv_plogi(vport, ndlp, cmdiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001618 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001619}
1620
1621static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001622lpfc_rcv_prli_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1623 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001624{
James Smart2e0fef82007-06-17 19:56:36 -05001625 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001626
James Smart2e0fef82007-06-17 19:56:36 -05001627 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001628 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001629}
1630
1631static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001632lpfc_rcv_logo_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1633 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001634{
James Smart2e0fef82007-06-17 19:56:36 -05001635 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001636
James Smart2e0fef82007-06-17 19:56:36 -05001637 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001638 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001639}
1640
1641static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001642lpfc_rcv_padisc_mapped_node(struct lpfc_vport *vport,
1643 struct lpfc_nodelist *ndlp,
1644 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001645{
James Smart2e0fef82007-06-17 19:56:36 -05001646 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001647
James Smart2e0fef82007-06-17 19:56:36 -05001648 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001649 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001650}
1651
1652static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001653lpfc_rcv_prlo_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1654 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001655{
James Smart2e0fef82007-06-17 19:56:36 -05001656 struct lpfc_hba *phba = vport->phba;
1657 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001658
1659 /* flush the target */
James Smart51ef4c22007-08-02 11:10:31 -04001660 lpfc_sli_abort_iocb(vport, &phba->sli.ring[phba->sli.fcp_ring],
1661 ndlp->nlp_sid, 0, LPFC_CTX_TGT);
dea31012005-04-17 16:05:31 -05001662
1663 /* Treat like rcv logo */
James Smart2e0fef82007-06-17 19:56:36 -05001664 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_PRLO);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001665 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001666}
1667
1668static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001669lpfc_device_recov_mapped_node(struct lpfc_vport *vport,
1670 struct lpfc_nodelist *ndlp,
1671 void *arg,
1672 uint32_t evt)
dea31012005-04-17 16:05:31 -05001673{
James Smart2e0fef82007-06-17 19:56:36 -05001674 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1675
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001676 ndlp->nlp_prev_state = NLP_STE_MAPPED_NODE;
James Smart2e0fef82007-06-17 19:56:36 -05001677 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1678 spin_lock_irq(shost->host_lock);
James Smarta0f9b482006-04-15 11:52:56 -04001679 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
James Smart2e0fef82007-06-17 19:56:36 -05001680 spin_unlock_irq(shost->host_lock);
1681 lpfc_disc_set_adisc(vport, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001682 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001683}
1684
1685static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001686lpfc_rcv_plogi_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1687 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001688{
James Smart2e0fef82007-06-17 19:56:36 -05001689 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1690 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001691
1692 /* Ignore PLOGI if we have an outstanding LOGO */
James Smart0d2b6b82008-06-14 22:52:47 -04001693 if (ndlp->nlp_flag & (NLP_LOGO_SND | NLP_LOGO_ACC))
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001694 return ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05001695 if (lpfc_rcv_plogi(vport, ndlp, cmdiocb)) {
James Smart0d2b6b82008-06-14 22:52:47 -04001696 lpfc_cancel_retry_delay_tmo(vport, ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05001697 spin_lock_irq(shost->host_lock);
James Smart0d2b6b82008-06-14 22:52:47 -04001698 ndlp->nlp_flag &= ~(NLP_NPR_ADISC | NLP_NPR_2B_DISC);
James Smart2e0fef82007-06-17 19:56:36 -05001699 spin_unlock_irq(shost->host_lock);
James Smart0d2b6b82008-06-14 22:52:47 -04001700 } else if (!(ndlp->nlp_flag & NLP_NPR_2B_DISC)) {
1701 /* send PLOGI immediately, move to PLOGI issue state */
1702 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
1703 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
1704 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
1705 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
1706 }
dea31012005-04-17 16:05:31 -05001707 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001708 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001709}
1710
1711static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001712lpfc_rcv_prli_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1713 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001714{
James Smart2e0fef82007-06-17 19:56:36 -05001715 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1716 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1717 struct ls_rjt stat;
dea31012005-04-17 16:05:31 -05001718
1719 memset(&stat, 0, sizeof (struct ls_rjt));
1720 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
1721 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
James Smart858c9f62007-06-17 19:56:39 -05001722 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05001723
1724 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
1725 if (ndlp->nlp_flag & NLP_NPR_ADISC) {
James Smart2e0fef82007-06-17 19:56:36 -05001726 spin_lock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001727 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001728 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
James Smart2e0fef82007-06-17 19:56:36 -05001729 spin_unlock_irq(shost->host_lock);
1730 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
1731 lpfc_issue_els_adisc(vport, ndlp, 0);
dea31012005-04-17 16:05:31 -05001732 } else {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001733 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
James Smart2e0fef82007-06-17 19:56:36 -05001734 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
1735 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
dea31012005-04-17 16:05:31 -05001736 }
1737 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001738 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001739}
1740
1741static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001742lpfc_rcv_logo_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1743 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001744{
James Smart2e0fef82007-06-17 19:56:36 -05001745 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001746
James Smart2e0fef82007-06-17 19:56:36 -05001747 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001748 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001749}
1750
1751static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001752lpfc_rcv_padisc_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1753 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001754{
James Smart2e0fef82007-06-17 19:56:36 -05001755 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001756
James Smart2e0fef82007-06-17 19:56:36 -05001757 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
James Smart33ccf8d2006-08-17 11:57:58 -04001758 /*
1759 * Do not start discovery if discovery is about to start
1760 * or discovery in progress for this node. Starting discovery
1761 * here will affect the counting of discovery threads.
1762 */
James Smart2fb9bd82006-12-02 13:33:57 -05001763 if (!(ndlp->nlp_flag & NLP_DELAY_TMO) &&
James Smart92d7f7b2007-06-17 19:56:38 -05001764 !(ndlp->nlp_flag & NLP_NPR_2B_DISC)) {
dea31012005-04-17 16:05:31 -05001765 if (ndlp->nlp_flag & NLP_NPR_ADISC) {
James Smart92d7f7b2007-06-17 19:56:38 -05001766 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001767 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
James Smart2e0fef82007-06-17 19:56:36 -05001768 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
1769 lpfc_issue_els_adisc(vport, ndlp, 0);
dea31012005-04-17 16:05:31 -05001770 } else {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001771 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
James Smart2e0fef82007-06-17 19:56:36 -05001772 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
1773 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
dea31012005-04-17 16:05:31 -05001774 }
1775 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001776 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001777}
1778
1779static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001780lpfc_rcv_prlo_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1781 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001782{
James Smart2e0fef82007-06-17 19:56:36 -05001783 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1784 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001785
James Smart2e0fef82007-06-17 19:56:36 -05001786 spin_lock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001787 ndlp->nlp_flag |= NLP_LOGO_ACC;
James Smart2e0fef82007-06-17 19:56:36 -05001788 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001789
James Smart51ef4c22007-08-02 11:10:31 -04001790 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05001791
James Smart2e0fef82007-06-17 19:56:36 -05001792 if ((ndlp->nlp_flag & NLP_DELAY_TMO) == 0) {
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001793 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ * 1);
James Smart2e0fef82007-06-17 19:56:36 -05001794 spin_lock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001795 ndlp->nlp_flag |= NLP_DELAY_TMO;
1796 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
James Smart2e0fef82007-06-17 19:56:36 -05001797 spin_unlock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001798 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001799 } else {
James Smart2e0fef82007-06-17 19:56:36 -05001800 spin_lock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001801 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
James Smart2e0fef82007-06-17 19:56:36 -05001802 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001803 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001804 return ndlp->nlp_state;
1805}
dea31012005-04-17 16:05:31 -05001806
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001807static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001808lpfc_cmpl_plogi_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1809 void *arg, uint32_t evt)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001810{
1811 struct lpfc_iocbq *cmdiocb, *rspiocb;
James Smarta0f9b482006-04-15 11:52:56 -04001812 IOCB_t *irsp;
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001813
1814 cmdiocb = (struct lpfc_iocbq *) arg;
1815 rspiocb = cmdiocb->context_un.rsp_iocb;
James Smarta0f9b482006-04-15 11:52:56 -04001816
1817 irsp = &rspiocb->iocb;
1818 if (irsp->ulpStatus) {
James Smarta8adb832007-10-27 13:37:53 -04001819 ndlp->nlp_flag |= NLP_DEFER_RM;
James Smarta0f9b482006-04-15 11:52:56 -04001820 return NLP_STE_FREED_NODE;
1821 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001822 return ndlp->nlp_state;
1823}
1824
1825static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001826lpfc_cmpl_prli_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1827 void *arg, uint32_t evt)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001828{
1829 struct lpfc_iocbq *cmdiocb, *rspiocb;
James Smarta0f9b482006-04-15 11:52:56 -04001830 IOCB_t *irsp;
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001831
1832 cmdiocb = (struct lpfc_iocbq *) arg;
1833 rspiocb = cmdiocb->context_un.rsp_iocb;
James Smarta0f9b482006-04-15 11:52:56 -04001834
1835 irsp = &rspiocb->iocb;
1836 if (irsp->ulpStatus && (ndlp->nlp_flag & NLP_NODEV_REMOVE)) {
James Smart2e0fef82007-06-17 19:56:36 -05001837 lpfc_drop_node(vport, ndlp);
James Smarta0f9b482006-04-15 11:52:56 -04001838 return NLP_STE_FREED_NODE;
1839 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001840 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001841}
1842
1843static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001844lpfc_cmpl_logo_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1845 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001846{
James Smartd7c255b2008-08-24 21:50:00 -04001847 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1848 if (ndlp->nlp_DID == Fabric_DID) {
1849 spin_lock_irq(shost->host_lock);
1850 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
1851 spin_unlock_irq(shost->host_lock);
1852 }
James Smart2e0fef82007-06-17 19:56:36 -05001853 lpfc_unreg_rpi(vport, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001854 return ndlp->nlp_state;
1855}
1856
1857static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001858lpfc_cmpl_adisc_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1859 void *arg, uint32_t evt)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001860{
1861 struct lpfc_iocbq *cmdiocb, *rspiocb;
James Smarta0f9b482006-04-15 11:52:56 -04001862 IOCB_t *irsp;
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001863
1864 cmdiocb = (struct lpfc_iocbq *) arg;
1865 rspiocb = cmdiocb->context_un.rsp_iocb;
James Smarta0f9b482006-04-15 11:52:56 -04001866
1867 irsp = &rspiocb->iocb;
1868 if (irsp->ulpStatus && (ndlp->nlp_flag & NLP_NODEV_REMOVE)) {
James Smart2e0fef82007-06-17 19:56:36 -05001869 lpfc_drop_node(vport, ndlp);
James Smarta0f9b482006-04-15 11:52:56 -04001870 return NLP_STE_FREED_NODE;
1871 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001872 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001873}
1874
1875static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001876lpfc_cmpl_reglogin_npr_node(struct lpfc_vport *vport,
1877 struct lpfc_nodelist *ndlp,
1878 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001879{
James Smart2e0fef82007-06-17 19:56:36 -05001880 LPFC_MBOXQ_t *pmb = (LPFC_MBOXQ_t *) arg;
1881 MAILBOX_t *mb = &pmb->mb;
dea31012005-04-17 16:05:31 -05001882
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001883 if (!mb->mbxStatus)
1884 ndlp->nlp_rpi = mb->un.varWords[0];
James Smarta0f9b482006-04-15 11:52:56 -04001885 else {
1886 if (ndlp->nlp_flag & NLP_NODEV_REMOVE) {
James Smart2e0fef82007-06-17 19:56:36 -05001887 lpfc_drop_node(vport, ndlp);
James Smarta0f9b482006-04-15 11:52:56 -04001888 return NLP_STE_FREED_NODE;
1889 }
1890 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001891 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001892}
1893
1894static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001895lpfc_device_rm_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1896 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001897{
James Smart2e0fef82007-06-17 19:56:36 -05001898 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1899
James Smarta0f9b482006-04-15 11:52:56 -04001900 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
James Smart2e0fef82007-06-17 19:56:36 -05001901 spin_lock_irq(shost->host_lock);
James Smarta0f9b482006-04-15 11:52:56 -04001902 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
James Smart2e0fef82007-06-17 19:56:36 -05001903 spin_unlock_irq(shost->host_lock);
James Smarta0f9b482006-04-15 11:52:56 -04001904 return ndlp->nlp_state;
1905 }
James Smart2e0fef82007-06-17 19:56:36 -05001906 lpfc_drop_node(vport, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001907 return NLP_STE_FREED_NODE;
dea31012005-04-17 16:05:31 -05001908}
1909
1910static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001911lpfc_device_recov_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1912 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001913{
James Smart2e0fef82007-06-17 19:56:36 -05001914 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1915
James Smart92d7f7b2007-06-17 19:56:38 -05001916 /* Don't do anything that will mess up processing of the
1917 * previous RSCN.
1918 */
1919 if (vport->fc_flag & FC_RSCN_DEFERRED)
1920 return ndlp->nlp_state;
1921
James Smarteaf15d52008-12-04 22:39:29 -05001922 lpfc_cancel_retry_delay_tmo(vport, ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05001923 spin_lock_irq(shost->host_lock);
James Smarta0f9b482006-04-15 11:52:56 -04001924 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
James Smart2e0fef82007-06-17 19:56:36 -05001925 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001926 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001927}
1928
1929
1930/* This next section defines the NPort Discovery State Machine */
1931
1932/* There are 4 different double linked lists nodelist entries can reside on.
1933 * The plogi list and adisc list are used when Link Up discovery or RSCN
1934 * processing is needed. Each list holds the nodes that we will send PLOGI
1935 * or ADISC on. These lists will keep track of what nodes will be effected
1936 * by an RSCN, or a Link Up (Typically, all nodes are effected on Link Up).
1937 * The unmapped_list will contain all nodes that we have successfully logged
1938 * into at the Fibre Channel level. The mapped_list will contain all nodes
1939 * that are mapped FCP targets.
1940 */
1941/*
1942 * The bind list is a list of undiscovered (potentially non-existent) nodes
1943 * that we have saved binding information on. This information is used when
1944 * nodes transition from the unmapped to the mapped list.
1945 */
1946/* For UNUSED_NODE state, the node has just been allocated .
1947 * For PLOGI_ISSUE and REG_LOGIN_ISSUE, the node is on
1948 * the PLOGI list. For REG_LOGIN_COMPL, the node is taken off the PLOGI list
1949 * and put on the unmapped list. For ADISC processing, the node is taken off
1950 * the ADISC list and placed on either the mapped or unmapped list (depending
1951 * on its previous state). Once on the unmapped list, a PRLI is issued and the
1952 * state changed to PRLI_ISSUE. When the PRLI completion occurs, the state is
1953 * changed to UNMAPPED_NODE. If the completion indicates a mapped
1954 * node, the node is taken off the unmapped list. The binding list is checked
1955 * for a valid binding, or a binding is automatically assigned. If binding
1956 * assignment is unsuccessful, the node is left on the unmapped list. If
1957 * binding assignment is successful, the associated binding list entry (if
1958 * any) is removed, and the node is placed on the mapped list.
1959 */
1960/*
1961 * For a Link Down, all nodes on the ADISC, PLOGI, unmapped or mapped
James Smartc01f3202006-08-18 17:47:08 -04001962 * lists will receive a DEVICE_RECOVERY event. If the linkdown or devloss timers
dea31012005-04-17 16:05:31 -05001963 * expire, all effected nodes will receive a DEVICE_RM event.
1964 */
1965/*
1966 * For a Link Up or RSCN, all nodes will move from the mapped / unmapped lists
1967 * to either the ADISC or PLOGI list. After a Nameserver query or ALPA loopmap
1968 * check, additional nodes may be added or removed (via DEVICE_RM) to / from
1969 * the PLOGI or ADISC lists. Once the PLOGI and ADISC lists are populated,
1970 * we will first process the ADISC list. 32 entries are processed initially and
1971 * ADISC is initited for each one. Completions / Events for each node are
1972 * funnelled thru the state machine. As each node finishes ADISC processing, it
1973 * starts ADISC for any nodes waiting for ADISC processing. If no nodes are
1974 * waiting, and the ADISC list count is identically 0, then we are done. For
1975 * Link Up discovery, since all nodes on the PLOGI list are UNREG_LOGIN'ed, we
1976 * can issue a CLEAR_LA and reenable Link Events. Next we will process the PLOGI
1977 * list. 32 entries are processed initially and PLOGI is initited for each one.
1978 * Completions / Events for each node are funnelled thru the state machine. As
1979 * each node finishes PLOGI processing, it starts PLOGI for any nodes waiting
1980 * for PLOGI processing. If no nodes are waiting, and the PLOGI list count is
1981 * indentically 0, then we are done. We have now completed discovery / RSCN
1982 * handling. Upon completion, ALL nodes should be on either the mapped or
1983 * unmapped lists.
1984 */
1985
1986static uint32_t (*lpfc_disc_action[NLP_STE_MAX_STATE * NLP_EVT_MAX_EVENT])
James Smart2e0fef82007-06-17 19:56:36 -05001987 (struct lpfc_vport *, struct lpfc_nodelist *, void *, uint32_t) = {
dea31012005-04-17 16:05:31 -05001988 /* Action routine Event Current State */
1989 lpfc_rcv_plogi_unused_node, /* RCV_PLOGI UNUSED_NODE */
1990 lpfc_rcv_els_unused_node, /* RCV_PRLI */
1991 lpfc_rcv_logo_unused_node, /* RCV_LOGO */
1992 lpfc_rcv_els_unused_node, /* RCV_ADISC */
1993 lpfc_rcv_els_unused_node, /* RCV_PDISC */
1994 lpfc_rcv_els_unused_node, /* RCV_PRLO */
1995 lpfc_disc_illegal, /* CMPL_PLOGI */
1996 lpfc_disc_illegal, /* CMPL_PRLI */
1997 lpfc_cmpl_logo_unused_node, /* CMPL_LOGO */
1998 lpfc_disc_illegal, /* CMPL_ADISC */
1999 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2000 lpfc_device_rm_unused_node, /* DEVICE_RM */
2001 lpfc_disc_illegal, /* DEVICE_RECOVERY */
2002
2003 lpfc_rcv_plogi_plogi_issue, /* RCV_PLOGI PLOGI_ISSUE */
James Smart92d7f7b2007-06-17 19:56:38 -05002004 lpfc_rcv_prli_plogi_issue, /* RCV_PRLI */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002005 lpfc_rcv_logo_plogi_issue, /* RCV_LOGO */
dea31012005-04-17 16:05:31 -05002006 lpfc_rcv_els_plogi_issue, /* RCV_ADISC */
2007 lpfc_rcv_els_plogi_issue, /* RCV_PDISC */
2008 lpfc_rcv_els_plogi_issue, /* RCV_PRLO */
2009 lpfc_cmpl_plogi_plogi_issue, /* CMPL_PLOGI */
2010 lpfc_disc_illegal, /* CMPL_PRLI */
James Smart0ff10d42008-01-11 01:52:36 -05002011 lpfc_cmpl_logo_plogi_issue, /* CMPL_LOGO */
dea31012005-04-17 16:05:31 -05002012 lpfc_disc_illegal, /* CMPL_ADISC */
James Smart0ff10d42008-01-11 01:52:36 -05002013 lpfc_cmpl_reglogin_plogi_issue,/* CMPL_REG_LOGIN */
dea31012005-04-17 16:05:31 -05002014 lpfc_device_rm_plogi_issue, /* DEVICE_RM */
2015 lpfc_device_recov_plogi_issue, /* DEVICE_RECOVERY */
2016
2017 lpfc_rcv_plogi_adisc_issue, /* RCV_PLOGI ADISC_ISSUE */
2018 lpfc_rcv_prli_adisc_issue, /* RCV_PRLI */
2019 lpfc_rcv_logo_adisc_issue, /* RCV_LOGO */
2020 lpfc_rcv_padisc_adisc_issue, /* RCV_ADISC */
2021 lpfc_rcv_padisc_adisc_issue, /* RCV_PDISC */
2022 lpfc_rcv_prlo_adisc_issue, /* RCV_PRLO */
2023 lpfc_disc_illegal, /* CMPL_PLOGI */
2024 lpfc_disc_illegal, /* CMPL_PRLI */
2025 lpfc_disc_illegal, /* CMPL_LOGO */
2026 lpfc_cmpl_adisc_adisc_issue, /* CMPL_ADISC */
2027 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2028 lpfc_device_rm_adisc_issue, /* DEVICE_RM */
2029 lpfc_device_recov_adisc_issue, /* DEVICE_RECOVERY */
2030
2031 lpfc_rcv_plogi_reglogin_issue, /* RCV_PLOGI REG_LOGIN_ISSUE */
2032 lpfc_rcv_prli_reglogin_issue, /* RCV_PLOGI */
2033 lpfc_rcv_logo_reglogin_issue, /* RCV_LOGO */
2034 lpfc_rcv_padisc_reglogin_issue, /* RCV_ADISC */
2035 lpfc_rcv_padisc_reglogin_issue, /* RCV_PDISC */
2036 lpfc_rcv_prlo_reglogin_issue, /* RCV_PRLO */
James Smart87af33f2007-10-27 13:37:43 -04002037 lpfc_cmpl_plogi_illegal, /* CMPL_PLOGI */
dea31012005-04-17 16:05:31 -05002038 lpfc_disc_illegal, /* CMPL_PRLI */
2039 lpfc_disc_illegal, /* CMPL_LOGO */
2040 lpfc_disc_illegal, /* CMPL_ADISC */
2041 lpfc_cmpl_reglogin_reglogin_issue,/* CMPL_REG_LOGIN */
2042 lpfc_device_rm_reglogin_issue, /* DEVICE_RM */
2043 lpfc_device_recov_reglogin_issue,/* DEVICE_RECOVERY */
2044
2045 lpfc_rcv_plogi_prli_issue, /* RCV_PLOGI PRLI_ISSUE */
2046 lpfc_rcv_prli_prli_issue, /* RCV_PRLI */
2047 lpfc_rcv_logo_prli_issue, /* RCV_LOGO */
2048 lpfc_rcv_padisc_prli_issue, /* RCV_ADISC */
2049 lpfc_rcv_padisc_prli_issue, /* RCV_PDISC */
2050 lpfc_rcv_prlo_prli_issue, /* RCV_PRLO */
James Smart87af33f2007-10-27 13:37:43 -04002051 lpfc_cmpl_plogi_illegal, /* CMPL_PLOGI */
dea31012005-04-17 16:05:31 -05002052 lpfc_cmpl_prli_prli_issue, /* CMPL_PRLI */
2053 lpfc_disc_illegal, /* CMPL_LOGO */
2054 lpfc_disc_illegal, /* CMPL_ADISC */
2055 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2056 lpfc_device_rm_prli_issue, /* DEVICE_RM */
2057 lpfc_device_recov_prli_issue, /* DEVICE_RECOVERY */
2058
2059 lpfc_rcv_plogi_unmap_node, /* RCV_PLOGI UNMAPPED_NODE */
2060 lpfc_rcv_prli_unmap_node, /* RCV_PRLI */
2061 lpfc_rcv_logo_unmap_node, /* RCV_LOGO */
2062 lpfc_rcv_padisc_unmap_node, /* RCV_ADISC */
2063 lpfc_rcv_padisc_unmap_node, /* RCV_PDISC */
2064 lpfc_rcv_prlo_unmap_node, /* RCV_PRLO */
2065 lpfc_disc_illegal, /* CMPL_PLOGI */
2066 lpfc_disc_illegal, /* CMPL_PRLI */
2067 lpfc_disc_illegal, /* CMPL_LOGO */
2068 lpfc_disc_illegal, /* CMPL_ADISC */
2069 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2070 lpfc_disc_illegal, /* DEVICE_RM */
2071 lpfc_device_recov_unmap_node, /* DEVICE_RECOVERY */
2072
2073 lpfc_rcv_plogi_mapped_node, /* RCV_PLOGI MAPPED_NODE */
2074 lpfc_rcv_prli_mapped_node, /* RCV_PRLI */
2075 lpfc_rcv_logo_mapped_node, /* RCV_LOGO */
2076 lpfc_rcv_padisc_mapped_node, /* RCV_ADISC */
2077 lpfc_rcv_padisc_mapped_node, /* RCV_PDISC */
2078 lpfc_rcv_prlo_mapped_node, /* RCV_PRLO */
2079 lpfc_disc_illegal, /* CMPL_PLOGI */
2080 lpfc_disc_illegal, /* CMPL_PRLI */
2081 lpfc_disc_illegal, /* CMPL_LOGO */
2082 lpfc_disc_illegal, /* CMPL_ADISC */
2083 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2084 lpfc_disc_illegal, /* DEVICE_RM */
2085 lpfc_device_recov_mapped_node, /* DEVICE_RECOVERY */
2086
2087 lpfc_rcv_plogi_npr_node, /* RCV_PLOGI NPR_NODE */
2088 lpfc_rcv_prli_npr_node, /* RCV_PRLI */
2089 lpfc_rcv_logo_npr_node, /* RCV_LOGO */
2090 lpfc_rcv_padisc_npr_node, /* RCV_ADISC */
2091 lpfc_rcv_padisc_npr_node, /* RCV_PDISC */
2092 lpfc_rcv_prlo_npr_node, /* RCV_PRLO */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002093 lpfc_cmpl_plogi_npr_node, /* CMPL_PLOGI */
2094 lpfc_cmpl_prli_npr_node, /* CMPL_PRLI */
dea31012005-04-17 16:05:31 -05002095 lpfc_cmpl_logo_npr_node, /* CMPL_LOGO */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002096 lpfc_cmpl_adisc_npr_node, /* CMPL_ADISC */
dea31012005-04-17 16:05:31 -05002097 lpfc_cmpl_reglogin_npr_node, /* CMPL_REG_LOGIN */
2098 lpfc_device_rm_npr_node, /* DEVICE_RM */
2099 lpfc_device_recov_npr_node, /* DEVICE_RECOVERY */
2100};
2101
2102int
James Smart2e0fef82007-06-17 19:56:36 -05002103lpfc_disc_state_machine(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2104 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05002105{
2106 uint32_t cur_state, rc;
James Smart2e0fef82007-06-17 19:56:36 -05002107 uint32_t(*func) (struct lpfc_vport *, struct lpfc_nodelist *, void *,
dea31012005-04-17 16:05:31 -05002108 uint32_t);
James Smarte47c9092008-02-08 18:49:26 -05002109 uint32_t got_ndlp = 0;
dea31012005-04-17 16:05:31 -05002110
James Smarte47c9092008-02-08 18:49:26 -05002111 if (lpfc_nlp_get(ndlp))
2112 got_ndlp = 1;
2113
dea31012005-04-17 16:05:31 -05002114 cur_state = ndlp->nlp_state;
2115
2116 /* DSM in event <evt> on NPort <nlp_DID> in state <cur_state> */
James Smarte8b62012007-08-02 11:10:09 -04002117 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2118 "0211 DSM in event x%x on NPort x%x in "
2119 "state %d Data: x%x\n",
2120 evt, ndlp->nlp_DID, cur_state, ndlp->nlp_flag);
dea31012005-04-17 16:05:31 -05002121
James Smart858c9f62007-06-17 19:56:39 -05002122 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_DSM,
2123 "DSM in: evt:%d ste:%d did:x%x",
2124 evt, cur_state, ndlp->nlp_DID);
2125
dea31012005-04-17 16:05:31 -05002126 func = lpfc_disc_action[(cur_state * NLP_EVT_MAX_EVENT) + evt];
James Smart2e0fef82007-06-17 19:56:36 -05002127 rc = (func) (vport, ndlp, arg, evt);
dea31012005-04-17 16:05:31 -05002128
2129 /* DSM out state <rc> on NPort <nlp_DID> */
James Smarte47c9092008-02-08 18:49:26 -05002130 if (got_ndlp) {
2131 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
James Smarte8b62012007-08-02 11:10:09 -04002132 "0212 DSM out state %d on NPort x%x Data: x%x\n",
2133 rc, ndlp->nlp_DID, ndlp->nlp_flag);
dea31012005-04-17 16:05:31 -05002134
James Smarte47c9092008-02-08 18:49:26 -05002135 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_DSM,
2136 "DSM out: ste:%d did:x%x flg:x%x",
2137 rc, ndlp->nlp_DID, ndlp->nlp_flag);
2138 /* Decrement the ndlp reference count held for this function */
2139 lpfc_nlp_put(ndlp);
2140 } else {
2141 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
James Smartd7c255b2008-08-24 21:50:00 -04002142 "0213 DSM out state %d on NPort free\n", rc);
James Smart858c9f62007-06-17 19:56:39 -05002143
James Smarte47c9092008-02-08 18:49:26 -05002144 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_DSM,
2145 "DSM out: ste:%d did:x%x flg:x%x",
2146 rc, 0, 0);
2147 }
dea31012005-04-17 16:05:31 -05002148
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002149 return rc;
dea31012005-04-17 16:05:31 -05002150}