blob: d08c4c890744d30b05da9b60dc018e71c2af8bcc [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"
33#include "lpfc_disc.h"
34#include "lpfc_scsi.h"
35#include "lpfc.h"
36#include "lpfc_logmsg.h"
37#include "lpfc_crtn.h"
James Smart92d7f7b2007-06-17 19:56:38 -050038#include "lpfc_vport.h"
James Smart858c9f62007-06-17 19:56:39 -050039#include "lpfc_debugfs.h"
dea31012005-04-17 16:05:31 -050040
41
42/* Called to verify a rcv'ed ADISC was intended for us. */
43static int
James Smart2e0fef82007-06-17 19:56:36 -050044lpfc_check_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
45 struct lpfc_name *nn, struct lpfc_name *pn)
dea31012005-04-17 16:05:31 -050046{
47 /* Compare the ADISC rsp WWNN / WWPN matches our internal node
48 * table entry for that node.
49 */
James Smart2e0fef82007-06-17 19:56:36 -050050 if (memcmp(nn, &ndlp->nlp_nodename, sizeof (struct lpfc_name)))
Jamie Wellnitzc9f87352006-02-28 19:25:23 -050051 return 0;
dea31012005-04-17 16:05:31 -050052
James Smart2e0fef82007-06-17 19:56:36 -050053 if (memcmp(pn, &ndlp->nlp_portname, sizeof (struct lpfc_name)))
Jamie Wellnitzc9f87352006-02-28 19:25:23 -050054 return 0;
dea31012005-04-17 16:05:31 -050055
56 /* we match, return success */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -050057 return 1;
dea31012005-04-17 16:05:31 -050058}
59
dea31012005-04-17 16:05:31 -050060int
James Smart2e0fef82007-06-17 19:56:36 -050061lpfc_check_sparm(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
62 struct serv_parm * sp, uint32_t class)
dea31012005-04-17 16:05:31 -050063{
James Smart2e0fef82007-06-17 19:56:36 -050064 volatile struct serv_parm *hsp = &vport->fc_sparam;
James.Smart@Emulex.Com2fb70f72005-11-28 11:41:24 -050065 uint16_t hsp_value, ssp_value = 0;
dea31012005-04-17 16:05:31 -050066
James.Smart@Emulex.Com2fb70f72005-11-28 11:41:24 -050067 /*
68 * The receive data field size and buffer-to-buffer receive data field
69 * size entries are 16 bits but are represented as two 8-bit fields in
70 * the driver data structure to account for rsvd bits and other control
71 * bits. Reconstruct and compare the fields as a 16-bit values before
72 * correcting the byte values.
73 */
dea31012005-04-17 16:05:31 -050074 if (sp->cls1.classValid) {
James.Smart@Emulex.Com2fb70f72005-11-28 11:41:24 -050075 hsp_value = (hsp->cls1.rcvDataSizeMsb << 8) |
76 hsp->cls1.rcvDataSizeLsb;
77 ssp_value = (sp->cls1.rcvDataSizeMsb << 8) |
78 sp->cls1.rcvDataSizeLsb;
James Smart92d7f7b2007-06-17 19:56:38 -050079 if (!ssp_value)
80 goto bad_service_param;
James.Smart@Emulex.Com2fb70f72005-11-28 11:41:24 -050081 if (ssp_value > hsp_value) {
dea31012005-04-17 16:05:31 -050082 sp->cls1.rcvDataSizeLsb = hsp->cls1.rcvDataSizeLsb;
James.Smart@Emulex.Com2fb70f72005-11-28 11:41:24 -050083 sp->cls1.rcvDataSizeMsb = hsp->cls1.rcvDataSizeMsb;
84 }
dea31012005-04-17 16:05:31 -050085 } else if (class == CLASS1) {
James Smart92d7f7b2007-06-17 19:56:38 -050086 goto bad_service_param;
dea31012005-04-17 16:05:31 -050087 }
88
89 if (sp->cls2.classValid) {
James.Smart@Emulex.Com2fb70f72005-11-28 11:41:24 -050090 hsp_value = (hsp->cls2.rcvDataSizeMsb << 8) |
91 hsp->cls2.rcvDataSizeLsb;
92 ssp_value = (sp->cls2.rcvDataSizeMsb << 8) |
93 sp->cls2.rcvDataSizeLsb;
James Smart92d7f7b2007-06-17 19:56:38 -050094 if (!ssp_value)
95 goto bad_service_param;
James.Smart@Emulex.Com2fb70f72005-11-28 11:41:24 -050096 if (ssp_value > hsp_value) {
dea31012005-04-17 16:05:31 -050097 sp->cls2.rcvDataSizeLsb = hsp->cls2.rcvDataSizeLsb;
James.Smart@Emulex.Com2fb70f72005-11-28 11:41:24 -050098 sp->cls2.rcvDataSizeMsb = hsp->cls2.rcvDataSizeMsb;
99 }
dea31012005-04-17 16:05:31 -0500100 } else if (class == CLASS2) {
James Smart92d7f7b2007-06-17 19:56:38 -0500101 goto bad_service_param;
dea31012005-04-17 16:05:31 -0500102 }
103
104 if (sp->cls3.classValid) {
James.Smart@Emulex.Com2fb70f72005-11-28 11:41:24 -0500105 hsp_value = (hsp->cls3.rcvDataSizeMsb << 8) |
106 hsp->cls3.rcvDataSizeLsb;
107 ssp_value = (sp->cls3.rcvDataSizeMsb << 8) |
108 sp->cls3.rcvDataSizeLsb;
James Smart92d7f7b2007-06-17 19:56:38 -0500109 if (!ssp_value)
110 goto bad_service_param;
James.Smart@Emulex.Com2fb70f72005-11-28 11:41:24 -0500111 if (ssp_value > hsp_value) {
dea31012005-04-17 16:05:31 -0500112 sp->cls3.rcvDataSizeLsb = hsp->cls3.rcvDataSizeLsb;
James.Smart@Emulex.Com2fb70f72005-11-28 11:41:24 -0500113 sp->cls3.rcvDataSizeMsb = hsp->cls3.rcvDataSizeMsb;
114 }
dea31012005-04-17 16:05:31 -0500115 } else if (class == CLASS3) {
James Smart92d7f7b2007-06-17 19:56:38 -0500116 goto bad_service_param;
dea31012005-04-17 16:05:31 -0500117 }
118
James.Smart@Emulex.Com2fb70f72005-11-28 11:41:24 -0500119 /*
120 * Preserve the upper four bits of the MSB from the PLOGI response.
121 * These bits contain the Buffer-to-Buffer State Change Number
122 * from the target and need to be passed to the FW.
123 */
124 hsp_value = (hsp->cmn.bbRcvSizeMsb << 8) | hsp->cmn.bbRcvSizeLsb;
125 ssp_value = (sp->cmn.bbRcvSizeMsb << 8) | sp->cmn.bbRcvSizeLsb;
126 if (ssp_value > hsp_value) {
dea31012005-04-17 16:05:31 -0500127 sp->cmn.bbRcvSizeLsb = hsp->cmn.bbRcvSizeLsb;
James.Smart@Emulex.Com2fb70f72005-11-28 11:41:24 -0500128 sp->cmn.bbRcvSizeMsb = (sp->cmn.bbRcvSizeMsb & 0xF0) |
129 (hsp->cmn.bbRcvSizeMsb & 0x0F);
130 }
dea31012005-04-17 16:05:31 -0500131
dea31012005-04-17 16:05:31 -0500132 memcpy(&ndlp->nlp_nodename, &sp->nodeName, sizeof (struct lpfc_name));
133 memcpy(&ndlp->nlp_portname, &sp->portName, sizeof (struct lpfc_name));
James.Smart@Emulex.Com2fb70f72005-11-28 11:41:24 -0500134 return 1;
James Smart92d7f7b2007-06-17 19:56:38 -0500135bad_service_param:
James Smarte8b62012007-08-02 11:10:09 -0400136 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
137 "0207 Device %x "
138 "(%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x) sent "
139 "invalid service parameters. Ignoring device.\n",
140 ndlp->nlp_DID,
141 sp->nodeName.u.wwn[0], sp->nodeName.u.wwn[1],
142 sp->nodeName.u.wwn[2], sp->nodeName.u.wwn[3],
143 sp->nodeName.u.wwn[4], sp->nodeName.u.wwn[5],
144 sp->nodeName.u.wwn[6], sp->nodeName.u.wwn[7]);
James Smart92d7f7b2007-06-17 19:56:38 -0500145 return 0;
dea31012005-04-17 16:05:31 -0500146}
147
148static void *
James Smart2e0fef82007-06-17 19:56:36 -0500149lpfc_check_elscmpl_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -0500150 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -0500151{
152 struct lpfc_dmabuf *pcmd, *prsp;
153 uint32_t *lp;
154 void *ptr = NULL;
155 IOCB_t *irsp;
156
157 irsp = &rspiocb->iocb;
158 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
159
160 /* For lpfc_els_abort, context2 could be zero'ed to delay
161 * freeing associated memory till after ABTS completes.
162 */
163 if (pcmd) {
164 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf,
165 list);
166 if (prsp) {
167 lp = (uint32_t *) prsp->virt;
168 ptr = (void *)((uint8_t *)lp + sizeof(uint32_t));
169 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500170 } else {
dea31012005-04-17 16:05:31 -0500171 /* Force ulpStatus error since we are returning NULL ptr */
172 if (!(irsp->ulpStatus)) {
173 irsp->ulpStatus = IOSTAT_LOCAL_REJECT;
174 irsp->un.ulpWord[4] = IOERR_SLI_ABORTED;
175 }
176 ptr = NULL;
177 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500178 return ptr;
dea31012005-04-17 16:05:31 -0500179}
180
181
182/*
183 * Free resources / clean up outstanding I/Os
184 * associated with a LPFC_NODELIST entry. This
185 * routine effectively results in a "software abort".
186 */
187int
James Smart2e0fef82007-06-17 19:56:36 -0500188lpfc_els_abort(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -0500189{
James Smart2534ba72007-04-25 09:52:20 -0400190 LIST_HEAD(completions);
James Smart2e0fef82007-06-17 19:56:36 -0500191 struct lpfc_sli *psli = &phba->sli;
192 struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING];
dea31012005-04-17 16:05:31 -0500193 struct lpfc_iocbq *iocb, *next_iocb;
James Smart2534ba72007-04-25 09:52:20 -0400194 IOCB_t *cmd;
dea31012005-04-17 16:05:31 -0500195
196 /* Abort outstanding I/O on NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -0400197 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_DISCOVERY,
198 "0205 Abort outstanding I/O on NPort x%x "
199 "Data: x%x x%x x%x\n",
200 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
201 ndlp->nlp_rpi);
James Smart92d7f7b2007-06-17 19:56:38 -0500202
203 lpfc_fabric_abort_nport(ndlp);
dea31012005-04-17 16:05:31 -0500204
dea31012005-04-17 16:05:31 -0500205 /* First check the txq */
James Smart2e0fef82007-06-17 19:56:36 -0500206 spin_lock_irq(&phba->hbalock);
James Smart2534ba72007-04-25 09:52:20 -0400207 list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
James Smart858c9f62007-06-17 19:56:39 -0500208 /* Check to see if iocb matches the nport we are looking for */
James Smart2534ba72007-04-25 09:52:20 -0400209 if (lpfc_check_sli_ndlp(phba, pring, iocb, ndlp)) {
James Smart858c9f62007-06-17 19:56:39 -0500210 /* It matches, so deque and call compl with anp error */
James Smart2534ba72007-04-25 09:52:20 -0400211 list_move_tail(&iocb->list, &completions);
212 pring->txq_cnt--;
dea31012005-04-17 16:05:31 -0500213 }
James Smart2534ba72007-04-25 09:52:20 -0400214 }
dea31012005-04-17 16:05:31 -0500215
dea31012005-04-17 16:05:31 -0500216 /* Next check the txcmplq */
James Smart07951072007-04-25 09:51:38 -0400217 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
James Smart858c9f62007-06-17 19:56:39 -0500218 /* Check to see if iocb matches the nport we are looking for */
James Smart92d7f7b2007-06-17 19:56:38 -0500219 if (lpfc_check_sli_ndlp(phba, pring, iocb, ndlp)) {
James Smart07951072007-04-25 09:51:38 -0400220 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
James Smart92d7f7b2007-06-17 19:56:38 -0500221 }
James Smart07951072007-04-25 09:51:38 -0400222 }
James Smart2e0fef82007-06-17 19:56:36 -0500223 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500224
James Smart2534ba72007-04-25 09:52:20 -0400225 while (!list_empty(&completions)) {
226 iocb = list_get_first(&completions, struct lpfc_iocbq, list);
227 cmd = &iocb->iocb;
James Smart92d7f7b2007-06-17 19:56:38 -0500228 list_del_init(&iocb->list);
James Smart2534ba72007-04-25 09:52:20 -0400229
James Smart2e0fef82007-06-17 19:56:36 -0500230 if (!iocb->iocb_cmpl)
231 lpfc_sli_release_iocbq(phba, iocb);
232 else {
James Smart2534ba72007-04-25 09:52:20 -0400233 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
234 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
235 (iocb->iocb_cmpl) (phba, iocb, iocb);
James Smart2e0fef82007-06-17 19:56:36 -0500236 }
James Smart2534ba72007-04-25 09:52:20 -0400237 }
238
dea31012005-04-17 16:05:31 -0500239 /* If we are delaying issuing an ELS command, cancel it */
James Smartfdcebe22006-03-07 15:04:01 -0500240 if (ndlp->nlp_flag & NLP_DELAY_TMO)
James Smart2e0fef82007-06-17 19:56:36 -0500241 lpfc_cancel_retry_delay_tmo(phba->pport, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500242 return 0;
dea31012005-04-17 16:05:31 -0500243}
244
245static int
James Smart2e0fef82007-06-17 19:56:36 -0500246lpfc_rcv_plogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
James Smart92d7f7b2007-06-17 19:56:38 -0500247 struct lpfc_iocbq *cmdiocb)
dea31012005-04-17 16:05:31 -0500248{
James Smart2e0fef82007-06-17 19:56:36 -0500249 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
250 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500251 struct lpfc_dmabuf *pcmd;
James Smarte47c9092008-02-08 18:49:26 -0500252 struct lpfc_work_evt *evtp;
dea31012005-04-17 16:05:31 -0500253 uint32_t *lp;
254 IOCB_t *icmd;
255 struct serv_parm *sp;
256 LPFC_MBOXQ_t *mbox;
257 struct ls_rjt stat;
258 int rc;
259
260 memset(&stat, 0, sizeof (struct ls_rjt));
James Smart2e0fef82007-06-17 19:56:36 -0500261 if (vport->port_state <= LPFC_FLOGI) {
dea31012005-04-17 16:05:31 -0500262 /* Before responding to PLOGI, check for pt2pt mode.
263 * If we are pt2pt, with an outstanding FLOGI, abort
264 * the FLOGI and resend it first.
265 */
James Smart2e0fef82007-06-17 19:56:36 -0500266 if (vport->fc_flag & FC_PT2PT) {
James Smart92d7f7b2007-06-17 19:56:38 -0500267 lpfc_els_abort_flogi(phba);
James Smart2e0fef82007-06-17 19:56:36 -0500268 if (!(vport->fc_flag & FC_PT2PT_PLOGI)) {
dea31012005-04-17 16:05:31 -0500269 /* If the other side is supposed to initiate
270 * the PLOGI anyway, just ACC it now and
271 * move on with discovery.
272 */
273 phba->fc_edtov = FF_DEF_EDTOV;
274 phba->fc_ratov = FF_DEF_RATOV;
275 /* Start discovery - this should just do
276 CLEAR_LA */
James Smart2e0fef82007-06-17 19:56:36 -0500277 lpfc_disc_start(vport);
James Smarted957682007-06-17 19:56:37 -0500278 } else
James Smart2e0fef82007-06-17 19:56:36 -0500279 lpfc_initial_flogi(vport);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500280 } else {
dea31012005-04-17 16:05:31 -0500281 stat.un.b.lsRjtRsnCode = LSRJT_LOGICAL_BSY;
282 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
James Smart2e0fef82007-06-17 19:56:36 -0500283 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb,
James Smart858c9f62007-06-17 19:56:39 -0500284 ndlp, NULL);
dea31012005-04-17 16:05:31 -0500285 return 0;
286 }
287 }
288 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
289 lp = (uint32_t *) pcmd->virt;
290 sp = (struct serv_parm *) ((uint8_t *) lp + sizeof (uint32_t));
James Smarta8adb832007-10-27 13:37:53 -0400291 if (wwn_to_u64(sp->portName.u.wwn) == 0) {
292 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
293 "0140 PLOGI Reject: invalid nname\n");
294 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
295 stat.un.b.lsRjtRsnCodeExp = LSEXP_INVALID_PNAME;
296 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
297 NULL);
298 return 0;
299 }
300 if (wwn_to_u64(sp->nodeName.u.wwn) == 0) {
301 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
302 "0141 PLOGI Reject: invalid pname\n");
303 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
304 stat.un.b.lsRjtRsnCodeExp = LSEXP_INVALID_NNAME;
305 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
306 NULL);
307 return 0;
308 }
James Smart2e0fef82007-06-17 19:56:36 -0500309 if ((lpfc_check_sparm(vport, ndlp, sp, CLASS3) == 0)) {
dea31012005-04-17 16:05:31 -0500310 /* Reject this request because invalid parameters */
311 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
312 stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
James Smart858c9f62007-06-17 19:56:39 -0500313 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
314 NULL);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500315 return 0;
dea31012005-04-17 16:05:31 -0500316 }
317 icmd = &cmdiocb->iocb;
318
319 /* PLOGI chkparm OK */
James Smarte8b62012007-08-02 11:10:09 -0400320 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
321 "0114 PLOGI chkparm OK Data: x%x x%x x%x x%x\n",
322 ndlp->nlp_DID, ndlp->nlp_state, ndlp->nlp_flag,
323 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -0500324
James Smart3de2a652007-08-02 11:09:59 -0400325 if (vport->cfg_fcp_class == 2 && sp->cls2.classValid)
dea31012005-04-17 16:05:31 -0500326 ndlp->nlp_fcp_info |= CLASS2;
James Smarted957682007-06-17 19:56:37 -0500327 else
dea31012005-04-17 16:05:31 -0500328 ndlp->nlp_fcp_info |= CLASS3;
James Smart2e0fef82007-06-17 19:56:36 -0500329
dea31012005-04-17 16:05:31 -0500330 ndlp->nlp_class_sup = 0;
331 if (sp->cls1.classValid)
332 ndlp->nlp_class_sup |= FC_COS_CLASS1;
333 if (sp->cls2.classValid)
334 ndlp->nlp_class_sup |= FC_COS_CLASS2;
335 if (sp->cls3.classValid)
336 ndlp->nlp_class_sup |= FC_COS_CLASS3;
337 if (sp->cls4.classValid)
338 ndlp->nlp_class_sup |= FC_COS_CLASS4;
339 ndlp->nlp_maxframe =
340 ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) | sp->cmn.bbRcvSizeLsb;
341
342 /* no need to reg_login if we are already in one of these states */
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500343 switch (ndlp->nlp_state) {
dea31012005-04-17 16:05:31 -0500344 case NLP_STE_NPR_NODE:
345 if (!(ndlp->nlp_flag & NLP_NPR_ADISC))
346 break;
347 case NLP_STE_REG_LOGIN_ISSUE:
348 case NLP_STE_PRLI_ISSUE:
349 case NLP_STE_UNMAPPED_NODE:
350 case NLP_STE_MAPPED_NODE:
James Smart51ef4c22007-08-02 11:10:31 -0400351 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp, NULL);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500352 return 1;
dea31012005-04-17 16:05:31 -0500353 }
354
James Smart92d7f7b2007-06-17 19:56:38 -0500355 if ((vport->fc_flag & FC_PT2PT) &&
356 !(vport->fc_flag & FC_PT2PT_PLOGI)) {
dea31012005-04-17 16:05:31 -0500357 /* rcv'ed PLOGI decides what our NPortId will be */
James Smart2e0fef82007-06-17 19:56:36 -0500358 vport->fc_myDID = icmd->un.rcvels.parmRo;
dea31012005-04-17 16:05:31 -0500359 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
360 if (mbox == NULL)
361 goto out;
362 lpfc_config_link(phba, mbox);
363 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smarted957682007-06-17 19:56:37 -0500364 mbox->vport = vport;
James Smart0b727fe2007-10-27 13:37:25 -0400365 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
dea31012005-04-17 16:05:31 -0500366 if (rc == MBX_NOT_FINISHED) {
James Smart92d7f7b2007-06-17 19:56:38 -0500367 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -0500368 goto out;
369 }
370
James Smart2e0fef82007-06-17 19:56:36 -0500371 lpfc_can_disctmo(vport);
dea31012005-04-17 16:05:31 -0500372 }
373 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
James Smart2e0fef82007-06-17 19:56:36 -0500374 if (!mbox)
dea31012005-04-17 16:05:31 -0500375 goto out;
376
James Smart92d7f7b2007-06-17 19:56:38 -0500377 rc = lpfc_reg_login(phba, vport->vpi, icmd->un.rcvels.remoteID,
378 (uint8_t *) sp, mbox, 0);
James Smart2e0fef82007-06-17 19:56:36 -0500379 if (rc) {
380 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -0500381 goto out;
382 }
383
384 /* ACC PLOGI rsp command needs to execute first,
385 * queue this mbox command to be processed later.
386 */
387 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
James Smart329f9bc2007-04-25 09:53:01 -0400388 /*
389 * mbox->context2 = lpfc_nlp_get(ndlp) deferred until mailbox
390 * command issued in lpfc_cmpl_els_acc().
391 */
James Smart2e0fef82007-06-17 19:56:36 -0500392 mbox->vport = vport;
393 spin_lock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -0500394 ndlp->nlp_flag |= (NLP_ACC_REGLOGIN | NLP_RCV_PLOGI);
James Smart2e0fef82007-06-17 19:56:36 -0500395 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500396
James Smart33ccf8d2006-08-17 11:57:58 -0400397 /*
398 * If there is an outstanding PLOGI issued, abort it before
399 * sending ACC rsp for received PLOGI. If pending plogi
400 * is not canceled here, the plogi will be rejected by
401 * remote port and will be retried. On a configuration with
402 * single discovery thread, this will cause a huge delay in
403 * discovery. Also this will cause multiple state machines
404 * running in parallel for this node.
405 */
406 if (ndlp->nlp_state == NLP_STE_PLOGI_ISSUE) {
407 /* software abort outstanding PLOGI */
James Smart07951072007-04-25 09:51:38 -0400408 lpfc_els_abort(phba, ndlp);
James Smart33ccf8d2006-08-17 11:57:58 -0400409 }
410
James Smart858c9f62007-06-17 19:56:39 -0500411 if ((vport->port_type == LPFC_NPIV_PORT &&
James Smart3de2a652007-08-02 11:09:59 -0400412 vport->cfg_restrict_login)) {
James Smart858c9f62007-06-17 19:56:39 -0500413
414 /* In order to preserve RPIs, we want to cleanup
415 * the default RPI the firmware created to rcv
416 * this ELS request. The only way to do this is
417 * to register, then unregister the RPI.
418 */
419 spin_lock_irq(shost->host_lock);
420 ndlp->nlp_flag |= NLP_RM_DFLT_RPI;
421 spin_unlock_irq(shost->host_lock);
422 stat.un.b.lsRjtRsnCode = LSRJT_INVALID_CMD;
423 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
424 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb,
425 ndlp, mbox);
426 return 1;
427 }
James Smart87af33f2007-10-27 13:37:43 -0400428
429 /* If the remote NPort logs into us, before we can initiate
430 * discovery to them, cleanup the NPort from discovery accordingly.
431 */
432 if (ndlp->nlp_state == NLP_STE_NPR_NODE) {
433 spin_lock_irq(shost->host_lock);
434 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
435 spin_unlock_irq(shost->host_lock);
436 del_timer_sync(&ndlp->nlp_delayfunc);
437 ndlp->nlp_last_elscmd = 0;
438
James Smarte47c9092008-02-08 18:49:26 -0500439 if (!list_empty(&ndlp->els_retry_evt.evt_listp)) {
James Smart87af33f2007-10-27 13:37:43 -0400440 list_del_init(&ndlp->els_retry_evt.evt_listp);
James Smarte47c9092008-02-08 18:49:26 -0500441 /* Decrement ndlp reference count held for the
442 * delayed retry
443 */
444 evtp = &ndlp->els_retry_evt;
445 lpfc_nlp_put((struct lpfc_nodelist *)evtp->evt_arg1);
446 }
James Smart87af33f2007-10-27 13:37:43 -0400447
448 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
449 spin_lock_irq(shost->host_lock);
450 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
451 spin_unlock_irq(shost->host_lock);
James Smart0ff10d42008-01-11 01:52:36 -0500452
453 if ((ndlp->nlp_flag & NLP_ADISC_SND) &&
James Smart58da1ff2008-04-07 10:15:56 -0400454 (vport->num_disc_nodes)) {
James Smart0ff10d42008-01-11 01:52:36 -0500455 /* Check to see if there are more
456 * ADISCs to be sent
457 */
458 lpfc_more_adisc(vport);
459
460 if ((vport->num_disc_nodes == 0) &&
461 (vport->fc_npr_cnt))
462 lpfc_els_disc_plogi(vport);
463
464 if (vport->num_disc_nodes == 0) {
465 spin_lock_irq(shost->host_lock);
466 vport->fc_flag &= ~FC_NDISC_ACTIVE;
467 spin_unlock_irq(shost->host_lock);
468 lpfc_can_disctmo(vport);
469 lpfc_end_rscn(vport);
470 }
471 }
James Smart58da1ff2008-04-07 10:15:56 -0400472 }
473 } else if ((ndlp->nlp_state == NLP_STE_PLOGI_ISSUE) &&
474 (ndlp->nlp_flag & NLP_NPR_2B_DISC) &&
475 (vport->num_disc_nodes)) {
476 spin_lock_irq(shost->host_lock);
477 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
478 spin_unlock_irq(shost->host_lock);
479 /* Check to see if there are more
480 * PLOGIs to be sent
481 */
482 lpfc_more_plogi(vport);
483 if (vport->num_disc_nodes == 0) {
484 spin_lock_irq(shost->host_lock);
485 vport->fc_flag &= ~FC_NDISC_ACTIVE;
486 spin_unlock_irq(shost->host_lock);
487 lpfc_can_disctmo(vport);
488 lpfc_end_rscn(vport);
James Smart87af33f2007-10-27 13:37:43 -0400489 }
490 }
491
James Smart51ef4c22007-08-02 11:10:31 -0400492 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp, mbox);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500493 return 1;
dea31012005-04-17 16:05:31 -0500494
495out:
496 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
497 stat.un.b.lsRjtRsnCodeExp = LSEXP_OUT_OF_RESOURCE;
James Smart858c9f62007-06-17 19:56:39 -0500498 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500499 return 0;
dea31012005-04-17 16:05:31 -0500500}
501
502static int
James Smart2e0fef82007-06-17 19:56:36 -0500503lpfc_rcv_padisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -0500504 struct lpfc_iocbq *cmdiocb)
505{
James Smart2e0fef82007-06-17 19:56:36 -0500506 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -0500507 struct lpfc_dmabuf *pcmd;
James Smart2e0fef82007-06-17 19:56:36 -0500508 struct serv_parm *sp;
509 struct lpfc_name *pnn, *ppn;
dea31012005-04-17 16:05:31 -0500510 struct ls_rjt stat;
511 ADISC *ap;
512 IOCB_t *icmd;
513 uint32_t *lp;
514 uint32_t cmd;
515
516 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
517 lp = (uint32_t *) pcmd->virt;
518
519 cmd = *lp++;
520 if (cmd == ELS_CMD_ADISC) {
521 ap = (ADISC *) lp;
522 pnn = (struct lpfc_name *) & ap->nodeName;
523 ppn = (struct lpfc_name *) & ap->portName;
524 } else {
525 sp = (struct serv_parm *) lp;
526 pnn = (struct lpfc_name *) & sp->nodeName;
527 ppn = (struct lpfc_name *) & sp->portName;
528 }
529
530 icmd = &cmdiocb->iocb;
James Smart2e0fef82007-06-17 19:56:36 -0500531 if (icmd->ulpStatus == 0 && lpfc_check_adisc(vport, ndlp, pnn, ppn)) {
dea31012005-04-17 16:05:31 -0500532 if (cmd == ELS_CMD_ADISC) {
James Smart2e0fef82007-06-17 19:56:36 -0500533 lpfc_els_rsp_adisc_acc(vport, cmdiocb, ndlp);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500534 } else {
James Smart2e0fef82007-06-17 19:56:36 -0500535 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp,
James Smart51ef4c22007-08-02 11:10:31 -0400536 NULL);
dea31012005-04-17 16:05:31 -0500537 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500538 return 1;
dea31012005-04-17 16:05:31 -0500539 }
540 /* Reject this request because invalid parameters */
541 stat.un.b.lsRjtRsvd0 = 0;
542 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
543 stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
544 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -0500545 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -0500546
dea31012005-04-17 16:05:31 -0500547 /* 1 sec timeout */
548 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ);
549
James Smart2e0fef82007-06-17 19:56:36 -0500550 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500551 ndlp->nlp_flag |= NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -0500552 spin_unlock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -0500553 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
554 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -0500555 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500556 return 0;
dea31012005-04-17 16:05:31 -0500557}
558
559static int
James Smart2e0fef82007-06-17 19:56:36 -0500560lpfc_rcv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
561 struct lpfc_iocbq *cmdiocb, uint32_t els_cmd)
dea31012005-04-17 16:05:31 -0500562{
James Smart2e0fef82007-06-17 19:56:36 -0500563 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
564
565 /* Put ndlp in NPR state with 1 sec timeout for plogi, ACC logo */
dea31012005-04-17 16:05:31 -0500566 /* Only call LOGO ACC for first LOGO, this avoids sending unnecessary
567 * PLOGIs during LOGO storms from a device.
568 */
James Smart2e0fef82007-06-17 19:56:36 -0500569 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500570 ndlp->nlp_flag |= NLP_LOGO_ACC;
James Smart2e0fef82007-06-17 19:56:36 -0500571 spin_unlock_irq(shost->host_lock);
James Smart82d9a2a2006-04-15 11:53:05 -0400572 if (els_cmd == ELS_CMD_PRLO)
James Smart51ef4c22007-08-02 11:10:31 -0400573 lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL);
James Smart82d9a2a2006-04-15 11:53:05 -0400574 else
James Smart51ef4c22007-08-02 11:10:31 -0400575 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -0500576
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500577 if (!(ndlp->nlp_type & NLP_FABRIC) ||
James Smart92d7f7b2007-06-17 19:56:38 -0500578 (ndlp->nlp_state == NLP_STE_ADISC_ISSUE)) {
dea31012005-04-17 16:05:31 -0500579 /* Only try to re-login if this is NOT a Fabric Node */
dea31012005-04-17 16:05:31 -0500580 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ * 1);
James Smart2e0fef82007-06-17 19:56:36 -0500581 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500582 ndlp->nlp_flag |= NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -0500583 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500584
Jamie Wellnitz5024ab12006-02-28 19:25:28 -0500585 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
dea31012005-04-17 16:05:31 -0500586 }
James Smart87af33f2007-10-27 13:37:43 -0400587 ndlp->nlp_prev_state = ndlp->nlp_state;
588 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
dea31012005-04-17 16:05:31 -0500589
James Smart2e0fef82007-06-17 19:56:36 -0500590 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500591 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
James Smart2e0fef82007-06-17 19:56:36 -0500592 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500593 /* The driver has to wait until the ACC completes before it continues
594 * processing the LOGO. The action will resume in
595 * lpfc_cmpl_els_logo_acc routine. Since part of processing includes an
596 * unreg_login, the driver waits so the ACC does not get aborted.
597 */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500598 return 0;
dea31012005-04-17 16:05:31 -0500599}
600
601static void
James Smart2e0fef82007-06-17 19:56:36 -0500602lpfc_rcv_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
603 struct lpfc_iocbq *cmdiocb)
dea31012005-04-17 16:05:31 -0500604{
605 struct lpfc_dmabuf *pcmd;
606 uint32_t *lp;
607 PRLI *npr;
608 struct fc_rport *rport = ndlp->rport;
609 u32 roles;
610
611 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
612 lp = (uint32_t *) pcmd->virt;
613 npr = (PRLI *) ((uint8_t *) lp + sizeof (uint32_t));
614
615 ndlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR);
616 ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
James Smart92d7f7b2007-06-17 19:56:38 -0500617 if (npr->prliType == PRLI_FCP_TYPE) {
dea31012005-04-17 16:05:31 -0500618 if (npr->initiatorFunc)
619 ndlp->nlp_type |= NLP_FCP_INITIATOR;
620 if (npr->targetFunc)
621 ndlp->nlp_type |= NLP_FCP_TARGET;
622 if (npr->Retry)
623 ndlp->nlp_fcp_info |= NLP_FCP_2_DEVICE;
624 }
625 if (rport) {
626 /* We need to update the rport role values */
627 roles = FC_RPORT_ROLE_UNKNOWN;
628 if (ndlp->nlp_type & NLP_FCP_INITIATOR)
629 roles |= FC_RPORT_ROLE_FCP_INITIATOR;
630 if (ndlp->nlp_type & NLP_FCP_TARGET)
631 roles |= FC_RPORT_ROLE_FCP_TARGET;
James Smart858c9f62007-06-17 19:56:39 -0500632
633 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
634 "rport rolechg: role:x%x did:x%x flg:x%x",
635 roles, ndlp->nlp_DID, ndlp->nlp_flag);
636
dea31012005-04-17 16:05:31 -0500637 fc_remote_port_rolechg(rport, roles);
638 }
639}
640
641static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -0500642lpfc_disc_set_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -0500643{
James Smart2e0fef82007-06-17 19:56:36 -0500644 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart2e0fef82007-06-17 19:56:36 -0500645
James Smart51ef4c22007-08-02 11:10:31 -0400646 if (!ndlp->nlp_rpi) {
647 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
648 return 0;
649 }
650
James Smart1b32f6a2008-02-08 18:49:39 -0500651 if (!(vport->fc_flag & FC_PT2PT)) {
652 /* Check config parameter use-adisc or FCP-2 */
653 if ((vport->cfg_use_adisc && (vport->fc_flag & FC_RSCN_MODE)) ||
654 ndlp->nlp_fcp_info & NLP_FCP_2_DEVICE) {
655 spin_lock_irq(shost->host_lock);
656 ndlp->nlp_flag |= NLP_NPR_ADISC;
657 spin_unlock_irq(shost->host_lock);
658 return 1;
659 }
James Smart92d7f7b2007-06-17 19:56:38 -0500660 }
661 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
662 lpfc_unreg_rpi(vport, ndlp);
663 return 0;
dea31012005-04-17 16:05:31 -0500664}
665
666static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -0500667lpfc_disc_illegal(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
668 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -0500669{
James Smarte8b62012007-08-02 11:10:09 -0400670 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
James Smarte47c9092008-02-08 18:49:26 -0500671 "0271 Illegal State Transition: node x%x "
James Smarte8b62012007-08-02 11:10:09 -0400672 "event x%x, state x%x Data: x%x x%x\n",
673 ndlp->nlp_DID, evt, ndlp->nlp_state, ndlp->nlp_rpi,
674 ndlp->nlp_flag);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500675 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -0500676}
677
James Smart87af33f2007-10-27 13:37:43 -0400678static uint32_t
679lpfc_cmpl_plogi_illegal(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
680 void *arg, uint32_t evt)
681{
682 /* This transition is only legal if we previously
683 * rcv'ed a PLOGI. Since we don't want 2 discovery threads
684 * working on the same NPortID, do nothing for this thread
685 * to stop it.
686 */
687 if (!(ndlp->nlp_flag & NLP_RCV_PLOGI)) {
688 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
James Smarte47c9092008-02-08 18:49:26 -0500689 "0272 Illegal State Transition: node x%x "
James Smart87af33f2007-10-27 13:37:43 -0400690 "event x%x, state x%x Data: x%x x%x\n",
691 ndlp->nlp_DID, evt, ndlp->nlp_state, ndlp->nlp_rpi,
692 ndlp->nlp_flag);
693 }
694 return ndlp->nlp_state;
695}
696
dea31012005-04-17 16:05:31 -0500697/* Start of Discovery State Machine routines */
698
699static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -0500700lpfc_rcv_plogi_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
701 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -0500702{
703 struct lpfc_iocbq *cmdiocb;
704
705 cmdiocb = (struct lpfc_iocbq *) arg;
706
James Smart2e0fef82007-06-17 19:56:36 -0500707 if (lpfc_rcv_plogi(vport, ndlp, cmdiocb)) {
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500708 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -0500709 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500710 return NLP_STE_FREED_NODE;
dea31012005-04-17 16:05:31 -0500711}
712
713static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -0500714lpfc_rcv_els_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
715 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -0500716{
James Smart2e0fef82007-06-17 19:56:36 -0500717 lpfc_issue_els_logo(vport, ndlp, 0);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500718 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -0500719}
720
721static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -0500722lpfc_rcv_logo_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
723 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -0500724{
James Smart2e0fef82007-06-17 19:56:36 -0500725 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
726 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -0500727
James Smart2e0fef82007-06-17 19:56:36 -0500728 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500729 ndlp->nlp_flag |= NLP_LOGO_ACC;
James Smart2e0fef82007-06-17 19:56:36 -0500730 spin_unlock_irq(shost->host_lock);
James Smart51ef4c22007-08-02 11:10:31 -0400731 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -0500732
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500733 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -0500734}
735
736static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -0500737lpfc_cmpl_logo_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -0500738 void *arg, uint32_t evt)
739{
James Smart2e0fef82007-06-17 19:56:36 -0500740 return NLP_STE_FREED_NODE;
741}
742
743static uint32_t
744lpfc_device_rm_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
745 void *arg, uint32_t evt)
746{
James Smart2e0fef82007-06-17 19:56:36 -0500747 return NLP_STE_FREED_NODE;
748}
749
750static uint32_t
751lpfc_rcv_plogi_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
752 void *arg, uint32_t evt)
753{
754 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500755 struct lpfc_iocbq *cmdiocb = arg;
James Smart2e0fef82007-06-17 19:56:36 -0500756 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
757 uint32_t *lp = (uint32_t *) pcmd->virt;
758 struct serv_parm *sp = (struct serv_parm *) (lp + 1);
dea31012005-04-17 16:05:31 -0500759 struct ls_rjt stat;
760 int port_cmp;
761
dea31012005-04-17 16:05:31 -0500762 memset(&stat, 0, sizeof (struct ls_rjt));
763
764 /* For a PLOGI, we only accept if our portname is less
765 * than the remote portname.
766 */
767 phba->fc_stat.elsLogiCol++;
James Smart2e0fef82007-06-17 19:56:36 -0500768 port_cmp = memcmp(&vport->fc_portname, &sp->portName,
James Smart92d7f7b2007-06-17 19:56:38 -0500769 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -0500770
771 if (port_cmp >= 0) {
772 /* Reject this request because the remote node will accept
773 ours */
774 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
775 stat.un.b.lsRjtRsnCodeExp = LSEXP_CMD_IN_PROGRESS;
James Smart858c9f62007-06-17 19:56:39 -0500776 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
777 NULL);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500778 } else {
James Smart2e0fef82007-06-17 19:56:36 -0500779 lpfc_rcv_plogi(vport, ndlp, cmdiocb);
780 } /* If our portname was less */
dea31012005-04-17 16:05:31 -0500781
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500782 return ndlp->nlp_state;
783}
784
785static uint32_t
James Smart92d7f7b2007-06-17 19:56:38 -0500786lpfc_rcv_prli_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
787 void *arg, uint32_t evt)
788{
789 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
790 struct ls_rjt stat;
791
792 memset(&stat, 0, sizeof (struct ls_rjt));
793 stat.un.b.lsRjtRsnCode = LSRJT_LOGICAL_BSY;
794 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
James Smart858c9f62007-06-17 19:56:39 -0500795 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
James Smart92d7f7b2007-06-17 19:56:38 -0500796 return ndlp->nlp_state;
797}
798
799static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -0500800lpfc_rcv_logo_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
801 void *arg, uint32_t evt)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500802{
James Smart2e0fef82007-06-17 19:56:36 -0500803 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500804
James Smart92d7f7b2007-06-17 19:56:38 -0500805 /* software abort outstanding PLOGI */
James Smart2e0fef82007-06-17 19:56:36 -0500806 lpfc_els_abort(vport->phba, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500807
James Smart2e0fef82007-06-17 19:56:36 -0500808 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500809 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -0500810}
811
812static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -0500813lpfc_rcv_els_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
814 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -0500815{
James Smart2e0fef82007-06-17 19:56:36 -0500816 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
817 struct lpfc_hba *phba = vport->phba;
818 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -0500819
820 /* software abort outstanding PLOGI */
James Smart07951072007-04-25 09:51:38 -0400821 lpfc_els_abort(phba, ndlp);
dea31012005-04-17 16:05:31 -0500822
823 if (evt == NLP_EVT_RCV_LOGO) {
James Smart51ef4c22007-08-02 11:10:31 -0400824 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500825 } else {
James Smart2e0fef82007-06-17 19:56:36 -0500826 lpfc_issue_els_logo(vport, ndlp, 0);
dea31012005-04-17 16:05:31 -0500827 }
828
James Smart2e0fef82007-06-17 19:56:36 -0500829 /* Put ndlp in npr state set plogi timer for 1 sec */
Jamie Wellnitz5024ab12006-02-28 19:25:28 -0500830 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ * 1);
James Smart2e0fef82007-06-17 19:56:36 -0500831 spin_lock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -0500832 ndlp->nlp_flag |= NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -0500833 spin_unlock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -0500834 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
835 ndlp->nlp_prev_state = NLP_STE_PLOGI_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -0500836 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
dea31012005-04-17 16:05:31 -0500837
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500838 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -0500839}
840
841static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -0500842lpfc_cmpl_plogi_plogi_issue(struct lpfc_vport *vport,
843 struct lpfc_nodelist *ndlp,
844 void *arg,
dea31012005-04-17 16:05:31 -0500845 uint32_t evt)
846{
James Smart2e0fef82007-06-17 19:56:36 -0500847 struct lpfc_hba *phba = vport->phba;
James Smart0ff10d42008-01-11 01:52:36 -0500848 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart2e0fef82007-06-17 19:56:36 -0500849 struct lpfc_iocbq *cmdiocb, *rspiocb;
James Smart14691152006-12-02 13:34:28 -0500850 struct lpfc_dmabuf *pcmd, *prsp, *mp;
dea31012005-04-17 16:05:31 -0500851 uint32_t *lp;
852 IOCB_t *irsp;
853 struct serv_parm *sp;
854 LPFC_MBOXQ_t *mbox;
855
856 cmdiocb = (struct lpfc_iocbq *) arg;
857 rspiocb = cmdiocb->context_un.rsp_iocb;
858
859 if (ndlp->nlp_flag & NLP_ACC_REGLOGIN) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -0500860 /* Recovery from PLOGI collision logic */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500861 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -0500862 }
863
864 irsp = &rspiocb->iocb;
865
866 if (irsp->ulpStatus)
867 goto out;
868
869 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
870
James Smart2e0fef82007-06-17 19:56:36 -0500871 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
dea31012005-04-17 16:05:31 -0500872
James Smart2e0fef82007-06-17 19:56:36 -0500873 lp = (uint32_t *) prsp->virt;
dea31012005-04-17 16:05:31 -0500874 sp = (struct serv_parm *) ((uint8_t *) lp + sizeof (uint32_t));
James Smart58da1ff2008-04-07 10:15:56 -0400875
876 /* Some switches have FDMI servers returning 0 for WWN */
877 if ((ndlp->nlp_DID != FDMI_DID) &&
878 (wwn_to_u64(sp->portName.u.wwn) == 0 ||
879 wwn_to_u64(sp->nodeName.u.wwn) == 0)) {
James Smarta8adb832007-10-27 13:37:53 -0400880 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
881 "0142 PLOGI RSP: Invalid WWN.\n");
882 goto out;
883 }
James Smart2e0fef82007-06-17 19:56:36 -0500884 if (!lpfc_check_sparm(vport, ndlp, sp, CLASS3))
dea31012005-04-17 16:05:31 -0500885 goto out;
dea31012005-04-17 16:05:31 -0500886 /* PLOGI chkparm OK */
James Smarte8b62012007-08-02 11:10:09 -0400887 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
888 "0121 PLOGI chkparm OK Data: x%x x%x x%x x%x\n",
889 ndlp->nlp_DID, ndlp->nlp_state,
890 ndlp->nlp_flag, ndlp->nlp_rpi);
James Smart3de2a652007-08-02 11:09:59 -0400891 if (vport->cfg_fcp_class == 2 && (sp->cls2.classValid))
dea31012005-04-17 16:05:31 -0500892 ndlp->nlp_fcp_info |= CLASS2;
James Smart2e0fef82007-06-17 19:56:36 -0500893 else
dea31012005-04-17 16:05:31 -0500894 ndlp->nlp_fcp_info |= CLASS3;
James Smart2e0fef82007-06-17 19:56:36 -0500895
dea31012005-04-17 16:05:31 -0500896 ndlp->nlp_class_sup = 0;
897 if (sp->cls1.classValid)
898 ndlp->nlp_class_sup |= FC_COS_CLASS1;
899 if (sp->cls2.classValid)
900 ndlp->nlp_class_sup |= FC_COS_CLASS2;
901 if (sp->cls3.classValid)
902 ndlp->nlp_class_sup |= FC_COS_CLASS3;
903 if (sp->cls4.classValid)
904 ndlp->nlp_class_sup |= FC_COS_CLASS4;
905 ndlp->nlp_maxframe =
James Smart2e0fef82007-06-17 19:56:36 -0500906 ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) | sp->cmn.bbRcvSizeLsb;
dea31012005-04-17 16:05:31 -0500907
James Smart2e0fef82007-06-17 19:56:36 -0500908 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
James Smart92d7f7b2007-06-17 19:56:38 -0500909 if (!mbox) {
James Smarte8b62012007-08-02 11:10:09 -0400910 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
911 "0133 PLOGI: no memory for reg_login "
James Smart92d7f7b2007-06-17 19:56:38 -0500912 "Data: x%x x%x x%x x%x\n",
James Smart92d7f7b2007-06-17 19:56:38 -0500913 ndlp->nlp_DID, ndlp->nlp_state,
914 ndlp->nlp_flag, ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -0500915 goto out;
James Smart92d7f7b2007-06-17 19:56:38 -0500916 }
dea31012005-04-17 16:05:31 -0500917
James Smart2e0fef82007-06-17 19:56:36 -0500918 lpfc_unreg_rpi(vport, ndlp);
919
James Smart92d7f7b2007-06-17 19:56:38 -0500920 if (lpfc_reg_login(phba, vport->vpi, irsp->un.elsreq64.remoteID,
921 (uint8_t *) sp, mbox, 0) == 0) {
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500922 switch (ndlp->nlp_DID) {
dea31012005-04-17 16:05:31 -0500923 case NameServer_DID:
James Smartde0c5b32007-04-25 09:52:27 -0400924 mbox->mbox_cmpl = lpfc_mbx_cmpl_ns_reg_login;
dea31012005-04-17 16:05:31 -0500925 break;
926 case FDMI_DID:
James Smartde0c5b32007-04-25 09:52:27 -0400927 mbox->mbox_cmpl = lpfc_mbx_cmpl_fdmi_reg_login;
dea31012005-04-17 16:05:31 -0500928 break;
929 default:
James Smartde0c5b32007-04-25 09:52:27 -0400930 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
dea31012005-04-17 16:05:31 -0500931 }
James Smart329f9bc2007-04-25 09:53:01 -0400932 mbox->context2 = lpfc_nlp_get(ndlp);
James Smart2e0fef82007-06-17 19:56:36 -0500933 mbox->vport = vport;
James Smart0b727fe2007-10-27 13:37:25 -0400934 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
dea31012005-04-17 16:05:31 -0500935 != MBX_NOT_FINISHED) {
James Smart2e0fef82007-06-17 19:56:36 -0500936 lpfc_nlp_set_state(vport, ndlp,
937 NLP_STE_REG_LOGIN_ISSUE);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500938 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -0500939 }
James Smartfa4066b2008-01-11 01:53:27 -0500940 /* decrement node reference count to the failed mbox
941 * command
942 */
James Smart329f9bc2007-04-25 09:53:01 -0400943 lpfc_nlp_put(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -0500944 mp = (struct lpfc_dmabuf *) mbox->context1;
James Smart14691152006-12-02 13:34:28 -0500945 lpfc_mbuf_free(phba, mp->virt, mp->phys);
946 kfree(mp);
dea31012005-04-17 16:05:31 -0500947 mempool_free(mbox, phba->mbox_mem_pool);
James Smart92d7f7b2007-06-17 19:56:38 -0500948
James Smarte8b62012007-08-02 11:10:09 -0400949 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
950 "0134 PLOGI: cannot issue reg_login "
951 "Data: x%x x%x x%x x%x\n",
952 ndlp->nlp_DID, ndlp->nlp_state,
953 ndlp->nlp_flag, ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -0500954 } else {
955 mempool_free(mbox, phba->mbox_mem_pool);
James Smart92d7f7b2007-06-17 19:56:38 -0500956
James Smarte8b62012007-08-02 11:10:09 -0400957 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
958 "0135 PLOGI: cannot format reg_login "
959 "Data: x%x x%x x%x x%x\n",
960 ndlp->nlp_DID, ndlp->nlp_state,
961 ndlp->nlp_flag, ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -0500962 }
963
964
James Smart92d7f7b2007-06-17 19:56:38 -0500965out:
966 if (ndlp->nlp_DID == NameServer_DID) {
967 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -0400968 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
969 "0261 Cannot Register NameServer login\n");
James Smart92d7f7b2007-06-17 19:56:38 -0500970 }
971
James Smart0ff10d42008-01-11 01:52:36 -0500972 spin_lock_irq(shost->host_lock);
James Smarta8adb832007-10-27 13:37:53 -0400973 ndlp->nlp_flag |= NLP_DEFER_RM;
James Smart0ff10d42008-01-11 01:52:36 -0500974 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500975 return NLP_STE_FREED_NODE;
dea31012005-04-17 16:05:31 -0500976}
977
978static uint32_t
James Smart0ff10d42008-01-11 01:52:36 -0500979lpfc_cmpl_logo_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
980 void *arg, uint32_t evt)
981{
982 return ndlp->nlp_state;
983}
984
985static uint32_t
986lpfc_cmpl_reglogin_plogi_issue(struct lpfc_vport *vport,
987 struct lpfc_nodelist *ndlp, void *arg, uint32_t evt)
988{
989 return ndlp->nlp_state;
990}
991
992static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -0500993lpfc_device_rm_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
994 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -0500995{
James Smart2e0fef82007-06-17 19:56:36 -0500996 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -0500997
James Smart2e0fef82007-06-17 19:56:36 -0500998 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
999 spin_lock_irq(shost->host_lock);
1000 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
1001 spin_unlock_irq(shost->host_lock);
1002 return ndlp->nlp_state;
1003 } else {
1004 /* software abort outstanding PLOGI */
1005 lpfc_els_abort(vport->phba, ndlp);
1006
1007 lpfc_drop_node(vport, ndlp);
James Smarta0f9b482006-04-15 11:52:56 -04001008 return NLP_STE_FREED_NODE;
1009 }
dea31012005-04-17 16:05:31 -05001010}
1011
1012static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001013lpfc_device_recov_plogi_issue(struct lpfc_vport *vport,
1014 struct lpfc_nodelist *ndlp,
1015 void *arg,
1016 uint32_t evt)
dea31012005-04-17 16:05:31 -05001017{
James Smart2e0fef82007-06-17 19:56:36 -05001018 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1019 struct lpfc_hba *phba = vport->phba;
1020
James Smart92d7f7b2007-06-17 19:56:38 -05001021 /* Don't do anything that will mess up processing of the
1022 * previous RSCN.
1023 */
1024 if (vport->fc_flag & FC_RSCN_DEFERRED)
1025 return ndlp->nlp_state;
1026
dea31012005-04-17 16:05:31 -05001027 /* software abort outstanding PLOGI */
James Smart07951072007-04-25 09:51:38 -04001028 lpfc_els_abort(phba, ndlp);
dea31012005-04-17 16:05:31 -05001029
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001030 ndlp->nlp_prev_state = NLP_STE_PLOGI_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -05001031 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
James Smart92d7f7b2007-06-17 19:56:38 -05001032 spin_lock_irq(shost->host_lock);
James Smarta0f9b482006-04-15 11:52:56 -04001033 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
James Smart2e0fef82007-06-17 19:56:36 -05001034 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001035
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001036 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001037}
1038
1039static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001040lpfc_rcv_plogi_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1041 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001042{
James Smart2e0fef82007-06-17 19:56:36 -05001043 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001044 struct lpfc_iocbq *cmdiocb;
1045
1046 /* software abort outstanding ADISC */
James Smart07951072007-04-25 09:51:38 -04001047 lpfc_els_abort(phba, ndlp);
dea31012005-04-17 16:05:31 -05001048
1049 cmdiocb = (struct lpfc_iocbq *) arg;
1050
James Smart2e0fef82007-06-17 19:56:36 -05001051 if (lpfc_rcv_plogi(vport, ndlp, cmdiocb))
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001052 return ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05001053
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001054 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -05001055 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
1056 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
dea31012005-04-17 16:05:31 -05001057
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_rcv_prli_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1063 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001064{
James Smart2e0fef82007-06-17 19:56:36 -05001065 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001066
James Smart2e0fef82007-06-17 19:56:36 -05001067 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001068 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001069}
1070
1071static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001072lpfc_rcv_logo_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1073 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001074{
James Smart2e0fef82007-06-17 19:56:36 -05001075 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001076 struct lpfc_iocbq *cmdiocb;
1077
1078 cmdiocb = (struct lpfc_iocbq *) arg;
1079
1080 /* software abort outstanding ADISC */
James Smart07951072007-04-25 09:51:38 -04001081 lpfc_els_abort(phba, ndlp);
dea31012005-04-17 16:05:31 -05001082
James Smart2e0fef82007-06-17 19:56:36 -05001083 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001084 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001085}
1086
1087static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001088lpfc_rcv_padisc_adisc_issue(struct lpfc_vport *vport,
1089 struct lpfc_nodelist *ndlp,
1090 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001091{
1092 struct lpfc_iocbq *cmdiocb;
1093
1094 cmdiocb = (struct lpfc_iocbq *) arg;
1095
James Smart2e0fef82007-06-17 19:56:36 -05001096 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001097 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001098}
1099
1100static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001101lpfc_rcv_prlo_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1102 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001103{
1104 struct lpfc_iocbq *cmdiocb;
1105
1106 cmdiocb = (struct lpfc_iocbq *) arg;
1107
1108 /* Treat like rcv logo */
James Smart2e0fef82007-06-17 19:56:36 -05001109 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_PRLO);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001110 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001111}
1112
1113static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001114lpfc_cmpl_adisc_adisc_issue(struct lpfc_vport *vport,
1115 struct lpfc_nodelist *ndlp,
1116 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001117{
James Smart2e0fef82007-06-17 19:56:36 -05001118 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1119 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001120 struct lpfc_iocbq *cmdiocb, *rspiocb;
1121 IOCB_t *irsp;
1122 ADISC *ap;
1123
1124 cmdiocb = (struct lpfc_iocbq *) arg;
1125 rspiocb = cmdiocb->context_un.rsp_iocb;
1126
1127 ap = (ADISC *)lpfc_check_elscmpl_iocb(phba, cmdiocb, rspiocb);
1128 irsp = &rspiocb->iocb;
1129
1130 if ((irsp->ulpStatus) ||
James Smart92d7f7b2007-06-17 19:56:38 -05001131 (!lpfc_check_adisc(vport, ndlp, &ap->nodeName, &ap->portName))) {
dea31012005-04-17 16:05:31 -05001132 /* 1 sec timeout */
1133 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ);
James Smart2e0fef82007-06-17 19:56:36 -05001134 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001135 ndlp->nlp_flag |= NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05001136 spin_unlock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001137 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
dea31012005-04-17 16:05:31 -05001138
James Smart2e0fef82007-06-17 19:56:36 -05001139 memset(&ndlp->nlp_nodename, 0, sizeof(struct lpfc_name));
1140 memset(&ndlp->nlp_portname, 0, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05001141
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001142 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -05001143 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1144 lpfc_unreg_rpi(vport, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001145 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001146 }
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001147
James.Smart@Emulex.Com25013222005-06-25 10:34:33 -04001148 if (ndlp->nlp_type & NLP_FCP_TARGET) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001149 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -05001150 lpfc_nlp_set_state(vport, ndlp, NLP_STE_MAPPED_NODE);
James.Smart@Emulex.Com25013222005-06-25 10:34:33 -04001151 } else {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001152 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -05001153 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
James.Smart@Emulex.Com25013222005-06-25 10:34:33 -04001154 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001155 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001156}
1157
1158static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001159lpfc_device_rm_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1160 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001161{
James Smart2e0fef82007-06-17 19:56:36 -05001162 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001163
James Smart2e0fef82007-06-17 19:56:36 -05001164 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1165 spin_lock_irq(shost->host_lock);
1166 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
1167 spin_unlock_irq(shost->host_lock);
1168 return ndlp->nlp_state;
1169 } else {
1170 /* software abort outstanding ADISC */
1171 lpfc_els_abort(vport->phba, ndlp);
1172
1173 lpfc_drop_node(vport, ndlp);
James Smarta0f9b482006-04-15 11:52:56 -04001174 return NLP_STE_FREED_NODE;
1175 }
dea31012005-04-17 16:05:31 -05001176}
1177
1178static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001179lpfc_device_recov_adisc_issue(struct lpfc_vport *vport,
1180 struct lpfc_nodelist *ndlp,
1181 void *arg,
1182 uint32_t evt)
dea31012005-04-17 16:05:31 -05001183{
James Smart2e0fef82007-06-17 19:56:36 -05001184 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1185 struct lpfc_hba *phba = vport->phba;
1186
James Smart92d7f7b2007-06-17 19:56:38 -05001187 /* Don't do anything that will mess up processing of the
1188 * previous RSCN.
1189 */
1190 if (vport->fc_flag & FC_RSCN_DEFERRED)
1191 return ndlp->nlp_state;
1192
dea31012005-04-17 16:05:31 -05001193 /* software abort outstanding ADISC */
James Smart07951072007-04-25 09:51:38 -04001194 lpfc_els_abort(phba, ndlp);
dea31012005-04-17 16:05:31 -05001195
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001196 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -05001197 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1198 spin_lock_irq(shost->host_lock);
James Smarta0f9b482006-04-15 11:52:56 -04001199 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
James Smart2e0fef82007-06-17 19:56:36 -05001200 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05001201 lpfc_disc_set_adisc(vport, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001202 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001203}
1204
1205static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001206lpfc_rcv_plogi_reglogin_issue(struct lpfc_vport *vport,
1207 struct lpfc_nodelist *ndlp,
1208 void *arg,
dea31012005-04-17 16:05:31 -05001209 uint32_t evt)
1210{
James Smart2e0fef82007-06-17 19:56:36 -05001211 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001212
James Smart2e0fef82007-06-17 19:56:36 -05001213 lpfc_rcv_plogi(vport, ndlp, cmdiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001214 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001215}
1216
1217static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001218lpfc_rcv_prli_reglogin_issue(struct lpfc_vport *vport,
1219 struct lpfc_nodelist *ndlp,
1220 void *arg,
dea31012005-04-17 16:05:31 -05001221 uint32_t evt)
1222{
James Smart2e0fef82007-06-17 19:56:36 -05001223 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001224
James Smart2e0fef82007-06-17 19:56:36 -05001225 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001226 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001227}
1228
1229static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001230lpfc_rcv_logo_reglogin_issue(struct lpfc_vport *vport,
1231 struct lpfc_nodelist *ndlp,
1232 void *arg,
dea31012005-04-17 16:05:31 -05001233 uint32_t evt)
1234{
James Smart2e0fef82007-06-17 19:56:36 -05001235 struct lpfc_hba *phba = vport->phba;
1236 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
James Smart7054a602007-04-25 09:52:34 -04001237 LPFC_MBOXQ_t *mb;
1238 LPFC_MBOXQ_t *nextmb;
1239 struct lpfc_dmabuf *mp;
dea31012005-04-17 16:05:31 -05001240
1241 cmdiocb = (struct lpfc_iocbq *) arg;
1242
James Smart7054a602007-04-25 09:52:34 -04001243 /* cleanup any ndlp on mbox q waiting for reglogin cmpl */
1244 if ((mb = phba->sli.mbox_active)) {
1245 if ((mb->mb.mbxCommand == MBX_REG_LOGIN64) &&
1246 (ndlp == (struct lpfc_nodelist *) mb->context2)) {
James Smart92d7f7b2007-06-17 19:56:38 -05001247 lpfc_nlp_put(ndlp);
James Smart7054a602007-04-25 09:52:34 -04001248 mb->context2 = NULL;
1249 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1250 }
1251 }
1252
James Smart2e0fef82007-06-17 19:56:36 -05001253 spin_lock_irq(&phba->hbalock);
James Smart7054a602007-04-25 09:52:34 -04001254 list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) {
1255 if ((mb->mb.mbxCommand == MBX_REG_LOGIN64) &&
1256 (ndlp == (struct lpfc_nodelist *) mb->context2)) {
1257 mp = (struct lpfc_dmabuf *) (mb->context1);
1258 if (mp) {
James Smart98c9ea52007-10-27 13:37:33 -04001259 __lpfc_mbuf_free(phba, mp->virt, mp->phys);
James Smart7054a602007-04-25 09:52:34 -04001260 kfree(mp);
1261 }
James Smart92d7f7b2007-06-17 19:56:38 -05001262 lpfc_nlp_put(ndlp);
James Smart7054a602007-04-25 09:52:34 -04001263 list_del(&mb->list);
1264 mempool_free(mb, phba->mbox_mem_pool);
1265 }
1266 }
James Smart2e0fef82007-06-17 19:56:36 -05001267 spin_unlock_irq(&phba->hbalock);
James Smart7054a602007-04-25 09:52:34 -04001268
James Smart2e0fef82007-06-17 19:56:36 -05001269 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001270 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001271}
1272
1273static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001274lpfc_rcv_padisc_reglogin_issue(struct lpfc_vport *vport,
1275 struct lpfc_nodelist *ndlp,
1276 void *arg,
dea31012005-04-17 16:05:31 -05001277 uint32_t evt)
1278{
James Smart2e0fef82007-06-17 19:56:36 -05001279 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001280
James Smart2e0fef82007-06-17 19:56:36 -05001281 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001282 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001283}
1284
1285static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001286lpfc_rcv_prlo_reglogin_issue(struct lpfc_vport *vport,
1287 struct lpfc_nodelist *ndlp,
1288 void *arg,
dea31012005-04-17 16:05:31 -05001289 uint32_t evt)
1290{
1291 struct lpfc_iocbq *cmdiocb;
1292
1293 cmdiocb = (struct lpfc_iocbq *) arg;
James Smart51ef4c22007-08-02 11:10:31 -04001294 lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001295 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001296}
1297
1298static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001299lpfc_cmpl_reglogin_reglogin_issue(struct lpfc_vport *vport,
1300 struct lpfc_nodelist *ndlp,
1301 void *arg,
1302 uint32_t evt)
dea31012005-04-17 16:05:31 -05001303{
James Smart2e0fef82007-06-17 19:56:36 -05001304 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart2e0fef82007-06-17 19:56:36 -05001305 LPFC_MBOXQ_t *pmb = (LPFC_MBOXQ_t *) arg;
1306 MAILBOX_t *mb = &pmb->mb;
1307 uint32_t did = mb->un.varWords[1];
dea31012005-04-17 16:05:31 -05001308
dea31012005-04-17 16:05:31 -05001309 if (mb->mbxStatus) {
1310 /* RegLogin failed */
James Smarte8b62012007-08-02 11:10:09 -04001311 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
1312 "0246 RegLogin failed Data: x%x x%x x%x\n",
James Smart2e0fef82007-06-17 19:56:36 -05001313 did, mb->mbxStatus, vport->port_state);
James Smartd0e56da2006-07-06 15:49:42 -04001314 /*
1315 * If RegLogin failed due to lack of HBA resources do not
1316 * retry discovery.
1317 */
1318 if (mb->mbxStatus == MBXERR_RPI_FULL) {
James Smart87af33f2007-10-27 13:37:43 -04001319 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
1320 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
James Smartd0e56da2006-07-06 15:49:42 -04001321 return ndlp->nlp_state;
1322 }
1323
James Smart2e0fef82007-06-17 19:56:36 -05001324 /* Put ndlp in npr state set plogi timer for 1 sec */
dea31012005-04-17 16:05:31 -05001325 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ * 1);
James Smart2e0fef82007-06-17 19:56:36 -05001326 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001327 ndlp->nlp_flag |= NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05001328 spin_unlock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001329 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
dea31012005-04-17 16:05:31 -05001330
James Smart2e0fef82007-06-17 19:56:36 -05001331 lpfc_issue_els_logo(vport, ndlp, 0);
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);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001334 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001335 }
1336
dea31012005-04-17 16:05:31 -05001337 ndlp->nlp_rpi = mb->un.varWords[0];
dea31012005-04-17 16:05:31 -05001338
1339 /* Only if we are not a fabric nport do we issue PRLI */
1340 if (!(ndlp->nlp_type & NLP_FABRIC)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001341 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -05001342 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
1343 lpfc_issue_els_prli(vport, ndlp, 0);
dea31012005-04-17 16:05:31 -05001344 } else {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001345 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -05001346 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
dea31012005-04-17 16:05:31 -05001347 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001348 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001349}
1350
1351static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001352lpfc_device_rm_reglogin_issue(struct lpfc_vport *vport,
1353 struct lpfc_nodelist *ndlp,
1354 void *arg,
dea31012005-04-17 16:05:31 -05001355 uint32_t evt)
1356{
James Smart2e0fef82007-06-17 19:56:36 -05001357 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1358
1359 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1360 spin_lock_irq(shost->host_lock);
James Smarta0f9b482006-04-15 11:52:56 -04001361 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
James Smart2e0fef82007-06-17 19:56:36 -05001362 spin_unlock_irq(shost->host_lock);
James Smarta0f9b482006-04-15 11:52:56 -04001363 return ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05001364 } else {
1365 lpfc_drop_node(vport, ndlp);
James Smarta0f9b482006-04-15 11:52:56 -04001366 return NLP_STE_FREED_NODE;
1367 }
dea31012005-04-17 16:05:31 -05001368}
1369
1370static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001371lpfc_device_recov_reglogin_issue(struct lpfc_vport *vport,
1372 struct lpfc_nodelist *ndlp,
1373 void *arg,
1374 uint32_t evt)
dea31012005-04-17 16:05:31 -05001375{
James Smart2e0fef82007-06-17 19:56:36 -05001376 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1377
James Smart92d7f7b2007-06-17 19:56:38 -05001378 /* Don't do anything that will mess up processing of the
1379 * previous RSCN.
1380 */
1381 if (vport->fc_flag & FC_RSCN_DEFERRED)
1382 return ndlp->nlp_state;
1383
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001384 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -05001385 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1386 spin_lock_irq(shost->host_lock);
James Smarta0f9b482006-04-15 11:52:56 -04001387 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
James Smart2e0fef82007-06-17 19:56:36 -05001388 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05001389 lpfc_disc_set_adisc(vport, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001390 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001391}
1392
1393static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001394lpfc_rcv_plogi_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1395 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001396{
1397 struct lpfc_iocbq *cmdiocb;
1398
1399 cmdiocb = (struct lpfc_iocbq *) arg;
1400
James Smart2e0fef82007-06-17 19:56:36 -05001401 lpfc_rcv_plogi(vport, ndlp, cmdiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001402 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001403}
1404
1405static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001406lpfc_rcv_prli_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1407 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001408{
James Smart2e0fef82007-06-17 19:56:36 -05001409 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001410
James Smart2e0fef82007-06-17 19:56:36 -05001411 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001412 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001413}
1414
1415static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001416lpfc_rcv_logo_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1417 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001418{
James Smart2e0fef82007-06-17 19:56:36 -05001419 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001420
1421 /* Software abort outstanding PRLI before sending acc */
James Smart2e0fef82007-06-17 19:56:36 -05001422 lpfc_els_abort(vport->phba, ndlp);
dea31012005-04-17 16:05:31 -05001423
James Smart2e0fef82007-06-17 19:56:36 -05001424 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001425 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001426}
1427
1428static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001429lpfc_rcv_padisc_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1430 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001431{
James Smart2e0fef82007-06-17 19:56:36 -05001432 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001433
James Smart2e0fef82007-06-17 19:56:36 -05001434 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001435 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001436}
1437
1438/* This routine is envoked when we rcv a PRLO request from a nport
1439 * we are logged into. We should send back a PRLO rsp setting the
1440 * appropriate bits.
1441 * NEXT STATE = PRLI_ISSUE
1442 */
1443static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001444lpfc_rcv_prlo_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1445 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001446{
James Smart2e0fef82007-06-17 19:56:36 -05001447 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001448
James Smart51ef4c22007-08-02 11:10:31 -04001449 lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001450 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001451}
1452
1453static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001454lpfc_cmpl_prli_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1455 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001456{
James Smart92d7f7b2007-06-17 19:56:38 -05001457 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001458 struct lpfc_iocbq *cmdiocb, *rspiocb;
James Smart2e0fef82007-06-17 19:56:36 -05001459 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001460 IOCB_t *irsp;
1461 PRLI *npr;
1462
1463 cmdiocb = (struct lpfc_iocbq *) arg;
1464 rspiocb = cmdiocb->context_un.rsp_iocb;
1465 npr = (PRLI *)lpfc_check_elscmpl_iocb(phba, cmdiocb, rspiocb);
1466
1467 irsp = &rspiocb->iocb;
1468 if (irsp->ulpStatus) {
James Smart858c9f62007-06-17 19:56:39 -05001469 if ((vport->port_type == LPFC_NPIV_PORT) &&
James Smart3de2a652007-08-02 11:09:59 -04001470 vport->cfg_restrict_login) {
James Smart858c9f62007-06-17 19:56:39 -05001471 goto out;
1472 }
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001473 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -05001474 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001475 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001476 }
1477
1478 /* Check out PRLI rsp */
1479 ndlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR);
1480 ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
1481 if ((npr->acceptRspCode == PRLI_REQ_EXECUTED) &&
1482 (npr->prliType == PRLI_FCP_TYPE)) {
1483 if (npr->initiatorFunc)
1484 ndlp->nlp_type |= NLP_FCP_INITIATOR;
1485 if (npr->targetFunc)
1486 ndlp->nlp_type |= NLP_FCP_TARGET;
1487 if (npr->Retry)
1488 ndlp->nlp_fcp_info |= NLP_FCP_2_DEVICE;
1489 }
James Smart92d7f7b2007-06-17 19:56:38 -05001490 if (!(ndlp->nlp_type & NLP_FCP_TARGET) &&
1491 (vport->port_type == LPFC_NPIV_PORT) &&
James Smart3de2a652007-08-02 11:09:59 -04001492 vport->cfg_restrict_login) {
James Smart858c9f62007-06-17 19:56:39 -05001493out:
James Smart92d7f7b2007-06-17 19:56:38 -05001494 spin_lock_irq(shost->host_lock);
1495 ndlp->nlp_flag |= NLP_TARGET_REMOVE;
1496 spin_unlock_irq(shost->host_lock);
1497 lpfc_issue_els_logo(vport, ndlp, 0);
1498
1499 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
James Smart87af33f2007-10-27 13:37:43 -04001500 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
James Smart92d7f7b2007-06-17 19:56:38 -05001501 return ndlp->nlp_state;
1502 }
dea31012005-04-17 16:05:31 -05001503
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001504 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
James Smart92d7f7b2007-06-17 19:56:38 -05001505 if (ndlp->nlp_type & NLP_FCP_TARGET)
1506 lpfc_nlp_set_state(vport, ndlp, NLP_STE_MAPPED_NODE);
1507 else
1508 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001509 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001510}
1511
1512/*! lpfc_device_rm_prli_issue
James Smart92d7f7b2007-06-17 19:56:38 -05001513 *
1514 * \pre
1515 * \post
1516 * \param phba
1517 * \param ndlp
1518 * \param arg
1519 * \param evt
1520 * \return uint32_t
1521 *
1522 * \b Description:
1523 * This routine is envoked when we a request to remove a nport we are in the
1524 * process of PRLIing. We should software abort outstanding prli, unreg
1525 * login, send a logout. We will change node state to UNUSED_NODE, put it
1526 * on plogi list so it can be freed when LOGO completes.
1527 *
1528 */
1529
dea31012005-04-17 16:05:31 -05001530static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001531lpfc_device_rm_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1532 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001533{
James Smart2e0fef82007-06-17 19:56:36 -05001534 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001535
James Smart2e0fef82007-06-17 19:56:36 -05001536 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1537 spin_lock_irq(shost->host_lock);
1538 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
1539 spin_unlock_irq(shost->host_lock);
1540 return ndlp->nlp_state;
1541 } else {
1542 /* software abort outstanding PLOGI */
1543 lpfc_els_abort(vport->phba, ndlp);
1544
1545 lpfc_drop_node(vport, ndlp);
James Smarta0f9b482006-04-15 11:52:56 -04001546 return NLP_STE_FREED_NODE;
1547 }
dea31012005-04-17 16:05:31 -05001548}
1549
1550
1551/*! lpfc_device_recov_prli_issue
James Smart92d7f7b2007-06-17 19:56:38 -05001552 *
1553 * \pre
1554 * \post
1555 * \param phba
1556 * \param ndlp
1557 * \param arg
1558 * \param evt
1559 * \return uint32_t
1560 *
1561 * \b Description:
1562 * The routine is envoked when the state of a device is unknown, like
1563 * during a link down. We should remove the nodelist entry from the
1564 * unmapped list, issue a UNREG_LOGIN, do a software abort of the
1565 * outstanding PRLI command, then free the node entry.
1566 */
dea31012005-04-17 16:05:31 -05001567static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001568lpfc_device_recov_prli_issue(struct lpfc_vport *vport,
1569 struct lpfc_nodelist *ndlp,
1570 void *arg,
1571 uint32_t evt)
dea31012005-04-17 16:05:31 -05001572{
James Smart2e0fef82007-06-17 19:56:36 -05001573 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1574 struct lpfc_hba *phba = vport->phba;
1575
James Smart92d7f7b2007-06-17 19:56:38 -05001576 /* Don't do anything that will mess up processing of the
1577 * previous RSCN.
1578 */
1579 if (vport->fc_flag & FC_RSCN_DEFERRED)
1580 return ndlp->nlp_state;
1581
dea31012005-04-17 16:05:31 -05001582 /* software abort outstanding PRLI */
James Smart07951072007-04-25 09:51:38 -04001583 lpfc_els_abort(phba, ndlp);
dea31012005-04-17 16:05:31 -05001584
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001585 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -05001586 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1587 spin_lock_irq(shost->host_lock);
James Smarta0f9b482006-04-15 11:52:56 -04001588 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
James Smart2e0fef82007-06-17 19:56:36 -05001589 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05001590 lpfc_disc_set_adisc(vport, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001591 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001592}
1593
1594static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001595lpfc_rcv_plogi_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1596 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001597{
James Smart2e0fef82007-06-17 19:56:36 -05001598 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001599
James Smart2e0fef82007-06-17 19:56:36 -05001600 lpfc_rcv_plogi(vport, ndlp, cmdiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001601 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001602}
1603
1604static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001605lpfc_rcv_prli_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1606 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001607{
James Smart2e0fef82007-06-17 19:56:36 -05001608 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001609
James Smart2e0fef82007-06-17 19:56:36 -05001610 lpfc_rcv_prli(vport, ndlp, cmdiocb);
1611 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001612 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001613}
1614
1615static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001616lpfc_rcv_logo_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1617 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001618{
James Smart2e0fef82007-06-17 19:56:36 -05001619 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001620
James Smart2e0fef82007-06-17 19:56:36 -05001621 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001622 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001623}
1624
1625static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001626lpfc_rcv_padisc_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1627 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001628{
James Smart2e0fef82007-06-17 19:56:36 -05001629 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001630
James Smart2e0fef82007-06-17 19:56:36 -05001631 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001632 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001633}
1634
1635static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001636lpfc_rcv_prlo_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1637 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001638{
James Smart2e0fef82007-06-17 19:56:36 -05001639 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001640
James Smart51ef4c22007-08-02 11:10:31 -04001641 lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001642 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001643}
1644
1645static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001646lpfc_device_recov_unmap_node(struct lpfc_vport *vport,
1647 struct lpfc_nodelist *ndlp,
1648 void *arg,
1649 uint32_t evt)
dea31012005-04-17 16:05:31 -05001650{
James Smart2e0fef82007-06-17 19:56:36 -05001651 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1652
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001653 ndlp->nlp_prev_state = NLP_STE_UNMAPPED_NODE;
James Smart2e0fef82007-06-17 19:56:36 -05001654 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1655 spin_lock_irq(shost->host_lock);
James Smarta0f9b482006-04-15 11:52:56 -04001656 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
James Smart2e0fef82007-06-17 19:56:36 -05001657 spin_unlock_irq(shost->host_lock);
1658 lpfc_disc_set_adisc(vport, ndlp);
dea31012005-04-17 16:05:31 -05001659
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001660 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001661}
1662
1663static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001664lpfc_rcv_plogi_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1665 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001666{
James Smart2e0fef82007-06-17 19:56:36 -05001667 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001668
James Smart2e0fef82007-06-17 19:56:36 -05001669 lpfc_rcv_plogi(vport, ndlp, cmdiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001670 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001671}
1672
1673static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001674lpfc_rcv_prli_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1675 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001676{
James Smart2e0fef82007-06-17 19:56:36 -05001677 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001678
James Smart2e0fef82007-06-17 19:56:36 -05001679 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001680 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001681}
1682
1683static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001684lpfc_rcv_logo_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1685 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001686{
James Smart2e0fef82007-06-17 19:56:36 -05001687 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001688
James Smart2e0fef82007-06-17 19:56:36 -05001689 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001690 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001691}
1692
1693static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001694lpfc_rcv_padisc_mapped_node(struct lpfc_vport *vport,
1695 struct lpfc_nodelist *ndlp,
1696 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001697{
James Smart2e0fef82007-06-17 19:56:36 -05001698 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001699
James Smart2e0fef82007-06-17 19:56:36 -05001700 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001701 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001702}
1703
1704static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001705lpfc_rcv_prlo_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1706 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001707{
James Smart2e0fef82007-06-17 19:56:36 -05001708 struct lpfc_hba *phba = vport->phba;
1709 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001710
1711 /* flush the target */
James Smart51ef4c22007-08-02 11:10:31 -04001712 lpfc_sli_abort_iocb(vport, &phba->sli.ring[phba->sli.fcp_ring],
1713 ndlp->nlp_sid, 0, LPFC_CTX_TGT);
dea31012005-04-17 16:05:31 -05001714
1715 /* Treat like rcv logo */
James Smart2e0fef82007-06-17 19:56:36 -05001716 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_PRLO);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001717 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001718}
1719
1720static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001721lpfc_device_recov_mapped_node(struct lpfc_vport *vport,
1722 struct lpfc_nodelist *ndlp,
1723 void *arg,
1724 uint32_t evt)
dea31012005-04-17 16:05:31 -05001725{
James Smart2e0fef82007-06-17 19:56:36 -05001726 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1727
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001728 ndlp->nlp_prev_state = NLP_STE_MAPPED_NODE;
James Smart2e0fef82007-06-17 19:56:36 -05001729 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1730 spin_lock_irq(shost->host_lock);
James Smarta0f9b482006-04-15 11:52:56 -04001731 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
James Smart2e0fef82007-06-17 19:56:36 -05001732 spin_unlock_irq(shost->host_lock);
1733 lpfc_disc_set_adisc(vport, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001734 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001735}
1736
1737static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001738lpfc_rcv_plogi_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1739 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001740{
James Smart2e0fef82007-06-17 19:56:36 -05001741 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1742 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001743
1744 /* Ignore PLOGI if we have an outstanding LOGO */
James Smart858c9f62007-06-17 19:56:39 -05001745 if (ndlp->nlp_flag & (NLP_LOGO_SND | NLP_LOGO_ACC)) {
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001746 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001747 }
1748
James Smart2e0fef82007-06-17 19:56:36 -05001749 if (lpfc_rcv_plogi(vport, ndlp, cmdiocb)) {
1750 spin_lock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05001751 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
James Smart2e0fef82007-06-17 19:56:36 -05001752 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001753 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001754 }
1755
1756 /* send PLOGI immediately, move to PLOGI issue state */
1757 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
James Smart488d1462006-03-07 15:02:37 -05001758 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
James Smart2e0fef82007-06-17 19:56:36 -05001759 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
1760 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
dea31012005-04-17 16:05:31 -05001761 }
James Smart488d1462006-03-07 15:02:37 -05001762
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001763 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001764}
1765
1766static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001767lpfc_rcv_prli_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1768 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001769{
James Smart2e0fef82007-06-17 19:56:36 -05001770 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1771 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1772 struct ls_rjt stat;
dea31012005-04-17 16:05:31 -05001773
1774 memset(&stat, 0, sizeof (struct ls_rjt));
1775 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
1776 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
James Smart858c9f62007-06-17 19:56:39 -05001777 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05001778
1779 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
1780 if (ndlp->nlp_flag & NLP_NPR_ADISC) {
James Smart2e0fef82007-06-17 19:56:36 -05001781 spin_lock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001782 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001783 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
James Smart2e0fef82007-06-17 19:56:36 -05001784 spin_unlock_irq(shost->host_lock);
1785 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
1786 lpfc_issue_els_adisc(vport, ndlp, 0);
dea31012005-04-17 16:05:31 -05001787 } else {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001788 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
James Smart2e0fef82007-06-17 19:56:36 -05001789 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
1790 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
dea31012005-04-17 16:05:31 -05001791 }
1792 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001793 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001794}
1795
1796static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001797lpfc_rcv_logo_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1798 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001799{
James Smart2e0fef82007-06-17 19:56:36 -05001800 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001801
James Smart2e0fef82007-06-17 19:56:36 -05001802 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001803 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001804}
1805
1806static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001807lpfc_rcv_padisc_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1808 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001809{
James Smart2e0fef82007-06-17 19:56:36 -05001810 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001811
James Smart2e0fef82007-06-17 19:56:36 -05001812 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
dea31012005-04-17 16:05:31 -05001813
James Smart33ccf8d2006-08-17 11:57:58 -04001814 /*
1815 * Do not start discovery if discovery is about to start
1816 * or discovery in progress for this node. Starting discovery
1817 * here will affect the counting of discovery threads.
1818 */
James Smart2fb9bd82006-12-02 13:33:57 -05001819 if (!(ndlp->nlp_flag & NLP_DELAY_TMO) &&
James Smart92d7f7b2007-06-17 19:56:38 -05001820 !(ndlp->nlp_flag & NLP_NPR_2B_DISC)) {
dea31012005-04-17 16:05:31 -05001821 if (ndlp->nlp_flag & NLP_NPR_ADISC) {
James Smart92d7f7b2007-06-17 19:56:38 -05001822 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001823 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
James Smart2e0fef82007-06-17 19:56:36 -05001824 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
1825 lpfc_issue_els_adisc(vport, ndlp, 0);
dea31012005-04-17 16:05:31 -05001826 } else {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001827 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
James Smart2e0fef82007-06-17 19:56:36 -05001828 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
1829 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
dea31012005-04-17 16:05:31 -05001830 }
1831 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001832 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001833}
1834
1835static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001836lpfc_rcv_prlo_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1837 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001838{
James Smart2e0fef82007-06-17 19:56:36 -05001839 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1840 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001841
James Smart2e0fef82007-06-17 19:56:36 -05001842 spin_lock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001843 ndlp->nlp_flag |= NLP_LOGO_ACC;
James Smart2e0fef82007-06-17 19:56:36 -05001844 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001845
James Smart51ef4c22007-08-02 11:10:31 -04001846 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05001847
James Smart2e0fef82007-06-17 19:56:36 -05001848 if ((ndlp->nlp_flag & NLP_DELAY_TMO) == 0) {
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001849 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ * 1);
James Smart2e0fef82007-06-17 19:56:36 -05001850 spin_lock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001851 ndlp->nlp_flag |= NLP_DELAY_TMO;
1852 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
James Smart2e0fef82007-06-17 19:56:36 -05001853 spin_unlock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001854 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001855 } else {
James Smart2e0fef82007-06-17 19:56:36 -05001856 spin_lock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001857 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
James Smart2e0fef82007-06-17 19:56:36 -05001858 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001859 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001860 return ndlp->nlp_state;
1861}
dea31012005-04-17 16:05:31 -05001862
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001863static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001864lpfc_cmpl_plogi_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1865 void *arg, uint32_t evt)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001866{
1867 struct lpfc_iocbq *cmdiocb, *rspiocb;
James Smarta0f9b482006-04-15 11:52:56 -04001868 IOCB_t *irsp;
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001869
1870 cmdiocb = (struct lpfc_iocbq *) arg;
1871 rspiocb = cmdiocb->context_un.rsp_iocb;
James Smarta0f9b482006-04-15 11:52:56 -04001872
1873 irsp = &rspiocb->iocb;
1874 if (irsp->ulpStatus) {
James Smarta8adb832007-10-27 13:37:53 -04001875 ndlp->nlp_flag |= NLP_DEFER_RM;
James Smarta0f9b482006-04-15 11:52:56 -04001876 return NLP_STE_FREED_NODE;
1877 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001878 return ndlp->nlp_state;
1879}
1880
1881static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001882lpfc_cmpl_prli_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1883 void *arg, uint32_t evt)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001884{
1885 struct lpfc_iocbq *cmdiocb, *rspiocb;
James Smarta0f9b482006-04-15 11:52:56 -04001886 IOCB_t *irsp;
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001887
1888 cmdiocb = (struct lpfc_iocbq *) arg;
1889 rspiocb = cmdiocb->context_un.rsp_iocb;
James Smarta0f9b482006-04-15 11:52:56 -04001890
1891 irsp = &rspiocb->iocb;
1892 if (irsp->ulpStatus && (ndlp->nlp_flag & NLP_NODEV_REMOVE)) {
James Smart2e0fef82007-06-17 19:56:36 -05001893 lpfc_drop_node(vport, ndlp);
James Smarta0f9b482006-04-15 11:52:56 -04001894 return NLP_STE_FREED_NODE;
1895 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001896 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001897}
1898
1899static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001900lpfc_cmpl_logo_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1901 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001902{
James Smart2e0fef82007-06-17 19:56:36 -05001903 lpfc_unreg_rpi(vport, ndlp);
dea31012005-04-17 16:05:31 -05001904 /* This routine does nothing, just return the current state */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001905 return ndlp->nlp_state;
1906}
1907
1908static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001909lpfc_cmpl_adisc_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1910 void *arg, uint32_t evt)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001911{
1912 struct lpfc_iocbq *cmdiocb, *rspiocb;
James Smarta0f9b482006-04-15 11:52:56 -04001913 IOCB_t *irsp;
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001914
1915 cmdiocb = (struct lpfc_iocbq *) arg;
1916 rspiocb = cmdiocb->context_un.rsp_iocb;
James Smarta0f9b482006-04-15 11:52:56 -04001917
1918 irsp = &rspiocb->iocb;
1919 if (irsp->ulpStatus && (ndlp->nlp_flag & NLP_NODEV_REMOVE)) {
James Smart2e0fef82007-06-17 19:56:36 -05001920 lpfc_drop_node(vport, ndlp);
James Smarta0f9b482006-04-15 11:52:56 -04001921 return NLP_STE_FREED_NODE;
1922 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001923 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001924}
1925
1926static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001927lpfc_cmpl_reglogin_npr_node(struct lpfc_vport *vport,
1928 struct lpfc_nodelist *ndlp,
1929 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001930{
James Smart2e0fef82007-06-17 19:56:36 -05001931 LPFC_MBOXQ_t *pmb = (LPFC_MBOXQ_t *) arg;
1932 MAILBOX_t *mb = &pmb->mb;
dea31012005-04-17 16:05:31 -05001933
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001934 if (!mb->mbxStatus)
1935 ndlp->nlp_rpi = mb->un.varWords[0];
James Smarta0f9b482006-04-15 11:52:56 -04001936 else {
1937 if (ndlp->nlp_flag & NLP_NODEV_REMOVE) {
James Smart2e0fef82007-06-17 19:56:36 -05001938 lpfc_drop_node(vport, ndlp);
James Smarta0f9b482006-04-15 11:52:56 -04001939 return NLP_STE_FREED_NODE;
1940 }
1941 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001942 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001943}
1944
1945static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001946lpfc_device_rm_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1947 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001948{
James Smart2e0fef82007-06-17 19:56:36 -05001949 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1950
James Smarta0f9b482006-04-15 11:52:56 -04001951 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
James Smart2e0fef82007-06-17 19:56:36 -05001952 spin_lock_irq(shost->host_lock);
James Smarta0f9b482006-04-15 11:52:56 -04001953 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
James Smart2e0fef82007-06-17 19:56:36 -05001954 spin_unlock_irq(shost->host_lock);
James Smarta0f9b482006-04-15 11:52:56 -04001955 return ndlp->nlp_state;
1956 }
James Smart2e0fef82007-06-17 19:56:36 -05001957 lpfc_drop_node(vport, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001958 return NLP_STE_FREED_NODE;
dea31012005-04-17 16:05:31 -05001959}
1960
1961static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001962lpfc_device_recov_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1963 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001964{
James Smart2e0fef82007-06-17 19:56:36 -05001965 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1966
James Smart92d7f7b2007-06-17 19:56:38 -05001967 /* Don't do anything that will mess up processing of the
1968 * previous RSCN.
1969 */
1970 if (vport->fc_flag & FC_RSCN_DEFERRED)
1971 return ndlp->nlp_state;
1972
James Smart2e0fef82007-06-17 19:56:36 -05001973 spin_lock_irq(shost->host_lock);
James Smarta0f9b482006-04-15 11:52:56 -04001974 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
James Smart2e0fef82007-06-17 19:56:36 -05001975 spin_unlock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05001976 if (ndlp->nlp_flag & NLP_DELAY_TMO) {
James Smart2e0fef82007-06-17 19:56:36 -05001977 lpfc_cancel_retry_delay_tmo(vport, ndlp);
James Smartfdcebe22006-03-07 15:04:01 -05001978 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001979 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001980}
1981
1982
1983/* This next section defines the NPort Discovery State Machine */
1984
1985/* There are 4 different double linked lists nodelist entries can reside on.
1986 * The plogi list and adisc list are used when Link Up discovery or RSCN
1987 * processing is needed. Each list holds the nodes that we will send PLOGI
1988 * or ADISC on. These lists will keep track of what nodes will be effected
1989 * by an RSCN, or a Link Up (Typically, all nodes are effected on Link Up).
1990 * The unmapped_list will contain all nodes that we have successfully logged
1991 * into at the Fibre Channel level. The mapped_list will contain all nodes
1992 * that are mapped FCP targets.
1993 */
1994/*
1995 * The bind list is a list of undiscovered (potentially non-existent) nodes
1996 * that we have saved binding information on. This information is used when
1997 * nodes transition from the unmapped to the mapped list.
1998 */
1999/* For UNUSED_NODE state, the node has just been allocated .
2000 * For PLOGI_ISSUE and REG_LOGIN_ISSUE, the node is on
2001 * the PLOGI list. For REG_LOGIN_COMPL, the node is taken off the PLOGI list
2002 * and put on the unmapped list. For ADISC processing, the node is taken off
2003 * the ADISC list and placed on either the mapped or unmapped list (depending
2004 * on its previous state). Once on the unmapped list, a PRLI is issued and the
2005 * state changed to PRLI_ISSUE. When the PRLI completion occurs, the state is
2006 * changed to UNMAPPED_NODE. If the completion indicates a mapped
2007 * node, the node is taken off the unmapped list. The binding list is checked
2008 * for a valid binding, or a binding is automatically assigned. If binding
2009 * assignment is unsuccessful, the node is left on the unmapped list. If
2010 * binding assignment is successful, the associated binding list entry (if
2011 * any) is removed, and the node is placed on the mapped list.
2012 */
2013/*
2014 * For a Link Down, all nodes on the ADISC, PLOGI, unmapped or mapped
James Smartc01f3202006-08-18 17:47:08 -04002015 * lists will receive a DEVICE_RECOVERY event. If the linkdown or devloss timers
dea31012005-04-17 16:05:31 -05002016 * expire, all effected nodes will receive a DEVICE_RM event.
2017 */
2018/*
2019 * For a Link Up or RSCN, all nodes will move from the mapped / unmapped lists
2020 * to either the ADISC or PLOGI list. After a Nameserver query or ALPA loopmap
2021 * check, additional nodes may be added or removed (via DEVICE_RM) to / from
2022 * the PLOGI or ADISC lists. Once the PLOGI and ADISC lists are populated,
2023 * we will first process the ADISC list. 32 entries are processed initially and
2024 * ADISC is initited for each one. Completions / Events for each node are
2025 * funnelled thru the state machine. As each node finishes ADISC processing, it
2026 * starts ADISC for any nodes waiting for ADISC processing. If no nodes are
2027 * waiting, and the ADISC list count is identically 0, then we are done. For
2028 * Link Up discovery, since all nodes on the PLOGI list are UNREG_LOGIN'ed, we
2029 * can issue a CLEAR_LA and reenable Link Events. Next we will process the PLOGI
2030 * list. 32 entries are processed initially and PLOGI is initited for each one.
2031 * Completions / Events for each node are funnelled thru the state machine. As
2032 * each node finishes PLOGI processing, it starts PLOGI for any nodes waiting
2033 * for PLOGI processing. If no nodes are waiting, and the PLOGI list count is
2034 * indentically 0, then we are done. We have now completed discovery / RSCN
2035 * handling. Upon completion, ALL nodes should be on either the mapped or
2036 * unmapped lists.
2037 */
2038
2039static uint32_t (*lpfc_disc_action[NLP_STE_MAX_STATE * NLP_EVT_MAX_EVENT])
James Smart2e0fef82007-06-17 19:56:36 -05002040 (struct lpfc_vport *, struct lpfc_nodelist *, void *, uint32_t) = {
dea31012005-04-17 16:05:31 -05002041 /* Action routine Event Current State */
2042 lpfc_rcv_plogi_unused_node, /* RCV_PLOGI UNUSED_NODE */
2043 lpfc_rcv_els_unused_node, /* RCV_PRLI */
2044 lpfc_rcv_logo_unused_node, /* RCV_LOGO */
2045 lpfc_rcv_els_unused_node, /* RCV_ADISC */
2046 lpfc_rcv_els_unused_node, /* RCV_PDISC */
2047 lpfc_rcv_els_unused_node, /* RCV_PRLO */
2048 lpfc_disc_illegal, /* CMPL_PLOGI */
2049 lpfc_disc_illegal, /* CMPL_PRLI */
2050 lpfc_cmpl_logo_unused_node, /* CMPL_LOGO */
2051 lpfc_disc_illegal, /* CMPL_ADISC */
2052 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2053 lpfc_device_rm_unused_node, /* DEVICE_RM */
2054 lpfc_disc_illegal, /* DEVICE_RECOVERY */
2055
2056 lpfc_rcv_plogi_plogi_issue, /* RCV_PLOGI PLOGI_ISSUE */
James Smart92d7f7b2007-06-17 19:56:38 -05002057 lpfc_rcv_prli_plogi_issue, /* RCV_PRLI */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002058 lpfc_rcv_logo_plogi_issue, /* RCV_LOGO */
dea31012005-04-17 16:05:31 -05002059 lpfc_rcv_els_plogi_issue, /* RCV_ADISC */
2060 lpfc_rcv_els_plogi_issue, /* RCV_PDISC */
2061 lpfc_rcv_els_plogi_issue, /* RCV_PRLO */
2062 lpfc_cmpl_plogi_plogi_issue, /* CMPL_PLOGI */
2063 lpfc_disc_illegal, /* CMPL_PRLI */
James Smart0ff10d42008-01-11 01:52:36 -05002064 lpfc_cmpl_logo_plogi_issue, /* CMPL_LOGO */
dea31012005-04-17 16:05:31 -05002065 lpfc_disc_illegal, /* CMPL_ADISC */
James Smart0ff10d42008-01-11 01:52:36 -05002066 lpfc_cmpl_reglogin_plogi_issue,/* CMPL_REG_LOGIN */
dea31012005-04-17 16:05:31 -05002067 lpfc_device_rm_plogi_issue, /* DEVICE_RM */
2068 lpfc_device_recov_plogi_issue, /* DEVICE_RECOVERY */
2069
2070 lpfc_rcv_plogi_adisc_issue, /* RCV_PLOGI ADISC_ISSUE */
2071 lpfc_rcv_prli_adisc_issue, /* RCV_PRLI */
2072 lpfc_rcv_logo_adisc_issue, /* RCV_LOGO */
2073 lpfc_rcv_padisc_adisc_issue, /* RCV_ADISC */
2074 lpfc_rcv_padisc_adisc_issue, /* RCV_PDISC */
2075 lpfc_rcv_prlo_adisc_issue, /* RCV_PRLO */
2076 lpfc_disc_illegal, /* CMPL_PLOGI */
2077 lpfc_disc_illegal, /* CMPL_PRLI */
2078 lpfc_disc_illegal, /* CMPL_LOGO */
2079 lpfc_cmpl_adisc_adisc_issue, /* CMPL_ADISC */
2080 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2081 lpfc_device_rm_adisc_issue, /* DEVICE_RM */
2082 lpfc_device_recov_adisc_issue, /* DEVICE_RECOVERY */
2083
2084 lpfc_rcv_plogi_reglogin_issue, /* RCV_PLOGI REG_LOGIN_ISSUE */
2085 lpfc_rcv_prli_reglogin_issue, /* RCV_PLOGI */
2086 lpfc_rcv_logo_reglogin_issue, /* RCV_LOGO */
2087 lpfc_rcv_padisc_reglogin_issue, /* RCV_ADISC */
2088 lpfc_rcv_padisc_reglogin_issue, /* RCV_PDISC */
2089 lpfc_rcv_prlo_reglogin_issue, /* RCV_PRLO */
James Smart87af33f2007-10-27 13:37:43 -04002090 lpfc_cmpl_plogi_illegal, /* CMPL_PLOGI */
dea31012005-04-17 16:05:31 -05002091 lpfc_disc_illegal, /* CMPL_PRLI */
2092 lpfc_disc_illegal, /* CMPL_LOGO */
2093 lpfc_disc_illegal, /* CMPL_ADISC */
2094 lpfc_cmpl_reglogin_reglogin_issue,/* CMPL_REG_LOGIN */
2095 lpfc_device_rm_reglogin_issue, /* DEVICE_RM */
2096 lpfc_device_recov_reglogin_issue,/* DEVICE_RECOVERY */
2097
2098 lpfc_rcv_plogi_prli_issue, /* RCV_PLOGI PRLI_ISSUE */
2099 lpfc_rcv_prli_prli_issue, /* RCV_PRLI */
2100 lpfc_rcv_logo_prli_issue, /* RCV_LOGO */
2101 lpfc_rcv_padisc_prli_issue, /* RCV_ADISC */
2102 lpfc_rcv_padisc_prli_issue, /* RCV_PDISC */
2103 lpfc_rcv_prlo_prli_issue, /* RCV_PRLO */
James Smart87af33f2007-10-27 13:37:43 -04002104 lpfc_cmpl_plogi_illegal, /* CMPL_PLOGI */
dea31012005-04-17 16:05:31 -05002105 lpfc_cmpl_prli_prli_issue, /* CMPL_PRLI */
2106 lpfc_disc_illegal, /* CMPL_LOGO */
2107 lpfc_disc_illegal, /* CMPL_ADISC */
2108 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2109 lpfc_device_rm_prli_issue, /* DEVICE_RM */
2110 lpfc_device_recov_prli_issue, /* DEVICE_RECOVERY */
2111
2112 lpfc_rcv_plogi_unmap_node, /* RCV_PLOGI UNMAPPED_NODE */
2113 lpfc_rcv_prli_unmap_node, /* RCV_PRLI */
2114 lpfc_rcv_logo_unmap_node, /* RCV_LOGO */
2115 lpfc_rcv_padisc_unmap_node, /* RCV_ADISC */
2116 lpfc_rcv_padisc_unmap_node, /* RCV_PDISC */
2117 lpfc_rcv_prlo_unmap_node, /* RCV_PRLO */
2118 lpfc_disc_illegal, /* CMPL_PLOGI */
2119 lpfc_disc_illegal, /* CMPL_PRLI */
2120 lpfc_disc_illegal, /* CMPL_LOGO */
2121 lpfc_disc_illegal, /* CMPL_ADISC */
2122 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2123 lpfc_disc_illegal, /* DEVICE_RM */
2124 lpfc_device_recov_unmap_node, /* DEVICE_RECOVERY */
2125
2126 lpfc_rcv_plogi_mapped_node, /* RCV_PLOGI MAPPED_NODE */
2127 lpfc_rcv_prli_mapped_node, /* RCV_PRLI */
2128 lpfc_rcv_logo_mapped_node, /* RCV_LOGO */
2129 lpfc_rcv_padisc_mapped_node, /* RCV_ADISC */
2130 lpfc_rcv_padisc_mapped_node, /* RCV_PDISC */
2131 lpfc_rcv_prlo_mapped_node, /* RCV_PRLO */
2132 lpfc_disc_illegal, /* CMPL_PLOGI */
2133 lpfc_disc_illegal, /* CMPL_PRLI */
2134 lpfc_disc_illegal, /* CMPL_LOGO */
2135 lpfc_disc_illegal, /* CMPL_ADISC */
2136 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2137 lpfc_disc_illegal, /* DEVICE_RM */
2138 lpfc_device_recov_mapped_node, /* DEVICE_RECOVERY */
2139
2140 lpfc_rcv_plogi_npr_node, /* RCV_PLOGI NPR_NODE */
2141 lpfc_rcv_prli_npr_node, /* RCV_PRLI */
2142 lpfc_rcv_logo_npr_node, /* RCV_LOGO */
2143 lpfc_rcv_padisc_npr_node, /* RCV_ADISC */
2144 lpfc_rcv_padisc_npr_node, /* RCV_PDISC */
2145 lpfc_rcv_prlo_npr_node, /* RCV_PRLO */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002146 lpfc_cmpl_plogi_npr_node, /* CMPL_PLOGI */
2147 lpfc_cmpl_prli_npr_node, /* CMPL_PRLI */
dea31012005-04-17 16:05:31 -05002148 lpfc_cmpl_logo_npr_node, /* CMPL_LOGO */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002149 lpfc_cmpl_adisc_npr_node, /* CMPL_ADISC */
dea31012005-04-17 16:05:31 -05002150 lpfc_cmpl_reglogin_npr_node, /* CMPL_REG_LOGIN */
2151 lpfc_device_rm_npr_node, /* DEVICE_RM */
2152 lpfc_device_recov_npr_node, /* DEVICE_RECOVERY */
2153};
2154
2155int
James Smart2e0fef82007-06-17 19:56:36 -05002156lpfc_disc_state_machine(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2157 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05002158{
2159 uint32_t cur_state, rc;
James Smart2e0fef82007-06-17 19:56:36 -05002160 uint32_t(*func) (struct lpfc_vport *, struct lpfc_nodelist *, void *,
dea31012005-04-17 16:05:31 -05002161 uint32_t);
James Smarte47c9092008-02-08 18:49:26 -05002162 uint32_t got_ndlp = 0;
dea31012005-04-17 16:05:31 -05002163
James Smarte47c9092008-02-08 18:49:26 -05002164 if (lpfc_nlp_get(ndlp))
2165 got_ndlp = 1;
2166
dea31012005-04-17 16:05:31 -05002167 cur_state = ndlp->nlp_state;
2168
2169 /* DSM in event <evt> on NPort <nlp_DID> in state <cur_state> */
James Smarte8b62012007-08-02 11:10:09 -04002170 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2171 "0211 DSM in event x%x on NPort x%x in "
2172 "state %d Data: x%x\n",
2173 evt, ndlp->nlp_DID, cur_state, ndlp->nlp_flag);
dea31012005-04-17 16:05:31 -05002174
James Smart858c9f62007-06-17 19:56:39 -05002175 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_DSM,
2176 "DSM in: evt:%d ste:%d did:x%x",
2177 evt, cur_state, ndlp->nlp_DID);
2178
dea31012005-04-17 16:05:31 -05002179 func = lpfc_disc_action[(cur_state * NLP_EVT_MAX_EVENT) + evt];
James Smart2e0fef82007-06-17 19:56:36 -05002180 rc = (func) (vport, ndlp, arg, evt);
dea31012005-04-17 16:05:31 -05002181
2182 /* DSM out state <rc> on NPort <nlp_DID> */
James Smarte47c9092008-02-08 18:49:26 -05002183 if (got_ndlp) {
2184 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
James Smarte8b62012007-08-02 11:10:09 -04002185 "0212 DSM out state %d on NPort x%x Data: x%x\n",
2186 rc, ndlp->nlp_DID, ndlp->nlp_flag);
dea31012005-04-17 16:05:31 -05002187
James Smarte47c9092008-02-08 18:49:26 -05002188 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_DSM,
2189 "DSM out: ste:%d did:x%x flg:x%x",
2190 rc, ndlp->nlp_DID, ndlp->nlp_flag);
2191 /* Decrement the ndlp reference count held for this function */
2192 lpfc_nlp_put(ndlp);
2193 } else {
2194 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2195 "0212 DSM out state %d on NPort free\n", rc);
James Smart858c9f62007-06-17 19:56:39 -05002196
James Smarte47c9092008-02-08 18:49:26 -05002197 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_DSM,
2198 "DSM out: ste:%d did:x%x flg:x%x",
2199 rc, 0, 0);
2200 }
dea31012005-04-17 16:05:31 -05002201
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002202 return rc;
dea31012005-04-17 16:05:31 -05002203}