libata-eh.c (cd955463bb4e96cfec18a0e5b6887c6797fb821d) libata-eh.c (416dc9ed206bba09807300ee5f155a81cebbd4a1)
1/*
2 * libata-eh.c - libata error handling
3 *
4 * Maintained by: Jeff Garzik <jgarzik@pobox.com>
5 * Please ALWAYS copy linux-ide@vger.kernel.org
6 * on emails.
7 *
8 * Copyright 2006 Tejun Heo <htejun@gmail.com>

--- 2051 unchanged lines hidden (view full) ---

2060 return 1;
2061 return 0;
2062}
2063
2064int ata_eh_reset(struct ata_link *link, int classify,
2065 ata_prereset_fn_t prereset, ata_reset_fn_t softreset,
2066 ata_reset_fn_t hardreset, ata_postreset_fn_t postreset)
2067{
1/*
2 * libata-eh.c - libata error handling
3 *
4 * Maintained by: Jeff Garzik <jgarzik@pobox.com>
5 * Please ALWAYS copy linux-ide@vger.kernel.org
6 * on emails.
7 *
8 * Copyright 2006 Tejun Heo <htejun@gmail.com>

--- 2051 unchanged lines hidden (view full) ---

2060 return 1;
2061 return 0;
2062}
2063
2064int ata_eh_reset(struct ata_link *link, int classify,
2065 ata_prereset_fn_t prereset, ata_reset_fn_t softreset,
2066 ata_reset_fn_t hardreset, ata_postreset_fn_t postreset)
2067{
2068 const int max_tries = ARRAY_SIZE(ata_eh_reset_timeouts);
2068 struct ata_port *ap = link->ap;
2069 struct ata_eh_context *ehc = &link->eh_context;
2070 unsigned int *classes = ehc->classes;
2069 struct ata_port *ap = link->ap;
2070 struct ata_eh_context *ehc = &link->eh_context;
2071 unsigned int *classes = ehc->classes;
2072 unsigned int lflags = link->flags;
2071 int verbose = !(ehc->i.flags & ATA_EHI_QUIET);
2072 int try = 0;
2073 struct ata_device *dev;
2073 int verbose = !(ehc->i.flags & ATA_EHI_QUIET);
2074 int try = 0;
2075 struct ata_device *dev;
2074 unsigned long deadline;
2076 unsigned long deadline, now;
2075 unsigned int tmp_action;
2076 ata_reset_fn_t reset;
2077 unsigned long flags;
2077 unsigned int tmp_action;
2078 ata_reset_fn_t reset;
2079 unsigned long flags;
2080 u32 sstatus;
2078 int rc;
2079
2080 /* about to reset */
2081 spin_lock_irqsave(ap->lock, flags);
2082 ap->pflags |= ATA_PFLAG_RESETTING;
2083 spin_unlock_irqrestore(ap->lock, flags);
2084
2085 ata_eh_about_to_do(link, NULL, ehc->i.action & ATA_EH_RESET_MASK);

--- 15 unchanged lines hidden (view full) ---

2101 */
2102 if (ap->ops->set_piomode)
2103 ap->ops->set_piomode(ap, dev);
2104 }
2105
2106 /* Determine which reset to use and record in ehc->i.action.
2107 * prereset() may examine and modify it.
2108 */
2081 int rc;
2082
2083 /* about to reset */
2084 spin_lock_irqsave(ap->lock, flags);
2085 ap->pflags |= ATA_PFLAG_RESETTING;
2086 spin_unlock_irqrestore(ap->lock, flags);
2087
2088 ata_eh_about_to_do(link, NULL, ehc->i.action & ATA_EH_RESET_MASK);

--- 15 unchanged lines hidden (view full) ---

