Skip to contentSkip to conversation

libata: disable runtime pm for hotpluggable port

PATCH Superseded Lin Ming 2 participants 3 messages Mar 12, 2012 libata

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Lin Ming

author
#0 lore raw

PATCH 1/1 libata: disable runtime pm for hotpluggable port

Currently, hotplug doesn't work if port is already runtime suspended. For now, we simply disable runtime pm for hotpluggable port. Later, we should add runtime pm support for hotpluggable port too.

https://lkml.org/lkml/2012/2/19/70

TODO: add similar hotpluggable port check for controllers other than AHCI.

Reported-and-tested-by Jiri Slaby <[email protected]>
Reported-and-tested-by [email protected]
Reported-and-tested-by [email protected]
---
 drivers/ata/ahci.c             |    3 +++
 drivers/ata/ahci.h             |    3 +++
 drivers/ata/libahci.c          |   20 ++++++++++++++++++++
 drivers/ata/libata-transport.c |    6 ++++--
 include/linux/libata.h         |    4 +++-
 5 files changed, 33 insertions(+), 3 deletions(-)
drivers/ata/ahci.c +3 -0
index fb659c8..fb7de91 100644
@@ -1153,6 +1153,9 @@ static int ahci_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
 	if (hpriv->cap & HOST_CAP_PMP)
 		pi.flags |= ATA_FLAG_PMP;
 
