diff options
Diffstat (limited to 'drivers/ata/libata-eh.c')
-rw-r--r-- | drivers/ata/libata-eh.c | 349 |
1 files changed, 295 insertions, 54 deletions
diff --git a/drivers/ata/libata-eh.c b/drivers/ata/libata-eh.c index e48302eae55f..7f099d6e4e0b 100644 --- a/drivers/ata/libata-eh.c +++ b/drivers/ata/libata-eh.c | |||
@@ -57,6 +57,7 @@ enum { | |||
57 | /* error flags */ | 57 | /* error flags */ |
58 | ATA_EFLAG_IS_IO = (1 << 0), | 58 | ATA_EFLAG_IS_IO = (1 << 0), |
59 | ATA_EFLAG_DUBIOUS_XFER = (1 << 1), | 59 | ATA_EFLAG_DUBIOUS_XFER = (1 << 1), |
60 | ATA_EFLAG_OLD_ER = (1 << 31), | ||
60 | 61 | ||
61 | /* error categories */ | 62 | /* error categories */ |
62 | ATA_ECAT_NONE = 0, | 63 | ATA_ECAT_NONE = 0, |
@@ -396,14 +397,9 @@ static struct ata_ering_entry *ata_ering_top(struct ata_ering *ering) | |||
396 | return NULL; | 397 | return NULL; |
397 | } | 398 | } |
398 | 399 | ||
399 | static void ata_ering_clear(struct ata_ering *ering) | 400 | int ata_ering_map(struct ata_ering *ering, |
400 | { | 401 | int (*map_fn)(struct ata_ering_entry *, void *), |
401 | memset(ering, 0, sizeof(*ering)); | 402 | void *arg) |
402 | } | ||
403 | |||
404 | static int ata_ering_map(struct ata_ering *ering, | ||
405 | int (*map_fn)(struct ata_ering_entry *, void *), | ||
406 | void *arg) | ||
407 | { | 403 | { |
408 | int idx, rc = 0; | 404 | int idx, rc = 0; |
409 | struct ata_ering_entry *ent; | 405 | struct ata_ering_entry *ent; |
@@ -422,6 +418,17 @@ static int ata_ering_map(struct ata_ering *ering, | |||
422 | return rc; | 418 | return rc; |
423 | } | 419 | } |
424 | 420 | ||
421 | int ata_ering_clear_cb(struct ata_ering_entry *ent, void *void_arg) | ||
422 | { | ||
423 | ent->eflags |= ATA_EFLAG_OLD_ER; | ||
424 | return 0; | ||
425 | } | ||
426 | |||
427 | static void ata_ering_clear(struct ata_ering *ering) | ||
428 | { | ||
429 | ata_ering_map(ering, ata_ering_clear_cb, NULL); | ||
430 | } | ||
431 | |||
425 | static unsigned int ata_eh_dev_action(struct ata_device *dev) | 432 | static unsigned int ata_eh_dev_action(struct ata_device *dev) |
426 | { | 433 | { |
427 | struct ata_eh_context *ehc = &dev->link->eh_context; | 434 | struct ata_eh_context *ehc = &dev->link->eh_context; |
@@ -456,6 +463,41 @@ static void ata_eh_clear_action(struct ata_link *link, struct ata_device *dev, | |||
456 | } | 463 | } |
457 | 464 | ||
458 | /** | 465 | /** |
466 | * ata_eh_acquire - acquire EH ownership | ||
467 | * @ap: ATA port to acquire EH ownership for | ||
468 | * | ||
469 | * Acquire EH ownership for @ap. This is the basic exclusion | ||
470 | * mechanism for ports sharing a host. Only one port hanging off | ||
471 | * the same host can claim the ownership of EH. | ||
472 | * | ||
473 | * LOCKING: | ||
474 | * EH context. | ||
475 | */ | ||
476 | void ata_eh_acquire(struct ata_port *ap) | ||
477 | { | ||
478 | mutex_lock(&ap->host->eh_mutex); | ||
479 | WARN_ON_ONCE(ap->host->eh_owner); | ||
480 | ap->host->eh_owner = current; | ||
481 | } | ||
482 | |||
483 | /** | ||
484 | * ata_eh_release - release EH ownership | ||
485 | * @ap: ATA port to release EH ownership for | ||
486 | * | ||
487 | * Release EH ownership for @ap if the caller. The caller must | ||
488 | * have acquired EH ownership using ata_eh_acquire() previously. | ||
489 | * | ||
490 | * LOCKING: | ||
491 | * EH context. | ||
492 | */ | ||
493 | void ata_eh_release(struct ata_port *ap) | ||
494 | { | ||
495 | WARN_ON_ONCE(ap->host->eh_owner != current); | ||
496 | ap->host->eh_owner = NULL; | ||
497 | mutex_unlock(&ap->host->eh_mutex); | ||
498 | } | ||
499 | |||
500 | /** | ||
459 | * ata_scsi_timed_out - SCSI layer time out callback | 501 | * ata_scsi_timed_out - SCSI layer time out callback |
460 | * @cmd: timed out SCSI command | 502 | * @cmd: timed out SCSI command |
461 | * | 503 | * |
@@ -545,11 +587,43 @@ static void ata_eh_unload(struct ata_port *ap) | |||
545 | void ata_scsi_error(struct Scsi_Host *host) | 587 | void ata_scsi_error(struct Scsi_Host *host) |
546 | { | 588 | { |
547 | struct ata_port *ap = ata_shost_to_port(host); | 589 | struct ata_port *ap = ata_shost_to_port(host); |
548 | int i; | ||
549 | unsigned long flags; | 590 | unsigned long flags; |
591 | LIST_HEAD(eh_work_q); | ||
550 | 592 | ||
551 | DPRINTK("ENTER\n"); | 593 | DPRINTK("ENTER\n"); |
552 | 594 | ||
595 | spin_lock_irqsave(host->host_lock, flags); | ||
596 | list_splice_init(&host->eh_cmd_q, &eh_work_q); | ||
597 | spin_unlock_irqrestore(host->host_lock, flags); | ||
598 | |||
599 | ata_scsi_cmd_error_handler(host, ap, &eh_work_q); | ||
600 | |||
601 | /* If we timed raced normal completion and there is nothing to | ||
602 | recover nr_timedout == 0 why exactly are we doing error recovery ? */ | ||
603 | ata_scsi_port_error_handler(host, ap); | ||
604 | |||
605 | /* finish or retry handled scmd's and clean up */ | ||
606 | WARN_ON(host->host_failed || !list_empty(&eh_work_q)); | ||
607 | |||
608 | DPRINTK("EXIT\n"); | ||
609 | } | ||
610 | |||
611 | /** | ||
612 | * ata_scsi_cmd_error_handler - error callback for a list of commands | ||
613 | * @host: scsi host containing the port | ||
614 | * @ap: ATA port within the host | ||
615 | * @eh_work_q: list of commands to process | ||
616 | * | ||
617 | * process the given list of commands and return those finished to the | ||
618 | * ap->eh_done_q. This function is the first part of the libata error | ||
619 | * handler which processes a given list of failed commands. | ||
620 | */ | ||
621 | void ata_scsi_cmd_error_handler(struct Scsi_Host *host, struct ata_port *ap, | ||
622 | struct list_head *eh_work_q) | ||
623 | { | ||
624 | int i; | ||
625 | unsigned long flags; | ||
626 | |||
553 | /* make sure sff pio task is not running */ | 627 | /* make sure sff pio task is not running */ |
554 | ata_sff_flush_pio_task(ap); | 628 | ata_sff_flush_pio_task(ap); |
555 | 629 | ||
@@ -572,20 +646,20 @@ void ata_scsi_error(struct Scsi_Host *host) | |||
572 | int nr_timedout = 0; | 646 | int nr_timedout = 0; |
573 | 647 | ||
574 | spin_lock_irqsave(ap->lock, flags); | 648 | spin_lock_irqsave(ap->lock, flags); |
575 | 649 | ||
576 | /* This must occur under the ap->lock as we don't want | 650 | /* This must occur under the ap->lock as we don't want |
577 | a polled recovery to race the real interrupt handler | 651 | a polled recovery to race the real interrupt handler |
578 | 652 | ||
579 | The lost_interrupt handler checks for any completed but | 653 | The lost_interrupt handler checks for any completed but |
580 | non-notified command and completes much like an IRQ handler. | 654 | non-notified command and completes much like an IRQ handler. |
581 | 655 | ||
582 | We then fall into the error recovery code which will treat | 656 | We then fall into the error recovery code which will treat |
583 | this as if normal completion won the race */ | 657 | this as if normal completion won the race */ |
584 | 658 | ||
585 | if (ap->ops->lost_interrupt) | 659 | if (ap->ops->lost_interrupt) |
586 | ap->ops->lost_interrupt(ap); | 660 | ap->ops->lost_interrupt(ap); |
587 | 661 | ||
588 | list_for_each_entry_safe(scmd, tmp, &host->eh_cmd_q, eh_entry) { | 662 | list_for_each_entry_safe(scmd, tmp, eh_work_q, eh_entry) { |
589 | struct ata_queued_cmd *qc; | 663 | struct ata_queued_cmd *qc; |
590 | 664 | ||
591 | for (i = 0; i < ATA_MAX_QUEUE; i++) { | 665 | for (i = 0; i < ATA_MAX_QUEUE; i++) { |
@@ -628,15 +702,29 @@ void ata_scsi_error(struct Scsi_Host *host) | |||
628 | ap->eh_tries = ATA_EH_MAX_TRIES; | 702 | ap->eh_tries = ATA_EH_MAX_TRIES; |
629 | } else | 703 | } else |
630 | spin_unlock_wait(ap->lock); | 704 | spin_unlock_wait(ap->lock); |
631 | |||
632 | /* If we timed raced normal completion and there is nothing to | ||
633 | recover nr_timedout == 0 why exactly are we doing error recovery ? */ | ||
634 | 705 | ||
635 | repeat: | 706 | } |
707 | EXPORT_SYMBOL(ata_scsi_cmd_error_handler); | ||
708 | |||
709 | /** | ||
710 | * ata_scsi_port_error_handler - recover the port after the commands | ||
711 | * @host: SCSI host containing the port | ||
712 | * @ap: the ATA port | ||
713 | * | ||
714 | * Handle the recovery of the port @ap after all the commands | ||
715 | * have been recovered. | ||
716 | */ | ||
717 | void ata_scsi_port_error_handler(struct Scsi_Host *host, struct ata_port *ap) | ||
718 | { | ||
719 | unsigned long flags; | ||
720 | |||
636 | /* invoke error handler */ | 721 | /* invoke error handler */ |
637 | if (ap->ops->error_handler) { | 722 | if (ap->ops->error_handler) { |
638 | struct ata_link *link; | 723 | struct ata_link *link; |
639 | 724 | ||
725 | /* acquire EH ownership */ | ||
726 | ata_eh_acquire(ap); | ||
727 | repeat: | ||
640 | /* kill fast drain timer */ | 728 | /* kill fast drain timer */ |
641 | del_timer_sync(&ap->fastdrain_timer); | 729 | del_timer_sync(&ap->fastdrain_timer); |
642 | 730 | ||
@@ -683,7 +771,7 @@ void ata_scsi_error(struct Scsi_Host *host) | |||
683 | /* process port suspend request */ | 771 | /* process port suspend request */ |
684 | ata_eh_handle_port_suspend(ap); | 772 | ata_eh_handle_port_suspend(ap); |
685 | 773 | ||
686 | /* Exception might have happend after ->error_handler | 774 | /* Exception might have happened after ->error_handler |
687 | * recovered the port but before this point. Repeat | 775 | * recovered the port but before this point. Repeat |
688 | * EH in such case. | 776 | * EH in such case. |
689 | */ | 777 | */ |
@@ -711,14 +799,12 @@ void ata_scsi_error(struct Scsi_Host *host) | |||
711 | host->host_eh_scheduled = 0; | 799 | host->host_eh_scheduled = 0; |
712 | 800 | ||
713 | spin_unlock_irqrestore(ap->lock, flags); | 801 | spin_unlock_irqrestore(ap->lock, flags); |
802 | ata_eh_release(ap); | ||
714 | } else { | 803 | } else { |
715 | WARN_ON(ata_qc_from_tag(ap, ap->link.active_tag) == NULL); | 804 | WARN_ON(ata_qc_from_tag(ap, ap->link.active_tag) == NULL); |
716 | ap->ops->eng_timeout(ap); | 805 | ap->ops->eng_timeout(ap); |
717 | } | 806 | } |
718 | 807 | ||
719 | /* finish or retry handled scmd's and clean up */ | ||
720 | WARN_ON(host->host_failed || !list_empty(&host->eh_cmd_q)); | ||
721 | |||
722 | scsi_eh_flush_done_q(&ap->eh_done_q); | 808 | scsi_eh_flush_done_q(&ap->eh_done_q); |
723 | 809 | ||
724 | /* clean up */ | 810 | /* clean up */ |
@@ -739,9 +825,8 @@ void ata_scsi_error(struct Scsi_Host *host) | |||
739 | wake_up_all(&ap->eh_wait_q); | 825 | wake_up_all(&ap->eh_wait_q); |
740 | 826 | ||
741 | spin_unlock_irqrestore(ap->lock, flags); | 827 | spin_unlock_irqrestore(ap->lock, flags); |
742 | |||
743 | DPRINTK("EXIT\n"); | ||
744 | } | 828 | } |
829 | EXPORT_SYMBOL_GPL(ata_scsi_port_error_handler); | ||
745 | 830 | ||
746 | /** | 831 | /** |
747 | * ata_port_wait_eh - Wait for the currently pending EH to complete | 832 | * ata_port_wait_eh - Wait for the currently pending EH to complete |
@@ -772,7 +857,7 @@ void ata_port_wait_eh(struct ata_port *ap) | |||
772 | 857 | ||
773 | /* make sure SCSI EH is complete */ | 858 | /* make sure SCSI EH is complete */ |
774 | if (scsi_host_in_recovery(ap->scsi_host)) { | 859 | if (scsi_host_in_recovery(ap->scsi_host)) { |
775 | msleep(10); | 860 | ata_msleep(ap, 10); |
776 | goto retry; | 861 | goto retry; |
777 | } | 862 | } |
778 | } | 863 | } |
@@ -1573,9 +1658,9 @@ static void ata_eh_analyze_serror(struct ata_link *link) | |||
1573 | * host links. For disabled PMP links, only N bit is | 1658 | * host links. For disabled PMP links, only N bit is |
1574 | * considered as X bit is left at 1 for link plugging. | 1659 | * considered as X bit is left at 1 for link plugging. |
1575 | */ | 1660 | */ |
1576 | hotplug_mask = 0; | 1661 | if (link->lpm_policy > ATA_LPM_MAX_POWER) |
1577 | 1662 | hotplug_mask = 0; /* hotplug doesn't work w/ LPM */ | |
1578 | if (!(link->flags & ATA_LFLAG_DISABLED) || ata_is_host_link(link)) | 1663 | else if (!(link->flags & ATA_LFLAG_DISABLED) || ata_is_host_link(link)) |
1579 | hotplug_mask = SERR_PHYRDY_CHG | SERR_DEV_XCHG; | 1664 | hotplug_mask = SERR_PHYRDY_CHG | SERR_DEV_XCHG; |
1580 | else | 1665 | else |
1581 | hotplug_mask = SERR_PHYRDY_CHG; | 1666 | hotplug_mask = SERR_PHYRDY_CHG; |
@@ -1657,7 +1742,7 @@ void ata_eh_analyze_ncq_error(struct ata_link *link) | |||
1657 | * | 1742 | * |
1658 | * Analyze taskfile of @qc and further determine cause of | 1743 | * Analyze taskfile of @qc and further determine cause of |
1659 | * failure. This function also requests ATAPI sense data if | 1744 | * failure. This function also requests ATAPI sense data if |
1660 | * avaliable. | 1745 | * available. |
1661 | * | 1746 | * |
1662 | * LOCKING: | 1747 | * LOCKING: |
1663 | * Kernel thread context (may sleep). | 1748 | * Kernel thread context (may sleep). |
@@ -1755,7 +1840,7 @@ static int speed_down_verdict_cb(struct ata_ering_entry *ent, void *void_arg) | |||
1755 | struct speed_down_verdict_arg *arg = void_arg; | 1840 | struct speed_down_verdict_arg *arg = void_arg; |
1756 | int cat; | 1841 | int cat; |
1757 | 1842 | ||
1758 | if (ent->timestamp < arg->since) | 1843 | if ((ent->eflags & ATA_EFLAG_OLD_ER) || (ent->timestamp < arg->since)) |
1759 | return -1; | 1844 | return -1; |
1760 | 1845 | ||
1761 | cat = ata_eh_categorize_error(ent->eflags, ent->err_mask, | 1846 | cat = ata_eh_categorize_error(ent->eflags, ent->err_mask, |
@@ -1808,7 +1893,7 @@ static int speed_down_verdict_cb(struct ata_ering_entry *ent, void *void_arg) | |||
1808 | * occurred during last 5 mins, NCQ_OFF. | 1893 | * occurred during last 5 mins, NCQ_OFF. |
1809 | * | 1894 | * |
1810 | * 3. If more than 8 ATA_BUS, TOUT_HSM or UNK_DEV errors | 1895 | * 3. If more than 8 ATA_BUS, TOUT_HSM or UNK_DEV errors |
1811 | * ocurred during last 5 mins, FALLBACK_TO_PIO | 1896 | * occurred during last 5 mins, FALLBACK_TO_PIO |
1812 | * | 1897 | * |
1813 | * 4. If more than 3 TOUT_HSM or UNK_DEV errors occurred | 1898 | * 4. If more than 3 TOUT_HSM or UNK_DEV errors occurred |
1814 | * during last 10 mins, NCQ_OFF. | 1899 | * during last 10 mins, NCQ_OFF. |
@@ -2492,7 +2577,7 @@ int ata_eh_reset(struct ata_link *link, int classify, | |||
2492 | if (link->flags & ATA_LFLAG_NO_SRST) | 2577 | if (link->flags & ATA_LFLAG_NO_SRST) |
2493 | softreset = NULL; | 2578 | softreset = NULL; |
2494 | 2579 | ||
2495 | /* make sure each reset attemp is at least COOL_DOWN apart */ | 2580 | /* make sure each reset attempt is at least COOL_DOWN apart */ |
2496 | if (ehc->i.flags & ATA_EHI_DID_RESET) { | 2581 | if (ehc->i.flags & ATA_EHI_DID_RESET) { |
2497 | now = jiffies; | 2582 | now = jiffies; |
2498 | WARN_ON(time_after(ehc->last_reset, now)); | 2583 | WARN_ON(time_after(ehc->last_reset, now)); |
@@ -2651,7 +2736,7 @@ int ata_eh_reset(struct ata_link *link, int classify, | |||
2651 | if (!reset) { | 2736 | if (!reset) { |
2652 | ata_link_printk(link, KERN_ERR, | 2737 | ata_link_printk(link, KERN_ERR, |
2653 | "follow-up softreset required " | 2738 | "follow-up softreset required " |
2654 | "but no softreset avaliable\n"); | 2739 | "but no softreset available\n"); |
2655 | failed_link = link; | 2740 | failed_link = link; |
2656 | rc = -EINVAL; | 2741 | rc = -EINVAL; |
2657 | goto fail; | 2742 | goto fail; |
@@ -2717,10 +2802,11 @@ int ata_eh_reset(struct ata_link *link, int classify, | |||
2717 | } | 2802 | } |
2718 | 2803 | ||
2719 | /* | 2804 | /* |
2720 | * Some controllers can't be frozen very well and may set | 2805 | * Some controllers can't be frozen very well and may set spurious |
2721 | * spuruious error conditions during reset. Clear accumulated | 2806 | * error conditions during reset. Clear accumulated error |
2722 | * error information. As reset is the final recovery action, | 2807 | * information and re-thaw the port if frozen. As reset is the |
2723 | * nothing is lost by doing this. | 2808 | * final recovery action and we cross check link onlineness against |
2809 | * device classification later, no hotplug event is lost by this. | ||
2724 | */ | 2810 | */ |
2725 | spin_lock_irqsave(link->ap->lock, flags); | 2811 | spin_lock_irqsave(link->ap->lock, flags); |
2726 | memset(&link->eh_info, 0, sizeof(link->eh_info)); | 2812 | memset(&link->eh_info, 0, sizeof(link->eh_info)); |
@@ -2729,6 +2815,9 @@ int ata_eh_reset(struct ata_link *link, int classify, | |||
2729 | ap->pflags &= ~ATA_PFLAG_EH_PENDING; | 2815 | ap->pflags &= ~ATA_PFLAG_EH_PENDING; |
2730 | spin_unlock_irqrestore(link->ap->lock, flags); | 2816 | spin_unlock_irqrestore(link->ap->lock, flags); |
2731 | 2817 | ||
2818 | if (ap->pflags & ATA_PFLAG_FROZEN) | ||
2819 | ata_eh_thaw_port(ap); | ||
2820 | |||
2732 | /* | 2821 | /* |
2733 | * Make sure onlineness and classification result correspond. | 2822 | * Make sure onlineness and classification result correspond. |
2734 | * Hotplug could have happened during reset and some | 2823 | * Hotplug could have happened during reset and some |
@@ -2777,8 +2866,9 @@ int ata_eh_reset(struct ata_link *link, int classify, | |||
2777 | ata_eh_done(link, NULL, ATA_EH_RESET); | 2866 | ata_eh_done(link, NULL, ATA_EH_RESET); |
2778 | if (slave) | 2867 | if (slave) |
2779 | ata_eh_done(slave, NULL, ATA_EH_RESET); | 2868 | ata_eh_done(slave, NULL, ATA_EH_RESET); |
2780 | ehc->last_reset = jiffies; /* update to completion time */ | 2869 | ehc->last_reset = jiffies; /* update to completion time */ |
2781 | ehc->i.action |= ATA_EH_REVALIDATE; | 2870 | ehc->i.action |= ATA_EH_REVALIDATE; |
2871 | link->lpm_policy = ATA_LPM_UNKNOWN; /* reset LPM state */ | ||
2782 | 2872 | ||
2783 | rc = 0; | 2873 | rc = 0; |
2784 | out: | 2874 | out: |
@@ -2810,8 +2900,10 @@ int ata_eh_reset(struct ata_link *link, int classify, | |||
2810 | "reset failed (errno=%d), retrying in %u secs\n", | 2900 | "reset failed (errno=%d), retrying in %u secs\n", |
2811 | rc, DIV_ROUND_UP(jiffies_to_msecs(delta), 1000)); | 2901 | rc, DIV_ROUND_UP(jiffies_to_msecs(delta), 1000)); |
2812 | 2902 | ||
2903 | ata_eh_release(ap); | ||
2813 | while (delta) | 2904 | while (delta) |
2814 | delta = schedule_timeout_uninterruptible(delta); | 2905 | delta = schedule_timeout_uninterruptible(delta); |
2906 | ata_eh_acquire(ap); | ||
2815 | } | 2907 | } |
2816 | 2908 | ||
2817 | if (try == max_tries - 1) { | 2909 | if (try == max_tries - 1) { |
@@ -3204,7 +3296,138 @@ static int ata_eh_maybe_retry_flush(struct ata_device *dev) | |||
3204 | return rc; | 3296 | return rc; |
3205 | } | 3297 | } |
3206 | 3298 | ||
3207 | static int ata_link_nr_enabled(struct ata_link *link) | 3299 | /** |
3300 | * ata_eh_set_lpm - configure SATA interface power management | ||
3301 | * @link: link to configure power management | ||
3302 | * @policy: the link power management policy | ||
3303 | * @r_failed_dev: out parameter for failed device | ||
3304 | * | ||
3305 | * Enable SATA Interface power management. This will enable | ||
3306 | * Device Interface Power Management (DIPM) for min_power | ||
3307 | * policy, and then call driver specific callbacks for | ||
3308 | * enabling Host Initiated Power management. | ||
3309 | * | ||
3310 | * LOCKING: | ||
3311 | * EH context. | ||
3312 | * | ||
3313 | * RETURNS: | ||
3314 | * 0 on success, -errno on failure. | ||
3315 | */ | ||
3316 | static int ata_eh_set_lpm(struct ata_link *link, enum ata_lpm_policy policy, | ||
3317 | struct ata_device **r_failed_dev) | ||
3318 | { | ||
3319 | struct ata_port *ap = ata_is_host_link(link) ? link->ap : NULL; | ||
3320 | struct ata_eh_context *ehc = &link->eh_context; | ||
3321 | struct ata_device *dev, *link_dev = NULL, *lpm_dev = NULL; | ||
3322 | enum ata_lpm_policy old_policy = link->lpm_policy; | ||
3323 | bool no_dipm = link->ap->flags & ATA_FLAG_NO_DIPM; | ||
3324 | unsigned int hints = ATA_LPM_EMPTY | ATA_LPM_HIPM; | ||
3325 | unsigned int err_mask; | ||
3326 | int rc; | ||
3327 | |||
3328 | /* if the link or host doesn't do LPM, noop */ | ||
3329 | if ((link->flags & ATA_LFLAG_NO_LPM) || (ap && !ap->ops->set_lpm)) | ||
3330 | return 0; | ||
3331 | |||
3332 | /* | ||
3333 | * DIPM is enabled only for MIN_POWER as some devices | ||
3334 | * misbehave when the host NACKs transition to SLUMBER. Order | ||
3335 | * device and link configurations such that the host always | ||
3336 | * allows DIPM requests. | ||
3337 | */ | ||
3338 | ata_for_each_dev(dev, link, ENABLED) { | ||
3339 | bool hipm = ata_id_has_hipm(dev->id); | ||
3340 | bool dipm = ata_id_has_dipm(dev->id) && !no_dipm; | ||
3341 | |||
3342 | /* find the first enabled and LPM enabled devices */ | ||
3343 | if (!link_dev) | ||
3344 | link_dev = dev; | ||
3345 | |||
3346 | if (!lpm_dev && (hipm || dipm)) | ||
3347 | lpm_dev = dev; | ||
3348 | |||
3349 | hints &= ~ATA_LPM_EMPTY; | ||
3350 | if (!hipm) | ||
3351 | hints &= ~ATA_LPM_HIPM; | ||
3352 | |||
3353 | /* disable DIPM before changing link config */ | ||
3354 | if (policy != ATA_LPM_MIN_POWER && dipm) { | ||
3355 | err_mask = ata_dev_set_feature(dev, | ||
3356 | SETFEATURES_SATA_DISABLE, SATA_DIPM); | ||
3357 | if (err_mask && err_mask != AC_ERR_DEV) { | ||
3358 | ata_dev_printk(dev, KERN_WARNING, | ||
3359 | "failed to disable DIPM, Emask 0x%x\n", | ||
3360 | err_mask); | ||
3361 | rc = -EIO; | ||
3362 | goto fail; | ||
3363 | } | ||
3364 | } | ||
3365 | } | ||
3366 | |||
3367 | if (ap) { | ||
3368 | rc = ap->ops->set_lpm(link, policy, hints); | ||
3369 | if (!rc && ap->slave_link) | ||
3370 | rc = ap->ops->set_lpm(ap->slave_link, policy, hints); | ||
3371 | } else | ||
3372 | rc = sata_pmp_set_lpm(link, policy, hints); | ||
3373 | |||
3374 | /* | ||
3375 | * Attribute link config failure to the first (LPM) enabled | ||
3376 | * device on the link. | ||
3377 | */ | ||
3378 | if (rc) { | ||
3379 | if (rc == -EOPNOTSUPP) { | ||
3380 | link->flags |= ATA_LFLAG_NO_LPM; | ||
3381 | return 0; | ||
3382 | } | ||
3383 | dev = lpm_dev ? lpm_dev : link_dev; | ||
3384 | goto fail; | ||
3385 | } | ||
3386 | |||
3387 | /* | ||
3388 | * Low level driver acked the transition. Issue DIPM command | ||
3389 | * with the new policy set. | ||
3390 | */ | ||
3391 | link->lpm_policy = policy; | ||
3392 | if (ap && ap->slave_link) | ||
3393 | ap->slave_link->lpm_policy = policy; | ||
3394 | |||
3395 | /* host config updated, enable DIPM if transitioning to MIN_POWER */ | ||
3396 | ata_for_each_dev(dev, link, ENABLED) { | ||
3397 | if (policy == ATA_LPM_MIN_POWER && !no_dipm && | ||
3398 | ata_id_has_dipm(dev->id)) { | ||
3399 | err_mask = ata_dev_set_feature(dev, | ||
3400 | SETFEATURES_SATA_ENABLE, SATA_DIPM); | ||
3401 | if (err_mask && err_mask != AC_ERR_DEV) { | ||
3402 | ata_dev_printk(dev, KERN_WARNING, | ||
3403 | "failed to enable DIPM, Emask 0x%x\n", | ||
3404 | err_mask); | ||
3405 | rc = -EIO; | ||
3406 | goto fail; | ||
3407 | } | ||
3408 | } | ||
3409 | } | ||
3410 | |||
3411 | return 0; | ||
3412 | |||
3413 | fail: | ||
3414 | /* restore the old policy */ | ||
3415 | link->lpm_policy = old_policy; | ||
3416 | if (ap && ap->slave_link) | ||
3417 | ap->slave_link->lpm_policy = old_policy; | ||
3418 | |||
3419 | /* if no device or only one more chance is left, disable LPM */ | ||
3420 | if (!dev || ehc->tries[dev->devno] <= 2) { | ||
3421 | ata_link_printk(link, KERN_WARNING, | ||
3422 | "disabling LPM on the link\n"); | ||
3423 | link->flags |= ATA_LFLAG_NO_LPM; | ||
3424 | } | ||
3425 | if (r_failed_dev) | ||
3426 | *r_failed_dev = dev; | ||
3427 | return rc; | ||
3428 | } | ||
3429 | |||
3430 | int ata_link_nr_enabled(struct ata_link *link) | ||
3208 | { | 3431 | { |
3209 | struct ata_device *dev; | 3432 | struct ata_device *dev; |
3210 | int cnt = 0; | 3433 | int cnt = 0; |
@@ -3288,6 +3511,16 @@ static int ata_eh_schedule_probe(struct ata_device *dev) | |||
3288 | ehc->saved_xfer_mode[dev->devno] = 0; | 3511 | ehc->saved_xfer_mode[dev->devno] = 0; |
3289 | ehc->saved_ncq_enabled &= ~(1 << dev->devno); | 3512 | ehc->saved_ncq_enabled &= ~(1 << dev->devno); |
3290 | 3513 | ||
3514 | /* the link maybe in a deep sleep, wake it up */ | ||
3515 | if (link->lpm_policy > ATA_LPM_MAX_POWER) { | ||
3516 | if (ata_is_host_link(link)) | ||
3517 | link->ap->ops->set_lpm(link, ATA_LPM_MAX_POWER, | ||
3518 | ATA_LPM_EMPTY); | ||
3519 | else | ||
3520 | sata_pmp_set_lpm(link, ATA_LPM_MAX_POWER, | ||
3521 | ATA_LPM_EMPTY); | ||
3522 | } | ||
3523 | |||
3291 | /* Record and count probe trials on the ering. The specific | 3524 | /* Record and count probe trials on the ering. The specific |
3292 | * error mask used is irrelevant. Because a successful device | 3525 | * error mask used is irrelevant. Because a successful device |
3293 | * detection clears the ering, this count accumulates only if | 3526 | * detection clears the ering, this count accumulates only if |
@@ -3389,8 +3622,7 @@ int ata_eh_recover(struct ata_port *ap, ata_prereset_fn_t prereset, | |||
3389 | { | 3622 | { |
3390 | struct ata_link *link; | 3623 | struct ata_link *link; |
3391 | struct ata_device *dev; | 3624 | struct ata_device *dev; |
3392 | int nr_failed_devs; | 3625 | int rc, nr_fails; |
3393 | int rc; | ||
3394 | unsigned long flags, deadline; | 3626 | unsigned long flags, deadline; |
3395 | 3627 | ||
3396 | DPRINTK("ENTER\n"); | 3628 | DPRINTK("ENTER\n"); |
@@ -3431,7 +3663,6 @@ int ata_eh_recover(struct ata_port *ap, ata_prereset_fn_t prereset, | |||
3431 | 3663 | ||
3432 | retry: | 3664 | retry: |
3433 | rc = 0; | 3665 | rc = 0; |
3434 | nr_failed_devs = 0; | ||
3435 | 3666 | ||
3436 | /* if UNLOADING, finish immediately */ | 3667 | /* if UNLOADING, finish immediately */ |
3437 | if (ap->pflags & ATA_PFLAG_UNLOADING) | 3668 | if (ap->pflags & ATA_PFLAG_UNLOADING) |
@@ -3501,8 +3732,10 @@ int ata_eh_recover(struct ata_port *ap, ata_prereset_fn_t prereset, | |||
3501 | if (time_before_eq(deadline, now)) | 3732 | if (time_before_eq(deadline, now)) |
3502 | break; | 3733 | break; |
3503 | 3734 | ||
3735 | ata_eh_release(ap); | ||
3504 | deadline = wait_for_completion_timeout(&ap->park_req_pending, | 3736 | deadline = wait_for_completion_timeout(&ap->park_req_pending, |
3505 | deadline - now); | 3737 | deadline - now); |
3738 | ata_eh_acquire(ap); | ||
3506 | } while (deadline); | 3739 | } while (deadline); |
3507 | ata_for_each_link(link, ap, EDGE) { | 3740 | ata_for_each_link(link, ap, EDGE) { |
3508 | ata_for_each_dev(dev, link, ALL) { | 3741 | ata_for_each_dev(dev, link, ALL) { |
@@ -3516,13 +3749,17 @@ int ata_eh_recover(struct ata_port *ap, ata_prereset_fn_t prereset, | |||
3516 | } | 3749 | } |
3517 | 3750 | ||
3518 | /* the rest */ | 3751 | /* the rest */ |
3519 | ata_for_each_link(link, ap, EDGE) { | 3752 | nr_fails = 0; |
3753 | ata_for_each_link(link, ap, PMP_FIRST) { | ||
3520 | struct ata_eh_context *ehc = &link->eh_context; | 3754 | struct ata_eh_context *ehc = &link->eh_context; |
3521 | 3755 | ||
3756 | if (sata_pmp_attached(ap) && ata_is_host_link(link)) | ||
3757 | goto config_lpm; | ||
3758 | |||
3522 | /* revalidate existing devices and attach new ones */ | 3759 | /* revalidate existing devices and attach new ones */ |
3523 | rc = ata_eh_revalidate_and_attach(link, &dev); | 3760 | rc = ata_eh_revalidate_and_attach(link, &dev); |
3524 | if (rc) | 3761 | if (rc) |
3525 | goto dev_fail; | 3762 | goto rest_fail; |
3526 | 3763 | ||
3527 | /* if PMP got attached, return, pmp EH will take care of it */ | 3764 | /* if PMP got attached, return, pmp EH will take care of it */ |
3528 | if (link->device->class == ATA_DEV_PMP) { | 3765 | if (link->device->class == ATA_DEV_PMP) { |
@@ -3534,7 +3771,7 @@ int ata_eh_recover(struct ata_port *ap, ata_prereset_fn_t prereset, | |||
3534 | if (ehc->i.flags & ATA_EHI_SETMODE) { | 3771 | if (ehc->i.flags & ATA_EHI_SETMODE) { |
3535 | rc = ata_set_mode(link, &dev); | 3772 | rc = ata_set_mode(link, &dev); |
3536 | if (rc) | 3773 | if (rc) |
3537 | goto dev_fail; | 3774 | goto rest_fail; |
3538 | ehc->i.flags &= ~ATA_EHI_SETMODE; | 3775 | ehc->i.flags &= ~ATA_EHI_SETMODE; |
3539 | } | 3776 | } |
3540 | 3777 | ||
@@ -3547,7 +3784,7 @@ int ata_eh_recover(struct ata_port *ap, ata_prereset_fn_t prereset, | |||
3547 | continue; | 3784 | continue; |
3548 | rc = atapi_eh_clear_ua(dev); | 3785 | rc = atapi_eh_clear_ua(dev); |
3549 | if (rc) | 3786 | if (rc) |
3550 | goto dev_fail; | 3787 | goto rest_fail; |
3551 | } | 3788 | } |
3552 | } | 3789 | } |
3553 | 3790 | ||
@@ -3557,21 +3794,25 @@ int ata_eh_recover(struct ata_port *ap, ata_prereset_fn_t prereset, | |||
3557 | continue; | 3794 | continue; |
3558 | rc = ata_eh_maybe_retry_flush(dev); | 3795 | rc = ata_eh_maybe_retry_flush(dev); |
3559 | if (rc) | 3796 | if (rc) |
3560 | goto dev_fail; | 3797 | goto rest_fail; |
3561 | } | 3798 | } |
3562 | 3799 | ||
3800 | config_lpm: | ||
3563 | /* configure link power saving */ | 3801 | /* configure link power saving */ |
3564 | if (ehc->i.action & ATA_EH_LPM) | 3802 | if (link->lpm_policy != ap->target_lpm_policy) { |
3565 | ata_for_each_dev(dev, link, ALL) | 3803 | rc = ata_eh_set_lpm(link, ap->target_lpm_policy, &dev); |
3566 | ata_dev_enable_pm(dev, ap->pm_policy); | 3804 | if (rc) |
3805 | goto rest_fail; | ||
3806 | } | ||
3567 | 3807 | ||
3568 | /* this link is okay now */ | 3808 | /* this link is okay now */ |
3569 | ehc->i.flags = 0; | 3809 | ehc->i.flags = 0; |
3570 | continue; | 3810 | continue; |
3571 | 3811 | ||
3572 | dev_fail: | 3812 | rest_fail: |
3573 | nr_failed_devs++; | 3813 | nr_fails++; |
3574 | ata_eh_handle_dev_fail(dev, rc); | 3814 | if (dev) |
3815 | ata_eh_handle_dev_fail(dev, rc); | ||
3575 | 3816 | ||
3576 | if (ap->pflags & ATA_PFLAG_FROZEN) { | 3817 | if (ap->pflags & ATA_PFLAG_FROZEN) { |
3577 | /* PMP reset requires working host port. | 3818 | /* PMP reset requires working host port. |
@@ -3583,7 +3824,7 @@ dev_fail: | |||
3583 | } | 3824 | } |
3584 | } | 3825 | } |
3585 | 3826 | ||
3586 | if (nr_failed_devs) | 3827 | if (nr_fails) |
3587 | goto retry; | 3828 | goto retry; |
3588 | 3829 | ||
3589 | out: | 3830 | out: |