improve libata error handling
PATCH 1/1 improve libata error handling
This patch experiments with making the second arg to ata_qc_complete() a mask of error classes. Not committing this (at least not verbatim).
drivers/scsi/ahci.c +7 -3
@@ -609,7 +609,8 @@ static void ahci_eng_timeout(struct ata_* not being called from the SCSI EH. */ qc->scsidone = scsi_finish_command; -ata_qc_complete (qc,ATA_ERR ); + qc->tf.command =ATA_BUSY ; +ata_qc_complete (qc,AC_ERR_UNKNOWN ); }spin_unlock_irqrestore (&host_set->lock, flags);
@@ -630,6 +631,7 @@ static inline int ahci_host_intr(struct ci =readl (port_mmio +PORT_CMD_ISSUE );if (likely ((ci &0x1 ) ==0 )) {if (qc) { + qc->tf.command =ahci_check_status (ap);ata_qc_complete (qc,0 ); qc =NULL ; }
@@ -637,8 +639,10 @@ static inline int ahci_host_intr(structif (status &PORT_IRQ_FATAL ) {ahci_intr_error (ap, status); -if (qc) -ata_qc_complete (qc,ATA_ERR ); +if (qc) { + qc->tf.command =ahci_check_status (ap); +ata_qc_complete (qc,AC_ERR_UNKNOWN ); + } }return 1 ;
drivers/scsi/libata-core.c +26 -21
160 lines not on this page · raw message
drivers/scsi/libata-scsi.c +12 -12
@@ -1199,10 +1199,10 @@ nothing_to_do:return 1 ; } -static int ata_scsi_qc_complete (struct ata_queued_cmd *qc,u8 drv_stat) +static int ata_scsi_qc_complete (struct ata_queued_cmd *qc,unsigned int err_mask) {struct scsi_cmnd *cmd = qc->scsicmd; -int need_sense = drv_stat & (ATA_ERR |ATA_BUSY |ATA_DRQ ); +int need_sense = (err_mask &AC_ERR_ALL );/* For ATA pass thru (SAT) commands, generate a sense block if * user mandated it or if there's an error. Note that if we
@@ -1995,21 +1995,13 @@ void atapi_request_sense(struct ata_portDPRINTK ("EXIT\n" ); } -static int atapi_qc_complete (struct ata_queued_cmd *qc,u8 drv_stat) +static int atapi_qc_complete (struct ata_queued_cmd *qc,unsigned int err_mask) {struct scsi_cmnd *cmd = qc->scsicmd;VPRINTK ("ENTER, drv_stat == 0x%x\n" , drv_stat); -if (unlikely (drv_stat & (ATA_BUSY |ATA_DRQ ))) -/* FIXME: not quite right; we don't want the -* translation of taskfile registers into -* a sense descriptors, since that's only -* correct for ATA, not ATAPI -*/ -ata_gen_ata_desc_sense (qc); - -else if (unlikely (drv_stat &ATA_ERR )) { +if (unlikely (err_mask &AC_ERR_DEV )) {DPRINTK ("request check condition\n" );/* FIXME: command completion with check condition
@@ -2026,6 +2018,14 @@ static int atapi_qc_complete(struct ata_return 1 ; } +else if (unlikely (err_mask)) +/* FIXME: not quite right; we don't want the +* translation of taskfile registers into +* a sense descriptors, since that's only +* correct for ATA, not ATAPI +*/ +ata_gen_ata_desc_sense (qc); +else {u8 *scsicmd = cmd->cmnd;
drivers/scsi/libata.h +1 -1
@@ -39,7 +39,7 @@ struct ata_scsi_args {/* libata-core.c */ extern int atapi_enabled; -extern int ata_qc_complete_noop (struct ata_queued_cmd *qc,u8 drv_stat); +extern int ata_qc_complete_noop (struct ata_queued_cmd *qc,unsigned int err_mask);extern struct ata_queued_cmd *ata_qc_new_init (struct ata_port *ap,struct ata_device *dev);extern void ata_rwcmd_protocol (struct ata_queued_cmd *qc);
drivers/scsi/pdc_adma.c +10 -4
@@ -464,11 +464,16 @@ static inline unsigned int adma_intr_pktcontinue ; qc =ata_qc_from_tag (ap, ap->active_tag);if (qc && (!(qc->tf.ctl &ATA_NIEN ))) { +unsigned int err_mask =0 ; +if ((status & (aPERR | aPSD | aUIRQ))) - drv_stat =ATA_ERR ; + err_mask |=AC_ERR_DEV ;else if (pp->pkt[0 ] != cDONE) - drv_stat =ATA_ERR ; -ata_qc_complete (qc, drv_stat); + err_mask |=AC_ERR_UNKNOWN ; + + qc->tf.command = drv_stat; + err_mask |=ata_stat_err_mask (drv_stat); +ata_qc_complete (qc, err_mask); } }return handled;
@@ -498,7 +503,8 @@ static inline unsigned int adma_intr_mmi/* complete taskfile transaction */ pp->state = adma_state_idle; -ata_qc_complete (qc, status); + qc->tf.command = status; +ata_qc_complete (qc,ata_stat_err_mask (status)); handled =1 ; } }
drivers/scsi/sata_mv.c +10 -5
@@ -1068,6 +1068,7 @@ static void mv_host_intr(struct ata_hostu32 hc_irq_cause;int shift, port, port0, hard_port, handled;u8 ata_status =0 ; +unsigned int err_mask;if (hc ==0 ) { port0 =0 ;
@@ -1088,6 +1089,7 @@ static void mv_host_intr(struct ata_host ap = host_set->ports[port]; hard_port = port &MV_PORT_MASK ;/* range 0-3 */ handled =0 ;/* ensure ata_status is set if handled++ */ + err_mask =0 ;if ((CRPB_DMA_DONE << hard_port) & hc_irq_cause) {/* new CRPB on the queue; just one at a time until NCQ
@@ -1108,9 +1110,7 @@ static void mv_host_intr(struct ata_host }if ((PORT0_ERR << shift) & relevant) {mv_err_intr (ap); -/* OR in ATA_ERR to ensure libata knows we took one */ - ata_status =readb ((void __iomem *) - ap->ioaddr.status_addr) |ATA_ERR ; + err_mask |=AC_ERR_UNKNOWN ; handled++; }
@@ -1120,7 +1120,11 @@ static void mv_host_intr(struct ata_hostVPRINTK ("port %u IRQ found for qc, " "ata_status 0x%x\n" , port,ata_status);/* mark qc status appropriately */ -ata_qc_complete (qc, ata_status); + qc->tf.command = ata_status; +ata_qc_complete (qc, +ata_stat_err_mask (ata_status) | + err_mask); + } } }
@@ -1312,7 +1316,8 @@ static void mv_eng_timeout(struct ata_po*/ spin_lock_irqsave (&ap->host_set->lock, flags); qc->scsidone = scsi_finish_command; -ata_qc_complete (qc,ATA_ERR ); + qc->tf.command =ATA_BUSY ; +ata_qc_complete (qc,AC_ERR_UNKNOWN );spin_unlock_irqrestore (&ap->host_set->lock, flags); } }
drivers/scsi/sata_promise.c +7 -6
@@ -399,7 +399,8 @@ static void pdc_eng_timeout(struct ata_pcase ATA_PROT_DMA :case ATA_PROT_NODATA :printk (KERN_ERR "ata%u: command timeout\n" , ap->id); -ata_qc_complete (qc,ata_wait_idle (ap) |ATA_ERR ); + qc->tf.command =ATA_BUSY ; +ata_qc_complete (qc,AC_ERR_UNKNOWN );break ;default :
@@ -408,7 +409,8 @@ static void pdc_eng_timeout(struct ata_pprintk (KERN_ERR "ata%u: unknown timeout, cmd 0x%x stat 0x%x\n" , ap->id, qc->tf.command, drv_stat); -ata_qc_complete (qc, drv_stat); + qc->tf.command = drv_stat; +ata_qc_complete (qc,AC_ERR_UNKNOWN );break ; }
@@ -427,7 +429,7 @@ static inline unsigned int pdc_host_intr tmp =readl (mmio);if (tmp &PDC_ERR_MASK ) { - have_err =1 ; + have_err =AC_ERR_UNKNOWN ;pdc_reset_port (ap); }
@@ -435,9 +437,8 @@ static inline unsigned int pdc_host_intrcase ATA_PROT_DMA :case ATA_PROT_NODATA : status =ata_wait_idle (ap); -if (have_err) - status |=ATA_ERR ; -ata_qc_complete (qc, status); + qc->tf.command = status; +ata_qc_complete (qc,ata_stat_err_mask (status) | have_err); handled =1 ;break ;
drivers/scsi/sata_qstor.c +9 -3
@@ -399,12 +399,17 @@ static inline unsigned int qs_intr_pkt(scontinue ; qc =ata_qc_from_tag (ap, ap->active_tag);if (qc && (!(qc->tf.ctl &ATA_NIEN ))) { +unsigned int err_mask =0 ;switch (sHST) { -case 0 :/* sucessful CPB */ case 3 :/* device error */ + err_mask =AC_ERR_DEV ; +case 0 :/* successful CPB */ pp->state = qs_state_idle;qs_enter_reg_mode (qc->ap); -ata_qc_complete (qc, sDST); + err_mask |= +ata_stat_err_mask (sDST); + qc->tf.command = sDST; +ata_qc_complete (qc, err_mask);break ;default :break ;
@@ -441,7 +446,8 @@ static inline unsigned int qs_intr_mmio(/* complete taskfile transaction */ pp->state = qs_state_idle; -ata_qc_complete (qc, status); + qc->tf.command = status; +ata_qc_complete (qc,ata_stat_err_mask (status)); handled =1 ; } }
drivers/scsi/sata_sil24.c +9 -4
@@ -518,7 +518,8 @@ static void sil24_eng_timeout(struct ata*/ printk (KERN_ERR "ata%u: command timeout\n" , ap->id); qc->scsidone = scsi_finish_command; -ata_qc_complete (qc,ATA_ERR ); + qc->tf.command =ATA_BUSY ; +ata_qc_complete (qc,AC_ERR_UNKNOWN );sil24_reset_controller (ap); }
@@ -529,6 +530,7 @@ static void sil24_error_intr(struct ata_struct sil24_port_priv *pp = ap->private_data;void *port = (void *)ap->ioaddr.cmd_addr;u32 irq_stat, cmd_err, sstatus, serror; +unsigned int err_mask =0 ; irq_stat =readl (port +PORT_IRQ_STAT );writel (irq_stat, port +PORT_IRQ_STAT );/* clear irq */
@@ -556,17 +558,20 @@ static void sil24_error_intr(struct ata_* Device is reporting error, tf registers are valid. */ sil24_update_tf (ap); + err_mask =ata_stat_err_mask (pp->tf.command); + qc->tf.command = pp->tf.command; }else {/* * Other errors. libata currently doesn't have any * mechanism to report these errors. Just turn on * ATA_ERR. */ - pp->tf.command =ATA_ERR ; + qc->tf.command =ATA_BUSY ; + err_mask =AC_ERR_UNKNOWN ; }if (qc) -ata_qc_complete (qc, pp->tf.command); +ata_qc_complete (qc, err_mask);sil24_reset_controller (ap); }
@@ -591,7 +596,7 @@ static inline void sil24_host_intr(strucsil24_update_tf (ap);if (qc) -ata_qc_complete (qc, pp->tf.command); +ata_qc_complete (qc,ata_stat_err_mask (pp->tf.command)); }else sil24_error_intr (ap, slot_stat); }
drivers/scsi/sata_sx4.c +12 -5
@@ -718,7 +718,9 @@ static inline unsigned int pdc20621_hostVPRINTK ("ata%u: read hdma, 0x%x 0x%x\n" , ap->id,readl (mmio +0x104 ),readl (mmio +PDC_HDMA_CTLSTAT ));/* get drive status; clear intr; complete txn */ -ata_qc_complete (qc,ata_wait_idle (ap)); + status =ata_wait_idle (ap); + qc->tf.command = status; +ata_qc_complete (qc,ata_stat_err_mask (status));pdc20621_pop_hdma (qc); }
@@ -756,7 +758,9 @@ static inline unsigned int pdc20621_hostVPRINTK ("ata%u: write ata, 0x%x 0x%x\n" , ap->id,readl (mmio +0x104 ),readl (mmio +PDC_HDMA_CTLSTAT ));/* get drive status; clear intr; complete txn */ -ata_qc_complete (qc,ata_wait_idle (ap)); + status =ata_wait_idle (ap); + qc->tf.command = status; +ata_qc_complete (qc,ata_stat_err_mask (status));pdc20621_pop_hdma (qc); } handled =1 ;
@@ -766,7 +770,8 @@ static inline unsigned int pdc20621_host status =ata_busy_wait (ap,ATA_BUSY |ATA_DRQ ,1000 );DPRINTK ("BUS_NODATA (drv_stat 0x%X)\n" , status); -ata_qc_complete (qc, status); + qc->tf.command = status; +ata_qc_complete (qc,ata_stat_err_mask (status)); handled =1 ; }else {
@@ -881,7 +886,8 @@ static void pdc_eng_timeout(struct ata_pcase ATA_PROT_DMA :case ATA_PROT_NODATA :printk (KERN_ERR "ata%u: command timeout\n" , ap->id); -ata_qc_complete (qc,ata_wait_idle (ap) |ATA_ERR ); + qc->tf.command =ATA_BUSY ; +ata_qc_complete (qc,AC_ERR_UNKNOWN );break ;default :
@@ -890,7 +896,8 @@ static void pdc_eng_timeout(struct ata_pprintk (KERN_ERR "ata%u: unknown timeout, cmd 0x%x stat 0x%x\n" , ap->id, qc->tf.command, drv_stat); -ata_qc_complete (qc, drv_stat); + qc->tf.command = drv_stat; +ata_qc_complete (qc,AC_ERR_UNKNOWN );break ; }
include/linux/libata.h +21 -2
@@ -172,6 +172,16 @@ enum hsm_task_states { HSM_ST_ERR, }; +enum ata_err_mask { +AC_ERR_UNKNOWN = (1 <<0 ), +AC_ERR_DEV = (1 <<1 ), +AC_ERR_ATA_BUS = (1 <<2 ), +AC_ERR_HOST_BUS = (1 <<3 ), + +AC_ERR_ALL =AC_ERR_UNKNOWN |AC_ERR_DEV | +AC_ERR_ATA_BUS |AC_ERR_HOST_BUS , +}; +/* forward declarations */ struct scsi_device ;struct ata_port_operations ;
@@ -179,7 +189,7 @@ struct ata_port;struct ata_queued_cmd ;/* typedefs */ -typedef int (*ata_qc_cb_t ) (struct ata_queued_cmd *qc,u8 drv_stat); +typedef int (*ata_qc_cb_t ) (struct ata_queued_cmd *qc,unsigned int err_mask);struct ata_ioports {unsigned long cmd_addr;
@@ -455,7 +465,7 @@ extern void ata_bmdma_start (struct ata_extern void ata_bmdma_stop (struct ata_queued_cmd *qc);extern u8 ata_bmdma_status (struct ata_port *ap);extern void ata_bmdma_irq_clear (struct ata_port *ap); -extern void ata_qc_complete (struct ata_queued_cmd *qc,u8 drv_stat); +extern void ata_qc_complete (struct ata_queued_cmd *qc,unsigned int err_mask);extern void ata_eng_timeout (struct ata_port *ap);extern void ata_scsi_simulate (u16 *id,struct scsi_cmnd *cmd,void (*done)(struct scsi_cmnd *));
@@ -718,4 +728,13 @@ static inline int ata_try_flush_cache(co ata_id_has_flush_ext(dev->id); } +static inline unsigned int ata_stat_err_mask (u8 stat) +{ +if (stat &ATA_BUSY ) +return AC_ERR_ATA_BUS ; +if (stat & (ATA_ERR |ATA_DF )) +return AC_ERR_DEV ; +return 0 ; +} +#endif /* __LINUX_LIBATA_H__ */