diff mbox

[1/1] libata: ahci_start_engine compliant to AHCI spec

Message ID 1303249499-11557-1-git-send-email-jipeng2005@gmail.com
State Not Applicable
Delegated to: David Miller
Headers show

Commit Message

Jian Peng April 19, 2011, 9:44 p.m. UTC
At the end of section 10.1 of AHCI spec (rev 1.3), it states

Software shall not set PxCMD.ST to 1 until it is determined that a
functoinal device is present on the port as determined by
PxTFD.STS.BSY=0, PxTFD.STS.DRQ=0 and PxSSTS.DET=3h

Even though most AHCI host controller works without this additional
check, specific controller will fail without this.

Signed-off-by: Jian Peng <jipeng2005@gmail.com>
---
 drivers/ata/libahci.c |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)

Comments

Tejun Heo April 21, 2011, 1:40 p.m. UTC | #1
On Tue, Apr 19, 2011 at 02:44:59PM -0700, Jian Peng wrote:
> At the end of section 10.1 of AHCI spec (rev 1.3), it states
> 
> Software shall not set PxCMD.ST to 1 until it is determined that a
> functoinal device is present on the port as determined by
> PxTFD.STS.BSY=0, PxTFD.STS.DRQ=0 and PxSSTS.DET=3h
> 
> Even though most AHCI host controller works without this additional
> check, specific controller will fail without this.
> 
> Signed-off-by: Jian Peng <jipeng2005@gmail.com>

Acked-by: Tejun Heo <tj@kernel.org>

But some nitpicks below.

> +	u8 status = readl(port_mmio + PORT_TFDATA) & 0xFF;

It usually isn't customary to initialize variable with a statement
which has side effect, especially hardware access.  Please make the
readl a separate statement.

> +	if (status & (ATA_BUSY | ATA_DRQ) ||
> +	    ahci_scr_read(&ap->link, SCR_STATUS, &tmp) ||

Also, ahci_scr_read() is known not to fail on host port in ahci and
it's customary to skip error return in such cases in low level
drivers.

> +	    (tmp & 0x0f) != 0x03)
> +		return;

And please add comment explaining what condition is being checked.
It's much easier to read comment than digging through changelog and
find out what the code is trying to achieve.

Thanks.
diff mbox

Patch

diff --git a/drivers/ata/libahci.c b/drivers/ata/libahci.c
index 26d4523..39e0698 100644
--- a/drivers/ata/libahci.c
+++ b/drivers/ata/libahci.c
@@ -539,6 +539,12 @@  void ahci_start_engine(struct ata_port *ap)
 {
 	void __iomem *port_mmio = ahci_port_base(ap);
 	u32 tmp;
+	u8 status = readl(port_mmio + PORT_TFDATA) & 0xFF;
+
+	if (status & (ATA_BUSY | ATA_DRQ) ||
+	    ahci_scr_read(&ap->link, SCR_STATUS, &tmp) ||
+	    (tmp & 0x0f) != 0x03)
+		return;
 
 	/* start DMA */
 	tmp = readl(port_mmio + PORT_CMD);