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_device.h>
27 #include <scsi/scsi_host.h>
28 #include <scsi/scsi_transport_fc.h>
32 #include "lpfc_disc.h"
33 #include "lpfc_scsi.h"
35 #include "lpfc_logmsg.h"
36 #include "lpfc_crtn.h"
39 /* Called to verify a rcv'ed ADISC was intended for us. */
41 lpfc_check_adisc(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp,
42 struct lpfc_name * nn, struct lpfc_name * pn)
44 /* Compare the ADISC rsp WWNN / WWPN matches our internal node
45 * table entry for that node.
47 if (memcmp(nn, &ndlp->nlp_nodename, sizeof (struct lpfc_name)) != 0)
50 if (memcmp(pn, &ndlp->nlp_portname, sizeof (struct lpfc_name)) != 0)
53 /* we match, return success */
59 lpfc_check_sparm(struct lpfc_hba * phba,
60 struct lpfc_nodelist * ndlp, struct serv_parm * sp,
63 volatile struct serv_parm *hsp = &phba->fc_sparam;
64 /* First check for supported version */
66 /* Next check for class validity */
67 if (sp->cls1.classValid) {
69 if (sp->cls1.rcvDataSizeMsb > hsp->cls1.rcvDataSizeMsb)
70 sp->cls1.rcvDataSizeMsb = hsp->cls1.rcvDataSizeMsb;
71 if (sp->cls1.rcvDataSizeLsb > hsp->cls1.rcvDataSizeLsb)
72 sp->cls1.rcvDataSizeLsb = hsp->cls1.rcvDataSizeLsb;
73 } else if (class == CLASS1) {
77 if (sp->cls2.classValid) {
79 if (sp->cls2.rcvDataSizeMsb > hsp->cls2.rcvDataSizeMsb)
80 sp->cls2.rcvDataSizeMsb = hsp->cls2.rcvDataSizeMsb;
81 if (sp->cls2.rcvDataSizeLsb > hsp->cls2.rcvDataSizeLsb)
82 sp->cls2.rcvDataSizeLsb = hsp->cls2.rcvDataSizeLsb;
83 } else if (class == CLASS2) {
87 if (sp->cls3.classValid) {
89 if (sp->cls3.rcvDataSizeMsb > hsp->cls3.rcvDataSizeMsb)
90 sp->cls3.rcvDataSizeMsb = hsp->cls3.rcvDataSizeMsb;
91 if (sp->cls3.rcvDataSizeLsb > hsp->cls3.rcvDataSizeLsb)
92 sp->cls3.rcvDataSizeLsb = hsp->cls3.rcvDataSizeLsb;
93 } else if (class == CLASS3) {
97 if (sp->cmn.bbRcvSizeMsb > hsp->cmn.bbRcvSizeMsb)
98 sp->cmn.bbRcvSizeMsb = hsp->cmn.bbRcvSizeMsb;
99 if (sp->cmn.bbRcvSizeLsb > hsp->cmn.bbRcvSizeLsb)
100 sp->cmn.bbRcvSizeLsb = hsp->cmn.bbRcvSizeLsb;
102 /* If check is good, copy wwpn wwnn into ndlp */
103 memcpy(&ndlp->nlp_nodename, &sp->nodeName, sizeof (struct lpfc_name));
104 memcpy(&ndlp->nlp_portname, &sp->portName, sizeof (struct lpfc_name));
109 lpfc_check_elscmpl_iocb(struct lpfc_hba * phba,
110 struct lpfc_iocbq *cmdiocb,
111 struct lpfc_iocbq *rspiocb)
113 struct lpfc_dmabuf *pcmd, *prsp;
118 irsp = &rspiocb->iocb;
119 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
121 /* For lpfc_els_abort, context2 could be zero'ed to delay
122 * freeing associated memory till after ABTS completes.
125 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf,
128 lp = (uint32_t *) prsp->virt;
129 ptr = (void *)((uint8_t *)lp + sizeof(uint32_t));
133 /* Force ulpStatus error since we are returning NULL ptr */
134 if (!(irsp->ulpStatus)) {
135 irsp->ulpStatus = IOSTAT_LOCAL_REJECT;
136 irsp->un.ulpWord[4] = IOERR_SLI_ABORTED;
145 * Free resources / clean up outstanding I/Os
146 * associated with a LPFC_NODELIST entry. This
147 * routine effectively results in a "software abort".
150 lpfc_els_abort(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp,
153 struct lpfc_sli *psli;
154 struct lpfc_sli_ring *pring;
155 struct lpfc_iocbq *iocb, *next_iocb;
159 /* Abort outstanding I/O on NPort <nlp_DID> */
160 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
161 "%d:0201 Abort outstanding I/O on NPort x%x "
162 "Data: x%x x%x x%x\n",
163 phba->brd_no, ndlp->nlp_DID, ndlp->nlp_flag,
164 ndlp->nlp_state, ndlp->nlp_rpi);
167 pring = &psli->ring[LPFC_ELS_RING];
169 /* First check the txq */
172 spin_lock_irq(phba->host->host_lock);
173 list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
174 /* Check to see if iocb matches the nport we are looking
176 if ((lpfc_check_sli_ndlp(phba, pring, iocb, ndlp))) {
178 /* It matches, so deque and call compl with an
180 list_del(&iocb->list);
182 if (iocb->iocb_cmpl) {
184 icmd->ulpStatus = IOSTAT_LOCAL_REJECT;
185 icmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
186 spin_unlock_irq(phba->host->host_lock);
187 (iocb->iocb_cmpl) (phba, iocb, iocb);
188 spin_lock_irq(phba->host->host_lock);
190 list_add_tail(&iocb->list,
191 &phba->lpfc_iocb_list);
196 spin_unlock_irq(phba->host->host_lock);
199 /* Everything on txcmplq will be returned by firmware
200 * with a no rpi / linkdown / abort error. For ring 0,
201 * ELS discovery, we want to get rid of it right here.
203 /* Next check the txcmplq */
206 spin_lock_irq(phba->host->host_lock);
207 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq,
209 /* Check to see if iocb matches the nport we are looking
211 if ((lpfc_check_sli_ndlp (phba, pring, iocb, ndlp))) {
213 /* It matches, so deque and call compl with an
215 list_del(&iocb->list);
216 pring->txcmplq_cnt--;
219 /* If the driver is completing an ELS
220 * command early, flush it out of the firmware.
223 (icmd->ulpCommand == CMD_ELS_REQUEST64_CR) &&
224 (icmd->un.elsreq64.bdl.ulpIoTag32)) {
225 lpfc_sli_issue_abort_iotag32(phba,
228 if (iocb->iocb_cmpl) {
229 icmd->ulpStatus = IOSTAT_LOCAL_REJECT;
230 icmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
231 spin_unlock_irq(phba->host->host_lock);
232 (iocb->iocb_cmpl) (phba, iocb, iocb);
233 spin_lock_irq(phba->host->host_lock);
235 list_add_tail(&iocb->list,
236 &phba->lpfc_iocb_list);
241 spin_unlock_irq(phba->host->host_lock);
244 /* If we are delaying issuing an ELS command, cancel it */
245 if (ndlp->nlp_flag & NLP_DELAY_TMO) {
246 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
247 del_timer_sync(&ndlp->nlp_delayfunc);
248 if (!list_empty(&ndlp->els_retry_evt.evt_listp))
249 list_del_init(&ndlp->els_retry_evt.evt_listp);
255 lpfc_rcv_plogi(struct lpfc_hba * phba,
256 struct lpfc_nodelist * ndlp,
257 struct lpfc_iocbq *cmdiocb)
259 struct lpfc_dmabuf *pcmd;
262 struct serv_parm *sp;
267 memset(&stat, 0, sizeof (struct ls_rjt));
268 if (phba->hba_state <= LPFC_FLOGI) {
269 /* Before responding to PLOGI, check for pt2pt mode.
270 * If we are pt2pt, with an outstanding FLOGI, abort
271 * the FLOGI and resend it first.
273 if (phba->fc_flag & FC_PT2PT) {
274 lpfc_els_abort_flogi(phba);
275 if (!(phba->fc_flag & FC_PT2PT_PLOGI)) {
276 /* If the other side is supposed to initiate
277 * the PLOGI anyway, just ACC it now and
278 * move on with discovery.
280 phba->fc_edtov = FF_DEF_EDTOV;
281 phba->fc_ratov = FF_DEF_RATOV;
282 /* Start discovery - this should just do
284 lpfc_disc_start(phba);
287 lpfc_initial_flogi(phba);
291 stat.un.b.lsRjtRsnCode = LSRJT_LOGICAL_BSY;
292 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
293 lpfc_els_rsp_reject(phba, stat.un.lsRjtError, cmdiocb,
298 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
299 lp = (uint32_t *) pcmd->virt;
300 sp = (struct serv_parm *) ((uint8_t *) lp + sizeof (uint32_t));
301 if ((lpfc_check_sparm(phba, ndlp, sp, CLASS3) == 0)) {
302 /* Reject this request because invalid parameters */
303 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
304 stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
305 lpfc_els_rsp_reject(phba, stat.un.lsRjtError, cmdiocb, ndlp);
308 icmd = &cmdiocb->iocb;
310 /* PLOGI chkparm OK */
311 lpfc_printf_log(phba,
314 "%d:0114 PLOGI chkparm OK Data: x%x x%x x%x x%x\n",
316 ndlp->nlp_DID, ndlp->nlp_state, ndlp->nlp_flag,
319 if ((phba->cfg_fcp_class == 2) &&
320 (sp->cls2.classValid)) {
321 ndlp->nlp_fcp_info |= CLASS2;
323 ndlp->nlp_fcp_info |= CLASS3;
325 ndlp->nlp_class_sup = 0;
326 if (sp->cls1.classValid)
327 ndlp->nlp_class_sup |= FC_COS_CLASS1;
328 if (sp->cls2.classValid)
329 ndlp->nlp_class_sup |= FC_COS_CLASS2;
330 if (sp->cls3.classValid)
331 ndlp->nlp_class_sup |= FC_COS_CLASS3;
332 if (sp->cls4.classValid)
333 ndlp->nlp_class_sup |= FC_COS_CLASS4;
335 ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) | sp->cmn.bbRcvSizeLsb;
337 /* no need to reg_login if we are already in one of these states */
338 switch(ndlp->nlp_state) {
339 case NLP_STE_NPR_NODE:
340 if (!(ndlp->nlp_flag & NLP_NPR_ADISC))
342 case NLP_STE_REG_LOGIN_ISSUE:
343 case NLP_STE_PRLI_ISSUE:
344 case NLP_STE_UNMAPPED_NODE:
345 case NLP_STE_MAPPED_NODE:
346 lpfc_els_rsp_acc(phba, ELS_CMD_PLOGI, cmdiocb, ndlp, NULL, 0);
350 if ((phba->fc_flag & FC_PT2PT)
351 && !(phba->fc_flag & FC_PT2PT_PLOGI)) {
352 /* rcv'ed PLOGI decides what our NPortId will be */
353 phba->fc_myDID = icmd->un.rcvels.parmRo;
354 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
357 lpfc_config_link(phba, mbox);
358 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
359 rc = lpfc_sli_issue_mbox
360 (phba, mbox, (MBX_NOWAIT | MBX_STOP_IOCB));
361 if (rc == MBX_NOT_FINISHED) {
362 mempool_free( mbox, phba->mbox_mem_pool);
366 lpfc_can_disctmo(phba);
368 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
372 if (lpfc_reg_login(phba, icmd->un.rcvels.remoteID,
373 (uint8_t *) sp, mbox, 0)) {
374 mempool_free( mbox, phba->mbox_mem_pool);
378 /* ACC PLOGI rsp command needs to execute first,
379 * queue this mbox command to be processed later.
381 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
382 mbox->context2 = ndlp;
383 ndlp->nlp_flag |= NLP_ACC_REGLOGIN;
385 /* If there is an outstanding PLOGI issued, abort it before
386 * sending ACC rsp to PLOGI recieved.
388 if (ndlp->nlp_state == NLP_STE_PLOGI_ISSUE) {
389 /* software abort outstanding PLOGI */
390 lpfc_els_abort(phba, ndlp, 1);
392 ndlp->nlp_flag |= NLP_RCV_PLOGI;
393 lpfc_els_rsp_acc(phba, ELS_CMD_PLOGI, cmdiocb, ndlp, mbox, 0);
397 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
398 stat.un.b.lsRjtRsnCodeExp = LSEXP_OUT_OF_RESOURCE;
399 lpfc_els_rsp_reject(phba, stat.un.lsRjtError, cmdiocb, ndlp);
404 lpfc_rcv_padisc(struct lpfc_hba * phba,
405 struct lpfc_nodelist * ndlp,
406 struct lpfc_iocbq *cmdiocb)
408 struct lpfc_dmabuf *pcmd;
409 struct serv_parm *sp;
410 struct lpfc_name *pnn, *ppn;
417 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
418 lp = (uint32_t *) pcmd->virt;
421 if (cmd == ELS_CMD_ADISC) {
423 pnn = (struct lpfc_name *) & ap->nodeName;
424 ppn = (struct lpfc_name *) & ap->portName;
426 sp = (struct serv_parm *) lp;
427 pnn = (struct lpfc_name *) & sp->nodeName;
428 ppn = (struct lpfc_name *) & sp->portName;
431 icmd = &cmdiocb->iocb;
432 if ((icmd->ulpStatus == 0) &&
433 (lpfc_check_adisc(phba, ndlp, pnn, ppn))) {
434 if (cmd == ELS_CMD_ADISC) {
435 lpfc_els_rsp_adisc_acc(phba, cmdiocb, ndlp);
438 lpfc_els_rsp_acc(phba, ELS_CMD_PLOGI, cmdiocb, ndlp,
443 /* Reject this request because invalid parameters */
444 stat.un.b.lsRjtRsvd0 = 0;
445 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
446 stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
447 stat.un.b.vendorUnique = 0;
448 lpfc_els_rsp_reject(phba, stat.un.lsRjtError, cmdiocb, ndlp);
450 ndlp->nlp_last_elscmd = (unsigned long)ELS_CMD_PLOGI;
452 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ);
454 spin_lock_irq(phba->host->host_lock);
455 ndlp->nlp_flag |= NLP_DELAY_TMO;
456 spin_unlock_irq(phba->host->host_lock);
457 ndlp->nlp_state = NLP_STE_NPR_NODE;
458 lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
463 lpfc_rcv_logo(struct lpfc_hba * phba,
464 struct lpfc_nodelist * ndlp,
465 struct lpfc_iocbq *cmdiocb)
467 /* Put ndlp on NPR list with 1 sec timeout for plogi, ACC logo */
468 /* Only call LOGO ACC for first LOGO, this avoids sending unnecessary
469 * PLOGIs during LOGO storms from a device.
471 ndlp->nlp_flag |= NLP_LOGO_ACC;
472 lpfc_els_rsp_acc(phba, ELS_CMD_ACC, cmdiocb, ndlp, NULL, 0);
474 if (!(ndlp->nlp_type & NLP_FABRIC)) {
475 /* Only try to re-login if this is NOT a Fabric Node */
476 ndlp->nlp_last_elscmd = (unsigned long)ELS_CMD_PLOGI;
477 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ * 1);
478 spin_lock_irq(phba->host->host_lock);
479 ndlp->nlp_flag |= NLP_DELAY_TMO;
480 spin_unlock_irq(phba->host->host_lock);
483 ndlp->nlp_state = NLP_STE_NPR_NODE;
484 lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
486 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
487 /* The driver has to wait until the ACC completes before it continues
488 * processing the LOGO. The action will resume in
489 * lpfc_cmpl_els_logo_acc routine. Since part of processing includes an
490 * unreg_login, the driver waits so the ACC does not get aborted.
496 lpfc_rcv_prli(struct lpfc_hba * phba,
497 struct lpfc_nodelist * ndlp,
498 struct lpfc_iocbq *cmdiocb)
500 struct lpfc_dmabuf *pcmd;
503 struct fc_rport *rport = ndlp->rport;
506 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
507 lp = (uint32_t *) pcmd->virt;
508 npr = (PRLI *) ((uint8_t *) lp + sizeof (uint32_t));
510 ndlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR);
511 ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
512 if ((npr->acceptRspCode == PRLI_REQ_EXECUTED) &&
513 (npr->prliType == PRLI_FCP_TYPE)) {
514 if (npr->initiatorFunc)
515 ndlp->nlp_type |= NLP_FCP_INITIATOR;
517 ndlp->nlp_type |= NLP_FCP_TARGET;
519 ndlp->nlp_fcp_info |= NLP_FCP_2_DEVICE;
522 /* We need to update the rport role values */
523 roles = FC_RPORT_ROLE_UNKNOWN;
524 if (ndlp->nlp_type & NLP_FCP_INITIATOR)
525 roles |= FC_RPORT_ROLE_FCP_INITIATOR;
526 if (ndlp->nlp_type & NLP_FCP_TARGET)
527 roles |= FC_RPORT_ROLE_FCP_TARGET;
528 fc_remote_port_rolechg(rport, roles);
533 lpfc_disc_set_adisc(struct lpfc_hba * phba,
534 struct lpfc_nodelist * ndlp)
536 /* Check config parameter use-adisc or FCP-2 */
537 if ((phba->cfg_use_adisc == 0) &&
538 !(phba->fc_flag & FC_RSCN_MODE)) {
539 if (!(ndlp->nlp_fcp_info & NLP_FCP_2_DEVICE))
542 spin_lock_irq(phba->host->host_lock);
543 ndlp->nlp_flag |= NLP_NPR_ADISC;
544 spin_unlock_irq(phba->host->host_lock);
549 lpfc_disc_noop(struct lpfc_hba * phba,
550 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
552 /* This routine does nothing, just return the current state */
553 return (ndlp->nlp_state);
557 lpfc_disc_illegal(struct lpfc_hba * phba,
558 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
560 lpfc_printf_log(phba,
563 "%d:0253 Illegal State Transition: node x%x event x%x, "
564 "state x%x Data: x%x x%x\n",
566 ndlp->nlp_DID, evt, ndlp->nlp_state, ndlp->nlp_rpi,
568 return (ndlp->nlp_state);
571 /* Start of Discovery State Machine routines */
574 lpfc_rcv_plogi_unused_node(struct lpfc_hba * phba,
575 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
577 struct lpfc_iocbq *cmdiocb;
579 cmdiocb = (struct lpfc_iocbq *) arg;
581 if (lpfc_rcv_plogi(phba, ndlp, cmdiocb)) {
582 ndlp->nlp_state = NLP_STE_UNUSED_NODE;
583 lpfc_nlp_list(phba, ndlp, NLP_UNUSED_LIST);
584 return (ndlp->nlp_state);
586 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
587 return (NLP_STE_FREED_NODE);
591 lpfc_rcv_els_unused_node(struct lpfc_hba * phba,
592 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
594 lpfc_issue_els_logo(phba, ndlp, 0);
595 lpfc_nlp_list(phba, ndlp, NLP_UNUSED_LIST);
596 return (ndlp->nlp_state);
600 lpfc_rcv_logo_unused_node(struct lpfc_hba * phba,
601 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
603 struct lpfc_iocbq *cmdiocb;
605 cmdiocb = (struct lpfc_iocbq *) arg;
607 spin_lock_irq(phba->host->host_lock);
608 ndlp->nlp_flag |= NLP_LOGO_ACC;
609 spin_unlock_irq(phba->host->host_lock);
610 lpfc_els_rsp_acc(phba, ELS_CMD_ACC, cmdiocb, ndlp, NULL, 0);
611 lpfc_nlp_list(phba, ndlp, NLP_UNUSED_LIST);
613 return (ndlp->nlp_state);
617 lpfc_cmpl_logo_unused_node(struct lpfc_hba * phba,
618 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
620 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
621 return (NLP_STE_FREED_NODE);
625 lpfc_device_rm_unused_node(struct lpfc_hba * phba,
626 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
628 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
629 return (NLP_STE_FREED_NODE);
633 lpfc_rcv_plogi_plogi_issue(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp,
634 void *arg, uint32_t evt)
636 struct lpfc_iocbq *cmdiocb = arg;
637 struct lpfc_dmabuf *pcmd;
638 struct serv_parm *sp;
643 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
644 lp = (uint32_t *) pcmd->virt;
645 sp = (struct serv_parm *) ((uint8_t *) lp + sizeof (uint32_t));
647 memset(&stat, 0, sizeof (struct ls_rjt));
649 /* For a PLOGI, we only accept if our portname is less
650 * than the remote portname.
652 phba->fc_stat.elsLogiCol++;
653 port_cmp = memcmp(&phba->fc_portname, &sp->portName,
654 sizeof (struct lpfc_name));
657 /* Reject this request because the remote node will accept
659 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
660 stat.un.b.lsRjtRsnCodeExp = LSEXP_CMD_IN_PROGRESS;
661 lpfc_els_rsp_reject(phba, stat.un.lsRjtError, cmdiocb, ndlp);
664 lpfc_rcv_plogi(phba, ndlp, cmdiocb);
665 } /* if our portname was less */
667 return (ndlp->nlp_state);
671 lpfc_rcv_els_plogi_issue(struct lpfc_hba * phba,
672 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
674 struct lpfc_iocbq *cmdiocb;
676 cmdiocb = (struct lpfc_iocbq *) arg;
678 /* software abort outstanding PLOGI */
679 lpfc_els_abort(phba, ndlp, 1);
680 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ * 1);
681 spin_lock_irq(phba->host->host_lock);
682 ndlp->nlp_flag |= NLP_DELAY_TMO;
683 spin_unlock_irq(phba->host->host_lock);
685 if (evt == NLP_EVT_RCV_LOGO) {
686 lpfc_els_rsp_acc(phba, ELS_CMD_ACC, cmdiocb, ndlp, NULL, 0);
689 lpfc_issue_els_logo(phba, ndlp, 0);
692 /* Put ndlp in npr list set plogi timer for 1 sec */
693 ndlp->nlp_last_elscmd = (unsigned long)ELS_CMD_PLOGI;
694 ndlp->nlp_state = NLP_STE_NPR_NODE;
695 lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
697 return (ndlp->nlp_state);
701 lpfc_cmpl_plogi_plogi_issue(struct lpfc_hba * phba,
702 struct lpfc_nodelist * ndlp, void *arg,
705 struct lpfc_iocbq *cmdiocb, *rspiocb;
706 struct lpfc_dmabuf *pcmd, *prsp;
709 struct serv_parm *sp;
712 cmdiocb = (struct lpfc_iocbq *) arg;
713 rspiocb = cmdiocb->context_un.rsp_iocb;
715 if (ndlp->nlp_flag & NLP_ACC_REGLOGIN) {
716 return (ndlp->nlp_state);
719 irsp = &rspiocb->iocb;
724 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
726 prsp = list_get_first(&pcmd->list,
729 lp = (uint32_t *) prsp->virt;
731 sp = (struct serv_parm *) ((uint8_t *) lp + sizeof (uint32_t));
732 if (!lpfc_check_sparm(phba, ndlp, sp, CLASS3))
735 /* PLOGI chkparm OK */
736 lpfc_printf_log(phba,
739 "%d:0121 PLOGI chkparm OK "
740 "Data: x%x x%x x%x x%x\n",
742 ndlp->nlp_DID, ndlp->nlp_state,
743 ndlp->nlp_flag, ndlp->nlp_rpi);
745 if ((phba->cfg_fcp_class == 2) &&
746 (sp->cls2.classValid)) {
747 ndlp->nlp_fcp_info |= CLASS2;
749 ndlp->nlp_fcp_info |= CLASS3;
751 ndlp->nlp_class_sup = 0;
752 if (sp->cls1.classValid)
753 ndlp->nlp_class_sup |= FC_COS_CLASS1;
754 if (sp->cls2.classValid)
755 ndlp->nlp_class_sup |= FC_COS_CLASS2;
756 if (sp->cls3.classValid)
757 ndlp->nlp_class_sup |= FC_COS_CLASS3;
758 if (sp->cls4.classValid)
759 ndlp->nlp_class_sup |= FC_COS_CLASS4;
761 ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) |
762 sp->cmn.bbRcvSizeLsb;
764 if (!(mbox = mempool_alloc(phba->mbox_mem_pool,
768 lpfc_unreg_rpi(phba, ndlp);
770 (phba, irsp->un.elsreq64.remoteID,
771 (uint8_t *) sp, mbox, 0) == 0) {
772 /* set_slim mailbox command needs to
773 * execute first, queue this command to
774 * be processed later.
776 switch(ndlp->nlp_DID) {
779 lpfc_mbx_cmpl_ns_reg_login;
783 lpfc_mbx_cmpl_fdmi_reg_login;
787 lpfc_mbx_cmpl_reg_login;
789 mbox->context2 = ndlp;
790 if (lpfc_sli_issue_mbox(phba, mbox,
791 (MBX_NOWAIT | MBX_STOP_IOCB))
792 != MBX_NOT_FINISHED) {
794 NLP_STE_REG_LOGIN_ISSUE;
795 lpfc_nlp_list(phba, ndlp,
797 return (ndlp->nlp_state);
799 mempool_free(mbox, phba->mbox_mem_pool);
801 mempool_free(mbox, phba->mbox_mem_pool);
806 /* Free this node since the driver cannot login or has the wrong
808 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
809 return (NLP_STE_FREED_NODE);
813 lpfc_device_rm_plogi_issue(struct lpfc_hba * phba,
814 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
816 /* software abort outstanding PLOGI */
817 lpfc_els_abort(phba, ndlp, 1);
819 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
820 return (NLP_STE_FREED_NODE);
824 lpfc_device_recov_plogi_issue(struct lpfc_hba * phba,
825 struct lpfc_nodelist * ndlp, void *arg,
828 /* software abort outstanding PLOGI */
829 lpfc_els_abort(phba, ndlp, 1);
831 ndlp->nlp_state = NLP_STE_NPR_NODE;
832 lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
833 spin_lock_irq(phba->host->host_lock);
834 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
835 spin_unlock_irq(phba->host->host_lock);
837 return (ndlp->nlp_state);
841 lpfc_rcv_plogi_adisc_issue(struct lpfc_hba * phba,
842 struct lpfc_nodelist * ndlp, void *arg,
845 struct lpfc_iocbq *cmdiocb;
847 /* software abort outstanding ADISC */
848 lpfc_els_abort(phba, ndlp, 1);
850 cmdiocb = (struct lpfc_iocbq *) arg;
852 if (lpfc_rcv_plogi(phba, ndlp, cmdiocb)) {
853 return (ndlp->nlp_state);
855 ndlp->nlp_state = NLP_STE_PLOGI_ISSUE;
856 lpfc_nlp_list(phba, ndlp, NLP_PLOGI_LIST);
857 lpfc_issue_els_plogi(phba, ndlp, 0);
859 return (ndlp->nlp_state);
863 lpfc_rcv_prli_adisc_issue(struct lpfc_hba * phba,
864 struct lpfc_nodelist * ndlp, void *arg,
867 struct lpfc_iocbq *cmdiocb;
869 cmdiocb = (struct lpfc_iocbq *) arg;
871 lpfc_els_rsp_prli_acc(phba, cmdiocb, ndlp);
872 return (ndlp->nlp_state);
876 lpfc_rcv_logo_adisc_issue(struct lpfc_hba * phba,
877 struct lpfc_nodelist * ndlp, void *arg,
880 struct lpfc_iocbq *cmdiocb;
882 cmdiocb = (struct lpfc_iocbq *) arg;
884 /* software abort outstanding ADISC */
885 lpfc_els_abort(phba, ndlp, 0);
887 lpfc_rcv_logo(phba, ndlp, cmdiocb);
888 return (ndlp->nlp_state);
892 lpfc_rcv_padisc_adisc_issue(struct lpfc_hba * phba,
893 struct lpfc_nodelist * ndlp, void *arg,
896 struct lpfc_iocbq *cmdiocb;
898 cmdiocb = (struct lpfc_iocbq *) arg;
900 lpfc_rcv_padisc(phba, ndlp, cmdiocb);
901 return (ndlp->nlp_state);
905 lpfc_rcv_prlo_adisc_issue(struct lpfc_hba * phba,
906 struct lpfc_nodelist * ndlp, void *arg,
909 struct lpfc_iocbq *cmdiocb;
911 cmdiocb = (struct lpfc_iocbq *) arg;
913 /* Treat like rcv logo */
914 lpfc_rcv_logo(phba, ndlp, cmdiocb);
915 return (ndlp->nlp_state);
919 lpfc_cmpl_adisc_adisc_issue(struct lpfc_hba * phba,
920 struct lpfc_nodelist * ndlp, void *arg,
923 struct lpfc_iocbq *cmdiocb, *rspiocb;
927 cmdiocb = (struct lpfc_iocbq *) arg;
928 rspiocb = cmdiocb->context_un.rsp_iocb;
930 ap = (ADISC *)lpfc_check_elscmpl_iocb(phba, cmdiocb, rspiocb);
931 irsp = &rspiocb->iocb;
933 if ((irsp->ulpStatus) ||
934 (!lpfc_check_adisc(phba, ndlp, &ap->nodeName, &ap->portName))) {
935 ndlp->nlp_last_elscmd = (unsigned long)ELS_CMD_PLOGI;
937 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ);
938 spin_lock_irq(phba->host->host_lock);
939 ndlp->nlp_flag |= NLP_DELAY_TMO;
940 spin_unlock_irq(phba->host->host_lock);
942 memset(&ndlp->nlp_nodename, 0, sizeof (struct lpfc_name));
943 memset(&ndlp->nlp_portname, 0, sizeof (struct lpfc_name));
945 ndlp->nlp_state = NLP_STE_NPR_NODE;
946 lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
947 lpfc_unreg_rpi(phba, ndlp);
948 return (ndlp->nlp_state);
950 if (ndlp->nlp_type & NLP_FCP_TARGET) {
951 ndlp->nlp_state = NLP_STE_MAPPED_NODE;
952 lpfc_nlp_list(phba, ndlp, NLP_MAPPED_LIST);
954 ndlp->nlp_state = NLP_STE_UNMAPPED_NODE;
955 lpfc_nlp_list(phba, ndlp, NLP_UNMAPPED_LIST);
957 return (ndlp->nlp_state);
961 lpfc_device_rm_adisc_issue(struct lpfc_hba * phba,
962 struct lpfc_nodelist * ndlp, void *arg,
965 /* software abort outstanding ADISC */
966 lpfc_els_abort(phba, ndlp, 1);
968 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
969 return (NLP_STE_FREED_NODE);
973 lpfc_device_recov_adisc_issue(struct lpfc_hba * phba,
974 struct lpfc_nodelist * ndlp, void *arg,
977 /* software abort outstanding ADISC */
978 lpfc_els_abort(phba, ndlp, 1);
980 ndlp->nlp_state = NLP_STE_NPR_NODE;
981 lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
982 spin_lock_irq(phba->host->host_lock);
983 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
984 spin_unlock_irq(phba->host->host_lock);
986 lpfc_disc_set_adisc(phba, ndlp);
987 return (ndlp->nlp_state);
991 lpfc_rcv_plogi_reglogin_issue(struct lpfc_hba * phba,
992 struct lpfc_nodelist * ndlp, void *arg,
995 struct lpfc_iocbq *cmdiocb;
997 cmdiocb = (struct lpfc_iocbq *) arg;
999 lpfc_rcv_plogi(phba, ndlp, cmdiocb);
1000 return (ndlp->nlp_state);
1004 lpfc_rcv_prli_reglogin_issue(struct lpfc_hba * phba,
1005 struct lpfc_nodelist * ndlp, void *arg,
1008 struct lpfc_iocbq *cmdiocb;
1010 cmdiocb = (struct lpfc_iocbq *) arg;
1012 lpfc_els_rsp_prli_acc(phba, cmdiocb, ndlp);
1013 return (ndlp->nlp_state);
1017 lpfc_rcv_logo_reglogin_issue(struct lpfc_hba * phba,
1018 struct lpfc_nodelist * ndlp, void *arg,
1021 struct lpfc_iocbq *cmdiocb;
1023 cmdiocb = (struct lpfc_iocbq *) arg;
1025 lpfc_rcv_logo(phba, ndlp, cmdiocb);
1026 return (ndlp->nlp_state);
1030 lpfc_rcv_padisc_reglogin_issue(struct lpfc_hba * phba,
1031 struct lpfc_nodelist * ndlp, void *arg,
1034 struct lpfc_iocbq *cmdiocb;
1036 cmdiocb = (struct lpfc_iocbq *) arg;
1038 lpfc_rcv_padisc(phba, ndlp, cmdiocb);
1039 return (ndlp->nlp_state);
1043 lpfc_rcv_prlo_reglogin_issue(struct lpfc_hba * phba,
1044 struct lpfc_nodelist * ndlp, void *arg,
1047 struct lpfc_iocbq *cmdiocb;
1049 cmdiocb = (struct lpfc_iocbq *) arg;
1050 lpfc_els_rsp_acc(phba, ELS_CMD_ACC, cmdiocb, ndlp, NULL, 0);
1051 return (ndlp->nlp_state);
1055 lpfc_cmpl_reglogin_reglogin_issue(struct lpfc_hba * phba,
1056 struct lpfc_nodelist * ndlp,
1057 void *arg, uint32_t evt)
1063 pmb = (LPFC_MBOXQ_t *) arg;
1065 did = mb->un.varWords[1];
1066 if (mb->mbxStatus) {
1067 /* RegLogin failed */
1068 lpfc_printf_log(phba,
1071 "%d:0246 RegLogin failed Data: x%x x%x x%x\n",
1073 did, mb->mbxStatus, phba->hba_state);
1075 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ * 1);
1076 spin_lock_irq(phba->host->host_lock);
1077 ndlp->nlp_flag |= NLP_DELAY_TMO;
1078 spin_unlock_irq(phba->host->host_lock);
1080 lpfc_issue_els_logo(phba, ndlp, 0);
1081 /* Put ndlp in npr list set plogi timer for 1 sec */
1082 ndlp->nlp_last_elscmd = (unsigned long)ELS_CMD_PLOGI;
1083 ndlp->nlp_state = NLP_STE_NPR_NODE;
1084 lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
1085 return (ndlp->nlp_state);
1088 if (ndlp->nlp_rpi != 0)
1089 lpfc_findnode_remove_rpi(phba, ndlp->nlp_rpi);
1091 ndlp->nlp_rpi = mb->un.varWords[0];
1092 lpfc_addnode_rpi(phba, ndlp, ndlp->nlp_rpi);
1094 /* Only if we are not a fabric nport do we issue PRLI */
1095 if (!(ndlp->nlp_type & NLP_FABRIC)) {
1096 ndlp->nlp_state = NLP_STE_PRLI_ISSUE;
1097 lpfc_nlp_list(phba, ndlp, NLP_PRLI_LIST);
1098 lpfc_issue_els_prli(phba, ndlp, 0);
1100 ndlp->nlp_state = NLP_STE_UNMAPPED_NODE;
1101 lpfc_nlp_list(phba, ndlp, NLP_UNMAPPED_LIST);
1103 return (ndlp->nlp_state);
1107 lpfc_device_rm_reglogin_issue(struct lpfc_hba * phba,
1108 struct lpfc_nodelist * ndlp, void *arg,
1111 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
1112 return (NLP_STE_FREED_NODE);
1116 lpfc_device_recov_reglogin_issue(struct lpfc_hba * phba,
1117 struct lpfc_nodelist * ndlp, void *arg,
1120 ndlp->nlp_state = NLP_STE_NPR_NODE;
1121 lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
1122 spin_lock_irq(phba->host->host_lock);
1123 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
1124 spin_unlock_irq(phba->host->host_lock);
1125 return (ndlp->nlp_state);
1129 lpfc_rcv_plogi_prli_issue(struct lpfc_hba * phba,
1130 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1132 struct lpfc_iocbq *cmdiocb;
1134 cmdiocb = (struct lpfc_iocbq *) arg;
1136 lpfc_rcv_plogi(phba, ndlp, cmdiocb);
1137 return (ndlp->nlp_state);
1141 lpfc_rcv_prli_prli_issue(struct lpfc_hba * phba,
1142 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1144 struct lpfc_iocbq *cmdiocb;
1146 cmdiocb = (struct lpfc_iocbq *) arg;
1148 lpfc_els_rsp_prli_acc(phba, cmdiocb, ndlp);
1149 return (ndlp->nlp_state);
1153 lpfc_rcv_logo_prli_issue(struct lpfc_hba * phba,
1154 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1156 struct lpfc_iocbq *cmdiocb;
1158 cmdiocb = (struct lpfc_iocbq *) arg;
1160 /* Software abort outstanding PRLI before sending acc */
1161 lpfc_els_abort(phba, ndlp, 1);
1163 lpfc_rcv_logo(phba, ndlp, cmdiocb);
1164 return (ndlp->nlp_state);
1168 lpfc_rcv_padisc_prli_issue(struct lpfc_hba * phba,
1169 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1171 struct lpfc_iocbq *cmdiocb;
1173 cmdiocb = (struct lpfc_iocbq *) arg;
1175 lpfc_rcv_padisc(phba, ndlp, cmdiocb);
1176 return (ndlp->nlp_state);
1179 /* This routine is envoked when we rcv a PRLO request from a nport
1180 * we are logged into. We should send back a PRLO rsp setting the
1182 * NEXT STATE = PRLI_ISSUE
1185 lpfc_rcv_prlo_prli_issue(struct lpfc_hba * phba,
1186 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1188 struct lpfc_iocbq *cmdiocb;
1190 cmdiocb = (struct lpfc_iocbq *) arg;
1191 lpfc_els_rsp_acc(phba, ELS_CMD_ACC, cmdiocb, ndlp, NULL, 0);
1192 return (ndlp->nlp_state);
1196 lpfc_cmpl_prli_prli_issue(struct lpfc_hba * phba,
1197 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1199 struct lpfc_iocbq *cmdiocb, *rspiocb;
1203 cmdiocb = (struct lpfc_iocbq *) arg;
1204 rspiocb = cmdiocb->context_un.rsp_iocb;
1205 npr = (PRLI *)lpfc_check_elscmpl_iocb(phba, cmdiocb, rspiocb);
1207 irsp = &rspiocb->iocb;
1208 if (irsp->ulpStatus) {
1209 ndlp->nlp_state = NLP_STE_UNMAPPED_NODE;
1210 lpfc_nlp_list(phba, ndlp, NLP_UNMAPPED_LIST);
1211 return (ndlp->nlp_state);
1214 /* Check out PRLI rsp */
1215 ndlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR);
1216 ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
1217 if ((npr->acceptRspCode == PRLI_REQ_EXECUTED) &&
1218 (npr->prliType == PRLI_FCP_TYPE)) {
1219 if (npr->initiatorFunc)
1220 ndlp->nlp_type |= NLP_FCP_INITIATOR;
1221 if (npr->targetFunc)
1222 ndlp->nlp_type |= NLP_FCP_TARGET;
1224 ndlp->nlp_fcp_info |= NLP_FCP_2_DEVICE;
1227 ndlp->nlp_state = NLP_STE_MAPPED_NODE;
1228 lpfc_nlp_list(phba, ndlp, NLP_MAPPED_LIST);
1229 return (ndlp->nlp_state);
1232 /*! lpfc_device_rm_prli_issue
1243 * This routine is envoked when we a request to remove a nport we are in the
1244 * process of PRLIing. We should software abort outstanding prli, unreg
1245 * login, send a logout. We will change node state to UNUSED_NODE, put it
1246 * on plogi list so it can be freed when LOGO completes.
1250 lpfc_device_rm_prli_issue(struct lpfc_hba * phba,
1251 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1253 /* software abort outstanding PRLI */
1254 lpfc_els_abort(phba, ndlp, 1);
1256 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
1257 return (NLP_STE_FREED_NODE);
1261 /*! lpfc_device_recov_prli_issue
1272 * The routine is envoked when the state of a device is unknown, like
1273 * during a link down. We should remove the nodelist entry from the
1274 * unmapped list, issue a UNREG_LOGIN, do a software abort of the
1275 * outstanding PRLI command, then free the node entry.
1278 lpfc_device_recov_prli_issue(struct lpfc_hba * phba,
1279 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1281 /* software abort outstanding PRLI */
1282 lpfc_els_abort(phba, ndlp, 1);
1284 ndlp->nlp_state = NLP_STE_NPR_NODE;
1285 lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
1286 spin_lock_irq(phba->host->host_lock);
1287 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
1288 spin_unlock_irq(phba->host->host_lock);
1289 return (ndlp->nlp_state);
1293 lpfc_rcv_plogi_unmap_node(struct lpfc_hba * phba,
1294 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1296 struct lpfc_iocbq *cmdiocb;
1298 cmdiocb = (struct lpfc_iocbq *) arg;
1300 lpfc_rcv_plogi(phba, ndlp, cmdiocb);
1301 return (ndlp->nlp_state);
1305 lpfc_rcv_prli_unmap_node(struct lpfc_hba * phba,
1306 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1308 struct lpfc_iocbq *cmdiocb;
1310 cmdiocb = (struct lpfc_iocbq *) arg;
1312 lpfc_rcv_prli(phba, ndlp, cmdiocb);
1313 lpfc_els_rsp_prli_acc(phba, cmdiocb, ndlp);
1314 return (ndlp->nlp_state);
1318 lpfc_rcv_logo_unmap_node(struct lpfc_hba * phba,
1319 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1321 struct lpfc_iocbq *cmdiocb;
1323 cmdiocb = (struct lpfc_iocbq *) arg;
1325 lpfc_rcv_logo(phba, ndlp, cmdiocb);
1326 return (ndlp->nlp_state);
1330 lpfc_rcv_padisc_unmap_node(struct lpfc_hba * phba,
1331 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1333 struct lpfc_iocbq *cmdiocb;
1335 cmdiocb = (struct lpfc_iocbq *) arg;
1337 lpfc_rcv_padisc(phba, ndlp, cmdiocb);
1338 return (ndlp->nlp_state);
1342 lpfc_rcv_prlo_unmap_node(struct lpfc_hba * phba,
1343 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1345 struct lpfc_iocbq *cmdiocb;
1347 cmdiocb = (struct lpfc_iocbq *) arg;
1349 /* Treat like rcv logo */
1350 lpfc_rcv_logo(phba, ndlp, cmdiocb);
1351 return (ndlp->nlp_state);
1355 lpfc_device_recov_unmap_node(struct lpfc_hba * phba,
1356 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1358 ndlp->nlp_state = NLP_STE_NPR_NODE;
1359 lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
1360 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
1361 lpfc_disc_set_adisc(phba, ndlp);
1363 return (ndlp->nlp_state);
1367 lpfc_rcv_plogi_mapped_node(struct lpfc_hba * phba,
1368 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1370 struct lpfc_iocbq *cmdiocb;
1372 cmdiocb = (struct lpfc_iocbq *) arg;
1374 lpfc_rcv_plogi(phba, ndlp, cmdiocb);
1375 return (ndlp->nlp_state);
1379 lpfc_rcv_prli_mapped_node(struct lpfc_hba * phba,
1380 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1382 struct lpfc_iocbq *cmdiocb;
1384 cmdiocb = (struct lpfc_iocbq *) arg;
1386 lpfc_els_rsp_prli_acc(phba, cmdiocb, ndlp);
1387 return (ndlp->nlp_state);
1391 lpfc_rcv_logo_mapped_node(struct lpfc_hba * phba,
1392 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1394 struct lpfc_iocbq *cmdiocb;
1396 cmdiocb = (struct lpfc_iocbq *) arg;
1398 lpfc_rcv_logo(phba, ndlp, cmdiocb);
1399 return (ndlp->nlp_state);
1403 lpfc_rcv_padisc_mapped_node(struct lpfc_hba * phba,
1404 struct lpfc_nodelist * ndlp, void *arg,
1407 struct lpfc_iocbq *cmdiocb;
1409 cmdiocb = (struct lpfc_iocbq *) arg;
1411 lpfc_rcv_padisc(phba, ndlp, cmdiocb);
1412 return (ndlp->nlp_state);
1416 lpfc_rcv_prlo_mapped_node(struct lpfc_hba * phba,
1417 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1419 struct lpfc_iocbq *cmdiocb;
1421 cmdiocb = (struct lpfc_iocbq *) arg;
1423 /* flush the target */
1424 spin_lock_irq(phba->host->host_lock);
1425 lpfc_sli_abort_iocb(phba, &phba->sli.ring[phba->sli.fcp_ring],
1426 ndlp->nlp_sid, 0, 0, LPFC_CTX_TGT);
1427 spin_unlock_irq(phba->host->host_lock);
1429 /* Treat like rcv logo */
1430 lpfc_rcv_logo(phba, ndlp, cmdiocb);
1431 return (ndlp->nlp_state);
1435 lpfc_device_recov_mapped_node(struct lpfc_hba * phba,
1436 struct lpfc_nodelist * ndlp, void *arg,
1439 ndlp->nlp_state = NLP_STE_NPR_NODE;
1440 lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
1441 spin_lock_irq(phba->host->host_lock);
1442 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
1443 spin_unlock_irq(phba->host->host_lock);
1444 lpfc_disc_set_adisc(phba, ndlp);
1445 return (ndlp->nlp_state);
1449 lpfc_rcv_plogi_npr_node(struct lpfc_hba * phba,
1450 struct lpfc_nodelist * ndlp, void *arg,
1453 struct lpfc_iocbq *cmdiocb;
1455 cmdiocb = (struct lpfc_iocbq *) arg;
1457 /* Ignore PLOGI if we have an outstanding LOGO */
1458 if (ndlp->nlp_flag & NLP_LOGO_SND) {
1459 return (ndlp->nlp_state);
1462 if (lpfc_rcv_plogi(phba, ndlp, cmdiocb)) {
1463 spin_lock_irq(phba->host->host_lock);
1464 ndlp->nlp_flag &= ~(NLP_NPR_ADISC | NLP_NPR_2B_DISC);
1465 spin_unlock_irq(phba->host->host_lock);
1466 return (ndlp->nlp_state);
1469 /* send PLOGI immediately, move to PLOGI issue state */
1470 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
1471 ndlp->nlp_state = NLP_STE_PLOGI_ISSUE;
1472 lpfc_nlp_list(phba, ndlp, NLP_PLOGI_LIST);
1473 lpfc_issue_els_plogi(phba, ndlp, 0);
1475 return (ndlp->nlp_state);
1479 lpfc_rcv_prli_npr_node(struct lpfc_hba * phba,
1480 struct lpfc_nodelist * ndlp, void *arg,
1483 struct lpfc_iocbq *cmdiocb;
1486 cmdiocb = (struct lpfc_iocbq *) arg;
1488 memset(&stat, 0, sizeof (struct ls_rjt));
1489 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
1490 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
1491 lpfc_els_rsp_reject(phba, stat.un.lsRjtError, cmdiocb, ndlp);
1493 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
1494 if (ndlp->nlp_flag & NLP_NPR_ADISC) {
1495 ndlp->nlp_state = NLP_STE_ADISC_ISSUE;
1496 lpfc_nlp_list(phba, ndlp, NLP_ADISC_LIST);
1497 lpfc_issue_els_adisc(phba, ndlp, 0);
1499 ndlp->nlp_state = NLP_STE_PLOGI_ISSUE;
1500 lpfc_nlp_list(phba, ndlp, NLP_PLOGI_LIST);
1501 lpfc_issue_els_plogi(phba, ndlp, 0);
1504 return (ndlp->nlp_state);
1508 lpfc_rcv_logo_npr_node(struct lpfc_hba * phba,
1509 struct lpfc_nodelist * ndlp, void *arg,
1512 struct lpfc_iocbq *cmdiocb;
1514 cmdiocb = (struct lpfc_iocbq *) arg;
1516 lpfc_rcv_logo(phba, ndlp, cmdiocb);
1517 return (ndlp->nlp_state);
1521 lpfc_rcv_padisc_npr_node(struct lpfc_hba * phba,
1522 struct lpfc_nodelist * ndlp, void *arg,
1525 struct lpfc_iocbq *cmdiocb;
1527 cmdiocb = (struct lpfc_iocbq *) arg;
1529 lpfc_rcv_padisc(phba, ndlp, cmdiocb);
1531 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
1532 if (ndlp->nlp_flag & NLP_NPR_ADISC) {
1533 ndlp->nlp_state = NLP_STE_ADISC_ISSUE;
1534 lpfc_nlp_list(phba, ndlp, NLP_ADISC_LIST);
1535 lpfc_issue_els_adisc(phba, ndlp, 0);
1537 ndlp->nlp_state = NLP_STE_PLOGI_ISSUE;
1538 lpfc_nlp_list(phba, ndlp, NLP_PLOGI_LIST);
1539 lpfc_issue_els_plogi(phba, ndlp, 0);
1542 return (ndlp->nlp_state);
1546 lpfc_rcv_prlo_npr_node(struct lpfc_hba * phba,
1547 struct lpfc_nodelist * ndlp, void *arg,
1550 struct lpfc_iocbq *cmdiocb;
1552 cmdiocb = (struct lpfc_iocbq *) arg;
1554 lpfc_els_rsp_acc(phba, ELS_CMD_ACC, cmdiocb, ndlp, NULL, 0);
1556 if (ndlp->nlp_flag & NLP_DELAY_TMO) {
1557 if (ndlp->nlp_last_elscmd == (unsigned long)ELS_CMD_PLOGI) {
1558 return (ndlp->nlp_state);
1560 spin_lock_irq(phba->host->host_lock);
1561 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
1562 spin_unlock_irq(phba->host->host_lock);
1563 del_timer_sync(&ndlp->nlp_delayfunc);
1564 if (!list_empty(&ndlp->els_retry_evt.evt_listp))
1565 list_del_init(&ndlp->els_retry_evt.evt_listp);
1569 ndlp->nlp_state = NLP_STE_PLOGI_ISSUE;
1570 lpfc_nlp_list(phba, ndlp, NLP_PLOGI_LIST);
1571 lpfc_issue_els_plogi(phba, ndlp, 0);
1572 return (ndlp->nlp_state);
1576 lpfc_cmpl_logo_npr_node(struct lpfc_hba * phba,
1577 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1579 lpfc_unreg_rpi(phba, ndlp);
1580 /* This routine does nothing, just return the current state */
1581 return (ndlp->nlp_state);
1585 lpfc_cmpl_reglogin_npr_node(struct lpfc_hba * phba,
1586 struct lpfc_nodelist * ndlp, void *arg,
1592 pmb = (LPFC_MBOXQ_t *) arg;
1596 if (ndlp->nlp_rpi != 0)
1597 lpfc_findnode_remove_rpi(phba, ndlp->nlp_rpi);
1599 ndlp->nlp_rpi = mb->un.varWords[0];
1600 lpfc_addnode_rpi(phba, ndlp, ndlp->nlp_rpi);
1602 return (ndlp->nlp_state);
1606 lpfc_device_rm_npr_node(struct lpfc_hba * phba,
1607 struct lpfc_nodelist * ndlp, void *arg,
1610 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
1611 return (NLP_STE_FREED_NODE);
1615 lpfc_device_recov_npr_node(struct lpfc_hba * phba,
1616 struct lpfc_nodelist * ndlp, void *arg,
1619 spin_lock_irq(phba->host->host_lock);
1620 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
1621 spin_unlock_irq(phba->host->host_lock);
1622 return (ndlp->nlp_state);
1626 /* This next section defines the NPort Discovery State Machine */
1628 /* There are 4 different double linked lists nodelist entries can reside on.
1629 * The plogi list and adisc list are used when Link Up discovery or RSCN
1630 * processing is needed. Each list holds the nodes that we will send PLOGI
1631 * or ADISC on. These lists will keep track of what nodes will be effected
1632 * by an RSCN, or a Link Up (Typically, all nodes are effected on Link Up).
1633 * The unmapped_list will contain all nodes that we have successfully logged
1634 * into at the Fibre Channel level. The mapped_list will contain all nodes
1635 * that are mapped FCP targets.
1638 * The bind list is a list of undiscovered (potentially non-existent) nodes
1639 * that we have saved binding information on. This information is used when
1640 * nodes transition from the unmapped to the mapped list.
1642 /* For UNUSED_NODE state, the node has just been allocated .
1643 * For PLOGI_ISSUE and REG_LOGIN_ISSUE, the node is on
1644 * the PLOGI list. For REG_LOGIN_COMPL, the node is taken off the PLOGI list
1645 * and put on the unmapped list. For ADISC processing, the node is taken off
1646 * the ADISC list and placed on either the mapped or unmapped list (depending
1647 * on its previous state). Once on the unmapped list, a PRLI is issued and the
1648 * state changed to PRLI_ISSUE. When the PRLI completion occurs, the state is
1649 * changed to UNMAPPED_NODE. If the completion indicates a mapped
1650 * node, the node is taken off the unmapped list. The binding list is checked
1651 * for a valid binding, or a binding is automatically assigned. If binding
1652 * assignment is unsuccessful, the node is left on the unmapped list. If
1653 * binding assignment is successful, the associated binding list entry (if
1654 * any) is removed, and the node is placed on the mapped list.
1657 * For a Link Down, all nodes on the ADISC, PLOGI, unmapped or mapped
1658 * lists will receive a DEVICE_RECOVERY event. If the linkdown or nodev timers
1659 * expire, all effected nodes will receive a DEVICE_RM event.
1662 * For a Link Up or RSCN, all nodes will move from the mapped / unmapped lists
1663 * to either the ADISC or PLOGI list. After a Nameserver query or ALPA loopmap
1664 * check, additional nodes may be added or removed (via DEVICE_RM) to / from
1665 * the PLOGI or ADISC lists. Once the PLOGI and ADISC lists are populated,
1666 * we will first process the ADISC list. 32 entries are processed initially and
1667 * ADISC is initited for each one. Completions / Events for each node are
1668 * funnelled thru the state machine. As each node finishes ADISC processing, it
1669 * starts ADISC for any nodes waiting for ADISC processing. If no nodes are
1670 * waiting, and the ADISC list count is identically 0, then we are done. For
1671 * Link Up discovery, since all nodes on the PLOGI list are UNREG_LOGIN'ed, we
1672 * can issue a CLEAR_LA and reenable Link Events. Next we will process the PLOGI
1673 * list. 32 entries are processed initially and PLOGI is initited for each one.
1674 * Completions / Events for each node are funnelled thru the state machine. As
1675 * each node finishes PLOGI processing, it starts PLOGI for any nodes waiting
1676 * for PLOGI processing. If no nodes are waiting, and the PLOGI list count is
1677 * indentically 0, then we are done. We have now completed discovery / RSCN
1678 * handling. Upon completion, ALL nodes should be on either the mapped or
1682 static uint32_t (*lpfc_disc_action[NLP_STE_MAX_STATE * NLP_EVT_MAX_EVENT])
1683 (struct lpfc_hba *, struct lpfc_nodelist *, void *, uint32_t) = {
1684 /* Action routine Event Current State */
1685 lpfc_rcv_plogi_unused_node, /* RCV_PLOGI UNUSED_NODE */
1686 lpfc_rcv_els_unused_node, /* RCV_PRLI */
1687 lpfc_rcv_logo_unused_node, /* RCV_LOGO */
1688 lpfc_rcv_els_unused_node, /* RCV_ADISC */
1689 lpfc_rcv_els_unused_node, /* RCV_PDISC */
1690 lpfc_rcv_els_unused_node, /* RCV_PRLO */
1691 lpfc_disc_illegal, /* CMPL_PLOGI */
1692 lpfc_disc_illegal, /* CMPL_PRLI */
1693 lpfc_cmpl_logo_unused_node, /* CMPL_LOGO */
1694 lpfc_disc_illegal, /* CMPL_ADISC */
1695 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
1696 lpfc_device_rm_unused_node, /* DEVICE_RM */
1697 lpfc_disc_illegal, /* DEVICE_RECOVERY */
1699 lpfc_rcv_plogi_plogi_issue, /* RCV_PLOGI PLOGI_ISSUE */
1700 lpfc_rcv_els_plogi_issue, /* RCV_PRLI */
1701 lpfc_rcv_els_plogi_issue, /* RCV_LOGO */
1702 lpfc_rcv_els_plogi_issue, /* RCV_ADISC */
1703 lpfc_rcv_els_plogi_issue, /* RCV_PDISC */
1704 lpfc_rcv_els_plogi_issue, /* RCV_PRLO */
1705 lpfc_cmpl_plogi_plogi_issue, /* CMPL_PLOGI */
1706 lpfc_disc_illegal, /* CMPL_PRLI */
1707 lpfc_disc_illegal, /* CMPL_LOGO */
1708 lpfc_disc_illegal, /* CMPL_ADISC */
1709 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
1710 lpfc_device_rm_plogi_issue, /* DEVICE_RM */
1711 lpfc_device_recov_plogi_issue, /* DEVICE_RECOVERY */
1713 lpfc_rcv_plogi_adisc_issue, /* RCV_PLOGI ADISC_ISSUE */
1714 lpfc_rcv_prli_adisc_issue, /* RCV_PRLI */
1715 lpfc_rcv_logo_adisc_issue, /* RCV_LOGO */
1716 lpfc_rcv_padisc_adisc_issue, /* RCV_ADISC */
1717 lpfc_rcv_padisc_adisc_issue, /* RCV_PDISC */
1718 lpfc_rcv_prlo_adisc_issue, /* RCV_PRLO */
1719 lpfc_disc_illegal, /* CMPL_PLOGI */
1720 lpfc_disc_illegal, /* CMPL_PRLI */
1721 lpfc_disc_illegal, /* CMPL_LOGO */
1722 lpfc_cmpl_adisc_adisc_issue, /* CMPL_ADISC */
1723 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
1724 lpfc_device_rm_adisc_issue, /* DEVICE_RM */
1725 lpfc_device_recov_adisc_issue, /* DEVICE_RECOVERY */
1727 lpfc_rcv_plogi_reglogin_issue, /* RCV_PLOGI REG_LOGIN_ISSUE */
1728 lpfc_rcv_prli_reglogin_issue, /* RCV_PLOGI */
1729 lpfc_rcv_logo_reglogin_issue, /* RCV_LOGO */
1730 lpfc_rcv_padisc_reglogin_issue, /* RCV_ADISC */
1731 lpfc_rcv_padisc_reglogin_issue, /* RCV_PDISC */
1732 lpfc_rcv_prlo_reglogin_issue, /* RCV_PRLO */
1733 lpfc_disc_illegal, /* CMPL_PLOGI */
1734 lpfc_disc_illegal, /* CMPL_PRLI */
1735 lpfc_disc_illegal, /* CMPL_LOGO */
1736 lpfc_disc_illegal, /* CMPL_ADISC */
1737 lpfc_cmpl_reglogin_reglogin_issue,/* CMPL_REG_LOGIN */
1738 lpfc_device_rm_reglogin_issue, /* DEVICE_RM */
1739 lpfc_device_recov_reglogin_issue,/* DEVICE_RECOVERY */
1741 lpfc_rcv_plogi_prli_issue, /* RCV_PLOGI PRLI_ISSUE */
1742 lpfc_rcv_prli_prli_issue, /* RCV_PRLI */
1743 lpfc_rcv_logo_prli_issue, /* RCV_LOGO */
1744 lpfc_rcv_padisc_prli_issue, /* RCV_ADISC */
1745 lpfc_rcv_padisc_prli_issue, /* RCV_PDISC */
1746 lpfc_rcv_prlo_prli_issue, /* RCV_PRLO */
1747 lpfc_disc_illegal, /* CMPL_PLOGI */
1748 lpfc_cmpl_prli_prli_issue, /* CMPL_PRLI */
1749 lpfc_disc_illegal, /* CMPL_LOGO */
1750 lpfc_disc_illegal, /* CMPL_ADISC */
1751 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
1752 lpfc_device_rm_prli_issue, /* DEVICE_RM */
1753 lpfc_device_recov_prli_issue, /* DEVICE_RECOVERY */
1755 lpfc_rcv_plogi_unmap_node, /* RCV_PLOGI UNMAPPED_NODE */
1756 lpfc_rcv_prli_unmap_node, /* RCV_PRLI */
1757 lpfc_rcv_logo_unmap_node, /* RCV_LOGO */
1758 lpfc_rcv_padisc_unmap_node, /* RCV_ADISC */
1759 lpfc_rcv_padisc_unmap_node, /* RCV_PDISC */
1760 lpfc_rcv_prlo_unmap_node, /* RCV_PRLO */
1761 lpfc_disc_illegal, /* CMPL_PLOGI */
1762 lpfc_disc_illegal, /* CMPL_PRLI */
1763 lpfc_disc_illegal, /* CMPL_LOGO */
1764 lpfc_disc_illegal, /* CMPL_ADISC */
1765 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
1766 lpfc_disc_illegal, /* DEVICE_RM */
1767 lpfc_device_recov_unmap_node, /* DEVICE_RECOVERY */
1769 lpfc_rcv_plogi_mapped_node, /* RCV_PLOGI MAPPED_NODE */
1770 lpfc_rcv_prli_mapped_node, /* RCV_PRLI */
1771 lpfc_rcv_logo_mapped_node, /* RCV_LOGO */
1772 lpfc_rcv_padisc_mapped_node, /* RCV_ADISC */
1773 lpfc_rcv_padisc_mapped_node, /* RCV_PDISC */
1774 lpfc_rcv_prlo_mapped_node, /* RCV_PRLO */
1775 lpfc_disc_illegal, /* CMPL_PLOGI */
1776 lpfc_disc_illegal, /* CMPL_PRLI */
1777 lpfc_disc_illegal, /* CMPL_LOGO */
1778 lpfc_disc_illegal, /* CMPL_ADISC */
1779 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
1780 lpfc_disc_illegal, /* DEVICE_RM */
1781 lpfc_device_recov_mapped_node, /* DEVICE_RECOVERY */
1783 lpfc_rcv_plogi_npr_node, /* RCV_PLOGI NPR_NODE */
1784 lpfc_rcv_prli_npr_node, /* RCV_PRLI */
1785 lpfc_rcv_logo_npr_node, /* RCV_LOGO */
1786 lpfc_rcv_padisc_npr_node, /* RCV_ADISC */
1787 lpfc_rcv_padisc_npr_node, /* RCV_PDISC */
1788 lpfc_rcv_prlo_npr_node, /* RCV_PRLO */
1789 lpfc_disc_noop, /* CMPL_PLOGI */
1790 lpfc_disc_noop, /* CMPL_PRLI */
1791 lpfc_cmpl_logo_npr_node, /* CMPL_LOGO */
1792 lpfc_disc_noop, /* CMPL_ADISC */
1793 lpfc_cmpl_reglogin_npr_node, /* CMPL_REG_LOGIN */
1794 lpfc_device_rm_npr_node, /* DEVICE_RM */
1795 lpfc_device_recov_npr_node, /* DEVICE_RECOVERY */
1799 lpfc_disc_state_machine(struct lpfc_hba * phba,
1800 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1802 uint32_t cur_state, rc;
1803 uint32_t(*func) (struct lpfc_hba *, struct lpfc_nodelist *, void *,
1806 ndlp->nlp_disc_refcnt++;
1807 cur_state = ndlp->nlp_state;
1809 /* DSM in event <evt> on NPort <nlp_DID> in state <cur_state> */
1810 lpfc_printf_log(phba,
1813 "%d:0211 DSM in event x%x on NPort x%x in state %d "
1816 evt, ndlp->nlp_DID, cur_state, ndlp->nlp_flag);
1818 func = lpfc_disc_action[(cur_state * NLP_EVT_MAX_EVENT) + evt];
1819 rc = (func) (phba, ndlp, arg, evt);
1821 /* DSM out state <rc> on NPort <nlp_DID> */
1822 lpfc_printf_log(phba,
1825 "%d:0212 DSM out state %d on NPort x%x Data: x%x\n",
1827 rc, ndlp->nlp_DID, ndlp->nlp_flag);
1829 ndlp->nlp_disc_refcnt--;
1831 /* Check to see if ndlp removal is deferred */
1832 if ((ndlp->nlp_disc_refcnt == 0)
1833 && (ndlp->nlp_flag & NLP_DELAY_REMOVE)) {
1834 spin_lock_irq(phba->host->host_lock);
1835 ndlp->nlp_flag &= ~NLP_DELAY_REMOVE;
1836 spin_unlock_irq(phba->host->host_lock);
1837 lpfc_nlp_remove(phba, ndlp);
1838 return (NLP_STE_FREED_NODE);
1840 if (rc == NLP_STE_FREED_NODE)
1841 return (NLP_STE_FREED_NODE);
1842 ndlp->nlp_state = rc;