From bfe7ee9a4e62a7c9431e7c51f01d166e1a4a3a32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Wadowski?= Date: Sat, 18 May 2019 00:38:48 +0200 Subject: [PATCH] Fix for initialize drives not capable to handle maximum bandwidth MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In some cases if sata drive can't work with default controller bandwidth, driver fails to initialize the device. libata-core: sata_link_hardreset - if after reset the device is offline, then driver should try again, with lower SPD. sata_down_spd_limit - function should handle corner case values, if device is not initialized yet. Bugzilla: https://bugs.launchpad.net/ubuntu/+source/linux/+bug/1783906 Signed-off-by: MichaƂ Wadowski --- drivers/ata/libata-core.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c index adf28788cab5..c0b4c378ae14 100644 --- a/drivers/ata/libata-core.c +++ b/drivers/ata/libata-core.c @@ -3061,6 +3061,7 @@ int sata_down_spd_limit(struct ata_link *link, u32 spd_limit) /* If SCR can be read, use it to determine the current SPD. * If not, use cached value in link->sata_spd. + * Value of link->sata_spd may be 0. */ rc = sata_scr_read(link, SCR_STATUS, &sstatus); if (rc == 0 && ata_sstatus_online(sstatus)) @@ -3072,23 +3073,22 @@ 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); /* - * Mask off all speeds higher than or equal to the current one. At - * this point, if current SPD is not available and we previously - * 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. + * Mask off all speeds higher than or equal to the current one. + * If device is not initialized yet, value of SPD is 0, so + * we should ignore this. */ - if (spd > 1) + if (spd > 0) mask &= (1 << (spd - 1)) - 1; - else - return -EINVAL; /* were we already at the bottom? */ if (!mask) @@ -4116,7 +4116,10 @@ int sata_link_hardreset(struct ata_link *link, const unsigned long *timing, goto out; /* if link is offline nothing more to do */ if (ata_phys_link_offline(link)) + { + rc = -EPIPE; goto out; + } /* Link is online. From this point, -ENODEV too is an error. */ if (online) -- 2.7.4