1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2004-2006 Emulex. All rights reserved. *
5 * EMULEX and SLI are trademarks of Emulex. *
7 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
9 * This program is free software; you can redistribute it and/or *
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. *
20 *******************************************************************/
22 #include <linux/blkdev.h>
23 #include <linux/pci.h>
24 #include <linux/interrupt.h>
26 #include <scsi/scsi.h>
27 #include <scsi/scsi_device.h>
28 #include <scsi/scsi_host.h>
29 #include <scsi/scsi_transport_fc.h>
33 #include "lpfc_disc.h"
34 #include "lpfc_scsi.h"
36 #include "lpfc_logmsg.h"
37 #include "lpfc_crtn.h"
40 /* Called to verify a rcv'ed ADISC was intended for us. */
42 lpfc_check_adisc(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp,
43 struct lpfc_name * nn, struct lpfc_name * pn)
45 /* Compare the ADISC rsp WWNN / WWPN matches our internal node
46 * table entry for that node.
48 if (memcmp(nn, &ndlp->nlp_nodename, sizeof (struct lpfc_name)) != 0)
51 if (memcmp(pn, &ndlp->nlp_portname, sizeof (struct lpfc_name)) != 0)
54 /* we match, return success */
59 lpfc_check_sparm(struct lpfc_hba * phba,
60 struct lpfc_nodelist * ndlp, struct serv_parm * sp,
63 volatile struct serv_parm *hsp = &phba->fc_sparam;
64 uint16_t hsp_value, ssp_value = 0;
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.
73 if (sp->cls1.classValid) {
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) {
79 sp->cls1.rcvDataSizeLsb = hsp->cls1.rcvDataSizeLsb;
80 sp->cls1.rcvDataSizeMsb = hsp->cls1.rcvDataSizeMsb;
82 } else if (class == CLASS1) {
86 if (sp->cls2.classValid) {
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) {
92 sp->cls2.rcvDataSizeLsb = hsp->cls2.rcvDataSizeLsb;
93 sp->cls2.rcvDataSizeMsb = hsp->cls2.rcvDataSizeMsb;
95 } else if (class == CLASS2) {
99 if (sp->cls3.classValid) {
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) {
105 sp->cls3.rcvDataSizeLsb = hsp->cls3.rcvDataSizeLsb;
106 sp->cls3.rcvDataSizeMsb = hsp->cls3.rcvDataSizeMsb;
108 } else if (class == CLASS3) {
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.
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) {
120 sp->cmn.bbRcvSizeLsb = hsp->cmn.bbRcvSizeLsb;
121 sp->cmn.bbRcvSizeMsb = (sp->cmn.bbRcvSizeMsb & 0xF0) |
122 (hsp->cmn.bbRcvSizeMsb & 0x0F);
125 memcpy(&ndlp->nlp_nodename, &sp->nodeName, sizeof (struct lpfc_name));
126 memcpy(&ndlp->nlp_portname, &sp->portName, sizeof (struct lpfc_name));
131 lpfc_check_elscmpl_iocb(struct lpfc_hba * phba,
132 struct lpfc_iocbq *cmdiocb,
133 struct lpfc_iocbq *rspiocb)
135 struct lpfc_dmabuf *pcmd, *prsp;
140 irsp = &rspiocb->iocb;
141 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
143 /* For lpfc_els_abort, context2 could be zero'ed to delay
144 * freeing associated memory till after ABTS completes.
147 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf,
150 lp = (uint32_t *) prsp->virt;
151 ptr = (void *)((uint8_t *)lp + sizeof(uint32_t));
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;
166 * Free resources / clean up outstanding I/Os
167 * associated with a LPFC_NODELIST entry. This
168 * routine effectively results in a "software abort".
171 lpfc_els_abort(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp,
174 struct lpfc_sli *psli;
175 struct lpfc_sli_ring *pring;
176 struct lpfc_iocbq *iocb, *next_iocb;
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);
188 pring = &psli->ring[LPFC_ELS_RING];
190 /* First check the txq */
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
197 if ((lpfc_check_sli_ndlp(phba, pring, iocb, ndlp))) {
199 /* It matches, so deque and call compl with an
201 list_del(&iocb->list);
203 if (iocb->iocb_cmpl) {
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);
211 lpfc_sli_release_iocbq(phba, iocb);
215 spin_unlock_irq(phba->host->host_lock);
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.
222 /* Next check the txcmplq */
225 spin_lock_irq(phba->host->host_lock);
226 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq,
228 /* Check to see if iocb matches the nport we are looking
230 if ((lpfc_check_sli_ndlp (phba, pring, iocb, ndlp))) {
232 /* It matches, so deque and call compl with an
234 list_del(&iocb->list);
235 pring->txcmplq_cnt--;
238 /* If the driver is completing an ELS
239 * command early, flush it out of the firmware.
242 (icmd->ulpCommand == CMD_ELS_REQUEST64_CR) &&
243 (icmd->un.elsreq64.bdl.ulpIoTag32)) {
244 lpfc_sli_issue_abort_iotag32(phba,
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);
254 lpfc_sli_release_iocbq(phba, iocb);
258 spin_unlock_irq(phba->host->host_lock);
261 /* If we are delaying issuing an ELS command, cancel it */
262 if (ndlp->nlp_flag & NLP_DELAY_TMO)
263 lpfc_cancel_retry_delay_tmo(phba, ndlp);
268 lpfc_rcv_plogi(struct lpfc_hba * phba,
269 struct lpfc_nodelist * ndlp,
270 struct lpfc_iocbq *cmdiocb)
272 struct lpfc_dmabuf *pcmd;
275 struct serv_parm *sp;
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.
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.
293 phba->fc_edtov = FF_DEF_EDTOV;
294 phba->fc_ratov = FF_DEF_RATOV;
295 /* Start discovery - this should just do
297 lpfc_disc_start(phba);
299 lpfc_initial_flogi(phba);
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,
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);
319 icmd = &cmdiocb->iocb;
321 /* PLOGI chkparm OK */
322 lpfc_printf_log(phba,
325 "%d:0114 PLOGI chkparm OK Data: x%x x%x x%x x%x\n",
327 ndlp->nlp_DID, ndlp->nlp_state, ndlp->nlp_flag,
330 if ((phba->cfg_fcp_class == 2) &&
331 (sp->cls2.classValid)) {
332 ndlp->nlp_fcp_info |= CLASS2;
334 ndlp->nlp_fcp_info |= CLASS3;
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;
346 ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) | sp->cmn.bbRcvSizeLsb;
348 /* no need to reg_login if we are already in one of these states */
349 switch (ndlp->nlp_state) {
350 case NLP_STE_NPR_NODE:
351 if (!(ndlp->nlp_flag & NLP_NPR_ADISC))
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);
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);
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);
377 lpfc_can_disctmo(phba);
379 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
383 if (lpfc_reg_login(phba, icmd->un.rcvels.remoteID,
384 (uint8_t *) sp, mbox, 0)) {
385 mempool_free( mbox, phba->mbox_mem_pool);
389 /* ACC PLOGI rsp command needs to execute first,
390 * queue this mbox command to be processed later.
392 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
393 mbox->context2 = ndlp;
394 ndlp->nlp_flag |= (NLP_ACC_REGLOGIN | NLP_RCV_PLOGI);
396 lpfc_els_rsp_acc(phba, ELS_CMD_PLOGI, cmdiocb, ndlp, mbox, 0);
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);
407 lpfc_rcv_padisc(struct lpfc_hba * phba,
408 struct lpfc_nodelist * ndlp,
409 struct lpfc_iocbq *cmdiocb)
411 struct lpfc_dmabuf *pcmd;
412 struct serv_parm *sp;
413 struct lpfc_name *pnn, *ppn;
420 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
421 lp = (uint32_t *) pcmd->virt;
424 if (cmd == ELS_CMD_ADISC) {
426 pnn = (struct lpfc_name *) & ap->nodeName;
427 ppn = (struct lpfc_name *) & ap->portName;
429 sp = (struct serv_parm *) lp;
430 pnn = (struct lpfc_name *) & sp->nodeName;
431 ppn = (struct lpfc_name *) & sp->portName;
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);
440 lpfc_els_rsp_acc(phba, ELS_CMD_PLOGI, cmdiocb, ndlp,
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);
453 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ);
455 spin_lock_irq(phba->host->host_lock);
456 ndlp->nlp_flag |= NLP_DELAY_TMO;
457 spin_unlock_irq(phba->host->host_lock);
458 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
459 ndlp->nlp_prev_state = ndlp->nlp_state;
460 ndlp->nlp_state = NLP_STE_NPR_NODE;
461 lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
466 lpfc_rcv_logo(struct lpfc_hba * phba,
467 struct lpfc_nodelist * ndlp,
468 struct lpfc_iocbq *cmdiocb,
471 /* Put ndlp on NPR list with 1 sec timeout for plogi, ACC logo */
472 /* Only call LOGO ACC for first LOGO, this avoids sending unnecessary
473 * PLOGIs during LOGO storms from a device.
475 ndlp->nlp_flag |= NLP_LOGO_ACC;
476 if (els_cmd == ELS_CMD_PRLO)
477 lpfc_els_rsp_acc(phba, ELS_CMD_PRLO, cmdiocb, ndlp, NULL, 0);
479 lpfc_els_rsp_acc(phba, ELS_CMD_ACC, cmdiocb, ndlp, NULL, 0);
481 if (!(ndlp->nlp_type & NLP_FABRIC) ||
482 (ndlp->nlp_state == NLP_STE_ADISC_ISSUE)) {
483 /* Only try to re-login if this is NOT a Fabric Node */
484 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ * 1);
485 spin_lock_irq(phba->host->host_lock);
486 ndlp->nlp_flag |= NLP_DELAY_TMO;
487 spin_unlock_irq(phba->host->host_lock);
489 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
490 ndlp->nlp_prev_state = ndlp->nlp_state;
491 ndlp->nlp_state = NLP_STE_NPR_NODE;
492 lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
494 ndlp->nlp_prev_state = ndlp->nlp_state;
495 ndlp->nlp_state = NLP_STE_UNUSED_NODE;
496 lpfc_nlp_list(phba, ndlp, NLP_UNUSED_LIST);
499 spin_lock_irq(phba->host->host_lock);
500 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
501 spin_unlock_irq(phba->host->host_lock);
502 /* The driver has to wait until the ACC completes before it continues
503 * processing the LOGO. The action will resume in
504 * lpfc_cmpl_els_logo_acc routine. Since part of processing includes an
505 * unreg_login, the driver waits so the ACC does not get aborted.
511 lpfc_rcv_prli(struct lpfc_hba * phba,
512 struct lpfc_nodelist * ndlp,
513 struct lpfc_iocbq *cmdiocb)
515 struct lpfc_dmabuf *pcmd;
518 struct fc_rport *rport = ndlp->rport;
521 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
522 lp = (uint32_t *) pcmd->virt;
523 npr = (PRLI *) ((uint8_t *) lp + sizeof (uint32_t));
525 ndlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR);
526 ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
527 if ((npr->acceptRspCode == PRLI_REQ_EXECUTED) &&
528 (npr->prliType == PRLI_FCP_TYPE)) {
529 if (npr->initiatorFunc)
530 ndlp->nlp_type |= NLP_FCP_INITIATOR;
532 ndlp->nlp_type |= NLP_FCP_TARGET;
534 ndlp->nlp_fcp_info |= NLP_FCP_2_DEVICE;
537 /* We need to update the rport role values */
538 roles = FC_RPORT_ROLE_UNKNOWN;
539 if (ndlp->nlp_type & NLP_FCP_INITIATOR)
540 roles |= FC_RPORT_ROLE_FCP_INITIATOR;
541 if (ndlp->nlp_type & NLP_FCP_TARGET)
542 roles |= FC_RPORT_ROLE_FCP_TARGET;
543 fc_remote_port_rolechg(rport, roles);
548 lpfc_disc_set_adisc(struct lpfc_hba * phba,
549 struct lpfc_nodelist * ndlp)
551 /* Check config parameter use-adisc or FCP-2 */
552 if ((phba->cfg_use_adisc == 0) &&
553 !(phba->fc_flag & FC_RSCN_MODE)) {
554 if (!(ndlp->nlp_fcp_info & NLP_FCP_2_DEVICE))
557 spin_lock_irq(phba->host->host_lock);
558 ndlp->nlp_flag |= NLP_NPR_ADISC;
559 spin_unlock_irq(phba->host->host_lock);
564 lpfc_disc_illegal(struct lpfc_hba * phba,
565 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
567 lpfc_printf_log(phba,
570 "%d:0253 Illegal State Transition: node x%x event x%x, "
571 "state x%x Data: x%x x%x\n",
573 ndlp->nlp_DID, evt, ndlp->nlp_state, ndlp->nlp_rpi,
575 return ndlp->nlp_state;
578 /* Start of Discovery State Machine routines */
581 lpfc_rcv_plogi_unused_node(struct lpfc_hba * phba,
582 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
584 struct lpfc_iocbq *cmdiocb;
586 cmdiocb = (struct lpfc_iocbq *) arg;
588 if (lpfc_rcv_plogi(phba, ndlp, cmdiocb)) {
589 ndlp->nlp_prev_state = NLP_STE_UNUSED_NODE;
590 ndlp->nlp_state = NLP_STE_UNUSED_NODE;
591 lpfc_nlp_list(phba, ndlp, NLP_UNUSED_LIST);
592 return ndlp->nlp_state;
594 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
595 return NLP_STE_FREED_NODE;
599 lpfc_rcv_els_unused_node(struct lpfc_hba * phba,
600 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
602 lpfc_issue_els_logo(phba, ndlp, 0);
603 lpfc_nlp_list(phba, ndlp, NLP_UNUSED_LIST);
604 return ndlp->nlp_state;
608 lpfc_rcv_logo_unused_node(struct lpfc_hba * phba,
609 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
611 struct lpfc_iocbq *cmdiocb;
613 cmdiocb = (struct lpfc_iocbq *) arg;
615 spin_lock_irq(phba->host->host_lock);
616 ndlp->nlp_flag |= NLP_LOGO_ACC;
617 spin_unlock_irq(phba->host->host_lock);
618 lpfc_els_rsp_acc(phba, ELS_CMD_ACC, cmdiocb, ndlp, NULL, 0);
619 lpfc_nlp_list(phba, ndlp, NLP_UNUSED_LIST);
621 return ndlp->nlp_state;
625 lpfc_cmpl_logo_unused_node(struct lpfc_hba * phba,
626 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
628 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
629 return NLP_STE_FREED_NODE;
633 lpfc_device_rm_unused_node(struct lpfc_hba * phba,
634 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
636 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
637 return NLP_STE_FREED_NODE;
641 lpfc_rcv_plogi_plogi_issue(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp,
642 void *arg, uint32_t evt)
644 struct lpfc_iocbq *cmdiocb = arg;
645 struct lpfc_dmabuf *pcmd;
646 struct serv_parm *sp;
651 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
652 lp = (uint32_t *) pcmd->virt;
653 sp = (struct serv_parm *) ((uint8_t *) lp + sizeof (uint32_t));
655 memset(&stat, 0, sizeof (struct ls_rjt));
657 /* For a PLOGI, we only accept if our portname is less
658 * than the remote portname.
660 phba->fc_stat.elsLogiCol++;
661 port_cmp = memcmp(&phba->fc_portname, &sp->portName,
662 sizeof (struct lpfc_name));
665 /* Reject this request because the remote node will accept
667 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
668 stat.un.b.lsRjtRsnCodeExp = LSEXP_CMD_IN_PROGRESS;
669 lpfc_els_rsp_reject(phba, stat.un.lsRjtError, cmdiocb, ndlp);
671 lpfc_rcv_plogi(phba, ndlp, cmdiocb);
672 } /* if our portname was less */
674 return ndlp->nlp_state;
678 lpfc_rcv_logo_plogi_issue(struct lpfc_hba * phba,
679 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
681 struct lpfc_iocbq *cmdiocb;
683 cmdiocb = (struct lpfc_iocbq *) arg;
685 /* software abort outstanding PLOGI */
686 lpfc_els_abort(phba, ndlp, 1);
688 lpfc_rcv_logo(phba, ndlp, cmdiocb, ELS_CMD_LOGO);
689 return ndlp->nlp_state;
693 lpfc_rcv_els_plogi_issue(struct lpfc_hba * phba,
694 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
696 struct lpfc_iocbq *cmdiocb;
698 cmdiocb = (struct lpfc_iocbq *) arg;
700 /* software abort outstanding PLOGI */
701 lpfc_els_abort(phba, ndlp, 1);
703 if (evt == NLP_EVT_RCV_LOGO) {
704 lpfc_els_rsp_acc(phba, ELS_CMD_ACC, cmdiocb, ndlp, NULL, 0);
706 lpfc_issue_els_logo(phba, ndlp, 0);
709 /* Put ndlp in npr list set plogi timer for 1 sec */
710 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ * 1);
711 spin_lock_irq(phba->host->host_lock);
712 ndlp->nlp_flag |= NLP_DELAY_TMO;
713 spin_unlock_irq(phba->host->host_lock);
714 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
715 ndlp->nlp_prev_state = NLP_STE_PLOGI_ISSUE;
716 ndlp->nlp_state = NLP_STE_NPR_NODE;
717 lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
719 return ndlp->nlp_state;
723 lpfc_cmpl_plogi_plogi_issue(struct lpfc_hba * phba,
724 struct lpfc_nodelist * ndlp, void *arg,
727 struct lpfc_iocbq *cmdiocb, *rspiocb;
728 struct lpfc_dmabuf *pcmd, *prsp;
731 struct serv_parm *sp;
734 cmdiocb = (struct lpfc_iocbq *) arg;
735 rspiocb = cmdiocb->context_un.rsp_iocb;
737 if (ndlp->nlp_flag & NLP_ACC_REGLOGIN) {
738 /* Recovery from PLOGI collision logic */
739 return ndlp->nlp_state;
742 irsp = &rspiocb->iocb;
747 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
749 prsp = list_get_first(&pcmd->list,
752 lp = (uint32_t *) prsp->virt;
754 sp = (struct serv_parm *) ((uint8_t *) lp + sizeof (uint32_t));
755 if (!lpfc_check_sparm(phba, ndlp, sp, CLASS3))
758 /* PLOGI chkparm OK */
759 lpfc_printf_log(phba,
762 "%d:0121 PLOGI chkparm OK "
763 "Data: x%x x%x x%x x%x\n",
765 ndlp->nlp_DID, ndlp->nlp_state,
766 ndlp->nlp_flag, ndlp->nlp_rpi);
768 if ((phba->cfg_fcp_class == 2) &&
769 (sp->cls2.classValid)) {
770 ndlp->nlp_fcp_info |= CLASS2;
772 ndlp->nlp_fcp_info |= CLASS3;
774 ndlp->nlp_class_sup = 0;
775 if (sp->cls1.classValid)
776 ndlp->nlp_class_sup |= FC_COS_CLASS1;
777 if (sp->cls2.classValid)
778 ndlp->nlp_class_sup |= FC_COS_CLASS2;
779 if (sp->cls3.classValid)
780 ndlp->nlp_class_sup |= FC_COS_CLASS3;
781 if (sp->cls4.classValid)
782 ndlp->nlp_class_sup |= FC_COS_CLASS4;
784 ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) |
785 sp->cmn.bbRcvSizeLsb;
787 if (!(mbox = mempool_alloc(phba->mbox_mem_pool,
791 lpfc_unreg_rpi(phba, ndlp);
793 (phba, irsp->un.elsreq64.remoteID,
794 (uint8_t *) sp, mbox, 0) == 0) {
795 switch (ndlp->nlp_DID) {
798 lpfc_mbx_cmpl_ns_reg_login;
802 lpfc_mbx_cmpl_fdmi_reg_login;
806 lpfc_mbx_cmpl_reg_login;
808 mbox->context2 = ndlp;
809 if (lpfc_sli_issue_mbox(phba, mbox,
810 (MBX_NOWAIT | MBX_STOP_IOCB))
811 != MBX_NOT_FINISHED) {
813 NLP_STE_REG_LOGIN_ISSUE;
814 lpfc_nlp_list(phba, ndlp,
816 return ndlp->nlp_state;
818 mempool_free(mbox, phba->mbox_mem_pool);
820 mempool_free(mbox, phba->mbox_mem_pool);
825 /* Free this node since the driver cannot login or has the wrong
827 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
828 return NLP_STE_FREED_NODE;
832 lpfc_device_rm_plogi_issue(struct lpfc_hba * phba,
833 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
835 if(ndlp->nlp_flag & NLP_NPR_2B_DISC) {
836 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
837 return ndlp->nlp_state;
840 /* software abort outstanding PLOGI */
841 lpfc_els_abort(phba, ndlp, 1);
843 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
844 return NLP_STE_FREED_NODE;
849 lpfc_device_recov_plogi_issue(struct lpfc_hba * phba,
850 struct lpfc_nodelist * ndlp, void *arg,
853 /* software abort outstanding PLOGI */
854 lpfc_els_abort(phba, ndlp, 1);
856 ndlp->nlp_prev_state = NLP_STE_PLOGI_ISSUE;
857 ndlp->nlp_state = NLP_STE_NPR_NODE;
858 lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
859 spin_lock_irq(phba->host->host_lock);
860 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
861 spin_unlock_irq(phba->host->host_lock);
863 return ndlp->nlp_state;
867 lpfc_rcv_plogi_adisc_issue(struct lpfc_hba * phba,
868 struct lpfc_nodelist * ndlp, void *arg,
871 struct lpfc_iocbq *cmdiocb;
873 /* software abort outstanding ADISC */
874 lpfc_els_abort(phba, ndlp, 1);
876 cmdiocb = (struct lpfc_iocbq *) arg;
878 if (lpfc_rcv_plogi(phba, ndlp, cmdiocb)) {
879 return ndlp->nlp_state;
881 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
882 ndlp->nlp_state = NLP_STE_PLOGI_ISSUE;
883 lpfc_nlp_list(phba, ndlp, NLP_PLOGI_LIST);
884 lpfc_issue_els_plogi(phba, ndlp->nlp_DID, 0);
886 return ndlp->nlp_state;
890 lpfc_rcv_prli_adisc_issue(struct lpfc_hba * phba,
891 struct lpfc_nodelist * ndlp, void *arg,
894 struct lpfc_iocbq *cmdiocb;
896 cmdiocb = (struct lpfc_iocbq *) arg;
898 lpfc_els_rsp_prli_acc(phba, cmdiocb, ndlp);
899 return ndlp->nlp_state;
903 lpfc_rcv_logo_adisc_issue(struct lpfc_hba * phba,
904 struct lpfc_nodelist * ndlp, void *arg,
907 struct lpfc_iocbq *cmdiocb;
909 cmdiocb = (struct lpfc_iocbq *) arg;
911 /* software abort outstanding ADISC */
912 lpfc_els_abort(phba, ndlp, 0);
914 lpfc_rcv_logo(phba, ndlp, cmdiocb, ELS_CMD_LOGO);
915 return ndlp->nlp_state;
919 lpfc_rcv_padisc_adisc_issue(struct lpfc_hba * phba,
920 struct lpfc_nodelist * ndlp, void *arg,
923 struct lpfc_iocbq *cmdiocb;
925 cmdiocb = (struct lpfc_iocbq *) arg;
927 lpfc_rcv_padisc(phba, ndlp, cmdiocb);
928 return ndlp->nlp_state;
932 lpfc_rcv_prlo_adisc_issue(struct lpfc_hba * phba,
933 struct lpfc_nodelist * ndlp, void *arg,
936 struct lpfc_iocbq *cmdiocb;
938 cmdiocb = (struct lpfc_iocbq *) arg;
940 /* Treat like rcv logo */
941 lpfc_rcv_logo(phba, ndlp, cmdiocb, ELS_CMD_PRLO);
942 return ndlp->nlp_state;
946 lpfc_cmpl_adisc_adisc_issue(struct lpfc_hba * phba,
947 struct lpfc_nodelist * ndlp, void *arg,
950 struct lpfc_iocbq *cmdiocb, *rspiocb;
954 cmdiocb = (struct lpfc_iocbq *) arg;
955 rspiocb = cmdiocb->context_un.rsp_iocb;
957 ap = (ADISC *)lpfc_check_elscmpl_iocb(phba, cmdiocb, rspiocb);
958 irsp = &rspiocb->iocb;
960 if ((irsp->ulpStatus) ||
961 (!lpfc_check_adisc(phba, ndlp, &ap->nodeName, &ap->portName))) {
963 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ);
964 spin_lock_irq(phba->host->host_lock);
965 ndlp->nlp_flag |= NLP_DELAY_TMO;
966 spin_unlock_irq(phba->host->host_lock);
967 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
969 memset(&ndlp->nlp_nodename, 0, sizeof (struct lpfc_name));
970 memset(&ndlp->nlp_portname, 0, sizeof (struct lpfc_name));
972 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
973 ndlp->nlp_state = NLP_STE_NPR_NODE;
974 lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
975 lpfc_unreg_rpi(phba, ndlp);
976 return ndlp->nlp_state;
979 if (ndlp->nlp_type & NLP_FCP_TARGET) {
980 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
981 ndlp->nlp_state = NLP_STE_MAPPED_NODE;
982 lpfc_nlp_list(phba, ndlp, NLP_MAPPED_LIST);
984 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
985 ndlp->nlp_state = NLP_STE_UNMAPPED_NODE;
986 lpfc_nlp_list(phba, ndlp, NLP_UNMAPPED_LIST);
988 return ndlp->nlp_state;
992 lpfc_device_rm_adisc_issue(struct lpfc_hba * phba,
993 struct lpfc_nodelist * ndlp, void *arg,
996 if(ndlp->nlp_flag & NLP_NPR_2B_DISC) {
997 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
998 return ndlp->nlp_state;
1001 /* software abort outstanding ADISC */
1002 lpfc_els_abort(phba, ndlp, 1);
1004 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
1005 return NLP_STE_FREED_NODE;
1010 lpfc_device_recov_adisc_issue(struct lpfc_hba * phba,
1011 struct lpfc_nodelist * ndlp, void *arg,
1014 /* software abort outstanding ADISC */
1015 lpfc_els_abort(phba, ndlp, 1);
1017 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
1018 ndlp->nlp_state = NLP_STE_NPR_NODE;
1019 lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
1020 spin_lock_irq(phba->host->host_lock);
1021 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
1022 ndlp->nlp_flag |= NLP_NPR_ADISC;
1023 spin_unlock_irq(phba->host->host_lock);
1025 return ndlp->nlp_state;
1029 lpfc_rcv_plogi_reglogin_issue(struct lpfc_hba * phba,
1030 struct lpfc_nodelist * ndlp, void *arg,
1033 struct lpfc_iocbq *cmdiocb;
1035 cmdiocb = (struct lpfc_iocbq *) arg;
1037 lpfc_rcv_plogi(phba, ndlp, cmdiocb);
1038 return ndlp->nlp_state;
1042 lpfc_rcv_prli_reglogin_issue(struct lpfc_hba * phba,
1043 struct lpfc_nodelist * ndlp, void *arg,
1046 struct lpfc_iocbq *cmdiocb;
1048 cmdiocb = (struct lpfc_iocbq *) arg;
1050 lpfc_els_rsp_prli_acc(phba, cmdiocb, ndlp);
1051 return ndlp->nlp_state;
1055 lpfc_rcv_logo_reglogin_issue(struct lpfc_hba * phba,
1056 struct lpfc_nodelist * ndlp, void *arg,
1059 struct lpfc_iocbq *cmdiocb;
1061 cmdiocb = (struct lpfc_iocbq *) arg;
1063 lpfc_rcv_logo(phba, ndlp, cmdiocb, ELS_CMD_LOGO);
1064 return ndlp->nlp_state;
1068 lpfc_rcv_padisc_reglogin_issue(struct lpfc_hba * phba,
1069 struct lpfc_nodelist * ndlp, void *arg,
1072 struct lpfc_iocbq *cmdiocb;
1074 cmdiocb = (struct lpfc_iocbq *) arg;
1076 lpfc_rcv_padisc(phba, ndlp, cmdiocb);
1077 return ndlp->nlp_state;
1081 lpfc_rcv_prlo_reglogin_issue(struct lpfc_hba * phba,
1082 struct lpfc_nodelist * ndlp, void *arg,
1085 struct lpfc_iocbq *cmdiocb;
1087 cmdiocb = (struct lpfc_iocbq *) arg;
1088 lpfc_els_rsp_acc(phba, ELS_CMD_PRLO, cmdiocb, ndlp, NULL, 0);
1089 return ndlp->nlp_state;
1093 lpfc_cmpl_reglogin_reglogin_issue(struct lpfc_hba * phba,
1094 struct lpfc_nodelist * ndlp,
1095 void *arg, uint32_t evt)
1101 pmb = (LPFC_MBOXQ_t *) arg;
1103 did = mb->un.varWords[1];
1104 if (mb->mbxStatus) {
1105 /* RegLogin failed */
1106 lpfc_printf_log(phba,
1109 "%d:0246 RegLogin failed Data: x%x x%x x%x\n",
1111 did, mb->mbxStatus, phba->hba_state);
1114 * If RegLogin failed due to lack of HBA resources do not
1117 if (mb->mbxStatus == MBXERR_RPI_FULL) {
1118 ndlp->nlp_prev_state = NLP_STE_UNUSED_NODE;
1119 ndlp->nlp_state = NLP_STE_UNUSED_NODE;
1120 lpfc_nlp_list(phba, ndlp, NLP_UNUSED_LIST);
1121 return ndlp->nlp_state;
1124 /* Put ndlp in npr list set plogi timer for 1 sec */
1125 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ * 1);
1126 spin_lock_irq(phba->host->host_lock);
1127 ndlp->nlp_flag |= NLP_DELAY_TMO;
1128 spin_unlock_irq(phba->host->host_lock);
1129 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
1131 lpfc_issue_els_logo(phba, ndlp, 0);
1132 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
1133 ndlp->nlp_state = NLP_STE_NPR_NODE;
1134 lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
1135 return ndlp->nlp_state;
1138 ndlp->nlp_rpi = mb->un.varWords[0];
1140 /* Only if we are not a fabric nport do we issue PRLI */
1141 if (!(ndlp->nlp_type & NLP_FABRIC)) {
1142 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
1143 ndlp->nlp_state = NLP_STE_PRLI_ISSUE;
1144 lpfc_nlp_list(phba, ndlp, NLP_PRLI_LIST);
1145 lpfc_issue_els_prli(phba, ndlp, 0);
1147 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
1148 ndlp->nlp_state = NLP_STE_UNMAPPED_NODE;
1149 lpfc_nlp_list(phba, ndlp, NLP_UNMAPPED_LIST);
1151 return ndlp->nlp_state;
1155 lpfc_device_rm_reglogin_issue(struct lpfc_hba * phba,
1156 struct lpfc_nodelist * ndlp, void *arg,
1159 if(ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1160 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
1161 return ndlp->nlp_state;
1164 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
1165 return NLP_STE_FREED_NODE;
1170 lpfc_device_recov_reglogin_issue(struct lpfc_hba * phba,
1171 struct lpfc_nodelist * ndlp, void *arg,
1174 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
1175 ndlp->nlp_state = NLP_STE_NPR_NODE;
1176 lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
1177 spin_lock_irq(phba->host->host_lock);
1178 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
1179 spin_unlock_irq(phba->host->host_lock);
1180 return ndlp->nlp_state;
1184 lpfc_rcv_plogi_prli_issue(struct lpfc_hba * phba,
1185 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1187 struct lpfc_iocbq *cmdiocb;
1189 cmdiocb = (struct lpfc_iocbq *) arg;
1191 lpfc_rcv_plogi(phba, ndlp, cmdiocb);
1192 return ndlp->nlp_state;
1196 lpfc_rcv_prli_prli_issue(struct lpfc_hba * phba,
1197 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1199 struct lpfc_iocbq *cmdiocb;
1201 cmdiocb = (struct lpfc_iocbq *) arg;
1203 lpfc_els_rsp_prli_acc(phba, cmdiocb, ndlp);
1204 return ndlp->nlp_state;
1208 lpfc_rcv_logo_prli_issue(struct lpfc_hba * phba,
1209 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1211 struct lpfc_iocbq *cmdiocb;
1213 cmdiocb = (struct lpfc_iocbq *) arg;
1215 /* Software abort outstanding PRLI before sending acc */
1216 lpfc_els_abort(phba, ndlp, 1);
1218 lpfc_rcv_logo(phba, ndlp, cmdiocb, ELS_CMD_LOGO);
1219 return ndlp->nlp_state;
1223 lpfc_rcv_padisc_prli_issue(struct lpfc_hba * phba,
1224 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1226 struct lpfc_iocbq *cmdiocb;
1228 cmdiocb = (struct lpfc_iocbq *) arg;
1230 lpfc_rcv_padisc(phba, ndlp, cmdiocb);
1231 return ndlp->nlp_state;
1234 /* This routine is envoked when we rcv a PRLO request from a nport
1235 * we are logged into. We should send back a PRLO rsp setting the
1237 * NEXT STATE = PRLI_ISSUE
1240 lpfc_rcv_prlo_prli_issue(struct lpfc_hba * phba,
1241 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1243 struct lpfc_iocbq *cmdiocb;
1245 cmdiocb = (struct lpfc_iocbq *) arg;
1246 lpfc_els_rsp_acc(phba, ELS_CMD_PRLO, cmdiocb, ndlp, NULL, 0);
1247 return ndlp->nlp_state;
1251 lpfc_cmpl_prli_prli_issue(struct lpfc_hba * phba,
1252 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1254 struct lpfc_iocbq *cmdiocb, *rspiocb;
1258 cmdiocb = (struct lpfc_iocbq *) arg;
1259 rspiocb = cmdiocb->context_un.rsp_iocb;
1260 npr = (PRLI *)lpfc_check_elscmpl_iocb(phba, cmdiocb, rspiocb);
1262 irsp = &rspiocb->iocb;
1263 if (irsp->ulpStatus) {
1264 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
1265 ndlp->nlp_state = NLP_STE_UNMAPPED_NODE;
1266 lpfc_nlp_list(phba, ndlp, NLP_UNMAPPED_LIST);
1267 return ndlp->nlp_state;
1270 /* Check out PRLI rsp */
1271 ndlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR);
1272 ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
1273 if ((npr->acceptRspCode == PRLI_REQ_EXECUTED) &&
1274 (npr->prliType == PRLI_FCP_TYPE)) {
1275 if (npr->initiatorFunc)
1276 ndlp->nlp_type |= NLP_FCP_INITIATOR;
1277 if (npr->targetFunc)
1278 ndlp->nlp_type |= NLP_FCP_TARGET;
1280 ndlp->nlp_fcp_info |= NLP_FCP_2_DEVICE;
1283 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
1284 ndlp->nlp_state = NLP_STE_MAPPED_NODE;
1285 lpfc_nlp_list(phba, ndlp, NLP_MAPPED_LIST);
1286 return ndlp->nlp_state;
1289 /*! lpfc_device_rm_prli_issue
1300 * This routine is envoked when we a request to remove a nport we are in the
1301 * process of PRLIing. We should software abort outstanding prli, unreg
1302 * login, send a logout. We will change node state to UNUSED_NODE, put it
1303 * on plogi list so it can be freed when LOGO completes.
1307 lpfc_device_rm_prli_issue(struct lpfc_hba * phba,
1308 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1310 if(ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1311 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
1312 return ndlp->nlp_state;
1315 /* software abort outstanding PLOGI */
1316 lpfc_els_abort(phba, ndlp, 1);
1318 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
1319 return NLP_STE_FREED_NODE;
1324 /*! lpfc_device_recov_prli_issue
1335 * The routine is envoked when the state of a device is unknown, like
1336 * during a link down. We should remove the nodelist entry from the
1337 * unmapped list, issue a UNREG_LOGIN, do a software abort of the
1338 * outstanding PRLI command, then free the node entry.
1341 lpfc_device_recov_prli_issue(struct lpfc_hba * phba,
1342 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1344 /* software abort outstanding PRLI */
1345 lpfc_els_abort(phba, ndlp, 1);
1347 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
1348 ndlp->nlp_state = NLP_STE_NPR_NODE;
1349 lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
1350 spin_lock_irq(phba->host->host_lock);
1351 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
1352 spin_unlock_irq(phba->host->host_lock);
1353 return ndlp->nlp_state;
1357 lpfc_rcv_plogi_unmap_node(struct lpfc_hba * phba,
1358 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1360 struct lpfc_iocbq *cmdiocb;
1362 cmdiocb = (struct lpfc_iocbq *) arg;
1364 lpfc_rcv_plogi(phba, ndlp, cmdiocb);
1365 return ndlp->nlp_state;
1369 lpfc_rcv_prli_unmap_node(struct lpfc_hba * phba,
1370 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1372 struct lpfc_iocbq *cmdiocb;
1374 cmdiocb = (struct lpfc_iocbq *) arg;
1376 lpfc_rcv_prli(phba, ndlp, cmdiocb);
1377 lpfc_els_rsp_prli_acc(phba, cmdiocb, ndlp);
1378 return ndlp->nlp_state;
1382 lpfc_rcv_logo_unmap_node(struct lpfc_hba * phba,
1383 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1385 struct lpfc_iocbq *cmdiocb;
1387 cmdiocb = (struct lpfc_iocbq *) arg;
1389 lpfc_rcv_logo(phba, ndlp, cmdiocb, ELS_CMD_LOGO);
1390 return ndlp->nlp_state;
1394 lpfc_rcv_padisc_unmap_node(struct lpfc_hba * phba,
1395 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1397 struct lpfc_iocbq *cmdiocb;
1399 cmdiocb = (struct lpfc_iocbq *) arg;
1401 lpfc_rcv_padisc(phba, ndlp, cmdiocb);
1402 return ndlp->nlp_state;
1406 lpfc_rcv_prlo_unmap_node(struct lpfc_hba * phba,
1407 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1409 struct lpfc_iocbq *cmdiocb;
1411 cmdiocb = (struct lpfc_iocbq *) arg;
1413 lpfc_els_rsp_acc(phba, ELS_CMD_PRLO, cmdiocb, ndlp, NULL, 0);
1414 return ndlp->nlp_state;
1418 lpfc_device_recov_unmap_node(struct lpfc_hba * phba,
1419 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1421 ndlp->nlp_prev_state = NLP_STE_UNMAPPED_NODE;
1422 ndlp->nlp_state = NLP_STE_NPR_NODE;
1423 lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
1424 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
1425 lpfc_disc_set_adisc(phba, ndlp);
1427 return ndlp->nlp_state;
1431 lpfc_rcv_plogi_mapped_node(struct lpfc_hba * phba,
1432 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1434 struct lpfc_iocbq *cmdiocb;
1436 cmdiocb = (struct lpfc_iocbq *) arg;
1438 lpfc_rcv_plogi(phba, ndlp, cmdiocb);
1439 return ndlp->nlp_state;
1443 lpfc_rcv_prli_mapped_node(struct lpfc_hba * phba,
1444 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1446 struct lpfc_iocbq *cmdiocb;
1448 cmdiocb = (struct lpfc_iocbq *) arg;
1450 lpfc_els_rsp_prli_acc(phba, cmdiocb, ndlp);
1451 return ndlp->nlp_state;
1455 lpfc_rcv_logo_mapped_node(struct lpfc_hba * phba,
1456 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1458 struct lpfc_iocbq *cmdiocb;
1460 cmdiocb = (struct lpfc_iocbq *) arg;
1462 lpfc_rcv_logo(phba, ndlp, cmdiocb, ELS_CMD_LOGO);
1463 return ndlp->nlp_state;
1467 lpfc_rcv_padisc_mapped_node(struct lpfc_hba * phba,
1468 struct lpfc_nodelist * ndlp, void *arg,
1471 struct lpfc_iocbq *cmdiocb;
1473 cmdiocb = (struct lpfc_iocbq *) arg;
1475 lpfc_rcv_padisc(phba, ndlp, cmdiocb);
1476 return ndlp->nlp_state;
1480 lpfc_rcv_prlo_mapped_node(struct lpfc_hba * phba,
1481 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1483 struct lpfc_iocbq *cmdiocb;
1485 cmdiocb = (struct lpfc_iocbq *) arg;
1487 /* flush the target */
1488 spin_lock_irq(phba->host->host_lock);
1489 lpfc_sli_abort_iocb(phba, &phba->sli.ring[phba->sli.fcp_ring],
1490 ndlp->nlp_sid, 0, 0, LPFC_CTX_TGT);
1491 spin_unlock_irq(phba->host->host_lock);
1493 /* Treat like rcv logo */
1494 lpfc_rcv_logo(phba, ndlp, cmdiocb, ELS_CMD_PRLO);
1495 return ndlp->nlp_state;
1499 lpfc_device_recov_mapped_node(struct lpfc_hba * phba,
1500 struct lpfc_nodelist * ndlp, void *arg,
1503 ndlp->nlp_prev_state = NLP_STE_MAPPED_NODE;
1504 ndlp->nlp_state = NLP_STE_NPR_NODE;
1505 lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
1506 spin_lock_irq(phba->host->host_lock);
1507 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
1508 spin_unlock_irq(phba->host->host_lock);
1509 lpfc_disc_set_adisc(phba, ndlp);
1510 return ndlp->nlp_state;
1514 lpfc_rcv_plogi_npr_node(struct lpfc_hba * phba,
1515 struct lpfc_nodelist * ndlp, void *arg,
1518 struct lpfc_iocbq *cmdiocb;
1520 cmdiocb = (struct lpfc_iocbq *) arg;
1522 /* Ignore PLOGI if we have an outstanding LOGO */
1523 if (ndlp->nlp_flag & NLP_LOGO_SND) {
1524 return ndlp->nlp_state;
1527 if (lpfc_rcv_plogi(phba, ndlp, cmdiocb)) {
1528 spin_lock_irq(phba->host->host_lock);
1529 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
1530 spin_unlock_irq(phba->host->host_lock);
1531 return ndlp->nlp_state;
1534 /* send PLOGI immediately, move to PLOGI issue state */
1535 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
1536 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
1537 ndlp->nlp_state = NLP_STE_PLOGI_ISSUE;
1538 lpfc_nlp_list(phba, ndlp, NLP_PLOGI_LIST);
1539 lpfc_issue_els_plogi(phba, ndlp->nlp_DID, 0);
1542 return ndlp->nlp_state;
1546 lpfc_rcv_prli_npr_node(struct lpfc_hba * phba,
1547 struct lpfc_nodelist * ndlp, void *arg,
1550 struct lpfc_iocbq *cmdiocb;
1553 cmdiocb = (struct lpfc_iocbq *) arg;
1555 memset(&stat, 0, sizeof (struct ls_rjt));
1556 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
1557 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
1558 lpfc_els_rsp_reject(phba, stat.un.lsRjtError, cmdiocb, ndlp);
1560 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
1561 if (ndlp->nlp_flag & NLP_NPR_ADISC) {
1562 spin_lock_irq(phba->host->host_lock);
1563 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
1564 spin_unlock_irq(phba->host->host_lock);
1565 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
1566 ndlp->nlp_state = NLP_STE_ADISC_ISSUE;
1567 lpfc_nlp_list(phba, ndlp, NLP_ADISC_LIST);
1568 lpfc_issue_els_adisc(phba, ndlp, 0);
1570 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
1571 ndlp->nlp_state = NLP_STE_PLOGI_ISSUE;
1572 lpfc_nlp_list(phba, ndlp, NLP_PLOGI_LIST);
1573 lpfc_issue_els_plogi(phba, ndlp->nlp_DID, 0);
1577 return ndlp->nlp_state;
1581 lpfc_rcv_logo_npr_node(struct lpfc_hba * phba,
1582 struct lpfc_nodelist * ndlp, void *arg,
1585 struct lpfc_iocbq *cmdiocb;
1587 cmdiocb = (struct lpfc_iocbq *) arg;
1589 lpfc_rcv_logo(phba, ndlp, cmdiocb, ELS_CMD_LOGO);
1590 return ndlp->nlp_state;
1594 lpfc_rcv_padisc_npr_node(struct lpfc_hba * phba,
1595 struct lpfc_nodelist * ndlp, void *arg,
1598 struct lpfc_iocbq *cmdiocb;
1600 cmdiocb = (struct lpfc_iocbq *) arg;
1602 lpfc_rcv_padisc(phba, ndlp, cmdiocb);
1604 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
1605 if (ndlp->nlp_flag & NLP_NPR_ADISC) {
1606 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
1607 ndlp->nlp_state = NLP_STE_ADISC_ISSUE;
1608 lpfc_nlp_list(phba, ndlp, NLP_ADISC_LIST);
1609 lpfc_issue_els_adisc(phba, ndlp, 0);
1611 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
1612 ndlp->nlp_state = NLP_STE_PLOGI_ISSUE;
1613 lpfc_nlp_list(phba, ndlp, NLP_PLOGI_LIST);
1614 lpfc_issue_els_plogi(phba, ndlp->nlp_DID, 0);
1617 return ndlp->nlp_state;
1621 lpfc_rcv_prlo_npr_node(struct lpfc_hba * phba,
1622 struct lpfc_nodelist * ndlp, void *arg,
1625 struct lpfc_iocbq *cmdiocb;
1627 cmdiocb = (struct lpfc_iocbq *) arg;
1629 spin_lock_irq(phba->host->host_lock);
1630 ndlp->nlp_flag |= NLP_LOGO_ACC;
1631 spin_unlock_irq(phba->host->host_lock);
1633 lpfc_els_rsp_acc(phba, ELS_CMD_ACC, cmdiocb, ndlp, NULL, 0);
1635 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
1636 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ * 1);
1637 spin_lock_irq(phba->host->host_lock);
1638 ndlp->nlp_flag |= NLP_DELAY_TMO;
1639 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
1640 spin_unlock_irq(phba->host->host_lock);
1641 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
1643 spin_lock_irq(phba->host->host_lock);
1644 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
1645 spin_unlock_irq(phba->host->host_lock);
1647 return ndlp->nlp_state;
1651 lpfc_cmpl_plogi_npr_node(struct lpfc_hba * phba,
1652 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1654 struct lpfc_iocbq *cmdiocb, *rspiocb;
1657 cmdiocb = (struct lpfc_iocbq *) arg;
1658 rspiocb = cmdiocb->context_un.rsp_iocb;
1660 irsp = &rspiocb->iocb;
1661 if (irsp->ulpStatus) {
1662 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
1663 return NLP_STE_FREED_NODE;
1665 return ndlp->nlp_state;
1669 lpfc_cmpl_prli_npr_node(struct lpfc_hba * phba,
1670 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1672 struct lpfc_iocbq *cmdiocb, *rspiocb;
1675 cmdiocb = (struct lpfc_iocbq *) arg;
1676 rspiocb = cmdiocb->context_un.rsp_iocb;
1678 irsp = &rspiocb->iocb;
1679 if (irsp->ulpStatus && (ndlp->nlp_flag & NLP_NODEV_REMOVE)) {
1680 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
1681 return NLP_STE_FREED_NODE;
1683 return ndlp->nlp_state;
1687 lpfc_cmpl_logo_npr_node(struct lpfc_hba * phba,
1688 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1690 lpfc_unreg_rpi(phba, ndlp);
1691 /* This routine does nothing, just return the current state */
1692 return ndlp->nlp_state;
1696 lpfc_cmpl_adisc_npr_node(struct lpfc_hba * phba,
1697 struct lpfc_nodelist * ndlp, void *arg,
1700 struct lpfc_iocbq *cmdiocb, *rspiocb;
1703 cmdiocb = (struct lpfc_iocbq *) arg;
1704 rspiocb = cmdiocb->context_un.rsp_iocb;
1706 irsp = &rspiocb->iocb;
1707 if (irsp->ulpStatus && (ndlp->nlp_flag & NLP_NODEV_REMOVE)) {
1708 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
1709 return NLP_STE_FREED_NODE;
1711 return ndlp->nlp_state;
1715 lpfc_cmpl_reglogin_npr_node(struct lpfc_hba * phba,
1716 struct lpfc_nodelist * ndlp, void *arg,
1722 pmb = (LPFC_MBOXQ_t *) arg;
1726 ndlp->nlp_rpi = mb->un.varWords[0];
1728 if (ndlp->nlp_flag & NLP_NODEV_REMOVE) {
1729 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
1730 return NLP_STE_FREED_NODE;
1733 return ndlp->nlp_state;
1737 lpfc_device_rm_npr_node(struct lpfc_hba * phba,
1738 struct lpfc_nodelist * ndlp, void *arg,
1741 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1742 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
1743 return ndlp->nlp_state;
1745 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
1746 return NLP_STE_FREED_NODE;
1750 lpfc_device_recov_npr_node(struct lpfc_hba * phba,
1751 struct lpfc_nodelist * ndlp, void *arg,
1754 spin_lock_irq(phba->host->host_lock);
1755 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
1756 spin_unlock_irq(phba->host->host_lock);
1757 if (ndlp->nlp_flag & NLP_DELAY_TMO) {
1758 lpfc_cancel_retry_delay_tmo(phba, ndlp);
1760 return ndlp->nlp_state;
1764 /* This next section defines the NPort Discovery State Machine */
1766 /* There are 4 different double linked lists nodelist entries can reside on.
1767 * The plogi list and adisc list are used when Link Up discovery or RSCN
1768 * processing is needed. Each list holds the nodes that we will send PLOGI
1769 * or ADISC on. These lists will keep track of what nodes will be effected
1770 * by an RSCN, or a Link Up (Typically, all nodes are effected on Link Up).
1771 * The unmapped_list will contain all nodes that we have successfully logged
1772 * into at the Fibre Channel level. The mapped_list will contain all nodes
1773 * that are mapped FCP targets.
1776 * The bind list is a list of undiscovered (potentially non-existent) nodes
1777 * that we have saved binding information on. This information is used when
1778 * nodes transition from the unmapped to the mapped list.
1780 /* For UNUSED_NODE state, the node has just been allocated .
1781 * For PLOGI_ISSUE and REG_LOGIN_ISSUE, the node is on
1782 * the PLOGI list. For REG_LOGIN_COMPL, the node is taken off the PLOGI list
1783 * and put on the unmapped list. For ADISC processing, the node is taken off
1784 * the ADISC list and placed on either the mapped or unmapped list (depending
1785 * on its previous state). Once on the unmapped list, a PRLI is issued and the
1786 * state changed to PRLI_ISSUE. When the PRLI completion occurs, the state is
1787 * changed to UNMAPPED_NODE. If the completion indicates a mapped
1788 * node, the node is taken off the unmapped list. The binding list is checked
1789 * for a valid binding, or a binding is automatically assigned. If binding
1790 * assignment is unsuccessful, the node is left on the unmapped list. If
1791 * binding assignment is successful, the associated binding list entry (if
1792 * any) is removed, and the node is placed on the mapped list.
1795 * For a Link Down, all nodes on the ADISC, PLOGI, unmapped or mapped
1796 * lists will receive a DEVICE_RECOVERY event. If the linkdown or nodev timers
1797 * expire, all effected nodes will receive a DEVICE_RM event.
1800 * For a Link Up or RSCN, all nodes will move from the mapped / unmapped lists
1801 * to either the ADISC or PLOGI list. After a Nameserver query or ALPA loopmap
1802 * check, additional nodes may be added or removed (via DEVICE_RM) to / from
1803 * the PLOGI or ADISC lists. Once the PLOGI and ADISC lists are populated,
1804 * we will first process the ADISC list. 32 entries are processed initially and
1805 * ADISC is initited for each one. Completions / Events for each node are
1806 * funnelled thru the state machine. As each node finishes ADISC processing, it
1807 * starts ADISC for any nodes waiting for ADISC processing. If no nodes are
1808 * waiting, and the ADISC list count is identically 0, then we are done. For
1809 * Link Up discovery, since all nodes on the PLOGI list are UNREG_LOGIN'ed, we
1810 * can issue a CLEAR_LA and reenable Link Events. Next we will process the PLOGI
1811 * list. 32 entries are processed initially and PLOGI is initited for each one.
1812 * Completions / Events for each node are funnelled thru the state machine. As
1813 * each node finishes PLOGI processing, it starts PLOGI for any nodes waiting
1814 * for PLOGI processing. If no nodes are waiting, and the PLOGI list count is
1815 * indentically 0, then we are done. We have now completed discovery / RSCN
1816 * handling. Upon completion, ALL nodes should be on either the mapped or
1820 static uint32_t (*lpfc_disc_action[NLP_STE_MAX_STATE * NLP_EVT_MAX_EVENT])
1821 (struct lpfc_hba *, struct lpfc_nodelist *, void *, uint32_t) = {
1822 /* Action routine Event Current State */
1823 lpfc_rcv_plogi_unused_node, /* RCV_PLOGI UNUSED_NODE */
1824 lpfc_rcv_els_unused_node, /* RCV_PRLI */
1825 lpfc_rcv_logo_unused_node, /* RCV_LOGO */
1826 lpfc_rcv_els_unused_node, /* RCV_ADISC */
1827 lpfc_rcv_els_unused_node, /* RCV_PDISC */
1828 lpfc_rcv_els_unused_node, /* RCV_PRLO */
1829 lpfc_disc_illegal, /* CMPL_PLOGI */
1830 lpfc_disc_illegal, /* CMPL_PRLI */
1831 lpfc_cmpl_logo_unused_node, /* CMPL_LOGO */
1832 lpfc_disc_illegal, /* CMPL_ADISC */
1833 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
1834 lpfc_device_rm_unused_node, /* DEVICE_RM */
1835 lpfc_disc_illegal, /* DEVICE_RECOVERY */
1837 lpfc_rcv_plogi_plogi_issue, /* RCV_PLOGI PLOGI_ISSUE */
1838 lpfc_rcv_els_plogi_issue, /* RCV_PRLI */
1839 lpfc_rcv_logo_plogi_issue, /* RCV_LOGO */
1840 lpfc_rcv_els_plogi_issue, /* RCV_ADISC */
1841 lpfc_rcv_els_plogi_issue, /* RCV_PDISC */
1842 lpfc_rcv_els_plogi_issue, /* RCV_PRLO */
1843 lpfc_cmpl_plogi_plogi_issue, /* CMPL_PLOGI */
1844 lpfc_disc_illegal, /* CMPL_PRLI */
1845 lpfc_disc_illegal, /* CMPL_LOGO */
1846 lpfc_disc_illegal, /* CMPL_ADISC */
1847 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
1848 lpfc_device_rm_plogi_issue, /* DEVICE_RM */
1849 lpfc_device_recov_plogi_issue, /* DEVICE_RECOVERY */
1851 lpfc_rcv_plogi_adisc_issue, /* RCV_PLOGI ADISC_ISSUE */
1852 lpfc_rcv_prli_adisc_issue, /* RCV_PRLI */
1853 lpfc_rcv_logo_adisc_issue, /* RCV_LOGO */
1854 lpfc_rcv_padisc_adisc_issue, /* RCV_ADISC */
1855 lpfc_rcv_padisc_adisc_issue, /* RCV_PDISC */
1856 lpfc_rcv_prlo_adisc_issue, /* RCV_PRLO */
1857 lpfc_disc_illegal, /* CMPL_PLOGI */
1858 lpfc_disc_illegal, /* CMPL_PRLI */
1859 lpfc_disc_illegal, /* CMPL_LOGO */
1860 lpfc_cmpl_adisc_adisc_issue, /* CMPL_ADISC */
1861 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
1862 lpfc_device_rm_adisc_issue, /* DEVICE_RM */
1863 lpfc_device_recov_adisc_issue, /* DEVICE_RECOVERY */
1865 lpfc_rcv_plogi_reglogin_issue, /* RCV_PLOGI REG_LOGIN_ISSUE */
1866 lpfc_rcv_prli_reglogin_issue, /* RCV_PLOGI */
1867 lpfc_rcv_logo_reglogin_issue, /* RCV_LOGO */
1868 lpfc_rcv_padisc_reglogin_issue, /* RCV_ADISC */
1869 lpfc_rcv_padisc_reglogin_issue, /* RCV_PDISC */
1870 lpfc_rcv_prlo_reglogin_issue, /* RCV_PRLO */
1871 lpfc_disc_illegal, /* CMPL_PLOGI */
1872 lpfc_disc_illegal, /* CMPL_PRLI */
1873 lpfc_disc_illegal, /* CMPL_LOGO */
1874 lpfc_disc_illegal, /* CMPL_ADISC */
1875 lpfc_cmpl_reglogin_reglogin_issue,/* CMPL_REG_LOGIN */
1876 lpfc_device_rm_reglogin_issue, /* DEVICE_RM */
1877 lpfc_device_recov_reglogin_issue,/* DEVICE_RECOVERY */
1879 lpfc_rcv_plogi_prli_issue, /* RCV_PLOGI PRLI_ISSUE */
1880 lpfc_rcv_prli_prli_issue, /* RCV_PRLI */
1881 lpfc_rcv_logo_prli_issue, /* RCV_LOGO */
1882 lpfc_rcv_padisc_prli_issue, /* RCV_ADISC */
1883 lpfc_rcv_padisc_prli_issue, /* RCV_PDISC */
1884 lpfc_rcv_prlo_prli_issue, /* RCV_PRLO */
1885 lpfc_disc_illegal, /* CMPL_PLOGI */
1886 lpfc_cmpl_prli_prli_issue, /* CMPL_PRLI */
1887 lpfc_disc_illegal, /* CMPL_LOGO */
1888 lpfc_disc_illegal, /* CMPL_ADISC */
1889 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
1890 lpfc_device_rm_prli_issue, /* DEVICE_RM */
1891 lpfc_device_recov_prli_issue, /* DEVICE_RECOVERY */
1893 lpfc_rcv_plogi_unmap_node, /* RCV_PLOGI UNMAPPED_NODE */
1894 lpfc_rcv_prli_unmap_node, /* RCV_PRLI */
1895 lpfc_rcv_logo_unmap_node, /* RCV_LOGO */
1896 lpfc_rcv_padisc_unmap_node, /* RCV_ADISC */
1897 lpfc_rcv_padisc_unmap_node, /* RCV_PDISC */
1898 lpfc_rcv_prlo_unmap_node, /* RCV_PRLO */
1899 lpfc_disc_illegal, /* CMPL_PLOGI */
1900 lpfc_disc_illegal, /* CMPL_PRLI */
1901 lpfc_disc_illegal, /* CMPL_LOGO */
1902 lpfc_disc_illegal, /* CMPL_ADISC */
1903 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
1904 lpfc_disc_illegal, /* DEVICE_RM */
1905 lpfc_device_recov_unmap_node, /* DEVICE_RECOVERY */
1907 lpfc_rcv_plogi_mapped_node, /* RCV_PLOGI MAPPED_NODE */
1908 lpfc_rcv_prli_mapped_node, /* RCV_PRLI */
1909 lpfc_rcv_logo_mapped_node, /* RCV_LOGO */
1910 lpfc_rcv_padisc_mapped_node, /* RCV_ADISC */
1911 lpfc_rcv_padisc_mapped_node, /* RCV_PDISC */
1912 lpfc_rcv_prlo_mapped_node, /* RCV_PRLO */
1913 lpfc_disc_illegal, /* CMPL_PLOGI */
1914 lpfc_disc_illegal, /* CMPL_PRLI */
1915 lpfc_disc_illegal, /* CMPL_LOGO */
1916 lpfc_disc_illegal, /* CMPL_ADISC */
1917 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
1918 lpfc_disc_illegal, /* DEVICE_RM */
1919 lpfc_device_recov_mapped_node, /* DEVICE_RECOVERY */
1921 lpfc_rcv_plogi_npr_node, /* RCV_PLOGI NPR_NODE */
1922 lpfc_rcv_prli_npr_node, /* RCV_PRLI */
1923 lpfc_rcv_logo_npr_node, /* RCV_LOGO */
1924 lpfc_rcv_padisc_npr_node, /* RCV_ADISC */
1925 lpfc_rcv_padisc_npr_node, /* RCV_PDISC */
1926 lpfc_rcv_prlo_npr_node, /* RCV_PRLO */
1927 lpfc_cmpl_plogi_npr_node, /* CMPL_PLOGI */
1928 lpfc_cmpl_prli_npr_node, /* CMPL_PRLI */
1929 lpfc_cmpl_logo_npr_node, /* CMPL_LOGO */
1930 lpfc_cmpl_adisc_npr_node, /* CMPL_ADISC */
1931 lpfc_cmpl_reglogin_npr_node, /* CMPL_REG_LOGIN */
1932 lpfc_device_rm_npr_node, /* DEVICE_RM */
1933 lpfc_device_recov_npr_node, /* DEVICE_RECOVERY */
1937 lpfc_disc_state_machine(struct lpfc_hba * phba,
1938 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1940 uint32_t cur_state, rc;
1941 uint32_t(*func) (struct lpfc_hba *, struct lpfc_nodelist *, void *,
1944 ndlp->nlp_disc_refcnt++;
1945 cur_state = ndlp->nlp_state;
1947 /* DSM in event <evt> on NPort <nlp_DID> in state <cur_state> */
1948 lpfc_printf_log(phba,
1951 "%d:0211 DSM in event x%x on NPort x%x in state %d "
1954 evt, ndlp->nlp_DID, cur_state, ndlp->nlp_flag);
1956 func = lpfc_disc_action[(cur_state * NLP_EVT_MAX_EVENT) + evt];
1957 rc = (func) (phba, ndlp, arg, evt);
1959 /* DSM out state <rc> on NPort <nlp_DID> */
1960 lpfc_printf_log(phba,
1963 "%d:0212 DSM out state %d on NPort x%x Data: x%x\n",
1965 rc, ndlp->nlp_DID, ndlp->nlp_flag);
1967 ndlp->nlp_disc_refcnt--;
1969 /* Check to see if ndlp removal is deferred */
1970 if ((ndlp->nlp_disc_refcnt == 0)
1971 && (ndlp->nlp_flag & NLP_DELAY_REMOVE)) {
1972 spin_lock_irq(phba->host->host_lock);
1973 ndlp->nlp_flag &= ~NLP_DELAY_REMOVE;
1974 spin_unlock_irq(phba->host->host_lock);
1975 lpfc_nlp_remove(phba, ndlp);
1976 return NLP_STE_FREED_NODE;
1978 if (rc == NLP_STE_FREED_NODE)
1979 return NLP_STE_FREED_NODE;