1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Enterprise Fibre Channel Host Bus Adapters. *
4 * Refer to the README file included with this package for *
5 * driver version and adapter support. *
6 * Copyright (C) 2004 Emulex Corporation. *
9 * This program is free software; you can redistribute it and/or *
10 * modify it under the terms of the GNU General Public License *
11 * as published by the Free Software Foundation; either version 2 *
12 * of the License, or (at your option) any later version. *
14 * This program is distributed in the hope that it will be useful, *
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
17 * GNU General Public License for more details, a copy of which *
18 * can be found in the file COPYING included with this package. *
19 *******************************************************************/
21 #include <linux/blkdev.h>
22 #include <linux/pci.h>
23 #include <linux/interrupt.h>
25 #include <scsi/scsi_device.h>
26 #include <scsi/scsi_host.h>
27 #include <scsi/scsi_transport_fc.h>
31 #include "lpfc_disc.h"
32 #include "lpfc_scsi.h"
34 #include "lpfc_logmsg.h"
35 #include "lpfc_crtn.h"
38 /* Called to verify a rcv'ed ADISC was intended for us. */
40 lpfc_check_adisc(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp,
41 struct lpfc_name * nn, struct lpfc_name * pn)
43 /* Compare the ADISC rsp WWNN / WWPN matches our internal node
44 * table entry for that node.
46 if (memcmp(nn, &ndlp->nlp_nodename, sizeof (struct lpfc_name)) != 0)
49 if (memcmp(pn, &ndlp->nlp_portname, sizeof (struct lpfc_name)) != 0)
52 /* we match, return success */
58 lpfc_check_sparm(struct lpfc_hba * phba,
59 struct lpfc_nodelist * ndlp, struct serv_parm * sp,
62 volatile struct serv_parm *hsp = &phba->fc_sparam;
63 /* First check for supported version */
65 /* Next check for class validity */
66 if (sp->cls1.classValid) {
68 if (sp->cls1.rcvDataSizeMsb > hsp->cls1.rcvDataSizeMsb)
69 sp->cls1.rcvDataSizeMsb = hsp->cls1.rcvDataSizeMsb;
70 if (sp->cls1.rcvDataSizeLsb > hsp->cls1.rcvDataSizeLsb)
71 sp->cls1.rcvDataSizeLsb = hsp->cls1.rcvDataSizeLsb;
72 } else if (class == CLASS1) {
76 if (sp->cls2.classValid) {
78 if (sp->cls2.rcvDataSizeMsb > hsp->cls2.rcvDataSizeMsb)
79 sp->cls2.rcvDataSizeMsb = hsp->cls2.rcvDataSizeMsb;
80 if (sp->cls2.rcvDataSizeLsb > hsp->cls2.rcvDataSizeLsb)
81 sp->cls2.rcvDataSizeLsb = hsp->cls2.rcvDataSizeLsb;
82 } else if (class == CLASS2) {
86 if (sp->cls3.classValid) {
88 if (sp->cls3.rcvDataSizeMsb > hsp->cls3.rcvDataSizeMsb)
89 sp->cls3.rcvDataSizeMsb = hsp->cls3.rcvDataSizeMsb;
90 if (sp->cls3.rcvDataSizeLsb > hsp->cls3.rcvDataSizeLsb)
91 sp->cls3.rcvDataSizeLsb = hsp->cls3.rcvDataSizeLsb;
92 } else if (class == CLASS3) {
96 if (sp->cmn.bbRcvSizeMsb > hsp->cmn.bbRcvSizeMsb)
97 sp->cmn.bbRcvSizeMsb = hsp->cmn.bbRcvSizeMsb;
98 if (sp->cmn.bbRcvSizeLsb > hsp->cmn.bbRcvSizeLsb)
99 sp->cmn.bbRcvSizeLsb = hsp->cmn.bbRcvSizeLsb;
101 /* If check is good, copy wwpn wwnn into ndlp */
102 memcpy(&ndlp->nlp_nodename, &sp->nodeName, sizeof (struct lpfc_name));
103 memcpy(&ndlp->nlp_portname, &sp->portName, sizeof (struct lpfc_name));
108 lpfc_check_elscmpl_iocb(struct lpfc_hba * phba,
109 struct lpfc_iocbq *cmdiocb,
110 struct lpfc_iocbq *rspiocb)
112 struct lpfc_dmabuf *pcmd, *prsp;
117 irsp = &rspiocb->iocb;
118 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
120 /* For lpfc_els_abort, context2 could be zero'ed to delay
121 * freeing associated memory till after ABTS completes.
124 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf,
127 lp = (uint32_t *) prsp->virt;
128 ptr = (void *)((uint8_t *)lp + sizeof(uint32_t));
132 /* Force ulpStatus error since we are returning NULL ptr */
133 if (!(irsp->ulpStatus)) {
134 irsp->ulpStatus = IOSTAT_LOCAL_REJECT;
135 irsp->un.ulpWord[4] = IOERR_SLI_ABORTED;
144 * Free resources / clean up outstanding I/Os
145 * associated with a LPFC_NODELIST entry. This
146 * routine effectively results in a "software abort".
149 lpfc_els_abort(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp,
152 struct lpfc_sli *psli;
153 struct lpfc_sli_ring *pring;
154 struct lpfc_iocbq *iocb, *next_iocb;
158 /* Abort outstanding I/O on NPort <nlp_DID> */
159 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
160 "%d:0201 Abort outstanding I/O on NPort x%x "
161 "Data: x%x x%x x%x\n",
162 phba->brd_no, ndlp->nlp_DID, ndlp->nlp_flag,
163 ndlp->nlp_state, ndlp->nlp_rpi);
166 pring = &psli->ring[LPFC_ELS_RING];
168 /* First check the txq */
171 spin_lock_irq(phba->host->host_lock);
172 list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
173 /* Check to see if iocb matches the nport we are looking
175 if ((lpfc_check_sli_ndlp(phba, pring, iocb, ndlp))) {
177 /* It matches, so deque and call compl with an
179 list_del(&iocb->list);
181 if (iocb->iocb_cmpl) {
183 icmd->ulpStatus = IOSTAT_LOCAL_REJECT;
184 icmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
185 spin_unlock_irq(phba->host->host_lock);
186 (iocb->iocb_cmpl) (phba, iocb, iocb);
187 spin_lock_irq(phba->host->host_lock);
189 list_add_tail(&iocb->list,
190 &phba->lpfc_iocb_list);
195 spin_unlock_irq(phba->host->host_lock);
198 /* Everything on txcmplq will be returned by firmware
199 * with a no rpi / linkdown / abort error. For ring 0,
200 * ELS discovery, we want to get rid of it right here.
202 /* Next check the txcmplq */
205 spin_lock_irq(phba->host->host_lock);
206 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq,
208 /* Check to see if iocb matches the nport we are looking
210 if ((lpfc_check_sli_ndlp (phba, pring, iocb, ndlp))) {
212 /* It matches, so deque and call compl with an
214 list_del(&iocb->list);
215 pring->txcmplq_cnt--;
218 /* If the driver is completing an ELS
219 * command early, flush it out of the firmware.
222 (icmd->ulpCommand == CMD_ELS_REQUEST64_CR) &&
223 (icmd->un.elsreq64.bdl.ulpIoTag32)) {
224 lpfc_sli_issue_abort_iotag32(phba,
227 if (iocb->iocb_cmpl) {
228 icmd->ulpStatus = IOSTAT_LOCAL_REJECT;
229 icmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
230 spin_unlock_irq(phba->host->host_lock);
231 (iocb->iocb_cmpl) (phba, iocb, iocb);
232 spin_lock_irq(phba->host->host_lock);
234 list_add_tail(&iocb->list,
235 &phba->lpfc_iocb_list);
240 spin_unlock_irq(phba->host->host_lock);
243 /* If we are delaying issuing an ELS command, cancel it */
244 if (ndlp->nlp_flag & NLP_DELAY_TMO) {
245 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
246 del_timer_sync(&ndlp->nlp_delayfunc);
247 if (!list_empty(&ndlp->els_retry_evt.evt_listp))
248 list_del_init(&ndlp->els_retry_evt.evt_listp);
254 lpfc_rcv_plogi(struct lpfc_hba * phba,
255 struct lpfc_nodelist * ndlp,
256 struct lpfc_iocbq *cmdiocb)
258 struct lpfc_dmabuf *pcmd;
261 struct serv_parm *sp;
266 memset(&stat, 0, sizeof (struct ls_rjt));
267 if (phba->hba_state <= LPFC_FLOGI) {
268 /* Before responding to PLOGI, check for pt2pt mode.
269 * If we are pt2pt, with an outstanding FLOGI, abort
270 * the FLOGI and resend it first.
272 if (phba->fc_flag & FC_PT2PT) {
273 lpfc_els_abort_flogi(phba);
274 if (!(phba->fc_flag & FC_PT2PT_PLOGI)) {
275 /* If the other side is supposed to initiate
276 * the PLOGI anyway, just ACC it now and
277 * move on with discovery.
279 phba->fc_edtov = FF_DEF_EDTOV;
280 phba->fc_ratov = FF_DEF_RATOV;
281 /* Start discovery - this should just do
283 lpfc_disc_start(phba);
286 lpfc_initial_flogi(phba);
290 stat.un.b.lsRjtRsnCode = LSRJT_LOGICAL_BSY;
291 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
292 lpfc_els_rsp_reject(phba, stat.un.lsRjtError, cmdiocb,
297 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
298 lp = (uint32_t *) pcmd->virt;
299 sp = (struct serv_parm *) ((uint8_t *) lp + sizeof (uint32_t));
300 if ((lpfc_check_sparm(phba, ndlp, sp, CLASS3) == 0)) {
301 /* Reject this request because invalid parameters */
302 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
303 stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
304 lpfc_els_rsp_reject(phba, stat.un.lsRjtError, cmdiocb, ndlp);
307 icmd = &cmdiocb->iocb;
309 /* PLOGI chkparm OK */
310 lpfc_printf_log(phba,
313 "%d:0114 PLOGI chkparm OK Data: x%x x%x x%x x%x\n",
315 ndlp->nlp_DID, ndlp->nlp_state, ndlp->nlp_flag,
318 if ((phba->cfg_fcp_class == 2) &&
319 (sp->cls2.classValid)) {
320 ndlp->nlp_fcp_info |= CLASS2;
322 ndlp->nlp_fcp_info |= CLASS3;
324 ndlp->nlp_class_sup = 0;
325 if (sp->cls1.classValid)
326 ndlp->nlp_class_sup |= FC_COS_CLASS1;
327 if (sp->cls2.classValid)
328 ndlp->nlp_class_sup |= FC_COS_CLASS2;
329 if (sp->cls3.classValid)
330 ndlp->nlp_class_sup |= FC_COS_CLASS3;
331 if (sp->cls4.classValid)
332 ndlp->nlp_class_sup |= FC_COS_CLASS4;
334 ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) | sp->cmn.bbRcvSizeLsb;
336 /* no need to reg_login if we are already in one of these states */
337 switch(ndlp->nlp_state) {
338 case NLP_STE_NPR_NODE:
339 if (!(ndlp->nlp_flag & NLP_NPR_ADISC))
341 case NLP_STE_REG_LOGIN_ISSUE:
342 case NLP_STE_PRLI_ISSUE:
343 case NLP_STE_UNMAPPED_NODE:
344 case NLP_STE_MAPPED_NODE:
345 lpfc_els_rsp_acc(phba, ELS_CMD_PLOGI, cmdiocb, ndlp, NULL, 0);
349 if ((phba->fc_flag & FC_PT2PT)
350 && !(phba->fc_flag & FC_PT2PT_PLOGI)) {
351 /* rcv'ed PLOGI decides what our NPortId will be */
352 phba->fc_myDID = icmd->un.rcvels.parmRo;
353 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
356 lpfc_config_link(phba, mbox);
357 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
358 rc = lpfc_sli_issue_mbox
359 (phba, mbox, (MBX_NOWAIT | MBX_STOP_IOCB));
360 if (rc == MBX_NOT_FINISHED) {
361 mempool_free( mbox, phba->mbox_mem_pool);
365 lpfc_can_disctmo(phba);
367 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
371 if (lpfc_reg_login(phba, icmd->un.rcvels.remoteID,
372 (uint8_t *) sp, mbox, 0)) {
373 mempool_free( mbox, phba->mbox_mem_pool);
377 /* ACC PLOGI rsp command needs to execute first,
378 * queue this mbox command to be processed later.
380 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
381 mbox->context2 = ndlp;
382 ndlp->nlp_flag |= NLP_ACC_REGLOGIN;
384 /* If there is an outstanding PLOGI issued, abort it before
385 * sending ACC rsp to PLOGI recieved.
387 if (ndlp->nlp_state == NLP_STE_PLOGI_ISSUE) {
388 /* software abort outstanding PLOGI */
389 lpfc_els_abort(phba, ndlp, 1);
391 ndlp->nlp_flag |= NLP_RCV_PLOGI;
392 lpfc_els_rsp_acc(phba, ELS_CMD_PLOGI, cmdiocb, ndlp, mbox, 0);
396 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
397 stat.un.b.lsRjtRsnCodeExp = LSEXP_OUT_OF_RESOURCE;
398 lpfc_els_rsp_reject(phba, stat.un.lsRjtError, cmdiocb, ndlp);
403 lpfc_rcv_padisc(struct lpfc_hba * phba,
404 struct lpfc_nodelist * ndlp,
405 struct lpfc_iocbq *cmdiocb)
407 struct lpfc_dmabuf *pcmd;
408 struct serv_parm *sp;
409 struct lpfc_name *pnn, *ppn;
416 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
417 lp = (uint32_t *) pcmd->virt;
420 if (cmd == ELS_CMD_ADISC) {
422 pnn = (struct lpfc_name *) & ap->nodeName;
423 ppn = (struct lpfc_name *) & ap->portName;
425 sp = (struct serv_parm *) lp;
426 pnn = (struct lpfc_name *) & sp->nodeName;
427 ppn = (struct lpfc_name *) & sp->portName;
430 icmd = &cmdiocb->iocb;
431 if ((icmd->ulpStatus == 0) &&
432 (lpfc_check_adisc(phba, ndlp, pnn, ppn))) {
433 if (cmd == ELS_CMD_ADISC) {
434 lpfc_els_rsp_adisc_acc(phba, cmdiocb, ndlp);
437 lpfc_els_rsp_acc(phba, ELS_CMD_PLOGI, cmdiocb, ndlp,
442 /* Reject this request because invalid parameters */
443 stat.un.b.lsRjtRsvd0 = 0;
444 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
445 stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
446 stat.un.b.vendorUnique = 0;
447 lpfc_els_rsp_reject(phba, stat.un.lsRjtError, cmdiocb, ndlp);
449 ndlp->nlp_last_elscmd = (unsigned long)ELS_CMD_PLOGI;
451 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ);
453 spin_lock_irq(phba->host->host_lock);
454 ndlp->nlp_flag |= NLP_DELAY_TMO;
455 spin_unlock_irq(phba->host->host_lock);
456 ndlp->nlp_state = NLP_STE_NPR_NODE;
457 lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
462 lpfc_rcv_logo(struct lpfc_hba * phba,
463 struct lpfc_nodelist * ndlp,
464 struct lpfc_iocbq *cmdiocb)
466 /* Put ndlp on NPR list with 1 sec timeout for plogi, ACC logo */
467 /* Only call LOGO ACC for first LOGO, this avoids sending unnecessary
468 * PLOGIs during LOGO storms from a device.
470 ndlp->nlp_flag |= NLP_LOGO_ACC;
471 lpfc_els_rsp_acc(phba, ELS_CMD_ACC, cmdiocb, ndlp, NULL, 0);
473 if (!(ndlp->nlp_type & NLP_FABRIC)) {
474 /* Only try to re-login if this is NOT a Fabric Node */
475 ndlp->nlp_last_elscmd = (unsigned long)ELS_CMD_PLOGI;
476 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ * 1);
477 spin_lock_irq(phba->host->host_lock);
478 ndlp->nlp_flag |= NLP_DELAY_TMO;
479 spin_unlock_irq(phba->host->host_lock);
482 ndlp->nlp_state = NLP_STE_NPR_NODE;
483 lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
485 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
486 /* The driver has to wait until the ACC completes before it continues
487 * processing the LOGO. The action will resume in
488 * lpfc_cmpl_els_logo_acc routine. Since part of processing includes an
489 * unreg_login, the driver waits so the ACC does not get aborted.
495 lpfc_rcv_prli(struct lpfc_hba * phba,
496 struct lpfc_nodelist * ndlp,
497 struct lpfc_iocbq *cmdiocb)
499 struct lpfc_dmabuf *pcmd;
502 struct fc_rport *rport = ndlp->rport;
505 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
506 lp = (uint32_t *) pcmd->virt;
507 npr = (PRLI *) ((uint8_t *) lp + sizeof (uint32_t));
509 ndlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR);
510 ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
511 if ((npr->acceptRspCode == PRLI_REQ_EXECUTED) &&
512 (npr->prliType == PRLI_FCP_TYPE)) {
513 if (npr->initiatorFunc)
514 ndlp->nlp_type |= NLP_FCP_INITIATOR;
516 ndlp->nlp_type |= NLP_FCP_TARGET;
518 ndlp->nlp_fcp_info |= NLP_FCP_2_DEVICE;
521 /* We need to update the rport role values */
522 roles = FC_RPORT_ROLE_UNKNOWN;
523 if (ndlp->nlp_type & NLP_FCP_INITIATOR)
524 roles |= FC_RPORT_ROLE_FCP_INITIATOR;
525 if (ndlp->nlp_type & NLP_FCP_TARGET)
526 roles |= FC_RPORT_ROLE_FCP_TARGET;
527 fc_remote_port_rolechg(rport, roles);
532 lpfc_disc_set_adisc(struct lpfc_hba * phba,
533 struct lpfc_nodelist * ndlp)
535 /* Check config parameter use-adisc or FCP-2 */
536 if ((phba->cfg_use_adisc == 0) &&
537 !(phba->fc_flag & FC_RSCN_MODE)) {
538 if (!(ndlp->nlp_fcp_info & NLP_FCP_2_DEVICE))
541 spin_lock_irq(phba->host->host_lock);
542 ndlp->nlp_flag |= NLP_NPR_ADISC;
543 spin_unlock_irq(phba->host->host_lock);
548 lpfc_disc_noop(struct lpfc_hba * phba,
549 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
551 /* This routine does nothing, just return the current state */
552 return (ndlp->nlp_state);
556 lpfc_disc_illegal(struct lpfc_hba * phba,
557 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
559 lpfc_printf_log(phba,
562 "%d:0253 Illegal State Transition: node x%x event x%x, "
563 "state x%x Data: x%x x%x\n",
565 ndlp->nlp_DID, evt, ndlp->nlp_state, ndlp->nlp_rpi,
567 return (ndlp->nlp_state);
570 /* Start of Discovery State Machine routines */
573 lpfc_rcv_plogi_unused_node(struct lpfc_hba * phba,
574 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
576 struct lpfc_iocbq *cmdiocb;
578 cmdiocb = (struct lpfc_iocbq *) arg;
580 if (lpfc_rcv_plogi(phba, ndlp, cmdiocb)) {
581 ndlp->nlp_state = NLP_STE_UNUSED_NODE;
582 lpfc_nlp_list(phba, ndlp, NLP_UNUSED_LIST);
583 return (ndlp->nlp_state);
585 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
586 return (NLP_STE_FREED_NODE);
590 lpfc_rcv_els_unused_node(struct lpfc_hba * phba,
591 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
593 lpfc_issue_els_logo(phba, ndlp, 0);
594 lpfc_nlp_list(phba, ndlp, NLP_UNUSED_LIST);
595 return (ndlp->nlp_state);
599 lpfc_rcv_logo_unused_node(struct lpfc_hba * phba,
600 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
602 struct lpfc_iocbq *cmdiocb;
604 cmdiocb = (struct lpfc_iocbq *) arg;
606 spin_lock_irq(phba->host->host_lock);
607 ndlp->nlp_flag |= NLP_LOGO_ACC;
608 spin_unlock_irq(phba->host->host_lock);
609 lpfc_els_rsp_acc(phba, ELS_CMD_ACC, cmdiocb, ndlp, NULL, 0);
610 lpfc_nlp_list(phba, ndlp, NLP_UNUSED_LIST);
612 return (ndlp->nlp_state);
616 lpfc_cmpl_logo_unused_node(struct lpfc_hba * phba,
617 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
619 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
620 return (NLP_STE_FREED_NODE);
624 lpfc_device_rm_unused_node(struct lpfc_hba * phba,
625 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
627 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
628 return (NLP_STE_FREED_NODE);
632 lpfc_rcv_plogi_plogi_issue(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp,
633 void *arg, uint32_t evt)
635 struct lpfc_iocbq *cmdiocb = arg;
636 struct lpfc_dmabuf *pcmd;
637 struct serv_parm *sp;
642 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
643 lp = (uint32_t *) pcmd->virt;
644 sp = (struct serv_parm *) ((uint8_t *) lp + sizeof (uint32_t));
646 memset(&stat, 0, sizeof (struct ls_rjt));
648 /* For a PLOGI, we only accept if our portname is less
649 * than the remote portname.
651 phba->fc_stat.elsLogiCol++;
652 port_cmp = memcmp(&phba->fc_portname, &sp->portName,
653 sizeof (struct lpfc_name));
656 /* Reject this request because the remote node will accept
658 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
659 stat.un.b.lsRjtRsnCodeExp = LSEXP_CMD_IN_PROGRESS;
660 lpfc_els_rsp_reject(phba, stat.un.lsRjtError, cmdiocb, ndlp);
663 lpfc_rcv_plogi(phba, ndlp, cmdiocb);
664 } /* if our portname was less */
666 return (ndlp->nlp_state);
670 lpfc_rcv_els_plogi_issue(struct lpfc_hba * phba,
671 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
673 struct lpfc_iocbq *cmdiocb;
675 cmdiocb = (struct lpfc_iocbq *) arg;
677 /* software abort outstanding PLOGI */
678 lpfc_els_abort(phba, ndlp, 1);
679 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ * 1);
680 spin_lock_irq(phba->host->host_lock);
681 ndlp->nlp_flag |= NLP_DELAY_TMO;
682 spin_unlock_irq(phba->host->host_lock);
684 if (evt == NLP_EVT_RCV_LOGO) {
685 lpfc_els_rsp_acc(phba, ELS_CMD_ACC, cmdiocb, ndlp, NULL, 0);
688 lpfc_issue_els_logo(phba, ndlp, 0);
691 /* Put ndlp in npr list set plogi timer for 1 sec */
692 ndlp->nlp_last_elscmd = (unsigned long)ELS_CMD_PLOGI;
693 ndlp->nlp_state = NLP_STE_NPR_NODE;
694 lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
696 return (ndlp->nlp_state);
700 lpfc_cmpl_plogi_plogi_issue(struct lpfc_hba * phba,
701 struct lpfc_nodelist * ndlp, void *arg,
704 struct lpfc_iocbq *cmdiocb, *rspiocb;
705 struct lpfc_dmabuf *pcmd, *prsp;
708 struct serv_parm *sp;
711 cmdiocb = (struct lpfc_iocbq *) arg;
712 rspiocb = cmdiocb->context_un.rsp_iocb;
714 if (ndlp->nlp_flag & NLP_ACC_REGLOGIN) {
715 return (ndlp->nlp_state);
718 irsp = &rspiocb->iocb;
723 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
725 prsp = list_get_first(&pcmd->list,
728 lp = (uint32_t *) prsp->virt;
730 sp = (struct serv_parm *) ((uint8_t *) lp + sizeof (uint32_t));
731 if (!lpfc_check_sparm(phba, ndlp, sp, CLASS3))
734 /* PLOGI chkparm OK */
735 lpfc_printf_log(phba,
738 "%d:0121 PLOGI chkparm OK "
739 "Data: x%x x%x x%x x%x\n",
741 ndlp->nlp_DID, ndlp->nlp_state,
742 ndlp->nlp_flag, ndlp->nlp_rpi);
744 if ((phba->cfg_fcp_class == 2) &&
745 (sp->cls2.classValid)) {
746 ndlp->nlp_fcp_info |= CLASS2;
748 ndlp->nlp_fcp_info |= CLASS3;
750 ndlp->nlp_class_sup = 0;
751 if (sp->cls1.classValid)
752 ndlp->nlp_class_sup |= FC_COS_CLASS1;
753 if (sp->cls2.classValid)
754 ndlp->nlp_class_sup |= FC_COS_CLASS2;
755 if (sp->cls3.classValid)
756 ndlp->nlp_class_sup |= FC_COS_CLASS3;
757 if (sp->cls4.classValid)
758 ndlp->nlp_class_sup |= FC_COS_CLASS4;
760 ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) |
761 sp->cmn.bbRcvSizeLsb;
763 if (!(mbox = mempool_alloc(phba->mbox_mem_pool,
767 lpfc_unreg_rpi(phba, ndlp);
769 (phba, irsp->un.elsreq64.remoteID,
770 (uint8_t *) sp, mbox, 0) == 0) {
771 /* set_slim mailbox command needs to
772 * execute first, queue this command to
773 * be processed later.
775 switch(ndlp->nlp_DID) {
778 lpfc_mbx_cmpl_ns_reg_login;
782 lpfc_mbx_cmpl_fdmi_reg_login;
786 lpfc_mbx_cmpl_reg_login;
788 mbox->context2 = ndlp;
789 if (lpfc_sli_issue_mbox(phba, mbox,
790 (MBX_NOWAIT | MBX_STOP_IOCB))
791 != MBX_NOT_FINISHED) {
793 NLP_STE_REG_LOGIN_ISSUE;
794 lpfc_nlp_list(phba, ndlp,
796 return (ndlp->nlp_state);
798 mempool_free(mbox, phba->mbox_mem_pool);
800 mempool_free(mbox, phba->mbox_mem_pool);
805 /* Free this node since the driver cannot login or has the wrong
807 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
808 return (NLP_STE_FREED_NODE);
812 lpfc_device_rm_plogi_issue(struct lpfc_hba * phba,
813 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
815 /* software abort outstanding PLOGI */
816 lpfc_els_abort(phba, ndlp, 1);
818 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
819 return (NLP_STE_FREED_NODE);
823 lpfc_device_recov_plogi_issue(struct lpfc_hba * phba,
824 struct lpfc_nodelist * ndlp, void *arg,
827 /* software abort outstanding PLOGI */
828 lpfc_els_abort(phba, ndlp, 1);
830 ndlp->nlp_state = NLP_STE_NPR_NODE;
831 lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
832 spin_lock_irq(phba->host->host_lock);
833 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
834 spin_unlock_irq(phba->host->host_lock);
836 return (ndlp->nlp_state);
840 lpfc_rcv_plogi_adisc_issue(struct lpfc_hba * phba,
841 struct lpfc_nodelist * ndlp, void *arg,
844 struct lpfc_iocbq *cmdiocb;
846 /* software abort outstanding ADISC */
847 lpfc_els_abort(phba, ndlp, 1);
849 cmdiocb = (struct lpfc_iocbq *) arg;
851 if (lpfc_rcv_plogi(phba, ndlp, cmdiocb)) {
852 return (ndlp->nlp_state);
854 ndlp->nlp_state = NLP_STE_PLOGI_ISSUE;
855 lpfc_nlp_list(phba, ndlp, NLP_PLOGI_LIST);
856 lpfc_issue_els_plogi(phba, ndlp, 0);
858 return (ndlp->nlp_state);
862 lpfc_rcv_prli_adisc_issue(struct lpfc_hba * phba,
863 struct lpfc_nodelist * ndlp, void *arg,
866 struct lpfc_iocbq *cmdiocb;
868 cmdiocb = (struct lpfc_iocbq *) arg;
870 lpfc_els_rsp_prli_acc(phba, cmdiocb, ndlp);
871 return (ndlp->nlp_state);
875 lpfc_rcv_logo_adisc_issue(struct lpfc_hba * phba,
876 struct lpfc_nodelist * ndlp, void *arg,
879 struct lpfc_iocbq *cmdiocb;
881 cmdiocb = (struct lpfc_iocbq *) arg;
883 /* software abort outstanding ADISC */
884 lpfc_els_abort(phba, ndlp, 0);
886 lpfc_rcv_logo(phba, ndlp, cmdiocb);
887 return (ndlp->nlp_state);
891 lpfc_rcv_padisc_adisc_issue(struct lpfc_hba * phba,
892 struct lpfc_nodelist * ndlp, void *arg,
895 struct lpfc_iocbq *cmdiocb;
897 cmdiocb = (struct lpfc_iocbq *) arg;
899 lpfc_rcv_padisc(phba, ndlp, cmdiocb);
900 return (ndlp->nlp_state);
904 lpfc_rcv_prlo_adisc_issue(struct lpfc_hba * phba,
905 struct lpfc_nodelist * ndlp, void *arg,
908 struct lpfc_iocbq *cmdiocb;
910 cmdiocb = (struct lpfc_iocbq *) arg;
912 /* Treat like rcv logo */
913 lpfc_rcv_logo(phba, ndlp, cmdiocb);
914 return (ndlp->nlp_state);
918 lpfc_cmpl_adisc_adisc_issue(struct lpfc_hba * phba,
919 struct lpfc_nodelist * ndlp, void *arg,
922 struct lpfc_iocbq *cmdiocb, *rspiocb;
926 cmdiocb = (struct lpfc_iocbq *) arg;
927 rspiocb = cmdiocb->context_un.rsp_iocb;
929 ap = (ADISC *)lpfc_check_elscmpl_iocb(phba, cmdiocb, rspiocb);
930 irsp = &rspiocb->iocb;
932 if ((irsp->ulpStatus) ||
933 (!lpfc_check_adisc(phba, ndlp, &ap->nodeName, &ap->portName))) {
934 ndlp->nlp_last_elscmd = (unsigned long)ELS_CMD_PLOGI;
936 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ);
937 spin_lock_irq(phba->host->host_lock);
938 ndlp->nlp_flag |= NLP_DELAY_TMO;
939 spin_unlock_irq(phba->host->host_lock);
941 memset(&ndlp->nlp_nodename, 0, sizeof (struct lpfc_name));
942 memset(&ndlp->nlp_portname, 0, sizeof (struct lpfc_name));
944 ndlp->nlp_state = NLP_STE_NPR_NODE;
945 lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
946 lpfc_unreg_rpi(phba, ndlp);
947 return (ndlp->nlp_state);
949 if (ndlp->nlp_type & NLP_FCP_TARGET) {
950 ndlp->nlp_state = NLP_STE_MAPPED_NODE;
951 lpfc_nlp_list(phba, ndlp, NLP_MAPPED_LIST);
953 ndlp->nlp_state = NLP_STE_UNMAPPED_NODE;
954 lpfc_nlp_list(phba, ndlp, NLP_UNMAPPED_LIST);
956 return (ndlp->nlp_state);
960 lpfc_device_rm_adisc_issue(struct lpfc_hba * phba,
961 struct lpfc_nodelist * ndlp, void *arg,
964 /* software abort outstanding ADISC */
965 lpfc_els_abort(phba, ndlp, 1);
967 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
968 return (NLP_STE_FREED_NODE);
972 lpfc_device_recov_adisc_issue(struct lpfc_hba * phba,
973 struct lpfc_nodelist * ndlp, void *arg,
976 /* software abort outstanding ADISC */
977 lpfc_els_abort(phba, ndlp, 1);
979 ndlp->nlp_state = NLP_STE_NPR_NODE;
980 lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
981 spin_lock_irq(phba->host->host_lock);
982 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
983 spin_unlock_irq(phba->host->host_lock);
985 lpfc_disc_set_adisc(phba, ndlp);
986 return (ndlp->nlp_state);
990 lpfc_rcv_plogi_reglogin_issue(struct lpfc_hba * phba,
991 struct lpfc_nodelist * ndlp, void *arg,
994 struct lpfc_iocbq *cmdiocb;
996 cmdiocb = (struct lpfc_iocbq *) arg;
998 lpfc_rcv_plogi(phba, ndlp, cmdiocb);
999 return (ndlp->nlp_state);
1003 lpfc_rcv_prli_reglogin_issue(struct lpfc_hba * phba,
1004 struct lpfc_nodelist * ndlp, void *arg,
1007 struct lpfc_iocbq *cmdiocb;
1009 cmdiocb = (struct lpfc_iocbq *) arg;
1011 lpfc_els_rsp_prli_acc(phba, cmdiocb, ndlp);
1012 return (ndlp->nlp_state);
1016 lpfc_rcv_logo_reglogin_issue(struct lpfc_hba * phba,
1017 struct lpfc_nodelist * ndlp, void *arg,
1020 struct lpfc_iocbq *cmdiocb;
1022 cmdiocb = (struct lpfc_iocbq *) arg;
1024 lpfc_rcv_logo(phba, ndlp, cmdiocb);
1025 return (ndlp->nlp_state);
1029 lpfc_rcv_padisc_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_padisc(phba, ndlp, cmdiocb);
1038 return (ndlp->nlp_state);
1042 lpfc_rcv_prlo_reglogin_issue(struct lpfc_hba * phba,
1043 struct lpfc_nodelist * ndlp, void *arg,
1046 struct lpfc_iocbq *cmdiocb;
1048 cmdiocb = (struct lpfc_iocbq *) arg;
1049 lpfc_els_rsp_acc(phba, ELS_CMD_ACC, cmdiocb, ndlp, NULL, 0);
1050 return (ndlp->nlp_state);
1054 lpfc_cmpl_reglogin_reglogin_issue(struct lpfc_hba * phba,
1055 struct lpfc_nodelist * ndlp,
1056 void *arg, uint32_t evt)
1062 pmb = (LPFC_MBOXQ_t *) arg;
1064 did = mb->un.varWords[1];
1065 if (mb->mbxStatus) {
1066 /* RegLogin failed */
1067 lpfc_printf_log(phba,
1070 "%d:0246 RegLogin failed Data: x%x x%x x%x\n",
1072 did, mb->mbxStatus, phba->hba_state);
1074 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ * 1);
1075 spin_lock_irq(phba->host->host_lock);
1076 ndlp->nlp_flag |= NLP_DELAY_TMO;
1077 spin_unlock_irq(phba->host->host_lock);
1079 lpfc_issue_els_logo(phba, ndlp, 0);
1080 /* Put ndlp in npr list set plogi timer for 1 sec */
1081 ndlp->nlp_last_elscmd = (unsigned long)ELS_CMD_PLOGI;
1082 ndlp->nlp_state = NLP_STE_NPR_NODE;
1083 lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
1084 return (ndlp->nlp_state);
1087 if (ndlp->nlp_rpi != 0)
1088 lpfc_findnode_remove_rpi(phba, ndlp->nlp_rpi);
1090 ndlp->nlp_rpi = mb->un.varWords[0];
1091 lpfc_addnode_rpi(phba, ndlp, ndlp->nlp_rpi);
1093 /* Only if we are not a fabric nport do we issue PRLI */
1094 if (!(ndlp->nlp_type & NLP_FABRIC)) {
1095 ndlp->nlp_state = NLP_STE_PRLI_ISSUE;
1096 lpfc_nlp_list(phba, ndlp, NLP_PRLI_LIST);
1097 lpfc_issue_els_prli(phba, ndlp, 0);
1099 ndlp->nlp_state = NLP_STE_UNMAPPED_NODE;
1100 lpfc_nlp_list(phba, ndlp, NLP_UNMAPPED_LIST);
1102 return (ndlp->nlp_state);
1106 lpfc_device_rm_reglogin_issue(struct lpfc_hba * phba,
1107 struct lpfc_nodelist * ndlp, void *arg,
1110 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
1111 return (NLP_STE_FREED_NODE);
1115 lpfc_device_recov_reglogin_issue(struct lpfc_hba * phba,
1116 struct lpfc_nodelist * ndlp, void *arg,
1119 ndlp->nlp_state = NLP_STE_NPR_NODE;
1120 lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
1121 spin_lock_irq(phba->host->host_lock);
1122 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
1123 spin_unlock_irq(phba->host->host_lock);
1124 return (ndlp->nlp_state);
1128 lpfc_rcv_plogi_prli_issue(struct lpfc_hba * phba,
1129 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1131 struct lpfc_iocbq *cmdiocb;
1133 cmdiocb = (struct lpfc_iocbq *) arg;
1135 lpfc_rcv_plogi(phba, ndlp, cmdiocb);
1136 return (ndlp->nlp_state);
1140 lpfc_rcv_prli_prli_issue(struct lpfc_hba * phba,
1141 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1143 struct lpfc_iocbq *cmdiocb;
1145 cmdiocb = (struct lpfc_iocbq *) arg;
1147 lpfc_els_rsp_prli_acc(phba, cmdiocb, ndlp);
1148 return (ndlp->nlp_state);
1152 lpfc_rcv_logo_prli_issue(struct lpfc_hba * phba,
1153 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1155 struct lpfc_iocbq *cmdiocb;
1157 cmdiocb = (struct lpfc_iocbq *) arg;
1159 /* Software abort outstanding PRLI before sending acc */
1160 lpfc_els_abort(phba, ndlp, 1);
1162 lpfc_rcv_logo(phba, ndlp, cmdiocb);
1163 return (ndlp->nlp_state);
1167 lpfc_rcv_padisc_prli_issue(struct lpfc_hba * phba,
1168 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1170 struct lpfc_iocbq *cmdiocb;
1172 cmdiocb = (struct lpfc_iocbq *) arg;
1174 lpfc_rcv_padisc(phba, ndlp, cmdiocb);
1175 return (ndlp->nlp_state);
1178 /* This routine is envoked when we rcv a PRLO request from a nport
1179 * we are logged into. We should send back a PRLO rsp setting the
1181 * NEXT STATE = PRLI_ISSUE
1184 lpfc_rcv_prlo_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;
1190 lpfc_els_rsp_acc(phba, ELS_CMD_ACC, cmdiocb, ndlp, NULL, 0);
1191 return (ndlp->nlp_state);
1195 lpfc_cmpl_prli_prli_issue(struct lpfc_hba * phba,
1196 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1198 struct lpfc_iocbq *cmdiocb, *rspiocb;
1202 cmdiocb = (struct lpfc_iocbq *) arg;
1203 rspiocb = cmdiocb->context_un.rsp_iocb;
1204 npr = (PRLI *)lpfc_check_elscmpl_iocb(phba, cmdiocb, rspiocb);
1206 irsp = &rspiocb->iocb;
1207 if (irsp->ulpStatus) {
1208 ndlp->nlp_state = NLP_STE_UNMAPPED_NODE;
1209 lpfc_nlp_list(phba, ndlp, NLP_UNMAPPED_LIST);
1210 return (ndlp->nlp_state);
1213 /* Check out PRLI rsp */
1214 ndlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR);
1215 ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
1216 if ((npr->acceptRspCode == PRLI_REQ_EXECUTED) &&
1217 (npr->prliType == PRLI_FCP_TYPE)) {
1218 if (npr->initiatorFunc)
1219 ndlp->nlp_type |= NLP_FCP_INITIATOR;
1220 if (npr->targetFunc)
1221 ndlp->nlp_type |= NLP_FCP_TARGET;
1223 ndlp->nlp_fcp_info |= NLP_FCP_2_DEVICE;
1226 ndlp->nlp_state = NLP_STE_MAPPED_NODE;
1227 lpfc_nlp_list(phba, ndlp, NLP_MAPPED_LIST);
1228 return (ndlp->nlp_state);
1231 /*! lpfc_device_rm_prli_issue
1242 * This routine is envoked when we a request to remove a nport we are in the
1243 * process of PRLIing. We should software abort outstanding prli, unreg
1244 * login, send a logout. We will change node state to UNUSED_NODE, put it
1245 * on plogi list so it can be freed when LOGO completes.
1249 lpfc_device_rm_prli_issue(struct lpfc_hba * phba,
1250 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1252 /* software abort outstanding PRLI */
1253 lpfc_els_abort(phba, ndlp, 1);
1255 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
1256 return (NLP_STE_FREED_NODE);
1260 /*! lpfc_device_recov_prli_issue
1271 * The routine is envoked when the state of a device is unknown, like
1272 * during a link down. We should remove the nodelist entry from the
1273 * unmapped list, issue a UNREG_LOGIN, do a software abort of the
1274 * outstanding PRLI command, then free the node entry.
1277 lpfc_device_recov_prli_issue(struct lpfc_hba * phba,
1278 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1280 /* software abort outstanding PRLI */
1281 lpfc_els_abort(phba, ndlp, 1);
1283 ndlp->nlp_state = NLP_STE_NPR_NODE;
1284 lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
1285 spin_lock_irq(phba->host->host_lock);
1286 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
1287 spin_unlock_irq(phba->host->host_lock);
1288 return (ndlp->nlp_state);
1292 lpfc_rcv_plogi_unmap_node(struct lpfc_hba * phba,
1293 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1295 struct lpfc_iocbq *cmdiocb;
1297 cmdiocb = (struct lpfc_iocbq *) arg;
1299 lpfc_rcv_plogi(phba, ndlp, cmdiocb);
1300 return (ndlp->nlp_state);
1304 lpfc_rcv_prli_unmap_node(struct lpfc_hba * phba,
1305 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1307 struct lpfc_iocbq *cmdiocb;
1309 cmdiocb = (struct lpfc_iocbq *) arg;
1311 lpfc_rcv_prli(phba, ndlp, cmdiocb);
1312 lpfc_els_rsp_prli_acc(phba, cmdiocb, ndlp);
1313 return (ndlp->nlp_state);
1317 lpfc_rcv_logo_unmap_node(struct lpfc_hba * phba,
1318 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1320 struct lpfc_iocbq *cmdiocb;
1322 cmdiocb = (struct lpfc_iocbq *) arg;
1324 lpfc_rcv_logo(phba, ndlp, cmdiocb);
1325 return (ndlp->nlp_state);
1329 lpfc_rcv_padisc_unmap_node(struct lpfc_hba * phba,
1330 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1332 struct lpfc_iocbq *cmdiocb;
1334 cmdiocb = (struct lpfc_iocbq *) arg;
1336 lpfc_rcv_padisc(phba, ndlp, cmdiocb);
1337 return (ndlp->nlp_state);
1341 lpfc_rcv_prlo_unmap_node(struct lpfc_hba * phba,
1342 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1344 struct lpfc_iocbq *cmdiocb;
1346 cmdiocb = (struct lpfc_iocbq *) arg;
1348 /* Treat like rcv logo */
1349 lpfc_rcv_logo(phba, ndlp, cmdiocb);
1350 return (ndlp->nlp_state);
1354 lpfc_device_recov_unmap_node(struct lpfc_hba * phba,
1355 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1357 ndlp->nlp_state = NLP_STE_NPR_NODE;
1358 lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
1359 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
1360 lpfc_disc_set_adisc(phba, ndlp);
1362 return (ndlp->nlp_state);
1366 lpfc_rcv_plogi_mapped_node(struct lpfc_hba * phba,
1367 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1369 struct lpfc_iocbq *cmdiocb;
1371 cmdiocb = (struct lpfc_iocbq *) arg;
1373 lpfc_rcv_plogi(phba, ndlp, cmdiocb);
1374 return (ndlp->nlp_state);
1378 lpfc_rcv_prli_mapped_node(struct lpfc_hba * phba,
1379 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1381 struct lpfc_iocbq *cmdiocb;
1383 cmdiocb = (struct lpfc_iocbq *) arg;
1385 lpfc_els_rsp_prli_acc(phba, cmdiocb, ndlp);
1386 return (ndlp->nlp_state);
1390 lpfc_rcv_logo_mapped_node(struct lpfc_hba * phba,
1391 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1393 struct lpfc_iocbq *cmdiocb;
1395 cmdiocb = (struct lpfc_iocbq *) arg;
1397 lpfc_rcv_logo(phba, ndlp, cmdiocb);
1398 return (ndlp->nlp_state);
1402 lpfc_rcv_padisc_mapped_node(struct lpfc_hba * phba,
1403 struct lpfc_nodelist * ndlp, void *arg,
1406 struct lpfc_iocbq *cmdiocb;
1408 cmdiocb = (struct lpfc_iocbq *) arg;
1410 lpfc_rcv_padisc(phba, ndlp, cmdiocb);
1411 return (ndlp->nlp_state);
1415 lpfc_rcv_prlo_mapped_node(struct lpfc_hba * phba,
1416 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1418 struct lpfc_iocbq *cmdiocb;
1420 cmdiocb = (struct lpfc_iocbq *) arg;
1422 /* flush the target */
1423 spin_lock_irq(phba->host->host_lock);
1424 lpfc_sli_abort_iocb(phba, &phba->sli.ring[phba->sli.fcp_ring],
1425 ndlp->nlp_sid, 0, 0, LPFC_CTX_TGT);
1426 spin_unlock_irq(phba->host->host_lock);
1428 /* Treat like rcv logo */
1429 lpfc_rcv_logo(phba, ndlp, cmdiocb);
1430 return (ndlp->nlp_state);
1434 lpfc_device_recov_mapped_node(struct lpfc_hba * phba,
1435 struct lpfc_nodelist * ndlp, void *arg,
1438 ndlp->nlp_state = NLP_STE_NPR_NODE;
1439 lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
1440 spin_lock_irq(phba->host->host_lock);
1441 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
1442 spin_unlock_irq(phba->host->host_lock);
1443 lpfc_disc_set_adisc(phba, ndlp);
1444 return (ndlp->nlp_state);
1448 lpfc_rcv_plogi_npr_node(struct lpfc_hba * phba,
1449 struct lpfc_nodelist * ndlp, void *arg,
1452 struct lpfc_iocbq *cmdiocb;
1454 cmdiocb = (struct lpfc_iocbq *) arg;
1456 /* Ignore PLOGI if we have an outstanding LOGO */
1457 if (ndlp->nlp_flag & NLP_LOGO_SND) {
1458 return (ndlp->nlp_state);
1461 if (lpfc_rcv_plogi(phba, ndlp, cmdiocb)) {
1462 spin_lock_irq(phba->host->host_lock);
1463 ndlp->nlp_flag &= ~(NLP_NPR_ADISC | NLP_NPR_2B_DISC);
1464 spin_unlock_irq(phba->host->host_lock);
1465 return (ndlp->nlp_state);
1468 /* send PLOGI immediately, move to PLOGI issue state */
1469 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
1470 ndlp->nlp_state = NLP_STE_PLOGI_ISSUE;
1471 lpfc_nlp_list(phba, ndlp, NLP_PLOGI_LIST);
1472 lpfc_issue_els_plogi(phba, ndlp, 0);
1474 return (ndlp->nlp_state);
1478 lpfc_rcv_prli_npr_node(struct lpfc_hba * phba,
1479 struct lpfc_nodelist * ndlp, void *arg,
1482 struct lpfc_iocbq *cmdiocb;
1485 cmdiocb = (struct lpfc_iocbq *) arg;
1487 memset(&stat, 0, sizeof (struct ls_rjt));
1488 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
1489 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
1490 lpfc_els_rsp_reject(phba, stat.un.lsRjtError, cmdiocb, ndlp);
1492 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
1493 if (ndlp->nlp_flag & NLP_NPR_ADISC) {
1494 ndlp->nlp_state = NLP_STE_ADISC_ISSUE;
1495 lpfc_nlp_list(phba, ndlp, NLP_ADISC_LIST);
1496 lpfc_issue_els_adisc(phba, ndlp, 0);
1498 ndlp->nlp_state = NLP_STE_PLOGI_ISSUE;
1499 lpfc_nlp_list(phba, ndlp, NLP_PLOGI_LIST);
1500 lpfc_issue_els_plogi(phba, ndlp, 0);
1503 return (ndlp->nlp_state);
1507 lpfc_rcv_logo_npr_node(struct lpfc_hba * phba,
1508 struct lpfc_nodelist * ndlp, void *arg,
1511 struct lpfc_iocbq *cmdiocb;
1513 cmdiocb = (struct lpfc_iocbq *) arg;
1515 lpfc_rcv_logo(phba, ndlp, cmdiocb);
1516 return (ndlp->nlp_state);
1520 lpfc_rcv_padisc_npr_node(struct lpfc_hba * phba,
1521 struct lpfc_nodelist * ndlp, void *arg,
1524 struct lpfc_iocbq *cmdiocb;
1526 cmdiocb = (struct lpfc_iocbq *) arg;
1528 lpfc_rcv_padisc(phba, ndlp, cmdiocb);
1530 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
1531 if (ndlp->nlp_flag & NLP_NPR_ADISC) {
1532 ndlp->nlp_state = NLP_STE_ADISC_ISSUE;
1533 lpfc_nlp_list(phba, ndlp, NLP_ADISC_LIST);
1534 lpfc_issue_els_adisc(phba, ndlp, 0);
1536 ndlp->nlp_state = NLP_STE_PLOGI_ISSUE;
1537 lpfc_nlp_list(phba, ndlp, NLP_PLOGI_LIST);
1538 lpfc_issue_els_plogi(phba, ndlp, 0);
1541 return (ndlp->nlp_state);
1545 lpfc_rcv_prlo_npr_node(struct lpfc_hba * phba,
1546 struct lpfc_nodelist * ndlp, void *arg,
1549 struct lpfc_iocbq *cmdiocb;
1551 cmdiocb = (struct lpfc_iocbq *) arg;
1553 lpfc_els_rsp_acc(phba, ELS_CMD_ACC, cmdiocb, ndlp, NULL, 0);
1555 if (ndlp->nlp_flag & NLP_DELAY_TMO) {
1556 if (ndlp->nlp_last_elscmd == (unsigned long)ELS_CMD_PLOGI) {
1557 return (ndlp->nlp_state);
1559 spin_lock_irq(phba->host->host_lock);
1560 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
1561 spin_unlock_irq(phba->host->host_lock);
1562 del_timer_sync(&ndlp->nlp_delayfunc);
1563 if (!list_empty(&ndlp->els_retry_evt.evt_listp))
1564 list_del_init(&ndlp->els_retry_evt.evt_listp);
1568 ndlp->nlp_state = NLP_STE_PLOGI_ISSUE;
1569 lpfc_nlp_list(phba, ndlp, NLP_PLOGI_LIST);
1570 lpfc_issue_els_plogi(phba, ndlp, 0);
1571 return (ndlp->nlp_state);
1575 lpfc_cmpl_logo_npr_node(struct lpfc_hba * phba,
1576 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1578 lpfc_unreg_rpi(phba, ndlp);
1579 /* This routine does nothing, just return the current state */
1580 return (ndlp->nlp_state);
1584 lpfc_cmpl_reglogin_npr_node(struct lpfc_hba * phba,
1585 struct lpfc_nodelist * ndlp, void *arg,
1591 pmb = (LPFC_MBOXQ_t *) arg;
1595 if (ndlp->nlp_rpi != 0)
1596 lpfc_findnode_remove_rpi(phba, ndlp->nlp_rpi);
1598 ndlp->nlp_rpi = mb->un.varWords[0];
1599 lpfc_addnode_rpi(phba, ndlp, ndlp->nlp_rpi);
1601 return (ndlp->nlp_state);
1605 lpfc_device_rm_npr_node(struct lpfc_hba * phba,
1606 struct lpfc_nodelist * ndlp, void *arg,
1609 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
1610 return (NLP_STE_FREED_NODE);
1614 lpfc_device_recov_npr_node(struct lpfc_hba * phba,
1615 struct lpfc_nodelist * ndlp, void *arg,
1618 spin_lock_irq(phba->host->host_lock);
1619 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
1620 spin_unlock_irq(phba->host->host_lock);
1621 return (ndlp->nlp_state);
1625 /* This next section defines the NPort Discovery State Machine */
1627 /* There are 4 different double linked lists nodelist entries can reside on.
1628 * The plogi list and adisc list are used when Link Up discovery or RSCN
1629 * processing is needed. Each list holds the nodes that we will send PLOGI
1630 * or ADISC on. These lists will keep track of what nodes will be effected
1631 * by an RSCN, or a Link Up (Typically, all nodes are effected on Link Up).
1632 * The unmapped_list will contain all nodes that we have successfully logged
1633 * into at the Fibre Channel level. The mapped_list will contain all nodes
1634 * that are mapped FCP targets.
1637 * The bind list is a list of undiscovered (potentially non-existent) nodes
1638 * that we have saved binding information on. This information is used when
1639 * nodes transition from the unmapped to the mapped list.
1641 /* For UNUSED_NODE state, the node has just been allocated .
1642 * For PLOGI_ISSUE and REG_LOGIN_ISSUE, the node is on
1643 * the PLOGI list. For REG_LOGIN_COMPL, the node is taken off the PLOGI list
1644 * and put on the unmapped list. For ADISC processing, the node is taken off
1645 * the ADISC list and placed on either the mapped or unmapped list (depending
1646 * on its previous state). Once on the unmapped list, a PRLI is issued and the
1647 * state changed to PRLI_ISSUE. When the PRLI completion occurs, the state is
1648 * changed to UNMAPPED_NODE. If the completion indicates a mapped
1649 * node, the node is taken off the unmapped list. The binding list is checked
1650 * for a valid binding, or a binding is automatically assigned. If binding
1651 * assignment is unsuccessful, the node is left on the unmapped list. If
1652 * binding assignment is successful, the associated binding list entry (if
1653 * any) is removed, and the node is placed on the mapped list.
1656 * For a Link Down, all nodes on the ADISC, PLOGI, unmapped or mapped
1657 * lists will receive a DEVICE_RECOVERY event. If the linkdown or nodev timers
1658 * expire, all effected nodes will receive a DEVICE_RM event.
1661 * For a Link Up or RSCN, all nodes will move from the mapped / unmapped lists
1662 * to either the ADISC or PLOGI list. After a Nameserver query or ALPA loopmap
1663 * check, additional nodes may be added or removed (via DEVICE_RM) to / from
1664 * the PLOGI or ADISC lists. Once the PLOGI and ADISC lists are populated,
1665 * we will first process the ADISC list. 32 entries are processed initially and
1666 * ADISC is initited for each one. Completions / Events for each node are
1667 * funnelled thru the state machine. As each node finishes ADISC processing, it
1668 * starts ADISC for any nodes waiting for ADISC processing. If no nodes are
1669 * waiting, and the ADISC list count is identically 0, then we are done. For
1670 * Link Up discovery, since all nodes on the PLOGI list are UNREG_LOGIN'ed, we
1671 * can issue a CLEAR_LA and reenable Link Events. Next we will process the PLOGI
1672 * list. 32 entries are processed initially and PLOGI is initited for each one.
1673 * Completions / Events for each node are funnelled thru the state machine. As
1674 * each node finishes PLOGI processing, it starts PLOGI for any nodes waiting
1675 * for PLOGI processing. If no nodes are waiting, and the PLOGI list count is
1676 * indentically 0, then we are done. We have now completed discovery / RSCN
1677 * handling. Upon completion, ALL nodes should be on either the mapped or
1681 static uint32_t (*lpfc_disc_action[NLP_STE_MAX_STATE * NLP_EVT_MAX_EVENT])
1682 (struct lpfc_hba *, struct lpfc_nodelist *, void *, uint32_t) = {
1683 /* Action routine Event Current State */
1684 lpfc_rcv_plogi_unused_node, /* RCV_PLOGI UNUSED_NODE */
1685 lpfc_rcv_els_unused_node, /* RCV_PRLI */
1686 lpfc_rcv_logo_unused_node, /* RCV_LOGO */
1687 lpfc_rcv_els_unused_node, /* RCV_ADISC */
1688 lpfc_rcv_els_unused_node, /* RCV_PDISC */
1689 lpfc_rcv_els_unused_node, /* RCV_PRLO */
1690 lpfc_disc_illegal, /* CMPL_PLOGI */
1691 lpfc_disc_illegal, /* CMPL_PRLI */
1692 lpfc_cmpl_logo_unused_node, /* CMPL_LOGO */
1693 lpfc_disc_illegal, /* CMPL_ADISC */
1694 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
1695 lpfc_device_rm_unused_node, /* DEVICE_RM */
1696 lpfc_disc_illegal, /* DEVICE_RECOVERY */
1698 lpfc_rcv_plogi_plogi_issue, /* RCV_PLOGI PLOGI_ISSUE */
1699 lpfc_rcv_els_plogi_issue, /* RCV_PRLI */
1700 lpfc_rcv_els_plogi_issue, /* RCV_LOGO */
1701 lpfc_rcv_els_plogi_issue, /* RCV_ADISC */
1702 lpfc_rcv_els_plogi_issue, /* RCV_PDISC */
1703 lpfc_rcv_els_plogi_issue, /* RCV_PRLO */
1704 lpfc_cmpl_plogi_plogi_issue, /* CMPL_PLOGI */
1705 lpfc_disc_illegal, /* CMPL_PRLI */
1706 lpfc_disc_illegal, /* CMPL_LOGO */
1707 lpfc_disc_illegal, /* CMPL_ADISC */
1708 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
1709 lpfc_device_rm_plogi_issue, /* DEVICE_RM */
1710 lpfc_device_recov_plogi_issue, /* DEVICE_RECOVERY */
1712 lpfc_rcv_plogi_adisc_issue, /* RCV_PLOGI ADISC_ISSUE */
1713 lpfc_rcv_prli_adisc_issue, /* RCV_PRLI */
1714 lpfc_rcv_logo_adisc_issue, /* RCV_LOGO */
1715 lpfc_rcv_padisc_adisc_issue, /* RCV_ADISC */
1716 lpfc_rcv_padisc_adisc_issue, /* RCV_PDISC */
1717 lpfc_rcv_prlo_adisc_issue, /* RCV_PRLO */
1718 lpfc_disc_illegal, /* CMPL_PLOGI */
1719 lpfc_disc_illegal, /* CMPL_PRLI */
1720 lpfc_disc_illegal, /* CMPL_LOGO */
1721 lpfc_cmpl_adisc_adisc_issue, /* CMPL_ADISC */
1722 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
1723 lpfc_device_rm_adisc_issue, /* DEVICE_RM */
1724 lpfc_device_recov_adisc_issue, /* DEVICE_RECOVERY */
1726 lpfc_rcv_plogi_reglogin_issue, /* RCV_PLOGI REG_LOGIN_ISSUE */
1727 lpfc_rcv_prli_reglogin_issue, /* RCV_PLOGI */
1728 lpfc_rcv_logo_reglogin_issue, /* RCV_LOGO */
1729 lpfc_rcv_padisc_reglogin_issue, /* RCV_ADISC */
1730 lpfc_rcv_padisc_reglogin_issue, /* RCV_PDISC */
1731 lpfc_rcv_prlo_reglogin_issue, /* RCV_PRLO */
1732 lpfc_disc_illegal, /* CMPL_PLOGI */
1733 lpfc_disc_illegal, /* CMPL_PRLI */
1734 lpfc_disc_illegal, /* CMPL_LOGO */
1735 lpfc_disc_illegal, /* CMPL_ADISC */
1736 lpfc_cmpl_reglogin_reglogin_issue,/* CMPL_REG_LOGIN */
1737 lpfc_device_rm_reglogin_issue, /* DEVICE_RM */
1738 lpfc_device_recov_reglogin_issue,/* DEVICE_RECOVERY */
1740 lpfc_rcv_plogi_prli_issue, /* RCV_PLOGI PRLI_ISSUE */
1741 lpfc_rcv_prli_prli_issue, /* RCV_PRLI */
1742 lpfc_rcv_logo_prli_issue, /* RCV_LOGO */
1743 lpfc_rcv_padisc_prli_issue, /* RCV_ADISC */
1744 lpfc_rcv_padisc_prli_issue, /* RCV_PDISC */
1745 lpfc_rcv_prlo_prli_issue, /* RCV_PRLO */
1746 lpfc_disc_illegal, /* CMPL_PLOGI */
1747 lpfc_cmpl_prli_prli_issue, /* CMPL_PRLI */
1748 lpfc_disc_illegal, /* CMPL_LOGO */
1749 lpfc_disc_illegal, /* CMPL_ADISC */
1750 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
1751 lpfc_device_rm_prli_issue, /* DEVICE_RM */
1752 lpfc_device_recov_prli_issue, /* DEVICE_RECOVERY */
1754 lpfc_rcv_plogi_unmap_node, /* RCV_PLOGI UNMAPPED_NODE */
1755 lpfc_rcv_prli_unmap_node, /* RCV_PRLI */
1756 lpfc_rcv_logo_unmap_node, /* RCV_LOGO */
1757 lpfc_rcv_padisc_unmap_node, /* RCV_ADISC */
1758 lpfc_rcv_padisc_unmap_node, /* RCV_PDISC */
1759 lpfc_rcv_prlo_unmap_node, /* RCV_PRLO */
1760 lpfc_disc_illegal, /* CMPL_PLOGI */
1761 lpfc_disc_illegal, /* CMPL_PRLI */
1762 lpfc_disc_illegal, /* CMPL_LOGO */
1763 lpfc_disc_illegal, /* CMPL_ADISC */
1764 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
1765 lpfc_disc_illegal, /* DEVICE_RM */
1766 lpfc_device_recov_unmap_node, /* DEVICE_RECOVERY */
1768 lpfc_rcv_plogi_mapped_node, /* RCV_PLOGI MAPPED_NODE */
1769 lpfc_rcv_prli_mapped_node, /* RCV_PRLI */
1770 lpfc_rcv_logo_mapped_node, /* RCV_LOGO */
1771 lpfc_rcv_padisc_mapped_node, /* RCV_ADISC */
1772 lpfc_rcv_padisc_mapped_node, /* RCV_PDISC */
1773 lpfc_rcv_prlo_mapped_node, /* RCV_PRLO */
1774 lpfc_disc_illegal, /* CMPL_PLOGI */
1775 lpfc_disc_illegal, /* CMPL_PRLI */
1776 lpfc_disc_illegal, /* CMPL_LOGO */
1777 lpfc_disc_illegal, /* CMPL_ADISC */
1778 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
1779 lpfc_disc_illegal, /* DEVICE_RM */
1780 lpfc_device_recov_mapped_node, /* DEVICE_RECOVERY */
1782 lpfc_rcv_plogi_npr_node, /* RCV_PLOGI NPR_NODE */
1783 lpfc_rcv_prli_npr_node, /* RCV_PRLI */
1784 lpfc_rcv_logo_npr_node, /* RCV_LOGO */
1785 lpfc_rcv_padisc_npr_node, /* RCV_ADISC */
1786 lpfc_rcv_padisc_npr_node, /* RCV_PDISC */
1787 lpfc_rcv_prlo_npr_node, /* RCV_PRLO */
1788 lpfc_disc_noop, /* CMPL_PLOGI */
1789 lpfc_disc_noop, /* CMPL_PRLI */
1790 lpfc_cmpl_logo_npr_node, /* CMPL_LOGO */
1791 lpfc_disc_noop, /* CMPL_ADISC */
1792 lpfc_cmpl_reglogin_npr_node, /* CMPL_REG_LOGIN */
1793 lpfc_device_rm_npr_node, /* DEVICE_RM */
1794 lpfc_device_recov_npr_node, /* DEVICE_RECOVERY */
1798 lpfc_disc_state_machine(struct lpfc_hba * phba,
1799 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1801 uint32_t cur_state, rc;
1802 uint32_t(*func) (struct lpfc_hba *, struct lpfc_nodelist *, void *,
1805 ndlp->nlp_disc_refcnt++;
1806 cur_state = ndlp->nlp_state;
1808 /* DSM in event <evt> on NPort <nlp_DID> in state <cur_state> */
1809 lpfc_printf_log(phba,
1812 "%d:0211 DSM in event x%x on NPort x%x in state %d "
1815 evt, ndlp->nlp_DID, cur_state, ndlp->nlp_flag);
1817 func = lpfc_disc_action[(cur_state * NLP_EVT_MAX_EVENT) + evt];
1818 rc = (func) (phba, ndlp, arg, evt);
1820 /* DSM out state <rc> on NPort <nlp_DID> */
1821 lpfc_printf_log(phba,
1824 "%d:0212 DSM out state %d on NPort x%x Data: x%x\n",
1826 rc, ndlp->nlp_DID, ndlp->nlp_flag);
1828 ndlp->nlp_disc_refcnt--;
1830 /* Check to see if ndlp removal is deferred */
1831 if ((ndlp->nlp_disc_refcnt == 0)
1832 && (ndlp->nlp_flag & NLP_DELAY_REMOVE)) {
1833 spin_lock_irq(phba->host->host_lock);
1834 ndlp->nlp_flag &= ~NLP_DELAY_REMOVE;
1835 spin_unlock_irq(phba->host->host_lock);
1836 lpfc_nlp_remove(phba, ndlp);
1837 return (NLP_STE_FREED_NODE);
1839 if (rc == NLP_STE_FREED_NODE)
1840 return (NLP_STE_FREED_NODE);
1841 ndlp->nlp_state = rc;