blob: 83ffa75378e55fb8f851baacf6cdf6bc82fc7a31 [file] [log] [blame]
James Smart92d7f7b2007-06-17 19:56:38 -05001 /*******************************************************************
dea31012005-04-17 16:05:31 -05002 * This file is part of the Emulex Linux Device Driver for *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04003 * Fibre Channel Host Bus Adapters. *
James Smarte47c9092008-02-08 18:49:26 -05004 * Copyright (C) 2004-2008 Emulex. All rights reserved. *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04005 * EMULEX and SLI are trademarks of Emulex. *
dea31012005-04-17 16:05:31 -05006 * www.emulex.com *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04007 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
dea31012005-04-17 16:05:31 -05008 * *
9 * This program is free software; you can redistribute it and/or *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -040010 * modify it under the terms of version 2 of the GNU General *
11 * Public License as published by the Free Software Foundation. *
12 * This program is distributed in the hope that it will be useful. *
13 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
14 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
15 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
16 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
17 * TO BE LEGALLY INVALID. See the GNU General Public License for *
18 * more details, a copy of which can be found in the file COPYING *
19 * included with this package. *
dea31012005-04-17 16:05:31 -050020 *******************************************************************/
21
dea31012005-04-17 16:05:31 -050022#include <linux/blkdev.h>
23#include <linux/pci.h>
24#include <linux/interrupt.h>
25
James.Smart@Emulex.Com91886522005-08-10 15:03:09 -040026#include <scsi/scsi.h>
dea31012005-04-17 16:05:31 -050027#include <scsi/scsi_device.h>
28#include <scsi/scsi_host.h>
29#include <scsi/scsi_transport_fc.h>
30
31#include "lpfc_hw.h"
32#include "lpfc_sli.h"
33#include "lpfc_disc.h"
34#include "lpfc_scsi.h"
35#include "lpfc.h"
36#include "lpfc_logmsg.h"
37#include "lpfc_crtn.h"
James Smart92d7f7b2007-06-17 19:56:38 -050038#include "lpfc_vport.h"
James Smart858c9f62007-06-17 19:56:39 -050039#include "lpfc_debugfs.h"
dea31012005-04-17 16:05:31 -050040
41
42/* Called to verify a rcv'ed ADISC was intended for us. */
43static int
James Smart2e0fef82007-06-17 19:56:36 -050044lpfc_check_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
45 struct lpfc_name *nn, struct lpfc_name *pn)
dea31012005-04-17 16:05:31 -050046{
47 /* Compare the ADISC rsp WWNN / WWPN matches our internal node
48 * table entry for that node.
49 */
James Smart2e0fef82007-06-17 19:56:36 -050050 if (memcmp(nn, &ndlp->nlp_nodename, sizeof (struct lpfc_name)))
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -050051 return 0;
dea31012005-04-17 16:05:31 -050052
James Smart2e0fef82007-06-17 19:56:36 -050053 if (memcmp(pn, &ndlp->nlp_portname, sizeof (struct lpfc_name)))
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -050054 return 0;
dea31012005-04-17 16:05:31 -050055
56 /* we match, return success */
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -050057 return 1;
dea31012005-04-17 16:05:31 -050058}
59
dea31012005-04-17 16:05:31 -050060int
James Smart2e0fef82007-06-17 19:56:36 -050061lpfc_check_sparm(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
62 struct serv_parm * sp, uint32_t class)
dea31012005-04-17 16:05:31 -050063{
James Smart2e0fef82007-06-17 19:56:36 -050064 volatile struct serv_parm *hsp = &vport->fc_sparam;
James.Smart@Emulex.Com2fb70f72005-11-28 11:41:24 -050065 uint16_t hsp_value, ssp_value = 0;
dea31012005-04-17 16:05:31 -050066
James.Smart@Emulex.Com2fb70f72005-11-28 11:41:24 -050067 /*
68 * The receive data field size and buffer-to-buffer receive data field
69 * size entries are 16 bits but are represented as two 8-bit fields in
70 * the driver data structure to account for rsvd bits and other control
71 * bits. Reconstruct and compare the fields as a 16-bit values before
72 * correcting the byte values.
73 */
dea31012005-04-17 16:05:31 -050074 if (sp->cls1.classValid) {
James.Smart@Emulex.Com2fb70f72005-11-28 11:41:24 -050075 hsp_value = (hsp->cls1.rcvDataSizeMsb << 8) |
76 hsp->cls1.rcvDataSizeLsb;
77 ssp_value = (sp->cls1.rcvDataSizeMsb << 8) |
78 sp->cls1.rcvDataSizeLsb;
James Smart92d7f7b2007-06-17 19:56:38 -050079 if (!ssp_value)
80 goto bad_service_param;
James.Smart@Emulex.Com2fb70f72005-11-28 11:41:24 -050081 if (ssp_value > hsp_value) {
dea31012005-04-17 16:05:31 -050082 sp->cls1.rcvDataSizeLsb = hsp->cls1.rcvDataSizeLsb;
James.Smart@Emulex.Com2fb70f72005-11-28 11:41:24 -050083 sp->cls1.rcvDataSizeMsb = hsp->cls1.rcvDataSizeMsb;
84 }
dea31012005-04-17 16:05:31 -050085 } else if (class == CLASS1) {
James Smart92d7f7b2007-06-17 19:56:38 -050086 goto bad_service_param;
dea31012005-04-17 16:05:31 -050087 }
88
89 if (sp->cls2.classValid) {
James.Smart@Emulex.Com2fb70f72005-11-28 11:41:24 -050090 hsp_value = (hsp->cls2.rcvDataSizeMsb << 8) |
91 hsp->cls2.rcvDataSizeLsb;
92 ssp_value = (sp->cls2.rcvDataSizeMsb << 8) |
93 sp->cls2.rcvDataSizeLsb;
James Smart92d7f7b2007-06-17 19:56:38 -050094 if (!ssp_value)
95 goto bad_service_param;
James.Smart@Emulex.Com2fb70f72005-11-28 11:41:24 -050096 if (ssp_value > hsp_value) {
dea31012005-04-17 16:05:31 -050097 sp->cls2.rcvDataSizeLsb = hsp->cls2.rcvDataSizeLsb;
James.Smart@Emulex.Com2fb70f72005-11-28 11:41:24 -050098 sp->cls2.rcvDataSizeMsb = hsp->cls2.rcvDataSizeMsb;
99 }
dea31012005-04-17 16:05:31 -0500100 } else if (class == CLASS2) {
James Smart92d7f7b2007-06-17 19:56:38 -0500101 goto bad_service_param;
dea31012005-04-17 16:05:31 -0500102 }
103
104 if (sp->cls3.classValid) {
James.Smart@Emulex.Com2fb70f72005-11-28 11:41:24 -0500105 hsp_value = (hsp->cls3.rcvDataSizeMsb << 8) |
106 hsp->cls3.rcvDataSizeLsb;
107 ssp_value = (sp->cls3.rcvDataSizeMsb << 8) |
108 sp->cls3.rcvDataSizeLsb;
James Smart92d7f7b2007-06-17 19:56:38 -0500109 if (!ssp_value)
110 goto bad_service_param;
James.Smart@Emulex.Com2fb70f72005-11-28 11:41:24 -0500111 if (ssp_value > hsp_value) {
dea31012005-04-17 16:05:31 -0500112 sp->cls3.rcvDataSizeLsb = hsp->cls3.rcvDataSizeLsb;
James.Smart@Emulex.Com2fb70f72005-11-28 11:41:24 -0500113 sp->cls3.rcvDataSizeMsb = hsp->cls3.rcvDataSizeMsb;
114 }
dea31012005-04-17 16:05:31 -0500115 } else if (class == CLASS3) {
James Smart92d7f7b2007-06-17 19:56:38 -0500116 goto bad_service_param;
dea31012005-04-17 16:05:31 -0500117 }
118
James.Smart@Emulex.Com2fb70f72005-11-28 11:41:24 -0500119 /*
120 * Preserve the upper four bits of the MSB from the PLOGI response.
121 * These bits contain the Buffer-to-Buffer State Change Number
122 * from the target and need to be passed to the FW.
123 */
124 hsp_value = (hsp->cmn.bbRcvSizeMsb << 8) | hsp->cmn.bbRcvSizeLsb;
125 ssp_value = (sp->cmn.bbRcvSizeMsb << 8) | sp->cmn.bbRcvSizeLsb;
126 if (ssp_value > hsp_value) {
dea31012005-04-17 16:05:31 -0500127 sp->cmn.bbRcvSizeLsb = hsp->cmn.bbRcvSizeLsb;
James.Smart@Emulex.Com2fb70f72005-11-28 11:41:24 -0500128 sp->cmn.bbRcvSizeMsb = (sp->cmn.bbRcvSizeMsb & 0xF0) |
129 (hsp->cmn.bbRcvSizeMsb & 0x0F);
130 }
dea31012005-04-17 16:05:31 -0500131
dea31012005-04-17 16:05:31 -0500132 memcpy(&ndlp->nlp_nodename, &sp->nodeName, sizeof (struct lpfc_name));
133 memcpy(&ndlp->nlp_portname, &sp->portName, sizeof (struct lpfc_name));
James.Smart@Emulex.Com2fb70f72005-11-28 11:41:24 -0500134 return 1;
James Smart92d7f7b2007-06-17 19:56:38 -0500135bad_service_param:
James Smarte8b62012007-08-02 11:10:09 -0400136 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
137 "0207 Device %x "
138 "(%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x) sent "
139 "invalid service parameters. Ignoring device.\n",
140 ndlp->nlp_DID,
141 sp->nodeName.u.wwn[0], sp->nodeName.u.wwn[1],
142 sp->nodeName.u.wwn[2], sp->nodeName.u.wwn[3],
143 sp->nodeName.u.wwn[4], sp->nodeName.u.wwn[5],
144 sp->nodeName.u.wwn[6], sp->nodeName.u.wwn[7]);
James Smart92d7f7b2007-06-17 19:56:38 -0500145 return 0;
dea31012005-04-17 16:05:31 -0500146}
147
148static void *
James Smart2e0fef82007-06-17 19:56:36 -0500149lpfc_check_elscmpl_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -0500150 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -0500151{
152 struct lpfc_dmabuf *pcmd, *prsp;
153 uint32_t *lp;
154 void *ptr = NULL;
155 IOCB_t *irsp;
156
157 irsp = &rspiocb->iocb;
158 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
159
160 /* For lpfc_els_abort, context2 could be zero'ed to delay
161 * freeing associated memory till after ABTS completes.
162 */
163 if (pcmd) {
164 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf,
165 list);
166 if (prsp) {
167 lp = (uint32_t *) prsp->virt;
168 ptr = (void *)((uint8_t *)lp + sizeof(uint32_t));
169 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500170 } else {
dea31012005-04-17 16:05:31 -0500171 /* Force ulpStatus error since we are returning NULL ptr */
172 if (!(irsp->ulpStatus)) {
173 irsp->ulpStatus = IOSTAT_LOCAL_REJECT;
174 irsp->un.ulpWord[4] = IOERR_SLI_ABORTED;
175 }
176 ptr = NULL;
177 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -0500178 return ptr;
dea31012005-04-17 16:05:31 -0500179}
180
181
182/*
183 * Free resources / clean up outstanding I/Os
184 * associated with a LPFC_NODELIST entry. This
185 * routine effectively results in a "software abort".
186 */
187int
James Smart2e0fef82007-06-17 19:56:36 -0500188lpfc_els_abort(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -0500189{
James Smart2534ba72007-04-25 09:52:20 -0400190 LIST_HEAD(completions);
James Smart2e0fef82007-06-17 19:56:36 -0500191 struct lpfc_sli *psli = &phba->sli;
192 struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING];
dea31012005-04-17 16:05:31 -0500193 struct lpfc_iocbq *iocb, *next_iocb;
James Smart2534ba72007-04-25 09:52:20 -0400194 IOCB_t *cmd;
dea31012005-04-17 16:05:31 -0500195
196 /* Abort outstanding I/O on NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -0400197 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_DISCOVERY,
198 "0205 Abort outstanding I/O on NPort x%x "
199 "Data: x%x x%x x%x\n",
200 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
201 ndlp->nlp_rpi);
James Smart92d7f7b2007-06-17 19:56:38 -0500202
203 lpfc_fabric_abort_nport(ndlp);
dea31012005-04-17 16:05:31 -0500204
dea31012005-04-17 16:05:31 -0500205 /* First check the txq */
James Smart2e0fef82007-06-17 19:56:36 -0500206 spin_lock_irq(&phba->hbalock);
James Smart2534ba72007-04-25 09:52:20 -0400207 list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
James Smart858c9f62007-06-17 19:56:39 -0500208 /* Check to see if iocb matches the nport we are looking for */
James Smart2534ba72007-04-25 09:52:20 -0400209 if (lpfc_check_sli_ndlp(phba, pring, iocb, ndlp)) {
James Smart858c9f62007-06-17 19:56:39 -0500210 /* It matches, so deque and call compl with anp error */
James Smart2534ba72007-04-25 09:52:20 -0400211 list_move_tail(&iocb->list, &completions);
212 pring->txq_cnt--;
dea31012005-04-17 16:05:31 -0500213 }
James Smart2534ba72007-04-25 09:52:20 -0400214 }
dea31012005-04-17 16:05:31 -0500215
dea31012005-04-17 16:05:31 -0500216 /* Next check the txcmplq */
James Smart07951072007-04-25 09:51:38 -0400217 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
James Smart858c9f62007-06-17 19:56:39 -0500218 /* Check to see if iocb matches the nport we are looking for */
James Smart92d7f7b2007-06-17 19:56:38 -0500219 if (lpfc_check_sli_ndlp(phba, pring, iocb, ndlp)) {
James Smart07951072007-04-25 09:51:38 -0400220 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
James Smart92d7f7b2007-06-17 19:56:38 -0500221 }
James Smart07951072007-04-25 09:51:38 -0400222 }
James Smart2e0fef82007-06-17 19:56:36 -0500223 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500224
James Smart2534ba72007-04-25 09:52:20 -0400225 while (!list_empty(&completions)) {
226 iocb = list_get_first(&completions, struct lpfc_iocbq, list);
227 cmd = &iocb->iocb;
James Smart92d7f7b2007-06-17 19:56:38 -0500228 list_del_init(&iocb->list);
James Smart2534ba72007-04-25 09:52:20 -0400229
James Smart2e0fef82007-06-17 19:56:36 -0500230 if (!iocb->iocb_cmpl)
231 lpfc_sli_release_iocbq(phba, iocb);
232 else {
James Smart2534ba72007-04-25 09:52:20 -0400233 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
234 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
235 (iocb->iocb_cmpl) (phba, iocb, iocb);
James Smart2e0fef82007-06-17 19:56:36 -0500236 }
James Smart2534ba72007-04-25 09:52:20 -0400237 }
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 Smart2e0fef82007-06-17 19:56:36 -0500257 if (vport->port_state <= LPFC_FLOGI) {
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 Smart2e0fef82007-06-17 19:56:36 -0500305 if ((lpfc_check_sparm(vport, ndlp, sp, CLASS3) == 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 Smart92d7f7b2007-06-17 19:56:38 -0500373 rc = lpfc_reg_login(phba, vport->vpi, icmd->un.rcvels.remoteID,
374 (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);
dea31012005-04-17 16:05:31 -0500507
James Smart0d2b6b82008-06-14 22:52:47 -0400508 if ((!(ndlp->nlp_type & NLP_FABRIC) &&
509 ((ndlp->nlp_type & NLP_FCP_TARGET) ||
510 !(ndlp->nlp_type & NLP_FCP_INITIATOR))) ||
James Smart92d7f7b2007-06-17 19:56:38 -0500511 (ndlp->nlp_state == NLP_STE_ADISC_ISSUE)) {
dea31012005-04-17 16:05:31 -0500512 /* Only try to re-login if this is NOT a Fabric Node */
dea31012005-04-17 16:05:31 -0500513 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ * 1);
James Smart2e0fef82007-06-17 19:56:36 -0500514 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500515 ndlp->nlp_flag |= NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -0500516 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -0500517
Jamie Wellnitz5024ab12006-02-28 19:25:28 -0500518 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
dea31012005-04-17 16:05:31 -0500519 }
James Smart87af33f2007-10-27 13:37:43 -0400520 ndlp->nlp_prev_state = ndlp->nlp_state;
521 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
dea31012005-04-17 16:05:31 -0500522
James Smart2e0fef82007-06-17 19:56:36 -0500523 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500524 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
James Smart2e0fef82007-06-17 19:56:36 -0500525 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500526 /* The driver has to wait until the ACC completes before it continues
527 * processing the LOGO. The action will resume in
528 * lpfc_cmpl_els_logo_acc routine. Since part of processing includes an
529 * unreg_login, the driver waits so the ACC does not get aborted.
530 */
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -0500531 return 0;
dea31012005-04-17 16:05:31 -0500532}
533
534static void
James Smart2e0fef82007-06-17 19:56:36 -0500535lpfc_rcv_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
536 struct lpfc_iocbq *cmdiocb)
dea31012005-04-17 16:05:31 -0500537{
538 struct lpfc_dmabuf *pcmd;
539 uint32_t *lp;
540 PRLI *npr;
541 struct fc_rport *rport = ndlp->rport;
542 u32 roles;
543
544 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
545 lp = (uint32_t *) pcmd->virt;
546 npr = (PRLI *) ((uint8_t *) lp + sizeof (uint32_t));
547
548 ndlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR);
549 ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
James Smart92d7f7b2007-06-17 19:56:38 -0500550 if (npr->prliType == PRLI_FCP_TYPE) {
dea31012005-04-17 16:05:31 -0500551 if (npr->initiatorFunc)
552 ndlp->nlp_type |= NLP_FCP_INITIATOR;
553 if (npr->targetFunc)
554 ndlp->nlp_type |= NLP_FCP_TARGET;
555 if (npr->Retry)
556 ndlp->nlp_fcp_info |= NLP_FCP_2_DEVICE;
557 }
558 if (rport) {
559 /* We need to update the rport role values */
560 roles = FC_RPORT_ROLE_UNKNOWN;
561 if (ndlp->nlp_type & NLP_FCP_INITIATOR)
562 roles |= FC_RPORT_ROLE_FCP_INITIATOR;
563 if (ndlp->nlp_type & NLP_FCP_TARGET)
564 roles |= FC_RPORT_ROLE_FCP_TARGET;
James Smart858c9f62007-06-17 19:56:39 -0500565
566 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
567 "rport rolechg: role:x%x did:x%x flg:x%x",
568 roles, ndlp->nlp_DID, ndlp->nlp_flag);
569
dea31012005-04-17 16:05:31 -0500570 fc_remote_port_rolechg(rport, roles);
571 }
572}
573
574static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -0500575lpfc_disc_set_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -0500576{
James Smart2e0fef82007-06-17 19:56:36 -0500577 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart2e0fef82007-06-17 19:56:36 -0500578
James Smart51ef4c22007-08-02 11:10:31 -0400579 if (!ndlp->nlp_rpi) {
580 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
581 return 0;
582 }
583
James Smart1b32f6a2008-02-08 18:49:39 -0500584 if (!(vport->fc_flag & FC_PT2PT)) {
585 /* Check config parameter use-adisc or FCP-2 */
586 if ((vport->cfg_use_adisc && (vport->fc_flag & FC_RSCN_MODE)) ||
587 ndlp->nlp_fcp_info & NLP_FCP_2_DEVICE) {
588 spin_lock_irq(shost->host_lock);
589 ndlp->nlp_flag |= NLP_NPR_ADISC;
590 spin_unlock_irq(shost->host_lock);
591 return 1;
592 }
James Smart92d7f7b2007-06-17 19:56:38 -0500593 }
594 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
595 lpfc_unreg_rpi(vport, ndlp);
596 return 0;
dea31012005-04-17 16:05:31 -0500597}
598
599static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -0500600lpfc_disc_illegal(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
601 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -0500602{
James Smarte8b62012007-08-02 11:10:09 -0400603 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
James Smarte47c9092008-02-08 18:49:26 -0500604 "0271 Illegal State Transition: node x%x "
James Smarte8b62012007-08-02 11:10:09 -0400605 "event x%x, state x%x Data: x%x x%x\n",
606 ndlp->nlp_DID, evt, ndlp->nlp_state, ndlp->nlp_rpi,
607 ndlp->nlp_flag);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -0500608 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -0500609}
610
James Smart87af33f2007-10-27 13:37:43 -0400611static uint32_t
612lpfc_cmpl_plogi_illegal(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
613 void *arg, uint32_t evt)
614{
615 /* This transition is only legal if we previously
616 * rcv'ed a PLOGI. Since we don't want 2 discovery threads
617 * working on the same NPortID, do nothing for this thread
618 * to stop it.
619 */
620 if (!(ndlp->nlp_flag & NLP_RCV_PLOGI)) {
621 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
James Smarte47c9092008-02-08 18:49:26 -0500622 "0272 Illegal State Transition: node x%x "
James Smart87af33f2007-10-27 13:37:43 -0400623 "event x%x, state x%x Data: x%x x%x\n",
624 ndlp->nlp_DID, evt, ndlp->nlp_state, ndlp->nlp_rpi,
625 ndlp->nlp_flag);
626 }
627 return ndlp->nlp_state;
628}
629
dea31012005-04-17 16:05:31 -0500630/* Start of Discovery State Machine routines */
631
632static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -0500633lpfc_rcv_plogi_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
634 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -0500635{
636 struct lpfc_iocbq *cmdiocb;
637
638 cmdiocb = (struct lpfc_iocbq *) arg;
639
James Smart2e0fef82007-06-17 19:56:36 -0500640 if (lpfc_rcv_plogi(vport, ndlp, cmdiocb)) {
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -0500641 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -0500642 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -0500643 return NLP_STE_FREED_NODE;
dea31012005-04-17 16:05:31 -0500644}
645
646static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -0500647lpfc_rcv_els_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
648 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -0500649{
James Smart2e0fef82007-06-17 19:56:36 -0500650 lpfc_issue_els_logo(vport, ndlp, 0);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -0500651 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -0500652}
653
654static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -0500655lpfc_rcv_logo_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 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
659 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -0500660
James Smart2e0fef82007-06-17 19:56:36 -0500661 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500662 ndlp->nlp_flag |= NLP_LOGO_ACC;
James Smart2e0fef82007-06-17 19:56:36 -0500663 spin_unlock_irq(shost->host_lock);
James Smart51ef4c22007-08-02 11:10:31 -0400664 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -0500665
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -0500666 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -0500667}
668
669static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -0500670lpfc_cmpl_logo_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -0500671 void *arg, uint32_t evt)
672{
James Smart2e0fef82007-06-17 19:56:36 -0500673 return NLP_STE_FREED_NODE;
674}
675
676static uint32_t
677lpfc_device_rm_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
678 void *arg, uint32_t evt)
679{
James Smart2e0fef82007-06-17 19:56:36 -0500680 return NLP_STE_FREED_NODE;
681}
682
683static uint32_t
684lpfc_rcv_plogi_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
685 void *arg, uint32_t evt)
686{
James Smart0d2b6b82008-06-14 22:52:47 -0400687 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart2e0fef82007-06-17 19:56:36 -0500688 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500689 struct lpfc_iocbq *cmdiocb = arg;
James Smart2e0fef82007-06-17 19:56:36 -0500690 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
691 uint32_t *lp = (uint32_t *) pcmd->virt;
692 struct serv_parm *sp = (struct serv_parm *) (lp + 1);
dea31012005-04-17 16:05:31 -0500693 struct ls_rjt stat;
694 int port_cmp;
695
dea31012005-04-17 16:05:31 -0500696 memset(&stat, 0, sizeof (struct ls_rjt));
697
698 /* For a PLOGI, we only accept if our portname is less
699 * than the remote portname.
700 */
701 phba->fc_stat.elsLogiCol++;
James Smart2e0fef82007-06-17 19:56:36 -0500702 port_cmp = memcmp(&vport->fc_portname, &sp->portName,
James Smart92d7f7b2007-06-17 19:56:38 -0500703 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -0500704
705 if (port_cmp >= 0) {
706 /* Reject this request because the remote node will accept
707 ours */
708 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
709 stat.un.b.lsRjtRsnCodeExp = LSEXP_CMD_IN_PROGRESS;
James Smart858c9f62007-06-17 19:56:39 -0500710 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
711 NULL);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500712 } else {
James Smart0d2b6b82008-06-14 22:52:47 -0400713 if (lpfc_rcv_plogi(vport, ndlp, cmdiocb) &&
714 (ndlp->nlp_flag & NLP_NPR_2B_DISC) &&
715 (vport->num_disc_nodes)) {
716 spin_lock_irq(shost->host_lock);
717 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
718 spin_unlock_irq(shost->host_lock);
719 /* Check if there are more PLOGIs to be sent */
720 lpfc_more_plogi(vport);
721 if (vport->num_disc_nodes == 0) {
722 spin_lock_irq(shost->host_lock);
723 vport->fc_flag &= ~FC_NDISC_ACTIVE;
724 spin_unlock_irq(shost->host_lock);
725 lpfc_can_disctmo(vport);
726 lpfc_end_rscn(vport);
727 }
728 }
James Smart2e0fef82007-06-17 19:56:36 -0500729 } /* If our portname was less */
dea31012005-04-17 16:05:31 -0500730
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -0500731 return ndlp->nlp_state;
732}
733
734static uint32_t
James Smart92d7f7b2007-06-17 19:56:38 -0500735lpfc_rcv_prli_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
736 void *arg, uint32_t evt)
737{
738 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
739 struct ls_rjt stat;
740
741 memset(&stat, 0, sizeof (struct ls_rjt));
742 stat.un.b.lsRjtRsnCode = LSRJT_LOGICAL_BSY;
743 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
James Smart858c9f62007-06-17 19:56:39 -0500744 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
James Smart92d7f7b2007-06-17 19:56:38 -0500745 return ndlp->nlp_state;
746}
747
748static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -0500749lpfc_rcv_logo_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
750 void *arg, uint32_t evt)
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -0500751{
James Smart2e0fef82007-06-17 19:56:36 -0500752 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -0500753
James Smart92d7f7b2007-06-17 19:56:38 -0500754 /* software abort outstanding PLOGI */
James Smart2e0fef82007-06-17 19:56:36 -0500755 lpfc_els_abort(vport->phba, ndlp);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -0500756
James Smart2e0fef82007-06-17 19:56:36 -0500757 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -0500758 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -0500759}
760
761static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -0500762lpfc_rcv_els_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
763 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -0500764{
James Smart2e0fef82007-06-17 19:56:36 -0500765 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
766 struct lpfc_hba *phba = vport->phba;
767 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -0500768
769 /* software abort outstanding PLOGI */
James Smart07951072007-04-25 09:51:38 -0400770 lpfc_els_abort(phba, ndlp);
dea31012005-04-17 16:05:31 -0500771
772 if (evt == NLP_EVT_RCV_LOGO) {
James Smart51ef4c22007-08-02 11:10:31 -0400773 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500774 } else {
James Smart2e0fef82007-06-17 19:56:36 -0500775 lpfc_issue_els_logo(vport, ndlp, 0);
dea31012005-04-17 16:05:31 -0500776 }
777
James Smart2e0fef82007-06-17 19:56:36 -0500778 /* Put ndlp in npr state set plogi timer for 1 sec */
Jamie Wellnitz5024ab12006-02-28 19:25:28 -0500779 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ * 1);
James Smart2e0fef82007-06-17 19:56:36 -0500780 spin_lock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -0500781 ndlp->nlp_flag |= NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -0500782 spin_unlock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -0500783 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
784 ndlp->nlp_prev_state = NLP_STE_PLOGI_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -0500785 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
dea31012005-04-17 16:05:31 -0500786
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -0500787 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -0500788}
789
790static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -0500791lpfc_cmpl_plogi_plogi_issue(struct lpfc_vport *vport,
792 struct lpfc_nodelist *ndlp,
793 void *arg,
dea31012005-04-17 16:05:31 -0500794 uint32_t evt)
795{
James Smart2e0fef82007-06-17 19:56:36 -0500796 struct lpfc_hba *phba = vport->phba;
James Smart0ff10d42008-01-11 01:52:36 -0500797 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart2e0fef82007-06-17 19:56:36 -0500798 struct lpfc_iocbq *cmdiocb, *rspiocb;
James Smart14691152006-12-02 13:34:28 -0500799 struct lpfc_dmabuf *pcmd, *prsp, *mp;
dea31012005-04-17 16:05:31 -0500800 uint32_t *lp;
801 IOCB_t *irsp;
802 struct serv_parm *sp;
803 LPFC_MBOXQ_t *mbox;
804
805 cmdiocb = (struct lpfc_iocbq *) arg;
806 rspiocb = cmdiocb->context_un.rsp_iocb;
807
808 if (ndlp->nlp_flag & NLP_ACC_REGLOGIN) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -0500809 /* Recovery from PLOGI collision logic */
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -0500810 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -0500811 }
812
813 irsp = &rspiocb->iocb;
814
815 if (irsp->ulpStatus)
816 goto out;
817
818 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
819
James Smart2e0fef82007-06-17 19:56:36 -0500820 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
dea31012005-04-17 16:05:31 -0500821
James Smart2e0fef82007-06-17 19:56:36 -0500822 lp = (uint32_t *) prsp->virt;
dea31012005-04-17 16:05:31 -0500823 sp = (struct serv_parm *) ((uint8_t *) lp + sizeof (uint32_t));
James Smart58da1ff2008-04-07 10:15:56 -0400824
825 /* Some switches have FDMI servers returning 0 for WWN */
826 if ((ndlp->nlp_DID != FDMI_DID) &&
827 (wwn_to_u64(sp->portName.u.wwn) == 0 ||
828 wwn_to_u64(sp->nodeName.u.wwn) == 0)) {
James Smarta8adb832007-10-27 13:37:53 -0400829 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
830 "0142 PLOGI RSP: Invalid WWN.\n");
831 goto out;
832 }
James Smart2e0fef82007-06-17 19:56:36 -0500833 if (!lpfc_check_sparm(vport, ndlp, sp, CLASS3))
dea31012005-04-17 16:05:31 -0500834 goto out;
dea31012005-04-17 16:05:31 -0500835 /* PLOGI chkparm OK */
James Smarte8b62012007-08-02 11:10:09 -0400836 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
837 "0121 PLOGI chkparm OK Data: x%x x%x x%x x%x\n",
838 ndlp->nlp_DID, ndlp->nlp_state,
839 ndlp->nlp_flag, ndlp->nlp_rpi);
James Smart3de2a652007-08-02 11:09:59 -0400840 if (vport->cfg_fcp_class == 2 && (sp->cls2.classValid))
dea31012005-04-17 16:05:31 -0500841 ndlp->nlp_fcp_info |= CLASS2;
James Smart2e0fef82007-06-17 19:56:36 -0500842 else
dea31012005-04-17 16:05:31 -0500843 ndlp->nlp_fcp_info |= CLASS3;
James Smart2e0fef82007-06-17 19:56:36 -0500844
dea31012005-04-17 16:05:31 -0500845 ndlp->nlp_class_sup = 0;
846 if (sp->cls1.classValid)
847 ndlp->nlp_class_sup |= FC_COS_CLASS1;
848 if (sp->cls2.classValid)
849 ndlp->nlp_class_sup |= FC_COS_CLASS2;
850 if (sp->cls3.classValid)
851 ndlp->nlp_class_sup |= FC_COS_CLASS3;
852 if (sp->cls4.classValid)
853 ndlp->nlp_class_sup |= FC_COS_CLASS4;
854 ndlp->nlp_maxframe =
James Smart2e0fef82007-06-17 19:56:36 -0500855 ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) | sp->cmn.bbRcvSizeLsb;
dea31012005-04-17 16:05:31 -0500856
James Smart2e0fef82007-06-17 19:56:36 -0500857 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
James Smart92d7f7b2007-06-17 19:56:38 -0500858 if (!mbox) {
James Smarte8b62012007-08-02 11:10:09 -0400859 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
860 "0133 PLOGI: no memory for reg_login "
James Smart92d7f7b2007-06-17 19:56:38 -0500861 "Data: x%x x%x x%x x%x\n",
James Smart92d7f7b2007-06-17 19:56:38 -0500862 ndlp->nlp_DID, ndlp->nlp_state,
863 ndlp->nlp_flag, ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -0500864 goto out;
James Smart92d7f7b2007-06-17 19:56:38 -0500865 }
dea31012005-04-17 16:05:31 -0500866
James Smart2e0fef82007-06-17 19:56:36 -0500867 lpfc_unreg_rpi(vport, ndlp);
868
James Smart92d7f7b2007-06-17 19:56:38 -0500869 if (lpfc_reg_login(phba, vport->vpi, irsp->un.elsreq64.remoteID,
870 (uint8_t *) sp, mbox, 0) == 0) {
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500871 switch (ndlp->nlp_DID) {
dea31012005-04-17 16:05:31 -0500872 case NameServer_DID:
James Smartde0c5b32007-04-25 09:52:27 -0400873 mbox->mbox_cmpl = lpfc_mbx_cmpl_ns_reg_login;
dea31012005-04-17 16:05:31 -0500874 break;
875 case FDMI_DID:
James Smartde0c5b32007-04-25 09:52:27 -0400876 mbox->mbox_cmpl = lpfc_mbx_cmpl_fdmi_reg_login;
dea31012005-04-17 16:05:31 -0500877 break;
878 default:
James Smartde0c5b32007-04-25 09:52:27 -0400879 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
dea31012005-04-17 16:05:31 -0500880 }
James Smart329f9bc2007-04-25 09:53:01 -0400881 mbox->context2 = lpfc_nlp_get(ndlp);
James Smart2e0fef82007-06-17 19:56:36 -0500882 mbox->vport = vport;
James Smart0b727fe2007-10-27 13:37:25 -0400883 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
dea31012005-04-17 16:05:31 -0500884 != MBX_NOT_FINISHED) {
James Smart2e0fef82007-06-17 19:56:36 -0500885 lpfc_nlp_set_state(vport, ndlp,
886 NLP_STE_REG_LOGIN_ISSUE);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -0500887 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -0500888 }
James Smartfa4066b2008-01-11 01:53:27 -0500889 /* decrement node reference count to the failed mbox
890 * command
891 */
James Smart329f9bc2007-04-25 09:53:01 -0400892 lpfc_nlp_put(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -0500893 mp = (struct lpfc_dmabuf *) mbox->context1;
James Smart14691152006-12-02 13:34:28 -0500894 lpfc_mbuf_free(phba, mp->virt, mp->phys);
895 kfree(mp);
dea31012005-04-17 16:05:31 -0500896 mempool_free(mbox, phba->mbox_mem_pool);
James Smart92d7f7b2007-06-17 19:56:38 -0500897
James Smarte8b62012007-08-02 11:10:09 -0400898 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
899 "0134 PLOGI: cannot issue reg_login "
900 "Data: x%x x%x x%x x%x\n",
901 ndlp->nlp_DID, ndlp->nlp_state,
902 ndlp->nlp_flag, ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -0500903 } else {
904 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 "0135 PLOGI: cannot format 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 }
912
913
James Smart92d7f7b2007-06-17 19:56:38 -0500914out:
915 if (ndlp->nlp_DID == NameServer_DID) {
916 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -0400917 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
918 "0261 Cannot Register NameServer login\n");
James Smart92d7f7b2007-06-17 19:56:38 -0500919 }
920
James Smart0ff10d42008-01-11 01:52:36 -0500921 spin_lock_irq(shost->host_lock);
James Smarta8adb832007-10-27 13:37:53 -0400922 ndlp->nlp_flag |= NLP_DEFER_RM;
James Smart0ff10d42008-01-11 01:52:36 -0500923 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -0500924 return NLP_STE_FREED_NODE;
dea31012005-04-17 16:05:31 -0500925}
926
927static uint32_t
James Smart0ff10d42008-01-11 01:52:36 -0500928lpfc_cmpl_logo_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
929 void *arg, uint32_t evt)
930{
931 return ndlp->nlp_state;
932}
933
934static uint32_t
935lpfc_cmpl_reglogin_plogi_issue(struct lpfc_vport *vport,
936 struct lpfc_nodelist *ndlp, void *arg, uint32_t evt)
937{
938 return ndlp->nlp_state;
939}
940
941static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -0500942lpfc_device_rm_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
943 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -0500944{
James Smart2e0fef82007-06-17 19:56:36 -0500945 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -0500946
James Smart2e0fef82007-06-17 19:56:36 -0500947 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
948 spin_lock_irq(shost->host_lock);
949 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
950 spin_unlock_irq(shost->host_lock);
951 return ndlp->nlp_state;
952 } else {
953 /* software abort outstanding PLOGI */
954 lpfc_els_abort(vport->phba, ndlp);
955
956 lpfc_drop_node(vport, ndlp);
James Smarta0f9b482006-04-15 11:52:56 -0400957 return NLP_STE_FREED_NODE;
958 }
dea31012005-04-17 16:05:31 -0500959}
960
961static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -0500962lpfc_device_recov_plogi_issue(struct lpfc_vport *vport,
963 struct lpfc_nodelist *ndlp,
964 void *arg,
965 uint32_t evt)
dea31012005-04-17 16:05:31 -0500966{
James Smart2e0fef82007-06-17 19:56:36 -0500967 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
968 struct lpfc_hba *phba = vport->phba;
969
James Smart92d7f7b2007-06-17 19:56:38 -0500970 /* Don't do anything that will mess up processing of the
971 * previous RSCN.
972 */
973 if (vport->fc_flag & FC_RSCN_DEFERRED)
974 return ndlp->nlp_state;
975
dea31012005-04-17 16:05:31 -0500976 /* software abort outstanding PLOGI */
James Smart07951072007-04-25 09:51:38 -0400977 lpfc_els_abort(phba, ndlp);
dea31012005-04-17 16:05:31 -0500978
Jamie Wellnitz5024ab12006-02-28 19:25:28 -0500979 ndlp->nlp_prev_state = NLP_STE_PLOGI_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -0500980 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
James Smart92d7f7b2007-06-17 19:56:38 -0500981 spin_lock_irq(shost->host_lock);
James Smarta0f9b482006-04-15 11:52:56 -0400982 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
James Smart2e0fef82007-06-17 19:56:36 -0500983 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500984
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -0500985 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -0500986}
987
988static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -0500989lpfc_rcv_plogi_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
990 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -0500991{
James Smart0d2b6b82008-06-14 22:52:47 -0400992 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart2e0fef82007-06-17 19:56:36 -0500993 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500994 struct lpfc_iocbq *cmdiocb;
995
996 /* software abort outstanding ADISC */
James Smart07951072007-04-25 09:51:38 -0400997 lpfc_els_abort(phba, ndlp);
dea31012005-04-17 16:05:31 -0500998
999 cmdiocb = (struct lpfc_iocbq *) arg;
1000
James Smart0d2b6b82008-06-14 22:52:47 -04001001 if (lpfc_rcv_plogi(vport, ndlp, cmdiocb)) {
1002 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1003 spin_lock_irq(shost->host_lock);
1004 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
1005 spin_unlock_irq(shost->host_lock);
James Smart90160e02008-08-24 21:49:45 -04001006 if (vport->num_disc_nodes)
James Smart0d2b6b82008-06-14 22:52:47 -04001007 lpfc_more_adisc(vport);
James Smart0d2b6b82008-06-14 22:52:47 -04001008 }
1009 return ndlp->nlp_state;
1010 }
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001011 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -05001012 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
1013 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
dea31012005-04-17 16:05:31 -05001014
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001015 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001016}
1017
1018static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001019lpfc_rcv_prli_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1020 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001021{
James Smart2e0fef82007-06-17 19:56:36 -05001022 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001023
James Smart2e0fef82007-06-17 19:56:36 -05001024 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001025 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001026}
1027
1028static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001029lpfc_rcv_logo_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1030 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001031{
James Smart2e0fef82007-06-17 19:56:36 -05001032 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001033 struct lpfc_iocbq *cmdiocb;
1034
1035 cmdiocb = (struct lpfc_iocbq *) arg;
1036
1037 /* software abort outstanding ADISC */
James Smart07951072007-04-25 09:51:38 -04001038 lpfc_els_abort(phba, ndlp);
dea31012005-04-17 16:05:31 -05001039
James Smart2e0fef82007-06-17 19:56:36 -05001040 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001041 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001042}
1043
1044static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001045lpfc_rcv_padisc_adisc_issue(struct lpfc_vport *vport,
1046 struct lpfc_nodelist *ndlp,
1047 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001048{
1049 struct lpfc_iocbq *cmdiocb;
1050
1051 cmdiocb = (struct lpfc_iocbq *) arg;
1052
James Smart2e0fef82007-06-17 19:56:36 -05001053 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001054 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001055}
1056
1057static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001058lpfc_rcv_prlo_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1059 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001060{
1061 struct lpfc_iocbq *cmdiocb;
1062
1063 cmdiocb = (struct lpfc_iocbq *) arg;
1064
1065 /* Treat like rcv logo */
James Smart2e0fef82007-06-17 19:56:36 -05001066 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_PRLO);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001067 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001068}
1069
1070static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001071lpfc_cmpl_adisc_adisc_issue(struct lpfc_vport *vport,
1072 struct lpfc_nodelist *ndlp,
1073 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001074{
James Smart2e0fef82007-06-17 19:56:36 -05001075 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1076 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001077 struct lpfc_iocbq *cmdiocb, *rspiocb;
1078 IOCB_t *irsp;
1079 ADISC *ap;
1080
1081 cmdiocb = (struct lpfc_iocbq *) arg;
1082 rspiocb = cmdiocb->context_un.rsp_iocb;
1083
1084 ap = (ADISC *)lpfc_check_elscmpl_iocb(phba, cmdiocb, rspiocb);
1085 irsp = &rspiocb->iocb;
1086
1087 if ((irsp->ulpStatus) ||
James Smart92d7f7b2007-06-17 19:56:38 -05001088 (!lpfc_check_adisc(vport, ndlp, &ap->nodeName, &ap->portName))) {
dea31012005-04-17 16:05:31 -05001089 /* 1 sec timeout */
1090 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ);
James Smart2e0fef82007-06-17 19:56:36 -05001091 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001092 ndlp->nlp_flag |= NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05001093 spin_unlock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001094 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
dea31012005-04-17 16:05:31 -05001095
James Smart2e0fef82007-06-17 19:56:36 -05001096 memset(&ndlp->nlp_nodename, 0, sizeof(struct lpfc_name));
1097 memset(&ndlp->nlp_portname, 0, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05001098
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001099 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -05001100 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1101 lpfc_unreg_rpi(vport, ndlp);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001102 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001103 }
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001104
James.Smart@Emulex.Com25013222005-06-25 10:34:33 -04001105 if (ndlp->nlp_type & NLP_FCP_TARGET) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001106 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -05001107 lpfc_nlp_set_state(vport, ndlp, NLP_STE_MAPPED_NODE);
James.Smart@Emulex.Com25013222005-06-25 10:34:33 -04001108 } else {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001109 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -05001110 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
James.Smart@Emulex.Com25013222005-06-25 10:34:33 -04001111 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001112 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001113}
1114
1115static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001116lpfc_device_rm_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1117 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001118{
James Smart2e0fef82007-06-17 19:56:36 -05001119 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001120
James Smart2e0fef82007-06-17 19:56:36 -05001121 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1122 spin_lock_irq(shost->host_lock);
1123 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
1124 spin_unlock_irq(shost->host_lock);
1125 return ndlp->nlp_state;
1126 } else {
1127 /* software abort outstanding ADISC */
1128 lpfc_els_abort(vport->phba, ndlp);
1129
1130 lpfc_drop_node(vport, ndlp);
James Smarta0f9b482006-04-15 11:52:56 -04001131 return NLP_STE_FREED_NODE;
1132 }
dea31012005-04-17 16:05:31 -05001133}
1134
1135static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001136lpfc_device_recov_adisc_issue(struct lpfc_vport *vport,
1137 struct lpfc_nodelist *ndlp,
1138 void *arg,
1139 uint32_t evt)
dea31012005-04-17 16:05:31 -05001140{
James Smart2e0fef82007-06-17 19:56:36 -05001141 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1142 struct lpfc_hba *phba = vport->phba;
1143
James Smart92d7f7b2007-06-17 19:56:38 -05001144 /* Don't do anything that will mess up processing of the
1145 * previous RSCN.
1146 */
1147 if (vport->fc_flag & FC_RSCN_DEFERRED)
1148 return ndlp->nlp_state;
1149
dea31012005-04-17 16:05:31 -05001150 /* software abort outstanding ADISC */
James Smart07951072007-04-25 09:51:38 -04001151 lpfc_els_abort(phba, ndlp);
dea31012005-04-17 16:05:31 -05001152
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001153 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -05001154 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1155 spin_lock_irq(shost->host_lock);
James Smarta0f9b482006-04-15 11:52:56 -04001156 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
James Smart2e0fef82007-06-17 19:56:36 -05001157 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05001158 lpfc_disc_set_adisc(vport, ndlp);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001159 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001160}
1161
1162static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001163lpfc_rcv_plogi_reglogin_issue(struct lpfc_vport *vport,
1164 struct lpfc_nodelist *ndlp,
1165 void *arg,
dea31012005-04-17 16:05:31 -05001166 uint32_t evt)
1167{
James Smart2e0fef82007-06-17 19:56:36 -05001168 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001169
James Smart2e0fef82007-06-17 19:56:36 -05001170 lpfc_rcv_plogi(vport, ndlp, cmdiocb);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001171 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001172}
1173
1174static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001175lpfc_rcv_prli_reglogin_issue(struct lpfc_vport *vport,
1176 struct lpfc_nodelist *ndlp,
1177 void *arg,
dea31012005-04-17 16:05:31 -05001178 uint32_t evt)
1179{
James Smart2e0fef82007-06-17 19:56:36 -05001180 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001181
James Smart2e0fef82007-06-17 19:56:36 -05001182 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001183 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001184}
1185
1186static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001187lpfc_rcv_logo_reglogin_issue(struct lpfc_vport *vport,
1188 struct lpfc_nodelist *ndlp,
1189 void *arg,
dea31012005-04-17 16:05:31 -05001190 uint32_t evt)
1191{
James Smart2e0fef82007-06-17 19:56:36 -05001192 struct lpfc_hba *phba = vport->phba;
1193 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
James Smart7054a602007-04-25 09:52:34 -04001194 LPFC_MBOXQ_t *mb;
1195 LPFC_MBOXQ_t *nextmb;
1196 struct lpfc_dmabuf *mp;
dea31012005-04-17 16:05:31 -05001197
1198 cmdiocb = (struct lpfc_iocbq *) arg;
1199
James Smart7054a602007-04-25 09:52:34 -04001200 /* cleanup any ndlp on mbox q waiting for reglogin cmpl */
1201 if ((mb = phba->sli.mbox_active)) {
1202 if ((mb->mb.mbxCommand == MBX_REG_LOGIN64) &&
1203 (ndlp == (struct lpfc_nodelist *) mb->context2)) {
James Smart92d7f7b2007-06-17 19:56:38 -05001204 lpfc_nlp_put(ndlp);
James Smart7054a602007-04-25 09:52:34 -04001205 mb->context2 = NULL;
1206 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1207 }
1208 }
1209
James Smart2e0fef82007-06-17 19:56:36 -05001210 spin_lock_irq(&phba->hbalock);
James Smart7054a602007-04-25 09:52:34 -04001211 list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) {
1212 if ((mb->mb.mbxCommand == MBX_REG_LOGIN64) &&
1213 (ndlp == (struct lpfc_nodelist *) mb->context2)) {
1214 mp = (struct lpfc_dmabuf *) (mb->context1);
1215 if (mp) {
James Smart98c9ea52007-10-27 13:37:33 -04001216 __lpfc_mbuf_free(phba, mp->virt, mp->phys);
James Smart7054a602007-04-25 09:52:34 -04001217 kfree(mp);
1218 }
James Smart92d7f7b2007-06-17 19:56:38 -05001219 lpfc_nlp_put(ndlp);
James Smart7054a602007-04-25 09:52:34 -04001220 list_del(&mb->list);
1221 mempool_free(mb, phba->mbox_mem_pool);
1222 }
1223 }
James Smart2e0fef82007-06-17 19:56:36 -05001224 spin_unlock_irq(&phba->hbalock);
James Smart7054a602007-04-25 09:52:34 -04001225
James Smart2e0fef82007-06-17 19:56:36 -05001226 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001227 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001228}
1229
1230static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001231lpfc_rcv_padisc_reglogin_issue(struct lpfc_vport *vport,
1232 struct lpfc_nodelist *ndlp,
1233 void *arg,
dea31012005-04-17 16:05:31 -05001234 uint32_t evt)
1235{
James Smart2e0fef82007-06-17 19:56:36 -05001236 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001237
James Smart2e0fef82007-06-17 19:56:36 -05001238 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001239 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001240}
1241
1242static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001243lpfc_rcv_prlo_reglogin_issue(struct lpfc_vport *vport,
1244 struct lpfc_nodelist *ndlp,
1245 void *arg,
dea31012005-04-17 16:05:31 -05001246 uint32_t evt)
1247{
1248 struct lpfc_iocbq *cmdiocb;
1249
1250 cmdiocb = (struct lpfc_iocbq *) arg;
James Smart51ef4c22007-08-02 11:10:31 -04001251 lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001252 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001253}
1254
1255static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001256lpfc_cmpl_reglogin_reglogin_issue(struct lpfc_vport *vport,
1257 struct lpfc_nodelist *ndlp,
1258 void *arg,
1259 uint32_t evt)
dea31012005-04-17 16:05:31 -05001260{
James Smart2e0fef82007-06-17 19:56:36 -05001261 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart2e0fef82007-06-17 19:56:36 -05001262 LPFC_MBOXQ_t *pmb = (LPFC_MBOXQ_t *) arg;
1263 MAILBOX_t *mb = &pmb->mb;
1264 uint32_t did = mb->un.varWords[1];
dea31012005-04-17 16:05:31 -05001265
dea31012005-04-17 16:05:31 -05001266 if (mb->mbxStatus) {
1267 /* RegLogin failed */
James Smarte8b62012007-08-02 11:10:09 -04001268 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
1269 "0246 RegLogin failed Data: x%x x%x x%x\n",
James Smart2e0fef82007-06-17 19:56:36 -05001270 did, mb->mbxStatus, vport->port_state);
James Smartd0e56da2006-07-06 15:49:42 -04001271 /*
1272 * If RegLogin failed due to lack of HBA resources do not
1273 * retry discovery.
1274 */
1275 if (mb->mbxStatus == MBXERR_RPI_FULL) {
James Smart87af33f2007-10-27 13:37:43 -04001276 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
1277 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
James Smartd0e56da2006-07-06 15:49:42 -04001278 return ndlp->nlp_state;
1279 }
1280
James Smart2e0fef82007-06-17 19:56:36 -05001281 /* Put ndlp in npr state set plogi timer for 1 sec */
dea31012005-04-17 16:05:31 -05001282 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ * 1);
James Smart2e0fef82007-06-17 19:56:36 -05001283 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001284 ndlp->nlp_flag |= NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05001285 spin_unlock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001286 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
dea31012005-04-17 16:05:31 -05001287
James Smart2e0fef82007-06-17 19:56:36 -05001288 lpfc_issue_els_logo(vport, ndlp, 0);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001289 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -05001290 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001291 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001292 }
1293
dea31012005-04-17 16:05:31 -05001294 ndlp->nlp_rpi = mb->un.varWords[0];
dea31012005-04-17 16:05:31 -05001295
1296 /* Only if we are not a fabric nport do we issue PRLI */
1297 if (!(ndlp->nlp_type & NLP_FABRIC)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001298 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -05001299 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
1300 lpfc_issue_els_prli(vport, ndlp, 0);
dea31012005-04-17 16:05:31 -05001301 } else {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001302 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -05001303 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
dea31012005-04-17 16:05:31 -05001304 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001305 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001306}
1307
1308static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001309lpfc_device_rm_reglogin_issue(struct lpfc_vport *vport,
1310 struct lpfc_nodelist *ndlp,
1311 void *arg,
dea31012005-04-17 16:05:31 -05001312 uint32_t evt)
1313{
James Smart2e0fef82007-06-17 19:56:36 -05001314 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1315
1316 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1317 spin_lock_irq(shost->host_lock);
James Smarta0f9b482006-04-15 11:52:56 -04001318 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
James Smart2e0fef82007-06-17 19:56:36 -05001319 spin_unlock_irq(shost->host_lock);
James Smarta0f9b482006-04-15 11:52:56 -04001320 return ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05001321 } else {
1322 lpfc_drop_node(vport, ndlp);
James Smarta0f9b482006-04-15 11:52:56 -04001323 return NLP_STE_FREED_NODE;
1324 }
dea31012005-04-17 16:05:31 -05001325}
1326
1327static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001328lpfc_device_recov_reglogin_issue(struct lpfc_vport *vport,
1329 struct lpfc_nodelist *ndlp,
1330 void *arg,
1331 uint32_t evt)
dea31012005-04-17 16:05:31 -05001332{
James Smart2e0fef82007-06-17 19:56:36 -05001333 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1334
James Smart92d7f7b2007-06-17 19:56:38 -05001335 /* Don't do anything that will mess up processing of the
1336 * previous RSCN.
1337 */
1338 if (vport->fc_flag & FC_RSCN_DEFERRED)
1339 return ndlp->nlp_state;
1340
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001341 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -05001342 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1343 spin_lock_irq(shost->host_lock);
James Smarta0f9b482006-04-15 11:52:56 -04001344 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
James Smart2e0fef82007-06-17 19:56:36 -05001345 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05001346 lpfc_disc_set_adisc(vport, ndlp);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001347 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001348}
1349
1350static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001351lpfc_rcv_plogi_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1352 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001353{
1354 struct lpfc_iocbq *cmdiocb;
1355
1356 cmdiocb = (struct lpfc_iocbq *) arg;
1357
James Smart2e0fef82007-06-17 19:56:36 -05001358 lpfc_rcv_plogi(vport, ndlp, cmdiocb);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001359 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001360}
1361
1362static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001363lpfc_rcv_prli_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1364 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001365{
James Smart2e0fef82007-06-17 19:56:36 -05001366 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001367
James Smart2e0fef82007-06-17 19:56:36 -05001368 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001369 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001370}
1371
1372static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001373lpfc_rcv_logo_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1374 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001375{
James Smart2e0fef82007-06-17 19:56:36 -05001376 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001377
1378 /* Software abort outstanding PRLI before sending acc */
James Smart2e0fef82007-06-17 19:56:36 -05001379 lpfc_els_abort(vport->phba, ndlp);
dea31012005-04-17 16:05:31 -05001380
James Smart2e0fef82007-06-17 19:56:36 -05001381 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001382 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001383}
1384
1385static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001386lpfc_rcv_padisc_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1387 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001388{
James Smart2e0fef82007-06-17 19:56:36 -05001389 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001390
James Smart2e0fef82007-06-17 19:56:36 -05001391 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001392 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001393}
1394
1395/* This routine is envoked when we rcv a PRLO request from a nport
1396 * we are logged into. We should send back a PRLO rsp setting the
1397 * appropriate bits.
1398 * NEXT STATE = PRLI_ISSUE
1399 */
1400static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001401lpfc_rcv_prlo_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1402 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001403{
James Smart2e0fef82007-06-17 19:56:36 -05001404 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001405
James Smart51ef4c22007-08-02 11:10:31 -04001406 lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001407 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001408}
1409
1410static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001411lpfc_cmpl_prli_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1412 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001413{
James Smart92d7f7b2007-06-17 19:56:38 -05001414 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001415 struct lpfc_iocbq *cmdiocb, *rspiocb;
James Smart2e0fef82007-06-17 19:56:36 -05001416 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001417 IOCB_t *irsp;
1418 PRLI *npr;
1419
1420 cmdiocb = (struct lpfc_iocbq *) arg;
1421 rspiocb = cmdiocb->context_un.rsp_iocb;
1422 npr = (PRLI *)lpfc_check_elscmpl_iocb(phba, cmdiocb, rspiocb);
1423
1424 irsp = &rspiocb->iocb;
1425 if (irsp->ulpStatus) {
James Smart858c9f62007-06-17 19:56:39 -05001426 if ((vport->port_type == LPFC_NPIV_PORT) &&
James Smart3de2a652007-08-02 11:09:59 -04001427 vport->cfg_restrict_login) {
James Smart858c9f62007-06-17 19:56:39 -05001428 goto out;
1429 }
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001430 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -05001431 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001432 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001433 }
1434
1435 /* Check out PRLI rsp */
1436 ndlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR);
1437 ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
1438 if ((npr->acceptRspCode == PRLI_REQ_EXECUTED) &&
1439 (npr->prliType == PRLI_FCP_TYPE)) {
1440 if (npr->initiatorFunc)
1441 ndlp->nlp_type |= NLP_FCP_INITIATOR;
1442 if (npr->targetFunc)
1443 ndlp->nlp_type |= NLP_FCP_TARGET;
1444 if (npr->Retry)
1445 ndlp->nlp_fcp_info |= NLP_FCP_2_DEVICE;
1446 }
James Smart92d7f7b2007-06-17 19:56:38 -05001447 if (!(ndlp->nlp_type & NLP_FCP_TARGET) &&
1448 (vport->port_type == LPFC_NPIV_PORT) &&
James Smart3de2a652007-08-02 11:09:59 -04001449 vport->cfg_restrict_login) {
James Smart858c9f62007-06-17 19:56:39 -05001450out:
James Smart92d7f7b2007-06-17 19:56:38 -05001451 spin_lock_irq(shost->host_lock);
1452 ndlp->nlp_flag |= NLP_TARGET_REMOVE;
1453 spin_unlock_irq(shost->host_lock);
1454 lpfc_issue_els_logo(vport, ndlp, 0);
1455
1456 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
James Smart87af33f2007-10-27 13:37:43 -04001457 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
James Smart92d7f7b2007-06-17 19:56:38 -05001458 return ndlp->nlp_state;
1459 }
dea31012005-04-17 16:05:31 -05001460
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001461 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
James Smart92d7f7b2007-06-17 19:56:38 -05001462 if (ndlp->nlp_type & NLP_FCP_TARGET)
1463 lpfc_nlp_set_state(vport, ndlp, NLP_STE_MAPPED_NODE);
1464 else
1465 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001466 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001467}
1468
1469/*! lpfc_device_rm_prli_issue
James Smart92d7f7b2007-06-17 19:56:38 -05001470 *
1471 * \pre
1472 * \post
1473 * \param phba
1474 * \param ndlp
1475 * \param arg
1476 * \param evt
1477 * \return uint32_t
1478 *
1479 * \b Description:
1480 * This routine is envoked when we a request to remove a nport we are in the
1481 * process of PRLIing. We should software abort outstanding prli, unreg
1482 * login, send a logout. We will change node state to UNUSED_NODE, put it
1483 * on plogi list so it can be freed when LOGO completes.
1484 *
1485 */
1486
dea31012005-04-17 16:05:31 -05001487static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001488lpfc_device_rm_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1489 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001490{
James Smart2e0fef82007-06-17 19:56:36 -05001491 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001492
James Smart2e0fef82007-06-17 19:56:36 -05001493 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1494 spin_lock_irq(shost->host_lock);
1495 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
1496 spin_unlock_irq(shost->host_lock);
1497 return ndlp->nlp_state;
1498 } else {
1499 /* software abort outstanding PLOGI */
1500 lpfc_els_abort(vport->phba, ndlp);
1501
1502 lpfc_drop_node(vport, ndlp);
James Smarta0f9b482006-04-15 11:52:56 -04001503 return NLP_STE_FREED_NODE;
1504 }
dea31012005-04-17 16:05:31 -05001505}
1506
1507
1508/*! lpfc_device_recov_prli_issue
James Smart92d7f7b2007-06-17 19:56:38 -05001509 *
1510 * \pre
1511 * \post
1512 * \param phba
1513 * \param ndlp
1514 * \param arg
1515 * \param evt
1516 * \return uint32_t
1517 *
1518 * \b Description:
1519 * The routine is envoked when the state of a device is unknown, like
1520 * during a link down. We should remove the nodelist entry from the
1521 * unmapped list, issue a UNREG_LOGIN, do a software abort of the
1522 * outstanding PRLI command, then free the node entry.
1523 */
dea31012005-04-17 16:05:31 -05001524static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001525lpfc_device_recov_prli_issue(struct lpfc_vport *vport,
1526 struct lpfc_nodelist *ndlp,
1527 void *arg,
1528 uint32_t evt)
dea31012005-04-17 16:05:31 -05001529{
James Smart2e0fef82007-06-17 19:56:36 -05001530 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1531 struct lpfc_hba *phba = vport->phba;
1532
James Smart92d7f7b2007-06-17 19:56:38 -05001533 /* Don't do anything that will mess up processing of the
1534 * previous RSCN.
1535 */
1536 if (vport->fc_flag & FC_RSCN_DEFERRED)
1537 return ndlp->nlp_state;
1538
dea31012005-04-17 16:05:31 -05001539 /* software abort outstanding PRLI */
James Smart07951072007-04-25 09:51:38 -04001540 lpfc_els_abort(phba, ndlp);
dea31012005-04-17 16:05:31 -05001541
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001542 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -05001543 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1544 spin_lock_irq(shost->host_lock);
James Smarta0f9b482006-04-15 11:52:56 -04001545 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
James Smart2e0fef82007-06-17 19:56:36 -05001546 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05001547 lpfc_disc_set_adisc(vport, ndlp);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001548 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001549}
1550
1551static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001552lpfc_rcv_plogi_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1553 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001554{
James Smart2e0fef82007-06-17 19:56:36 -05001555 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001556
James Smart2e0fef82007-06-17 19:56:36 -05001557 lpfc_rcv_plogi(vport, ndlp, cmdiocb);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001558 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001559}
1560
1561static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001562lpfc_rcv_prli_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1563 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001564{
James Smart2e0fef82007-06-17 19:56:36 -05001565 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001566
James Smart2e0fef82007-06-17 19:56:36 -05001567 lpfc_rcv_prli(vport, ndlp, cmdiocb);
1568 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001569 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001570}
1571
1572static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001573lpfc_rcv_logo_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1574 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001575{
James Smart2e0fef82007-06-17 19:56:36 -05001576 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001577
James Smart2e0fef82007-06-17 19:56:36 -05001578 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001579 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001580}
1581
1582static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001583lpfc_rcv_padisc_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1584 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001585{
James Smart2e0fef82007-06-17 19:56:36 -05001586 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001587
James Smart2e0fef82007-06-17 19:56:36 -05001588 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001589 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001590}
1591
1592static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001593lpfc_rcv_prlo_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1594 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001595{
James Smart2e0fef82007-06-17 19:56:36 -05001596 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001597
James Smart51ef4c22007-08-02 11:10:31 -04001598 lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001599 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001600}
1601
1602static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001603lpfc_device_recov_unmap_node(struct lpfc_vport *vport,
1604 struct lpfc_nodelist *ndlp,
1605 void *arg,
1606 uint32_t evt)
dea31012005-04-17 16:05:31 -05001607{
James Smart2e0fef82007-06-17 19:56:36 -05001608 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1609
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001610 ndlp->nlp_prev_state = NLP_STE_UNMAPPED_NODE;
James Smart2e0fef82007-06-17 19:56:36 -05001611 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1612 spin_lock_irq(shost->host_lock);
James Smarta0f9b482006-04-15 11:52:56 -04001613 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
James Smart2e0fef82007-06-17 19:56:36 -05001614 spin_unlock_irq(shost->host_lock);
1615 lpfc_disc_set_adisc(vport, ndlp);
dea31012005-04-17 16:05:31 -05001616
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001617 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001618}
1619
1620static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001621lpfc_rcv_plogi_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1622 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001623{
James Smart2e0fef82007-06-17 19:56:36 -05001624 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001625
James Smart2e0fef82007-06-17 19:56:36 -05001626 lpfc_rcv_plogi(vport, ndlp, cmdiocb);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001627 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001628}
1629
1630static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001631lpfc_rcv_prli_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1632 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001633{
James Smart2e0fef82007-06-17 19:56:36 -05001634 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001635
James Smart2e0fef82007-06-17 19:56:36 -05001636 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001637 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001638}
1639
1640static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001641lpfc_rcv_logo_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1642 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001643{
James Smart2e0fef82007-06-17 19:56:36 -05001644 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001645
James Smart2e0fef82007-06-17 19:56:36 -05001646 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001647 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001648}
1649
1650static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001651lpfc_rcv_padisc_mapped_node(struct lpfc_vport *vport,
1652 struct lpfc_nodelist *ndlp,
1653 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001654{
James Smart2e0fef82007-06-17 19:56:36 -05001655 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001656
James Smart2e0fef82007-06-17 19:56:36 -05001657 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001658 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001659}
1660
1661static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001662lpfc_rcv_prlo_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1663 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001664{
James Smart2e0fef82007-06-17 19:56:36 -05001665 struct lpfc_hba *phba = vport->phba;
1666 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001667
1668 /* flush the target */
James Smart51ef4c22007-08-02 11:10:31 -04001669 lpfc_sli_abort_iocb(vport, &phba->sli.ring[phba->sli.fcp_ring],
1670 ndlp->nlp_sid, 0, LPFC_CTX_TGT);
dea31012005-04-17 16:05:31 -05001671
1672 /* Treat like rcv logo */
James Smart2e0fef82007-06-17 19:56:36 -05001673 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_PRLO);
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_device_recov_mapped_node(struct lpfc_vport *vport,
1679 struct lpfc_nodelist *ndlp,
1680 void *arg,
1681 uint32_t evt)
dea31012005-04-17 16:05:31 -05001682{
James Smart2e0fef82007-06-17 19:56:36 -05001683 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1684
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001685 ndlp->nlp_prev_state = NLP_STE_MAPPED_NODE;
James Smart2e0fef82007-06-17 19:56:36 -05001686 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1687 spin_lock_irq(shost->host_lock);
James Smarta0f9b482006-04-15 11:52:56 -04001688 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
James Smart2e0fef82007-06-17 19:56:36 -05001689 spin_unlock_irq(shost->host_lock);
1690 lpfc_disc_set_adisc(vport, ndlp);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001691 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001692}
1693
1694static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001695lpfc_rcv_plogi_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1696 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001697{
James Smart2e0fef82007-06-17 19:56:36 -05001698 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1699 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001700
1701 /* Ignore PLOGI if we have an outstanding LOGO */
James Smart0d2b6b82008-06-14 22:52:47 -04001702 if (ndlp->nlp_flag & (NLP_LOGO_SND | NLP_LOGO_ACC))
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001703 return ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05001704 if (lpfc_rcv_plogi(vport, ndlp, cmdiocb)) {
James Smart0d2b6b82008-06-14 22:52:47 -04001705 lpfc_cancel_retry_delay_tmo(vport, ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05001706 spin_lock_irq(shost->host_lock);
James Smart0d2b6b82008-06-14 22:52:47 -04001707 ndlp->nlp_flag &= ~(NLP_NPR_ADISC | NLP_NPR_2B_DISC);
James Smart2e0fef82007-06-17 19:56:36 -05001708 spin_unlock_irq(shost->host_lock);
James Smart0d2b6b82008-06-14 22:52:47 -04001709 } else if (!(ndlp->nlp_flag & NLP_NPR_2B_DISC)) {
1710 /* send PLOGI immediately, move to PLOGI issue state */
1711 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
1712 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
1713 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
1714 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
1715 }
dea31012005-04-17 16:05:31 -05001716 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001717 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001718}
1719
1720static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001721lpfc_rcv_prli_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1722 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001723{
James Smart2e0fef82007-06-17 19:56:36 -05001724 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1725 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1726 struct ls_rjt stat;
dea31012005-04-17 16:05:31 -05001727
1728 memset(&stat, 0, sizeof (struct ls_rjt));
1729 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
1730 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
James Smart858c9f62007-06-17 19:56:39 -05001731 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05001732
1733 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
1734 if (ndlp->nlp_flag & NLP_NPR_ADISC) {
James Smart2e0fef82007-06-17 19:56:36 -05001735 spin_lock_irq(shost->host_lock);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001736 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001737 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
James Smart2e0fef82007-06-17 19:56:36 -05001738 spin_unlock_irq(shost->host_lock);
1739 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
1740 lpfc_issue_els_adisc(vport, ndlp, 0);
dea31012005-04-17 16:05:31 -05001741 } else {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001742 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
James Smart2e0fef82007-06-17 19:56:36 -05001743 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
1744 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
dea31012005-04-17 16:05:31 -05001745 }
1746 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001747 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001748}
1749
1750static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001751lpfc_rcv_logo_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1752 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001753{
James Smart2e0fef82007-06-17 19:56:36 -05001754 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001755
James Smart2e0fef82007-06-17 19:56:36 -05001756 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001757 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001758}
1759
1760static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001761lpfc_rcv_padisc_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1762 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001763{
James Smart2e0fef82007-06-17 19:56:36 -05001764 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001765
James Smart2e0fef82007-06-17 19:56:36 -05001766 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
James Smart33ccf8d2006-08-17 11:57:58 -04001767 /*
1768 * Do not start discovery if discovery is about to start
1769 * or discovery in progress for this node. Starting discovery
1770 * here will affect the counting of discovery threads.
1771 */
James Smart2fb9bd82006-12-02 13:33:57 -05001772 if (!(ndlp->nlp_flag & NLP_DELAY_TMO) &&
James Smart92d7f7b2007-06-17 19:56:38 -05001773 !(ndlp->nlp_flag & NLP_NPR_2B_DISC)) {
dea31012005-04-17 16:05:31 -05001774 if (ndlp->nlp_flag & NLP_NPR_ADISC) {
James Smart92d7f7b2007-06-17 19:56:38 -05001775 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001776 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
James Smart2e0fef82007-06-17 19:56:36 -05001777 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
1778 lpfc_issue_els_adisc(vport, ndlp, 0);
dea31012005-04-17 16:05:31 -05001779 } else {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001780 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
James Smart2e0fef82007-06-17 19:56:36 -05001781 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
1782 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
dea31012005-04-17 16:05:31 -05001783 }
1784 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001785 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001786}
1787
1788static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001789lpfc_rcv_prlo_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1790 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001791{
James Smart2e0fef82007-06-17 19:56:36 -05001792 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1793 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea31012005-04-17 16:05:31 -05001794
James Smart2e0fef82007-06-17 19:56:36 -05001795 spin_lock_irq(shost->host_lock);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001796 ndlp->nlp_flag |= NLP_LOGO_ACC;
James Smart2e0fef82007-06-17 19:56:36 -05001797 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001798
James Smart51ef4c22007-08-02 11:10:31 -04001799 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05001800
James Smart2e0fef82007-06-17 19:56:36 -05001801 if ((ndlp->nlp_flag & NLP_DELAY_TMO) == 0) {
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001802 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ * 1);
James Smart2e0fef82007-06-17 19:56:36 -05001803 spin_lock_irq(shost->host_lock);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001804 ndlp->nlp_flag |= NLP_DELAY_TMO;
1805 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
James Smart2e0fef82007-06-17 19:56:36 -05001806 spin_unlock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001807 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001808 } else {
James Smart2e0fef82007-06-17 19:56:36 -05001809 spin_lock_irq(shost->host_lock);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001810 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
James Smart2e0fef82007-06-17 19:56:36 -05001811 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001812 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001813 return ndlp->nlp_state;
1814}
dea31012005-04-17 16:05:31 -05001815
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001816static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001817lpfc_cmpl_plogi_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1818 void *arg, uint32_t evt)
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001819{
1820 struct lpfc_iocbq *cmdiocb, *rspiocb;
James Smarta0f9b482006-04-15 11:52:56 -04001821 IOCB_t *irsp;
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001822
1823 cmdiocb = (struct lpfc_iocbq *) arg;
1824 rspiocb = cmdiocb->context_un.rsp_iocb;
James Smarta0f9b482006-04-15 11:52:56 -04001825
1826 irsp = &rspiocb->iocb;
1827 if (irsp->ulpStatus) {
James Smarta8adb832007-10-27 13:37:53 -04001828 ndlp->nlp_flag |= NLP_DEFER_RM;
James Smarta0f9b482006-04-15 11:52:56 -04001829 return NLP_STE_FREED_NODE;
1830 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001831 return ndlp->nlp_state;
1832}
1833
1834static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001835lpfc_cmpl_prli_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1836 void *arg, uint32_t evt)
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001837{
1838 struct lpfc_iocbq *cmdiocb, *rspiocb;
James Smarta0f9b482006-04-15 11:52:56 -04001839 IOCB_t *irsp;
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001840
1841 cmdiocb = (struct lpfc_iocbq *) arg;
1842 rspiocb = cmdiocb->context_un.rsp_iocb;
James Smarta0f9b482006-04-15 11:52:56 -04001843
1844 irsp = &rspiocb->iocb;
1845 if (irsp->ulpStatus && (ndlp->nlp_flag & NLP_NODEV_REMOVE)) {
James Smart2e0fef82007-06-17 19:56:36 -05001846 lpfc_drop_node(vport, ndlp);
James Smarta0f9b482006-04-15 11:52:56 -04001847 return NLP_STE_FREED_NODE;
1848 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001849 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001850}
1851
1852static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001853lpfc_cmpl_logo_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1854 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001855{
James Smartd7c255b2008-08-24 21:50:00 -04001856 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1857 if (ndlp->nlp_DID == Fabric_DID) {
1858 spin_lock_irq(shost->host_lock);
1859 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
1860 spin_unlock_irq(shost->host_lock);
1861 }
James Smart2e0fef82007-06-17 19:56:36 -05001862 lpfc_unreg_rpi(vport, ndlp);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001863 return ndlp->nlp_state;
1864}
1865
1866static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001867lpfc_cmpl_adisc_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1868 void *arg, uint32_t evt)
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001869{
1870 struct lpfc_iocbq *cmdiocb, *rspiocb;
James Smarta0f9b482006-04-15 11:52:56 -04001871 IOCB_t *irsp;
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001872
1873 cmdiocb = (struct lpfc_iocbq *) arg;
1874 rspiocb = cmdiocb->context_un.rsp_iocb;
James Smarta0f9b482006-04-15 11:52:56 -04001875
1876 irsp = &rspiocb->iocb;
1877 if (irsp->ulpStatus && (ndlp->nlp_flag & NLP_NODEV_REMOVE)) {
James Smart2e0fef82007-06-17 19:56:36 -05001878 lpfc_drop_node(vport, ndlp);
James Smarta0f9b482006-04-15 11:52:56 -04001879 return NLP_STE_FREED_NODE;
1880 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001881 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001882}
1883
1884static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001885lpfc_cmpl_reglogin_npr_node(struct lpfc_vport *vport,
1886 struct lpfc_nodelist *ndlp,
1887 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001888{
James Smart2e0fef82007-06-17 19:56:36 -05001889 LPFC_MBOXQ_t *pmb = (LPFC_MBOXQ_t *) arg;
1890 MAILBOX_t *mb = &pmb->mb;
dea31012005-04-17 16:05:31 -05001891
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001892 if (!mb->mbxStatus)
1893 ndlp->nlp_rpi = mb->un.varWords[0];
James Smarta0f9b482006-04-15 11:52:56 -04001894 else {
1895 if (ndlp->nlp_flag & NLP_NODEV_REMOVE) {
James Smart2e0fef82007-06-17 19:56:36 -05001896 lpfc_drop_node(vport, ndlp);
James Smarta0f9b482006-04-15 11:52:56 -04001897 return NLP_STE_FREED_NODE;
1898 }
1899 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001900 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001901}
1902
1903static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001904lpfc_device_rm_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1905 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001906{
James Smart2e0fef82007-06-17 19:56:36 -05001907 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1908
James Smarta0f9b482006-04-15 11:52:56 -04001909 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
James Smart2e0fef82007-06-17 19:56:36 -05001910 spin_lock_irq(shost->host_lock);
James Smarta0f9b482006-04-15 11:52:56 -04001911 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
James Smart2e0fef82007-06-17 19:56:36 -05001912 spin_unlock_irq(shost->host_lock);
James Smarta0f9b482006-04-15 11:52:56 -04001913 return ndlp->nlp_state;
1914 }
James Smart2e0fef82007-06-17 19:56:36 -05001915 lpfc_drop_node(vport, ndlp);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001916 return NLP_STE_FREED_NODE;
dea31012005-04-17 16:05:31 -05001917}
1918
1919static uint32_t
James Smart2e0fef82007-06-17 19:56:36 -05001920lpfc_device_recov_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1921 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05001922{
James Smart2e0fef82007-06-17 19:56:36 -05001923 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1924
James Smart92d7f7b2007-06-17 19:56:38 -05001925 /* Don't do anything that will mess up processing of the
1926 * previous RSCN.
1927 */
1928 if (vport->fc_flag & FC_RSCN_DEFERRED)
1929 return ndlp->nlp_state;
1930
James Smart2e0fef82007-06-17 19:56:36 -05001931 spin_lock_irq(shost->host_lock);
James Smarta0f9b482006-04-15 11:52:56 -04001932 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
James Smart2e0fef82007-06-17 19:56:36 -05001933 spin_unlock_irq(shost->host_lock);
James Smart0d2b6b82008-06-14 22:52:47 -04001934 lpfc_cancel_retry_delay_tmo(vport, ndlp);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001935 return ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001936}
1937
1938
1939/* This next section defines the NPort Discovery State Machine */
1940
1941/* There are 4 different double linked lists nodelist entries can reside on.
1942 * The plogi list and adisc list are used when Link Up discovery or RSCN
1943 * processing is needed. Each list holds the nodes that we will send PLOGI
1944 * or ADISC on. These lists will keep track of what nodes will be effected
1945 * by an RSCN, or a Link Up (Typically, all nodes are effected on Link Up).
1946 * The unmapped_list will contain all nodes that we have successfully logged
1947 * into at the Fibre Channel level. The mapped_list will contain all nodes
1948 * that are mapped FCP targets.
1949 */
1950/*
1951 * The bind list is a list of undiscovered (potentially non-existent) nodes
1952 * that we have saved binding information on. This information is used when
1953 * nodes transition from the unmapped to the mapped list.
1954 */
1955/* For UNUSED_NODE state, the node has just been allocated .
1956 * For PLOGI_ISSUE and REG_LOGIN_ISSUE, the node is on
1957 * the PLOGI list. For REG_LOGIN_COMPL, the node is taken off the PLOGI list
1958 * and put on the unmapped list. For ADISC processing, the node is taken off
1959 * the ADISC list and placed on either the mapped or unmapped list (depending
1960 * on its previous state). Once on the unmapped list, a PRLI is issued and the
1961 * state changed to PRLI_ISSUE. When the PRLI completion occurs, the state is
1962 * changed to UNMAPPED_NODE. If the completion indicates a mapped
1963 * node, the node is taken off the unmapped list. The binding list is checked
1964 * for a valid binding, or a binding is automatically assigned. If binding
1965 * assignment is unsuccessful, the node is left on the unmapped list. If
1966 * binding assignment is successful, the associated binding list entry (if
1967 * any) is removed, and the node is placed on the mapped list.
1968 */
1969/*
1970 * For a Link Down, all nodes on the ADISC, PLOGI, unmapped or mapped
James Smartc01f3202006-08-18 17:47:08 -04001971 * lists will receive a DEVICE_RECOVERY event. If the linkdown or devloss timers
dea31012005-04-17 16:05:31 -05001972 * expire, all effected nodes will receive a DEVICE_RM event.
1973 */
1974/*
1975 * For a Link Up or RSCN, all nodes will move from the mapped / unmapped lists
1976 * to either the ADISC or PLOGI list. After a Nameserver query or ALPA loopmap
1977 * check, additional nodes may be added or removed (via DEVICE_RM) to / from
1978 * the PLOGI or ADISC lists. Once the PLOGI and ADISC lists are populated,
1979 * we will first process the ADISC list. 32 entries are processed initially and
1980 * ADISC is initited for each one. Completions / Events for each node are
1981 * funnelled thru the state machine. As each node finishes ADISC processing, it
1982 * starts ADISC for any nodes waiting for ADISC processing. If no nodes are
1983 * waiting, and the ADISC list count is identically 0, then we are done. For
1984 * Link Up discovery, since all nodes on the PLOGI list are UNREG_LOGIN'ed, we
1985 * can issue a CLEAR_LA and reenable Link Events. Next we will process the PLOGI
1986 * list. 32 entries are processed initially and PLOGI is initited for each one.
1987 * Completions / Events for each node are funnelled thru the state machine. As
1988 * each node finishes PLOGI processing, it starts PLOGI for any nodes waiting
1989 * for PLOGI processing. If no nodes are waiting, and the PLOGI list count is
1990 * indentically 0, then we are done. We have now completed discovery / RSCN
1991 * handling. Upon completion, ALL nodes should be on either the mapped or
1992 * unmapped lists.
1993 */
1994
1995static uint32_t (*lpfc_disc_action[NLP_STE_MAX_STATE * NLP_EVT_MAX_EVENT])
James Smart2e0fef82007-06-17 19:56:36 -05001996 (struct lpfc_vport *, struct lpfc_nodelist *, void *, uint32_t) = {
dea31012005-04-17 16:05:31 -05001997 /* Action routine Event Current State */
1998 lpfc_rcv_plogi_unused_node, /* RCV_PLOGI UNUSED_NODE */
1999 lpfc_rcv_els_unused_node, /* RCV_PRLI */
2000 lpfc_rcv_logo_unused_node, /* RCV_LOGO */
2001 lpfc_rcv_els_unused_node, /* RCV_ADISC */
2002 lpfc_rcv_els_unused_node, /* RCV_PDISC */
2003 lpfc_rcv_els_unused_node, /* RCV_PRLO */
2004 lpfc_disc_illegal, /* CMPL_PLOGI */
2005 lpfc_disc_illegal, /* CMPL_PRLI */
2006 lpfc_cmpl_logo_unused_node, /* CMPL_LOGO */
2007 lpfc_disc_illegal, /* CMPL_ADISC */
2008 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2009 lpfc_device_rm_unused_node, /* DEVICE_RM */
2010 lpfc_disc_illegal, /* DEVICE_RECOVERY */
2011
2012 lpfc_rcv_plogi_plogi_issue, /* RCV_PLOGI PLOGI_ISSUE */
James Smart92d7f7b2007-06-17 19:56:38 -05002013 lpfc_rcv_prli_plogi_issue, /* RCV_PRLI */
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002014 lpfc_rcv_logo_plogi_issue, /* RCV_LOGO */
dea31012005-04-17 16:05:31 -05002015 lpfc_rcv_els_plogi_issue, /* RCV_ADISC */
2016 lpfc_rcv_els_plogi_issue, /* RCV_PDISC */
2017 lpfc_rcv_els_plogi_issue, /* RCV_PRLO */
2018 lpfc_cmpl_plogi_plogi_issue, /* CMPL_PLOGI */
2019 lpfc_disc_illegal, /* CMPL_PRLI */
James Smart0ff10d42008-01-11 01:52:36 -05002020 lpfc_cmpl_logo_plogi_issue, /* CMPL_LOGO */
dea31012005-04-17 16:05:31 -05002021 lpfc_disc_illegal, /* CMPL_ADISC */
James Smart0ff10d42008-01-11 01:52:36 -05002022 lpfc_cmpl_reglogin_plogi_issue,/* CMPL_REG_LOGIN */
dea31012005-04-17 16:05:31 -05002023 lpfc_device_rm_plogi_issue, /* DEVICE_RM */
2024 lpfc_device_recov_plogi_issue, /* DEVICE_RECOVERY */
2025
2026 lpfc_rcv_plogi_adisc_issue, /* RCV_PLOGI ADISC_ISSUE */
2027 lpfc_rcv_prli_adisc_issue, /* RCV_PRLI */
2028 lpfc_rcv_logo_adisc_issue, /* RCV_LOGO */
2029 lpfc_rcv_padisc_adisc_issue, /* RCV_ADISC */
2030 lpfc_rcv_padisc_adisc_issue, /* RCV_PDISC */
2031 lpfc_rcv_prlo_adisc_issue, /* RCV_PRLO */
2032 lpfc_disc_illegal, /* CMPL_PLOGI */
2033 lpfc_disc_illegal, /* CMPL_PRLI */
2034 lpfc_disc_illegal, /* CMPL_LOGO */
2035 lpfc_cmpl_adisc_adisc_issue, /* CMPL_ADISC */
2036 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2037 lpfc_device_rm_adisc_issue, /* DEVICE_RM */
2038 lpfc_device_recov_adisc_issue, /* DEVICE_RECOVERY */
2039
2040 lpfc_rcv_plogi_reglogin_issue, /* RCV_PLOGI REG_LOGIN_ISSUE */
2041 lpfc_rcv_prli_reglogin_issue, /* RCV_PLOGI */
2042 lpfc_rcv_logo_reglogin_issue, /* RCV_LOGO */
2043 lpfc_rcv_padisc_reglogin_issue, /* RCV_ADISC */
2044 lpfc_rcv_padisc_reglogin_issue, /* RCV_PDISC */
2045 lpfc_rcv_prlo_reglogin_issue, /* RCV_PRLO */
James Smart87af33f2007-10-27 13:37:43 -04002046 lpfc_cmpl_plogi_illegal, /* CMPL_PLOGI */
dea31012005-04-17 16:05:31 -05002047 lpfc_disc_illegal, /* CMPL_PRLI */
2048 lpfc_disc_illegal, /* CMPL_LOGO */
2049 lpfc_disc_illegal, /* CMPL_ADISC */
2050 lpfc_cmpl_reglogin_reglogin_issue,/* CMPL_REG_LOGIN */
2051 lpfc_device_rm_reglogin_issue, /* DEVICE_RM */
2052 lpfc_device_recov_reglogin_issue,/* DEVICE_RECOVERY */
2053
2054 lpfc_rcv_plogi_prli_issue, /* RCV_PLOGI PRLI_ISSUE */
2055 lpfc_rcv_prli_prli_issue, /* RCV_PRLI */
2056 lpfc_rcv_logo_prli_issue, /* RCV_LOGO */
2057 lpfc_rcv_padisc_prli_issue, /* RCV_ADISC */
2058 lpfc_rcv_padisc_prli_issue, /* RCV_PDISC */
2059 lpfc_rcv_prlo_prli_issue, /* RCV_PRLO */
James Smart87af33f2007-10-27 13:37:43 -04002060 lpfc_cmpl_plogi_illegal, /* CMPL_PLOGI */
dea31012005-04-17 16:05:31 -05002061 lpfc_cmpl_prli_prli_issue, /* CMPL_PRLI */
2062 lpfc_disc_illegal, /* CMPL_LOGO */
2063 lpfc_disc_illegal, /* CMPL_ADISC */
2064 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2065 lpfc_device_rm_prli_issue, /* DEVICE_RM */
2066 lpfc_device_recov_prli_issue, /* DEVICE_RECOVERY */
2067
2068 lpfc_rcv_plogi_unmap_node, /* RCV_PLOGI UNMAPPED_NODE */
2069 lpfc_rcv_prli_unmap_node, /* RCV_PRLI */
2070 lpfc_rcv_logo_unmap_node, /* RCV_LOGO */
2071 lpfc_rcv_padisc_unmap_node, /* RCV_ADISC */
2072 lpfc_rcv_padisc_unmap_node, /* RCV_PDISC */
2073 lpfc_rcv_prlo_unmap_node, /* RCV_PRLO */
2074 lpfc_disc_illegal, /* CMPL_PLOGI */
2075 lpfc_disc_illegal, /* CMPL_PRLI */
2076 lpfc_disc_illegal, /* CMPL_LOGO */
2077 lpfc_disc_illegal, /* CMPL_ADISC */
2078 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2079 lpfc_disc_illegal, /* DEVICE_RM */
2080 lpfc_device_recov_unmap_node, /* DEVICE_RECOVERY */
2081
2082 lpfc_rcv_plogi_mapped_node, /* RCV_PLOGI MAPPED_NODE */
2083 lpfc_rcv_prli_mapped_node, /* RCV_PRLI */
2084 lpfc_rcv_logo_mapped_node, /* RCV_LOGO */
2085 lpfc_rcv_padisc_mapped_node, /* RCV_ADISC */
2086 lpfc_rcv_padisc_mapped_node, /* RCV_PDISC */
2087 lpfc_rcv_prlo_mapped_node, /* RCV_PRLO */
2088 lpfc_disc_illegal, /* CMPL_PLOGI */
2089 lpfc_disc_illegal, /* CMPL_PRLI */
2090 lpfc_disc_illegal, /* CMPL_LOGO */
2091 lpfc_disc_illegal, /* CMPL_ADISC */
2092 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2093 lpfc_disc_illegal, /* DEVICE_RM */
2094 lpfc_device_recov_mapped_node, /* DEVICE_RECOVERY */
2095
2096 lpfc_rcv_plogi_npr_node, /* RCV_PLOGI NPR_NODE */
2097 lpfc_rcv_prli_npr_node, /* RCV_PRLI */
2098 lpfc_rcv_logo_npr_node, /* RCV_LOGO */
2099 lpfc_rcv_padisc_npr_node, /* RCV_ADISC */
2100 lpfc_rcv_padisc_npr_node, /* RCV_PDISC */
2101 lpfc_rcv_prlo_npr_node, /* RCV_PRLO */
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002102 lpfc_cmpl_plogi_npr_node, /* CMPL_PLOGI */
2103 lpfc_cmpl_prli_npr_node, /* CMPL_PRLI */
dea31012005-04-17 16:05:31 -05002104 lpfc_cmpl_logo_npr_node, /* CMPL_LOGO */
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002105 lpfc_cmpl_adisc_npr_node, /* CMPL_ADISC */
dea31012005-04-17 16:05:31 -05002106 lpfc_cmpl_reglogin_npr_node, /* CMPL_REG_LOGIN */
2107 lpfc_device_rm_npr_node, /* DEVICE_RM */
2108 lpfc_device_recov_npr_node, /* DEVICE_RECOVERY */
2109};
2110
2111int
James Smart2e0fef82007-06-17 19:56:36 -05002112lpfc_disc_state_machine(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2113 void *arg, uint32_t evt)
dea31012005-04-17 16:05:31 -05002114{
2115 uint32_t cur_state, rc;
James Smart2e0fef82007-06-17 19:56:36 -05002116 uint32_t(*func) (struct lpfc_vport *, struct lpfc_nodelist *, void *,
dea31012005-04-17 16:05:31 -05002117 uint32_t);
James Smarte47c9092008-02-08 18:49:26 -05002118 uint32_t got_ndlp = 0;
dea31012005-04-17 16:05:31 -05002119
James Smarte47c9092008-02-08 18:49:26 -05002120 if (lpfc_nlp_get(ndlp))
2121 got_ndlp = 1;
2122
dea31012005-04-17 16:05:31 -05002123 cur_state = ndlp->nlp_state;
2124
2125 /* DSM in event <evt> on NPort <nlp_DID> in state <cur_state> */
James Smarte8b62012007-08-02 11:10:09 -04002126 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2127 "0211 DSM in event x%x on NPort x%x in "
2128 "state %d Data: x%x\n",
2129 evt, ndlp->nlp_DID, cur_state, ndlp->nlp_flag);
dea31012005-04-17 16:05:31 -05002130
James Smart858c9f62007-06-17 19:56:39 -05002131 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_DSM,
2132 "DSM in: evt:%d ste:%d did:x%x",
2133 evt, cur_state, ndlp->nlp_DID);
2134
dea31012005-04-17 16:05:31 -05002135 func = lpfc_disc_action[(cur_state * NLP_EVT_MAX_EVENT) + evt];
James Smart2e0fef82007-06-17 19:56:36 -05002136 rc = (func) (vport, ndlp, arg, evt);
dea31012005-04-17 16:05:31 -05002137
2138 /* DSM out state <rc> on NPort <nlp_DID> */
James Smarte47c9092008-02-08 18:49:26 -05002139 if (got_ndlp) {
2140 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
James Smarte8b62012007-08-02 11:10:09 -04002141 "0212 DSM out state %d on NPort x%x Data: x%x\n",
2142 rc, ndlp->nlp_DID, ndlp->nlp_flag);
dea31012005-04-17 16:05:31 -05002143
James Smarte47c9092008-02-08 18:49:26 -05002144 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_DSM,
2145 "DSM out: ste:%d did:x%x flg:x%x",
2146 rc, ndlp->nlp_DID, ndlp->nlp_flag);
2147 /* Decrement the ndlp reference count held for this function */
2148 lpfc_nlp_put(ndlp);
2149 } else {
2150 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
James Smartd7c255b2008-08-24 21:50:00 -04002151 "0213 DSM out state %d on NPort free\n", rc);
James Smart858c9f62007-06-17 19:56:39 -05002152
James Smarte47c9092008-02-08 18:49:26 -05002153 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_DSM,
2154 "DSM out: ste:%d did:x%x flg:x%x",
2155 rc, 0, 0);
2156 }
dea31012005-04-17 16:05:31 -05002157
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002158 return rc;
dea31012005-04-17 16:05:31 -05002159}