Skip to contentSkip to conversation

ahci/libata: clean up platform device removal

PATCH In review Brian Norris 4 participants 27 messages Nov 2, 2012 – Dec 3, 2012

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover ahci/libata: clean up platform device removal

Hi,

This is a revision and extension of an RFC series I sent out a few times. Here are links to the previous patches, discussion, and questions.

    http://article.gmane.org/gmane.linux.ide/53159
    http://article.gmane.org/gmane.linux.ide/53143
    http://article.gmane.org/gmane.linux.ide/52951

The major change from RFC v2 is that I rebased to the current libata/NEXT, then added new patches (PATCH 04/14 through PATCH 14/14).

This series does the following:

(1) Allows ahci_platform to unbind a device from the driver. This is useful for allowing total power-off of the device, for instance.
(2) Adds ahci_platform ata_port_operations.host_stop() hook, so that platform-device exit() can power down the device at the appropriate point in the removal sequence.
(3) Adds a common ata_platform_remove_one() function so that we don't re-implement a simple host detach across many platform drivers
(4) Switches many platform drivers to the new .remove function from (3)

Thanks to Tejun for the comments, which suggested that ahci_platform (not libata-core) was broken.

Note that patch 13 provides untested new functionality to the pata_octeon_cf driver. It was missing a .remove function, so I took the liberty to add the common one. Feel free to exclude this patch.

Thanks,
Brian

P.S. A related but distinct issue: someting is still broken in the ata_host_detach() function, for shutting down the host, spinning down disks, etc. When I rmmod the driver or unbind the device, I get the following failures, and the HDD doesn't spin down:

   # echo strict-ahci.0 > /sys/bus/platform/drivers/ahci/unbind 
   ata2.00: disabled
   sd 1:0:0:0: [sda] Synchronizing SCSI cache
   sd 1:0:0:0: [sda]  Result: hostbyte=0x04 driverbyte=0x00
   sd 1:0:0:0: [sda] Stopping disk
   sd 1:0:0:0: [sda] START_STOP FAILED
   sd 1:0:0:0: [sda]  Result: hostbyte=0x04 driverbyte=0x00

This is reproducible on my laptop (v3.2 kernel, AHCI PCI driver) and on my SoC AHCI core (v3.3 kernel, AHCI platform driver). I haven't been able to try a more recent kernel, but nothing I see in the changelogs suggests that there would be any difference.

I have narrowed down the error messages to the following info, although I am not yet familiar enough with these codepaths to make a recommendation:

ata_host_detach
|_ ata_port_detach

  |_ ata_port_schedule_eh => SCSI error handler calls ata_dev_disable()
  | ...
  |_scsi_remove_host()
    | ...
    |__..._ sd_start_stop_device() => failure!

Brian Norris (14):
ahci_platform: enable hotplug unbinding
ahci_platform: convert to module_platform_driver
ahci_platform: perform platform exit in host_stop() hook
libata: implement ata_platform_remove_one()
ahci_platform: utilize common ata_platform_remove_one()
pata_ixp4xx_cf: utilize common ata_platform_remove_one()
pata_mpc52xx: utilize common ata_platform_remove_one()
pata_of_platform: utilize common ata_platform_remove_one()
pata_platform: utilize common ata_platform_remove_one()
ata_platform: remove unused remove function
pata_palmld: utilize common ata_platform_remove_one()
sata_highbank: utilize common ata_platform_remove_one()
pata_octeon_cf: perform host detach, removal on exit
libata: use pci_get_drvdata() helper

 drivers/ata/ahci_platform.c    | 44 +++++++++++++++++++-----------------------
 drivers/ata/libata-core.c      | 30 ++++++++++++++++++++++++----
 drivers/ata/pata_ixp4xx_cf.c   | 11 +----------
 drivers/ata/pata_mpc52xx.c     | 17 +++-------------
 drivers/ata/pata_octeon_cf.c   |  1 +
 drivers/ata/pata_of_platform.c |  7 +------
 drivers/ata/pata_palmld.c      |  4 +---
 drivers/ata/pata_platform.c    | 24 +----------------------
 drivers/ata/sata_highbank.c    | 12 +-----------
 include/linux/ata_platform.h   |  2 --
 include/linux/libata.h         |  4 ++++
 11 files changed, 59 insertions(+), 97 deletions(-)
Signature · 1 line
1.7.11.3
#1 lore raw

PATCH 1/14 ahci_platform: enable hotplug unbinding

platform_driver_probe() should be used for registering this driver only if we want to

"...remove its run-once probe() infrastructure from memory after the driver has bound to the device."

However, we may want to leave the probe infrastructure in place in order to support binding/unbinding a device dynamically. This is useful, for instance, as a power management mechanism, where a device can be totally powered down when unbound (whereas with runtime power management, powering down the SATA core would incur unacceptable loss of functionality).

Thus, convert this driver to use platform_driver_register().

---
 drivers/ata/ahci_platform.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/ata/ahci_platform.c +3 -2
index b1ae480..9bc8a78 100644
@@ -75,7 +75,7 @@ static struct scsi_host_template ahci_platform_sht = {
 	AHCI_SHT("ahci_platform"),
 };
 
