Skip to contentSkip to conversation

ahci: Turn off DMA engines when there's no device attached

PATCH In review Matthew Garrett 2 participants 5 messages Mar 10, 2010 – Mar 29, 2010 libata

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ahci: Turn off DMA engines when there's no device attached

According to section 10.3.1 of the AHCI spec, PxCMD.ST must not be set unless there's a device attached. Following this saves us a measurable quantity of power and does not impair hotplug support. Based on a patch by Kristen Carlson Accardi.

Cc Kristen Carlson Accardi <[email protected]>
---
 drivers/ata/ahci.c |   19 +++++++++++++++++++
 1 files changed, 19 insertions(+), 0 deletions(-)
drivers/ata/ahci.c +19 -0
index 6bd930b..ff08317 100644
@@ -1016,11 +1016,30 @@ static int ahci_scr_write(struct ata_link *link, unsigned int sc_reg, u32 val)
 	return -EINVAL;
 }
 
+static int ahci_is_device_present(struct ata_port *ap)
+{
+	void __iomem *port_mmio = ahci_port_base(ap);
+	u8 status = readl(port_mmio + PORT_TFDATA) & 0xff;
+
+	/* Make sure PxTFD.STS.BSY and PxTFD.STS.DRQ are 0 */
+	if (status & (ATA_BUSY | ATA_DRQ))
+		return 0;
+
+	/* Make sure PxSSTS.DET is 3h */
+	status = readl(port_mmio + PORT_SCR_STAT) & 0xf;
+	if (status != 3)
+		return 0;
+	return 1;
+}
+
 static void ahci_start_engine(struct ata_port *ap)
 {
 	void __iomem *port_mmio = ahci_port_base(ap);
 	u32 tmp;
 
+	if (!ahci_is_device_present(ap))
+		return;
+
 	/* start DMA */
 	tmp = readl(port_mmio + PORT_CMD);
 	tmp |= PORT_CMD_START;
Signature · 1 line
1.6.6.1
#1 lore raw

Any feedback on this?

Quoted 54 lines · Matthew Garrett

According to section 10.3.1 of the AHCI spec, PxCMD.ST must not be set unless there's a device attached. Following this saves us a measurable quantity of power and does not impair hotplug support. Based on a patch by Kristen Carlson Accardi.

Cc Kristen Carlson Accardi <[email protected]>
---
 drivers/ata/ahci.c |   19 +++++++++++++++++++
 1 files changed, 19 insertions(+), 0 deletions(-)
drivers/ata/ahci.c +19 -0
index 6bd930b..ff08317 100644
@@ -1016,11 +1016,30 @@ static int ahci_scr_write(struct ata_link *link, unsigned int sc_reg, u32 val)
 	return -EINVAL;
 }
 
+static int ahci_is_device_present(struct ata_port *ap)
+{
+	void __iomem *port_mmio = ahci_port_base(ap);
+	u8 status = readl(port_mmio + PORT_TFDATA) & 0xff;
+
+	/* Make sure PxTFD.STS.BSY and PxTFD.STS.DRQ are 0 */
+	if (status & (ATA_BUSY | ATA_DRQ))
+		return 0;
+
+	/* Make sure PxSSTS.DET is 3h */
+	status = readl(port_mmio + PORT_SCR_STAT) & 0xf;
+	if (status != 3)
+		return 0;
+	return 1;
+}
+
 static void ahci_start_engine(struct ata_port *ap)
 {
 	void __iomem *port_mmio = ahci_port_base(ap);
 	u32 tmp;
 
+	if (!ahci_is_device_present(ap))
+		return;
+
 	/* start DMA */
 	tmp = readl(port_mmio + PORT_CMD);
 	tmp |= PORT_CMD_START;
Signature · 6 lines
1.6.6.1

--
To unsubscribe from this list: send the line "unsubscribe linux-ide" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Signature · 1 line
Matthew Garrett | [email protected]
#2 lore raw
Quoted 11 lines · Matthew Garrett
Quoted 10 lines · Matthew Garrett

According to section 10.3.1 of the AHCI spec, PxCMD.ST must not be set unless there's a device attached. Following this saves us a measurable quantity of power and does not impair hotplug support. Based on a patch by Kristen Carlson Accardi.

Cc Kristen Carlson Accardi<[email protected]>
---
  drivers/ata/ahci.c |   19 +++++++++++++++++++
  1 files changed, 19 insertions(+), 0 deletions(-)

(please don't top-post, it makes replying more difficult)

Quoted 1 line

Any feedback on this?

It should be fine, but I have to rebase it onto the latest upstream ahci (libata-dev.git#upstream), so it's been waiting on that...

Jeff

#3 lore raw
In reply to Matthew Garrett
Quoted 10 lines · Matthew Garrett

According to section 10.3.1 of the AHCI spec, PxCMD.ST must not be set unless there's a device attached. Following this saves us a measurable quantity of power and does not impair hotplug support. Based on a patch by Kristen Carlson Accardi.

Cc Kristen Carlson Accardi<[email protected]>
---
  drivers/ata/ahci.c |   19 +++++++++++++++++++
  1 files changed, 19 insertions(+), 0 deletions(-)

applied manually to libata-dev.git#upstream, due to large code movements in creation of new libahci kernel module

#4 lore raw
In reply to Matthew Garrett
Quoted 4 lines · Matthew Garrett
drivers/ata/ahci.c +4 -0
+static int ahci_is_device_present(struct ata_port *ap)
+{
+	void __iomem *port_mmio = ahci_port_base(ap);
+	u8 status = readl(port_mmio + PORT_TFDATA)&  0xff;

drivers/ata/ahci.c static int ahci_scr_write(struct ata_link *link, unsigned int sc_reg, u32 val) · line 1032

Quoted 10 lines
drivers/ata/ahci.c +10 -0
+
+	/* Make sure PxTFD.STS.BSY and PxTFD.STS.DRQ are 0 */
+	if (status&  (ATA_BUSY | ATA_DRQ))
+		return 0;
+
+	/* Make sure PxSSTS.DET is 3h */
+	status = readl(port_mmio + PORT_SCR_STAT)&  0xf;
+	if (status != 3)
+		return 0;
+	return 1;

Note that this last test, reading SATA Control Register (SCR) Status, does not account for in-transition status, ie. devices that were just plugged in.

Jeff