libata: improve 0xff status handling

For PATA, 0xff status indicates empty port.  For SATA, it depends on
how the controller emulates status register.  On some controllers,
0xff is used to represent broken link or certain stage during reset.

libata currently deals SATA the same.  This hasn't caused any problem
because problematic situations usually only occur after hotplug or
other link disruption events and libata blindly waited for the device
to spin up and settle after hotplug giving the link and device
whatever time to go through those stages.

libata is going to replace unconditional spinup wait with generic
timed sequence of resets, so not only getting 0xff handling right for
SATA is, well, the right thing to do, it's much more important now.

This patch makes the following changes.

* Make ata_bus_softreset() return -ENODEV if any of its wait fails
  due to 0xff status.

* Fail soft/hardreset if status wait returns -ENODEV indicating 0xff
  status while SStatus says the link is online.  e.g. Reset fails if
  status is 0xff after reset when SStatus reports the linke is online.
  If SCR registers are not available, everything is the same as
  before.

Signed-off-by: Tejun Heo <htejun@gmail.com>
Signed-off-by: Jeff Garzik <jeff@garzik.org>
This commit is contained in:
Tejun Heo 2007-02-02 16:50:52 +09:00 committed by Jeff Garzik
parent d4b2bab4f2
commit 9b89391cc8
3 changed files with 30 additions and 20 deletions

View File

