aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/scsi/libata-eh.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/scsi/libata-eh.c')
-rw-r--r--drivers/scsi/libata-eh.c405
1 files changed, 357 insertions, 48 deletions
diff --git a/drivers/scsi/libata-eh.c b/drivers/scsi/libata-eh.c
index bf5a72aca8a4..4b6aa30f4d68 100644
--- a/drivers/scsi/libata-eh.c
+++ b/drivers/scsi/libata-eh.c
@@ -47,6 +47,8 @@
47 47
48static void __ata_port_freeze(struct ata_port *ap); 48static void __ata_port_freeze(struct ata_port *ap);
49static void ata_eh_finish(struct ata_port *ap); 49static void ata_eh_finish(struct ata_port *ap);
50static void ata_eh_handle_port_suspend(struct ata_port *ap);
51static void ata_eh_handle_port_resume(struct ata_port *ap);
50 52
51static void ata_ering_record(struct ata_ering *ering, int is_io, 53static void ata_ering_record(struct ata_ering *ering, int is_io,
52 unsigned int err_mask) 54 unsigned int err_mask)
@@ -190,7 +192,6 @@ enum scsi_eh_timer_return ata_scsi_timed_out(struct scsi_cmnd *cmd)
190void ata_scsi_error(struct Scsi_Host *host) 192void ata_scsi_error(struct Scsi_Host *host)
191{ 193{
192 struct ata_port *ap = ata_shost_to_port(host); 194 struct ata_port *ap = ata_shost_to_port(host);
193 spinlock_t *ap_lock = ap->lock;
194 int i, repeat_cnt = ATA_EH_MAX_REPEAT; 195 int i, repeat_cnt = ATA_EH_MAX_REPEAT;
195 unsigned long flags; 196 unsigned long flags;
196 197
@@ -217,7 +218,7 @@ void ata_scsi_error(struct Scsi_Host *host)
217 struct scsi_cmnd *scmd, *tmp; 218 struct scsi_cmnd *scmd, *tmp;
218 int nr_timedout = 0; 219 int nr_timedout = 0;
219 220
220 spin_lock_irqsave(ap_lock, flags); 221 spin_lock_irqsave(ap->lock, flags);
221 222
222 list_for_each_entry_safe(scmd, tmp, &host->eh_cmd_q, eh_entry) { 223 list_for_each_entry_safe(scmd, tmp, &host->eh_cmd_q, eh_entry) {
223 struct ata_queued_cmd *qc; 224 struct ata_queued_cmd *qc;
@@ -256,43 +257,49 @@ void ata_scsi_error(struct Scsi_Host *host)
256 if (nr_timedout) 257 if (nr_timedout)
257 __ata_port_freeze(ap); 258 __ata_port_freeze(ap);
258 259
259 spin_unlock_irqrestore(ap_lock, flags); 260 spin_unlock_irqrestore(ap->lock, flags);
260 } else 261 } else
261 spin_unlock_wait(ap_lock); 262 spin_unlock_wait(ap->lock);
262 263
263 repeat: 264 repeat:
264 /* invoke error handler */ 265 /* invoke error handler */
265 if (ap->ops->error_handler) { 266 if (ap->ops->error_handler) {
267 /* process port resume request */
268 ata_eh_handle_port_resume(ap);
269
266 /* fetch & clear EH info */ 270 /* fetch & clear EH info */
267 spin_lock_irqsave(ap_lock, flags); 271 spin_lock_irqsave(ap->lock, flags);
268 272
269 memset(&ap->eh_context, 0, sizeof(ap->eh_context)); 273 memset(&ap->eh_context, 0, sizeof(ap->eh_context));
270 ap->eh_context.i = ap->eh_info; 274 ap->eh_context.i = ap->eh_info;
271 memset(&ap->eh_info, 0, sizeof(ap->eh_info)); 275 memset(&ap->eh_info, 0, sizeof(ap->eh_info));
272 276
273 ap->flags |= ATA_FLAG_EH_IN_PROGRESS; 277 ap->pflags |= ATA_PFLAG_EH_IN_PROGRESS;
274 ap->flags &= ~ATA_FLAG_EH_PENDING; 278 ap->pflags &= ~ATA_PFLAG_EH_PENDING;
275 279
276 spin_unlock_irqrestore(ap_lock, flags); 280 spin_unlock_irqrestore(ap->lock, flags);
277 281
278 /* invoke EH. if unloading, just finish failed qcs */ 282 /* invoke EH, skip if unloading or suspended */
279 if (!(ap->flags & ATA_FLAG_UNLOADING)) 283 if (!(ap->pflags & (ATA_PFLAG_UNLOADING | ATA_PFLAG_SUSPENDED)))
280 ap->ops->error_handler(ap); 284 ap->ops->error_handler(ap);
281 else 285 else
282 ata_eh_finish(ap); 286 ata_eh_finish(ap);
283 287
288 /* process port suspend request */
289 ata_eh_handle_port_suspend(ap);
290
284 /* Exception might have happend after ->error_handler 291 /* Exception might have happend after ->error_handler
285 * recovered the port but before this point. Repeat 292 * recovered the port but before this point. Repeat
286 * EH in such case. 293 * EH in such case.
287 */ 294 */
288 spin_lock_irqsave(ap_lock, flags); 295 spin_lock_irqsave(ap->lock, flags);
289 296
290 if (ap->flags & ATA_FLAG_EH_PENDING) { 297 if (ap->pflags & ATA_PFLAG_EH_PENDING) {
291 if (--repeat_cnt) { 298 if (--repeat_cnt) {
292 ata_port_printk(ap, KERN_INFO, 299 ata_port_printk(ap, KERN_INFO,
293 "EH pending after completion, " 300 "EH pending after completion, "
294 "repeating EH (cnt=%d)\n", repeat_cnt); 301 "repeating EH (cnt=%d)\n", repeat_cnt);
295 spin_unlock_irqrestore(ap_lock, flags); 302 spin_unlock_irqrestore(ap->lock, flags);
296 goto repeat; 303 goto repeat;
297 } 304 }
298 ata_port_printk(ap, KERN_ERR, "EH pending after %d " 305 ata_port_printk(ap, KERN_ERR, "EH pending after %d "
@@ -302,14 +309,14 @@ void ata_scsi_error(struct Scsi_Host *host)
302 /* this run is complete, make sure EH info is clear */ 309 /* this run is complete, make sure EH info is clear */
303 memset(&ap->eh_info, 0, sizeof(ap->eh_info)); 310 memset(&ap->eh_info, 0, sizeof(ap->eh_info));
304 311
305 /* Clear host_eh_scheduled while holding ap_lock such 312 /* Clear host_eh_scheduled while holding ap->lock such
306 * that if exception occurs after this point but 313 * that if exception occurs after this point but
307 * before EH completion, SCSI midlayer will 314 * before EH completion, SCSI midlayer will
308 * re-initiate EH. 315 * re-initiate EH.
309 */ 316 */
310 host->host_eh_scheduled = 0; 317 host->host_eh_scheduled = 0;
311 318
312 spin_unlock_irqrestore(ap_lock, flags); 319 spin_unlock_irqrestore(ap->lock, flags);
313 } else { 320 } else {
314 WARN_ON(ata_qc_from_tag(ap, ap->active_tag) == NULL); 321 WARN_ON(ata_qc_from_tag(ap, ap->active_tag) == NULL);
315 ap->ops->eng_timeout(ap); 322 ap->ops->eng_timeout(ap);
@@ -321,24 +328,23 @@ void ata_scsi_error(struct Scsi_Host *host)
321 scsi_eh_flush_done_q(&ap->eh_done_q); 328 scsi_eh_flush_done_q(&ap->eh_done_q);
322 329
323 /* clean up */ 330 /* clean up */
324 spin_lock_irqsave(ap_lock, flags); 331 spin_lock_irqsave(ap->lock, flags);
325 332
326 if (ap->flags & ATA_FLAG_LOADING) { 333 if (ap->pflags & ATA_PFLAG_LOADING)
327 ap->flags &= ~ATA_FLAG_LOADING; 334 ap->pflags &= ~ATA_PFLAG_LOADING;
328 } else { 335 else if (ap->pflags & ATA_PFLAG_SCSI_HOTPLUG)
329 if (ap->flags & ATA_FLAG_SCSI_HOTPLUG) 336 queue_work(ata_aux_wq, &ap->hotplug_task);
330 queue_work(ata_aux_wq, &ap->hotplug_task); 337
331 if (ap->flags & ATA_FLAG_RECOVERED) 338 if (ap->pflags & ATA_PFLAG_RECOVERED)
332 ata_port_printk(ap, KERN_INFO, "EH complete\n"); 339 ata_port_printk(ap, KERN_INFO, "EH complete\n");
333 }
334 340
335 ap->flags &= ~(ATA_FLAG_SCSI_HOTPLUG | ATA_FLAG_RECOVERED); 341 ap->pflags &= ~(ATA_PFLAG_SCSI_HOTPLUG | ATA_PFLAG_RECOVERED);
336 342
337 /* tell wait_eh that we're done */ 343 /* tell wait_eh that we're done */
338 ap->flags &= ~ATA_FLAG_EH_IN_PROGRESS; 344 ap->pflags &= ~ATA_PFLAG_EH_IN_PROGRESS;
339 wake_up_all(&ap->eh_wait_q); 345 wake_up_all(&ap->eh_wait_q);
340 346
341 spin_unlock_irqrestore(ap_lock, flags); 347 spin_unlock_irqrestore(ap->lock, flags);
342 348
343 DPRINTK("EXIT\n"); 349 DPRINTK("EXIT\n");
344} 350}
@@ -360,7 +366,7 @@ void ata_port_wait_eh(struct ata_port *ap)
360 retry: 366 retry:
361 spin_lock_irqsave(ap->lock, flags); 367 spin_lock_irqsave(ap->lock, flags);
362 368
363 while (ap->flags & (ATA_FLAG_EH_PENDING | ATA_FLAG_EH_IN_PROGRESS)) { 369 while (ap->pflags & (ATA_PFLAG_EH_PENDING | ATA_PFLAG_EH_IN_PROGRESS)) {
364 prepare_to_wait(&ap->eh_wait_q, &wait, TASK_UNINTERRUPTIBLE); 370 prepare_to_wait(&ap->eh_wait_q, &wait, TASK_UNINTERRUPTIBLE);
365 spin_unlock_irqrestore(ap->lock, flags); 371 spin_unlock_irqrestore(ap->lock, flags);
366 schedule(); 372 schedule();
@@ -489,7 +495,7 @@ void ata_qc_schedule_eh(struct ata_queued_cmd *qc)
489 WARN_ON(!ap->ops->error_handler); 495 WARN_ON(!ap->ops->error_handler);
490 496
491 qc->flags |= ATA_QCFLAG_FAILED; 497 qc->flags |= ATA_QCFLAG_FAILED;
492 qc->ap->flags |= ATA_FLAG_EH_PENDING; 498 qc->ap->pflags |= ATA_PFLAG_EH_PENDING;
493 499
494 /* The following will fail if timeout has already expired. 500 /* The following will fail if timeout has already expired.
495 * ata_scsi_error() takes care of such scmds on EH entry. 501 * ata_scsi_error() takes care of such scmds on EH entry.
@@ -513,7 +519,7 @@ void ata_port_schedule_eh(struct ata_port *ap)
513{ 519{
514 WARN_ON(!ap->ops->error_handler); 520 WARN_ON(!ap->ops->error_handler);
515 521
516 ap->flags |= ATA_FLAG_EH_PENDING; 522 ap->pflags |= ATA_PFLAG_EH_PENDING;
517 scsi_schedule_eh(ap->host); 523 scsi_schedule_eh(ap->host);
518 524
519 DPRINTK("port EH scheduled\n"); 525 DPRINTK("port EH scheduled\n");
@@ -578,7 +584,7 @@ static void __ata_port_freeze(struct ata_port *ap)
578 if (ap->ops->freeze) 584 if (ap->ops->freeze)
579 ap->ops->freeze(ap); 585 ap->ops->freeze(ap);
580 586
581 ap->flags |= ATA_FLAG_FROZEN; 587 ap->pflags |= ATA_PFLAG_FROZEN;
582 588
583 DPRINTK("ata%u port frozen\n", ap->id); 589 DPRINTK("ata%u port frozen\n", ap->id);
584} 590}
@@ -646,7 +652,7 @@ void ata_eh_thaw_port(struct ata_port *ap)
646 652
647 spin_lock_irqsave(ap->lock, flags); 653 spin_lock_irqsave(ap->lock, flags);
648 654
649 ap->flags &= ~ATA_FLAG_FROZEN; 655 ap->pflags &= ~ATA_PFLAG_FROZEN;
650 656
651 if (ap->ops->thaw) 657 if (ap->ops->thaw)
652 ap->ops->thaw(ap); 658 ap->ops->thaw(ap);
@@ -731,7 +737,7 @@ static void ata_eh_detach_dev(struct ata_device *dev)
731 737
732 if (ata_scsi_offline_dev(dev)) { 738 if (ata_scsi_offline_dev(dev)) {
733 dev->flags |= ATA_DFLAG_DETACHED; 739 dev->flags |= ATA_DFLAG_DETACHED;
734 ap->flags |= ATA_FLAG_SCSI_HOTPLUG; 740 ap->pflags |= ATA_PFLAG_SCSI_HOTPLUG;
735 } 741 }
736 742
737 /* clear per-dev EH actions */ 743 /* clear per-dev EH actions */
@@ -760,8 +766,12 @@ static void ata_eh_about_to_do(struct ata_port *ap, struct ata_device *dev,
760 unsigned long flags; 766 unsigned long flags;
761 767
762 spin_lock_irqsave(ap->lock, flags); 768 spin_lock_irqsave(ap->lock, flags);
769
763 ata_eh_clear_action(dev, &ap->eh_info, action); 770 ata_eh_clear_action(dev, &ap->eh_info, action);
764 ap->flags |= ATA_FLAG_RECOVERED; 771
772 if (!(ap->eh_context.i.flags & ATA_EHI_QUIET))
773 ap->pflags |= ATA_PFLAG_RECOVERED;
774
765 spin_unlock_irqrestore(ap->lock, flags); 775 spin_unlock_irqrestore(ap->lock, flags);
766} 776}
767 777
@@ -1027,7 +1037,7 @@ static void ata_eh_analyze_ncq_error(struct ata_port *ap)
1027 int tag, rc; 1037 int tag, rc;
1028 1038
1029 /* if frozen, we can't do much */ 1039 /* if frozen, we can't do much */
1030 if (ap->flags & ATA_FLAG_FROZEN) 1040 if (ap->pflags & ATA_PFLAG_FROZEN)
1031 return; 1041 return;
1032 1042
1033 /* is it NCQ device error? */ 1043 /* is it NCQ device error? */
@@ -1275,6 +1285,9 @@ static void ata_eh_autopsy(struct ata_port *ap)
1275 1285
1276 DPRINTK("ENTER\n"); 1286 DPRINTK("ENTER\n");
1277 1287
1288 if (ehc->i.flags & ATA_EHI_NO_AUTOPSY)
1289 return;
1290
1278 /* obtain and analyze SError */ 1291 /* obtain and analyze SError */
1279 rc = sata_scr_read(ap, SCR_ERROR, &serror); 1292 rc = sata_scr_read(ap, SCR_ERROR, &serror);
1280 if (rc == 0) { 1293 if (rc == 0) {
@@ -1327,7 +1340,7 @@ static void ata_eh_autopsy(struct ata_port *ap)
1327 } 1340 }
1328 1341
1329 /* enforce default EH actions */ 1342 /* enforce default EH actions */
1330 if (ap->flags & ATA_FLAG_FROZEN || 1343 if (ap->pflags & ATA_PFLAG_FROZEN ||
1331 all_err_mask & (AC_ERR_HSM | AC_ERR_TIMEOUT)) 1344 all_err_mask & (AC_ERR_HSM | AC_ERR_TIMEOUT))
1332 action |= ATA_EH_SOFTRESET; 1345 action |= ATA_EH_SOFTRESET;
1333 else if (all_err_mask) 1346 else if (all_err_mask)
@@ -1346,7 +1359,7 @@ static void ata_eh_autopsy(struct ata_port *ap)
1346 1359
1347 /* record autopsy result */ 1360 /* record autopsy result */
1348 ehc->i.dev = failed_dev; 1361 ehc->i.dev = failed_dev;
1349 ehc->i.action = action; 1362 ehc->i.action |= action;
1350 1363
1351 DPRINTK("EXIT\n"); 1364 DPRINTK("EXIT\n");
1352} 1365}
@@ -1385,7 +1398,7 @@ static void ata_eh_report(struct ata_port *ap)
1385 return; 1398 return;
1386 1399
1387 frozen = ""; 1400 frozen = "";
1388 if (ap->flags & ATA_FLAG_FROZEN) 1401 if (ap->pflags & ATA_PFLAG_FROZEN)
1389 frozen = " frozen"; 1402 frozen = " frozen";
1390 1403
1391 if (ehc->i.dev) { 1404 if (ehc->i.dev) {
@@ -1465,7 +1478,7 @@ static int ata_eh_reset(struct ata_port *ap, int classify,
1465 struct ata_eh_context *ehc = &ap->eh_context; 1478 struct ata_eh_context *ehc = &ap->eh_context;
1466 unsigned int *classes = ehc->classes; 1479 unsigned int *classes = ehc->classes;
1467 int tries = ATA_EH_RESET_TRIES; 1480 int tries = ATA_EH_RESET_TRIES;
1468 int verbose = !(ap->flags & ATA_FLAG_LOADING); 1481 int verbose = !(ehc->i.flags & ATA_EHI_QUIET);
1469 unsigned int action; 1482 unsigned int action;
1470 ata_reset_fn_t reset; 1483 ata_reset_fn_t reset;
1471 int i, did_followup_srst, rc; 1484 int i, did_followup_srst, rc;
@@ -1605,7 +1618,7 @@ static int ata_eh_revalidate_and_attach(struct ata_port *ap,
1605 dev = &ap->device[i]; 1618 dev = &ap->device[i];
1606 action = ata_eh_dev_action(dev); 1619 action = ata_eh_dev_action(dev);
1607 1620
1608 if (action & ATA_EH_REVALIDATE && ata_dev_enabled(dev)) { 1621 if (action & ATA_EH_REVALIDATE && ata_dev_ready(dev)) {
1609 if (ata_port_offline(ap)) { 1622 if (ata_port_offline(ap)) {
1610 rc = -EIO; 1623 rc = -EIO;
1611 break; 1624 break;
@@ -1636,7 +1649,7 @@ static int ata_eh_revalidate_and_attach(struct ata_port *ap,
1636 } 1649 }
1637 1650
1638 spin_lock_irqsave(ap->lock, flags); 1651 spin_lock_irqsave(ap->lock, flags);
1639 ap->flags |= ATA_FLAG_SCSI_HOTPLUG; 1652 ap->pflags |= ATA_PFLAG_SCSI_HOTPLUG;
1640 spin_unlock_irqrestore(ap->lock, flags); 1653 spin_unlock_irqrestore(ap->lock, flags);
1641 } 1654 }
1642 } 1655 }
@@ -1648,6 +1661,164 @@ static int ata_eh_revalidate_and_attach(struct ata_port *ap,
1648 return rc; 1661 return rc;
1649} 1662}
1650 1663
1664/**
1665 * ata_eh_suspend - handle suspend EH action
1666 * @ap: target host port
1667 * @r_failed_dev: result parameter to indicate failing device
1668 *
1669 * Handle suspend EH action. Disk devices are spinned down and
1670 * other types of devices are just marked suspended. Once
1671 * suspended, no EH action to the device is allowed until it is
1672 * resumed.
1673 *
1674 * LOCKING:
1675 * Kernel thread context (may sleep).
1676 *
1677 * RETURNS:
1678 * 0 on success, -errno otherwise
1679 */
1680static int ata_eh_suspend(struct ata_port *ap, struct ata_device **r_failed_dev)
1681{
1682 struct ata_device *dev;
1683 int i, rc = 0;
1684
1685 DPRINTK("ENTER\n");
1686
1687 for (i = 0; i < ATA_MAX_DEVICES; i++) {
1688 unsigned long flags;
1689 unsigned int action, err_mask;
1690
1691 dev = &ap->device[i];
1692 action = ata_eh_dev_action(dev);
1693
1694 if (!ata_dev_enabled(dev) || !(action & ATA_EH_SUSPEND))
1695 continue;
1696
1697 WARN_ON(dev->flags & ATA_DFLAG_SUSPENDED);
1698
1699 ata_eh_about_to_do(ap, dev, ATA_EH_SUSPEND);
1700
1701 if (dev->class == ATA_DEV_ATA && !(action & ATA_EH_PM_FREEZE)) {
1702 /* flush cache */
1703 rc = ata_flush_cache(dev);
1704 if (rc)
1705 break;
1706
1707 /* spin down */
1708 err_mask = ata_do_simple_cmd(dev, ATA_CMD_STANDBYNOW1);
1709 if (err_mask) {
1710 ata_dev_printk(dev, KERN_ERR, "failed to "
1711 "spin down (err_mask=0x%x)\n",
1712 err_mask);
1713 rc = -EIO;
1714 break;
1715 }
1716 }
1717
1718 spin_lock_irqsave(ap->lock, flags);
1719 dev->flags |= ATA_DFLAG_SUSPENDED;
1720 spin_unlock_irqrestore(ap->lock, flags);
1721
1722 ata_eh_done(ap, dev, ATA_EH_SUSPEND);
1723 }
1724
1725 if (rc)
1726 *r_failed_dev = dev;
1727
1728 DPRINTK("EXIT\n");
1729 return 0;
1730}
1731
1732/**
1733 * ata_eh_prep_resume - prep for resume EH action
1734 * @ap: target host port
1735 *
1736 * Clear SUSPENDED in preparation for scheduled resume actions.
1737 * This allows other parts of EH to access the devices being
1738 * resumed.
1739 *
1740 * LOCKING:
1741 * Kernel thread context (may sleep).
1742 */
1743static void ata_eh_prep_resume(struct ata_port *ap)
1744{
1745 struct ata_device *dev;
1746 unsigned long flags;
1747 int i;
1748
1749 DPRINTK("ENTER\n");
1750
1751 for (i = 0; i < ATA_MAX_DEVICES; i++) {
1752 unsigned int action;
1753
1754 dev = &ap->device[i];
1755 action = ata_eh_dev_action(dev);
1756
1757 if (!ata_dev_enabled(dev) || !(action & ATA_EH_RESUME))
1758 continue;
1759
1760 spin_lock_irqsave(ap->lock, flags);
1761 dev->flags &= ~ATA_DFLAG_SUSPENDED;
1762 spin_unlock_irqrestore(ap->lock, flags);
1763 }
1764
1765 DPRINTK("EXIT\n");
1766}
1767
1768/**
1769 * ata_eh_resume - handle resume EH action
1770 * @ap: target host port
1771 * @r_failed_dev: result parameter to indicate failing device
1772 *
1773 * Handle resume EH action. Target devices are already reset and
1774 * revalidated. Spinning up is the only operation left.
1775 *
1776 * LOCKING:
1777 * Kernel thread context (may sleep).
1778 *
1779 * RETURNS:
1780 * 0 on success, -errno otherwise
1781 */
1782static int ata_eh_resume(struct ata_port *ap, struct ata_device **r_failed_dev)
1783{
1784 struct ata_device *dev;
1785 int i, rc = 0;
1786
1787 DPRINTK("ENTER\n");
1788
1789 for (i = 0; i < ATA_MAX_DEVICES; i++) {
1790 unsigned int action, err_mask;
1791
1792 dev = &ap->device[i];
1793 action = ata_eh_dev_action(dev);
1794
1795 if (!ata_dev_enabled(dev) || !(action & ATA_EH_RESUME))
1796 continue;
1797
1798 ata_eh_about_to_do(ap, dev, ATA_EH_RESUME);
1799
1800 if (dev->class == ATA_DEV_ATA && !(action & ATA_EH_PM_FREEZE)) {
1801 err_mask = ata_do_simple_cmd(dev,
1802 ATA_CMD_IDLEIMMEDIATE);
1803 if (err_mask) {
1804 ata_dev_printk(dev, KERN_ERR, "failed to "
1805 "spin up (err_mask=0x%x)\n",
1806 err_mask);
1807 rc = -EIO;
1808 break;
1809 }
1810 }
1811
1812 ata_eh_done(ap, dev, ATA_EH_RESUME);
1813 }
1814
1815 if (rc)
1816 *r_failed_dev = dev;
1817
1818 DPRINTK("EXIT\n");
1819 return 0;
1820}
1821
1651static int ata_port_nr_enabled(struct ata_port *ap) 1822static int ata_port_nr_enabled(struct ata_port *ap)
1652{ 1823{
1653 int i, cnt = 0; 1824 int i, cnt = 0;
@@ -1673,7 +1844,19 @@ static int ata_eh_skip_recovery(struct ata_port *ap)
1673 struct ata_eh_context *ehc = &ap->eh_context; 1844 struct ata_eh_context *ehc = &ap->eh_context;
1674 int i; 1845 int i;
1675 1846
1676 if (ap->flags & ATA_FLAG_FROZEN || ata_port_nr_enabled(ap)) 1847 /* skip if all possible devices are suspended */
1848 for (i = 0; i < ata_port_max_devices(ap); i++) {
1849 struct ata_device *dev = &ap->device[i];
1850
1851 if (ata_dev_absent(dev) || ata_dev_ready(dev))
1852 break;
1853 }
1854
1855 if (i == ata_port_max_devices(ap))
1856 return 1;
1857
1858 /* always thaw frozen port and recover failed devices */
1859 if (ap->pflags & ATA_PFLAG_FROZEN || ata_port_nr_enabled(ap))
1677 return 0; 1860 return 0;
1678 1861
1679 /* skip if class codes for all vacant slots are ATA_DEV_NONE */ 1862 /* skip if class codes for all vacant slots are ATA_DEV_NONE */
@@ -1744,9 +1927,12 @@ static int ata_eh_recover(struct ata_port *ap, ata_prereset_fn_t prereset,
1744 rc = 0; 1927 rc = 0;
1745 1928
1746 /* if UNLOADING, finish immediately */ 1929 /* if UNLOADING, finish immediately */
1747 if (ap->flags & ATA_FLAG_UNLOADING) 1930 if (ap->pflags & ATA_PFLAG_UNLOADING)
1748 goto out; 1931 goto out;
1749 1932
1933 /* prep for resume */
1934 ata_eh_prep_resume(ap);
1935
1750 /* skip EH if possible. */ 1936 /* skip EH if possible. */
1751 if (ata_eh_skip_recovery(ap)) 1937 if (ata_eh_skip_recovery(ap))
1752 ehc->i.action = 0; 1938 ehc->i.action = 0;
@@ -1774,6 +1960,11 @@ static int ata_eh_recover(struct ata_port *ap, ata_prereset_fn_t prereset,
1774 if (rc) 1960 if (rc)
1775 goto dev_fail; 1961 goto dev_fail;
1776 1962
1963 /* resume devices */
1964 rc = ata_eh_resume(ap, &dev);
1965 if (rc)
1966 goto dev_fail;
1967
1777 /* configure transfer mode if the port has been reset */ 1968 /* configure transfer mode if the port has been reset */
1778 if (ehc->i.flags & ATA_EHI_DID_RESET) { 1969 if (ehc->i.flags & ATA_EHI_DID_RESET) {
1779 rc = ata_set_mode(ap, &dev); 1970 rc = ata_set_mode(ap, &dev);
@@ -1783,6 +1974,11 @@ static int ata_eh_recover(struct ata_port *ap, ata_prereset_fn_t prereset,
1783 } 1974 }
1784 } 1975 }
1785 1976
1977 /* suspend devices */
1978 rc = ata_eh_suspend(ap, &dev);
1979 if (rc)
1980 goto dev_fail;
1981
1786 goto out; 1982 goto out;
1787 1983
1788 dev_fail: 1984 dev_fail:
@@ -1908,11 +2104,124 @@ void ata_do_eh(struct ata_port *ap, ata_prereset_fn_t prereset,
1908 ata_reset_fn_t softreset, ata_reset_fn_t hardreset, 2104 ata_reset_fn_t softreset, ata_reset_fn_t hardreset,
1909 ata_postreset_fn_t postreset) 2105 ata_postreset_fn_t postreset)
1910{ 2106{
1911 if (!(ap->flags & ATA_FLAG_LOADING)) { 2107 ata_eh_autopsy(ap);
1912 ata_eh_autopsy(ap); 2108 ata_eh_report(ap);
1913 ata_eh_report(ap);
1914 }
1915
1916 ata_eh_recover(ap, prereset, softreset, hardreset, postreset); 2109 ata_eh_recover(ap, prereset, softreset, hardreset, postreset);
1917 ata_eh_finish(ap); 2110 ata_eh_finish(ap);
1918} 2111}
2112
2113/**
2114 * ata_eh_handle_port_suspend - perform port suspend operation
2115 * @ap: port to suspend
2116 *
2117 * Suspend @ap.
2118 *
2119 * LOCKING:
2120 * Kernel thread context (may sleep).
2121 */
2122static void ata_eh_handle_port_suspend(struct ata_port *ap)
2123{
2124 unsigned long flags;
2125 int rc = 0;
2126
2127 /* are we suspending? */
2128 spin_lock_irqsave(ap->lock, flags);
2129 if (!(ap->pflags & ATA_PFLAG_PM_PENDING) ||
2130 ap->pm_mesg.event == PM_EVENT_ON) {
2131 spin_unlock_irqrestore(ap->lock, flags);
2132 return;
2133 }
2134 spin_unlock_irqrestore(ap->lock, flags);
2135
2136 WARN_ON(ap->pflags & ATA_PFLAG_SUSPENDED);
2137
2138 /* suspend */
2139 ata_eh_freeze_port(ap);
2140
2141 if (ap->ops->port_suspend)
2142 rc = ap->ops->port_suspend(ap, ap->pm_mesg);
2143
2144 /* report result */
2145 spin_lock_irqsave(ap->lock, flags);
2146
2147 ap->pflags &= ~ATA_PFLAG_PM_PENDING;
2148 if (rc == 0)
2149 ap->pflags |= ATA_PFLAG_SUSPENDED;
2150 else
2151 ata_port_schedule_eh(ap);
2152
2153 if (ap->pm_result) {
2154 *ap->pm_result = rc;
2155 ap->pm_result = NULL;
2156 }
2157
2158 spin_unlock_irqrestore(ap->lock, flags);
2159
2160 return;
2161}
2162
2163/**
2164 * ata_eh_handle_port_resume - perform port resume operation
2165 * @ap: port to resume
2166 *
2167 * Resume @ap.
2168 *
2169 * This function also waits upto one second until all devices
2170 * hanging off this port requests resume EH action. This is to
2171 * prevent invoking EH and thus reset multiple times on resume.
2172 *
2173 * On DPM resume, where some of devices might not be resumed
2174 * together, this may delay port resume upto one second, but such
2175 * DPM resumes are rare and 1 sec delay isn't too bad.
2176 *
2177 * LOCKING:
2178 * Kernel thread context (may sleep).
2179 */
2180static void ata_eh_handle_port_resume(struct ata_port *ap)
2181{
2182 unsigned long timeout;
2183 unsigned long flags;
2184 int i, rc = 0;
2185
2186 /* are we resuming? */
2187 spin_lock_irqsave(ap->lock, flags);
2188 if (!(ap->pflags & ATA_PFLAG_PM_PENDING) ||
2189 ap->pm_mesg.event != PM_EVENT_ON) {
2190 spin_unlock_irqrestore(ap->lock, flags);
2191 return;
2192 }
2193 spin_unlock_irqrestore(ap->lock, flags);
2194
2195 /* spurious? */
2196 if (!(ap->pflags & ATA_PFLAG_SUSPENDED))
2197 goto done;
2198
2199 if (ap->ops->port_resume)
2200 rc = ap->ops->port_resume(ap);
2201
2202 /* give devices time to request EH */
2203 timeout = jiffies + HZ; /* 1s max */
2204 while (1) {
2205 for (i = 0; i < ATA_MAX_DEVICES; i++) {
2206 struct ata_device *dev = &ap->device[i];
2207 unsigned int action = ata_eh_dev_action(dev);
2208
2209 if ((dev->flags & ATA_DFLAG_SUSPENDED) &&
2210 !(action & ATA_EH_RESUME))
2211 break;
2212 }
2213
2214 if (i == ATA_MAX_DEVICES || time_after(jiffies, timeout))
2215 break;
2216 msleep(10);
2217 }
2218
2219 done:
2220 spin_lock_irqsave(ap->lock, flags);
2221 ap->pflags &= ~(ATA_PFLAG_PM_PENDING | ATA_PFLAG_SUSPENDED);
2222 if (ap->pm_result) {
2223 *ap->pm_result = rc;
2224 ap->pm_result = NULL;
2225 }
2226 spin_unlock_irqrestore(ap->lock, flags);
2227}