All of lore.kernel.org
 help / color / mirror / Atom feed
From: Michael Wu <michael@allwinnertech.com>
To: ulf.hansson@linaro.org, axboe@kernel.dk, adrian.hunter@intel.com,
	avri.altman@wdc.com, kch@nvidia.com, beanhuo@micron.com,
	swboyd@chromium.org, digetx@gmail.com, bigeasy@linutronix.de,
	CLoehle@hyperstone.com, cjb@laptop.org, arnd@arndb.de,
	andreiw@motorola.com, tgih.jun@samsung.com,
	jh80.chung@samsung.com, linus.walleij@linaro.org
Cc: linux-mmc@vger.kernel.org, linux-kernel@vger.kernel.org,
	allwinner-opensource-support@allwinnertech.com
Subject: [PATCH v2] mmc: block: enable cache-flushing when mmc cache is on
Date: Thu, 31 Mar 2022 15:32:23 +0800	[thread overview]
Message-ID: <20220331073223.106415-1-michael@allwinnertech.com> (raw)

The mmc core enables cache by default. But it only enables
cache-flushing when host supports cmd23 and eMMC supports
reliable-write.
For hosts which do not support cmd23 or eMMCs which do not support
reliable-write, the cache can not be flushed by `sync` command.
This may leads to cache data lost.
This patch enables cache-flushing as long as cache is enabled,
no matter host supports cmd23 and/or eMMC supports reliable write
or not.
For SD cards, backwards compatibility is guaranteed. Newer components
like SD5.0 which have cache are also supported in advance, which means
this patch will also be applicable if SD5.0 cache is added to the mmc
core in the future.

Fixes: f4c5522b0a88 ("mmc: Reliable write support.")
Fixes: 881d1c25f765 ("mmc: core: Add cache control for eMMC4.5 device")
Fixes: 130206a615a9 ("mmc: core: Add support for cache ctrl for SD cards")
Fixes: d0c97cfb81eb ("mmc: core: Use CMD23 for multiblock transfers when we can.")
Fixes: e9d5c746246c ("mmc/block: switch to using blk_queue_write_cache()")

Reviewed-by: Avri Altman <Avri.Altman@wdc.com>
Reviewed-by: Ulf Hansson <ulf.hansson@linaro.org>

Signed-off-by: Michael Wu <michael@allwinnertech.com>
---
 drivers/mmc/core/block.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/drivers/mmc/core/block.c b/drivers/mmc/core/block.c
index 4e67c1403cc9..ec76ed82abb9 100644
--- a/drivers/mmc/core/block.c
+++ b/drivers/mmc/core/block.c
@@ -2350,6 +2350,8 @@ static struct mmc_blk_data *mmc_blk_alloc_req(struct mmc_card *card,
 	struct mmc_blk_data *md;
 	int devidx, ret;
 	char cap_str[10];
+	bool cache_enabled = false;
+	bool fua_enabled = false;
 
 	devidx = ida_simple_get(&mmc_blk_ida, 0, max_devices, GFP_KERNEL);
 	if (devidx < 0) {
@@ -2429,13 +2431,17 @@ static struct mmc_blk_data *mmc_blk_alloc_req(struct mmc_card *card,
 			md->flags |= MMC_BLK_CMD23;
 	}
 
-	if (mmc_card_mmc(card) &&
-	    md->flags & MMC_BLK_CMD23 &&
+	if (md->flags & MMC_BLK_CMD23 &&
 	    ((card->ext_csd.rel_param & EXT_CSD_WR_REL_PARAM_EN) ||
 	     card->ext_csd.rel_sectors)) {
 		md->flags |= MMC_BLK_REL_WR;
-		blk_queue_write_cache(md->queue.queue, true, true);
+		fua_enabled = true;
+		cache_enabled = true;
 	}
+	if (mmc_cache_enabled(card->host))
+		cache_enabled  = true;
+
+	blk_queue_write_cache(md->queue.queue, cache_enabled, fua_enabled);
 
 	string_get_size((u64)size, 512, STRING_UNITS_2,
 			cap_str, sizeof(cap_str));
-- 
2.29.0


             reply	other threads:[~2022-03-31  7:32 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-31  7:32 Michael Wu [this message]
2022-04-04 11:52 ` [PATCH v2] mmc: block: enable cache-flushing when mmc cache is on Ulf Hansson
2022-04-19 14:59   ` Michael Wu

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=20220331073223.106415-1-michael@allwinnertech.com \
    --to=michael@allwinnertech.com \
    --cc=CLoehle@hyperstone.com \
    --cc=adrian.hunter@intel.com \
    --cc=allwinner-opensource-support@allwinnertech.com \
    --cc=andreiw@motorola.com \
    --cc=arnd@arndb.de \
    --cc=avri.altman@wdc.com \
    --cc=axboe@kernel.dk \
    --cc=beanhuo@micron.com \
    --cc=bigeasy@linutronix.de \
    --cc=cjb@laptop.org \
    --cc=digetx@gmail.com \
    --cc=jh80.chung@samsung.com \
    --cc=kch@nvidia.com \
    --cc=linus.walleij@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mmc@vger.kernel.org \
    --cc=swboyd@chromium.org \
    --cc=tgih.jun@samsung.com \
    --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 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.