aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/scsi/lpfc/lpfc_bsg.c
diff options
context:
space:
mode:
authorJames Smart <james.smart@emulex.com>2010-09-29 11:18:45 -0400
committerJames Bottomley <James.Bottomley@suse.de>2010-10-07 18:26:19 -0400
commitd439d286f573afab8c164dbc953ce1d214585a40 (patch)
treeeec9c3089e49ae0938b4fff282afd2472d9b7fdc /drivers/scsi/lpfc/lpfc_bsg.c
parentbf5eefb007e7c5498a41af2dd65d957ae9793a63 (diff)
[SCSI] lpfc 8.3.17: Code Cleanup and Locking fixes
- Move Unload flag earlier in vport deletei to stop ELS traffic - Replaced some unnecessary spin_lock_irqsave with spin_lock_irq - Fixed circular spinlock dependency between low-level driver and SCSI midlayer - Remove duplicate code from lpfc_els_retry routine - Make all error values negative Signed-off-by: Alex Iannicelli <alex.iannicelli@emulex.com> Signed-off-by: James Smart <james.smart@emulex.com> Signed-off-by: James Bottomley <James.Bottomley@suse.de>
Diffstat (limited to 'drivers/scsi/lpfc/lpfc_bsg.c')
-rw-r--r--drivers/scsi/lpfc/lpfc_bsg.c81
1 files changed, 42 insertions, 39 deletions
diff --git a/drivers/scsi/lpfc/lpfc_bsg.c b/drivers/scsi/lpfc/lpfc_bsg.c
index 49d0cf99c24c..10cfc64782ad 100644
--- a/drivers/scsi/lpfc/lpfc_bsg.c
+++ b/drivers/scsi/lpfc/lpfc_bsg.c
@@ -259,6 +259,7 @@ lpfc_bsg_send_mgmt_cmd(struct fc_bsg_job *job)
259 struct bsg_job_data *dd_data; 259 struct bsg_job_data *dd_data;
260 uint32_t creg_val; 260 uint32_t creg_val;
261 int rc = 0; 261 int rc = 0;
262 int iocb_stat;
262 263
263 /* in case no data is transferred */ 264 /* in case no data is transferred */
264 job->reply->reply_payload_rcv_len = 0; 265 job->reply->reply_payload_rcv_len = 0;
@@ -373,14 +374,13 @@ lpfc_bsg_send_mgmt_cmd(struct fc_bsg_job *job)
373 readl(phba->HCregaddr); /* flush */ 374 readl(phba->HCregaddr); /* flush */
374 } 375 }
375 376
376 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, cmdiocbq, 0); 377 iocb_stat = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, cmdiocbq, 0);
377 378 if (iocb_stat == IOCB_SUCCESS)
378 if (rc == IOCB_SUCCESS)
379 return 0; /* done for now */ 379 return 0; /* done for now */
380 else if (rc == IOCB_BUSY) 380 else if (iocb_stat == IOCB_BUSY)
381 rc = EAGAIN; 381 rc = -EAGAIN;
382 else 382 else
383 rc = EIO; 383 rc = -EIO;
384 384
385 385
386 /* iocb failed so cleanup */ 386 /* iocb failed so cleanup */
@@ -631,9 +631,9 @@ lpfc_bsg_rport_els(struct fc_bsg_job *job)
631 if (rc == IOCB_SUCCESS) 631 if (rc == IOCB_SUCCESS)
632 return 0; /* done for now */ 632 return 0; /* done for now */
633 else if (rc == IOCB_BUSY) 633 else if (rc == IOCB_BUSY)
634 rc = EAGAIN; 634 rc = -EAGAIN;
635 else 635 else
636 rc = EIO; 636 rc = -EIO;
637 637
638 pci_unmap_sg(phba->pcidev, job->request_payload.sg_list, 638 pci_unmap_sg(phba->pcidev, job->request_payload.sg_list,
639 job->request_payload.sg_cnt, DMA_TO_DEVICE); 639 job->request_payload.sg_cnt, DMA_TO_DEVICE);
@@ -1299,7 +1299,7 @@ lpfc_issue_ct_rsp(struct lpfc_hba *phba, struct fc_bsg_job *job, uint32_t tag,
1299 /* Allocate buffer for command iocb */ 1299 /* Allocate buffer for command iocb */
1300 ctiocb = lpfc_sli_get_iocbq(phba); 1300 ctiocb = lpfc_sli_get_iocbq(phba);
1301 if (!ctiocb) { 1301 if (!ctiocb) {
1302 rc = ENOMEM; 1302 rc = -ENOMEM;
1303 goto no_ctiocb; 1303 goto no_ctiocb;
1304 } 1304 }
1305 1305
@@ -1649,17 +1649,18 @@ static int lpfcdiag_loop_self_reg(struct lpfc_hba *phba, uint16_t * rpi)
1649 1649
1650 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); 1650 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1651 if (!mbox) 1651 if (!mbox)
1652 return ENOMEM; 1652 return -ENOMEM;
1653 1653
1654 status = lpfc_reg_rpi(phba, 0, phba->pport->fc_myDID, 1654 status = lpfc_reg_rpi(phba, 0, phba->pport->fc_myDID,
1655 (uint8_t *)&phba->pport->fc_sparam, mbox, 0); 1655 (uint8_t *)&phba->pport->fc_sparam, mbox, 0);
1656 if (status) { 1656 if (status) {
1657 mempool_free(mbox, phba->mbox_mem_pool); 1657 mempool_free(mbox, phba->mbox_mem_pool);
1658 return ENOMEM; 1658 return -ENOMEM;
1659 } 1659 }
1660 1660
1661 dmabuff = (struct lpfc_dmabuf *) mbox->context1; 1661 dmabuff = (struct lpfc_dmabuf *) mbox->context1;
1662 mbox->context1 = NULL; 1662 mbox->context1 = NULL;
1663 mbox->context2 = NULL;
1663 status = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO); 1664 status = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO);
1664 1665
1665 if ((status != MBX_SUCCESS) || (mbox->u.mb.mbxStatus)) { 1666 if ((status != MBX_SUCCESS) || (mbox->u.mb.mbxStatus)) {
@@ -1667,7 +1668,7 @@ static int lpfcdiag_loop_self_reg(struct lpfc_hba *phba, uint16_t * rpi)
1667 kfree(dmabuff); 1668 kfree(dmabuff);
1668 if (status != MBX_TIMEOUT) 1669 if (status != MBX_TIMEOUT)
1669 mempool_free(mbox, phba->mbox_mem_pool); 1670 mempool_free(mbox, phba->mbox_mem_pool);
1670 return ENODEV; 1671 return -ENODEV;
1671 } 1672 }
1672 1673
1673 *rpi = mbox->u.mb.un.varWords[0]; 1674 *rpi = mbox->u.mb.un.varWords[0];
@@ -1693,7 +1694,7 @@ static int lpfcdiag_loop_self_unreg(struct lpfc_hba *phba, uint16_t rpi)
1693 /* Allocate mboxq structure */ 1694 /* Allocate mboxq structure */
1694 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); 1695 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1695 if (mbox == NULL) 1696 if (mbox == NULL)
1696 return ENOMEM; 1697 return -ENOMEM;
1697 1698
1698 lpfc_unreg_login(phba, 0, rpi, mbox); 1699 lpfc_unreg_login(phba, 0, rpi, mbox);
1699 status = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO); 1700 status = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO);
@@ -1701,7 +1702,7 @@ static int lpfcdiag_loop_self_unreg(struct lpfc_hba *phba, uint16_t rpi)
1701 if ((status != MBX_SUCCESS) || (mbox->u.mb.mbxStatus)) { 1702 if ((status != MBX_SUCCESS) || (mbox->u.mb.mbxStatus)) {
1702 if (status != MBX_TIMEOUT) 1703 if (status != MBX_TIMEOUT)
1703 mempool_free(mbox, phba->mbox_mem_pool); 1704 mempool_free(mbox, phba->mbox_mem_pool);
1704 return EIO; 1705 return -EIO;
1705 } 1706 }
1706 1707
1707 mempool_free(mbox, phba->mbox_mem_pool); 1708 mempool_free(mbox, phba->mbox_mem_pool);
@@ -1730,6 +1731,8 @@ static int lpfcdiag_loop_get_xri(struct lpfc_hba *phba, uint16_t rpi,
1730 struct ulp_bde64 *bpl = NULL; 1731 struct ulp_bde64 *bpl = NULL;
1731 struct lpfc_sli_ct_request *ctreq = NULL; 1732 struct lpfc_sli_ct_request *ctreq = NULL;
1732 int ret_val = 0; 1733 int ret_val = 0;
1734 int time_left;
1735 int iocb_stat;
1733 unsigned long flags; 1736 unsigned long flags;
1734 1737
1735 *txxri = 0; 1738 *txxri = 0;
@@ -1737,7 +1740,7 @@ static int lpfcdiag_loop_get_xri(struct lpfc_hba *phba, uint16_t rpi,
1737 evt = lpfc_bsg_event_new(FC_REG_CT_EVENT, current->pid, 1740 evt = lpfc_bsg_event_new(FC_REG_CT_EVENT, current->pid,
1738 SLI_CT_ELX_LOOPBACK); 1741 SLI_CT_ELX_LOOPBACK);
1739 if (!evt) 1742 if (!evt)
1740 return ENOMEM; 1743 return -ENOMEM;
1741 1744
1742 spin_lock_irqsave(&phba->ct_ev_lock, flags); 1745 spin_lock_irqsave(&phba->ct_ev_lock, flags);
1743 list_add(&evt->node, &phba->ct_ev_waiters); 1746 list_add(&evt->node, &phba->ct_ev_waiters);
@@ -1770,7 +1773,7 @@ static int lpfcdiag_loop_get_xri(struct lpfc_hba *phba, uint16_t rpi,
1770 if (cmdiocbq == NULL || rspiocbq == NULL || 1773 if (cmdiocbq == NULL || rspiocbq == NULL ||
1771 dmabuf == NULL || bpl == NULL || ctreq == NULL || 1774 dmabuf == NULL || bpl == NULL || ctreq == NULL ||
1772 dmabuf->virt == NULL) { 1775 dmabuf->virt == NULL) {
1773 ret_val = ENOMEM; 1776 ret_val = -ENOMEM;
1774 goto err_get_xri_exit; 1777 goto err_get_xri_exit;
1775 } 1778 }
1776 1779
@@ -1806,24 +1809,24 @@ static int lpfcdiag_loop_get_xri(struct lpfc_hba *phba, uint16_t rpi,
1806 cmdiocbq->iocb_flag |= LPFC_IO_LIBDFC; 1809 cmdiocbq->iocb_flag |= LPFC_IO_LIBDFC;
1807 cmdiocbq->vport = phba->pport; 1810 cmdiocbq->vport = phba->pport;
1808 1811
1809 ret_val = lpfc_sli_issue_iocb_wait(phba, LPFC_ELS_RING, cmdiocbq, 1812 iocb_stat = lpfc_sli_issue_iocb_wait(phba, LPFC_ELS_RING, cmdiocbq,
1810 rspiocbq, 1813 rspiocbq,
1811 (phba->fc_ratov * 2) 1814 (phba->fc_ratov * 2)
1812 + LPFC_DRVR_TIMEOUT); 1815 + LPFC_DRVR_TIMEOUT);
1813 if (ret_val) 1816 if (iocb_stat) {
1817 ret_val = -EIO;
1814 goto err_get_xri_exit; 1818 goto err_get_xri_exit;
1815 1819 }
1816 *txxri = rsp->ulpContext; 1820 *txxri = rsp->ulpContext;
1817 1821
1818 evt->waiting = 1; 1822 evt->waiting = 1;
1819 evt->wait_time_stamp = jiffies; 1823 evt->wait_time_stamp = jiffies;
1820 ret_val = wait_event_interruptible_timeout( 1824 time_left = wait_event_interruptible_timeout(
1821 evt->wq, !list_empty(&evt->events_to_see), 1825 evt->wq, !list_empty(&evt->events_to_see),
1822 ((phba->fc_ratov * 2) + LPFC_DRVR_TIMEOUT) * HZ); 1826 ((phba->fc_ratov * 2) + LPFC_DRVR_TIMEOUT) * HZ);
1823 if (list_empty(&evt->events_to_see)) 1827 if (list_empty(&evt->events_to_see))
1824 ret_val = (ret_val) ? EINTR : ETIMEDOUT; 1828 ret_val = (time_left) ? -EINTR : -ETIMEDOUT;
1825 else { 1829 else {
1826 ret_val = IOCB_SUCCESS;
1827 spin_lock_irqsave(&phba->ct_ev_lock, flags); 1830 spin_lock_irqsave(&phba->ct_ev_lock, flags);
1828 list_move(evt->events_to_see.prev, &evt->events_to_get); 1831 list_move(evt->events_to_see.prev, &evt->events_to_get);
1829 spin_unlock_irqrestore(&phba->ct_ev_lock, flags); 1832 spin_unlock_irqrestore(&phba->ct_ev_lock, flags);
@@ -1845,7 +1848,7 @@ err_get_xri_exit:
1845 kfree(dmabuf); 1848 kfree(dmabuf);
1846 } 1849 }
1847 1850
1848 if (cmdiocbq && (ret_val != IOCB_TIMEDOUT)) 1851 if (cmdiocbq && (iocb_stat != IOCB_TIMEDOUT))
1849 lpfc_sli_release_iocbq(phba, cmdiocbq); 1852 lpfc_sli_release_iocbq(phba, cmdiocbq);
1850 if (rspiocbq) 1853 if (rspiocbq)
1851 lpfc_sli_release_iocbq(phba, rspiocbq); 1854 lpfc_sli_release_iocbq(phba, rspiocbq);
@@ -1959,6 +1962,7 @@ static int lpfcdiag_loop_post_rxbufs(struct lpfc_hba *phba, uint16_t rxxri,
1959 uint32_t num_bde; 1962 uint32_t num_bde;
1960 struct lpfc_dmabufext *rxbuffer = NULL; 1963 struct lpfc_dmabufext *rxbuffer = NULL;
1961 int ret_val = 0; 1964 int ret_val = 0;
1965 int iocb_stat;
1962 int i = 0; 1966 int i = 0;
1963 1967
1964 cmdiocbq = lpfc_sli_get_iocbq(phba); 1968 cmdiocbq = lpfc_sli_get_iocbq(phba);
@@ -1973,7 +1977,7 @@ static int lpfcdiag_loop_post_rxbufs(struct lpfc_hba *phba, uint16_t rxxri,
1973 } 1977 }
1974 1978
1975 if (!cmdiocbq || !rxbmp || !rxbpl || !rxbuffer) { 1979 if (!cmdiocbq || !rxbmp || !rxbpl || !rxbuffer) {
1976 ret_val = ENOMEM; 1980 ret_val = -ENOMEM;
1977 goto err_post_rxbufs_exit; 1981 goto err_post_rxbufs_exit;
1978 } 1982 }
1979 1983
@@ -2022,16 +2026,16 @@ static int lpfcdiag_loop_post_rxbufs(struct lpfc_hba *phba, uint16_t rxxri,
2022 cmd->ulpClass = CLASS3; 2026 cmd->ulpClass = CLASS3;
2023 cmd->ulpContext = rxxri; 2027 cmd->ulpContext = rxxri;
2024 2028
2025 ret_val = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, cmdiocbq, 0); 2029 iocb_stat = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, cmdiocbq,
2026 2030 0);
2027 if (ret_val == IOCB_ERROR) { 2031 if (iocb_stat == IOCB_ERROR) {
2028 diag_cmd_data_free(phba, 2032 diag_cmd_data_free(phba,
2029 (struct lpfc_dmabufext *)mp[0]); 2033 (struct lpfc_dmabufext *)mp[0]);
2030 if (mp[1]) 2034 if (mp[1])
2031 diag_cmd_data_free(phba, 2035 diag_cmd_data_free(phba,
2032 (struct lpfc_dmabufext *)mp[1]); 2036 (struct lpfc_dmabufext *)mp[1]);
2033 dmp = list_entry(next, struct lpfc_dmabuf, list); 2037 dmp = list_entry(next, struct lpfc_dmabuf, list);
2034 ret_val = EIO; 2038 ret_val = -EIO;
2035 goto err_post_rxbufs_exit; 2039 goto err_post_rxbufs_exit;
2036 } 2040 }
2037 2041
@@ -2045,7 +2049,7 @@ static int lpfcdiag_loop_post_rxbufs(struct lpfc_hba *phba, uint16_t rxxri,
2045 cmdiocbq = lpfc_sli_get_iocbq(phba); 2049 cmdiocbq = lpfc_sli_get_iocbq(phba);
2046 if (!cmdiocbq) { 2050 if (!cmdiocbq) {
2047 dmp = list_entry(next, struct lpfc_dmabuf, list); 2051 dmp = list_entry(next, struct lpfc_dmabuf, list);
2048 ret_val = EIO; 2052 ret_val = -EIO;
2049 goto err_post_rxbufs_exit; 2053 goto err_post_rxbufs_exit;
2050 } 2054 }
2051 2055
@@ -2111,6 +2115,8 @@ lpfc_bsg_diag_test(struct fc_bsg_job *job)
2111 uint32_t num_bde; 2115 uint32_t num_bde;
2112 uint8_t *ptr = NULL, *rx_databuf = NULL; 2116 uint8_t *ptr = NULL, *rx_databuf = NULL;
2113 int rc = 0; 2117 int rc = 0;
2118 int time_left;
2119 int iocb_stat;
2114 unsigned long flags; 2120 unsigned long flags;
2115 void *dataout = NULL; 2121 void *dataout = NULL;
2116 uint32_t total_mem; 2122 uint32_t total_mem;
@@ -2185,22 +2191,18 @@ lpfc_bsg_diag_test(struct fc_bsg_job *job)
2185 ptr, size); 2191 ptr, size);
2186 2192
2187 rc = lpfcdiag_loop_self_reg(phba, &rpi); 2193 rc = lpfcdiag_loop_self_reg(phba, &rpi);
2188 if (rc) { 2194 if (rc)
2189 rc = -ENOMEM;
2190 goto loopback_test_exit; 2195 goto loopback_test_exit;
2191 }
2192 2196
2193 rc = lpfcdiag_loop_get_xri(phba, rpi, &txxri, &rxxri); 2197 rc = lpfcdiag_loop_get_xri(phba, rpi, &txxri, &rxxri);
2194 if (rc) { 2198 if (rc) {
2195 lpfcdiag_loop_self_unreg(phba, rpi); 2199 lpfcdiag_loop_self_unreg(phba, rpi);
2196 rc = -ENOMEM;
2197 goto loopback_test_exit; 2200 goto loopback_test_exit;
2198 } 2201 }
2199 2202
2200 rc = lpfcdiag_loop_post_rxbufs(phba, rxxri, full_size); 2203 rc = lpfcdiag_loop_post_rxbufs(phba, rxxri, full_size);
2201 if (rc) { 2204 if (rc) {
2202 lpfcdiag_loop_self_unreg(phba, rpi); 2205 lpfcdiag_loop_self_unreg(phba, rpi);
2203 rc = -ENOMEM;
2204 goto loopback_test_exit; 2206 goto loopback_test_exit;
2205 } 2207 }
2206 2208
@@ -2290,21 +2292,22 @@ lpfc_bsg_diag_test(struct fc_bsg_job *job)
2290 cmdiocbq->iocb_flag |= LPFC_IO_LIBDFC; 2292 cmdiocbq->iocb_flag |= LPFC_IO_LIBDFC;
2291 cmdiocbq->vport = phba->pport; 2293 cmdiocbq->vport = phba->pport;
2292 2294
2293 rc = lpfc_sli_issue_iocb_wait(phba, LPFC_ELS_RING, cmdiocbq, rspiocbq, 2295 iocb_stat = lpfc_sli_issue_iocb_wait(phba, LPFC_ELS_RING, cmdiocbq,
2294 (phba->fc_ratov * 2) + LPFC_DRVR_TIMEOUT); 2296 rspiocbq, (phba->fc_ratov * 2) +
2297 LPFC_DRVR_TIMEOUT);
2295 2298
2296 if ((rc != IOCB_SUCCESS) || (rsp->ulpStatus != IOCB_SUCCESS)) { 2299 if ((iocb_stat != IOCB_SUCCESS) || (rsp->ulpStatus != IOCB_SUCCESS)) {
2297 rc = -EIO; 2300 rc = -EIO;
2298 goto err_loopback_test_exit; 2301 goto err_loopback_test_exit;
2299 } 2302 }
2300 2303
2301 evt->waiting = 1; 2304 evt->waiting = 1;
2302 rc = wait_event_interruptible_timeout( 2305 time_left = wait_event_interruptible_timeout(
2303 evt->wq, !list_empty(&evt->events_to_see), 2306 evt->wq, !list_empty(&evt->events_to_see),
2304 ((phba->fc_ratov * 2) + LPFC_DRVR_TIMEOUT) * HZ); 2307 ((phba->fc_ratov * 2) + LPFC_DRVR_TIMEOUT) * HZ);
2305 evt->waiting = 0; 2308 evt->waiting = 0;
2306 if (list_empty(&evt->events_to_see)) 2309 if (list_empty(&evt->events_to_see))
2307 rc = (rc) ? -EINTR : -ETIMEDOUT; 2310 rc = (time_left) ? -EINTR : -ETIMEDOUT;
2308 else { 2311 else {
2309 spin_lock_irqsave(&phba->ct_ev_lock, flags); 2312 spin_lock_irqsave(&phba->ct_ev_lock, flags);
2310 list_move(evt->events_to_see.prev, &evt->events_to_get); 2313 list_move(evt->events_to_see.prev, &evt->events_to_get);