Re: Linux 4.15 and onwards fails to initialize some hard drives

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Sorry, but I made some mistake with handle current SPD.
There is fixed patch:

---
 drivers/ata/libata-core.c | 22 +++++++++++++---------
 1 file changed, 13 insertions(+), 9 deletions(-)

diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
index adf28788cab5..a37249c4ebeb 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,23 @@ 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 is 1, then we can't speed down
+	 * any more.
 	 */
 	if (spd > 1)
 		mask &= (1 << (spd - 1)) - 1;
-	else
-		return -EINVAL;
 
 	/* were we already at the bottom? */
 	if (!mask)
@@ -4116,7 +4117,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




[Index of Archives]     [Linux Filesystems]     [Linux SCSI]     [Linux RAID]     [Git]     [Kernel Newbies]     [Linux Newbie]     [Security]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Samba]     [Device Mapper]

  Powered by Linux