diff options
Diffstat (limited to 'drivers/ata/libata-core.c')
-rw-r--r-- | drivers/ata/libata-core.c | 96 |
1 files changed, 72 insertions, 24 deletions
diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c index 88c242856dae..9fbf0595f3d4 100644 --- a/drivers/ata/libata-core.c +++ b/drivers/ata/libata-core.c | |||
@@ -164,6 +164,11 @@ MODULE_LICENSE("GPL"); | |||
164 | MODULE_VERSION(DRV_VERSION); | 164 | MODULE_VERSION(DRV_VERSION); |
165 | 165 | ||
166 | 166 | ||
167 | static bool ata_sstatus_online(u32 sstatus) | ||
168 | { | ||
169 | return (sstatus & 0xf) == 0x3; | ||
170 | } | ||
171 | |||
167 | /** | 172 | /** |
168 | * ata_link_next - link iteration helper | 173 | * ata_link_next - link iteration helper |
169 | * @link: the previous link, NULL to start | 174 | * @link: the previous link, NULL to start |
@@ -1015,18 +1020,6 @@ static const char *sata_spd_string(unsigned int spd) | |||
1015 | return spd_str[spd - 1]; | 1020 | return spd_str[spd - 1]; |
1016 | } | 1021 | } |
1017 | 1022 | ||
1018 | void ata_dev_disable(struct ata_device *dev) | ||
1019 | { | ||
1020 | if (ata_dev_enabled(dev)) { | ||
1021 | if (ata_msg_drv(dev->link->ap)) | ||
1022 | ata_dev_printk(dev, KERN_WARNING, "disabled\n"); | ||
1023 | ata_acpi_on_disable(dev); | ||
1024 | ata_down_xfermask_limit(dev, ATA_DNXFER_FORCE_PIO0 | | ||
1025 | ATA_DNXFER_QUIET); | ||
1026 | dev->class++; | ||
1027 | } | ||
1028 | } | ||
1029 | |||
1030 | static int ata_dev_set_dipm(struct ata_device *dev, enum link_pm policy) | 1023 | static int ata_dev_set_dipm(struct ata_device *dev, enum link_pm policy) |
1031 | { | 1024 | { |
1032 | struct ata_link *link = dev->link; | 1025 | struct ata_link *link = dev->link; |
@@ -2239,6 +2232,40 @@ retry: | |||
2239 | return rc; | 2232 | return rc; |
2240 | } | 2233 | } |
2241 | 2234 | ||
2235 | static int ata_do_link_spd_horkage(struct ata_device *dev) | ||
2236 | { | ||
2237 | struct ata_link *plink = ata_dev_phys_link(dev); | ||
2238 | u32 target, target_limit; | ||
2239 | |||
2240 | if (!sata_scr_valid(plink)) | ||
2241 | return 0; | ||
2242 | |||
2243 | if (dev->horkage & ATA_HORKAGE_1_5_GBPS) | ||
2244 | target = 1; | ||
2245 | else | ||
2246 | return 0; | ||
2247 | |||
2248 | target_limit = (1 << target) - 1; | ||
2249 | |||
2250 | /* if already on stricter limit, no need to push further */ | ||
2251 | if (plink->sata_spd_limit <= target_limit) | ||
2252 | return 0; | ||
2253 | |||
2254 | plink->sata_spd_limit = target_limit; | ||
2255 | |||
2256 | /* Request another EH round by returning -EAGAIN if link is | ||
2257 | * going faster than the target speed. Forward progress is | ||
2258 | * guaranteed by setting sata_spd_limit to target_limit above. | ||
2259 | */ | ||
2260 | if (plink->sata_spd > target) { | ||
2261 | ata_dev_printk(dev, KERN_INFO, | ||
2262 | "applying link speed limit horkage to %s\n", | ||
2263 | sata_spd_string(target)); | ||
2264 | return -EAGAIN; | ||
2265 | } | ||
2266 | return 0; | ||
2267 | } | ||
2268 | |||
2242 | static inline u8 ata_dev_knobble(struct ata_device *dev) | 2269 | static inline u8 ata_dev_knobble(struct ata_device *dev) |
2243 | { | 2270 | { |
2244 | struct ata_port *ap = dev->link->ap; | 2271 | struct ata_port *ap = dev->link->ap; |
@@ -2329,6 +2356,10 @@ int ata_dev_configure(struct ata_device *dev) | |||
2329 | return 0; | 2356 | return 0; |
2330 | } | 2357 | } |
2331 | 2358 | ||
2359 | rc = ata_do_link_spd_horkage(dev); | ||
2360 | if (rc) | ||
2361 | return rc; | ||
2362 | |||
2332 | /* let ACPI work its magic */ | 2363 | /* let ACPI work its magic */ |
2333 | rc = ata_acpi_on_devcfg(dev); | 2364 | rc = ata_acpi_on_devcfg(dev); |
2334 | if (rc) | 2365 | if (rc) |
@@ -2784,7 +2815,7 @@ int ata_bus_probe(struct ata_port *ap) | |||
2784 | /* This is the last chance, better to slow | 2815 | /* This is the last chance, better to slow |
2785 | * down than lose it. | 2816 | * down than lose it. |
2786 | */ | 2817 | */ |
2787 | sata_down_spd_limit(&ap->link); | 2818 | sata_down_spd_limit(&ap->link, 0); |
2788 | ata_down_xfermask_limit(dev, ATA_DNXFER_PIO); | 2819 | ata_down_xfermask_limit(dev, ATA_DNXFER_PIO); |
2789 | } | 2820 | } |
2790 | } | 2821 | } |
@@ -2880,21 +2911,27 @@ void ata_port_disable(struct ata_port *ap) | |||
2880 | /** | 2911 | /** |
2881 | * sata_down_spd_limit - adjust SATA spd limit downward | 2912 | * sata_down_spd_limit - adjust SATA spd limit downward |
2882 | * @link: Link to adjust SATA spd limit for | 2913 | * @link: Link to adjust SATA spd limit for |
2914 | * @spd_limit: Additional limit | ||
2883 | * | 2915 | * |
2884 | * Adjust SATA spd limit of @link downward. Note that this | 2916 | * Adjust SATA spd limit of @link downward. Note that this |
2885 | * function only adjusts the limit. The change must be applied | 2917 | * function only adjusts the limit. The change must be applied |
2886 | * using sata_set_spd(). | 2918 | * using sata_set_spd(). |
2887 | * | 2919 | * |
2920 | * If @spd_limit is non-zero, the speed is limited to equal to or | ||
2921 | * lower than @spd_limit if such speed is supported. If | ||
2922 | * @spd_limit is slower than any supported speed, only the lowest | ||
2923 | * supported speed is allowed. | ||
2924 | * | ||
2888 | * LOCKING: | 2925 | * LOCKING: |
2889 | * Inherited from caller. | 2926 | * Inherited from caller. |
2890 | * | 2927 | * |
2891 | * RETURNS: | 2928 | * RETURNS: |
2892 | * 0 on success, negative errno on failure | 2929 | * 0 on success, negative errno on failure |
2893 | */ | 2930 | */ |
2894 | int sata_down_spd_limit(struct ata_link *link) | 2931 | int sata_down_spd_limit(struct ata_link *link, u32 spd_limit) |
2895 | { | 2932 | { |
2896 | u32 sstatus, spd, mask; | 2933 | u32 sstatus, spd, mask; |
2897 | int rc, highbit; | 2934 | int rc, bit; |
2898 | 2935 | ||
2899 | if (!sata_scr_valid(link)) | 2936 | if (!sata_scr_valid(link)) |
2900 | return -EOPNOTSUPP; | 2937 | return -EOPNOTSUPP; |
@@ -2903,7 +2940,7 @@ int sata_down_spd_limit(struct ata_link *link) | |||
2903 | * If not, use cached value in link->sata_spd. | 2940 | * If not, use cached value in link->sata_spd. |
2904 | */ | 2941 | */ |
2905 | rc = sata_scr_read(link, SCR_STATUS, &sstatus); | 2942 | rc = sata_scr_read(link, SCR_STATUS, &sstatus); |
2906 | if (rc == 0) | 2943 | if (rc == 0 && ata_sstatus_online(sstatus)) |
2907 | spd = (sstatus >> 4) & 0xf; | 2944 | spd = (sstatus >> 4) & 0xf; |
2908 | else | 2945 | else |
2909 | spd = link->sata_spd; | 2946 | spd = link->sata_spd; |
@@ -2913,8 +2950,8 @@ int sata_down_spd_limit(struct ata_link *link) | |||
2913 | return -EINVAL; | 2950 | return -EINVAL; |
2914 | 2951 | ||
2915 | /* unconditionally mask off the highest bit */ | 2952 | /* unconditionally mask off the highest bit */ |
2916 | highbit = fls(mask) - 1; | 2953 | bit = fls(mask) - 1; |
2917 | mask &= ~(1 << highbit); | 2954 | mask &= ~(1 << bit); |
2918 | 2955 | ||
2919 | /* Mask off all speeds higher than or equal to the current | 2956 | /* Mask off all speeds higher than or equal to the current |
2920 | * one. Force 1.5Gbps if current SPD is not available. | 2957 | * one. Force 1.5Gbps if current SPD is not available. |
@@ -2928,6 +2965,15 @@ int sata_down_spd_limit(struct ata_link *link) | |||
2928 | if (!mask) | 2965 | if (!mask) |
2929 | return -EINVAL; | 2966 | return -EINVAL; |
2930 | 2967 | ||
2968 | if (spd_limit) { | ||
2969 | if (mask & ((1 << spd_limit) - 1)) | ||
2970 | mask &= (1 << spd_limit) - 1; | ||
2971 | else { | ||
2972 | bit = ffs(mask) - 1; | ||
2973 | mask = 1 << bit; | ||
2974 | } | ||
2975 | } | ||
2976 | |||
2931 | link->sata_spd_limit = mask; | 2977 | link->sata_spd_limit = mask; |
2932 | 2978 | ||
2933 | ata_link_printk(link, KERN_WARNING, "limiting SATA link speed to %s\n", | 2979 | ata_link_printk(link, KERN_WARNING, "limiting SATA link speed to %s\n", |
@@ -4215,6 +4261,9 @@ static const struct ata_blacklist_entry ata_device_blacklist [] = { | |||
4215 | /* Devices that do not need bridging limits applied */ | 4261 | /* Devices that do not need bridging limits applied */ |
4216 | { "MTRON MSP-SATA*", NULL, ATA_HORKAGE_BRIDGE_OK, }, | 4262 | { "MTRON MSP-SATA*", NULL, ATA_HORKAGE_BRIDGE_OK, }, |
4217 | 4263 | ||
4264 | /* Devices which aren't very happy with higher link speeds */ | ||
4265 | { "WD My Book", NULL, ATA_HORKAGE_1_5_GBPS, }, | ||
4266 | |||
4218 | /* End Marker */ | 4267 | /* End Marker */ |
4219 | { } | 4268 | { } |
4220 | }; | 4269 | }; |
@@ -4709,8 +4758,7 @@ void swap_buf_le16(u16 *buf, unsigned int buf_words) | |||
4709 | 4758 | ||
4710 | /** | 4759 | /** |
4711 | * ata_qc_new - Request an available ATA command, for queueing | 4760 | * ata_qc_new - Request an available ATA command, for queueing |
4712 | * @ap: Port associated with device @dev | 4761 | * @ap: target port |
4713 | * @dev: Device from whom we request an available command structure | ||
4714 | * | 4762 | * |
4715 | * LOCKING: | 4763 | * LOCKING: |
4716 | * None. | 4764 | * None. |
@@ -5175,7 +5223,7 @@ bool ata_phys_link_online(struct ata_link *link) | |||
5175 | u32 sstatus; | 5223 | u32 sstatus; |
5176 | 5224 | ||
5177 | if (sata_scr_read(link, SCR_STATUS, &sstatus) == 0 && | 5225 | if (sata_scr_read(link, SCR_STATUS, &sstatus) == 0 && |
5178 | (sstatus & 0xf) == 0x3) | 5226 | ata_sstatus_online(sstatus)) |
5179 | return true; | 5227 | return true; |
5180 | return false; | 5228 | return false; |
5181 | } | 5229 | } |
@@ -5199,7 +5247,7 @@ bool ata_phys_link_offline(struct ata_link *link) | |||
5199 | u32 sstatus; | 5247 | u32 sstatus; |
5200 | 5248 | ||
5201 | if (sata_scr_read(link, SCR_STATUS, &sstatus) == 0 && | 5249 | if (sata_scr_read(link, SCR_STATUS, &sstatus) == 0 && |
5202 | (sstatus & 0xf) != 0x3) | 5250 | !ata_sstatus_online(sstatus)) |
5203 | return true; | 5251 | return true; |
5204 | return false; | 5252 | return false; |
5205 | } | 5253 | } |
@@ -5412,8 +5460,8 @@ void ata_dev_init(struct ata_device *dev) | |||
5412 | dev->horkage = 0; | 5460 | dev->horkage = 0; |
5413 | spin_unlock_irqrestore(ap->lock, flags); | 5461 | spin_unlock_irqrestore(ap->lock, flags); |
5414 | 5462 | ||
5415 | memset((void *)dev + ATA_DEVICE_CLEAR_OFFSET, 0, | 5463 | memset((void *)dev + ATA_DEVICE_CLEAR_BEGIN, 0, |
5416 | sizeof(*dev) - ATA_DEVICE_CLEAR_OFFSET); | 5464 | ATA_DEVICE_CLEAR_END - ATA_DEVICE_CLEAR_BEGIN); |
5417 | dev->pio_mask = UINT_MAX; | 5465 | dev->pio_mask = UINT_MAX; |
5418 | dev->mwdma_mask = UINT_MAX; | 5466 | dev->mwdma_mask = UINT_MAX; |
5419 | dev->udma_mask = UINT_MAX; | 5467 | dev->udma_mask = UINT_MAX; |