diff options
Diffstat (limited to 'drivers/ata/libata-eh.c')
-rw-r--r-- | drivers/ata/libata-eh.c | 94 |
1 files changed, 84 insertions, 10 deletions
diff --git a/drivers/ata/libata-eh.c b/drivers/ata/libata-eh.c index 8147a8386370..ea890911d4fa 100644 --- a/drivers/ata/libata-eh.c +++ b/drivers/ata/libata-eh.c | |||
@@ -82,6 +82,10 @@ enum { | |||
82 | ATA_EH_FASTDRAIN_INTERVAL = 3000, | 82 | ATA_EH_FASTDRAIN_INTERVAL = 3000, |
83 | 83 | ||
84 | ATA_EH_UA_TRIES = 5, | 84 | ATA_EH_UA_TRIES = 5, |
85 | |||
86 | /* probe speed down parameters, see ata_eh_schedule_probe() */ | ||
87 | ATA_EH_PROBE_TRIAL_INTERVAL = 60000, /* 1 min */ | ||
88 | ATA_EH_PROBE_TRIALS = 2, | ||
85 | }; | 89 | }; |
86 | 90 | ||
87 | /* The following table determines how we sequence resets. Each entry | 91 | /* The following table determines how we sequence resets. Each entry |
@@ -1176,6 +1180,32 @@ void ata_eh_qc_retry(struct ata_queued_cmd *qc) | |||
1176 | } | 1180 | } |
1177 | 1181 | ||
1178 | /** | 1182 | /** |
1183 | * ata_dev_disable - disable ATA device | ||
1184 | * @dev: ATA device to disable | ||
1185 | * | ||
1186 | * Disable @dev. | ||
1187 | * | ||
1188 | * Locking: | ||
1189 | * EH context. | ||
1190 | */ | ||
1191 | void ata_dev_disable(struct ata_device *dev) | ||
1192 | { | ||
1193 | if (!ata_dev_enabled(dev)) | ||
1194 | return; | ||
1195 | |||
1196 | if (ata_msg_drv(dev->link->ap)) | ||
1197 | ata_dev_printk(dev, KERN_WARNING, "disabled\n"); | ||
1198 | ata_acpi_on_disable(dev); | ||
1199 | ata_down_xfermask_limit(dev, ATA_DNXFER_FORCE_PIO0 | ATA_DNXFER_QUIET); | ||
1200 | dev->class++; | ||
1201 | |||
1202 | /* From now till the next successful probe, ering is used to | ||
1203 | * track probe failures. Clear accumulated device error info. | ||
1204 | */ | ||
1205 | ata_ering_clear(&dev->ering); | ||
1206 | } | ||
1207 | |||
1208 | /** | ||
1179 | * ata_eh_detach_dev - detach ATA device | 1209 | * ata_eh_detach_dev - detach ATA device |
1180 | * @dev: ATA device to detach | 1210 | * @dev: ATA device to detach |
1181 | * | 1211 | * |
@@ -1849,7 +1879,7 @@ static unsigned int ata_eh_speed_down(struct ata_device *dev, | |||
1849 | /* speed down? */ | 1879 | /* speed down? */ |
1850 | if (verdict & ATA_EH_SPDN_SPEED_DOWN) { | 1880 | if (verdict & ATA_EH_SPDN_SPEED_DOWN) { |
1851 | /* speed down SATA link speed if possible */ | 1881 | /* speed down SATA link speed if possible */ |
1852 | if (sata_down_spd_limit(link) == 0) { | 1882 | if (sata_down_spd_limit(link, 0) == 0) { |
1853 | action |= ATA_EH_RESET; | 1883 | action |= ATA_EH_RESET; |
1854 | goto done; | 1884 | goto done; |
1855 | } | 1885 | } |
@@ -2393,11 +2423,14 @@ int ata_eh_reset(struct ata_link *link, int classify, | |||
2393 | } | 2423 | } |
2394 | 2424 | ||
2395 | /* prereset() might have cleared ATA_EH_RESET. If so, | 2425 | /* prereset() might have cleared ATA_EH_RESET. If so, |
2396 | * bang classes and return. | 2426 | * bang classes, thaw and return. |
2397 | */ | 2427 | */ |
2398 | if (reset && !(ehc->i.action & ATA_EH_RESET)) { | 2428 | if (reset && !(ehc->i.action & ATA_EH_RESET)) { |
2399 | ata_for_each_dev(dev, link, ALL) | 2429 | ata_for_each_dev(dev, link, ALL) |
2400 | classes[dev->devno] = ATA_DEV_NONE; | 2430 | classes[dev->devno] = ATA_DEV_NONE; |
2431 | if ((ap->pflags & ATA_PFLAG_FROZEN) && | ||
2432 | ata_is_host_link(link)) | ||
2433 | ata_eh_thaw_port(ap); | ||
2401 | rc = 0; | 2434 | rc = 0; |
2402 | goto out; | 2435 | goto out; |
2403 | } | 2436 | } |
@@ -2601,11 +2634,11 @@ int ata_eh_reset(struct ata_link *link, int classify, | |||
2601 | } | 2634 | } |
2602 | 2635 | ||
2603 | if (try == max_tries - 1) { | 2636 | if (try == max_tries - 1) { |
2604 | sata_down_spd_limit(link); | 2637 | sata_down_spd_limit(link, 0); |
2605 | if (slave) | 2638 | if (slave) |
2606 | sata_down_spd_limit(slave); | 2639 | sata_down_spd_limit(slave, 0); |
2607 | } else if (rc == -EPIPE) | 2640 | } else if (rc == -EPIPE) |
2608 | sata_down_spd_limit(failed_link); | 2641 | sata_down_spd_limit(failed_link, 0); |
2609 | 2642 | ||
2610 | if (hardreset) | 2643 | if (hardreset) |
2611 | reset = hardreset; | 2644 | reset = hardreset; |
@@ -2744,6 +2777,8 @@ static int ata_eh_revalidate_and_attach(struct ata_link *link, | |||
2744 | readid_flags, dev->id); | 2777 | readid_flags, dev->id); |
2745 | switch (rc) { | 2778 | switch (rc) { |
2746 | case 0: | 2779 | case 0: |
2780 | /* clear error info accumulated during probe */ | ||
2781 | ata_ering_clear(&dev->ering); | ||
2747 | new_mask |= 1 << dev->devno; | 2782 | new_mask |= 1 << dev->devno; |
2748 | break; | 2783 | break; |
2749 | case -ENOENT: | 2784 | case -ENOENT: |
@@ -2869,7 +2904,7 @@ static int atapi_eh_clear_ua(struct ata_device *dev) | |||
2869 | int i; | 2904 | int i; |
2870 | 2905 | ||
2871 | for (i = 0; i < ATA_EH_UA_TRIES; i++) { | 2906 | for (i = 0; i < ATA_EH_UA_TRIES; i++) { |
2872 | u8 sense_buffer[SCSI_SENSE_BUFFERSIZE]; | 2907 | u8 *sense_buffer = dev->link->ap->sector_buf; |
2873 | u8 sense_key = 0; | 2908 | u8 sense_key = 0; |
2874 | unsigned int err_mask; | 2909 | unsigned int err_mask; |
2875 | 2910 | ||
@@ -2947,9 +2982,24 @@ static int ata_eh_skip_recovery(struct ata_link *link) | |||
2947 | return 1; | 2982 | return 1; |
2948 | } | 2983 | } |
2949 | 2984 | ||
2985 | static int ata_count_probe_trials_cb(struct ata_ering_entry *ent, void *void_arg) | ||
2986 | { | ||
2987 | u64 interval = msecs_to_jiffies(ATA_EH_PROBE_TRIAL_INTERVAL); | ||
2988 | u64 now = get_jiffies_64(); | ||
2989 | int *trials = void_arg; | ||
2990 | |||
2991 | if (ent->timestamp < now - min(now, interval)) | ||
2992 | return -1; | ||
2993 | |||
2994 | (*trials)++; | ||
2995 | return 0; | ||
2996 | } | ||
2997 | |||
2950 | static int ata_eh_schedule_probe(struct ata_device *dev) | 2998 | static int ata_eh_schedule_probe(struct ata_device *dev) |
2951 | { | 2999 | { |
2952 | struct ata_eh_context *ehc = &dev->link->eh_context; | 3000 | struct ata_eh_context *ehc = &dev->link->eh_context; |
3001 | struct ata_link *link = ata_dev_phys_link(dev); | ||
3002 | int trials = 0; | ||
2953 | 3003 | ||
2954 | if (!(ehc->i.probe_mask & (1 << dev->devno)) || | 3004 | if (!(ehc->i.probe_mask & (1 << dev->devno)) || |
2955 | (ehc->did_probe_mask & (1 << dev->devno))) | 3005 | (ehc->did_probe_mask & (1 << dev->devno))) |
@@ -2962,6 +3012,25 @@ static int ata_eh_schedule_probe(struct ata_device *dev) | |||
2962 | ehc->saved_xfer_mode[dev->devno] = 0; | 3012 | ehc->saved_xfer_mode[dev->devno] = 0; |
2963 | ehc->saved_ncq_enabled &= ~(1 << dev->devno); | 3013 | ehc->saved_ncq_enabled &= ~(1 << dev->devno); |
2964 | 3014 | ||
3015 | /* Record and count probe trials on the ering. The specific | ||
3016 | * error mask used is irrelevant. Because a successful device | ||
3017 | * detection clears the ering, this count accumulates only if | ||
3018 | * there are consecutive failed probes. | ||
3019 | * | ||
3020 | * If the count is equal to or higher than ATA_EH_PROBE_TRIALS | ||
3021 | * in the last ATA_EH_PROBE_TRIAL_INTERVAL, link speed is | ||
3022 | * forced to 1.5Gbps. | ||
3023 | * | ||
3024 | * This is to work around cases where failed link speed | ||
3025 | * negotiation results in device misdetection leading to | ||
3026 | * infinite DEVXCHG or PHRDY CHG events. | ||
3027 | */ | ||
3028 | ata_ering_record(&dev->ering, 0, AC_ERR_OTHER); | ||
3029 | ata_ering_map(&dev->ering, ata_count_probe_trials_cb, &trials); | ||
3030 | |||
3031 | if (trials > ATA_EH_PROBE_TRIALS) | ||
3032 | sata_down_spd_limit(link, 1); | ||
3033 | |||
2965 | return 1; | 3034 | return 1; |
2966 | } | 3035 | } |
2967 | 3036 | ||
@@ -2969,7 +3038,11 @@ static int ata_eh_handle_dev_fail(struct ata_device *dev, int err) | |||
2969 | { | 3038 | { |
2970 | struct ata_eh_context *ehc = &dev->link->eh_context; | 3039 | struct ata_eh_context *ehc = &dev->link->eh_context; |
2971 | 3040 | ||
2972 | ehc->tries[dev->devno]--; | 3041 | /* -EAGAIN from EH routine indicates retry without prejudice. |
3042 | * The requester is responsible for ensuring forward progress. | ||
3043 | */ | ||
3044 | if (err != -EAGAIN) | ||
3045 | ehc->tries[dev->devno]--; | ||
2973 | 3046 | ||
2974 | switch (err) { | 3047 | switch (err) { |
2975 | case -ENODEV: | 3048 | case -ENODEV: |
@@ -2979,12 +3052,13 @@ static int ata_eh_handle_dev_fail(struct ata_device *dev, int err) | |||
2979 | /* give it just one more chance */ | 3052 | /* give it just one more chance */ |
2980 | ehc->tries[dev->devno] = min(ehc->tries[dev->devno], 1); | 3053 | ehc->tries[dev->devno] = min(ehc->tries[dev->devno], 1); |
2981 | case -EIO: | 3054 | case -EIO: |
2982 | if (ehc->tries[dev->devno] == 1 && dev->pio_mode > XFER_PIO_0) { | 3055 | if (ehc->tries[dev->devno] == 1) { |
2983 | /* This is the last chance, better to slow | 3056 | /* This is the last chance, better to slow |
2984 | * down than lose it. | 3057 | * down than lose it. |
2985 | */ | 3058 | */ |
2986 | sata_down_spd_limit(ata_dev_phys_link(dev)); | 3059 | sata_down_spd_limit(ata_dev_phys_link(dev), 0); |
2987 | ata_down_xfermask_limit(dev, ATA_DNXFER_PIO); | 3060 | if (dev->pio_mode > XFER_PIO_0) |
3061 | ata_down_xfermask_limit(dev, ATA_DNXFER_PIO); | ||
2988 | } | 3062 | } |
2989 | } | 3063 | } |
2990 | 3064 | ||