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 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
264 ndlp->nlp_last_elscmd = 0;
265 del_timer_sync(&ndlp->nlp_delayfunc);
266 if (!list_empty(&ndlp->els_retry_evt.evt_listp))
267 list_del_init(&ndlp->els_retry_evt.evt_listp);
273 lpfc_rcv_plogi(struct lpfc_hba * phba,
274 struct lpfc_nodelist * ndlp,
275 struct lpfc_iocbq *cmdiocb)
277 struct lpfc_dmabuf *pcmd;
280 struct serv_parm *sp;
285 memset(&stat, 0, sizeof (struct ls_rjt));
286 if (phba->hba_state <= LPFC_FLOGI) {
287 /* Before responding to PLOGI, check for pt2pt mode.
288 * If we are pt2pt, with an outstanding FLOGI, abort
289 * the FLOGI and resend it first.
291 if (phba->fc_flag & FC_PT2PT) {
292 lpfc_els_abort_flogi(phba);
293 if (!(phba->fc_flag & FC_PT2PT_PLOGI)) {
294 /* If the other side is supposed to initiate
295 * the PLOGI anyway, just ACC it now and
296 * move on with discovery.
298 phba->fc_edtov = FF_DEF_EDTOV;
299 phba->fc_ratov = FF_DEF_RATOV;
300 /* Start discovery - this should just do
302 lpfc_disc_start(phba);
304 lpfc_initial_flogi(phba);
307 stat.un.b.lsRjtRsnCode = LSRJT_LOGICAL_BSY;
308 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
309 lpfc_els_rsp_reject(phba, stat.un.lsRjtError, cmdiocb,
314 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
315 lp = (uint32_t *) pcmd->virt;
316 sp = (struct serv_parm *) ((uint8_t *) lp + sizeof (uint32_t));
317 if ((lpfc_check_sparm(phba, ndlp, sp, CLASS3) == 0)) {
318 /* Reject this request because invalid parameters */
319 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
320 stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
321 lpfc_els_rsp_reject(phba, stat.un.lsRjtError, cmdiocb, ndlp);
324 icmd = &cmdiocb->iocb;
326 /* PLOGI chkparm OK */
327 lpfc_printf_log(phba,
330 "%d:0114 PLOGI chkparm OK Data: x%x x%x x%x x%x\n",
332 ndlp->nlp_DID, ndlp->nlp_state, ndlp->nlp_flag,
335 if ((phba->cfg_fcp_class == 2) &&
336 (sp->cls2.classValid)) {
337 ndlp->nlp_fcp_info |= CLASS2;
339 ndlp->nlp_fcp_info |= CLASS3;
341 ndlp->nlp_class_sup = 0;
342 if (sp->cls1.classValid)
343 ndlp->nlp_class_sup |= FC_COS_CLASS1;
344 if (sp->cls2.classValid)
345 ndlp->nlp_class_sup |= FC_COS_CLASS2;
346 if (sp->cls3.classValid)
347 ndlp->nlp_class_sup |= FC_COS_CLASS3;
348 if (sp->cls4.classValid)
349 ndlp->nlp_class_sup |= FC_COS_CLASS4;
351 ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) | sp->cmn.bbRcvSizeLsb;
353 /* no need to reg_login if we are already in one of these states */
354 switch (ndlp->nlp_state) {
355 case NLP_STE_NPR_NODE:
356 if (!(ndlp->nlp_flag & NLP_NPR_ADISC))
358 case NLP_STE_REG_LOGIN_ISSUE:
359 case NLP_STE_PRLI_ISSUE:
360 case NLP_STE_UNMAPPED_NODE:
361 case NLP_STE_MAPPED_NODE:
362 lpfc_els_rsp_acc(phba, ELS_CMD_PLOGI, cmdiocb, ndlp, NULL, 0);
366 if ((phba->fc_flag & FC_PT2PT)
367 && !(phba->fc_flag & FC_PT2PT_PLOGI)) {
368 /* rcv'ed PLOGI decides what our NPortId will be */
369 phba->fc_myDID = icmd->un.rcvels.parmRo;
370 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
373 lpfc_config_link(phba, mbox);
374 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
375 rc = lpfc_sli_issue_mbox
376 (phba, mbox, (MBX_NOWAIT | MBX_STOP_IOCB));
377 if (rc == MBX_NOT_FINISHED) {
378 mempool_free( mbox, phba->mbox_mem_pool);
382 lpfc_can_disctmo(phba);
384 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
388 if (lpfc_reg_login(phba, icmd->un.rcvels.remoteID,
389 (uint8_t *) sp, mbox, 0)) {
390 mempool_free( mbox, phba->mbox_mem_pool);
394 /* ACC PLOGI rsp command needs to execute first,
395 * queue this mbox command to be processed later.
397 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
398 mbox->context2 = ndlp;
399 ndlp->nlp_flag |= (NLP_ACC_REGLOGIN | NLP_RCV_PLOGI);
401 lpfc_els_rsp_acc(phba, ELS_CMD_PLOGI, cmdiocb, ndlp, mbox, 0);
405 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
406 stat.un.b.lsRjtRsnCodeExp = LSEXP_OUT_OF_RESOURCE;
407 lpfc_els_rsp_reject(phba, stat.un.lsRjtError, cmdiocb, ndlp);
412 lpfc_rcv_padisc(struct lpfc_hba * phba,
413 struct lpfc_nodelist * ndlp,
414 struct lpfc_iocbq *cmdiocb)
416 struct lpfc_dmabuf *pcmd;
417 struct serv_parm *sp;
418 struct lpfc_name *pnn, *ppn;
425 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
426 lp = (uint32_t *) pcmd->virt;
429 if (cmd == ELS_CMD_ADISC) {
431 pnn = (struct lpfc_name *) & ap->nodeName;
432 ppn = (struct lpfc_name *) & ap->portName;
434 sp = (struct serv_parm *) lp;
435 pnn = (struct lpfc_name *) & sp->nodeName;
436 ppn = (struct lpfc_name *) & sp->portName;
439 icmd = &cmdiocb->iocb;
440 if ((icmd->ulpStatus == 0) &&
441 (lpfc_check_adisc(phba, ndlp, pnn, ppn))) {
442 if (cmd == ELS_CMD_ADISC) {
443 lpfc_els_rsp_adisc_acc(phba, cmdiocb, ndlp);
445 lpfc_els_rsp_acc(phba, ELS_CMD_PLOGI, cmdiocb, ndlp,
450 /* Reject this request because invalid parameters */
451 stat.un.b.lsRjtRsvd0 = 0;
452 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
453 stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
454 stat.un.b.vendorUnique = 0;
455 lpfc_els_rsp_reject(phba, stat.un.lsRjtError, cmdiocb, ndlp);
458 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ);
460 spin_lock_irq(phba->host->host_lock);
461 ndlp->nlp_flag |= NLP_DELAY_TMO;
462 spin_unlock_irq(phba->host->host_lock);
463 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
464 ndlp->nlp_prev_state = ndlp->nlp_state;
465 ndlp->nlp_state = NLP_STE_NPR_NODE;
466 lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
471 lpfc_rcv_logo(struct lpfc_hba * phba,
472 struct lpfc_nodelist * ndlp,
473 struct lpfc_iocbq *cmdiocb)
475 /* Put ndlp on NPR list with 1 sec timeout for plogi, ACC logo */
476 /* Only call LOGO ACC for first LOGO, this avoids sending unnecessary
477 * PLOGIs during LOGO storms from a device.
479 ndlp->nlp_flag |= NLP_LOGO_ACC;
480 lpfc_els_rsp_acc(phba, ELS_CMD_ACC, cmdiocb, ndlp, NULL, 0);
482 if (!(ndlp->nlp_type & NLP_FABRIC) ||
483 (ndlp->nlp_state == NLP_STE_ADISC_ISSUE)) {
484 /* Only try to re-login if this is NOT a Fabric Node */
485 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ * 1);
486 spin_lock_irq(phba->host->host_lock);
487 ndlp->nlp_flag |= NLP_DELAY_TMO;
488 spin_unlock_irq(phba->host->host_lock);
490 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
491 ndlp->nlp_prev_state = ndlp->nlp_state;
492 ndlp->nlp_state = NLP_STE_NPR_NODE;
493 lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
495 ndlp->nlp_prev_state = ndlp->nlp_state;
496 ndlp->nlp_state = NLP_STE_UNUSED_NODE;
497 lpfc_nlp_list(phba, ndlp, NLP_UNUSED_LIST);
500 spin_lock_irq(phba->host->host_lock);
501 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
502 spin_unlock_irq(phba->host->host_lock);
503 /* The driver has to wait until the ACC completes before it continues
504 * processing the LOGO. The action will resume in
505 * lpfc_cmpl_els_logo_acc routine. Since part of processing includes an
506 * unreg_login, the driver waits so the ACC does not get aborted.
512 lpfc_rcv_prli(struct lpfc_hba * phba,
513 struct lpfc_nodelist * ndlp,
514 struct lpfc_iocbq *cmdiocb)
516 struct lpfc_dmabuf *pcmd;
519 struct fc_rport *rport = ndlp->rport;
522 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
523 lp = (uint32_t *) pcmd->virt;
524 npr = (PRLI *) ((uint8_t *) lp + sizeof (uint32_t));
526 ndlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR);
527 ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
528 if ((npr->acceptRspCode == PRLI_REQ_EXECUTED) &&
529 (npr->prliType == PRLI_FCP_TYPE)) {
530 if (npr->initiatorFunc)
531 ndlp->nlp_type |= NLP_FCP_INITIATOR;
533 ndlp->nlp_type |= NLP_FCP_TARGET;
535 ndlp->nlp_fcp_info |= NLP_FCP_2_DEVICE;
538 /* We need to update the rport role values */
539 roles = FC_RPORT_ROLE_UNKNOWN;
540 if (ndlp->nlp_type & NLP_FCP_INITIATOR)
541 roles |= FC_RPORT_ROLE_FCP_INITIATOR;
542 if (ndlp->nlp_type & NLP_FCP_TARGET)
543 roles |= FC_RPORT_ROLE_FCP_TARGET;
544 fc_remote_port_rolechg(rport, roles);
549 lpfc_disc_set_adisc(struct lpfc_hba * phba,
550 struct lpfc_nodelist * ndlp)
552 /* Check config parameter use-adisc or FCP-2 */
553 if ((phba->cfg_use_adisc == 0) &&
554 !(phba->fc_flag & FC_RSCN_MODE)) {
555 if (!(ndlp->nlp_fcp_info & NLP_FCP_2_DEVICE))
558 spin_lock_irq(phba->host->host_lock);
559 ndlp->nlp_flag |= NLP_NPR_ADISC;
560 spin_unlock_irq(phba->host->host_lock);
565 lpfc_disc_illegal(struct lpfc_hba * phba,
566 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
568 lpfc_printf_log(phba,
571 "%d:0253 Illegal State Transition: node x%x event x%x, "
572 "state x%x Data: x%x x%x\n",
574 ndlp->nlp_DID, evt, ndlp->nlp_state, ndlp->nlp_rpi,
576 return ndlp->nlp_state;
579 /* Start of Discovery State Machine routines */
582 lpfc_rcv_plogi_unused_node(struct lpfc_hba * phba,
583 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
585 struct lpfc_iocbq *cmdiocb;
587 cmdiocb = (struct lpfc_iocbq *) arg;
589 if (lpfc_rcv_plogi(phba, ndlp, cmdiocb)) {
590 ndlp->nlp_prev_state = NLP_STE_UNUSED_NODE;
591 ndlp->nlp_state = NLP_STE_UNUSED_NODE;
592 lpfc_nlp_list(phba, ndlp, NLP_UNUSED_LIST);
593 return ndlp->nlp_state;
595 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
596 return NLP_STE_FREED_NODE;
600 lpfc_rcv_els_unused_node(struct lpfc_hba * phba,
601 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
603 lpfc_issue_els_logo(phba, ndlp, 0);
604 lpfc_nlp_list(phba, ndlp, NLP_UNUSED_LIST);
605 return ndlp->nlp_state;
609 lpfc_rcv_logo_unused_node(struct lpfc_hba * phba,
610 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
612 struct lpfc_iocbq *cmdiocb;
614 cmdiocb = (struct lpfc_iocbq *) arg;
616 spin_lock_irq(phba->host->host_lock);
617 ndlp->nlp_flag |= NLP_LOGO_ACC;
618 spin_unlock_irq(phba->host->host_lock);
619 lpfc_els_rsp_acc(phba, ELS_CMD_ACC, cmdiocb, ndlp, NULL, 0);
620 lpfc_nlp_list(phba, ndlp, NLP_UNUSED_LIST);
622 return ndlp->nlp_state;
626 lpfc_cmpl_logo_unused_node(struct lpfc_hba * phba,
627 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
629 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
630 return NLP_STE_FREED_NODE;
634 lpfc_device_rm_unused_node(struct lpfc_hba * phba,
635 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
637 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
638 return NLP_STE_FREED_NODE;
642 lpfc_rcv_plogi_plogi_issue(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp,
643 void *arg, uint32_t evt)
645 struct lpfc_iocbq *cmdiocb = arg;
646 struct lpfc_dmabuf *pcmd;
647 struct serv_parm *sp;
652 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
653 lp = (uint32_t *) pcmd->virt;
654 sp = (struct serv_parm *) ((uint8_t *) lp + sizeof (uint32_t));
656 memset(&stat, 0, sizeof (struct ls_rjt));
658 /* For a PLOGI, we only accept if our portname is less
659 * than the remote portname.
661 phba->fc_stat.elsLogiCol++;
662 port_cmp = memcmp(&phba->fc_portname, &sp->portName,
663 sizeof (struct lpfc_name));
666 /* Reject this request because the remote node will accept
668 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
669 stat.un.b.lsRjtRsnCodeExp = LSEXP_CMD_IN_PROGRESS;
670 lpfc_els_rsp_reject(phba, stat.un.lsRjtError, cmdiocb, ndlp);
672 lpfc_rcv_plogi(phba, ndlp, cmdiocb);
673 } /* if our portname was less */
675 return ndlp->nlp_state;
679 lpfc_rcv_logo_plogi_issue(struct lpfc_hba * phba,
680 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
682 struct lpfc_iocbq *cmdiocb;
684 cmdiocb = (struct lpfc_iocbq *) arg;
686 /* software abort outstanding PLOGI */
687 lpfc_els_abort(phba, ndlp, 1);
689 lpfc_rcv_logo(phba, ndlp, cmdiocb);
690 return ndlp->nlp_state;
694 lpfc_rcv_els_plogi_issue(struct lpfc_hba * phba,
695 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
697 struct lpfc_iocbq *cmdiocb;
699 cmdiocb = (struct lpfc_iocbq *) arg;
701 /* software abort outstanding PLOGI */
702 lpfc_els_abort(phba, ndlp, 1);
704 if (evt == NLP_EVT_RCV_LOGO) {
705 lpfc_els_rsp_acc(phba, ELS_CMD_ACC, cmdiocb, ndlp, NULL, 0);
707 lpfc_issue_els_logo(phba, ndlp, 0);
710 /* Put ndlp in npr list set plogi timer for 1 sec */
711 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ * 1);
712 spin_lock_irq(phba->host->host_lock);
713 ndlp->nlp_flag |= NLP_DELAY_TMO;
714 spin_unlock_irq(phba->host->host_lock);
715 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
716 ndlp->nlp_prev_state = NLP_STE_PLOGI_ISSUE;
717 ndlp->nlp_state = NLP_STE_NPR_NODE;
718 lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
720 return ndlp->nlp_state;
724 lpfc_cmpl_plogi_plogi_issue(struct lpfc_hba * phba,
725 struct lpfc_nodelist * ndlp, void *arg,
728 struct lpfc_iocbq *cmdiocb, *rspiocb;
729 struct lpfc_dmabuf *pcmd, *prsp;
732 struct serv_parm *sp;
735 cmdiocb = (struct lpfc_iocbq *) arg;
736 rspiocb = cmdiocb->context_un.rsp_iocb;
738 if (ndlp->nlp_flag & NLP_ACC_REGLOGIN) {
739 /* Recovery from PLOGI collision logic */
740 return ndlp->nlp_state;
743 irsp = &rspiocb->iocb;
748 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
750 prsp = list_get_first(&pcmd->list,
753 lp = (uint32_t *) prsp->virt;
755 sp = (struct serv_parm *) ((uint8_t *) lp + sizeof (uint32_t));
756 if (!lpfc_check_sparm(phba, ndlp, sp, CLASS3))
759 /* PLOGI chkparm OK */
760 lpfc_printf_log(phba,
763 "%d:0121 PLOGI chkparm OK "
764 "Data: x%x x%x x%x x%x\n",
766 ndlp->nlp_DID, ndlp->nlp_state,
767 ndlp->nlp_flag, ndlp->nlp_rpi);
769 if ((phba->cfg_fcp_class == 2) &&
770 (sp->cls2.classValid)) {
771 ndlp->nlp_fcp_info |= CLASS2;
773 ndlp->nlp_fcp_info |= CLASS3;
775 ndlp->nlp_class_sup = 0;
776 if (sp->cls1.classValid)
777 ndlp->nlp_class_sup |= FC_COS_CLASS1;
778 if (sp->cls2.classValid)
779 ndlp->nlp_class_sup |= FC_COS_CLASS2;
780 if (sp->cls3.classValid)
781 ndlp->nlp_class_sup |= FC_COS_CLASS3;
782 if (sp->cls4.classValid)
783 ndlp->nlp_class_sup |= FC_COS_CLASS4;
785 ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) |
786 sp->cmn.bbRcvSizeLsb;
788 if (!(mbox = mempool_alloc(phba->mbox_mem_pool,
792 lpfc_unreg_rpi(phba, ndlp);
794 (phba, irsp->un.elsreq64.remoteID,
795 (uint8_t *) sp, mbox, 0) == 0) {
796 /* set_slim mailbox command needs to
797 * execute first, queue this command to
798 * be processed later.
800 switch (ndlp->nlp_DID) {
803 lpfc_mbx_cmpl_ns_reg_login;
807 lpfc_mbx_cmpl_fdmi_reg_login;
811 lpfc_mbx_cmpl_reg_login;
813 mbox->context2 = ndlp;
814 if (lpfc_sli_issue_mbox(phba, mbox,
815 (MBX_NOWAIT | MBX_STOP_IOCB))
816 != MBX_NOT_FINISHED) {
818 NLP_STE_REG_LOGIN_ISSUE;
819 lpfc_nlp_list(phba, ndlp,
821 return ndlp->nlp_state;
823 mempool_free(mbox, phba->mbox_mem_pool);
825 mempool_free(mbox, phba->mbox_mem_pool);
830 /* Free this node since the driver cannot login or has the wrong
832 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
833 return NLP_STE_FREED_NODE;
837 lpfc_device_rm_plogi_issue(struct lpfc_hba * phba,
838 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
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;
848 lpfc_device_recov_plogi_issue(struct lpfc_hba * phba,
849 struct lpfc_nodelist * ndlp, void *arg,
852 /* software abort outstanding PLOGI */
853 lpfc_els_abort(phba, ndlp, 1);
855 ndlp->nlp_prev_state = NLP_STE_PLOGI_ISSUE;
856 ndlp->nlp_state = NLP_STE_NPR_NODE;
857 lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
858 spin_lock_irq(phba->host->host_lock);
859 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
860 spin_unlock_irq(phba->host->host_lock);
862 return ndlp->nlp_state;
866 lpfc_rcv_plogi_adisc_issue(struct lpfc_hba * phba,
867 struct lpfc_nodelist * ndlp, void *arg,
870 struct lpfc_iocbq *cmdiocb;
872 /* software abort outstanding ADISC */
873 lpfc_els_abort(phba, ndlp, 1);
875 cmdiocb = (struct lpfc_iocbq *) arg;
877 if (lpfc_rcv_plogi(phba, ndlp, cmdiocb)) {
878 return ndlp->nlp_state;
880 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
881 ndlp->nlp_state = NLP_STE_PLOGI_ISSUE;
882 lpfc_nlp_list(phba, ndlp, NLP_PLOGI_LIST);
883 lpfc_issue_els_plogi(phba, ndlp, 0);
885 return ndlp->nlp_state;
889 lpfc_rcv_prli_adisc_issue(struct lpfc_hba * phba,
890 struct lpfc_nodelist * ndlp, void *arg,
893 struct lpfc_iocbq *cmdiocb;
895 cmdiocb = (struct lpfc_iocbq *) arg;
897 lpfc_els_rsp_prli_acc(phba, cmdiocb, ndlp);
898 return ndlp->nlp_state;
902 lpfc_rcv_logo_adisc_issue(struct lpfc_hba * phba,
903 struct lpfc_nodelist * ndlp, void *arg,
906 struct lpfc_iocbq *cmdiocb;
908 cmdiocb = (struct lpfc_iocbq *) arg;
910 /* software abort outstanding ADISC */
911 lpfc_els_abort(phba, ndlp, 0);
913 lpfc_rcv_logo(phba, ndlp, cmdiocb);
914 return ndlp->nlp_state;
918 lpfc_rcv_padisc_adisc_issue(struct lpfc_hba * phba,
919 struct lpfc_nodelist * ndlp, void *arg,
922 struct lpfc_iocbq *cmdiocb;
924 cmdiocb = (struct lpfc_iocbq *) arg;
926 lpfc_rcv_padisc(phba, ndlp, cmdiocb);
927 return ndlp->nlp_state;
931 lpfc_rcv_prlo_adisc_issue(struct lpfc_hba * phba,
932 struct lpfc_nodelist * ndlp, void *arg,
935 struct lpfc_iocbq *cmdiocb;
937 cmdiocb = (struct lpfc_iocbq *) arg;
939 /* Treat like rcv logo */
940 lpfc_rcv_logo(phba, ndlp, cmdiocb);
941 return ndlp->nlp_state;
945 lpfc_cmpl_adisc_adisc_issue(struct lpfc_hba * phba,
946 struct lpfc_nodelist * ndlp, void *arg,
949 struct lpfc_iocbq *cmdiocb, *rspiocb;
953 cmdiocb = (struct lpfc_iocbq *) arg;
954 rspiocb = cmdiocb->context_un.rsp_iocb;
956 ap = (ADISC *)lpfc_check_elscmpl_iocb(phba, cmdiocb, rspiocb);
957 irsp = &rspiocb->iocb;
959 if ((irsp->ulpStatus) ||
960 (!lpfc_check_adisc(phba, ndlp, &ap->nodeName, &ap->portName))) {
962 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ);
963 spin_lock_irq(phba->host->host_lock);
964 ndlp->nlp_flag |= NLP_DELAY_TMO;
965 spin_unlock_irq(phba->host->host_lock);
966 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
968 memset(&ndlp->nlp_nodename, 0, sizeof (struct lpfc_name));
969 memset(&ndlp->nlp_portname, 0, sizeof (struct lpfc_name));
971 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
972 ndlp->nlp_state = NLP_STE_NPR_NODE;
973 lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
974 lpfc_unreg_rpi(phba, ndlp);
975 return ndlp->nlp_state;
978 if (ndlp->nlp_type & NLP_FCP_TARGET) {
979 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
980 ndlp->nlp_state = NLP_STE_MAPPED_NODE;
981 lpfc_nlp_list(phba, ndlp, NLP_MAPPED_LIST);
983 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
984 ndlp->nlp_state = NLP_STE_UNMAPPED_NODE;
985 lpfc_nlp_list(phba, ndlp, NLP_UNMAPPED_LIST);
987 return ndlp->nlp_state;
991 lpfc_device_rm_adisc_issue(struct lpfc_hba * phba,
992 struct lpfc_nodelist * ndlp, void *arg,
995 /* software abort outstanding ADISC */
996 lpfc_els_abort(phba, ndlp, 1);
998 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
999 return NLP_STE_FREED_NODE;
1003 lpfc_device_recov_adisc_issue(struct lpfc_hba * phba,
1004 struct lpfc_nodelist * ndlp, void *arg,
1007 /* software abort outstanding ADISC */
1008 lpfc_els_abort(phba, ndlp, 1);
1010 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
1011 ndlp->nlp_state = NLP_STE_NPR_NODE;
1012 lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
1013 spin_lock_irq(phba->host->host_lock);
1014 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
1015 ndlp->nlp_flag |= NLP_NPR_ADISC;
1016 spin_unlock_irq(phba->host->host_lock);
1018 return ndlp->nlp_state;
1022 lpfc_rcv_plogi_reglogin_issue(struct lpfc_hba * phba,
1023 struct lpfc_nodelist * ndlp, void *arg,
1026 struct lpfc_iocbq *cmdiocb;
1028 cmdiocb = (struct lpfc_iocbq *) arg;
1030 lpfc_rcv_plogi(phba, ndlp, cmdiocb);
1031 return ndlp->nlp_state;
1035 lpfc_rcv_prli_reglogin_issue(struct lpfc_hba * phba,
1036 struct lpfc_nodelist * ndlp, void *arg,
1039 struct lpfc_iocbq *cmdiocb;
1041 cmdiocb = (struct lpfc_iocbq *) arg;
1043 lpfc_els_rsp_prli_acc(phba, cmdiocb, ndlp);
1044 return ndlp->nlp_state;
1048 lpfc_rcv_logo_reglogin_issue(struct lpfc_hba * phba,
1049 struct lpfc_nodelist * ndlp, void *arg,
1052 struct lpfc_iocbq *cmdiocb;
1054 cmdiocb = (struct lpfc_iocbq *) arg;
1056 lpfc_rcv_logo(phba, ndlp, cmdiocb);
1057 return ndlp->nlp_state;
1061 lpfc_rcv_padisc_reglogin_issue(struct lpfc_hba * phba,
1062 struct lpfc_nodelist * ndlp, void *arg,
1065 struct lpfc_iocbq *cmdiocb;
1067 cmdiocb = (struct lpfc_iocbq *) arg;
1069 lpfc_rcv_padisc(phba, ndlp, cmdiocb);
1070 return ndlp->nlp_state;
1074 lpfc_rcv_prlo_reglogin_issue(struct lpfc_hba * phba,
1075 struct lpfc_nodelist * ndlp, void *arg,
1078 struct lpfc_iocbq *cmdiocb;
1080 cmdiocb = (struct lpfc_iocbq *) arg;
1081 lpfc_els_rsp_acc(phba, ELS_CMD_ACC, cmdiocb, ndlp, NULL, 0);
1082 return ndlp->nlp_state;
1086 lpfc_cmpl_reglogin_reglogin_issue(struct lpfc_hba * phba,
1087 struct lpfc_nodelist * ndlp,
1088 void *arg, uint32_t evt)
1094 pmb = (LPFC_MBOXQ_t *) arg;
1096 did = mb->un.varWords[1];
1097 if (mb->mbxStatus) {
1098 /* RegLogin failed */
1099 lpfc_printf_log(phba,
1102 "%d:0246 RegLogin failed Data: x%x x%x x%x\n",
1104 did, mb->mbxStatus, phba->hba_state);
1106 /* Put ndlp in npr list set plogi timer for 1 sec */
1107 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ * 1);
1108 spin_lock_irq(phba->host->host_lock);
1109 ndlp->nlp_flag |= NLP_DELAY_TMO;
1110 spin_unlock_irq(phba->host->host_lock);
1111 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
1113 lpfc_issue_els_logo(phba, ndlp, 0);
1114 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
1115 ndlp->nlp_state = NLP_STE_NPR_NODE;
1116 lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
1117 return ndlp->nlp_state;
1120 ndlp->nlp_rpi = mb->un.varWords[0];
1122 /* Only if we are not a fabric nport do we issue PRLI */
1123 if (!(ndlp->nlp_type & NLP_FABRIC)) {
1124 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
1125 ndlp->nlp_state = NLP_STE_PRLI_ISSUE;
1126 lpfc_nlp_list(phba, ndlp, NLP_PRLI_LIST);
1127 lpfc_issue_els_prli(phba, ndlp, 0);
1129 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
1130 ndlp->nlp_state = NLP_STE_UNMAPPED_NODE;
1131 lpfc_nlp_list(phba, ndlp, NLP_UNMAPPED_LIST);
1133 return ndlp->nlp_state;
1137 lpfc_device_rm_reglogin_issue(struct lpfc_hba * phba,
1138 struct lpfc_nodelist * ndlp, void *arg,
1141 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
1142 return NLP_STE_FREED_NODE;
1146 lpfc_device_recov_reglogin_issue(struct lpfc_hba * phba,
1147 struct lpfc_nodelist * ndlp, void *arg,
1150 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
1151 ndlp->nlp_state = NLP_STE_NPR_NODE;
1152 lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
1153 spin_lock_irq(phba->host->host_lock);
1154 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
1155 spin_unlock_irq(phba->host->host_lock);
1156 return ndlp->nlp_state;
1160 lpfc_rcv_plogi_prli_issue(struct lpfc_hba * phba,
1161 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1163 struct lpfc_iocbq *cmdiocb;
1165 cmdiocb = (struct lpfc_iocbq *) arg;
1167 lpfc_rcv_plogi(phba, ndlp, cmdiocb);
1168 return ndlp->nlp_state;
1172 lpfc_rcv_prli_prli_issue(struct lpfc_hba * phba,
1173 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1175 struct lpfc_iocbq *cmdiocb;
1177 cmdiocb = (struct lpfc_iocbq *) arg;
1179 lpfc_els_rsp_prli_acc(phba, cmdiocb, ndlp);
1180 return ndlp->nlp_state;
1184 lpfc_rcv_logo_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 /* Software abort outstanding PRLI before sending acc */
1192 lpfc_els_abort(phba, ndlp, 1);
1194 lpfc_rcv_logo(phba, ndlp, cmdiocb);
1195 return ndlp->nlp_state;
1199 lpfc_rcv_padisc_prli_issue(struct lpfc_hba * phba,
1200 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1202 struct lpfc_iocbq *cmdiocb;
1204 cmdiocb = (struct lpfc_iocbq *) arg;
1206 lpfc_rcv_padisc(phba, ndlp, cmdiocb);
1207 return ndlp->nlp_state;
1210 /* This routine is envoked when we rcv a PRLO request from a nport
1211 * we are logged into. We should send back a PRLO rsp setting the
1213 * NEXT STATE = PRLI_ISSUE
1216 lpfc_rcv_prlo_prli_issue(struct lpfc_hba * phba,
1217 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1219 struct lpfc_iocbq *cmdiocb;
1221 cmdiocb = (struct lpfc_iocbq *) arg;
1222 lpfc_els_rsp_acc(phba, ELS_CMD_ACC, cmdiocb, ndlp, NULL, 0);
1223 return ndlp->nlp_state;
1227 lpfc_cmpl_prli_prli_issue(struct lpfc_hba * phba,
1228 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1230 struct lpfc_iocbq *cmdiocb, *rspiocb;
1234 cmdiocb = (struct lpfc_iocbq *) arg;
1235 rspiocb = cmdiocb->context_un.rsp_iocb;
1236 npr = (PRLI *)lpfc_check_elscmpl_iocb(phba, cmdiocb, rspiocb);
1238 irsp = &rspiocb->iocb;
1239 if (irsp->ulpStatus) {
1240 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
1241 ndlp->nlp_state = NLP_STE_UNMAPPED_NODE;
1242 lpfc_nlp_list(phba, ndlp, NLP_UNMAPPED_LIST);
1243 return ndlp->nlp_state;
1246 /* Check out PRLI rsp */
1247 ndlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR);
1248 ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
1249 if ((npr->acceptRspCode == PRLI_REQ_EXECUTED) &&
1250 (npr->prliType == PRLI_FCP_TYPE)) {
1251 if (npr->initiatorFunc)
1252 ndlp->nlp_type |= NLP_FCP_INITIATOR;
1253 if (npr->targetFunc)
1254 ndlp->nlp_type |= NLP_FCP_TARGET;
1256 ndlp->nlp_fcp_info |= NLP_FCP_2_DEVICE;
1259 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
1260 ndlp->nlp_state = NLP_STE_MAPPED_NODE;
1261 lpfc_nlp_list(phba, ndlp, NLP_MAPPED_LIST);
1262 return ndlp->nlp_state;
1265 /*! lpfc_device_rm_prli_issue
1276 * This routine is envoked when we a request to remove a nport we are in the
1277 * process of PRLIing. We should software abort outstanding prli, unreg
1278 * login, send a logout. We will change node state to UNUSED_NODE, put it
1279 * on plogi list so it can be freed when LOGO completes.
1283 lpfc_device_rm_prli_issue(struct lpfc_hba * phba,
1284 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1286 /* software abort outstanding PRLI */
1287 lpfc_els_abort(phba, ndlp, 1);
1289 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
1290 return NLP_STE_FREED_NODE;
1294 /*! lpfc_device_recov_prli_issue
1305 * The routine is envoked when the state of a device is unknown, like
1306 * during a link down. We should remove the nodelist entry from the
1307 * unmapped list, issue a UNREG_LOGIN, do a software abort of the
1308 * outstanding PRLI command, then free the node entry.
1311 lpfc_device_recov_prli_issue(struct lpfc_hba * phba,
1312 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1314 /* software abort outstanding PRLI */
1315 lpfc_els_abort(phba, ndlp, 1);
1317 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
1318 ndlp->nlp_state = NLP_STE_NPR_NODE;
1319 lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
1320 spin_lock_irq(phba->host->host_lock);
1321 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
1322 spin_unlock_irq(phba->host->host_lock);
1323 return ndlp->nlp_state;
1327 lpfc_rcv_plogi_unmap_node(struct lpfc_hba * phba,
1328 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1330 struct lpfc_iocbq *cmdiocb;
1332 cmdiocb = (struct lpfc_iocbq *) arg;
1334 lpfc_rcv_plogi(phba, ndlp, cmdiocb);
1335 return ndlp->nlp_state;
1339 lpfc_rcv_prli_unmap_node(struct lpfc_hba * phba,
1340 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1342 struct lpfc_iocbq *cmdiocb;
1344 cmdiocb = (struct lpfc_iocbq *) arg;
1346 lpfc_rcv_prli(phba, ndlp, cmdiocb);
1347 lpfc_els_rsp_prli_acc(phba, cmdiocb, ndlp);
1348 return ndlp->nlp_state;
1352 lpfc_rcv_logo_unmap_node(struct lpfc_hba * phba,
1353 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1355 struct lpfc_iocbq *cmdiocb;
1357 cmdiocb = (struct lpfc_iocbq *) arg;
1359 lpfc_rcv_logo(phba, ndlp, cmdiocb);
1360 return ndlp->nlp_state;
1364 lpfc_rcv_padisc_unmap_node(struct lpfc_hba * phba,
1365 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1367 struct lpfc_iocbq *cmdiocb;
1369 cmdiocb = (struct lpfc_iocbq *) arg;
1371 lpfc_rcv_padisc(phba, ndlp, cmdiocb);
1372 return ndlp->nlp_state;
1376 lpfc_rcv_prlo_unmap_node(struct lpfc_hba * phba,
1377 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1379 struct lpfc_iocbq *cmdiocb;
1381 cmdiocb = (struct lpfc_iocbq *) arg;
1383 lpfc_els_rsp_acc(phba, ELS_CMD_ACC, cmdiocb, ndlp, NULL, 0);
1384 return ndlp->nlp_state;
1388 lpfc_device_recov_unmap_node(struct lpfc_hba * phba,
1389 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1391 ndlp->nlp_prev_state = NLP_STE_UNMAPPED_NODE;
1392 ndlp->nlp_state = NLP_STE_NPR_NODE;
1393 lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
1394 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
1395 lpfc_disc_set_adisc(phba, ndlp);
1397 return ndlp->nlp_state;
1401 lpfc_rcv_plogi_mapped_node(struct lpfc_hba * phba,
1402 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1404 struct lpfc_iocbq *cmdiocb;
1406 cmdiocb = (struct lpfc_iocbq *) arg;
1408 lpfc_rcv_plogi(phba, ndlp, cmdiocb);
1409 return ndlp->nlp_state;
1413 lpfc_rcv_prli_mapped_node(struct lpfc_hba * phba,
1414 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1416 struct lpfc_iocbq *cmdiocb;
1418 cmdiocb = (struct lpfc_iocbq *) arg;
1420 lpfc_els_rsp_prli_acc(phba, cmdiocb, ndlp);
1421 return ndlp->nlp_state;
1425 lpfc_rcv_logo_mapped_node(struct lpfc_hba * phba,
1426 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1428 struct lpfc_iocbq *cmdiocb;
1430 cmdiocb = (struct lpfc_iocbq *) arg;
1432 lpfc_rcv_logo(phba, ndlp, cmdiocb);
1433 return ndlp->nlp_state;
1437 lpfc_rcv_padisc_mapped_node(struct lpfc_hba * phba,
1438 struct lpfc_nodelist * ndlp, void *arg,
1441 struct lpfc_iocbq *cmdiocb;
1443 cmdiocb = (struct lpfc_iocbq *) arg;
1445 lpfc_rcv_padisc(phba, ndlp, cmdiocb);
1446 return ndlp->nlp_state;
1450 lpfc_rcv_prlo_mapped_node(struct lpfc_hba * phba,
1451 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1453 struct lpfc_iocbq *cmdiocb;
1455 cmdiocb = (struct lpfc_iocbq *) arg;
1457 /* flush the target */
1458 spin_lock_irq(phba->host->host_lock);
1459 lpfc_sli_abort_iocb(phba, &phba->sli.ring[phba->sli.fcp_ring],
1460 ndlp->nlp_sid, 0, 0, LPFC_CTX_TGT);
1461 spin_unlock_irq(phba->host->host_lock);
1463 /* Treat like rcv logo */
1464 lpfc_rcv_logo(phba, ndlp, cmdiocb);
1465 return ndlp->nlp_state;
1469 lpfc_device_recov_mapped_node(struct lpfc_hba * phba,
1470 struct lpfc_nodelist * ndlp, void *arg,
1473 ndlp->nlp_prev_state = NLP_STE_MAPPED_NODE;
1474 ndlp->nlp_state = NLP_STE_NPR_NODE;
1475 lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
1476 spin_lock_irq(phba->host->host_lock);
1477 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
1478 spin_unlock_irq(phba->host->host_lock);
1479 lpfc_disc_set_adisc(phba, ndlp);
1480 return ndlp->nlp_state;
1484 lpfc_rcv_plogi_npr_node(struct lpfc_hba * phba,
1485 struct lpfc_nodelist * ndlp, void *arg,
1488 struct lpfc_iocbq *cmdiocb;
1490 cmdiocb = (struct lpfc_iocbq *) arg;
1492 /* Ignore PLOGI if we have an outstanding LOGO */
1493 if (ndlp->nlp_flag & NLP_LOGO_SND) {
1494 return ndlp->nlp_state;
1497 if (lpfc_rcv_plogi(phba, ndlp, cmdiocb)) {
1498 spin_lock_irq(phba->host->host_lock);
1499 ndlp->nlp_flag &= ~(NLP_NPR_ADISC | NLP_NPR_2B_DISC);
1500 spin_unlock_irq(phba->host->host_lock);
1501 return ndlp->nlp_state;
1504 /* send PLOGI immediately, move to PLOGI issue state */
1505 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
1506 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
1507 ndlp->nlp_state = NLP_STE_PLOGI_ISSUE;
1508 lpfc_nlp_list(phba, ndlp, NLP_PLOGI_LIST);
1509 lpfc_issue_els_plogi(phba, ndlp, 0);
1511 return ndlp->nlp_state;
1515 lpfc_rcv_prli_npr_node(struct lpfc_hba * phba,
1516 struct lpfc_nodelist * ndlp, void *arg,
1519 struct lpfc_iocbq *cmdiocb;
1522 cmdiocb = (struct lpfc_iocbq *) arg;
1524 memset(&stat, 0, sizeof (struct ls_rjt));
1525 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
1526 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
1527 lpfc_els_rsp_reject(phba, stat.un.lsRjtError, cmdiocb, ndlp);
1529 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
1530 if (ndlp->nlp_flag & NLP_NPR_ADISC) {
1531 spin_lock_irq(phba->host->host_lock);
1532 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
1533 spin_unlock_irq(phba->host->host_lock);
1534 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
1535 ndlp->nlp_state = NLP_STE_ADISC_ISSUE;
1536 lpfc_nlp_list(phba, ndlp, NLP_ADISC_LIST);
1537 lpfc_issue_els_adisc(phba, ndlp, 0);
1539 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
1540 ndlp->nlp_state = NLP_STE_PLOGI_ISSUE;
1541 lpfc_nlp_list(phba, ndlp, NLP_PLOGI_LIST);
1542 lpfc_issue_els_plogi(phba, ndlp, 0);
1545 return ndlp->nlp_state;
1549 lpfc_rcv_logo_npr_node(struct lpfc_hba * phba,
1550 struct lpfc_nodelist * ndlp, void *arg,
1553 struct lpfc_iocbq *cmdiocb;
1555 cmdiocb = (struct lpfc_iocbq *) arg;
1557 lpfc_rcv_logo(phba, ndlp, cmdiocb);
1558 return ndlp->nlp_state;
1562 lpfc_rcv_padisc_npr_node(struct lpfc_hba * phba,
1563 struct lpfc_nodelist * ndlp, void *arg,
1566 struct lpfc_iocbq *cmdiocb;
1568 cmdiocb = (struct lpfc_iocbq *) arg;
1570 lpfc_rcv_padisc(phba, ndlp, cmdiocb);
1572 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
1573 if (ndlp->nlp_flag & NLP_NPR_ADISC) {
1574 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
1575 ndlp->nlp_state = NLP_STE_ADISC_ISSUE;
1576 lpfc_nlp_list(phba, ndlp, NLP_ADISC_LIST);
1577 lpfc_issue_els_adisc(phba, ndlp, 0);
1579 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
1580 ndlp->nlp_state = NLP_STE_PLOGI_ISSUE;
1581 lpfc_nlp_list(phba, ndlp, NLP_PLOGI_LIST);
1582 lpfc_issue_els_plogi(phba, ndlp, 0);
1585 return ndlp->nlp_state;
1589 lpfc_rcv_prlo_npr_node(struct lpfc_hba * phba,
1590 struct lpfc_nodelist * ndlp, void *arg,
1593 struct lpfc_iocbq *cmdiocb;
1595 cmdiocb = (struct lpfc_iocbq *) arg;
1597 spin_lock_irq(phba->host->host_lock);
1598 ndlp->nlp_flag |= NLP_LOGO_ACC;
1599 spin_unlock_irq(phba->host->host_lock);
1601 lpfc_els_rsp_acc(phba, ELS_CMD_ACC, cmdiocb, ndlp, NULL, 0);
1603 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
1604 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ * 1);
1605 spin_lock_irq(phba->host->host_lock);
1606 ndlp->nlp_flag |= NLP_DELAY_TMO;
1607 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
1608 spin_unlock_irq(phba->host->host_lock);
1609 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
1611 spin_lock_irq(phba->host->host_lock);
1612 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
1613 spin_unlock_irq(phba->host->host_lock);
1615 return ndlp->nlp_state;
1619 lpfc_cmpl_plogi_npr_node(struct lpfc_hba * phba,
1620 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1622 struct lpfc_iocbq *cmdiocb, *rspiocb;
1624 cmdiocb = (struct lpfc_iocbq *) arg;
1625 rspiocb = cmdiocb->context_un.rsp_iocb;
1626 return ndlp->nlp_state;
1630 lpfc_cmpl_prli_npr_node(struct lpfc_hba * phba,
1631 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1633 struct lpfc_iocbq *cmdiocb, *rspiocb;
1635 cmdiocb = (struct lpfc_iocbq *) arg;
1636 rspiocb = cmdiocb->context_un.rsp_iocb;
1637 return ndlp->nlp_state;
1641 lpfc_cmpl_logo_npr_node(struct lpfc_hba * phba,
1642 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1644 lpfc_unreg_rpi(phba, ndlp);
1645 /* This routine does nothing, just return the current state */
1646 return ndlp->nlp_state;
1650 lpfc_cmpl_adisc_npr_node(struct lpfc_hba * phba,
1651 struct lpfc_nodelist * ndlp, void *arg,
1654 struct lpfc_iocbq *cmdiocb, *rspiocb;
1656 cmdiocb = (struct lpfc_iocbq *) arg;
1657 rspiocb = cmdiocb->context_un.rsp_iocb;
1658 return ndlp->nlp_state;
1662 lpfc_cmpl_reglogin_npr_node(struct lpfc_hba * phba,
1663 struct lpfc_nodelist * ndlp, void *arg,
1669 pmb = (LPFC_MBOXQ_t *) arg;
1673 ndlp->nlp_rpi = mb->un.varWords[0];
1675 return ndlp->nlp_state;
1679 lpfc_device_rm_npr_node(struct lpfc_hba * phba,
1680 struct lpfc_nodelist * ndlp, void *arg,
1683 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
1684 return NLP_STE_FREED_NODE;
1688 lpfc_device_recov_npr_node(struct lpfc_hba * phba,
1689 struct lpfc_nodelist * ndlp, void *arg,
1692 spin_lock_irq(phba->host->host_lock);
1693 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
1694 if (ndlp->nlp_flag & NLP_DELAY_TMO) {
1695 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
1696 if (!list_empty(&ndlp->els_retry_evt.evt_listp))
1697 list_del_init(&ndlp->els_retry_evt.evt_listp);
1698 spin_unlock_irq(phba->host->host_lock);
1699 ndlp->nlp_last_elscmd = 0;
1700 del_timer_sync(&ndlp->nlp_delayfunc);
1701 return ndlp->nlp_state;
1703 spin_unlock_irq(phba->host->host_lock);
1704 return ndlp->nlp_state;
1708 /* This next section defines the NPort Discovery State Machine */
1710 /* There are 4 different double linked lists nodelist entries can reside on.
1711 * The plogi list and adisc list are used when Link Up discovery or RSCN
1712 * processing is needed. Each list holds the nodes that we will send PLOGI
1713 * or ADISC on. These lists will keep track of what nodes will be effected
1714 * by an RSCN, or a Link Up (Typically, all nodes are effected on Link Up).
1715 * The unmapped_list will contain all nodes that we have successfully logged
1716 * into at the Fibre Channel level. The mapped_list will contain all nodes
1717 * that are mapped FCP targets.
1720 * The bind list is a list of undiscovered (potentially non-existent) nodes
1721 * that we have saved binding information on. This information is used when
1722 * nodes transition from the unmapped to the mapped list.
1724 /* For UNUSED_NODE state, the node has just been allocated .
1725 * For PLOGI_ISSUE and REG_LOGIN_ISSUE, the node is on
1726 * the PLOGI list. For REG_LOGIN_COMPL, the node is taken off the PLOGI list
1727 * and put on the unmapped list. For ADISC processing, the node is taken off
1728 * the ADISC list and placed on either the mapped or unmapped list (depending
1729 * on its previous state). Once on the unmapped list, a PRLI is issued and the
1730 * state changed to PRLI_ISSUE. When the PRLI completion occurs, the state is
1731 * changed to UNMAPPED_NODE. If the completion indicates a mapped
1732 * node, the node is taken off the unmapped list. The binding list is checked
1733 * for a valid binding, or a binding is automatically assigned. If binding
1734 * assignment is unsuccessful, the node is left on the unmapped list. If
1735 * binding assignment is successful, the associated binding list entry (if
1736 * any) is removed, and the node is placed on the mapped list.
1739 * For a Link Down, all nodes on the ADISC, PLOGI, unmapped or mapped
1740 * lists will receive a DEVICE_RECOVERY event. If the linkdown or nodev timers
1741 * expire, all effected nodes will receive a DEVICE_RM event.
1744 * For a Link Up or RSCN, all nodes will move from the mapped / unmapped lists
1745 * to either the ADISC or PLOGI list. After a Nameserver query or ALPA loopmap
1746 * check, additional nodes may be added or removed (via DEVICE_RM) to / from
1747 * the PLOGI or ADISC lists. Once the PLOGI and ADISC lists are populated,
1748 * we will first process the ADISC list. 32 entries are processed initially and
1749 * ADISC is initited for each one. Completions / Events for each node are
1750 * funnelled thru the state machine. As each node finishes ADISC processing, it
1751 * starts ADISC for any nodes waiting for ADISC processing. If no nodes are
1752 * waiting, and the ADISC list count is identically 0, then we are done. For
1753 * Link Up discovery, since all nodes on the PLOGI list are UNREG_LOGIN'ed, we
1754 * can issue a CLEAR_LA and reenable Link Events. Next we will process the PLOGI
1755 * list. 32 entries are processed initially and PLOGI is initited for each one.
1756 * Completions / Events for each node are funnelled thru the state machine. As
1757 * each node finishes PLOGI processing, it starts PLOGI for any nodes waiting
1758 * for PLOGI processing. If no nodes are waiting, and the PLOGI list count is
1759 * indentically 0, then we are done. We have now completed discovery / RSCN
1760 * handling. Upon completion, ALL nodes should be on either the mapped or
1764 static uint32_t (*lpfc_disc_action[NLP_STE_MAX_STATE * NLP_EVT_MAX_EVENT])
1765 (struct lpfc_hba *, struct lpfc_nodelist *, void *, uint32_t) = {
1766 /* Action routine Event Current State */
1767 lpfc_rcv_plogi_unused_node, /* RCV_PLOGI UNUSED_NODE */
1768 lpfc_rcv_els_unused_node, /* RCV_PRLI */
1769 lpfc_rcv_logo_unused_node, /* RCV_LOGO */
1770 lpfc_rcv_els_unused_node, /* RCV_ADISC */
1771 lpfc_rcv_els_unused_node, /* RCV_PDISC */
1772 lpfc_rcv_els_unused_node, /* RCV_PRLO */
1773 lpfc_disc_illegal, /* CMPL_PLOGI */
1774 lpfc_disc_illegal, /* CMPL_PRLI */
1775 lpfc_cmpl_logo_unused_node, /* CMPL_LOGO */
1776 lpfc_disc_illegal, /* CMPL_ADISC */
1777 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
1778 lpfc_device_rm_unused_node, /* DEVICE_RM */
1779 lpfc_disc_illegal, /* DEVICE_RECOVERY */
1781 lpfc_rcv_plogi_plogi_issue, /* RCV_PLOGI PLOGI_ISSUE */
1782 lpfc_rcv_els_plogi_issue, /* RCV_PRLI */
1783 lpfc_rcv_logo_plogi_issue, /* RCV_LOGO */
1784 lpfc_rcv_els_plogi_issue, /* RCV_ADISC */
1785 lpfc_rcv_els_plogi_issue, /* RCV_PDISC */
1786 lpfc_rcv_els_plogi_issue, /* RCV_PRLO */
1787 lpfc_cmpl_plogi_plogi_issue, /* CMPL_PLOGI */
1788 lpfc_disc_illegal, /* CMPL_PRLI */
1789 lpfc_disc_illegal, /* CMPL_LOGO */
1790 lpfc_disc_illegal, /* CMPL_ADISC */
1791 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
1792 lpfc_device_rm_plogi_issue, /* DEVICE_RM */
1793 lpfc_device_recov_plogi_issue, /* DEVICE_RECOVERY */
1795 lpfc_rcv_plogi_adisc_issue, /* RCV_PLOGI ADISC_ISSUE */
1796 lpfc_rcv_prli_adisc_issue, /* RCV_PRLI */
1797 lpfc_rcv_logo_adisc_issue, /* RCV_LOGO */
1798 lpfc_rcv_padisc_adisc_issue, /* RCV_ADISC */
1799 lpfc_rcv_padisc_adisc_issue, /* RCV_PDISC */
1800 lpfc_rcv_prlo_adisc_issue, /* RCV_PRLO */
1801 lpfc_disc_illegal, /* CMPL_PLOGI */
1802 lpfc_disc_illegal, /* CMPL_PRLI */
1803 lpfc_disc_illegal, /* CMPL_LOGO */
1804 lpfc_cmpl_adisc_adisc_issue, /* CMPL_ADISC */
1805 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
1806 lpfc_device_rm_adisc_issue, /* DEVICE_RM */
1807 lpfc_device_recov_adisc_issue, /* DEVICE_RECOVERY */
1809 lpfc_rcv_plogi_reglogin_issue, /* RCV_PLOGI REG_LOGIN_ISSUE */
1810 lpfc_rcv_prli_reglogin_issue, /* RCV_PLOGI */
1811 lpfc_rcv_logo_reglogin_issue, /* RCV_LOGO */
1812 lpfc_rcv_padisc_reglogin_issue, /* RCV_ADISC */
1813 lpfc_rcv_padisc_reglogin_issue, /* RCV_PDISC */
1814 lpfc_rcv_prlo_reglogin_issue, /* RCV_PRLO */
1815 lpfc_disc_illegal, /* CMPL_PLOGI */
1816 lpfc_disc_illegal, /* CMPL_PRLI */
1817 lpfc_disc_illegal, /* CMPL_LOGO */
1818 lpfc_disc_illegal, /* CMPL_ADISC */
1819 lpfc_cmpl_reglogin_reglogin_issue,/* CMPL_REG_LOGIN */
1820 lpfc_device_rm_reglogin_issue, /* DEVICE_RM */
1821 lpfc_device_recov_reglogin_issue,/* DEVICE_RECOVERY */
1823 lpfc_rcv_plogi_prli_issue, /* RCV_PLOGI PRLI_ISSUE */
1824 lpfc_rcv_prli_prli_issue, /* RCV_PRLI */
1825 lpfc_rcv_logo_prli_issue, /* RCV_LOGO */
1826 lpfc_rcv_padisc_prli_issue, /* RCV_ADISC */
1827 lpfc_rcv_padisc_prli_issue, /* RCV_PDISC */
1828 lpfc_rcv_prlo_prli_issue, /* RCV_PRLO */
1829 lpfc_disc_illegal, /* CMPL_PLOGI */
1830 lpfc_cmpl_prli_prli_issue, /* CMPL_PRLI */
1831 lpfc_disc_illegal, /* CMPL_LOGO */
1832 lpfc_disc_illegal, /* CMPL_ADISC */
1833 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
1834 lpfc_device_rm_prli_issue, /* DEVICE_RM */
1835 lpfc_device_recov_prli_issue, /* DEVICE_RECOVERY */
1837 lpfc_rcv_plogi_unmap_node, /* RCV_PLOGI UNMAPPED_NODE */
1838 lpfc_rcv_prli_unmap_node, /* RCV_PRLI */
1839 lpfc_rcv_logo_unmap_node, /* RCV_LOGO */
1840 lpfc_rcv_padisc_unmap_node, /* RCV_ADISC */
1841 lpfc_rcv_padisc_unmap_node, /* RCV_PDISC */
1842 lpfc_rcv_prlo_unmap_node, /* RCV_PRLO */
1843 lpfc_disc_illegal, /* 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_disc_illegal, /* DEVICE_RM */
1849 lpfc_device_recov_unmap_node, /* DEVICE_RECOVERY */
1851 lpfc_rcv_plogi_mapped_node, /* RCV_PLOGI MAPPED_NODE */
1852 lpfc_rcv_prli_mapped_node, /* RCV_PRLI */
1853 lpfc_rcv_logo_mapped_node, /* RCV_LOGO */
1854 lpfc_rcv_padisc_mapped_node, /* RCV_ADISC */
1855 lpfc_rcv_padisc_mapped_node, /* RCV_PDISC */
1856 lpfc_rcv_prlo_mapped_node, /* RCV_PRLO */
1857 lpfc_disc_illegal, /* CMPL_PLOGI */
1858 lpfc_disc_illegal, /* CMPL_PRLI */
1859 lpfc_disc_illegal, /* CMPL_LOGO */
1860 lpfc_disc_illegal, /* CMPL_ADISC */
1861 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
1862 lpfc_disc_illegal, /* DEVICE_RM */
1863 lpfc_device_recov_mapped_node, /* DEVICE_RECOVERY */
1865 lpfc_rcv_plogi_npr_node, /* RCV_PLOGI NPR_NODE */
1866 lpfc_rcv_prli_npr_node, /* RCV_PRLI */
1867 lpfc_rcv_logo_npr_node, /* RCV_LOGO */
1868 lpfc_rcv_padisc_npr_node, /* RCV_ADISC */
1869 lpfc_rcv_padisc_npr_node, /* RCV_PDISC */
1870 lpfc_rcv_prlo_npr_node, /* RCV_PRLO */
1871 lpfc_cmpl_plogi_npr_node, /* CMPL_PLOGI */
1872 lpfc_cmpl_prli_npr_node, /* CMPL_PRLI */
1873 lpfc_cmpl_logo_npr_node, /* CMPL_LOGO */
1874 lpfc_cmpl_adisc_npr_node, /* CMPL_ADISC */
1875 lpfc_cmpl_reglogin_npr_node, /* CMPL_REG_LOGIN */
1876 lpfc_device_rm_npr_node, /* DEVICE_RM */
1877 lpfc_device_recov_npr_node, /* DEVICE_RECOVERY */
1881 lpfc_disc_state_machine(struct lpfc_hba * phba,
1882 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1884 uint32_t cur_state, rc;
1885 uint32_t(*func) (struct lpfc_hba *, struct lpfc_nodelist *, void *,
1888 ndlp->nlp_disc_refcnt++;
1889 cur_state = ndlp->nlp_state;
1891 /* DSM in event <evt> on NPort <nlp_DID> in state <cur_state> */
1892 lpfc_printf_log(phba,
1895 "%d:0211 DSM in event x%x on NPort x%x in state %d "
1898 evt, ndlp->nlp_DID, cur_state, ndlp->nlp_flag);
1900 func = lpfc_disc_action[(cur_state * NLP_EVT_MAX_EVENT) + evt];
1901 rc = (func) (phba, ndlp, arg, evt);
1903 /* DSM out state <rc> on NPort <nlp_DID> */
1904 lpfc_printf_log(phba,
1907 "%d:0212 DSM out state %d on NPort x%x Data: x%x\n",
1909 rc, ndlp->nlp_DID, ndlp->nlp_flag);
1911 ndlp->nlp_disc_refcnt--;
1913 /* Check to see if ndlp removal is deferred */
1914 if ((ndlp->nlp_disc_refcnt == 0)
1915 && (ndlp->nlp_flag & NLP_DELAY_REMOVE)) {
1916 spin_lock_irq(phba->host->host_lock);
1917 ndlp->nlp_flag &= ~NLP_DELAY_REMOVE;
1918 spin_unlock_irq(phba->host->host_lock);
1919 lpfc_nlp_remove(phba, ndlp);
1920 return NLP_STE_FREED_NODE;
1922 if (rc == NLP_STE_FREED_NODE)
1923 return NLP_STE_FREED_NODE;