2104 */
2105 if (ap->ops->set_piomode)
2106 ap->ops->set_piomode(ap, dev);
2107 }
2108
2109 /* Determine which reset to use and record in ehc->i.action.
2110 * prereset() may examine and modify it.
2111 */
2109 if (softreset && (!hardreset || (!(link->flags & ATA_LFLAG_NO_SRST) &&
2112 if (softreset && (!hardreset || (!(lflags & ATA_LFLAG_NO_SRST) &&
2110 !sata_set_spd_needed(link) &&
2111 !(ehc->i.action & ATA_EH_HARDRESET))))
2112 tmp_action = ATA_EH_SOFTRESET;
2113 else
2114 tmp_action = ATA_EH_HARDRESET;
2115
2116 ehc->i.action = (ehc->i.action & ~ATA_EH_RESET_MASK) | tmp_action;
2117

--- 65 unchanged lines hidden (view full) ---

2183 rc = -EINVAL;
2184 goto out;
2185 }
2186
2187 ata_eh_about_to_do(link, NULL, ATA_EH_RESET_MASK);
2188 rc = ata_do_reset(link, reset, classes, deadline);
2189
2190 if (rc == 0 && classify && classes[0] == ATA_DEV_UNKNOWN &&
2113 !sata_set_spd_needed(link) &&
2114 !(ehc->i.action & ATA_EH_HARDRESET))))
2115 tmp_action = ATA_EH_SOFTRESET;
2116 else
2117 tmp_action = ATA_EH_HARDRESET;
2118
2119 ehc->i.action = (ehc->i.action & ~ATA_EH_RESET_MASK) | tmp_action;
2120

--- 65 unchanged lines hidden (view full) ---

