libata-link: update EH to deal with PMP links

Update ata_eh_autopsy(), ata_eh_report(),
ata_eh_revalidate_and_attach() and ata_eh_recover() to deal with PMP
links.  ata_eh_autopsy() and ata_eh_report() updates are
straightforward.  They just repeat the same operation over all
configured links.  The only change to ata_eh_revalidate_and_attach()
is avoiding calling ->cable_select() on non-host ports.

ata_eh_recover() update is more complex as it first processes all
resets and then performs the rest.  This is necessary as thawing with
some links in unknown state can be dangerous.  ehi->action is cleared
on successful recovery of a link to avoid repeating recovery due to
failures in other links.

ata_eh_recover() iterates over only PMP links if PMP is attached, and,
on failure, the failing link is returned in @failed_link instead of
disabling devices directly.  These are to integrate ata_eh_recover()
into PMP EH later.

Signed-off-by: Tejun Heo <htejun@gmail.com>
Signed-off-by: Jeff Garzik <jeff@garzik.org>
This commit is contained in:
Tejun Heo 2007-08-06 18:36:24 +09:00 committed by Jeff Garzik
parent cf1b86c8ab
commit 9b1e2658fa
1 changed files with 158 additions and 70 deletions

View File

@ -1578,8 +1578,8 @@ static unsigned int ata_eh_speed_down(struct ata_device *dev, int is_io,
} }
/** /**
* ata_eh_autopsy - analyze error and determine recovery action * ata_eh_link_autopsy - analyze error and determine recovery action
* @link: ATA link to perform autopsy on * @link: host link to perform autopsy on
* *
* Analyze why @link failed and determine which recovery actions * Analyze why @link failed and determine which recovery actions
* are needed. This function also sets more detailed AC_ERR_* * are needed. This function also sets more detailed AC_ERR_*
@ -1588,7 +1588,7 @@ static unsigned int ata_eh_speed_down(struct ata_device *dev, int is_io,
* LOCKING: * LOCKING:
* Kernel thread context (may sleep). * Kernel thread context (may sleep).
*/ */
static void ata_eh_autopsy(struct ata_link *link) static void ata_eh_link_autopsy(struct ata_link *link)
{ {
struct ata_port *ap = link->ap; struct ata_port *ap = link->ap;
struct ata_eh_context *ehc = &link->eh_context; struct ata_eh_context *ehc = &link->eh_context;
@ -1680,7 +1680,25 @@ static void ata_eh_autopsy(struct ata_link *link)
} }
/** /**
* ata_eh_report - report error handling to user * ata_eh_autopsy - analyze error and determine recovery action
* @ap: host port to perform autopsy on
*
* Analyze all links of @ap and determine why they failed and
* which recovery actions are needed.
*
* LOCKING:
* Kernel thread context (may sleep).
*/
static void ata_eh_autopsy(struct ata_port *ap)
{
struct ata_link *link;
__ata_port_for_each_link(link, ap)
ata_eh_link_autopsy(link);
}
/**
* ata_eh_link_report - report error handling to user
* @link: ATA link EH is going on * @link: ATA link EH is going on
* *
* Report EH to user. * Report EH to user.
@ -1688,7 +1706,7 @@ static void ata_eh_autopsy(struct ata_link *link)
* LOCKING: * LOCKING:
* None. * None.
*/ */
static void ata_eh_report(struct ata_link *link) static void ata_eh_link_report(struct ata_link *link)
{ {
struct ata_port *ap = link->ap; struct ata_port *ap = link->ap;
struct ata_eh_context *ehc = &link->eh_context; struct ata_eh_context *ehc = &link->eh_context;
@ -1767,6 +1785,23 @@ static void ata_eh_report(struct ata_link *link)
} }
} }
/**
* ata_eh_report - report error handling to user
* @ap: ATA port to report EH about
*
* Report EH to user.
*
* LOCKING:
* None.
*/
static void ata_eh_report(struct ata_port *ap)
{
struct ata_link *link;
__ata_port_for_each_link(link, ap)
ata_eh_link_report(link);
}
static int ata_do_reset(struct ata_link *link, ata_reset_fn_t reset, static int ata_do_reset(struct ata_link *link, ata_reset_fn_t reset,
unsigned int *classes, unsigned long deadline) unsigned int *classes, unsigned long deadline)
{ {
@ -2036,7 +2071,8 @@ static int ata_eh_revalidate_and_attach(struct ata_link *link,
} }
/* PDIAG- should have been released, ask cable type if post-reset */ /* PDIAG- should have been released, ask cable type if post-reset */
if ((ehc->i.flags & ATA_EHI_DID_RESET) && ap->ops->cable_detect) if (ata_is_host_link(link) && ap->ops->cable_detect &&
(ehc->i.flags & ATA_EHI_DID_RESET))
ap->cbl = ap->ops->cable_detect(ap); ap->cbl = ap->ops->cable_detect(ap);
/* Configure new devices forward such that user doesn't see /* Configure new devices forward such that user doesn't see
@ -2110,7 +2146,7 @@ static int ata_eh_skip_recovery(struct ata_link *link)
return 1; return 1;
} }
static void ata_eh_handle_dev_fail(struct ata_device *dev, int err) static int ata_eh_handle_dev_fail(struct ata_device *dev, int err)
{ {
struct ata_eh_context *ehc = &dev->link->eh_context; struct ata_eh_context *ehc = &dev->link->eh_context;
@ -2151,12 +2187,16 @@ static void ata_eh_handle_dev_fail(struct ata_device *dev, int err)
ehc->did_probe_mask |= (1 << dev->devno); ehc->did_probe_mask |= (1 << dev->devno);
ehc->i.action |= ATA_EH_SOFTRESET; ehc->i.action |= ATA_EH_SOFTRESET;
} }
return 1;
} else { } else {
/* soft didn't work? be haaaaard */ /* soft didn't work? be haaaaard */
if (ehc->i.flags & ATA_EHI_DID_RESET) if (ehc->i.flags & ATA_EHI_DID_RESET)
ehc->i.action |= ATA_EH_HARDRESET; ehc->i.action |= ATA_EH_HARDRESET;
else else
ehc->i.action |= ATA_EH_SOFTRESET; ehc->i.action |= ATA_EH_SOFTRESET;
return 0;
} }
} }
@ -2167,12 +2207,13 @@ static void ata_eh_handle_dev_fail(struct ata_device *dev, int err)
* @softreset: softreset method (can be NULL) * @softreset: softreset method (can be NULL)
* @hardreset: hardreset method (can be NULL) * @hardreset: hardreset method (can be NULL)
* @postreset: postreset method (can be NULL) * @postreset: postreset method (can be NULL)
* @r_failed_link: out parameter for failed link
* *
* This is the alpha and omega, eum and yang, heart and soul of * This is the alpha and omega, eum and yang, heart and soul of
* libata exception handling. On entry, actions required to * libata exception handling. On entry, actions required to
* recover the port and hotplug requests are recorded in * recover each link and hotplug requests are recorded in the
* eh_context. This function executes all the operations with * link's eh_context. This function executes all the operations
* appropriate retrials and fallbacks to resurrect failed * with appropriate retrials and fallbacks to resurrect failed
* devices, detach goners and greet newcomers. * devices, detach goners and greet newcomers.
* *
* LOCKING: * LOCKING:
@ -2183,101 +2224,138 @@ static void ata_eh_handle_dev_fail(struct ata_device *dev, int err)
*/ */
static int ata_eh_recover(struct ata_port *ap, ata_prereset_fn_t prereset, static int ata_eh_recover(struct ata_port *ap, ata_prereset_fn_t prereset,
ata_reset_fn_t softreset, ata_reset_fn_t hardreset, ata_reset_fn_t softreset, ata_reset_fn_t hardreset,
ata_postreset_fn_t postreset) ata_postreset_fn_t postreset,
struct ata_link **r_failed_link)
{ {
struct ata_link *link = &ap->link; struct ata_link *link;
struct ata_eh_context *ehc = &link->eh_context;
struct ata_device *dev; struct ata_device *dev;
int rc; int nr_failed_devs, nr_disabled_devs;
int reset, rc;
DPRINTK("ENTER\n"); DPRINTK("ENTER\n");
/* prep for recovery */ /* prep for recovery */
ata_link_for_each_dev(dev, link) { ata_port_for_each_link(link, ap) {
ehc->tries[dev->devno] = ATA_EH_DEV_TRIES; struct ata_eh_context *ehc = &link->eh_context;
/* collect port action mask recorded in dev actions */ ata_link_for_each_dev(dev, link) {
ehc->i.action |= ehc->tries[dev->devno] = ATA_EH_DEV_TRIES;
ehc->i.dev_action[dev->devno] & ~ATA_EH_PERDEV_MASK;
ehc->i.dev_action[dev->devno] &= ATA_EH_PERDEV_MASK;
/* process hotplug request */ /* collect port action mask recorded in dev actions */
if (dev->flags & ATA_DFLAG_DETACH) ehc->i.action |= ehc->i.dev_action[dev->devno] &
ata_eh_detach_dev(dev); ~ATA_EH_PERDEV_MASK;
ehc->i.dev_action[dev->devno] &= ATA_EH_PERDEV_MASK;
if (!ata_dev_enabled(dev) && /* process hotplug request */
((ehc->i.probe_mask & (1 << dev->devno)) && if (dev->flags & ATA_DFLAG_DETACH)
!(ehc->did_probe_mask & (1 << dev->devno)))) { ata_eh_detach_dev(dev);
ata_eh_detach_dev(dev);
ata_dev_init(dev); if (!ata_dev_enabled(dev) &&
ehc->did_probe_mask |= (1 << dev->devno); ((ehc->i.probe_mask & (1 << dev->devno)) &&
ehc->i.action |= ATA_EH_SOFTRESET; !(ehc->did_probe_mask & (1 << dev->devno)))) {
ata_eh_detach_dev(dev);
ata_dev_init(dev);
ehc->did_probe_mask |= (1 << dev->devno);
ehc->i.action |= ATA_EH_SOFTRESET;
}
} }
} }
retry: retry:
rc = 0; rc = 0;
nr_failed_devs = 0;
nr_disabled_devs = 0;
reset = 0;
/* if UNLOADING, finish immediately */ /* if UNLOADING, finish immediately */
if (ap->pflags & ATA_PFLAG_UNLOADING) if (ap->pflags & ATA_PFLAG_UNLOADING)
goto out; goto out;
/* skip EH if possible. */ /* prep for EH */
if (ata_eh_skip_recovery(link)) ata_port_for_each_link(link, ap) {
ehc->i.action = 0; struct ata_eh_context *ehc = &link->eh_context;
ata_link_for_each_dev(dev, link) /* skip EH if possible. */
ehc->classes[dev->devno] = ATA_DEV_UNKNOWN; if (ata_eh_skip_recovery(link))
ehc->i.action = 0;
/* do we need to reset? */
if (ehc->i.action & ATA_EH_RESET_MASK)
reset = 1;
ata_link_for_each_dev(dev, link)
ehc->classes[dev->devno] = ATA_DEV_UNKNOWN;
}
/* reset */ /* reset */
if (ehc->i.action & ATA_EH_RESET_MASK) { if (reset) {
ata_eh_freeze_port(ap); ata_eh_freeze_port(ap);
rc = ata_eh_reset(link, ata_link_nr_vacant(link), prereset, ata_port_for_each_link(link, ap) {
softreset, hardreset, postreset); struct ata_eh_context *ehc = &link->eh_context;
if (rc) {
ata_link_printk(link, KERN_ERR, if (!(ehc->i.action & ATA_EH_RESET_MASK))
"reset failed, giving up\n"); continue;
goto out;
rc = ata_eh_reset(link, ata_link_nr_vacant(link),
prereset, softreset, hardreset,
postreset);
if (rc) {
ata_link_printk(link, KERN_ERR,
"reset failed, giving up\n");
goto out;
}
} }
ata_eh_thaw_port(ap); ata_eh_thaw_port(ap);
} }
/* revalidate existing devices and attach new ones */ /* the rest */
rc = ata_eh_revalidate_and_attach(link, &dev); ata_port_for_each_link(link, ap) {
if (rc) struct ata_eh_context *ehc = &link->eh_context;
goto dev_fail;
/* configure transfer mode if necessary */ /* revalidate existing devices and attach new ones */
if (ehc->i.flags & ATA_EHI_SETMODE) { rc = ata_eh_revalidate_and_attach(link, &dev);
rc = ata_set_mode(link, &dev);
if (rc) if (rc)
goto dev_fail; goto dev_fail;
ehc->i.flags &= ~ATA_EHI_SETMODE;
/* configure transfer mode if necessary */
if (ehc->i.flags & ATA_EHI_SETMODE) {
rc = ata_set_mode(link, &dev);
if (rc)
goto dev_fail;
ehc->i.flags &= ~ATA_EHI_SETMODE;
}
/* this link is okay now */
ehc->i.flags = 0;
continue;
dev_fail:
nr_failed_devs++;
if (ata_eh_handle_dev_fail(dev, rc))
nr_disabled_devs++;
if (ap->pflags & ATA_PFLAG_FROZEN)
break;
} }
goto out; if (nr_failed_devs) {
if (nr_failed_devs != nr_disabled_devs) {
ata_port_printk(ap, KERN_WARNING, "failed to recover "
"some devices, retrying in 5 secs\n");
ssleep(5);
} else {
/* no device left to recover, repeat fast */
msleep(500);
}
dev_fail: goto retry;
ata_eh_handle_dev_fail(dev, rc);
if (ata_link_nr_enabled(link)) {
ata_link_printk(link, KERN_WARNING, "failed to recover some "
"devices, retrying in 5 secs\n");
ssleep(5);
} else {
/* no device left, repeat fast */
msleep(500);
} }
goto retry;
out: out:
if (rc) { if (rc && r_failed_link)
ata_link_for_each_dev(dev, link); *r_failed_link = link;
ata_dev_disable(dev);
}
DPRINTK("EXIT, rc=%d\n", rc); DPRINTK("EXIT, rc=%d\n", rc);
return rc; return rc;
@ -2342,9 +2420,19 @@ void ata_do_eh(struct ata_port *ap, ata_prereset_fn_t prereset,
ata_reset_fn_t softreset, ata_reset_fn_t hardreset, ata_reset_fn_t softreset, ata_reset_fn_t hardreset,
ata_postreset_fn_t postreset) ata_postreset_fn_t postreset)
{ {
ata_eh_autopsy(&ap->link); struct ata_device *dev;
ata_eh_report(&ap->link); int rc;
ata_eh_recover(ap, prereset, softreset, hardreset, postreset);
ata_eh_autopsy(ap);
ata_eh_report(ap);
rc = ata_eh_recover(ap, prereset, softreset, hardreset, postreset,
NULL);
if (rc) {
ata_link_for_each_dev(dev, &ap->link)
ata_dev_disable(dev);
}
ata_eh_finish(ap); ata_eh_finish(ap);
} }