diff options
author | Tejun Heo <htejun@gmail.com> | 2007-01-20 02:00:28 -0500 |
---|---|---|
committer | Jeff Garzik <jeff@garzik.org> | 2007-02-09 17:39:37 -0500 |
commit | 24dc5f33ea4b504cfbd23fa159a4cacba8e4d800 (patch) | |
tree | d76de456157f555c9a65b83f426fd805fee1e846 /drivers/ata/sata_promise.c | |
parent | f0d36efdc624beb3d9e29b9ab9e9537bf0f25d5b (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_promise.c')
-rw-r--r-- | drivers/ata/sata_promise.c | 106 |
1 files changed, 23 insertions, 83 deletions
diff --git a/drivers/ata/sata_promise.c b/drivers/ata/sata_promise.c index 32ae03e9081b..e09c609d4961 100644 --- a/drivers/ata/sata_promise.c +++ b/drivers/ata/sata_promise.c | |||
@@ -43,7 +43,6 @@ | |||
43 | #include <scsi/scsi_host.h> | 43 | #include <scsi/scsi_host.h> |
44 | #include <scsi/scsi_cmnd.h> | 44 | #include <scsi/scsi_cmnd.h> |
45 | #include <linux/libata.h> | 45 | #include <linux/libata.h> |
46 | #include <asm/io.h> | ||
47 | #include "sata_promise.h" | 46 | #include "sata_promise.h" |
48 | 47 | ||
49 | #define DRV_NAME "sata_promise" | 48 | #define DRV_NAME "sata_promise" |
@@ -121,7 +120,6 @@ static int pdc_ata_init_one (struct pci_dev *pdev, const struct pci_device_id *e | |||
121 | static irqreturn_t pdc_interrupt (int irq, void *dev_instance); | 120 | static irqreturn_t pdc_interrupt (int irq, void *dev_instance); |
122 | static void pdc_eng_timeout(struct ata_port *ap); | 121 | static void pdc_eng_timeout(struct ata_port *ap); |
123 | static int pdc_port_start(struct ata_port *ap); | 122 | static int pdc_port_start(struct ata_port *ap); |
124 | static void pdc_port_stop(struct ata_port *ap); | ||
125 | static void pdc_pata_phy_reset(struct ata_port *ap); | 123 | static void pdc_pata_phy_reset(struct ata_port *ap); |
126 | static void pdc_qc_prep(struct ata_queued_cmd *qc); | 124 | static void pdc_qc_prep(struct ata_queued_cmd *qc); |
127 | static void pdc_tf_load_mmio(struct ata_port *ap, const struct ata_taskfile *tf); | 125 | static void pdc_tf_load_mmio(struct ata_port *ap, const struct ata_taskfile *tf); |
@@ -130,7 +128,6 @@ static int pdc_check_atapi_dma(struct ata_queued_cmd *qc); | |||
130 | static int pdc_old_check_atapi_dma(struct ata_queued_cmd *qc); | 128 | static int pdc_old_check_atapi_dma(struct ata_queued_cmd *qc); |
131 | static void pdc_irq_clear(struct ata_port *ap); | 129 | static void pdc_irq_clear(struct ata_port *ap); |
132 | static unsigned int pdc_qc_issue_prot(struct ata_queued_cmd *qc); | 130 | static unsigned int pdc_qc_issue_prot(struct ata_queued_cmd *qc); |
133 | static void pdc_host_stop(struct ata_host *host); | ||
134 | static void pdc_freeze(struct ata_port *ap); | 131 | static void pdc_freeze(struct ata_port *ap); |
135 | static void pdc_thaw(struct ata_port *ap); | 132 | static void pdc_thaw(struct ata_port *ap); |
136 | static void pdc_error_handler(struct ata_port *ap); | 133 | static void pdc_error_handler(struct ata_port *ap); |
@@ -177,8 +174,6 @@ static const struct ata_port_operations pdc_sata_ops = { | |||
177 | .scr_read = pdc_sata_scr_read, | 174 | .scr_read = pdc_sata_scr_read, |
178 | .scr_write = pdc_sata_scr_write, | 175 | .scr_write = pdc_sata_scr_write, |
179 | .port_start = pdc_port_start, | 176 | .port_start = pdc_port_start, |
180 | .port_stop = pdc_port_stop, | ||
181 | .host_stop = pdc_host_stop, | ||
182 | }; | 177 | }; |
183 | 178 | ||
184 | /* First-generation chips need a more restrictive ->check_atapi_dma op */ | 179 | /* First-generation chips need a more restrictive ->check_atapi_dma op */ |
@@ -204,8 +199,6 @@ static const struct ata_port_operations pdc_old_sata_ops = { | |||
204 | .scr_read = pdc_sata_scr_read, | 199 | .scr_read = pdc_sata_scr_read, |
205 | .scr_write = pdc_sata_scr_write, | 200 | .scr_write = pdc_sata_scr_write, |
206 | .port_start = pdc_port_start, | 201 | .port_start = pdc_port_start, |
207 | .port_stop = pdc_port_stop, | ||
208 | .host_stop = pdc_host_stop, | ||
209 | }; | 202 | }; |
210 | 203 | ||
211 | static const struct ata_port_operations pdc_pata_ops = { | 204 | static const struct ata_port_operations pdc_pata_ops = { |
@@ -227,8 +220,6 @@ static const struct ata_port_operations pdc_pata_ops = { | |||
227 | .irq_clear = pdc_irq_clear, | 220 | .irq_clear = pdc_irq_clear, |
228 | 221 | ||
229 | .port_start = pdc_port_start, | 222 | .port_start = pdc_port_start, |
230 | .port_stop = pdc_port_stop, | ||
231 | .host_stop = pdc_host_stop, | ||
232 | }; | 223 | }; |
233 | 224 | ||
234 | static const struct ata_port_info pdc_port_info[] = { | 225 | static const struct ata_port_info pdc_port_info[] = { |
@@ -332,17 +323,13 @@ static int pdc_port_start(struct ata_port *ap) | |||
332 | if (rc) | 323 | if (rc) |
333 | return rc; | 324 | return rc; |
334 | 325 | ||
335 | pp = kzalloc(sizeof(*pp), GFP_KERNEL); | 326 | pp = devm_kzalloc(dev, sizeof(*pp), GFP_KERNEL); |
336 | if (!pp) { | 327 | if (!pp) |
337 | rc = -ENOMEM; | 328 | return -ENOMEM; |
338 | goto err_out; | ||
339 | } | ||
340 | 329 | ||
341 | pp->pkt = dma_alloc_coherent(dev, 128, &pp->pkt_dma, GFP_KERNEL); | 330 | pp->pkt = dmam_alloc_coherent(dev, 128, &pp->pkt_dma, GFP_KERNEL); |
342 | if (!pp->pkt) { | 331 | if (!pp->pkt) |
343 | rc = -ENOMEM; | 332 | return -ENOMEM; |
344 | goto err_out_kfree; | ||
345 | } | ||
346 | 333 | ||
347 | ap->private_data = pp; | 334 | ap->private_data = pp; |
348 | 335 | ||
@@ -357,37 +344,8 @@ static int pdc_port_start(struct ata_port *ap) | |||
357 | } | 344 | } |
358 | 345 | ||
359 | return 0; | 346 | return 0; |
360 | |||
361 | err_out_kfree: | ||
362 | kfree(pp); | ||
363 | err_out: | ||
364 | ata_port_stop(ap); | ||
365 | return rc; | ||
366 | } | 347 | } |
367 | 348 | ||
368 | |||
369 | static void pdc_port_stop(struct ata_port *ap) | ||
370 | { | ||
371 | struct device *dev = ap->host->dev; | ||
372 | struct pdc_port_priv *pp = ap->private_data; | ||
373 | |||
374 | ap->private_data = NULL; | ||
375 | dma_free_coherent(dev, 128, pp->pkt, pp->pkt_dma); | ||
376 | kfree(pp); | ||
377 | ata_port_stop(ap); | ||
378 | } | ||
379 | |||
380 | |||
381 | static void pdc_host_stop(struct ata_host *host) | ||
382 | { | ||
383 | struct pdc_host_priv *hp = host->private_data; | ||
384 | |||
385 | ata_pci_host_stop(host); | ||
386 | |||
387 | kfree(hp); | ||
388 | } | ||
389 | |||
390 | |||
391 | static void pdc_reset_port(struct ata_port *ap) | 349 | static void pdc_reset_port(struct ata_port *ap) |
392 | { | 350 | { |
393 | void __iomem *mmio = (void __iomem *) ap->ioaddr.cmd_addr + PDC_CTLSTAT; | 351 | void __iomem *mmio = (void __iomem *) ap->ioaddr.cmd_addr + PDC_CTLSTAT; |
@@ -924,56 +882,49 @@ static void pdc_host_init(unsigned int chip_id, struct ata_probe_ent *pe) | |||
924 | static int pdc_ata_init_one (struct pci_dev *pdev, const struct pci_device_id *ent) | 882 | static int pdc_ata_init_one (struct pci_dev *pdev, const struct pci_device_id *ent) |
925 | { | 883 | { |
926 | static int printed_version; | 884 | static int printed_version; |
927 | struct ata_probe_ent *probe_ent = NULL; | 885 | struct ata_probe_ent *probe_ent; |
928 | struct pdc_host_priv *hp; | 886 | struct pdc_host_priv *hp; |
929 | unsigned long base; | 887 | unsigned long base; |
930 | void __iomem *mmio_base; | 888 | void __iomem *mmio_base; |
931 | unsigned int board_idx = (unsigned int) ent->driver_data; | 889 | unsigned int board_idx = (unsigned int) ent->driver_data; |
932 | int pci_dev_busy = 0; | ||
933 | int rc; | 890 | int rc; |
934 | u8 tmp; | 891 | u8 tmp; |
935 | 892 | ||
936 | if (!printed_version++) | 893 | if (!printed_version++) |
937 | dev_printk(KERN_DEBUG, &pdev->dev, "version " DRV_VERSION "\n"); | 894 | dev_printk(KERN_DEBUG, &pdev->dev, "version " DRV_VERSION "\n"); |
938 | 895 | ||
939 | rc = pci_enable_device(pdev); | 896 | rc = pcim_enable_device(pdev); |
940 | if (rc) | 897 | if (rc) |
941 | return rc; | 898 | return rc; |
942 | 899 | ||
943 | rc = pci_request_regions(pdev, DRV_NAME); | 900 | rc = pci_request_regions(pdev, DRV_NAME); |
944 | if (rc) { | 901 | if (rc) { |
945 | pci_dev_busy = 1; | 902 | pcim_pin_device(pdev); |
946 | goto err_out; | 903 | return rc; |
947 | } | 904 | } |
948 | 905 | ||
949 | rc = pci_set_dma_mask(pdev, ATA_DMA_MASK); | 906 | rc = pci_set_dma_mask(pdev, ATA_DMA_MASK); |
950 | if (rc) | 907 | if (rc) |
951 | goto err_out_regions; | 908 | return rc; |
952 | rc = pci_set_consistent_dma_mask(pdev, ATA_DMA_MASK); | 909 | rc = pci_set_consistent_dma_mask(pdev, ATA_DMA_MASK); |
953 | if (rc) | 910 | if (rc) |
954 | goto err_out_regions; | 911 | return rc; |
955 | 912 | ||
956 | probe_ent = kzalloc(sizeof(*probe_ent), GFP_KERNEL); | 913 | probe_ent = devm_kzalloc(&pdev->dev, sizeof(*probe_ent), GFP_KERNEL); |
957 | if (probe_ent == NULL) { | 914 | if (probe_ent == NULL) |
958 | rc = -ENOMEM; | 915 | return -ENOMEM; |
959 | goto err_out_regions; | ||
960 | } | ||
961 | 916 | ||
962 | probe_ent->dev = pci_dev_to_dev(pdev); | 917 | probe_ent->dev = pci_dev_to_dev(pdev); |
963 | INIT_LIST_HEAD(&probe_ent->node); | 918 | INIT_LIST_HEAD(&probe_ent->node); |
964 | 919 | ||
965 | mmio_base = pci_iomap(pdev, 3, 0); | 920 | mmio_base = pcim_iomap(pdev, 3, 0); |
966 | if (mmio_base == NULL) { | 921 | if (mmio_base == NULL) |
967 | rc = -ENOMEM; | 922 | return -ENOMEM; |
968 | goto err_out_free_ent; | ||
969 | } | ||
970 | base = (unsigned long) mmio_base; | 923 | base = (unsigned long) mmio_base; |
971 | 924 | ||
972 | hp = kzalloc(sizeof(*hp), GFP_KERNEL); | 925 | hp = devm_kzalloc(&pdev->dev, sizeof(*hp), GFP_KERNEL); |
973 | if (hp == NULL) { | 926 | if (hp == NULL) |
974 | rc = -ENOMEM; | 927 | return -ENOMEM; |
975 | goto err_out_free_ent; | ||
976 | } | ||
977 | 928 | ||
978 | probe_ent->private_data = hp; | 929 | probe_ent->private_data = hp; |
979 | 930 | ||
@@ -1043,22 +994,11 @@ static int pdc_ata_init_one (struct pci_dev *pdev, const struct pci_device_id *e | |||
1043 | /* initialize adapter */ | 994 | /* initialize adapter */ |
1044 | pdc_host_init(board_idx, probe_ent); | 995 | pdc_host_init(board_idx, probe_ent); |
1045 | 996 | ||
1046 | /* FIXME: Need any other frees than hp? */ | ||
1047 | if (!ata_device_add(probe_ent)) | 997 | if (!ata_device_add(probe_ent)) |
1048 | kfree(hp); | 998 | return -ENODEV; |
1049 | |||
1050 | kfree(probe_ent); | ||
1051 | 999 | ||
1000 | devm_kfree(&pdev->dev, probe_ent); | ||
1052 | return 0; | 1001 | return 0; |
1053 | |||
1054 | err_out_free_ent: | ||
1055 | kfree(probe_ent); | ||
1056 | err_out_regions: | ||
1057 | pci_release_regions(pdev); | ||
1058 | err_out: | ||
1059 | if (!pci_dev_busy) | ||
1060 | pci_disable_device(pdev); | ||
1061 | return rc; | ||
1062 | } | 1002 | } |
1063 | 1003 | ||
1064 | 1004 | ||