mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH] mci: sdhci: don't hang indefinitely waiting for DMA completion
Date: Thu, 24 Aug 2023 15:59:39 +0200	[thread overview]
Message-ID: <20230824135939.1614716-1-a.fatoum@pengutronix.de> (raw)

barebox was observed to hang on an i.MX8MP while reading ext_csd from
a broken eMMC that even bootROM refused to boot from. For PIO, we
already have a maximum wait time of 10s. Do the same for DMA.

It's unlikely that in that state any further communication with the card
will work, but at least, the system isn't stuck and the shell can be
reached. The reset is done on the off-chance that the DMA would've completed
after the 10s and corrupted memory if not disabled.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 drivers/mci/sdhci.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/drivers/mci/sdhci.c b/drivers/mci/sdhci.c
index b0b83bfaa9a7..9829a78cb6c5 100644
--- a/drivers/mci/sdhci.c
+++ b/drivers/mci/sdhci.c
@@ -252,6 +252,7 @@ int sdhci_transfer_data_dma(struct sdhci *sdhci, struct mci_data *data,
 			    dma_addr_t dma)
 {
 	struct device *dev = sdhci->mci->hw_dev;
+	u64 start;
 	int nbytes;
 	u32 irqstat;
 	int ret;
@@ -261,6 +262,8 @@ int sdhci_transfer_data_dma(struct sdhci *sdhci, struct mci_data *data,
 
 	nbytes = data->blocks * data->blocksize;
 
+	start = get_time_ns();
+
 	do {
 		irqstat = sdhci_read32(sdhci, SDHCI_INT_STATUS);
 
@@ -304,6 +307,13 @@ int sdhci_transfer_data_dma(struct sdhci *sdhci, struct mci_data *data,
 
 		if (irqstat & SDHCI_INT_XFER_COMPLETE)
 			break;
+
+		if (is_timeout(start, 10 * SECOND)) {
+			dev_alert(dev, "DMA wait timed out. Resetting, but recovery unlikely\n");
+			sdhci_reset(sdhci, SDHCI_RESET_ALL);
+			ret = -ETIMEDOUT;
+			goto out;
+		}
 	} while (1);
 
 	ret = 0;
-- 
2.39.2




             reply	other threads:[~2023-08-24 14:05 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-24 13:59 Ahmad Fatoum [this message]
2023-08-25  7:34 ` Marco Felsch
2023-08-28  8:02 ` Sascha Hauer

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=20230824135939.1614716-1-a.fatoum@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.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