-static int __init ahci_probe(struct platform_device *pdev)
+static int __devinit ahci_probe(struct platform_device *pdev)
 {
 	struct device *dev = &pdev->dev;
 	struct ahci_platform_data *pdata = dev_get_platdata(dev);
@@ -326,6 +326,7 @@ static const struct of_device_id ahci_of_match[] = {
 MODULE_DEVICE_TABLE(of, ahci_of_match);
 
 static struct platform_driver ahci_driver = {
+	.probe = ahci_probe,
 	.remove = __devexit_p(ahci_remove),
 	.driver = {
 		.name = "ahci",
@@ -338,7 +339,7 @@ static struct platform_driver ahci_driver = {
 
 static int __init ahci_init(void)
 {
-	return platform_driver_probe(&ahci_driver, ahci_probe);
+	return platform_driver_register(&ahci_driver);
 }
 module_init(ahci_init);
 
Signature · 1 line
1.7.11.3
#2 lore raw

PATCH 2/14 ahci_platform: convert to module_platform_driver

In reply to Brian Norris

The ahci_platform driver can now use the module_platform_driver() macro.

---
 drivers/ata/ahci_platform.c | 13 +------------
 1 file changed, 1 insertion(+), 12 deletions(-)
drivers/ata/ahci_platform.c +1 -12
index 9bc8a78..8ae1c6f 100644
@@ -336,18 +336,7 @@ static struct platform_driver ahci_driver = {
 	},
 	.id_table	= ahci_devtype,
 };
-
-static int __init ahci_init(void)
-{
-	return platform_driver_register(&ahci_driver);
-}
-module_init(ahci_init);
-
-static void __exit ahci_exit(void)
-{
-	platform_driver_unregister(&ahci_driver);
-}
-module_exit(ahci_exit);
+module_platform_driver(ahci_driver);
 
 MODULE_DESCRIPTION("AHCI SATA platform driver");
 MODULE_AUTHOR("Anton Vorontsov <[email protected]>");
Signature · 1 line
1.7.11.3
#3 lore raw

PATCH 3/14 ahci_platform: perform platform exit in host_stop() hook

In reply to Brian Norris

AHCI platform devices may provide an exit() routine, via ahci_platform_data, that powers off the SATA core. Such a routine should be executed from the ata_port_operations host_stop() hook. That way, the ATA subsystem can perform any last-minute hardware cleanup (via devres, for example), then trigger the power-off at the appropriate time.

This patch fixes bus errors triggered during module removal or device unbinding, seen on an SoC SATA core.

---
 drivers/ata/ahci_platform.c | 30 +++++++++++++++++++++++-------
 1 file changed, 23 insertions(+), 7 deletions(-)
drivers/ata/ahci_platform.c +23 -7
index 8ae1c6f..05806e0 100644
@@ -25,6 +25,8 @@
 #include <linux/ahci_platform.h>
 #include "ahci.h"
 
+static void ahci_host_stop(struct ata_host *host);
+
 enum ahci_type {
 	AHCI,		/* standard platform ahci */
 	IMX53_AHCI,	/* ahci on i.mx53 */
@@ -47,6 +49,15 @@ static struct platform_device_id ahci_devtype[] = {
 };
 MODULE_DEVICE_TABLE(platform, ahci_devtype);
 
+struct ata_port_operations ahci_platform_ops = {
+	.inherits	= &ahci_ops,
+	.host_stop	= ahci_host_stop,
+};
+
+struct ata_port_operations ahci_platform_retry_srst_ops = {
+	.inherits	= &ahci_pmp_retry_srst_ops,
+	.host_stop	= ahci_host_stop,
+};
 
 static const struct ata_port_info ahci_port_info[] = {
 	/* by features */
@@ -54,20 +65,20 @@ static const struct ata_port_info ahci_port_info[] = {
 		.flags		= AHCI_FLAG_COMMON,
 		.pio_mask	= ATA_PIO4,
 		.udma_mask	= ATA_UDMA6,
-		.port_ops	= &ahci_ops,
+		.port_ops	= &ahci_platform_ops,
 	},
 	[IMX53_AHCI] = {
 		.flags		= AHCI_FLAG_COMMON,
 		.pio_mask	= ATA_PIO4,
 		.udma_mask	= ATA_UDMA6,
-		.port_ops	= &ahci_pmp_retry_srst_ops,
+		.port_ops	= &ahci_platform_retry_srst_ops,
 	},
 	[STRICT_AHCI] = {
 		AHCI_HFLAGS	(AHCI_HFLAG_DELAY_ENGINE),
 		.flags		= AHCI_FLAG_COMMON,
 		.pio_mask	= ATA_PIO4,
 		.udma_mask	= ATA_UDMA6,
-		.port_ops	= &ahci_ops,
+		.port_ops	= &ahci_platform_ops,
 	},
 };
 
@@ -221,12 +232,19 @@ free_clk:
 static int __devexit ahci_remove(struct platform_device *pdev)
 {
 	struct device *dev = &pdev->dev;
-	struct ahci_platform_data *pdata = dev_get_platdata(dev);
 	struct ata_host *host = dev_get_drvdata(dev);
-	struct ahci_host_priv *hpriv = host->private_data;
 
 	ata_host_detach(host);
 
+	return 0;
+}
+
+static void ahci_host_stop(struct ata_host *host)
+{
+	struct device *dev = host->dev;
+	struct ahci_platform_data *pdata = dev_get_platdata(dev);
+	struct ahci_host_priv *hpriv = host->private_data;
+
 	if (pdata && pdata->exit)
 		pdata->exit(dev);
 
@@ -234,8 +252,6 @@ static int __devexit ahci_remove(struct platform_device *pdev)
 		clk_disable_unprepare(hpriv->clk);
 		clk_put(hpriv->clk);
 	}
-
-	return 0;
 }
 
 #ifdef CONFIG_PM
Signature · 1 line
1.7.11.3
#4 lore raw

PATCH 4/14 libata: implement ata_platform_remove_one()

In reply to Brian Norris

This relatively simple boiler-plate code is repeated in several platform drivers. We should implement a common version in libata.

---
 drivers/ata/libata-core.c | 23 +++++++++++++++++++++++
 include/linux/libata.h    |  4 ++++
 2 files changed, 27 insertions(+)
drivers/ata/libata-core.c +23 -0
index 611050d..820e47f 100644
@@ -67,6 +67,7 @@
 #include <linux/cdrom.h>
 #include <linux/ratelimit.h>
 #include <linux/pm_runtime.h>
+#include <linux/platform_device.h>
 
 #include "libata.h"
 #include "libata-transport.h"
@@ -6350,6 +6351,26 @@ int ata_pci_device_resume(struct pci_dev *pdev)
 
 #endif /* CONFIG_PCI */
 
+/**
+ *      ata_platform_remove_one- Platform layer callback for device removal
+ *      @pdev: Platform device that was removed
+ *
+ *      Platform layer indicates to libata via this hook that hot-unplug or
+ *      module unload event has occurred.  Detach all ports.  Resource
+ *      release is handled via devres.
+ *
+ *      LOCKING:
+ *      Inherited from platform layer (may sleep).
+ */
+int ata_platform_remove_one(struct platform_device *pdev)
+{
+        struct ata_host *host = platform_get_drvdata(pdev);
+
+        ata_host_detach(host);
+
+	return 0;
+}
+
 static int __init ata_parse_force_one(char **cur,
 				      struct ata_force_ent *force_ent,
 				      const char **reason)
@@ -6844,6 +6865,8 @@ EXPORT_SYMBOL_GPL(ata_pci_device_resume);
 #endif /* CONFIG_PM */
 #endif /* CONFIG_PCI */
 
+EXPORT_SYMBOL_GPL(ata_platform_remove_one);
+
 EXPORT_SYMBOL_GPL(__ata_ehi_push_desc);
 EXPORT_SYMBOL_GPL(ata_ehi_push_desc);
 EXPORT_SYMBOL_GPL(ata_ehi_clear_desc);
include/linux/libata.h +4 -0
index 464e67c..cedcd0f 100644
@@ -1103,6 +1103,10 @@ extern int ata_pci_device_resume(struct pci_dev *pdev);
 #endif /* CONFIG_PM */
 #endif /* CONFIG_PCI */
 
+struct platform_device;
+
+extern int ata_platform_remove_one(struct platform_device *pdev);
+
 /*
  * ACPI - drivers/ata/libata-acpi.c
  */
Signature · 1 line
1.7.11.3
#11 lore raw

PATCH 5/14 ahci_platform: utilize common ata_platform_remove_one()

In reply to Brian Norris
---
 drivers/ata/ahci_platform.c | 12 +-----------
 1 file changed, 1 insertion(+), 11 deletions(-)
drivers/ata/ahci_platform.c +1 -11
index 05806e0..13e4456 100644
@@ -229,16 +229,6 @@ free_clk:
 	return rc;
 }
 
-static int __devexit ahci_remove(struct platform_device *pdev)
-{
-	struct device *dev = &pdev->dev;
-	struct ata_host *host = dev_get_drvdata(dev);
-
-	ata_host_detach(host);
-
-	return 0;
-}
-
 static void ahci_host_stop(struct ata_host *host)
 {
 	struct device *dev = host->dev;
@@ -343,7 +333,7 @@ MODULE_DEVICE_TABLE(of, ahci_of_match);
 
 static struct platform_driver ahci_driver = {
 	.probe = ahci_probe,
-	.remove = __devexit_p(ahci_remove),
+	.remove = ata_platform_remove_one,
 	.driver = {
 		.name = "ahci",
 		.owner = THIS_MODULE,
Signature · 1 line
1.7.11.3
#12 lore raw

PATCH 6/14 pata_ixp4xx_cf: utilize common ata_platform_remove_one()

In reply to Brian Norris
---
 drivers/ata/pata_ixp4xx_cf.c | 11 +----------
 1 file changed, 1 insertion(+), 10 deletions(-)
drivers/ata/pata_ixp4xx_cf.c +1 -10
index badb178..0566e67 100644
@@ -187,22 +187,13 @@ static __devinit int ixp4xx_pata_probe(struct platform_device *pdev)
 	return ata_host_activate(host, irq, ata_sff_interrupt, 0, &ixp4xx_sht);
 }
 
-static __devexit int ixp4xx_pata_remove(struct platform_device *dev)
-{
-	struct ata_host *host = platform_get_drvdata(dev);
-
-	ata_host_detach(host);
-
-	return 0;
-}
-
 static struct platform_driver ixp4xx_pata_platform_driver = {
 	.driver	 = {
 		.name   = DRV_NAME,
 		.owner  = THIS_MODULE,
 	},
 	.probe		= ixp4xx_pata_probe,
-	.remove		= __devexit_p(ixp4xx_pata_remove),
+	.remove		= ata_platform_remove_one,
 };
 
 module_platform_driver(ixp4xx_pata_platform_driver);
Signature · 1 line
1.7.11.3
#13 lore raw

PATCH 7/14 pata_mpc52xx: utilize common ata_platform_remove_one()

In reply to Brian Norris
---
 drivers/ata/pata_mpc52xx.c | 17 +++--------------
 1 file changed, 3 insertions(+), 14 deletions(-)
drivers/ata/pata_mpc52xx.c +3 -14
index d2c102f..ec67f54 100644
@@ -663,18 +663,6 @@ mpc52xx_ata_init_one(struct device *dev, struct mpc52xx_ata_priv *priv,
 				 &mpc52xx_ata_sht);
 }
 
-static struct mpc52xx_ata_priv *
-mpc52xx_ata_remove_one(struct device *dev)
-{
-	struct ata_host *host = dev_get_drvdata(dev);
-	struct mpc52xx_ata_priv *priv = host->private_data;
-
-	ata_host_detach(host);
-
-	return priv;
-}
-
-
 /* ======================================================================== */
 /* OF Platform driver                                                       */
 /* ======================================================================== */
@@ -815,11 +803,12 @@ mpc52xx_ata_probe(struct platform_device *op)
 static int
 mpc52xx_ata_remove(struct platform_device *op)
 {
-	struct mpc52xx_ata_priv *priv;
+	struct ata_host *host = platform_get_drvdata(op);
+	struct mpc52xx_ata_priv *priv = host->private_data;
 	int task_irq;
 
 	/* Deregister the ATA interface */
-	priv = mpc52xx_ata_remove_one(&op->dev);
+	ata_platform_remove_one(op);
 
 	/* Clean up DMA */
 	task_irq = bcom_get_task_irq(priv->dmatsk);
Signature · 1 line
1.7.11.3
#14 lore raw

PATCH 8/14 pata_of_platform: utilize common ata_platform_remove_one()

In reply to Brian Norris
---
 drivers/ata/pata_of_platform.c | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)
drivers/ata/pata_of_platform.c +1 -6
index 1654dc2..cd0f9da 100644
@@ -76,11 +76,6 @@ static int __devinit pata_of_platform_probe(struct platform_device *ofdev)
 				     reg_shift, pio_mask);
 }
 
-static int __devexit pata_of_platform_remove(struct platform_device *ofdev)
-{
-	return __pata_platform_remove(&ofdev->dev);
-}
-
 static struct of_device_id pata_of_platform_match[] = {
 	{ .compatible = "ata-generic", },
 	{ .compatible = "electra-ide", },
@@ -95,7 +90,7 @@ static struct platform_driver pata_of_platform_driver = {
 		.of_match_table = pata_of_platform_match,
 	},
 	.probe		= pata_of_platform_probe,
-	.remove		= __devexit_p(pata_of_platform_remove),
+	.remove		= ata_platform_remove_one,
 };
 
 module_platform_driver(pata_of_platform_driver);
Signature · 1 line
1.7.11.3
#15 lore raw

PATCH 9/14 pata_platform: utilize common ata_platform_remove_one()

In reply to Brian Norris
---
 drivers/ata/pata_platform.c | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)
drivers/ata/pata_platform.c +1 -6
index f1848ae..449aa29 100644
@@ -242,14 +242,9 @@ static int __devinit pata_platform_probe(struct platform_device *pdev)
 				     pio_mask);
 }
 
