All of lore.kernel.org
 help / color / mirror / Atom feed
From: biju.das@bp.renesas.com (Biju Das)
To: cip-dev@lists.cip-project.org
Subject: [cip-dev] [PATCH 4.4.y-cip 25/31] mmc: tmio: ensure end of DMA and SD access are in sync
Date: Tue, 19 Nov 2019 13:36:04 +0000	[thread overview]
Message-ID: <1574170570-15179-26-git-send-email-biju.das@bp.renesas.com> (raw)
In-Reply-To: <1574170570-15179-1-git-send-email-biju.das@bp.renesas.com>

From: Wolfram Sang <wsa+renesas@sang-engineering.com>

commit 52ad9a8e854ca13151f4af8140297f73d49e318a upstream.

The current code assumes that DMA is finished before SD access end is
flagged. Thus, it schedules the 'dma_complete' tasklet in the SD card
interrupt routine when DATAEND is set. The assumption is not safe,
though. Even by mounting an SD card, it can be seen that sometimes DMA
complete is first, sometimes DATAEND. It seems they are usually close
enough timewise to not cause problems. However, a customer reported that
with CMD53 sometimes things really break apart. As a result, the BSP has
a patch which introduces flags for both events and makes sure both flags
are set before scheduling the tasklet. The customer accepted the patch,
yet it doesn't seem a proper upstream solution to me.

This patch refactors the code to replace the tasklet with already
existing and more lightweight mechanisms. First of all, we set the
callback in a DMA descriptor to automatically get notified when DMA is
done. In the callback, we then use a completion to make sure the SD
access has already ended. Then, we proceed as before.

Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
Signed-off-by: Biju Das <biju.das@bp.renesas.com>
---
 drivers/mmc/host/tmio_mmc.h     |  2 +-
 drivers/mmc/host/tmio_mmc_dma.c | 58 ++++++++++++++++++++++++-----------------
 drivers/mmc/host/tmio_mmc_pio.c |  4 +--
 3 files changed, 37 insertions(+), 27 deletions(-)

diff --git a/drivers/mmc/host/tmio_mmc.h b/drivers/mmc/host/tmio_mmc.h
index e414670..f864be46 100644
--- a/drivers/mmc/host/tmio_mmc.h
+++ b/drivers/mmc/host/tmio_mmc.h
@@ -136,7 +136,7 @@ struct tmio_mmc_host {
 	bool			force_pio;
 	struct dma_chan		*chan_rx;
 	struct dma_chan		*chan_tx;
-	struct tasklet_struct	dma_complete;
+	struct completion	dma_dataend;
 	struct tasklet_struct	dma_issue;
 	struct scatterlist	bounce_sg;
 	u8			*bounce_buf;
diff --git a/drivers/mmc/host/tmio_mmc_dma.c b/drivers/mmc/host/tmio_mmc_dma.c
index d157368..cef1eb4 100644
--- a/drivers/mmc/host/tmio_mmc_dma.c
+++ b/drivers/mmc/host/tmio_mmc_dma.c
@@ -43,6 +43,31 @@ void tmio_mmc_abort_dma(struct tmio_mmc_host *host)
 	tmio_mmc_enable_dma(host, true);
 }
 
