From ef7e68cb27fc0e5788fe21540ba46414cffce27a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Wadowski?= Date: Wed, 15 May 2019 10:30:19 +0200 Subject: [PATCH] libata: sata_down_spd_limit should record link speed limit before return MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit During hotplug, it is possible for a device to fail hard reset ata4: COMRESET failed (errno=-16) In this case, __sata_set_spd_needed() will return false preventing sata_link_hardreset() to never turn off the phy and reconfigure the speed. This patch will reset the sata speed limit allowing a hard reset to reconfigure the speed. Fixes commit (2dc0b46b5ea3 libata: sata_down_spd_limit should return if driver has not recorded sstatus speed. Signed-off-by: MichaƂ Wadowski --- drivers/ata/libata-core.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c index adf28788cab5..43ba6c214153 100644 --- a/drivers/ata/libata-core.c +++ b/drivers/ata/libata-core.c @@ -3072,6 +3072,11 @@ int sata_down_spd_limit(struct ata_link *link, u32 spd_limit) if (mask <= 1) return -EINVAL; + /* sata_spd_limit may by initially INT_MAX, that is not correct value to working with. + * Cut down mask to highest correct value. + */ + mask &= 0x7; + /* unconditionally mask off the highest bit */ bit = fls(mask) - 1; mask &= ~(1 << bit); @@ -3082,13 +3087,16 @@ int sata_down_spd_limit(struct ata_link *link, u32 spd_limit) * recorded the link speed from SStatus, the driver has already * masked off the highest bit so mask should already be 1 or 0. * Otherwise, we should not force 1.5Gbps on a link where we have - * not previously recorded speed from SStatus. Just return in this - * case. + * not previously recorded speed from SStatus. Reset the link + * speed limit in case a device fails hard reset, and return. */ if (spd > 1) mask &= (1 << (spd - 1)) - 1; else + { + link->sata_spd_limit = mask; return -EINVAL; + } /* were we already at the bottom? */ if (!mask) -- 2.7.4