[PATCH] mci: sdhci: don't hang indefinitely waiting for DMA completion

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

 



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@xxxxxxxxxxxxxx>
---
 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





[Index of Archives]     [Linux Embedded]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux