Linux MultiMedia Card development
 help / color / mirror / Atom feed
From: Shawn Lin <shawn.lin@rock-chips.com>
To: Ulf Hansson <ulf.hansson@linaro.org>,
	Jaehoon Chung <jh80.chung@samsung.com>
Cc: linux-mmc@vger.kernel.org, linux-kernel@vger.kernel.org,
	Shawn Lin <shawn.lin@rock-chips.com>
Subject: [PATCH 4/4] mmc: dw_mmc: Convert descriptor ring buffer to per-instance configurable
Date: Thu,  9 Apr 2026 15:48:14 +0800	[thread overview]
Message-ID: <1775720894-97901-5-git-send-email-shawn.lin@rock-chips.com> (raw)
In-Reply-To: <1775720894-97901-1-git-send-email-shawn.lin@rock-chips.com>

Replace the hardcoded DESC_RING_BUF_SZ macro with a per-instance
ring_size member in struct dw_mci. This change provides greater
flexibility and prepares the driver for future configuration options.

Variant host controllers can now override the default ring_size via
the struct dw_mci_drv_data::init() callback, allowing them to tune
the descriptor ring buffer size for their specific use cases. This
is particularly beneficial for improving performance in large-block
sequential read/write scenarios.

Empirical testing shows that increasing ring_size can significantly
improve request efficiency. For example, the block count per request
can increase from 0x800 (1 MiB) to 0x2000 (4 MiB), as demonstrated
by trace data:

    dd-706     [004] .....   106.017566: mmc_request_start: mmc1: start
    struct mmc_request[0000000066f43a37]: ... sbc_arg=0x800

    dd-697     [001] .....    15.227953: mmc_request_start: mmc1: start
    struct mmc_request[00000000d82bf187]: ... sbc_arg=0x2000

While increasing the request size improves sequential I/O throughput,
it also introduces trade-offs: larger requests can delay other pending
I/O operations. Therefore, this configuration should be balanced
according to the specific workload and not hardcoded globally.

The default ring_size is initialized to PAGE_SIZE in dw_mci_alloc_host(),
preserving existing behavior. All buffer size calculations now use
host->ring_size instead of the hardcoded macro.

No functional changes are introduced for existing platforms.

Signed-off-by: Shawn Lin <shawn.lin@rock-chips.com>

---

 drivers/mmc/host/dw_mmc.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/drivers/mmc/host/dw_mmc.c b/drivers/mmc/host/dw_mmc.c
index df6daa6..61f10e7 100644
--- a/drivers/mmc/host/dw_mmc.c
+++ b/drivers/mmc/host/dw_mmc.c
@@ -50,8 +50,6 @@
 				 SDMMC_IDMAC_INT_FBE | SDMMC_IDMAC_INT_RI | \
 				 SDMMC_IDMAC_INT_TI)
 
-#define DESC_RING_BUF_SZ	PAGE_SIZE
-
 struct idmac_desc_64addr {
 	u32		des0;	/* Control Descriptor */
 #define IDMAC_OWN_CLR64(x) \
@@ -493,7 +491,7 @@ static int dw_mci_idmac_init(struct dw_mci *host)
 		struct idmac_desc_64addr *p;
 
 		host->desc_num =
-			DESC_RING_BUF_SZ / sizeof(struct idmac_desc_64addr);
+			host->ring_size / sizeof(struct idmac_desc_64addr);
 
 		/* Forward link the descriptor list */
 		for (i = 0, p = host->sg_cpu; i < host->desc_num - 1;
@@ -521,7 +519,7 @@ static int dw_mci_idmac_init(struct dw_mci *host)
 		struct idmac_desc *p;
 
 		host->desc_num =
-			DESC_RING_BUF_SZ / sizeof(struct idmac_desc);
+			host->ring_size / sizeof(struct idmac_desc);
 
 		/* Forward link the descriptor list */
 		for (i = 0, p = host->sg_cpu;
@@ -653,7 +651,7 @@ static inline int dw_mci_prepare_desc(struct dw_mci *host, struct mmc_data *data
 err_own_bit:
 	/* restore the descriptor chain as it's polluted */
 	dev_dbg(host->dev, "descriptor is still owned by IDMAC.\n");
-	memset(host->sg_cpu, 0, DESC_RING_BUF_SZ);
+	memset(host->sg_cpu, 0, host->ring_size);
 	dw_mci_idmac_init(host);
 	return -EINVAL;
 }
@@ -2954,7 +2952,7 @@ static void dw_mci_init_dma(struct dw_mci *host)
 
 		/* Alloc memory for sg translation */
 		host->sg_cpu = dmam_alloc_coherent(host->dev,
-						   DESC_RING_BUF_SZ,
+						   host->ring_size,
 						   &host->sg_dma, GFP_KERNEL);
 		if (!host->sg_cpu) {
 			dev_err(host->dev,
@@ -3185,6 +3183,7 @@ struct dw_mci *dw_mci_alloc_host(struct device *dev)
 	host = mmc_priv(mmc);
 	host->mmc = mmc;
 	host->dev = dev;
+	host->ring_size = PAGE_SIZE;
 
 	return host;
 }
-- 
2.7.4


      parent reply	other threads:[~2026-04-09  7:48 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-09  7:48 [PATCH 0/4] Refactoring to support per-instance configurable max segments for dw_mmc Shawn Lin
2026-04-09  7:48 ` [PATCH 1/4] mmc: core: mmc: core: Add validation for host-provided max_segs Shawn Lin
2026-04-09  7:48 ` [PATCH 2/4] mmc: dw_mmc: Move misplaced comment Shawn Lin
2026-04-09  7:48 ` [PATCH 3/4] mmc: dw_mmc: Add desc_num field for clarity Shawn Lin
2026-04-09  7:48 ` Shawn Lin [this message]

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=1775720894-97901-5-git-send-email-shawn.lin@rock-chips.com \
    --to=shawn.lin@rock-chips.com \
    --cc=jh80.chung@samsung.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mmc@vger.kernel.org \
    --cc=ulf.hansson@linaro.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