From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH 05/30] mci: sdhci: unmap DMA buffers on timeout
Date: Mon, 5 May 2025 14:06:08 +0200 [thread overview]
Message-ID: <20250505120633.3717186-6-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20250505120633.3717186-1-a.fatoum@pengutronix.de>
We map DMA buffers during sdhci_setup_data_dma and unmap them inside
sdhci_transfer_data_dma, but if an error happens between these two
functions, DMA buffers are never unmapped.
Fix this to silence CONFIG_DMA_API_DEBUG observed during a timeout on an
i.MX8M.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
drivers/mci/am654-sdhci.c | 4 +++-
drivers/mci/arasan-sdhci.c | 4 +++-
drivers/mci/dwcmshc-sdhci.c | 4 +++-
drivers/mci/imx-esdhc-common.c | 19 +++++++++++++------
drivers/mci/rockchip-dwcmshc-sdhci.c | 4 +++-
drivers/mci/sdhci.c | 22 ++++++++++++++++++----
drivers/mci/sdhci.h | 1 +
7 files changed, 44 insertions(+), 14 deletions(-)
diff --git a/drivers/mci/am654-sdhci.c b/drivers/mci/am654-sdhci.c
index 2c1fa5d80451..a378e3d53c91 100644
--- a/drivers/mci/am654-sdhci.c
+++ b/drivers/mci/am654-sdhci.c
@@ -488,8 +488,10 @@ static int am654_sdhci_send_cmd(struct mci_host *mci, struct mci_cmd *cmd,
sdhci_write16(&host->sdhci, SDHCI_COMMAND, command);
ret = sdhci_wait_for_done(&host->sdhci, SDHCI_INT_CMD_COMPLETE);
- if (ret)
+ if (ret) {
+ sdhci_teardown_data(&host->sdhci, data, dma);
goto error;
+ }
sdhci_read_response(&host->sdhci, cmd);
sdhci_write32(&host->sdhci, SDHCI_INT_STATUS, SDHCI_INT_CMD_COMPLETE);
diff --git a/drivers/mci/arasan-sdhci.c b/drivers/mci/arasan-sdhci.c
index 0ec4cb57ab76..f98f7eb3d10b 100644
--- a/drivers/mci/arasan-sdhci.c
+++ b/drivers/mci/arasan-sdhci.c
@@ -284,8 +284,10 @@ static int arasan_sdhci_send_cmd(struct mci_host *mci, struct mci_cmd *cmd,
mask = SDHCI_INT_DATA_AVAIL;
ret = sdhci_wait_for_done(&host->sdhci, mask);
- if (ret)
+ if (ret) {
+ sdhci_teardown_data(&host->sdhci, data, dma);
goto error;
+ }
sdhci_read_response(&host->sdhci, cmd);
sdhci_write32(&host->sdhci, SDHCI_INT_STATUS, SDHCI_INT_CMD_COMPLETE);
diff --git a/drivers/mci/dwcmshc-sdhci.c b/drivers/mci/dwcmshc-sdhci.c
index 8398889a703c..f6d559e393d4 100644
--- a/drivers/mci/dwcmshc-sdhci.c
+++ b/drivers/mci/dwcmshc-sdhci.c
@@ -153,8 +153,10 @@ static int do_send_cmd(struct mci_host *mci, struct mci_cmd *cmd,
sdhci_write16(&host->sdhci, SDHCI_COMMAND, command);
ret = sdhci_wait_for_done(&host->sdhci, SDHCI_INT_CMD_COMPLETE);
- if (ret)
+ if (ret) {
+ sdhci_teardown_data(&host->sdhci, data, dma);
goto error;
+ }
sdhci_read_response(&host->sdhci, cmd);
diff --git a/drivers/mci/imx-esdhc-common.c b/drivers/mci/imx-esdhc-common.c
index a51e38734cb3..7673220fe8d4 100644
--- a/drivers/mci/imx-esdhc-common.c
+++ b/drivers/mci/imx-esdhc-common.c
@@ -164,16 +164,20 @@ int __esdhc_send_cmd(struct fsl_esdhc_host *host, struct mci_cmd *cmd,
100 * MSECOND);
if (ret) {
dev_dbg(host->dev, "timeout 1\n");
- return -ETIMEDOUT;
+ goto undo_setup_data;
}
irqstat = sdhci_read32(&host->sdhci, SDHCI_INT_STATUS);
- if (irqstat & CMD_ERR)
- return -EIO;
+ if (irqstat & CMD_ERR) {
+ ret = -EIO;
+ goto undo_setup_data;
+ }
- if (irqstat & SDHCI_INT_TIMEOUT)
- return -ETIMEDOUT;
+ if (irqstat & SDHCI_INT_TIMEOUT) {
+ ret = -ETIMEDOUT;
+ goto undo_setup_data;
+ }
/* Workaround for ESDHC errata ENGcm03648 / ENGcm12360 */
if (!data && (cmd->resp_type & MMC_RSP_BUSY)) {
@@ -186,7 +190,7 @@ int __esdhc_send_cmd(struct fsl_esdhc_host *host, struct mci_cmd *cmd,
2500 * MSECOND);
if (ret) {
dev_err(host->dev, "timeout PRSSTAT_DAT0\n");
- return -ETIMEDOUT;
+ goto undo_setup_data;
}
}
@@ -223,5 +227,8 @@ int __esdhc_send_cmd(struct fsl_esdhc_host *host, struct mci_cmd *cmd,
}
return 0;
+undo_setup_data:
+ sdhci_teardown_data(&host->sdhci, data, dma);
+ return ret;
}
diff --git a/drivers/mci/rockchip-dwcmshc-sdhci.c b/drivers/mci/rockchip-dwcmshc-sdhci.c
index 6f3795465765..a7da64f4d7db 100644
--- a/drivers/mci/rockchip-dwcmshc-sdhci.c
+++ b/drivers/mci/rockchip-dwcmshc-sdhci.c
@@ -269,8 +269,10 @@ static int rk_sdhci_send_cmd(struct mci_host *mci, struct mci_cmd *cmd,
sdhci_write16(&host->sdhci, SDHCI_COMMAND, command);
ret = sdhci_wait_for_done(&host->sdhci, SDHCI_INT_CMD_COMPLETE);
- if (ret)
+ if (ret) {
+ sdhci_teardown_data(&host->sdhci, data, dma);
goto error;
+ }
sdhci_read_response(&host->sdhci, cmd);
sdhci_write32(&host->sdhci, SDHCI_INT_STATUS, SDHCI_INT_CMD_COMPLETE);
diff --git a/drivers/mci/sdhci.c b/drivers/mci/sdhci.c
index f54cc6d58b2c..d0caee22f2f7 100644
--- a/drivers/mci/sdhci.c
+++ b/drivers/mci/sdhci.c
@@ -507,6 +507,23 @@ void sdhci_setup_data_dma(struct sdhci *sdhci, struct mci_data *data,
sdhci_set_sdma_addr(sdhci, *dma);
}
+void sdhci_teardown_data(struct sdhci *sdhci,
+ struct mci_data *data, dma_addr_t dma)
+{
+ struct device *dev = sdhci_dev(sdhci);
+ unsigned nbytes;
+
+ if (IN_PBL || !data || dma_mapping_error(dev, dma))
+ return;
+
+ nbytes = data->blocks * data->blocksize;
+
+ if (data->flags & MMC_DATA_READ)
+ dma_unmap_single(dev, dma, nbytes, DMA_FROM_DEVICE);
+ else
+ dma_unmap_single(dev, dma, nbytes, DMA_TO_DEVICE);
+}
+
int sdhci_transfer_data_dma(struct sdhci *sdhci, struct mci_data *data,
dma_addr_t dma)
{
@@ -572,10 +589,7 @@ int sdhci_transfer_data_dma(struct sdhci *sdhci, struct mci_data *data,
ret = 0;
out:
- if (data->flags & MMC_DATA_READ)
- dma_unmap_single(dev, dma, nbytes, DMA_FROM_DEVICE);
- else
- dma_unmap_single(dev, dma, nbytes, DMA_TO_DEVICE);
+ sdhci_teardown_data(sdhci, data, dma);
return ret;
}
diff --git a/drivers/mci/sdhci.h b/drivers/mci/sdhci.h
index 841e39af05ee..d3b681153134 100644
--- a/drivers/mci/sdhci.h
+++ b/drivers/mci/sdhci.h
@@ -323,6 +323,7 @@ void sdhci_set_cmd_xfer_mode(struct sdhci *host, struct mci_cmd *cmd,
u32 *xfer);
void sdhci_setup_data_pio(struct sdhci *sdhci, struct mci_data *data);
void sdhci_setup_data_dma(struct sdhci *sdhci, struct mci_data *data, dma_addr_t *dma);
+void sdhci_teardown_data(struct sdhci *sdhci, struct mci_data *data, dma_addr_t dma);
int sdhci_transfer_data(struct sdhci *sdhci, struct mci_data *data, dma_addr_t dma);
int sdhci_transfer_data_pio(struct sdhci *sdhci, struct mci_data *data);
int sdhci_transfer_data_dma(struct sdhci *sdhci, struct mci_data *data,
--
2.39.5
next prev parent reply other threads:[~2025-05-05 12:08 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-05 12:06 [PATCH 00/30] mci: imx-esdhc: add HS200 support Ahmad Fatoum
2025-05-05 12:06 ` [PATCH 01/30] mci: sdhci: fix SDHCI_TRNS_AUTO_CMD12 definition Ahmad Fatoum
2025-05-05 12:06 ` [PATCH 02/30] mci: move most recent I/O settings into mci_host::ios Ahmad Fatoum
2025-05-05 12:06 ` [PATCH 03/30] mci: use struct mci_host::ios inside mci_set_ios Ahmad Fatoum
2025-05-05 12:06 ` [PATCH 04/30] mci: tuning: fix fallback to DDR52 Ahmad Fatoum
2025-05-05 12:06 ` Ahmad Fatoum [this message]
2025-05-05 12:06 ` [PATCH 06/30] mci: add MMC_CAP_UHS constants Ahmad Fatoum
2025-05-05 12:06 ` [PATCH 07/30] mci: rename MMC_CAP_MMC_x_yV_DDR to MMC_CAP_x_yV_DDR as in Linux Ahmad Fatoum
2025-05-05 12:06 ` [PATCH 08/30] mci: compare host and card caps for supported speeds Ahmad Fatoum
2025-05-05 12:06 ` [PATCH 09/30] mci: print HS200 capabilities in devinfo Ahmad Fatoum
2025-05-05 12:06 ` [PATCH 10/30] mci: respect no-1-8-v OF property Ahmad Fatoum
2025-05-05 12:06 ` [PATCH 11/30] mci: sdhci: add support for struct mci_data::timeout_ns Ahmad Fatoum
2025-05-05 12:06 ` [PATCH 12/30] mci: imx-esdhc: use unsigned types where appropriate Ahmad Fatoum
2025-05-05 12:06 ` [PATCH 13/30] mci: imx-esdhc: implement esdhc_poll using sdhci_read32_poll_timeout Ahmad Fatoum
2025-05-06 6:25 ` Sascha Hauer
2025-05-05 12:06 ` [PATCH 14/30] mci: imx-esdhc: drop one extra read of SDHCI_INT_STATUS Ahmad Fatoum
2025-05-05 12:06 ` [PATCH 15/30] mci: sdhci: add cmd parameter to sdhci_transfer_* Ahmad Fatoum
2025-05-05 12:06 ` [PATCH 16/30] mci: arasan: introduce mmc_op_tuning helper Ahmad Fatoum
2025-05-05 12:06 ` [PATCH 17/30] mci: imx-esdhc: flesh out register description Ahmad Fatoum
2025-05-05 12:06 ` [PATCH 18/30] mci: imx-esdhc: add support for delay/tuning properties in DT Ahmad Fatoum
2025-05-06 6:37 ` Sascha Hauer
2025-05-05 12:06 ` [PATCH 19/30] mci: add mci_set_timing helper Ahmad Fatoum
2025-05-05 12:06 ` [PATCH 20/30] mci: imx-esdhc: add support for setting drive strength Ahmad Fatoum
2025-05-05 12:06 ` [PATCH 21/30] mci: sdhci: move SDHCI_MAKE_BLKSZ definition to header Ahmad Fatoum
2025-05-05 12:06 ` [PATCH 22/30] mci: imx-esdhc: select different pinctrl state depending on frequency Ahmad Fatoum
2025-05-05 12:06 ` [PATCH 23/30] mci: core: retry MMC_CMD_SET_BLOCKLEN up to 4 times Ahmad Fatoum
2025-05-05 12:06 ` [PATCH 24/30] mci: imx-esdhc: don't reconfigure clock unless required Ahmad Fatoum
2025-05-05 12:06 ` [PATCH 25/30] mci: sdhci: fix sdhci_transfer_data MMC_SEND_TUNING compatibility Ahmad Fatoum
2025-05-05 12:06 ` [PATCH 26/30] mci: core: implement mmc_send_tuning Ahmad Fatoum
2025-05-05 12:06 ` [PATCH 27/30] mci: imx-esdhc: set burst_length_enable Ahmad Fatoum
2025-05-05 12:06 ` [PATCH 28/30] mci: imx-esdhc: fixup quirks in standard SDHCI registers Ahmad Fatoum
2025-05-06 7:11 ` Sascha Hauer
2025-05-05 12:06 ` [PATCH 29/30] mci: sdhci: support Linux SDHCI_QUIRK2_BROKEN_HS200 flag Ahmad Fatoum
2025-05-05 12:06 ` [PATCH 30/30] mci: imx-esdhc: implement HS200 support Ahmad Fatoum
2025-05-05 12:41 ` Ahmad Fatoum
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=20250505120633.3717186-6-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