aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/ata/pdc_adma.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/pdc_adma.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/pdc_adma.c')
-rw-r--r--drivers/ata/pdc_adma.c79
1 files changed, 21 insertions, 58 deletions
diff --git a/drivers/ata/pdc_adma.c b/drivers/ata/pdc_adma.c
index 90786d7a20bb..a6bf7cbdfdc5 100644
--- a/drivers/ata/pdc_adma.c
+++ b/drivers/ata/pdc_adma.c
@@ -42,7 +42,6 @@
42#include <linux/sched.h> 42#include <linux/sched.h>
43#include <linux/device.h> 43#include <linux/device.h>
44#include <scsi/scsi_host.h> 44#include <scsi/scsi_host.h>
45#include <asm/io.h>
46#include <linux/libata.h> 45#include <linux/libata.h>
47 46
48#define DRV_NAME "pdc_adma" 47#define DRV_NAME "pdc_adma"
@@ -550,48 +549,28 @@ static int adma_port_start(struct ata_port *ap)
550 if (rc) 549 if (rc)
551 return rc; 550 return rc;
552 adma_enter_reg_mode(ap); 551 adma_enter_reg_mode(ap);
553 rc = -ENOMEM; 552 pp = devm_kzalloc(dev, sizeof(*pp), GFP_KERNEL);
554 pp = kzalloc(sizeof(*pp), GFP_KERNEL);
555 if (!pp) 553 if (!pp)
556 goto err_out; 554 return -ENOMEM;
557 pp->pkt = dma_alloc_coherent(dev, ADMA_PKT_BYTES, &pp->pkt_dma, 555 pp->pkt = dmam_alloc_coherent(dev, ADMA_PKT_BYTES, &pp->pkt_dma,
558 GFP_KERNEL); 556 GFP_KERNEL);
559 if (!pp->pkt) 557 if (!pp->pkt)
560 goto err_out_kfree; 558 return -ENOMEM;
561 /* paranoia? */ 559 /* paranoia? */
562 if ((pp->pkt_dma & 7) != 0) { 560 if ((pp->pkt_dma & 7) != 0) {
563 printk("bad alignment for pp->pkt_dma: %08x\n", 561 printk("bad alignment for pp->pkt_dma: %08x\n",
564 (u32)pp->pkt_dma); 562 (u32)pp->pkt_dma);
565 dma_free_coherent(dev, ADMA_PKT_BYTES, 563 return -ENOMEM;
566 pp->pkt, pp->pkt_dma);
567 goto err_out_kfree;
568 } 564 }
569 memset(pp->pkt, 0, ADMA_PKT_BYTES); 565 memset(pp->pkt, 0, ADMA_PKT_BYTES);
570 ap->private_data = pp; 566 ap->private_data = pp;
571 adma_reinit_engine(ap); 567 adma_reinit_engine(ap);
572 return 0; 568 return 0;
573
574err_out_kfree:
575 kfree(pp);
576err_out:
577 ata_port_stop(ap);
578 return rc;
579} 569}
580 570
581static void adma_port_stop(struct ata_port *ap) 571static void adma_port_stop(struct ata_port *ap)
582{ 572{
583 struct device *dev = ap->host->dev;
584 struct adma_port_priv *pp = ap->private_data;
585
586 adma_reset_engine(ADMA_REGS(ap->host->mmio_base, ap->port_no)); 573 adma_reset_engine(ADMA_REGS(ap->host->mmio_base, ap->port_no));
587 if (pp != NULL) {
588 ap->private_data = NULL;
589 if (pp->pkt != NULL)
590 dma_free_coherent(dev, ADMA_PKT_BYTES,
591 pp->pkt, pp->pkt_dma);
592 kfree(pp);
593 }
594 ata_port_stop(ap);
595} 574}
596 575
597static void adma_host_stop(struct ata_host *host) 576static void adma_host_stop(struct ata_host *host)
@@ -600,8 +579,6 @@ static void adma_host_stop(struct ata_host *host)
600 579
601 for (port_no = 0; port_no < ADMA_PORTS; ++port_no) 580 for (port_no = 0; port_no < ADMA_PORTS; ++port_no)
602 adma_reset_engine(ADMA_REGS(host->mmio_base, port_no)); 581 adma_reset_engine(ADMA_REGS(host->mmio_base, port_no));
603
604 ata_pci_host_stop(host);
605} 582}
606 583
607static void adma_host_init(unsigned int chip_id, 584static void adma_host_init(unsigned int chip_id,
@@ -649,34 +626,28 @@ static int adma_ata_init_one(struct pci_dev *pdev,
649 if (!printed_version++) 626 if (!printed_version++)
650 dev_printk(KERN_DEBUG, &pdev->dev, "version " DRV_VERSION "\n"); 627 dev_printk(KERN_DEBUG, &pdev->dev, "version " DRV_VERSION "\n");
651 628
652 rc = pci_enable_device(pdev); 629 rc = pcim_enable_device(pdev);
653 if (rc) 630 if (rc)
654 return rc; 631 return rc;
655 632
656 rc = pci_request_regions(pdev, DRV_NAME); 633 rc = pci_request_regions(pdev, DRV_NAME);
657 if (rc) 634 if (rc)
658 goto err_out; 635 return rc;
659 636
660 if ((pci_resource_flags(pdev, 4) & IORESOURCE_MEM) == 0) { 637 if ((pci_resource_flags(pdev, 4) & IORESOURCE_MEM) == 0)
661 rc = -ENODEV; 638 return -ENODEV;
662 goto err_out_regions;
663 }
664 639
665 mmio_base = pci_iomap(pdev, 4, 0); 640 mmio_base = pcim_iomap(pdev, 4, 0);
666 if (mmio_base == NULL) { 641 if (mmio_base == NULL)
667 rc = -ENOMEM; 642 return -ENOMEM;
668 goto err_out_regions;
669 }
670 643
671 rc = adma_set_dma_masks(pdev, mmio_base); 644 rc = adma_set_dma_masks(pdev, mmio_base);
672 if (rc) 645 if (rc)
673 goto err_out_iounmap; 646 return rc;
674 647
675 probe_ent = kzalloc(sizeof(*probe_ent), GFP_KERNEL); 648 probe_ent = devm_kzalloc(&pdev->dev, sizeof(*probe_ent), GFP_KERNEL);
676 if (probe_ent == NULL) { 649 if (probe_ent == NULL)
677 rc = -ENOMEM; 650 return -ENOMEM;
678 goto err_out_iounmap;
679 }
680 651
681 probe_ent->dev = pci_dev_to_dev(pdev); 652 probe_ent->dev = pci_dev_to_dev(pdev);
682 INIT_LIST_HEAD(&probe_ent->node); 653 INIT_LIST_HEAD(&probe_ent->node);
@@ -703,19 +674,11 @@ static int adma_ata_init_one(struct pci_dev *pdev,
703 /* initialize adapter */ 674 /* initialize adapter */
704 adma_host_init(board_idx, probe_ent); 675 adma_host_init(board_idx, probe_ent);
705 676
706 rc = ata_device_add(probe_ent); 677 if (!ata_device_add(probe_ent))
707 kfree(probe_ent); 678 return -ENODEV;
708 if (rc != ADMA_PORTS)
709 goto err_out_iounmap;
710 return 0;
711 679
712err_out_iounmap: 680 devm_kfree(&pdev->dev, probe_ent);
713 pci_iounmap(pdev, mmio_base); 681 return 0;
714err_out_regions:
715 pci_release_regions(pdev);
716err_out:
717 pci_disable_device(pdev);
718 return rc;
719} 682}
720 683
721static int __init adma_ata_init(void) 684static int __init adma_ata_init(void)