void lpfc_read_lnk_stat(struct lpfc_hba *, LPFC_MBOXQ_t *);
 int lpfc_reg_rpi(struct lpfc_hba *, uint16_t, uint32_t, uint8_t *,
                 LPFC_MBOXQ_t *, uint32_t);
+void lpfc_set_var(struct lpfc_hba *, LPFC_MBOXQ_t *, uint32_t, uint32_t);
 void lpfc_unreg_login(struct lpfc_hba *, uint16_t, uint32_t, LPFC_MBOXQ_t *);
 void lpfc_unreg_did(struct lpfc_hba *, uint16_t, uint32_t, LPFC_MBOXQ_t *);
 void lpfc_reg_vpi(struct lpfc_vport *, LPFC_MBOXQ_t *);
 
        if (!(vport->load_flag & FC_UNLOADING) &&
            !(ndlp->nlp_flag & NLP_DELAY_TMO) &&
            !(ndlp->nlp_flag & NLP_NPR_2B_DISC) &&
-           (ndlp->nlp_state != NLP_STE_UNMAPPED_NODE))
+           (ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
+           (ndlp->nlp_state != NLP_STE_REG_LOGIN_ISSUE))
                lpfc_disc_state_machine(vport, ndlp, NULL, NLP_EVT_DEVICE_RM);
 
        lpfc_unregister_unused_fcf(phba);
        struct lpfc_vport  *vport = pmb->vport;
        struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
        struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
+       struct Scsi_Host  *shost = lpfc_shost_from_vport(vport);
 
        pmb->context1 = NULL;
 
-       /* Good status, call state machine */
-       lpfc_disc_state_machine(vport, ndlp, pmb, NLP_EVT_CMPL_REG_LOGIN);
+       if (ndlp->nlp_flag & NLP_REG_LOGIN_SEND)
+               ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND;
+
+       if (ndlp->nlp_flag &  NLP_IGNR_REG_CMPL ||
+               ndlp->nlp_state != NLP_STE_REG_LOGIN_ISSUE) {
+               /* We rcvd a rscn after issuing this
+                * mbox reg login, we may have cycled
+                * back through the state and be
+                * back at reg login state so this
+                * mbox needs to be ignored becase
+                * there is another reg login in
+                * proccess.
+                */
+               spin_lock_irq(shost->host_lock);
+               ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL;
+               spin_unlock_irq(shost->host_lock);
+               if (phba->sli_rev == LPFC_SLI_REV4)
+                       lpfc_sli4_free_rpi(phba,
+                               pmb->u.mb.un.varRegLogin.rpi);
+
+       } else
+               /* Good status, call state machine */
+               lpfc_disc_state_machine(vport, ndlp, pmb,
+                               NLP_EVT_CMPL_REG_LOGIN);
+
        lpfc_mbuf_free(phba, mp->virt, mp->phys);
        kfree(mp);
        mempool_free(pmb, phba->mbox_mem_pool);
                                kfree(mp);
                        }
                        list_del(&mb->list);
+                       if (phba->sli_rev == LPFC_SLI_REV4)
+                               lpfc_sli4_free_rpi(phba,
+                                        mb->u.mb.un.varRegLogin.rpi);
                        mempool_free(mb, phba->mbox_mem_pool);
                        /* We shall not invoke the lpfc_nlp_put to decrement
                         * the ndlp reference count as we are in the process
 
        lpfc_cancel_retry_delay_tmo(vport, ndlp);
        if ((ndlp->nlp_flag & NLP_DEFER_RM) &&
+               !(ndlp->nlp_flag & NLP_REG_LOGIN_SEND) &&
            !(ndlp->nlp_flag & NLP_RPI_VALID)) {
                /* For this case we need to cleanup the default rpi
                 * allocated by the firmware.
 
        if (!(vport->fc_flag & FC_PT2PT)) {
                /* Check config parameter use-adisc or FCP-2 */
                if ((vport->cfg_use_adisc && (vport->fc_flag & FC_RSCN_MODE)) ||
-                   ndlp->nlp_fcp_info & NLP_FCP_2_DEVICE) {
+                   ((ndlp->nlp_fcp_info & NLP_FCP_2_DEVICE) &&
+                    (ndlp->nlp_type & NLP_FCP_TARGET))) {
                        spin_lock_irq(shost->host_lock);
                        ndlp->nlp_flag |= NLP_NPR_ADISC;
                        spin_unlock_irq(shost->host_lock);
                        mbox->mbox_cmpl = lpfc_mbx_cmpl_fdmi_reg_login;
                        break;
                default:
+                       ndlp->nlp_flag |= NLP_REG_LOGIN_SEND;
                        mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
                }
                mbox->context2 = lpfc_nlp_get(ndlp);
                                           NLP_STE_REG_LOGIN_ISSUE);
                        return ndlp->nlp_state;
                }
+               if (ndlp->nlp_flag & NLP_REG_LOGIN_SEND)
+                       ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND;
                /* decrement node reference count to the failed mbox
                 * command
                 */
        ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
        lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
        spin_lock_irq(shost->host_lock);
+       ndlp->nlp_flag |= NLP_IGNR_REG_CMPL;
        ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
        spin_unlock_irq(shost->host_lock);
        lpfc_disc_set_adisc(vport, ndlp);