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