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"
39 #include "lpfc_debugfs.h"
42 /* Called to verify a rcv'ed ADISC was intended for us. */
44 lpfc_check_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
45 struct lpfc_name *nn, struct lpfc_name *pn)
47 /* Compare the ADISC rsp WWNN / WWPN matches our internal node
48 * table entry for that node.
50 if (memcmp(nn, &ndlp->nlp_nodename, sizeof (struct lpfc_name)))
53 if (memcmp(pn, &ndlp->nlp_portname, sizeof (struct lpfc_name)))
56 /* we match, return success */
61 lpfc_check_sparm(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
62 struct serv_parm * sp, uint32_t class)
64 volatile struct serv_parm *hsp = &vport->fc_sparam;
65 uint16_t hsp_value, ssp_value = 0;
68 * The receive data field size and buffer-to-buffer receive data field
69 * size entries are 16 bits but are represented as two 8-bit fields in
70 * the driver data structure to account for rsvd bits and other control
71 * bits. Reconstruct and compare the fields as a 16-bit values before
72 * correcting the byte values.
74 if (sp->cls1.classValid) {
75 hsp_value = (hsp->cls1.rcvDataSizeMsb << 8) |
76 hsp->cls1.rcvDataSizeLsb;
77 ssp_value = (sp->cls1.rcvDataSizeMsb << 8) |
78 sp->cls1.rcvDataSizeLsb;
80 goto bad_service_param;
81 if (ssp_value > hsp_value) {
82 sp->cls1.rcvDataSizeLsb = hsp->cls1.rcvDataSizeLsb;
83 sp->cls1.rcvDataSizeMsb = hsp->cls1.rcvDataSizeMsb;
85 } else if (class == CLASS1) {
86 goto bad_service_param;
89 if (sp->cls2.classValid) {
90 hsp_value = (hsp->cls2.rcvDataSizeMsb << 8) |
91 hsp->cls2.rcvDataSizeLsb;
92 ssp_value = (sp->cls2.rcvDataSizeMsb << 8) |
93 sp->cls2.rcvDataSizeLsb;
95 goto bad_service_param;
96 if (ssp_value > hsp_value) {
97 sp->cls2.rcvDataSizeLsb = hsp->cls2.rcvDataSizeLsb;
98 sp->cls2.rcvDataSizeMsb = hsp->cls2.rcvDataSizeMsb;
100 } else if (class == CLASS2) {
101 goto bad_service_param;
104 if (sp->cls3.classValid) {
105 hsp_value = (hsp->cls3.rcvDataSizeMsb << 8) |
106 hsp->cls3.rcvDataSizeLsb;
107 ssp_value = (sp->cls3.rcvDataSizeMsb << 8) |
108 sp->cls3.rcvDataSizeLsb;
110 goto bad_service_param;
111 if (ssp_value > hsp_value) {
112 sp->cls3.rcvDataSizeLsb = hsp->cls3.rcvDataSizeLsb;
113 sp->cls3.rcvDataSizeMsb = hsp->cls3.rcvDataSizeMsb;
115 } else if (class == CLASS3) {
116 goto bad_service_param;
120 * Preserve the upper four bits of the MSB from the PLOGI response.
121 * These bits contain the Buffer-to-Buffer State Change Number
122 * from the target and need to be passed to the FW.
124 hsp_value = (hsp->cmn.bbRcvSizeMsb << 8) | hsp->cmn.bbRcvSizeLsb;
125 ssp_value = (sp->cmn.bbRcvSizeMsb << 8) | sp->cmn.bbRcvSizeLsb;
126 if (ssp_value > hsp_value) {
127 sp->cmn.bbRcvSizeLsb = hsp->cmn.bbRcvSizeLsb;
128 sp->cmn.bbRcvSizeMsb = (sp->cmn.bbRcvSizeMsb & 0xF0) |
129 (hsp->cmn.bbRcvSizeMsb & 0x0F);
132 memcpy(&ndlp->nlp_nodename, &sp->nodeName, sizeof (struct lpfc_name));
133 memcpy(&ndlp->nlp_portname, &sp->portName, sizeof (struct lpfc_name));
136 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
138 "(%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x) sent "
139 "invalid service parameters. Ignoring device.\n",
141 sp->nodeName.u.wwn[0], sp->nodeName.u.wwn[1],
142 sp->nodeName.u.wwn[2], sp->nodeName.u.wwn[3],
143 sp->nodeName.u.wwn[4], sp->nodeName.u.wwn[5],
144 sp->nodeName.u.wwn[6], sp->nodeName.u.wwn[7]);
149 lpfc_check_elscmpl_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
150 struct lpfc_iocbq *rspiocb)
152 struct lpfc_dmabuf *pcmd, *prsp;
157 irsp = &rspiocb->iocb;
158 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
160 /* For lpfc_els_abort, context2 could be zero'ed to delay
161 * freeing associated memory till after ABTS completes.
164 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf,
167 lp = (uint32_t *) prsp->virt;
168 ptr = (void *)((uint8_t *)lp + sizeof(uint32_t));
171 /* Force ulpStatus error since we are returning NULL ptr */
172 if (!(irsp->ulpStatus)) {
173 irsp->ulpStatus = IOSTAT_LOCAL_REJECT;
174 irsp->un.ulpWord[4] = IOERR_SLI_ABORTED;
183 * Free resources / clean up outstanding I/Os
184 * associated with a LPFC_NODELIST entry. This
185 * routine effectively results in a "software abort".
188 lpfc_els_abort(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp)
190 LIST_HEAD(completions);
191 struct lpfc_sli *psli = &phba->sli;
192 struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING];
193 struct lpfc_iocbq *iocb, *next_iocb;
196 /* Abort outstanding I/O on NPort <nlp_DID> */
197 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_DISCOVERY,
198 "0205 Abort outstanding I/O on NPort x%x "
199 "Data: x%x x%x x%x\n",
200 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
203 lpfc_fabric_abort_nport(ndlp);
205 /* First check the txq */
206 spin_lock_irq(&phba->hbalock);
207 list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
208 /* Check to see if iocb matches the nport we are looking for */
209 if (lpfc_check_sli_ndlp(phba, pring, iocb, ndlp)) {
210 /* It matches, so deque and call compl with anp error */
211 list_move_tail(&iocb->list, &completions);
216 /* Next check the txcmplq */
217 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
218 /* Check to see if iocb matches the nport we are looking for */
219 if (lpfc_check_sli_ndlp(phba, pring, iocb, ndlp)) {
220 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
223 spin_unlock_irq(&phba->hbalock);
225 while (!list_empty(&completions)) {
226 iocb = list_get_first(&completions, struct lpfc_iocbq, list);
228 list_del_init(&iocb->list);
230 if (!iocb->iocb_cmpl)
231 lpfc_sli_release_iocbq(phba, iocb);
233 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
234 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
235 (iocb->iocb_cmpl) (phba, iocb, iocb);
239 /* If we are delaying issuing an ELS command, cancel it */
240 if (ndlp->nlp_flag & NLP_DELAY_TMO)
241 lpfc_cancel_retry_delay_tmo(phba->pport, ndlp);
246 lpfc_rcv_plogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
247 struct lpfc_iocbq *cmdiocb)
249 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
250 struct lpfc_hba *phba = vport->phba;
251 struct lpfc_dmabuf *pcmd;
254 struct serv_parm *sp;
259 memset(&stat, 0, sizeof (struct ls_rjt));
260 if (vport->port_state <= LPFC_FLOGI) {
261 /* Before responding to PLOGI, check for pt2pt mode.
262 * If we are pt2pt, with an outstanding FLOGI, abort
263 * the FLOGI and resend it first.
265 if (vport->fc_flag & FC_PT2PT) {
266 lpfc_els_abort_flogi(phba);
267 if (!(vport->fc_flag & FC_PT2PT_PLOGI)) {
268 /* If the other side is supposed to initiate
269 * the PLOGI anyway, just ACC it now and
270 * move on with discovery.
272 phba->fc_edtov = FF_DEF_EDTOV;
273 phba->fc_ratov = FF_DEF_RATOV;
274 /* Start discovery - this should just do
276 lpfc_disc_start(vport);
278 lpfc_initial_flogi(vport);
280 stat.un.b.lsRjtRsnCode = LSRJT_LOGICAL_BSY;
281 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
282 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb,
287 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
288 lp = (uint32_t *) pcmd->virt;
289 sp = (struct serv_parm *) ((uint8_t *) lp + sizeof (uint32_t));
290 if ((lpfc_check_sparm(vport, ndlp, sp, CLASS3) == 0)) {
291 /* Reject this request because invalid parameters */
292 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
293 stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
294 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
298 icmd = &cmdiocb->iocb;
300 /* PLOGI chkparm OK */
301 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
302 "0114 PLOGI chkparm OK Data: x%x x%x x%x x%x\n",
303 ndlp->nlp_DID, ndlp->nlp_state, ndlp->nlp_flag,
306 if (vport->cfg_fcp_class == 2 && sp->cls2.classValid)
307 ndlp->nlp_fcp_info |= CLASS2;
309 ndlp->nlp_fcp_info |= CLASS3;
311 ndlp->nlp_class_sup = 0;
312 if (sp->cls1.classValid)
313 ndlp->nlp_class_sup |= FC_COS_CLASS1;
314 if (sp->cls2.classValid)
315 ndlp->nlp_class_sup |= FC_COS_CLASS2;
316 if (sp->cls3.classValid)
317 ndlp->nlp_class_sup |= FC_COS_CLASS3;
318 if (sp->cls4.classValid)
319 ndlp->nlp_class_sup |= FC_COS_CLASS4;
321 ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) | sp->cmn.bbRcvSizeLsb;
323 /* no need to reg_login if we are already in one of these states */
324 switch (ndlp->nlp_state) {
325 case NLP_STE_NPR_NODE:
326 if (!(ndlp->nlp_flag & NLP_NPR_ADISC))
328 case NLP_STE_REG_LOGIN_ISSUE:
329 case NLP_STE_PRLI_ISSUE:
330 case NLP_STE_UNMAPPED_NODE:
331 case NLP_STE_MAPPED_NODE:
332 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp, NULL);
336 if ((vport->fc_flag & FC_PT2PT) &&
337 !(vport->fc_flag & FC_PT2PT_PLOGI)) {
338 /* rcv'ed PLOGI decides what our NPortId will be */
339 vport->fc_myDID = icmd->un.rcvels.parmRo;
340 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
343 lpfc_config_link(phba, mbox);
344 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
346 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
347 if (rc == MBX_NOT_FINISHED) {
348 mempool_free(mbox, phba->mbox_mem_pool);
352 lpfc_can_disctmo(vport);
354 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
358 rc = lpfc_reg_login(phba, vport->vpi, icmd->un.rcvels.remoteID,
359 (uint8_t *) sp, mbox, 0);
361 mempool_free(mbox, phba->mbox_mem_pool);
365 /* ACC PLOGI rsp command needs to execute first,
366 * queue this mbox command to be processed later.
368 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
370 * mbox->context2 = lpfc_nlp_get(ndlp) deferred until mailbox
371 * command issued in lpfc_cmpl_els_acc().
374 spin_lock_irq(shost->host_lock);
375 ndlp->nlp_flag |= (NLP_ACC_REGLOGIN | NLP_RCV_PLOGI);
376 spin_unlock_irq(shost->host_lock);
379 * If there is an outstanding PLOGI issued, abort it before
380 * sending ACC rsp for received PLOGI. If pending plogi
381 * is not canceled here, the plogi will be rejected by
382 * remote port and will be retried. On a configuration with
383 * single discovery thread, this will cause a huge delay in
384 * discovery. Also this will cause multiple state machines
385 * running in parallel for this node.
387 if (ndlp->nlp_state == NLP_STE_PLOGI_ISSUE) {
388 /* software abort outstanding PLOGI */
389 lpfc_els_abort(phba, ndlp);
392 if ((vport->port_type == LPFC_NPIV_PORT &&
393 vport->cfg_restrict_login)) {
395 /* In order to preserve RPIs, we want to cleanup
396 * the default RPI the firmware created to rcv
397 * this ELS request. The only way to do this is
398 * to register, then unregister the RPI.
400 spin_lock_irq(shost->host_lock);
401 ndlp->nlp_flag |= NLP_RM_DFLT_RPI;
402 spin_unlock_irq(shost->host_lock);
403 stat.un.b.lsRjtRsnCode = LSRJT_INVALID_CMD;
404 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
405 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb,
409 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp, mbox);
413 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
414 stat.un.b.lsRjtRsnCodeExp = LSEXP_OUT_OF_RESOURCE;
415 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
420 lpfc_rcv_padisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
421 struct lpfc_iocbq *cmdiocb)
423 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
424 struct lpfc_dmabuf *pcmd;
425 struct serv_parm *sp;
426 struct lpfc_name *pnn, *ppn;
433 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
434 lp = (uint32_t *) pcmd->virt;
437 if (cmd == ELS_CMD_ADISC) {
439 pnn = (struct lpfc_name *) & ap->nodeName;
440 ppn = (struct lpfc_name *) & ap->portName;
442 sp = (struct serv_parm *) lp;
443 pnn = (struct lpfc_name *) & sp->nodeName;
444 ppn = (struct lpfc_name *) & sp->portName;
447 icmd = &cmdiocb->iocb;
448 if (icmd->ulpStatus == 0 && lpfc_check_adisc(vport, ndlp, pnn, ppn)) {
449 if (cmd == ELS_CMD_ADISC) {
450 lpfc_els_rsp_adisc_acc(vport, cmdiocb, ndlp);
452 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp,
457 /* Reject this request because invalid parameters */
458 stat.un.b.lsRjtRsvd0 = 0;
459 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
460 stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
461 stat.un.b.vendorUnique = 0;
462 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
465 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ);
467 spin_lock_irq(shost->host_lock);
468 ndlp->nlp_flag |= NLP_DELAY_TMO;
469 spin_unlock_irq(shost->host_lock);
470 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
471 ndlp->nlp_prev_state = ndlp->nlp_state;
472 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
477 lpfc_rcv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
478 struct lpfc_iocbq *cmdiocb, uint32_t els_cmd)
480 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
482 /* Put ndlp in NPR state with 1 sec timeout for plogi, ACC logo */
483 /* Only call LOGO ACC for first LOGO, this avoids sending unnecessary
484 * PLOGIs during LOGO storms from a device.
486 spin_lock_irq(shost->host_lock);
487 ndlp->nlp_flag |= NLP_LOGO_ACC;
488 spin_unlock_irq(shost->host_lock);
489 if (els_cmd == ELS_CMD_PRLO)
490 lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL);
492 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
494 if (!(ndlp->nlp_type & NLP_FABRIC) ||
495 (ndlp->nlp_state == NLP_STE_ADISC_ISSUE)) {
496 /* Only try to re-login if this is NOT a Fabric Node */
497 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ * 1);
498 spin_lock_irq(shost->host_lock);
499 ndlp->nlp_flag |= NLP_DELAY_TMO;
500 spin_unlock_irq(shost->host_lock);
502 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
503 ndlp->nlp_prev_state = ndlp->nlp_state;
504 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
506 ndlp->nlp_prev_state = ndlp->nlp_state;
507 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNUSED_NODE);
510 spin_lock_irq(shost->host_lock);
511 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
512 spin_unlock_irq(shost->host_lock);
513 /* The driver has to wait until the ACC completes before it continues
514 * processing the LOGO. The action will resume in
515 * lpfc_cmpl_els_logo_acc routine. Since part of processing includes an
516 * unreg_login, the driver waits so the ACC does not get aborted.
522 lpfc_rcv_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
523 struct lpfc_iocbq *cmdiocb)
525 struct lpfc_dmabuf *pcmd;
528 struct fc_rport *rport = ndlp->rport;
531 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
532 lp = (uint32_t *) pcmd->virt;
533 npr = (PRLI *) ((uint8_t *) lp + sizeof (uint32_t));
535 ndlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR);
536 ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
537 if (npr->prliType == PRLI_FCP_TYPE) {
538 if (npr->initiatorFunc)
539 ndlp->nlp_type |= NLP_FCP_INITIATOR;
541 ndlp->nlp_type |= NLP_FCP_TARGET;
543 ndlp->nlp_fcp_info |= NLP_FCP_2_DEVICE;
546 /* We need to update the rport role values */
547 roles = FC_RPORT_ROLE_UNKNOWN;
548 if (ndlp->nlp_type & NLP_FCP_INITIATOR)
549 roles |= FC_RPORT_ROLE_FCP_INITIATOR;
550 if (ndlp->nlp_type & NLP_FCP_TARGET)
551 roles |= FC_RPORT_ROLE_FCP_TARGET;
553 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
554 "rport rolechg: role:x%x did:x%x flg:x%x",
555 roles, ndlp->nlp_DID, ndlp->nlp_flag);
557 fc_remote_port_rolechg(rport, roles);
562 lpfc_disc_set_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
564 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
566 if (!ndlp->nlp_rpi) {
567 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
571 /* Check config parameter use-adisc or FCP-2 */
572 if ((vport->cfg_use_adisc && (vport->fc_flag & FC_RSCN_MODE)) ||
573 ndlp->nlp_fcp_info & NLP_FCP_2_DEVICE) {
574 spin_lock_irq(shost->host_lock);
575 ndlp->nlp_flag |= NLP_NPR_ADISC;
576 spin_unlock_irq(shost->host_lock);
579 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
580 lpfc_unreg_rpi(vport, ndlp);
585 lpfc_disc_illegal(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
586 void *arg, uint32_t evt)
588 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
589 "0253 Illegal State Transition: node x%x "
590 "event x%x, state x%x Data: x%x x%x\n",
591 ndlp->nlp_DID, evt, ndlp->nlp_state, ndlp->nlp_rpi,
593 return ndlp->nlp_state;
596 /* Start of Discovery State Machine routines */
599 lpfc_rcv_plogi_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
600 void *arg, uint32_t evt)
602 struct lpfc_iocbq *cmdiocb;
604 cmdiocb = (struct lpfc_iocbq *) arg;
606 if (lpfc_rcv_plogi(vport, ndlp, cmdiocb)) {
607 ndlp->nlp_prev_state = NLP_STE_UNUSED_NODE;
608 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNUSED_NODE);
609 return ndlp->nlp_state;
611 lpfc_drop_node(vport, ndlp);
612 return NLP_STE_FREED_NODE;
616 lpfc_rcv_els_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
617 void *arg, uint32_t evt)
619 lpfc_issue_els_logo(vport, ndlp, 0);
620 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNUSED_NODE);
621 return ndlp->nlp_state;
625 lpfc_rcv_logo_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
626 void *arg, uint32_t evt)
628 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
629 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
631 spin_lock_irq(shost->host_lock);
632 ndlp->nlp_flag |= NLP_LOGO_ACC;
633 spin_unlock_irq(shost->host_lock);
634 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
635 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNUSED_NODE);
637 return ndlp->nlp_state;
641 lpfc_cmpl_logo_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
642 void *arg, uint32_t evt)
644 lpfc_drop_node(vport, ndlp);
645 return NLP_STE_FREED_NODE;
649 lpfc_device_rm_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
650 void *arg, uint32_t evt)
652 lpfc_drop_node(vport, ndlp);
653 return NLP_STE_FREED_NODE;
657 lpfc_rcv_plogi_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
658 void *arg, uint32_t evt)
660 struct lpfc_hba *phba = vport->phba;
661 struct lpfc_iocbq *cmdiocb = arg;
662 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
663 uint32_t *lp = (uint32_t *) pcmd->virt;
664 struct serv_parm *sp = (struct serv_parm *) (lp + 1);
668 memset(&stat, 0, sizeof (struct ls_rjt));
670 /* For a PLOGI, we only accept if our portname is less
671 * than the remote portname.
673 phba->fc_stat.elsLogiCol++;
674 port_cmp = memcmp(&vport->fc_portname, &sp->portName,
675 sizeof(struct lpfc_name));
678 /* Reject this request because the remote node will accept
680 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
681 stat.un.b.lsRjtRsnCodeExp = LSEXP_CMD_IN_PROGRESS;
682 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
685 lpfc_rcv_plogi(vport, ndlp, cmdiocb);
686 } /* If our portname was less */
688 return ndlp->nlp_state;
692 lpfc_rcv_prli_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
693 void *arg, uint32_t evt)
695 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
698 memset(&stat, 0, sizeof (struct ls_rjt));
699 stat.un.b.lsRjtRsnCode = LSRJT_LOGICAL_BSY;
700 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
701 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
702 return ndlp->nlp_state;
706 lpfc_rcv_logo_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
707 void *arg, uint32_t evt)
709 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
711 /* software abort outstanding PLOGI */
712 lpfc_els_abort(vport->phba, ndlp);
714 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
715 return ndlp->nlp_state;
719 lpfc_rcv_els_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
720 void *arg, uint32_t evt)
722 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
723 struct lpfc_hba *phba = vport->phba;
724 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
726 /* software abort outstanding PLOGI */
727 lpfc_els_abort(phba, ndlp);
729 if (evt == NLP_EVT_RCV_LOGO) {
730 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
732 lpfc_issue_els_logo(vport, ndlp, 0);
735 /* Put ndlp in npr state set plogi timer for 1 sec */
736 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ * 1);
737 spin_lock_irq(shost->host_lock);
738 ndlp->nlp_flag |= NLP_DELAY_TMO;
739 spin_unlock_irq(shost->host_lock);
740 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
741 ndlp->nlp_prev_state = NLP_STE_PLOGI_ISSUE;
742 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
744 return ndlp->nlp_state;
748 lpfc_cmpl_plogi_plogi_issue(struct lpfc_vport *vport,
749 struct lpfc_nodelist *ndlp,
753 struct lpfc_hba *phba = vport->phba;
754 struct lpfc_iocbq *cmdiocb, *rspiocb;
755 struct lpfc_dmabuf *pcmd, *prsp, *mp;
758 struct serv_parm *sp;
761 cmdiocb = (struct lpfc_iocbq *) arg;
762 rspiocb = cmdiocb->context_un.rsp_iocb;
764 if (ndlp->nlp_flag & NLP_ACC_REGLOGIN) {
765 /* Recovery from PLOGI collision logic */
766 return ndlp->nlp_state;
769 irsp = &rspiocb->iocb;
774 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
776 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
778 lp = (uint32_t *) prsp->virt;
779 sp = (struct serv_parm *) ((uint8_t *) lp + sizeof (uint32_t));
780 if (!lpfc_check_sparm(vport, ndlp, sp, CLASS3))
782 /* PLOGI chkparm OK */
783 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
784 "0121 PLOGI chkparm OK Data: x%x x%x x%x x%x\n",
785 ndlp->nlp_DID, ndlp->nlp_state,
786 ndlp->nlp_flag, ndlp->nlp_rpi);
787 if (vport->cfg_fcp_class == 2 && (sp->cls2.classValid))
788 ndlp->nlp_fcp_info |= CLASS2;
790 ndlp->nlp_fcp_info |= CLASS3;
792 ndlp->nlp_class_sup = 0;
793 if (sp->cls1.classValid)
794 ndlp->nlp_class_sup |= FC_COS_CLASS1;
795 if (sp->cls2.classValid)
796 ndlp->nlp_class_sup |= FC_COS_CLASS2;
797 if (sp->cls3.classValid)
798 ndlp->nlp_class_sup |= FC_COS_CLASS3;
799 if (sp->cls4.classValid)
800 ndlp->nlp_class_sup |= FC_COS_CLASS4;
802 ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) | sp->cmn.bbRcvSizeLsb;
804 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
806 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
807 "0133 PLOGI: no memory for reg_login "
808 "Data: x%x x%x x%x x%x\n",
809 ndlp->nlp_DID, ndlp->nlp_state,
810 ndlp->nlp_flag, ndlp->nlp_rpi);
814 lpfc_unreg_rpi(vport, ndlp);
816 if (lpfc_reg_login(phba, vport->vpi, irsp->un.elsreq64.remoteID,
817 (uint8_t *) sp, mbox, 0) == 0) {
818 switch (ndlp->nlp_DID) {
820 mbox->mbox_cmpl = lpfc_mbx_cmpl_ns_reg_login;
823 mbox->mbox_cmpl = lpfc_mbx_cmpl_fdmi_reg_login;
826 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
828 mbox->context2 = lpfc_nlp_get(ndlp);
830 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
831 != MBX_NOT_FINISHED) {
832 lpfc_nlp_set_state(vport, ndlp,
833 NLP_STE_REG_LOGIN_ISSUE);
834 return ndlp->nlp_state;
837 mp = (struct lpfc_dmabuf *) mbox->context1;
838 lpfc_mbuf_free(phba, mp->virt, mp->phys);
840 mempool_free(mbox, phba->mbox_mem_pool);
842 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
843 "0134 PLOGI: cannot issue reg_login "
844 "Data: x%x x%x x%x x%x\n",
845 ndlp->nlp_DID, ndlp->nlp_state,
846 ndlp->nlp_flag, ndlp->nlp_rpi);
848 mempool_free(mbox, phba->mbox_mem_pool);
850 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
851 "0135 PLOGI: cannot format reg_login "
852 "Data: x%x x%x x%x x%x\n",
853 ndlp->nlp_DID, ndlp->nlp_state,
854 ndlp->nlp_flag, ndlp->nlp_rpi);
859 if (ndlp->nlp_DID == NameServer_DID) {
860 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
861 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
862 "0261 Cannot Register NameServer login\n");
865 /* Free this node since the driver cannot login or has the wrong
867 lpfc_drop_node(vport, ndlp);
868 return NLP_STE_FREED_NODE;
872 lpfc_device_rm_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
873 void *arg, uint32_t evt)
875 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
877 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
878 spin_lock_irq(shost->host_lock);
879 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
880 spin_unlock_irq(shost->host_lock);
881 return ndlp->nlp_state;
883 /* software abort outstanding PLOGI */
884 lpfc_els_abort(vport->phba, ndlp);
886 lpfc_drop_node(vport, ndlp);
887 return NLP_STE_FREED_NODE;
892 lpfc_device_recov_plogi_issue(struct lpfc_vport *vport,
893 struct lpfc_nodelist *ndlp,
897 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
898 struct lpfc_hba *phba = vport->phba;
900 /* Don't do anything that will mess up processing of the
903 if (vport->fc_flag & FC_RSCN_DEFERRED)
904 return ndlp->nlp_state;
906 /* software abort outstanding PLOGI */
907 lpfc_els_abort(phba, ndlp);
909 ndlp->nlp_prev_state = NLP_STE_PLOGI_ISSUE;
910 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
911 spin_lock_irq(shost->host_lock);
912 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
913 spin_unlock_irq(shost->host_lock);
915 return ndlp->nlp_state;
919 lpfc_rcv_plogi_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
920 void *arg, uint32_t evt)
922 struct lpfc_hba *phba = vport->phba;
923 struct lpfc_iocbq *cmdiocb;
925 /* software abort outstanding ADISC */
926 lpfc_els_abort(phba, ndlp);
928 cmdiocb = (struct lpfc_iocbq *) arg;
930 if (lpfc_rcv_plogi(vport, ndlp, cmdiocb))
931 return ndlp->nlp_state;
933 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
934 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
935 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
937 return ndlp->nlp_state;
941 lpfc_rcv_prli_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
942 void *arg, uint32_t evt)
944 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
946 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
947 return ndlp->nlp_state;
951 lpfc_rcv_logo_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
952 void *arg, uint32_t evt)
954 struct lpfc_hba *phba = vport->phba;
955 struct lpfc_iocbq *cmdiocb;
957 cmdiocb = (struct lpfc_iocbq *) arg;
959 /* software abort outstanding ADISC */
960 lpfc_els_abort(phba, ndlp);
962 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
963 return ndlp->nlp_state;
967 lpfc_rcv_padisc_adisc_issue(struct lpfc_vport *vport,
968 struct lpfc_nodelist *ndlp,
969 void *arg, uint32_t evt)
971 struct lpfc_iocbq *cmdiocb;
973 cmdiocb = (struct lpfc_iocbq *) arg;
975 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
976 return ndlp->nlp_state;
980 lpfc_rcv_prlo_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
981 void *arg, uint32_t evt)
983 struct lpfc_iocbq *cmdiocb;
985 cmdiocb = (struct lpfc_iocbq *) arg;
987 /* Treat like rcv logo */
988 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_PRLO);
989 return ndlp->nlp_state;
993 lpfc_cmpl_adisc_adisc_issue(struct lpfc_vport *vport,
994 struct lpfc_nodelist *ndlp,
995 void *arg, uint32_t evt)
997 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
998 struct lpfc_hba *phba = vport->phba;
999 struct lpfc_iocbq *cmdiocb, *rspiocb;
1003 cmdiocb = (struct lpfc_iocbq *) arg;
1004 rspiocb = cmdiocb->context_un.rsp_iocb;
1006 ap = (ADISC *)lpfc_check_elscmpl_iocb(phba, cmdiocb, rspiocb);
1007 irsp = &rspiocb->iocb;
1009 if ((irsp->ulpStatus) ||
1010 (!lpfc_check_adisc(vport, ndlp, &ap->nodeName, &ap->portName))) {
1012 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ);
1013 spin_lock_irq(shost->host_lock);
1014 ndlp->nlp_flag |= NLP_DELAY_TMO;
1015 spin_unlock_irq(shost->host_lock);
1016 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
1018 memset(&ndlp->nlp_nodename, 0, sizeof(struct lpfc_name));
1019 memset(&ndlp->nlp_portname, 0, sizeof(struct lpfc_name));
1021 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
1022 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1023 lpfc_unreg_rpi(vport, ndlp);
1024 return ndlp->nlp_state;
1027 if (ndlp->nlp_type & NLP_FCP_TARGET) {
1028 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
1029 lpfc_nlp_set_state(vport, ndlp, NLP_STE_MAPPED_NODE);
1031 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
1032 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
1034 return ndlp->nlp_state;
1038 lpfc_device_rm_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1039 void *arg, uint32_t evt)
1041 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1043 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1044 spin_lock_irq(shost->host_lock);
1045 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
1046 spin_unlock_irq(shost->host_lock);
1047 return ndlp->nlp_state;
1049 /* software abort outstanding ADISC */
1050 lpfc_els_abort(vport->phba, ndlp);
1052 lpfc_drop_node(vport, ndlp);
1053 return NLP_STE_FREED_NODE;
1058 lpfc_device_recov_adisc_issue(struct lpfc_vport *vport,
1059 struct lpfc_nodelist *ndlp,
1063 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1064 struct lpfc_hba *phba = vport->phba;
1066 /* Don't do anything that will mess up processing of the
1069 if (vport->fc_flag & FC_RSCN_DEFERRED)
1070 return ndlp->nlp_state;
1072 /* software abort outstanding ADISC */
1073 lpfc_els_abort(phba, ndlp);
1075 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
1076 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1077 spin_lock_irq(shost->host_lock);
1078 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
1079 spin_unlock_irq(shost->host_lock);
1080 lpfc_disc_set_adisc(vport, ndlp);
1081 return ndlp->nlp_state;
1085 lpfc_rcv_plogi_reglogin_issue(struct lpfc_vport *vport,
1086 struct lpfc_nodelist *ndlp,
1090 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1092 lpfc_rcv_plogi(vport, ndlp, cmdiocb);
1093 return ndlp->nlp_state;
1097 lpfc_rcv_prli_reglogin_issue(struct lpfc_vport *vport,
1098 struct lpfc_nodelist *ndlp,
1102 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1104 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
1105 return ndlp->nlp_state;
1109 lpfc_rcv_logo_reglogin_issue(struct lpfc_vport *vport,
1110 struct lpfc_nodelist *ndlp,
1114 struct lpfc_hba *phba = vport->phba;
1115 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1117 LPFC_MBOXQ_t *nextmb;
1118 struct lpfc_dmabuf *mp;
1120 cmdiocb = (struct lpfc_iocbq *) arg;
1122 /* cleanup any ndlp on mbox q waiting for reglogin cmpl */
1123 if ((mb = phba->sli.mbox_active)) {
1124 if ((mb->mb.mbxCommand == MBX_REG_LOGIN64) &&
1125 (ndlp == (struct lpfc_nodelist *) mb->context2)) {
1127 mb->context2 = NULL;
1128 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1132 spin_lock_irq(&phba->hbalock);
1133 list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) {
1134 if ((mb->mb.mbxCommand == MBX_REG_LOGIN64) &&
1135 (ndlp == (struct lpfc_nodelist *) mb->context2)) {
1136 mp = (struct lpfc_dmabuf *) (mb->context1);
1138 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1142 list_del(&mb->list);
1143 mempool_free(mb, phba->mbox_mem_pool);
1146 spin_unlock_irq(&phba->hbalock);
1148 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
1149 return ndlp->nlp_state;
1153 lpfc_rcv_padisc_reglogin_issue(struct lpfc_vport *vport,
1154 struct lpfc_nodelist *ndlp,
1158 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1160 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
1161 return ndlp->nlp_state;
1165 lpfc_rcv_prlo_reglogin_issue(struct lpfc_vport *vport,
1166 struct lpfc_nodelist *ndlp,
1170 struct lpfc_iocbq *cmdiocb;
1172 cmdiocb = (struct lpfc_iocbq *) arg;
1173 lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL);
1174 return ndlp->nlp_state;
1178 lpfc_cmpl_reglogin_reglogin_issue(struct lpfc_vport *vport,
1179 struct lpfc_nodelist *ndlp,
1183 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1184 LPFC_MBOXQ_t *pmb = (LPFC_MBOXQ_t *) arg;
1185 MAILBOX_t *mb = &pmb->mb;
1186 uint32_t did = mb->un.varWords[1];
1188 if (mb->mbxStatus) {
1189 /* RegLogin failed */
1190 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
1191 "0246 RegLogin failed Data: x%x x%x x%x\n",
1192 did, mb->mbxStatus, vport->port_state);
1194 * If RegLogin failed due to lack of HBA resources do not
1197 if (mb->mbxStatus == MBXERR_RPI_FULL) {
1198 ndlp->nlp_prev_state = NLP_STE_UNUSED_NODE;
1199 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNUSED_NODE);
1200 return ndlp->nlp_state;
1203 /* Put ndlp in npr state set plogi timer for 1 sec */
1204 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ * 1);
1205 spin_lock_irq(shost->host_lock);
1206 ndlp->nlp_flag |= NLP_DELAY_TMO;
1207 spin_unlock_irq(shost->host_lock);
1208 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
1210 lpfc_issue_els_logo(vport, ndlp, 0);
1211 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
1212 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1213 return ndlp->nlp_state;
1216 ndlp->nlp_rpi = mb->un.varWords[0];
1218 /* Only if we are not a fabric nport do we issue PRLI */
1219 if (!(ndlp->nlp_type & NLP_FABRIC)) {
1220 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
1221 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
1222 lpfc_issue_els_prli(vport, ndlp, 0);
1224 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
1225 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
1227 return ndlp->nlp_state;
1231 lpfc_device_rm_reglogin_issue(struct lpfc_vport *vport,
1232 struct lpfc_nodelist *ndlp,
1236 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1238 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1239 spin_lock_irq(shost->host_lock);
1240 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
1241 spin_unlock_irq(shost->host_lock);
1242 return ndlp->nlp_state;
1244 lpfc_drop_node(vport, ndlp);
1245 return NLP_STE_FREED_NODE;
1250 lpfc_device_recov_reglogin_issue(struct lpfc_vport *vport,
1251 struct lpfc_nodelist *ndlp,
1255 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1257 /* Don't do anything that will mess up processing of the
1260 if (vport->fc_flag & FC_RSCN_DEFERRED)
1261 return ndlp->nlp_state;
1263 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
1264 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1265 spin_lock_irq(shost->host_lock);
1266 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
1267 spin_unlock_irq(shost->host_lock);
1268 lpfc_disc_set_adisc(vport, ndlp);
1269 return ndlp->nlp_state;
1273 lpfc_rcv_plogi_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1274 void *arg, uint32_t evt)
1276 struct lpfc_iocbq *cmdiocb;
1278 cmdiocb = (struct lpfc_iocbq *) arg;
1280 lpfc_rcv_plogi(vport, ndlp, cmdiocb);
1281 return ndlp->nlp_state;
1285 lpfc_rcv_prli_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 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
1291 return ndlp->nlp_state;
1295 lpfc_rcv_logo_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1296 void *arg, uint32_t evt)
1298 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1300 /* Software abort outstanding PRLI before sending acc */
1301 lpfc_els_abort(vport->phba, ndlp);
1303 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
1304 return ndlp->nlp_state;
1308 lpfc_rcv_padisc_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1309 void *arg, uint32_t evt)
1311 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1313 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
1314 return ndlp->nlp_state;
1317 /* This routine is envoked when we rcv a PRLO request from a nport
1318 * we are logged into. We should send back a PRLO rsp setting the
1320 * NEXT STATE = PRLI_ISSUE
1323 lpfc_rcv_prlo_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1324 void *arg, uint32_t evt)
1326 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1328 lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL);
1329 return ndlp->nlp_state;
1333 lpfc_cmpl_prli_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1334 void *arg, uint32_t evt)
1336 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1337 struct lpfc_iocbq *cmdiocb, *rspiocb;
1338 struct lpfc_hba *phba = vport->phba;
1342 cmdiocb = (struct lpfc_iocbq *) arg;
1343 rspiocb = cmdiocb->context_un.rsp_iocb;
1344 npr = (PRLI *)lpfc_check_elscmpl_iocb(phba, cmdiocb, rspiocb);
1346 irsp = &rspiocb->iocb;
1347 if (irsp->ulpStatus) {
1348 if ((vport->port_type == LPFC_NPIV_PORT) &&
1349 vport->cfg_restrict_login) {
1352 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
1353 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
1354 return ndlp->nlp_state;
1357 /* Check out PRLI rsp */
1358 ndlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR);
1359 ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
1360 if ((npr->acceptRspCode == PRLI_REQ_EXECUTED) &&
1361 (npr->prliType == PRLI_FCP_TYPE)) {
1362 if (npr->initiatorFunc)
1363 ndlp->nlp_type |= NLP_FCP_INITIATOR;
1364 if (npr->targetFunc)
1365 ndlp->nlp_type |= NLP_FCP_TARGET;
1367 ndlp->nlp_fcp_info |= NLP_FCP_2_DEVICE;
1369 if (!(ndlp->nlp_type & NLP_FCP_TARGET) &&
1370 (vport->port_type == LPFC_NPIV_PORT) &&
1371 vport->cfg_restrict_login) {
1373 spin_lock_irq(shost->host_lock);
1374 ndlp->nlp_flag |= NLP_TARGET_REMOVE;
1375 spin_unlock_irq(shost->host_lock);
1376 lpfc_issue_els_logo(vport, ndlp, 0);
1378 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
1379 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNUSED_NODE);
1380 return ndlp->nlp_state;
1383 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
1384 if (ndlp->nlp_type & NLP_FCP_TARGET)
1385 lpfc_nlp_set_state(vport, ndlp, NLP_STE_MAPPED_NODE);
1387 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
1388 return ndlp->nlp_state;
1391 /*! lpfc_device_rm_prli_issue
1402 * This routine is envoked when we a request to remove a nport we are in the
1403 * process of PRLIing. We should software abort outstanding prli, unreg
1404 * login, send a logout. We will change node state to UNUSED_NODE, put it
1405 * on plogi list so it can be freed when LOGO completes.
1410 lpfc_device_rm_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1411 void *arg, uint32_t evt)
1413 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1415 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1416 spin_lock_irq(shost->host_lock);
1417 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
1418 spin_unlock_irq(shost->host_lock);
1419 return ndlp->nlp_state;
1421 /* software abort outstanding PLOGI */
1422 lpfc_els_abort(vport->phba, ndlp);
1424 lpfc_drop_node(vport, ndlp);
1425 return NLP_STE_FREED_NODE;
1430 /*! lpfc_device_recov_prli_issue
1441 * The routine is envoked when the state of a device is unknown, like
1442 * during a link down. We should remove the nodelist entry from the
1443 * unmapped list, issue a UNREG_LOGIN, do a software abort of the
1444 * outstanding PRLI command, then free the node entry.
1447 lpfc_device_recov_prli_issue(struct lpfc_vport *vport,
1448 struct lpfc_nodelist *ndlp,
1452 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1453 struct lpfc_hba *phba = vport->phba;
1455 /* Don't do anything that will mess up processing of the
1458 if (vport->fc_flag & FC_RSCN_DEFERRED)
1459 return ndlp->nlp_state;
1461 /* software abort outstanding PRLI */
1462 lpfc_els_abort(phba, ndlp);
1464 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
1465 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1466 spin_lock_irq(shost->host_lock);
1467 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
1468 spin_unlock_irq(shost->host_lock);
1469 lpfc_disc_set_adisc(vport, ndlp);
1470 return ndlp->nlp_state;
1474 lpfc_rcv_plogi_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1475 void *arg, uint32_t evt)
1477 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1479 lpfc_rcv_plogi(vport, ndlp, cmdiocb);
1480 return ndlp->nlp_state;
1484 lpfc_rcv_prli_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1485 void *arg, uint32_t evt)
1487 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1489 lpfc_rcv_prli(vport, ndlp, cmdiocb);
1490 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
1491 return ndlp->nlp_state;
1495 lpfc_rcv_logo_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1496 void *arg, uint32_t evt)
1498 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1500 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
1501 return ndlp->nlp_state;
1505 lpfc_rcv_padisc_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1506 void *arg, uint32_t evt)
1508 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1510 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
1511 return ndlp->nlp_state;
1515 lpfc_rcv_prlo_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1516 void *arg, uint32_t evt)
1518 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1520 lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL);
1521 return ndlp->nlp_state;
1525 lpfc_device_recov_unmap_node(struct lpfc_vport *vport,
1526 struct lpfc_nodelist *ndlp,
1530 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1532 ndlp->nlp_prev_state = NLP_STE_UNMAPPED_NODE;
1533 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1534 spin_lock_irq(shost->host_lock);
1535 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
1536 spin_unlock_irq(shost->host_lock);
1537 lpfc_disc_set_adisc(vport, ndlp);
1539 return ndlp->nlp_state;
1543 lpfc_rcv_plogi_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1544 void *arg, uint32_t evt)
1546 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1548 lpfc_rcv_plogi(vport, ndlp, cmdiocb);
1549 return ndlp->nlp_state;
1553 lpfc_rcv_prli_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1554 void *arg, uint32_t evt)
1556 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1558 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
1559 return ndlp->nlp_state;
1563 lpfc_rcv_logo_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1564 void *arg, uint32_t evt)
1566 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1568 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
1569 return ndlp->nlp_state;
1573 lpfc_rcv_padisc_mapped_node(struct lpfc_vport *vport,
1574 struct lpfc_nodelist *ndlp,
1575 void *arg, uint32_t evt)
1577 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1579 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
1580 return ndlp->nlp_state;
1584 lpfc_rcv_prlo_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1585 void *arg, uint32_t evt)
1587 struct lpfc_hba *phba = vport->phba;
1588 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1590 /* flush the target */
1591 lpfc_sli_abort_iocb(vport, &phba->sli.ring[phba->sli.fcp_ring],
1592 ndlp->nlp_sid, 0, LPFC_CTX_TGT);
1594 /* Treat like rcv logo */
1595 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_PRLO);
1596 return ndlp->nlp_state;
1600 lpfc_device_recov_mapped_node(struct lpfc_vport *vport,
1601 struct lpfc_nodelist *ndlp,
1605 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1607 ndlp->nlp_prev_state = NLP_STE_MAPPED_NODE;
1608 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1609 spin_lock_irq(shost->host_lock);
1610 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
1611 spin_unlock_irq(shost->host_lock);
1612 lpfc_disc_set_adisc(vport, ndlp);
1613 return ndlp->nlp_state;
1617 lpfc_rcv_plogi_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1618 void *arg, uint32_t evt)
1620 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1621 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1623 /* Ignore PLOGI if we have an outstanding LOGO */
1624 if (ndlp->nlp_flag & (NLP_LOGO_SND | NLP_LOGO_ACC)) {
1625 return ndlp->nlp_state;
1628 if (lpfc_rcv_plogi(vport, ndlp, cmdiocb)) {
1629 spin_lock_irq(shost->host_lock);
1630 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
1631 spin_unlock_irq(shost->host_lock);
1632 return ndlp->nlp_state;
1635 /* send PLOGI immediately, move to PLOGI issue state */
1636 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
1637 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
1638 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
1639 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
1642 return ndlp->nlp_state;
1646 lpfc_rcv_prli_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1647 void *arg, uint32_t evt)
1649 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1650 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1653 memset(&stat, 0, sizeof (struct ls_rjt));
1654 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
1655 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
1656 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
1658 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
1659 if (ndlp->nlp_flag & NLP_NPR_ADISC) {
1660 spin_lock_irq(shost->host_lock);
1661 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
1662 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
1663 spin_unlock_irq(shost->host_lock);
1664 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
1665 lpfc_issue_els_adisc(vport, ndlp, 0);
1667 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
1668 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
1669 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
1672 return ndlp->nlp_state;
1676 lpfc_rcv_logo_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1677 void *arg, uint32_t evt)
1679 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1681 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
1682 return ndlp->nlp_state;
1686 lpfc_rcv_padisc_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1687 void *arg, uint32_t evt)
1689 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1691 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
1694 * Do not start discovery if discovery is about to start
1695 * or discovery in progress for this node. Starting discovery
1696 * here will affect the counting of discovery threads.
1698 if (!(ndlp->nlp_flag & NLP_DELAY_TMO) &&
1699 !(ndlp->nlp_flag & NLP_NPR_2B_DISC)) {
1700 if (ndlp->nlp_flag & NLP_NPR_ADISC) {
1701 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
1702 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
1703 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
1704 lpfc_issue_els_adisc(vport, ndlp, 0);
1706 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
1707 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
1708 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
1711 return ndlp->nlp_state;
1715 lpfc_rcv_prlo_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1716 void *arg, uint32_t evt)
1718 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1719 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1721 spin_lock_irq(shost->host_lock);
1722 ndlp->nlp_flag |= NLP_LOGO_ACC;
1723 spin_unlock_irq(shost->host_lock);
1725 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
1727 if ((ndlp->nlp_flag & NLP_DELAY_TMO) == 0) {
1728 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ * 1);
1729 spin_lock_irq(shost->host_lock);
1730 ndlp->nlp_flag |= NLP_DELAY_TMO;
1731 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
1732 spin_unlock_irq(shost->host_lock);
1733 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
1735 spin_lock_irq(shost->host_lock);
1736 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
1737 spin_unlock_irq(shost->host_lock);
1739 return ndlp->nlp_state;
1743 lpfc_cmpl_plogi_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1744 void *arg, uint32_t evt)
1746 struct lpfc_iocbq *cmdiocb, *rspiocb;
1749 cmdiocb = (struct lpfc_iocbq *) arg;
1750 rspiocb = cmdiocb->context_un.rsp_iocb;
1752 irsp = &rspiocb->iocb;
1753 if (irsp->ulpStatus) {
1754 lpfc_drop_node(vport, ndlp);
1755 return NLP_STE_FREED_NODE;
1757 return ndlp->nlp_state;
1761 lpfc_cmpl_prli_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1762 void *arg, uint32_t evt)
1764 struct lpfc_iocbq *cmdiocb, *rspiocb;
1767 cmdiocb = (struct lpfc_iocbq *) arg;
1768 rspiocb = cmdiocb->context_un.rsp_iocb;
1770 irsp = &rspiocb->iocb;
1771 if (irsp->ulpStatus && (ndlp->nlp_flag & NLP_NODEV_REMOVE)) {
1772 lpfc_drop_node(vport, ndlp);
1773 return NLP_STE_FREED_NODE;
1775 return ndlp->nlp_state;
1779 lpfc_cmpl_logo_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1780 void *arg, uint32_t evt)
1782 lpfc_unreg_rpi(vport, ndlp);
1783 /* This routine does nothing, just return the current state */
1784 return ndlp->nlp_state;
1788 lpfc_cmpl_adisc_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1789 void *arg, uint32_t evt)
1791 struct lpfc_iocbq *cmdiocb, *rspiocb;
1794 cmdiocb = (struct lpfc_iocbq *) arg;
1795 rspiocb = cmdiocb->context_un.rsp_iocb;
1797 irsp = &rspiocb->iocb;
1798 if (irsp->ulpStatus && (ndlp->nlp_flag & NLP_NODEV_REMOVE)) {
1799 lpfc_drop_node(vport, ndlp);
1800 return NLP_STE_FREED_NODE;
1802 return ndlp->nlp_state;
1806 lpfc_cmpl_reglogin_npr_node(struct lpfc_vport *vport,
1807 struct lpfc_nodelist *ndlp,
1808 void *arg, uint32_t evt)
1810 LPFC_MBOXQ_t *pmb = (LPFC_MBOXQ_t *) arg;
1811 MAILBOX_t *mb = &pmb->mb;
1814 ndlp->nlp_rpi = mb->un.varWords[0];
1816 if (ndlp->nlp_flag & NLP_NODEV_REMOVE) {
1817 lpfc_drop_node(vport, ndlp);
1818 return NLP_STE_FREED_NODE;
1821 return ndlp->nlp_state;
1825 lpfc_device_rm_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1826 void *arg, uint32_t evt)
1828 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1830 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1831 spin_lock_irq(shost->host_lock);
1832 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
1833 spin_unlock_irq(shost->host_lock);
1834 return ndlp->nlp_state;
1836 lpfc_drop_node(vport, ndlp);
1837 return NLP_STE_FREED_NODE;
1841 lpfc_device_recov_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1842 void *arg, uint32_t evt)
1844 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1846 /* Don't do anything that will mess up processing of the
1849 if (vport->fc_flag & FC_RSCN_DEFERRED)
1850 return ndlp->nlp_state;
1852 spin_lock_irq(shost->host_lock);
1853 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
1854 spin_unlock_irq(shost->host_lock);
1855 if (ndlp->nlp_flag & NLP_DELAY_TMO) {
1856 lpfc_cancel_retry_delay_tmo(vport, ndlp);
1858 return ndlp->nlp_state;
1862 /* This next section defines the NPort Discovery State Machine */
1864 /* There are 4 different double linked lists nodelist entries can reside on.
1865 * The plogi list and adisc list are used when Link Up discovery or RSCN
1866 * processing is needed. Each list holds the nodes that we will send PLOGI
1867 * or ADISC on. These lists will keep track of what nodes will be effected
1868 * by an RSCN, or a Link Up (Typically, all nodes are effected on Link Up).
1869 * The unmapped_list will contain all nodes that we have successfully logged
1870 * into at the Fibre Channel level. The mapped_list will contain all nodes
1871 * that are mapped FCP targets.
1874 * The bind list is a list of undiscovered (potentially non-existent) nodes
1875 * that we have saved binding information on. This information is used when
1876 * nodes transition from the unmapped to the mapped list.
1878 /* For UNUSED_NODE state, the node has just been allocated .
1879 * For PLOGI_ISSUE and REG_LOGIN_ISSUE, the node is on
1880 * the PLOGI list. For REG_LOGIN_COMPL, the node is taken off the PLOGI list
1881 * and put on the unmapped list. For ADISC processing, the node is taken off
1882 * the ADISC list and placed on either the mapped or unmapped list (depending
1883 * on its previous state). Once on the unmapped list, a PRLI is issued and the
1884 * state changed to PRLI_ISSUE. When the PRLI completion occurs, the state is
1885 * changed to UNMAPPED_NODE. If the completion indicates a mapped
1886 * node, the node is taken off the unmapped list. The binding list is checked
1887 * for a valid binding, or a binding is automatically assigned. If binding
1888 * assignment is unsuccessful, the node is left on the unmapped list. If
1889 * binding assignment is successful, the associated binding list entry (if
1890 * any) is removed, and the node is placed on the mapped list.
1893 * For a Link Down, all nodes on the ADISC, PLOGI, unmapped or mapped
1894 * lists will receive a DEVICE_RECOVERY event. If the linkdown or devloss timers
1895 * expire, all effected nodes will receive a DEVICE_RM event.
1898 * For a Link Up or RSCN, all nodes will move from the mapped / unmapped lists
1899 * to either the ADISC or PLOGI list. After a Nameserver query or ALPA loopmap
1900 * check, additional nodes may be added or removed (via DEVICE_RM) to / from
1901 * the PLOGI or ADISC lists. Once the PLOGI and ADISC lists are populated,
1902 * we will first process the ADISC list. 32 entries are processed initially and
1903 * ADISC is initited for each one. Completions / Events for each node are
1904 * funnelled thru the state machine. As each node finishes ADISC processing, it
1905 * starts ADISC for any nodes waiting for ADISC processing. If no nodes are
1906 * waiting, and the ADISC list count is identically 0, then we are done. For
1907 * Link Up discovery, since all nodes on the PLOGI list are UNREG_LOGIN'ed, we
1908 * can issue a CLEAR_LA and reenable Link Events. Next we will process the PLOGI
1909 * list. 32 entries are processed initially and PLOGI is initited for each one.
1910 * Completions / Events for each node are funnelled thru the state machine. As
1911 * each node finishes PLOGI processing, it starts PLOGI for any nodes waiting
1912 * for PLOGI processing. If no nodes are waiting, and the PLOGI list count is
1913 * indentically 0, then we are done. We have now completed discovery / RSCN
1914 * handling. Upon completion, ALL nodes should be on either the mapped or
1918 static uint32_t (*lpfc_disc_action[NLP_STE_MAX_STATE * NLP_EVT_MAX_EVENT])
1919 (struct lpfc_vport *, struct lpfc_nodelist *, void *, uint32_t) = {
1920 /* Action routine Event Current State */
1921 lpfc_rcv_plogi_unused_node, /* RCV_PLOGI UNUSED_NODE */
1922 lpfc_rcv_els_unused_node, /* RCV_PRLI */
1923 lpfc_rcv_logo_unused_node, /* RCV_LOGO */
1924 lpfc_rcv_els_unused_node, /* RCV_ADISC */
1925 lpfc_rcv_els_unused_node, /* RCV_PDISC */
1926 lpfc_rcv_els_unused_node, /* RCV_PRLO */
1927 lpfc_disc_illegal, /* CMPL_PLOGI */
1928 lpfc_disc_illegal, /* CMPL_PRLI */
1929 lpfc_cmpl_logo_unused_node, /* CMPL_LOGO */
1930 lpfc_disc_illegal, /* CMPL_ADISC */
1931 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
1932 lpfc_device_rm_unused_node, /* DEVICE_RM */
1933 lpfc_disc_illegal, /* DEVICE_RECOVERY */
1935 lpfc_rcv_plogi_plogi_issue, /* RCV_PLOGI PLOGI_ISSUE */
1936 lpfc_rcv_prli_plogi_issue, /* RCV_PRLI */
1937 lpfc_rcv_logo_plogi_issue, /* RCV_LOGO */
1938 lpfc_rcv_els_plogi_issue, /* RCV_ADISC */
1939 lpfc_rcv_els_plogi_issue, /* RCV_PDISC */
1940 lpfc_rcv_els_plogi_issue, /* RCV_PRLO */
1941 lpfc_cmpl_plogi_plogi_issue, /* CMPL_PLOGI */
1942 lpfc_disc_illegal, /* CMPL_PRLI */
1943 lpfc_disc_illegal, /* CMPL_LOGO */
1944 lpfc_disc_illegal, /* CMPL_ADISC */
1945 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
1946 lpfc_device_rm_plogi_issue, /* DEVICE_RM */
1947 lpfc_device_recov_plogi_issue, /* DEVICE_RECOVERY */
1949 lpfc_rcv_plogi_adisc_issue, /* RCV_PLOGI ADISC_ISSUE */
1950 lpfc_rcv_prli_adisc_issue, /* RCV_PRLI */
1951 lpfc_rcv_logo_adisc_issue, /* RCV_LOGO */
1952 lpfc_rcv_padisc_adisc_issue, /* RCV_ADISC */
1953 lpfc_rcv_padisc_adisc_issue, /* RCV_PDISC */
1954 lpfc_rcv_prlo_adisc_issue, /* RCV_PRLO */
1955 lpfc_disc_illegal, /* CMPL_PLOGI */
1956 lpfc_disc_illegal, /* CMPL_PRLI */
1957 lpfc_disc_illegal, /* CMPL_LOGO */
1958 lpfc_cmpl_adisc_adisc_issue, /* CMPL_ADISC */
1959 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
1960 lpfc_device_rm_adisc_issue, /* DEVICE_RM */
1961 lpfc_device_recov_adisc_issue, /* DEVICE_RECOVERY */
1963 lpfc_rcv_plogi_reglogin_issue, /* RCV_PLOGI REG_LOGIN_ISSUE */
1964 lpfc_rcv_prli_reglogin_issue, /* RCV_PLOGI */
1965 lpfc_rcv_logo_reglogin_issue, /* RCV_LOGO */
1966 lpfc_rcv_padisc_reglogin_issue, /* RCV_ADISC */
1967 lpfc_rcv_padisc_reglogin_issue, /* RCV_PDISC */
1968 lpfc_rcv_prlo_reglogin_issue, /* RCV_PRLO */
1969 lpfc_disc_illegal, /* CMPL_PLOGI */
1970 lpfc_disc_illegal, /* CMPL_PRLI */
1971 lpfc_disc_illegal, /* CMPL_LOGO */
1972 lpfc_disc_illegal, /* CMPL_ADISC */
1973 lpfc_cmpl_reglogin_reglogin_issue,/* CMPL_REG_LOGIN */
1974 lpfc_device_rm_reglogin_issue, /* DEVICE_RM */
1975 lpfc_device_recov_reglogin_issue,/* DEVICE_RECOVERY */
1977 lpfc_rcv_plogi_prli_issue, /* RCV_PLOGI PRLI_ISSUE */
1978 lpfc_rcv_prli_prli_issue, /* RCV_PRLI */
1979 lpfc_rcv_logo_prli_issue, /* RCV_LOGO */
1980 lpfc_rcv_padisc_prli_issue, /* RCV_ADISC */
1981 lpfc_rcv_padisc_prli_issue, /* RCV_PDISC */
1982 lpfc_rcv_prlo_prli_issue, /* RCV_PRLO */
1983 lpfc_disc_illegal, /* CMPL_PLOGI */
1984 lpfc_cmpl_prli_prli_issue, /* CMPL_PRLI */
1985 lpfc_disc_illegal, /* CMPL_LOGO */
1986 lpfc_disc_illegal, /* CMPL_ADISC */
1987 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
1988 lpfc_device_rm_prli_issue, /* DEVICE_RM */
1989 lpfc_device_recov_prli_issue, /* DEVICE_RECOVERY */
1991 lpfc_rcv_plogi_unmap_node, /* RCV_PLOGI UNMAPPED_NODE */
1992 lpfc_rcv_prli_unmap_node, /* RCV_PRLI */
1993 lpfc_rcv_logo_unmap_node, /* RCV_LOGO */
1994 lpfc_rcv_padisc_unmap_node, /* RCV_ADISC */
1995 lpfc_rcv_padisc_unmap_node, /* RCV_PDISC */
1996 lpfc_rcv_prlo_unmap_node, /* RCV_PRLO */
1997 lpfc_disc_illegal, /* CMPL_PLOGI */
1998 lpfc_disc_illegal, /* CMPL_PRLI */
1999 lpfc_disc_illegal, /* CMPL_LOGO */
2000 lpfc_disc_illegal, /* CMPL_ADISC */
2001 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2002 lpfc_disc_illegal, /* DEVICE_RM */
2003 lpfc_device_recov_unmap_node, /* DEVICE_RECOVERY */
2005 lpfc_rcv_plogi_mapped_node, /* RCV_PLOGI MAPPED_NODE */
2006 lpfc_rcv_prli_mapped_node, /* RCV_PRLI */
2007 lpfc_rcv_logo_mapped_node, /* RCV_LOGO */
2008 lpfc_rcv_padisc_mapped_node, /* RCV_ADISC */
2009 lpfc_rcv_padisc_mapped_node, /* RCV_PDISC */
2010 lpfc_rcv_prlo_mapped_node, /* RCV_PRLO */
2011 lpfc_disc_illegal, /* CMPL_PLOGI */
2012 lpfc_disc_illegal, /* CMPL_PRLI */
2013 lpfc_disc_illegal, /* CMPL_LOGO */
2014 lpfc_disc_illegal, /* CMPL_ADISC */
2015 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2016 lpfc_disc_illegal, /* DEVICE_RM */
2017 lpfc_device_recov_mapped_node, /* DEVICE_RECOVERY */
2019 lpfc_rcv_plogi_npr_node, /* RCV_PLOGI NPR_NODE */
2020 lpfc_rcv_prli_npr_node, /* RCV_PRLI */
2021 lpfc_rcv_logo_npr_node, /* RCV_LOGO */
2022 lpfc_rcv_padisc_npr_node, /* RCV_ADISC */
2023 lpfc_rcv_padisc_npr_node, /* RCV_PDISC */
2024 lpfc_rcv_prlo_npr_node, /* RCV_PRLO */
2025 lpfc_cmpl_plogi_npr_node, /* CMPL_PLOGI */
2026 lpfc_cmpl_prli_npr_node, /* CMPL_PRLI */
2027 lpfc_cmpl_logo_npr_node, /* CMPL_LOGO */
2028 lpfc_cmpl_adisc_npr_node, /* CMPL_ADISC */
2029 lpfc_cmpl_reglogin_npr_node, /* CMPL_REG_LOGIN */
2030 lpfc_device_rm_npr_node, /* DEVICE_RM */
2031 lpfc_device_recov_npr_node, /* DEVICE_RECOVERY */
2035 lpfc_disc_state_machine(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2036 void *arg, uint32_t evt)
2038 uint32_t cur_state, rc;
2039 uint32_t(*func) (struct lpfc_vport *, struct lpfc_nodelist *, void *,
2043 cur_state = ndlp->nlp_state;
2045 /* DSM in event <evt> on NPort <nlp_DID> in state <cur_state> */
2046 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2047 "0211 DSM in event x%x on NPort x%x in "
2048 "state %d Data: x%x\n",
2049 evt, ndlp->nlp_DID, cur_state, ndlp->nlp_flag);
2051 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_DSM,
2052 "DSM in: evt:%d ste:%d did:x%x",
2053 evt, cur_state, ndlp->nlp_DID);
2055 func = lpfc_disc_action[(cur_state * NLP_EVT_MAX_EVENT) + evt];
2056 rc = (func) (vport, ndlp, arg, evt);
2058 /* DSM out state <rc> on NPort <nlp_DID> */
2059 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2060 "0212 DSM out state %d on NPort x%x Data: x%x\n",
2061 rc, ndlp->nlp_DID, ndlp->nlp_flag);
2063 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_DSM,
2064 "DSM out: ste:%d did:x%x flg:x%x",
2065 rc, ndlp->nlp_DID, ndlp->nlp_flag);