mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: dragos.tatulea@intel.com
To: linux-kernel@vger.kernel.org, linux-mmc@vger.kernel.org, cjb@laptop.org
Cc: kirill.shutemov@linux.intel.com, irina.tirdea@intel.com,
	octavian.purdila@intel.com, tony.luck@intel.com,
	keescook@chromium.org, dragos.tatulea@gmail.com,
	Adrian Hunter <adrian.hunter@intel.com>
Subject: [PATCH v2 22/26] mmc: sdhci: panic write: no dma mapping
Date: Thu,  8 Nov 2012 15:06:20 +0200	[thread overview]
Message-ID: <1352379984-18381-23-git-send-email-dragos.tatulea@intel.com> (raw)
In-Reply-To: <1352379984-18381-1-git-send-email-dragos.tatulea@intel.com>

From: Adrian Hunter <adrian.hunter@intel.com>

Implement simple dma ops to avoid usage dma mapping in panic mode.
Init & cleanup pave the way for the dma ops implemented through
pre and post functions.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Signed-off-by: Irina Tirdea <irina.tirdea@intel.com>
---
 drivers/mmc/host/sdhci.c  |  158 ++++++++++++++++++++++++++++++++++++++++++++-
 include/linux/mmc/sdhci.h |    8 +++
 2 files changed, 164 insertions(+), 2 deletions(-)

diff --git a/drivers/mmc/host/sdhci.c b/drivers/mmc/host/sdhci.c
index d85e9d5..ab3f5ce 100644
--- a/drivers/mmc/host/sdhci.c
+++ b/drivers/mmc/host/sdhci.c
@@ -649,6 +649,69 @@ static void sdhci_adma_table_post(struct sdhci_host *host,
 		data->sg_len, direction);
 }
 
