1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2004-2009 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/slab.h>
25 #include <linux/interrupt.h>
27 #include <scsi/scsi.h>
28 #include <scsi/scsi_device.h>
29 #include <scsi/scsi_host.h>
30 #include <scsi/scsi_transport_fc.h>
35 #include "lpfc_sli4.h"
37 #include "lpfc_disc.h"
38 #include "lpfc_scsi.h"
40 #include "lpfc_logmsg.h"
41 #include "lpfc_crtn.h"
42 #include "lpfc_vport.h"
43 #include "lpfc_debugfs.h"
46 /* Called to verify a rcv'ed ADISC was intended for us. */
48 lpfc_check_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
49 struct lpfc_name *nn, struct lpfc_name *pn)
51 /* Compare the ADISC rsp WWNN / WWPN matches our internal node
52 * table entry for that node.
54 if (memcmp(nn, &ndlp->nlp_nodename, sizeof (struct lpfc_name)))
57 if (memcmp(pn, &ndlp->nlp_portname, sizeof (struct lpfc_name)))
60 /* we match, return success */
65 lpfc_check_sparm(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
66 struct serv_parm *sp, uint32_t class, int flogi)
68 volatile struct serv_parm *hsp = &vport->fc_sparam;
69 uint16_t hsp_value, ssp_value = 0;
72 * The receive data field size and buffer-to-buffer receive data field
73 * size entries are 16 bits but are represented as two 8-bit fields in
74 * the driver data structure to account for rsvd bits and other control
75 * bits. Reconstruct and compare the fields as a 16-bit values before
76 * correcting the byte values.
78 if (sp->cls1.classValid) {
80 hsp_value = ((hsp->cls1.rcvDataSizeMsb << 8) |
81 hsp->cls1.rcvDataSizeLsb);
82 ssp_value = ((sp->cls1.rcvDataSizeMsb << 8) |
83 sp->cls1.rcvDataSizeLsb);
85 goto bad_service_param;
86 if (ssp_value > hsp_value) {
87 sp->cls1.rcvDataSizeLsb =
88 hsp->cls1.rcvDataSizeLsb;
89 sp->cls1.rcvDataSizeMsb =
90 hsp->cls1.rcvDataSizeMsb;
93 } else if (class == CLASS1)
94 goto bad_service_param;
95 if (sp->cls2.classValid) {
97 hsp_value = ((hsp->cls2.rcvDataSizeMsb << 8) |
98 hsp->cls2.rcvDataSizeLsb);
99 ssp_value = ((sp->cls2.rcvDataSizeMsb << 8) |
100 sp->cls2.rcvDataSizeLsb);
102 goto bad_service_param;
103 if (ssp_value > hsp_value) {
104 sp->cls2.rcvDataSizeLsb =
105 hsp->cls2.rcvDataSizeLsb;
106 sp->cls2.rcvDataSizeMsb =
107 hsp->cls2.rcvDataSizeMsb;
110 } else if (class == CLASS2)
111 goto bad_service_param;
112 if (sp->cls3.classValid) {
114 hsp_value = ((hsp->cls3.rcvDataSizeMsb << 8) |
115 hsp->cls3.rcvDataSizeLsb);
116 ssp_value = ((sp->cls3.rcvDataSizeMsb << 8) |
117 sp->cls3.rcvDataSizeLsb);
119 goto bad_service_param;
120 if (ssp_value > hsp_value) {
121 sp->cls3.rcvDataSizeLsb =
122 hsp->cls3.rcvDataSizeLsb;
123 sp->cls3.rcvDataSizeMsb =
124 hsp->cls3.rcvDataSizeMsb;
127 } else if (class == CLASS3)
128 goto bad_service_param;
131 * Preserve the upper four bits of the MSB from the PLOGI response.
132 * These bits contain the Buffer-to-Buffer State Change Number
133 * from the target and need to be passed to the FW.
135 hsp_value = (hsp->cmn.bbRcvSizeMsb << 8) | hsp->cmn.bbRcvSizeLsb;
136 ssp_value = (sp->cmn.bbRcvSizeMsb << 8) | sp->cmn.bbRcvSizeLsb;
137 if (ssp_value > hsp_value) {
138 sp->cmn.bbRcvSizeLsb = hsp->cmn.bbRcvSizeLsb;
139 sp->cmn.bbRcvSizeMsb = (sp->cmn.bbRcvSizeMsb & 0xF0) |
140 (hsp->cmn.bbRcvSizeMsb & 0x0F);
143 memcpy(&ndlp->nlp_nodename, &sp->nodeName, sizeof (struct lpfc_name));
144 memcpy(&ndlp->nlp_portname, &sp->portName, sizeof (struct lpfc_name));
147 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
149 "(%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x) sent "
150 "invalid service parameters. Ignoring device.\n",
152 sp->nodeName.u.wwn[0], sp->nodeName.u.wwn[1],
153 sp->nodeName.u.wwn[2], sp->nodeName.u.wwn[3],
154 sp->nodeName.u.wwn[4], sp->nodeName.u.wwn[5],
155 sp->nodeName.u.wwn[6], sp->nodeName.u.wwn[7]);
160 lpfc_check_elscmpl_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
161 struct lpfc_iocbq *rspiocb)
163 struct lpfc_dmabuf *pcmd, *prsp;
168 irsp = &rspiocb->iocb;
169 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
171 /* For lpfc_els_abort, context2 could be zero'ed to delay
172 * freeing associated memory till after ABTS completes.
175 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf,
178 lp = (uint32_t *) prsp->virt;
179 ptr = (void *)((uint8_t *)lp + sizeof(uint32_t));
182 /* Force ulpStatus error since we are returning NULL ptr */
183 if (!(irsp->ulpStatus)) {
184 irsp->ulpStatus = IOSTAT_LOCAL_REJECT;
185 irsp->un.ulpWord[4] = IOERR_SLI_ABORTED;
194 * Free resources / clean up outstanding I/Os
195 * associated with a LPFC_NODELIST entry. This
196 * routine effectively results in a "software abort".
199 lpfc_els_abort(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp)
201 LIST_HEAD(completions);
202 struct lpfc_sli *psli = &phba->sli;
203 struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING];
204 struct lpfc_iocbq *iocb, *next_iocb;
206 /* Abort outstanding I/O on NPort <nlp_DID> */
207 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_DISCOVERY,
208 "0205 Abort outstanding I/O on NPort x%x "
209 "Data: x%x x%x x%x\n",
210 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
213 lpfc_fabric_abort_nport(ndlp);
215 /* First check the txq */
216 spin_lock_irq(&phba->hbalock);
217 list_for_each_entry_safe(iocb, next_iocb, &pring->txq, 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 /* It matches, so deque and call compl with anp error */
221 list_move_tail(&iocb->list, &completions);
226 /* Next check the txcmplq */
227 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
228 /* Check to see if iocb matches the nport we are looking for */
229 if (lpfc_check_sli_ndlp(phba, pring, iocb, ndlp)) {
230 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
233 spin_unlock_irq(&phba->hbalock);
235 /* Cancel all the IOCBs from the completions list */
236 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
239 lpfc_cancel_retry_delay_tmo(phba->pport, ndlp);
244 lpfc_rcv_plogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
245 struct lpfc_iocbq *cmdiocb)
247 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
248 struct lpfc_hba *phba = vport->phba;
249 struct lpfc_dmabuf *pcmd;
252 struct serv_parm *sp;
257 memset(&stat, 0, sizeof (struct ls_rjt));
258 if (vport->port_state <= LPFC_FDISC) {
259 /* Before responding to PLOGI, check for pt2pt mode.
260 * If we are pt2pt, with an outstanding FLOGI, abort
261 * the FLOGI and resend it first.
263 if (vport->fc_flag & FC_PT2PT) {
264 lpfc_els_abort_flogi(phba);
265 if (!(vport->fc_flag & FC_PT2PT_PLOGI)) {
266 /* If the other side is supposed to initiate
267 * the PLOGI anyway, just ACC it now and
268 * move on with discovery.
270 phba->fc_edtov = FF_DEF_EDTOV;
271 phba->fc_ratov = FF_DEF_RATOV;
272 /* Start discovery - this should just do
274 lpfc_disc_start(vport);
276 lpfc_initial_flogi(vport);
278 stat.un.b.lsRjtRsnCode = LSRJT_LOGICAL_BSY;
279 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
280 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb,
285 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
286 lp = (uint32_t *) pcmd->virt;
287 sp = (struct serv_parm *) ((uint8_t *) lp + sizeof (uint32_t));
288 if (wwn_to_u64(sp->portName.u.wwn) == 0) {
289 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
290 "0140 PLOGI Reject: invalid nname\n");
291 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
292 stat.un.b.lsRjtRsnCodeExp = LSEXP_INVALID_PNAME;
293 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
297 if (wwn_to_u64(sp->nodeName.u.wwn) == 0) {
298 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
299 "0141 PLOGI Reject: invalid pname\n");
300 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
301 stat.un.b.lsRjtRsnCodeExp = LSEXP_INVALID_NNAME;
302 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
306 if ((lpfc_check_sparm(vport, ndlp, sp, CLASS3, 0) == 0)) {
307 /* Reject this request because invalid parameters */
308 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
309 stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
310 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
314 icmd = &cmdiocb->iocb;
316 /* PLOGI chkparm OK */
317 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
318 "0114 PLOGI chkparm OK Data: x%x x%x x%x x%x\n",
319 ndlp->nlp_DID, ndlp->nlp_state, ndlp->nlp_flag,
322 if (vport->cfg_fcp_class == 2 && sp->cls2.classValid)
323 ndlp->nlp_fcp_info |= CLASS2;
325 ndlp->nlp_fcp_info |= CLASS3;
327 ndlp->nlp_class_sup = 0;
328 if (sp->cls1.classValid)
329 ndlp->nlp_class_sup |= FC_COS_CLASS1;
330 if (sp->cls2.classValid)
331 ndlp->nlp_class_sup |= FC_COS_CLASS2;
332 if (sp->cls3.classValid)
333 ndlp->nlp_class_sup |= FC_COS_CLASS3;
334 if (sp->cls4.classValid)
335 ndlp->nlp_class_sup |= FC_COS_CLASS4;
337 ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) | sp->cmn.bbRcvSizeLsb;
339 /* no need to reg_login if we are already in one of these states */
340 switch (ndlp->nlp_state) {
341 case NLP_STE_NPR_NODE:
342 if (!(ndlp->nlp_flag & NLP_NPR_ADISC))
344 case NLP_STE_REG_LOGIN_ISSUE:
345 case NLP_STE_PRLI_ISSUE:
346 case NLP_STE_UNMAPPED_NODE:
347 case NLP_STE_MAPPED_NODE:
348 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp, NULL);
352 if ((vport->fc_flag & FC_PT2PT) &&
353 !(vport->fc_flag & FC_PT2PT_PLOGI)) {
354 /* rcv'ed PLOGI decides what our NPortId will be */
355 vport->fc_myDID = icmd->un.rcvels.parmRo;
356 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
359 lpfc_config_link(phba, mbox);
360 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
362 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
363 if (rc == MBX_NOT_FINISHED) {
364 mempool_free(mbox, phba->mbox_mem_pool);
368 lpfc_can_disctmo(vport);
370 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
374 rc = lpfc_reg_rpi(phba, vport->vpi, icmd->un.rcvels.remoteID,
375 (uint8_t *) sp, mbox, 0);
377 mempool_free(mbox, phba->mbox_mem_pool);
381 /* ACC PLOGI rsp command needs to execute first,
382 * queue this mbox command to be processed later.
384 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
386 * mbox->context2 = lpfc_nlp_get(ndlp) deferred until mailbox
387 * command issued in lpfc_cmpl_els_acc().
390 spin_lock_irq(shost->host_lock);
391 ndlp->nlp_flag |= (NLP_ACC_REGLOGIN | NLP_RCV_PLOGI);
392 spin_unlock_irq(shost->host_lock);
395 * If there is an outstanding PLOGI issued, abort it before
396 * sending ACC rsp for received PLOGI. If pending plogi
397 * is not canceled here, the plogi will be rejected by
398 * remote port and will be retried. On a configuration with
399 * single discovery thread, this will cause a huge delay in
400 * discovery. Also this will cause multiple state machines
401 * running in parallel for this node.
403 if (ndlp->nlp_state == NLP_STE_PLOGI_ISSUE) {
404 /* software abort outstanding PLOGI */
405 lpfc_els_abort(phba, ndlp);
408 if ((vport->port_type == LPFC_NPIV_PORT &&
409 vport->cfg_restrict_login)) {
411 /* In order to preserve RPIs, we want to cleanup
412 * the default RPI the firmware created to rcv
413 * this ELS request. The only way to do this is
414 * to register, then unregister the RPI.
416 spin_lock_irq(shost->host_lock);
417 ndlp->nlp_flag |= NLP_RM_DFLT_RPI;
418 spin_unlock_irq(shost->host_lock);
419 stat.un.b.lsRjtRsnCode = LSRJT_INVALID_CMD;
420 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
421 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb,
425 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp, mbox);
428 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
429 stat.un.b.lsRjtRsnCodeExp = LSEXP_OUT_OF_RESOURCE;
430 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
435 lpfc_rcv_padisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
436 struct lpfc_iocbq *cmdiocb)
438 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
439 struct lpfc_dmabuf *pcmd;
440 struct serv_parm *sp;
441 struct lpfc_name *pnn, *ppn;
448 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
449 lp = (uint32_t *) pcmd->virt;
452 if (cmd == ELS_CMD_ADISC) {
454 pnn = (struct lpfc_name *) & ap->nodeName;
455 ppn = (struct lpfc_name *) & ap->portName;
457 sp = (struct serv_parm *) lp;
458 pnn = (struct lpfc_name *) & sp->nodeName;
459 ppn = (struct lpfc_name *) & sp->portName;
462 icmd = &cmdiocb->iocb;
463 if (icmd->ulpStatus == 0 && lpfc_check_adisc(vport, ndlp, pnn, ppn)) {
464 if (cmd == ELS_CMD_ADISC) {
465 lpfc_els_rsp_adisc_acc(vport, cmdiocb, ndlp);
467 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp,
472 /* Reject this request because invalid parameters */
473 stat.un.b.lsRjtRsvd0 = 0;
474 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
475 stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
476 stat.un.b.vendorUnique = 0;
477 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
480 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ);
482 spin_lock_irq(shost->host_lock);
483 ndlp->nlp_flag |= NLP_DELAY_TMO;
484 spin_unlock_irq(shost->host_lock);
485 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
486 ndlp->nlp_prev_state = ndlp->nlp_state;
487 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
492 lpfc_rcv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
493 struct lpfc_iocbq *cmdiocb, uint32_t els_cmd)
495 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
497 /* Put ndlp in NPR state with 1 sec timeout for plogi, ACC logo */
498 /* Only call LOGO ACC for first LOGO, this avoids sending unnecessary
499 * PLOGIs during LOGO storms from a device.
501 spin_lock_irq(shost->host_lock);
502 ndlp->nlp_flag |= NLP_LOGO_ACC;
503 spin_unlock_irq(shost->host_lock);
504 if (els_cmd == ELS_CMD_PRLO)
505 lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL);
507 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
508 if ((ndlp->nlp_DID == Fabric_DID) &&
509 vport->port_type == LPFC_NPIV_PORT) {
510 lpfc_linkdown_port(vport);
511 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ * 1);
512 spin_lock_irq(shost->host_lock);
513 ndlp->nlp_flag |= NLP_DELAY_TMO;
514 spin_unlock_irq(shost->host_lock);
516 ndlp->nlp_last_elscmd = ELS_CMD_FDISC;
517 } else if ((!(ndlp->nlp_type & NLP_FABRIC) &&
518 ((ndlp->nlp_type & NLP_FCP_TARGET) ||
519 !(ndlp->nlp_type & NLP_FCP_INITIATOR))) ||
520 (ndlp->nlp_state == NLP_STE_ADISC_ISSUE)) {
521 /* Only try to re-login if this is NOT a Fabric Node */
522 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ * 1);
523 spin_lock_irq(shost->host_lock);
524 ndlp->nlp_flag |= NLP_DELAY_TMO;
525 spin_unlock_irq(shost->host_lock);
527 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
529 ndlp->nlp_prev_state = ndlp->nlp_state;
530 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
532 spin_lock_irq(shost->host_lock);
533 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
534 spin_unlock_irq(shost->host_lock);
535 /* The driver has to wait until the ACC completes before it continues
536 * processing the LOGO. The action will resume in
537 * lpfc_cmpl_els_logo_acc routine. Since part of processing includes an
538 * unreg_login, the driver waits so the ACC does not get aborted.
544 lpfc_rcv_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
545 struct lpfc_iocbq *cmdiocb)
547 struct lpfc_dmabuf *pcmd;
550 struct fc_rport *rport = ndlp->rport;
553 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
554 lp = (uint32_t *) pcmd->virt;
555 npr = (PRLI *) ((uint8_t *) lp + sizeof (uint32_t));
557 ndlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR);
558 ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
559 if (npr->prliType == PRLI_FCP_TYPE) {
560 if (npr->initiatorFunc)
561 ndlp->nlp_type |= NLP_FCP_INITIATOR;
563 ndlp->nlp_type |= NLP_FCP_TARGET;
565 ndlp->nlp_fcp_info |= NLP_FCP_2_DEVICE;
568 /* We need to update the rport role values */
569 roles = FC_RPORT_ROLE_UNKNOWN;
570 if (ndlp->nlp_type & NLP_FCP_INITIATOR)
571 roles |= FC_RPORT_ROLE_FCP_INITIATOR;
572 if (ndlp->nlp_type & NLP_FCP_TARGET)
573 roles |= FC_RPORT_ROLE_FCP_TARGET;
575 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
576 "rport rolechg: role:x%x did:x%x flg:x%x",
577 roles, ndlp->nlp_DID, ndlp->nlp_flag);
579 fc_remote_port_rolechg(rport, roles);
584 lpfc_disc_set_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
586 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
588 if (!(ndlp->nlp_flag & NLP_RPI_VALID)) {
589 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
593 if (!(vport->fc_flag & FC_PT2PT)) {
594 /* Check config parameter use-adisc or FCP-2 */
595 if ((vport->cfg_use_adisc && (vport->fc_flag & FC_RSCN_MODE)) ||
596 ndlp->nlp_fcp_info & NLP_FCP_2_DEVICE) {
597 spin_lock_irq(shost->host_lock);
598 ndlp->nlp_flag |= NLP_NPR_ADISC;
599 spin_unlock_irq(shost->host_lock);
603 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
604 lpfc_unreg_rpi(vport, ndlp);
609 lpfc_disc_illegal(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
610 void *arg, uint32_t evt)
612 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
613 "0271 Illegal State Transition: node x%x "
614 "event x%x, state x%x Data: x%x x%x\n",
615 ndlp->nlp_DID, evt, ndlp->nlp_state, ndlp->nlp_rpi,
617 return ndlp->nlp_state;
621 lpfc_cmpl_plogi_illegal(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
622 void *arg, uint32_t evt)
624 /* This transition is only legal if we previously
625 * rcv'ed a PLOGI. Since we don't want 2 discovery threads
626 * working on the same NPortID, do nothing for this thread
629 if (!(ndlp->nlp_flag & NLP_RCV_PLOGI)) {
630 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
631 "0272 Illegal State Transition: node x%x "
632 "event x%x, state x%x Data: x%x x%x\n",
633 ndlp->nlp_DID, evt, ndlp->nlp_state, ndlp->nlp_rpi,
636 return ndlp->nlp_state;
639 /* Start of Discovery State Machine routines */
642 lpfc_rcv_plogi_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
643 void *arg, uint32_t evt)
645 struct lpfc_iocbq *cmdiocb;
647 cmdiocb = (struct lpfc_iocbq *) arg;
649 if (lpfc_rcv_plogi(vport, ndlp, cmdiocb)) {
650 return ndlp->nlp_state;
652 return NLP_STE_FREED_NODE;
656 lpfc_rcv_els_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
657 void *arg, uint32_t evt)
659 lpfc_issue_els_logo(vport, ndlp, 0);
660 return ndlp->nlp_state;
664 lpfc_rcv_logo_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
665 void *arg, uint32_t evt)
667 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
668 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
670 spin_lock_irq(shost->host_lock);
671 ndlp->nlp_flag |= NLP_LOGO_ACC;
672 spin_unlock_irq(shost->host_lock);
673 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
675 return ndlp->nlp_state;
679 lpfc_cmpl_logo_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
680 void *arg, uint32_t evt)
682 return NLP_STE_FREED_NODE;
686 lpfc_device_rm_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
687 void *arg, uint32_t evt)
689 return NLP_STE_FREED_NODE;
693 lpfc_rcv_plogi_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
694 void *arg, uint32_t evt)
696 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
697 struct lpfc_hba *phba = vport->phba;
698 struct lpfc_iocbq *cmdiocb = arg;
699 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
700 uint32_t *lp = (uint32_t *) pcmd->virt;
701 struct serv_parm *sp = (struct serv_parm *) (lp + 1);
705 memset(&stat, 0, sizeof (struct ls_rjt));
707 /* For a PLOGI, we only accept if our portname is less
708 * than the remote portname.
710 phba->fc_stat.elsLogiCol++;
711 port_cmp = memcmp(&vport->fc_portname, &sp->portName,
712 sizeof(struct lpfc_name));
715 /* Reject this request because the remote node will accept
717 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
718 stat.un.b.lsRjtRsnCodeExp = LSEXP_CMD_IN_PROGRESS;
719 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
722 if (lpfc_rcv_plogi(vport, ndlp, cmdiocb) &&
723 (ndlp->nlp_flag & NLP_NPR_2B_DISC) &&
724 (vport->num_disc_nodes)) {
725 spin_lock_irq(shost->host_lock);
726 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
727 spin_unlock_irq(shost->host_lock);
728 /* Check if there are more PLOGIs to be sent */
729 lpfc_more_plogi(vport);
730 if (vport->num_disc_nodes == 0) {
731 spin_lock_irq(shost->host_lock);
732 vport->fc_flag &= ~FC_NDISC_ACTIVE;
733 spin_unlock_irq(shost->host_lock);
734 lpfc_can_disctmo(vport);
735 lpfc_end_rscn(vport);
738 } /* If our portname was less */
740 return ndlp->nlp_state;
744 lpfc_rcv_prli_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
745 void *arg, uint32_t evt)
747 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
750 memset(&stat, 0, sizeof (struct ls_rjt));
751 stat.un.b.lsRjtRsnCode = LSRJT_LOGICAL_BSY;
752 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
753 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
754 return ndlp->nlp_state;
758 lpfc_rcv_logo_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
759 void *arg, uint32_t evt)
761 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
763 /* software abort outstanding PLOGI */
764 lpfc_els_abort(vport->phba, ndlp);
766 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
767 return ndlp->nlp_state;
771 lpfc_rcv_els_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
772 void *arg, uint32_t evt)
774 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
775 struct lpfc_hba *phba = vport->phba;
776 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
778 /* software abort outstanding PLOGI */
779 lpfc_els_abort(phba, ndlp);
781 if (evt == NLP_EVT_RCV_LOGO) {
782 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
784 lpfc_issue_els_logo(vport, ndlp, 0);
787 /* Put ndlp in npr state set plogi timer for 1 sec */
788 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ * 1);
789 spin_lock_irq(shost->host_lock);
790 ndlp->nlp_flag |= NLP_DELAY_TMO;
791 spin_unlock_irq(shost->host_lock);
792 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
793 ndlp->nlp_prev_state = NLP_STE_PLOGI_ISSUE;
794 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
796 return ndlp->nlp_state;
800 lpfc_cmpl_plogi_plogi_issue(struct lpfc_vport *vport,
801 struct lpfc_nodelist *ndlp,
805 struct lpfc_hba *phba = vport->phba;
806 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
807 struct lpfc_iocbq *cmdiocb, *rspiocb;
808 struct lpfc_dmabuf *pcmd, *prsp, *mp;
811 struct serv_parm *sp;
814 cmdiocb = (struct lpfc_iocbq *) arg;
815 rspiocb = cmdiocb->context_un.rsp_iocb;
817 if (ndlp->nlp_flag & NLP_ACC_REGLOGIN) {
818 /* Recovery from PLOGI collision logic */
819 return ndlp->nlp_state;
822 irsp = &rspiocb->iocb;
827 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
829 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
831 lp = (uint32_t *) prsp->virt;
832 sp = (struct serv_parm *) ((uint8_t *) lp + sizeof (uint32_t));
834 /* Some switches have FDMI servers returning 0 for WWN */
835 if ((ndlp->nlp_DID != FDMI_DID) &&
836 (wwn_to_u64(sp->portName.u.wwn) == 0 ||
837 wwn_to_u64(sp->nodeName.u.wwn) == 0)) {
838 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
839 "0142 PLOGI RSP: Invalid WWN.\n");
842 if (!lpfc_check_sparm(vport, ndlp, sp, CLASS3, 0))
844 /* PLOGI chkparm OK */
845 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
846 "0121 PLOGI chkparm OK Data: x%x x%x x%x x%x\n",
847 ndlp->nlp_DID, ndlp->nlp_state,
848 ndlp->nlp_flag, ndlp->nlp_rpi);
849 if (vport->cfg_fcp_class == 2 && (sp->cls2.classValid))
850 ndlp->nlp_fcp_info |= CLASS2;
852 ndlp->nlp_fcp_info |= CLASS3;
854 ndlp->nlp_class_sup = 0;
855 if (sp->cls1.classValid)
856 ndlp->nlp_class_sup |= FC_COS_CLASS1;
857 if (sp->cls2.classValid)
858 ndlp->nlp_class_sup |= FC_COS_CLASS2;
859 if (sp->cls3.classValid)
860 ndlp->nlp_class_sup |= FC_COS_CLASS3;
861 if (sp->cls4.classValid)
862 ndlp->nlp_class_sup |= FC_COS_CLASS4;
864 ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) | sp->cmn.bbRcvSizeLsb;
866 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
868 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
869 "0133 PLOGI: no memory for reg_login "
870 "Data: x%x x%x x%x x%x\n",
871 ndlp->nlp_DID, ndlp->nlp_state,
872 ndlp->nlp_flag, ndlp->nlp_rpi);
876 lpfc_unreg_rpi(vport, ndlp);
878 if (lpfc_reg_rpi(phba, vport->vpi, irsp->un.elsreq64.remoteID,
879 (uint8_t *) sp, mbox, 0) == 0) {
880 switch (ndlp->nlp_DID) {
882 mbox->mbox_cmpl = lpfc_mbx_cmpl_ns_reg_login;
885 mbox->mbox_cmpl = lpfc_mbx_cmpl_fdmi_reg_login;
888 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
890 mbox->context2 = lpfc_nlp_get(ndlp);
892 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
893 != MBX_NOT_FINISHED) {
894 lpfc_nlp_set_state(vport, ndlp,
895 NLP_STE_REG_LOGIN_ISSUE);
896 return ndlp->nlp_state;
898 /* decrement node reference count to the failed mbox
902 mp = (struct lpfc_dmabuf *) mbox->context1;
903 lpfc_mbuf_free(phba, mp->virt, mp->phys);
905 mempool_free(mbox, phba->mbox_mem_pool);
907 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
908 "0134 PLOGI: cannot issue reg_login "
909 "Data: x%x x%x x%x x%x\n",
910 ndlp->nlp_DID, ndlp->nlp_state,
911 ndlp->nlp_flag, ndlp->nlp_rpi);
913 mempool_free(mbox, phba->mbox_mem_pool);
915 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
916 "0135 PLOGI: cannot format reg_login "
917 "Data: x%x x%x x%x x%x\n",
918 ndlp->nlp_DID, ndlp->nlp_state,
919 ndlp->nlp_flag, ndlp->nlp_rpi);
924 if (ndlp->nlp_DID == NameServer_DID) {
925 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
926 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
927 "0261 Cannot Register NameServer login\n");
930 spin_lock_irq(shost->host_lock);
931 ndlp->nlp_flag |= NLP_DEFER_RM;
932 spin_unlock_irq(shost->host_lock);
933 return NLP_STE_FREED_NODE;
937 lpfc_cmpl_logo_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
938 void *arg, uint32_t evt)
940 return ndlp->nlp_state;
944 lpfc_cmpl_reglogin_plogi_issue(struct lpfc_vport *vport,
945 struct lpfc_nodelist *ndlp, void *arg, uint32_t evt)
947 return ndlp->nlp_state;
951 lpfc_device_rm_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
952 void *arg, uint32_t evt)
954 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
956 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
957 spin_lock_irq(shost->host_lock);
958 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
959 spin_unlock_irq(shost->host_lock);
960 return ndlp->nlp_state;
962 /* software abort outstanding PLOGI */
963 lpfc_els_abort(vport->phba, ndlp);
965 lpfc_drop_node(vport, ndlp);
966 return NLP_STE_FREED_NODE;
971 lpfc_device_recov_plogi_issue(struct lpfc_vport *vport,
972 struct lpfc_nodelist *ndlp,
976 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
977 struct lpfc_hba *phba = vport->phba;
979 /* Don't do anything that will mess up processing of the
982 if (vport->fc_flag & FC_RSCN_DEFERRED)
983 return ndlp->nlp_state;
985 /* software abort outstanding PLOGI */
986 lpfc_els_abort(phba, ndlp);
988 ndlp->nlp_prev_state = NLP_STE_PLOGI_ISSUE;
989 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
990 spin_lock_irq(shost->host_lock);
991 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
992 spin_unlock_irq(shost->host_lock);
994 return ndlp->nlp_state;
998 lpfc_rcv_plogi_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
999 void *arg, uint32_t evt)
1001 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1002 struct lpfc_hba *phba = vport->phba;
1003 struct lpfc_iocbq *cmdiocb;
1005 /* software abort outstanding ADISC */
1006 lpfc_els_abort(phba, ndlp);
1008 cmdiocb = (struct lpfc_iocbq *) arg;
1010 if (lpfc_rcv_plogi(vport, ndlp, cmdiocb)) {
1011 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1012 spin_lock_irq(shost->host_lock);
1013 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
1014 spin_unlock_irq(shost->host_lock);
1015 if (vport->num_disc_nodes)
1016 lpfc_more_adisc(vport);
1018 return ndlp->nlp_state;
1020 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
1021 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
1022 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
1024 return ndlp->nlp_state;
1028 lpfc_rcv_prli_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1029 void *arg, uint32_t evt)
1031 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1033 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
1034 return ndlp->nlp_state;
1038 lpfc_rcv_logo_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1039 void *arg, uint32_t evt)
1041 struct lpfc_hba *phba = vport->phba;
1042 struct lpfc_iocbq *cmdiocb;
1044 cmdiocb = (struct lpfc_iocbq *) arg;
1046 /* software abort outstanding ADISC */
1047 lpfc_els_abort(phba, ndlp);
1049 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
1050 return ndlp->nlp_state;
1054 lpfc_rcv_padisc_adisc_issue(struct lpfc_vport *vport,
1055 struct lpfc_nodelist *ndlp,
1056 void *arg, uint32_t evt)
1058 struct lpfc_iocbq *cmdiocb;
1060 cmdiocb = (struct lpfc_iocbq *) arg;
1062 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
1063 return ndlp->nlp_state;
1067 lpfc_rcv_prlo_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1068 void *arg, uint32_t evt)
1070 struct lpfc_iocbq *cmdiocb;
1072 cmdiocb = (struct lpfc_iocbq *) arg;
1074 /* Treat like rcv logo */
1075 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_PRLO);
1076 return ndlp->nlp_state;
1080 lpfc_cmpl_adisc_adisc_issue(struct lpfc_vport *vport,
1081 struct lpfc_nodelist *ndlp,
1082 void *arg, uint32_t evt)
1084 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1085 struct lpfc_hba *phba = vport->phba;
1086 struct lpfc_iocbq *cmdiocb, *rspiocb;
1091 cmdiocb = (struct lpfc_iocbq *) arg;
1092 rspiocb = cmdiocb->context_un.rsp_iocb;
1094 ap = (ADISC *)lpfc_check_elscmpl_iocb(phba, cmdiocb, rspiocb);
1095 irsp = &rspiocb->iocb;
1097 if ((irsp->ulpStatus) ||
1098 (!lpfc_check_adisc(vport, ndlp, &ap->nodeName, &ap->portName))) {
1100 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ);
1101 spin_lock_irq(shost->host_lock);
1102 ndlp->nlp_flag |= NLP_DELAY_TMO;
1103 spin_unlock_irq(shost->host_lock);
1104 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
1106 memset(&ndlp->nlp_nodename, 0, sizeof(struct lpfc_name));
1107 memset(&ndlp->nlp_portname, 0, sizeof(struct lpfc_name));
1109 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
1110 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1111 lpfc_unreg_rpi(vport, ndlp);
1112 return ndlp->nlp_state;
1115 if (phba->sli_rev == LPFC_SLI_REV4) {
1116 rc = lpfc_sli4_resume_rpi(ndlp);
1118 /* Stay in state and retry. */
1119 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
1120 return ndlp->nlp_state;
1124 if (ndlp->nlp_type & NLP_FCP_TARGET) {
1125 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
1126 lpfc_nlp_set_state(vport, ndlp, NLP_STE_MAPPED_NODE);
1128 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
1129 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
1132 return ndlp->nlp_state;
1136 lpfc_device_rm_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1137 void *arg, uint32_t evt)
1139 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1141 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1142 spin_lock_irq(shost->host_lock);
1143 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
1144 spin_unlock_irq(shost->host_lock);
1145 return ndlp->nlp_state;
1147 /* software abort outstanding ADISC */
1148 lpfc_els_abort(vport->phba, ndlp);
1150 lpfc_drop_node(vport, ndlp);
1151 return NLP_STE_FREED_NODE;
1156 lpfc_device_recov_adisc_issue(struct lpfc_vport *vport,
1157 struct lpfc_nodelist *ndlp,
1161 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1162 struct lpfc_hba *phba = vport->phba;
1164 /* Don't do anything that will mess up processing of the
1167 if (vport->fc_flag & FC_RSCN_DEFERRED)
1168 return ndlp->nlp_state;
1170 /* software abort outstanding ADISC */
1171 lpfc_els_abort(phba, ndlp);
1173 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
1174 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1175 spin_lock_irq(shost->host_lock);
1176 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
1177 spin_unlock_irq(shost->host_lock);
1178 lpfc_disc_set_adisc(vport, ndlp);
1179 return ndlp->nlp_state;
1183 lpfc_rcv_plogi_reglogin_issue(struct lpfc_vport *vport,
1184 struct lpfc_nodelist *ndlp,
1188 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1190 lpfc_rcv_plogi(vport, ndlp, cmdiocb);
1191 return ndlp->nlp_state;
1195 lpfc_rcv_prli_reglogin_issue(struct lpfc_vport *vport,
1196 struct lpfc_nodelist *ndlp,
1200 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1202 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
1203 return ndlp->nlp_state;
1207 lpfc_rcv_logo_reglogin_issue(struct lpfc_vport *vport,
1208 struct lpfc_nodelist *ndlp,
1212 struct lpfc_hba *phba = vport->phba;
1213 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1215 LPFC_MBOXQ_t *nextmb;
1216 struct lpfc_dmabuf *mp;
1218 cmdiocb = (struct lpfc_iocbq *) arg;
1220 /* cleanup any ndlp on mbox q waiting for reglogin cmpl */
1221 if ((mb = phba->sli.mbox_active)) {
1222 if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) &&
1223 (ndlp == (struct lpfc_nodelist *) mb->context2)) {
1225 mb->context2 = NULL;
1226 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1230 spin_lock_irq(&phba->hbalock);
1231 list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) {
1232 if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) &&
1233 (ndlp == (struct lpfc_nodelist *) mb->context2)) {
1234 if (phba->sli_rev == LPFC_SLI_REV4) {
1235 spin_unlock_irq(&phba->hbalock);
1236 lpfc_sli4_free_rpi(phba,
1237 mb->u.mb.un.varRegLogin.rpi);
1238 spin_lock_irq(&phba->hbalock);
1240 mp = (struct lpfc_dmabuf *) (mb->context1);
1242 __lpfc_mbuf_free(phba, mp->virt, mp->phys);
1246 list_del(&mb->list);
1247 phba->sli.mboxq_cnt--;
1248 mempool_free(mb, phba->mbox_mem_pool);
1251 spin_unlock_irq(&phba->hbalock);
1253 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
1254 return ndlp->nlp_state;
1258 lpfc_rcv_padisc_reglogin_issue(struct lpfc_vport *vport,
1259 struct lpfc_nodelist *ndlp,
1263 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1265 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
1266 return ndlp->nlp_state;
1270 lpfc_rcv_prlo_reglogin_issue(struct lpfc_vport *vport,
1271 struct lpfc_nodelist *ndlp,
1275 struct lpfc_iocbq *cmdiocb;
1277 cmdiocb = (struct lpfc_iocbq *) arg;
1278 lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL);
1279 return ndlp->nlp_state;
1283 lpfc_cmpl_reglogin_reglogin_issue(struct lpfc_vport *vport,
1284 struct lpfc_nodelist *ndlp,
1288 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1289 LPFC_MBOXQ_t *pmb = (LPFC_MBOXQ_t *) arg;
1290 MAILBOX_t *mb = &pmb->u.mb;
1291 uint32_t did = mb->un.varWords[1];
1293 if (mb->mbxStatus) {
1294 /* RegLogin failed */
1295 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
1296 "0246 RegLogin failed Data: x%x x%x x%x\n",
1297 did, mb->mbxStatus, vport->port_state);
1299 * If RegLogin failed due to lack of HBA resources do not
1302 if (mb->mbxStatus == MBXERR_RPI_FULL) {
1303 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
1304 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1305 return ndlp->nlp_state;
1308 /* Put ndlp in npr state set plogi timer for 1 sec */
1309 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ * 1);
1310 spin_lock_irq(shost->host_lock);
1311 ndlp->nlp_flag |= NLP_DELAY_TMO;
1312 spin_unlock_irq(shost->host_lock);
1313 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
1315 lpfc_issue_els_logo(vport, ndlp, 0);
1316 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
1317 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1318 return ndlp->nlp_state;
1321 ndlp->nlp_rpi = mb->un.varWords[0];
1322 ndlp->nlp_flag |= NLP_RPI_VALID;
1324 /* Only if we are not a fabric nport do we issue PRLI */
1325 if (!(ndlp->nlp_type & NLP_FABRIC)) {
1326 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
1327 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
1328 lpfc_issue_els_prli(vport, ndlp, 0);
1330 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
1331 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
1333 return ndlp->nlp_state;
1337 lpfc_device_rm_reglogin_issue(struct lpfc_vport *vport,
1338 struct lpfc_nodelist *ndlp,
1342 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1344 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1345 spin_lock_irq(shost->host_lock);
1346 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
1347 spin_unlock_irq(shost->host_lock);
1348 return ndlp->nlp_state;
1350 lpfc_drop_node(vport, ndlp);
1351 return NLP_STE_FREED_NODE;
1356 lpfc_device_recov_reglogin_issue(struct lpfc_vport *vport,
1357 struct lpfc_nodelist *ndlp,
1361 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1363 /* Don't do anything that will mess up processing of the
1366 if (vport->fc_flag & FC_RSCN_DEFERRED)
1367 return ndlp->nlp_state;
1369 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
1370 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1371 spin_lock_irq(shost->host_lock);
1372 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
1373 spin_unlock_irq(shost->host_lock);
1374 lpfc_disc_set_adisc(vport, ndlp);
1375 return ndlp->nlp_state;
1379 lpfc_rcv_plogi_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1380 void *arg, uint32_t evt)
1382 struct lpfc_iocbq *cmdiocb;
1384 cmdiocb = (struct lpfc_iocbq *) arg;
1386 lpfc_rcv_plogi(vport, ndlp, cmdiocb);
1387 return ndlp->nlp_state;
1391 lpfc_rcv_prli_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1392 void *arg, uint32_t evt)
1394 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1396 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
1397 return ndlp->nlp_state;
1401 lpfc_rcv_logo_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1402 void *arg, uint32_t evt)
1404 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1406 /* Software abort outstanding PRLI before sending acc */
1407 lpfc_els_abort(vport->phba, ndlp);
1409 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
1410 return ndlp->nlp_state;
1414 lpfc_rcv_padisc_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1415 void *arg, uint32_t evt)
1417 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1419 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
1420 return ndlp->nlp_state;
1423 /* This routine is envoked when we rcv a PRLO request from a nport
1424 * we are logged into. We should send back a PRLO rsp setting the
1426 * NEXT STATE = PRLI_ISSUE
1429 lpfc_rcv_prlo_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1430 void *arg, uint32_t evt)
1432 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1434 lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL);
1435 return ndlp->nlp_state;
1439 lpfc_cmpl_prli_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1440 void *arg, uint32_t evt)
1442 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1443 struct lpfc_iocbq *cmdiocb, *rspiocb;
1444 struct lpfc_hba *phba = vport->phba;
1448 cmdiocb = (struct lpfc_iocbq *) arg;
1449 rspiocb = cmdiocb->context_un.rsp_iocb;
1450 npr = (PRLI *)lpfc_check_elscmpl_iocb(phba, cmdiocb, rspiocb);
1452 irsp = &rspiocb->iocb;
1453 if (irsp->ulpStatus) {
1454 if ((vport->port_type == LPFC_NPIV_PORT) &&
1455 vport->cfg_restrict_login) {
1458 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
1459 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
1460 return ndlp->nlp_state;
1463 /* Check out PRLI rsp */
1464 ndlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR);
1465 ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
1466 if ((npr->acceptRspCode == PRLI_REQ_EXECUTED) &&
1467 (npr->prliType == PRLI_FCP_TYPE)) {
1468 if (npr->initiatorFunc)
1469 ndlp->nlp_type |= NLP_FCP_INITIATOR;
1470 if (npr->targetFunc)
1471 ndlp->nlp_type |= NLP_FCP_TARGET;
1473 ndlp->nlp_fcp_info |= NLP_FCP_2_DEVICE;
1475 if (!(ndlp->nlp_type & NLP_FCP_TARGET) &&
1476 (vport->port_type == LPFC_NPIV_PORT) &&
1477 vport->cfg_restrict_login) {
1479 spin_lock_irq(shost->host_lock);
1480 ndlp->nlp_flag |= NLP_TARGET_REMOVE;
1481 spin_unlock_irq(shost->host_lock);
1482 lpfc_issue_els_logo(vport, ndlp, 0);
1484 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
1485 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1486 return ndlp->nlp_state;
1489 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
1490 if (ndlp->nlp_type & NLP_FCP_TARGET)
1491 lpfc_nlp_set_state(vport, ndlp, NLP_STE_MAPPED_NODE);
1493 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
1494 return ndlp->nlp_state;
1497 /*! lpfc_device_rm_prli_issue
1508 * This routine is envoked when we a request to remove a nport we are in the
1509 * process of PRLIing. We should software abort outstanding prli, unreg
1510 * login, send a logout. We will change node state to UNUSED_NODE, put it
1511 * on plogi list so it can be freed when LOGO completes.
1516 lpfc_device_rm_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1517 void *arg, uint32_t evt)
1519 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1521 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1522 spin_lock_irq(shost->host_lock);
1523 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
1524 spin_unlock_irq(shost->host_lock);
1525 return ndlp->nlp_state;
1527 /* software abort outstanding PLOGI */
1528 lpfc_els_abort(vport->phba, ndlp);
1530 lpfc_drop_node(vport, ndlp);
1531 return NLP_STE_FREED_NODE;
1536 /*! lpfc_device_recov_prli_issue
1547 * The routine is envoked when the state of a device is unknown, like
1548 * during a link down. We should remove the nodelist entry from the
1549 * unmapped list, issue a UNREG_LOGIN, do a software abort of the
1550 * outstanding PRLI command, then free the node entry.
1553 lpfc_device_recov_prli_issue(struct lpfc_vport *vport,
1554 struct lpfc_nodelist *ndlp,
1558 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1559 struct lpfc_hba *phba = vport->phba;
1561 /* Don't do anything that will mess up processing of the
1564 if (vport->fc_flag & FC_RSCN_DEFERRED)
1565 return ndlp->nlp_state;
1567 /* software abort outstanding PRLI */
1568 lpfc_els_abort(phba, ndlp);
1570 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
1571 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1572 spin_lock_irq(shost->host_lock);
1573 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
1574 spin_unlock_irq(shost->host_lock);
1575 lpfc_disc_set_adisc(vport, ndlp);
1576 return ndlp->nlp_state;
1580 lpfc_rcv_plogi_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1581 void *arg, uint32_t evt)
1583 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1585 lpfc_rcv_plogi(vport, ndlp, cmdiocb);
1586 return ndlp->nlp_state;
1590 lpfc_rcv_prli_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1591 void *arg, uint32_t evt)
1593 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1595 lpfc_rcv_prli(vport, ndlp, cmdiocb);
1596 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
1597 return ndlp->nlp_state;
1601 lpfc_rcv_logo_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1602 void *arg, uint32_t evt)
1604 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1606 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
1607 return ndlp->nlp_state;
1611 lpfc_rcv_padisc_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1612 void *arg, uint32_t evt)
1614 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1616 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
1617 return ndlp->nlp_state;
1621 lpfc_rcv_prlo_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1622 void *arg, uint32_t evt)
1624 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1626 lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL);
1627 return ndlp->nlp_state;
1631 lpfc_device_recov_unmap_node(struct lpfc_vport *vport,
1632 struct lpfc_nodelist *ndlp,
1636 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1638 ndlp->nlp_prev_state = NLP_STE_UNMAPPED_NODE;
1639 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1640 spin_lock_irq(shost->host_lock);
1641 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
1642 spin_unlock_irq(shost->host_lock);
1643 lpfc_disc_set_adisc(vport, ndlp);
1645 return ndlp->nlp_state;
1649 lpfc_rcv_plogi_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1650 void *arg, uint32_t evt)
1652 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1654 lpfc_rcv_plogi(vport, ndlp, cmdiocb);
1655 return ndlp->nlp_state;
1659 lpfc_rcv_prli_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1660 void *arg, uint32_t evt)
1662 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1664 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
1665 return ndlp->nlp_state;
1669 lpfc_rcv_logo_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1670 void *arg, uint32_t evt)
1672 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1674 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
1675 return ndlp->nlp_state;
1679 lpfc_rcv_padisc_mapped_node(struct lpfc_vport *vport,
1680 struct lpfc_nodelist *ndlp,
1681 void *arg, uint32_t evt)
1683 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1685 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
1686 return ndlp->nlp_state;
1690 lpfc_rcv_prlo_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1691 void *arg, uint32_t evt)
1693 struct lpfc_hba *phba = vport->phba;
1694 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1696 /* flush the target */
1697 lpfc_sli_abort_iocb(vport, &phba->sli.ring[phba->sli.fcp_ring],
1698 ndlp->nlp_sid, 0, LPFC_CTX_TGT);
1700 /* Treat like rcv logo */
1701 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_PRLO);
1702 return ndlp->nlp_state;
1706 lpfc_device_recov_mapped_node(struct lpfc_vport *vport,
1707 struct lpfc_nodelist *ndlp,
1711 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1713 ndlp->nlp_prev_state = NLP_STE_MAPPED_NODE;
1714 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1715 spin_lock_irq(shost->host_lock);
1716 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
1717 spin_unlock_irq(shost->host_lock);
1718 lpfc_disc_set_adisc(vport, ndlp);
1719 return ndlp->nlp_state;
1723 lpfc_rcv_plogi_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1724 void *arg, uint32_t evt)
1726 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1727 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1729 /* Ignore PLOGI if we have an outstanding LOGO */
1730 if (ndlp->nlp_flag & (NLP_LOGO_SND | NLP_LOGO_ACC))
1731 return ndlp->nlp_state;
1732 if (lpfc_rcv_plogi(vport, ndlp, cmdiocb)) {
1733 lpfc_cancel_retry_delay_tmo(vport, ndlp);
1734 spin_lock_irq(shost->host_lock);
1735 ndlp->nlp_flag &= ~(NLP_NPR_ADISC | NLP_NPR_2B_DISC);
1736 spin_unlock_irq(shost->host_lock);
1737 } else if (!(ndlp->nlp_flag & NLP_NPR_2B_DISC)) {
1738 /* send PLOGI immediately, move to PLOGI issue state */
1739 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
1740 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
1741 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
1742 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
1745 return ndlp->nlp_state;
1749 lpfc_rcv_prli_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1750 void *arg, uint32_t evt)
1752 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1753 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1756 memset(&stat, 0, sizeof (struct ls_rjt));
1757 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
1758 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
1759 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
1761 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
1762 if (ndlp->nlp_flag & NLP_NPR_ADISC) {
1763 spin_lock_irq(shost->host_lock);
1764 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
1765 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
1766 spin_unlock_irq(shost->host_lock);
1767 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
1768 lpfc_issue_els_adisc(vport, ndlp, 0);
1770 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
1771 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
1772 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
1775 return ndlp->nlp_state;
1779 lpfc_rcv_logo_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1780 void *arg, uint32_t evt)
1782 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1784 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
1785 return ndlp->nlp_state;
1789 lpfc_rcv_padisc_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1790 void *arg, uint32_t evt)
1792 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1794 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
1796 * Do not start discovery if discovery is about to start
1797 * or discovery in progress for this node. Starting discovery
1798 * here will affect the counting of discovery threads.
1800 if (!(ndlp->nlp_flag & NLP_DELAY_TMO) &&
1801 !(ndlp->nlp_flag & NLP_NPR_2B_DISC)) {
1802 if (ndlp->nlp_flag & NLP_NPR_ADISC) {
1803 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
1804 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
1805 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
1806 lpfc_issue_els_adisc(vport, ndlp, 0);
1808 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
1809 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
1810 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
1813 return ndlp->nlp_state;
1817 lpfc_rcv_prlo_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1818 void *arg, uint32_t evt)
1820 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1821 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1823 spin_lock_irq(shost->host_lock);
1824 ndlp->nlp_flag |= NLP_LOGO_ACC;
1825 spin_unlock_irq(shost->host_lock);
1827 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
1829 if ((ndlp->nlp_flag & NLP_DELAY_TMO) == 0) {
1830 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ * 1);
1831 spin_lock_irq(shost->host_lock);
1832 ndlp->nlp_flag |= NLP_DELAY_TMO;
1833 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
1834 spin_unlock_irq(shost->host_lock);
1835 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
1837 spin_lock_irq(shost->host_lock);
1838 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
1839 spin_unlock_irq(shost->host_lock);
1841 return ndlp->nlp_state;
1845 lpfc_cmpl_plogi_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1846 void *arg, uint32_t evt)
1848 struct lpfc_iocbq *cmdiocb, *rspiocb;
1851 cmdiocb = (struct lpfc_iocbq *) arg;
1852 rspiocb = cmdiocb->context_un.rsp_iocb;
1854 irsp = &rspiocb->iocb;
1855 if (irsp->ulpStatus) {
1856 ndlp->nlp_flag |= NLP_DEFER_RM;
1857 return NLP_STE_FREED_NODE;
1859 return ndlp->nlp_state;
1863 lpfc_cmpl_prli_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1864 void *arg, uint32_t evt)
1866 struct lpfc_iocbq *cmdiocb, *rspiocb;
1869 cmdiocb = (struct lpfc_iocbq *) arg;
1870 rspiocb = cmdiocb->context_un.rsp_iocb;
1872 irsp = &rspiocb->iocb;
1873 if (irsp->ulpStatus && (ndlp->nlp_flag & NLP_NODEV_REMOVE)) {
1874 lpfc_drop_node(vport, ndlp);
1875 return NLP_STE_FREED_NODE;
1877 return ndlp->nlp_state;
1881 lpfc_cmpl_logo_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1882 void *arg, uint32_t evt)
1884 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1885 if (ndlp->nlp_DID == Fabric_DID) {
1886 spin_lock_irq(shost->host_lock);
1887 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
1888 spin_unlock_irq(shost->host_lock);
1890 lpfc_unreg_rpi(vport, ndlp);
1891 return ndlp->nlp_state;
1895 lpfc_cmpl_adisc_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1896 void *arg, uint32_t evt)
1898 struct lpfc_iocbq *cmdiocb, *rspiocb;
1901 cmdiocb = (struct lpfc_iocbq *) arg;
1902 rspiocb = cmdiocb->context_un.rsp_iocb;
1904 irsp = &rspiocb->iocb;
1905 if (irsp->ulpStatus && (ndlp->nlp_flag & NLP_NODEV_REMOVE)) {
1906 lpfc_drop_node(vport, ndlp);
1907 return NLP_STE_FREED_NODE;
1909 return ndlp->nlp_state;
1913 lpfc_cmpl_reglogin_npr_node(struct lpfc_vport *vport,
1914 struct lpfc_nodelist *ndlp,
1915 void *arg, uint32_t evt)
1917 LPFC_MBOXQ_t *pmb = (LPFC_MBOXQ_t *) arg;
1918 MAILBOX_t *mb = &pmb->u.mb;
1920 if (!mb->mbxStatus) {
1921 ndlp->nlp_rpi = mb->un.varWords[0];
1922 ndlp->nlp_flag |= NLP_RPI_VALID;
1924 if (ndlp->nlp_flag & NLP_NODEV_REMOVE) {
1925 lpfc_drop_node(vport, ndlp);
1926 return NLP_STE_FREED_NODE;
1929 return ndlp->nlp_state;
1933 lpfc_device_rm_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1934 void *arg, uint32_t evt)
1936 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1938 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1939 spin_lock_irq(shost->host_lock);
1940 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
1941 spin_unlock_irq(shost->host_lock);
1942 return ndlp->nlp_state;
1944 lpfc_drop_node(vport, ndlp);
1945 return NLP_STE_FREED_NODE;
1949 lpfc_device_recov_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1950 void *arg, uint32_t evt)
1952 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1954 /* Don't do anything that will mess up processing of the
1957 if (vport->fc_flag & FC_RSCN_DEFERRED)
1958 return ndlp->nlp_state;
1960 lpfc_cancel_retry_delay_tmo(vport, ndlp);
1961 spin_lock_irq(shost->host_lock);
1962 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
1963 spin_unlock_irq(shost->host_lock);
1964 return ndlp->nlp_state;
1968 /* This next section defines the NPort Discovery State Machine */
1970 /* There are 4 different double linked lists nodelist entries can reside on.
1971 * The plogi list and adisc list are used when Link Up discovery or RSCN
1972 * processing is needed. Each list holds the nodes that we will send PLOGI
1973 * or ADISC on. These lists will keep track of what nodes will be effected
1974 * by an RSCN, or a Link Up (Typically, all nodes are effected on Link Up).
1975 * The unmapped_list will contain all nodes that we have successfully logged
1976 * into at the Fibre Channel level. The mapped_list will contain all nodes
1977 * that are mapped FCP targets.
1980 * The bind list is a list of undiscovered (potentially non-existent) nodes
1981 * that we have saved binding information on. This information is used when
1982 * nodes transition from the unmapped to the mapped list.
1984 /* For UNUSED_NODE state, the node has just been allocated .
1985 * For PLOGI_ISSUE and REG_LOGIN_ISSUE, the node is on
1986 * the PLOGI list. For REG_LOGIN_COMPL, the node is taken off the PLOGI list
1987 * and put on the unmapped list. For ADISC processing, the node is taken off
1988 * the ADISC list and placed on either the mapped or unmapped list (depending
1989 * on its previous state). Once on the unmapped list, a PRLI is issued and the
1990 * state changed to PRLI_ISSUE. When the PRLI completion occurs, the state is
1991 * changed to UNMAPPED_NODE. If the completion indicates a mapped
1992 * node, the node is taken off the unmapped list. The binding list is checked
1993 * for a valid binding, or a binding is automatically assigned. If binding
1994 * assignment is unsuccessful, the node is left on the unmapped list. If
1995 * binding assignment is successful, the associated binding list entry (if
1996 * any) is removed, and the node is placed on the mapped list.
1999 * For a Link Down, all nodes on the ADISC, PLOGI, unmapped or mapped
2000 * lists will receive a DEVICE_RECOVERY event. If the linkdown or devloss timers
2001 * expire, all effected nodes will receive a DEVICE_RM event.
2004 * For a Link Up or RSCN, all nodes will move from the mapped / unmapped lists
2005 * to either the ADISC or PLOGI list. After a Nameserver query or ALPA loopmap
2006 * check, additional nodes may be added or removed (via DEVICE_RM) to / from
2007 * the PLOGI or ADISC lists. Once the PLOGI and ADISC lists are populated,
2008 * we will first process the ADISC list. 32 entries are processed initially and
2009 * ADISC is initited for each one. Completions / Events for each node are
2010 * funnelled thru the state machine. As each node finishes ADISC processing, it
2011 * starts ADISC for any nodes waiting for ADISC processing. If no nodes are
2012 * waiting, and the ADISC list count is identically 0, then we are done. For
2013 * Link Up discovery, since all nodes on the PLOGI list are UNREG_LOGIN'ed, we
2014 * can issue a CLEAR_LA and reenable Link Events. Next we will process the PLOGI
2015 * list. 32 entries are processed initially and PLOGI is initited for each one.
2016 * Completions / Events for each node are funnelled thru the state machine. As
2017 * each node finishes PLOGI processing, it starts PLOGI for any nodes waiting
2018 * for PLOGI processing. If no nodes are waiting, and the PLOGI list count is
2019 * indentically 0, then we are done. We have now completed discovery / RSCN
2020 * handling. Upon completion, ALL nodes should be on either the mapped or
2024 static uint32_t (*lpfc_disc_action[NLP_STE_MAX_STATE * NLP_EVT_MAX_EVENT])
2025 (struct lpfc_vport *, struct lpfc_nodelist *, void *, uint32_t) = {
2026 /* Action routine Event Current State */
2027 lpfc_rcv_plogi_unused_node, /* RCV_PLOGI UNUSED_NODE */
2028 lpfc_rcv_els_unused_node, /* RCV_PRLI */
2029 lpfc_rcv_logo_unused_node, /* RCV_LOGO */
2030 lpfc_rcv_els_unused_node, /* RCV_ADISC */
2031 lpfc_rcv_els_unused_node, /* RCV_PDISC */
2032 lpfc_rcv_els_unused_node, /* RCV_PRLO */
2033 lpfc_disc_illegal, /* CMPL_PLOGI */
2034 lpfc_disc_illegal, /* CMPL_PRLI */
2035 lpfc_cmpl_logo_unused_node, /* CMPL_LOGO */
2036 lpfc_disc_illegal, /* CMPL_ADISC */
2037 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2038 lpfc_device_rm_unused_node, /* DEVICE_RM */
2039 lpfc_disc_illegal, /* DEVICE_RECOVERY */
2041 lpfc_rcv_plogi_plogi_issue, /* RCV_PLOGI PLOGI_ISSUE */
2042 lpfc_rcv_prli_plogi_issue, /* RCV_PRLI */
2043 lpfc_rcv_logo_plogi_issue, /* RCV_LOGO */
2044 lpfc_rcv_els_plogi_issue, /* RCV_ADISC */
2045 lpfc_rcv_els_plogi_issue, /* RCV_PDISC */
2046 lpfc_rcv_els_plogi_issue, /* RCV_PRLO */
2047 lpfc_cmpl_plogi_plogi_issue, /* CMPL_PLOGI */
2048 lpfc_disc_illegal, /* CMPL_PRLI */
2049 lpfc_cmpl_logo_plogi_issue, /* CMPL_LOGO */
2050 lpfc_disc_illegal, /* CMPL_ADISC */
2051 lpfc_cmpl_reglogin_plogi_issue,/* CMPL_REG_LOGIN */
2052 lpfc_device_rm_plogi_issue, /* DEVICE_RM */
2053 lpfc_device_recov_plogi_issue, /* DEVICE_RECOVERY */
2055 lpfc_rcv_plogi_adisc_issue, /* RCV_PLOGI ADISC_ISSUE */
2056 lpfc_rcv_prli_adisc_issue, /* RCV_PRLI */
2057 lpfc_rcv_logo_adisc_issue, /* RCV_LOGO */
2058 lpfc_rcv_padisc_adisc_issue, /* RCV_ADISC */
2059 lpfc_rcv_padisc_adisc_issue, /* RCV_PDISC */
2060 lpfc_rcv_prlo_adisc_issue, /* RCV_PRLO */
2061 lpfc_disc_illegal, /* CMPL_PLOGI */
2062 lpfc_disc_illegal, /* CMPL_PRLI */
2063 lpfc_disc_illegal, /* CMPL_LOGO */
2064 lpfc_cmpl_adisc_adisc_issue, /* CMPL_ADISC */
2065 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2066 lpfc_device_rm_adisc_issue, /* DEVICE_RM */
2067 lpfc_device_recov_adisc_issue, /* DEVICE_RECOVERY */
2069 lpfc_rcv_plogi_reglogin_issue, /* RCV_PLOGI REG_LOGIN_ISSUE */
2070 lpfc_rcv_prli_reglogin_issue, /* RCV_PLOGI */
2071 lpfc_rcv_logo_reglogin_issue, /* RCV_LOGO */
2072 lpfc_rcv_padisc_reglogin_issue, /* RCV_ADISC */
2073 lpfc_rcv_padisc_reglogin_issue, /* RCV_PDISC */
2074 lpfc_rcv_prlo_reglogin_issue, /* RCV_PRLO */
2075 lpfc_cmpl_plogi_illegal, /* CMPL_PLOGI */
2076 lpfc_disc_illegal, /* CMPL_PRLI */
2077 lpfc_disc_illegal, /* CMPL_LOGO */
2078 lpfc_disc_illegal, /* CMPL_ADISC */
2079 lpfc_cmpl_reglogin_reglogin_issue,/* CMPL_REG_LOGIN */
2080 lpfc_device_rm_reglogin_issue, /* DEVICE_RM */
2081 lpfc_device_recov_reglogin_issue,/* DEVICE_RECOVERY */
2083 lpfc_rcv_plogi_prli_issue, /* RCV_PLOGI PRLI_ISSUE */
2084 lpfc_rcv_prli_prli_issue, /* RCV_PRLI */
2085 lpfc_rcv_logo_prli_issue, /* RCV_LOGO */
2086 lpfc_rcv_padisc_prli_issue, /* RCV_ADISC */
2087 lpfc_rcv_padisc_prli_issue, /* RCV_PDISC */
2088 lpfc_rcv_prlo_prli_issue, /* RCV_PRLO */
2089 lpfc_cmpl_plogi_illegal, /* CMPL_PLOGI */
2090 lpfc_cmpl_prli_prli_issue, /* CMPL_PRLI */
2091 lpfc_disc_illegal, /* CMPL_LOGO */
2092 lpfc_disc_illegal, /* CMPL_ADISC */
2093 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2094 lpfc_device_rm_prli_issue, /* DEVICE_RM */
2095 lpfc_device_recov_prli_issue, /* DEVICE_RECOVERY */
2097 lpfc_rcv_plogi_unmap_node, /* RCV_PLOGI UNMAPPED_NODE */
2098 lpfc_rcv_prli_unmap_node, /* RCV_PRLI */
2099 lpfc_rcv_logo_unmap_node, /* RCV_LOGO */
2100 lpfc_rcv_padisc_unmap_node, /* RCV_ADISC */
2101 lpfc_rcv_padisc_unmap_node, /* RCV_PDISC */
2102 lpfc_rcv_prlo_unmap_node, /* RCV_PRLO */
2103 lpfc_disc_illegal, /* CMPL_PLOGI */
2104 lpfc_disc_illegal, /* CMPL_PRLI */
2105 lpfc_disc_illegal, /* CMPL_LOGO */
2106 lpfc_disc_illegal, /* CMPL_ADISC */
2107 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2108 lpfc_disc_illegal, /* DEVICE_RM */
2109 lpfc_device_recov_unmap_node, /* DEVICE_RECOVERY */
2111 lpfc_rcv_plogi_mapped_node, /* RCV_PLOGI MAPPED_NODE */
2112 lpfc_rcv_prli_mapped_node, /* RCV_PRLI */
2113 lpfc_rcv_logo_mapped_node, /* RCV_LOGO */
2114 lpfc_rcv_padisc_mapped_node, /* RCV_ADISC */
2115 lpfc_rcv_padisc_mapped_node, /* RCV_PDISC */
2116 lpfc_rcv_prlo_mapped_node, /* RCV_PRLO */
2117 lpfc_disc_illegal, /* CMPL_PLOGI */
2118 lpfc_disc_illegal, /* CMPL_PRLI */
2119 lpfc_disc_illegal, /* CMPL_LOGO */
2120 lpfc_disc_illegal, /* CMPL_ADISC */
2121 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2122 lpfc_disc_illegal, /* DEVICE_RM */
2123 lpfc_device_recov_mapped_node, /* DEVICE_RECOVERY */
2125 lpfc_rcv_plogi_npr_node, /* RCV_PLOGI NPR_NODE */
2126 lpfc_rcv_prli_npr_node, /* RCV_PRLI */
2127 lpfc_rcv_logo_npr_node, /* RCV_LOGO */
2128 lpfc_rcv_padisc_npr_node, /* RCV_ADISC */
2129 lpfc_rcv_padisc_npr_node, /* RCV_PDISC */
2130 lpfc_rcv_prlo_npr_node, /* RCV_PRLO */
2131 lpfc_cmpl_plogi_npr_node, /* CMPL_PLOGI */
2132 lpfc_cmpl_prli_npr_node, /* CMPL_PRLI */
2133 lpfc_cmpl_logo_npr_node, /* CMPL_LOGO */
2134 lpfc_cmpl_adisc_npr_node, /* CMPL_ADISC */
2135 lpfc_cmpl_reglogin_npr_node, /* CMPL_REG_LOGIN */
2136 lpfc_device_rm_npr_node, /* DEVICE_RM */
2137 lpfc_device_recov_npr_node, /* DEVICE_RECOVERY */
2141 lpfc_disc_state_machine(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2142 void *arg, uint32_t evt)
2144 uint32_t cur_state, rc;
2145 uint32_t(*func) (struct lpfc_vport *, struct lpfc_nodelist *, void *,
2147 uint32_t got_ndlp = 0;
2149 if (lpfc_nlp_get(ndlp))
2152 cur_state = ndlp->nlp_state;
2154 /* DSM in event <evt> on NPort <nlp_DID> in state <cur_state> */
2155 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2156 "0211 DSM in event x%x on NPort x%x in "
2157 "state %d Data: x%x\n",
2158 evt, ndlp->nlp_DID, cur_state, ndlp->nlp_flag);
2160 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_DSM,
2161 "DSM in: evt:%d ste:%d did:x%x",
2162 evt, cur_state, ndlp->nlp_DID);
2164 func = lpfc_disc_action[(cur_state * NLP_EVT_MAX_EVENT) + evt];
2165 rc = (func) (vport, ndlp, arg, evt);
2167 /* DSM out state <rc> on NPort <nlp_DID> */
2169 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2170 "0212 DSM out state %d on NPort x%x Data: x%x\n",
2171 rc, ndlp->nlp_DID, ndlp->nlp_flag);
2173 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_DSM,
2174 "DSM out: ste:%d did:x%x flg:x%x",
2175 rc, ndlp->nlp_DID, ndlp->nlp_flag);
2176 /* Decrement the ndlp reference count held for this function */
2179 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2180 "0213 DSM out state %d on NPort free\n", rc);
2182 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_DSM,
2183 "DSM out: ste:%d did:x%x flg:x%x",