Re: [patch 1/2] ahci: Dont start port DMA engines unless a device is present

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Kristen Carlson Accardi wrote:
According to the AHCI spec, you should not set PxCMD.ST unless
a functional device is present, as determined by PxTFD.STS.BSY=0,
PxTFD.STS.DRQ=0, and PxSSTS.DET = 3.

Signed-off-by:  Kristen Carlson Accardi <kristen.c.accardi@xxxxxxxxx>

Index: linux-2.6.25-rc3/drivers/ata/ahci.c
===================================================================
--- linux-2.6.25-rc3.orig/drivers/ata/ahci.c
+++ linux-2.6.25-rc3/drivers/ata/ahci.c
@@ -783,11 +783,40 @@ static int ahci_scr_write(struct ata_por
 	return -EINVAL;
 }
+static int ahci_is_device_present(struct ata_port *ap)
+{
+	void __iomem *port_mmio = ahci_port_base(ap);
+	u8 status;
+
+	/* Make sure PxTFD.STS.BSY and PxTFD.STS.DRQ are 0 */
+	status = ahci_check_status(ap);
+	if (status & (ATA_BUSY | ATA_DRQ))
+		return 0;
+
+	/* Make sure PxSSTS.DET is 3h */
+	status = readl(port_mmio + PORT_SCR_STAT);
+	status &= 0xf;
+	if ((status & 0xf) != 3)
+		return 0;
+	return 1;
+}
+
 static void ahci_start_engine(struct ata_port *ap)
 {
 	void __iomem *port_mmio = ahci_port_base(ap);
 	u32 tmp;
+ /*
+	 * See AHCI specification 1.2 section 10.1.2
+	 *
+	 * Software shall not set PxCMD.ST to '1' until it is
+ 	 * determined that a functional device is present on
+ 	 * the port, as determined by PxTFD.STS.BSY = '0',
+ 	 * PxTFD.STS.DRQ = '0', PxSSTS.DET = 3h
+ 	 */
+	if (!ahci_is_device_present(ap))
+		return;
+
 	/* start DMA */
 	tmp = readl(port_mmio + PORT_CMD);

This seems incomplete?

If we wish to maintain this invariant, which seems like a good idea and the right thing to do, then this patch fails to cover the hotplug case, correct?

	Jeff



--
To unsubscribe from this list: send the line "unsubscribe linux-ide" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Filesystems]     [Linux SCSI]     [Linux RAID]     [Git]     [Kernel Newbies]     [Linux Newbie]     [Security]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Samba]     [Device Mapper]

  Powered by Linux