linux-ide.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Michał Wadowski" <wadosm@gmail.com>
To: Jens Axboe <axboe@kernel.dk>
Cc: linux-ide@vger.kernel.org, linux-kernel@vger.kernel.org,
	wadosm@gmail.com
Subject: [PATCH] Fix for initialize drives not capable to handle maximum bandwidth
Date: Fri, 5 Jul 2019 12:40:37 +0200	[thread overview]
Message-ID: <461c653b-77e8-fa24-e8b5-56f210c23965@gmail.com> (raw)

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 <wadosm@gmail.com>
---
 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


                 reply	other threads:[~2019-07-05 10:40 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=461c653b-77e8-fa24-e8b5-56f210c23965@gmail.com \
    --to=wadosm@gmail.com \
    --cc=axboe@kernel.dk \
    --cc=linux-ide@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).