aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/ata/sata_qstor.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/sata_qstor.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/sata_qstor.c')
-rw-r--r--drivers/ata/sata_qstor.c90
1 files changed, 22 insertions, 68 deletions
diff --git a/drivers/ata/sata_qstor.c b/drivers/ata/sata_qstor.c
index 0292a79f9747..339f61648af6 100644
--- a/drivers/ata/sata_qstor.c
+++ b/drivers/ata/sata_qstor.c
@@ -37,7 +37,6 @@
37#include <linux/sched.h> 37#include <linux/sched.h>
38#include <linux/device.h> 38#include <linux/device.h>
39#include <scsi/scsi_host.h> 39#include <scsi/scsi_host.h>
40#include <asm/io.h>
41#include <linux/libata.h> 40#include <linux/libata.h>
42 41
43#define DRV_NAME "sata_qstor" 42#define DRV_NAME "sata_qstor"
@@ -117,7 +116,6 @@ static int qs_ata_init_one (struct pci_dev *pdev, const struct pci_device_id *en
117static irqreturn_t qs_intr (int irq, void *dev_instance); 116static irqreturn_t qs_intr (int irq, void *dev_instance);
118static int qs_port_start(struct ata_port *ap); 117static int qs_port_start(struct ata_port *ap);
119static void qs_host_stop(struct ata_host *host); 118static void qs_host_stop(struct ata_host *host);
120static void qs_port_stop(struct ata_port *ap);
121static void qs_phy_reset(struct ata_port *ap); 119static void qs_phy_reset(struct ata_port *ap);
122static void qs_qc_prep(struct ata_queued_cmd *qc); 120static void qs_qc_prep(struct ata_queued_cmd *qc);
123static unsigned int qs_qc_issue(struct ata_queued_cmd *qc); 121static unsigned int qs_qc_issue(struct ata_queued_cmd *qc);
@@ -164,7 +162,6 @@ static const struct ata_port_operations qs_ata_ops = {
164 .scr_read = qs_scr_read, 162 .scr_read = qs_scr_read,
165 .scr_write = qs_scr_write, 163 .scr_write = qs_scr_write,
166 .port_start = qs_port_start, 164 .port_start = qs_port_start,
167 .port_stop = qs_port_stop,
168 .host_stop = qs_host_stop, 165 .host_stop = qs_host_stop,
169 .bmdma_stop = qs_bmdma_stop, 166 .bmdma_stop = qs_bmdma_stop,
170 .bmdma_status = qs_bmdma_status, 167 .bmdma_status = qs_bmdma_status,
@@ -501,17 +498,13 @@ static int qs_port_start(struct ata_port *ap)
501 if (rc) 498 if (rc)
502 return rc; 499 return rc;
503 qs_enter_reg_mode(ap); 500 qs_enter_reg_mode(ap);
504 pp = kzalloc(sizeof(*pp), GFP_KERNEL); 501 pp = devm_kzalloc(dev, sizeof(*pp), GFP_KERNEL);
505 if (!pp) { 502 if (!pp)
506 rc = -ENOMEM; 503 return -ENOMEM;
507 goto err_out; 504 pp->pkt = dmam_alloc_coherent(dev, QS_PKT_BYTES, &pp->pkt_dma,
508 } 505 GFP_KERNEL);
509 pp->pkt = dma_alloc_coherent(dev, QS_PKT_BYTES, &pp->pkt_dma, 506 if (!pp->pkt)
510 GFP_KERNEL); 507 return -ENOMEM;
511 if (!pp->pkt) {
512 rc = -ENOMEM;
513 goto err_out_kfree;
514 }
515 memset(pp->pkt, 0, QS_PKT_BYTES); 508 memset(pp->pkt, 0, QS_PKT_BYTES);
516 ap->private_data = pp; 509 ap->private_data = pp;
517 510
@@ -519,38 +512,14 @@ static int qs_port_start(struct ata_port *ap)
519 writel((u32) addr, chan + QS_CCF_CPBA); 512 writel((u32) addr, chan + QS_CCF_CPBA);
520 writel((u32)(addr >> 32), chan + QS_CCF_CPBA + 4); 513 writel((u32)(addr >> 32), chan + QS_CCF_CPBA + 4);
521 return 0; 514 return 0;
522
523err_out_kfree:
524 kfree(pp);
525err_out:
526 ata_port_stop(ap);
527 return rc;
528}
529
530static void qs_port_stop(struct ata_port *ap)
531{
532 struct device *dev = ap->host->dev;
533 struct qs_port_priv *pp = ap->private_data;
534
535 if (pp != NULL) {
536 ap->private_data = NULL;
537 if (pp->pkt != NULL)
538 dma_free_coherent(dev, QS_PKT_BYTES, pp->pkt,
539 pp->pkt_dma);
540 kfree(pp);
541 }
542 ata_port_stop(ap);
543} 515}
544 516
545static void qs_host_stop(struct ata_host *host) 517static void qs_host_stop(struct ata_host *host)
546{ 518{
547 void __iomem *mmio_base = host->mmio_base; 519 void __iomem *mmio_base = host->mmio_base;
548 struct pci_dev *pdev = to_pci_dev(host->dev);
549 520
550 writeb(0, mmio_base + QS_HCT_CTRL); /* disable host interrupts */ 521 writeb(0, mmio_base + QS_HCT_CTRL); /* disable host interrupts */
551 writeb(QS_CNFG3_GSRST, mmio_base + QS_HCF_CNFG3); /* global reset */ 522 writeb(QS_CNFG3_GSRST, mmio_base + QS_HCF_CNFG3); /* global reset */
552
553 pci_iounmap(pdev, mmio_base);
554} 523}
555 524
556static void qs_host_init(unsigned int chip_id, struct ata_probe_ent *pe) 525static void qs_host_init(unsigned int chip_id, struct ata_probe_ent *pe)
@@ -638,36 +607,29 @@ static int qs_ata_init_one(struct pci_dev *pdev,
638 if (!printed_version++) 607 if (!printed_version++)
639 dev_printk(KERN_DEBUG, &pdev->dev, "version " DRV_VERSION "\n"); 608 dev_printk(KERN_DEBUG, &pdev->dev, "version " DRV_VERSION "\n");
640 609
641 rc = pci_enable_device(pdev); 610 rc = pcim_enable_device(pdev);
642 if (rc) 611 if (rc)
643 return rc; 612 return rc;
644 613
645 rc = pci_request_regions(pdev, DRV_NAME); 614 rc = pci_request_regions(pdev, DRV_NAME);
646 if (rc) 615 if (rc)
647 goto err_out; 616 return rc;
648 617
649 if ((pci_resource_flags(pdev, 4) & IORESOURCE_MEM) == 0) { 618 if ((pci_resource_flags(pdev, 4) & IORESOURCE_MEM) == 0)
650 rc = -ENODEV; 619 return -ENODEV;
651 goto err_out_regions;
652 }
653 620
654 mmio_base = pci_iomap(pdev, 4, 0); 621 mmio_base = pcim_iomap(pdev, 4, 0);
655 if (mmio_base == NULL) { 622 if (mmio_base == NULL)
656 rc = -ENOMEM; 623 return -ENOMEM;
657 goto err_out_regions;
658 }
659 624
660 rc = qs_set_dma_masks(pdev, mmio_base); 625 rc = qs_set_dma_masks(pdev, mmio_base);
661 if (rc) 626 if (rc)
662 goto err_out_iounmap; 627 return rc;
663 628
664 probe_ent = kmalloc(sizeof(*probe_ent), GFP_KERNEL); 629 probe_ent = devm_kzalloc(&pdev->dev, sizeof(*probe_ent), GFP_KERNEL);
665 if (probe_ent == NULL) { 630 if (probe_ent == NULL)
666 rc = -ENOMEM; 631 return -ENOMEM;
667 goto err_out_iounmap;
668 }
669 632
670 memset(probe_ent, 0, sizeof(*probe_ent));
671 probe_ent->dev = pci_dev_to_dev(pdev); 633 probe_ent->dev = pci_dev_to_dev(pdev);
672 INIT_LIST_HEAD(&probe_ent->node); 634 INIT_LIST_HEAD(&probe_ent->node);
673 635
@@ -694,19 +656,11 @@ static int qs_ata_init_one(struct pci_dev *pdev,
694 /* initialize adapter */ 656 /* initialize adapter */
695 qs_host_init(board_idx, probe_ent); 657 qs_host_init(board_idx, probe_ent);
696 658
697 rc = ata_device_add(probe_ent); 659 if (ata_device_add(probe_ent) != QS_PORTS)
698 kfree(probe_ent); 660 return -EIO;
699 if (rc != QS_PORTS)
700 goto err_out_iounmap;
701 return 0;
702 661
703err_out_iounmap: 662 devm_kfree(&pdev->dev, probe_ent);
704 pci_iounmap(pdev, mmio_base); 663 return 0;
705err_out_regions:
706 pci_release_regions(pdev);
707err_out:
708 pci_disable_device(pdev);
709 return rc;
710} 664}
711 665
712static int __init qs_ata_init(void) 666static int __init qs_ata_init(void)