diff options
Diffstat (limited to 'drivers/ata/libata-eh.c')
| -rw-r--r-- | drivers/ata/libata-eh.c | 362 | 
1 files changed, 335 insertions, 27 deletions
| diff --git a/drivers/ata/libata-eh.c b/drivers/ata/libata-eh.c index c1db2f234d2e..f2dd99122bd6 100644 --- a/drivers/ata/libata-eh.c +++ b/drivers/ata/libata-eh.c | |||
| @@ -79,6 +79,8 @@ enum { | |||
| 79 | */ | 79 | */ | 
| 80 | ATA_EH_PRERESET_TIMEOUT = 10000, | 80 | ATA_EH_PRERESET_TIMEOUT = 10000, | 
| 81 | ATA_EH_FASTDRAIN_INTERVAL = 3000, | 81 | ATA_EH_FASTDRAIN_INTERVAL = 3000, | 
| 82 | |||
| 83 | ATA_EH_UA_TRIES = 5, | ||
| 82 | }; | 84 | }; | 
| 83 | 85 | ||
| 84 | /* The following table determines how we sequence resets. Each entry | 86 | /* The following table determines how we sequence resets. Each entry | 
| @@ -1357,6 +1359,37 @@ static int ata_eh_read_log_10h(struct ata_device *dev, | |||
| 1357 | } | 1359 | } | 
| 1358 | 1360 | ||
| 1359 | /** | 1361 | /** | 
| 1362 | * atapi_eh_tur - perform ATAPI TEST_UNIT_READY | ||
| 1363 | * @dev: target ATAPI device | ||
| 1364 | * @r_sense_key: out parameter for sense_key | ||
| 1365 | * | ||
| 1366 | * Perform ATAPI TEST_UNIT_READY. | ||
| 1367 | * | ||
| 1368 | * LOCKING: | ||
| 1369 | * EH context (may sleep). | ||
| 1370 | * | ||
| 1371 | * RETURNS: | ||
| 1372 | * 0 on success, AC_ERR_* mask on failure. | ||
| 1373 | */ | ||
| 1374 | static unsigned int atapi_eh_tur(struct ata_device *dev, u8 *r_sense_key) | ||
| 1375 | { | ||
| 1376 | u8 cdb[ATAPI_CDB_LEN] = { TEST_UNIT_READY, 0, 0, 0, 0, 0 }; | ||
| 1377 | struct ata_taskfile tf; | ||
| 1378 | unsigned int err_mask; | ||
| 1379 | |||
| 1380 | ata_tf_init(dev, &tf); | ||
| 1381 | |||
| 1382 | tf.flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE; | ||
| 1383 | tf.command = ATA_CMD_PACKET; | ||
| 1384 | tf.protocol = ATAPI_PROT_NODATA; | ||
| 1385 | |||
| 1386 | err_mask = ata_exec_internal(dev, &tf, cdb, DMA_NONE, NULL, 0, 0); | ||
| 1387 | if (err_mask == AC_ERR_DEV) | ||
| 1388 | *r_sense_key = tf.feature >> 4; | ||
| 1389 | return err_mask; | ||
| 1390 | } | ||
| 1391 | |||
| 1392 | /** | ||
| 1360 | * atapi_eh_request_sense - perform ATAPI REQUEST_SENSE | 1393 | * atapi_eh_request_sense - perform ATAPI REQUEST_SENSE | 
| 1361 | * @dev: device to perform REQUEST_SENSE to | 1394 | * @dev: device to perform REQUEST_SENSE to | 
| 1362 | * @sense_buf: result sense data buffer (SCSI_SENSE_BUFFERSIZE bytes long) | 1395 | * @sense_buf: result sense data buffer (SCSI_SENSE_BUFFERSIZE bytes long) | 
| @@ -1756,7 +1789,7 @@ static unsigned int ata_eh_speed_down_verdict(struct ata_device *dev) | |||
| 1756 | static unsigned int ata_eh_speed_down(struct ata_device *dev, | 1789 | static unsigned int ata_eh_speed_down(struct ata_device *dev, | 
| 1757 | unsigned int eflags, unsigned int err_mask) | 1790 | unsigned int eflags, unsigned int err_mask) | 
| 1758 | { | 1791 | { | 
| 1759 | struct ata_link *link = dev->link; | 1792 | struct ata_link *link = ata_dev_phys_link(dev); | 
| 1760 | int xfer_ok = 0; | 1793 | int xfer_ok = 0; | 
| 1761 | unsigned int verdict; | 1794 | unsigned int verdict; | 
| 1762 | unsigned int action = 0; | 1795 | unsigned int action = 0; | 
| @@ -1880,7 +1913,8 @@ static void ata_eh_link_autopsy(struct ata_link *link) | |||
| 1880 | for (tag = 0; tag < ATA_MAX_QUEUE; tag++) { | 1913 | for (tag = 0; tag < ATA_MAX_QUEUE; tag++) { | 
| 1881 | struct ata_queued_cmd *qc = __ata_qc_from_tag(ap, tag); | 1914 | struct ata_queued_cmd *qc = __ata_qc_from_tag(ap, tag); | 
| 1882 | 1915 | ||
| 1883 | if (!(qc->flags & ATA_QCFLAG_FAILED) || qc->dev->link != link) | 1916 | if (!(qc->flags & ATA_QCFLAG_FAILED) || | 
| 1917 | ata_dev_phys_link(qc->dev) != link) | ||
| 1884 | continue; | 1918 | continue; | 
| 1885 | 1919 | ||
| 1886 | /* inherit upper level err_mask */ | 1920 | /* inherit upper level err_mask */ | 
| @@ -1967,6 +2001,23 @@ void ata_eh_autopsy(struct ata_port *ap) | |||
| 1967 | ata_port_for_each_link(link, ap) | 2001 | ata_port_for_each_link(link, ap) | 
| 1968 | ata_eh_link_autopsy(link); | 2002 | ata_eh_link_autopsy(link); | 
| 1969 | 2003 | ||
| 2004 | /* Handle the frigging slave link. Autopsy is done similarly | ||
| 2005 | * but actions and flags are transferred over to the master | ||
| 2006 | * link and handled from there. | ||
| 2007 | */ | ||
| 2008 | if (ap->slave_link) { | ||
| 2009 | struct ata_eh_context *mehc = &ap->link.eh_context; | ||
| 2010 | struct ata_eh_context *sehc = &ap->slave_link->eh_context; | ||
| 2011 | |||
| 2012 | ata_eh_link_autopsy(ap->slave_link); | ||
| 2013 | |||
| 2014 | ata_eh_about_to_do(ap->slave_link, NULL, ATA_EH_ALL_ACTIONS); | ||
| 2015 | mehc->i.action |= sehc->i.action; | ||
| 2016 | mehc->i.dev_action[1] |= sehc->i.dev_action[1]; | ||
| 2017 | mehc->i.flags |= sehc->i.flags; | ||
| 2018 | ata_eh_done(ap->slave_link, NULL, ATA_EH_ALL_ACTIONS); | ||
| 2019 | } | ||
| 2020 | |||
| 1970 | /* Autopsy of fanout ports can affect host link autopsy. | 2021 | /* Autopsy of fanout ports can affect host link autopsy. | 
| 1971 | * Perform host link autopsy last. | 2022 | * Perform host link autopsy last. | 
| 1972 | */ | 2023 | */ | 
| @@ -2001,7 +2052,8 @@ static void ata_eh_link_report(struct ata_link *link) | |||
| 2001 | for (tag = 0; tag < ATA_MAX_QUEUE; tag++) { | 2052 | for (tag = 0; tag < ATA_MAX_QUEUE; tag++) { | 
| 2002 | struct ata_queued_cmd *qc = __ata_qc_from_tag(ap, tag); | 2053 | struct ata_queued_cmd *qc = __ata_qc_from_tag(ap, tag); | 
| 2003 | 2054 | ||
| 2004 | if (!(qc->flags & ATA_QCFLAG_FAILED) || qc->dev->link != link || | 2055 | if (!(qc->flags & ATA_QCFLAG_FAILED) || | 
| 2056 | ata_dev_phys_link(qc->dev) != link || | ||
| 2005 | ((qc->flags & ATA_QCFLAG_QUIET) && | 2057 | ((qc->flags & ATA_QCFLAG_QUIET) && | 
| 2006 | qc->err_mask == AC_ERR_DEV)) | 2058 | qc->err_mask == AC_ERR_DEV)) | 
| 2007 | continue; | 2059 | continue; | 
| @@ -2068,7 +2120,7 @@ static void ata_eh_link_report(struct ata_link *link) | |||
| 2068 | char cdb_buf[70] = ""; | 2120 | char cdb_buf[70] = ""; | 
| 2069 | 2121 | ||
| 2070 | if (!(qc->flags & ATA_QCFLAG_FAILED) || | 2122 | if (!(qc->flags & ATA_QCFLAG_FAILED) || | 
| 2071 | qc->dev->link != link || !qc->err_mask) | 2123 | ata_dev_phys_link(qc->dev) != link || !qc->err_mask) | 
| 2072 | continue; | 2124 | continue; | 
| 2073 | 2125 | ||
| 2074 | if (qc->dma_dir != DMA_NONE) { | 2126 | if (qc->dma_dir != DMA_NONE) { | 
| @@ -2160,12 +2212,14 @@ void ata_eh_report(struct ata_port *ap) | |||
| 2160 | } | 2212 | } | 
| 2161 | 2213 | ||
| 2162 | static int ata_do_reset(struct ata_link *link, ata_reset_fn_t reset, | 2214 | static int ata_do_reset(struct ata_link *link, ata_reset_fn_t reset, | 
| 2163 | unsigned int *classes, unsigned long deadline) | 2215 | unsigned int *classes, unsigned long deadline, | 
| 2216 | bool clear_classes) | ||
| 2164 | { | 2217 | { | 
| 2165 | struct ata_device *dev; | 2218 | struct ata_device *dev; | 
| 2166 | 2219 | ||
| 2167 | ata_link_for_each_dev(dev, link) | 2220 | if (clear_classes) | 
| 2168 | classes[dev->devno] = ATA_DEV_UNKNOWN; | 2221 | ata_link_for_each_dev(dev, link) | 
| 2222 | classes[dev->devno] = ATA_DEV_UNKNOWN; | ||
| 2169 | 2223 | ||
| 2170 | return reset(link, classes, deadline); | 2224 | return reset(link, classes, deadline); | 
| 2171 | } | 2225 | } | 
| @@ -2187,17 +2241,20 @@ int ata_eh_reset(struct ata_link *link, int classify, | |||
| 2187 | ata_reset_fn_t hardreset, ata_postreset_fn_t postreset) | 2241 | ata_reset_fn_t hardreset, ata_postreset_fn_t postreset) | 
| 2188 | { | 2242 | { | 
| 2189 | struct ata_port *ap = link->ap; | 2243 | struct ata_port *ap = link->ap; | 
| 2244 | struct ata_link *slave = ap->slave_link; | ||
| 2190 | struct ata_eh_context *ehc = &link->eh_context; | 2245 | struct ata_eh_context *ehc = &link->eh_context; | 
| 2246 | struct ata_eh_context *sehc = &slave->eh_context; | ||
| 2191 | unsigned int *classes = ehc->classes; | 2247 | unsigned int *classes = ehc->classes; | 
| 2192 | unsigned int lflags = link->flags; | 2248 | unsigned int lflags = link->flags; | 
| 2193 | int verbose = !(ehc->i.flags & ATA_EHI_QUIET); | 2249 | int verbose = !(ehc->i.flags & ATA_EHI_QUIET); | 
| 2194 | int max_tries = 0, try = 0; | 2250 | int max_tries = 0, try = 0; | 
| 2251 | struct ata_link *failed_link; | ||
| 2195 | struct ata_device *dev; | 2252 | struct ata_device *dev; | 
| 2196 | unsigned long deadline, now; | 2253 | unsigned long deadline, now; | 
| 2197 | ata_reset_fn_t reset; | 2254 | ata_reset_fn_t reset; | 
| 2198 | unsigned long flags; | 2255 | unsigned long flags; | 
| 2199 | u32 sstatus; | 2256 | u32 sstatus; | 
| 2200 | int nr_known, rc; | 2257 | int nr_unknown, rc; | 
| 2201 | 2258 | ||
| 2202 | /* | 2259 | /* | 
| 2203 | * Prepare to reset | 2260 | * Prepare to reset | 
| @@ -2252,8 +2309,30 @@ int ata_eh_reset(struct ata_link *link, int classify, | |||
| 2252 | } | 2309 | } | 
| 2253 | 2310 | ||
| 2254 | if (prereset) { | 2311 | if (prereset) { | 
| 2255 | rc = prereset(link, | 2312 | unsigned long deadline = ata_deadline(jiffies, | 
| 2256 | ata_deadline(jiffies, ATA_EH_PRERESET_TIMEOUT)); | 2313 | ATA_EH_PRERESET_TIMEOUT); | 
| 2314 | |||
| 2315 | if (slave) { | ||
| 2316 | sehc->i.action &= ~ATA_EH_RESET; | ||
| 2317 | sehc->i.action |= ehc->i.action; | ||
| 2318 | } | ||
| 2319 | |||
| 2320 | rc = prereset(link, deadline); | ||
| 2321 | |||
| 2322 | /* If present, do prereset on slave link too. Reset | ||
| 2323 | * is skipped iff both master and slave links report | ||
| 2324 | * -ENOENT or clear ATA_EH_RESET. | ||
| 2325 | */ | ||
| 2326 | if (slave && (rc == 0 || rc == -ENOENT)) { | ||
| 2327 | int tmp; | ||
| 2328 | |||
| 2329 | tmp = prereset(slave, deadline); | ||
| 2330 | if (tmp != -ENOENT) | ||
| 2331 | rc = tmp; | ||
| 2332 | |||
| 2333 | ehc->i.action |= sehc->i.action; | ||
| 2334 | } | ||
| 2335 | |||
| 2257 | if (rc) { | 2336 | if (rc) { | 
| 2258 | if (rc == -ENOENT) { | 2337 | if (rc == -ENOENT) { | 
| 2259 | ata_link_printk(link, KERN_DEBUG, | 2338 | ata_link_printk(link, KERN_DEBUG, | 
| @@ -2302,25 +2381,51 @@ int ata_eh_reset(struct ata_link *link, int classify, | |||
| 2302 | else | 2381 | else | 
| 2303 | ehc->i.flags |= ATA_EHI_DID_SOFTRESET; | 2382 | ehc->i.flags |= ATA_EHI_DID_SOFTRESET; | 
| 2304 | 2383 | ||
| 2305 | rc = ata_do_reset(link, reset, classes, deadline); | 2384 | rc = ata_do_reset(link, reset, classes, deadline, true); | 
| 2306 | if (rc && rc != -EAGAIN) | 2385 | if (rc && rc != -EAGAIN) { | 
| 2386 | failed_link = link; | ||
| 2307 | goto fail; | 2387 | goto fail; | 
| 2388 | } | ||
| 2389 | |||
| 2390 | /* hardreset slave link if existent */ | ||
| 2391 | if (slave && reset == hardreset) { | ||
| 2392 | int tmp; | ||
| 2393 | |||
| 2394 | if (verbose) | ||
| 2395 | ata_link_printk(slave, KERN_INFO, | ||
| 2396 | "hard resetting link\n"); | ||
| 2308 | 2397 | ||
| 2398 | ata_eh_about_to_do(slave, NULL, ATA_EH_RESET); | ||
| 2399 | tmp = ata_do_reset(slave, reset, classes, deadline, | ||
| 2400 | false); | ||
| 2401 | switch (tmp) { | ||
| 2402 | case -EAGAIN: | ||
| 2403 | rc = -EAGAIN; | ||
| 2404 | case 0: | ||
| 2405 | break; | ||
| 2406 | default: | ||
| 2407 | failed_link = slave; | ||
| 2408 | rc = tmp; | ||
| 2409 | goto fail; | ||
| 2410 | } | ||
| 2411 | } | ||
| 2412 | |||
| 2413 | /* perform follow-up SRST if necessary */ | ||
| 2309 | if (reset == hardreset && | 2414 | if (reset == hardreset && | 
| 2310 | ata_eh_followup_srst_needed(link, rc, classes)) { | 2415 | ata_eh_followup_srst_needed(link, rc, classes)) { | 
| 2311 | /* okay, let's do follow-up softreset */ | ||
| 2312 | reset = softreset; | 2416 | reset = softreset; | 
| 2313 | 2417 | ||
| 2314 | if (!reset) { | 2418 | if (!reset) { | 
| 2315 | ata_link_printk(link, KERN_ERR, | 2419 | ata_link_printk(link, KERN_ERR, | 
| 2316 | "follow-up softreset required " | 2420 | "follow-up softreset required " | 
| 2317 | "but no softreset avaliable\n"); | 2421 | "but no softreset avaliable\n"); | 
| 2422 | failed_link = link; | ||
| 2318 | rc = -EINVAL; | 2423 | rc = -EINVAL; | 
| 2319 | goto fail; | 2424 | goto fail; | 
| 2320 | } | 2425 | } | 
| 2321 | 2426 | ||
| 2322 | ata_eh_about_to_do(link, NULL, ATA_EH_RESET); | 2427 | ata_eh_about_to_do(link, NULL, ATA_EH_RESET); | 
| 2323 | rc = ata_do_reset(link, reset, classes, deadline); | 2428 | rc = ata_do_reset(link, reset, classes, deadline, true); | 
| 2324 | } | 2429 | } | 
| 2325 | } else { | 2430 | } else { | 
| 2326 | if (verbose) | 2431 | if (verbose) | 
| @@ -2341,7 +2446,7 @@ int ata_eh_reset(struct ata_link *link, int classify, | |||
| 2341 | dev->pio_mode = XFER_PIO_0; | 2446 | dev->pio_mode = XFER_PIO_0; | 
| 2342 | dev->flags &= ~ATA_DFLAG_SLEEPING; | 2447 | dev->flags &= ~ATA_DFLAG_SLEEPING; | 
| 2343 | 2448 | ||
| 2344 | if (ata_link_offline(link)) | 2449 | if (ata_phys_link_offline(ata_dev_phys_link(dev))) | 
| 2345 | continue; | 2450 | continue; | 
| 2346 | 2451 | ||
| 2347 | /* apply class override */ | 2452 | /* apply class override */ | 
| @@ -2354,6 +2459,8 @@ int ata_eh_reset(struct ata_link *link, int classify, | |||
| 2354 | /* record current link speed */ | 2459 | /* record current link speed */ | 
| 2355 | if (sata_scr_read(link, SCR_STATUS, &sstatus) == 0) | 2460 | if (sata_scr_read(link, SCR_STATUS, &sstatus) == 0) | 
| 2356 | link->sata_spd = (sstatus >> 4) & 0xf; | 2461 | link->sata_spd = (sstatus >> 4) & 0xf; | 
| 2462 | if (slave && sata_scr_read(slave, SCR_STATUS, &sstatus) == 0) | ||
| 2463 | slave->sata_spd = (sstatus >> 4) & 0xf; | ||
| 2357 | 2464 | ||
| 2358 | /* thaw the port */ | 2465 | /* thaw the port */ | 
| 2359 | if (ata_is_host_link(link)) | 2466 | if (ata_is_host_link(link)) | 
| @@ -2366,12 +2473,17 @@ int ata_eh_reset(struct ata_link *link, int classify, | |||
| 2366 | * reset and here. This race is mediated by cross checking | 2473 | * reset and here. This race is mediated by cross checking | 
| 2367 | * link onlineness and classification result later. | 2474 | * link onlineness and classification result later. | 
| 2368 | */ | 2475 | */ | 
| 2369 | if (postreset) | 2476 | if (postreset) { | 
| 2370 | postreset(link, classes); | 2477 | postreset(link, classes); | 
| 2478 | if (slave) | ||
| 2479 | postreset(slave, classes); | ||
| 2480 | } | ||
| 2371 | 2481 | ||
| 2372 | /* clear cached SError */ | 2482 | /* clear cached SError */ | 
| 2373 | spin_lock_irqsave(link->ap->lock, flags); | 2483 | spin_lock_irqsave(link->ap->lock, flags); | 
| 2374 | link->eh_info.serror = 0; | 2484 | link->eh_info.serror = 0; | 
| 2485 | if (slave) | ||
| 2486 | slave->eh_info.serror = 0; | ||
| 2375 | spin_unlock_irqrestore(link->ap->lock, flags); | 2487 | spin_unlock_irqrestore(link->ap->lock, flags); | 
| 2376 | 2488 | ||
| 2377 | /* Make sure onlineness and classification result correspond. | 2489 | /* Make sure onlineness and classification result correspond. | 
| @@ -2381,19 +2493,21 @@ int ata_eh_reset(struct ata_link *link, int classify, | |||
| 2381 | * link onlineness and classification result, those conditions | 2493 | * link onlineness and classification result, those conditions | 
| 2382 | * can be reliably detected and retried. | 2494 | * can be reliably detected and retried. | 
| 2383 | */ | 2495 | */ | 
| 2384 | nr_known = 0; | 2496 | nr_unknown = 0; | 
| 2385 | ata_link_for_each_dev(dev, link) { | 2497 | ata_link_for_each_dev(dev, link) { | 
| 2386 | /* convert all ATA_DEV_UNKNOWN to ATA_DEV_NONE */ | 2498 | /* convert all ATA_DEV_UNKNOWN to ATA_DEV_NONE */ | 
| 2387 | if (classes[dev->devno] == ATA_DEV_UNKNOWN) | 2499 | if (classes[dev->devno] == ATA_DEV_UNKNOWN) { | 
| 2388 | classes[dev->devno] = ATA_DEV_NONE; | 2500 | classes[dev->devno] = ATA_DEV_NONE; | 
| 2389 | else | 2501 | if (ata_phys_link_online(ata_dev_phys_link(dev))) | 
| 2390 | nr_known++; | 2502 | nr_unknown++; | 
| 2503 | } | ||
| 2391 | } | 2504 | } | 
| 2392 | 2505 | ||
| 2393 | if (classify && !nr_known && ata_link_online(link)) { | 2506 | if (classify && nr_unknown) { | 
| 2394 | if (try < max_tries) { | 2507 | if (try < max_tries) { | 
| 2395 | ata_link_printk(link, KERN_WARNING, "link online but " | 2508 | ata_link_printk(link, KERN_WARNING, "link online but " | 
| 2396 | "device misclassified, retrying\n"); | 2509 | "device misclassified, retrying\n"); | 
| 2510 | failed_link = link; | ||
| 2397 | rc = -EAGAIN; | 2511 | rc = -EAGAIN; | 
| 2398 | goto fail; | 2512 | goto fail; | 
| 2399 | } | 2513 | } | 
| @@ -2404,6 +2518,8 @@ int ata_eh_reset(struct ata_link *link, int classify, | |||
| 2404 | 2518 | ||
| 2405 | /* reset successful, schedule revalidation */ | 2519 | /* reset successful, schedule revalidation */ | 
| 2406 | ata_eh_done(link, NULL, ATA_EH_RESET); | 2520 | ata_eh_done(link, NULL, ATA_EH_RESET); | 
| 2521 | if (slave) | ||
| 2522 | ata_eh_done(slave, NULL, ATA_EH_RESET); | ||
| 2407 | ehc->last_reset = jiffies; | 2523 | ehc->last_reset = jiffies; | 
| 2408 | ehc->i.action |= ATA_EH_REVALIDATE; | 2524 | ehc->i.action |= ATA_EH_REVALIDATE; | 
| 2409 | 2525 | ||
| @@ -2411,6 +2527,8 @@ int ata_eh_reset(struct ata_link *link, int classify, | |||
| 2411 | out: | 2527 | out: | 
| 2412 | /* clear hotplug flag */ | 2528 | /* clear hotplug flag */ | 
| 2413 | ehc->i.flags &= ~ATA_EHI_HOTPLUGGED; | 2529 | ehc->i.flags &= ~ATA_EHI_HOTPLUGGED; | 
| 2530 | if (slave) | ||
| 2531 | sehc->i.flags &= ~ATA_EHI_HOTPLUGGED; | ||
| 2414 | 2532 | ||
| 2415 | spin_lock_irqsave(ap->lock, flags); | 2533 | spin_lock_irqsave(ap->lock, flags); | 
| 2416 | ap->pflags &= ~ATA_PFLAG_RESETTING; | 2534 | ap->pflags &= ~ATA_PFLAG_RESETTING; | 
| @@ -2431,7 +2549,7 @@ int ata_eh_reset(struct ata_link *link, int classify, | |||
| 2431 | if (time_before(now, deadline)) { | 2549 | if (time_before(now, deadline)) { | 
| 2432 | unsigned long delta = deadline - now; | 2550 | unsigned long delta = deadline - now; | 
| 2433 | 2551 | ||
| 2434 | ata_link_printk(link, KERN_WARNING, | 2552 | ata_link_printk(failed_link, KERN_WARNING, | 
| 2435 | "reset failed (errno=%d), retrying in %u secs\n", | 2553 | "reset failed (errno=%d), retrying in %u secs\n", | 
| 2436 | rc, DIV_ROUND_UP(jiffies_to_msecs(delta), 1000)); | 2554 | rc, DIV_ROUND_UP(jiffies_to_msecs(delta), 1000)); | 
| 2437 | 2555 | ||
| @@ -2439,13 +2557,92 @@ int ata_eh_reset(struct ata_link *link, int classify, | |||
| 2439 | delta = schedule_timeout_uninterruptible(delta); | 2557 | delta = schedule_timeout_uninterruptible(delta); | 
| 2440 | } | 2558 | } | 
| 2441 | 2559 | ||
| 2442 | if (rc == -EPIPE || try == max_tries - 1) | 2560 | if (try == max_tries - 1) { | 
| 2443 | sata_down_spd_limit(link); | 2561 | sata_down_spd_limit(link); | 
| 2562 | if (slave) | ||
| 2563 | sata_down_spd_limit(slave); | ||
| 2564 | } else if (rc == -EPIPE) | ||
| 2565 | sata_down_spd_limit(failed_link); | ||
| 2566 | |||
| 2444 | if (hardreset) | 2567 | if (hardreset) | 
| 2445 | reset = hardreset; | 2568 | reset = hardreset; | 
| 2446 | goto retry; | 2569 | goto retry; | 
| 2447 | } | 2570 | } | 
| 2448 | 2571 | ||
| 2572 | static inline void ata_eh_pull_park_action(struct ata_port *ap) | ||
| 2573 | { | ||
| 2574 | struct ata_link *link; | ||
| 2575 | struct ata_device *dev; | ||
| 2576 | unsigned long flags; | ||
| 2577 | |||
| 2578 | /* | ||
| 2579 | * This function can be thought of as an extended version of | ||
| 2580 | * ata_eh_about_to_do() specially crafted to accommodate the | ||
| 2581 | * requirements of ATA_EH_PARK handling. Since the EH thread | ||
| 2582 | * does not leave the do {} while () loop in ata_eh_recover as | ||
| 2583 | * long as the timeout for a park request to *one* device on | ||
| 2584 | * the port has not expired, and since we still want to pick | ||
| 2585 | * up park requests to other devices on the same port or | ||
| 2586 | * timeout updates for the same device, we have to pull | ||
| 2587 | * ATA_EH_PARK actions from eh_info into eh_context.i | ||
| 2588 | * ourselves at the beginning of each pass over the loop. | ||
| 2589 | * | ||
| 2590 | * Additionally, all write accesses to &ap->park_req_pending | ||
| 2591 | * through INIT_COMPLETION() (see below) or complete_all() | ||
| 2592 | * (see ata_scsi_park_store()) are protected by the host lock. | ||
| 2593 | * As a result we have that park_req_pending.done is zero on | ||
| 2594 | * exit from this function, i.e. when ATA_EH_PARK actions for | ||
| 2595 | * *all* devices on port ap have been pulled into the | ||
| 2596 | * respective eh_context structs. If, and only if, | ||
| 2597 | * park_req_pending.done is non-zero by the time we reach | ||
| 2598 | * wait_for_completion_timeout(), another ATA_EH_PARK action | ||
| 2599 | * has been scheduled for at least one of the devices on port | ||
| 2600 | * ap and we have to cycle over the do {} while () loop in | ||
| 2601 | * ata_eh_recover() again. | ||
| 2602 | */ | ||
| 2603 | |||
| 2604 | spin_lock_irqsave(ap->lock, flags); | ||
| 2605 | INIT_COMPLETION(ap->park_req_pending); | ||
| 2606 | ata_port_for_each_link(link, ap) { | ||
| 2607 | ata_link_for_each_dev(dev, link) { | ||
| 2608 | struct ata_eh_info *ehi = &link->eh_info; | ||
| 2609 | |||
| 2610 | link->eh_context.i.dev_action[dev->devno] |= | ||
| 2611 | ehi->dev_action[dev->devno] & ATA_EH_PARK; | ||
| 2612 | ata_eh_clear_action(link, dev, ehi, ATA_EH_PARK); | ||
| 2613 | } | ||
| 2614 | } | ||
| 2615 | spin_unlock_irqrestore(ap->lock, flags); | ||
| 2616 | } | ||
| 2617 | |||
| 2618 | static void ata_eh_park_issue_cmd(struct ata_device *dev, int park) | ||
| 2619 | { | ||
| 2620 | struct ata_eh_context *ehc = &dev->link->eh_context; | ||
| 2621 | struct ata_taskfile tf; | ||
| 2622 | unsigned int err_mask; | ||
| 2623 | |||
| 2624 | ata_tf_init(dev, &tf); | ||
| 2625 | if (park) { | ||
| 2626 | ehc->unloaded_mask |= 1 << dev->devno; | ||
| 2627 | tf.command = ATA_CMD_IDLEIMMEDIATE; | ||
| 2628 | tf.feature = 0x44; | ||
| 2629 | tf.lbal = 0x4c; | ||
| 2630 | tf.lbam = 0x4e; | ||
| 2631 | tf.lbah = 0x55; | ||
| 2632 | } else { | ||
| 2633 | ehc->unloaded_mask &= ~(1 << dev->devno); | ||
| 2634 | tf.command = ATA_CMD_CHK_POWER; | ||
| 2635 | } | ||
| 2636 | |||
| 2637 | tf.flags |= ATA_TFLAG_DEVICE | ATA_TFLAG_ISADDR; | ||
| 2638 | tf.protocol |= ATA_PROT_NODATA; | ||
| 2639 | err_mask = ata_exec_internal(dev, &tf, NULL, DMA_NONE, NULL, 0, 0); | ||
| 2640 | if (park && (err_mask || tf.lbal != 0xc4)) { | ||
| 2641 | ata_dev_printk(dev, KERN_ERR, "head unload failed!\n"); | ||
| 2642 | ehc->unloaded_mask &= ~(1 << dev->devno); | ||
| 2643 | } | ||
| 2644 | } | ||
| 2645 | |||
| 2449 | static int ata_eh_revalidate_and_attach(struct ata_link *link, | 2646 | static int ata_eh_revalidate_and_attach(struct ata_link *link, | 
| 2450 | struct ata_device **r_failed_dev) | 2647 | struct ata_device **r_failed_dev) | 
| 2451 | { | 2648 | { | 
| @@ -2472,7 +2669,7 @@ static int ata_eh_revalidate_and_attach(struct ata_link *link, | |||
| 2472 | if ((action & ATA_EH_REVALIDATE) && ata_dev_enabled(dev)) { | 2669 | if ((action & ATA_EH_REVALIDATE) && ata_dev_enabled(dev)) { | 
| 2473 | WARN_ON(dev->class == ATA_DEV_PMP); | 2670 | WARN_ON(dev->class == ATA_DEV_PMP); | 
| 2474 | 2671 | ||
| 2475 | if (ata_link_offline(link)) { | 2672 | if (ata_phys_link_offline(ata_dev_phys_link(dev))) { | 
| 2476 | rc = -EIO; | 2673 | rc = -EIO; | 
| 2477 | goto err; | 2674 | goto err; | 
| 2478 | } | 2675 | } | 
| @@ -2610,6 +2807,53 @@ int ata_set_mode(struct ata_link *link, struct ata_device **r_failed_dev) | |||
| 2610 | return rc; | 2807 | return rc; | 
| 2611 | } | 2808 | } | 
| 2612 | 2809 | ||
| 2810 | /** | ||
| 2811 | * atapi_eh_clear_ua - Clear ATAPI UNIT ATTENTION after reset | ||
| 2812 | * @dev: ATAPI device to clear UA for | ||
| 2813 | * | ||
| 2814 | * Resets and other operations can make an ATAPI device raise | ||
| 2815 | * UNIT ATTENTION which causes the next operation to fail. This | ||
| 2816 | * function clears UA. | ||
| 2817 | * | ||
| 2818 | * LOCKING: | ||
| 2819 | * EH context (may sleep). | ||
| 2820 | * | ||
| 2821 | * RETURNS: | ||
| 2822 | * 0 on success, -errno on failure. | ||
| 2823 | */ | ||
| 2824 | static int atapi_eh_clear_ua(struct ata_device *dev) | ||
| 2825 | { | ||
| 2826 | int i; | ||
| 2827 | |||
| 2828 | for (i = 0; i < ATA_EH_UA_TRIES; i++) { | ||
| 2829 | u8 sense_buffer[SCSI_SENSE_BUFFERSIZE]; | ||
| 2830 | u8 sense_key = 0; | ||
| 2831 | unsigned int err_mask; | ||
| 2832 | |||
| 2833 | err_mask = atapi_eh_tur(dev, &sense_key); | ||
| 2834 | if (err_mask != 0 && err_mask != AC_ERR_DEV) { | ||
| 2835 | ata_dev_printk(dev, KERN_WARNING, "TEST_UNIT_READY " | ||
| 2836 | "failed (err_mask=0x%x)\n", err_mask); | ||
| 2837 | return -EIO; | ||
| 2838 | } | ||
| 2839 | |||
| 2840 | if (!err_mask || sense_key != UNIT_ATTENTION) | ||
| 2841 | return 0; | ||
| 2842 | |||
| 2843 | err_mask = atapi_eh_request_sense(dev, sense_buffer, sense_key); | ||
| 2844 | if (err_mask) { | ||
| 2845 | ata_dev_printk(dev, KERN_WARNING, "failed to clear " | ||
| 2846 | "UNIT ATTENTION (err_mask=0x%x)\n", err_mask); | ||
| 2847 | return -EIO; | ||
| 2848 | } | ||
| 2849 | } | ||
| 2850 | |||
| 2851 | ata_dev_printk(dev, KERN_WARNING, | ||
| 2852 | "UNIT ATTENTION persists after %d tries\n", ATA_EH_UA_TRIES); | ||
| 2853 | |||
| 2854 | return 0; | ||
| 2855 | } | ||
| 2856 | |||
| 2613 | static int ata_link_nr_enabled(struct ata_link *link) | 2857 | static int ata_link_nr_enabled(struct ata_link *link) | 
| 2614 | { | 2858 | { | 
| 2615 | struct ata_device *dev; | 2859 | struct ata_device *dev; | 
| @@ -2697,7 +2941,7 @@ static int ata_eh_handle_dev_fail(struct ata_device *dev, int err) | |||
| 2697 | /* This is the last chance, better to slow | 2941 | /* This is the last chance, better to slow | 
| 2698 | * down than lose it. | 2942 | * down than lose it. | 
| 2699 | */ | 2943 | */ | 
| 2700 | sata_down_spd_limit(dev->link); | 2944 | sata_down_spd_limit(ata_dev_phys_link(dev)); | 
| 2701 | ata_down_xfermask_limit(dev, ATA_DNXFER_PIO); | 2945 | ata_down_xfermask_limit(dev, ATA_DNXFER_PIO); | 
| 2702 | } | 2946 | } | 
| 2703 | } | 2947 | } | 
| @@ -2707,7 +2951,7 @@ static int ata_eh_handle_dev_fail(struct ata_device *dev, int err) | |||
| 2707 | ata_dev_disable(dev); | 2951 | ata_dev_disable(dev); | 
| 2708 | 2952 | ||
| 2709 | /* detach if offline */ | 2953 | /* detach if offline */ | 
| 2710 | if (ata_link_offline(dev->link)) | 2954 | if (ata_phys_link_offline(ata_dev_phys_link(dev))) | 
| 2711 | ata_eh_detach_dev(dev); | 2955 | ata_eh_detach_dev(dev); | 
| 2712 | 2956 | ||
| 2713 | /* schedule probe if necessary */ | 2957 | /* schedule probe if necessary */ | 
| @@ -2755,7 +2999,7 @@ int ata_eh_recover(struct ata_port *ap, ata_prereset_fn_t prereset, | |||
| 2755 | struct ata_device *dev; | 2999 | struct ata_device *dev; | 
| 2756 | int nr_failed_devs; | 3000 | int nr_failed_devs; | 
| 2757 | int rc; | 3001 | int rc; | 
| 2758 | unsigned long flags; | 3002 | unsigned long flags, deadline; | 
| 2759 | 3003 | ||
| 2760 | DPRINTK("ENTER\n"); | 3004 | DPRINTK("ENTER\n"); | 
| 2761 | 3005 | ||
| @@ -2829,6 +3073,56 @@ int ata_eh_recover(struct ata_port *ap, ata_prereset_fn_t prereset, | |||
| 2829 | } | 3073 | } | 
| 2830 | } | 3074 | } | 
| 2831 | 3075 | ||
| 3076 | do { | ||
| 3077 | unsigned long now; | ||
| 3078 | |||
| 3079 | /* | ||
| 3080 | * clears ATA_EH_PARK in eh_info and resets | ||
| 3081 | * ap->park_req_pending | ||
| 3082 | */ | ||
| 3083 | ata_eh_pull_park_action(ap); | ||
| 3084 | |||
| 3085 | deadline = jiffies; | ||
| 3086 | ata_port_for_each_link(link, ap) { | ||
| 3087 | ata_link_for_each_dev(dev, link) { | ||
| 3088 | struct ata_eh_context *ehc = &link->eh_context; | ||
| 3089 | unsigned long tmp; | ||
| 3090 | |||
| 3091 | if (dev->class != ATA_DEV_ATA) | ||
| 3092 | continue; | ||
| 3093 | if (!(ehc->i.dev_action[dev->devno] & | ||
| 3094 | ATA_EH_PARK)) | ||
| 3095 | continue; | ||
| 3096 | tmp = dev->unpark_deadline; | ||
| 3097 | if (time_before(deadline, tmp)) | ||
| 3098 | deadline = tmp; | ||
| 3099 | else if (time_before_eq(tmp, jiffies)) | ||
| 3100 | continue; | ||
| 3101 | if (ehc->unloaded_mask & (1 << dev->devno)) | ||
| 3102 | continue; | ||
| 3103 | |||
| 3104 | ata_eh_park_issue_cmd(dev, 1); | ||
| 3105 | } | ||
| 3106 | } | ||
| 3107 | |||
| 3108 | now = jiffies; | ||
| 3109 | if (time_before_eq(deadline, now)) | ||
| 3110 | break; | ||
| 3111 | |||
| 3112 | deadline = wait_for_completion_timeout(&ap->park_req_pending, | ||
| 3113 | deadline - now); | ||
| 3114 | } while (deadline); | ||
| 3115 | ata_port_for_each_link(link, ap) { | ||
| 3116 | ata_link_for_each_dev(dev, link) { | ||
| 3117 | if (!(link->eh_context.unloaded_mask & | ||
| 3118 | (1 << dev->devno))) | ||
| 3119 | continue; | ||
| 3120 | |||
| 3121 | ata_eh_park_issue_cmd(dev, 0); | ||
| 3122 | ata_eh_done(link, dev, ATA_EH_PARK); | ||
| 3123 | } | ||
| 3124 | } | ||
| 3125 | |||
| 2832 | /* the rest */ | 3126 | /* the rest */ | 
| 2833 | ata_port_for_each_link(link, ap) { | 3127 | ata_port_for_each_link(link, ap) { | 
| 2834 | struct ata_eh_context *ehc = &link->eh_context; | 3128 | struct ata_eh_context *ehc = &link->eh_context; | 
| @@ -2852,6 +3146,20 @@ int ata_eh_recover(struct ata_port *ap, ata_prereset_fn_t prereset, | |||
| 2852 | ehc->i.flags &= ~ATA_EHI_SETMODE; | 3146 | ehc->i.flags &= ~ATA_EHI_SETMODE; | 
| 2853 | } | 3147 | } | 
| 2854 | 3148 | ||
| 3149 | /* If reset has been issued, clear UA to avoid | ||
| 3150 | * disrupting the current users of the device. | ||
| 3151 | */ | ||
| 3152 | if (ehc->i.flags & ATA_EHI_DID_RESET) { | ||
| 3153 | ata_link_for_each_dev(dev, link) { | ||
| 3154 | if (dev->class != ATA_DEV_ATAPI) | ||
| 3155 | continue; | ||
| 3156 | rc = atapi_eh_clear_ua(dev); | ||
| 3157 | if (rc) | ||
| 3158 | goto dev_fail; | ||
| 3159 | } | ||
| 3160 | } | ||
| 3161 | |||
| 3162 | /* configure link power saving */ | ||
| 2855 | if (ehc->i.action & ATA_EH_LPM) | 3163 | if (ehc->i.action & ATA_EH_LPM) | 
| 2856 | ata_link_for_each_dev(dev, link) | 3164 | ata_link_for_each_dev(dev, link) | 
| 2857 | ata_dev_enable_pm(dev, ap->pm_policy); | 3165 | ata_dev_enable_pm(dev, ap->pm_policy); | 
