Commit 5bd28a4b authored by Robert Hancock's avatar Robert Hancock Committed by Jeff Garzik

sata_nv: cleanup ADMA error handling

This cleans up a few issues with the error handling in sata_nv in ADMA mode
to make it more consistent with other NCQ-capable drivers like ahci and
sata_sil24:

- When a command failed, we would effectively set AC_ERR_DEV on the
  queued command always.  In the case of NCQ commands this prevents libata
  from doing a log page query to determine the details of the failed
  command, since it thinks we've already analyzed.  Just set flags in the
  port ehi->err_mask, then freeze or abort and let libata figure out what
  went wrong.

- The code handled NV_ADMA_STAT_CPBERR as a "really bad error" which
  caused it to set error flags on every queued command.  I don't know
  exactly what this flag means (no docs, grr!) but from what I can guess
  from the standard ADMA spec, it just means that one or more of the CPBs
  had an error, so we just need to go through and do our normal checks in
  this case.

- In the error_handler function the code would always dump the state of
  all the CPBs.  This output seems redundant at this point since libata
  already dumps the state of all active commands on errors (and it also
  triggers at times when it shouldn't, like when suspending).  Take this
  out.

[akpm@osdl.org: many coding-style fixes]
Signed-off-by: default avatarRobert Hancock <hancockr@shaw.ca>
Cc: Jeff Garzik <jeff@garzik.org>
Cc: Tejun Heo <htejun@gmail.com>
Cc: Allen Martin <AMartin@nvidia.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarJeff Garzik <jeff@garzik.org>
parent 92ae7849
...@@ -651,53 +651,62 @@ static unsigned int nv_adma_tf_to_cpb(struct ata_taskfile *tf, __le16 *cpb) ...@@ -651,53 +651,62 @@ static unsigned int nv_adma_tf_to_cpb(struct ata_taskfile *tf, __le16 *cpb)
return idx; return idx;
} }
static void nv_adma_check_cpb(struct ata_port *ap, int cpb_num, int force_err) static int nv_adma_check_cpb(struct ata_port *ap, int cpb_num, int force_err)
{ {
struct nv_adma_port_priv *pp = ap->private_data; struct nv_adma_port_priv *pp = ap->private_data;
int complete = 0, have_err = 0;
u8 flags = pp->cpb[cpb_num].resp_flags; u8 flags = pp->cpb[cpb_num].resp_flags;
VPRINTK("CPB %d, flags=0x%x\n", cpb_num, flags); VPRINTK("CPB %d, flags=0x%x\n", cpb_num, flags);
if (flags & NV_CPB_RESP_DONE) { if (unlikely((force_err ||
VPRINTK("CPB flags done, flags=0x%x\n", flags); flags & (NV_CPB_RESP_ATA_ERR |
complete = 1; NV_CPB_RESP_CMD_ERR |
} NV_CPB_RESP_CPB_ERR)))) {
if (flags & NV_CPB_RESP_ATA_ERR) { struct ata_eh_info *ehi = &ap->eh_info;
ata_port_printk(ap, KERN_ERR, "CPB flags ATA err, flags=0x%x\n", flags); int freeze = 0;
have_err = 1;
complete = 1; ata_ehi_clear_desc(ehi);
} ata_ehi_push_desc(ehi, "CPB resp_flags 0x%x", flags );
if (flags & NV_CPB_RESP_CMD_ERR) { if (flags & NV_CPB_RESP_ATA_ERR) {
ata_port_printk(ap, KERN_ERR, "CPB flags CMD err, flags=0x%x\n", flags); ata_ehi_push_desc(ehi, ": ATA error");
have_err = 1; ehi->err_mask |= AC_ERR_DEV;
complete = 1; } else if (flags & NV_CPB_RESP_CMD_ERR) {
} ata_ehi_push_desc(ehi, ": CMD error");
if (flags & NV_CPB_RESP_CPB_ERR) { ehi->err_mask |= AC_ERR_DEV;
ata_port_printk(ap, KERN_ERR, "CPB flags CPB err, flags=0x%x\n", flags); } else if (flags & NV_CPB_RESP_CPB_ERR) {
have_err = 1; ata_ehi_push_desc(ehi, ": CPB error");
complete = 1; ehi->err_mask |= AC_ERR_SYSTEM;
freeze = 1;
} else {
/* notifier error, but no error in CPB flags? */
ehi->err_mask |= AC_ERR_OTHER;
freeze = 1;
}
/* Kill all commands. EH will determine what actually failed. */
if (freeze)
ata_port_freeze(ap);
else
ata_port_abort(ap);
return 1;
} }
if(complete || force_err)
{ if (flags & NV_CPB_RESP_DONE) {
struct ata_queued_cmd *qc = ata_qc_from_tag(ap, cpb_num); struct ata_queued_cmd *qc = ata_qc_from_tag(ap, cpb_num);
if(likely(qc)) { VPRINTK("CPB flags done, flags=0x%x\n", flags);
u8 ata_status = 0; if (likely(qc)) {
/* Only use the ATA port status for non-NCQ commands. /* Grab the ATA port status for non-NCQ commands.
For NCQ commands the current status may have nothing to do with For NCQ commands the current status may have nothing to do with
the command just completed. */ the command just completed. */
if(qc->tf.protocol != ATA_PROT_NCQ) if (qc->tf.protocol != ATA_PROT_NCQ) {
ata_status = readb(pp->ctl_block + (ATA_REG_STATUS * 4)); u8 ata_status = readb(pp->ctl_block + (ATA_REG_STATUS * 4));
qc->err_mask |= ac_err_mask(ata_status);
if(have_err || force_err) }
ata_status |= ATA_ERR;
qc->err_mask |= ac_err_mask(ata_status);
DPRINTK("Completing qc from tag %d with err_mask %u\n",cpb_num, DPRINTK("Completing qc from tag %d with err_mask %u\n",cpb_num,
qc->err_mask); qc->err_mask);
ata_qc_complete(qc); ata_qc_complete(qc);
} }
} }
return 0;
} }
static int nv_host_intr(struct ata_port *ap, u8 irq_stat) static int nv_host_intr(struct ata_port *ap, u8 irq_stat)
...@@ -741,7 +750,6 @@ static irqreturn_t nv_adma_interrupt(int irq, void *dev_instance) ...@@ -741,7 +750,6 @@ static irqreturn_t nv_adma_interrupt(int irq, void *dev_instance)
void __iomem *mmio = pp->ctl_block; void __iomem *mmio = pp->ctl_block;
u16 status; u16 status;
u32 gen_ctl; u32 gen_ctl;
int have_global_err = 0;
u32 notifier, notifier_error; u32 notifier, notifier_error;
/* if in ATA register mode, use standard ata interrupt handler */ /* if in ATA register mode, use standard ata interrupt handler */
...@@ -777,42 +785,50 @@ static irqreturn_t nv_adma_interrupt(int irq, void *dev_instance) ...@@ -777,42 +785,50 @@ static irqreturn_t nv_adma_interrupt(int irq, void *dev_instance)
readw(mmio + NV_ADMA_STAT); /* flush posted write */ readw(mmio + NV_ADMA_STAT); /* flush posted write */
rmb(); rmb();
/* freeze if hotplugged */ handled++; /* irq handled if we got here */
if (unlikely(status & (NV_ADMA_STAT_HOTPLUG | NV_ADMA_STAT_HOTUNPLUG))) {
ata_port_printk(ap, KERN_NOTICE, "Hotplug event, freezing\n"); /* freeze if hotplugged or controller error */
if (unlikely(status & (NV_ADMA_STAT_HOTPLUG |
NV_ADMA_STAT_HOTUNPLUG |
NV_ADMA_STAT_TIMEOUT))) {
struct ata_eh_info *ehi = &ap->eh_info;
ata_ehi_clear_desc(ehi);
ata_ehi_push_desc(ehi, "ADMA status 0x%08x", status );
if (status & NV_ADMA_STAT_TIMEOUT) {
ehi->err_mask |= AC_ERR_SYSTEM;
ata_ehi_push_desc(ehi, ": timeout");
} else if (status & NV_ADMA_STAT_HOTPLUG) {
ata_ehi_hotplugged(ehi);
ata_ehi_push_desc(ehi, ": hotplug");
} else if (status & NV_ADMA_STAT_HOTUNPLUG) {
ata_ehi_hotplugged(ehi);
ata_ehi_push_desc(ehi, ": hot unplug");
}
ata_port_freeze(ap); ata_port_freeze(ap);
handled++;
continue; continue;
} }
if (status & NV_ADMA_STAT_TIMEOUT) { if (status & (NV_ADMA_STAT_DONE |
ata_port_printk(ap, KERN_ERR, "timeout, stat=0x%x\n", status); NV_ADMA_STAT_CPBERR)) {
have_global_err = 1;
}
if (status & NV_ADMA_STAT_CPBERR) {
ata_port_printk(ap, KERN_ERR, "CPB error, stat=0x%x\n", status);
have_global_err = 1;
}
if ((status & NV_ADMA_STAT_DONE) || have_global_err) {
/** Check CPBs for completed commands */ /** Check CPBs for completed commands */
if(ata_tag_valid(ap->active_tag)) if (ata_tag_valid(ap->active_tag)) {
/* Non-NCQ command */ /* Non-NCQ command */
nv_adma_check_cpb(ap, ap->active_tag, have_global_err || nv_adma_check_cpb(ap, ap->active_tag,
(notifier_error & (1 << ap->active_tag))); notifier_error & (1 << ap->active_tag));
else { } else {
int pos; int pos, error = 0;
u32 active = ap->sactive; u32 active = ap->sactive;
while( (pos = ffs(active)) ) {
while ((pos = ffs(active)) && !error) {
pos--; pos--;
nv_adma_check_cpb(ap, pos, have_global_err || error = nv_adma_check_cpb(ap, pos,
(notifier_error & (1 << pos)) ); notifier_error & (1 << pos) );
active &= ~(1 << pos ); active &= ~(1 << pos );
} }
} }
} }
handled++; /* irq handled if we got here */
} }
} }
...@@ -1372,28 +1388,9 @@ static void nv_adma_error_handler(struct ata_port *ap) ...@@ -1372,28 +1388,9 @@ static void nv_adma_error_handler(struct ata_port *ap)
int i; int i;
u16 tmp; u16 tmp;
u32 notifier = readl(mmio + NV_ADMA_NOTIFIER);
u32 notifier_error = readl(mmio + NV_ADMA_NOTIFIER_ERROR);
u32 gen_ctl = readl(pp->gen_block + NV_ADMA_GEN_CTL);
u32 status = readw(mmio + NV_ADMA_STAT);
ata_port_printk(ap, KERN_ERR, "EH in ADMA mode, notifier 0x%X "
"notifier_error 0x%X gen_ctl 0x%X status 0x%X\n",
notifier, notifier_error, gen_ctl, status);
for( i=0;i<NV_ADMA_MAX_CPBS;i++) {
struct nv_adma_cpb *cpb = &pp->cpb[i];
if( cpb->ctl_flags || cpb->resp_flags )
ata_port_printk(ap, KERN_ERR,
"CPB %d: ctl_flags 0x%x, resp_flags 0x%x\n",
i, cpb->ctl_flags, cpb->resp_flags);
}
/* Push us back into port register mode for error handling. */ /* Push us back into port register mode for error handling. */
nv_adma_register_mode(ap); nv_adma_register_mode(ap);
ata_port_printk(ap, KERN_ERR, "Resetting port\n");
/* Mark all of the CPBs as invalid to prevent them from being executed */ /* Mark all of the CPBs as invalid to prevent them from being executed */
for( i=0;i<NV_ADMA_MAX_CPBS;i++) for( i=0;i<NV_ADMA_MAX_CPBS;i++)
pp->cpb[i].ctl_flags &= ~NV_CPB_CTL_CPB_VALID; pp->cpb[i].ctl_flags &= ~NV_CPB_CTL_CPB_VALID;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment