1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2004-2005 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 */
60 lpfc_check_sparm(struct lpfc_hba * phba,
61 struct lpfc_nodelist * ndlp, struct serv_parm * sp,
64 volatile struct serv_parm *hsp = &phba->fc_sparam;
65 /* First check for supported version */
67 /* Next check for class validity */
68 if (sp->cls1.classValid) {
70 if (sp->cls1.rcvDataSizeMsb > hsp->cls1.rcvDataSizeMsb)
71 sp->cls1.rcvDataSizeMsb = hsp->cls1.rcvDataSizeMsb;
72 if (sp->cls1.rcvDataSizeLsb > hsp->cls1.rcvDataSizeLsb)
73 sp->cls1.rcvDataSizeLsb = hsp->cls1.rcvDataSizeLsb;
74 } else if (class == CLASS1) {
78 if (sp->cls2.classValid) {
80 if (sp->cls2.rcvDataSizeMsb > hsp->cls2.rcvDataSizeMsb)
81 sp->cls2.rcvDataSizeMsb = hsp->cls2.rcvDataSizeMsb;
82 if (sp->cls2.rcvDataSizeLsb > hsp->cls2.rcvDataSizeLsb)
83 sp->cls2.rcvDataSizeLsb = hsp->cls2.rcvDataSizeLsb;
84 } else if (class == CLASS2) {
88 if (sp->cls3.classValid) {
90 if (sp->cls3.rcvDataSizeMsb > hsp->cls3.rcvDataSizeMsb)
91 sp->cls3.rcvDataSizeMsb = hsp->cls3.rcvDataSizeMsb;
92 if (sp->cls3.rcvDataSizeLsb > hsp->cls3.rcvDataSizeLsb)
93 sp->cls3.rcvDataSizeLsb = hsp->cls3.rcvDataSizeLsb;
94 } else if (class == CLASS3) {
98 if (sp->cmn.bbRcvSizeMsb > hsp->cmn.bbRcvSizeMsb)
99 sp->cmn.bbRcvSizeMsb = hsp->cmn.bbRcvSizeMsb;
100 if (sp->cmn.bbRcvSizeLsb > hsp->cmn.bbRcvSizeLsb)
101 sp->cmn.bbRcvSizeLsb = hsp->cmn.bbRcvSizeLsb;
103 /* If check is good, copy wwpn wwnn into ndlp */
104 memcpy(&ndlp->nlp_nodename, &sp->nodeName, sizeof (struct lpfc_name));
105 memcpy(&ndlp->nlp_portname, &sp->portName, sizeof (struct lpfc_name));
110 lpfc_check_elscmpl_iocb(struct lpfc_hba * phba,
111 struct lpfc_iocbq *cmdiocb,
112 struct lpfc_iocbq *rspiocb)
114 struct lpfc_dmabuf *pcmd, *prsp;
119 irsp = &rspiocb->iocb;
120 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
122 /* For lpfc_els_abort, context2 could be zero'ed to delay
123 * freeing associated memory till after ABTS completes.
126 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf,
129 lp = (uint32_t *) prsp->virt;
130 ptr = (void *)((uint8_t *)lp + sizeof(uint32_t));
134 /* Force ulpStatus error since we are returning NULL ptr */
135 if (!(irsp->ulpStatus)) {
136 irsp->ulpStatus = IOSTAT_LOCAL_REJECT;
137 irsp->un.ulpWord[4] = IOERR_SLI_ABORTED;
146 * Free resources / clean up outstanding I/Os
147 * associated with a LPFC_NODELIST entry. This
148 * routine effectively results in a "software abort".
151 lpfc_els_abort(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp,
154 struct lpfc_sli *psli;
155 struct lpfc_sli_ring *pring;
156 struct lpfc_iocbq *iocb, *next_iocb;
160 /* Abort outstanding I/O on NPort <nlp_DID> */
161 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
162 "%d:0201 Abort outstanding I/O on NPort x%x "
163 "Data: x%x x%x x%x\n",
164 phba->brd_no, ndlp->nlp_DID, ndlp->nlp_flag,
165 ndlp->nlp_state, ndlp->nlp_rpi);
168 pring = &psli->ring[LPFC_ELS_RING];
170 /* First check the txq */
173 spin_lock_irq(phba->host->host_lock);
174 list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
175 /* Check to see if iocb matches the nport we are looking
177 if ((lpfc_check_sli_ndlp(phba, pring, iocb, ndlp))) {
179 /* It matches, so deque and call compl with an
181 list_del(&iocb->list);
183 if (iocb->iocb_cmpl) {
185 icmd->ulpStatus = IOSTAT_LOCAL_REJECT;
186 icmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
187 spin_unlock_irq(phba->host->host_lock);
188 (iocb->iocb_cmpl) (phba, iocb, iocb);
189 spin_lock_irq(phba->host->host_lock);
191 lpfc_sli_release_iocbq(phba, iocb);
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 lpfc_sli_release_iocbq(phba, iocb);
238 spin_unlock_irq(phba->host->host_lock);
241 /* If we are delaying issuing an ELS command, cancel it */
242 if (ndlp->nlp_flag & NLP_DELAY_TMO) {
243 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
244 del_timer_sync(&ndlp->nlp_delayfunc);
245 if (!list_empty(&ndlp->els_retry_evt.evt_listp))
246 list_del_init(&ndlp->els_retry_evt.evt_listp);
252 lpfc_rcv_plogi(struct lpfc_hba * phba,
253 struct lpfc_nodelist * ndlp,
254 struct lpfc_iocbq *cmdiocb)
256 struct lpfc_dmabuf *pcmd;
259 struct serv_parm *sp;
264 memset(&stat, 0, sizeof (struct ls_rjt));
265 if (phba->hba_state <= LPFC_FLOGI) {
266 /* Before responding to PLOGI, check for pt2pt mode.
267 * If we are pt2pt, with an outstanding FLOGI, abort
268 * the FLOGI and resend it first.
270 if (phba->fc_flag & FC_PT2PT) {
271 lpfc_els_abort_flogi(phba);
272 if (!(phba->fc_flag & FC_PT2PT_PLOGI)) {
273 /* If the other side is supposed to initiate
274 * the PLOGI anyway, just ACC it now and
275 * move on with discovery.
277 phba->fc_edtov = FF_DEF_EDTOV;
278 phba->fc_ratov = FF_DEF_RATOV;
279 /* Start discovery - this should just do
281 lpfc_disc_start(phba);
284 lpfc_initial_flogi(phba);
288 stat.un.b.lsRjtRsnCode = LSRJT_LOGICAL_BSY;
289 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
290 lpfc_els_rsp_reject(phba, stat.un.lsRjtError, cmdiocb,
295 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
296 lp = (uint32_t *) pcmd->virt;
297 sp = (struct serv_parm *) ((uint8_t *) lp + sizeof (uint32_t));
298 if ((lpfc_check_sparm(phba, ndlp, sp, CLASS3) == 0)) {
299 /* Reject this request because invalid parameters */
300 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
301 stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
302 lpfc_els_rsp_reject(phba, stat.un.lsRjtError, cmdiocb, ndlp);
305 icmd = &cmdiocb->iocb;
307 /* PLOGI chkparm OK */
308 lpfc_printf_log(phba,
311 "%d:0114 PLOGI chkparm OK Data: x%x x%x x%x x%x\n",
313 ndlp->nlp_DID, ndlp->nlp_state, ndlp->nlp_flag,
316 if ((phba->cfg_fcp_class == 2) &&
317 (sp->cls2.classValid)) {
318 ndlp->nlp_fcp_info |= CLASS2;
320 ndlp->nlp_fcp_info |= CLASS3;
322 ndlp->nlp_class_sup = 0;
323 if (sp->cls1.classValid)
324 ndlp->nlp_class_sup |= FC_COS_CLASS1;
325 if (sp->cls2.classValid)
326 ndlp->nlp_class_sup |= FC_COS_CLASS2;
327 if (sp->cls3.classValid)
328 ndlp->nlp_class_sup |= FC_COS_CLASS3;
329 if (sp->cls4.classValid)
330 ndlp->nlp_class_sup |= FC_COS_CLASS4;
332 ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) | sp->cmn.bbRcvSizeLsb;
334 /* no need to reg_login if we are already in one of these states */
335 switch(ndlp->nlp_state) {
336 case NLP_STE_NPR_NODE:
337 if (!(ndlp->nlp_flag & NLP_NPR_ADISC))
339 case NLP_STE_REG_LOGIN_ISSUE:
340 case NLP_STE_PRLI_ISSUE:
341 case NLP_STE_UNMAPPED_NODE:
342 case NLP_STE_MAPPED_NODE:
343 lpfc_els_rsp_acc(phba, ELS_CMD_PLOGI, cmdiocb, ndlp, NULL, 0);
347 if ((phba->fc_flag & FC_PT2PT)
348 && !(phba->fc_flag & FC_PT2PT_PLOGI)) {
349 /* rcv'ed PLOGI decides what our NPortId will be */
350 phba->fc_myDID = icmd->un.rcvels.parmRo;
351 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
354 lpfc_config_link(phba, mbox);
355 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
356 rc = lpfc_sli_issue_mbox
357 (phba, mbox, (MBX_NOWAIT | MBX_STOP_IOCB));
358 if (rc == MBX_NOT_FINISHED) {
359 mempool_free( mbox, phba->mbox_mem_pool);
363 lpfc_can_disctmo(phba);
365 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
369 if (lpfc_reg_login(phba, icmd->un.rcvels.remoteID,
370 (uint8_t *) sp, mbox, 0)) {
371 mempool_free( mbox, phba->mbox_mem_pool);
375 /* ACC PLOGI rsp command needs to execute first,
376 * queue this mbox command to be processed later.
378 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
379 mbox->context2 = ndlp;
380 ndlp->nlp_flag |= NLP_ACC_REGLOGIN;
382 /* If there is an outstanding PLOGI issued, abort it before
383 * sending ACC rsp to PLOGI recieved.
385 if (ndlp->nlp_state == NLP_STE_PLOGI_ISSUE) {
386 /* software abort outstanding PLOGI */
387 lpfc_els_abort(phba, ndlp, 1);
389 ndlp->nlp_flag |= NLP_RCV_PLOGI;
390 lpfc_els_rsp_acc(phba, ELS_CMD_PLOGI, cmdiocb, ndlp, mbox, 0);
394 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
395 stat.un.b.lsRjtRsnCodeExp = LSEXP_OUT_OF_RESOURCE;
396 lpfc_els_rsp_reject(phba, stat.un.lsRjtError, cmdiocb, ndlp);
401 lpfc_rcv_padisc(struct lpfc_hba * phba,
402 struct lpfc_nodelist * ndlp,
403 struct lpfc_iocbq *cmdiocb)
405 struct lpfc_dmabuf *pcmd;
406 struct serv_parm *sp;
407 struct lpfc_name *pnn, *ppn;
414 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
415 lp = (uint32_t *) pcmd->virt;
418 if (cmd == ELS_CMD_ADISC) {
420 pnn = (struct lpfc_name *) & ap->nodeName;
421 ppn = (struct lpfc_name *) & ap->portName;
423 sp = (struct serv_parm *) lp;
424 pnn = (struct lpfc_name *) & sp->nodeName;
425 ppn = (struct lpfc_name *) & sp->portName;
428 icmd = &cmdiocb->iocb;
429 if ((icmd->ulpStatus == 0) &&
430 (lpfc_check_adisc(phba, ndlp, pnn, ppn))) {
431 if (cmd == ELS_CMD_ADISC) {
432 lpfc_els_rsp_adisc_acc(phba, cmdiocb, ndlp);
435 lpfc_els_rsp_acc(phba, ELS_CMD_PLOGI, cmdiocb, ndlp,
440 /* Reject this request because invalid parameters */
441 stat.un.b.lsRjtRsvd0 = 0;
442 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
443 stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
444 stat.un.b.vendorUnique = 0;
445 lpfc_els_rsp_reject(phba, stat.un.lsRjtError, cmdiocb, ndlp);
447 ndlp->nlp_last_elscmd = (unsigned long)ELS_CMD_PLOGI;
449 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ);
451 spin_lock_irq(phba->host->host_lock);
452 ndlp->nlp_flag |= NLP_DELAY_TMO;
453 spin_unlock_irq(phba->host->host_lock);
454 ndlp->nlp_state = NLP_STE_NPR_NODE;
455 lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
460 lpfc_rcv_logo(struct lpfc_hba * phba,
461 struct lpfc_nodelist * ndlp,
462 struct lpfc_iocbq *cmdiocb)
464 /* Put ndlp on NPR list with 1 sec timeout for plogi, ACC logo */
465 /* Only call LOGO ACC for first LOGO, this avoids sending unnecessary
466 * PLOGIs during LOGO storms from a device.
468 ndlp->nlp_flag |= NLP_LOGO_ACC;
469 lpfc_els_rsp_acc(phba, ELS_CMD_ACC, cmdiocb, ndlp, NULL, 0);
471 if (!(ndlp->nlp_type & NLP_FABRIC)) {
472 /* Only try to re-login if this is NOT a Fabric Node */
473 ndlp->nlp_last_elscmd = (unsigned long)ELS_CMD_PLOGI;
474 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ * 1);
475 spin_lock_irq(phba->host->host_lock);
476 ndlp->nlp_flag |= NLP_DELAY_TMO;
477 spin_unlock_irq(phba->host->host_lock);
480 ndlp->nlp_state = NLP_STE_NPR_NODE;
481 lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
483 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
484 /* The driver has to wait until the ACC completes before it continues
485 * processing the LOGO. The action will resume in
486 * lpfc_cmpl_els_logo_acc routine. Since part of processing includes an
487 * unreg_login, the driver waits so the ACC does not get aborted.
493 lpfc_rcv_prli(struct lpfc_hba * phba,
494 struct lpfc_nodelist * ndlp,
495 struct lpfc_iocbq *cmdiocb)
497 struct lpfc_dmabuf *pcmd;
500 struct fc_rport *rport = ndlp->rport;
503 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
504 lp = (uint32_t *) pcmd->virt;
505 npr = (PRLI *) ((uint8_t *) lp + sizeof (uint32_t));
507 ndlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR);
508 ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
509 if ((npr->acceptRspCode == PRLI_REQ_EXECUTED) &&
510 (npr->prliType == PRLI_FCP_TYPE)) {
511 if (npr->initiatorFunc)
512 ndlp->nlp_type |= NLP_FCP_INITIATOR;
514 ndlp->nlp_type |= NLP_FCP_TARGET;
516 ndlp->nlp_fcp_info |= NLP_FCP_2_DEVICE;
519 /* We need to update the rport role values */
520 roles = FC_RPORT_ROLE_UNKNOWN;
521 if (ndlp->nlp_type & NLP_FCP_INITIATOR)
522 roles |= FC_RPORT_ROLE_FCP_INITIATOR;
523 if (ndlp->nlp_type & NLP_FCP_TARGET)
524 roles |= FC_RPORT_ROLE_FCP_TARGET;
525 fc_remote_port_rolechg(rport, roles);
530 lpfc_disc_set_adisc(struct lpfc_hba * phba,
531 struct lpfc_nodelist * ndlp)
533 /* Check config parameter use-adisc or FCP-2 */
534 if ((phba->cfg_use_adisc == 0) &&
535 !(phba->fc_flag & FC_RSCN_MODE)) {
536 if (!(ndlp->nlp_fcp_info & NLP_FCP_2_DEVICE))
539 spin_lock_irq(phba->host->host_lock);
540 ndlp->nlp_flag |= NLP_NPR_ADISC;
541 spin_unlock_irq(phba->host->host_lock);
546 lpfc_disc_noop(struct lpfc_hba * phba,
547 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
549 /* This routine does nothing, just return the current state */
550 return (ndlp->nlp_state);
554 lpfc_disc_illegal(struct lpfc_hba * phba,
555 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
557 lpfc_printf_log(phba,
560 "%d:0253 Illegal State Transition: node x%x event x%x, "
561 "state x%x Data: x%x x%x\n",
563 ndlp->nlp_DID, evt, ndlp->nlp_state, ndlp->nlp_rpi,
565 return (ndlp->nlp_state);
568 /* Start of Discovery State Machine routines */
571 lpfc_rcv_plogi_unused_node(struct lpfc_hba * phba,
572 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
574 struct lpfc_iocbq *cmdiocb;
576 cmdiocb = (struct lpfc_iocbq *) arg;
578 if (lpfc_rcv_plogi(phba, ndlp, cmdiocb)) {
579 ndlp->nlp_state = NLP_STE_UNUSED_NODE;
580 lpfc_nlp_list(phba, ndlp, NLP_UNUSED_LIST);
581 return (ndlp->nlp_state);
583 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
584 return (NLP_STE_FREED_NODE);
588 lpfc_rcv_els_unused_node(struct lpfc_hba * phba,
589 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
591 lpfc_issue_els_logo(phba, ndlp, 0);
592 lpfc_nlp_list(phba, ndlp, NLP_UNUSED_LIST);
593 return (ndlp->nlp_state);
597 lpfc_rcv_logo_unused_node(struct lpfc_hba * phba,
598 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
600 struct lpfc_iocbq *cmdiocb;
602 cmdiocb = (struct lpfc_iocbq *) arg;
604 spin_lock_irq(phba->host->host_lock);
605 ndlp->nlp_flag |= NLP_LOGO_ACC;
606 spin_unlock_irq(phba->host->host_lock);
607 lpfc_els_rsp_acc(phba, ELS_CMD_ACC, cmdiocb, ndlp, NULL, 0);
608 lpfc_nlp_list(phba, ndlp, NLP_UNUSED_LIST);
610 return (ndlp->nlp_state);
614 lpfc_cmpl_logo_unused_node(struct lpfc_hba * phba,
615 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
617 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
618 return (NLP_STE_FREED_NODE);
622 lpfc_device_rm_unused_node(struct lpfc_hba * phba,
623 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
625 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
626 return (NLP_STE_FREED_NODE);
630 lpfc_rcv_plogi_plogi_issue(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp,
631 void *arg, uint32_t evt)
633 struct lpfc_iocbq *cmdiocb = arg;
634 struct lpfc_dmabuf *pcmd;
635 struct serv_parm *sp;
640 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
641 lp = (uint32_t *) pcmd->virt;
642 sp = (struct serv_parm *) ((uint8_t *) lp + sizeof (uint32_t));
644 memset(&stat, 0, sizeof (struct ls_rjt));
646 /* For a PLOGI, we only accept if our portname is less
647 * than the remote portname.
649 phba->fc_stat.elsLogiCol++;
650 port_cmp = memcmp(&phba->fc_portname, &sp->portName,
651 sizeof (struct lpfc_name));
654 /* Reject this request because the remote node will accept
656 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
657 stat.un.b.lsRjtRsnCodeExp = LSEXP_CMD_IN_PROGRESS;
658 lpfc_els_rsp_reject(phba, stat.un.lsRjtError, cmdiocb, ndlp);
661 lpfc_rcv_plogi(phba, ndlp, cmdiocb);
662 } /* if our portname was less */
664 return (ndlp->nlp_state);
668 lpfc_rcv_els_plogi_issue(struct lpfc_hba * phba,
669 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
671 struct lpfc_iocbq *cmdiocb;
673 cmdiocb = (struct lpfc_iocbq *) arg;
675 /* software abort outstanding PLOGI */
676 lpfc_els_abort(phba, ndlp, 1);
677 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ * 1);
678 spin_lock_irq(phba->host->host_lock);
679 ndlp->nlp_flag |= NLP_DELAY_TMO;
680 spin_unlock_irq(phba->host->host_lock);
682 if (evt == NLP_EVT_RCV_LOGO) {
683 lpfc_els_rsp_acc(phba, ELS_CMD_ACC, cmdiocb, ndlp, NULL, 0);
686 lpfc_issue_els_logo(phba, ndlp, 0);
689 /* Put ndlp in npr list set plogi timer for 1 sec */
690 ndlp->nlp_last_elscmd = (unsigned long)ELS_CMD_PLOGI;
691 ndlp->nlp_state = NLP_STE_NPR_NODE;
692 lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
694 return (ndlp->nlp_state);
698 lpfc_cmpl_plogi_plogi_issue(struct lpfc_hba * phba,
699 struct lpfc_nodelist * ndlp, void *arg,
702 struct lpfc_iocbq *cmdiocb, *rspiocb;
703 struct lpfc_dmabuf *pcmd, *prsp;
706 struct serv_parm *sp;
709 cmdiocb = (struct lpfc_iocbq *) arg;
710 rspiocb = cmdiocb->context_un.rsp_iocb;
712 if (ndlp->nlp_flag & NLP_ACC_REGLOGIN) {
713 return (ndlp->nlp_state);
716 irsp = &rspiocb->iocb;
721 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
723 prsp = list_get_first(&pcmd->list,
726 lp = (uint32_t *) prsp->virt;
728 sp = (struct serv_parm *) ((uint8_t *) lp + sizeof (uint32_t));
729 if (!lpfc_check_sparm(phba, ndlp, sp, CLASS3))
732 /* PLOGI chkparm OK */
733 lpfc_printf_log(phba,
736 "%d:0121 PLOGI chkparm OK "
737 "Data: x%x x%x x%x x%x\n",
739 ndlp->nlp_DID, ndlp->nlp_state,
740 ndlp->nlp_flag, ndlp->nlp_rpi);
742 if ((phba->cfg_fcp_class == 2) &&
743 (sp->cls2.classValid)) {
744 ndlp->nlp_fcp_info |= CLASS2;
746 ndlp->nlp_fcp_info |= CLASS3;
748 ndlp->nlp_class_sup = 0;
749 if (sp->cls1.classValid)
750 ndlp->nlp_class_sup |= FC_COS_CLASS1;
751 if (sp->cls2.classValid)
752 ndlp->nlp_class_sup |= FC_COS_CLASS2;
753 if (sp->cls3.classValid)
754 ndlp->nlp_class_sup |= FC_COS_CLASS3;
755 if (sp->cls4.classValid)
756 ndlp->nlp_class_sup |= FC_COS_CLASS4;
758 ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) |
759 sp->cmn.bbRcvSizeLsb;
761 if (!(mbox = mempool_alloc(phba->mbox_mem_pool,
765 lpfc_unreg_rpi(phba, ndlp);
767 (phba, irsp->un.elsreq64.remoteID,
768 (uint8_t *) sp, mbox, 0) == 0) {
769 /* set_slim mailbox command needs to
770 * execute first, queue this command to
771 * be processed later.
773 switch(ndlp->nlp_DID) {
776 lpfc_mbx_cmpl_ns_reg_login;
780 lpfc_mbx_cmpl_fdmi_reg_login;
784 lpfc_mbx_cmpl_reg_login;
786 mbox->context2 = ndlp;
787 if (lpfc_sli_issue_mbox(phba, mbox,
788 (MBX_NOWAIT | MBX_STOP_IOCB))
789 != MBX_NOT_FINISHED) {
791 NLP_STE_REG_LOGIN_ISSUE;
792 lpfc_nlp_list(phba, ndlp,
794 return (ndlp->nlp_state);
796 mempool_free(mbox, phba->mbox_mem_pool);
798 mempool_free(mbox, phba->mbox_mem_pool);
803 /* Free this node since the driver cannot login or has the wrong
805 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
806 return (NLP_STE_FREED_NODE);
810 lpfc_device_rm_plogi_issue(struct lpfc_hba * phba,
811 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
813 /* software abort outstanding PLOGI */
814 lpfc_els_abort(phba, ndlp, 1);
816 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
817 return (NLP_STE_FREED_NODE);
821 lpfc_device_recov_plogi_issue(struct lpfc_hba * phba,
822 struct lpfc_nodelist * ndlp, void *arg,
825 /* software abort outstanding PLOGI */
826 lpfc_els_abort(phba, ndlp, 1);
828 ndlp->nlp_state = NLP_STE_NPR_NODE;
829 lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
830 spin_lock_irq(phba->host->host_lock);
831 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
832 spin_unlock_irq(phba->host->host_lock);
834 return (ndlp->nlp_state);
838 lpfc_rcv_plogi_adisc_issue(struct lpfc_hba * phba,
839 struct lpfc_nodelist * ndlp, void *arg,
842 struct lpfc_iocbq *cmdiocb;
844 /* software abort outstanding ADISC */
845 lpfc_els_abort(phba, ndlp, 1);
847 cmdiocb = (struct lpfc_iocbq *) arg;
849 if (lpfc_rcv_plogi(phba, ndlp, cmdiocb)) {
850 return (ndlp->nlp_state);
852 ndlp->nlp_state = NLP_STE_PLOGI_ISSUE;
853 lpfc_nlp_list(phba, ndlp, NLP_PLOGI_LIST);
854 lpfc_issue_els_plogi(phba, ndlp, 0);
856 return (ndlp->nlp_state);
860 lpfc_rcv_prli_adisc_issue(struct lpfc_hba * phba,
861 struct lpfc_nodelist * ndlp, void *arg,
864 struct lpfc_iocbq *cmdiocb;
866 cmdiocb = (struct lpfc_iocbq *) arg;
868 lpfc_els_rsp_prli_acc(phba, cmdiocb, ndlp);
869 return (ndlp->nlp_state);
873 lpfc_rcv_logo_adisc_issue(struct lpfc_hba * phba,
874 struct lpfc_nodelist * ndlp, void *arg,
877 struct lpfc_iocbq *cmdiocb;
879 cmdiocb = (struct lpfc_iocbq *) arg;
881 /* software abort outstanding ADISC */
882 lpfc_els_abort(phba, ndlp, 0);
884 lpfc_rcv_logo(phba, ndlp, cmdiocb);
885 return (ndlp->nlp_state);
889 lpfc_rcv_padisc_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_rcv_padisc(phba, ndlp, cmdiocb);
898 return (ndlp->nlp_state);
902 lpfc_rcv_prlo_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 /* Treat like rcv logo */
911 lpfc_rcv_logo(phba, ndlp, cmdiocb);
912 return (ndlp->nlp_state);
916 lpfc_cmpl_adisc_adisc_issue(struct lpfc_hba * phba,
917 struct lpfc_nodelist * ndlp, void *arg,
920 struct lpfc_iocbq *cmdiocb, *rspiocb;
924 cmdiocb = (struct lpfc_iocbq *) arg;
925 rspiocb = cmdiocb->context_un.rsp_iocb;
927 ap = (ADISC *)lpfc_check_elscmpl_iocb(phba, cmdiocb, rspiocb);
928 irsp = &rspiocb->iocb;
930 if ((irsp->ulpStatus) ||
931 (!lpfc_check_adisc(phba, ndlp, &ap->nodeName, &ap->portName))) {
932 ndlp->nlp_last_elscmd = (unsigned long)ELS_CMD_PLOGI;
934 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ);
935 spin_lock_irq(phba->host->host_lock);
936 ndlp->nlp_flag |= NLP_DELAY_TMO;
937 spin_unlock_irq(phba->host->host_lock);
939 memset(&ndlp->nlp_nodename, 0, sizeof (struct lpfc_name));
940 memset(&ndlp->nlp_portname, 0, sizeof (struct lpfc_name));
942 ndlp->nlp_state = NLP_STE_NPR_NODE;
943 lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
944 lpfc_unreg_rpi(phba, ndlp);
945 return (ndlp->nlp_state);
947 if (ndlp->nlp_type & NLP_FCP_TARGET) {
948 ndlp->nlp_state = NLP_STE_MAPPED_NODE;
949 lpfc_nlp_list(phba, ndlp, NLP_MAPPED_LIST);
951 ndlp->nlp_state = NLP_STE_UNMAPPED_NODE;
952 lpfc_nlp_list(phba, ndlp, NLP_UNMAPPED_LIST);
954 return (ndlp->nlp_state);
958 lpfc_device_rm_adisc_issue(struct lpfc_hba * phba,
959 struct lpfc_nodelist * ndlp, void *arg,
962 /* software abort outstanding ADISC */
963 lpfc_els_abort(phba, ndlp, 1);
965 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
966 return (NLP_STE_FREED_NODE);
970 lpfc_device_recov_adisc_issue(struct lpfc_hba * phba,
971 struct lpfc_nodelist * ndlp, void *arg,
974 /* software abort outstanding ADISC */
975 lpfc_els_abort(phba, ndlp, 1);
977 ndlp->nlp_state = NLP_STE_NPR_NODE;
978 lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
979 spin_lock_irq(phba->host->host_lock);
980 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
981 spin_unlock_irq(phba->host->host_lock);
983 lpfc_disc_set_adisc(phba, ndlp);
984 return (ndlp->nlp_state);
988 lpfc_rcv_plogi_reglogin_issue(struct lpfc_hba * phba,
989 struct lpfc_nodelist * ndlp, void *arg,
992 struct lpfc_iocbq *cmdiocb;
994 cmdiocb = (struct lpfc_iocbq *) arg;
996 lpfc_rcv_plogi(phba, ndlp, cmdiocb);
997 return (ndlp->nlp_state);
1001 lpfc_rcv_prli_reglogin_issue(struct lpfc_hba * phba,
1002 struct lpfc_nodelist * ndlp, void *arg,
1005 struct lpfc_iocbq *cmdiocb;
1007 cmdiocb = (struct lpfc_iocbq *) arg;
1009 lpfc_els_rsp_prli_acc(phba, cmdiocb, ndlp);
1010 return (ndlp->nlp_state);
1014 lpfc_rcv_logo_reglogin_issue(struct lpfc_hba * phba,
1015 struct lpfc_nodelist * ndlp, void *arg,
1018 struct lpfc_iocbq *cmdiocb;
1020 cmdiocb = (struct lpfc_iocbq *) arg;
1022 lpfc_rcv_logo(phba, ndlp, cmdiocb);
1023 return (ndlp->nlp_state);
1027 lpfc_rcv_padisc_reglogin_issue(struct lpfc_hba * phba,
1028 struct lpfc_nodelist * ndlp, void *arg,
1031 struct lpfc_iocbq *cmdiocb;
1033 cmdiocb = (struct lpfc_iocbq *) arg;
1035 lpfc_rcv_padisc(phba, ndlp, cmdiocb);
1036 return (ndlp->nlp_state);
1040 lpfc_rcv_prlo_reglogin_issue(struct lpfc_hba * phba,
1041 struct lpfc_nodelist * ndlp, void *arg,
1044 struct lpfc_iocbq *cmdiocb;
1046 cmdiocb = (struct lpfc_iocbq *) arg;
1047 lpfc_els_rsp_acc(phba, ELS_CMD_ACC, cmdiocb, ndlp, NULL, 0);
1048 return (ndlp->nlp_state);
1052 lpfc_cmpl_reglogin_reglogin_issue(struct lpfc_hba * phba,
1053 struct lpfc_nodelist * ndlp,
1054 void *arg, uint32_t evt)
1060 pmb = (LPFC_MBOXQ_t *) arg;
1062 did = mb->un.varWords[1];
1063 if (mb->mbxStatus) {
1064 /* RegLogin failed */
1065 lpfc_printf_log(phba,
1068 "%d:0246 RegLogin failed Data: x%x x%x x%x\n",
1070 did, mb->mbxStatus, phba->hba_state);
1072 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ * 1);
1073 spin_lock_irq(phba->host->host_lock);
1074 ndlp->nlp_flag |= NLP_DELAY_TMO;
1075 spin_unlock_irq(phba->host->host_lock);
1077 lpfc_issue_els_logo(phba, ndlp, 0);
1078 /* Put ndlp in npr list set plogi timer for 1 sec */
1079 ndlp->nlp_last_elscmd = (unsigned long)ELS_CMD_PLOGI;
1080 ndlp->nlp_state = NLP_STE_NPR_NODE;
1081 lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
1082 return (ndlp->nlp_state);
1085 ndlp->nlp_rpi = mb->un.varWords[0];
1087 /* Only if we are not a fabric nport do we issue PRLI */
1088 if (!(ndlp->nlp_type & NLP_FABRIC)) {
1089 ndlp->nlp_state = NLP_STE_PRLI_ISSUE;
1090 lpfc_nlp_list(phba, ndlp, NLP_PRLI_LIST);
1091 lpfc_issue_els_prli(phba, ndlp, 0);
1093 ndlp->nlp_state = NLP_STE_UNMAPPED_NODE;
1094 lpfc_nlp_list(phba, ndlp, NLP_UNMAPPED_LIST);
1096 return (ndlp->nlp_state);
1100 lpfc_device_rm_reglogin_issue(struct lpfc_hba * phba,
1101 struct lpfc_nodelist * ndlp, void *arg,
1104 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
1105 return (NLP_STE_FREED_NODE);
1109 lpfc_device_recov_reglogin_issue(struct lpfc_hba * phba,
1110 struct lpfc_nodelist * ndlp, void *arg,
1113 ndlp->nlp_state = NLP_STE_NPR_NODE;
1114 lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
1115 spin_lock_irq(phba->host->host_lock);
1116 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
1117 spin_unlock_irq(phba->host->host_lock);
1118 return (ndlp->nlp_state);
1122 lpfc_rcv_plogi_prli_issue(struct lpfc_hba * phba,
1123 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1125 struct lpfc_iocbq *cmdiocb;
1127 cmdiocb = (struct lpfc_iocbq *) arg;
1129 lpfc_rcv_plogi(phba, ndlp, cmdiocb);
1130 return (ndlp->nlp_state);
1134 lpfc_rcv_prli_prli_issue(struct lpfc_hba * phba,
1135 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1137 struct lpfc_iocbq *cmdiocb;
1139 cmdiocb = (struct lpfc_iocbq *) arg;
1141 lpfc_els_rsp_prli_acc(phba, cmdiocb, ndlp);
1142 return (ndlp->nlp_state);
1146 lpfc_rcv_logo_prli_issue(struct lpfc_hba * phba,
1147 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1149 struct lpfc_iocbq *cmdiocb;
1151 cmdiocb = (struct lpfc_iocbq *) arg;
1153 /* Software abort outstanding PRLI before sending acc */
1154 lpfc_els_abort(phba, ndlp, 1);
1156 lpfc_rcv_logo(phba, ndlp, cmdiocb);
1157 return (ndlp->nlp_state);
1161 lpfc_rcv_padisc_prli_issue(struct lpfc_hba * phba,
1162 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1164 struct lpfc_iocbq *cmdiocb;
1166 cmdiocb = (struct lpfc_iocbq *) arg;
1168 lpfc_rcv_padisc(phba, ndlp, cmdiocb);
1169 return (ndlp->nlp_state);
1172 /* This routine is envoked when we rcv a PRLO request from a nport
1173 * we are logged into. We should send back a PRLO rsp setting the
1175 * NEXT STATE = PRLI_ISSUE
1178 lpfc_rcv_prlo_prli_issue(struct lpfc_hba * phba,
1179 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1181 struct lpfc_iocbq *cmdiocb;
1183 cmdiocb = (struct lpfc_iocbq *) arg;
1184 lpfc_els_rsp_acc(phba, ELS_CMD_ACC, cmdiocb, ndlp, NULL, 0);
1185 return (ndlp->nlp_state);
1189 lpfc_cmpl_prli_prli_issue(struct lpfc_hba * phba,
1190 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1192 struct lpfc_iocbq *cmdiocb, *rspiocb;
1196 cmdiocb = (struct lpfc_iocbq *) arg;
1197 rspiocb = cmdiocb->context_un.rsp_iocb;
1198 npr = (PRLI *)lpfc_check_elscmpl_iocb(phba, cmdiocb, rspiocb);
1200 irsp = &rspiocb->iocb;
1201 if (irsp->ulpStatus) {
1202 ndlp->nlp_state = NLP_STE_UNMAPPED_NODE;
1203 lpfc_nlp_list(phba, ndlp, NLP_UNMAPPED_LIST);
1204 return (ndlp->nlp_state);
1207 /* Check out PRLI rsp */
1208 ndlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR);
1209 ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
1210 if ((npr->acceptRspCode == PRLI_REQ_EXECUTED) &&
1211 (npr->prliType == PRLI_FCP_TYPE)) {
1212 if (npr->initiatorFunc)
1213 ndlp->nlp_type |= NLP_FCP_INITIATOR;
1214 if (npr->targetFunc)
1215 ndlp->nlp_type |= NLP_FCP_TARGET;
1217 ndlp->nlp_fcp_info |= NLP_FCP_2_DEVICE;
1220 ndlp->nlp_state = NLP_STE_MAPPED_NODE;
1221 lpfc_nlp_list(phba, ndlp, NLP_MAPPED_LIST);
1222 return (ndlp->nlp_state);
1225 /*! lpfc_device_rm_prli_issue
1236 * This routine is envoked when we a request to remove a nport we are in the
1237 * process of PRLIing. We should software abort outstanding prli, unreg
1238 * login, send a logout. We will change node state to UNUSED_NODE, put it
1239 * on plogi list so it can be freed when LOGO completes.
1243 lpfc_device_rm_prli_issue(struct lpfc_hba * phba,
1244 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1246 /* software abort outstanding PRLI */
1247 lpfc_els_abort(phba, ndlp, 1);
1249 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
1250 return (NLP_STE_FREED_NODE);
1254 /*! lpfc_device_recov_prli_issue
1265 * The routine is envoked when the state of a device is unknown, like
1266 * during a link down. We should remove the nodelist entry from the
1267 * unmapped list, issue a UNREG_LOGIN, do a software abort of the
1268 * outstanding PRLI command, then free the node entry.
1271 lpfc_device_recov_prli_issue(struct lpfc_hba * phba,
1272 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1274 /* software abort outstanding PRLI */
1275 lpfc_els_abort(phba, ndlp, 1);
1277 ndlp->nlp_state = NLP_STE_NPR_NODE;
1278 lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
1279 spin_lock_irq(phba->host->host_lock);
1280 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
1281 spin_unlock_irq(phba->host->host_lock);
1282 return (ndlp->nlp_state);
1286 lpfc_rcv_plogi_unmap_node(struct lpfc_hba * phba,
1287 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1289 struct lpfc_iocbq *cmdiocb;
1291 cmdiocb = (struct lpfc_iocbq *) arg;
1293 lpfc_rcv_plogi(phba, ndlp, cmdiocb);
1294 return (ndlp->nlp_state);
1298 lpfc_rcv_prli_unmap_node(struct lpfc_hba * phba,
1299 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1301 struct lpfc_iocbq *cmdiocb;
1303 cmdiocb = (struct lpfc_iocbq *) arg;
1305 lpfc_rcv_prli(phba, ndlp, cmdiocb);
1306 lpfc_els_rsp_prli_acc(phba, cmdiocb, ndlp);
1307 return (ndlp->nlp_state);
1311 lpfc_rcv_logo_unmap_node(struct lpfc_hba * phba,
1312 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1314 struct lpfc_iocbq *cmdiocb;
1316 cmdiocb = (struct lpfc_iocbq *) arg;
1318 lpfc_rcv_logo(phba, ndlp, cmdiocb);
1319 return (ndlp->nlp_state);
1323 lpfc_rcv_padisc_unmap_node(struct lpfc_hba * phba,
1324 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1326 struct lpfc_iocbq *cmdiocb;
1328 cmdiocb = (struct lpfc_iocbq *) arg;
1330 lpfc_rcv_padisc(phba, ndlp, cmdiocb);
1331 return (ndlp->nlp_state);
1335 lpfc_rcv_prlo_unmap_node(struct lpfc_hba * phba,
1336 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1338 struct lpfc_iocbq *cmdiocb;
1340 cmdiocb = (struct lpfc_iocbq *) arg;
1342 /* Treat like rcv logo */
1343 lpfc_rcv_logo(phba, ndlp, cmdiocb);
1344 return (ndlp->nlp_state);
1348 lpfc_device_recov_unmap_node(struct lpfc_hba * phba,
1349 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1351 ndlp->nlp_state = NLP_STE_NPR_NODE;
1352 lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
1353 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
1354 lpfc_disc_set_adisc(phba, ndlp);
1356 return (ndlp->nlp_state);
1360 lpfc_rcv_plogi_mapped_node(struct lpfc_hba * phba,
1361 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1363 struct lpfc_iocbq *cmdiocb;
1365 cmdiocb = (struct lpfc_iocbq *) arg;
1367 lpfc_rcv_plogi(phba, ndlp, cmdiocb);
1368 return (ndlp->nlp_state);
1372 lpfc_rcv_prli_mapped_node(struct lpfc_hba * phba,
1373 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1375 struct lpfc_iocbq *cmdiocb;
1377 cmdiocb = (struct lpfc_iocbq *) arg;
1379 lpfc_els_rsp_prli_acc(phba, cmdiocb, ndlp);
1380 return (ndlp->nlp_state);
1384 lpfc_rcv_logo_mapped_node(struct lpfc_hba * phba,
1385 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1387 struct lpfc_iocbq *cmdiocb;
1389 cmdiocb = (struct lpfc_iocbq *) arg;
1391 lpfc_rcv_logo(phba, ndlp, cmdiocb);
1392 return (ndlp->nlp_state);
1396 lpfc_rcv_padisc_mapped_node(struct lpfc_hba * phba,
1397 struct lpfc_nodelist * ndlp, void *arg,
1400 struct lpfc_iocbq *cmdiocb;
1402 cmdiocb = (struct lpfc_iocbq *) arg;
1404 lpfc_rcv_padisc(phba, ndlp, cmdiocb);
1405 return (ndlp->nlp_state);
1409 lpfc_rcv_prlo_mapped_node(struct lpfc_hba * phba,
1410 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1412 struct lpfc_iocbq *cmdiocb;
1414 cmdiocb = (struct lpfc_iocbq *) arg;
1416 /* flush the target */
1417 spin_lock_irq(phba->host->host_lock);
1418 lpfc_sli_abort_iocb(phba, &phba->sli.ring[phba->sli.fcp_ring],
1419 ndlp->nlp_sid, 0, 0, LPFC_CTX_TGT);
1420 spin_unlock_irq(phba->host->host_lock);
1422 /* Treat like rcv logo */
1423 lpfc_rcv_logo(phba, ndlp, cmdiocb);
1424 return (ndlp->nlp_state);
1428 lpfc_device_recov_mapped_node(struct lpfc_hba * phba,
1429 struct lpfc_nodelist * ndlp, void *arg,
1432 ndlp->nlp_state = NLP_STE_NPR_NODE;
1433 lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
1434 spin_lock_irq(phba->host->host_lock);
1435 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
1436 spin_unlock_irq(phba->host->host_lock);
1437 lpfc_disc_set_adisc(phba, ndlp);
1438 return (ndlp->nlp_state);
1442 lpfc_rcv_plogi_npr_node(struct lpfc_hba * phba,
1443 struct lpfc_nodelist * ndlp, void *arg,
1446 struct lpfc_iocbq *cmdiocb;
1448 cmdiocb = (struct lpfc_iocbq *) arg;
1450 /* Ignore PLOGI if we have an outstanding LOGO */
1451 if (ndlp->nlp_flag & NLP_LOGO_SND) {
1452 return (ndlp->nlp_state);
1455 if (lpfc_rcv_plogi(phba, ndlp, cmdiocb)) {
1456 spin_lock_irq(phba->host->host_lock);
1457 ndlp->nlp_flag &= ~(NLP_NPR_ADISC | NLP_NPR_2B_DISC);
1458 spin_unlock_irq(phba->host->host_lock);
1459 return (ndlp->nlp_state);
1462 /* send PLOGI immediately, move to PLOGI issue state */
1463 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
1464 ndlp->nlp_state = NLP_STE_PLOGI_ISSUE;
1465 lpfc_nlp_list(phba, ndlp, NLP_PLOGI_LIST);
1466 lpfc_issue_els_plogi(phba, ndlp, 0);
1468 return (ndlp->nlp_state);
1472 lpfc_rcv_prli_npr_node(struct lpfc_hba * phba,
1473 struct lpfc_nodelist * ndlp, void *arg,
1476 struct lpfc_iocbq *cmdiocb;
1479 cmdiocb = (struct lpfc_iocbq *) arg;
1481 memset(&stat, 0, sizeof (struct ls_rjt));
1482 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
1483 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
1484 lpfc_els_rsp_reject(phba, stat.un.lsRjtError, cmdiocb, ndlp);
1486 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
1487 if (ndlp->nlp_flag & NLP_NPR_ADISC) {
1488 ndlp->nlp_state = NLP_STE_ADISC_ISSUE;
1489 lpfc_nlp_list(phba, ndlp, NLP_ADISC_LIST);
1490 lpfc_issue_els_adisc(phba, ndlp, 0);
1492 ndlp->nlp_state = NLP_STE_PLOGI_ISSUE;
1493 lpfc_nlp_list(phba, ndlp, NLP_PLOGI_LIST);
1494 lpfc_issue_els_plogi(phba, ndlp, 0);
1497 return (ndlp->nlp_state);
1501 lpfc_rcv_logo_npr_node(struct lpfc_hba * phba,
1502 struct lpfc_nodelist * ndlp, void *arg,
1505 struct lpfc_iocbq *cmdiocb;
1507 cmdiocb = (struct lpfc_iocbq *) arg;
1509 lpfc_rcv_logo(phba, ndlp, cmdiocb);
1510 return (ndlp->nlp_state);
1514 lpfc_rcv_padisc_npr_node(struct lpfc_hba * phba,
1515 struct lpfc_nodelist * ndlp, void *arg,
1518 struct lpfc_iocbq *cmdiocb;
1520 cmdiocb = (struct lpfc_iocbq *) arg;
1522 lpfc_rcv_padisc(phba, ndlp, cmdiocb);
1524 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
1525 if (ndlp->nlp_flag & NLP_NPR_ADISC) {
1526 ndlp->nlp_state = NLP_STE_ADISC_ISSUE;
1527 lpfc_nlp_list(phba, ndlp, NLP_ADISC_LIST);
1528 lpfc_issue_els_adisc(phba, ndlp, 0);
1530 ndlp->nlp_state = NLP_STE_PLOGI_ISSUE;
1531 lpfc_nlp_list(phba, ndlp, NLP_PLOGI_LIST);
1532 lpfc_issue_els_plogi(phba, ndlp, 0);
1535 return (ndlp->nlp_state);
1539 lpfc_rcv_prlo_npr_node(struct lpfc_hba * phba,
1540 struct lpfc_nodelist * ndlp, void *arg,
1543 struct lpfc_iocbq *cmdiocb;
1545 cmdiocb = (struct lpfc_iocbq *) arg;
1547 lpfc_els_rsp_acc(phba, ELS_CMD_ACC, cmdiocb, ndlp, NULL, 0);
1549 if (ndlp->nlp_flag & NLP_DELAY_TMO) {
1550 if (ndlp->nlp_last_elscmd == (unsigned long)ELS_CMD_PLOGI) {
1551 return (ndlp->nlp_state);
1553 spin_lock_irq(phba->host->host_lock);
1554 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
1555 spin_unlock_irq(phba->host->host_lock);
1556 del_timer_sync(&ndlp->nlp_delayfunc);
1557 if (!list_empty(&ndlp->els_retry_evt.evt_listp))
1558 list_del_init(&ndlp->els_retry_evt.evt_listp);
1562 ndlp->nlp_state = NLP_STE_PLOGI_ISSUE;
1563 lpfc_nlp_list(phba, ndlp, NLP_PLOGI_LIST);
1564 lpfc_issue_els_plogi(phba, ndlp, 0);
1565 return (ndlp->nlp_state);
1569 lpfc_cmpl_logo_npr_node(struct lpfc_hba * phba,
1570 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1572 lpfc_unreg_rpi(phba, ndlp);
1573 /* This routine does nothing, just return the current state */
1574 return (ndlp->nlp_state);
1578 lpfc_cmpl_reglogin_npr_node(struct lpfc_hba * phba,
1579 struct lpfc_nodelist * ndlp, void *arg,
1585 pmb = (LPFC_MBOXQ_t *) arg;
1588 ndlp->nlp_rpi = mb->un.varWords[0];
1590 return (ndlp->nlp_state);
1594 lpfc_device_rm_npr_node(struct lpfc_hba * phba,
1595 struct lpfc_nodelist * ndlp, void *arg,
1598 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
1599 return (NLP_STE_FREED_NODE);
1603 lpfc_device_recov_npr_node(struct lpfc_hba * phba,
1604 struct lpfc_nodelist * ndlp, void *arg,
1607 spin_lock_irq(phba->host->host_lock);
1608 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
1609 spin_unlock_irq(phba->host->host_lock);
1610 return (ndlp->nlp_state);
1614 /* This next section defines the NPort Discovery State Machine */
1616 /* There are 4 different double linked lists nodelist entries can reside on.
1617 * The plogi list and adisc list are used when Link Up discovery or RSCN
1618 * processing is needed. Each list holds the nodes that we will send PLOGI
1619 * or ADISC on. These lists will keep track of what nodes will be effected
1620 * by an RSCN, or a Link Up (Typically, all nodes are effected on Link Up).
1621 * The unmapped_list will contain all nodes that we have successfully logged
1622 * into at the Fibre Channel level. The mapped_list will contain all nodes
1623 * that are mapped FCP targets.
1626 * The bind list is a list of undiscovered (potentially non-existent) nodes
1627 * that we have saved binding information on. This information is used when
1628 * nodes transition from the unmapped to the mapped list.
1630 /* For UNUSED_NODE state, the node has just been allocated .
1631 * For PLOGI_ISSUE and REG_LOGIN_ISSUE, the node is on
1632 * the PLOGI list. For REG_LOGIN_COMPL, the node is taken off the PLOGI list
1633 * and put on the unmapped list. For ADISC processing, the node is taken off
1634 * the ADISC list and placed on either the mapped or unmapped list (depending
1635 * on its previous state). Once on the unmapped list, a PRLI is issued and the
1636 * state changed to PRLI_ISSUE. When the PRLI completion occurs, the state is
1637 * changed to UNMAPPED_NODE. If the completion indicates a mapped
1638 * node, the node is taken off the unmapped list. The binding list is checked
1639 * for a valid binding, or a binding is automatically assigned. If binding
1640 * assignment is unsuccessful, the node is left on the unmapped list. If
1641 * binding assignment is successful, the associated binding list entry (if
1642 * any) is removed, and the node is placed on the mapped list.
1645 * For a Link Down, all nodes on the ADISC, PLOGI, unmapped or mapped
1646 * lists will receive a DEVICE_RECOVERY event. If the linkdown or nodev timers
1647 * expire, all effected nodes will receive a DEVICE_RM event.
1650 * For a Link Up or RSCN, all nodes will move from the mapped / unmapped lists
1651 * to either the ADISC or PLOGI list. After a Nameserver query or ALPA loopmap
1652 * check, additional nodes may be added or removed (via DEVICE_RM) to / from
1653 * the PLOGI or ADISC lists. Once the PLOGI and ADISC lists are populated,
1654 * we will first process the ADISC list. 32 entries are processed initially and
1655 * ADISC is initited for each one. Completions / Events for each node are
1656 * funnelled thru the state machine. As each node finishes ADISC processing, it
1657 * starts ADISC for any nodes waiting for ADISC processing. If no nodes are
1658 * waiting, and the ADISC list count is identically 0, then we are done. For
1659 * Link Up discovery, since all nodes on the PLOGI list are UNREG_LOGIN'ed, we
1660 * can issue a CLEAR_LA and reenable Link Events. Next we will process the PLOGI
1661 * list. 32 entries are processed initially and PLOGI is initited for each one.
1662 * Completions / Events for each node are funnelled thru the state machine. As
1663 * each node finishes PLOGI processing, it starts PLOGI for any nodes waiting
1664 * for PLOGI processing. If no nodes are waiting, and the PLOGI list count is
1665 * indentically 0, then we are done. We have now completed discovery / RSCN
1666 * handling. Upon completion, ALL nodes should be on either the mapped or
1670 static uint32_t (*lpfc_disc_action[NLP_STE_MAX_STATE * NLP_EVT_MAX_EVENT])
1671 (struct lpfc_hba *, struct lpfc_nodelist *, void *, uint32_t) = {
1672 /* Action routine Event Current State */
1673 lpfc_rcv_plogi_unused_node, /* RCV_PLOGI UNUSED_NODE */
1674 lpfc_rcv_els_unused_node, /* RCV_PRLI */
1675 lpfc_rcv_logo_unused_node, /* RCV_LOGO */
1676 lpfc_rcv_els_unused_node, /* RCV_ADISC */
1677 lpfc_rcv_els_unused_node, /* RCV_PDISC */
1678 lpfc_rcv_els_unused_node, /* RCV_PRLO */
1679 lpfc_disc_illegal, /* CMPL_PLOGI */
1680 lpfc_disc_illegal, /* CMPL_PRLI */
1681 lpfc_cmpl_logo_unused_node, /* CMPL_LOGO */
1682 lpfc_disc_illegal, /* CMPL_ADISC */
1683 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
1684 lpfc_device_rm_unused_node, /* DEVICE_RM */
1685 lpfc_disc_illegal, /* DEVICE_RECOVERY */
1687 lpfc_rcv_plogi_plogi_issue, /* RCV_PLOGI PLOGI_ISSUE */
1688 lpfc_rcv_els_plogi_issue, /* RCV_PRLI */
1689 lpfc_rcv_els_plogi_issue, /* RCV_LOGO */
1690 lpfc_rcv_els_plogi_issue, /* RCV_ADISC */
1691 lpfc_rcv_els_plogi_issue, /* RCV_PDISC */
1692 lpfc_rcv_els_plogi_issue, /* RCV_PRLO */
1693 lpfc_cmpl_plogi_plogi_issue, /* CMPL_PLOGI */
1694 lpfc_disc_illegal, /* CMPL_PRLI */
1695 lpfc_disc_illegal, /* CMPL_LOGO */
1696 lpfc_disc_illegal, /* CMPL_ADISC */
1697 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
1698 lpfc_device_rm_plogi_issue, /* DEVICE_RM */
1699 lpfc_device_recov_plogi_issue, /* DEVICE_RECOVERY */
1701 lpfc_rcv_plogi_adisc_issue, /* RCV_PLOGI ADISC_ISSUE */
1702 lpfc_rcv_prli_adisc_issue, /* RCV_PRLI */
1703 lpfc_rcv_logo_adisc_issue, /* RCV_LOGO */
1704 lpfc_rcv_padisc_adisc_issue, /* RCV_ADISC */
1705 lpfc_rcv_padisc_adisc_issue, /* RCV_PDISC */
1706 lpfc_rcv_prlo_adisc_issue, /* RCV_PRLO */
1707 lpfc_disc_illegal, /* CMPL_PLOGI */
1708 lpfc_disc_illegal, /* CMPL_PRLI */
1709 lpfc_disc_illegal, /* CMPL_LOGO */
1710 lpfc_cmpl_adisc_adisc_issue, /* CMPL_ADISC */
1711 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
1712 lpfc_device_rm_adisc_issue, /* DEVICE_RM */
1713 lpfc_device_recov_adisc_issue, /* DEVICE_RECOVERY */
1715 lpfc_rcv_plogi_reglogin_issue, /* RCV_PLOGI REG_LOGIN_ISSUE */
1716 lpfc_rcv_prli_reglogin_issue, /* RCV_PLOGI */
1717 lpfc_rcv_logo_reglogin_issue, /* RCV_LOGO */
1718 lpfc_rcv_padisc_reglogin_issue, /* RCV_ADISC */
1719 lpfc_rcv_padisc_reglogin_issue, /* RCV_PDISC */
1720 lpfc_rcv_prlo_reglogin_issue, /* RCV_PRLO */
1721 lpfc_disc_illegal, /* CMPL_PLOGI */
1722 lpfc_disc_illegal, /* CMPL_PRLI */
1723 lpfc_disc_illegal, /* CMPL_LOGO */
1724 lpfc_disc_illegal, /* CMPL_ADISC */
1725 lpfc_cmpl_reglogin_reglogin_issue,/* CMPL_REG_LOGIN */
1726 lpfc_device_rm_reglogin_issue, /* DEVICE_RM */
1727 lpfc_device_recov_reglogin_issue,/* DEVICE_RECOVERY */
1729 lpfc_rcv_plogi_prli_issue, /* RCV_PLOGI PRLI_ISSUE */
1730 lpfc_rcv_prli_prli_issue, /* RCV_PRLI */
1731 lpfc_rcv_logo_prli_issue, /* RCV_LOGO */
1732 lpfc_rcv_padisc_prli_issue, /* RCV_ADISC */
1733 lpfc_rcv_padisc_prli_issue, /* RCV_PDISC */
1734 lpfc_rcv_prlo_prli_issue, /* RCV_PRLO */
1735 lpfc_disc_illegal, /* CMPL_PLOGI */
1736 lpfc_cmpl_prli_prli_issue, /* CMPL_PRLI */
1737 lpfc_disc_illegal, /* CMPL_LOGO */
1738 lpfc_disc_illegal, /* CMPL_ADISC */
1739 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
1740 lpfc_device_rm_prli_issue, /* DEVICE_RM */
1741 lpfc_device_recov_prli_issue, /* DEVICE_RECOVERY */
1743 lpfc_rcv_plogi_unmap_node, /* RCV_PLOGI UNMAPPED_NODE */
1744 lpfc_rcv_prli_unmap_node, /* RCV_PRLI */
1745 lpfc_rcv_logo_unmap_node, /* RCV_LOGO */
1746 lpfc_rcv_padisc_unmap_node, /* RCV_ADISC */
1747 lpfc_rcv_padisc_unmap_node, /* RCV_PDISC */
1748 lpfc_rcv_prlo_unmap_node, /* RCV_PRLO */
1749 lpfc_disc_illegal, /* CMPL_PLOGI */
1750 lpfc_disc_illegal, /* CMPL_PRLI */
1751 lpfc_disc_illegal, /* CMPL_LOGO */
1752 lpfc_disc_illegal, /* CMPL_ADISC */
1753 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
1754 lpfc_disc_illegal, /* DEVICE_RM */
1755 lpfc_device_recov_unmap_node, /* DEVICE_RECOVERY */
1757 lpfc_rcv_plogi_mapped_node, /* RCV_PLOGI MAPPED_NODE */
1758 lpfc_rcv_prli_mapped_node, /* RCV_PRLI */
1759 lpfc_rcv_logo_mapped_node, /* RCV_LOGO */
1760 lpfc_rcv_padisc_mapped_node, /* RCV_ADISC */
1761 lpfc_rcv_padisc_mapped_node, /* RCV_PDISC */
1762 lpfc_rcv_prlo_mapped_node, /* RCV_PRLO */
1763 lpfc_disc_illegal, /* CMPL_PLOGI */
1764 lpfc_disc_illegal, /* CMPL_PRLI */
1765 lpfc_disc_illegal, /* CMPL_LOGO */
1766 lpfc_disc_illegal, /* CMPL_ADISC */
1767 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
1768 lpfc_disc_illegal, /* DEVICE_RM */
1769 lpfc_device_recov_mapped_node, /* DEVICE_RECOVERY */
1771 lpfc_rcv_plogi_npr_node, /* RCV_PLOGI NPR_NODE */
1772 lpfc_rcv_prli_npr_node, /* RCV_PRLI */
1773 lpfc_rcv_logo_npr_node, /* RCV_LOGO */
1774 lpfc_rcv_padisc_npr_node, /* RCV_ADISC */
1775 lpfc_rcv_padisc_npr_node, /* RCV_PDISC */
1776 lpfc_rcv_prlo_npr_node, /* RCV_PRLO */
1777 lpfc_disc_noop, /* CMPL_PLOGI */
1778 lpfc_disc_noop, /* CMPL_PRLI */
1779 lpfc_cmpl_logo_npr_node, /* CMPL_LOGO */
1780 lpfc_disc_noop, /* CMPL_ADISC */
1781 lpfc_cmpl_reglogin_npr_node, /* CMPL_REG_LOGIN */
1782 lpfc_device_rm_npr_node, /* DEVICE_RM */
1783 lpfc_device_recov_npr_node, /* DEVICE_RECOVERY */
1787 lpfc_disc_state_machine(struct lpfc_hba * phba,
1788 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1790 uint32_t cur_state, rc;
1791 uint32_t(*func) (struct lpfc_hba *, struct lpfc_nodelist *, void *,
1794 ndlp->nlp_disc_refcnt++;
1795 cur_state = ndlp->nlp_state;
1797 /* DSM in event <evt> on NPort <nlp_DID> in state <cur_state> */
1798 lpfc_printf_log(phba,
1801 "%d:0211 DSM in event x%x on NPort x%x in state %d "
1804 evt, ndlp->nlp_DID, cur_state, ndlp->nlp_flag);
1806 func = lpfc_disc_action[(cur_state * NLP_EVT_MAX_EVENT) + evt];
1807 rc = (func) (phba, ndlp, arg, evt);
1809 /* DSM out state <rc> on NPort <nlp_DID> */
1810 lpfc_printf_log(phba,
1813 "%d:0212 DSM out state %d on NPort x%x Data: x%x\n",
1815 rc, ndlp->nlp_DID, ndlp->nlp_flag);
1817 ndlp->nlp_disc_refcnt--;
1819 /* Check to see if ndlp removal is deferred */
1820 if ((ndlp->nlp_disc_refcnt == 0)
1821 && (ndlp->nlp_flag & NLP_DELAY_REMOVE)) {
1822 spin_lock_irq(phba->host->host_lock);
1823 ndlp->nlp_flag &= ~NLP_DELAY_REMOVE;
1824 spin_unlock_irq(phba->host->host_lock);
1825 lpfc_nlp_remove(phba, ndlp);
1826 return (NLP_STE_FREED_NODE);
1828 if (rc == NLP_STE_FREED_NODE)
1829 return (NLP_STE_FREED_NODE);
1830 ndlp->nlp_state = rc;