2186 rc = -EINVAL;
2187 goto out;
2188 }
2189
2190 ata_eh_about_to_do(link, NULL, ATA_EH_RESET_MASK);
2191 rc = ata_do_reset(link, reset, classes, deadline);
2192
2193 if (rc == 0 && classify && classes[0] == ATA_DEV_UNKNOWN &&
2191 !(link->flags & ATA_LFLAG_ASSUME_CLASS)) {
2194 !(lflags & ATA_LFLAG_ASSUME_CLASS)) {
2192 ata_link_printk(link, KERN_ERR,
2193 "classification failed\n");
2194 rc = -EINVAL;
2195 goto out;
2196 }
2197 }
2198
2195 ata_link_printk(link, KERN_ERR,
2196 "classification failed\n");
2197 rc = -EINVAL;
2198 goto out;
2199 }
2200 }
2201
2199 /* if we skipped follow-up srst, clear rc */
2200 if (rc == -EAGAIN)
2201 rc = 0;
2202 /* -EAGAIN can happen if we skipped followup SRST */
2203 if (rc && rc != -EAGAIN)
2204 goto fail;
2202
2205
2203 if (rc && rc != -ERESTART && try < ARRAY_SIZE(ata_eh_reset_timeouts)) {
2204 unsigned long now = jiffies;
2206 ata_link_for_each_dev(dev, link) {
2207 /* After the reset, the device state is PIO 0 and the
2208 * controller state is undefined. Reset also wakes up
2209 * drives from sleeping mode.
2210 */
2211 dev->pio_mode = XFER_PIO_0;
2212 dev->flags &= ~ATA_DFLAG_SLEEPING;
2205
2213
2206 if (time_before(now, deadline)) {
2207 unsigned long delta = deadline - now;
2214 if (ata_link_offline(link))
2215 continue;
2208
2216
2209 ata_link_printk(link, KERN_WARNING, "reset failed "
2210 "(errno=%d), retrying in %u secs\n",
2211 rc, (jiffies_to_msecs(delta) + 999) / 1000);
2212
2213 while (delta)
2214 delta = schedule_timeout_uninterruptible(delta);
2215 }
2216
2217 if (rc == -EPIPE ||
2218 try == ARRAY_SIZE(ata_eh_reset_timeouts) - 1)
2219 sata_down_spd_limit(link);
2220 if (hardreset)
2221 reset = hardreset;
2222 goto retry;
2217 /* apply class override and convert UNKNOWN to NONE */
2218 if (lflags & ATA_LFLAG_ASSUME_ATA)
2219 classes[dev->devno] = ATA_DEV_ATA;
2220 else if (lflags & ATA_LFLAG_ASSUME_SEMB)
2221 classes[dev->devno] = ATA_DEV_SEMB_UNSUP; /* not yet */
2222 else if (classes[dev->devno] == ATA_DEV_UNKNOWN)
2223 classes[dev->devno] = ATA_DEV_NONE;
2223 }
2224
2224 }
2225
2225 if (rc == 0) {
2226 u32 sstatus;
2226 /* record current link speed */
2227 if (sata_scr_read(link, SCR_STATUS, &sstatus) == 0)
2228 link->sata_spd = (sstatus >> 4) & 0xf;
2227
2229
2228 ata_link_for_each_dev(dev, link) {
2229 /* After the reset, the device state is PIO 0
2230 * and the controller state is undefined.
2231 * Reset also wakes up drives from sleeping
2232 * mode.
2233 */
2234 dev->pio_mode = XFER_PIO_0;
2235 dev->flags &= ~ATA_DFLAG_SLEEPING;
2230 if (postreset)
2231 postreset(link, classes);
2236
2232
2237 if (ata_link_offline(link))
2238 continue;
2233 /* reset successful, schedule revalidation */
2234 ata_eh_done(link, NULL, ehc->i.action & ATA_EH_RESET_MASK);
2235 ehc->i.action |= ATA_EH_REVALIDATE;
2239
2236
2240 /* apply class override and convert UNKNOWN to NONE */
2241 if (link->flags & ATA_LFLAG_ASSUME_ATA)
2242 classes[dev->devno] = ATA_DEV_ATA;
2243 else if (link->flags & ATA_LFLAG_ASSUME_SEMB)
2244 classes[dev->devno] = ATA_DEV_SEMB_UNSUP; /* not yet */
2245 else if (classes[dev->devno] == ATA_DEV_UNKNOWN)
2246 classes[dev->devno] = ATA_DEV_NONE;
2247 }
2248
2249 /* record current link speed */
2250 if (sata_scr_read(link, SCR_STATUS, &sstatus) == 0)
2251 link->sata_spd = (sstatus >> 4) & 0xf;
2252
2253 if (postreset)
2254 postreset(link, classes);
2255
2256 /* reset successful, schedule revalidation */
2257 ata_eh_done(link, NULL, ehc->i.action & ATA_EH_RESET_MASK);
2258 ehc->i.action |= ATA_EH_REVALIDATE;
2259 }
2237 rc = 0;
2260 out:
2261 /* clear hotplug flag */
2262 ehc->i.flags &= ~ATA_EHI_HOTPLUGGED;
2263
2264 spin_lock_irqsave(ap->lock, flags);
2265 ap->pflags &= ~ATA_PFLAG_RESETTING;
2266 spin_unlock_irqrestore(ap->lock, flags);
2267
2268 return rc;
2238 out:
2239 /* clear hotplug flag */
2240 ehc->i.flags &= ~ATA_EHI_HOTPLUGGED;
2241
2242 spin_lock_irqsave(ap->lock, flags);
2243 ap->pflags &= ~ATA_PFLAG_RESETTING;
2244 spin_unlock_irqrestore(ap->lock, flags);
2245
2246 return rc;
2247
2248 fail:
2249 if (rc == -ERESTART || try >= max_tries)
2250 goto out;
2251
2252 now = jiffies;
2253 if (time_before(now, deadline)) {
2254 unsigned long delta = deadline - now;
2255
2256 ata_link_printk(link, KERN_WARNING, "reset failed "
2257 "(errno=%d), retrying in %u secs\n",
2258 rc, (jiffies_to_msecs(delta) + 999) / 1000);
2259
2260 while (delta)
2261 delta = schedule_timeout_uninterruptible(delta);
2262 }
2263
2264 if (rc == -EPIPE || try == max_tries - 1)
2265 sata_down_spd_limit(link);
2266 if (hardreset)
2267 reset = hardreset;
2268 goto retry;
2269}
2270
2271static int ata_eh_revalidate_and_attach(struct ata_link *link,
2272 struct ata_device **r_failed_dev)
2273{
2274 struct ata_port *ap = link->ap;
2275 struct ata_eh_context *ehc = &link->eh_context;
2276 struct ata_device *dev;

--- 583 unchanged lines hidden ---
2269}
2270
2271static int ata_eh_revalidate_and_attach(struct ata_link *link,
2272 struct ata_device **r_failed_dev)
2273{
2274 struct ata_port *ap = link->ap;
2275 struct ata_eh_context *ehc = &link->eh_context;
2276 struct ata_device *dev;

--- 583 unchanged lines hidden ---