@ -960,15 +960,13 @@ static int ahci_softreset(struct ata_port *ap, unsigned int *class,
*/ */
msleep(150); msleep(150);
*class = ATA_DEV_NONE; rc = ata_wait_ready(ap, deadline);
if (ata_port_online(ap)) { /* link occupied, -ENODEV too is an error */
rc = ata_wait_ready(ap, deadline); if (rc) {
if (rc && rc != -ENODEV) { reason = "device not ready";
reason = "device not ready"; goto fail;
goto fail;
}
*class = ahci_dev_classify(ap);
} }
*class = ahci_dev_classify(ap);
DPRINTK("EXIT, class=%u\n", *class); DPRINTK("EXIT, class=%u\n", *class);
return 0; return 0;

View File

@ -3027,15 +3027,18 @@ static int ata_bus_post_reset(struct ata_port *ap, unsigned int devmask,
struct ata_ioports *ioaddr = &ap->ioaddr; struct ata_ioports *ioaddr = &ap->ioaddr;
unsigned int dev0 = devmask & (1 << 0); unsigned int dev0 = devmask & (1 << 0);
unsigned int dev1 = devmask & (1 << 1); unsigned int dev1 = devmask & (1 << 1);
int rc; int rc, ret = 0;
/* if device 0 was found in ata_devchk, wait for its /* if device 0 was found in ata_devchk, wait for its
* BSY bit to clear * BSY bit to clear
*/ */
if (dev0) { if (dev0) {
rc = ata_wait_ready(ap, deadline); rc = ata_wait_ready(ap, deadline);
if (rc && rc != -ENODEV) if (rc) {
return rc; if (rc != -ENODEV)
return rc;
ret = rc;
}
} }
/* if device 1 was found in ata_devchk, wait for /* if device 1 was found in ata_devchk, wait for
@ -3055,8 +3058,11 @@ static int ata_bus_post_reset(struct ata_port *ap, unsigned int devmask,
} }
if (dev1) { if (dev1) {
rc = ata_wait_ready(ap, deadline); rc = ata_wait_ready(ap, deadline);
if (rc && rc != -ENODEV) if (rc) {
return rc; if (rc != -ENODEV)
return rc;
ret = rc;
}
} }
/* is all this really necessary? */ /* is all this really necessary? */
@ -3066,7 +3072,7 @@ static int ata_bus_post_reset(struct ata_port *ap, unsigned int devmask,
if (dev0) if (dev0)
ap->ops->dev_select(ap, 0); ap->ops->dev_select(ap, 0);
return 0; return ret;
} }
static int ata_bus_softreset(struct ata_port *ap, unsigned int devmask, static int ata_bus_softreset(struct ata_port *ap, unsigned int devmask,
@ -3100,7 +3106,7 @@ static int ata_bus_softreset(struct ata_port *ap, unsigned int devmask,
* pulldown resistor. * pulldown resistor.
*/ */
if (ata_check_status(ap) == 0xFF) if (ata_check_status(ap) == 0xFF)
return 0; return -ENODEV;
return ata_bus_post_reset(ap, devmask, deadline); return ata_bus_post_reset(ap, devmask, deadline);
} }
@ -3131,6 +3137,7 @@ void ata_bus_reset(struct ata_port *ap)
unsigned int slave_possible = ap->flags & ATA_FLAG_SLAVE_POSS; unsigned int slave_possible = ap->flags & ATA_FLAG_SLAVE_POSS;
u8 err; u8 err;
unsigned int dev0, dev1 = 0, devmask = 0; unsigned int dev0, dev1 = 0, devmask = 0;
int rc;
DPRINTK("ENTER, host %u, port %u\n", ap->print_id, ap->port_no); DPRINTK("ENTER, host %u, port %u\n", ap->print_id, ap->port_no);
@ -3152,9 +3159,11 @@ void ata_bus_reset(struct ata_port *ap)
ap->ops->dev_select(ap, 0); ap->ops->dev_select(ap, 0);
/* issue bus reset */ /* issue bus reset */
if (ap->flags & ATA_FLAG_SRST) if (ap->flags & ATA_FLAG_SRST) {
if (ata_bus_softreset(ap, devmask, jiffies + 40 * HZ)) rc = ata_bus_softreset(ap, devmask, jiffies + 40 * HZ);
if (rc && rc != -ENODEV)
goto err_out; goto err_out;
}
/* /*
* determine by signature whether we have ATA or ATAPI devices * determine by signature whether we have ATA or ATAPI devices
@ -3417,7 +3426,8 @@ int ata_std_softreset(struct ata_port *ap, unsigned int *classes,
/* issue bus reset */ /* issue bus reset */
DPRINTK("about to softreset, devmask=%x\n", devmask); DPRINTK("about to softreset, devmask=%x\n", devmask);
rc = ata_bus_softreset(ap, devmask, deadline); rc = ata_bus_softreset(ap, devmask, deadline);
if (rc) { /* if link is occupied, -ENODEV too is an error */
if (rc && (rc != -ENODEV || sata_scr_valid(ap))) {
ata_port_printk(ap, KERN_ERR, "SRST failed (errno=%d)\n", rc); ata_port_printk(ap, KERN_ERR, "SRST failed (errno=%d)\n", rc);
return rc; return rc;
} }
@ -3534,7 +3544,8 @@ int sata_std_hardreset(struct ata_port *ap, unsigned int *class,
msleep(150); msleep(150);
rc = ata_wait_ready(ap, deadline); rc = ata_wait_ready(ap, deadline);
if (rc && rc != -ENODEV) { /* link occupied, -ENODEV too is an error */
if (rc) {
ata_port_printk(ap, KERN_ERR, ata_port_printk(ap, KERN_ERR,
"COMRESET failed (errno=%d)\n", rc); "COMRESET failed (errno=%d)\n", rc);
return rc; return rc;

View File

@ -453,7 +453,8 @@ static int inic_hardreset(struct ata_port *ap, unsigned int *class,
msleep(150); msleep(150);
rc = ata_wait_ready(ap, deadline); rc = ata_wait_ready(ap, deadline);
if (rc && rc != -ENODEV) { /* link occupied, -ENODEV too is an error */
if (rc) {
ata_port_printk(ap, KERN_WARNING, "device not ready " ata_port_printk(ap, KERN_WARNING, "device not ready "
"after hardreset (errno=%d)\n", rc); "after hardreset (errno=%d)\n", rc);
return rc; return rc;