Skip to contentSkip to conversation

libata: always use polling SETXFER

PATCH In review Tejun Heo 3 participants 7 messages Mar 14, 2007 – May 25, 2007 libata

lore
Share & tools
lore

Tejun Heo

author
#0 lore raw

PATCH 1/1 libata: always use polling SETXFER

Several people have reported LITE-ON LTR-48246S detection failed because SETXFER fails. It seems the device raises IRQ too early after SETXFER. This is controller independent. The same problem has been reported for different controllers.

So, now we have pata_via where the controller raises IRQ before it's ready after SETXFER and a device which does similar thing. This patch makes libata always execute SETXFER via polling. As this only happens during EH, performance impact is nil. Setting ATA_TFLAG_POLLING is also moved from issue hot path to ata_dev_set_xfermode() - the only place where SETXFER can be issued.

Jeff Garzik suggests that, in the long term, it might be better to modify libata HSM implementation such that we're more tolerant of erratic ATAPI IRQ behavior - e.g. default to IRQ but falling back to polling if the device doesn't seem ready at the point of interrupt. Such change might be necessary to support ancient/weird ATAPI devices.

drivers/ata/libata-core.c +4 -9
index 14629a3..3a8da9d 100644
@@ -3575,10 +3575,13 @@ static unsigned int ata_dev_set_xfermode(struct ata_device *dev)
 	/* set up set-features taskfile */
 	DPRINTK("set features - xfer mode\n");
 
+	/* Some controllers and ATAPI devices show flaky interrupt
+	 * behavior after setting xfer mode.  Use polling instead.
+	 */
 	ata_tf_init(dev, &tf);
 	tf.command = ATA_CMD_SET_FEATURES;
 	tf.feature = SETFEATURES_XFER;
-	tf.flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE;
+	tf.flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE | ATA_TFLAG_POLLING;
 	tf.protocol = ATA_PROT_NODATA;
 	tf.nsect = dev->xfer_mode;
 
@@ -5036,14 +5039,6 @@ unsigned int ata_qc_issue_prot(struct ata_queued_cmd *qc)
 		}
 	}
 
-	/* Some controllers show flaky interrupt behavior after
-	 * setting xfer mode.  Use polling instead.
-	 */
-	if (unlikely(qc->tf.command == ATA_CMD_SET_FEATURES &&
-		     qc->tf.feature == SETFEATURES_XFER) &&
-	    (ap->flags & ATA_FLAG_SETXFER_POLLING))
-		qc->tf.flags |= ATA_TFLAG_POLLING;
-
 	/* select the device */
 	ata_dev_select(ap, qc->dev->devno, 1, 0);
 
