aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/scsi/lpfc
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/scsi/lpfc')
-rw-r--r--drivers/scsi/lpfc/lpfc.h21
-rw-r--r--drivers/scsi/lpfc/lpfc_attr.c3
-rw-r--r--drivers/scsi/lpfc/lpfc_crtn.h3
-rw-r--r--drivers/scsi/lpfc/lpfc_ct.c22
-rw-r--r--drivers/scsi/lpfc/lpfc_els.c181
-rw-r--r--drivers/scsi/lpfc/lpfc_hbadisc.c120
-rw-r--r--drivers/scsi/lpfc/lpfc_init.c34
-rw-r--r--drivers/scsi/lpfc/lpfc_nportdisc.c145
-rw-r--r--drivers/scsi/lpfc/lpfc_scsi.c232
-rw-r--r--drivers/scsi/lpfc/lpfc_sli.c49
-rw-r--r--drivers/scsi/lpfc/lpfc_version.h2
-rw-r--r--drivers/scsi/lpfc/lpfc_vport.c16
12 files changed, 328 insertions, 500 deletions
diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
index ec0b0f6e5e1a..e0e018d12653 100644
--- a/drivers/scsi/lpfc/lpfc.h
+++ b/drivers/scsi/lpfc/lpfc.h
@@ -33,6 +33,7 @@ struct lpfc_sli2_slim;
33#define LPFC_MAX_SG_SEG_CNT 256 /* sg element count per scsi cmnd */ 33#define LPFC_MAX_SG_SEG_CNT 256 /* sg element count per scsi cmnd */
34#define LPFC_IOCB_LIST_CNT 2250 /* list of IOCBs for fast-path usage. */ 34#define LPFC_IOCB_LIST_CNT 2250 /* list of IOCBs for fast-path usage. */
35#define LPFC_Q_RAMP_UP_INTERVAL 120 /* lun q_depth ramp up interval */ 35#define LPFC_Q_RAMP_UP_INTERVAL 120 /* lun q_depth ramp up interval */
36#define LPFC_VNAME_LEN 100 /* vport symbolic name length */
36 37
37/* 38/*
38 * Following time intervals are used of adjusting SCSI device 39 * Following time intervals are used of adjusting SCSI device
@@ -59,6 +60,9 @@ struct lpfc_sli2_slim;
59 60
60#define MAX_HBAEVT 32 61#define MAX_HBAEVT 32
61 62
63/* lpfc wait event data ready flag */
64#define LPFC_DATA_READY (1<<0)
65
62enum lpfc_polling_flags { 66enum lpfc_polling_flags {
63 ENABLE_FCP_RING_POLLING = 0x1, 67 ENABLE_FCP_RING_POLLING = 0x1,
64 DISABLE_FCP_RING_INT = 0x2 68 DISABLE_FCP_RING_INT = 0x2
@@ -425,9 +429,6 @@ struct lpfc_hba {
425 429
426 uint16_t pci_cfg_value; 430 uint16_t pci_cfg_value;
427 431
428 uint8_t work_found;
429#define LPFC_MAX_WORKER_ITERATION 4
430
431 uint8_t fc_linkspeed; /* Link speed after last READ_LA */ 432 uint8_t fc_linkspeed; /* Link speed after last READ_LA */
432 433
433 uint32_t fc_eventTag; /* event tag for link attention */ 434 uint32_t fc_eventTag; /* event tag for link attention */
@@ -489,8 +490,9 @@ struct lpfc_hba {
489 uint32_t work_hs; /* HS stored in case of ERRAT */ 490 uint32_t work_hs; /* HS stored in case of ERRAT */
490 uint32_t work_status[2]; /* Extra status from SLIM */ 491 uint32_t work_status[2]; /* Extra status from SLIM */
491 492
492 wait_queue_head_t *work_wait; 493 wait_queue_head_t work_waitq;
493 struct task_struct *worker_thread; 494 struct task_struct *worker_thread;
495 long data_flags;
494 496
495 uint32_t hbq_in_use; /* HBQs in use flag */ 497 uint32_t hbq_in_use; /* HBQs in use flag */
496 struct list_head hbqbuf_in_list; /* in-fly hbq buffer list */ 498 struct list_head hbqbuf_in_list; /* in-fly hbq buffer list */
@@ -637,6 +639,17 @@ lpfc_is_link_up(struct lpfc_hba *phba)
637 phba->link_state == LPFC_HBA_READY; 639 phba->link_state == LPFC_HBA_READY;
638} 640}
639 641
642static inline void
643lpfc_worker_wake_up(struct lpfc_hba *phba)
644{
645 /* Set the lpfc data pending flag */
646 set_bit(LPFC_DATA_READY, &phba->data_flags);
647
648 /* Wake up worker thread */
649 wake_up(&phba->work_waitq);
650 return;
651}
652
640#define FC_REG_DUMP_EVENT 0x10 /* Register for Dump events */ 653#define FC_REG_DUMP_EVENT 0x10 /* Register for Dump events */
641#define FC_REG_TEMPERATURE_EVENT 0x20 /* Register for temperature 654#define FC_REG_TEMPERATURE_EVENT 0x20 /* Register for temperature
642 event */ 655 event */
diff --git a/drivers/scsi/lpfc/lpfc_attr.c b/drivers/scsi/lpfc/lpfc_attr.c
index 960baaf11fb1..37bfa0bd1dae 100644
--- a/drivers/scsi/lpfc/lpfc_attr.c
+++ b/drivers/scsi/lpfc/lpfc_attr.c
@@ -1995,8 +1995,7 @@ sysfs_mbox_read(struct kobject *kobj, struct bin_attribute *bin_attr,
1995 /* Don't allow mailbox commands to be sent when blocked 1995 /* Don't allow mailbox commands to be sent when blocked
1996 * or when in the middle of discovery 1996 * or when in the middle of discovery
1997 */ 1997 */
1998 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO || 1998 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO) {
1999 vport->fc_flag & FC_NDISC_ACTIVE) {
2000 sysfs_mbox_idle(phba); 1999 sysfs_mbox_idle(phba);
2001 spin_unlock_irq(&phba->hbalock); 2000 spin_unlock_irq(&phba->hbalock);
2002 return -EAGAIN; 2001 return -EAGAIN;
diff --git a/drivers/scsi/lpfc/lpfc_crtn.h b/drivers/scsi/lpfc/lpfc_crtn.h
index 7c9f8317d972..1b8245213b83 100644
--- a/drivers/scsi/lpfc/lpfc_crtn.h
+++ b/drivers/scsi/lpfc/lpfc_crtn.h
@@ -142,7 +142,7 @@ int lpfc_config_port_post(struct lpfc_hba *);
142int lpfc_hba_down_prep(struct lpfc_hba *); 142int lpfc_hba_down_prep(struct lpfc_hba *);
143int lpfc_hba_down_post(struct lpfc_hba *); 143int lpfc_hba_down_post(struct lpfc_hba *);
144void lpfc_hba_init(struct lpfc_hba *, uint32_t *); 144void lpfc_hba_init(struct lpfc_hba *, uint32_t *);
145int lpfc_post_buffer(struct lpfc_hba *, struct lpfc_sli_ring *, int, int); 145int lpfc_post_buffer(struct lpfc_hba *, struct lpfc_sli_ring *, int);
146void lpfc_decode_firmware_rev(struct lpfc_hba *, char *, int); 146void lpfc_decode_firmware_rev(struct lpfc_hba *, char *, int);
147int lpfc_online(struct lpfc_hba *); 147int lpfc_online(struct lpfc_hba *);
148void lpfc_unblock_mgmt_io(struct lpfc_hba *); 148void lpfc_unblock_mgmt_io(struct lpfc_hba *);
@@ -263,6 +263,7 @@ extern int lpfc_sli_mode;
263extern int lpfc_enable_npiv; 263extern int lpfc_enable_npiv;
264 264
265int lpfc_vport_symbolic_node_name(struct lpfc_vport *, char *, size_t); 265int lpfc_vport_symbolic_node_name(struct lpfc_vport *, char *, size_t);
266int lpfc_vport_symbolic_port_name(struct lpfc_vport *, char *, size_t);
266void lpfc_terminate_rport_io(struct fc_rport *); 267void lpfc_terminate_rport_io(struct fc_rport *);
267void lpfc_dev_loss_tmo_callbk(struct fc_rport *rport); 268void lpfc_dev_loss_tmo_callbk(struct fc_rport *rport);
268 269
diff --git a/drivers/scsi/lpfc/lpfc_ct.c b/drivers/scsi/lpfc/lpfc_ct.c
index 153afae567b5..7fc74cf5823b 100644
--- a/drivers/scsi/lpfc/lpfc_ct.c
+++ b/drivers/scsi/lpfc/lpfc_ct.c
@@ -101,7 +101,7 @@ lpfc_ct_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
101 /* Not enough posted buffers; Try posting more buffers */ 101 /* Not enough posted buffers; Try posting more buffers */
102 phba->fc_stat.NoRcvBuf++; 102 phba->fc_stat.NoRcvBuf++;
103 if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)) 103 if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED))
104 lpfc_post_buffer(phba, pring, 2, 1); 104 lpfc_post_buffer(phba, pring, 2);
105 return; 105 return;
106 } 106 }
107 107
@@ -151,7 +151,7 @@ lpfc_ct_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
151 } 151 }
152 list_del(&iocbq->list); 152 list_del(&iocbq->list);
153 lpfc_sli_release_iocbq(phba, iocbq); 153 lpfc_sli_release_iocbq(phba, iocbq);
154 lpfc_post_buffer(phba, pring, i, 1); 154 lpfc_post_buffer(phba, pring, i);
155 } 155 }
156 } 156 }
157} 157}
@@ -990,7 +990,7 @@ lpfc_cmpl_ct_cmd_rff_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
990 return; 990 return;
991} 991}
992 992
993static int 993int
994lpfc_vport_symbolic_port_name(struct lpfc_vport *vport, char *symbol, 994lpfc_vport_symbolic_port_name(struct lpfc_vport *vport, char *symbol,
995 size_t size) 995 size_t size)
996{ 996{
@@ -1679,20 +1679,18 @@ lpfc_fdmi_tmo(unsigned long ptr)
1679{ 1679{
1680 struct lpfc_vport *vport = (struct lpfc_vport *)ptr; 1680 struct lpfc_vport *vport = (struct lpfc_vport *)ptr;
1681 struct lpfc_hba *phba = vport->phba; 1681 struct lpfc_hba *phba = vport->phba;
1682 uint32_t tmo_posted;
1682 unsigned long iflag; 1683 unsigned long iflag;
1683 1684
1684 spin_lock_irqsave(&vport->work_port_lock, iflag); 1685 spin_lock_irqsave(&vport->work_port_lock, iflag);
1685 if (!(vport->work_port_events & WORKER_FDMI_TMO)) { 1686 tmo_posted = vport->work_port_events & WORKER_FDMI_TMO;
1687 if (!tmo_posted)
1686 vport->work_port_events |= WORKER_FDMI_TMO; 1688 vport->work_port_events |= WORKER_FDMI_TMO;
1687 spin_unlock_irqrestore(&vport->work_port_lock, iflag); 1689 spin_unlock_irqrestore(&vport->work_port_lock, iflag);
1688 1690
1689 spin_lock_irqsave(&phba->hbalock, iflag); 1691 if (!tmo_posted)
1690 if (phba->work_wait) 1692 lpfc_worker_wake_up(phba);
1691 lpfc_worker_wake_up(phba); 1693 return;
1692 spin_unlock_irqrestore(&phba->hbalock, iflag);
1693 }
1694 else
1695 spin_unlock_irqrestore(&vport->work_port_lock, iflag);
1696} 1694}
1697 1695
1698void 1696void
diff --git a/drivers/scsi/lpfc/lpfc_els.c b/drivers/scsi/lpfc/lpfc_els.c
index 886c5f1b11d2..f54e0f7eaee3 100644
--- a/drivers/scsi/lpfc/lpfc_els.c
+++ b/drivers/scsi/lpfc/lpfc_els.c
@@ -1754,29 +1754,34 @@ lpfc_cancel_retry_delay_tmo(struct lpfc_vport *vport, struct lpfc_nodelist *nlp)
1754 struct Scsi_Host *shost = lpfc_shost_from_vport(vport); 1754 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1755 struct lpfc_work_evt *evtp; 1755 struct lpfc_work_evt *evtp;
1756 1756
1757 if (!(nlp->nlp_flag & NLP_DELAY_TMO))
1758 return;
1757 spin_lock_irq(shost->host_lock); 1759 spin_lock_irq(shost->host_lock);
1758 nlp->nlp_flag &= ~NLP_DELAY_TMO; 1760 nlp->nlp_flag &= ~NLP_DELAY_TMO;
1759 spin_unlock_irq(shost->host_lock); 1761 spin_unlock_irq(shost->host_lock);
1760 del_timer_sync(&nlp->nlp_delayfunc); 1762 del_timer_sync(&nlp->nlp_delayfunc);
1761 nlp->nlp_last_elscmd = 0; 1763 nlp->nlp_last_elscmd = 0;
1762
1763 if (!list_empty(&nlp->els_retry_evt.evt_listp)) { 1764 if (!list_empty(&nlp->els_retry_evt.evt_listp)) {
1764 list_del_init(&nlp->els_retry_evt.evt_listp); 1765 list_del_init(&nlp->els_retry_evt.evt_listp);
1765 /* Decrement nlp reference count held for the delayed retry */ 1766 /* Decrement nlp reference count held for the delayed retry */
1766 evtp = &nlp->els_retry_evt; 1767 evtp = &nlp->els_retry_evt;
1767 lpfc_nlp_put((struct lpfc_nodelist *)evtp->evt_arg1); 1768 lpfc_nlp_put((struct lpfc_nodelist *)evtp->evt_arg1);
1768 } 1769 }
1769
1770 if (nlp->nlp_flag & NLP_NPR_2B_DISC) { 1770 if (nlp->nlp_flag & NLP_NPR_2B_DISC) {
1771 spin_lock_irq(shost->host_lock); 1771 spin_lock_irq(shost->host_lock);
1772 nlp->nlp_flag &= ~NLP_NPR_2B_DISC; 1772 nlp->nlp_flag &= ~NLP_NPR_2B_DISC;
1773 spin_unlock_irq(shost->host_lock); 1773 spin_unlock_irq(shost->host_lock);
1774 if (vport->num_disc_nodes) { 1774 if (vport->num_disc_nodes) {
1775 /* Check to see if there are more 1775 if (vport->port_state < LPFC_VPORT_READY) {
1776 * PLOGIs to be sent 1776 /* Check if there are more ADISCs to be sent */
1777 */ 1777 lpfc_more_adisc(vport);
1778 lpfc_more_plogi(vport); 1778 if ((vport->num_disc_nodes == 0) &&
1779 1779 (vport->fc_npr_cnt))
1780 lpfc_els_disc_plogi(vport);
1781 } else {
1782 /* Check if there are more PLOGIs to be sent */
1783 lpfc_more_plogi(vport);
1784 }
1780 if (vport->num_disc_nodes == 0) { 1785 if (vport->num_disc_nodes == 0) {
1781 spin_lock_irq(shost->host_lock); 1786 spin_lock_irq(shost->host_lock);
1782 vport->fc_flag &= ~FC_NDISC_ACTIVE; 1787 vport->fc_flag &= ~FC_NDISC_ACTIVE;
@@ -1798,10 +1803,6 @@ lpfc_els_retry_delay(unsigned long ptr)
1798 unsigned long flags; 1803 unsigned long flags;
1799 struct lpfc_work_evt *evtp = &ndlp->els_retry_evt; 1804 struct lpfc_work_evt *evtp = &ndlp->els_retry_evt;
1800 1805
1801 ndlp = (struct lpfc_nodelist *) ptr;
1802 phba = ndlp->vport->phba;
1803 evtp = &ndlp->els_retry_evt;
1804
1805 spin_lock_irqsave(&phba->hbalock, flags); 1806 spin_lock_irqsave(&phba->hbalock, flags);
1806 if (!list_empty(&evtp->evt_listp)) { 1807 if (!list_empty(&evtp->evt_listp)) {
1807 spin_unlock_irqrestore(&phba->hbalock, flags); 1808 spin_unlock_irqrestore(&phba->hbalock, flags);
@@ -1812,11 +1813,11 @@ lpfc_els_retry_delay(unsigned long ptr)
1812 * count until the queued work is done 1813 * count until the queued work is done
1813 */ 1814 */
1814 evtp->evt_arg1 = lpfc_nlp_get(ndlp); 1815 evtp->evt_arg1 = lpfc_nlp_get(ndlp);
1815 evtp->evt = LPFC_EVT_ELS_RETRY; 1816 if (evtp->evt_arg1) {
1816 list_add_tail(&evtp->evt_listp, &phba->work_list); 1817 evtp->evt = LPFC_EVT_ELS_RETRY;
1817 if (phba->work_wait) 1818 list_add_tail(&evtp->evt_listp, &phba->work_list);
1818 lpfc_worker_wake_up(phba); 1819 lpfc_worker_wake_up(phba);
1819 1820 }
1820 spin_unlock_irqrestore(&phba->hbalock, flags); 1821 spin_unlock_irqrestore(&phba->hbalock, flags);
1821 return; 1822 return;
1822} 1823}
@@ -2761,10 +2762,11 @@ lpfc_els_rsp_prli_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
2761 npr = (PRLI *) pcmd; 2762 npr = (PRLI *) pcmd;
2762 vpd = &phba->vpd; 2763 vpd = &phba->vpd;
2763 /* 2764 /*
2764 * If our firmware version is 3.20 or later, 2765 * If the remote port is a target and our firmware version is 3.20 or
2765 * set the following bits for FC-TAPE support. 2766 * later, set the following bits for FC-TAPE support.
2766 */ 2767 */
2767 if (vpd->rev.feaLevelHigh >= 0x02) { 2768 if ((ndlp->nlp_type & NLP_FCP_TARGET) &&
2769 (vpd->rev.feaLevelHigh >= 0x02)) {
2768 npr->ConfmComplAllowed = 1; 2770 npr->ConfmComplAllowed = 1;
2769 npr->Retry = 1; 2771 npr->Retry = 1;
2770 npr->TaskRetryIdReq = 1; 2772 npr->TaskRetryIdReq = 1;
@@ -3056,27 +3058,16 @@ lpfc_rscn_recovery_check(struct lpfc_vport *vport)
3056{ 3058{
3057 struct lpfc_nodelist *ndlp = NULL; 3059 struct lpfc_nodelist *ndlp = NULL;
3058 3060
3059 /* Look at all nodes effected by pending RSCNs and move 3061 /* Move all affected nodes by pending RSCNs to NPR state. */
3060 * them to NPR state.
3061 */
3062
3063 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) { 3062 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
3064 if (!NLP_CHK_NODE_ACT(ndlp) || 3063 if (!NLP_CHK_NODE_ACT(ndlp) ||
3065 ndlp->nlp_state == NLP_STE_UNUSED_NODE || 3064 (ndlp->nlp_state == NLP_STE_UNUSED_NODE) ||
3066 lpfc_rscn_payload_check(vport, ndlp->nlp_DID) == 0) 3065 !lpfc_rscn_payload_check(vport, ndlp->nlp_DID))
3067 continue; 3066 continue;
3068
3069 lpfc_disc_state_machine(vport, ndlp, NULL, 3067 lpfc_disc_state_machine(vport, ndlp, NULL,
3070 NLP_EVT_DEVICE_RECOVERY); 3068 NLP_EVT_DEVICE_RECOVERY);
3071 3069 lpfc_cancel_retry_delay_tmo(vport, ndlp);
3072 /*
3073 * Make sure NLP_DELAY_TMO is NOT running after a device
3074 * recovery event.
3075 */
3076 if (ndlp->nlp_flag & NLP_DELAY_TMO)
3077 lpfc_cancel_retry_delay_tmo(vport, ndlp);
3078 } 3070 }
3079
3080 return 0; 3071 return 0;
3081} 3072}
3082 3073
@@ -3781,91 +3772,27 @@ static int
3781lpfc_els_rcv_fan(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, 3772lpfc_els_rcv_fan(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
3782 struct lpfc_nodelist *fan_ndlp) 3773 struct lpfc_nodelist *fan_ndlp)
3783{ 3774{
3784 struct lpfc_dmabuf *pcmd; 3775 struct lpfc_hba *phba = vport->phba;
3785 uint32_t *lp; 3776 uint32_t *lp;
3786 IOCB_t *icmd;
3787 uint32_t cmd, did;
3788 FAN *fp; 3777 FAN *fp;
3789 struct lpfc_nodelist *ndlp, *next_ndlp;
3790 struct lpfc_hba *phba = vport->phba;
3791
3792 /* FAN received */
3793 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3794 "0265 FAN received\n");
3795 icmd = &cmdiocb->iocb;
3796 did = icmd->un.elsreq64.remoteID;
3797 pcmd = (struct lpfc_dmabuf *)cmdiocb->context2;
3798 lp = (uint32_t *)pcmd->virt;
3799
3800 cmd = *lp++;
3801 fp = (FAN *) lp;
3802 3778
3779 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, "0265 FAN received\n");
3780 lp = (uint32_t *)((struct lpfc_dmabuf *)cmdiocb->context2)->virt;
3781 fp = (FAN *) ++lp;
3803 /* FAN received; Fan does not have a reply sequence */ 3782 /* FAN received; Fan does not have a reply sequence */
3804 3783 if ((vport == phba->pport) &&
3805 if (phba->pport->port_state == LPFC_LOCAL_CFG_LINK) { 3784 (vport->port_state == LPFC_LOCAL_CFG_LINK)) {
3806 if ((memcmp(&phba->fc_fabparam.nodeName, &fp->FnodeName, 3785 if ((memcmp(&phba->fc_fabparam.nodeName, &fp->FnodeName,
3807 sizeof(struct lpfc_name)) != 0) || 3786 sizeof(struct lpfc_name))) ||
3808 (memcmp(&phba->fc_fabparam.portName, &fp->FportName, 3787 (memcmp(&phba->fc_fabparam.portName, &fp->FportName,
3809 sizeof(struct lpfc_name)) != 0)) { 3788 sizeof(struct lpfc_name)))) {
3810 /* 3789 /* This port has switched fabrics. FLOGI is required */
3811 * This node has switched fabrics. FLOGI is required
3812 * Clean up the old rpi's
3813 */
3814
3815 list_for_each_entry_safe(ndlp, next_ndlp,
3816 &vport->fc_nodes, nlp_listp) {
3817 if (!NLP_CHK_NODE_ACT(ndlp))
3818 continue;
3819 if (ndlp->nlp_state != NLP_STE_NPR_NODE)
3820 continue;
3821 if (ndlp->nlp_type & NLP_FABRIC) {
3822 /*
3823 * Clean up old Fabric, Nameserver and
3824 * other NLP_FABRIC logins
3825 */
3826 lpfc_drop_node(vport, ndlp);
3827
3828 } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) {
3829 /* Fail outstanding I/O now since this
3830 * device is marked for PLOGI
3831 */
3832 lpfc_unreg_rpi(vport, ndlp);
3833 }
3834 }
3835
3836 lpfc_initial_flogi(vport); 3790 lpfc_initial_flogi(vport);
3837 return 0; 3791 } else {
3838 } 3792 /* FAN verified - skip FLOGI */
3839 /* Discovery not needed, 3793 vport->fc_myDID = vport->fc_prevDID;
3840 * move the nodes to their original state. 3794 lpfc_issue_fabric_reglogin(vport);
3841 */
3842 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes,
3843 nlp_listp) {
3844 if (!NLP_CHK_NODE_ACT(ndlp))
3845 continue;
3846 if (ndlp->nlp_state != NLP_STE_NPR_NODE)
3847 continue;
3848
3849 switch (ndlp->nlp_prev_state) {
3850 case NLP_STE_UNMAPPED_NODE:
3851 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
3852 lpfc_nlp_set_state(vport, ndlp,
3853 NLP_STE_UNMAPPED_NODE);
3854 break;
3855
3856 case NLP_STE_MAPPED_NODE:
3857 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
3858 lpfc_nlp_set_state(vport, ndlp,
3859 NLP_STE_MAPPED_NODE);
3860 break;
3861
3862 default:
3863 break;
3864 }
3865 } 3795 }
3866
3867 /* Start discovery - this should just do CLEAR_LA */
3868 lpfc_disc_start(vport);
3869 } 3796 }
3870 return 0; 3797 return 0;
3871} 3798}
@@ -3875,20 +3802,17 @@ lpfc_els_timeout(unsigned long ptr)
3875{ 3802{
3876 struct lpfc_vport *vport = (struct lpfc_vport *) ptr; 3803 struct lpfc_vport *vport = (struct lpfc_vport *) ptr;
3877 struct lpfc_hba *phba = vport->phba; 3804 struct lpfc_hba *phba = vport->phba;
3805 uint32_t tmo_posted;
3878 unsigned long iflag; 3806 unsigned long iflag;
3879 3807
3880 spin_lock_irqsave(&vport->work_port_lock, iflag); 3808 spin_lock_irqsave(&vport->work_port_lock, iflag);
3881 if ((vport->work_port_events & WORKER_ELS_TMO) == 0) { 3809 tmo_posted = vport->work_port_events & WORKER_ELS_TMO;
3810 if (!tmo_posted)
3882 vport->work_port_events |= WORKER_ELS_TMO; 3811 vport->work_port_events |= WORKER_ELS_TMO;
3883 spin_unlock_irqrestore(&vport->work_port_lock, iflag); 3812 spin_unlock_irqrestore(&vport->work_port_lock, iflag);
3884 3813
3885 spin_lock_irqsave(&phba->hbalock, iflag); 3814 if (!tmo_posted)
3886 if (phba->work_wait) 3815 lpfc_worker_wake_up(phba);
3887 lpfc_worker_wake_up(phba);
3888 spin_unlock_irqrestore(&phba->hbalock, iflag);
3889 }
3890 else
3891 spin_unlock_irqrestore(&vport->work_port_lock, iflag);
3892 return; 3816 return;
3893} 3817}
3894 3818
@@ -3933,9 +3857,6 @@ lpfc_els_timeout_handler(struct lpfc_vport *vport)
3933 els_command == ELS_CMD_FDISC) 3857 els_command == ELS_CMD_FDISC)
3934 continue; 3858 continue;
3935 3859
3936 if (vport != piocb->vport)
3937 continue;
3938
3939 if (piocb->drvrTimeout > 0) { 3860 if (piocb->drvrTimeout > 0) {
3940 if (piocb->drvrTimeout >= timeout) 3861 if (piocb->drvrTimeout >= timeout)
3941 piocb->drvrTimeout -= timeout; 3862 piocb->drvrTimeout -= timeout;
@@ -4089,7 +4010,7 @@ lpfc_els_unsol_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
4089 payload = ((struct lpfc_dmabuf *)elsiocb->context2)->virt; 4010 payload = ((struct lpfc_dmabuf *)elsiocb->context2)->virt;
4090 cmd = *payload; 4011 cmd = *payload;
4091 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) == 0) 4012 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) == 0)
4092 lpfc_post_buffer(phba, pring, 1, 1); 4013 lpfc_post_buffer(phba, pring, 1);
4093 4014
4094 did = icmd->un.rcvels.remoteID; 4015 did = icmd->un.rcvels.remoteID;
4095 if (icmd->ulpStatus) { 4016 if (icmd->ulpStatus) {
@@ -4398,7 +4319,7 @@ lpfc_els_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
4398 phba->fc_stat.NoRcvBuf++; 4319 phba->fc_stat.NoRcvBuf++;
4399 /* Not enough posted buffers; Try posting more buffers */ 4320 /* Not enough posted buffers; Try posting more buffers */
4400 if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)) 4321 if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED))
4401 lpfc_post_buffer(phba, pring, 0, 1); 4322 lpfc_post_buffer(phba, pring, 0);
4402 return; 4323 return;
4403 } 4324 }
4404 4325
@@ -4842,18 +4763,16 @@ lpfc_fabric_block_timeout(unsigned long ptr)
4842 struct lpfc_hba *phba = (struct lpfc_hba *) ptr; 4763 struct lpfc_hba *phba = (struct lpfc_hba *) ptr;
4843 unsigned long iflags; 4764 unsigned long iflags;
4844 uint32_t tmo_posted; 4765 uint32_t tmo_posted;
4766
4845 spin_lock_irqsave(&phba->pport->work_port_lock, iflags); 4767 spin_lock_irqsave(&phba->pport->work_port_lock, iflags);
4846 tmo_posted = phba->pport->work_port_events & WORKER_FABRIC_BLOCK_TMO; 4768 tmo_posted = phba->pport->work_port_events & WORKER_FABRIC_BLOCK_TMO;
4847 if (!tmo_posted) 4769 if (!tmo_posted)
4848 phba->pport->work_port_events |= WORKER_FABRIC_BLOCK_TMO; 4770 phba->pport->work_port_events |= WORKER_FABRIC_BLOCK_TMO;
4849 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags); 4771 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags);
4850 4772
4851 if (!tmo_posted) { 4773 if (!tmo_posted)
4852 spin_lock_irqsave(&phba->hbalock, iflags); 4774 lpfc_worker_wake_up(phba);
4853 if (phba->work_wait) 4775 return;
4854 lpfc_worker_wake_up(phba);
4855 spin_unlock_irqrestore(&phba->hbalock, iflags);
4856 }
4857} 4776}
4858 4777
4859static void 4778static void
diff --git a/drivers/scsi/lpfc/lpfc_hbadisc.c b/drivers/scsi/lpfc/lpfc_hbadisc.c
index 7cb68feb04fd..a98d11bf3576 100644
--- a/drivers/scsi/lpfc/lpfc_hbadisc.c
+++ b/drivers/scsi/lpfc/lpfc_hbadisc.c
@@ -153,11 +153,11 @@ lpfc_dev_loss_tmo_callbk(struct fc_rport *rport)
153 * count until this queued work is done 153 * count until this queued work is done
154 */ 154 */
155 evtp->evt_arg1 = lpfc_nlp_get(ndlp); 155 evtp->evt_arg1 = lpfc_nlp_get(ndlp);
156 evtp->evt = LPFC_EVT_DEV_LOSS; 156 if (evtp->evt_arg1) {
157 list_add_tail(&evtp->evt_listp, &phba->work_list); 157 evtp->evt = LPFC_EVT_DEV_LOSS;
158 if (phba->work_wait) 158 list_add_tail(&evtp->evt_listp, &phba->work_list);
159 wake_up(phba->work_wait); 159 lpfc_worker_wake_up(phba);
160 160 }
161 spin_unlock_irq(&phba->hbalock); 161 spin_unlock_irq(&phba->hbalock);
162 162
163 return; 163 return;
@@ -276,14 +276,6 @@ lpfc_dev_loss_tmo_handler(struct lpfc_nodelist *ndlp)
276 lpfc_disc_state_machine(vport, ndlp, NULL, NLP_EVT_DEVICE_RM); 276 lpfc_disc_state_machine(vport, ndlp, NULL, NLP_EVT_DEVICE_RM);
277} 277}
278 278
279
280void
281lpfc_worker_wake_up(struct lpfc_hba *phba)
282{
283 wake_up(phba->work_wait);
284 return;
285}
286
287static void 279static void
288lpfc_work_list_done(struct lpfc_hba *phba) 280lpfc_work_list_done(struct lpfc_hba *phba)
289{ 281{
@@ -429,6 +421,8 @@ lpfc_work_done(struct lpfc_hba *phba)
429 || (pring->flag & LPFC_DEFERRED_RING_EVENT)) { 421 || (pring->flag & LPFC_DEFERRED_RING_EVENT)) {
430 if (pring->flag & LPFC_STOP_IOCB_EVENT) { 422 if (pring->flag & LPFC_STOP_IOCB_EVENT) {
431 pring->flag |= LPFC_DEFERRED_RING_EVENT; 423 pring->flag |= LPFC_DEFERRED_RING_EVENT;
424 /* Set the lpfc data pending flag */
425 set_bit(LPFC_DATA_READY, &phba->data_flags);
432 } else { 426 } else {
433 pring->flag &= ~LPFC_DEFERRED_RING_EVENT; 427 pring->flag &= ~LPFC_DEFERRED_RING_EVENT;
434 lpfc_sli_handle_slow_ring_event(phba, pring, 428 lpfc_sli_handle_slow_ring_event(phba, pring,
@@ -459,69 +453,29 @@ lpfc_work_done(struct lpfc_hba *phba)
459 lpfc_work_list_done(phba); 453 lpfc_work_list_done(phba);
460} 454}
461 455
462static int
463check_work_wait_done(struct lpfc_hba *phba)
464{
465 struct lpfc_vport *vport;
466 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
467 int rc = 0;
468
469 spin_lock_irq(&phba->hbalock);
470 list_for_each_entry(vport, &phba->port_list, listentry) {
471 if (vport->work_port_events) {
472 rc = 1;
473 break;
474 }
475 }
476 if (rc || phba->work_ha || (!list_empty(&phba->work_list)) ||
477 kthread_should_stop() || pring->flag & LPFC_DEFERRED_RING_EVENT) {
478 rc = 1;
479 phba->work_found++;
480 } else
481 phba->work_found = 0;
482 spin_unlock_irq(&phba->hbalock);
483 return rc;
484}
485
486
487int 456int
488lpfc_do_work(void *p) 457lpfc_do_work(void *p)
489{ 458{
490 struct lpfc_hba *phba = p; 459 struct lpfc_hba *phba = p;
491 int rc; 460 int rc;
492 DECLARE_WAIT_QUEUE_HEAD_ONSTACK(work_waitq);
493 461
494 set_user_nice(current, -20); 462 set_user_nice(current, -20);
495 phba->work_wait = &work_waitq; 463 phba->data_flags = 0;
496 phba->work_found = 0;
497 464
498 while (1) { 465 while (1) {
499 466 /* wait and check worker queue activities */
500 rc = wait_event_interruptible(work_waitq, 467 rc = wait_event_interruptible(phba->work_waitq,
501 check_work_wait_done(phba)); 468 (test_and_clear_bit(LPFC_DATA_READY,
502 469 &phba->data_flags)
470 || kthread_should_stop()));
503 BUG_ON(rc); 471 BUG_ON(rc);
504 472
505 if (kthread_should_stop()) 473 if (kthread_should_stop())
506 break; 474 break;
507 475
476 /* Attend pending lpfc data processing */
508 lpfc_work_done(phba); 477 lpfc_work_done(phba);
509
510 /* If there is alot of slow ring work, like during link up
511 * check_work_wait_done() may cause this thread to not give
512 * up the CPU for very long periods of time. This may cause
513 * soft lockups or other problems. To avoid these situations
514 * give up the CPU here after LPFC_MAX_WORKER_ITERATION
515 * consecutive iterations.
516 */
517 if (phba->work_found >= LPFC_MAX_WORKER_ITERATION) {
518 phba->work_found = 0;
519 schedule();
520 }
521 } 478 }
522 spin_lock_irq(&phba->hbalock);
523 phba->work_wait = NULL;
524 spin_unlock_irq(&phba->hbalock);
525 return 0; 479 return 0;
526} 480}
527 481
@@ -551,10 +505,10 @@ lpfc_workq_post_event(struct lpfc_hba *phba, void *arg1, void *arg2,
551 505
552 spin_lock_irqsave(&phba->hbalock, flags); 506 spin_lock_irqsave(&phba->hbalock, flags);
553 list_add_tail(&evtp->evt_listp, &phba->work_list); 507 list_add_tail(&evtp->evt_listp, &phba->work_list);
554 if (phba->work_wait)
555 lpfc_worker_wake_up(phba);
556 spin_unlock_irqrestore(&phba->hbalock, flags); 508 spin_unlock_irqrestore(&phba->hbalock, flags);
557 509
510 lpfc_worker_wake_up(phba);
511
558 return 1; 512 return 1;
559} 513}
560 514
@@ -963,6 +917,10 @@ lpfc_mbx_process_link_up(struct lpfc_hba *phba, READ_LA_VAR *la)
963 if (phba->fc_topology == TOPOLOGY_LOOP) { 917 if (phba->fc_topology == TOPOLOGY_LOOP) {
964 phba->sli3_options &= ~LPFC_SLI3_NPIV_ENABLED; 918 phba->sli3_options &= ~LPFC_SLI3_NPIV_ENABLED;
965 919
920 if (phba->cfg_enable_npiv)
921 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
922 "1309 Link Up Event npiv not supported in loop "
923 "topology\n");
966 /* Get Loop Map information */ 924 /* Get Loop Map information */
967 if (la->il) 925 if (la->il)
968 vport->fc_flag |= FC_LBIT; 926 vport->fc_flag |= FC_LBIT;
@@ -1087,6 +1045,8 @@ lpfc_mbx_cmpl_read_la(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
1087 MAILBOX_t *mb = &pmb->mb; 1045 MAILBOX_t *mb = &pmb->mb;
1088 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1); 1046 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
1089 1047
1048 /* Unblock ELS traffic */
1049 phba->sli.ring[LPFC_ELS_RING].flag &= ~LPFC_STOP_IOCB_EVENT;
1090 /* Check for error */ 1050 /* Check for error */
1091 if (mb->mbxStatus) { 1051 if (mb->mbxStatus) {
1092 lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT, 1052 lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
@@ -1650,7 +1610,6 @@ lpfc_nlp_set_state(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1650 ndlp->nlp_DID, old_state, state); 1610 ndlp->nlp_DID, old_state, state);
1651 1611
1652 if (old_state == NLP_STE_NPR_NODE && 1612 if (old_state == NLP_STE_NPR_NODE &&
1653 (ndlp->nlp_flag & NLP_DELAY_TMO) != 0 &&
1654 state != NLP_STE_NPR_NODE) 1613 state != NLP_STE_NPR_NODE)
1655 lpfc_cancel_retry_delay_tmo(vport, ndlp); 1614 lpfc_cancel_retry_delay_tmo(vport, ndlp);
1656 if (old_state == NLP_STE_UNMAPPED_NODE) { 1615 if (old_state == NLP_STE_UNMAPPED_NODE) {
@@ -1687,8 +1646,7 @@ lpfc_dequeue_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
1687{ 1646{
1688 struct Scsi_Host *shost = lpfc_shost_from_vport(vport); 1647 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1689 1648
1690 if ((ndlp->nlp_flag & NLP_DELAY_TMO) != 0) 1649 lpfc_cancel_retry_delay_tmo(vport, ndlp);
1691 lpfc_cancel_retry_delay_tmo(vport, ndlp);
1692 if (ndlp->nlp_state && !list_empty(&ndlp->nlp_listp)) 1650 if (ndlp->nlp_state && !list_empty(&ndlp->nlp_listp))
1693 lpfc_nlp_counters(vport, ndlp->nlp_state, -1); 1651 lpfc_nlp_counters(vport, ndlp->nlp_state, -1);
1694 spin_lock_irq(shost->host_lock); 1652 spin_lock_irq(shost->host_lock);
@@ -1701,8 +1659,7 @@ lpfc_dequeue_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
1701static void 1659static void
1702lpfc_disable_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) 1660lpfc_disable_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
1703{ 1661{
1704 if ((ndlp->nlp_flag & NLP_DELAY_TMO) != 0) 1662 lpfc_cancel_retry_delay_tmo(vport, ndlp);
1705 lpfc_cancel_retry_delay_tmo(vport, ndlp);
1706 if (ndlp->nlp_state && !list_empty(&ndlp->nlp_listp)) 1663 if (ndlp->nlp_state && !list_empty(&ndlp->nlp_listp))
1707 lpfc_nlp_counters(vport, ndlp->nlp_state, -1); 1664 lpfc_nlp_counters(vport, ndlp->nlp_state, -1);
1708 lpfc_nlp_state_cleanup(vport, ndlp, ndlp->nlp_state, 1665 lpfc_nlp_state_cleanup(vport, ndlp, ndlp->nlp_state,
@@ -2121,10 +2078,8 @@ lpfc_cleanup_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
2121 ndlp->nlp_last_elscmd = 0; 2078 ndlp->nlp_last_elscmd = 0;
2122 del_timer_sync(&ndlp->nlp_delayfunc); 2079 del_timer_sync(&ndlp->nlp_delayfunc);
2123 2080
2124 if (!list_empty(&ndlp->els_retry_evt.evt_listp)) 2081 list_del_init(&ndlp->els_retry_evt.evt_listp);
2125 list_del_init(&ndlp->els_retry_evt.evt_listp); 2082 list_del_init(&ndlp->dev_loss_evt.evt_listp);
2126 if (!list_empty(&ndlp->dev_loss_evt.evt_listp))
2127 list_del_init(&ndlp->dev_loss_evt.evt_listp);
2128 2083
2129 lpfc_unreg_rpi(vport, ndlp); 2084 lpfc_unreg_rpi(vport, ndlp);
2130 2085
@@ -2144,10 +2099,7 @@ lpfc_nlp_remove(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
2144 LPFC_MBOXQ_t *mbox; 2099 LPFC_MBOXQ_t *mbox;
2145 int rc; 2100 int rc;
2146 2101
2147 if (ndlp->nlp_flag & NLP_DELAY_TMO) { 2102 lpfc_cancel_retry_delay_tmo(vport, ndlp);
2148 lpfc_cancel_retry_delay_tmo(vport, ndlp);
2149 }
2150
2151 if (ndlp->nlp_flag & NLP_DEFER_RM && !ndlp->nlp_rpi) { 2103 if (ndlp->nlp_flag & NLP_DEFER_RM && !ndlp->nlp_rpi) {
2152 /* For this case we need to cleanup the default rpi 2104 /* For this case we need to cleanup the default rpi
2153 * allocated by the firmware. 2105 * allocated by the firmware.
@@ -2317,8 +2269,7 @@ lpfc_setup_disc_node(struct lpfc_vport *vport, uint32_t did)
2317 /* Since this node is marked for discovery, 2269 /* Since this node is marked for discovery,
2318 * delay timeout is not needed. 2270 * delay timeout is not needed.
2319 */ 2271 */
2320 if (ndlp->nlp_flag & NLP_DELAY_TMO) 2272 lpfc_cancel_retry_delay_tmo(vport, ndlp);
2321 lpfc_cancel_retry_delay_tmo(vport, ndlp);
2322 } else 2273 } else
2323 ndlp = NULL; 2274 ndlp = NULL;
2324 } else { 2275 } else {
@@ -2643,21 +2594,20 @@ lpfc_disc_timeout(unsigned long ptr)
2643{ 2594{
2644 struct lpfc_vport *vport = (struct lpfc_vport *) ptr; 2595 struct lpfc_vport *vport = (struct lpfc_vport *) ptr;
2645 struct lpfc_hba *phba = vport->phba; 2596 struct lpfc_hba *phba = vport->phba;
2597 uint32_t tmo_posted;
2646 unsigned long flags = 0; 2598 unsigned long flags = 0;
2647 2599
2648 if (unlikely(!phba)) 2600 if (unlikely(!phba))
2649 return; 2601 return;
2650 2602
2651 if ((vport->work_port_events & WORKER_DISC_TMO) == 0) { 2603 spin_lock_irqsave(&vport->work_port_lock, flags);
2652 spin_lock_irqsave(&vport->work_port_lock, flags); 2604 tmo_posted = vport->work_port_events & WORKER_DISC_TMO;
2605 if (!tmo_posted)
2653 vport->work_port_events |= WORKER_DISC_TMO; 2606 vport->work_port_events |= WORKER_DISC_TMO;
2654 spin_unlock_irqrestore(&vport->work_port_lock, flags); 2607 spin_unlock_irqrestore(&vport->work_port_lock, flags);
2655 2608
2656 spin_lock_irqsave(&phba->hbalock, flags); 2609 if (!tmo_posted)
2657 if (phba->work_wait) 2610 lpfc_worker_wake_up(phba);
2658 lpfc_worker_wake_up(phba);
2659 spin_unlock_irqrestore(&phba->hbalock, flags);
2660 }
2661 return; 2611 return;
2662} 2612}
2663 2613
diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
index fa757b251f82..5b6e5395c8eb 100644
--- a/drivers/scsi/lpfc/lpfc_init.c
+++ b/drivers/scsi/lpfc/lpfc_init.c
@@ -145,8 +145,10 @@ lpfc_config_port_prep(struct lpfc_hba *phba)
145 return -ERESTART; 145 return -ERESTART;
146 } 146 }
147 147
148 if (phba->sli_rev == 3 && !mb->un.varRdRev.v3rsp) 148 if (phba->sli_rev == 3 && !mb->un.varRdRev.v3rsp) {
149 mempool_free(pmb, phba->mbox_mem_pool);
149 return -EINVAL; 150 return -EINVAL;
151 }
150 152
151 /* Save information as VPD data */ 153 /* Save information as VPD data */
152 vp->rev.rBit = 1; 154 vp->rev.rBit = 1;
@@ -551,18 +553,18 @@ static void
551lpfc_hb_timeout(unsigned long ptr) 553lpfc_hb_timeout(unsigned long ptr)
552{ 554{
553 struct lpfc_hba *phba; 555 struct lpfc_hba *phba;
556 uint32_t tmo_posted;
554 unsigned long iflag; 557 unsigned long iflag;
555 558
556 phba = (struct lpfc_hba *)ptr; 559 phba = (struct lpfc_hba *)ptr;
557 spin_lock_irqsave(&phba->pport->work_port_lock, iflag); 560 spin_lock_irqsave(&phba->pport->work_port_lock, iflag);
558 if (!(phba->pport->work_port_events & WORKER_HB_TMO)) 561 tmo_posted = phba->pport->work_port_events & WORKER_HB_TMO;
562 if (!tmo_posted)
559 phba->pport->work_port_events |= WORKER_HB_TMO; 563 phba->pport->work_port_events |= WORKER_HB_TMO;
560 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag); 564 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag);
561 565
562 spin_lock_irqsave(&phba->hbalock, iflag); 566 if (!tmo_posted)
563 if (phba->work_wait) 567 lpfc_worker_wake_up(phba);
564 wake_up(phba->work_wait);
565 spin_unlock_irqrestore(&phba->hbalock, iflag);
566 return; 568 return;
567} 569}
568 570
@@ -851,6 +853,8 @@ lpfc_handle_latt(struct lpfc_hba *phba)
851 lpfc_read_la(phba, pmb, mp); 853 lpfc_read_la(phba, pmb, mp);
852 pmb->mbox_cmpl = lpfc_mbx_cmpl_read_la; 854 pmb->mbox_cmpl = lpfc_mbx_cmpl_read_la;
853 pmb->vport = vport; 855 pmb->vport = vport;
856 /* Block ELS IOCBs until we have processed this mbox command */
857 phba->sli.ring[LPFC_ELS_RING].flag |= LPFC_STOP_IOCB_EVENT;
854 rc = lpfc_sli_issue_mbox (phba, pmb, MBX_NOWAIT); 858 rc = lpfc_sli_issue_mbox (phba, pmb, MBX_NOWAIT);
855 if (rc == MBX_NOT_FINISHED) { 859 if (rc == MBX_NOT_FINISHED) {
856 rc = 4; 860 rc = 4;
@@ -866,6 +870,7 @@ lpfc_handle_latt(struct lpfc_hba *phba)
866 return; 870 return;
867 871
868lpfc_handle_latt_free_mbuf: 872lpfc_handle_latt_free_mbuf:
873 phba->sli.ring[LPFC_ELS_RING].flag &= ~LPFC_STOP_IOCB_EVENT;
869 lpfc_mbuf_free(phba, mp->virt, mp->phys); 874 lpfc_mbuf_free(phba, mp->virt, mp->phys);
870lpfc_handle_latt_free_mp: 875lpfc_handle_latt_free_mp:
871 kfree(mp); 876 kfree(mp);
@@ -1194,8 +1199,7 @@ lpfc_get_hba_model_desc(struct lpfc_hba *phba, uint8_t *mdp, uint8_t *descp)
1194/* Returns the number of buffers NOT posted. */ 1199/* Returns the number of buffers NOT posted. */
1195/**************************************************/ 1200/**************************************************/
1196int 1201int
1197lpfc_post_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, int cnt, 1202lpfc_post_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, int cnt)
1198 int type)
1199{ 1203{
1200 IOCB_t *icmd; 1204 IOCB_t *icmd;
1201 struct lpfc_iocbq *iocb; 1205 struct lpfc_iocbq *iocb;
@@ -1295,7 +1299,7 @@ lpfc_post_rcv_buf(struct lpfc_hba *phba)
1295 struct lpfc_sli *psli = &phba->sli; 1299 struct lpfc_sli *psli = &phba->sli;
1296 1300
1297 /* Ring 0, ELS / CT buffers */ 1301 /* Ring 0, ELS / CT buffers */
1298 lpfc_post_buffer(phba, &psli->ring[LPFC_ELS_RING], LPFC_BUF_RING0, 1); 1302 lpfc_post_buffer(phba, &psli->ring[LPFC_ELS_RING], LPFC_BUF_RING0);
1299 /* Ring 2 - FCP no buffers needed */ 1303 /* Ring 2 - FCP no buffers needed */
1300 1304
1301 return 0; 1305 return 0;
@@ -1454,6 +1458,15 @@ lpfc_cleanup(struct lpfc_vport *vport)
1454 1458
1455 lpfc_disc_state_machine(vport, ndlp, NULL, 1459 lpfc_disc_state_machine(vport, ndlp, NULL,
1456 NLP_EVT_DEVICE_RM); 1460 NLP_EVT_DEVICE_RM);
1461
1462 /* nlp_type zero is not defined, nlp_flag zero also not defined,
1463 * nlp_state is unused, this happens when
1464 * an initiator has logged
1465 * into us so cleanup this ndlp.
1466 */
1467 if ((ndlp->nlp_type == 0) && (ndlp->nlp_flag == 0) &&
1468 (ndlp->nlp_state == 0))
1469 lpfc_nlp_put(ndlp);
1457 } 1470 }
1458 1471
1459 /* At this point, ALL ndlp's should be gone 1472 /* At this point, ALL ndlp's should be gone
@@ -2101,6 +2114,9 @@ lpfc_pci_probe_one(struct pci_dev *pdev, const struct pci_device_id *pid)
2101 phba->work_ha_mask = (HA_ERATT|HA_MBATT|HA_LATT); 2114 phba->work_ha_mask = (HA_ERATT|HA_MBATT|HA_LATT);
2102 phba->work_ha_mask |= (HA_RXMASK << (LPFC_ELS_RING * 4)); 2115 phba->work_ha_mask |= (HA_RXMASK << (LPFC_ELS_RING * 4));
2103 2116
2117 /* Initialize the wait queue head for the kernel thread */
2118 init_waitqueue_head(&phba->work_waitq);
2119
2104 /* Startup the kernel thread for this host adapter. */ 2120 /* Startup the kernel thread for this host adapter. */
2105 phba->worker_thread = kthread_run(lpfc_do_work, phba, 2121 phba->worker_thread = kthread_run(lpfc_do_work, phba,
2106 "lpfc_worker_%d", phba->brd_no); 2122 "lpfc_worker_%d", phba->brd_no);
diff --git a/drivers/scsi/lpfc/lpfc_nportdisc.c b/drivers/scsi/lpfc/lpfc_nportdisc.c
index d08c4c890744..6688a8689b56 100644
--- a/drivers/scsi/lpfc/lpfc_nportdisc.c
+++ b/drivers/scsi/lpfc/lpfc_nportdisc.c
@@ -235,10 +235,7 @@ lpfc_els_abort(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp)
235 (iocb->iocb_cmpl) (phba, iocb, iocb); 235 (iocb->iocb_cmpl) (phba, iocb, iocb);
236 } 236 }
237 } 237 }
238 238 lpfc_cancel_retry_delay_tmo(phba->pport, ndlp);
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);
242 return 0; 239 return 0;
243} 240}
244 241
@@ -249,7 +246,6 @@ lpfc_rcv_plogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
249 struct Scsi_Host *shost = lpfc_shost_from_vport(vport); 246 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
250 struct lpfc_hba *phba = vport->phba; 247 struct lpfc_hba *phba = vport->phba;
251 struct lpfc_dmabuf *pcmd; 248 struct lpfc_dmabuf *pcmd;
252 struct lpfc_work_evt *evtp;
253 uint32_t *lp; 249 uint32_t *lp;
254 IOCB_t *icmd; 250 IOCB_t *icmd;
255 struct serv_parm *sp; 251 struct serv_parm *sp;
@@ -425,73 +421,8 @@ lpfc_rcv_plogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
425 ndlp, mbox); 421 ndlp, mbox);
426 return 1; 422 return 1;
427 } 423 }
428
429 /* If the remote NPort logs into us, before we can initiate
430 * discovery to them, cleanup the NPort from discovery accordingly.
431 */
432 if (ndlp->nlp_state == NLP_STE_NPR_NODE) {
433 spin_lock_irq(shost->host_lock);
434 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
435 spin_unlock_irq(shost->host_lock);
436 del_timer_sync(&ndlp->nlp_delayfunc);
437 ndlp->nlp_last_elscmd = 0;
438
439 if (!list_empty(&ndlp->els_retry_evt.evt_listp)) {
440 list_del_init(&ndlp->els_retry_evt.evt_listp);
441 /* Decrement ndlp reference count held for the
442 * delayed retry
443 */
444 evtp = &ndlp->els_retry_evt;
445 lpfc_nlp_put((struct lpfc_nodelist *)evtp->evt_arg1);
446 }
447
448 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
449 spin_lock_irq(shost->host_lock);
450 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
451 spin_unlock_irq(shost->host_lock);
452
453 if ((ndlp->nlp_flag & NLP_ADISC_SND) &&
454 (vport->num_disc_nodes)) {
455 /* Check to see if there are more
456 * ADISCs to be sent
457 */
458 lpfc_more_adisc(vport);
459
460 if ((vport->num_disc_nodes == 0) &&
461 (vport->fc_npr_cnt))
462 lpfc_els_disc_plogi(vport);
463
464 if (vport->num_disc_nodes == 0) {
465 spin_lock_irq(shost->host_lock);
466 vport->fc_flag &= ~FC_NDISC_ACTIVE;
467 spin_unlock_irq(shost->host_lock);
468 lpfc_can_disctmo(vport);
469 lpfc_end_rscn(vport);
470 }
471 }
472 }
473 } else if ((ndlp->nlp_state == NLP_STE_PLOGI_ISSUE) &&
474 (ndlp->nlp_flag & NLP_NPR_2B_DISC) &&
475 (vport->num_disc_nodes)) {
476 spin_lock_irq(shost->host_lock);
477 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
478 spin_unlock_irq(shost->host_lock);
479 /* Check to see if there are more
480 * PLOGIs to be sent
481 */
482 lpfc_more_plogi(vport);
483 if (vport->num_disc_nodes == 0) {
484 spin_lock_irq(shost->host_lock);
485 vport->fc_flag &= ~FC_NDISC_ACTIVE;
486 spin_unlock_irq(shost->host_lock);
487 lpfc_can_disctmo(vport);
488 lpfc_end_rscn(vport);
489 }
490 }
491
492 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp, mbox); 424 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp, mbox);
493 return 1; 425 return 1;
494
495out: 426out:
496 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; 427 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
497 stat.un.b.lsRjtRsnCodeExp = LSEXP_OUT_OF_RESOURCE; 428 stat.un.b.lsRjtRsnCodeExp = LSEXP_OUT_OF_RESOURCE;
@@ -574,7 +505,9 @@ lpfc_rcv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
574 else 505 else
575 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); 506 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
576 507
577 if (!(ndlp->nlp_type & NLP_FABRIC) || 508 if ((!(ndlp->nlp_type & NLP_FABRIC) &&
509 ((ndlp->nlp_type & NLP_FCP_TARGET) ||
510 !(ndlp->nlp_type & NLP_FCP_INITIATOR))) ||
578 (ndlp->nlp_state == NLP_STE_ADISC_ISSUE)) { 511 (ndlp->nlp_state == NLP_STE_ADISC_ISSUE)) {
579 /* Only try to re-login if this is NOT a Fabric Node */ 512 /* Only try to re-login if this is NOT a Fabric Node */
580 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ * 1); 513 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ * 1);
@@ -751,6 +684,7 @@ static uint32_t
751lpfc_rcv_plogi_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, 684lpfc_rcv_plogi_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
752 void *arg, uint32_t evt) 685 void *arg, uint32_t evt)
753{ 686{
687 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
754 struct lpfc_hba *phba = vport->phba; 688 struct lpfc_hba *phba = vport->phba;
755 struct lpfc_iocbq *cmdiocb = arg; 689 struct lpfc_iocbq *cmdiocb = arg;
756 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; 690 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
@@ -776,7 +710,22 @@ lpfc_rcv_plogi_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
776 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, 710 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
777 NULL); 711 NULL);
778 } else { 712 } else {
779 lpfc_rcv_plogi(vport, ndlp, cmdiocb); 713 if (lpfc_rcv_plogi(vport, ndlp, cmdiocb) &&
714 (ndlp->nlp_flag & NLP_NPR_2B_DISC) &&
715 (vport->num_disc_nodes)) {
716 spin_lock_irq(shost->host_lock);
717 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
718 spin_unlock_irq(shost->host_lock);
719 /* Check if there are more PLOGIs to be sent */
720 lpfc_more_plogi(vport);
721 if (vport->num_disc_nodes == 0) {
722 spin_lock_irq(shost->host_lock);
723 vport->fc_flag &= ~FC_NDISC_ACTIVE;
724 spin_unlock_irq(shost->host_lock);
725 lpfc_can_disctmo(vport);
726 lpfc_end_rscn(vport);
727 }
728 }
780 } /* If our portname was less */ 729 } /* If our portname was less */
781 730
782 return ndlp->nlp_state; 731 return ndlp->nlp_state;
@@ -1040,6 +989,7 @@ static uint32_t
1040lpfc_rcv_plogi_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, 989lpfc_rcv_plogi_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1041 void *arg, uint32_t evt) 990 void *arg, uint32_t evt)
1042{ 991{
992 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1043 struct lpfc_hba *phba = vport->phba; 993 struct lpfc_hba *phba = vport->phba;
1044 struct lpfc_iocbq *cmdiocb; 994 struct lpfc_iocbq *cmdiocb;
1045 995
@@ -1048,9 +998,28 @@ lpfc_rcv_plogi_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1048 998
1049 cmdiocb = (struct lpfc_iocbq *) arg; 999 cmdiocb = (struct lpfc_iocbq *) arg;
1050 1000
1051 if (lpfc_rcv_plogi(vport, ndlp, cmdiocb)) 1001 if (lpfc_rcv_plogi(vport, ndlp, cmdiocb)) {
1052 return ndlp->nlp_state; 1002 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1003 spin_lock_irq(shost->host_lock);
1004 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
1005 spin_unlock_irq(shost->host_lock);
1053 1006
1007 if (vport->num_disc_nodes) {
1008 lpfc_more_adisc(vport);
1009 if ((vport->num_disc_nodes == 0) &&
1010 (vport->fc_npr_cnt))
1011 lpfc_els_disc_plogi(vport);
1012 if (vport->num_disc_nodes == 0) {
1013 spin_lock_irq(shost->host_lock);
1014 vport->fc_flag &= ~FC_NDISC_ACTIVE;
1015 spin_unlock_irq(shost->host_lock);
1016 lpfc_can_disctmo(vport);
1017 lpfc_end_rscn(vport);
1018 }
1019 }
1020 }
1021 return ndlp->nlp_state;
1022 }
1054 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE; 1023 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
1055 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0); 1024 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
1056 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); 1025 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
@@ -1742,24 +1711,21 @@ lpfc_rcv_plogi_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1742 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg; 1711 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1743 1712
1744 /* Ignore PLOGI if we have an outstanding LOGO */ 1713 /* Ignore PLOGI if we have an outstanding LOGO */
1745 if (ndlp->nlp_flag & (NLP_LOGO_SND | NLP_LOGO_ACC)) { 1714 if (ndlp->nlp_flag & (NLP_LOGO_SND | NLP_LOGO_ACC))
1746 return ndlp->nlp_state; 1715 return ndlp->nlp_state;
1747 }
1748
1749 if (lpfc_rcv_plogi(vport, ndlp, cmdiocb)) { 1716 if (lpfc_rcv_plogi(vport, ndlp, cmdiocb)) {
1717 lpfc_cancel_retry_delay_tmo(vport, ndlp);
1750 spin_lock_irq(shost->host_lock); 1718 spin_lock_irq(shost->host_lock);
1751 ndlp->nlp_flag &= ~NLP_NPR_ADISC; 1719 ndlp->nlp_flag &= ~(NLP_NPR_ADISC | NLP_NPR_2B_DISC);
1752 spin_unlock_irq(shost->host_lock); 1720 spin_unlock_irq(shost->host_lock);
1753 return ndlp->nlp_state; 1721 } else if (!(ndlp->nlp_flag & NLP_NPR_2B_DISC)) {
1754 } 1722 /* send PLOGI immediately, move to PLOGI issue state */
1755 1723 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
1756 /* send PLOGI immediately, move to PLOGI issue state */ 1724 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
1757 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) { 1725 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
1758 ndlp->nlp_prev_state = NLP_STE_NPR_NODE; 1726 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
1759 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); 1727 }
1760 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
1761 } 1728 }
1762
1763 return ndlp->nlp_state; 1729 return ndlp->nlp_state;
1764} 1730}
1765 1731
@@ -1810,7 +1776,6 @@ lpfc_rcv_padisc_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1810 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg; 1776 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1811 1777
1812 lpfc_rcv_padisc(vport, ndlp, cmdiocb); 1778 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
1813
1814 /* 1779 /*
1815 * Do not start discovery if discovery is about to start 1780 * Do not start discovery if discovery is about to start
1816 * or discovery in progress for this node. Starting discovery 1781 * or discovery in progress for this node. Starting discovery
@@ -1973,9 +1938,7 @@ lpfc_device_recov_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1973 spin_lock_irq(shost->host_lock); 1938 spin_lock_irq(shost->host_lock);
1974 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC); 1939 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
1975 spin_unlock_irq(shost->host_lock); 1940 spin_unlock_irq(shost->host_lock);
1976 if (ndlp->nlp_flag & NLP_DELAY_TMO) { 1941 lpfc_cancel_retry_delay_tmo(vport, ndlp);
1977 lpfc_cancel_retry_delay_tmo(vport, ndlp);
1978 }
1979 return ndlp->nlp_state; 1942 return ndlp->nlp_state;
1980} 1943}
1981 1944
diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
index 0910a9ab76a5..c94da4f2b8a6 100644
--- a/drivers/scsi/lpfc/lpfc_scsi.c
+++ b/drivers/scsi/lpfc/lpfc_scsi.c
@@ -50,6 +50,7 @@ void
50lpfc_adjust_queue_depth(struct lpfc_hba *phba) 50lpfc_adjust_queue_depth(struct lpfc_hba *phba)
51{ 51{
52 unsigned long flags; 52 unsigned long flags;
53 uint32_t evt_posted;
53 54
54 spin_lock_irqsave(&phba->hbalock, flags); 55 spin_lock_irqsave(&phba->hbalock, flags);
55 atomic_inc(&phba->num_rsrc_err); 56 atomic_inc(&phba->num_rsrc_err);
@@ -65,17 +66,13 @@ lpfc_adjust_queue_depth(struct lpfc_hba *phba)
65 spin_unlock_irqrestore(&phba->hbalock, flags); 66 spin_unlock_irqrestore(&phba->hbalock, flags);
66 67
67 spin_lock_irqsave(&phba->pport->work_port_lock, flags); 68 spin_lock_irqsave(&phba->pport->work_port_lock, flags);
68 if ((phba->pport->work_port_events & 69 evt_posted = phba->pport->work_port_events & WORKER_RAMP_DOWN_QUEUE;
69 WORKER_RAMP_DOWN_QUEUE) == 0) { 70 if (!evt_posted)
70 phba->pport->work_port_events |= WORKER_RAMP_DOWN_QUEUE; 71 phba->pport->work_port_events |= WORKER_RAMP_DOWN_QUEUE;
71 }
72 spin_unlock_irqrestore(&phba->pport->work_port_lock, flags); 72 spin_unlock_irqrestore(&phba->pport->work_port_lock, flags);
73 73
74 spin_lock_irqsave(&phba->hbalock, flags); 74 if (!evt_posted)
75 if (phba->work_wait) 75 lpfc_worker_wake_up(phba);
76 wake_up(phba->work_wait);
77 spin_unlock_irqrestore(&phba->hbalock, flags);
78
79 return; 76 return;
80} 77}
81 78
@@ -89,6 +86,7 @@ lpfc_rampup_queue_depth(struct lpfc_vport *vport,
89{ 86{
90 unsigned long flags; 87 unsigned long flags;
91 struct lpfc_hba *phba = vport->phba; 88 struct lpfc_hba *phba = vport->phba;
89 uint32_t evt_posted;
92 atomic_inc(&phba->num_cmd_success); 90 atomic_inc(&phba->num_cmd_success);
93 91
94 if (vport->cfg_lun_queue_depth <= sdev->queue_depth) 92 if (vport->cfg_lun_queue_depth <= sdev->queue_depth)
@@ -103,16 +101,14 @@ lpfc_rampup_queue_depth(struct lpfc_vport *vport,
103 spin_unlock_irqrestore(&phba->hbalock, flags); 101 spin_unlock_irqrestore(&phba->hbalock, flags);
104 102
105 spin_lock_irqsave(&phba->pport->work_port_lock, flags); 103 spin_lock_irqsave(&phba->pport->work_port_lock, flags);
106 if ((phba->pport->work_port_events & 104 evt_posted = phba->pport->work_port_events & WORKER_RAMP_UP_QUEUE;
107 WORKER_RAMP_UP_QUEUE) == 0) { 105 if (!evt_posted)
108 phba->pport->work_port_events |= WORKER_RAMP_UP_QUEUE; 106 phba->pport->work_port_events |= WORKER_RAMP_UP_QUEUE;
109 }
110 spin_unlock_irqrestore(&phba->pport->work_port_lock, flags); 107 spin_unlock_irqrestore(&phba->pport->work_port_lock, flags);
111 108
112 spin_lock_irqsave(&phba->hbalock, flags); 109 if (!evt_posted)
113 if (phba->work_wait) 110 lpfc_worker_wake_up(phba);
114 wake_up(phba->work_wait); 111 return;
115 spin_unlock_irqrestore(&phba->hbalock, flags);
116} 112}
117 113
118void 114void
@@ -609,9 +605,6 @@ lpfc_scsi_cmd_iocb_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *pIocbIn,
609 result = cmd->result; 605 result = cmd->result;
610 sdev = cmd->device; 606 sdev = cmd->device;
611 lpfc_scsi_unprep_dma_buf(phba, lpfc_cmd); 607 lpfc_scsi_unprep_dma_buf(phba, lpfc_cmd);
612 spin_lock_irqsave(sdev->host->host_lock, flags);
613 lpfc_cmd->pCmd = NULL; /* This must be done before scsi_done */
614 spin_unlock_irqrestore(sdev->host->host_lock, flags);
615 cmd->scsi_done(cmd); 608 cmd->scsi_done(cmd);
616 609
617 if (phba->cfg_poll & ENABLE_FCP_RING_POLLING) { 610 if (phba->cfg_poll & ENABLE_FCP_RING_POLLING) {
@@ -620,6 +613,7 @@ lpfc_scsi_cmd_iocb_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *pIocbIn,
620 * wake up the thread. 613 * wake up the thread.
621 */ 614 */
622 spin_lock_irqsave(sdev->host->host_lock, flags); 615 spin_lock_irqsave(sdev->host->host_lock, flags);
616 lpfc_cmd->pCmd = NULL;
623 if (lpfc_cmd->waitq) 617 if (lpfc_cmd->waitq)
624 wake_up(lpfc_cmd->waitq); 618 wake_up(lpfc_cmd->waitq);
625 spin_unlock_irqrestore(sdev->host->host_lock, flags); 619 spin_unlock_irqrestore(sdev->host->host_lock, flags);
@@ -690,6 +684,7 @@ lpfc_scsi_cmd_iocb_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *pIocbIn,
690 * wake up the thread. 684 * wake up the thread.
691 */ 685 */
692 spin_lock_irqsave(sdev->host->host_lock, flags); 686 spin_lock_irqsave(sdev->host->host_lock, flags);
687 lpfc_cmd->pCmd = NULL;
693 if (lpfc_cmd->waitq) 688 if (lpfc_cmd->waitq)
694 wake_up(lpfc_cmd->waitq); 689 wake_up(lpfc_cmd->waitq);
695 spin_unlock_irqrestore(sdev->host->host_lock, flags); 690 spin_unlock_irqrestore(sdev->host->host_lock, flags);
@@ -849,14 +844,15 @@ lpfc_scsi_tgt_reset(struct lpfc_scsi_buf *lpfc_cmd, struct lpfc_vport *vport,
849 struct lpfc_iocbq *iocbq; 844 struct lpfc_iocbq *iocbq;
850 struct lpfc_iocbq *iocbqrsp; 845 struct lpfc_iocbq *iocbqrsp;
851 int ret; 846 int ret;
847 int status;
852 848
853 if (!rdata->pnode || !NLP_CHK_NODE_ACT(rdata->pnode)) 849 if (!rdata->pnode || !NLP_CHK_NODE_ACT(rdata->pnode))
854 return FAILED; 850 return FAILED;
855 851
856 lpfc_cmd->rdata = rdata; 852 lpfc_cmd->rdata = rdata;
857 ret = lpfc_scsi_prep_task_mgmt_cmd(vport, lpfc_cmd, lun, 853 status = lpfc_scsi_prep_task_mgmt_cmd(vport, lpfc_cmd, lun,
858 FCP_TARGET_RESET); 854 FCP_TARGET_RESET);
859 if (!ret) 855 if (!status)
860 return FAILED; 856 return FAILED;
861 857
862 iocbq = &lpfc_cmd->cur_iocbq; 858 iocbq = &lpfc_cmd->cur_iocbq;
@@ -869,12 +865,15 @@ lpfc_scsi_tgt_reset(struct lpfc_scsi_buf *lpfc_cmd, struct lpfc_vport *vport,
869 lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP, 865 lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP,
870 "0702 Issue Target Reset to TGT %d Data: x%x x%x\n", 866 "0702 Issue Target Reset to TGT %d Data: x%x x%x\n",
871 tgt_id, rdata->pnode->nlp_rpi, rdata->pnode->nlp_flag); 867 tgt_id, rdata->pnode->nlp_rpi, rdata->pnode->nlp_flag);
872 ret = lpfc_sli_issue_iocb_wait(phba, 868 status = lpfc_sli_issue_iocb_wait(phba,
873 &phba->sli.ring[phba->sli.fcp_ring], 869 &phba->sli.ring[phba->sli.fcp_ring],
874 iocbq, iocbqrsp, lpfc_cmd->timeout); 870 iocbq, iocbqrsp, lpfc_cmd->timeout);
875 if (ret != IOCB_SUCCESS) { 871 if (status != IOCB_SUCCESS) {
876 if (ret == IOCB_TIMEDOUT) 872 if (status == IOCB_TIMEDOUT) {
877 iocbq->iocb_cmpl = lpfc_tskmgmt_def_cmpl; 873 iocbq->iocb_cmpl = lpfc_tskmgmt_def_cmpl;
874 ret = TIMEOUT_ERROR;
875 } else
876 ret = FAILED;
878 lpfc_cmd->status = IOSTAT_DRIVER_REJECT; 877 lpfc_cmd->status = IOSTAT_DRIVER_REJECT;
879 } else { 878 } else {
880 ret = SUCCESS; 879 ret = SUCCESS;
@@ -1142,121 +1141,96 @@ lpfc_device_reset_handler(struct scsi_cmnd *cmnd)
1142 struct lpfc_iocbq *iocbq, *iocbqrsp; 1141 struct lpfc_iocbq *iocbq, *iocbqrsp;
1143 struct lpfc_rport_data *rdata = cmnd->device->hostdata; 1142 struct lpfc_rport_data *rdata = cmnd->device->hostdata;
1144 struct lpfc_nodelist *pnode = rdata->pnode; 1143 struct lpfc_nodelist *pnode = rdata->pnode;
1145 uint32_t cmd_result = 0, cmd_status = 0; 1144 unsigned long later;
1146 int ret = FAILED; 1145 int ret = SUCCESS;
1147 int iocb_status = IOCB_SUCCESS; 1146 int status;
1148 int cnt, loopcnt; 1147 int cnt;
1149 1148
1150 lpfc_block_error_handler(cmnd); 1149 lpfc_block_error_handler(cmnd);
1151 loopcnt = 0;
1152 /* 1150 /*
1153 * If target is not in a MAPPED state, delay the reset until 1151 * If target is not in a MAPPED state, delay the reset until
1154 * target is rediscovered or devloss timeout expires. 1152 * target is rediscovered or devloss timeout expires.
1155 */ 1153 */
1156 while (1) { 1154 later = msecs_to_jiffies(2 * vport->cfg_devloss_tmo * 1000) + jiffies;
1155 while (time_after(later, jiffies)) {
1157 if (!pnode || !NLP_CHK_NODE_ACT(pnode)) 1156 if (!pnode || !NLP_CHK_NODE_ACT(pnode))
1158 goto out; 1157 return FAILED;
1159
1160 if (pnode->nlp_state != NLP_STE_MAPPED_NODE) {
1161 schedule_timeout_uninterruptible(msecs_to_jiffies(500));
1162 loopcnt++;
1163 rdata = cmnd->device->hostdata;
1164 if (!rdata ||
1165 (loopcnt > ((vport->cfg_devloss_tmo * 2) + 1))){
1166 lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
1167 "0721 LUN Reset rport "
1168 "failure: cnt x%x rdata x%p\n",
1169 loopcnt, rdata);
1170 goto out;
1171 }
1172 pnode = rdata->pnode;
1173 if (!pnode || !NLP_CHK_NODE_ACT(pnode))
1174 goto out;
1175 }
1176 if (pnode->nlp_state == NLP_STE_MAPPED_NODE) 1158 if (pnode->nlp_state == NLP_STE_MAPPED_NODE)
1177 break; 1159 break;
1160 schedule_timeout_uninterruptible(msecs_to_jiffies(500));
1161 rdata = cmnd->device->hostdata;
1162 if (!rdata)
1163 break;
1164 pnode = rdata->pnode;
1165 }
1166 if (!rdata || pnode->nlp_state != NLP_STE_MAPPED_NODE) {
1167 lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
1168 "0721 LUN Reset rport "
1169 "failure: msec x%x rdata x%p\n",
1170 jiffies_to_msecs(jiffies - later), rdata);
1171 return FAILED;
1178 } 1172 }
1179
1180 lpfc_cmd = lpfc_get_scsi_buf(phba); 1173 lpfc_cmd = lpfc_get_scsi_buf(phba);
1181 if (lpfc_cmd == NULL) 1174 if (lpfc_cmd == NULL)
1182 goto out; 1175 return FAILED;
1183
1184 lpfc_cmd->timeout = 60; 1176 lpfc_cmd->timeout = 60;
1185 lpfc_cmd->rdata = rdata; 1177 lpfc_cmd->rdata = rdata;
1186 1178
1187 ret = lpfc_scsi_prep_task_mgmt_cmd(vport, lpfc_cmd, cmnd->device->lun, 1179 status = lpfc_scsi_prep_task_mgmt_cmd(vport, lpfc_cmd,
1188 FCP_TARGET_RESET); 1180 cmnd->device->lun,
1189 if (!ret) 1181 FCP_TARGET_RESET);
1190 goto out_free_scsi_buf; 1182 if (!status) {
1191 1183 lpfc_release_scsi_buf(phba, lpfc_cmd);
1184 return FAILED;
1185 }
1192 iocbq = &lpfc_cmd->cur_iocbq; 1186 iocbq = &lpfc_cmd->cur_iocbq;
1193 1187
1194 /* get a buffer for this IOCB command response */ 1188 /* get a buffer for this IOCB command response */
1195 iocbqrsp = lpfc_sli_get_iocbq(phba); 1189 iocbqrsp = lpfc_sli_get_iocbq(phba);
1196 if (iocbqrsp == NULL) 1190 if (iocbqrsp == NULL) {
1197 goto out_free_scsi_buf; 1191 lpfc_release_scsi_buf(phba, lpfc_cmd);
1198 1192 return FAILED;
1193 }
1199 lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP, 1194 lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP,
1200 "0703 Issue target reset to TGT %d LUN %d " 1195 "0703 Issue target reset to TGT %d LUN %d "
1201 "rpi x%x nlp_flag x%x\n", cmnd->device->id, 1196 "rpi x%x nlp_flag x%x\n", cmnd->device->id,
1202 cmnd->device->lun, pnode->nlp_rpi, pnode->nlp_flag); 1197 cmnd->device->lun, pnode->nlp_rpi, pnode->nlp_flag);
1203 iocb_status = lpfc_sli_issue_iocb_wait(phba, 1198 status = lpfc_sli_issue_iocb_wait(phba,
1204 &phba->sli.ring[phba->sli.fcp_ring], 1199 &phba->sli.ring[phba->sli.fcp_ring],
1205 iocbq, iocbqrsp, lpfc_cmd->timeout); 1200 iocbq, iocbqrsp, lpfc_cmd->timeout);
1206 1201 if (status == IOCB_TIMEDOUT) {
1207 if (iocb_status == IOCB_TIMEDOUT)
1208 iocbq->iocb_cmpl = lpfc_tskmgmt_def_cmpl; 1202 iocbq->iocb_cmpl = lpfc_tskmgmt_def_cmpl;
1209 1203 ret = TIMEOUT_ERROR;
1210 if (iocb_status == IOCB_SUCCESS) 1204 } else {
1211 ret = SUCCESS; 1205 if (status != IOCB_SUCCESS)
1212 else 1206 ret = FAILED;
1213 ret = iocb_status; 1207 lpfc_release_scsi_buf(phba, lpfc_cmd);
1214 1208 }
1215 cmd_result = iocbqrsp->iocb.un.ulpWord[4]; 1209 lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
1216 cmd_status = iocbqrsp->iocb.ulpStatus; 1210 "0713 SCSI layer issued device reset (%d, %d) "
1217 1211 "return x%x status x%x result x%x\n",
1212 cmnd->device->id, cmnd->device->lun, ret,
1213 iocbqrsp->iocb.ulpStatus,
1214 iocbqrsp->iocb.un.ulpWord[4]);
1218 lpfc_sli_release_iocbq(phba, iocbqrsp); 1215 lpfc_sli_release_iocbq(phba, iocbqrsp);
1219
1220 /*
1221 * All outstanding txcmplq I/Os should have been aborted by the device.
1222 * Unfortunately, some targets do not abide by this forcing the driver
1223 * to double check.
1224 */
1225 cnt = lpfc_sli_sum_iocb(vport, cmnd->device->id, cmnd->device->lun, 1216 cnt = lpfc_sli_sum_iocb(vport, cmnd->device->id, cmnd->device->lun,
1226 LPFC_CTX_LUN); 1217 LPFC_CTX_TGT);
1227 if (cnt) 1218 if (cnt)
1228 lpfc_sli_abort_iocb(vport, &phba->sli.ring[phba->sli.fcp_ring], 1219 lpfc_sli_abort_iocb(vport, &phba->sli.ring[phba->sli.fcp_ring],
1229 cmnd->device->id, cmnd->device->lun, 1220 cmnd->device->id, cmnd->device->lun,
1230 LPFC_CTX_LUN); 1221 LPFC_CTX_TGT);
1231 loopcnt = 0; 1222 later = msecs_to_jiffies(2 * vport->cfg_devloss_tmo * 1000) + jiffies;
1232 while(cnt) { 1223 while (time_after(later, jiffies) && cnt) {
1233 schedule_timeout_uninterruptible(LPFC_RESET_WAIT*HZ); 1224 schedule_timeout_uninterruptible(msecs_to_jiffies(20));
1234
1235 if (++loopcnt
1236 > (2 * vport->cfg_devloss_tmo)/LPFC_RESET_WAIT)
1237 break;
1238
1239 cnt = lpfc_sli_sum_iocb(vport, cmnd->device->id, 1225 cnt = lpfc_sli_sum_iocb(vport, cmnd->device->id,
1240 cmnd->device->lun, LPFC_CTX_LUN); 1226 cmnd->device->lun, LPFC_CTX_TGT);
1241 } 1227 }
1242
1243 if (cnt) { 1228 if (cnt) {
1244 lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, 1229 lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
1245 "0719 device reset I/O flush failure: " 1230 "0719 device reset I/O flush failure: "
1246 "cnt x%x\n", cnt); 1231 "cnt x%x\n", cnt);
1247 ret = FAILED; 1232 ret = FAILED;
1248 } 1233 }
1249
1250out_free_scsi_buf:
1251 if (iocb_status != IOCB_TIMEDOUT) {
1252 lpfc_release_scsi_buf(phba, lpfc_cmd);
1253 }
1254 lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
1255 "0713 SCSI layer issued device reset (%d, %d) "
1256 "return x%x status x%x result x%x\n",
1257 cmnd->device->id, cmnd->device->lun, ret,
1258 cmd_status, cmd_result);
1259out:
1260 return ret; 1234 return ret;
1261} 1235}
1262 1236
@@ -1268,19 +1242,12 @@ lpfc_bus_reset_handler(struct scsi_cmnd *cmnd)
1268 struct lpfc_hba *phba = vport->phba; 1242 struct lpfc_hba *phba = vport->phba;
1269 struct lpfc_nodelist *ndlp = NULL; 1243 struct lpfc_nodelist *ndlp = NULL;
1270 int match; 1244 int match;
1271 int ret = FAILED, i, err_count = 0; 1245 int ret = SUCCESS, status, i;
1272 int cnt, loopcnt; 1246 int cnt;
1273 struct lpfc_scsi_buf * lpfc_cmd; 1247 struct lpfc_scsi_buf * lpfc_cmd;
1248 unsigned long later;
1274 1249
1275 lpfc_block_error_handler(cmnd); 1250 lpfc_block_error_handler(cmnd);
1276
1277 lpfc_cmd = lpfc_get_scsi_buf(phba);
1278 if (lpfc_cmd == NULL)
1279 goto out;
1280
1281 /* The lpfc_cmd storage is reused. Set all loop invariants. */
1282 lpfc_cmd->timeout = 60;
1283
1284 /* 1251 /*
1285 * Since the driver manages a single bus device, reset all 1252 * Since the driver manages a single bus device, reset all
1286 * targets known to the driver. Should any target reset 1253 * targets known to the driver. Should any target reset
@@ -1294,7 +1261,7 @@ lpfc_bus_reset_handler(struct scsi_cmnd *cmnd)
1294 if (!NLP_CHK_NODE_ACT(ndlp)) 1261 if (!NLP_CHK_NODE_ACT(ndlp))
1295 continue; 1262 continue;
1296 if (ndlp->nlp_state == NLP_STE_MAPPED_NODE && 1263 if (ndlp->nlp_state == NLP_STE_MAPPED_NODE &&
1297 i == ndlp->nlp_sid && 1264 ndlp->nlp_sid == i &&
1298 ndlp->rport) { 1265 ndlp->rport) {
1299 match = 1; 1266 match = 1;
1300 break; 1267 break;
@@ -1303,27 +1270,22 @@ lpfc_bus_reset_handler(struct scsi_cmnd *cmnd)
1303 spin_unlock_irq(shost->host_lock); 1270 spin_unlock_irq(shost->host_lock);
1304 if (!match) 1271 if (!match)
1305 continue; 1272 continue;
1306 1273 lpfc_cmd = lpfc_get_scsi_buf(phba);
1307 ret = lpfc_scsi_tgt_reset(lpfc_cmd, vport, i, 1274 if (lpfc_cmd) {
1308 cmnd->device->lun, 1275 lpfc_cmd->timeout = 60;
1309 ndlp->rport->dd_data); 1276 status = lpfc_scsi_tgt_reset(lpfc_cmd, vport, i,
1310 if (ret != SUCCESS) { 1277 cmnd->device->lun,
1278 ndlp->rport->dd_data);
1279 if (status != TIMEOUT_ERROR)
1280 lpfc_release_scsi_buf(phba, lpfc_cmd);
1281 }
1282 if (!lpfc_cmd || status != SUCCESS) {
1311 lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, 1283 lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
1312 "0700 Bus Reset on target %d failed\n", 1284 "0700 Bus Reset on target %d failed\n",
1313 i); 1285 i);
1314 err_count++; 1286 ret = FAILED;
1315 break;
1316 } 1287 }
1317 } 1288 }
1318
1319 if (ret != IOCB_TIMEDOUT)
1320 lpfc_release_scsi_buf(phba, lpfc_cmd);
1321
1322 if (err_count == 0)
1323 ret = SUCCESS;
1324 else
1325 ret = FAILED;
1326
1327 /* 1289 /*
1328 * All outstanding txcmplq I/Os should have been aborted by 1290 * All outstanding txcmplq I/Os should have been aborted by
1329 * the targets. Unfortunately, some targets do not abide by 1291 * the targets. Unfortunately, some targets do not abide by
@@ -1333,27 +1295,19 @@ lpfc_bus_reset_handler(struct scsi_cmnd *cmnd)
1333 if (cnt) 1295 if (cnt)
1334 lpfc_sli_abort_iocb(vport, &phba->sli.ring[phba->sli.fcp_ring], 1296 lpfc_sli_abort_iocb(vport, &phba->sli.ring[phba->sli.fcp_ring],
1335 0, 0, LPFC_CTX_HOST); 1297 0, 0, LPFC_CTX_HOST);
1336 loopcnt = 0; 1298 later = msecs_to_jiffies(2 * vport->cfg_devloss_tmo * 1000) + jiffies;
1337 while(cnt) { 1299 while (time_after(later, jiffies) && cnt) {
1338 schedule_timeout_uninterruptible(LPFC_RESET_WAIT*HZ); 1300 schedule_timeout_uninterruptible(msecs_to_jiffies(20));
1339
1340 if (++loopcnt
1341 > (2 * vport->cfg_devloss_tmo)/LPFC_RESET_WAIT)
1342 break;
1343
1344 cnt = lpfc_sli_sum_iocb(vport, 0, 0, LPFC_CTX_HOST); 1301 cnt = lpfc_sli_sum_iocb(vport, 0, 0, LPFC_CTX_HOST);
1345 } 1302 }
1346
1347 if (cnt) { 1303 if (cnt) {
1348 lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, 1304 lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
1349 "0715 Bus Reset I/O flush failure: " 1305 "0715 Bus Reset I/O flush failure: "
1350 "cnt x%x left x%x\n", cnt, i); 1306 "cnt x%x left x%x\n", cnt, i);
1351 ret = FAILED; 1307 ret = FAILED;
1352 } 1308 }
1353
1354 lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, 1309 lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
1355 "0714 SCSI layer issued Bus Reset Data: x%x\n", ret); 1310 "0714 SCSI layer issued Bus Reset Data: x%x\n", ret);
1356out:
1357 return ret; 1311 return ret;
1358} 1312}
1359 1313
diff --git a/drivers/scsi/lpfc/lpfc_sli.c b/drivers/scsi/lpfc/lpfc_sli.c
index 70a0a9eab211..f40aa7b905f7 100644
--- a/drivers/scsi/lpfc/lpfc_sli.c
+++ b/drivers/scsi/lpfc/lpfc_sli.c
@@ -324,9 +324,7 @@ lpfc_sli_next_iocb_slot (struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
324 phba->work_ha |= HA_ERATT; 324 phba->work_ha |= HA_ERATT;
325 phba->work_hs = HS_FFER3; 325 phba->work_hs = HS_FFER3;
326 326
327 /* hbalock should already be held */ 327 lpfc_worker_wake_up(phba);
328 if (phba->work_wait)
329 lpfc_worker_wake_up(phba);
330 328
331 return NULL; 329 return NULL;
332 } 330 }
@@ -1309,9 +1307,7 @@ lpfc_sli_rsp_pointers_error(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
1309 phba->work_ha |= HA_ERATT; 1307 phba->work_ha |= HA_ERATT;
1310 phba->work_hs = HS_FFER3; 1308 phba->work_hs = HS_FFER3;
1311 1309
1312 /* hbalock should already be held */ 1310 lpfc_worker_wake_up(phba);
1313 if (phba->work_wait)
1314 lpfc_worker_wake_up(phba);
1315 1311
1316 return; 1312 return;
1317} 1313}
@@ -2611,12 +2607,9 @@ lpfc_mbox_timeout(unsigned long ptr)
2611 phba->pport->work_port_events |= WORKER_MBOX_TMO; 2607 phba->pport->work_port_events |= WORKER_MBOX_TMO;
2612 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag); 2608 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag);
2613 2609
2614 if (!tmo_posted) { 2610 if (!tmo_posted)
2615 spin_lock_irqsave(&phba->hbalock, iflag); 2611 lpfc_worker_wake_up(phba);
2616 if (phba->work_wait) 2612 return;
2617 lpfc_worker_wake_up(phba);
2618 spin_unlock_irqrestore(&phba->hbalock, iflag);
2619 }
2620} 2613}
2621 2614
2622void 2615void
@@ -3374,8 +3367,12 @@ lpfc_sli_host_down(struct lpfc_vport *vport)
3374 for (i = 0; i < psli->num_rings; i++) { 3367 for (i = 0; i < psli->num_rings; i++) {
3375 pring = &psli->ring[i]; 3368 pring = &psli->ring[i];
3376 prev_pring_flag = pring->flag; 3369 prev_pring_flag = pring->flag;
3377 if (pring->ringno == LPFC_ELS_RING) /* Only slow rings */ 3370 /* Only slow rings */
3371 if (pring->ringno == LPFC_ELS_RING) {
3378 pring->flag |= LPFC_DEFERRED_RING_EVENT; 3372 pring->flag |= LPFC_DEFERRED_RING_EVENT;
3373 /* Set the lpfc data pending flag */
3374 set_bit(LPFC_DATA_READY, &phba->data_flags);
3375 }
3379 /* 3376 /*
3380 * Error everything on the txq since these iocbs have not been 3377 * Error everything on the txq since these iocbs have not been
3381 * given to the FW yet. 3378 * given to the FW yet.
@@ -3434,8 +3431,12 @@ lpfc_sli_hba_down(struct lpfc_hba *phba)
3434 spin_lock_irqsave(&phba->hbalock, flags); 3431 spin_lock_irqsave(&phba->hbalock, flags);
3435 for (i = 0; i < psli->num_rings; i++) { 3432 for (i = 0; i < psli->num_rings; i++) {
3436 pring = &psli->ring[i]; 3433 pring = &psli->ring[i];
3437 if (pring->ringno == LPFC_ELS_RING) /* Only slow rings */ 3434 /* Only slow rings */
3435 if (pring->ringno == LPFC_ELS_RING) {
3438 pring->flag |= LPFC_DEFERRED_RING_EVENT; 3436 pring->flag |= LPFC_DEFERRED_RING_EVENT;
3437 /* Set the lpfc data pending flag */
3438 set_bit(LPFC_DATA_READY, &phba->data_flags);
3439 }
3439 3440
3440 /* 3441 /*
3441 * Error everything on the txq since these iocbs have not been 3442 * Error everything on the txq since these iocbs have not been
@@ -3762,7 +3763,6 @@ lpfc_sli_validate_fcp_iocb(struct lpfc_iocbq *iocbq, struct lpfc_vport *vport,
3762 lpfc_ctx_cmd ctx_cmd) 3763 lpfc_ctx_cmd ctx_cmd)
3763{ 3764{
3764 struct lpfc_scsi_buf *lpfc_cmd; 3765 struct lpfc_scsi_buf *lpfc_cmd;
3765 struct scsi_cmnd *cmnd;
3766 int rc = 1; 3766 int rc = 1;
3767 3767
3768 if (!(iocbq->iocb_flag & LPFC_IO_FCP)) 3768 if (!(iocbq->iocb_flag & LPFC_IO_FCP))
@@ -3772,19 +3772,20 @@ lpfc_sli_validate_fcp_iocb(struct lpfc_iocbq *iocbq, struct lpfc_vport *vport,
3772 return rc; 3772 return rc;
3773 3773
3774 lpfc_cmd = container_of(iocbq, struct lpfc_scsi_buf, cur_iocbq); 3774 lpfc_cmd = container_of(iocbq, struct lpfc_scsi_buf, cur_iocbq);
3775 cmnd = lpfc_cmd->pCmd;
3776 3775
3777 if (cmnd == NULL) 3776 if (lpfc_cmd->pCmd == NULL)
3778 return rc; 3777 return rc;
3779 3778
3780 switch (ctx_cmd) { 3779 switch (ctx_cmd) {
3781 case LPFC_CTX_LUN: 3780 case LPFC_CTX_LUN:
3782 if ((cmnd->device->id == tgt_id) && 3781 if ((lpfc_cmd->rdata->pnode) &&
3783 (cmnd->device->lun == lun_id)) 3782 (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id) &&
3783 (scsilun_to_int(&lpfc_cmd->fcp_cmnd->fcp_lun) == lun_id))
3784 rc = 0; 3784 rc = 0;
3785 break; 3785 break;
3786 case LPFC_CTX_TGT: 3786 case LPFC_CTX_TGT:
3787 if (cmnd->device->id == tgt_id) 3787 if ((lpfc_cmd->rdata->pnode) &&
3788 (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id))
3788 rc = 0; 3789 rc = 0;
3789 break; 3790 break;
3790 case LPFC_CTX_HOST: 3791 case LPFC_CTX_HOST:
@@ -3994,6 +3995,7 @@ lpfc_sli_issue_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq,
3994 if (pmboxq->context1) 3995 if (pmboxq->context1)
3995 return MBX_NOT_FINISHED; 3996 return MBX_NOT_FINISHED;
3996 3997
3998 pmboxq->mbox_flag &= ~LPFC_MBX_WAKE;
3997 /* setup wake call as IOCB callback */ 3999 /* setup wake call as IOCB callback */
3998 pmboxq->mbox_cmpl = lpfc_sli_wake_mbox_wait; 4000 pmboxq->mbox_cmpl = lpfc_sli_wake_mbox_wait;
3999 /* setup context field to pass wait_queue pointer to wake function */ 4001 /* setup context field to pass wait_queue pointer to wake function */
@@ -4159,7 +4161,7 @@ lpfc_intr_handler(int irq, void *dev_id)
4159 "pwork:x%x hawork:x%x wait:x%x", 4161 "pwork:x%x hawork:x%x wait:x%x",
4160 phba->work_ha, work_ha_copy, 4162 phba->work_ha, work_ha_copy,
4161 (uint32_t)((unsigned long) 4163 (uint32_t)((unsigned long)
4162 phba->work_wait)); 4164 &phba->work_waitq));
4163 4165
4164 control &= 4166 control &=
4165 ~(HC_R0INT_ENA << LPFC_ELS_RING); 4167 ~(HC_R0INT_ENA << LPFC_ELS_RING);
@@ -4172,7 +4174,7 @@ lpfc_intr_handler(int irq, void *dev_id)
4172 "x%x hawork:x%x wait:x%x", 4174 "x%x hawork:x%x wait:x%x",
4173 phba->work_ha, work_ha_copy, 4175 phba->work_ha, work_ha_copy,
4174 (uint32_t)((unsigned long) 4176 (uint32_t)((unsigned long)
4175 phba->work_wait)); 4177 &phba->work_waitq));
4176 } 4178 }
4177 spin_unlock(&phba->hbalock); 4179 spin_unlock(&phba->hbalock);
4178 } 4180 }
@@ -4297,9 +4299,8 @@ send_current_mbox:
4297 4299
4298 spin_lock(&phba->hbalock); 4300 spin_lock(&phba->hbalock);
4299 phba->work_ha |= work_ha_copy; 4301 phba->work_ha |= work_ha_copy;
4300 if (phba->work_wait)
4301 lpfc_worker_wake_up(phba);
4302 spin_unlock(&phba->hbalock); 4302 spin_unlock(&phba->hbalock);
4303 lpfc_worker_wake_up(phba);
4303 } 4304 }
4304 4305
4305 ha_copy &= ~(phba->work_ha_mask); 4306 ha_copy &= ~(phba->work_ha_mask);
diff --git a/drivers/scsi/lpfc/lpfc_version.h b/drivers/scsi/lpfc/lpfc_version.h
index b22b893019f4..ad24cacfbe10 100644
--- a/drivers/scsi/lpfc/lpfc_version.h
+++ b/drivers/scsi/lpfc/lpfc_version.h
@@ -18,7 +18,7 @@
18 * included with this package. * 18 * included with this package. *
19 *******************************************************************/ 19 *******************************************************************/
20 20
21#define LPFC_DRIVER_VERSION "8.2.6" 21#define LPFC_DRIVER_VERSION "8.2.7"
22 22
23#define LPFC_DRIVER_NAME "lpfc" 23#define LPFC_DRIVER_NAME "lpfc"
24 24
diff --git a/drivers/scsi/lpfc/lpfc_vport.c b/drivers/scsi/lpfc/lpfc_vport.c
index 6feaf59b0b1b..109f89d98830 100644
--- a/drivers/scsi/lpfc/lpfc_vport.c
+++ b/drivers/scsi/lpfc/lpfc_vport.c
@@ -216,6 +216,7 @@ lpfc_vport_create(struct fc_vport *fc_vport, bool disable)
216 int vpi; 216 int vpi;
217 int rc = VPORT_ERROR; 217 int rc = VPORT_ERROR;
218 int status; 218 int status;
219 int size;
219 220
220 if ((phba->sli_rev < 3) || 221 if ((phba->sli_rev < 3) ||
221 !(phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)) { 222 !(phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)) {
@@ -278,7 +279,20 @@ lpfc_vport_create(struct fc_vport *fc_vport, bool disable)
278 279
279 memcpy(vport->fc_portname.u.wwn, vport->fc_sparam.portName.u.wwn, 8); 280 memcpy(vport->fc_portname.u.wwn, vport->fc_sparam.portName.u.wwn, 8);
280 memcpy(vport->fc_nodename.u.wwn, vport->fc_sparam.nodeName.u.wwn, 8); 281 memcpy(vport->fc_nodename.u.wwn, vport->fc_sparam.nodeName.u.wwn, 8);
281 282 size = strnlen(fc_vport->symbolic_name, LPFC_VNAME_LEN);
283 if (size) {
284 vport->vname = kzalloc(size+1, GFP_KERNEL);
285 if (!vport->vname) {
286 lpfc_printf_vlog(vport, KERN_ERR, LOG_VPORT,
287 "1814 Create VPORT failed. "
288 "vname allocation failed.\n");
289 rc = VPORT_ERROR;
290 lpfc_free_vpi(phba, vpi);
291 destroy_port(vport);
292 goto error_out;
293 }
294 memcpy(vport->vname, fc_vport->symbolic_name, size+1);
295 }
282 if (fc_vport->node_name != 0) 296 if (fc_vport->node_name != 0)
283 u64_to_wwn(fc_vport->node_name, vport->fc_nodename.u.wwn); 297 u64_to_wwn(fc_vport->node_name, vport->fc_nodename.u.wwn);
284 if (fc_vport->port_name != 0) 298 if (fc_vport->port_name != 0)