aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/ata/ahci.c
diff options
context:
space:
mode:
authorTejun Heo <htejun@gmail.com>2007-01-20 02:00:28 -0500
committerJeff Garzik <jeff@garzik.org>2007-02-09 17:39:37 -0500
commit24dc5f33ea4b504cfbd23fa159a4cacba8e4d800 (patch)
treed76de456157f555c9a65b83f426fd805fee1e846 /drivers/ata/ahci.c
parentf0d36efdc624beb3d9e29b9ab9e9537bf0f25d5b (diff)
libata: update libata LLDs to use devres
Update libata LLDs to use devres. Core layer is already converted to support managed LLDs. This patch simplifies initialization and fixes many resource related bugs in init failure and detach path. For example, all converted drivers now handle ata_device_add() failure gracefully without excessive resource rollback code. As most resources are released automatically on driver detach, many drivers don't need or can do with much simpler ->{port|host}_stop(). In general, stop callbacks are need iff port or host needs to be given commands to shut it down. Note that freezing is enough in many cases and ports are automatically frozen before being detached. Signed-off-by: Tejun Heo <htejun@gmail.com> Signed-off-by: Jeff Garzik <jeff@garzik.org>
Diffstat (limited to 'drivers/ata/ahci.c')
-rw-r--r--drivers/ata/ahci.c125
1 files changed, 27 insertions, 98 deletions
diff --git a/drivers/ata/ahci.c b/drivers/ata/ahci.c
index d72568392e6c..20ab3ffce559 100644
--- a/drivers/ata/ahci.c
+++ b/drivers/ata/ahci.c
@@ -45,7 +45,6 @@
45#include <scsi/scsi_host.h> 45#include <scsi/scsi_host.h>
46#include <scsi/scsi_cmnd.h> 46#include <scsi/scsi_cmnd.h>
47#include <linux/libata.h> 47#include <linux/libata.h>
48#include <asm/io.h>
49 48
50#define DRV_NAME "ahci" 49#define DRV_NAME "ahci"
51#define DRV_VERSION "2.0" 50#define DRV_VERSION "2.0"
@@ -166,9 +165,6 @@ enum {
166 PORT_CMD_ICC_PARTIAL = (0x2 << 28), /* Put i/f in partial state */ 165 PORT_CMD_ICC_PARTIAL = (0x2 << 28), /* Put i/f in partial state */
167 PORT_CMD_ICC_SLUMBER = (0x6 << 28), /* Put i/f in slumber state */ 166 PORT_CMD_ICC_SLUMBER = (0x6 << 28), /* Put i/f in slumber state */
168 167
169 /* hpriv->flags bits */
170 AHCI_FLAG_MSI = (1 << 0),
171
172 /* ap->flags bits */ 168 /* ap->flags bits */
173 AHCI_FLAG_NO_NCQ = (1 << 24), 169 AHCI_FLAG_NO_NCQ = (1 << 24),
174 AHCI_FLAG_IGN_IRQ_IF_ERR = (1 << 25), /* ignore IRQ_IF_ERR */ 170 AHCI_FLAG_IGN_IRQ_IF_ERR = (1 << 25), /* ignore IRQ_IF_ERR */
@@ -191,7 +187,6 @@ struct ahci_sg {
191}; 187};
192 188
193struct ahci_host_priv { 189struct ahci_host_priv {
194 unsigned long flags;
195 u32 cap; /* cache of HOST_CAP register */ 190 u32 cap; /* cache of HOST_CAP register */
196 u32 port_map; /* cache of HOST_PORTS_IMPL reg */ 191 u32 port_map; /* cache of HOST_PORTS_IMPL reg */
197}; 192};
@@ -229,7 +224,6 @@ static int ahci_port_suspend(struct ata_port *ap, pm_message_t mesg);
229static int ahci_port_resume(struct ata_port *ap); 224static int ahci_port_resume(struct ata_port *ap);
230static int ahci_pci_device_suspend(struct pci_dev *pdev, pm_message_t mesg); 225static int ahci_pci_device_suspend(struct pci_dev *pdev, pm_message_t mesg);
231static int ahci_pci_device_resume(struct pci_dev *pdev); 226static int ahci_pci_device_resume(struct pci_dev *pdev);
232static void ahci_remove_one (struct pci_dev *pdev);
233 227
234static struct scsi_host_template ahci_sht = { 228static struct scsi_host_template ahci_sht = {
235 .module = THIS_MODULE, 229 .module = THIS_MODULE,
@@ -441,9 +435,9 @@ static struct pci_driver ahci_pci_driver = {
441 .name = DRV_NAME, 435 .name = DRV_NAME,
442 .id_table = ahci_pci_tbl, 436 .id_table = ahci_pci_tbl,
443 .probe = ahci_init_one, 437 .probe = ahci_init_one,
438 .remove = ata_pci_remove_one,
444 .suspend = ahci_pci_device_suspend, 439 .suspend = ahci_pci_device_suspend,
445 .resume = ahci_pci_device_resume, 440 .resume = ahci_pci_device_resume,
446 .remove = ahci_remove_one,
447}; 441};
448 442
449 443
@@ -1426,23 +1420,18 @@ static int ahci_port_start(struct ata_port *ap)
1426 dma_addr_t mem_dma; 1420 dma_addr_t mem_dma;
1427 int rc; 1421 int rc;
1428 1422
1429 pp = kmalloc(sizeof(*pp), GFP_KERNEL); 1423 pp = devm_kzalloc(dev, sizeof(*pp), GFP_KERNEL);
1430 if (!pp) 1424 if (!pp)
1431 return -ENOMEM; 1425 return -ENOMEM;
1432 memset(pp, 0, sizeof(*pp));
1433 1426
1434 rc = ata_pad_alloc(ap, dev); 1427 rc = ata_pad_alloc(ap, dev);
1435 if (rc) { 1428 if (rc)
1436 kfree(pp);
1437 return rc; 1429 return rc;
1438 }
1439 1430
1440 mem = dma_alloc_coherent(dev, AHCI_PORT_PRIV_DMA_SZ, &mem_dma, GFP_KERNEL); 1431 mem = dmam_alloc_coherent(dev, AHCI_PORT_PRIV_DMA_SZ, &mem_dma,
1441 if (!mem) { 1432 GFP_KERNEL);
1442 ata_pad_free(ap, dev); 1433 if (!mem)
1443 kfree(pp);
1444 return -ENOMEM; 1434 return -ENOMEM;
1445 }
1446 memset(mem, 0, AHCI_PORT_PRIV_DMA_SZ); 1435 memset(mem, 0, AHCI_PORT_PRIV_DMA_SZ);
1447 1436
1448 /* 1437 /*
@@ -1484,9 +1473,7 @@ static int ahci_port_start(struct ata_port *ap)
1484 1473
1485static void ahci_port_stop(struct ata_port *ap) 1474static void ahci_port_stop(struct ata_port *ap)
1486{ 1475{
1487 struct device *dev = ap->host->dev;
1488 struct ahci_host_priv *hpriv = ap->host->private_data; 1476 struct ahci_host_priv *hpriv = ap->host->private_data;
1489 struct ahci_port_priv *pp = ap->private_data;
1490 void __iomem *mmio = ap->host->mmio_base; 1477 void __iomem *mmio = ap->host->mmio_base;
1491 void __iomem *port_mmio = ahci_port_base(mmio, ap->port_no); 1478 void __iomem *port_mmio = ahci_port_base(mmio, ap->port_no);
1492 const char *emsg = NULL; 1479 const char *emsg = NULL;
@@ -1496,12 +1483,6 @@ static void ahci_port_stop(struct ata_port *ap)
1496 rc = ahci_deinit_port(port_mmio, hpriv->cap, &emsg); 1483 rc = ahci_deinit_port(port_mmio, hpriv->cap, &emsg);
1497 if (rc) 1484 if (rc)
1498 ata_port_printk(ap, KERN_WARNING, "%s (%d)\n", emsg, rc); 1485 ata_port_printk(ap, KERN_WARNING, "%s (%d)\n", emsg, rc);
1499
1500 ap->private_data = NULL;
1501 dma_free_coherent(dev, AHCI_PORT_PRIV_DMA_SZ,
1502 pp->cmd_slot, pp->cmd_slot_dma);
1503 ata_pad_free(ap, dev);
1504 kfree(pp);
1505} 1486}
1506 1487
1507static void ahci_setup_port(struct ata_ioports *port, unsigned long base, 1488static void ahci_setup_port(struct ata_ioports *port, unsigned long base,
@@ -1669,15 +1650,15 @@ static void ahci_print_info(struct ata_probe_ent *probe_ent)
1669 ); 1650 );
1670} 1651}
1671 1652
1672static int ahci_init_one (struct pci_dev *pdev, const struct pci_device_id *ent) 1653static int ahci_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
1673{ 1654{
1674 static int printed_version; 1655 static int printed_version;
1675 struct ata_probe_ent *probe_ent = NULL; 1656 unsigned int board_idx = (unsigned int) ent->driver_data;
1657 struct device *dev = &pdev->dev;
1658 struct ata_probe_ent *probe_ent;
1676 struct ahci_host_priv *hpriv; 1659 struct ahci_host_priv *hpriv;
1677 unsigned long base; 1660 unsigned long base;
1678 void __iomem *mmio_base; 1661 void __iomem *mmio_base;
1679 unsigned int board_idx = (unsigned int) ent->driver_data;
1680 int have_msi, pci_dev_busy = 0;
1681 int rc; 1662 int rc;
1682 1663
1683 VPRINTK("ENTER\n"); 1664 VPRINTK("ENTER\n");
@@ -1694,46 +1675,34 @@ static int ahci_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
1694 return -ENODEV; 1675 return -ENODEV;
1695 } 1676 }
1696 1677
1697 rc = pci_enable_device(pdev); 1678 rc = pcim_enable_device(pdev);
1698 if (rc) 1679 if (rc)
1699 return rc; 1680 return rc;
1700 1681
1701 rc = pci_request_regions(pdev, DRV_NAME); 1682 rc = pci_request_regions(pdev, DRV_NAME);
1702 if (rc) { 1683 if (rc) {
1703 pci_dev_busy = 1; 1684 pcim_pin_device(pdev);
1704 goto err_out; 1685 return rc;
1705 } 1686 }
1706 1687
1707 if (pci_enable_msi(pdev) == 0) 1688 if (pci_enable_msi(pdev))
1708 have_msi = 1;
1709 else {
1710 pci_intx(pdev, 1); 1689 pci_intx(pdev, 1);
1711 have_msi = 0;
1712 }
1713 1690
1714 probe_ent = kmalloc(sizeof(*probe_ent), GFP_KERNEL); 1691 probe_ent = devm_kzalloc(dev, sizeof(*probe_ent), GFP_KERNEL);
1715 if (probe_ent == NULL) { 1692 if (probe_ent == NULL)
1716 rc = -ENOMEM; 1693 return -ENOMEM;
1717 goto err_out_msi;
1718 }
1719 1694
1720 memset(probe_ent, 0, sizeof(*probe_ent));
1721 probe_ent->dev = pci_dev_to_dev(pdev); 1695 probe_ent->dev = pci_dev_to_dev(pdev);
1722 INIT_LIST_HEAD(&probe_ent->node); 1696 INIT_LIST_HEAD(&probe_ent->node);
1723 1697
1724 mmio_base = pci_iomap(pdev, AHCI_PCI_BAR, 0); 1698 mmio_base = pcim_iomap(pdev, AHCI_PCI_BAR, 0);
1725 if (mmio_base == NULL) { 1699 if (mmio_base == NULL)
1726 rc = -ENOMEM; 1700 return -ENOMEM;
1727 goto err_out_free_ent;
1728 }
1729 base = (unsigned long) mmio_base; 1701 base = (unsigned long) mmio_base;
1730 1702
1731 hpriv = kmalloc(sizeof(*hpriv), GFP_KERNEL); 1703 hpriv = devm_kzalloc(dev, sizeof(*hpriv), GFP_KERNEL);
1732 if (!hpriv) { 1704 if (!hpriv)
1733 rc = -ENOMEM; 1705 return -ENOMEM;
1734 goto err_out_iounmap;
1735 }
1736 memset(hpriv, 0, sizeof(*hpriv));
1737 1706
1738 probe_ent->sht = ahci_port_info[board_idx].sht; 1707 probe_ent->sht = ahci_port_info[board_idx].sht;
1739 probe_ent->port_flags = ahci_port_info[board_idx].flags; 1708 probe_ent->port_flags = ahci_port_info[board_idx].flags;
@@ -1746,13 +1715,10 @@ static int ahci_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
1746 probe_ent->mmio_base = mmio_base; 1715 probe_ent->mmio_base = mmio_base;
1747 probe_ent->private_data = hpriv; 1716 probe_ent->private_data = hpriv;
1748 1717
1749 if (have_msi)
1750 hpriv->flags |= AHCI_FLAG_MSI;
1751
1752 /* initialize adapter */ 1718 /* initialize adapter */
1753 rc = ahci_host_init(probe_ent); 1719 rc = ahci_host_init(probe_ent);
1754 if (rc) 1720 if (rc)
1755 goto err_out_hpriv; 1721 return rc;
1756 1722
1757 if (!(probe_ent->port_flags & AHCI_FLAG_NO_NCQ) && 1723 if (!(probe_ent->port_flags & AHCI_FLAG_NO_NCQ) &&
1758 (hpriv->cap & HOST_CAP_NCQ)) 1724 (hpriv->cap & HOST_CAP_NCQ))
@@ -1760,48 +1726,11 @@ static int ahci_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
1760 1726
1761 ahci_print_info(probe_ent); 1727 ahci_print_info(probe_ent);
1762 1728
1763 /* FIXME: check ata_device_add return value */ 1729 if (!ata_device_add(probe_ent))
1764 ata_device_add(probe_ent); 1730 return -ENODEV;
1765 kfree(probe_ent);
1766 1731
1732 devm_kfree(dev, probe_ent);
1767 return 0; 1733 return 0;
1768
1769err_out_hpriv:
1770 kfree(hpriv);
1771err_out_iounmap:
1772 pci_iounmap(pdev, mmio_base);
1773err_out_free_ent:
1774 kfree(probe_ent);
1775err_out_msi:
1776 if (have_msi)
1777 pci_disable_msi(pdev);
1778 else
1779 pci_intx(pdev, 0);
1780 pci_release_regions(pdev);
1781err_out:
1782 if (!pci_dev_busy)
1783 pci_disable_device(pdev);
1784 return rc;
1785}
1786
1787static void ahci_remove_one(struct pci_dev *pdev)
1788{
1789 struct device *dev = pci_dev_to_dev(pdev);
1790 struct ata_host *host = dev_get_drvdata(dev);
1791 struct ahci_host_priv *hpriv = host->private_data;
1792
1793 ata_host_remove(host);
1794
1795 pci_iounmap(pdev, host->mmio_base);
1796
1797 if (hpriv->flags & AHCI_FLAG_MSI)
1798 pci_disable_msi(pdev);
1799 else
1800 pci_intx(pdev, 0);
1801 pci_release_regions(pdev);
1802 pci_disable_device(pdev);
1803 dev_set_drvdata(dev, NULL);
1804 kfree(hpriv);
1805} 1734}
1806 1735
1807static int __init ahci_init(void) 1736static int __init ahci_init(void)