+static void tmio_mmc_dma_callback(void *arg)
+{
+	struct tmio_mmc_host *host = arg;
+
+	wait_for_completion(&host->dma_dataend);
+
+	spin_lock_irq(&host->lock);
+
+	if (!host->data)
+		goto out;
+
+	if (host->data->flags & MMC_DATA_READ)
+		dma_unmap_sg(host->chan_rx->device->dev,
+			     host->sg_ptr, host->sg_len,
+			     DMA_FROM_DEVICE);
+	else
+		dma_unmap_sg(host->chan_tx->device->dev,
+			     host->sg_ptr, host->sg_len,
+			     DMA_TO_DEVICE);
+
+	tmio_mmc_do_data_irq(host);
+out:
+	spin_unlock_irq(&host->lock);
+}
+
 static void tmio_mmc_start_dma_rx(struct tmio_mmc_host *host)
 {
 	struct scatterlist *sg = host->sg_ptr, *sg_tmp;
@@ -88,6 +113,10 @@ static void tmio_mmc_start_dma_rx(struct tmio_mmc_host *host)
 			DMA_DEV_TO_MEM, DMA_CTRL_ACK);
 
 	if (desc) {
+		reinit_completion(&host->dma_dataend);
+		desc->callback = tmio_mmc_dma_callback;
+		desc->callback_param = host;
+
 		cookie = dmaengine_submit(desc);
 		if (cookie < 0) {
 			desc = NULL;
@@ -162,6 +191,10 @@ static void tmio_mmc_start_dma_tx(struct tmio_mmc_host *host)
 			DMA_MEM_TO_DEV, DMA_CTRL_ACK);
 
 	if (desc) {
+		reinit_completion(&host->dma_dataend);
+		desc->callback = tmio_mmc_dma_callback;
+		desc->callback_param = host;
+
 		cookie = dmaengine_submit(desc);
 		if (cookie < 0) {
 			desc = NULL;
@@ -221,29 +254,6 @@ static void tmio_mmc_issue_tasklet_fn(unsigned long priv)
 		dma_async_issue_pending(chan);
 }
 
-static void tmio_mmc_tasklet_fn(unsigned long arg)
-{
-	struct tmio_mmc_host *host = (struct tmio_mmc_host *)arg;
-
-	spin_lock_irq(&host->lock);
-
-	if (!host->data)
-		goto out;
-
-	if (host->data->flags & MMC_DATA_READ)
-		dma_unmap_sg(host->chan_rx->device->dev,
-			     host->sg_ptr, host->sg_len,
-			     DMA_FROM_DEVICE);
-	else
-		dma_unmap_sg(host->chan_tx->device->dev,
-			     host->sg_ptr, host->sg_len,
-			     DMA_TO_DEVICE);
-
-	tmio_mmc_do_data_irq(host);
-out:
-	spin_unlock_irq(&host->lock);
-}
-
 void tmio_mmc_request_dma(struct tmio_mmc_host *host, struct tmio_mmc_data *pdata)
 {
 	/* We can only either use DMA for both Tx and Rx or not use it at all */
@@ -306,7 +316,7 @@ void tmio_mmc_request_dma(struct tmio_mmc_host *host, struct tmio_mmc_data *pdat
 		if (!host->bounce_buf)
 			goto ebouncebuf;
 
-		tasklet_init(&host->dma_complete, tmio_mmc_tasklet_fn, (unsigned long)host);
+		init_completion(&host->dma_dataend);
 		tasklet_init(&host->dma_issue, tmio_mmc_issue_tasklet_fn, (unsigned long)host);
 	}
 
diff --git a/drivers/mmc/host/tmio_mmc_pio.c b/drivers/mmc/host/tmio_mmc_pio.c
index 3ec58b44..7cb30d3 100644
--- a/drivers/mmc/host/tmio_mmc_pio.c
+++ b/drivers/mmc/host/tmio_mmc_pio.c
@@ -595,11 +595,11 @@ static void tmio_mmc_data_irq(struct tmio_mmc_host *host, unsigned int stat)
 
 		if (done) {
 			tmio_mmc_disable_mmc_irqs(host, TMIO_STAT_DATAEND);
-			tasklet_schedule(&host->dma_complete);
+			complete(&host->dma_dataend);
 		}
 	} else if (host->chan_rx && (data->flags & MMC_DATA_READ) && !host->force_pio) {
 		tmio_mmc_disable_mmc_irqs(host, TMIO_STAT_DATAEND);
-		tasklet_schedule(&host->dma_complete);
+		complete(&host->dma_dataend);
 	} else {
 		tmio_mmc_do_data_irq(host);
 		tmio_mmc_disable_mmc_irqs(host, TMIO_MASK_READOP | TMIO_MASK_WRITEOP);
-- 
2.7.4

  parent reply	other threads:[~2019-11-19 13:36 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-19 13:35 [cip-dev] [PATCH 4.4.y-cip 00/31] Add RZ/G1C SD/eMMC support Biju Das
2019-11-19 13:35 ` [cip-dev] [PATCH 4.4.y-cip 01/31] mmc: tmio-mmc: add support for 32bit data port Biju Das
2019-11-19 13:35 ` [cip-dev] [PATCH 4.4.y-cip 02/31] mmc: sh_mobile_sdhi: add ocr_mask option Biju Das
2019-11-19 13:35 ` [cip-dev] [PATCH 4.4.y-cip 03/31] mmc: tmio: enhance illegal sequence handling Biju Das
2019-11-21  0:41   ` Nobuhiro Iwamatsu
2019-11-21  7:42     ` Biju Das
2019-11-21  8:12       ` Pavel Machek
2019-11-19 13:35 ` [cip-dev] [PATCH 4.4.y-cip 04/31] mmc: tmio: document mandatory and optional callbacks Biju Das
2019-11-19 13:35 ` [cip-dev] [PATCH 4.4.y-cip 05/31] mmc: tmio: Add hw reset support Biju Das
2019-11-19 13:35 ` [cip-dev] [PATCH 4.4.y-cip 06/31] mmc: core: Add helper to see if a host can be retuned Biju Das
2019-11-19 13:35 ` [cip-dev] [PATCH 4.4.y-cip 07/31] mmc: tmio: Add tuning support Biju Das
2019-11-19 13:35 ` [cip-dev] [PATCH 4.4.y-cip 08/31] mmc: sh_mobile_sdhi: " Biju Das
2019-11-19 13:35 ` [cip-dev] [PATCH 4.4.y-cip 09/31] mmc: tmio: fix wrong bitmask for SDIO irqs Biju Das
2019-11-19 13:35 ` [cip-dev] [PATCH 4.4.y-cip 10/31] mmc: tmio: remove SDIO from TODO list Biju Das
2019-11-19 13:35 ` [cip-dev] [PATCH 4.4.y-cip 11/31] mmc: tmio: use SDIO master interrupt bit only when allowed Biju Das
2019-11-19 13:35 ` [cip-dev] [PATCH 4.4.y-cip 12/31] mmc: sh_mobile_sdhi: simplify accessing DT data Biju Das
2019-11-19 13:35 ` [cip-dev] [PATCH 4.4.y-cip 13/31] mmc: sh_mobile_sdhi: improve prerequisite for hw_reset Biju Das
2019-11-19 13:35 ` [cip-dev] [PATCH 4.4.y-cip 14/31] mmc: sh_mobile_sdhi: remove superfluous check in hw_reset Biju Das
2019-11-19 13:35 ` [cip-dev] [PATCH 4.4.y-cip 15/31] mmc: sh_mobile_sdhi: improve prerequisites for tuning Biju Das
2019-11-19 13:35 ` [cip-dev] [PATCH 4.4.y-cip 16/31] mmc: sh_mobile_sdhi: remove superfluous check in SCC error check Biju Das
2019-11-19 13:35 ` [cip-dev] [PATCH 4.4.y-cip 17/31] mmc: sh_mobile_sdhi: remove superfluous check in init_tuning Biju Das
2019-11-19 13:35 ` [cip-dev] [PATCH 4.4.y-cip 18/31] mmc: sh_mobile_sdhi: enable HS200 Biju Das
2019-11-19 13:35 ` [cip-dev] [PATCH 4.4.y-cip 19/31] mmc: host: tmio: drop superfluous exit path Biju Das
2019-11-19 13:35 ` [cip-dev] [PATCH 4.4.y-cip 20/31] mmc: tmio: Remove redundant check of mmc->slot.cd_irq Biju Das
2019-11-19 13:36 ` [cip-dev] [PATCH 4.4.y-cip 21/31] mmc: host: tmio: disable clocks when unbinding Biju Das
2019-11-19 13:36 ` [cip-dev] [PATCH 4.4.y-cip 22/31] mmc: host: tmio: refactor calls to sdio irq Biju Das
2019-11-19 13:36 ` [cip-dev] [PATCH 4.4.y-cip 23/31] mmc: host: tmio: SDIO_STATUS_QUIRK is rather SDIO_STATUS_SETBITS Biju Das
2019-11-19 13:36 ` [cip-dev] [PATCH 4.4.y-cip 24/31] mmc: tmio: discard obsolete SDIO irqs before enabling irqs Biju Das
2019-11-19 13:36 ` Biju Das [this message]
2019-11-19 13:36 ` [cip-dev] [PATCH 4.4.y-cip 26/31] mmc: host: tmio: use defines for CTL_STOP_INTERNAL_ACTION values Biju Das
2019-11-19 13:36 ` [cip-dev] [PATCH 4.4.y-cip 27/31] mmc: host: tmio: don't BUG on unsupported stop commands Biju Das
2019-11-19 13:36 ` [cip-dev] [PATCH 4.4.y-cip 28/31] mmc: host: tmio: fill in response from auto cmd12 Biju Das
2019-11-19 13:36 ` [cip-dev] [PATCH 4.4.y-cip 29/31] mmc: tmio: always get number of taps Biju Das
2019-11-19 13:36 ` [cip-dev] [PATCH 4.4.y-cip 30/31] mmc: tmio: drop filenames from comment at top of source Biju Das
2019-11-19 13:36 ` [cip-dev] [PATCH 4.4.y-cip 31/31] mmc: renesas-sdhi, tmio: make dma more modular Biju Das
2019-11-21  1:13 ` [cip-dev] [PATCH 4.4.y-cip 00/31] Add RZ/G1C SD/eMMC support Nobuhiro Iwamatsu
2019-11-21  8:33 ` Pavel Machek

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=1574170570-15179-26-git-send-email-biju.das@bp.renesas.com \
    --to=biju.das@bp.renesas.com \
    --cc=cip-dev@lists.cip-project.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.