aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/scsi/ufs/ufshcd.c
diff options
context:
space:
mode:
authorSeungwon Jeon <tgih.jun@samsung.com>2013-06-27 00:31:54 -0400
committerJames Bottomley <JBottomley@Parallels.com>2013-06-28 16:11:28 -0400
commit2953f850c3b80bdca004967c83733365d8aa0aa2 (patch)
treede80e56c2a9f42ab51bb50d05c40c31ed643a454 /drivers/scsi/ufs/ufshcd.c
parent3ca316c582ddf11944806a27e460e7bd8f61a968 (diff)
[SCSI] ufs: use devres functions for ufshcd
This patch replaces normal calls for resource allocation with devm_*() derivative functions. It makes resource freeing simpler. Signed-off-by: Seungwon Jeon <tgih.jun@samsung.com> Signed-off-by: Santosh Y <santoshsy@gmail.com> Signed-off-by: James Bottomley <JBottomley@Parallels.com>
Diffstat (limited to 'drivers/scsi/ufs/ufshcd.c')
-rw-r--r--drivers/scsi/ufs/ufshcd.c86
1 files changed, 19 insertions, 67 deletions
diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c
index 2230f1412d88..aba461f0f11c 100644
--- a/drivers/scsi/ufs/ufshcd.c
+++ b/drivers/scsi/ufs/ufshcd.c
@@ -191,38 +191,6 @@ static inline int ufshcd_get_uic_cmd_result(struct ufs_hba *hba)
191} 191}
192 192
193/** 193/**
194 * ufshcd_free_hba_memory - Free allocated memory for LRB, request
195 * and task lists
196 * @hba: Pointer to adapter instance
197 */
198static inline void ufshcd_free_hba_memory(struct ufs_hba *hba)
199{
200 size_t utmrdl_size, utrdl_size, ucdl_size;
201
202 kfree(hba->lrb);
203
204 if (hba->utmrdl_base_addr) {
205 utmrdl_size = sizeof(struct utp_task_req_desc) * hba->nutmrs;
206 dma_free_coherent(hba->dev, utmrdl_size,
207 hba->utmrdl_base_addr, hba->utmrdl_dma_addr);
208 }
209
210 if (hba->utrdl_base_addr) {
211 utrdl_size =
212 (sizeof(struct utp_transfer_req_desc) * hba->nutrs);
213 dma_free_coherent(hba->dev, utrdl_size,
214 hba->utrdl_base_addr, hba->utrdl_dma_addr);
215 }
216
217 if (hba->ucdl_base_addr) {
218 ucdl_size =
219 (sizeof(struct utp_transfer_cmd_desc) * hba->nutrs);
220 dma_free_coherent(hba->dev, ucdl_size,
221 hba->ucdl_base_addr, hba->ucdl_dma_addr);
222 }
223}
224
225/**
226 * ufshcd_is_valid_req_rsp - checks if controller TR response is valid 194 * ufshcd_is_valid_req_rsp - checks if controller TR response is valid
227 * @ucd_rsp_ptr: pointer to response UPIU 195 * @ucd_rsp_ptr: pointer to response UPIU
228 * 196 *
@@ -690,10 +658,10 @@ static int ufshcd_memory_alloc(struct ufs_hba *hba)
690 658
691 /* Allocate memory for UTP command descriptors */ 659 /* Allocate memory for UTP command descriptors */
692 ucdl_size = (sizeof(struct utp_transfer_cmd_desc) * hba->nutrs); 660 ucdl_size = (sizeof(struct utp_transfer_cmd_desc) * hba->nutrs);
693 hba->ucdl_base_addr = dma_alloc_coherent(hba->dev, 661 hba->ucdl_base_addr = dmam_alloc_coherent(hba->dev,
694 ucdl_size, 662 ucdl_size,
695 &hba->ucdl_dma_addr, 663 &hba->ucdl_dma_addr,
696 GFP_KERNEL); 664 GFP_KERNEL);
697 665
698 /* 666 /*
699 * UFSHCI requires UTP command descriptor to be 128 byte aligned. 667 * UFSHCI requires UTP command descriptor to be 128 byte aligned.
@@ -713,10 +681,10 @@ static int ufshcd_memory_alloc(struct ufs_hba *hba)
713 * UFSHCI requires 1024 byte alignment of UTRD 681 * UFSHCI requires 1024 byte alignment of UTRD
714 */ 682 */
715 utrdl_size = (sizeof(struct utp_transfer_req_desc) * hba->nutrs); 683 utrdl_size = (sizeof(struct utp_transfer_req_desc) * hba->nutrs);
716 hba->utrdl_base_addr = dma_alloc_coherent(hba->dev, 684 hba->utrdl_base_addr = dmam_alloc_coherent(hba->dev,
717 utrdl_size, 685 utrdl_size,
718 &hba->utrdl_dma_addr, 686 &hba->utrdl_dma_addr,
719 GFP_KERNEL); 687 GFP_KERNEL);
720 if (!hba->utrdl_base_addr || 688 if (!hba->utrdl_base_addr ||
721 WARN_ON(hba->utrdl_dma_addr & (PAGE_SIZE - 1))) { 689 WARN_ON(hba->utrdl_dma_addr & (PAGE_SIZE - 1))) {
722 dev_err(hba->dev, 690 dev_err(hba->dev,
@@ -729,10 +697,10 @@ static int ufshcd_memory_alloc(struct ufs_hba *hba)
729 * UFSHCI requires 1024 byte alignment of UTMRD 697 * UFSHCI requires 1024 byte alignment of UTMRD
730 */ 698 */
731 utmrdl_size = sizeof(struct utp_task_req_desc) * hba->nutmrs; 699 utmrdl_size = sizeof(struct utp_task_req_desc) * hba->nutmrs;
732 hba->utmrdl_base_addr = dma_alloc_coherent(hba->dev, 700 hba->utmrdl_base_addr = dmam_alloc_coherent(hba->dev,
733 utmrdl_size, 701 utmrdl_size,
734 &hba->utmrdl_dma_addr, 702 &hba->utmrdl_dma_addr,
735 GFP_KERNEL); 703 GFP_KERNEL);
736 if (!hba->utmrdl_base_addr || 704 if (!hba->utmrdl_base_addr ||
737 WARN_ON(hba->utmrdl_dma_addr & (PAGE_SIZE - 1))) { 705 WARN_ON(hba->utmrdl_dma_addr & (PAGE_SIZE - 1))) {
738 dev_err(hba->dev, 706 dev_err(hba->dev,
@@ -741,14 +709,15 @@ static int ufshcd_memory_alloc(struct ufs_hba *hba)
741 } 709 }
742 710
743 /* Allocate memory for local reference block */ 711 /* Allocate memory for local reference block */
744 hba->lrb = kcalloc(hba->nutrs, sizeof(struct ufshcd_lrb), GFP_KERNEL); 712 hba->lrb = devm_kzalloc(hba->dev,
713 hba->nutrs * sizeof(struct ufshcd_lrb),
714 GFP_KERNEL);
745 if (!hba->lrb) { 715 if (!hba->lrb) {
746 dev_err(hba->dev, "LRB Memory allocation failed\n"); 716 dev_err(hba->dev, "LRB Memory allocation failed\n");
747 goto out; 717 goto out;
748 } 718 }
749 return 0; 719 return 0;
750out: 720out:
751 ufshcd_free_hba_memory(hba);
752 return -ENOMEM; 721 return -ENOMEM;
753} 722}
754 723
@@ -1682,17 +1651,6 @@ int ufshcd_resume(struct ufs_hba *hba)
1682EXPORT_SYMBOL_GPL(ufshcd_resume); 1651EXPORT_SYMBOL_GPL(ufshcd_resume);
1683 1652
1684/** 1653/**
1685 * ufshcd_hba_free - free allocated memory for
1686 * host memory space data structures
1687 * @hba: per adapter instance
1688 */
1689static void ufshcd_hba_free(struct ufs_hba *hba)
1690{
1691 iounmap(hba->mmio_base);
1692 ufshcd_free_hba_memory(hba);
1693}
1694
1695/**
1696 * ufshcd_remove - de-allocate SCSI host and host memory space 1654 * ufshcd_remove - de-allocate SCSI host and host memory space
1697 * data structure memory 1655 * data structure memory
1698 * @hba - per adapter instance 1656 * @hba - per adapter instance
@@ -1701,9 +1659,7 @@ void ufshcd_remove(struct ufs_hba *hba)
1701{ 1659{
1702 /* disable interrupts */ 1660 /* disable interrupts */
1703 ufshcd_disable_intr(hba, hba->intr_mask); 1661 ufshcd_disable_intr(hba, hba->intr_mask);
1704
1705 ufshcd_hba_stop(hba); 1662 ufshcd_hba_stop(hba);
1706 ufshcd_hba_free(hba);
1707 1663
1708 scsi_remove_host(hba->host); 1664 scsi_remove_host(hba->host);
1709 scsi_host_put(hba->host); 1665 scsi_host_put(hba->host);
@@ -1789,23 +1745,23 @@ int ufshcd_init(struct device *dev, struct ufs_hba **hba_handle,
1789 mutex_init(&hba->uic_cmd_mutex); 1745 mutex_init(&hba->uic_cmd_mutex);
1790 1746
1791 /* IRQ registration */ 1747 /* IRQ registration */
1792 err = request_irq(irq, ufshcd_intr, IRQF_SHARED, UFSHCD, hba); 1748 err = devm_request_irq(dev, irq, ufshcd_intr, IRQF_SHARED, UFSHCD, hba);
1793 if (err) { 1749 if (err) {
1794 dev_err(hba->dev, "request irq failed\n"); 1750 dev_err(hba->dev, "request irq failed\n");
1795 goto out_lrb_free; 1751 goto out_disable;
1796 } 1752 }
1797 1753
1798 /* Enable SCSI tag mapping */ 1754 /* Enable SCSI tag mapping */
1799 err = scsi_init_shared_tag_map(host, host->can_queue); 1755 err = scsi_init_shared_tag_map(host, host->can_queue);
1800 if (err) { 1756 if (err) {
1801 dev_err(hba->dev, "init shared queue failed\n"); 1757 dev_err(hba->dev, "init shared queue failed\n");
1802 goto out_free_irq; 1758 goto out_disable;
1803 } 1759 }
1804 1760
1805 err = scsi_add_host(host, hba->dev); 1761 err = scsi_add_host(host, hba->dev);
1806 if (err) { 1762 if (err) {
1807 dev_err(hba->dev, "scsi_add_host failed\n"); 1763 dev_err(hba->dev, "scsi_add_host failed\n");
1808 goto out_free_irq; 1764 goto out_disable;
1809 } 1765 }
1810 1766
1811 /* Host controller enable */ 1767 /* Host controller enable */
@@ -1823,10 +1779,6 @@ int ufshcd_init(struct device *dev, struct ufs_hba **hba_handle,
1823 1779
1824out_remove_scsi_host: 1780out_remove_scsi_host:
1825 scsi_remove_host(hba->host); 1781 scsi_remove_host(hba->host);
1826out_free_irq:
1827 free_irq(irq, hba);
1828out_lrb_free:
1829 ufshcd_free_hba_memory(hba);
1830out_disable: 1782out_disable:
1831 scsi_host_put(host); 1783 scsi_host_put(host);
1832out_error: 1784out_error: