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_vsc.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_vsc.c')
-rw-r--r-- | drivers/ata/sata_vsc.c | 88 |
1 files changed, 17 insertions, 71 deletions
diff --git a/drivers/ata/sata_vsc.c b/drivers/ata/sata_vsc.c index 8d1683ebadc6..af77f71bdaa5 100644 --- a/drivers/ata/sata_vsc.c +++ b/drivers/ata/sata_vsc.c | |||
@@ -94,13 +94,6 @@ enum { | |||
94 | VSC_SATA_INT_ERROR_P | VSC_SATA_INT_ERROR_R | \ | 94 | VSC_SATA_INT_ERROR_P | VSC_SATA_INT_ERROR_R | \ |
95 | VSC_SATA_INT_ERROR_E | VSC_SATA_INT_ERROR_M | \ | 95 | VSC_SATA_INT_ERROR_E | VSC_SATA_INT_ERROR_M | \ |
96 | VSC_SATA_INT_PHY_CHANGE), | 96 | VSC_SATA_INT_PHY_CHANGE), |
97 | |||
98 | /* Host private flags (hp_flags) */ | ||
99 | VSC_SATA_HP_FLAG_MSI = (1 << 0), | ||
100 | }; | ||
101 | |||
102 | struct vsc_sata_host_priv { | ||
103 | u32 hp_flags; | ||
104 | }; | 97 | }; |
105 | 98 | ||
106 | #define is_vsc_sata_int_err(port_idx, int_status) \ | 99 | #define is_vsc_sata_int_err(port_idx, int_status) \ |
@@ -124,20 +117,6 @@ static void vsc_sata_scr_write (struct ata_port *ap, unsigned int sc_reg, | |||
124 | } | 117 | } |
125 | 118 | ||
126 | 119 | ||
127 | static void vsc_sata_host_stop(struct ata_host *host) | ||
128 | { | ||
129 | struct vsc_sata_host_priv *hpriv = host->private_data; | ||
130 | struct pci_dev *pdev = to_pci_dev(host->dev); | ||
131 | |||
132 | if (hpriv->hp_flags & VSC_SATA_HP_FLAG_MSI) | ||
133 | pci_disable_msi(pdev); | ||
134 | else | ||
135 | pci_intx(pdev, 0); | ||
136 | kfree (hpriv); | ||
137 | ata_pci_host_stop(host); | ||
138 | } | ||
139 | |||
140 | |||
141 | static void vsc_intr_mask_update(struct ata_port *ap, u8 ctl) | 120 | static void vsc_intr_mask_update(struct ata_port *ap, u8 ctl) |
142 | { | 121 | { |
143 | void __iomem *mask_addr; | 122 | void __iomem *mask_addr; |
@@ -331,8 +310,6 @@ static const struct ata_port_operations vsc_sata_ops = { | |||
331 | .scr_read = vsc_sata_scr_read, | 310 | .scr_read = vsc_sata_scr_read, |
332 | .scr_write = vsc_sata_scr_write, | 311 | .scr_write = vsc_sata_scr_write, |
333 | .port_start = ata_port_start, | 312 | .port_start = ata_port_start, |
334 | .port_stop = ata_port_stop, | ||
335 | .host_stop = vsc_sata_host_stop, | ||
336 | }; | 313 | }; |
337 | 314 | ||
338 | static void __devinit vsc_sata_setup_port(struct ata_ioports *port, unsigned long base) | 315 | static void __devinit vsc_sata_setup_port(struct ata_ioports *port, unsigned long base) |
@@ -361,31 +338,27 @@ static int __devinit vsc_sata_init_one (struct pci_dev *pdev, const struct pci_d | |||
361 | { | 338 | { |
362 | static int printed_version; | 339 | static int printed_version; |
363 | struct ata_probe_ent *probe_ent = NULL; | 340 | struct ata_probe_ent *probe_ent = NULL; |
364 | struct vsc_sata_host_priv *hpriv; | ||
365 | unsigned long base; | 341 | unsigned long base; |
366 | int pci_dev_busy = 0; | ||
367 | void __iomem *mmio_base; | 342 | void __iomem *mmio_base; |
368 | int rc; | 343 | int rc; |
369 | 344 | ||
370 | if (!printed_version++) | 345 | if (!printed_version++) |
371 | dev_printk(KERN_DEBUG, &pdev->dev, "version " DRV_VERSION "\n"); | 346 | dev_printk(KERN_DEBUG, &pdev->dev, "version " DRV_VERSION "\n"); |
372 | 347 | ||
373 | rc = pci_enable_device(pdev); | 348 | rc = pcim_enable_device(pdev); |
374 | if (rc) | 349 | if (rc) |
375 | return rc; | 350 | return rc; |
376 | 351 | ||
377 | /* | 352 | /* |
378 | * Check if we have needed resource mapped. | 353 | * Check if we have needed resource mapped. |
379 | */ | 354 | */ |
380 | if (pci_resource_len(pdev, 0) == 0) { | 355 | if (pci_resource_len(pdev, 0) == 0) |
381 | rc = -ENODEV; | 356 | return -ENODEV; |
382 | goto err_out; | ||
383 | } | ||
384 | 357 | ||
385 | rc = pci_request_regions(pdev, DRV_NAME); | 358 | rc = pci_request_regions(pdev, DRV_NAME); |
386 | if (rc) { | 359 | if (rc) { |
387 | pci_dev_busy = 1; | 360 | pcim_pin_device(pdev); |
388 | goto err_out; | 361 | return rc; |
389 | } | 362 | } |
390 | 363 | ||
391 | /* | 364 | /* |
@@ -393,44 +366,29 @@ static int __devinit vsc_sata_init_one (struct pci_dev *pdev, const struct pci_d | |||
393 | */ | 366 | */ |
394 | rc = pci_set_dma_mask(pdev, DMA_32BIT_MASK); | 367 | rc = pci_set_dma_mask(pdev, DMA_32BIT_MASK); |
395 | if (rc) | 368 | if (rc) |
396 | goto err_out_regions; | 369 | return rc; |
397 | rc = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK); | 370 | rc = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK); |
398 | if (rc) | 371 | if (rc) |
399 | goto err_out_regions; | 372 | return rc; |
400 | |||
401 | probe_ent = kmalloc(sizeof(*probe_ent), GFP_KERNEL); | ||
402 | if (probe_ent == NULL) { | ||
403 | rc = -ENOMEM; | ||
404 | goto err_out_regions; | ||
405 | } | ||
406 | 373 | ||
407 | memset(probe_ent, 0, sizeof(*probe_ent)); | 374 | probe_ent = devm_kzalloc(&pdev->dev, sizeof(*probe_ent), GFP_KERNEL); |
375 | if (probe_ent == NULL) | ||
376 | return -ENOMEM; | ||
408 | probe_ent->dev = pci_dev_to_dev(pdev); | 377 | probe_ent->dev = pci_dev_to_dev(pdev); |
409 | INIT_LIST_HEAD(&probe_ent->node); | 378 | INIT_LIST_HEAD(&probe_ent->node); |
410 | 379 | ||
411 | mmio_base = pci_iomap(pdev, 0, 0); | 380 | mmio_base = pcim_iomap(pdev, 0, 0); |
412 | if (mmio_base == NULL) { | 381 | if (mmio_base == NULL) |
413 | rc = -ENOMEM; | 382 | return -ENOMEM; |
414 | goto err_out_free_ent; | ||
415 | } | ||
416 | base = (unsigned long) mmio_base; | 383 | base = (unsigned long) mmio_base; |
417 | 384 | ||
418 | hpriv = kmalloc(sizeof(*hpriv), GFP_KERNEL); | ||
419 | if (!hpriv) { | ||
420 | rc = -ENOMEM; | ||
421 | goto err_out_iounmap; | ||
422 | } | ||
423 | memset(hpriv, 0, sizeof(*hpriv)); | ||
424 | |||
425 | /* | 385 | /* |
426 | * Due to a bug in the chip, the default cache line size can't be used | 386 | * Due to a bug in the chip, the default cache line size can't be used |
427 | */ | 387 | */ |
428 | pci_write_config_byte(pdev, PCI_CACHE_LINE_SIZE, 0x80); | 388 | pci_write_config_byte(pdev, PCI_CACHE_LINE_SIZE, 0x80); |
429 | 389 | ||
430 | if (pci_enable_msi(pdev) == 0) { | 390 | if (pci_enable_msi(pdev) == 0) |
431 | hpriv->hp_flags |= VSC_SATA_HP_FLAG_MSI; | ||
432 | pci_intx(pdev, 0); | 391 | pci_intx(pdev, 0); |
433 | } | ||
434 | else | 392 | else |
435 | probe_ent->irq_flags = IRQF_SHARED; | 393 | probe_ent->irq_flags = IRQF_SHARED; |
436 | 394 | ||
@@ -441,7 +399,6 @@ static int __devinit vsc_sata_init_one (struct pci_dev *pdev, const struct pci_d | |||
441 | probe_ent->n_ports = 4; | 399 | probe_ent->n_ports = 4; |
442 | probe_ent->irq = pdev->irq; | 400 | probe_ent->irq = pdev->irq; |
443 | probe_ent->mmio_base = mmio_base; | 401 | probe_ent->mmio_base = mmio_base; |
444 | probe_ent->private_data = hpriv; | ||
445 | 402 | ||
446 | /* We don't care much about the PIO/UDMA masks, but the core won't like us | 403 | /* We don't care much about the PIO/UDMA masks, but the core won't like us |
447 | * if we don't fill these | 404 | * if we don't fill these |
@@ -466,22 +423,11 @@ static int __devinit vsc_sata_init_one (struct pci_dev *pdev, const struct pci_d | |||
466 | */ | 423 | */ |
467 | pci_write_config_dword(pdev, 0x98, 0); | 424 | pci_write_config_dword(pdev, 0x98, 0); |
468 | 425 | ||
469 | /* FIXME: check ata_device_add return value */ | 426 | if (!ata_device_add(probe_ent)) |
470 | ata_device_add(probe_ent); | 427 | return -ENODEV; |
471 | 428 | ||
472 | kfree(probe_ent); | 429 | devm_kfree(&pdev->dev, probe_ent); |
473 | return 0; | 430 | return 0; |
474 | |||
475 | err_out_iounmap: | ||
476 | pci_iounmap(pdev, mmio_base); | ||
477 | err_out_free_ent: | ||
478 | kfree(probe_ent); | ||
479 | err_out_regions: | ||
480 | pci_release_regions(pdev); | ||
481 | err_out: | ||
482 | if (!pci_dev_busy) | ||
483 | pci_disable_device(pdev); | ||
484 | return rc; | ||
485 | } | 431 | } |
486 | 432 | ||
487 | static const struct pci_device_id vsc_sata_pci_tbl[] = { | 433 | static const struct pci_device_id vsc_sata_pci_tbl[] = { |