libata: Better timeout recovery
PATCH 1/1 libata: Better timeout recovery
From: Alan Cox <[email protected]>
Check for completed commands on a timeout, also implement data draining as Mark Lord suggested. The former should help a lot on various promise controllers which show random IRQ loss now and then, the latter at least for me fixes the hanging DRQ cases I can test.
To get the lost IRQ recovery working better we really need to short circuit a lot fo the recovery paths we trigger needlessly when EH finds that actually all was well.
---
drivers/ata/libata-eh.c | 19 +++++++++- drivers/ata/libata-sff.c | 88 ++++++++++++++++++++++++++++++++++++++++++++- drivers/ata/pata_isapnp.c | 12 +++++- drivers/ata/pata_pcmcia.c | 35 +++++++++++++++++- include/linux/libata.h | 5 +++ 5 files changed, 153 insertions(+), 6 deletions(-)
drivers/ata/libata-eh.c +17 -2
@@ -518,7 +518,7 @@ void ata_scsi_error(struct Scsi_Host *host)/* For new EH, all qcs are finished in one of three ways - * normal completion, error completion, and SCSI timeout. -* Both cmpletions can race against SCSI timeout. When normal +* Both completions can race against SCSI timeout. When normal * completion wins, the qc never reaches EH. When error * completion wins, the qc has ATA_QCFLAG_FAILED set. *
@@ -533,7 +533,19 @@ void ata_scsi_error(struct Scsi_Host *host)int nr_timedout =0 ;spin_lock_irqsave (ap->lock, flags); - + +/* This must occur under the ap->lock as we don't want +a polled recovery to race the real interrupt handler ++ The lost_interrupt handler checks for any completed but +non-notified command and completes much like an IRQ handler. ++ We then fall into the error recovery code which will treat +this as if normal completion won the race */ + +if (ap->ops->lost_interrupt) + ap->ops->lost_interrupt (ap); +list_for_each_entry_safe (scmd, tmp, &host->eh_cmd_q, eh_entry) {struct ata_queued_cmd *qc;
@@ -577,6 +589,9 @@ void ata_scsi_error(struct Scsi_Host *host) ap->eh_tries =ATA_EH_MAX_TRIES ; }else spin_unlock_wait (ap->lock); + +/* If we timed raced normal completion and there is nothing to +recover nr_timedout == 0 why exactly are we doing error recovery ? */ repeat:/* invoke error handler */
drivers/ata/libata-sff.c +87 -1
142 lines not on this page · raw message
drivers/ata/pata_isapnp.c +10 -2
@@ -17,7 +17,7 @@#include <linux/libata.h> #define DRV_NAME "pata_isapnp" -#define DRV_VERSION "0.2.2" +#define DRV_VERSION "0.2.5"static struct scsi_host_template isapnp_sht = {ATA_PIO_SHT (DRV_NAME ),
@@ -28,6 +28,13 @@ static struct ata_port_operations isapnp_port_ops = { .cable_detect = ata_cable_40wire, }; +static struct ata_port_operations isapnp_noalt_port_ops = { + .inherits = &ata_sff_port_ops, + .cable_detect = ata_cable_40wire, +/* No altstatus so we don't want to use the lost interrupt poll */ + .lost_interrupt =ATA_OP_NULL , +}; +/** * isapnp_init_one - attach an isapnp interface * @idev: PnP device
@@ -65,7 +72,7 @@ static int isapnp_init_one(struct pnp_dev *idev, const struct pnp_device_id *dev ap = host->ports[0 ]; - ap->ops = &isapnp_port_ops; + ap->ops = &isapnp_noalt_port_ops; ap->pio_mask =1 ; ap->flags |=ATA_FLAG_SLAVE_POSS ;
@@ -76,6 +83,7 @@ static int isapnp_init_one(struct pnp_dev *idev, const struct pnp_device_id *dev pnp_port_start(idev, 1), 1); ap->ioaddr.altstatus_addr = ctl_addr; ap->ioaddr.ctl_addr = ctl_addr; + ap->ops = &isapnp_port_ops; }ata_sff_std_ports (&ap->ioaddr);
drivers/ata/pata_pcmcia.c +34 -1
@@ -42,7 +42,7 @@#define DRV_NAME "pata_pcmcia" -#define DRV_VERSION "0.3.3" +#define DRV_VERSION "0.3.5"/* * Private data structure to glue stuff together
@@ -126,6 +126,38 @@ static unsigned int ata_data_xfer_8bit(struct ata_device *dev,return buflen; } +/** +* pcmcia_8bit_drain_fifo - Stock FIFO drain logic for SFF controllers +* @ap: port to drain +* @qc: command +* +* Drain the FIFO and device of any stuck data following a command +* failing to complete. In some cases this is neccessary before a +* reset will recover the device. +* +*/ + +void pcmcia_8bit_drain_fifo (struct ata_queued_cmd *qc) +{ +int count; +struct ata_port *ap; + +/* We only need to flush incoming data when a command was running */ +if (qc ==NULL || qc->dma_dir ==DMA_TO_DEVICE ) +return ; + + ap = qc->ap; + +/* Drain up to 64K of data before we give up this recovery method */ +for (count =0 ; (ap->ops->sff_check_status (ap) &ATA_DRQ ) + && count <65536 ;) +ioread8 (ap->ioaddr.data_addr); + +/* Can become DEBUG later */ +ata_port_printk (ap,KERN_WARNING ,"drained %d bytes to clear DRQ.\n" , + count); + +}static struct scsi_host_template pcmcia_sht = {ATA_PIO_SHT (DRV_NAME ),
@@ -143,6 +175,7 @@ static struct ata_port_operations pcmcia_8bit_port_ops = { .sff_data_xfer = ata_data_xfer_8bit, .cable_detect = ata_cable_40wire, .set_mode = pcmcia_set_mode_8bit, + .drain_fifo = pcmcia_8bit_drain_fifo, };#define CS_CHECK (fn, ret) \
include/linux/libata.h +5 -0
@@ -777,6 +777,7 @@ struct ata_port_operations {ata_reset_fn_t pmp_hardreset;ata_postreset_fn_t pmp_postreset;void (*error_handler)(struct ata_port *ap); +void (*lost_interrupt)(struct ata_port *ap);void (*post_internal_cmd)(struct ata_queued_cmd *qc);/*
@@ -818,6 +819,8 @@ struct ata_port_operations {void (*bmdma_start)(struct ata_queued_cmd *qc);void (*bmdma_stop)(struct ata_queued_cmd *qc);u8 (*bmdma_status)(struct ata_port *ap); + +void (*drain_fifo)(struct ata_queued_cmd *qc);#endif /* CONFIG_ATA_SFF */ ssize_t (*em_show)(struct ata_port *ap,char *buf);
@@ -1512,6 +1515,7 @@ extern bool ata_sff_qc_fill_rtf(struct ata_queued_cmd *qc);extern unsigned int ata_sff_host_intr (struct ata_port *ap,struct ata_queued_cmd *qc);extern irqreturn_t ata_sff_interrupt (int irq,void *dev_instance); +extern void ata_sff_lost_interrupt (struct ata_port *ap);extern void ata_sff_freeze (struct ata_port *ap);extern void ata_sff_thaw (struct ata_port *ap);extern int ata_sff_prereset (struct ata_link *link,unsigned long deadline);
@@ -1524,6 +1528,7 @@ extern int ata_sff_softreset(struct ata_link *link, unsigned int *classes,extern int sata_sff_hardreset (struct ata_link *link,unsigned int *class,unsigned long deadline);extern void ata_sff_postreset (struct ata_link *link,unsigned int *classes); +extern void ata_sff_drain_fifo (struct ata_queued_cmd *qc);extern void ata_sff_error_handler (struct ata_port *ap);extern void ata_sff_post_internal_cmd (struct ata_queued_cmd *qc);extern int ata_sff_port_start (struct ata_port *ap);
Quoted 13 lines · Alan Cox
From: Alan Cox <[email protected]>
Check for completed commands on a timeout, also implement data draining as Mark Lord suggested. The former should help a lot on various promise controllers which show random IRQ loss now and then, the latter at least for me fixes the hanging DRQ cases I can test.
To get the lost IRQ recovery working better we really need to short circuit a lot fo the recovery paths we trigger needlessly when EH finds that actually all was well.
Signed-off-by Alan Cox <[email protected]>---
[...]
Quoted 4 lines
drivers/ata/libata-sff.c +0
-0
[...]
Quoted 24 lines
drivers/ata/libata-sff.c +20
-0@@ -1660,6 +1663,47 @@ irqreturn_t ata_sff_interrupt(int irq, void *dev_instance) }/** +* ata_sff_lost_interrupt - Check for an apparent lost interrupt +* @ap: port that appears to have timed out +* +* Called from the libata error handlers when the core code suspects +* an interrupt has been lost. If it has complete anything we can and +* then return. Interface must support altstatus for this faster +* recovery to occur. +* +* Locking: +* Caller holds host lock +*/ + +void ata_sff_lost_interrupt (struct ata_port *ap) +{ +u8 status; +struct ata_queued_cmd *qc; + +/* Only one outstanding command per SFF channel */ + qc =ata_qc_from_tag (ap, ap->link.active_tag); +/* Check we have a live one.. */
drivers/ata/libata-sff.c irqreturn_t ata_sff_interrupt(int irq, void *dev_instance) · line 1695
Quoted 10 lines
drivers/ata/libata-sff.c +10
-0+if (qc ==NULL || !(qc->flags &ATA_QCFLAG_ACTIVE )) +return ; +/* We cannot lose an interrupt on a polled command */ +if (qc->tf.flags &ATA_TFLAG_POLLING ) +return ; +/* See if the controller thinks it is still busy - if so the command +isn't a lost IRQ but is still in progress */ + status =ata_sff_altstatus (ap); +if (!(status &ATA_BUSY )) +return ;
Shouldn't this rather be
if (status & ATA_BUSY) return;
?
Quoted 7 lines
drivers/ata/libata-sff.c +5
-0+ +/* There was a command running, we are no longer busy and we have +no interrupt. */ +ata_port_printk (ap,KERN_WARNING ,"lost interrupt (Status 0x%x)\n" , + status);From your changelog entry I got the impression that this is known to
happen on various controllers and there is nothing the user or you (kernel developers) can do about it. So, will this become a debug level message later too?
Quoted 10 lines
drivers/ata/libata-sff.c +6
-0+/* Run the host interrupt logic as if the interrupt had not been +lost */ +ata_sff_host_intr (ap, qc); +} + +/** * ata_sff_freeze - Freeze SFF controller port * @ap: port to freeze *
drivers/ata/libata-sff.c void ata_sff_postreset(struct ata_link *link, unsigned int *classes) · line 2121
Quoted 5 lines
drivers/ata/libata-sff.c +2
-0@@ -2073,6 +2117,39 @@ void ata_sff_postreset(struct ata_link *link, unsigned int *classes) }/** +* ata_sff_drain_fifo - Stock FIFO drain logic for SFF controllers +* @ap: port to drain
There is no @ap argument.
Quoted 17 lines
drivers/ata/libata-sff.c +17
-0+* @qc: command +* +* Drain the FIFO and device of any stuck data following a command +* failing to complete. In some cases this is neccessary before a +* reset will recover the device. +* +*/ + +void ata_sff_drain_fifo (struct ata_queued_cmd *qc) +{ +int count; +struct ata_port *ap; + +/* We only need to flush incoming data when a command was running */ +if (qc ==NULL || qc->dma_dir ==DMA_TO_DEVICE ) +return ; +
drivers/ata/libata-sff.c void ata_sff_postreset(struct ata_link *link, unsigned int *classes) · line 2148
Quoted 10 lines
drivers/ata/libata-sff.c +10
-0+ ap = qc->ap; +/* Drain up to 64K of data before we give up this recovery method */ +for (count =0 ; (ap->ops->sff_check_status (ap) &ATA_DRQ ) + && count <32768 ; count++) +ioread16 (ap->ioaddr.data_addr); + +/* Can become DEBUG later */ +if (count) +ata_port_printk (ap,KERN_WARNING , +"drained %d bytes to clear DRQ.\n" , count);
count * 2
[...]
Quoted 4 lines
drivers/ata/pata_pcmcia.c +0
-0
[...]
drivers/ata/pata_pcmcia.c static unsigned int ata_data_xfer_8bit(struct ata_device *dev, · line 131
Quoted 7 lines
drivers/ata/pata_pcmcia.c +3
-0@@ -126,6 +126,38 @@ static unsigned int ata_data_xfer_8bit(struct ata_device *dev,return buflen; } +/** +* pcmcia_8bit_drain_fifo - Stock FIFO drain logic for SFF controllers +* @ap: port to drain
No argument @ap.
Quoted 9 lines
drivers/ata/pata_pcmcia.c +9
-0+* @qc: command +* +* Drain the FIFO and device of any stuck data following a command +* failing to complete. In some cases this is neccessary before a +* reset will recover the device. +* +*/ + +void pcmcia_8bit_drain_fifo (struct ata_queued_cmd *qc)
Quoted 10 lines
drivers/ata/libata-sff.c irqreturn_t ata_sff_interrupt(int irq, void *dev_instance) · line 1695
Quoted 4 lines
drivers/ata/libata-sff.c +3
-0+ status =ata_sff_altstatus (ap); +if (!(status &ATA_BUSY )) +return ;Shouldn't this rather be
if (status & ATA_BUSY) return;?
Doh yes - I thought I fixed that after debugging it backwards in qemu
Quoted 7 lines
Quoted 4 lines
drivers/ata/libata-sff.c +2
-0+ata_port_printk (ap,KERN_WARNING ,"lost interrupt (Status 0x%x)\n" , + status);From your changelog entry I got the impression that this is known to
happen on various controllers and there is nothing the user or you (kernel developers) can do about it. So, will this become a debug level message later too?
Probably it shouldn't. It occurs but rarely on such boxes and as you get a long pause before the recovery we need to know. It may also be that we eventually should move buggier controllers to run with a parallel sanity checking timer just as networking sometimes does
Quoted 4 lines
Quoted 2 lines
+ *
ata_sff_drain_fifo- Stock FIFO drain logic for SFF controllers
+ * @ap: port to drainThere is no @ap argument.
Good point ;)
Quoted 4 lines
Quoted 2 lines
+ *
pcmcia_8bit_drain_fifo- Stock FIFO drain logic for SFF controllers
+ * @ap: port to drainNo argument @ap.
Ditto - there was one originally ;)
Thanks
Alan
Hello, Alan.
drivers/ata/libata-eh.c void ata_scsi_error(struct Scsi_Host *host) · line 524
Quoted 13 lines · Alan Cox
drivers/ata/libata-eh.c +1
-1@@ -518,7 +518,7 @@ void ata_scsi_error(struct Scsi_Host *host)/* For new EH, all qcs are finished in one of three ways - * normal completion, error completion, and SCSI timeout. -* Both cmpletions can race against SCSI timeout. When normal +* Both completions can race against SCSI timeout. When normal * completion wins, the qc never reaches EH. When error * completion wins, the qc has ATA_QCFLAG_FAILED set. *
Heh.. nice catch.
Quoted 4 lines
drivers/ata/libata-eh.c +0
-0@@ -533,7 +533,19 @@ void ata_scsi_error(struct Scsi_Host *host)int nr_timedout =0 ;spin_lock_irqsave (ap->lock, flags);
drivers/ata/libata-eh.c void ata_scsi_error(struct Scsi_Host *host) · line 544
Quoted 10 lines
drivers/ata/libata-eh.c +9
-1- + +/* This must occur under the ap->lock as we don't want +a polled recovery to race the real interrupt handler ++ The lost_interrupt handler checks for any completed but +non-notified command and completes much like an IRQ handler. ++ We then fall into the error recovery code which will treat +this as if normal completion won the race */
As Elias pointed out, I think it's better to stick with
/* The first line.
* The last line.
*/
as that's what the rest of the libata uses.
drivers/ata/libata-eh.c void ata_scsi_error(struct Scsi_Host *host) · line 550
Quoted 6 lines
drivers/ata/libata-eh.c +4
-0+ +if (ap->ops->lost_interrupt) + ap->ops->lost_interrupt (ap); +list_for_each_entry_safe (scmd, tmp, &host->eh_cmd_q, eh_entry) {struct ata_queued_cmd *qc;
Eh... I really wish this can be folded into ata_sff_error_handler() but, yeah, it's not easy to do as ata_scsi_error() marks commands as timed out before error handler is entered. Hmmm... I think it would be better to do this before entering error handler at all and way before the actual command out triggers but well I guess that's for another day.
Do you mind to separate out this one from the drain changes?
drivers/ata/libata-eh.c void ata_scsi_error(struct Scsi_Host *host) · line 594
Quoted 7 lines
drivers/ata/libata-eh.c +3
-0@@ -577,6 +589,9 @@ void ata_scsi_error(struct Scsi_Host *host) ap->eh_tries =ATA_EH_MAX_TRIES ; }else spin_unlock_wait (ap->lock); + +/* If we timed raced normal completion and there is nothing to +recover nr_timedout == 0 why exactly are we doing error recovery ? */
As it's easier that way and there's no need to optimize anything as we're already knee deep in EH.
drivers/ata/libata-eh.c void ata_scsi_error(struct Scsi_Host *host)
Quoted 4 lines
drivers/ata/libata-eh.c +4
-0+/* There was a command running, we are no longer busy and we have +no interrupt. */ +ata_port_printk (ap,KERN_WARNING ,"lost interrupt (Status 0x%x)\n" , + status);
I sometimes find your indenting style a bit strange but it's equally possible that I'm the weirdo. :-)
drivers/ata/libata-eh.c
Quoted 3 lines
drivers/ata/libata-eh.c +3
-0+/* Run the host interrupt logic as if the interrupt had not been +lost */ +ata_sff_host_intr (ap, qc);
Ah.. we don't have ->irq_handler as port op now but it looks rather strange to call ata_sff_host_intr() directly. Maybe we need a function which takes @irq_handler to call and make ata_sff_lost_interrupt() call it with ata_sff_host_intr()?
Quoted 5 lines
drivers/ata/libata-eh.c +1
-0+/** * ata_sff_error_handler - Stock error handler for BMDMA controller * @ap: port to handle error for *
drivers/ata/libata-eh.c void ata_sff_error_handler(struct ata_port *ap) · line 2209
Quoted 9 lines
drivers/ata/libata-eh.c +6
-0@@ -2124,6 +2201,12 @@ void ata_sff_error_handler(struct ata_port *ap)ata_sff_sync (ap);/* FIXME: We don't need this */ ap->ops->sff_check_status (ap); ap->ops->sff_irq_clear (ap); +/* We *MUST* do FIFO draining before we issue a reset as several +devices helpfully clear their internal state and will lock solid +if we touch the data port post reset. Pass qc in case anyone wants +to do different PIO/DMA recovery or has per command fixups */ +if (ap->ops->drain_fifo) + ap->ops->drain_fifo (qc);
If the mechanism is something which can be universally applied to SFF controllers (SATA ones w/ hardreset usually don't need this BTW), maybe we're better off with providing another flavor of ata_sff_error_handler() instead of adding ->drain_fifo method?
drivers/ata/libata-eh.c void ata_sff_error_handler(struct ata_port *ap) · line 2217
Quoted 7 lines
drivers/ata/libata-eh.c +1
-0spin_unlock_irqrestore (ap->lock, flags);@@ -2131,6 +2214,7 @@ void ata_sff_error_handler(struct ata_port *ap)ata_eh_thaw_port (ap);/* PIO and DMA engines have been stopped, perform recovery */ +
Is this intentional?
Thanks.
Signature · 1 line
tejun