-static int __devexit pata_platform_remove(struct platform_device *pdev)
-{
-	return __pata_platform_remove(&pdev->dev);
-}
-
 static struct platform_driver pata_platform_driver = {
 	.probe		= pata_platform_probe,
-	.remove		= __devexit_p(pata_platform_remove),
+	.remove		= ata_platform_remove_one,
 	.driver = {
 		.name		= DRV_NAME,
 		.owner		= THIS_MODULE,
Signature · 1 line
1.7.11.3
#16 lore raw

PATCH 10/14 ata_platform: remove unused remove function

In reply to Brian Norris

All users of __pata_platform_remove() have been converted to utilize the common ata_platform_remove_one().

---
 drivers/ata/pata_platform.c  | 17 -----------------
 include/linux/ata_platform.h |  2 --
 2 files changed, 19 deletions(-)
drivers/ata/pata_platform.c +0 -17
index 449aa29..f4372d0 100644
@@ -178,23 +178,6 @@ int __devinit __pata_platform_probe(struct device *dev,
 }
 EXPORT_SYMBOL_GPL(__pata_platform_probe);
 
-/**
- *	__pata_platform_remove		-	unplug a platform interface
- *	@dev: device
- *
- *	A platform bus ATA device has been unplugged. Perform the needed
- *	cleanup. Also called on module unload for any active devices.
- */
-int __pata_platform_remove(struct device *dev)
-{
-	struct ata_host *host = dev_get_drvdata(dev);
-
-	ata_host_detach(host);
-
-	return 0;
-}
-EXPORT_SYMBOL_GPL(__pata_platform_remove);
-
 static int __devinit pata_platform_probe(struct platform_device *pdev)
 {
 	struct resource *io_res;
include/linux/ata_platform.h +0 -2
index b856a2a..fe99896 100644
@@ -22,8 +22,6 @@ extern int __devinit __pata_platform_probe(struct device *dev,
 					   unsigned int ioport_shift,
 					   int __pio_mask);
 
-extern int __devexit __pata_platform_remove(struct device *dev);
-
 /*
  * Marvell SATA private data
  */
Signature · 1 line
1.7.11.3
#17 lore raw

PATCH 11/14 pata_palmld: utilize common ata_platform_remove_one()

In reply to Brian Norris
---
 drivers/ata/pata_palmld.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/ata/pata_palmld.c +1 -3
index 5ff31b6..f9f79fc 100644
@@ -111,9 +111,7 @@ err1:
 
 static __devexit int palmld_pata_remove(struct platform_device *dev)
 {
-	struct ata_host *host = platform_get_drvdata(dev);
-
-	ata_host_detach(host);
+	ata_platform_remove_one(dev);
 
 	/* power down the HDD */
 	gpio_set_value(GPIO_NR_PALMLD_IDE_PWEN, 0);
Signature · 1 line
1.7.11.3
#18 lore raw

PATCH 12/14 sata_highbank: utilize common ata_platform_remove_one()

In reply to Brian Norris
---
 drivers/ata/sata_highbank.c | 12 +-----------
 1 file changed, 1 insertion(+), 11 deletions(-)
drivers/ata/sata_highbank.c +1 -11
index 0d7c4c2..7601dd8 100644
@@ -368,16 +368,6 @@ err0:
 	return rc;
 }
 
-static int __devexit ahci_highbank_remove(struct platform_device *pdev)
-{
-	struct device *dev = &pdev->dev;
-	struct ata_host *host = dev_get_drvdata(dev);
-
-	ata_host_detach(host);
-
-	return 0;
-}
-
 #ifdef CONFIG_PM
 static int ahci_highbank_suspend(struct device *dev)
 {
@@ -432,7 +422,7 @@ SIMPLE_DEV_PM_OPS(ahci_highbank_pm_ops,
 		  ahci_highbank_suspend, ahci_highbank_resume);
 
 static struct platform_driver ahci_highbank_driver = {
-        .remove = __devexit_p(ahci_highbank_remove),
+        .remove = ata_platform_remove_one,
         .driver = {
                 .name = "highbank-ahci",
                 .owner = THIS_MODULE,
Signature · 1 line
1.7.11.3
#22 lore raw

PATCH 13/14 pata_octeon_cf: perform host detach, removal on exit

In reply to Brian Norris

This driver does not detach and remove its ata_host properly on device removal. Add the common .remove helper.

Note: I do not know this driver well enough to ensure this is the right thing to do. Merge this patch with caution.

---
 drivers/ata/pata_octeon_cf.c | 1 +
 1 file changed, 1 insertion(+)
drivers/ata/pata_octeon_cf.c +1 -0
index 1d61d5d..d8df93b 100644
@@ -921,6 +921,7 @@ free_cf_port:
 
 static struct platform_driver octeon_cf_driver = {
 	.probe		= octeon_cf_probe,
+	.remove		= ata_platform_remove_one,
 	.driver		= {
 		.name	= DRV_NAME,
 		.owner	= THIS_MODULE,
Signature · 1 line
1.7.11.3
#23 lore raw

PATCH 14/14 libata: use pci_get_drvdata() helper

In reply to Brian Norris
---
 drivers/ata/libata-core.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
drivers/ata/libata-core.c +3 -4
index 820e47f..a0c6cac 100644
@@ -6255,8 +6255,7 @@ void ata_host_detach(struct ata_host *host)
  */
 void ata_pci_remove_one(struct pci_dev *pdev)
 {
-	struct device *dev = &pdev->dev;
-	struct ata_host *host = dev_get_drvdata(dev);
+	struct ata_host *host = pci_get_drvdata(pdev);
 
 	ata_host_detach(host);
 }
@@ -6325,7 +6324,7 @@ int ata_pci_device_do_resume(struct pci_dev *pdev)
 
 int ata_pci_device_suspend(struct pci_dev *pdev, pm_message_t mesg)
 {
-	struct ata_host *host = dev_get_drvdata(&pdev->dev);
+	struct ata_host *host = pci_get_drvdata(pdev);
 	int rc = 0;
 
 	rc = ata_host_suspend(host, mesg);
@@ -6339,7 +6338,7 @@ int ata_pci_device_suspend(struct pci_dev *pdev, pm_message_t mesg)
 
 int ata_pci_device_resume(struct pci_dev *pdev)
 {
-	struct ata_host *host = dev_get_drvdata(&pdev->dev);
+	struct ata_host *host = pci_get_drvdata(pdev);
 	int rc;
 
 	rc = ata_pci_device_do_resume(pdev);
Signature · 1 line
1.7.11.3
#5 lore raw

Re: [PATCH 04/14] libata: implement ata_platform_remove_one()

In reply to Brian Norris

Hello.

Quoted 13 lines · Brian Norris

This relatively simple boiler-plate code is repeated in several platform drivers. We should implement a common version in libata.

---
  drivers/ata/libata-core.c | 23 +++++++++++++++++++++++
  include/linux/libata.h    |  4 ++++
  2 files changed, 27 insertions(+)
drivers/ata/libata-core.c +0 -0
index 611050d..820e47f 100644

[...]

Quoted 10 lines
drivers/ata/libata-core.c +6 -0
@@ -6350,6 +6351,26 @@ int ata_pci_device_resume(struct pci_dev *pdev)
 
  #endif /* CONFIG_PCI */
 
+/**
+ *      ata_platform_remove_one- Platform layer callback for device removal
+ *      @pdev: Platform device that was removed
+ *
+ *      Platform layer indicates to libata via this hook that hot-unplug or
+ *      module unload event has occurred.  Detach all ports.  Resource

drivers/ata/libata-core.c int ata_pci_device_resume(struct pci_dev *pdev) · line 6369

Quoted 10 lines
drivers/ata/libata-core.c +10 -0
+ *      release is handled via devres.
+ *
+ *      LOCKING:
+ *      Inherited from platform layer (may sleep).
+ */
+int ata_platform_remove_one(struct platform_device *pdev)
+{
+        struct ata_host *host = platform_get_drvdata(pdev);
+
+        ata_host_detach(host);

Indent with tabs, not spaces, as below.

drivers/ata/libata-core.c int ata_pci_device_resume(struct pci_dev *pdev) · line 6376

Quoted 7 lines
drivers/ata/libata-core.c +4 -0
+
+	return 0;
+}
+
  static int __init ata_parse_force_one(char **cur,
  				      struct ata_force_ent *force_ent,
  				      const char **reason)

MBR, Sergei

Acked-by on the v1 series
#24 lore raw
In reply to Brian Norris

Hello,

Quoted 8 lines · Brian Norris

(1) Allows ahci_platform to unbind a device from the driver. This is useful for allowing total power-off of the device, for instance.
(2) Adds ahci_platform ata_port_operations.host_stop() hook, so that platform-device exit() can power down the device at the appropriate point in the removal sequence.
(3) Adds a common ata_platform_remove_one() function so that we don't re-implement a simple host detach across many platform drivers
(4) Switches many platform drivers to the new .remove function from (3)

I personally would have converted all drivers in one patch but I think either way is fine. Other than the indentation thing, for all patches in this series.

Quoted 4 lines

P.S. A related but distinct issue: someting is still broken in the ata_host_detach() function, for shutting down the host, spinning down disks, etc. When I rmmod the driver or unbind the device, I get the following failures, and the HDD doesn't spin down:

That's because detaching the driver is handled basically as controller hot unplug. By the time SCSI is noticing the SCSI devices are going away, the corresponding ATA devices are already away. It's kinda natural to implement that way. Is this an actual problem?

Thanks.

Signature · 1 line
tejun
#25 lore raw
Quoted 10 lines · Tejun Heo
Quoted 8 lines · Brian Norris

(1) Allows ahci_platform to unbind a device from the driver. This is useful for allowing total power-off of the device, for instance.
(2) Adds ahci_platform ata_port_operations.host_stop() hook, so that platform-device exit() can power down the device at the appropriate point in the removal sequence.
(3) Adds a common ata_platform_remove_one() function so that we don't re-implement a simple host detach across many platform drivers
(4) Switches many platform drivers to the new .remove function from (3)

Quoted 5 lines

I personally would have converted all drivers in one patch but I think either way is fine. Other than the indentation thing, for all patches in this series.

Thanks. I'll reply to the indentation patch with a v2.

Quoted 9 lines
Quoted 4 lines

P.S. A related but distinct issue: someting is still broken in the ata_host_detach() function, for shutting down the host, spinning down disks, etc. When I rmmod the driver or unbind the device, I get the following failures, and the HDD doesn't spin down:

That's because detaching the driver is handled basically as controller hot unplug. By the time SCSI is noticing the SCSI devices are going away, the corresponding ATA devices are already away. It's kinda natural to implement that way. Is this an actual problem?

Yes. The HDD doesn't spin down. I'm removing the device because I want some power savings, so I would expect to spin down the disk.

Brian

#26 lore raw

Hello,

Quoted 7 lines · Brian Norris
Quoted 4 lines

That's because detaching the driver is handled basically as controller hot unplug. By the time SCSI is noticing the SCSI devices are going away, the corresponding ATA devices are already away. It's kinda natural to implement that way. Is this an actual problem?

Yes. The HDD doesn't spin down. I'm removing the device because I want some power savings, so I would expect to spin down the disk.

Detach the hdds first then. You're essentially yanking out the controller. The high level driver naturally loses control of the device before it can do anything about it.

Thanks.

Signature · 1 line
tejun
#6 lore raw

Re: [PATCH 04/14] libata: implement ata_platform_remove_one()

In reply to Sergei Shtylyov
Quoted 37 lines · Sergei Shtylyov
Quoted 15 lines · Brian Norris

This relatively simple boiler-plate code is repeated in several platform drivers. We should implement a common version in libata.

---
  drivers/ata/libata-core.c | 23 +++++++++++++++++++++++
  include/linux/libata.h    |  4 ++++
  2 files changed, 27 insertions(+)
drivers/ata/libata-core.c +0 -0
index 611050d..820e47f 100644

[...]

Quoted 17 lines
drivers/ata/libata-core.c +2 -0
@@ -6350,6 +6351,26 @@ int ata_pci_device_resume(struct pci_dev *pdev)
 
  #endif /* CONFIG_PCI */
 
+/**
+ *      ata_platform_remove_one- Platform layer callback for device

removal
+ * @pdev: Platform device that was removed
+ *
+ * Platform layer indicates to libata via this hook that hot-unplug
or
+ * module unload event has occurred. Detach all ports. Resource
+ * release is handled via devres.
+ *
+ * LOCKING:
+ * Inherited from platform layer (may sleep).
+ */

Quoted 8 lines

drivers/ata/libata-core.c int ata_pci_device_resume(struct pci_dev *pdev) · line 6369

Quoted 5 lines
drivers/ata/libata-core.c +5 -0
+int ata_platform_remove_one(struct platform_device *pdev)
+{
+        struct ata_host *host = platform_get_drvdata(pdev);
+
+        ata_host_detach(host);

Indent with tabs, not spaces, as below.

I need to remind myself to run checkpatch.pl more often. Thanks for pointing this out. Will send v2. (Also, patch 12 had a pre-existing indentation problem; I'll fix it for the line I change.)

Brian

#7 lore raw

PATCH v2 4/14 libata: implement ata_platform_remove_one()

In reply to Brian Norris

This relatively simple boiler-plate code is repeated in several platform drivers. We should implement a common version in libata.

---
v2: fix whitespace

 drivers/ata/libata-core.c | 23 +++++++++++++++++++++++
 include/linux/libata.h    |  4 ++++
 2 files changed, 27 insertions(+)
drivers/ata/libata-core.c +23 -0
index 611050d..7bf1199 100644
@@ -67,6 +67,7 @@
 #include <linux/cdrom.h>
 #include <linux/ratelimit.h>
 #include <linux/pm_runtime.h>
+#include <linux/platform_device.h>
 
 #include "libata.h"
 #include "libata-transport.h"
@@ -6350,6 +6351,26 @@ int ata_pci_device_resume(struct pci_dev *pdev)
 
 #endif /* CONFIG_PCI */
 
+/**
+ *      ata_platform_remove_one- Platform layer callback for device removal
+ *      @pdev: Platform device that was removed
+ *
+ *      Platform layer indicates to libata via this hook that hot-unplug or
+ *      module unload event has occurred.  Detach all ports.  Resource
+ *      release is handled via devres.
+ *
+ *      LOCKING:
+ *      Inherited from platform layer (may sleep).
+ */
+int ata_platform_remove_one(struct platform_device *pdev)
+{
+	struct ata_host *host = platform_get_drvdata(pdev);
+
+	ata_host_detach(host);
+
+	return 0;
+}
+
 static int __init ata_parse_force_one(char **cur,
 				      struct ata_force_ent *force_ent,
 				      const char **reason)
@@ -6844,6 +6865,8 @@ EXPORT_SYMBOL_GPL(ata_pci_device_resume);
 #endif /* CONFIG_PM */
 #endif /* CONFIG_PCI */
 
+EXPORT_SYMBOL_GPL(ata_platform_remove_one);
+
 EXPORT_SYMBOL_GPL(__ata_ehi_push_desc);
 EXPORT_SYMBOL_GPL(ata_ehi_push_desc);
 EXPORT_SYMBOL_GPL(ata_ehi_clear_desc);
include/linux/libata.h +4 -0
index 464e67c..cedcd0f 100644
@@ -1103,6 +1103,10 @@ extern int ata_pci_device_resume(struct pci_dev *pdev);
 #endif /* CONFIG_PM */
 #endif /* CONFIG_PCI */
 
+struct platform_device;
+
+extern int ata_platform_remove_one(struct platform_device *pdev);
+
 /*
  * ACPI - drivers/ata/libata-acpi.c
  */
Signature · 1 line
1.7.11.3
#19 lore raw

PATCH v2 12/14 sata_highbank: utilize common ata_platform_remove_one()

In reply to Brian Norris

---
v2: fix whitespace

 drivers/ata/sata_highbank.c | 12 +-----------
 1 file changed, 1 insertion(+), 11 deletions(-)
drivers/ata/sata_highbank.c +1 -11
index 0d7c4c2..64c7276 100644
@@ -368,16 +368,6 @@ err0:
 	return rc;
 }
 
-static int __devexit ahci_highbank_remove(struct platform_device *pdev)
-{
-	struct device *dev = &pdev->dev;
-	struct ata_host *host = dev_get_drvdata(dev);
-
-	ata_host_detach(host);
-
-	return 0;
-}
-
 #ifdef CONFIG_PM
 static int ahci_highbank_suspend(struct device *dev)
 {
@@ -432,7 +422,7 @@ SIMPLE_DEV_PM_OPS(ahci_highbank_pm_ops,
 		  ahci_highbank_suspend, ahci_highbank_resume);
 
 static struct platform_driver ahci_highbank_driver = {
-        .remove = __devexit_p(ahci_highbank_remove),
+	.remove = ata_platform_remove_one,
         .driver = {
                 .name = "highbank-ahci",
                 .owner = THIS_MODULE,
Signature · 1 line
1.7.11.3
#8 lore raw

Re: [PATCH v2 04/14] libata: implement ata_platform_remove_one()

In reply to Brian Norris
Quoted 15 lines · Brian Norris

This relatively simple boiler-plate code is repeated in several platform drivers. We should implement a common version in libata.

---
v2: fix whitespace

 drivers/ata/libata-core.c | 23 +++++++++++++++++++++++
 include/linux/libata.h    |  4 ++++
 2 files changed, 27 insertions(+)
drivers/ata/libata-core.c +0 -0
index 611050d..7bf1199 100644

[...]

drivers/ata/libata-core.c int ata_pci_device_resume(struct pci_dev *pdev) · line 6355

Quoted 6 lines
drivers/ata/libata-core.c +2 -0
@@ -6350,6 +6351,26 @@ int ata_pci_device_resume(struct pci_dev *pdev)
 
 #endif /* CONFIG_PCI */
 
+/**
+ *      ata_platform_remove_one- Platform layer callback for device removal

A space before hyphen is needed.

drivers/ata/libata-core.c int ata_pci_device_resume(struct pci_dev *pdev) · line 6364

Quoted 9 lines
drivers/ata/libata-core.c +9 -0
+ *      @pdev: Platform device that was removed
+ *
+ *      Platform layer indicates to libata via this hook that hot-unplug or
+ *      module unload event has occurred.  Detach all ports.  Resource
+ *      release is handled via devres.
+ *
+ *      LOCKING:
+ *      Inherited from platform layer (may sleep).
+ */

I actually meant indenting with tabs within the comment too. :-)

WBR, Sergei

#9 lore raw

Re: [PATCH v2 04/14] libata: implement ata_platform_remove_one()

Quoted 20 lines · Sergei Shtylyov

drivers/ata/libata-core.c int ata_pci_device_resume(struct pci_dev *pdev) · line 6355

Quoted 6 lines · Brian Norris
drivers/ata/libata-core.c +2 -0
@@ -6350,6 +6351,26 @@ int ata_pci_device_resume(struct pci_dev *pdev)
 
  #endif /* CONFIG_PCI */
 
+/**
+ *      ata_platform_remove_one- Platform layer callback for device removal

A space before hyphen is needed.

drivers/ata/libata-core.c int ata_pci_device_resume(struct pci_dev *pdev) · line 6364

Quoted 9 lines
drivers/ata/libata-core.c +9 -0
+ *      @pdev: Platform device that was removed
+ *
+ *      Platform layer indicates to libata via this hook that hot-unplug or
+ *      module unload event has occurred.  Detach all ports.  Resource
+ *      release is handled via devres.
+ *
+ *      LOCKING:
+ *      Inherited from platform layer (may sleep).
+ */
Quoted 1 line

I actually meant indenting with tabs within the comment too. :-)

Ugh, more sloppiness, due to a bad copy&paste job, from ata_pci_remove_one(). Thanks for keeping your eyes open. v3 coming...

Brian

#10 lore raw

PATCH v3 4/14 libata: implement ata_platform_remove_one()

In reply to Brian Norris

This relatively simple boiler-plate code is repeated in several platform drivers. We should implement a common version in libata.

---
v2: fix whitespace
v3: really fix whitespace. Thanks Sergei.

 drivers/ata/libata-core.c | 23 +++++++++++++++++++++++
 include/linux/libata.h    |  4 ++++
 2 files changed, 27 insertions(+)
drivers/ata/libata-core.c +23 -0
index 611050d..f13fe28 100644
@@ -67,6 +67,7 @@
 #include <linux/cdrom.h>
 #include <linux/ratelimit.h>
 #include <linux/pm_runtime.h>
+#include <linux/platform_device.h>
 
 #include "libata.h"
 #include "libata-transport.h"
@@ -6350,6 +6351,26 @@ int ata_pci_device_resume(struct pci_dev *pdev)
 
 #endif /* CONFIG_PCI */
 
+/**
+ *	ata_platform_remove_one - Platform layer callback for device removal
+ *	@pdev: Platform device that was removed
+ *
+ *	Platform layer indicates to libata via this hook that hot-unplug or
+ *	module unload event has occurred.  Detach all ports.  Resource
+ *	release is handled via devres.
+ *
+ *	LOCKING:
+ *	Inherited from platform layer (may sleep).
+ */
+int ata_platform_remove_one(struct platform_device *pdev)
+{
+	struct ata_host *host = platform_get_drvdata(pdev);
+
+	ata_host_detach(host);
+
+	return 0;
+}
+
 static int __init ata_parse_force_one(char **cur,
 				      struct ata_force_ent *force_ent,
 				      const char **reason)
@@ -6844,6 +6865,8 @@ EXPORT_SYMBOL_GPL(ata_pci_device_resume);
 #endif /* CONFIG_PM */
 #endif /* CONFIG_PCI */
 
+EXPORT_SYMBOL_GPL(ata_platform_remove_one);
+
 EXPORT_SYMBOL_GPL(__ata_ehi_push_desc);
 EXPORT_SYMBOL_GPL(ata_ehi_push_desc);
 EXPORT_SYMBOL_GPL(ata_ehi_clear_desc);
include/linux/libata.h +4 -0
index 464e67c..cedcd0f 100644
@@ -1103,6 +1103,10 @@ extern int ata_pci_device_resume(struct pci_dev *pdev);
 #endif /* CONFIG_PM */
 #endif /* CONFIG_PCI */
 
+struct platform_device;
+
+extern int ata_platform_remove_one(struct platform_device *pdev);
+
 /*
  * ACPI - drivers/ata/libata-acpi.c
  */
Signature · 1 line
1.7.11.3
#20 lore raw

Re: [PATCH v2 12/14] sata_highbank: utilize common ata_platform_remove_one()

In reply to Brian Norris
Quoted 6 lines · Brian Norris

---
v2: fix whitespace

  drivers/ata/sata_highbank.c | 12 +-----------
  1 file changed, 1 insertion(+), 11 deletions(-)

applied patches 1-11

patch #12 failed to apply (even manually), so I stopped there

#21 lore raw

Re: [PATCH v2 12/14] sata_highbank: utilize common ata_platform_remove_one()

Quoted 11 lines · Jeff Garzik
Quoted 7 lines · Brian Norris

---
v2: fix whitespace

  drivers/ata/sata_highbank.c | 12 +-----------
  1 file changed, 1 insertion(+), 11 deletions(-)

applied patches 1-11

Thanks.

Quoted 1 line

patch #12 failed to apply (even manually), so I stopped there

There was just a trivial change to the #ifdef next to the (unrelated, but adjacent) ahci_highbank_suspend function. I'll resend 12-14, as a v2 series, plus a (new) compile-error fix for pata_of_platform.

BTW, Tejun posted his "Ack" in reply to the original series. I'll include it in my version 2 of the original patches, but I noticed you didn't add it in libata-dev.git.

Brian