blob: d20ae6b3b3cf77552ad7061d8e311b34dd3f85b9 [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 Smartd8e93df2009-05-22 14:53:05 -04004 * Copyright (C) 2004-2009 Emulex. All rights reserved. *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04005 * EMULEX and SLI are trademarks of Emulex. *
dea31012005-04-17 16:05:31 -05006 * www.emulex.com *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04007 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
dea31012005-04-17 16:05:31 -05008 * *
9 * This program is free software; you can redistribute it and/or *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -040010 * modify it under the terms of version 2 of the GNU General *
11 * Public License as published by the Free Software Foundation. *
12 * This program is distributed in the hope that it will be useful. *
13 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
14 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
15 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
16 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
17 * TO BE LEGALLY INVALID. See the GNU General Public License for *
18 * more details, a copy of which can be found in the file COPYING *
19 * included with this package. *
dea31012005-04-17 16:05:31 -050020 *******************************************************************/
21
dea31012005-04-17 16:05:31 -050022#include <linux/blkdev.h>
23#include <linux/pci.h>
24#include <linux/interrupt.h>
25
James.Smart@Emulex.Com91886522005-08-10 15:03:09 -040026#include <scsi/scsi.h>
dea31012005-04-17 16:05:31 -050027#include <scsi/scsi_device.h>
28#include <scsi/scsi_host.h>
29#include <scsi/scsi_transport_fc.h>
30
James Smartda0436e2009-05-22 14:51:39 -040031#include "lpfc_hw4.h"
dea31012005-04-17 16:05:31 -050032#include "lpfc_hw.h"
33#include "lpfc_sli.h"
James Smartda0436e2009-05-22 14:51:39 -040034#include "lpfc_sli4.h"
James Smartea2151b2008-09-07 11:52:10 -040035#include "lpfc_nl.h"
dea31012005-04-17 16:05:31 -050036#include "lpfc_disc.h"
37#include "lpfc_scsi.h"
38#include "lpfc.h"
39#include "lpfc_logmsg.h"
40#include "lpfc_crtn.h"
James Smart92d7f7b2007-06-17 19:56:38 -050041#include "lpfc_vport.h"
James Smart858c9f62007-06-17 19:56:39 -050042#include "lpfc_debugfs.h"
dea31012005-04-17 16:05:31 -050043
44
45/* Called to verify a rcv'ed ADISC was intended for us. */
46static int
James Smart2e0fef82007-06-17 19:56:36 -050047lpfc_check_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
48 struct lpfc_name *nn, struct lpfc_name *pn)
dea31012005-04-17 16:05:31 -050049{
50 /* Compare the ADISC rsp WWNN / WWPN matches our internal node
51 * table entry for that node.
52 */
James Smart2e0fef82007-06-17 19:56:36 -050053 if (memcmp(nn, &ndlp->nlp_nodename, sizeof (struct lpfc_name)))
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -050054 return 0;
dea31012005-04-17 16:05:31 -050055
James Smart2e0fef82007-06-17 19:56:36 -050056 if (memcmp(pn, &ndlp->nlp_portname, sizeof (struct lpfc_name)))
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -050057 return 0;
dea31012005-04-17 16:05:31 -050058
59 /* we match, return success */
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -050060 return 1;
dea31012005-04-17 16:05:31 -050061}
62
dea31012005-04-17 16:05:31 -050063int
James Smart2e0fef82007-06-17 19:56:36 -050064lpfc_check_sparm(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
James Smart341af102010-01-26 23:07:37 -050065 struct serv_parm *sp, uint32_t class, int flogi)
dea31012005-04-17 16:05:31 -050066{
James Smart2e0fef82007-06-17 19:56:36 -050067 volatile struct serv_parm *hsp = &vport->fc_sparam;
James.Smart@Emulex.Com2fb70f72005-11-28 11:41:24 -050068 uint16_t hsp_value, ssp_value = 0;
dea31012005-04-17 16:05:31 -050069
James.Smart@Emulex.Com2fb70f72005-11-28 11:41:24 -050070 /*
71 * The receive data field size and buffer-to-buffer receive data field
72 * size entries are 16 bits but are represented as two 8-bit fields in
73 * the driver data structure to account for rsvd bits and other control
74 * bits. Reconstruct and compare the fields as a 16-bit values before
75 * correcting the byte values.
76 */
dea31012005-04-17 16:05:31 -050077 if (sp->cls1.classValid) {
James Smart341af102010-01-26 23:07:37 -050078 if (!flogi) {
79 hsp_value = ((hsp->cls1.rcvDataSizeMsb << 8) |
80 hsp->cls1.rcvDataSizeLsb);
81 ssp_value = ((sp->cls1.rcvDataSizeMsb << 8) |
82 sp->cls1.rcvDataSizeLsb);
83 if (!ssp_value)
84 goto bad_service_param;
85 if (ssp_value > hsp_value) {
86 sp->cls1.rcvDataSizeLsb =
87 hsp->cls1.rcvDataSizeLsb;
88 sp->cls1.rcvDataSizeMsb =
89 hsp->cls1.rcvDataSizeMsb;
90 }
James.Smart@Emulex.Com2fb70f72005-11-28 11:41:24 -050091 }
James Smart341af102010-01-26 23:07:37 -050092 } else if (class == CLASS1)
James Smart92d7f7b2007-06-17 19:56:38 -050093 goto bad_service_param;
dea31012005-04-17 16:05:31 -050094 if (sp->cls2.classValid) {
James Smart341af102010-01-26 23:07:37 -050095 if (!flogi) {
96 hsp_value = ((hsp->cls2.rcvDataSizeMsb << 8) |
97 hsp->cls2.rcvDataSizeLsb);
98 ssp_value = ((sp->cls2.rcvDataSizeMsb << 8) |
99 sp->cls2.rcvDataSizeLsb);
100 if (!ssp_value)
101 goto bad_service_param;
102 if (ssp_value > hsp_value) {
103 sp->cls2.rcvDataSizeLsb =
104 hsp->cls2.rcvDataSizeLsb;
105 sp->cls2.rcvDataSizeMsb =
106 hsp->cls2.rcvDataSizeMsb;
107 }
James.Smart@Emulex.Com2fb70f72005-11-28 11:41:24 -0500108 }
James Smart341af102010-01-26 23:07:37 -0500109 } else if (class == CLASS2)
James Smart92d7f7b2007-06-17 19:56:38 -0500110 goto bad_service_param;
dea31012005-04-17 16:05:31 -0500111 if (sp->cls3.classValid) {
James Smart341af102010-01-26 23:07:37 -0500112 if (!flogi) {
113 hsp_value = ((hsp->cls3.rcvDataSizeMsb << 8) |
114 hsp->cls3.rcvDataSizeLsb);
115 ssp_value = ((sp->cls3.rcvDataSizeMsb << 8) |
116 sp->cls3.rcvDataSizeLsb);
117 if (!ssp_value)
118 goto bad_service_param;
119 if (ssp_value > hsp_value) {
120 sp->cls3.rcvDataSizeLsb =
121 hsp->cls3.rcvDataSizeLsb;
122 sp->cls3.rcvDataSizeMsb =
123 hsp->cls3.rcvDataSizeMsb;
124 }
James.Smart@Emulex.Com2fb70f72005-11-28 11:41:24 -0500125 }
James Smart341af102010-01-26 23:07:37 -0500126 } else if (class == CLASS3)
James Smart92d7f7b2007-06-17 19:56:38 -0500127 goto bad_service_param;
dea31012005-04-17 16:05:31 -0500128
James.Smart@Emulex.Com2fb70f72005-11-28 11:41:24 -0500129 /*
130 * Preserve the upper four bits of the MSB from the PLOGI response.
131 * These bits contain the Buffer-to-Buffer State Change Number
132 * from the target and need to be passed to the FW.
133 */
134 hsp_value = (hsp->cmn.bbRcvSizeMsb << 8) | hsp->cmn.bbRcvSizeLsb;
135 ssp_value = (sp->cmn.bbRcvSizeMsb << 8) | sp->cmn.bbRcvSizeLsb;
136 if (ssp_value > hsp_value) {
dea31012005-04-17 16:05:31 -0500137 sp->cmn.bbRcvSizeLsb = hsp->cmn.bbRcvSizeLsb;
James.Smart@Emulex.Com2fb70f72005-11-28 11:41:24 -0500138 sp->cmn.bbRcvSizeMsb = (sp->cmn.bbRcvSizeMsb & 0xF0) |
139 (hsp->cmn.bbRcvSizeMsb & 0x0F);
140 }
dea31012005-04-17 16:05:31 -0500141
dea31012005-04-17 16:05:31 -0500142 memcpy(&ndlp->nlp_nodename, &sp->nodeName, sizeof (struct lpfc_name));
143 memcpy(&ndlp->nlp_portname, &sp->portName, sizeof (struct lpfc_name));
James.Smart@Emulex.Com2fb70f72005-11-28 11:41:24 -0500144 return 1;
James Smart92d7f7b2007-06-17 19:56:38 -0500145bad_service_param:
James Smarte8b62012007-08-02 11:10:09 -0400146 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
147 "0207 Device %x "
148 "(%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x) sent "
149 "invalid service parameters. Ignoring device.\n",
150 ndlp->nlp_DID,
151 sp->nodeName.u.wwn[0], sp->nodeName.u.wwn[1],
152 sp->nodeName.u.wwn[2], sp->nodeName.u.wwn[3],
153 sp->nodeName.u.wwn[4], sp->nodeName.u.wwn[5],
154 sp->nodeName.u.wwn[6], sp->nodeName.u.wwn[7]);
James Smart92d7f7b2007-06-17 19:56:38 -0500155 return 0;
dea31012005-04-17 16:05:31 -0500156}
157
158static void *
James Smart2e0fef82007-06-17 19:56:36 -0500159lpfc_check_elscmpl_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -0500160 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -0500161{
162 struct lpfc_dmabuf *pcmd, *prsp;
163 uint32_t *lp;
164 void *ptr = NULL;
165 IOCB_t *irsp;
166
167 irsp = &rspiocb->iocb;
168 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
169
170 /* For lpfc_els_abort, context2 could be zero'ed to delay
171 * freeing associated memory till after ABTS completes.
172 */
173 if (pcmd) {
174 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf,
175 list);
176 if (prsp) {
177 lp = (uint32_t *) prsp->virt;
178 ptr = (void *)((uint8_t *)lp + sizeof(uint32_t));
179 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500180 } else {
dea31012005-04-17 16:05:31 -0500181 /* Force ulpStatus error since we are returning NULL ptr */
182 if (!(irsp->ulpStatus)) {
183 irsp->ulpStatus = IOSTAT_LOCAL_REJECT;
184 irsp->un.ulpWord[4] = IOERR_SLI_ABORTED;
185 }
186 ptr = NULL;
187 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -0500188 return ptr;
dea31012005-04-17 16:05:31 -0500189}
190
191
192/*
193 * Free resources / clean up outstanding I/Os
194 * associated with a LPFC_NODELIST entry. This
195 * routine effectively results in a "software abort".
196 */
197int
James Smart2e0fef82007-06-17 19:56:36 -0500198lpfc_els_abort(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -0500199{
James Smart2534ba72007-04-25 09:52:20 -0400200 LIST_HEAD(completions);
James Smart2e0fef82007-06-17 19:56:36 -0500201 struct lpfc_sli *psli = &phba->sli;
202 struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING];
dea31012005-04-17 16:05:31 -0500203 struct lpfc_iocbq *iocb, *next_iocb;
dea31012005-04-17 16:05:31 -0500204
205 /* Abort outstanding I/O on NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -0400206 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_DISCOVERY,
207 "0205 Abort outstanding I/O on NPort x%x "
208 "Data: x%x x%x x%x\n",
209 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
210 ndlp->nlp_rpi);
James Smart92d7f7b2007-06-17 19:56:38 -0500211
212 lpfc_fabric_abort_nport(ndlp);
dea31012005-04-17 16:05:31 -0500213
dea31012005-04-17 16:05:31 -0500214 /* First check the txq */
James Smart2e0fef82007-06-17 19:56:36 -0500215 spin_lock_irq(&phba->hbalock);
James Smart2534ba72007-04-25 09:52:20 -0400216 list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
James Smart858c9f62007-06-17 19:56:39 -0500217 /* Check to see if iocb matches the nport we are looking for */
James Smart2534ba72007-04-25 09:52:20 -0400218 if (lpfc_check_sli_ndlp(phba, pring, iocb, ndlp)) {
James Smart858c9f62007-06-17 19:56:39 -0500219 /* It matches, so deque and call compl with anp error */
James Smart2534ba72007-04-25 09:52:20 -0400220 list_move_tail(&iocb->list, &completions);
221 pring->txq_cnt--;
dea31012005-04-17 16:05:31 -0500222 }
James Smart2534ba72007-04-25 09:52:20 -0400223 }
dea31012005-04-17 16:05:31 -0500224
dea31012005-04-17 16:05:31 -0500225 /* Next check the txcmplq */
James Smart07951072007-04-25 09:51:38 -0400226 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
James Smart858c9f62007-06-17 19:56:39 -0500227 /* Check to see if iocb matches the nport we are looking for */
James Smart92d7f7b2007-06-17 19:56:38 -0500228 if (lpfc_check_sli_ndlp(phba, pring, iocb, ndlp)) {
James Smart07951072007-04-25 09:51:38 -0400229 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
James Smart92d7f7b2007-06-17 19:56:38 -0500230 }
James Smart07951072007-04-25 09:51:38 -0400231 }
James Smart2e0fef82007-06-17 19:56:36 -0500232 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500233
James Smarta257bf92009-04-06 18:48:10 -0400234 /* Cancel all the IOCBs from the completions list */
235 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
236 IOERR_SLI_ABORTED);
James Smart2534ba72007-04-25 09:52:20 -0400237
James Smart0d2b6b82008-06-14 22:52:47 -0400238 lpfc_cancel_retry_delay_tmo(phba->pport, ndlp);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -0500239 return 0;
dea31012005-04-17 16:05:31 -0500240}
241
242static int
James Smart2e0fef82007-06-17 19:56:36 -0500243lpfc_rcv_plogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
James Smart92d7f7b2007-06-17 19:56:38 -0500244 struct lpfc_iocbq *cmdiocb)
dea31012005-04-17 16:05:31 -0500245{
James Smart2e0fef82007-06-17 19:56:36 -0500246 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
247 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500248 struct lpfc_dmabuf *pcmd;
249 uint32_t *lp;
250 IOCB_t *icmd;
251 struct serv_parm *sp;
252 LPFC_MBOXQ_t *mbox;
253 struct ls_rjt stat;
254 int rc;
255
256 memset(&stat, 0, sizeof (struct ls_rjt));
James Smart695a8142010-01-26 23:08:03 -0500257 if (vport->port_state <= LPFC_FDISC) {
dea31012005-04-17 16:05:31 -0500258 /* Before responding to PLOGI, check for pt2pt mode.
259 * If we are pt2pt, with an outstanding FLOGI, abort
260 * the FLOGI and resend it first.
261 */
James Smart2e0fef82007-06-17 19:56:36 -0500262 if (vport->fc_flag & FC_PT2PT) {
James Smart92d7f7b2007-06-17 19:56:38 -0500263 lpfc_els_abort_flogi(phba);
James Smart2e0fef82007-06-17 19:56:36 -0500264 if (!(vport->fc_flag & FC_PT2PT_PLOGI)) {
dea31012005-04-17 16:05:31 -0500265 /* If the other side is supposed to initiate
266 * the PLOGI anyway, just ACC it now and
267 * move on with discovery.
268 */
269 phba->fc_edtov = FF_DEF_EDTOV;
270 phba->fc_ratov = FF_DEF_RATOV;
271 /* Start discovery - this should just do
272 CLEAR_LA */
James Smart2e0fef82007-06-17 19:56:36 -0500273 lpfc_disc_start(vport);
James Smarted957682007-06-17 19:56:37 -0500274 } else
James Smart2e0fef82007-06-17 19:56:36 -0500275 lpfc_initial_flogi(vport);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500276 } else {
dea31012005-04-17 16:05:31 -0500277 stat.un.b.lsRjtRsnCode = LSRJT_LOGICAL_BSY;
278 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
James Smart2e0fef82007-06-17 19:56:36 -0500279 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb,
James Smart858c9f62007-06-17 19:56:39 -0500280 ndlp, NULL);
dea31012005-04-17 16:05:31 -0500281 return 0;
282 }
283 }
284 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
285 lp = (uint32_t *) pcmd->virt;
286 sp = (struct serv_parm *) ((uint8_t *) lp + sizeof (uint32_t));
James Smarta8adb832007-10-27 13:37:53 -0400287 if (wwn_to_u64(sp->portName.u.wwn) == 0) {
288 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
289 "0140 PLOGI Reject: invalid nname\n");
290 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
291 stat.un.b.lsRjtRsnCodeExp = LSEXP_INVALID_PNAME;
292 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
293 NULL);
294 return 0;
295 }
296 if (wwn_to_u64(sp->nodeName.u.wwn) == 0) {
297 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
298 "0141 PLOGI Reject: invalid pname\n");
299 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
300 stat.un.b.lsRjtRsnCodeExp = LSEXP_INVALID_NNAME;
301 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
302 NULL);
303 return 0;
304 }
James Smart341af102010-01-26 23:07:37 -0500305 if ((lpfc_check_sparm(vport, ndlp, sp, CLASS3, 0) == 0)) {
dea31012005-04-17 16:05:31 -0500306 /* Reject this request because invalid parameters */
307 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
308 stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
James Smart858c9f62007-06-17 19:56:39 -0500309 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
310 NULL);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -0500311 return 0;
dea31012005-04-17 16:05:31 -0500312 }
313 icmd = &cmdiocb->iocb;
314
315 /* PLOGI chkparm OK */
James Smarte8b62012007-08-02 11:10:09 -0400316 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
317 "0114 PLOGI chkparm OK Data: x%x x%x x%x x%x\n",
318 ndlp->nlp_DID, ndlp->nlp_state, ndlp->nlp_flag,
319 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -0500320
James Smart3de2a652007-08-02 11:09:59 -0400321 if (vport->cfg_fcp_class == 2 && sp->cls2.classValid)
dea31012005-04-17 16:05:31 -0500322 ndlp->nlp_fcp_info |= CLASS2;
James Smarted957682007-06-17 19:56:37 -0500323 else
dea31012005-04-17 16:05:31 -0500324 ndlp->nlp_fcp_info |= CLASS3;
James Smart2e0fef82007-06-17 19:56:36 -0500325
dea31012005-04-17 16:05:31 -0500326 ndlp->nlp_class_sup = 0;
327 if (sp->cls1.classValid)
328 ndlp->nlp_class_sup |= FC_COS_CLASS1;
329 if (sp->cls2.classValid)
330 ndlp->nlp_class_sup |= FC_COS_CLASS2;
331 if (sp->cls3.classValid)
332 ndlp->nlp_class_sup |= FC_COS_CLASS3;
333 if (sp->cls4.classValid)
334 ndlp->nlp_class_sup |= FC_COS_CLASS4;
335 ndlp->nlp_maxframe =
336 ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) | sp->cmn.bbRcvSizeLsb;
337
338 /* no need to reg_login if we are already in one of these states */
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500339 switch (ndlp->nlp_state) {
dea31012005-04-17 16:05:31 -0500340 case NLP_STE_NPR_NODE:
341 if (!(ndlp->nlp_flag & NLP_NPR_ADISC))
342 break;
343 case NLP_STE_REG_LOGIN_ISSUE:
344 case NLP_STE_PRLI_ISSUE:
345 case NLP_STE_UNMAPPED_NODE:
346 case NLP_STE_MAPPED_NODE:
James Smart51ef4c22007-08-02 11:10:31 -0400347 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp, NULL);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -0500348 return 1;
dea31012005-04-17 16:05:31 -0500349 }
350
James Smart92d7f7b2007-06-17 19:56:38 -0500351 if ((vport->fc_flag & FC_PT2PT) &&
352 !(vport->fc_flag & FC_PT2PT_PLOGI)) {
dea31012005-04-17 16:05:31 -0500353 /* rcv'ed PLOGI decides what our NPortId will be */
James Smart2e0fef82007-06-17 19:56:36 -0500354 vport->fc_myDID = icmd->un.rcvels.parmRo;
dea31012005-04-17 16:05:31 -0500355 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
356 if (mbox == NULL)
357 goto out;
358 lpfc_config_link(phba, mbox);
359 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smarted957682007-06-17 19:56:37 -0500360 mbox->vport = vport;
James Smart0b727fe2007-10-27 13:37:25 -0400361 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
dea31012005-04-17 16:05:31 -0500362 if (rc == MBX_NOT_FINISHED) {
James Smart92d7f7b2007-06-17 19:56:38 -0500363 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -0500364 goto out;
365 }
366
James Smart2e0fef82007-06-17 19:56:36 -0500367 lpfc_can_disctmo(vport);
dea31012005-04-17 16:05:31 -0500368 }
369 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
James Smart2e0fef82007-06-17 19:56:36 -0500370 if (!mbox)
dea31012005-04-17 16:05:31 -0500371 goto out;
372
James Smart6fb120a2009-05-22 14:52:59 -0400373 rc = lpfc_reg_rpi(phba, vport->vpi, icmd->un.rcvels.remoteID,
James Smart92d7f7b2007-06-17 19:56:38 -0500374 (uint8_t *) sp, mbox, 0);
James Smart2e0fef82007-06-17 19:56:36 -0500375 if (rc) {
376 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -0500377 goto out;
378 }
379
380 /* ACC PLOGI rsp command needs to execute first,
381 * queue this mbox command to be processed later.
382 */
383 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
James Smart329f9bc2007-04-25 09:53:01 -0400384 /*
385 * mbox->context2 = lpfc_nlp_get(ndlp) deferred until mailbox
386 * command issued in lpfc_cmpl_els_acc().
387 */
James Smart2e0fef82007-06-17 19:56:36 -0500388 mbox->vport = vport;
389 spin_lock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -0500390 ndlp->nlp_flag |= (NLP_ACC_REGLOGIN | NLP_RCV_PLOGI);
James Smart2e0fef82007-06-17 19:56:36 -0500391 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500392
James Smart33ccf8d2006-08-17 11:57:58 -0400393 /*
394 * If there is an outstanding PLOGI issued, abort it before
395 * sending ACC rsp for received PLOGI. If pending plogi
396 * is not canceled here, the plogi will be rejected by
397 * remote port and will be retried. On a configuration with
398 * single discovery thread, this will cause a huge delay in
399 * discovery. Also this will cause multiple state machines
400 * running in parallel for this node.
401 */
402 if (ndlp->nlp_state == NLP_STE_PLOGI_ISSUE) {
403 /* software abort outstanding PLOGI */
James Smart07951072007-04-25 09:51:38 -0400404 lpfc_els_abort(phba, ndlp);
James Smart33ccf8d2006-08-17 11:57:58 -0400405 }
406
James Smart858c9f62007-06-17 19:56:39 -0500407 if ((vport->port_type == LPFC_NPIV_PORT &&
James Smart3de2a652007-08-02 11:09:59 -0400408 vport->cfg_restrict_login)) {
James Smart858c9f62007-06-17 19:56:39 -0500409
410 /* In order to preserve RPIs, we want to cleanup
411 * the default RPI the firmware created to rcv
412 * this ELS request. The only way to do this is
413 * to register, then unregister the RPI.
414 */
415 spin_lock_irq(shost->host_lock);
416 ndlp->nlp_flag |= NLP_RM_DFLT_RPI;
417 spin_unlock_irq(shost->host_lock);
418 stat.un.b.lsRjtRsnCode = LSRJT_INVALID_CMD;
419 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
420 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb,
421 ndlp, mbox);
422 return 1;
423 }
James Smart51ef4c22007-08-02 11:10:31 -0400424 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp, mbox);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -0500425 return 1;
dea31012005-04-17 16:05:31 -0500426out:
427 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
428 stat.un.b.lsRjtRsnCodeExp = LSEXP_OUT_OF_RESOURCE;
James Smart858c9f62007-06-17 19:56:39 -0500429 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -0500430 return 0;
dea31012005-04-17 16:05:31 -0500431}
432
433static int
James Smart2e0fef82007-06-17 19:56:36 -0500434lpfc_rcv_padisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -0500435 struct lpfc_iocbq *cmdiocb)
436{
James Smart2e0fef82007-06-17 19:56:36 -0500437 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -0500438 struct lpfc_dmabuf *pcmd;
James Smart2e0fef82007-06-17 19:56:36 -0500439 struct serv_parm *sp;
440 struct lpfc_name *pnn, *ppn;
dea31012005-04-17 16:05:31 -0500441 struct ls_rjt stat;
442 ADISC *ap;
443 IOCB_t *icmd;
444 uint32_t *lp;
445 uint32_t cmd;
446
447 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
448 lp = (uint32_t *) pcmd->virt;
449
450 cmd = *lp++;
451 if (cmd == ELS_CMD_ADISC) {
452 ap = (ADISC *) lp;
453 pnn = (struct lpfc_name *) & ap->nodeName;
454 ppn = (struct lpfc_name *) & ap->portName;
455 } else {
456 sp = (struct serv_parm *) lp;
457 pnn = (struct lpfc_name *) & sp->nodeName;
458 ppn = (struct lpfc_name *) & sp->portName;
459 }
460
461 icmd = &cmdiocb->iocb;
James Smart2e0fef82007-06-17 19:56:36 -0500462 if (icmd->ulpStatus == 0 && lpfc_check_adisc(vport, ndlp, pnn, ppn)) {
dea31012005-04-17 16:05:31 -0500463 if (cmd == ELS_CMD_ADISC) {
James Smart2e0fef82007-06-17 19:56:36 -0500464 lpfc_els_rsp_adisc_acc(vport, cmdiocb, ndlp);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500465 } else {
James Smart2e0fef82007-06-17 19:56:36 -0500466 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp,
James Smart51ef4c22007-08-02 11:10:31 -0400467 NULL);
dea31012005-04-17 16:05:31 -0500468 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -0500469 return 1;
dea31012005-04-17 16:05:31 -0500470 }
471 /* Reject this request because invalid parameters */
472 stat.un.b.lsRjtRsvd0 = 0;
473 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
474 stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
475 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -0500476 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -0500477
dea31012005-04-17 16:05:31 -0500478 /* 1 sec timeout */
479 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ);
480
James Smart2e0fef82007-06-17 19:56:36 -0500481 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500482 ndlp->nlp_flag |= NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -0500483 spin_unlock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -0500484 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
485 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -0500486 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -0500487 return 0;
dea31012005-04-17 16:05:31 -0500488}
489
490static int
James Smart2e0fef82007-06-17 19:56:36 -0500491lpfc_rcv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
492 struct lpfc_iocbq *cmdiocb, uint32_t els_cmd)
dea31012005-04-17 16:05:31 -0500493{
James Smart2e0fef82007-06-17 19:56:36 -0500494 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
495
496 /* Put ndlp in NPR state with 1 sec timeout for plogi, ACC logo */
dea31012005-04-17 16:05:31 -0500497 /* Only call LOGO ACC for first LOGO, this avoids sending unnecessary
498 * PLOGIs during LOGO storms from a device.
499 */
James Smart2e0fef82007-06-17 19:56:36 -0500500 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500501 ndlp->nlp_flag |= NLP_LOGO_ACC;
James Smart2e0fef82007-06-17 19:56:36 -0500502 spin_unlock_irq(shost->host_lock);
James Smart82d9a2a2006-04-15 11:53:05 -0400503 if (els_cmd == ELS_CMD_PRLO)
James Smart51ef4c22007-08-02 11:10:31 -0400504 lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL);
James Smart82d9a2a2006-04-15 11:53:05 -0400505 else
James Smart51ef4c22007-08-02 11:10:31 -0400506 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
James Smart0c287582009-06-10 17:22:56 -0400507 if ((ndlp->nlp_DID == Fabric_DID) &&
James Smart6fb120a2009-05-22 14:52:59 -0400508 vport->port_type == LPFC_NPIV_PORT) {
509 lpfc_linkdown_port(vport);
510 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ * 1);
511 spin_lock_irq(shost->host_lock);
512 ndlp->nlp_flag |= NLP_DELAY_TMO;
513 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500514
James Smart6fb120a2009-05-22 14:52:59 -0400515 ndlp->nlp_last_elscmd = ELS_CMD_FDISC;
516 } else if ((!(ndlp->nlp_type & NLP_FABRIC) &&
517 ((ndlp->nlp_type & NLP_FCP_TARGET) ||
518 !(ndlp->nlp_type & NLP_FCP_INITIATOR))) ||
519 (ndlp->nlp_state == NLP_STE_ADISC_ISSUE)) {
dea31012005-04-17 16:05:31 -0500520 /* Only try to re-login if this is NOT a Fabric Node */
dea31012005-04-17 16:05:31 -0500521 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ * 1);
James Smart2e0fef82007-06-17 19:56:36 -0500522 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500523 ndlp->nlp_flag |= NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -0500524 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -0500525
Jamie Wellnitz5024ab12006-02-28 19:25:28 -0500526 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
dea31012005-04-17 16:05:31 -0500527 }
James Smart87af33f2007-10-27 13:37:43 -0400528 ndlp->nlp_prev_state = ndlp->nlp_state;
529 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
dea31012005-04-17 16:05:31 -0500530
James Smart2e0fef82007-06-17 19:56:36 -0500531 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500532 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
James Smart2e0fef82007-06-17 19:56:36 -0500533 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500534 /* The driver has to wait until the ACC completes before it continues
535 * processing the LOGO. The action will resume in
536 * lpfc_cmpl_els_logo_acc routine. Since part of processing includes an
537 * unreg_login, the driver waits so the ACC does not get aborted.
538 */
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -0500539 return 0;
dea31012005-04-17 16:05:31 -0500540}
541
542static void
James Smart2e0fef82007-06-17 19:56:36 -0500543lpfc_rcv_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
544 struct lpfc_iocbq *cmdiocb)
dea31012005-04-17 16:05:31 -0500545{
546 struct lpfc_dmabuf *pcmd;
547 uint32_t *lp;
548 PRLI *npr;
549 struct fc_rport *rport = ndlp->rport;
550 u32 roles;
551
552 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
553 lp = (uint32_t *) pcmd->virt;
554 npr = (PRLI *) ((uint8_t *) lp + sizeof (uint32_t));
555
556 ndlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR);
557 ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
James Smart92d7f7b2007-06-17 19:56:38 -0500558 if (npr->prliType == PRLI_FCP_TYPE) {
dea31012005-04-17 16:05:31 -0500559 if (npr->initiatorFunc)
560 ndlp->nlp_type |= NLP_FCP_INITIATOR;
561 if (npr->targetFunc)
562 ndlp->nlp_type |= NLP_FCP_TARGET;
563 if (npr->Retry)
564 ndlp->nlp_fcp_info |= NLP_FCP_2_DEVICE;
565 }
566 if (rport) {
567 /* We need to update the rport role values */
568 roles = FC_RPORT_ROLE_UNKNOWN;
569 if (ndlp->nlp_type & NLP_FCP_INITIATOR)
570 roles |= FC_RPORT_ROLE_FCP_INITIATOR;
571 if (ndlp->nlp_type & NLP_FCP_TARGET)
572 roles |= FC_RPORT_ROLE_FCP_TARGET;
James Smart858c9f62007-06-17 19:56:39 -0500573
574 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
575 "rport rolechg: role:x%x did:x%x flg:x%x",
576 roles, ndlp->nlp_DID, ndlp->nlp_flag);
577
dea31012005-04-17 16:05:31 -0500578 fc_remote_port_rolechg(rport, roles);
579 }
580}
581
582static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -0500583lpfc_disc_set_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -0500584{
James Smart2e0fef82007-06-17 19:56:36 -0500585 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart2e0fef82007-06-17 19:56:36 -0500586
James Smart6fb120a2009-05-22 14:52:59 -0400587 if (!(ndlp->nlp_flag & NLP_RPI_VALID)) {
James Smart51ef4c22007-08-02 11:10:31 -0400588 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
589 return 0;
590 }
591
James Smart1b32f6a2008-02-08 18:49:39 -0500592 if (!(vport->fc_flag & FC_PT2PT)) {
593 /* Check config parameter use-adisc or FCP-2 */
594 if ((vport->cfg_use_adisc && (vport->fc_flag & FC_RSCN_MODE)) ||
595 ndlp->nlp_fcp_info & NLP_FCP_2_DEVICE) {
596 spin_lock_irq(shost->host_lock);
597 ndlp->nlp_flag |= NLP_NPR_ADISC;
598 spin_unlock_irq(shost->host_lock);
599 return 1;
600 }
James Smart92d7f7b2007-06-17 19:56:38 -0500601 }
602 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
603 lpfc_unreg_rpi(vport, ndlp);
604 return 0;
dea31012005-04-17 16:05:31 -0500605}
606
607static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -0500608lpfc_disc_illegal(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
609 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -0500610{
James Smarte8b62012007-08-02 11:10:09 -0400611 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
James Smarte47c9092008-02-08 18:49:26 -0500612 "0271 Illegal State Transition: node x%x "
James Smarte8b62012007-08-02 11:10:09 -0400613 "event x%x, state x%x Data: x%x x%x\n",
614 ndlp->nlp_DID, evt, ndlp->nlp_state, ndlp->nlp_rpi,
615 ndlp->nlp_flag);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -0500616 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -0500617}
618
James Smart87af33f2007-10-27 13:37:43 -0400619static uint32_t
620lpfc_cmpl_plogi_illegal(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
621 void *arg, uint32_t evt)
622{
623 /* This transition is only legal if we previously
624 * rcv'ed a PLOGI. Since we don't want 2 discovery threads
625 * working on the same NPortID, do nothing for this thread
626 * to stop it.
627 */
628 if (!(ndlp->nlp_flag & NLP_RCV_PLOGI)) {
629 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
James Smarte47c9092008-02-08 18:49:26 -0500630 "0272 Illegal State Transition: node x%x "
James Smart87af33f2007-10-27 13:37:43 -0400631 "event x%x, state x%x Data: x%x x%x\n",
632 ndlp->nlp_DID, evt, ndlp->nlp_state, ndlp->nlp_rpi,
633 ndlp->nlp_flag);
634 }
635 return ndlp->nlp_state;
636}
637
dea31012005-04-17 16:05:31 -0500638/* Start of Discovery State Machine routines */
639
640static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -0500641lpfc_rcv_plogi_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
642 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -0500643{
644 struct lpfc_iocbq *cmdiocb;
645
646 cmdiocb = (struct lpfc_iocbq *) arg;
647
James Smart2e0fef82007-06-17 19:56:36 -0500648 if (lpfc_rcv_plogi(vport, ndlp, cmdiocb)) {
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -0500649 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -0500650 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -0500651 return NLP_STE_FREED_NODE;
dea31012005-04-17 16:05:31 -0500652}
653
654static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -0500655lpfc_rcv_els_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
656 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -0500657{
James Smart2e0fef82007-06-17 19:56:36 -0500658 lpfc_issue_els_logo(vport, ndlp, 0);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -0500659 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -0500660}
661
662static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -0500663lpfc_rcv_logo_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
664 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -0500665{
James Smart2e0fef82007-06-17 19:56:36 -0500666 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
667 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -0500668
James Smart2e0fef82007-06-17 19:56:36 -0500669 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500670 ndlp->nlp_flag |= NLP_LOGO_ACC;
James Smart2e0fef82007-06-17 19:56:36 -0500671 spin_unlock_irq(shost->host_lock);
James Smart51ef4c22007-08-02 11:10:31 -0400672 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -0500673
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -0500674 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -0500675}
676
677static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -0500678lpfc_cmpl_logo_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -0500679 void *arg, uint32_t evt)
680{
James Smart2e0fef82007-06-17 19:56:36 -0500681 return NLP_STE_FREED_NODE;
682}
683
684static uint32_t
685lpfc_device_rm_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
686 void *arg, uint32_t evt)
687{
James Smart2e0fef82007-06-17 19:56:36 -0500688 return NLP_STE_FREED_NODE;
689}
690
691static uint32_t
692lpfc_rcv_plogi_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
693 void *arg, uint32_t evt)
694{
James Smart0d2b6b82008-06-14 22:52:47 -0400695 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart2e0fef82007-06-17 19:56:36 -0500696 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500697 struct lpfc_iocbq *cmdiocb = arg;
James Smart2e0fef82007-06-17 19:56:36 -0500698 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
699 uint32_t *lp = (uint32_t *) pcmd->virt;
700 struct serv_parm *sp = (struct serv_parm *) (lp + 1);
dea31012005-04-17 16:05:31 -0500701 struct ls_rjt stat;
702 int port_cmp;
703
dea31012005-04-17 16:05:31 -0500704 memset(&stat, 0, sizeof (struct ls_rjt));
705
706 /* For a PLOGI, we only accept if our portname is less
707 * than the remote portname.
708 */
709 phba->fc_stat.elsLogiCol++;
James Smart2e0fef82007-06-17 19:56:36 -0500710 port_cmp = memcmp(&vport->fc_portname, &sp->portName,
James Smart92d7f7b2007-06-17 19:56:38 -0500711 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -0500712
713 if (port_cmp >= 0) {
714 /* Reject this request because the remote node will accept
715 ours */
716 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
717 stat.un.b.lsRjtRsnCodeExp = LSEXP_CMD_IN_PROGRESS;
James Smart858c9f62007-06-17 19:56:39 -0500718 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
719 NULL);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500720 } else {
James Smart0d2b6b82008-06-14 22:52:47 -0400721 if (lpfc_rcv_plogi(vport, ndlp, cmdiocb) &&
722 (ndlp->nlp_flag & NLP_NPR_2B_DISC) &&
723 (vport->num_disc_nodes)) {
724 spin_lock_irq(shost->host_lock);
725 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
726 spin_unlock_irq(shost->host_lock);
727 /* Check if there are more PLOGIs to be sent */
728 lpfc_more_plogi(vport);
729 if (vport->num_disc_nodes == 0) {
730 spin_lock_irq(shost->host_lock);
731 vport->fc_flag &= ~FC_NDISC_ACTIVE;
732 spin_unlock_irq(shost->host_lock);
733 lpfc_can_disctmo(vport);
734 lpfc_end_rscn(vport);
735 }
736 }
James Smart2e0fef82007-06-17 19:56:36 -0500737 } /* If our portname was less */
dea31012005-04-17 16:05:31 -0500738
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -0500739 return ndlp->nlp_state;
740}
741
742static uint32_t
James Smart92d7f7b2007-06-17 19:56:38 -0500743lpfc_rcv_prli_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
744 void *arg, uint32_t evt)
745{
746 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
747 struct ls_rjt stat;
748
749 memset(&stat, 0, sizeof (struct ls_rjt));
750 stat.un.b.lsRjtRsnCode = LSRJT_LOGICAL_BSY;
751 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
James Smart858c9f62007-06-17 19:56:39 -0500752 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
James Smart92d7f7b2007-06-17 19:56:38 -0500753 return ndlp->nlp_state;
754}
755
756static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -0500757lpfc_rcv_logo_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
758 void *arg, uint32_t evt)
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -0500759{
James Smart2e0fef82007-06-17 19:56:36 -0500760 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -0500761
James Smart92d7f7b2007-06-17 19:56:38 -0500762 /* software abort outstanding PLOGI */
James Smart2e0fef82007-06-17 19:56:36 -0500763 lpfc_els_abort(vport->phba, ndlp);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -0500764
James Smart2e0fef82007-06-17 19:56:36 -0500765 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -0500766 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -0500767}
768
769static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -0500770lpfc_rcv_els_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
771 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -0500772{
James Smart2e0fef82007-06-17 19:56:36 -0500773 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
774 struct lpfc_hba *phba = vport->phba;
775 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -0500776
777 /* software abort outstanding PLOGI */
James Smart07951072007-04-25 09:51:38 -0400778 lpfc_els_abort(phba, ndlp);
dea31012005-04-17 16:05:31 -0500779
780 if (evt == NLP_EVT_RCV_LOGO) {
James Smart51ef4c22007-08-02 11:10:31 -0400781 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500782 } else {
James Smart2e0fef82007-06-17 19:56:36 -0500783 lpfc_issue_els_logo(vport, ndlp, 0);
dea31012005-04-17 16:05:31 -0500784 }
785
James Smart2e0fef82007-06-17 19:56:36 -0500786 /* Put ndlp in npr state set plogi timer for 1 sec */
Jamie Wellnitz5024ab12006-02-28 19:25:28 -0500787 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ * 1);
James Smart2e0fef82007-06-17 19:56:36 -0500788 spin_lock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -0500789 ndlp->nlp_flag |= NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -0500790 spin_unlock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -0500791 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
792 ndlp->nlp_prev_state = NLP_STE_PLOGI_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -0500793 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
dea31012005-04-17 16:05:31 -0500794
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -0500795 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -0500796}
797
798static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -0500799lpfc_cmpl_plogi_plogi_issue(struct lpfc_vport *vport,
800 struct lpfc_nodelist *ndlp,
801 void *arg,
dea31012005-04-17 16:05:31 -0500802 uint32_t evt)
803{
James Smart2e0fef82007-06-17 19:56:36 -0500804 struct lpfc_hba *phba = vport->phba;
James Smart0ff10d42008-01-11 01:52:36 -0500805 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart2e0fef82007-06-17 19:56:36 -0500806 struct lpfc_iocbq *cmdiocb, *rspiocb;
James Smart14691152006-12-02 13:34:28 -0500807 struct lpfc_dmabuf *pcmd, *prsp, *mp;
dea31012005-04-17 16:05:31 -0500808 uint32_t *lp;
809 IOCB_t *irsp;
810 struct serv_parm *sp;
811 LPFC_MBOXQ_t *mbox;
812
813 cmdiocb = (struct lpfc_iocbq *) arg;
814 rspiocb = cmdiocb->context_un.rsp_iocb;
815
816 if (ndlp->nlp_flag & NLP_ACC_REGLOGIN) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -0500817 /* Recovery from PLOGI collision logic */
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -0500818 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -0500819 }
820
821 irsp = &rspiocb->iocb;
822
823 if (irsp->ulpStatus)
824 goto out;
825
826 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
827
James Smart2e0fef82007-06-17 19:56:36 -0500828 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
dea31012005-04-17 16:05:31 -0500829
James Smart2e0fef82007-06-17 19:56:36 -0500830 lp = (uint32_t *) prsp->virt;
dea31012005-04-17 16:05:31 -0500831 sp = (struct serv_parm *) ((uint8_t *) lp + sizeof (uint32_t));
James Smart58da1ff2008-04-07 10:15:56 -0400832
833 /* Some switches have FDMI servers returning 0 for WWN */
834 if ((ndlp->nlp_DID != FDMI_DID) &&
835 (wwn_to_u64(sp->portName.u.wwn) == 0 ||
836 wwn_to_u64(sp->nodeName.u.wwn) == 0)) {
James Smarta8adb832007-10-27 13:37:53 -0400837 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
838 "0142 PLOGI RSP: Invalid WWN.\n");
839 goto out;
840 }
James Smart341af102010-01-26 23:07:37 -0500841 if (!lpfc_check_sparm(vport, ndlp, sp, CLASS3, 0))
dea31012005-04-17 16:05:31 -0500842 goto out;
dea31012005-04-17 16:05:31 -0500843 /* PLOGI chkparm OK */
James Smarte8b62012007-08-02 11:10:09 -0400844 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
845 "0121 PLOGI chkparm OK Data: x%x x%x x%x x%x\n",
846 ndlp->nlp_DID, ndlp->nlp_state,
847 ndlp->nlp_flag, ndlp->nlp_rpi);
James Smart3de2a652007-08-02 11:09:59 -0400848 if (vport->cfg_fcp_class == 2 && (sp->cls2.classValid))
dea31012005-04-17 16:05:31 -0500849 ndlp->nlp_fcp_info |= CLASS2;
James Smart2e0fef82007-06-17 19:56:36 -0500850 else
dea31012005-04-17 16:05:31 -0500851 ndlp->nlp_fcp_info |= CLASS3;
James Smart2e0fef82007-06-17 19:56:36 -0500852
dea31012005-04-17 16:05:31 -0500853 ndlp->nlp_class_sup = 0;
854 if (sp->cls1.classValid)
855 ndlp->nlp_class_sup |= FC_COS_CLASS1;
856 if (sp->cls2.classValid)
857 ndlp->nlp_class_sup |= FC_COS_CLASS2;
858 if (sp->cls3.classValid)
859 ndlp->nlp_class_sup |= FC_COS_CLASS3;
860 if (sp->cls4.classValid)
861 ndlp->nlp_class_sup |= FC_COS_CLASS4;
862 ndlp->nlp_maxframe =
James Smart2e0fef82007-06-17 19:56:36 -0500863 ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) | sp->cmn.bbRcvSizeLsb;
dea31012005-04-17 16:05:31 -0500864
James Smart2e0fef82007-06-17 19:56:36 -0500865 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
James Smart92d7f7b2007-06-17 19:56:38 -0500866 if (!mbox) {
James Smarte8b62012007-08-02 11:10:09 -0400867 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
868 "0133 PLOGI: no memory for reg_login "
James Smart92d7f7b2007-06-17 19:56:38 -0500869 "Data: x%x x%x x%x x%x\n",
James Smart92d7f7b2007-06-17 19:56:38 -0500870 ndlp->nlp_DID, ndlp->nlp_state,
871 ndlp->nlp_flag, ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -0500872 goto out;
James Smart92d7f7b2007-06-17 19:56:38 -0500873 }
dea31012005-04-17 16:05:31 -0500874
James Smart2e0fef82007-06-17 19:56:36 -0500875 lpfc_unreg_rpi(vport, ndlp);
876
James Smart6fb120a2009-05-22 14:52:59 -0400877 if (lpfc_reg_rpi(phba, vport->vpi, irsp->un.elsreq64.remoteID,
James Smart92d7f7b2007-06-17 19:56:38 -0500878 (uint8_t *) sp, mbox, 0) == 0) {
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500879 switch (ndlp->nlp_DID) {
dea31012005-04-17 16:05:31 -0500880 case NameServer_DID:
James Smartde0c5b32007-04-25 09:52:27 -0400881 mbox->mbox_cmpl = lpfc_mbx_cmpl_ns_reg_login;
dea31012005-04-17 16:05:31 -0500882 break;
883 case FDMI_DID:
James Smartde0c5b32007-04-25 09:52:27 -0400884 mbox->mbox_cmpl = lpfc_mbx_cmpl_fdmi_reg_login;
dea31012005-04-17 16:05:31 -0500885 break;
886 default:
James Smartde0c5b32007-04-25 09:52:27 -0400887 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
dea31012005-04-17 16:05:31 -0500888 }
James Smart329f9bc2007-04-25 09:53:01 -0400889 mbox->context2 = lpfc_nlp_get(ndlp);
James Smart2e0fef82007-06-17 19:56:36 -0500890 mbox->vport = vport;
James Smart0b727fe2007-10-27 13:37:25 -0400891 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
dea31012005-04-17 16:05:31 -0500892 != MBX_NOT_FINISHED) {
James Smart2e0fef82007-06-17 19:56:36 -0500893 lpfc_nlp_set_state(vport, ndlp,
894 NLP_STE_REG_LOGIN_ISSUE);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -0500895 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -0500896 }
James Smartfa4066b2008-01-11 01:53:27 -0500897 /* decrement node reference count to the failed mbox
898 * command
899 */
James Smart329f9bc2007-04-25 09:53:01 -0400900 lpfc_nlp_put(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -0500901 mp = (struct lpfc_dmabuf *) mbox->context1;
James Smart14691152006-12-02 13:34:28 -0500902 lpfc_mbuf_free(phba, mp->virt, mp->phys);
903 kfree(mp);
dea31012005-04-17 16:05:31 -0500904 mempool_free(mbox, phba->mbox_mem_pool);
James Smart92d7f7b2007-06-17 19:56:38 -0500905
James Smarte8b62012007-08-02 11:10:09 -0400906 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
907 "0134 PLOGI: cannot issue reg_login "
908 "Data: x%x x%x x%x x%x\n",
909 ndlp->nlp_DID, ndlp->nlp_state,
910 ndlp->nlp_flag, ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -0500911 } else {
912 mempool_free(mbox, phba->mbox_mem_pool);
James Smart92d7f7b2007-06-17 19:56:38 -0500913
James Smarte8b62012007-08-02 11:10:09 -0400914 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
915 "0135 PLOGI: cannot format reg_login "
916 "Data: x%x x%x x%x x%x\n",
917 ndlp->nlp_DID, ndlp->nlp_state,
918 ndlp->nlp_flag, ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -0500919 }
920
921
James Smart92d7f7b2007-06-17 19:56:38 -0500922out:
923 if (ndlp->nlp_DID == NameServer_DID) {
924 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -0400925 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
926 "0261 Cannot Register NameServer login\n");
James Smart92d7f7b2007-06-17 19:56:38 -0500927 }
928
James Smart0ff10d42008-01-11 01:52:36 -0500929 spin_lock_irq(shost->host_lock);
James Smarta8adb832007-10-27 13:37:53 -0400930 ndlp->nlp_flag |= NLP_DEFER_RM;
James Smart0ff10d42008-01-11 01:52:36 -0500931 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -0500932 return NLP_STE_FREED_NODE;
dea31012005-04-17 16:05:31 -0500933}
934
935static uint32_t
James Smart0ff10d42008-01-11 01:52:36 -0500936lpfc_cmpl_logo_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
937 void *arg, uint32_t evt)
938{
939 return ndlp->nlp_state;
940}
941
942static uint32_t
943lpfc_cmpl_reglogin_plogi_issue(struct lpfc_vport *vport,
944 struct lpfc_nodelist *ndlp, void *arg, uint32_t evt)
945{
946 return ndlp->nlp_state;
947}
948
949static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -0500950lpfc_device_rm_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
951 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -0500952{
James Smart2e0fef82007-06-17 19:56:36 -0500953 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -0500954
James Smart2e0fef82007-06-17 19:56:36 -0500955 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
956 spin_lock_irq(shost->host_lock);
957 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
958 spin_unlock_irq(shost->host_lock);
959 return ndlp->nlp_state;
960 } else {
961 /* software abort outstanding PLOGI */
962 lpfc_els_abort(vport->phba, ndlp);
963
964 lpfc_drop_node(vport, ndlp);
James Smarta0f9b482006-04-15 11:52:56 -0400965 return NLP_STE_FREED_NODE;
966 }
dea31012005-04-17 16:05:31 -0500967}
968
969static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -0500970lpfc_device_recov_plogi_issue(struct lpfc_vport *vport,
971 struct lpfc_nodelist *ndlp,
972 void *arg,
973 uint32_t evt)
dea31012005-04-17 16:05:31 -0500974{
James Smart2e0fef82007-06-17 19:56:36 -0500975 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
976 struct lpfc_hba *phba = vport->phba;
977
James Smart92d7f7b2007-06-17 19:56:38 -0500978 /* Don't do anything that will mess up processing of the
979 * previous RSCN.
980 */
981 if (vport->fc_flag & FC_RSCN_DEFERRED)
982 return ndlp->nlp_state;
983
dea31012005-04-17 16:05:31 -0500984 /* software abort outstanding PLOGI */
James Smart07951072007-04-25 09:51:38 -0400985 lpfc_els_abort(phba, ndlp);
dea31012005-04-17 16:05:31 -0500986
Jamie Wellnitz5024ab12006-02-28 19:25:28 -0500987 ndlp->nlp_prev_state = NLP_STE_PLOGI_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -0500988 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
James Smart92d7f7b2007-06-17 19:56:38 -0500989 spin_lock_irq(shost->host_lock);
James Smarta0f9b482006-04-15 11:52:56 -0400990 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
James Smart2e0fef82007-06-17 19:56:36 -0500991 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500992
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -0500993 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -0500994}
995
996static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -0500997lpfc_rcv_plogi_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
998 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -0500999{
James Smart0d2b6b82008-06-14 22:52:47 -04001000 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart2e0fef82007-06-17 19:56:36 -05001001 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001002 struct lpfc_iocbq *cmdiocb;
1003
1004 /* software abort outstanding ADISC */
James Smart07951072007-04-25 09:51:38 -04001005 lpfc_els_abort(phba, ndlp);
dea31012005-04-17 16:05:31 -05001006
1007 cmdiocb = (struct lpfc_iocbq *) arg;
1008
James Smart0d2b6b82008-06-14 22:52:47 -04001009 if (lpfc_rcv_plogi(vport, ndlp, cmdiocb)) {
1010 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1011 spin_lock_irq(shost->host_lock);
1012 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
1013 spin_unlock_irq(shost->host_lock);
James Smart90160e02008-08-24 21:49:45 -04001014 if (vport->num_disc_nodes)
James Smart0d2b6b82008-06-14 22:52:47 -04001015 lpfc_more_adisc(vport);
James Smart0d2b6b82008-06-14 22:52:47 -04001016 }
1017 return ndlp->nlp_state;
1018 }
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001019 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -05001020 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
1021 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
dea31012005-04-17 16:05:31 -05001022
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001023 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001024}
1025
1026static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001027lpfc_rcv_prli_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1028 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001029{
James Smart2e0fef82007-06-17 19:56:36 -05001030 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001031
James Smart2e0fef82007-06-17 19:56:36 -05001032 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001033 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001034}
1035
1036static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001037lpfc_rcv_logo_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1038 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001039{
James Smart2e0fef82007-06-17 19:56:36 -05001040 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001041 struct lpfc_iocbq *cmdiocb;
1042
1043 cmdiocb = (struct lpfc_iocbq *) arg;
1044
1045 /* software abort outstanding ADISC */
James Smart07951072007-04-25 09:51:38 -04001046 lpfc_els_abort(phba, ndlp);
dea31012005-04-17 16:05:31 -05001047
James Smart2e0fef82007-06-17 19:56:36 -05001048 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001049 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001050}
1051
1052static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001053lpfc_rcv_padisc_adisc_issue(struct lpfc_vport *vport,
1054 struct lpfc_nodelist *ndlp,
1055 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001056{
1057 struct lpfc_iocbq *cmdiocb;
1058
1059 cmdiocb = (struct lpfc_iocbq *) arg;
1060
James Smart2e0fef82007-06-17 19:56:36 -05001061 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001062 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001063}
1064
1065static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001066lpfc_rcv_prlo_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1067 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001068{
1069 struct lpfc_iocbq *cmdiocb;
1070
1071 cmdiocb = (struct lpfc_iocbq *) arg;
1072
1073 /* Treat like rcv logo */
James Smart2e0fef82007-06-17 19:56:36 -05001074 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_PRLO);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001075 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001076}
1077
1078static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001079lpfc_cmpl_adisc_adisc_issue(struct lpfc_vport *vport,
1080 struct lpfc_nodelist *ndlp,
1081 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001082{
James Smart2e0fef82007-06-17 19:56:36 -05001083 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1084 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001085 struct lpfc_iocbq *cmdiocb, *rspiocb;
1086 IOCB_t *irsp;
1087 ADISC *ap;
James Smart6fb120a2009-05-22 14:52:59 -04001088 int rc;
dea31012005-04-17 16:05:31 -05001089
1090 cmdiocb = (struct lpfc_iocbq *) arg;
1091 rspiocb = cmdiocb->context_un.rsp_iocb;
1092
1093 ap = (ADISC *)lpfc_check_elscmpl_iocb(phba, cmdiocb, rspiocb);
1094 irsp = &rspiocb->iocb;
1095
1096 if ((irsp->ulpStatus) ||
James Smart92d7f7b2007-06-17 19:56:38 -05001097 (!lpfc_check_adisc(vport, ndlp, &ap->nodeName, &ap->portName))) {
dea31012005-04-17 16:05:31 -05001098 /* 1 sec timeout */
1099 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ);
James Smart2e0fef82007-06-17 19:56:36 -05001100 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001101 ndlp->nlp_flag |= NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05001102 spin_unlock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001103 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
dea31012005-04-17 16:05:31 -05001104
James Smart2e0fef82007-06-17 19:56:36 -05001105 memset(&ndlp->nlp_nodename, 0, sizeof(struct lpfc_name));
1106 memset(&ndlp->nlp_portname, 0, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05001107
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001108 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -05001109 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1110 lpfc_unreg_rpi(vport, ndlp);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001111 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001112 }
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001113
James Smart6fb120a2009-05-22 14:52:59 -04001114 if (phba->sli_rev == LPFC_SLI_REV4) {
1115 rc = lpfc_sli4_resume_rpi(ndlp);
1116 if (rc) {
1117 /* Stay in state and retry. */
1118 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
1119 return ndlp->nlp_state;
1120 }
1121 }
1122
James.Smart@Emulex.Com25013222005-06-25 10:34:33 -04001123 if (ndlp->nlp_type & NLP_FCP_TARGET) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001124 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -05001125 lpfc_nlp_set_state(vport, ndlp, NLP_STE_MAPPED_NODE);
James.Smart@Emulex.Com25013222005-06-25 10:34:33 -04001126 } else {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001127 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -05001128 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
James.Smart@Emulex.Com25013222005-06-25 10:34:33 -04001129 }
James Smart6fb120a2009-05-22 14:52:59 -04001130
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001131 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001132}
1133
1134static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001135lpfc_device_rm_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1136 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001137{
James Smart2e0fef82007-06-17 19:56:36 -05001138 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001139
James Smart2e0fef82007-06-17 19:56:36 -05001140 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1141 spin_lock_irq(shost->host_lock);
1142 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
1143 spin_unlock_irq(shost->host_lock);
1144 return ndlp->nlp_state;
1145 } else {
1146 /* software abort outstanding ADISC */
1147 lpfc_els_abort(vport->phba, ndlp);
1148
1149 lpfc_drop_node(vport, ndlp);
James Smarta0f9b482006-04-15 11:52:56 -04001150 return NLP_STE_FREED_NODE;
1151 }
dea31012005-04-17 16:05:31 -05001152}
1153
1154static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001155lpfc_device_recov_adisc_issue(struct lpfc_vport *vport,
1156 struct lpfc_nodelist *ndlp,
1157 void *arg,
1158 uint32_t evt)
dea31012005-04-17 16:05:31 -05001159{
James Smart2e0fef82007-06-17 19:56:36 -05001160 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1161 struct lpfc_hba *phba = vport->phba;
1162
James Smart92d7f7b2007-06-17 19:56:38 -05001163 /* Don't do anything that will mess up processing of the
1164 * previous RSCN.
1165 */
1166 if (vport->fc_flag & FC_RSCN_DEFERRED)
1167 return ndlp->nlp_state;
1168
dea31012005-04-17 16:05:31 -05001169 /* software abort outstanding ADISC */
James Smart07951072007-04-25 09:51:38 -04001170 lpfc_els_abort(phba, ndlp);
dea31012005-04-17 16:05:31 -05001171
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001172 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -05001173 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1174 spin_lock_irq(shost->host_lock);
James Smarta0f9b482006-04-15 11:52:56 -04001175 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
James Smart2e0fef82007-06-17 19:56:36 -05001176 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05001177 lpfc_disc_set_adisc(vport, ndlp);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001178 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001179}
1180
1181static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001182lpfc_rcv_plogi_reglogin_issue(struct lpfc_vport *vport,
1183 struct lpfc_nodelist *ndlp,
1184 void *arg,
dea31012005-04-17 16:05:31 -05001185 uint32_t evt)
1186{
James Smart2e0fef82007-06-17 19:56:36 -05001187 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001188
James Smart2e0fef82007-06-17 19:56:36 -05001189 lpfc_rcv_plogi(vport, ndlp, cmdiocb);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001190 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001191}
1192
1193static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001194lpfc_rcv_prli_reglogin_issue(struct lpfc_vport *vport,
1195 struct lpfc_nodelist *ndlp,
1196 void *arg,
dea31012005-04-17 16:05:31 -05001197 uint32_t evt)
1198{
James Smart2e0fef82007-06-17 19:56:36 -05001199 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001200
James Smart2e0fef82007-06-17 19:56:36 -05001201 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
Jamie Wellnitzc9f8735b2006-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_logo_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_hba *phba = vport->phba;
1212 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
James Smart7054a602007-04-25 09:52:34 -04001213 LPFC_MBOXQ_t *mb;
1214 LPFC_MBOXQ_t *nextmb;
1215 struct lpfc_dmabuf *mp;
dea31012005-04-17 16:05:31 -05001216
1217 cmdiocb = (struct lpfc_iocbq *) arg;
1218
James Smart7054a602007-04-25 09:52:34 -04001219 /* cleanup any ndlp on mbox q waiting for reglogin cmpl */
1220 if ((mb = phba->sli.mbox_active)) {
James Smart04c68492009-05-22 14:52:52 -04001221 if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) &&
James Smart7054a602007-04-25 09:52:34 -04001222 (ndlp == (struct lpfc_nodelist *) mb->context2)) {
James Smart92d7f7b2007-06-17 19:56:38 -05001223 lpfc_nlp_put(ndlp);
James Smart7054a602007-04-25 09:52:34 -04001224 mb->context2 = NULL;
1225 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1226 }
1227 }
1228
James Smart2e0fef82007-06-17 19:56:36 -05001229 spin_lock_irq(&phba->hbalock);
James Smart7054a602007-04-25 09:52:34 -04001230 list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) {
James Smart04c68492009-05-22 14:52:52 -04001231 if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) &&
James Smart7054a602007-04-25 09:52:34 -04001232 (ndlp == (struct lpfc_nodelist *) mb->context2)) {
James Smart5ffc2662009-11-18 15:39:44 -05001233 if (phba->sli_rev == LPFC_SLI_REV4) {
1234 spin_unlock_irq(&phba->hbalock);
1235 lpfc_sli4_free_rpi(phba,
1236 mb->u.mb.un.varRegLogin.rpi);
1237 spin_lock_irq(&phba->hbalock);
1238 }
James Smart7054a602007-04-25 09:52:34 -04001239 mp = (struct lpfc_dmabuf *) (mb->context1);
1240 if (mp) {
James Smart98c9ea52007-10-27 13:37:33 -04001241 __lpfc_mbuf_free(phba, mp->virt, mp->phys);
James Smart7054a602007-04-25 09:52:34 -04001242 kfree(mp);
1243 }
James Smart92d7f7b2007-06-17 19:56:38 -05001244 lpfc_nlp_put(ndlp);
James Smart7054a602007-04-25 09:52:34 -04001245 list_del(&mb->list);
James Smart5ffc2662009-11-18 15:39:44 -05001246 phba->sli.mboxq_cnt--;
James Smart7054a602007-04-25 09:52:34 -04001247 mempool_free(mb, phba->mbox_mem_pool);
1248 }
1249 }
James Smart2e0fef82007-06-17 19:56:36 -05001250 spin_unlock_irq(&phba->hbalock);
James Smart7054a602007-04-25 09:52:34 -04001251
James Smart2e0fef82007-06-17 19:56:36 -05001252 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001253 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001254}
1255
1256static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001257lpfc_rcv_padisc_reglogin_issue(struct lpfc_vport *vport,
1258 struct lpfc_nodelist *ndlp,
1259 void *arg,
dea31012005-04-17 16:05:31 -05001260 uint32_t evt)
1261{
James Smart2e0fef82007-06-17 19:56:36 -05001262 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001263
James Smart2e0fef82007-06-17 19:56:36 -05001264 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001265 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001266}
1267
1268static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001269lpfc_rcv_prlo_reglogin_issue(struct lpfc_vport *vport,
1270 struct lpfc_nodelist *ndlp,
1271 void *arg,
dea31012005-04-17 16:05:31 -05001272 uint32_t evt)
1273{
1274 struct lpfc_iocbq *cmdiocb;
1275
1276 cmdiocb = (struct lpfc_iocbq *) arg;
James Smart51ef4c22007-08-02 11:10:31 -04001277 lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001278 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001279}
1280
1281static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001282lpfc_cmpl_reglogin_reglogin_issue(struct lpfc_vport *vport,
1283 struct lpfc_nodelist *ndlp,
1284 void *arg,
1285 uint32_t evt)
dea31012005-04-17 16:05:31 -05001286{
James Smart2e0fef82007-06-17 19:56:36 -05001287 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart2e0fef82007-06-17 19:56:36 -05001288 LPFC_MBOXQ_t *pmb = (LPFC_MBOXQ_t *) arg;
James Smart04c68492009-05-22 14:52:52 -04001289 MAILBOX_t *mb = &pmb->u.mb;
James Smart2e0fef82007-06-17 19:56:36 -05001290 uint32_t did = mb->un.varWords[1];
dea31012005-04-17 16:05:31 -05001291
dea31012005-04-17 16:05:31 -05001292 if (mb->mbxStatus) {
1293 /* RegLogin failed */
James Smarte8b62012007-08-02 11:10:09 -04001294 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
1295 "0246 RegLogin failed Data: x%x x%x x%x\n",
James Smart2e0fef82007-06-17 19:56:36 -05001296 did, mb->mbxStatus, vport->port_state);
James Smartd0e56da2006-07-06 15:49:42 -04001297 /*
1298 * If RegLogin failed due to lack of HBA resources do not
1299 * retry discovery.
1300 */
1301 if (mb->mbxStatus == MBXERR_RPI_FULL) {
James Smart87af33f2007-10-27 13:37:43 -04001302 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
1303 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
James Smartd0e56da2006-07-06 15:49:42 -04001304 return ndlp->nlp_state;
1305 }
1306
James Smart2e0fef82007-06-17 19:56:36 -05001307 /* Put ndlp in npr state set plogi timer for 1 sec */
dea31012005-04-17 16:05:31 -05001308 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ * 1);
James Smart2e0fef82007-06-17 19:56:36 -05001309 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001310 ndlp->nlp_flag |= NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05001311 spin_unlock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001312 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
dea31012005-04-17 16:05:31 -05001313
James Smart2e0fef82007-06-17 19:56:36 -05001314 lpfc_issue_els_logo(vport, ndlp, 0);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001315 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -05001316 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001317 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001318 }
1319
dea31012005-04-17 16:05:31 -05001320 ndlp->nlp_rpi = mb->un.varWords[0];
James Smart6fb120a2009-05-22 14:52:59 -04001321 ndlp->nlp_flag |= NLP_RPI_VALID;
dea31012005-04-17 16:05:31 -05001322
1323 /* Only if we are not a fabric nport do we issue PRLI */
1324 if (!(ndlp->nlp_type & NLP_FABRIC)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001325 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -05001326 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
1327 lpfc_issue_els_prli(vport, ndlp, 0);
dea31012005-04-17 16:05:31 -05001328 } else {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001329 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -05001330 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
dea31012005-04-17 16:05:31 -05001331 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001332 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001333}
1334
1335static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001336lpfc_device_rm_reglogin_issue(struct lpfc_vport *vport,
1337 struct lpfc_nodelist *ndlp,
1338 void *arg,
dea31012005-04-17 16:05:31 -05001339 uint32_t evt)
1340{
James Smart2e0fef82007-06-17 19:56:36 -05001341 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1342
1343 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1344 spin_lock_irq(shost->host_lock);
James Smarta0f9b482006-04-15 11:52:56 -04001345 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
James Smart2e0fef82007-06-17 19:56:36 -05001346 spin_unlock_irq(shost->host_lock);
James Smarta0f9b482006-04-15 11:52:56 -04001347 return ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05001348 } else {
1349 lpfc_drop_node(vport, ndlp);
James Smarta0f9b482006-04-15 11:52:56 -04001350 return NLP_STE_FREED_NODE;
1351 }
dea31012005-04-17 16:05:31 -05001352}
1353
1354static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001355lpfc_device_recov_reglogin_issue(struct lpfc_vport *vport,
1356 struct lpfc_nodelist *ndlp,
1357 void *arg,
1358 uint32_t evt)
dea31012005-04-17 16:05:31 -05001359{
James Smart2e0fef82007-06-17 19:56:36 -05001360 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1361
James Smart92d7f7b2007-06-17 19:56:38 -05001362 /* Don't do anything that will mess up processing of the
1363 * previous RSCN.
1364 */
1365 if (vport->fc_flag & FC_RSCN_DEFERRED)
1366 return ndlp->nlp_state;
1367
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001368 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -05001369 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1370 spin_lock_irq(shost->host_lock);
James Smarta0f9b482006-04-15 11:52:56 -04001371 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
James Smart2e0fef82007-06-17 19:56:36 -05001372 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05001373 lpfc_disc_set_adisc(vport, ndlp);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001374 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001375}
1376
1377static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001378lpfc_rcv_plogi_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1379 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001380{
1381 struct lpfc_iocbq *cmdiocb;
1382
1383 cmdiocb = (struct lpfc_iocbq *) arg;
1384
James Smart2e0fef82007-06-17 19:56:36 -05001385 lpfc_rcv_plogi(vport, ndlp, cmdiocb);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001386 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001387}
1388
1389static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001390lpfc_rcv_prli_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1391 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001392{
James Smart2e0fef82007-06-17 19:56:36 -05001393 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001394
James Smart2e0fef82007-06-17 19:56:36 -05001395 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001396 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001397}
1398
1399static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001400lpfc_rcv_logo_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1401 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001402{
James Smart2e0fef82007-06-17 19:56:36 -05001403 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001404
1405 /* Software abort outstanding PRLI before sending acc */
James Smart2e0fef82007-06-17 19:56:36 -05001406 lpfc_els_abort(vport->phba, ndlp);
dea31012005-04-17 16:05:31 -05001407
James Smart2e0fef82007-06-17 19:56:36 -05001408 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001409 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001410}
1411
1412static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001413lpfc_rcv_padisc_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1414 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001415{
James Smart2e0fef82007-06-17 19:56:36 -05001416 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001417
James Smart2e0fef82007-06-17 19:56:36 -05001418 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001419 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001420}
1421
1422/* This routine is envoked when we rcv a PRLO request from a nport
1423 * we are logged into. We should send back a PRLO rsp setting the
1424 * appropriate bits.
1425 * NEXT STATE = PRLI_ISSUE
1426 */
1427static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001428lpfc_rcv_prlo_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1429 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001430{
James Smart2e0fef82007-06-17 19:56:36 -05001431 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001432
James Smart51ef4c22007-08-02 11:10:31 -04001433 lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001434 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001435}
1436
1437static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001438lpfc_cmpl_prli_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1439 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001440{
James Smart92d7f7b2007-06-17 19:56:38 -05001441 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001442 struct lpfc_iocbq *cmdiocb, *rspiocb;
James Smart2e0fef82007-06-17 19:56:36 -05001443 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001444 IOCB_t *irsp;
1445 PRLI *npr;
1446
1447 cmdiocb = (struct lpfc_iocbq *) arg;
1448 rspiocb = cmdiocb->context_un.rsp_iocb;
1449 npr = (PRLI *)lpfc_check_elscmpl_iocb(phba, cmdiocb, rspiocb);
1450
1451 irsp = &rspiocb->iocb;
1452 if (irsp->ulpStatus) {
James Smart858c9f62007-06-17 19:56:39 -05001453 if ((vport->port_type == LPFC_NPIV_PORT) &&
James Smart3de2a652007-08-02 11:09:59 -04001454 vport->cfg_restrict_login) {
James Smart858c9f62007-06-17 19:56:39 -05001455 goto out;
1456 }
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001457 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -05001458 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001459 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001460 }
1461
1462 /* Check out PRLI rsp */
1463 ndlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR);
1464 ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
1465 if ((npr->acceptRspCode == PRLI_REQ_EXECUTED) &&
1466 (npr->prliType == PRLI_FCP_TYPE)) {
1467 if (npr->initiatorFunc)
1468 ndlp->nlp_type |= NLP_FCP_INITIATOR;
1469 if (npr->targetFunc)
1470 ndlp->nlp_type |= NLP_FCP_TARGET;
1471 if (npr->Retry)
1472 ndlp->nlp_fcp_info |= NLP_FCP_2_DEVICE;
1473 }
James Smart92d7f7b2007-06-17 19:56:38 -05001474 if (!(ndlp->nlp_type & NLP_FCP_TARGET) &&
1475 (vport->port_type == LPFC_NPIV_PORT) &&
James Smart3de2a652007-08-02 11:09:59 -04001476 vport->cfg_restrict_login) {
James Smart858c9f62007-06-17 19:56:39 -05001477out:
James Smart92d7f7b2007-06-17 19:56:38 -05001478 spin_lock_irq(shost->host_lock);
1479 ndlp->nlp_flag |= NLP_TARGET_REMOVE;
1480 spin_unlock_irq(shost->host_lock);
1481 lpfc_issue_els_logo(vport, ndlp, 0);
1482
1483 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
James Smart87af33f2007-10-27 13:37:43 -04001484 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
James Smart92d7f7b2007-06-17 19:56:38 -05001485 return ndlp->nlp_state;
1486 }
dea31012005-04-17 16:05:31 -05001487
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001488 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
James Smart92d7f7b2007-06-17 19:56:38 -05001489 if (ndlp->nlp_type & NLP_FCP_TARGET)
1490 lpfc_nlp_set_state(vport, ndlp, NLP_STE_MAPPED_NODE);
1491 else
1492 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001493 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001494}
1495
1496/*! lpfc_device_rm_prli_issue
James Smart92d7f7b2007-06-17 19:56:38 -05001497 *
1498 * \pre
1499 * \post
1500 * \param phba
1501 * \param ndlp
1502 * \param arg
1503 * \param evt
1504 * \return uint32_t
1505 *
1506 * \b Description:
1507 * This routine is envoked when we a request to remove a nport we are in the
1508 * process of PRLIing. We should software abort outstanding prli, unreg
1509 * login, send a logout. We will change node state to UNUSED_NODE, put it
1510 * on plogi list so it can be freed when LOGO completes.
1511 *
1512 */
1513
dea31012005-04-17 16:05:31 -05001514static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001515lpfc_device_rm_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1516 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001517{
James Smart2e0fef82007-06-17 19:56:36 -05001518 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001519
James Smart2e0fef82007-06-17 19:56:36 -05001520 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1521 spin_lock_irq(shost->host_lock);
1522 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
1523 spin_unlock_irq(shost->host_lock);
1524 return ndlp->nlp_state;
1525 } else {
1526 /* software abort outstanding PLOGI */
1527 lpfc_els_abort(vport->phba, ndlp);
1528
1529 lpfc_drop_node(vport, ndlp);
James Smarta0f9b482006-04-15 11:52:56 -04001530 return NLP_STE_FREED_NODE;
1531 }
dea31012005-04-17 16:05:31 -05001532}
1533
1534
1535/*! lpfc_device_recov_prli_issue
James Smart92d7f7b2007-06-17 19:56:38 -05001536 *
1537 * \pre
1538 * \post
1539 * \param phba
1540 * \param ndlp
1541 * \param arg
1542 * \param evt
1543 * \return uint32_t
1544 *
1545 * \b Description:
1546 * The routine is envoked when the state of a device is unknown, like
1547 * during a link down. We should remove the nodelist entry from the
1548 * unmapped list, issue a UNREG_LOGIN, do a software abort of the
1549 * outstanding PRLI command, then free the node entry.
1550 */
dea31012005-04-17 16:05:31 -05001551static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001552lpfc_device_recov_prli_issue(struct lpfc_vport *vport,
1553 struct lpfc_nodelist *ndlp,
1554 void *arg,
1555 uint32_t evt)
dea31012005-04-17 16:05:31 -05001556{
James Smart2e0fef82007-06-17 19:56:36 -05001557 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1558 struct lpfc_hba *phba = vport->phba;
1559
James Smart92d7f7b2007-06-17 19:56:38 -05001560 /* Don't do anything that will mess up processing of the
1561 * previous RSCN.
1562 */
1563 if (vport->fc_flag & FC_RSCN_DEFERRED)
1564 return ndlp->nlp_state;
1565
dea31012005-04-17 16:05:31 -05001566 /* software abort outstanding PRLI */
James Smart07951072007-04-25 09:51:38 -04001567 lpfc_els_abort(phba, ndlp);
dea31012005-04-17 16:05:31 -05001568
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001569 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -05001570 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1571 spin_lock_irq(shost->host_lock);
James Smarta0f9b482006-04-15 11:52:56 -04001572 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
James Smart2e0fef82007-06-17 19:56:36 -05001573 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05001574 lpfc_disc_set_adisc(vport, ndlp);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001575 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001576}
1577
1578static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001579lpfc_rcv_plogi_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1580 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001581{
James Smart2e0fef82007-06-17 19:56:36 -05001582 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001583
James Smart2e0fef82007-06-17 19:56:36 -05001584 lpfc_rcv_plogi(vport, ndlp, cmdiocb);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001585 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001586}
1587
1588static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001589lpfc_rcv_prli_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1590 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001591{
James Smart2e0fef82007-06-17 19:56:36 -05001592 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001593
James Smart2e0fef82007-06-17 19:56:36 -05001594 lpfc_rcv_prli(vport, ndlp, cmdiocb);
1595 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001596 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001597}
1598
1599static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001600lpfc_rcv_logo_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1601 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001602{
James Smart2e0fef82007-06-17 19:56:36 -05001603 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001604
James Smart2e0fef82007-06-17 19:56:36 -05001605 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001606 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001607}
1608
1609static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001610lpfc_rcv_padisc_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1611 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001612{
James Smart2e0fef82007-06-17 19:56:36 -05001613 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001614
James Smart2e0fef82007-06-17 19:56:36 -05001615 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001616 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001617}
1618
1619static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001620lpfc_rcv_prlo_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1621 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001622{
James Smart2e0fef82007-06-17 19:56:36 -05001623 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001624
James Smart51ef4c22007-08-02 11:10:31 -04001625 lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001626 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001627}
1628
1629static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001630lpfc_device_recov_unmap_node(struct lpfc_vport *vport,
1631 struct lpfc_nodelist *ndlp,
1632 void *arg,
1633 uint32_t evt)
dea31012005-04-17 16:05:31 -05001634{
James Smart2e0fef82007-06-17 19:56:36 -05001635 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1636
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001637 ndlp->nlp_prev_state = NLP_STE_UNMAPPED_NODE;
James Smart2e0fef82007-06-17 19:56:36 -05001638 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1639 spin_lock_irq(shost->host_lock);
James Smarta0f9b482006-04-15 11:52:56 -04001640 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
James Smart2e0fef82007-06-17 19:56:36 -05001641 spin_unlock_irq(shost->host_lock);
1642 lpfc_disc_set_adisc(vport, ndlp);
dea31012005-04-17 16:05:31 -05001643
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001644 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001645}
1646
1647static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001648lpfc_rcv_plogi_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1649 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001650{
James Smart2e0fef82007-06-17 19:56:36 -05001651 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001652
James Smart2e0fef82007-06-17 19:56:36 -05001653 lpfc_rcv_plogi(vport, ndlp, cmdiocb);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001654 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001655}
1656
1657static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001658lpfc_rcv_prli_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1659 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001660{
James Smart2e0fef82007-06-17 19:56:36 -05001661 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001662
James Smart2e0fef82007-06-17 19:56:36 -05001663 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001664 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001665}
1666
1667static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001668lpfc_rcv_logo_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1669 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001670{
James Smart2e0fef82007-06-17 19:56:36 -05001671 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001672
James Smart2e0fef82007-06-17 19:56:36 -05001673 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001674 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001675}
1676
1677static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001678lpfc_rcv_padisc_mapped_node(struct lpfc_vport *vport,
1679 struct lpfc_nodelist *ndlp,
1680 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001681{
James Smart2e0fef82007-06-17 19:56:36 -05001682 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001683
James Smart2e0fef82007-06-17 19:56:36 -05001684 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001685 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001686}
1687
1688static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001689lpfc_rcv_prlo_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1690 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001691{
James Smart2e0fef82007-06-17 19:56:36 -05001692 struct lpfc_hba *phba = vport->phba;
1693 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001694
1695 /* flush the target */
James Smart51ef4c22007-08-02 11:10:31 -04001696 lpfc_sli_abort_iocb(vport, &phba->sli.ring[phba->sli.fcp_ring],
1697 ndlp->nlp_sid, 0, LPFC_CTX_TGT);
dea31012005-04-17 16:05:31 -05001698
1699 /* Treat like rcv logo */
James Smart2e0fef82007-06-17 19:56:36 -05001700 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_PRLO);
Jamie Wellnitzc9f8735b2006-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_device_recov_mapped_node(struct lpfc_vport *vport,
1706 struct lpfc_nodelist *ndlp,
1707 void *arg,
1708 uint32_t evt)
dea31012005-04-17 16:05:31 -05001709{
James Smart2e0fef82007-06-17 19:56:36 -05001710 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1711
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001712 ndlp->nlp_prev_state = NLP_STE_MAPPED_NODE;
James Smart2e0fef82007-06-17 19:56:36 -05001713 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1714 spin_lock_irq(shost->host_lock);
James Smarta0f9b482006-04-15 11:52:56 -04001715 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
James Smart2e0fef82007-06-17 19:56:36 -05001716 spin_unlock_irq(shost->host_lock);
1717 lpfc_disc_set_adisc(vport, ndlp);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001718 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001719}
1720
1721static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001722lpfc_rcv_plogi_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1723 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001724{
James Smart2e0fef82007-06-17 19:56:36 -05001725 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1726 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001727
1728 /* Ignore PLOGI if we have an outstanding LOGO */
James Smart0d2b6b82008-06-14 22:52:47 -04001729 if (ndlp->nlp_flag & (NLP_LOGO_SND | NLP_LOGO_ACC))
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001730 return ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05001731 if (lpfc_rcv_plogi(vport, ndlp, cmdiocb)) {
James Smart0d2b6b82008-06-14 22:52:47 -04001732 lpfc_cancel_retry_delay_tmo(vport, ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05001733 spin_lock_irq(shost->host_lock);
James Smart0d2b6b82008-06-14 22:52:47 -04001734 ndlp->nlp_flag &= ~(NLP_NPR_ADISC | NLP_NPR_2B_DISC);
James Smart2e0fef82007-06-17 19:56:36 -05001735 spin_unlock_irq(shost->host_lock);
James Smart0d2b6b82008-06-14 22:52:47 -04001736 } else if (!(ndlp->nlp_flag & NLP_NPR_2B_DISC)) {
1737 /* send PLOGI immediately, move to PLOGI issue state */
1738 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
1739 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
1740 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
1741 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
1742 }
dea31012005-04-17 16:05:31 -05001743 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001744 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001745}
1746
1747static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001748lpfc_rcv_prli_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1749 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001750{
James Smart2e0fef82007-06-17 19:56:36 -05001751 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1752 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1753 struct ls_rjt stat;
dea31012005-04-17 16:05:31 -05001754
1755 memset(&stat, 0, sizeof (struct ls_rjt));
1756 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
1757 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
James Smart858c9f62007-06-17 19:56:39 -05001758 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05001759
1760 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
1761 if (ndlp->nlp_flag & NLP_NPR_ADISC) {
James Smart2e0fef82007-06-17 19:56:36 -05001762 spin_lock_irq(shost->host_lock);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001763 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001764 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
James Smart2e0fef82007-06-17 19:56:36 -05001765 spin_unlock_irq(shost->host_lock);
1766 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
1767 lpfc_issue_els_adisc(vport, ndlp, 0);
dea31012005-04-17 16:05:31 -05001768 } else {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001769 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
James Smart2e0fef82007-06-17 19:56:36 -05001770 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
1771 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
dea31012005-04-17 16:05:31 -05001772 }
1773 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001774 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001775}
1776
1777static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001778lpfc_rcv_logo_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1779 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001780{
James Smart2e0fef82007-06-17 19:56:36 -05001781 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001782
James Smart2e0fef82007-06-17 19:56:36 -05001783 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001784 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001785}
1786
1787static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001788lpfc_rcv_padisc_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1789 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001790{
James Smart2e0fef82007-06-17 19:56:36 -05001791 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001792
James Smart2e0fef82007-06-17 19:56:36 -05001793 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
James Smart33ccf8d2006-08-17 11:57:58 -04001794 /*
1795 * Do not start discovery if discovery is about to start
1796 * or discovery in progress for this node. Starting discovery
1797 * here will affect the counting of discovery threads.
1798 */
James Smart2fb9bd82006-12-02 13:33:57 -05001799 if (!(ndlp->nlp_flag & NLP_DELAY_TMO) &&
James Smart92d7f7b2007-06-17 19:56:38 -05001800 !(ndlp->nlp_flag & NLP_NPR_2B_DISC)) {
dea31012005-04-17 16:05:31 -05001801 if (ndlp->nlp_flag & NLP_NPR_ADISC) {
James Smart92d7f7b2007-06-17 19:56:38 -05001802 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001803 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
James Smart2e0fef82007-06-17 19:56:36 -05001804 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
1805 lpfc_issue_els_adisc(vport, ndlp, 0);
dea31012005-04-17 16:05:31 -05001806 } else {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001807 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
James Smart2e0fef82007-06-17 19:56:36 -05001808 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
1809 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
dea31012005-04-17 16:05:31 -05001810 }
1811 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001812 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001813}
1814
1815static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001816lpfc_rcv_prlo_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1817 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001818{
James Smart2e0fef82007-06-17 19:56:36 -05001819 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1820 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001821
James Smart2e0fef82007-06-17 19:56:36 -05001822 spin_lock_irq(shost->host_lock);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001823 ndlp->nlp_flag |= NLP_LOGO_ACC;
James Smart2e0fef82007-06-17 19:56:36 -05001824 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001825
James Smart51ef4c22007-08-02 11:10:31 -04001826 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05001827
James Smart2e0fef82007-06-17 19:56:36 -05001828 if ((ndlp->nlp_flag & NLP_DELAY_TMO) == 0) {
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001829 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ * 1);
James Smart2e0fef82007-06-17 19:56:36 -05001830 spin_lock_irq(shost->host_lock);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001831 ndlp->nlp_flag |= NLP_DELAY_TMO;
1832 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
James Smart2e0fef82007-06-17 19:56:36 -05001833 spin_unlock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001834 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001835 } else {
James Smart2e0fef82007-06-17 19:56:36 -05001836 spin_lock_irq(shost->host_lock);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001837 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
James Smart2e0fef82007-06-17 19:56:36 -05001838 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001839 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001840 return ndlp->nlp_state;
1841}
dea31012005-04-17 16:05:31 -05001842
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001843static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001844lpfc_cmpl_plogi_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1845 void *arg, uint32_t evt)
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001846{
1847 struct lpfc_iocbq *cmdiocb, *rspiocb;
James Smarta0f9b482006-04-15 11:52:56 -04001848 IOCB_t *irsp;
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001849
1850 cmdiocb = (struct lpfc_iocbq *) arg;
1851 rspiocb = cmdiocb->context_un.rsp_iocb;
James Smarta0f9b482006-04-15 11:52:56 -04001852
1853 irsp = &rspiocb->iocb;
1854 if (irsp->ulpStatus) {
James Smarta8adb832007-10-27 13:37:53 -04001855 ndlp->nlp_flag |= NLP_DEFER_RM;
James Smarta0f9b482006-04-15 11:52:56 -04001856 return NLP_STE_FREED_NODE;
1857 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001858 return ndlp->nlp_state;
1859}
1860
1861static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001862lpfc_cmpl_prli_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1863 void *arg, uint32_t evt)
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001864{
1865 struct lpfc_iocbq *cmdiocb, *rspiocb;
James Smarta0f9b482006-04-15 11:52:56 -04001866 IOCB_t *irsp;
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001867
1868 cmdiocb = (struct lpfc_iocbq *) arg;
1869 rspiocb = cmdiocb->context_un.rsp_iocb;
James Smarta0f9b482006-04-15 11:52:56 -04001870
1871 irsp = &rspiocb->iocb;
1872 if (irsp->ulpStatus && (ndlp->nlp_flag & NLP_NODEV_REMOVE)) {
James Smart2e0fef82007-06-17 19:56:36 -05001873 lpfc_drop_node(vport, ndlp);
James Smarta0f9b482006-04-15 11:52:56 -04001874 return NLP_STE_FREED_NODE;
1875 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001876 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001877}
1878
1879static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001880lpfc_cmpl_logo_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1881 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001882{
James Smartd7c255b2008-08-24 21:50:00 -04001883 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1884 if (ndlp->nlp_DID == Fabric_DID) {
1885 spin_lock_irq(shost->host_lock);
1886 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
1887 spin_unlock_irq(shost->host_lock);
1888 }
James Smart2e0fef82007-06-17 19:56:36 -05001889 lpfc_unreg_rpi(vport, ndlp);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001890 return ndlp->nlp_state;
1891}
1892
1893static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001894lpfc_cmpl_adisc_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1895 void *arg, uint32_t evt)
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001896{
1897 struct lpfc_iocbq *cmdiocb, *rspiocb;
James Smarta0f9b482006-04-15 11:52:56 -04001898 IOCB_t *irsp;
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001899
1900 cmdiocb = (struct lpfc_iocbq *) arg;
1901 rspiocb = cmdiocb->context_un.rsp_iocb;
James Smarta0f9b482006-04-15 11:52:56 -04001902
1903 irsp = &rspiocb->iocb;
1904 if (irsp->ulpStatus && (ndlp->nlp_flag & NLP_NODEV_REMOVE)) {
James Smart2e0fef82007-06-17 19:56:36 -05001905 lpfc_drop_node(vport, ndlp);
James Smarta0f9b482006-04-15 11:52:56 -04001906 return NLP_STE_FREED_NODE;
1907 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001908 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001909}
1910
1911static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001912lpfc_cmpl_reglogin_npr_node(struct lpfc_vport *vport,
1913 struct lpfc_nodelist *ndlp,
1914 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001915{
James Smart2e0fef82007-06-17 19:56:36 -05001916 LPFC_MBOXQ_t *pmb = (LPFC_MBOXQ_t *) arg;
James Smart04c68492009-05-22 14:52:52 -04001917 MAILBOX_t *mb = &pmb->u.mb;
dea31012005-04-17 16:05:31 -05001918
James Smart04c68492009-05-22 14:52:52 -04001919 if (!mb->mbxStatus) {
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001920 ndlp->nlp_rpi = mb->un.varWords[0];
James Smart04c68492009-05-22 14:52:52 -04001921 ndlp->nlp_flag |= NLP_RPI_VALID;
1922 } else {
James Smarta0f9b482006-04-15 11:52:56 -04001923 if (ndlp->nlp_flag & NLP_NODEV_REMOVE) {
James Smart2e0fef82007-06-17 19:56:36 -05001924 lpfc_drop_node(vport, ndlp);
James Smarta0f9b482006-04-15 11:52:56 -04001925 return NLP_STE_FREED_NODE;
1926 }
1927 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001928 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001929}
1930
1931static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001932lpfc_device_rm_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1933 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001934{
James Smart2e0fef82007-06-17 19:56:36 -05001935 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1936
James Smarta0f9b482006-04-15 11:52:56 -04001937 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
James Smart2e0fef82007-06-17 19:56:36 -05001938 spin_lock_irq(shost->host_lock);
James Smarta0f9b482006-04-15 11:52:56 -04001939 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
James Smart2e0fef82007-06-17 19:56:36 -05001940 spin_unlock_irq(shost->host_lock);
James Smarta0f9b482006-04-15 11:52:56 -04001941 return ndlp->nlp_state;
1942 }
James Smart2e0fef82007-06-17 19:56:36 -05001943 lpfc_drop_node(vport, ndlp);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001944 return NLP_STE_FREED_NODE;
dea31012005-04-17 16:05:31 -05001945}
1946
1947static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001948lpfc_device_recov_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1949 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001950{
James Smart2e0fef82007-06-17 19:56:36 -05001951 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1952
James Smart92d7f7b2007-06-17 19:56:38 -05001953 /* Don't do anything that will mess up processing of the
1954 * previous RSCN.
1955 */
1956 if (vport->fc_flag & FC_RSCN_DEFERRED)
1957 return ndlp->nlp_state;
1958
James Smarteaf15d52008-12-04 22:39:29 -05001959 lpfc_cancel_retry_delay_tmo(vport, ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05001960 spin_lock_irq(shost->host_lock);
James Smarta0f9b482006-04-15 11:52:56 -04001961 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
James Smart2e0fef82007-06-17 19:56:36 -05001962 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001963 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001964}
1965
1966
1967/* This next section defines the NPort Discovery State Machine */
1968
1969/* There are 4 different double linked lists nodelist entries can reside on.
1970 * The plogi list and adisc list are used when Link Up discovery or RSCN
1971 * processing is needed. Each list holds the nodes that we will send PLOGI
1972 * or ADISC on. These lists will keep track of what nodes will be effected
1973 * by an RSCN, or a Link Up (Typically, all nodes are effected on Link Up).
1974 * The unmapped_list will contain all nodes that we have successfully logged
1975 * into at the Fibre Channel level. The mapped_list will contain all nodes
1976 * that are mapped FCP targets.
1977 */
1978/*
1979 * The bind list is a list of undiscovered (potentially non-existent) nodes
1980 * that we have saved binding information on. This information is used when
1981 * nodes transition from the unmapped to the mapped list.
1982 */
1983/* For UNUSED_NODE state, the node has just been allocated .
1984 * For PLOGI_ISSUE and REG_LOGIN_ISSUE, the node is on
1985 * the PLOGI list. For REG_LOGIN_COMPL, the node is taken off the PLOGI list
1986 * and put on the unmapped list. For ADISC processing, the node is taken off
1987 * the ADISC list and placed on either the mapped or unmapped list (depending
1988 * on its previous state). Once on the unmapped list, a PRLI is issued and the
1989 * state changed to PRLI_ISSUE. When the PRLI completion occurs, the state is
1990 * changed to UNMAPPED_NODE. If the completion indicates a mapped
1991 * node, the node is taken off the unmapped list. The binding list is checked
1992 * for a valid binding, or a binding is automatically assigned. If binding
1993 * assignment is unsuccessful, the node is left on the unmapped list. If
1994 * binding assignment is successful, the associated binding list entry (if
1995 * any) is removed, and the node is placed on the mapped list.
1996 */
1997/*
1998 * For a Link Down, all nodes on the ADISC, PLOGI, unmapped or mapped
James Smartc01f3202006-08-18 17:47:08 -04001999 * lists will receive a DEVICE_RECOVERY event. If the linkdown or devloss timers
dea31012005-04-17 16:05:31 -05002000 * expire, all effected nodes will receive a DEVICE_RM event.
2001 */
2002/*
2003 * For a Link Up or RSCN, all nodes will move from the mapped / unmapped lists
2004 * to either the ADISC or PLOGI list. After a Nameserver query or ALPA loopmap
2005 * check, additional nodes may be added or removed (via DEVICE_RM) to / from
2006 * the PLOGI or ADISC lists. Once the PLOGI and ADISC lists are populated,
2007 * we will first process the ADISC list. 32 entries are processed initially and
2008 * ADISC is initited for each one. Completions / Events for each node are
2009 * funnelled thru the state machine. As each node finishes ADISC processing, it
2010 * starts ADISC for any nodes waiting for ADISC processing. If no nodes are
2011 * waiting, and the ADISC list count is identically 0, then we are done. For
2012 * Link Up discovery, since all nodes on the PLOGI list are UNREG_LOGIN'ed, we
2013 * can issue a CLEAR_LA and reenable Link Events. Next we will process the PLOGI
2014 * list. 32 entries are processed initially and PLOGI is initited for each one.
2015 * Completions / Events for each node are funnelled thru the state machine. As
2016 * each node finishes PLOGI processing, it starts PLOGI for any nodes waiting
2017 * for PLOGI processing. If no nodes are waiting, and the PLOGI list count is
2018 * indentically 0, then we are done. We have now completed discovery / RSCN
2019 * handling. Upon completion, ALL nodes should be on either the mapped or
2020 * unmapped lists.
2021 */
2022
2023static uint32_t (*lpfc_disc_action[NLP_STE_MAX_STATE * NLP_EVT_MAX_EVENT])
James Smart2e0fef82007-06-17 19:56:36 -05002024 (struct lpfc_vport *, struct lpfc_nodelist *, void *, uint32_t) = {
dea31012005-04-17 16:05:31 -05002025 /* Action routine Event Current State */
2026 lpfc_rcv_plogi_unused_node, /* RCV_PLOGI UNUSED_NODE */
2027 lpfc_rcv_els_unused_node, /* RCV_PRLI */
2028 lpfc_rcv_logo_unused_node, /* RCV_LOGO */
2029 lpfc_rcv_els_unused_node, /* RCV_ADISC */
2030 lpfc_rcv_els_unused_node, /* RCV_PDISC */
2031 lpfc_rcv_els_unused_node, /* RCV_PRLO */
2032 lpfc_disc_illegal, /* CMPL_PLOGI */
2033 lpfc_disc_illegal, /* CMPL_PRLI */
2034 lpfc_cmpl_logo_unused_node, /* CMPL_LOGO */
2035 lpfc_disc_illegal, /* CMPL_ADISC */
2036 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2037 lpfc_device_rm_unused_node, /* DEVICE_RM */
2038 lpfc_disc_illegal, /* DEVICE_RECOVERY */
2039
2040 lpfc_rcv_plogi_plogi_issue, /* RCV_PLOGI PLOGI_ISSUE */
James Smart92d7f7b2007-06-17 19:56:38 -05002041 lpfc_rcv_prli_plogi_issue, /* RCV_PRLI */
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002042 lpfc_rcv_logo_plogi_issue, /* RCV_LOGO */
dea31012005-04-17 16:05:31 -05002043 lpfc_rcv_els_plogi_issue, /* RCV_ADISC */
2044 lpfc_rcv_els_plogi_issue, /* RCV_PDISC */
2045 lpfc_rcv_els_plogi_issue, /* RCV_PRLO */
2046 lpfc_cmpl_plogi_plogi_issue, /* CMPL_PLOGI */
2047 lpfc_disc_illegal, /* CMPL_PRLI */
James Smart0ff10d42008-01-11 01:52:36 -05002048 lpfc_cmpl_logo_plogi_issue, /* CMPL_LOGO */
dea31012005-04-17 16:05:31 -05002049 lpfc_disc_illegal, /* CMPL_ADISC */
James Smart0ff10d42008-01-11 01:52:36 -05002050 lpfc_cmpl_reglogin_plogi_issue,/* CMPL_REG_LOGIN */
dea31012005-04-17 16:05:31 -05002051 lpfc_device_rm_plogi_issue, /* DEVICE_RM */
2052 lpfc_device_recov_plogi_issue, /* DEVICE_RECOVERY */
2053
2054 lpfc_rcv_plogi_adisc_issue, /* RCV_PLOGI ADISC_ISSUE */
2055 lpfc_rcv_prli_adisc_issue, /* RCV_PRLI */
2056 lpfc_rcv_logo_adisc_issue, /* RCV_LOGO */
2057 lpfc_rcv_padisc_adisc_issue, /* RCV_ADISC */
2058 lpfc_rcv_padisc_adisc_issue, /* RCV_PDISC */
2059 lpfc_rcv_prlo_adisc_issue, /* RCV_PRLO */
2060 lpfc_disc_illegal, /* CMPL_PLOGI */
2061 lpfc_disc_illegal, /* CMPL_PRLI */
2062 lpfc_disc_illegal, /* CMPL_LOGO */
2063 lpfc_cmpl_adisc_adisc_issue, /* CMPL_ADISC */
2064 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2065 lpfc_device_rm_adisc_issue, /* DEVICE_RM */
2066 lpfc_device_recov_adisc_issue, /* DEVICE_RECOVERY */
2067
2068 lpfc_rcv_plogi_reglogin_issue, /* RCV_PLOGI REG_LOGIN_ISSUE */
2069 lpfc_rcv_prli_reglogin_issue, /* RCV_PLOGI */
2070 lpfc_rcv_logo_reglogin_issue, /* RCV_LOGO */
2071 lpfc_rcv_padisc_reglogin_issue, /* RCV_ADISC */
2072 lpfc_rcv_padisc_reglogin_issue, /* RCV_PDISC */
2073 lpfc_rcv_prlo_reglogin_issue, /* RCV_PRLO */
James Smart87af33f2007-10-27 13:37:43 -04002074 lpfc_cmpl_plogi_illegal, /* CMPL_PLOGI */
dea31012005-04-17 16:05:31 -05002075 lpfc_disc_illegal, /* CMPL_PRLI */
2076 lpfc_disc_illegal, /* CMPL_LOGO */
2077 lpfc_disc_illegal, /* CMPL_ADISC */
2078 lpfc_cmpl_reglogin_reglogin_issue,/* CMPL_REG_LOGIN */
2079 lpfc_device_rm_reglogin_issue, /* DEVICE_RM */
2080 lpfc_device_recov_reglogin_issue,/* DEVICE_RECOVERY */
2081
2082 lpfc_rcv_plogi_prli_issue, /* RCV_PLOGI PRLI_ISSUE */
2083 lpfc_rcv_prli_prli_issue, /* RCV_PRLI */
2084 lpfc_rcv_logo_prli_issue, /* RCV_LOGO */
2085 lpfc_rcv_padisc_prli_issue, /* RCV_ADISC */
2086 lpfc_rcv_padisc_prli_issue, /* RCV_PDISC */
2087 lpfc_rcv_prlo_prli_issue, /* RCV_PRLO */
James Smart87af33f2007-10-27 13:37:43 -04002088 lpfc_cmpl_plogi_illegal, /* CMPL_PLOGI */
dea31012005-04-17 16:05:31 -05002089 lpfc_cmpl_prli_prli_issue, /* CMPL_PRLI */
2090 lpfc_disc_illegal, /* CMPL_LOGO */
2091 lpfc_disc_illegal, /* CMPL_ADISC */
2092 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2093 lpfc_device_rm_prli_issue, /* DEVICE_RM */
2094 lpfc_device_recov_prli_issue, /* DEVICE_RECOVERY */
2095
2096 lpfc_rcv_plogi_unmap_node, /* RCV_PLOGI UNMAPPED_NODE */
2097 lpfc_rcv_prli_unmap_node, /* RCV_PRLI */
2098 lpfc_rcv_logo_unmap_node, /* RCV_LOGO */
2099 lpfc_rcv_padisc_unmap_node, /* RCV_ADISC */
2100 lpfc_rcv_padisc_unmap_node, /* RCV_PDISC */
2101 lpfc_rcv_prlo_unmap_node, /* RCV_PRLO */
2102 lpfc_disc_illegal, /* CMPL_PLOGI */
2103 lpfc_disc_illegal, /* CMPL_PRLI */
2104 lpfc_disc_illegal, /* CMPL_LOGO */
2105 lpfc_disc_illegal, /* CMPL_ADISC */
2106 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2107 lpfc_disc_illegal, /* DEVICE_RM */
2108 lpfc_device_recov_unmap_node, /* DEVICE_RECOVERY */
2109
2110 lpfc_rcv_plogi_mapped_node, /* RCV_PLOGI MAPPED_NODE */
2111 lpfc_rcv_prli_mapped_node, /* RCV_PRLI */
2112 lpfc_rcv_logo_mapped_node, /* RCV_LOGO */
2113 lpfc_rcv_padisc_mapped_node, /* RCV_ADISC */
2114 lpfc_rcv_padisc_mapped_node, /* RCV_PDISC */
2115 lpfc_rcv_prlo_mapped_node, /* RCV_PRLO */
2116 lpfc_disc_illegal, /* CMPL_PLOGI */
2117 lpfc_disc_illegal, /* CMPL_PRLI */
2118 lpfc_disc_illegal, /* CMPL_LOGO */
2119 lpfc_disc_illegal, /* CMPL_ADISC */
2120 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2121 lpfc_disc_illegal, /* DEVICE_RM */
2122 lpfc_device_recov_mapped_node, /* DEVICE_RECOVERY */
2123
2124 lpfc_rcv_plogi_npr_node, /* RCV_PLOGI NPR_NODE */
2125 lpfc_rcv_prli_npr_node, /* RCV_PRLI */
2126 lpfc_rcv_logo_npr_node, /* RCV_LOGO */
2127 lpfc_rcv_padisc_npr_node, /* RCV_ADISC */
2128 lpfc_rcv_padisc_npr_node, /* RCV_PDISC */
2129 lpfc_rcv_prlo_npr_node, /* RCV_PRLO */
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002130 lpfc_cmpl_plogi_npr_node, /* CMPL_PLOGI */
2131 lpfc_cmpl_prli_npr_node, /* CMPL_PRLI */
dea31012005-04-17 16:05:31 -05002132 lpfc_cmpl_logo_npr_node, /* CMPL_LOGO */
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002133 lpfc_cmpl_adisc_npr_node, /* CMPL_ADISC */
dea31012005-04-17 16:05:31 -05002134 lpfc_cmpl_reglogin_npr_node, /* CMPL_REG_LOGIN */
2135 lpfc_device_rm_npr_node, /* DEVICE_RM */
2136 lpfc_device_recov_npr_node, /* DEVICE_RECOVERY */
2137};
2138
2139int
James Smart2e0fef82007-06-17 19:56:36 -05002140lpfc_disc_state_machine(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2141 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05002142{
2143 uint32_t cur_state, rc;
James Smart2e0fef82007-06-17 19:56:36 -05002144 uint32_t(*func) (struct lpfc_vport *, struct lpfc_nodelist *, void *,
dea31012005-04-17 16:05:31 -05002145 uint32_t);
James Smarte47c9092008-02-08 18:49:26 -05002146 uint32_t got_ndlp = 0;
dea31012005-04-17 16:05:31 -05002147
James Smarte47c9092008-02-08 18:49:26 -05002148 if (lpfc_nlp_get(ndlp))
2149 got_ndlp = 1;
2150
dea31012005-04-17 16:05:31 -05002151 cur_state = ndlp->nlp_state;
2152
2153 /* DSM in event <evt> on NPort <nlp_DID> in state <cur_state> */
James Smarte8b62012007-08-02 11:10:09 -04002154 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2155 "0211 DSM in event x%x on NPort x%x in "
2156 "state %d Data: x%x\n",
2157 evt, ndlp->nlp_DID, cur_state, ndlp->nlp_flag);
dea31012005-04-17 16:05:31 -05002158
James Smart858c9f62007-06-17 19:56:39 -05002159 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_DSM,
2160 "DSM in: evt:%d ste:%d did:x%x",
2161 evt, cur_state, ndlp->nlp_DID);
2162
dea31012005-04-17 16:05:31 -05002163 func = lpfc_disc_action[(cur_state * NLP_EVT_MAX_EVENT) + evt];
James Smart2e0fef82007-06-17 19:56:36 -05002164 rc = (func) (vport, ndlp, arg, evt);
dea31012005-04-17 16:05:31 -05002165
2166 /* DSM out state <rc> on NPort <nlp_DID> */
James Smarte47c9092008-02-08 18:49:26 -05002167 if (got_ndlp) {
2168 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
James Smarte8b62012007-08-02 11:10:09 -04002169 "0212 DSM out state %d on NPort x%x Data: x%x\n",
2170 rc, ndlp->nlp_DID, ndlp->nlp_flag);
dea31012005-04-17 16:05:31 -05002171
James Smarte47c9092008-02-08 18:49:26 -05002172 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_DSM,
2173 "DSM out: ste:%d did:x%x flg:x%x",
2174 rc, ndlp->nlp_DID, ndlp->nlp_flag);
2175 /* Decrement the ndlp reference count held for this function */
2176 lpfc_nlp_put(ndlp);
2177 } else {
2178 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
James Smartd7c255b2008-08-24 21:50:00 -04002179 "0213 DSM out state %d on NPort free\n", rc);
James Smart858c9f62007-06-17 19:56:39 -05002180
James Smarte47c9092008-02-08 18:49:26 -05002181 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_DSM,
2182 "DSM out: ste:%d did:x%x flg:x%x",
2183 rc, 0, 0);
2184 }
dea31012005-04-17 16:05:31 -05002185
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002186 return rc;
dea31012005-04-17 16:05:31 -05002187}