]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - drivers/scsi/lpfc/lpfc_nportdisc.c
[SCSI] lpfc 8.3.2 : Addition of SLI4 Interface - Mailbox handling
[mirror_ubuntu-bionic-kernel.git] / drivers / scsi / lpfc / lpfc_nportdisc.c
CommitLineData
92d7f7b0 1 /*******************************************************************
dea3101e 2 * This file is part of the Emulex Linux Device Driver for *
c44ce173 3 * Fibre Channel Host Bus Adapters. *
e47c9093 4 * Copyright (C) 2004-2008 Emulex. All rights reserved. *
c44ce173 5 * EMULEX and SLI are trademarks of Emulex. *
dea3101e 6 * www.emulex.com *
c44ce173 7 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
dea3101e
JB
8 * *
9 * This program is free software; you can redistribute it and/or *
c44ce173
JSEC
10 * 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. *
dea3101e
JB
20 *******************************************************************/
21
dea3101e
JB
22#include <linux/blkdev.h>
23#include <linux/pci.h>
24#include <linux/interrupt.h>
25
91886523 26#include <scsi/scsi.h>
dea3101e
JB
27#include <scsi/scsi_device.h>
28#include <scsi/scsi_host.h>
29#include <scsi/scsi_transport_fc.h>
30
da0436e9 31#include "lpfc_hw4.h"
dea3101e
JB
32#include "lpfc_hw.h"
33#include "lpfc_sli.h"
da0436e9 34#include "lpfc_sli4.h"
ea2151b4 35#include "lpfc_nl.h"
dea3101e
JB
36#include "lpfc_disc.h"
37#include "lpfc_scsi.h"
38#include "lpfc.h"
39#include "lpfc_logmsg.h"
40#include "lpfc_crtn.h"
92d7f7b0 41#include "lpfc_vport.h"
858c9f6c 42#include "lpfc_debugfs.h"
dea3101e
JB
43
44
45/* Called to verify a rcv'ed ADISC was intended for us. */
46static int
2e0fef85
JS
47lpfc_check_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
48 struct lpfc_name *nn, struct lpfc_name *pn)
dea3101e
JB
49{
50 /* Compare the ADISC rsp WWNN / WWPN matches our internal node
51 * table entry for that node.
52 */
2e0fef85 53 if (memcmp(nn, &ndlp->nlp_nodename, sizeof (struct lpfc_name)))
c9f8735b 54 return 0;
dea3101e 55
2e0fef85 56 if (memcmp(pn, &ndlp->nlp_portname, sizeof (struct lpfc_name)))
c9f8735b 57 return 0;
dea3101e
JB
58
59 /* we match, return success */
c9f8735b 60 return 1;
dea3101e
JB
61}
62
dea3101e 63int
2e0fef85
JS
64lpfc_check_sparm(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
65 struct serv_parm * sp, uint32_t class)
dea3101e 66{
2e0fef85 67 volatile struct serv_parm *hsp = &vport->fc_sparam;
2fb70f79
JSEC
68 uint16_t hsp_value, ssp_value = 0;
69
70 /*
71 * The receive data field size and buffer-to-buffer receive data field
72 * size entries are 16 bits but are represented as two 8-bit fields in
73 * the driver data structure to account for rsvd bits and other control
74 * bits. Reconstruct and compare the fields as a 16-bit values before
75 * correcting the byte values.
76 */
dea3101e 77 if (sp->cls1.classValid) {
2fb70f79
JSEC
78 hsp_value = (hsp->cls1.rcvDataSizeMsb << 8) |
79 hsp->cls1.rcvDataSizeLsb;
80 ssp_value = (sp->cls1.rcvDataSizeMsb << 8) |
81 sp->cls1.rcvDataSizeLsb;
92d7f7b0
JS
82 if (!ssp_value)
83 goto bad_service_param;
2fb70f79 84 if (ssp_value > hsp_value) {
dea3101e 85 sp->cls1.rcvDataSizeLsb = hsp->cls1.rcvDataSizeLsb;
2fb70f79
JSEC
86 sp->cls1.rcvDataSizeMsb = hsp->cls1.rcvDataSizeMsb;
87 }
dea3101e 88 } else if (class == CLASS1) {
92d7f7b0 89 goto bad_service_param;
dea3101e
JB
90 }
91
92 if (sp->cls2.classValid) {
2fb70f79
JSEC
93 hsp_value = (hsp->cls2.rcvDataSizeMsb << 8) |
94 hsp->cls2.rcvDataSizeLsb;
95 ssp_value = (sp->cls2.rcvDataSizeMsb << 8) |
96 sp->cls2.rcvDataSizeLsb;
92d7f7b0
JS
97 if (!ssp_value)
98 goto bad_service_param;
2fb70f79 99 if (ssp_value > hsp_value) {
dea3101e 100 sp->cls2.rcvDataSizeLsb = hsp->cls2.rcvDataSizeLsb;
2fb70f79
JSEC
101 sp->cls2.rcvDataSizeMsb = hsp->cls2.rcvDataSizeMsb;
102 }
dea3101e 103 } else if (class == CLASS2) {
92d7f7b0 104 goto bad_service_param;
dea3101e
JB
105 }
106
107 if (sp->cls3.classValid) {
2fb70f79
JSEC
108 hsp_value = (hsp->cls3.rcvDataSizeMsb << 8) |
109 hsp->cls3.rcvDataSizeLsb;
110 ssp_value = (sp->cls3.rcvDataSizeMsb << 8) |
111 sp->cls3.rcvDataSizeLsb;
92d7f7b0
JS
112 if (!ssp_value)
113 goto bad_service_param;
2fb70f79 114 if (ssp_value > hsp_value) {
dea3101e 115 sp->cls3.rcvDataSizeLsb = hsp->cls3.rcvDataSizeLsb;
2fb70f79
JSEC
116 sp->cls3.rcvDataSizeMsb = hsp->cls3.rcvDataSizeMsb;
117 }
dea3101e 118 } else if (class == CLASS3) {
92d7f7b0 119 goto bad_service_param;
dea3101e
JB
120 }
121
2fb70f79
JSEC
122 /*
123 * Preserve the upper four bits of the MSB from the PLOGI response.
124 * These bits contain the Buffer-to-Buffer State Change Number
125 * from the target and need to be passed to the FW.
126 */
127 hsp_value = (hsp->cmn.bbRcvSizeMsb << 8) | hsp->cmn.bbRcvSizeLsb;
128 ssp_value = (sp->cmn.bbRcvSizeMsb << 8) | sp->cmn.bbRcvSizeLsb;
129 if (ssp_value > hsp_value) {
dea3101e 130 sp->cmn.bbRcvSizeLsb = hsp->cmn.bbRcvSizeLsb;
2fb70f79
JSEC
131 sp->cmn.bbRcvSizeMsb = (sp->cmn.bbRcvSizeMsb & 0xF0) |
132 (hsp->cmn.bbRcvSizeMsb & 0x0F);
133 }
dea3101e 134
dea3101e
JB
135 memcpy(&ndlp->nlp_nodename, &sp->nodeName, sizeof (struct lpfc_name));
136 memcpy(&ndlp->nlp_portname, &sp->portName, sizeof (struct lpfc_name));
2fb70f79 137 return 1;
92d7f7b0 138bad_service_param:
e8b62011
JS
139 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
140 "0207 Device %x "
141 "(%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x) sent "
142 "invalid service parameters. Ignoring device.\n",
143 ndlp->nlp_DID,
144 sp->nodeName.u.wwn[0], sp->nodeName.u.wwn[1],
145 sp->nodeName.u.wwn[2], sp->nodeName.u.wwn[3],
146 sp->nodeName.u.wwn[4], sp->nodeName.u.wwn[5],
147 sp->nodeName.u.wwn[6], sp->nodeName.u.wwn[7]);
92d7f7b0 148 return 0;
dea3101e
JB
149}
150
151static void *
2e0fef85 152lpfc_check_elscmpl_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
92d7f7b0 153 struct lpfc_iocbq *rspiocb)
dea3101e
JB
154{
155 struct lpfc_dmabuf *pcmd, *prsp;
156 uint32_t *lp;
157 void *ptr = NULL;
158 IOCB_t *irsp;
159
160 irsp = &rspiocb->iocb;
161 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
162
163 /* For lpfc_els_abort, context2 could be zero'ed to delay
164 * freeing associated memory till after ABTS completes.
165 */
166 if (pcmd) {
167 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf,
168 list);
169 if (prsp) {
170 lp = (uint32_t *) prsp->virt;
171 ptr = (void *)((uint8_t *)lp + sizeof(uint32_t));
172 }
2fe165b6 173 } else {
dea3101e
JB
174 /* Force ulpStatus error since we are returning NULL ptr */
175 if (!(irsp->ulpStatus)) {
176 irsp->ulpStatus = IOSTAT_LOCAL_REJECT;
177 irsp->un.ulpWord[4] = IOERR_SLI_ABORTED;
178 }
179 ptr = NULL;
180 }
c9f8735b 181 return ptr;
dea3101e
JB
182}
183
184
185/*
186 * Free resources / clean up outstanding I/Os
187 * associated with a LPFC_NODELIST entry. This
188 * routine effectively results in a "software abort".
189 */
190int
2e0fef85 191lpfc_els_abort(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp)
dea3101e 192{
2534ba75 193 LIST_HEAD(completions);
2e0fef85
JS
194 struct lpfc_sli *psli = &phba->sli;
195 struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING];
dea3101e 196 struct lpfc_iocbq *iocb, *next_iocb;
dea3101e
JB
197
198 /* Abort outstanding I/O on NPort <nlp_DID> */
e8b62011
JS
199 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_DISCOVERY,
200 "0205 Abort outstanding I/O on NPort x%x "
201 "Data: x%x x%x x%x\n",
202 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
203 ndlp->nlp_rpi);
92d7f7b0
JS
204
205 lpfc_fabric_abort_nport(ndlp);
dea3101e 206
dea3101e 207 /* First check the txq */
2e0fef85 208 spin_lock_irq(&phba->hbalock);
2534ba75 209 list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
858c9f6c 210 /* Check to see if iocb matches the nport we are looking for */
2534ba75 211 if (lpfc_check_sli_ndlp(phba, pring, iocb, ndlp)) {
858c9f6c 212 /* It matches, so deque and call compl with anp error */
2534ba75
JS
213 list_move_tail(&iocb->list, &completions);
214 pring->txq_cnt--;
dea3101e 215 }
2534ba75 216 }
dea3101e 217
dea3101e 218 /* Next check the txcmplq */
07951076 219 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
858c9f6c 220 /* Check to see if iocb matches the nport we are looking for */
92d7f7b0 221 if (lpfc_check_sli_ndlp(phba, pring, iocb, ndlp)) {
07951076 222 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
92d7f7b0 223 }
07951076 224 }
2e0fef85 225 spin_unlock_irq(&phba->hbalock);
dea3101e 226
a257bf90
JS
227 /* Cancel all the IOCBs from the completions list */
228 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
229 IOERR_SLI_ABORTED);
2534ba75 230
0d2b6b83 231 lpfc_cancel_retry_delay_tmo(phba->pport, ndlp);
c9f8735b 232 return 0;
dea3101e
JB
233}
234
235static int
2e0fef85 236lpfc_rcv_plogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
92d7f7b0 237 struct lpfc_iocbq *cmdiocb)
dea3101e 238{
2e0fef85
JS
239 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
240 struct lpfc_hba *phba = vport->phba;
dea3101e
JB
241 struct lpfc_dmabuf *pcmd;
242 uint32_t *lp;
243 IOCB_t *icmd;
244 struct serv_parm *sp;
245 LPFC_MBOXQ_t *mbox;
246 struct ls_rjt stat;
247 int rc;
248
249 memset(&stat, 0, sizeof (struct ls_rjt));
2e0fef85 250 if (vport->port_state <= LPFC_FLOGI) {
dea3101e
JB
251 /* Before responding to PLOGI, check for pt2pt mode.
252 * If we are pt2pt, with an outstanding FLOGI, abort
253 * the FLOGI and resend it first.
254 */
2e0fef85 255 if (vport->fc_flag & FC_PT2PT) {
92d7f7b0 256 lpfc_els_abort_flogi(phba);
2e0fef85 257 if (!(vport->fc_flag & FC_PT2PT_PLOGI)) {
dea3101e
JB
258 /* If the other side is supposed to initiate
259 * the PLOGI anyway, just ACC it now and
260 * move on with discovery.
261 */
262 phba->fc_edtov = FF_DEF_EDTOV;
263 phba->fc_ratov = FF_DEF_RATOV;
264 /* Start discovery - this should just do
265 CLEAR_LA */
2e0fef85 266 lpfc_disc_start(vport);
ed957684 267 } else
2e0fef85 268 lpfc_initial_flogi(vport);
2fe165b6 269 } else {
dea3101e
JB
270 stat.un.b.lsRjtRsnCode = LSRJT_LOGICAL_BSY;
271 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
2e0fef85 272 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb,
858c9f6c 273 ndlp, NULL);
dea3101e
JB
274 return 0;
275 }
276 }
277 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
278 lp = (uint32_t *) pcmd->virt;
279 sp = (struct serv_parm *) ((uint8_t *) lp + sizeof (uint32_t));
a8adb832
JS
280 if (wwn_to_u64(sp->portName.u.wwn) == 0) {
281 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
282 "0140 PLOGI Reject: invalid nname\n");
283 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
284 stat.un.b.lsRjtRsnCodeExp = LSEXP_INVALID_PNAME;
285 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
286 NULL);
287 return 0;
288 }
289 if (wwn_to_u64(sp->nodeName.u.wwn) == 0) {
290 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
291 "0141 PLOGI Reject: invalid pname\n");
292 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
293 stat.un.b.lsRjtRsnCodeExp = LSEXP_INVALID_NNAME;
294 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
295 NULL);
296 return 0;
297 }
2e0fef85 298 if ((lpfc_check_sparm(vport, ndlp, sp, CLASS3) == 0)) {
dea3101e
JB
299 /* Reject this request because invalid parameters */
300 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
301 stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
858c9f6c
JS
302 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
303 NULL);
c9f8735b 304 return 0;
dea3101e
JB
305 }
306 icmd = &cmdiocb->iocb;
307
308 /* PLOGI chkparm OK */
e8b62011
JS
309 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
310 "0114 PLOGI chkparm OK Data: x%x x%x x%x x%x\n",
311 ndlp->nlp_DID, ndlp->nlp_state, ndlp->nlp_flag,
312 ndlp->nlp_rpi);
dea3101e 313
3de2a653 314 if (vport->cfg_fcp_class == 2 && sp->cls2.classValid)
dea3101e 315 ndlp->nlp_fcp_info |= CLASS2;
ed957684 316 else
dea3101e 317 ndlp->nlp_fcp_info |= CLASS3;
2e0fef85 318
dea3101e
JB
319 ndlp->nlp_class_sup = 0;
320 if (sp->cls1.classValid)
321 ndlp->nlp_class_sup |= FC_COS_CLASS1;
322 if (sp->cls2.classValid)
323 ndlp->nlp_class_sup |= FC_COS_CLASS2;
324 if (sp->cls3.classValid)
325 ndlp->nlp_class_sup |= FC_COS_CLASS3;
326 if (sp->cls4.classValid)
327 ndlp->nlp_class_sup |= FC_COS_CLASS4;
328 ndlp->nlp_maxframe =
329 ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) | sp->cmn.bbRcvSizeLsb;
330
331 /* no need to reg_login if we are already in one of these states */
2fe165b6 332 switch (ndlp->nlp_state) {
dea3101e
JB
333 case NLP_STE_NPR_NODE:
334 if (!(ndlp->nlp_flag & NLP_NPR_ADISC))
335 break;
336 case NLP_STE_REG_LOGIN_ISSUE:
337 case NLP_STE_PRLI_ISSUE:
338 case NLP_STE_UNMAPPED_NODE:
339 case NLP_STE_MAPPED_NODE:
51ef4c26 340 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp, NULL);
c9f8735b 341 return 1;
dea3101e
JB
342 }
343
92d7f7b0
JS
344 if ((vport->fc_flag & FC_PT2PT) &&
345 !(vport->fc_flag & FC_PT2PT_PLOGI)) {
dea3101e 346 /* rcv'ed PLOGI decides what our NPortId will be */
2e0fef85 347 vport->fc_myDID = icmd->un.rcvels.parmRo;
dea3101e
JB
348 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
349 if (mbox == NULL)
350 goto out;
351 lpfc_config_link(phba, mbox);
352 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
ed957684 353 mbox->vport = vport;
0b727fea 354 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
dea3101e 355 if (rc == MBX_NOT_FINISHED) {
92d7f7b0 356 mempool_free(mbox, phba->mbox_mem_pool);
dea3101e
JB
357 goto out;
358 }
359
2e0fef85 360 lpfc_can_disctmo(vport);
dea3101e
JB
361 }
362 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2e0fef85 363 if (!mbox)
dea3101e
JB
364 goto out;
365
92d7f7b0
JS
366 rc = lpfc_reg_login(phba, vport->vpi, icmd->un.rcvels.remoteID,
367 (uint8_t *) sp, mbox, 0);
2e0fef85
JS
368 if (rc) {
369 mempool_free(mbox, phba->mbox_mem_pool);
dea3101e
JB
370 goto out;
371 }
372
373 /* ACC PLOGI rsp command needs to execute first,
374 * queue this mbox command to be processed later.
375 */
376 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
329f9bc7
JS
377 /*
378 * mbox->context2 = lpfc_nlp_get(ndlp) deferred until mailbox
379 * command issued in lpfc_cmpl_els_acc().
380 */
2e0fef85
JS
381 mbox->vport = vport;
382 spin_lock_irq(shost->host_lock);
5024ab17 383 ndlp->nlp_flag |= (NLP_ACC_REGLOGIN | NLP_RCV_PLOGI);
2e0fef85 384 spin_unlock_irq(shost->host_lock);
dea3101e 385
33ccf8d1
JS
386 /*
387 * If there is an outstanding PLOGI issued, abort it before
388 * sending ACC rsp for received PLOGI. If pending plogi
389 * is not canceled here, the plogi will be rejected by
390 * remote port and will be retried. On a configuration with
391 * single discovery thread, this will cause a huge delay in
392 * discovery. Also this will cause multiple state machines
393 * running in parallel for this node.
394 */
395 if (ndlp->nlp_state == NLP_STE_PLOGI_ISSUE) {
396 /* software abort outstanding PLOGI */
07951076 397 lpfc_els_abort(phba, ndlp);
33ccf8d1
JS
398 }
399
858c9f6c 400 if ((vport->port_type == LPFC_NPIV_PORT &&
3de2a653 401 vport->cfg_restrict_login)) {
858c9f6c
JS
402
403 /* In order to preserve RPIs, we want to cleanup
404 * the default RPI the firmware created to rcv
405 * this ELS request. The only way to do this is
406 * to register, then unregister the RPI.
407 */
408 spin_lock_irq(shost->host_lock);
409 ndlp->nlp_flag |= NLP_RM_DFLT_RPI;
410 spin_unlock_irq(shost->host_lock);
411 stat.un.b.lsRjtRsnCode = LSRJT_INVALID_CMD;
412 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
413 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb,
414 ndlp, mbox);
415 return 1;
416 }
51ef4c26 417 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp, mbox);
c9f8735b 418 return 1;
dea3101e
JB
419out:
420 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
421 stat.un.b.lsRjtRsnCodeExp = LSEXP_OUT_OF_RESOURCE;
858c9f6c 422 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
c9f8735b 423 return 0;
dea3101e
JB
424}
425
426static int
2e0fef85 427lpfc_rcv_padisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea3101e
JB
428 struct lpfc_iocbq *cmdiocb)
429{
2e0fef85 430 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea3101e 431 struct lpfc_dmabuf *pcmd;
2e0fef85
JS
432 struct serv_parm *sp;
433 struct lpfc_name *pnn, *ppn;
dea3101e
JB
434 struct ls_rjt stat;
435 ADISC *ap;
436 IOCB_t *icmd;
437 uint32_t *lp;
438 uint32_t cmd;
439
440 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
441 lp = (uint32_t *) pcmd->virt;
442
443 cmd = *lp++;
444 if (cmd == ELS_CMD_ADISC) {
445 ap = (ADISC *) lp;
446 pnn = (struct lpfc_name *) & ap->nodeName;
447 ppn = (struct lpfc_name *) & ap->portName;
448 } else {
449 sp = (struct serv_parm *) lp;
450 pnn = (struct lpfc_name *) & sp->nodeName;
451 ppn = (struct lpfc_name *) & sp->portName;
452 }
453
454 icmd = &cmdiocb->iocb;
2e0fef85 455 if (icmd->ulpStatus == 0 && lpfc_check_adisc(vport, ndlp, pnn, ppn)) {
dea3101e 456 if (cmd == ELS_CMD_ADISC) {
2e0fef85 457 lpfc_els_rsp_adisc_acc(vport, cmdiocb, ndlp);
2fe165b6 458 } else {
2e0fef85 459 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp,
51ef4c26 460 NULL);
dea3101e 461 }
c9f8735b 462 return 1;
dea3101e
JB
463 }
464 /* Reject this request because invalid parameters */
465 stat.un.b.lsRjtRsvd0 = 0;
466 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
467 stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
468 stat.un.b.vendorUnique = 0;
858c9f6c 469 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
dea3101e 470
dea3101e
JB
471 /* 1 sec timeout */
472 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ);
473
2e0fef85 474 spin_lock_irq(shost->host_lock);
dea3101e 475 ndlp->nlp_flag |= NLP_DELAY_TMO;
2e0fef85 476 spin_unlock_irq(shost->host_lock);
5024ab17
JW
477 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
478 ndlp->nlp_prev_state = ndlp->nlp_state;
2e0fef85 479 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
c9f8735b 480 return 0;
dea3101e
JB
481}
482
483static int
2e0fef85
JS
484lpfc_rcv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
485 struct lpfc_iocbq *cmdiocb, uint32_t els_cmd)
dea3101e 486{
2e0fef85
JS
487 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
488
489 /* Put ndlp in NPR state with 1 sec timeout for plogi, ACC logo */
dea3101e
JB
490 /* Only call LOGO ACC for first LOGO, this avoids sending unnecessary
491 * PLOGIs during LOGO storms from a device.
492 */
2e0fef85 493 spin_lock_irq(shost->host_lock);
dea3101e 494 ndlp->nlp_flag |= NLP_LOGO_ACC;
2e0fef85 495 spin_unlock_irq(shost->host_lock);
82d9a2a2 496 if (els_cmd == ELS_CMD_PRLO)
51ef4c26 497 lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL);
82d9a2a2 498 else
51ef4c26 499 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea3101e 500
0d2b6b83
JS
501 if ((!(ndlp->nlp_type & NLP_FABRIC) &&
502 ((ndlp->nlp_type & NLP_FCP_TARGET) ||
503 !(ndlp->nlp_type & NLP_FCP_INITIATOR))) ||
92d7f7b0 504 (ndlp->nlp_state == NLP_STE_ADISC_ISSUE)) {
dea3101e 505 /* Only try to re-login if this is NOT a Fabric Node */
dea3101e 506 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ * 1);
2e0fef85 507 spin_lock_irq(shost->host_lock);
dea3101e 508 ndlp->nlp_flag |= NLP_DELAY_TMO;
2e0fef85 509 spin_unlock_irq(shost->host_lock);
dea3101e 510
5024ab17 511 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
c9f8735b 512 }
87af33fe
JS
513 ndlp->nlp_prev_state = ndlp->nlp_state;
514 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
dea3101e 515
2e0fef85 516 spin_lock_irq(shost->host_lock);
dea3101e 517 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
2e0fef85 518 spin_unlock_irq(shost->host_lock);
dea3101e
JB
519 /* The driver has to wait until the ACC completes before it continues
520 * processing the LOGO. The action will resume in
521 * lpfc_cmpl_els_logo_acc routine. Since part of processing includes an
522 * unreg_login, the driver waits so the ACC does not get aborted.
523 */
c9f8735b 524 return 0;
dea3101e
JB
525}
526
527static void
2e0fef85
JS
528lpfc_rcv_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
529 struct lpfc_iocbq *cmdiocb)
dea3101e
JB
530{
531 struct lpfc_dmabuf *pcmd;
532 uint32_t *lp;
533 PRLI *npr;
534 struct fc_rport *rport = ndlp->rport;
535 u32 roles;
536
537 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
538 lp = (uint32_t *) pcmd->virt;
539 npr = (PRLI *) ((uint8_t *) lp + sizeof (uint32_t));
540
541 ndlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR);
542 ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
92d7f7b0 543 if (npr->prliType == PRLI_FCP_TYPE) {
dea3101e
JB
544 if (npr->initiatorFunc)
545 ndlp->nlp_type |= NLP_FCP_INITIATOR;
546 if (npr->targetFunc)
547 ndlp->nlp_type |= NLP_FCP_TARGET;
548 if (npr->Retry)
549 ndlp->nlp_fcp_info |= NLP_FCP_2_DEVICE;
550 }
551 if (rport) {
552 /* We need to update the rport role values */
553 roles = FC_RPORT_ROLE_UNKNOWN;
554 if (ndlp->nlp_type & NLP_FCP_INITIATOR)
555 roles |= FC_RPORT_ROLE_FCP_INITIATOR;
556 if (ndlp->nlp_type & NLP_FCP_TARGET)
557 roles |= FC_RPORT_ROLE_FCP_TARGET;
858c9f6c
JS
558
559 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
560 "rport rolechg: role:x%x did:x%x flg:x%x",
561 roles, ndlp->nlp_DID, ndlp->nlp_flag);
562
dea3101e
JB
563 fc_remote_port_rolechg(rport, roles);
564 }
565}
566
567static uint32_t
2e0fef85 568lpfc_disc_set_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
dea3101e 569{
2e0fef85 570 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2e0fef85 571
51ef4c26
JS
572 if (!ndlp->nlp_rpi) {
573 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
574 return 0;
575 }
576
1b32f6aa
JS
577 if (!(vport->fc_flag & FC_PT2PT)) {
578 /* Check config parameter use-adisc or FCP-2 */
579 if ((vport->cfg_use_adisc && (vport->fc_flag & FC_RSCN_MODE)) ||
580 ndlp->nlp_fcp_info & NLP_FCP_2_DEVICE) {
581 spin_lock_irq(shost->host_lock);
582 ndlp->nlp_flag |= NLP_NPR_ADISC;
583 spin_unlock_irq(shost->host_lock);
584 return 1;
585 }
92d7f7b0
JS
586 }
587 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
588 lpfc_unreg_rpi(vport, ndlp);
589 return 0;
dea3101e
JB
590}
591
592static uint32_t
2e0fef85
JS
593lpfc_disc_illegal(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
594 void *arg, uint32_t evt)
dea3101e 595{
e8b62011 596 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
e47c9093 597 "0271 Illegal State Transition: node x%x "
e8b62011
JS
598 "event x%x, state x%x Data: x%x x%x\n",
599 ndlp->nlp_DID, evt, ndlp->nlp_state, ndlp->nlp_rpi,
600 ndlp->nlp_flag);
c9f8735b 601 return ndlp->nlp_state;
dea3101e
JB
602}
603
87af33fe
JS
604static uint32_t
605lpfc_cmpl_plogi_illegal(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
606 void *arg, uint32_t evt)
607{
608 /* This transition is only legal if we previously
609 * rcv'ed a PLOGI. Since we don't want 2 discovery threads
610 * working on the same NPortID, do nothing for this thread
611 * to stop it.
612 */
613 if (!(ndlp->nlp_flag & NLP_RCV_PLOGI)) {
614 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
e47c9093 615 "0272 Illegal State Transition: node x%x "
87af33fe
JS
616 "event x%x, state x%x Data: x%x x%x\n",
617 ndlp->nlp_DID, evt, ndlp->nlp_state, ndlp->nlp_rpi,
618 ndlp->nlp_flag);
619 }
620 return ndlp->nlp_state;
621}
622
dea3101e
JB
623/* Start of Discovery State Machine routines */
624
625static uint32_t
2e0fef85
JS
626lpfc_rcv_plogi_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
627 void *arg, uint32_t evt)
dea3101e
JB
628{
629 struct lpfc_iocbq *cmdiocb;
630
631 cmdiocb = (struct lpfc_iocbq *) arg;
632
2e0fef85 633 if (lpfc_rcv_plogi(vport, ndlp, cmdiocb)) {
c9f8735b 634 return ndlp->nlp_state;
dea3101e 635 }
c9f8735b 636 return NLP_STE_FREED_NODE;
dea3101e
JB
637}
638
639static uint32_t
2e0fef85
JS
640lpfc_rcv_els_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
641 void *arg, uint32_t evt)
dea3101e 642{
2e0fef85 643 lpfc_issue_els_logo(vport, ndlp, 0);
c9f8735b 644 return ndlp->nlp_state;
dea3101e
JB
645}
646
647static uint32_t
2e0fef85
JS
648lpfc_rcv_logo_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
649 void *arg, uint32_t evt)
dea3101e 650{
2e0fef85
JS
651 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
652 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea3101e 653
2e0fef85 654 spin_lock_irq(shost->host_lock);
dea3101e 655 ndlp->nlp_flag |= NLP_LOGO_ACC;
2e0fef85 656 spin_unlock_irq(shost->host_lock);
51ef4c26 657 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea3101e 658
c9f8735b 659 return ndlp->nlp_state;
dea3101e
JB
660}
661
662static uint32_t
2e0fef85
JS
663lpfc_cmpl_logo_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
664 void *arg, uint32_t evt)
dea3101e 665{
c9f8735b 666 return NLP_STE_FREED_NODE;
dea3101e
JB
667}
668
669static uint32_t
2e0fef85
JS
670lpfc_device_rm_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
671 void *arg, uint32_t evt)
dea3101e 672{
c9f8735b 673 return NLP_STE_FREED_NODE;
dea3101e
JB
674}
675
676static uint32_t
2e0fef85 677lpfc_rcv_plogi_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea3101e
JB
678 void *arg, uint32_t evt)
679{
0d2b6b83 680 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2e0fef85 681 struct lpfc_hba *phba = vport->phba;
dea3101e 682 struct lpfc_iocbq *cmdiocb = arg;
2e0fef85
JS
683 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
684 uint32_t *lp = (uint32_t *) pcmd->virt;
685 struct serv_parm *sp = (struct serv_parm *) (lp + 1);
dea3101e
JB
686 struct ls_rjt stat;
687 int port_cmp;
688
dea3101e
JB
689 memset(&stat, 0, sizeof (struct ls_rjt));
690
691 /* For a PLOGI, we only accept if our portname is less
692 * than the remote portname.
693 */
694 phba->fc_stat.elsLogiCol++;
2e0fef85 695 port_cmp = memcmp(&vport->fc_portname, &sp->portName,
92d7f7b0 696 sizeof(struct lpfc_name));
dea3101e
JB
697
698 if (port_cmp >= 0) {
699 /* Reject this request because the remote node will accept
700 ours */
701 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
702 stat.un.b.lsRjtRsnCodeExp = LSEXP_CMD_IN_PROGRESS;
858c9f6c
JS
703 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
704 NULL);
2fe165b6 705 } else {
0d2b6b83
JS
706 if (lpfc_rcv_plogi(vport, ndlp, cmdiocb) &&
707 (ndlp->nlp_flag & NLP_NPR_2B_DISC) &&
708 (vport->num_disc_nodes)) {
709 spin_lock_irq(shost->host_lock);
710 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
711 spin_unlock_irq(shost->host_lock);
712 /* Check if there are more PLOGIs to be sent */
713 lpfc_more_plogi(vport);
714 if (vport->num_disc_nodes == 0) {
715 spin_lock_irq(shost->host_lock);
716 vport->fc_flag &= ~FC_NDISC_ACTIVE;
717 spin_unlock_irq(shost->host_lock);
718 lpfc_can_disctmo(vport);
719 lpfc_end_rscn(vport);
720 }
721 }
2e0fef85 722 } /* If our portname was less */
dea3101e 723
c9f8735b
JW
724 return ndlp->nlp_state;
725}
726
92d7f7b0
JS
727static uint32_t
728lpfc_rcv_prli_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
729 void *arg, uint32_t evt)
730{
731 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
732 struct ls_rjt stat;
733
734 memset(&stat, 0, sizeof (struct ls_rjt));
735 stat.un.b.lsRjtRsnCode = LSRJT_LOGICAL_BSY;
736 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
858c9f6c 737 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
92d7f7b0
JS
738 return ndlp->nlp_state;
739}
740
c9f8735b 741static uint32_t
2e0fef85
JS
742lpfc_rcv_logo_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
743 void *arg, uint32_t evt)
c9f8735b 744{
2e0fef85 745 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
c9f8735b 746
92d7f7b0 747 /* software abort outstanding PLOGI */
2e0fef85 748 lpfc_els_abort(vport->phba, ndlp);
c9f8735b 749
2e0fef85 750 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
c9f8735b 751 return ndlp->nlp_state;
dea3101e
JB
752}
753
754static uint32_t
2e0fef85
JS
755lpfc_rcv_els_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
756 void *arg, uint32_t evt)
dea3101e 757{
2e0fef85
JS
758 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
759 struct lpfc_hba *phba = vport->phba;
760 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea3101e
JB
761
762 /* software abort outstanding PLOGI */
07951076 763 lpfc_els_abort(phba, ndlp);
dea3101e
JB
764
765 if (evt == NLP_EVT_RCV_LOGO) {
51ef4c26 766 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
2fe165b6 767 } else {
2e0fef85 768 lpfc_issue_els_logo(vport, ndlp, 0);
dea3101e
JB
769 }
770
2e0fef85 771 /* Put ndlp in npr state set plogi timer for 1 sec */
5024ab17 772 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ * 1);
2e0fef85 773 spin_lock_irq(shost->host_lock);
5024ab17 774 ndlp->nlp_flag |= NLP_DELAY_TMO;
2e0fef85 775 spin_unlock_irq(shost->host_lock);
5024ab17
JW
776 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
777 ndlp->nlp_prev_state = NLP_STE_PLOGI_ISSUE;
2e0fef85 778 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
dea3101e 779
c9f8735b 780 return ndlp->nlp_state;
dea3101e
JB
781}
782
783static uint32_t
2e0fef85
JS
784lpfc_cmpl_plogi_plogi_issue(struct lpfc_vport *vport,
785 struct lpfc_nodelist *ndlp,
786 void *arg,
dea3101e
JB
787 uint32_t evt)
788{
2e0fef85 789 struct lpfc_hba *phba = vport->phba;
0ff10d46 790 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2e0fef85 791 struct lpfc_iocbq *cmdiocb, *rspiocb;
14691150 792 struct lpfc_dmabuf *pcmd, *prsp, *mp;
dea3101e
JB
793 uint32_t *lp;
794 IOCB_t *irsp;
795 struct serv_parm *sp;
796 LPFC_MBOXQ_t *mbox;
797
798 cmdiocb = (struct lpfc_iocbq *) arg;
799 rspiocb = cmdiocb->context_un.rsp_iocb;
800
801 if (ndlp->nlp_flag & NLP_ACC_REGLOGIN) {
5024ab17 802 /* Recovery from PLOGI collision logic */
c9f8735b 803 return ndlp->nlp_state;
dea3101e
JB
804 }
805
806 irsp = &rspiocb->iocb;
807
808 if (irsp->ulpStatus)
809 goto out;
810
811 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
812
2e0fef85 813 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
dea3101e 814
2e0fef85 815 lp = (uint32_t *) prsp->virt;
dea3101e 816 sp = (struct serv_parm *) ((uint8_t *) lp + sizeof (uint32_t));
58da1ffb
JS
817
818 /* Some switches have FDMI servers returning 0 for WWN */
819 if ((ndlp->nlp_DID != FDMI_DID) &&
820 (wwn_to_u64(sp->portName.u.wwn) == 0 ||
821 wwn_to_u64(sp->nodeName.u.wwn) == 0)) {
a8adb832
JS
822 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
823 "0142 PLOGI RSP: Invalid WWN.\n");
824 goto out;
825 }
2e0fef85 826 if (!lpfc_check_sparm(vport, ndlp, sp, CLASS3))
dea3101e 827 goto out;
dea3101e 828 /* PLOGI chkparm OK */
e8b62011
JS
829 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
830 "0121 PLOGI chkparm OK Data: x%x x%x x%x x%x\n",
831 ndlp->nlp_DID, ndlp->nlp_state,
832 ndlp->nlp_flag, ndlp->nlp_rpi);
3de2a653 833 if (vport->cfg_fcp_class == 2 && (sp->cls2.classValid))
dea3101e 834 ndlp->nlp_fcp_info |= CLASS2;
2e0fef85 835 else
dea3101e 836 ndlp->nlp_fcp_info |= CLASS3;
2e0fef85 837
dea3101e
JB
838 ndlp->nlp_class_sup = 0;
839 if (sp->cls1.classValid)
840 ndlp->nlp_class_sup |= FC_COS_CLASS1;
841 if (sp->cls2.classValid)
842 ndlp->nlp_class_sup |= FC_COS_CLASS2;
843 if (sp->cls3.classValid)
844 ndlp->nlp_class_sup |= FC_COS_CLASS3;
845 if (sp->cls4.classValid)
846 ndlp->nlp_class_sup |= FC_COS_CLASS4;
847 ndlp->nlp_maxframe =
2e0fef85 848 ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) | sp->cmn.bbRcvSizeLsb;
dea3101e 849
2e0fef85 850 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
92d7f7b0 851 if (!mbox) {
e8b62011
JS
852 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
853 "0133 PLOGI: no memory for reg_login "
92d7f7b0 854 "Data: x%x x%x x%x x%x\n",
92d7f7b0
JS
855 ndlp->nlp_DID, ndlp->nlp_state,
856 ndlp->nlp_flag, ndlp->nlp_rpi);
dea3101e 857 goto out;
92d7f7b0 858 }
dea3101e 859
2e0fef85
JS
860 lpfc_unreg_rpi(vport, ndlp);
861
92d7f7b0
JS
862 if (lpfc_reg_login(phba, vport->vpi, irsp->un.elsreq64.remoteID,
863 (uint8_t *) sp, mbox, 0) == 0) {
2fe165b6 864 switch (ndlp->nlp_DID) {
dea3101e 865 case NameServer_DID:
de0c5b32 866 mbox->mbox_cmpl = lpfc_mbx_cmpl_ns_reg_login;
dea3101e
JB
867 break;
868 case FDMI_DID:
de0c5b32 869 mbox->mbox_cmpl = lpfc_mbx_cmpl_fdmi_reg_login;
dea3101e
JB
870 break;
871 default:
de0c5b32 872 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
dea3101e 873 }
329f9bc7 874 mbox->context2 = lpfc_nlp_get(ndlp);
2e0fef85 875 mbox->vport = vport;
0b727fea 876 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
dea3101e 877 != MBX_NOT_FINISHED) {
2e0fef85
JS
878 lpfc_nlp_set_state(vport, ndlp,
879 NLP_STE_REG_LOGIN_ISSUE);
c9f8735b 880 return ndlp->nlp_state;
dea3101e 881 }
fa4066b6
JS
882 /* decrement node reference count to the failed mbox
883 * command
884 */
329f9bc7 885 lpfc_nlp_put(ndlp);
92d7f7b0 886 mp = (struct lpfc_dmabuf *) mbox->context1;
14691150
JS
887 lpfc_mbuf_free(phba, mp->virt, mp->phys);
888 kfree(mp);
dea3101e 889 mempool_free(mbox, phba->mbox_mem_pool);
92d7f7b0 890
e8b62011
JS
891 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
892 "0134 PLOGI: cannot issue reg_login "
893 "Data: x%x x%x x%x x%x\n",
894 ndlp->nlp_DID, ndlp->nlp_state,
895 ndlp->nlp_flag, ndlp->nlp_rpi);
dea3101e
JB
896 } else {
897 mempool_free(mbox, phba->mbox_mem_pool);
92d7f7b0 898
e8b62011
JS
899 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
900 "0135 PLOGI: cannot format reg_login "
901 "Data: x%x x%x x%x x%x\n",
902 ndlp->nlp_DID, ndlp->nlp_state,
903 ndlp->nlp_flag, ndlp->nlp_rpi);
dea3101e
JB
904 }
905
906
92d7f7b0
JS
907out:
908 if (ndlp->nlp_DID == NameServer_DID) {
909 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
e8b62011
JS
910 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
911 "0261 Cannot Register NameServer login\n");
92d7f7b0
JS
912 }
913
0ff10d46 914 spin_lock_irq(shost->host_lock);
a8adb832 915 ndlp->nlp_flag |= NLP_DEFER_RM;
0ff10d46 916 spin_unlock_irq(shost->host_lock);
c9f8735b 917 return NLP_STE_FREED_NODE;
dea3101e
JB
918}
919
0ff10d46
JS
920static uint32_t
921lpfc_cmpl_logo_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
922 void *arg, uint32_t evt)
923{
924 return ndlp->nlp_state;
925}
926
927static uint32_t
928lpfc_cmpl_reglogin_plogi_issue(struct lpfc_vport *vport,
929 struct lpfc_nodelist *ndlp, void *arg, uint32_t evt)
930{
931 return ndlp->nlp_state;
932}
933
dea3101e 934static uint32_t
2e0fef85
JS
935lpfc_device_rm_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
936 void *arg, uint32_t evt)
dea3101e 937{
2e0fef85
JS
938 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
939
940 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
941 spin_lock_irq(shost->host_lock);
a0f9b48d 942 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
2e0fef85 943 spin_unlock_irq(shost->host_lock);
a0f9b48d 944 return ndlp->nlp_state;
2e0fef85 945 } else {
a0f9b48d 946 /* software abort outstanding PLOGI */
2e0fef85 947 lpfc_els_abort(vport->phba, ndlp);
dea3101e 948
2e0fef85 949 lpfc_drop_node(vport, ndlp);
a0f9b48d
JS
950 return NLP_STE_FREED_NODE;
951 }
dea3101e
JB
952}
953
954static uint32_t
2e0fef85
JS
955lpfc_device_recov_plogi_issue(struct lpfc_vport *vport,
956 struct lpfc_nodelist *ndlp,
957 void *arg,
958 uint32_t evt)
dea3101e 959{
2e0fef85
JS
960 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
961 struct lpfc_hba *phba = vport->phba;
962
92d7f7b0
JS
963 /* Don't do anything that will mess up processing of the
964 * previous RSCN.
965 */
966 if (vport->fc_flag & FC_RSCN_DEFERRED)
967 return ndlp->nlp_state;
968
dea3101e 969 /* software abort outstanding PLOGI */
07951076 970 lpfc_els_abort(phba, ndlp);
dea3101e 971
5024ab17 972 ndlp->nlp_prev_state = NLP_STE_PLOGI_ISSUE;
2e0fef85 973 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
92d7f7b0 974 spin_lock_irq(shost->host_lock);
a0f9b48d 975 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
2e0fef85 976 spin_unlock_irq(shost->host_lock);
dea3101e 977
c9f8735b 978 return ndlp->nlp_state;
dea3101e
JB
979}
980
981static uint32_t
2e0fef85
JS
982lpfc_rcv_plogi_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
983 void *arg, uint32_t evt)
dea3101e 984{
0d2b6b83 985 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2e0fef85 986 struct lpfc_hba *phba = vport->phba;
dea3101e
JB
987 struct lpfc_iocbq *cmdiocb;
988
989 /* software abort outstanding ADISC */
07951076 990 lpfc_els_abort(phba, ndlp);
dea3101e
JB
991
992 cmdiocb = (struct lpfc_iocbq *) arg;
993
0d2b6b83
JS
994 if (lpfc_rcv_plogi(vport, ndlp, cmdiocb)) {
995 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
996 spin_lock_irq(shost->host_lock);
997 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
998 spin_unlock_irq(shost->host_lock);
90160e01 999 if (vport->num_disc_nodes)
0d2b6b83 1000 lpfc_more_adisc(vport);
0d2b6b83
JS
1001 }
1002 return ndlp->nlp_state;
1003 }
5024ab17 1004 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
2e0fef85
JS
1005 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
1006 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
dea3101e 1007
c9f8735b 1008 return ndlp->nlp_state;
dea3101e
JB
1009}
1010
1011static uint32_t
2e0fef85
JS
1012lpfc_rcv_prli_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1013 void *arg, uint32_t evt)
dea3101e 1014{
2e0fef85 1015 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea3101e 1016
2e0fef85 1017 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
c9f8735b 1018 return ndlp->nlp_state;
dea3101e
JB
1019}
1020
1021static uint32_t
2e0fef85
JS
1022lpfc_rcv_logo_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1023 void *arg, uint32_t evt)
dea3101e 1024{
2e0fef85 1025 struct lpfc_hba *phba = vport->phba;
dea3101e
JB
1026 struct lpfc_iocbq *cmdiocb;
1027
1028 cmdiocb = (struct lpfc_iocbq *) arg;
1029
1030 /* software abort outstanding ADISC */
07951076 1031 lpfc_els_abort(phba, ndlp);
dea3101e 1032
2e0fef85 1033 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
c9f8735b 1034 return ndlp->nlp_state;
dea3101e
JB
1035}
1036
1037static uint32_t
2e0fef85
JS
1038lpfc_rcv_padisc_adisc_issue(struct lpfc_vport *vport,
1039 struct lpfc_nodelist *ndlp,
1040 void *arg, uint32_t evt)
dea3101e
JB
1041{
1042 struct lpfc_iocbq *cmdiocb;
1043
1044 cmdiocb = (struct lpfc_iocbq *) arg;
1045
2e0fef85 1046 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
c9f8735b 1047 return ndlp->nlp_state;
dea3101e
JB
1048}
1049
1050static uint32_t
2e0fef85
JS
1051lpfc_rcv_prlo_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1052 void *arg, uint32_t evt)
dea3101e
JB
1053{
1054 struct lpfc_iocbq *cmdiocb;
1055
1056 cmdiocb = (struct lpfc_iocbq *) arg;
1057
1058 /* Treat like rcv logo */
2e0fef85 1059 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_PRLO);
c9f8735b 1060 return ndlp->nlp_state;
dea3101e
JB
1061}
1062
1063static uint32_t
2e0fef85
JS
1064lpfc_cmpl_adisc_adisc_issue(struct lpfc_vport *vport,
1065 struct lpfc_nodelist *ndlp,
1066 void *arg, uint32_t evt)
dea3101e 1067{
2e0fef85
JS
1068 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1069 struct lpfc_hba *phba = vport->phba;
dea3101e
JB
1070 struct lpfc_iocbq *cmdiocb, *rspiocb;
1071 IOCB_t *irsp;
1072 ADISC *ap;
1073
1074 cmdiocb = (struct lpfc_iocbq *) arg;
1075 rspiocb = cmdiocb->context_un.rsp_iocb;
1076
1077 ap = (ADISC *)lpfc_check_elscmpl_iocb(phba, cmdiocb, rspiocb);
1078 irsp = &rspiocb->iocb;
1079
1080 if ((irsp->ulpStatus) ||
92d7f7b0 1081 (!lpfc_check_adisc(vport, ndlp, &ap->nodeName, &ap->portName))) {
dea3101e
JB
1082 /* 1 sec timeout */
1083 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ);
2e0fef85 1084 spin_lock_irq(shost->host_lock);
dea3101e 1085 ndlp->nlp_flag |= NLP_DELAY_TMO;
2e0fef85 1086 spin_unlock_irq(shost->host_lock);
5024ab17 1087 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
dea3101e 1088
2e0fef85
JS
1089 memset(&ndlp->nlp_nodename, 0, sizeof(struct lpfc_name));
1090 memset(&ndlp->nlp_portname, 0, sizeof(struct lpfc_name));
dea3101e 1091
5024ab17 1092 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
2e0fef85
JS
1093 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1094 lpfc_unreg_rpi(vport, ndlp);
c9f8735b 1095 return ndlp->nlp_state;
dea3101e 1096 }
5024ab17 1097
2501322e 1098 if (ndlp->nlp_type & NLP_FCP_TARGET) {
5024ab17 1099 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
2e0fef85 1100 lpfc_nlp_set_state(vport, ndlp, NLP_STE_MAPPED_NODE);
2501322e 1101 } else {
5024ab17 1102 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
2e0fef85 1103 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
2501322e 1104 }
c9f8735b 1105 return ndlp->nlp_state;
dea3101e
JB
1106}
1107
1108static uint32_t
2e0fef85
JS
1109lpfc_device_rm_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1110 void *arg, uint32_t evt)
dea3101e 1111{
2e0fef85
JS
1112 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1113
1114 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1115 spin_lock_irq(shost->host_lock);
a0f9b48d 1116 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
2e0fef85 1117 spin_unlock_irq(shost->host_lock);
a0f9b48d 1118 return ndlp->nlp_state;
2e0fef85 1119 } else {
a0f9b48d 1120 /* software abort outstanding ADISC */
2e0fef85 1121 lpfc_els_abort(vport->phba, ndlp);
dea3101e 1122
2e0fef85 1123 lpfc_drop_node(vport, ndlp);
a0f9b48d
JS
1124 return NLP_STE_FREED_NODE;
1125 }
dea3101e
JB
1126}
1127
1128static uint32_t
2e0fef85
JS
1129lpfc_device_recov_adisc_issue(struct lpfc_vport *vport,
1130 struct lpfc_nodelist *ndlp,
1131 void *arg,
1132 uint32_t evt)
dea3101e 1133{
2e0fef85
JS
1134 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1135 struct lpfc_hba *phba = vport->phba;
1136
92d7f7b0
JS
1137 /* Don't do anything that will mess up processing of the
1138 * previous RSCN.
1139 */
1140 if (vport->fc_flag & FC_RSCN_DEFERRED)
1141 return ndlp->nlp_state;
1142
dea3101e 1143 /* software abort outstanding ADISC */
07951076 1144 lpfc_els_abort(phba, ndlp);
dea3101e 1145
5024ab17 1146 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
2e0fef85
JS
1147 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1148 spin_lock_irq(shost->host_lock);
a0f9b48d 1149 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
2e0fef85 1150 spin_unlock_irq(shost->host_lock);
92d7f7b0 1151 lpfc_disc_set_adisc(vport, ndlp);
c9f8735b 1152 return ndlp->nlp_state;
dea3101e
JB
1153}
1154
1155static uint32_t
2e0fef85
JS
1156lpfc_rcv_plogi_reglogin_issue(struct lpfc_vport *vport,
1157 struct lpfc_nodelist *ndlp,
1158 void *arg,
dea3101e
JB
1159 uint32_t evt)
1160{
2e0fef85 1161 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea3101e 1162
2e0fef85 1163 lpfc_rcv_plogi(vport, ndlp, cmdiocb);
c9f8735b 1164 return ndlp->nlp_state;
dea3101e
JB
1165}
1166
1167static uint32_t
2e0fef85
JS
1168lpfc_rcv_prli_reglogin_issue(struct lpfc_vport *vport,
1169 struct lpfc_nodelist *ndlp,
1170 void *arg,
dea3101e
JB
1171 uint32_t evt)
1172{
2e0fef85 1173 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea3101e 1174
2e0fef85 1175 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
c9f8735b 1176 return ndlp->nlp_state;
dea3101e
JB
1177}
1178
1179static uint32_t
2e0fef85
JS
1180lpfc_rcv_logo_reglogin_issue(struct lpfc_vport *vport,
1181 struct lpfc_nodelist *ndlp,
1182 void *arg,
dea3101e
JB
1183 uint32_t evt)
1184{
2e0fef85
JS
1185 struct lpfc_hba *phba = vport->phba;
1186 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
7054a606
JS
1187 LPFC_MBOXQ_t *mb;
1188 LPFC_MBOXQ_t *nextmb;
1189 struct lpfc_dmabuf *mp;
dea3101e
JB
1190
1191 cmdiocb = (struct lpfc_iocbq *) arg;
1192
7054a606
JS
1193 /* cleanup any ndlp on mbox q waiting for reglogin cmpl */
1194 if ((mb = phba->sli.mbox_active)) {
04c68496 1195 if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) &&
7054a606 1196 (ndlp == (struct lpfc_nodelist *) mb->context2)) {
92d7f7b0 1197 lpfc_nlp_put(ndlp);
7054a606
JS
1198 mb->context2 = NULL;
1199 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1200 }
1201 }
1202
2e0fef85 1203 spin_lock_irq(&phba->hbalock);
7054a606 1204 list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) {
04c68496 1205 if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) &&
7054a606
JS
1206 (ndlp == (struct lpfc_nodelist *) mb->context2)) {
1207 mp = (struct lpfc_dmabuf *) (mb->context1);
1208 if (mp) {
98c9ea5c 1209 __lpfc_mbuf_free(phba, mp->virt, mp->phys);
7054a606
JS
1210 kfree(mp);
1211 }
92d7f7b0 1212 lpfc_nlp_put(ndlp);
7054a606
JS
1213 list_del(&mb->list);
1214 mempool_free(mb, phba->mbox_mem_pool);
1215 }
1216 }
2e0fef85 1217 spin_unlock_irq(&phba->hbalock);
7054a606 1218
2e0fef85 1219 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
c9f8735b 1220 return ndlp->nlp_state;
dea3101e
JB
1221}
1222
1223static uint32_t
2e0fef85
JS
1224lpfc_rcv_padisc_reglogin_issue(struct lpfc_vport *vport,
1225 struct lpfc_nodelist *ndlp,
1226 void *arg,
dea3101e
JB
1227 uint32_t evt)
1228{
2e0fef85 1229 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea3101e 1230
2e0fef85 1231 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
c9f8735b 1232 return ndlp->nlp_state;
dea3101e
JB
1233}
1234
1235static uint32_t
2e0fef85
JS
1236lpfc_rcv_prlo_reglogin_issue(struct lpfc_vport *vport,
1237 struct lpfc_nodelist *ndlp,
1238 void *arg,
dea3101e
JB
1239 uint32_t evt)
1240{
1241 struct lpfc_iocbq *cmdiocb;
1242
1243 cmdiocb = (struct lpfc_iocbq *) arg;
51ef4c26 1244 lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL);
c9f8735b 1245 return ndlp->nlp_state;
dea3101e
JB
1246}
1247
1248static uint32_t
2e0fef85
JS
1249lpfc_cmpl_reglogin_reglogin_issue(struct lpfc_vport *vport,
1250 struct lpfc_nodelist *ndlp,
1251 void *arg,
1252 uint32_t evt)
dea3101e 1253{
2e0fef85 1254 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2e0fef85 1255 LPFC_MBOXQ_t *pmb = (LPFC_MBOXQ_t *) arg;
04c68496 1256 MAILBOX_t *mb = &pmb->u.mb;
2e0fef85 1257 uint32_t did = mb->un.varWords[1];
dea3101e 1258
dea3101e
JB
1259 if (mb->mbxStatus) {
1260 /* RegLogin failed */
e8b62011
JS
1261 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
1262 "0246 RegLogin failed Data: x%x x%x x%x\n",
2e0fef85 1263 did, mb->mbxStatus, vport->port_state);
d0e56dad
JS
1264 /*
1265 * If RegLogin failed due to lack of HBA resources do not
1266 * retry discovery.
1267 */
1268 if (mb->mbxStatus == MBXERR_RPI_FULL) {
87af33fe
JS
1269 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
1270 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
d0e56dad
JS
1271 return ndlp->nlp_state;
1272 }
1273
2e0fef85 1274 /* Put ndlp in npr state set plogi timer for 1 sec */
dea3101e 1275 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ * 1);
2e0fef85 1276 spin_lock_irq(shost->host_lock);
dea3101e 1277 ndlp->nlp_flag |= NLP_DELAY_TMO;
2e0fef85 1278 spin_unlock_irq(shost->host_lock);
5024ab17 1279 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
dea3101e 1280
2e0fef85 1281 lpfc_issue_els_logo(vport, ndlp, 0);
5024ab17 1282 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
2e0fef85 1283 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
c9f8735b 1284 return ndlp->nlp_state;
dea3101e
JB
1285 }
1286
dea3101e 1287 ndlp->nlp_rpi = mb->un.varWords[0];
dea3101e
JB
1288
1289 /* Only if we are not a fabric nport do we issue PRLI */
1290 if (!(ndlp->nlp_type & NLP_FABRIC)) {
5024ab17 1291 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
2e0fef85
JS
1292 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
1293 lpfc_issue_els_prli(vport, ndlp, 0);
dea3101e 1294 } else {
5024ab17 1295 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
2e0fef85 1296 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
dea3101e 1297 }
c9f8735b 1298 return ndlp->nlp_state;
dea3101e
JB
1299}
1300
1301static uint32_t
2e0fef85
JS
1302lpfc_device_rm_reglogin_issue(struct lpfc_vport *vport,
1303 struct lpfc_nodelist *ndlp,
1304 void *arg,
dea3101e
JB
1305 uint32_t evt)
1306{
2e0fef85
JS
1307 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1308
1309 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1310 spin_lock_irq(shost->host_lock);
a0f9b48d 1311 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
2e0fef85 1312 spin_unlock_irq(shost->host_lock);
a0f9b48d 1313 return ndlp->nlp_state;
2e0fef85
JS
1314 } else {
1315 lpfc_drop_node(vport, ndlp);
a0f9b48d
JS
1316 return NLP_STE_FREED_NODE;
1317 }
dea3101e
JB
1318}
1319
1320static uint32_t
2e0fef85
JS
1321lpfc_device_recov_reglogin_issue(struct lpfc_vport *vport,
1322 struct lpfc_nodelist *ndlp,
1323 void *arg,
1324 uint32_t evt)
dea3101e 1325{
2e0fef85
JS
1326 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1327
92d7f7b0
JS
1328 /* Don't do anything that will mess up processing of the
1329 * previous RSCN.
1330 */
1331 if (vport->fc_flag & FC_RSCN_DEFERRED)
1332 return ndlp->nlp_state;
1333
5024ab17 1334 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
2e0fef85
JS
1335 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1336 spin_lock_irq(shost->host_lock);
a0f9b48d 1337 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
2e0fef85 1338 spin_unlock_irq(shost->host_lock);
92d7f7b0 1339 lpfc_disc_set_adisc(vport, ndlp);
c9f8735b 1340 return ndlp->nlp_state;
dea3101e
JB
1341}
1342
1343static uint32_t
2e0fef85
JS
1344lpfc_rcv_plogi_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1345 void *arg, uint32_t evt)
dea3101e
JB
1346{
1347 struct lpfc_iocbq *cmdiocb;
1348
1349 cmdiocb = (struct lpfc_iocbq *) arg;
1350
2e0fef85 1351 lpfc_rcv_plogi(vport, ndlp, cmdiocb);
c9f8735b 1352 return ndlp->nlp_state;
dea3101e
JB
1353}
1354
1355static uint32_t
2e0fef85
JS
1356lpfc_rcv_prli_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1357 void *arg, uint32_t evt)
dea3101e 1358{
2e0fef85 1359 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea3101e 1360
2e0fef85 1361 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
c9f8735b 1362 return ndlp->nlp_state;
dea3101e
JB
1363}
1364
1365static uint32_t
2e0fef85
JS
1366lpfc_rcv_logo_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1367 void *arg, uint32_t evt)
dea3101e 1368{
2e0fef85 1369 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea3101e
JB
1370
1371 /* Software abort outstanding PRLI before sending acc */
2e0fef85 1372 lpfc_els_abort(vport->phba, ndlp);
dea3101e 1373
2e0fef85 1374 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
c9f8735b 1375 return ndlp->nlp_state;
dea3101e
JB
1376}
1377
1378static uint32_t
2e0fef85
JS
1379lpfc_rcv_padisc_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1380 void *arg, uint32_t evt)
dea3101e 1381{
2e0fef85 1382 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea3101e 1383
2e0fef85 1384 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
c9f8735b 1385 return ndlp->nlp_state;
dea3101e
JB
1386}
1387
1388/* This routine is envoked when we rcv a PRLO request from a nport
1389 * we are logged into. We should send back a PRLO rsp setting the
1390 * appropriate bits.
1391 * NEXT STATE = PRLI_ISSUE
1392 */
1393static uint32_t
2e0fef85
JS
1394lpfc_rcv_prlo_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1395 void *arg, uint32_t evt)
dea3101e 1396{
2e0fef85 1397 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea3101e 1398
51ef4c26 1399 lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL);
c9f8735b 1400 return ndlp->nlp_state;
dea3101e
JB
1401}
1402
1403static uint32_t
2e0fef85
JS
1404lpfc_cmpl_prli_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1405 void *arg, uint32_t evt)
dea3101e 1406{
92d7f7b0 1407 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea3101e 1408 struct lpfc_iocbq *cmdiocb, *rspiocb;
2e0fef85 1409 struct lpfc_hba *phba = vport->phba;
dea3101e
JB
1410 IOCB_t *irsp;
1411 PRLI *npr;
1412
1413 cmdiocb = (struct lpfc_iocbq *) arg;
1414 rspiocb = cmdiocb->context_un.rsp_iocb;
1415 npr = (PRLI *)lpfc_check_elscmpl_iocb(phba, cmdiocb, rspiocb);
1416
1417 irsp = &rspiocb->iocb;
1418 if (irsp->ulpStatus) {
858c9f6c 1419 if ((vport->port_type == LPFC_NPIV_PORT) &&
3de2a653 1420 vport->cfg_restrict_login) {
858c9f6c
JS
1421 goto out;
1422 }
5024ab17 1423 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
2e0fef85 1424 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
c9f8735b 1425 return ndlp->nlp_state;
dea3101e
JB
1426 }
1427
1428 /* Check out PRLI rsp */
1429 ndlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR);
1430 ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
1431 if ((npr->acceptRspCode == PRLI_REQ_EXECUTED) &&
1432 (npr->prliType == PRLI_FCP_TYPE)) {
1433 if (npr->initiatorFunc)
1434 ndlp->nlp_type |= NLP_FCP_INITIATOR;
1435 if (npr->targetFunc)
1436 ndlp->nlp_type |= NLP_FCP_TARGET;
1437 if (npr->Retry)
1438 ndlp->nlp_fcp_info |= NLP_FCP_2_DEVICE;
1439 }
92d7f7b0
JS
1440 if (!(ndlp->nlp_type & NLP_FCP_TARGET) &&
1441 (vport->port_type == LPFC_NPIV_PORT) &&
3de2a653 1442 vport->cfg_restrict_login) {
858c9f6c 1443out:
92d7f7b0
JS
1444 spin_lock_irq(shost->host_lock);
1445 ndlp->nlp_flag |= NLP_TARGET_REMOVE;
1446 spin_unlock_irq(shost->host_lock);
1447 lpfc_issue_els_logo(vport, ndlp, 0);
1448
1449 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
87af33fe 1450 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
92d7f7b0
JS
1451 return ndlp->nlp_state;
1452 }
dea3101e 1453
5024ab17 1454 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
92d7f7b0
JS
1455 if (ndlp->nlp_type & NLP_FCP_TARGET)
1456 lpfc_nlp_set_state(vport, ndlp, NLP_STE_MAPPED_NODE);
1457 else
1458 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
c9f8735b 1459 return ndlp->nlp_state;
dea3101e
JB
1460}
1461
1462/*! lpfc_device_rm_prli_issue
92d7f7b0
JS
1463 *
1464 * \pre
1465 * \post
1466 * \param phba
1467 * \param ndlp
1468 * \param arg
1469 * \param evt
1470 * \return uint32_t
1471 *
1472 * \b Description:
1473 * This routine is envoked when we a request to remove a nport we are in the
1474 * process of PRLIing. We should software abort outstanding prli, unreg
1475 * login, send a logout. We will change node state to UNUSED_NODE, put it
1476 * on plogi list so it can be freed when LOGO completes.
1477 *
1478 */
1479
dea3101e 1480static uint32_t
2e0fef85
JS
1481lpfc_device_rm_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1482 void *arg, uint32_t evt)
dea3101e 1483{
2e0fef85
JS
1484 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1485
1486 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1487 spin_lock_irq(shost->host_lock);
a0f9b48d 1488 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
2e0fef85 1489 spin_unlock_irq(shost->host_lock);
a0f9b48d 1490 return ndlp->nlp_state;
2e0fef85 1491 } else {
a0f9b48d 1492 /* software abort outstanding PLOGI */
2e0fef85 1493 lpfc_els_abort(vport->phba, ndlp);
dea3101e 1494
2e0fef85 1495 lpfc_drop_node(vport, ndlp);
a0f9b48d
JS
1496 return NLP_STE_FREED_NODE;
1497 }
dea3101e
JB
1498}
1499
1500
1501/*! lpfc_device_recov_prli_issue
92d7f7b0
JS
1502 *
1503 * \pre
1504 * \post
1505 * \param phba
1506 * \param ndlp
1507 * \param arg
1508 * \param evt
1509 * \return uint32_t
1510 *
1511 * \b Description:
1512 * The routine is envoked when the state of a device is unknown, like
1513 * during a link down. We should remove the nodelist entry from the
1514 * unmapped list, issue a UNREG_LOGIN, do a software abort of the
1515 * outstanding PRLI command, then free the node entry.
1516 */
dea3101e 1517static uint32_t
2e0fef85
JS
1518lpfc_device_recov_prli_issue(struct lpfc_vport *vport,
1519 struct lpfc_nodelist *ndlp,
1520 void *arg,
1521 uint32_t evt)
dea3101e 1522{
2e0fef85
JS
1523 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1524 struct lpfc_hba *phba = vport->phba;
1525
92d7f7b0
JS
1526 /* Don't do anything that will mess up processing of the
1527 * previous RSCN.
1528 */
1529 if (vport->fc_flag & FC_RSCN_DEFERRED)
1530 return ndlp->nlp_state;
1531
dea3101e 1532 /* software abort outstanding PRLI */
07951076 1533 lpfc_els_abort(phba, ndlp);
dea3101e 1534
5024ab17 1535 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
2e0fef85
JS
1536 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1537 spin_lock_irq(shost->host_lock);
a0f9b48d 1538 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
2e0fef85 1539 spin_unlock_irq(shost->host_lock);
92d7f7b0 1540 lpfc_disc_set_adisc(vport, ndlp);
c9f8735b 1541 return ndlp->nlp_state;
dea3101e
JB
1542}
1543
1544static uint32_t
2e0fef85
JS
1545lpfc_rcv_plogi_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1546 void *arg, uint32_t evt)
dea3101e 1547{
2e0fef85 1548 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea3101e 1549
2e0fef85 1550 lpfc_rcv_plogi(vport, ndlp, cmdiocb);
c9f8735b 1551 return ndlp->nlp_state;
dea3101e
JB
1552}
1553
1554static uint32_t
2e0fef85
JS
1555lpfc_rcv_prli_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1556 void *arg, uint32_t evt)
dea3101e 1557{
2e0fef85 1558 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea3101e 1559
2e0fef85
JS
1560 lpfc_rcv_prli(vport, ndlp, cmdiocb);
1561 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
c9f8735b 1562 return ndlp->nlp_state;
dea3101e
JB
1563}
1564
1565static uint32_t
2e0fef85
JS
1566lpfc_rcv_logo_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1567 void *arg, uint32_t evt)
dea3101e 1568{
2e0fef85 1569 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea3101e 1570
2e0fef85 1571 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
c9f8735b 1572 return ndlp->nlp_state;
dea3101e
JB
1573}
1574
1575static uint32_t
2e0fef85
JS
1576lpfc_rcv_padisc_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1577 void *arg, uint32_t evt)
dea3101e 1578{
2e0fef85 1579 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea3101e 1580
2e0fef85 1581 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
c9f8735b 1582 return ndlp->nlp_state;
dea3101e
JB
1583}
1584
1585static uint32_t
2e0fef85
JS
1586lpfc_rcv_prlo_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1587 void *arg, uint32_t evt)
dea3101e 1588{
2e0fef85 1589 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea3101e 1590
51ef4c26 1591 lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL);
c9f8735b 1592 return ndlp->nlp_state;
dea3101e
JB
1593}
1594
1595static uint32_t
2e0fef85
JS
1596lpfc_device_recov_unmap_node(struct lpfc_vport *vport,
1597 struct lpfc_nodelist *ndlp,
1598 void *arg,
1599 uint32_t evt)
dea3101e 1600{
2e0fef85
JS
1601 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1602
5024ab17 1603 ndlp->nlp_prev_state = NLP_STE_UNMAPPED_NODE;
2e0fef85
JS
1604 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1605 spin_lock_irq(shost->host_lock);
a0f9b48d 1606 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
2e0fef85
JS
1607 spin_unlock_irq(shost->host_lock);
1608 lpfc_disc_set_adisc(vport, ndlp);
dea3101e 1609
c9f8735b 1610 return ndlp->nlp_state;
dea3101e
JB
1611}
1612
1613static uint32_t
2e0fef85
JS
1614lpfc_rcv_plogi_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1615 void *arg, uint32_t evt)
dea3101e 1616{
2e0fef85 1617 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea3101e 1618
2e0fef85 1619 lpfc_rcv_plogi(vport, ndlp, cmdiocb);
c9f8735b 1620 return ndlp->nlp_state;
dea3101e
JB
1621}
1622
1623static uint32_t
2e0fef85
JS
1624lpfc_rcv_prli_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1625 void *arg, uint32_t evt)
dea3101e 1626{
2e0fef85 1627 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea3101e 1628
2e0fef85 1629 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
c9f8735b 1630 return ndlp->nlp_state;
dea3101e
JB
1631}
1632
1633static uint32_t
2e0fef85
JS
1634lpfc_rcv_logo_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1635 void *arg, uint32_t evt)
dea3101e 1636{
2e0fef85 1637 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea3101e 1638
2e0fef85 1639 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
c9f8735b 1640 return ndlp->nlp_state;
dea3101e
JB
1641}
1642
1643static uint32_t
2e0fef85
JS
1644lpfc_rcv_padisc_mapped_node(struct lpfc_vport *vport,
1645 struct lpfc_nodelist *ndlp,
1646 void *arg, uint32_t evt)
dea3101e 1647{
2e0fef85 1648 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea3101e 1649
2e0fef85 1650 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
c9f8735b 1651 return ndlp->nlp_state;
dea3101e
JB
1652}
1653
1654static uint32_t
2e0fef85
JS
1655lpfc_rcv_prlo_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1656 void *arg, uint32_t evt)
dea3101e 1657{
2e0fef85
JS
1658 struct lpfc_hba *phba = vport->phba;
1659 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea3101e
JB
1660
1661 /* flush the target */
51ef4c26
JS
1662 lpfc_sli_abort_iocb(vport, &phba->sli.ring[phba->sli.fcp_ring],
1663 ndlp->nlp_sid, 0, LPFC_CTX_TGT);
dea3101e
JB
1664
1665 /* Treat like rcv logo */
2e0fef85 1666 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_PRLO);
c9f8735b 1667 return ndlp->nlp_state;
dea3101e
JB
1668}
1669
1670static uint32_t
2e0fef85
JS
1671lpfc_device_recov_mapped_node(struct lpfc_vport *vport,
1672 struct lpfc_nodelist *ndlp,
1673 void *arg,
1674 uint32_t evt)
dea3101e 1675{
2e0fef85
JS
1676 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1677
5024ab17 1678 ndlp->nlp_prev_state = NLP_STE_MAPPED_NODE;
2e0fef85
JS
1679 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1680 spin_lock_irq(shost->host_lock);
a0f9b48d 1681 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
2e0fef85
JS
1682 spin_unlock_irq(shost->host_lock);
1683 lpfc_disc_set_adisc(vport, ndlp);
c9f8735b 1684 return ndlp->nlp_state;
dea3101e
JB
1685}
1686
1687static uint32_t
2e0fef85
JS
1688lpfc_rcv_plogi_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1689 void *arg, uint32_t evt)
dea3101e 1690{
2e0fef85
JS
1691 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1692 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea3101e
JB
1693
1694 /* Ignore PLOGI if we have an outstanding LOGO */
0d2b6b83 1695 if (ndlp->nlp_flag & (NLP_LOGO_SND | NLP_LOGO_ACC))
c9f8735b 1696 return ndlp->nlp_state;
2e0fef85 1697 if (lpfc_rcv_plogi(vport, ndlp, cmdiocb)) {
0d2b6b83 1698 lpfc_cancel_retry_delay_tmo(vport, ndlp);
2e0fef85 1699 spin_lock_irq(shost->host_lock);
0d2b6b83 1700 ndlp->nlp_flag &= ~(NLP_NPR_ADISC | NLP_NPR_2B_DISC);
2e0fef85 1701 spin_unlock_irq(shost->host_lock);
0d2b6b83
JS
1702 } else if (!(ndlp->nlp_flag & NLP_NPR_2B_DISC)) {
1703 /* send PLOGI immediately, move to PLOGI issue state */
1704 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
1705 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
1706 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
1707 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
1708 }
dea3101e 1709 }
c9f8735b 1710 return ndlp->nlp_state;
dea3101e
JB
1711}
1712
1713static uint32_t
2e0fef85
JS
1714lpfc_rcv_prli_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1715 void *arg, uint32_t evt)
dea3101e 1716{
2e0fef85
JS
1717 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1718 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1719 struct ls_rjt stat;
dea3101e
JB
1720
1721 memset(&stat, 0, sizeof (struct ls_rjt));
1722 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
1723 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
858c9f6c 1724 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
dea3101e
JB
1725
1726 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
1727 if (ndlp->nlp_flag & NLP_NPR_ADISC) {
2e0fef85 1728 spin_lock_irq(shost->host_lock);
c9f8735b 1729 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
5024ab17 1730 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
2e0fef85
JS
1731 spin_unlock_irq(shost->host_lock);
1732 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
1733 lpfc_issue_els_adisc(vport, ndlp, 0);
dea3101e 1734 } else {
5024ab17 1735 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
2e0fef85
JS
1736 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
1737 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
dea3101e
JB
1738 }
1739 }
c9f8735b 1740 return ndlp->nlp_state;
dea3101e
JB
1741}
1742
1743static uint32_t
2e0fef85
JS
1744lpfc_rcv_logo_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1745 void *arg, uint32_t evt)
dea3101e 1746{
2e0fef85 1747 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea3101e 1748
2e0fef85 1749 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
c9f8735b 1750 return ndlp->nlp_state;
dea3101e
JB
1751}
1752
1753static uint32_t
2e0fef85
JS
1754lpfc_rcv_padisc_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1755 void *arg, uint32_t evt)
dea3101e 1756{
2e0fef85 1757 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea3101e 1758
2e0fef85 1759 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
33ccf8d1
JS
1760 /*
1761 * Do not start discovery if discovery is about to start
1762 * or discovery in progress for this node. Starting discovery
1763 * here will affect the counting of discovery threads.
1764 */
2fb9bd8b 1765 if (!(ndlp->nlp_flag & NLP_DELAY_TMO) &&
92d7f7b0 1766 !(ndlp->nlp_flag & NLP_NPR_2B_DISC)) {
dea3101e 1767 if (ndlp->nlp_flag & NLP_NPR_ADISC) {
92d7f7b0 1768 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
5024ab17 1769 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
2e0fef85
JS
1770 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
1771 lpfc_issue_els_adisc(vport, ndlp, 0);
dea3101e 1772 } else {
5024ab17 1773 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
2e0fef85
JS
1774 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
1775 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
dea3101e
JB
1776 }
1777 }
c9f8735b 1778 return ndlp->nlp_state;
dea3101e
JB
1779}
1780
1781static uint32_t
2e0fef85
JS
1782lpfc_rcv_prlo_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1783 void *arg, uint32_t evt)
dea3101e 1784{
2e0fef85
JS
1785 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1786 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
dea3101e 1787
2e0fef85 1788 spin_lock_irq(shost->host_lock);
c9f8735b 1789 ndlp->nlp_flag |= NLP_LOGO_ACC;
2e0fef85 1790 spin_unlock_irq(shost->host_lock);
c9f8735b 1791
51ef4c26 1792 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea3101e 1793
2e0fef85 1794 if ((ndlp->nlp_flag & NLP_DELAY_TMO) == 0) {
c9f8735b 1795 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ * 1);
2e0fef85 1796 spin_lock_irq(shost->host_lock);
c9f8735b
JW
1797 ndlp->nlp_flag |= NLP_DELAY_TMO;
1798 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
2e0fef85 1799 spin_unlock_irq(shost->host_lock);
5024ab17 1800 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
c9f8735b 1801 } else {
2e0fef85 1802 spin_lock_irq(shost->host_lock);
c9f8735b 1803 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
2e0fef85 1804 spin_unlock_irq(shost->host_lock);
dea3101e 1805 }
c9f8735b
JW
1806 return ndlp->nlp_state;
1807}
dea3101e 1808
c9f8735b 1809static uint32_t
2e0fef85
JS
1810lpfc_cmpl_plogi_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1811 void *arg, uint32_t evt)
c9f8735b
JW
1812{
1813 struct lpfc_iocbq *cmdiocb, *rspiocb;
a0f9b48d 1814 IOCB_t *irsp;
c9f8735b
JW
1815
1816 cmdiocb = (struct lpfc_iocbq *) arg;
1817 rspiocb = cmdiocb->context_un.rsp_iocb;
a0f9b48d
JS
1818
1819 irsp = &rspiocb->iocb;
1820 if (irsp->ulpStatus) {
a8adb832 1821 ndlp->nlp_flag |= NLP_DEFER_RM;
a0f9b48d
JS
1822 return NLP_STE_FREED_NODE;
1823 }
c9f8735b
JW
1824 return ndlp->nlp_state;
1825}
1826
1827static uint32_t
2e0fef85
JS
1828lpfc_cmpl_prli_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1829 void *arg, uint32_t evt)
c9f8735b
JW
1830{
1831 struct lpfc_iocbq *cmdiocb, *rspiocb;
a0f9b48d 1832 IOCB_t *irsp;
c9f8735b
JW
1833
1834 cmdiocb = (struct lpfc_iocbq *) arg;
1835 rspiocb = cmdiocb->context_un.rsp_iocb;
a0f9b48d
JS
1836
1837 irsp = &rspiocb->iocb;
1838 if (irsp->ulpStatus && (ndlp->nlp_flag & NLP_NODEV_REMOVE)) {
2e0fef85 1839 lpfc_drop_node(vport, ndlp);
a0f9b48d
JS
1840 return NLP_STE_FREED_NODE;
1841 }
c9f8735b 1842 return ndlp->nlp_state;
dea3101e
JB
1843}
1844
1845static uint32_t
2e0fef85
JS
1846lpfc_cmpl_logo_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1847 void *arg, uint32_t evt)
dea3101e 1848{
d7c255b2
JS
1849 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1850 if (ndlp->nlp_DID == Fabric_DID) {
1851 spin_lock_irq(shost->host_lock);
1852 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
1853 spin_unlock_irq(shost->host_lock);
1854 }
2e0fef85 1855 lpfc_unreg_rpi(vport, ndlp);
c9f8735b
JW
1856 return ndlp->nlp_state;
1857}
1858
1859static uint32_t
2e0fef85
JS
1860lpfc_cmpl_adisc_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1861 void *arg, uint32_t evt)
c9f8735b
JW
1862{
1863 struct lpfc_iocbq *cmdiocb, *rspiocb;
a0f9b48d 1864 IOCB_t *irsp;
c9f8735b
JW
1865
1866 cmdiocb = (struct lpfc_iocbq *) arg;
1867 rspiocb = cmdiocb->context_un.rsp_iocb;
a0f9b48d
JS
1868
1869 irsp = &rspiocb->iocb;
1870 if (irsp->ulpStatus && (ndlp->nlp_flag & NLP_NODEV_REMOVE)) {
2e0fef85 1871 lpfc_drop_node(vport, ndlp);
a0f9b48d
JS
1872 return NLP_STE_FREED_NODE;
1873 }
c9f8735b 1874 return ndlp->nlp_state;
dea3101e
JB
1875}
1876
1877static uint32_t
2e0fef85
JS
1878lpfc_cmpl_reglogin_npr_node(struct lpfc_vport *vport,
1879 struct lpfc_nodelist *ndlp,
1880 void *arg, uint32_t evt)
dea3101e 1881{
2e0fef85 1882 LPFC_MBOXQ_t *pmb = (LPFC_MBOXQ_t *) arg;
04c68496 1883 MAILBOX_t *mb = &pmb->u.mb;
dea3101e 1884
04c68496 1885 if (!mb->mbxStatus) {
c9f8735b 1886 ndlp->nlp_rpi = mb->un.varWords[0];
04c68496
JS
1887 ndlp->nlp_flag |= NLP_RPI_VALID;
1888 } else {
a0f9b48d 1889 if (ndlp->nlp_flag & NLP_NODEV_REMOVE) {
2e0fef85 1890 lpfc_drop_node(vport, ndlp);
a0f9b48d
JS
1891 return NLP_STE_FREED_NODE;
1892 }
1893 }
c9f8735b 1894 return ndlp->nlp_state;
dea3101e
JB
1895}
1896
1897static uint32_t
2e0fef85
JS
1898lpfc_device_rm_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1899 void *arg, uint32_t evt)
dea3101e 1900{
2e0fef85
JS
1901 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1902
a0f9b48d 1903 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
2e0fef85 1904 spin_lock_irq(shost->host_lock);
a0f9b48d 1905 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
2e0fef85 1906 spin_unlock_irq(shost->host_lock);
a0f9b48d
JS
1907 return ndlp->nlp_state;
1908 }
2e0fef85 1909 lpfc_drop_node(vport, ndlp);
c9f8735b 1910 return NLP_STE_FREED_NODE;
dea3101e
JB
1911}
1912
1913static uint32_t
2e0fef85
JS
1914lpfc_device_recov_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1915 void *arg, uint32_t evt)
dea3101e 1916{
2e0fef85
JS
1917 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1918
92d7f7b0
JS
1919 /* Don't do anything that will mess up processing of the
1920 * previous RSCN.
1921 */
1922 if (vport->fc_flag & FC_RSCN_DEFERRED)
1923 return ndlp->nlp_state;
1924
eaf15d5b 1925 lpfc_cancel_retry_delay_tmo(vport, ndlp);
2e0fef85 1926 spin_lock_irq(shost->host_lock);
a0f9b48d 1927 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
2e0fef85 1928 spin_unlock_irq(shost->host_lock);
c9f8735b 1929 return ndlp->nlp_state;
dea3101e
JB
1930}
1931
1932
1933/* This next section defines the NPort Discovery State Machine */
1934
1935/* There are 4 different double linked lists nodelist entries can reside on.
1936 * The plogi list and adisc list are used when Link Up discovery or RSCN
1937 * processing is needed. Each list holds the nodes that we will send PLOGI
1938 * or ADISC on. These lists will keep track of what nodes will be effected
1939 * by an RSCN, or a Link Up (Typically, all nodes are effected on Link Up).
1940 * The unmapped_list will contain all nodes that we have successfully logged
1941 * into at the Fibre Channel level. The mapped_list will contain all nodes
1942 * that are mapped FCP targets.
1943 */
1944/*
1945 * The bind list is a list of undiscovered (potentially non-existent) nodes
1946 * that we have saved binding information on. This information is used when
1947 * nodes transition from the unmapped to the mapped list.
1948 */
1949/* For UNUSED_NODE state, the node has just been allocated .
1950 * For PLOGI_ISSUE and REG_LOGIN_ISSUE, the node is on
1951 * the PLOGI list. For REG_LOGIN_COMPL, the node is taken off the PLOGI list
1952 * and put on the unmapped list. For ADISC processing, the node is taken off
1953 * the ADISC list and placed on either the mapped or unmapped list (depending
1954 * on its previous state). Once on the unmapped list, a PRLI is issued and the
1955 * state changed to PRLI_ISSUE. When the PRLI completion occurs, the state is
1956 * changed to UNMAPPED_NODE. If the completion indicates a mapped
1957 * node, the node is taken off the unmapped list. The binding list is checked
1958 * for a valid binding, or a binding is automatically assigned. If binding
1959 * assignment is unsuccessful, the node is left on the unmapped list. If
1960 * binding assignment is successful, the associated binding list entry (if
1961 * any) is removed, and the node is placed on the mapped list.
1962 */
1963/*
1964 * For a Link Down, all nodes on the ADISC, PLOGI, unmapped or mapped
c01f3208 1965 * lists will receive a DEVICE_RECOVERY event. If the linkdown or devloss timers
dea3101e
JB
1966 * expire, all effected nodes will receive a DEVICE_RM event.
1967 */
1968/*
1969 * For a Link Up or RSCN, all nodes will move from the mapped / unmapped lists
1970 * to either the ADISC or PLOGI list. After a Nameserver query or ALPA loopmap
1971 * check, additional nodes may be added or removed (via DEVICE_RM) to / from
1972 * the PLOGI or ADISC lists. Once the PLOGI and ADISC lists are populated,
1973 * we will first process the ADISC list. 32 entries are processed initially and
1974 * ADISC is initited for each one. Completions / Events for each node are
1975 * funnelled thru the state machine. As each node finishes ADISC processing, it
1976 * starts ADISC for any nodes waiting for ADISC processing. If no nodes are
1977 * waiting, and the ADISC list count is identically 0, then we are done. For
1978 * Link Up discovery, since all nodes on the PLOGI list are UNREG_LOGIN'ed, we
1979 * can issue a CLEAR_LA and reenable Link Events. Next we will process the PLOGI
1980 * list. 32 entries are processed initially and PLOGI is initited for each one.
1981 * Completions / Events for each node are funnelled thru the state machine. As
1982 * each node finishes PLOGI processing, it starts PLOGI for any nodes waiting
1983 * for PLOGI processing. If no nodes are waiting, and the PLOGI list count is
1984 * indentically 0, then we are done. We have now completed discovery / RSCN
1985 * handling. Upon completion, ALL nodes should be on either the mapped or
1986 * unmapped lists.
1987 */
1988
1989static uint32_t (*lpfc_disc_action[NLP_STE_MAX_STATE * NLP_EVT_MAX_EVENT])
2e0fef85 1990 (struct lpfc_vport *, struct lpfc_nodelist *, void *, uint32_t) = {
dea3101e
JB
1991 /* Action routine Event Current State */
1992 lpfc_rcv_plogi_unused_node, /* RCV_PLOGI UNUSED_NODE */
1993 lpfc_rcv_els_unused_node, /* RCV_PRLI */
1994 lpfc_rcv_logo_unused_node, /* RCV_LOGO */
1995 lpfc_rcv_els_unused_node, /* RCV_ADISC */
1996 lpfc_rcv_els_unused_node, /* RCV_PDISC */
1997 lpfc_rcv_els_unused_node, /* RCV_PRLO */
1998 lpfc_disc_illegal, /* CMPL_PLOGI */
1999 lpfc_disc_illegal, /* CMPL_PRLI */
2000 lpfc_cmpl_logo_unused_node, /* CMPL_LOGO */
2001 lpfc_disc_illegal, /* CMPL_ADISC */
2002 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2003 lpfc_device_rm_unused_node, /* DEVICE_RM */
2004 lpfc_disc_illegal, /* DEVICE_RECOVERY */
2005
2006 lpfc_rcv_plogi_plogi_issue, /* RCV_PLOGI PLOGI_ISSUE */
92d7f7b0 2007 lpfc_rcv_prli_plogi_issue, /* RCV_PRLI */
c9f8735b 2008 lpfc_rcv_logo_plogi_issue, /* RCV_LOGO */
dea3101e
JB
2009 lpfc_rcv_els_plogi_issue, /* RCV_ADISC */
2010 lpfc_rcv_els_plogi_issue, /* RCV_PDISC */
2011 lpfc_rcv_els_plogi_issue, /* RCV_PRLO */
2012 lpfc_cmpl_plogi_plogi_issue, /* CMPL_PLOGI */
2013 lpfc_disc_illegal, /* CMPL_PRLI */
0ff10d46 2014 lpfc_cmpl_logo_plogi_issue, /* CMPL_LOGO */
dea3101e 2015 lpfc_disc_illegal, /* CMPL_ADISC */
0ff10d46 2016 lpfc_cmpl_reglogin_plogi_issue,/* CMPL_REG_LOGIN */
dea3101e
JB
2017 lpfc_device_rm_plogi_issue, /* DEVICE_RM */
2018 lpfc_device_recov_plogi_issue, /* DEVICE_RECOVERY */
2019
2020 lpfc_rcv_plogi_adisc_issue, /* RCV_PLOGI ADISC_ISSUE */
2021 lpfc_rcv_prli_adisc_issue, /* RCV_PRLI */
2022 lpfc_rcv_logo_adisc_issue, /* RCV_LOGO */
2023 lpfc_rcv_padisc_adisc_issue, /* RCV_ADISC */
2024 lpfc_rcv_padisc_adisc_issue, /* RCV_PDISC */
2025 lpfc_rcv_prlo_adisc_issue, /* RCV_PRLO */
2026 lpfc_disc_illegal, /* CMPL_PLOGI */
2027 lpfc_disc_illegal, /* CMPL_PRLI */
2028 lpfc_disc_illegal, /* CMPL_LOGO */
2029 lpfc_cmpl_adisc_adisc_issue, /* CMPL_ADISC */
2030 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2031 lpfc_device_rm_adisc_issue, /* DEVICE_RM */
2032 lpfc_device_recov_adisc_issue, /* DEVICE_RECOVERY */
2033
2034 lpfc_rcv_plogi_reglogin_issue, /* RCV_PLOGI REG_LOGIN_ISSUE */
2035 lpfc_rcv_prli_reglogin_issue, /* RCV_PLOGI */
2036 lpfc_rcv_logo_reglogin_issue, /* RCV_LOGO */
2037 lpfc_rcv_padisc_reglogin_issue, /* RCV_ADISC */
2038 lpfc_rcv_padisc_reglogin_issue, /* RCV_PDISC */
2039 lpfc_rcv_prlo_reglogin_issue, /* RCV_PRLO */
87af33fe 2040 lpfc_cmpl_plogi_illegal, /* CMPL_PLOGI */
dea3101e
JB
2041 lpfc_disc_illegal, /* CMPL_PRLI */
2042 lpfc_disc_illegal, /* CMPL_LOGO */
2043 lpfc_disc_illegal, /* CMPL_ADISC */
2044 lpfc_cmpl_reglogin_reglogin_issue,/* CMPL_REG_LOGIN */
2045 lpfc_device_rm_reglogin_issue, /* DEVICE_RM */
2046 lpfc_device_recov_reglogin_issue,/* DEVICE_RECOVERY */
2047
2048 lpfc_rcv_plogi_prli_issue, /* RCV_PLOGI PRLI_ISSUE */
2049 lpfc_rcv_prli_prli_issue, /* RCV_PRLI */
2050 lpfc_rcv_logo_prli_issue, /* RCV_LOGO */
2051 lpfc_rcv_padisc_prli_issue, /* RCV_ADISC */
2052 lpfc_rcv_padisc_prli_issue, /* RCV_PDISC */
2053 lpfc_rcv_prlo_prli_issue, /* RCV_PRLO */
87af33fe 2054 lpfc_cmpl_plogi_illegal, /* CMPL_PLOGI */
dea3101e
JB
2055 lpfc_cmpl_prli_prli_issue, /* CMPL_PRLI */
2056 lpfc_disc_illegal, /* CMPL_LOGO */
2057 lpfc_disc_illegal, /* CMPL_ADISC */
2058 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2059 lpfc_device_rm_prli_issue, /* DEVICE_RM */
2060 lpfc_device_recov_prli_issue, /* DEVICE_RECOVERY */
2061
2062 lpfc_rcv_plogi_unmap_node, /* RCV_PLOGI UNMAPPED_NODE */
2063 lpfc_rcv_prli_unmap_node, /* RCV_PRLI */
2064 lpfc_rcv_logo_unmap_node, /* RCV_LOGO */
2065 lpfc_rcv_padisc_unmap_node, /* RCV_ADISC */
2066 lpfc_rcv_padisc_unmap_node, /* RCV_PDISC */
2067 lpfc_rcv_prlo_unmap_node, /* RCV_PRLO */
2068 lpfc_disc_illegal, /* CMPL_PLOGI */
2069 lpfc_disc_illegal, /* CMPL_PRLI */
2070 lpfc_disc_illegal, /* CMPL_LOGO */
2071 lpfc_disc_illegal, /* CMPL_ADISC */
2072 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2073 lpfc_disc_illegal, /* DEVICE_RM */
2074 lpfc_device_recov_unmap_node, /* DEVICE_RECOVERY */
2075
2076 lpfc_rcv_plogi_mapped_node, /* RCV_PLOGI MAPPED_NODE */
2077 lpfc_rcv_prli_mapped_node, /* RCV_PRLI */
2078 lpfc_rcv_logo_mapped_node, /* RCV_LOGO */
2079 lpfc_rcv_padisc_mapped_node, /* RCV_ADISC */
2080 lpfc_rcv_padisc_mapped_node, /* RCV_PDISC */
2081 lpfc_rcv_prlo_mapped_node, /* RCV_PRLO */
2082 lpfc_disc_illegal, /* CMPL_PLOGI */
2083 lpfc_disc_illegal, /* CMPL_PRLI */
2084 lpfc_disc_illegal, /* CMPL_LOGO */
2085 lpfc_disc_illegal, /* CMPL_ADISC */
2086 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2087 lpfc_disc_illegal, /* DEVICE_RM */
2088 lpfc_device_recov_mapped_node, /* DEVICE_RECOVERY */
2089
2090 lpfc_rcv_plogi_npr_node, /* RCV_PLOGI NPR_NODE */
2091 lpfc_rcv_prli_npr_node, /* RCV_PRLI */
2092 lpfc_rcv_logo_npr_node, /* RCV_LOGO */
2093 lpfc_rcv_padisc_npr_node, /* RCV_ADISC */
2094 lpfc_rcv_padisc_npr_node, /* RCV_PDISC */
2095 lpfc_rcv_prlo_npr_node, /* RCV_PRLO */
c9f8735b
JW
2096 lpfc_cmpl_plogi_npr_node, /* CMPL_PLOGI */
2097 lpfc_cmpl_prli_npr_node, /* CMPL_PRLI */
dea3101e 2098 lpfc_cmpl_logo_npr_node, /* CMPL_LOGO */
c9f8735b 2099 lpfc_cmpl_adisc_npr_node, /* CMPL_ADISC */
dea3101e
JB
2100 lpfc_cmpl_reglogin_npr_node, /* CMPL_REG_LOGIN */
2101 lpfc_device_rm_npr_node, /* DEVICE_RM */
2102 lpfc_device_recov_npr_node, /* DEVICE_RECOVERY */
2103};
2104
2105int
2e0fef85
JS
2106lpfc_disc_state_machine(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2107 void *arg, uint32_t evt)
dea3101e
JB
2108{
2109 uint32_t cur_state, rc;
2e0fef85 2110 uint32_t(*func) (struct lpfc_vport *, struct lpfc_nodelist *, void *,
dea3101e 2111 uint32_t);
e47c9093
JS
2112 uint32_t got_ndlp = 0;
2113
2114 if (lpfc_nlp_get(ndlp))
2115 got_ndlp = 1;
dea3101e 2116
dea3101e
JB
2117 cur_state = ndlp->nlp_state;
2118
2119 /* DSM in event <evt> on NPort <nlp_DID> in state <cur_state> */
e8b62011
JS
2120 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2121 "0211 DSM in event x%x on NPort x%x in "
2122 "state %d Data: x%x\n",
2123 evt, ndlp->nlp_DID, cur_state, ndlp->nlp_flag);
dea3101e 2124
858c9f6c
JS
2125 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_DSM,
2126 "DSM in: evt:%d ste:%d did:x%x",
2127 evt, cur_state, ndlp->nlp_DID);
2128
dea3101e 2129 func = lpfc_disc_action[(cur_state * NLP_EVT_MAX_EVENT) + evt];
2e0fef85 2130 rc = (func) (vport, ndlp, arg, evt);
dea3101e
JB
2131
2132 /* DSM out state <rc> on NPort <nlp_DID> */
e47c9093
JS
2133 if (got_ndlp) {
2134 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
e8b62011
JS
2135 "0212 DSM out state %d on NPort x%x Data: x%x\n",
2136 rc, ndlp->nlp_DID, ndlp->nlp_flag);
dea3101e 2137
e47c9093
JS
2138 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_DSM,
2139 "DSM out: ste:%d did:x%x flg:x%x",
2140 rc, ndlp->nlp_DID, ndlp->nlp_flag);
2141 /* Decrement the ndlp reference count held for this function */
2142 lpfc_nlp_put(ndlp);
2143 } else {
2144 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
d7c255b2 2145 "0213 DSM out state %d on NPort free\n", rc);
858c9f6c 2146
e47c9093
JS
2147 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_DSM,
2148 "DSM out: ste:%d did:x%x flg:x%x",
2149 rc, 0, 0);
2150 }
dea3101e 2151
c9f8735b 2152 return rc;
dea3101e 2153}