+	if (hpriv->cap & HOST_CAP_SXS)
+		pi.flags |= ATA_FLAG_EXTERNAL;
+
 	ahci_set_em_messages(hpriv, &pi);
 
 	if (ahci_broken_system_poweroff(pdev)) {
drivers/ata/ahci.h +3 -0
index b175000..92f7172 100644
@@ -172,6 +172,9 @@ enum {
 	PORT_CMD_ALPE		= (1 << 26), /* Aggressive Link PM enable */
 	PORT_CMD_ATAPI		= (1 << 24), /* Device is ATAPI */
 	PORT_CMD_FBSCP		= (1 << 22), /* FBS Capable Port */
+	PORT_CMD_ESP		= (1 << 21), /* External SATA Port */
+	PORT_CMD_MPSP		= (1 << 19), /* Mechanical Presence Switch Attached to Port */
+	PORT_CMD_HPCP		= (1 << 18), /* Hot Plug Capable Port */
 	PORT_CMD_PMP		= (1 << 17), /* PMP attached */
 	PORT_CMD_LIST_ON	= (1 << 15), /* cmd list DMA engine running */
 	PORT_CMD_FIS_ON		= (1 << 14), /* FIS DMA engine running */
drivers/ata/libahci.c +20 -0
index a72bfd0..7d72d3c 100644
@@ -1097,6 +1097,23 @@ static void ahci_port_init(struct device *dev, struct ata_port *ap,
 	writel(1 << port_no, mmio + HOST_IRQ_STAT);
 }
 
+static bool ahci_port_pluggable(struct ata_port *ap)
+{
+	void __iomem *port_mmio = ahci_port_base(ap);
+	u32 cmd;
+
+	cmd = readl(port_mmio + PORT_CMD);
+
+	if ((ap->flags & ATA_FLAG_EXTERNAL) &&
+	    (cmd & PORT_CMD_ESP))
+		return true;
+
+	if (cmd & (PORT_CMD_MPSP | PORT_CMD_HPCP))
+		return true;
+
+	return false;
+}
+
 void ahci_init_controller(struct ata_host *host)
 {
 	struct ahci_host_priv *hpriv = host->private_data;
@@ -1112,6 +1129,9 @@ void ahci_init_controller(struct ata_host *host)
 		if (ata_port_is_dummy(ap))
 			continue;
 
+		if (ahci_port_pluggable(ap))
+			ap->flags |= ATA_FLAG_PLUGGABLE;
+
 		ahci_port_init(host->dev, ap, i, mmio, port_mmio);
 	}
 
drivers/ata/libata-transport.c +4 -2
index 74aaee3..a7166b9 100644
@@ -292,8 +292,10 @@ int ata_tport_add(struct device *parent,
 	}
 
 	device_enable_async_suspend(dev);
-	pm_runtime_set_active(dev);
-	pm_runtime_enable(dev);
+	if (!(ap->flags & ATA_FLAG_PLUGGABLE)) {
+		pm_runtime_set_active(dev);
+		pm_runtime_enable(dev);
+	}
 
 	transport_add_device(dev);
 	transport_configure_device(dev);
include/linux/libata.h +3 -1
index 3085bdc..ccf0282 100644
@@ -209,8 +209,10 @@ enum {
 	ATA_FLAG_SW_ACTIVITY	= (1 << 22), /* driver supports sw activity
 					      * led */
 	ATA_FLAG_NO_DIPM	= (1 << 23), /* host not happy with DIPM */
+	ATA_FLAG_EXTERNAL	= (1 << 24), /* controller supports external SATA */
+	ATA_FLAG_PLUGGABLE	= (1 << 25), /* port is hotpluggable */
 
-	/* bits 24:31 of ap->flags are reserved for LLD specific flags */
+	/* bits 26:31 of ap->flags are reserved for LLD specific flags */
 
 
 	/* struct ata_port pflags */
Signature · 1 line
1.7.2.5
#1 lore raw

Hello.

Quoted 12 lines · Lin Ming

Currently, hotplug doesn't work if port is already runtime suspended. For now, we simply disable runtime pm for hotpluggable port. Later, we should add runtime pm support for hotpluggable port too.

https://lkml.org/lkml/2012/2/19/70

TODO: add similar hotpluggable port check for controllers other than AHCI.

Reported-and-tested-by Jiri Slaby<[email protected]>
Reported-and-tested-by [email protected]
Reported-and-tested-by [email protected]

[...]

include/linux/libata.h enum { · line 215

Quoted 13 lines
include/linux/libata.h +3 -1
index 3085bdc..ccf0282 100644
@@ -209,8 +209,10 @@ enum {
  	ATA_FLAG_SW_ACTIVITY	= (1<<  22), /* driver supports sw activity
  					      * led */
  	ATA_FLAG_NO_DIPM	= (1<<  23), /* host not happy with DIPM */
+	ATA_FLAG_EXTERNAL	= (1<<  24), /* controller supports external SATA */
+	ATA_FLAG_PLUGGABLE	= (1<<  25), /* port is hotpluggable */
 
-	/* bits 24:31 of ap->flags are reserved for LLD specific flags */
+	/* bits 26:31 of ap->flags are reserved for LLD specific flags */

There's no need to use bits 24..25, I've freed up some lower order bits
last year, removing unused values.

WBR, Sergei

author
#2 lore raw
Quoted 29 lines · Sergei Shtylyov

Hello.

Quoted 12 lines · Lin Ming

Currently, hotplug doesn't work if port is already runtime suspended. For now, we simply disable runtime pm for hotpluggable port. Later, we should add runtime pm support for hotpluggable port too.

https://lkml.org/lkml/2012/2/19/70

TODO: add similar hotpluggable port check for controllers other than AHCI.

Reported-and-tested-by Jiri Slaby<[email protected]>
Reported-and-tested-by [email protected]
Reported-and-tested-by [email protected]

[...]

Quoted 11 lines
include/linux/libata.h +2 -0
index 3085bdc..ccf0282 100644
@@ -209,8 +209,10 @@ enum {
  	ATA_FLAG_SW_ACTIVITY	= (1<<  22), /* driver supports sw activity
  					      * led */
  	ATA_FLAG_NO_DIPM	= (1<<  23), /* host not happy with DIPM */
+	ATA_FLAG_EXTERNAL	= (1<<  24), /* controller supports external SATA */
+	ATA_FLAG_PLUGGABLE	= (1<<  25), /* port is hotpluggable */
 
Quoted 5 lines

include/linux/libata.h enum { · line 215

Quoted 2 lines
include/linux/libata.h +1 -1
-	/* bits 24:31 of ap->flags are reserved for LLD specific flags */
+	/* bits 26:31 of ap->flags are reserved for LLD specific flags */

There's no need to use bits 24..25, I've freed up some lower order bits
last year, removing unused values.

OK. I'll use bit 2 and 3, as below

include/linux/libata.h +2 -0
index cafc09a..f46961d 100644
@@ -187,6 +187,8 @@ enum {
 	ATA_FLAG_SLAVE_POSS	= (1 << 0), /* host supports slave dev */
 					    /* (doesn't imply presence) */
 	ATA_FLAG_SATA		= (1 << 1),
+	ATA_FLAG_EXTERNAL	= (1 << 2), /* Controller supports external SATA */
+	ATA_FLAG_PLUGGABLE	= (1 << 3), /* Port is hotpluggable */
 	ATA_FLAG_NO_ATAPI	= (1 << 6), /* No ATAPI support */
 	ATA_FLAG_PIO_DMA	= (1 << 7), /* PIO cmds via DMA */
 	ATA_FLAG_PIO_LBA48	= (1 << 8), /* Host DMA engine is LBA28 only */
Quoted 2 lines

WBR, Sergei