1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2004-2007 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"
38 #include "lpfc_vport.h"
41 /* Called to verify a rcv'ed ADISC was intended for us. */
43 lpfc_check_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
44 struct lpfc_name *nn, struct lpfc_name *pn)
46 /* Compare the ADISC rsp WWNN / WWPN matches our internal node
47 * table entry for that node.
49 if (memcmp(nn, &ndlp->nlp_nodename, sizeof (struct lpfc_name)))
52 if (memcmp(pn, &ndlp->nlp_portname, sizeof (struct lpfc_name)))
55 /* we match, return success */
60 lpfc_check_sparm(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
61 struct serv_parm * sp, uint32_t class)
63 volatile struct serv_parm *hsp = &vport->fc_sparam;
64 uint16_t hsp_value, ssp_value = 0;
67 * The receive data field size and buffer-to-buffer receive data field
68 * size entries are 16 bits but are represented as two 8-bit fields in
69 * the driver data structure to account for rsvd bits and other control
70 * bits. Reconstruct and compare the fields as a 16-bit values before
71 * correcting the byte values.
73 if (sp->cls1.classValid) {
74 hsp_value = (hsp->cls1.rcvDataSizeMsb << 8) |
75 hsp->cls1.rcvDataSizeLsb;
76 ssp_value = (sp->cls1.rcvDataSizeMsb << 8) |
77 sp->cls1.rcvDataSizeLsb;
79 goto bad_service_param;
80 if (ssp_value > hsp_value) {
81 sp->cls1.rcvDataSizeLsb = hsp->cls1.rcvDataSizeLsb;
82 sp->cls1.rcvDataSizeMsb = hsp->cls1.rcvDataSizeMsb;
84 } else if (class == CLASS1) {
85 goto bad_service_param;
88 if (sp->cls2.classValid) {
89 hsp_value = (hsp->cls2.rcvDataSizeMsb << 8) |
90 hsp->cls2.rcvDataSizeLsb;
91 ssp_value = (sp->cls2.rcvDataSizeMsb << 8) |
92 sp->cls2.rcvDataSizeLsb;
94 goto bad_service_param;
95 if (ssp_value > hsp_value) {
96 sp->cls2.rcvDataSizeLsb = hsp->cls2.rcvDataSizeLsb;
97 sp->cls2.rcvDataSizeMsb = hsp->cls2.rcvDataSizeMsb;
99 } else if (class == CLASS2) {
100 goto bad_service_param;
103 if (sp->cls3.classValid) {
104 hsp_value = (hsp->cls3.rcvDataSizeMsb << 8) |
105 hsp->cls3.rcvDataSizeLsb;
106 ssp_value = (sp->cls3.rcvDataSizeMsb << 8) |
107 sp->cls3.rcvDataSizeLsb;
109 goto bad_service_param;
110 if (ssp_value > hsp_value) {
111 sp->cls3.rcvDataSizeLsb = hsp->cls3.rcvDataSizeLsb;
112 sp->cls3.rcvDataSizeMsb = hsp->cls3.rcvDataSizeMsb;
114 } else if (class == CLASS3) {
115 goto bad_service_param;
119 * Preserve the upper four bits of the MSB from the PLOGI response.
120 * These bits contain the Buffer-to-Buffer State Change Number
121 * from the target and need to be passed to the FW.
123 hsp_value = (hsp->cmn.bbRcvSizeMsb << 8) | hsp->cmn.bbRcvSizeLsb;
124 ssp_value = (sp->cmn.bbRcvSizeMsb << 8) | sp->cmn.bbRcvSizeLsb;
125 if (ssp_value > hsp_value) {
126 sp->cmn.bbRcvSizeLsb = hsp->cmn.bbRcvSizeLsb;
127 sp->cmn.bbRcvSizeMsb = (sp->cmn.bbRcvSizeMsb & 0xF0) |
128 (hsp->cmn.bbRcvSizeMsb & 0x0F);
131 memcpy(&ndlp->nlp_nodename, &sp->nodeName, sizeof (struct lpfc_name));
132 memcpy(&ndlp->nlp_portname, &sp->portName, sizeof (struct lpfc_name));
135 lpfc_printf_log(vport->phba, KERN_ERR, LOG_DISCOVERY,
136 "%d (%d):0207 Device %x "
137 "(%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x) sent "
138 "invalid service parameters. Ignoring device.\n",
139 vport->phba->brd_no, ndlp->vport->vpi, ndlp->nlp_DID,
140 sp->nodeName.u.wwn[0], sp->nodeName.u.wwn[1],
141 sp->nodeName.u.wwn[2], sp->nodeName.u.wwn[3],
142 sp->nodeName.u.wwn[4], sp->nodeName.u.wwn[5],
143 sp->nodeName.u.wwn[6], sp->nodeName.u.wwn[7]);
148 lpfc_check_elscmpl_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
149 struct lpfc_iocbq *rspiocb)
151 struct lpfc_dmabuf *pcmd, *prsp;
156 irsp = &rspiocb->iocb;
157 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
159 /* For lpfc_els_abort, context2 could be zero'ed to delay
160 * freeing associated memory till after ABTS completes.
163 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf,
166 lp = (uint32_t *) prsp->virt;
167 ptr = (void *)((uint8_t *)lp + sizeof(uint32_t));
170 /* Force ulpStatus error since we are returning NULL ptr */
171 if (!(irsp->ulpStatus)) {
172 irsp->ulpStatus = IOSTAT_LOCAL_REJECT;
173 irsp->un.ulpWord[4] = IOERR_SLI_ABORTED;
182 * Free resources / clean up outstanding I/Os
183 * associated with a LPFC_NODELIST entry. This
184 * routine effectively results in a "software abort".
187 lpfc_els_abort(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp)
189 LIST_HEAD(completions);
190 struct lpfc_sli *psli = &phba->sli;
191 struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING];
192 struct lpfc_iocbq *iocb, *next_iocb;
195 /* Abort outstanding I/O on NPort <nlp_DID> */
196 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
197 "%d (%d):0205 Abort outstanding I/O on NPort x%x "
198 "Data: x%x x%x x%x\n",
199 phba->brd_no, ndlp->vport->vpi, ndlp->nlp_DID,
200 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
202 lpfc_fabric_abort_nport(ndlp);
204 /* First check the txq */
205 spin_lock_irq(&phba->hbalock);
206 list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
207 /* Check to see if iocb matches the nport we are looking
209 if (lpfc_check_sli_ndlp(phba, pring, iocb, ndlp)) {
210 /* It matches, so deque and call compl with an
212 list_move_tail(&iocb->list, &completions);
217 /* Next check the txcmplq */
218 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
219 /* Check to see if iocb matches the nport we are looking
221 if (lpfc_check_sli_ndlp(phba, pring, iocb, ndlp)) {
222 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
225 spin_unlock_irq(&phba->hbalock);
227 while (!list_empty(&completions)) {
228 iocb = list_get_first(&completions, struct lpfc_iocbq, list);
230 list_del_init(&iocb->list);
232 if (!iocb->iocb_cmpl)
233 lpfc_sli_release_iocbq(phba, iocb);
235 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
236 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
237 (iocb->iocb_cmpl) (phba, iocb, iocb);
241 /* If we are delaying issuing an ELS command, cancel it */
242 if (ndlp->nlp_flag & NLP_DELAY_TMO)
243 lpfc_cancel_retry_delay_tmo(phba->pport, ndlp);
248 lpfc_rcv_plogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
249 struct lpfc_iocbq *cmdiocb)
251 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
252 struct lpfc_hba *phba = vport->phba;
253 struct lpfc_dmabuf *pcmd;
256 struct serv_parm *sp;
261 memset(&stat, 0, sizeof (struct ls_rjt));
262 if (vport->port_state <= LPFC_FLOGI) {
263 /* Before responding to PLOGI, check for pt2pt mode.
264 * If we are pt2pt, with an outstanding FLOGI, abort
265 * the FLOGI and resend it first.
267 if (vport->fc_flag & FC_PT2PT) {
268 lpfc_els_abort_flogi(phba);
269 if (!(vport->fc_flag & FC_PT2PT_PLOGI)) {
270 /* If the other side is supposed to initiate
271 * the PLOGI anyway, just ACC it now and
272 * move on with discovery.
274 phba->fc_edtov = FF_DEF_EDTOV;
275 phba->fc_ratov = FF_DEF_RATOV;
276 /* Start discovery - this should just do
278 lpfc_disc_start(vport);
280 lpfc_initial_flogi(vport);
282 stat.un.b.lsRjtRsnCode = LSRJT_LOGICAL_BSY;
283 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
284 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb,
289 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
290 lp = (uint32_t *) pcmd->virt;
291 sp = (struct serv_parm *) ((uint8_t *) lp + sizeof (uint32_t));
292 if ((lpfc_check_sparm(vport, ndlp, sp, CLASS3) == 0)) {
293 /* Reject this request because invalid parameters */
294 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
295 stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
296 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp);
299 icmd = &cmdiocb->iocb;
301 /* PLOGI chkparm OK */
302 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
303 "%d (%d):0114 PLOGI chkparm OK Data: x%x x%x x%x x%x\n",
304 phba->brd_no, vport->vpi,
305 ndlp->nlp_DID, ndlp->nlp_state, ndlp->nlp_flag,
308 if (phba->cfg_fcp_class == 2 && sp->cls2.classValid)
309 ndlp->nlp_fcp_info |= CLASS2;
311 ndlp->nlp_fcp_info |= CLASS3;
313 ndlp->nlp_class_sup = 0;
314 if (sp->cls1.classValid)
315 ndlp->nlp_class_sup |= FC_COS_CLASS1;
316 if (sp->cls2.classValid)
317 ndlp->nlp_class_sup |= FC_COS_CLASS2;
318 if (sp->cls3.classValid)
319 ndlp->nlp_class_sup |= FC_COS_CLASS3;
320 if (sp->cls4.classValid)
321 ndlp->nlp_class_sup |= FC_COS_CLASS4;
323 ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) | sp->cmn.bbRcvSizeLsb;
325 /* no need to reg_login if we are already in one of these states */
326 switch (ndlp->nlp_state) {
327 case NLP_STE_NPR_NODE:
328 if (!(ndlp->nlp_flag & NLP_NPR_ADISC))
330 case NLP_STE_REG_LOGIN_ISSUE:
331 case NLP_STE_PRLI_ISSUE:
332 case NLP_STE_UNMAPPED_NODE:
333 case NLP_STE_MAPPED_NODE:
334 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp, NULL, 0);
338 if ((vport->fc_flag & FC_PT2PT) &&
339 !(vport->fc_flag & FC_PT2PT_PLOGI)) {
340 /* rcv'ed PLOGI decides what our NPortId will be */
341 vport->fc_myDID = icmd->un.rcvels.parmRo;
342 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
345 lpfc_config_link(phba, mbox);
346 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
348 rc = lpfc_sli_issue_mbox
349 (phba, mbox, (MBX_NOWAIT | MBX_STOP_IOCB));
350 if (rc == MBX_NOT_FINISHED) {
351 mempool_free(mbox, phba->mbox_mem_pool);
355 lpfc_can_disctmo(vport);
357 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
361 rc = lpfc_reg_login(phba, vport->vpi, icmd->un.rcvels.remoteID,
362 (uint8_t *) sp, mbox, 0);
364 mempool_free(mbox, phba->mbox_mem_pool);
368 /* ACC PLOGI rsp command needs to execute first,
369 * queue this mbox command to be processed later.
371 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
373 * mbox->context2 = lpfc_nlp_get(ndlp) deferred until mailbox
374 * command issued in lpfc_cmpl_els_acc().
377 spin_lock_irq(shost->host_lock);
378 ndlp->nlp_flag |= (NLP_ACC_REGLOGIN | NLP_RCV_PLOGI);
379 spin_unlock_irq(shost->host_lock);
382 * If there is an outstanding PLOGI issued, abort it before
383 * sending ACC rsp for received PLOGI. If pending plogi
384 * is not canceled here, the plogi will be rejected by
385 * remote port and will be retried. On a configuration with
386 * single discovery thread, this will cause a huge delay in
387 * discovery. Also this will cause multiple state machines
388 * running in parallel for this node.
390 if (ndlp->nlp_state == NLP_STE_PLOGI_ISSUE) {
391 /* software abort outstanding PLOGI */
392 lpfc_els_abort(phba, ndlp);
395 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp, mbox, 0);
399 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
400 stat.un.b.lsRjtRsnCodeExp = LSEXP_OUT_OF_RESOURCE;
401 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp);
406 lpfc_rcv_padisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
407 struct lpfc_iocbq *cmdiocb)
409 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
410 struct lpfc_dmabuf *pcmd;
411 struct serv_parm *sp;
412 struct lpfc_name *pnn, *ppn;
419 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
420 lp = (uint32_t *) pcmd->virt;
423 if (cmd == ELS_CMD_ADISC) {
425 pnn = (struct lpfc_name *) & ap->nodeName;
426 ppn = (struct lpfc_name *) & ap->portName;
428 sp = (struct serv_parm *) lp;
429 pnn = (struct lpfc_name *) & sp->nodeName;
430 ppn = (struct lpfc_name *) & sp->portName;
433 icmd = &cmdiocb->iocb;
434 if (icmd->ulpStatus == 0 && lpfc_check_adisc(vport, ndlp, pnn, ppn)) {
435 if (cmd == ELS_CMD_ADISC) {
436 lpfc_els_rsp_adisc_acc(vport, cmdiocb, ndlp);
438 lpfc_els_rsp_acc(vport, 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(vport, stat.un.lsRjtError, cmdiocb, ndlp);
451 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ);
453 spin_lock_irq(shost->host_lock);
454 ndlp->nlp_flag |= NLP_DELAY_TMO;
455 spin_unlock_irq(shost->host_lock);
456 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
457 ndlp->nlp_prev_state = ndlp->nlp_state;
458 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
463 lpfc_rcv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
464 struct lpfc_iocbq *cmdiocb, uint32_t els_cmd)
466 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
468 /* Put ndlp in NPR state with 1 sec timeout for plogi, ACC logo */
469 /* Only call LOGO ACC for first LOGO, this avoids sending unnecessary
470 * PLOGIs during LOGO storms from a device.
472 spin_lock_irq(shost->host_lock);
473 ndlp->nlp_flag |= NLP_LOGO_ACC;
474 spin_unlock_irq(shost->host_lock);
475 if (els_cmd == ELS_CMD_PRLO)
476 lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL, 0);
478 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL, 0);
480 if (!(ndlp->nlp_type & NLP_FABRIC) ||
481 (ndlp->nlp_state == NLP_STE_ADISC_ISSUE)) {
482 /* Only try to re-login if this is NOT a Fabric Node */
483 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ * 1);
484 spin_lock_irq(shost->host_lock);
485 ndlp->nlp_flag |= NLP_DELAY_TMO;
486 spin_unlock_irq(shost->host_lock);
488 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
489 ndlp->nlp_prev_state = ndlp->nlp_state;
490 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
492 ndlp->nlp_prev_state = ndlp->nlp_state;
493 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNUSED_NODE);
496 spin_lock_irq(shost->host_lock);
497 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
498 spin_unlock_irq(shost->host_lock);
499 /* The driver has to wait until the ACC completes before it continues
500 * processing the LOGO. The action will resume in
501 * lpfc_cmpl_els_logo_acc routine. Since part of processing includes an
502 * unreg_login, the driver waits so the ACC does not get aborted.
508 lpfc_rcv_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
509 struct lpfc_iocbq *cmdiocb)
511 struct lpfc_dmabuf *pcmd;
514 struct fc_rport *rport = ndlp->rport;
517 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
518 lp = (uint32_t *) pcmd->virt;
519 npr = (PRLI *) ((uint8_t *) lp + sizeof (uint32_t));
521 ndlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR);
522 ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
523 if (npr->prliType == PRLI_FCP_TYPE) {
524 if (npr->initiatorFunc)
525 ndlp->nlp_type |= NLP_FCP_INITIATOR;
527 ndlp->nlp_type |= NLP_FCP_TARGET;
529 ndlp->nlp_fcp_info |= NLP_FCP_2_DEVICE;
532 /* We need to update the rport role values */
533 roles = FC_RPORT_ROLE_UNKNOWN;
534 if (ndlp->nlp_type & NLP_FCP_INITIATOR)
535 roles |= FC_RPORT_ROLE_FCP_INITIATOR;
536 if (ndlp->nlp_type & NLP_FCP_TARGET)
537 roles |= FC_RPORT_ROLE_FCP_TARGET;
538 fc_remote_port_rolechg(rport, roles);
543 lpfc_disc_set_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
545 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
546 struct lpfc_hba *phba = vport->phba;
548 /* Check config parameter use-adisc or FCP-2 */
549 if ((phba->cfg_use_adisc && (vport->fc_flag & FC_RSCN_MODE)) ||
550 ndlp->nlp_fcp_info & NLP_FCP_2_DEVICE) {
551 spin_lock_irq(shost->host_lock);
552 ndlp->nlp_flag |= NLP_NPR_ADISC;
553 spin_unlock_irq(shost->host_lock);
556 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
557 lpfc_unreg_rpi(vport, ndlp);
562 lpfc_disc_illegal(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
563 void *arg, uint32_t evt)
565 lpfc_printf_log(vport->phba, KERN_ERR, LOG_DISCOVERY,
566 "%d (%d):0253 Illegal State Transition: node x%x "
567 "event x%x, state x%x Data: x%x x%x\n",
568 vport->phba->brd_no, vport->vpi,
569 ndlp->nlp_DID, evt, ndlp->nlp_state, ndlp->nlp_rpi,
571 return ndlp->nlp_state;
574 /* Start of Discovery State Machine routines */
577 lpfc_rcv_plogi_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
578 void *arg, uint32_t evt)
580 struct lpfc_iocbq *cmdiocb;
582 cmdiocb = (struct lpfc_iocbq *) arg;
584 if (lpfc_rcv_plogi(vport, ndlp, cmdiocb)) {
585 ndlp->nlp_prev_state = NLP_STE_UNUSED_NODE;
586 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNUSED_NODE);
587 return ndlp->nlp_state;
589 lpfc_drop_node(vport, ndlp);
590 return NLP_STE_FREED_NODE;
594 lpfc_rcv_els_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
595 void *arg, uint32_t evt)
597 lpfc_issue_els_logo(vport, ndlp, 0);
598 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNUSED_NODE);
599 return ndlp->nlp_state;
603 lpfc_rcv_logo_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
604 void *arg, uint32_t evt)
606 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
607 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
609 spin_lock_irq(shost->host_lock);
610 ndlp->nlp_flag |= NLP_LOGO_ACC;
611 spin_unlock_irq(shost->host_lock);
612 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL, 0);
613 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNUSED_NODE);
615 return ndlp->nlp_state;
619 lpfc_cmpl_logo_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
620 void *arg, uint32_t evt)
622 lpfc_drop_node(vport, ndlp);
623 return NLP_STE_FREED_NODE;
627 lpfc_device_rm_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
628 void *arg, uint32_t evt)
630 lpfc_drop_node(vport, ndlp);
631 return NLP_STE_FREED_NODE;
635 lpfc_rcv_plogi_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
636 void *arg, uint32_t evt)
638 struct lpfc_hba *phba = vport->phba;
639 struct lpfc_iocbq *cmdiocb = arg;
640 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
641 uint32_t *lp = (uint32_t *) pcmd->virt;
642 struct serv_parm *sp = (struct serv_parm *) (lp + 1);
646 memset(&stat, 0, sizeof (struct ls_rjt));
648 /* For a PLOGI, we only accept if our portname is less
649 * than the remote portname.
651 phba->fc_stat.elsLogiCol++;
652 port_cmp = memcmp(&vport->fc_portname, &sp->portName,
653 sizeof(struct lpfc_name));
656 /* Reject this request because the remote node will accept
658 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
659 stat.un.b.lsRjtRsnCodeExp = LSEXP_CMD_IN_PROGRESS;
660 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp);
662 lpfc_rcv_plogi(vport, ndlp, cmdiocb);
663 } /* If our portname was less */
665 return ndlp->nlp_state;
669 lpfc_rcv_prli_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
670 void *arg, uint32_t evt)
672 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
675 memset(&stat, 0, sizeof (struct ls_rjt));
676 stat.un.b.lsRjtRsnCode = LSRJT_LOGICAL_BSY;
677 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
678 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp);
679 return ndlp->nlp_state;
683 lpfc_rcv_logo_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
684 void *arg, uint32_t evt)
686 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
688 /* software abort outstanding PLOGI */
689 lpfc_els_abort(vport->phba, ndlp);
691 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
692 return ndlp->nlp_state;
696 lpfc_rcv_els_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
697 void *arg, uint32_t evt)
699 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
700 struct lpfc_hba *phba = vport->phba;
701 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
703 /* software abort outstanding PLOGI */
704 lpfc_els_abort(phba, ndlp);
706 if (evt == NLP_EVT_RCV_LOGO) {
707 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL, 0);
709 lpfc_issue_els_logo(vport, ndlp, 0);
712 /* Put ndlp in npr state set plogi timer for 1 sec */
713 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ * 1);
714 spin_lock_irq(shost->host_lock);
715 ndlp->nlp_flag |= NLP_DELAY_TMO;
716 spin_unlock_irq(shost->host_lock);
717 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
718 ndlp->nlp_prev_state = NLP_STE_PLOGI_ISSUE;
719 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
721 return ndlp->nlp_state;
725 lpfc_cmpl_plogi_plogi_issue(struct lpfc_vport *vport,
726 struct lpfc_nodelist *ndlp,
730 struct lpfc_hba *phba = vport->phba;
731 struct lpfc_iocbq *cmdiocb, *rspiocb;
732 struct lpfc_dmabuf *pcmd, *prsp, *mp;
735 struct serv_parm *sp;
738 cmdiocb = (struct lpfc_iocbq *) arg;
739 rspiocb = cmdiocb->context_un.rsp_iocb;
741 if (ndlp->nlp_flag & NLP_ACC_REGLOGIN) {
742 /* Recovery from PLOGI collision logic */
743 return ndlp->nlp_state;
746 irsp = &rspiocb->iocb;
751 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
753 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
755 lp = (uint32_t *) prsp->virt;
756 sp = (struct serv_parm *) ((uint8_t *) lp + sizeof (uint32_t));
757 if (!lpfc_check_sparm(vport, ndlp, sp, CLASS3))
760 /* PLOGI chkparm OK */
761 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
762 "%d (%d):0121 PLOGI chkparm OK "
763 "Data: x%x x%x x%x x%x\n",
764 phba->brd_no, vport->vpi,
765 ndlp->nlp_DID, ndlp->nlp_state,
766 ndlp->nlp_flag, ndlp->nlp_rpi);
768 if (phba->cfg_fcp_class == 2 && (sp->cls2.classValid))
769 ndlp->nlp_fcp_info |= CLASS2;
771 ndlp->nlp_fcp_info |= CLASS3;
773 ndlp->nlp_class_sup = 0;
774 if (sp->cls1.classValid)
775 ndlp->nlp_class_sup |= FC_COS_CLASS1;
776 if (sp->cls2.classValid)
777 ndlp->nlp_class_sup |= FC_COS_CLASS2;
778 if (sp->cls3.classValid)
779 ndlp->nlp_class_sup |= FC_COS_CLASS3;
780 if (sp->cls4.classValid)
781 ndlp->nlp_class_sup |= FC_COS_CLASS4;
783 ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) | sp->cmn.bbRcvSizeLsb;
785 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
787 lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
788 "%d (%d):0133 PLOGI: no memory for reg_login "
789 "Data: x%x x%x x%x x%x\n",
790 phba->brd_no, vport->vpi,
791 ndlp->nlp_DID, ndlp->nlp_state,
792 ndlp->nlp_flag, ndlp->nlp_rpi);
796 lpfc_unreg_rpi(vport, ndlp);
798 if (lpfc_reg_login(phba, vport->vpi, irsp->un.elsreq64.remoteID,
799 (uint8_t *) sp, mbox, 0) == 0) {
800 switch (ndlp->nlp_DID) {
802 mbox->mbox_cmpl = lpfc_mbx_cmpl_ns_reg_login;
805 mbox->mbox_cmpl = lpfc_mbx_cmpl_fdmi_reg_login;
808 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
810 mbox->context2 = lpfc_nlp_get(ndlp);
812 if (lpfc_sli_issue_mbox(phba, mbox,
813 (MBX_NOWAIT | MBX_STOP_IOCB))
814 != MBX_NOT_FINISHED) {
815 lpfc_nlp_set_state(vport, ndlp,
816 NLP_STE_REG_LOGIN_ISSUE);
817 return ndlp->nlp_state;
820 mp = (struct lpfc_dmabuf *) mbox->context1;
821 lpfc_mbuf_free(phba, mp->virt, mp->phys);
823 mempool_free(mbox, phba->mbox_mem_pool);
825 lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
826 "%d (%d):0134 PLOGI: cannot issue reg_login "
827 "Data: x%x x%x x%x x%x\n",
828 phba->brd_no, vport->vpi,
829 ndlp->nlp_DID, ndlp->nlp_state,
830 ndlp->nlp_flag, ndlp->nlp_rpi);
832 mempool_free(mbox, phba->mbox_mem_pool);
834 lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
835 "%d (%d):0135 PLOGI: cannot format reg_login "
836 "Data: x%x x%x x%x x%x\n",
837 phba->brd_no, vport->vpi,
838 ndlp->nlp_DID, ndlp->nlp_state,
839 ndlp->nlp_flag, ndlp->nlp_rpi);
844 if (ndlp->nlp_DID == NameServer_DID) {
845 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
846 lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
847 "%d (%d):0261 Cannot Register NameServer login\n",
848 phba->brd_no, vport->vpi);
851 /* Free this node since the driver cannot login or has the wrong
853 lpfc_drop_node(vport, ndlp);
854 return NLP_STE_FREED_NODE;
858 lpfc_device_rm_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
859 void *arg, uint32_t evt)
861 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
863 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
864 spin_lock_irq(shost->host_lock);
865 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
866 spin_unlock_irq(shost->host_lock);
867 return ndlp->nlp_state;
869 /* software abort outstanding PLOGI */
870 lpfc_els_abort(vport->phba, ndlp);
872 lpfc_drop_node(vport, ndlp);
873 return NLP_STE_FREED_NODE;
878 lpfc_device_recov_plogi_issue(struct lpfc_vport *vport,
879 struct lpfc_nodelist *ndlp,
883 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
884 struct lpfc_hba *phba = vport->phba;
886 /* Don't do anything that will mess up processing of the
889 if (vport->fc_flag & FC_RSCN_DEFERRED)
890 return ndlp->nlp_state;
892 /* software abort outstanding PLOGI */
893 lpfc_els_abort(phba, ndlp);
895 ndlp->nlp_prev_state = NLP_STE_PLOGI_ISSUE;
896 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
897 spin_lock_irq(shost->host_lock);
898 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
899 spin_unlock_irq(shost->host_lock);
901 return ndlp->nlp_state;
905 lpfc_rcv_plogi_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
906 void *arg, uint32_t evt)
908 struct lpfc_hba *phba = vport->phba;
909 struct lpfc_iocbq *cmdiocb;
911 /* software abort outstanding ADISC */
912 lpfc_els_abort(phba, ndlp);
914 cmdiocb = (struct lpfc_iocbq *) arg;
916 if (lpfc_rcv_plogi(vport, ndlp, cmdiocb))
917 return ndlp->nlp_state;
919 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
920 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
921 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
923 return ndlp->nlp_state;
927 lpfc_rcv_prli_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
928 void *arg, uint32_t evt)
930 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
932 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
933 return ndlp->nlp_state;
937 lpfc_rcv_logo_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
938 void *arg, uint32_t evt)
940 struct lpfc_hba *phba = vport->phba;
941 struct lpfc_iocbq *cmdiocb;
943 cmdiocb = (struct lpfc_iocbq *) arg;
945 /* software abort outstanding ADISC */
946 lpfc_els_abort(phba, ndlp);
948 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
949 return ndlp->nlp_state;
953 lpfc_rcv_padisc_adisc_issue(struct lpfc_vport *vport,
954 struct lpfc_nodelist *ndlp,
955 void *arg, uint32_t evt)
957 struct lpfc_iocbq *cmdiocb;
959 cmdiocb = (struct lpfc_iocbq *) arg;
961 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
962 return ndlp->nlp_state;
966 lpfc_rcv_prlo_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
967 void *arg, uint32_t evt)
969 struct lpfc_iocbq *cmdiocb;
971 cmdiocb = (struct lpfc_iocbq *) arg;
973 /* Treat like rcv logo */
974 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_PRLO);
975 return ndlp->nlp_state;
979 lpfc_cmpl_adisc_adisc_issue(struct lpfc_vport *vport,
980 struct lpfc_nodelist *ndlp,
981 void *arg, uint32_t evt)
983 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
984 struct lpfc_hba *phba = vport->phba;
985 struct lpfc_iocbq *cmdiocb, *rspiocb;
989 cmdiocb = (struct lpfc_iocbq *) arg;
990 rspiocb = cmdiocb->context_un.rsp_iocb;
992 ap = (ADISC *)lpfc_check_elscmpl_iocb(phba, cmdiocb, rspiocb);
993 irsp = &rspiocb->iocb;
995 if ((irsp->ulpStatus) ||
996 (!lpfc_check_adisc(vport, ndlp, &ap->nodeName, &ap->portName))) {
998 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ);
999 spin_lock_irq(shost->host_lock);
1000 ndlp->nlp_flag |= NLP_DELAY_TMO;
1001 spin_unlock_irq(shost->host_lock);
1002 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
1004 memset(&ndlp->nlp_nodename, 0, sizeof(struct lpfc_name));
1005 memset(&ndlp->nlp_portname, 0, sizeof(struct lpfc_name));
1007 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
1008 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1009 lpfc_unreg_rpi(vport, ndlp);
1010 return ndlp->nlp_state;
1013 if (ndlp->nlp_type & NLP_FCP_TARGET) {
1014 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
1015 lpfc_nlp_set_state(vport, ndlp, NLP_STE_MAPPED_NODE);
1017 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
1018 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
1020 return ndlp->nlp_state;
1024 lpfc_device_rm_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1025 void *arg, uint32_t evt)
1027 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1029 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1030 spin_lock_irq(shost->host_lock);
1031 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
1032 spin_unlock_irq(shost->host_lock);
1033 return ndlp->nlp_state;
1035 /* software abort outstanding ADISC */
1036 lpfc_els_abort(vport->phba, ndlp);
1038 lpfc_drop_node(vport, ndlp);
1039 return NLP_STE_FREED_NODE;
1044 lpfc_device_recov_adisc_issue(struct lpfc_vport *vport,
1045 struct lpfc_nodelist *ndlp,
1049 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1050 struct lpfc_hba *phba = vport->phba;
1052 /* Don't do anything that will mess up processing of the
1055 if (vport->fc_flag & FC_RSCN_DEFERRED)
1056 return ndlp->nlp_state;
1058 /* software abort outstanding ADISC */
1059 lpfc_els_abort(phba, ndlp);
1061 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
1062 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1063 spin_lock_irq(shost->host_lock);
1064 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
1065 spin_unlock_irq(shost->host_lock);
1066 lpfc_disc_set_adisc(vport, ndlp);
1067 return ndlp->nlp_state;
1071 lpfc_rcv_plogi_reglogin_issue(struct lpfc_vport *vport,
1072 struct lpfc_nodelist *ndlp,
1076 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1078 lpfc_rcv_plogi(vport, ndlp, cmdiocb);
1079 return ndlp->nlp_state;
1083 lpfc_rcv_prli_reglogin_issue(struct lpfc_vport *vport,
1084 struct lpfc_nodelist *ndlp,
1088 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1090 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
1091 return ndlp->nlp_state;
1095 lpfc_rcv_logo_reglogin_issue(struct lpfc_vport *vport,
1096 struct lpfc_nodelist *ndlp,
1100 struct lpfc_hba *phba = vport->phba;
1101 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1103 LPFC_MBOXQ_t *nextmb;
1104 struct lpfc_dmabuf *mp;
1106 cmdiocb = (struct lpfc_iocbq *) arg;
1108 /* cleanup any ndlp on mbox q waiting for reglogin cmpl */
1109 if ((mb = phba->sli.mbox_active)) {
1110 if ((mb->mb.mbxCommand == MBX_REG_LOGIN64) &&
1111 (ndlp == (struct lpfc_nodelist *) mb->context2)) {
1113 mb->context2 = NULL;
1114 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1118 spin_lock_irq(&phba->hbalock);
1119 list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) {
1120 if ((mb->mb.mbxCommand == MBX_REG_LOGIN64) &&
1121 (ndlp == (struct lpfc_nodelist *) mb->context2)) {
1122 mp = (struct lpfc_dmabuf *) (mb->context1);
1124 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1128 list_del(&mb->list);
1129 mempool_free(mb, phba->mbox_mem_pool);
1132 spin_unlock_irq(&phba->hbalock);
1134 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
1135 return ndlp->nlp_state;
1139 lpfc_rcv_padisc_reglogin_issue(struct lpfc_vport *vport,
1140 struct lpfc_nodelist *ndlp,
1144 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1146 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
1147 return ndlp->nlp_state;
1151 lpfc_rcv_prlo_reglogin_issue(struct lpfc_vport *vport,
1152 struct lpfc_nodelist *ndlp,
1156 struct lpfc_iocbq *cmdiocb;
1158 cmdiocb = (struct lpfc_iocbq *) arg;
1159 lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL, 0);
1160 return ndlp->nlp_state;
1164 lpfc_cmpl_reglogin_reglogin_issue(struct lpfc_vport *vport,
1165 struct lpfc_nodelist *ndlp,
1169 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1170 struct lpfc_hba *phba = vport->phba;
1171 LPFC_MBOXQ_t *pmb = (LPFC_MBOXQ_t *) arg;
1172 MAILBOX_t *mb = &pmb->mb;
1173 uint32_t did = mb->un.varWords[1];
1175 if (mb->mbxStatus) {
1176 /* RegLogin failed */
1177 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
1178 "%d (%d):0246 RegLogin failed Data: x%x x%x "
1180 phba->brd_no, vport->vpi,
1181 did, mb->mbxStatus, vport->port_state);
1184 * If RegLogin failed due to lack of HBA resources do not
1187 if (mb->mbxStatus == MBXERR_RPI_FULL) {
1188 ndlp->nlp_prev_state = NLP_STE_UNUSED_NODE;
1189 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNUSED_NODE);
1190 return ndlp->nlp_state;
1193 /* Put ndlp in npr state set plogi timer for 1 sec */
1194 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ * 1);
1195 spin_lock_irq(shost->host_lock);
1196 ndlp->nlp_flag |= NLP_DELAY_TMO;
1197 spin_unlock_irq(shost->host_lock);
1198 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
1200 lpfc_issue_els_logo(vport, ndlp, 0);
1201 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
1202 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1203 return ndlp->nlp_state;
1206 ndlp->nlp_rpi = mb->un.varWords[0];
1208 /* Only if we are not a fabric nport do we issue PRLI */
1209 if (!(ndlp->nlp_type & NLP_FABRIC)) {
1210 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
1211 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
1212 lpfc_issue_els_prli(vport, ndlp, 0);
1214 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
1215 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
1217 return ndlp->nlp_state;
1221 lpfc_device_rm_reglogin_issue(struct lpfc_vport *vport,
1222 struct lpfc_nodelist *ndlp,
1226 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1228 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1229 spin_lock_irq(shost->host_lock);
1230 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
1231 spin_unlock_irq(shost->host_lock);
1232 return ndlp->nlp_state;
1234 lpfc_drop_node(vport, ndlp);
1235 return NLP_STE_FREED_NODE;
1240 lpfc_device_recov_reglogin_issue(struct lpfc_vport *vport,
1241 struct lpfc_nodelist *ndlp,
1245 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1247 /* Don't do anything that will mess up processing of the
1250 if (vport->fc_flag & FC_RSCN_DEFERRED)
1251 return ndlp->nlp_state;
1253 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
1254 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1255 spin_lock_irq(shost->host_lock);
1256 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
1257 spin_unlock_irq(shost->host_lock);
1258 lpfc_disc_set_adisc(vport, ndlp);
1259 return ndlp->nlp_state;
1263 lpfc_rcv_plogi_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1264 void *arg, uint32_t evt)
1266 struct lpfc_iocbq *cmdiocb;
1268 cmdiocb = (struct lpfc_iocbq *) arg;
1270 lpfc_rcv_plogi(vport, ndlp, cmdiocb);
1271 return ndlp->nlp_state;
1275 lpfc_rcv_prli_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1276 void *arg, uint32_t evt)
1278 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1280 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
1281 return ndlp->nlp_state;
1285 lpfc_rcv_logo_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1286 void *arg, uint32_t evt)
1288 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1290 /* Software abort outstanding PRLI before sending acc */
1291 lpfc_els_abort(vport->phba, ndlp);
1293 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
1294 return ndlp->nlp_state;
1298 lpfc_rcv_padisc_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1299 void *arg, uint32_t evt)
1301 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1303 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
1304 return ndlp->nlp_state;
1307 /* This routine is envoked when we rcv a PRLO request from a nport
1308 * we are logged into. We should send back a PRLO rsp setting the
1310 * NEXT STATE = PRLI_ISSUE
1313 lpfc_rcv_prlo_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1314 void *arg, uint32_t evt)
1316 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1318 lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL, 0);
1319 return ndlp->nlp_state;
1323 lpfc_cmpl_prli_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1324 void *arg, uint32_t evt)
1326 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1327 struct lpfc_iocbq *cmdiocb, *rspiocb;
1328 struct lpfc_hba *phba = vport->phba;
1332 cmdiocb = (struct lpfc_iocbq *) arg;
1333 rspiocb = cmdiocb->context_un.rsp_iocb;
1334 npr = (PRLI *)lpfc_check_elscmpl_iocb(phba, cmdiocb, rspiocb);
1336 irsp = &rspiocb->iocb;
1337 if (irsp->ulpStatus) {
1338 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
1339 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
1340 return ndlp->nlp_state;
1343 /* Check out PRLI rsp */
1344 ndlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR);
1345 ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
1346 if ((npr->acceptRspCode == PRLI_REQ_EXECUTED) &&
1347 (npr->prliType == PRLI_FCP_TYPE)) {
1348 if (npr->initiatorFunc)
1349 ndlp->nlp_type |= NLP_FCP_INITIATOR;
1350 if (npr->targetFunc)
1351 ndlp->nlp_type |= NLP_FCP_TARGET;
1353 ndlp->nlp_fcp_info |= NLP_FCP_2_DEVICE;
1355 if (!(ndlp->nlp_type & NLP_FCP_TARGET) &&
1356 (vport->port_type == LPFC_NPIV_PORT) &&
1357 phba->cfg_vport_restrict_login) {
1358 spin_lock_irq(shost->host_lock);
1359 ndlp->nlp_flag |= NLP_TARGET_REMOVE;
1360 spin_unlock_irq(shost->host_lock);
1361 lpfc_issue_els_logo(vport, ndlp, 0);
1363 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
1364 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNUSED_NODE);
1365 return ndlp->nlp_state;
1368 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
1369 if (ndlp->nlp_type & NLP_FCP_TARGET)
1370 lpfc_nlp_set_state(vport, ndlp, NLP_STE_MAPPED_NODE);
1372 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
1373 return ndlp->nlp_state;
1376 /*! lpfc_device_rm_prli_issue
1387 * This routine is envoked when we a request to remove a nport we are in the
1388 * process of PRLIing. We should software abort outstanding prli, unreg
1389 * login, send a logout. We will change node state to UNUSED_NODE, put it
1390 * on plogi list so it can be freed when LOGO completes.
1395 lpfc_device_rm_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1396 void *arg, uint32_t evt)
1398 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1400 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1401 spin_lock_irq(shost->host_lock);
1402 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
1403 spin_unlock_irq(shost->host_lock);
1404 return ndlp->nlp_state;
1406 /* software abort outstanding PLOGI */
1407 lpfc_els_abort(vport->phba, ndlp);
1409 lpfc_drop_node(vport, ndlp);
1410 return NLP_STE_FREED_NODE;
1415 /*! lpfc_device_recov_prli_issue
1426 * The routine is envoked when the state of a device is unknown, like
1427 * during a link down. We should remove the nodelist entry from the
1428 * unmapped list, issue a UNREG_LOGIN, do a software abort of the
1429 * outstanding PRLI command, then free the node entry.
1432 lpfc_device_recov_prli_issue(struct lpfc_vport *vport,
1433 struct lpfc_nodelist *ndlp,
1437 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1438 struct lpfc_hba *phba = vport->phba;
1440 /* Don't do anything that will mess up processing of the
1443 if (vport->fc_flag & FC_RSCN_DEFERRED)
1444 return ndlp->nlp_state;
1446 /* software abort outstanding PRLI */
1447 lpfc_els_abort(phba, ndlp);
1449 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
1450 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1451 spin_lock_irq(shost->host_lock);
1452 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
1453 spin_unlock_irq(shost->host_lock);
1454 lpfc_disc_set_adisc(vport, ndlp);
1455 return ndlp->nlp_state;
1459 lpfc_rcv_plogi_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1460 void *arg, uint32_t evt)
1462 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1464 lpfc_rcv_plogi(vport, ndlp, cmdiocb);
1465 return ndlp->nlp_state;
1469 lpfc_rcv_prli_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1470 void *arg, uint32_t evt)
1472 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1474 lpfc_rcv_prli(vport, ndlp, cmdiocb);
1475 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
1476 return ndlp->nlp_state;
1480 lpfc_rcv_logo_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1481 void *arg, uint32_t evt)
1483 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1485 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
1486 return ndlp->nlp_state;
1490 lpfc_rcv_padisc_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1491 void *arg, uint32_t evt)
1493 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1495 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
1496 return ndlp->nlp_state;
1500 lpfc_rcv_prlo_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1501 void *arg, uint32_t evt)
1503 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1505 lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL, 0);
1506 return ndlp->nlp_state;
1510 lpfc_device_recov_unmap_node(struct lpfc_vport *vport,
1511 struct lpfc_nodelist *ndlp,
1515 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1517 ndlp->nlp_prev_state = NLP_STE_UNMAPPED_NODE;
1518 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1519 spin_lock_irq(shost->host_lock);
1520 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
1521 spin_unlock_irq(shost->host_lock);
1522 lpfc_disc_set_adisc(vport, ndlp);
1524 return ndlp->nlp_state;
1528 lpfc_rcv_plogi_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1529 void *arg, uint32_t evt)
1531 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1533 lpfc_rcv_plogi(vport, ndlp, cmdiocb);
1534 return ndlp->nlp_state;
1538 lpfc_rcv_prli_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1539 void *arg, uint32_t evt)
1541 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1543 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
1544 return ndlp->nlp_state;
1548 lpfc_rcv_logo_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1549 void *arg, uint32_t evt)
1551 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1553 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
1554 return ndlp->nlp_state;
1558 lpfc_rcv_padisc_mapped_node(struct lpfc_vport *vport,
1559 struct lpfc_nodelist *ndlp,
1560 void *arg, uint32_t evt)
1562 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1564 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
1565 return ndlp->nlp_state;
1569 lpfc_rcv_prlo_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1570 void *arg, uint32_t evt)
1572 struct lpfc_hba *phba = vport->phba;
1573 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1575 /* flush the target */
1576 lpfc_sli_abort_iocb(phba, &phba->sli.ring[phba->sli.fcp_ring],
1577 ndlp->nlp_sid, 0, 0, LPFC_CTX_TGT);
1579 /* Treat like rcv logo */
1580 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_PRLO);
1581 return ndlp->nlp_state;
1585 lpfc_device_recov_mapped_node(struct lpfc_vport *vport,
1586 struct lpfc_nodelist *ndlp,
1590 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1592 ndlp->nlp_prev_state = NLP_STE_MAPPED_NODE;
1593 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1594 spin_lock_irq(shost->host_lock);
1595 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
1596 spin_unlock_irq(shost->host_lock);
1597 lpfc_disc_set_adisc(vport, ndlp);
1598 return ndlp->nlp_state;
1602 lpfc_rcv_plogi_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1603 void *arg, uint32_t evt)
1605 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1606 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1608 /* Ignore PLOGI if we have an outstanding LOGO */
1609 if (ndlp->nlp_flag & NLP_LOGO_SND) {
1610 return ndlp->nlp_state;
1613 if (lpfc_rcv_plogi(vport, ndlp, cmdiocb)) {
1614 spin_lock_irq(shost->host_lock);
1615 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
1616 spin_unlock_irq(shost->host_lock);
1617 return ndlp->nlp_state;
1620 /* send PLOGI immediately, move to PLOGI issue state */
1621 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
1622 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
1623 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
1624 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
1627 return ndlp->nlp_state;
1631 lpfc_rcv_prli_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1632 void *arg, uint32_t evt)
1634 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1635 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1638 memset(&stat, 0, sizeof (struct ls_rjt));
1639 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
1640 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
1641 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp);
1643 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
1644 if (ndlp->nlp_flag & NLP_NPR_ADISC) {
1645 spin_lock_irq(shost->host_lock);
1646 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
1647 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
1648 spin_unlock_irq(shost->host_lock);
1649 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
1650 lpfc_issue_els_adisc(vport, ndlp, 0);
1652 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
1653 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
1654 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
1657 return ndlp->nlp_state;
1661 lpfc_rcv_logo_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1662 void *arg, uint32_t evt)
1664 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1666 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
1667 return ndlp->nlp_state;
1671 lpfc_rcv_padisc_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1672 void *arg, uint32_t evt)
1674 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1676 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
1679 * Do not start discovery if discovery is about to start
1680 * or discovery in progress for this node. Starting discovery
1681 * here will affect the counting of discovery threads.
1683 if (!(ndlp->nlp_flag & NLP_DELAY_TMO) &&
1684 !(ndlp->nlp_flag & NLP_NPR_2B_DISC)) {
1685 if (ndlp->nlp_flag & NLP_NPR_ADISC) {
1686 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
1687 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
1688 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
1689 lpfc_issue_els_adisc(vport, ndlp, 0);
1691 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
1692 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
1693 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
1696 return ndlp->nlp_state;
1700 lpfc_rcv_prlo_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1701 void *arg, uint32_t evt)
1703 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1704 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1706 spin_lock_irq(shost->host_lock);
1707 ndlp->nlp_flag |= NLP_LOGO_ACC;
1708 spin_unlock_irq(shost->host_lock);
1710 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL, 0);
1712 if ((ndlp->nlp_flag & NLP_DELAY_TMO) == 0) {
1713 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ * 1);
1714 spin_lock_irq(shost->host_lock);
1715 ndlp->nlp_flag |= NLP_DELAY_TMO;
1716 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
1717 spin_unlock_irq(shost->host_lock);
1718 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
1720 spin_lock_irq(shost->host_lock);
1721 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
1722 spin_unlock_irq(shost->host_lock);
1724 return ndlp->nlp_state;
1728 lpfc_cmpl_plogi_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1729 void *arg, uint32_t evt)
1731 struct lpfc_iocbq *cmdiocb, *rspiocb;
1734 cmdiocb = (struct lpfc_iocbq *) arg;
1735 rspiocb = cmdiocb->context_un.rsp_iocb;
1737 irsp = &rspiocb->iocb;
1738 if (irsp->ulpStatus) {
1739 lpfc_drop_node(vport, ndlp);
1740 return NLP_STE_FREED_NODE;
1742 return ndlp->nlp_state;
1746 lpfc_cmpl_prli_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1747 void *arg, uint32_t evt)
1749 struct lpfc_iocbq *cmdiocb, *rspiocb;
1752 cmdiocb = (struct lpfc_iocbq *) arg;
1753 rspiocb = cmdiocb->context_un.rsp_iocb;
1755 irsp = &rspiocb->iocb;
1756 if (irsp->ulpStatus && (ndlp->nlp_flag & NLP_NODEV_REMOVE)) {
1757 lpfc_drop_node(vport, ndlp);
1758 return NLP_STE_FREED_NODE;
1760 return ndlp->nlp_state;
1764 lpfc_cmpl_logo_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1765 void *arg, uint32_t evt)
1767 lpfc_unreg_rpi(vport, ndlp);
1768 /* This routine does nothing, just return the current state */
1769 return ndlp->nlp_state;
1773 lpfc_cmpl_adisc_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1774 void *arg, uint32_t evt)
1776 struct lpfc_iocbq *cmdiocb, *rspiocb;
1779 cmdiocb = (struct lpfc_iocbq *) arg;
1780 rspiocb = cmdiocb->context_un.rsp_iocb;
1782 irsp = &rspiocb->iocb;
1783 if (irsp->ulpStatus && (ndlp->nlp_flag & NLP_NODEV_REMOVE)) {
1784 lpfc_drop_node(vport, ndlp);
1785 return NLP_STE_FREED_NODE;
1787 return ndlp->nlp_state;
1791 lpfc_cmpl_reglogin_npr_node(struct lpfc_vport *vport,
1792 struct lpfc_nodelist *ndlp,
1793 void *arg, uint32_t evt)
1795 LPFC_MBOXQ_t *pmb = (LPFC_MBOXQ_t *) arg;
1796 MAILBOX_t *mb = &pmb->mb;
1799 ndlp->nlp_rpi = mb->un.varWords[0];
1801 if (ndlp->nlp_flag & NLP_NODEV_REMOVE) {
1802 lpfc_drop_node(vport, ndlp);
1803 return NLP_STE_FREED_NODE;
1806 return ndlp->nlp_state;
1810 lpfc_device_rm_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1811 void *arg, uint32_t evt)
1813 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1815 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1816 spin_lock_irq(shost->host_lock);
1817 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
1818 spin_unlock_irq(shost->host_lock);
1819 return ndlp->nlp_state;
1821 lpfc_drop_node(vport, ndlp);
1822 return NLP_STE_FREED_NODE;
1826 lpfc_device_recov_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1827 void *arg, uint32_t evt)
1829 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1831 /* Don't do anything that will mess up processing of the
1834 if (vport->fc_flag & FC_RSCN_DEFERRED)
1835 return ndlp->nlp_state;
1837 spin_lock_irq(shost->host_lock);
1838 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
1839 spin_unlock_irq(shost->host_lock);
1840 if (ndlp->nlp_flag & NLP_DELAY_TMO) {
1841 lpfc_cancel_retry_delay_tmo(vport, ndlp);
1843 return ndlp->nlp_state;
1847 /* This next section defines the NPort Discovery State Machine */
1849 /* There are 4 different double linked lists nodelist entries can reside on.
1850 * The plogi list and adisc list are used when Link Up discovery or RSCN
1851 * processing is needed. Each list holds the nodes that we will send PLOGI
1852 * or ADISC on. These lists will keep track of what nodes will be effected
1853 * by an RSCN, or a Link Up (Typically, all nodes are effected on Link Up).
1854 * The unmapped_list will contain all nodes that we have successfully logged
1855 * into at the Fibre Channel level. The mapped_list will contain all nodes
1856 * that are mapped FCP targets.
1859 * The bind list is a list of undiscovered (potentially non-existent) nodes
1860 * that we have saved binding information on. This information is used when
1861 * nodes transition from the unmapped to the mapped list.
1863 /* For UNUSED_NODE state, the node has just been allocated .
1864 * For PLOGI_ISSUE and REG_LOGIN_ISSUE, the node is on
1865 * the PLOGI list. For REG_LOGIN_COMPL, the node is taken off the PLOGI list
1866 * and put on the unmapped list. For ADISC processing, the node is taken off
1867 * the ADISC list and placed on either the mapped or unmapped list (depending
1868 * on its previous state). Once on the unmapped list, a PRLI is issued and the
1869 * state changed to PRLI_ISSUE. When the PRLI completion occurs, the state is
1870 * changed to UNMAPPED_NODE. If the completion indicates a mapped
1871 * node, the node is taken off the unmapped list. The binding list is checked
1872 * for a valid binding, or a binding is automatically assigned. If binding
1873 * assignment is unsuccessful, the node is left on the unmapped list. If
1874 * binding assignment is successful, the associated binding list entry (if
1875 * any) is removed, and the node is placed on the mapped list.
1878 * For a Link Down, all nodes on the ADISC, PLOGI, unmapped or mapped
1879 * lists will receive a DEVICE_RECOVERY event. If the linkdown or devloss timers
1880 * expire, all effected nodes will receive a DEVICE_RM event.
1883 * For a Link Up or RSCN, all nodes will move from the mapped / unmapped lists
1884 * to either the ADISC or PLOGI list. After a Nameserver query or ALPA loopmap
1885 * check, additional nodes may be added or removed (via DEVICE_RM) to / from
1886 * the PLOGI or ADISC lists. Once the PLOGI and ADISC lists are populated,
1887 * we will first process the ADISC list. 32 entries are processed initially and
1888 * ADISC is initited for each one. Completions / Events for each node are
1889 * funnelled thru the state machine. As each node finishes ADISC processing, it
1890 * starts ADISC for any nodes waiting for ADISC processing. If no nodes are
1891 * waiting, and the ADISC list count is identically 0, then we are done. For
1892 * Link Up discovery, since all nodes on the PLOGI list are UNREG_LOGIN'ed, we
1893 * can issue a CLEAR_LA and reenable Link Events. Next we will process the PLOGI
1894 * list. 32 entries are processed initially and PLOGI is initited for each one.
1895 * Completions / Events for each node are funnelled thru the state machine. As
1896 * each node finishes PLOGI processing, it starts PLOGI for any nodes waiting
1897 * for PLOGI processing. If no nodes are waiting, and the PLOGI list count is
1898 * indentically 0, then we are done. We have now completed discovery / RSCN
1899 * handling. Upon completion, ALL nodes should be on either the mapped or
1903 static uint32_t (*lpfc_disc_action[NLP_STE_MAX_STATE * NLP_EVT_MAX_EVENT])
1904 (struct lpfc_vport *, struct lpfc_nodelist *, void *, uint32_t) = {
1905 /* Action routine Event Current State */
1906 lpfc_rcv_plogi_unused_node, /* RCV_PLOGI UNUSED_NODE */
1907 lpfc_rcv_els_unused_node, /* RCV_PRLI */
1908 lpfc_rcv_logo_unused_node, /* RCV_LOGO */
1909 lpfc_rcv_els_unused_node, /* RCV_ADISC */
1910 lpfc_rcv_els_unused_node, /* RCV_PDISC */
1911 lpfc_rcv_els_unused_node, /* RCV_PRLO */
1912 lpfc_disc_illegal, /* CMPL_PLOGI */
1913 lpfc_disc_illegal, /* CMPL_PRLI */
1914 lpfc_cmpl_logo_unused_node, /* CMPL_LOGO */
1915 lpfc_disc_illegal, /* CMPL_ADISC */
1916 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
1917 lpfc_device_rm_unused_node, /* DEVICE_RM */
1918 lpfc_disc_illegal, /* DEVICE_RECOVERY */
1920 lpfc_rcv_plogi_plogi_issue, /* RCV_PLOGI PLOGI_ISSUE */
1921 lpfc_rcv_prli_plogi_issue, /* RCV_PRLI */
1922 lpfc_rcv_logo_plogi_issue, /* RCV_LOGO */
1923 lpfc_rcv_els_plogi_issue, /* RCV_ADISC */
1924 lpfc_rcv_els_plogi_issue, /* RCV_PDISC */
1925 lpfc_rcv_els_plogi_issue, /* RCV_PRLO */
1926 lpfc_cmpl_plogi_plogi_issue, /* CMPL_PLOGI */
1927 lpfc_disc_illegal, /* CMPL_PRLI */
1928 lpfc_disc_illegal, /* CMPL_LOGO */
1929 lpfc_disc_illegal, /* CMPL_ADISC */
1930 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
1931 lpfc_device_rm_plogi_issue, /* DEVICE_RM */
1932 lpfc_device_recov_plogi_issue, /* DEVICE_RECOVERY */
1934 lpfc_rcv_plogi_adisc_issue, /* RCV_PLOGI ADISC_ISSUE */
1935 lpfc_rcv_prli_adisc_issue, /* RCV_PRLI */
1936 lpfc_rcv_logo_adisc_issue, /* RCV_LOGO */
1937 lpfc_rcv_padisc_adisc_issue, /* RCV_ADISC */
1938 lpfc_rcv_padisc_adisc_issue, /* RCV_PDISC */
1939 lpfc_rcv_prlo_adisc_issue, /* RCV_PRLO */
1940 lpfc_disc_illegal, /* CMPL_PLOGI */
1941 lpfc_disc_illegal, /* CMPL_PRLI */
1942 lpfc_disc_illegal, /* CMPL_LOGO */
1943 lpfc_cmpl_adisc_adisc_issue, /* CMPL_ADISC */
1944 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
1945 lpfc_device_rm_adisc_issue, /* DEVICE_RM */
1946 lpfc_device_recov_adisc_issue, /* DEVICE_RECOVERY */
1948 lpfc_rcv_plogi_reglogin_issue, /* RCV_PLOGI REG_LOGIN_ISSUE */
1949 lpfc_rcv_prli_reglogin_issue, /* RCV_PLOGI */
1950 lpfc_rcv_logo_reglogin_issue, /* RCV_LOGO */
1951 lpfc_rcv_padisc_reglogin_issue, /* RCV_ADISC */
1952 lpfc_rcv_padisc_reglogin_issue, /* RCV_PDISC */
1953 lpfc_rcv_prlo_reglogin_issue, /* RCV_PRLO */
1954 lpfc_disc_illegal, /* CMPL_PLOGI */
1955 lpfc_disc_illegal, /* CMPL_PRLI */
1956 lpfc_disc_illegal, /* CMPL_LOGO */
1957 lpfc_disc_illegal, /* CMPL_ADISC */
1958 lpfc_cmpl_reglogin_reglogin_issue,/* CMPL_REG_LOGIN */
1959 lpfc_device_rm_reglogin_issue, /* DEVICE_RM */
1960 lpfc_device_recov_reglogin_issue,/* DEVICE_RECOVERY */
1962 lpfc_rcv_plogi_prli_issue, /* RCV_PLOGI PRLI_ISSUE */
1963 lpfc_rcv_prli_prli_issue, /* RCV_PRLI */
1964 lpfc_rcv_logo_prli_issue, /* RCV_LOGO */
1965 lpfc_rcv_padisc_prli_issue, /* RCV_ADISC */
1966 lpfc_rcv_padisc_prli_issue, /* RCV_PDISC */
1967 lpfc_rcv_prlo_prli_issue, /* RCV_PRLO */
1968 lpfc_disc_illegal, /* CMPL_PLOGI */
1969 lpfc_cmpl_prli_prli_issue, /* CMPL_PRLI */
1970 lpfc_disc_illegal, /* CMPL_LOGO */
1971 lpfc_disc_illegal, /* CMPL_ADISC */
1972 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
1973 lpfc_device_rm_prli_issue, /* DEVICE_RM */
1974 lpfc_device_recov_prli_issue, /* DEVICE_RECOVERY */
1976 lpfc_rcv_plogi_unmap_node, /* RCV_PLOGI UNMAPPED_NODE */
1977 lpfc_rcv_prli_unmap_node, /* RCV_PRLI */
1978 lpfc_rcv_logo_unmap_node, /* RCV_LOGO */
1979 lpfc_rcv_padisc_unmap_node, /* RCV_ADISC */
1980 lpfc_rcv_padisc_unmap_node, /* RCV_PDISC */
1981 lpfc_rcv_prlo_unmap_node, /* RCV_PRLO */
1982 lpfc_disc_illegal, /* CMPL_PLOGI */
1983 lpfc_disc_illegal, /* CMPL_PRLI */
1984 lpfc_disc_illegal, /* CMPL_LOGO */
1985 lpfc_disc_illegal, /* CMPL_ADISC */
1986 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
1987 lpfc_disc_illegal, /* DEVICE_RM */
1988 lpfc_device_recov_unmap_node, /* DEVICE_RECOVERY */
1990 lpfc_rcv_plogi_mapped_node, /* RCV_PLOGI MAPPED_NODE */
1991 lpfc_rcv_prli_mapped_node, /* RCV_PRLI */
1992 lpfc_rcv_logo_mapped_node, /* RCV_LOGO */
1993 lpfc_rcv_padisc_mapped_node, /* RCV_ADISC */
1994 lpfc_rcv_padisc_mapped_node, /* RCV_PDISC */
1995 lpfc_rcv_prlo_mapped_node, /* RCV_PRLO */
1996 lpfc_disc_illegal, /* CMPL_PLOGI */
1997 lpfc_disc_illegal, /* CMPL_PRLI */
1998 lpfc_disc_illegal, /* CMPL_LOGO */
1999 lpfc_disc_illegal, /* CMPL_ADISC */
2000 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2001 lpfc_disc_illegal, /* DEVICE_RM */
2002 lpfc_device_recov_mapped_node, /* DEVICE_RECOVERY */
2004 lpfc_rcv_plogi_npr_node, /* RCV_PLOGI NPR_NODE */
2005 lpfc_rcv_prli_npr_node, /* RCV_PRLI */
2006 lpfc_rcv_logo_npr_node, /* RCV_LOGO */
2007 lpfc_rcv_padisc_npr_node, /* RCV_ADISC */
2008 lpfc_rcv_padisc_npr_node, /* RCV_PDISC */
2009 lpfc_rcv_prlo_npr_node, /* RCV_PRLO */
2010 lpfc_cmpl_plogi_npr_node, /* CMPL_PLOGI */
2011 lpfc_cmpl_prli_npr_node, /* CMPL_PRLI */
2012 lpfc_cmpl_logo_npr_node, /* CMPL_LOGO */
2013 lpfc_cmpl_adisc_npr_node, /* CMPL_ADISC */
2014 lpfc_cmpl_reglogin_npr_node, /* CMPL_REG_LOGIN */
2015 lpfc_device_rm_npr_node, /* DEVICE_RM */
2016 lpfc_device_recov_npr_node, /* DEVICE_RECOVERY */
2020 lpfc_disc_state_machine(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2021 void *arg, uint32_t evt)
2023 struct lpfc_hba *phba = vport->phba;
2024 uint32_t cur_state, rc;
2025 uint32_t(*func) (struct lpfc_vport *, struct lpfc_nodelist *, void *,
2029 cur_state = ndlp->nlp_state;
2031 /* DSM in event <evt> on NPort <nlp_DID> in state <cur_state> */
2032 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
2033 "%d (%d):0211 DSM in event x%x on NPort x%x in "
2034 "state %d Data: x%x\n",
2035 phba->brd_no, vport->vpi,
2036 evt, ndlp->nlp_DID, cur_state, ndlp->nlp_flag);
2038 func = lpfc_disc_action[(cur_state * NLP_EVT_MAX_EVENT) + evt];
2039 rc = (func) (vport, ndlp, arg, evt);
2041 /* DSM out state <rc> on NPort <nlp_DID> */
2042 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
2043 "%d (%d):0212 DSM out state %d on NPort x%x "
2045 phba->brd_no, vport->vpi,
2046 rc, ndlp->nlp_DID, ndlp->nlp_flag);