[PATCH] libata ATA vs SATA detection and workaround.

From: Brad Campbell
Date: Mon Aug 30 2004 - 09:49:32 EST


Jeff Garzik wrote:
Jeff Garzik wrote:

me either, unless I can figure out a way to detect that a disk is PATA not SATA. Nothing is obvious from the specs on www.t13.org, but who knows.


According to the Serial ATA docs, IDENTIFY DEVICE word 93 will be zero if it's Serial ATA. Who knows if that's true, given the wierd wild world of ATA devices.


I'm assuming here that if the driver uses sata_phy_reset in libata-core then it's actually a SATA controller.

Patch attached, tested and verified.
SATA drives (of which I only have one brand) report IDENTIFY DEVICE word 93 as zero, ATA devices behind the bridge (Of which I only have one brand) report at a minimum bit 13 to report an 80 conductor cable.

Like I said before, my assumptions are

A) IDENTIFY DEVICE and the associated Word 93 register have been *Mandatory* at least since ATA-5

B) ATA-5 maxed out at < udma/100 and did not contain lba48

C) The SATA->PATA bridge looks like an 80 conductor cable and thus on any drive that supports lba48 will always present a non-zero value in IDENTIFY DEVICE Word 93.

It works here anyway.
Patch against vanilla 2.6.9-rc1 attached (including your ata.h patch)

Thanks again for all the help. I'll see if I can get some other older ATA drives to test with (I might have to gut all the machines in the office for the weekend)

Regards,
Brad
diff -ur orig/linux-2.6.0/drivers/scsi/libata-core.c linux-2.6.9-rc1/drivers/scsi/libata-core.c
--- orig/linux-2.6.0/drivers/scsi/libata-core.c 2004-08-30 18:31:31.000000000 +0400
+++ linux-2.6.9-rc1/drivers/scsi/libata-core.c 2004-08-30 18:22:05.000000000 +0400
@@ -1152,6 +1152,16 @@
found = 1;
if (ap->ops->dev_config)
ap->ops->dev_config(ap, &ap->device[i]);
+ /* limit bridge transfers to udma5, 200 sectors */
+ printk("Value is %u\n",ap->cbl==ATA_CBL_SATA);
+ if ((ap->cbl == ATA_CBL_SATA) && (!ata_id_is_sata(ap->device))) {
+ printk(KERN_INFO "ata%u(%u): applying bridge limits\n",
+ ap->id, ap->device->devno);
+ ap->udma_mask &= ATA_UDMA5;
+ ap->host->max_sectors = ATA_MAX_SECTORS;
+ ap->host->hostt->max_sectors = ATA_MAX_SECTORS;
+ ap->device->flags |= ATA_DFLAG_LOCK_SECTORS;
+ }
}
}

@@ -1226,7 +1236,7 @@
ata_port_disable(ap);
return;
}
-
+ ap->cbl = ATA_CBL_SATA;
ata_bus_reset(ap);
}

diff -ur orig/linux-2.6.0/include/linux/ata.h linux-2.6.9-rc1/include/linux/ata.h
--- orig/linux-2.6.0/include/linux/ata.h 2004-08-30 18:31:32.000000000 +0400
+++ linux-2.6.9-rc1/include/linux/ata.h 2004-08-30 17:56:53.000000000 +0400
@@ -218,6 +218,7 @@
};

#define ata_id_is_ata(dev) (((dev)->id[0] & (1 << 15)) == 0)
+#define ata_id_is_sata(dev) ((dev)->id[93] == 0)
#define ata_id_rahead_enabled(dev) ((dev)->id[85] & (1 << 6))
#define ata_id_wcache_enabled(dev) ((dev)->id[85] & (1 << 5))
#define ata_id_has_flush(dev) ((dev)->id[83] & (1 << 12))