+#ifdef CONFIG_MMC_BLOCK_PANIC_WRITE
+
+static void sdhci_panic_dma_pre(struct sdhci_host *host, struct mmc_data *data)
+{
+	struct scatterlist *sg;
+	int i, len;
+	dma_addr_t addr;
+	u8 *desc;
+
+	if (host->flags & SDHCI_USE_ADMA) {
+		if (data->sg_len != 1) {
+			WARN_ON(1);
+			host->flags &= ~SDHCI_REQ_USE_DMA;
+			return;
+		}
+		desc = host->panic_adma_desc;
+		for_each_sg(data->sg, sg, 1, i) {
+			addr = host->panic_dma_addr;
+			len = sg->length;
+			sdhci_set_adma_desc(desc, addr, len, 0x21);
+			desc += 8;
+		}
+		if (host->quirks & SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC) {
+			if (desc != host->panic_adma_desc) {
+				desc -= 8;
+				desc[0] |= 0x2;
+			}
+		} else {
+			sdhci_set_adma_desc(desc, 0, 0, 0x3);
+		}
+		sdhci_writel(host, host->panic_adma_addr, SDHCI_ADMA_ADDRESS);
+	} else {
+		sdhci_writel(host, host->panic_dma_addr, SDHCI_DMA_ADDRESS);
+	}
+
+	if (data->flags & MMC_DATA_WRITE) {
+		sg_copy_to_buffer(data->sg, data->sg_len, host->panic_buf,
+				  host->panic_bufsize);
+	}
+}
+
+static void sdhci_panic_dma_post(struct sdhci_host *host, struct mmc_data *data)
+{
+	if (data->flags & MMC_DATA_READ) {
+		sg_copy_from_buffer(data->sg, data->sg_len, host->panic_buf,
+				    host->panic_bufsize);
+	}
+}
+
+#else
+
+static inline void sdhci_panic_dma_pre(struct sdhci_host *host,
+				       struct mmc_data *data)
+{
+}
+
+static inline void sdhci_panic_dma_post(struct sdhci_host *host,
+					struct mmc_data *data)
+{
+}
+
+#endif
+
 static u8 sdhci_calc_timeout(struct sdhci_host *host, struct mmc_command *cmd)
 {
 	u8 count;
@@ -810,7 +873,9 @@ static void sdhci_prepare_data(struct sdhci_host *host, struct mmc_command *cmd)
 	}
 
 	if (host->flags & SDHCI_REQ_USE_DMA) {
-		if (host->flags & SDHCI_USE_ADMA) {
+		if (mmc_am_panic_task(host->mmc)) {
+			sdhci_panic_dma_pre(host, data);
+		} else if (host->flags & SDHCI_USE_ADMA) {
 			ret = sdhci_adma_table_pre(host, data);
 			if (ret) {
 				/*
@@ -937,7 +1002,9 @@ static void sdhci_finish_data(struct sdhci_host *host)
 	host->data = NULL;
 
 	if (host->flags & SDHCI_REQ_USE_DMA) {
-		if (host->flags & SDHCI_USE_ADMA)
+		if (mmc_am_panic_task(host->mmc))
+			sdhci_panic_dma_post(host, data);
+		else if (host->flags & SDHCI_USE_ADMA)
 			sdhci_adma_table_post(host, data);
 		else {
 			dma_unmap_sg(mmc_dev(host->mmc), data->sg,
@@ -2045,6 +2112,91 @@ static const struct mmc_host_ops sdhci_ops = {
 
 #ifdef CONFIG_MMC_BLOCK_PANIC_WRITE
 
+/*
+ * Arbitrary maximum DMA buffer size and hence maximum request size when using
+ * DMA.
+ */
+#define SDHCI_PANIC_DMA_BUFSIZE (32 * 1024)
+
+/*
+ * We DMA at most one segment which is aligned. Plus we need an end descriptor.
+ * We allow for a 8 byte (32-bit address) descriptor size.
+ */
+#define SDHCI_PANIC_ADMA_DESC_SZ ((1 + 1) * 12)
+
+static void sdhci_panic_dma_cleanup(struct sdhci_host *host)
+{
+	if (host->panic_adma_desc) {
+		dma_free_coherent(mmc_dev(host->mmc), SDHCI_PANIC_ADMA_DESC_SZ,
+				  host->panic_adma_desc, host->panic_adma_addr);
+		host->panic_adma_desc = NULL;
+	}
+
+	if (host->panic_buf) {
+		dma_free_coherent(mmc_dev(host->mmc), host->panic_bufsize,
+				  host->panic_buf, host->panic_dma_addr);
+		host->panic_buf = NULL;
+	}
+}
+
+static int sdhci_panic_dma_init(struct sdhci_host *host)
+{
+	size_t size;
+
+	size = min_t(size_t, SDHCI_PANIC_DMA_BUFSIZE, host->mmc->max_seg_size);
+	while (size > PAGE_SIZE) {
+		host->panic_buf = dma_alloc_coherent(mmc_dev(host->mmc), size,
+						     &host->panic_dma_addr,
+						     GFP_KERNEL | __GFP_NOWARN);
+		if (host->panic_buf)
+			break;
+		size >>= 1;
+	}
+	if (!host->panic_buf) {
+		host->panic_buf = dma_alloc_coherent(mmc_dev(host->mmc), size,
+						     &host->panic_dma_addr,
+						     GFP_KERNEL);
+	}
+	if (!host->panic_buf)
+		return -ENOMEM;
+
+	host->panic_bufsize = size;
+	host->mmc->panic_max_size = size;
+
+	if (host->flags & SDHCI_USE_ADMA) {
+		size = SDHCI_PANIC_ADMA_DESC_SZ;
+		host->panic_adma_desc = dma_alloc_coherent(mmc_dev(host->mmc),
+							size,
+							&host->panic_adma_addr,
+							GFP_KERNEL);
+		if (!host->panic_adma_desc) {
+			sdhci_panic_dma_cleanup(host);
+			return -ENOMEM;
+		}
+	}
+
+	return 0;
+}
+
+static int sdhci_panic_init(struct mmc_host *mmc)
+{
+	struct sdhci_host *host = mmc_priv(mmc);
+
+	mmc->panic_max_size = mmc->max_seg_size;
+
+	if (host->flags & (SDHCI_USE_SDMA | SDHCI_USE_ADMA))
+		return sdhci_panic_dma_init(host);
+
+	return 0;
+}
+
+static void sdhci_panic_cleanup(struct mmc_host *mmc)
+{
+	struct sdhci_host *host = mmc_priv(mmc);
+
+	sdhci_panic_dma_cleanup(host);
+}
+
 void sdhci_lock(struct sdhci_host *host)
 {
 	if (mmc_am_panic_task(host->mmc))
@@ -2092,6 +2244,8 @@ static void sdhci_panic_end(struct mmc_host *mmc)
 }
 
 static const struct mmc_panic_ops sdhci_pops = {
+	.init		= sdhci_panic_init,
+	.cleanup	= sdhci_panic_cleanup,
 	.begin		= sdhci_panic_begin,
 	.end		= sdhci_panic_end,
 };
diff --git a/include/linux/mmc/sdhci.h b/include/linux/mmc/sdhci.h
index fa8529a..873e41d 100644
--- a/include/linux/mmc/sdhci.h
+++ b/include/linux/mmc/sdhci.h
@@ -172,6 +172,14 @@ struct sdhci_host {
 #define SDHCI_TUNING_MODE_1	0
 	struct timer_list	tuning_timer;	/* Timer for tuning */
 
+#ifdef CONFIG_MMC_BLOCK_PANIC_WRITE
+	void			*panic_buf;	/* buffer for panic requests */
+	size_t			panic_bufsize;	/* panic buffer size */
+	dma_addr_t		panic_dma_addr;	/* panic buffer dma address */
+	u8			*panic_adma_desc;	/* adma desc buffer */
+	dma_addr_t		panic_adma_addr;	/* adma desc address */
+#endif
+
 	unsigned long private[0] ____cacheline_aligned;
 };
 #endif /* LINUX_MMC_SDHCI_H */
-- 
1.7.9.5


  parent reply	other threads:[~2012-11-08 13:04 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-11-08 13:05 [PATCH v2 00/26] pstore, mmc: add mmc as backend for pstore dragos.tatulea
2012-11-08 13:05 ` [PATCH v2 01/26] pstore: allow for big files dragos.tatulea
2012-11-08 13:06 ` [PATCH v2 02/26] pstore: add flags dragos.tatulea
2012-11-08 13:06 ` [PATCH v2 03/26] pstore: add flush dragos.tatulea
2012-11-08 13:06 ` [PATCH v2 04/26] blkoops: add a block device oops / panic logger dragos.tatulea
2012-11-08 13:06 ` [PATCH v2 05/26] block: add panic write dragos.tatulea
2012-11-08 13:06 ` [PATCH v2 06/26] mmc: block: add panic write support dragos.tatulea
2012-11-08 13:06 ` [PATCH v2 07/26] mmc: panic write: bypass host claiming dragos.tatulea
2012-11-08 13:06 ` [PATCH v2 08/26] mmc: panic write: bypass request completion dragos.tatulea
2012-11-08 13:06 ` [PATCH v2 09/26] mmc: panic write: suppress host not claimed warnings dragos.tatulea
2012-11-08 13:06 ` [PATCH v2 10/26] mmc: panic write: do not msleep dragos.tatulea
2012-11-08 13:06 ` [PATCH v2 11/26] mmc: panic write: bypass clock gating dragos.tatulea
2012-11-08 13:06 ` [PATCH v2 12/26] mmc: panic write: bypass regulators dragos.tatulea
2012-11-08 13:06 ` [PATCH v2 13/26] mmc: panic write: trap non panic tasks dragos.tatulea
2012-11-08 13:06 ` [PATCH v2 14/26] mmc: panic write: bypass bus ref locking dragos.tatulea
2012-11-08 13:06 ` [PATCH v2 15/26] mmc: sdhci: panic write: bypass spin lock dragos.tatulea
2012-11-08 13:06 ` [PATCH v2 16/26] mmc: sdhci: panic write: no sleeping dragos.tatulea
2012-11-08 13:06 ` [PATCH v2 17/26] mmc: sdhci: panic write: call tasklets inline dragos.tatulea
2012-11-08 13:06 ` [PATCH v2 18/26] mmc: sdhci: panic write: no timeout timer dragos.tatulea
2012-11-08 13:06 ` [PATCH v2 19/26] mmc: sdhci: panic write: no runtime pm dragos.tatulea
2012-11-08 13:06 ` [PATCH v2 20/26] mmc: sdhci: panic write: no tuning dragos.tatulea
2012-11-08 13:06 ` [PATCH v2 21/26] mmc: sdhci: panic write: poll interrupts dragos.tatulea
2012-11-08 13:06 ` dragos.tatulea [this message]
2012-11-08 13:06 ` [PATCH v2 23/26] mmc: sdhci: panic write: resume suspended host dragos.tatulea
2012-11-08 13:06 ` [PATCH v2 24/26] mmc: sdhci: panic write: abort request in progress dragos.tatulea
2012-11-08 13:06 ` [PATCH v2 25/26] mmc: sdhci: panic write: trap nonpanic tasks dragos.tatulea
2012-11-08 13:06 ` [PATCH v2 26/26] mmc: sdhci-pci: add panic write support dragos.tatulea

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=1352379984-18381-23-git-send-email-dragos.tatulea@intel.com \
    --to=dragos.tatulea@intel.com \
    --cc=adrian.hunter@intel.com \
    --cc=cjb@laptop.org \
    --cc=dragos.tatulea@gmail.com \
    --cc=irina.tirdea@intel.com \
    --cc=keescook@chromium.org \
    --cc=kirill.shutemov@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mmc@vger.kernel.org \
    --cc=octavian.purdila@intel.com \
    --cc=tony.luck@intel.com \
    /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

all inboxes | Powered by JetHome®