drivers/ata/pata_via.c +6 -6
index 96b7179..377e792 100644
@@ -426,7 +426,7 @@ static int via_init_one(struct pci_dev *pdev, const struct pci_device_id *id)
 	/* Early VIA without UDMA support */
 	static struct ata_port_info via_mwdma_info = {
 		.sht = &via_sht,
-		.flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SETXFER_POLLING,
+		.flags = ATA_FLAG_SLAVE_POSS,
 		.pio_mask = 0x1f,
 		.mwdma_mask = 0x07,
 		.port_ops = &via_port_ops
@@ -434,7 +434,7 @@ static int via_init_one(struct pci_dev *pdev, const struct pci_device_id *id)
 	/* Ditto with IRQ masking required */
 	static struct ata_port_info via_mwdma_info_borked = {
 		.sht = &via_sht,
-		.flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SETXFER_POLLING,
+		.flags = ATA_FLAG_SLAVE_POSS,
 		.pio_mask = 0x1f,
 		.mwdma_mask = 0x07,
 		.port_ops = &via_port_ops_noirq,
@@ -442,7 +442,7 @@ static int via_init_one(struct pci_dev *pdev, const struct pci_device_id *id)
 	/* VIA UDMA 33 devices (and borked 66) */
 	static struct ata_port_info via_udma33_info = {
 		.sht = &via_sht,
-		.flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SETXFER_POLLING,
+		.flags = ATA_FLAG_SLAVE_POSS,
 		.pio_mask = 0x1f,
 		.mwdma_mask = 0x07,
 		.udma_mask = 0x7,
@@ -451,7 +451,7 @@ static int via_init_one(struct pci_dev *pdev, const struct pci_device_id *id)
 	/* VIA UDMA 66 devices */
 	static struct ata_port_info via_udma66_info = {
 		.sht = &via_sht,
-		.flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SETXFER_POLLING,
+		.flags = ATA_FLAG_SLAVE_POSS,
 		.pio_mask = 0x1f,
 		.mwdma_mask = 0x07,
 		.udma_mask = 0x1f,
@@ -460,7 +460,7 @@ static int via_init_one(struct pci_dev *pdev, const struct pci_device_id *id)
 	/* VIA UDMA 100 devices */
 	static struct ata_port_info via_udma100_info = {
 		.sht = &via_sht,
-		.flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SETXFER_POLLING,
+		.flags = ATA_FLAG_SLAVE_POSS,
 		.pio_mask = 0x1f,
 		.mwdma_mask = 0x07,
 		.udma_mask = 0x3f,
@@ -469,7 +469,7 @@ static int via_init_one(struct pci_dev *pdev, const struct pci_device_id *id)
 	/* UDMA133 with bad AST (All current 133) */
 	static struct ata_port_info via_udma133_info = {
 		.sht = &via_sht,
-		.flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SETXFER_POLLING,
+		.flags = ATA_FLAG_SLAVE_POSS,
 		.pio_mask = 0x1f,
 		.mwdma_mask = 0x07,
 		.udma_mask = 0x7f,	/* FIXME: should check north bridge */
include/linux/libata.h +0 -1
index 0ad28a3..b9fc57c 100644
@@ -171,7 +171,6 @@ enum {
 	ATA_FLAG_SKIP_D2H_BSY	= (1 << 12), /* can't wait for the first D2H
 					      * Register FIS clearing BSY */
 	ATA_FLAG_DEBUGMSG	= (1 << 13),
-	ATA_FLAG_SETXFER_POLLING= (1 << 14), /* use polling for SETXFER */
 	ATA_FLAG_IGN_SIMPLEX	= (1 << 15), /* ignore SIMPLEX */
 	ATA_FLAG_NO_IORDY	= (1 << 16), /* controller lacks iordy */
 
Acked-by on v1 1/1
#1 lore raw
Quoted 12 lines · Tejun Heo

Several people have reported LITE-ON LTR-48246S detection failed because SETXFER fails. It seems the device raises IRQ too early after SETXFER. This is controller independent. The same problem has been reported for different controllers.

So, now we have pata_via where the controller raises IRQ before it's ready after SETXFER and a device which does similar thing. This patch makes libata always execute SETXFER via polling. As this only happens during EH, performance impact is nil. Setting ATA_TFLAG_POLLING is also moved from issue hot path to ata_dev_set_xfermode() - the only place where SETXFER can be issued.

Quoted 7 lines

Jeff Garzik suggests that, in the long term, it might be better to modify libata HSM implementation such that we're more tolerant of erratic ATAPI IRQ behavior - e.g. default to IRQ but falling back to polling if the device doesn't seem ready at the point of interrupt. Such change might be necessary to support ancient/weird ATAPI devices.

author
#2 lore raw
In reply to Tejun Heo
Quoted 12 lines · Tejun Heo

Several people have reported LITE-ON LTR-48246S detection failed because SETXFER fails. It seems the device raises IRQ too early after SETXFER. This is controller independent. The same problem has been reported for different controllers.

So, now we have pata_via where the controller raises IRQ before it's ready after SETXFER and a device which does similar thing. This patch makes libata always execute SETXFER via polling. As this only happens during EH, performance impact is nil. Setting ATA_TFLAG_POLLING is also moved from issue hot path to ata_dev_set_xfermode() - the only place where SETXFER can be issued.

Quoted 7 lines

Jeff Garzik suggests that, in the long term, it might be better to modify libata HSM implementation such that we're more tolerant of erratic ATAPI IRQ behavior - e.g. default to IRQ but falling back to polling if the device doesn't seem ready at the point of interrupt. Such change might be necessary to support ancient/weird ATAPI devices.

Jeff, ping.

Signature · 1 line
tejun
#3 lore raw
In reply to Tejun Heo
Quoted 12 lines · Tejun Heo

Several people have reported LITE-ON LTR-48246S detection failed because SETXFER fails. It seems the device raises IRQ too early after SETXFER. This is controller independent. The same problem has been reported for different controllers.

So, now we have pata_via where the controller raises IRQ before it's ready after SETXFER and a device which does similar thing. This patch makes libata always execute SETXFER via polling. As this only happens during EH, performance impact is nil. Setting ATA_TFLAG_POLLING is also moved from issue hot path to ata_dev_set_xfermode() - the only place where SETXFER can be issued.

Quoted 7 lines

Jeff Garzik suggests that, in the long term, it might be better to modify libata HSM implementation such that we're more tolerant of erratic ATAPI IRQ behavior - e.g. default to IRQ but falling back to polling if the device doesn't seem ready at the point of interrupt. Such change might be necessary to support ancient/weird ATAPI devices.

Since I wrote them up in IRC, I might as well post them here and get it archived:

We need to figure out a better polling solution.

For SAS and advanced SATA, polling really has no meaning at all, when you consider what polling IDENTIFY DEVICE and polling SET FEATURES are trying to solve. To the advanced hardware, it's all a bunch of packets.
An event that appears "late" to the eyes of the PATA world is now
presented as changing data fields in the packet stream.

We are going to have to deal with the HSM issue underlying the need to do SET FEATURES - XFER MODE polling, and ultimately IDENTIFY DEVICE polling too.

This is the main reason why I have resisted applying "[PATCH] libata: always use polling SETXFER" -- polling implies a model that does not exist on SAS/SATA and advanced SATA. It's only luck that AHCI includes a real register to poll.

To illustrate: Fixing this problem The Right Way(tm) will yield a result that would allow ahci.c to operate in an interrupt-driven mode, examining the contents of the FIS's returned. Polling status can already be replaced by examining the D2H and SDB FIS areas.

And by definition, on AHCI (and sata_sil24, IIRC) the status will not change unless a new FIS has arrived.

Polling is still fine on PCI IDE-like controllers (older ones), but advanced controllers require us to coalesce the polling bandaid into a test for a sequence of events.

We cannot escape the "hard part." :)

Jeff

author
#4 lore raw

Hello, Jeff.

Quoted 2 lines · Jeff Garzik

Since I wrote them up in IRC, I might as well post them here and get it archived:

Just about to reply on IRC. :-)

Quoted 22 lines

We need to figure out a better polling solution.

For SAS and advanced SATA, polling really has no meaning at all, when you consider what polling IDENTIFY DEVICE and polling SET FEATURES are trying to solve. To the advanced hardware, it's all a bunch of packets.
An event that appears "late" to the eyes of the PATA world is now
presented as changing data fields in the packet stream.

We are going to have to deal with the HSM issue underlying the need to do SET FEATURES - XFER MODE polling, and ultimately IDENTIFY DEVICE polling too.

This is the main reason why I have resisted applying "[PATCH] libata:
always use polling SETXFER" -- polling implies a model that does not exist on SAS/SATA and advanced SATA. It's only luck that AHCI includes a real register to poll.

To illustrate: Fixing this problem The Right Way(tm) will yield a result that would allow ahci.c to operate in an interrupt-driven mode, examining the contents of the FIS's returned. Polling status can already be replaced by examining the D2H and SDB FIS areas.

Quoted 8 lines

And by definition, on AHCI (and sata_sil24, IIRC) the status will not change unless a new FIS has arrived.

Polling is still fine on PCI IDE-like controllers (older ones), but advanced controllers require us to coalesce the polling bandaid into a test for a sequence of events.

We cannot escape the "hard part." :)

I don't think the "hard part" exists at all.

1. There are only a handful of PATA devices which raise IRQ too early. For native SATA devices, it's much more difficult to get it wrong if you consider the SATA non-data and PIO transport protocol. For PATA devices bridged to SATA, again, there's nothing much we can do. The bridge implements HSM and would send D2H Reg FIS on command completion IRQ. If the PATA shows incorrect register values at that stage, well, that's it.

3. Intelligent controllers such as AHCI and sil24 implement some part of HSM in the silicon. sil24 implements most of it, ahci a bit less, but, even for ahci, the too early interrupt can trigger internal HSM failure. I don't think we can do much in such cases. sil24 doesn't even update
the TF area if command is not in progress. In the intelligent controllers, the problem polling SETXFER tries to solve is in lower layer than OS driver.

So, I don't think the problem exists for SATA in the first place. At least there hasn't been any report of it and doing SETXFER by polling can handle all the existing cases. We can and probably should deal with such SATA devices when and if they come up. How are we gonna verify the controller doesn't crap itself and ahci TF register monitoring HSM can work around the weirdo when we don't have any such device? Even if we determine that we need to do HSM over intelligent SATA controller now, I think we still need to push polling SETXFER first to take care of the existing cases.

Thanks.

Signature · 1 line
tejun
#5 lore raw
Quoted 9 lines · Tejun Heo

So, I don't think the problem exists for SATA in the first place. At least there hasn't been any report of it and doing SETXFER by polling can handle all the existing cases. We can and probably should deal with such SATA devices when and if they come up. How are we gonna verify the controller doesn't crap itself and ahci TF register monitoring HSM can work around the weirdo when we don't have any such device? Even if we determine that we need to do HSM over intelligent SATA controller now, I think we still need to push polling SETXFER first to take care of the existing cases.

Doing SETXFER by polling only handles the cases where the driver actually honors ATA_TFLAG_POLLING, which is /not/ always the case.

If the new policy ensures that it continues to be OK to /not/ honor ATA_TFLAG_POLLING -- thus limiting SETXFER polling assumptions to older hardware -- that's fine, and it merely needs to be documented.

But let us not make the assumption that this bandaid fixes all cases, because the bandaid is not applied in all cases.

Jeff

author
#6 lore raw
Quoted 11 lines · Jeff Garzik
Quoted 9 lines · Tejun Heo

So, I don't think the problem exists for SATA in the first place. At least there hasn't been any report of it and doing SETXFER by polling can handle all the existing cases. We can and probably should deal with such SATA devices when and if they come up. How are we gonna verify the controller doesn't crap itself and ahci TF register monitoring HSM can work around the weirdo when we don't have any such device? Even if we determine that we need to do HSM over intelligent SATA controller now, I think we still need to push polling SETXFER first to take care of the existing cases.

Quoted 6 lines

Doing SETXFER by polling only handles the cases where the driver actually honors ATA_TFLAG_POLLING, which is /not/ always the case.

If the new policy ensures that it continues to be OK to /not/ honor ATA_TFLAG_POLLING -- thus limiting SETXFER polling assumptions to older hardware -- that's fine, and it merely needs to be documented.

Basically this flag applies to drivers which is SFF compliant, at least at TF interface level. There also are other flags/callbacks which only apply to SFF or BMDMA. It would be nice to separate them out in the long term and yeah it needs documentation.

Quoted 2 lines

But let us not make the assumption that this bandaid fixes all cases, because the bandaid is not applied in all cases.

It covers all the known cases but I agree that SFF specific things certainly need documentation.

Thanks.

Signature · 1 line
tejun