All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] mmc: block: enable cache-flushing when mmc cache is on
@ 2022-03-12  4:43 Michael Wu
  2022-03-14  6:54 ` Adrian Hunter
  2022-03-14  7:26 ` Avri Altman
  0 siblings, 2 replies; 21+ messages in thread
From: Michael Wu @ 2022-03-12  4:43 UTC (permalink / raw)
  To: maintainer:MULTIMEDIA CARD (MMC),
	SECURE DIGITAL (SD)
	AND...,commit_signer:11/9=100%,authored:4/9=44% 
	,added_lines:26/61=43%,removed_lines:25/35=71%,
	commit_signer:3/9=33%,authored:4/9=44% 
	,added_lines:26/61=43%,removed_lines:25/35=71%,
	commit_signer:2/9=22%,authored:4/9=44% 
	,authored:2/9=22%,added_lines:26/61=43%,added_lines:16/61=26% 
	,removed_lines:25/35=71%,
	commit_signer:1/9=11%,authored:4/9=44% 
	,authored:1/9=11%,added_lines:26/61=43%,removed_lines:25/35=71%,
	commit_signer:1/9=11%,authored:4/9=44% 
	,authored:1/9=11%,added_lines:26/61=43%,added_lines:4/61=7% 
	,removed_lines:25/35=71%,removed_lines:3/35=9%,
	authored:1/9=11%,added_lines:26/61=43% 
	,added_lines:14/61=23%,removed_lines:25/35=71%,removed_lines:6/35=17%
  Cc: Michael Wu, Ulf Hansson, Adrian Hunter, Avri Altman, Luca Porzio,
	lixiang, Bean Huo, open list:MULTIMEDIA CARD (MMC),
	SECURE DIGITAL (SD) AND...,
	open list

The mmc core enable cache on 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.

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

diff --git a/drivers/mmc/core/block.c b/drivers/mmc/core/block.c
index 689eb9afeeed..1e508c079c1e 100644
--- a/drivers/mmc/core/block.c
+++ b/drivers/mmc/core/block.c
@@ -2279,6 +2279,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 enable_cache = false;
+	bool enable_fua = false;
 
 	devidx = ida_simple_get(&mmc_blk_ida, 0, max_devices, GFP_KERNEL);
 	if (devidx < 0) {
@@ -2375,12 +2377,18 @@ 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 &&
-	    ((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);
+	if (mmc_card_mmc(card)) {
+		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;
+			enable_fua = true;
+		}
+
+		if (mmc_cache_enabled(card->host))
+			enable_cache = true;
+
+		blk_queue_write_cache(md->queue.queue, enable_cache, enable_fua);
 	}
 
 	string_get_size((u64)size, 512, STRING_UNITS_2,
-- 
2.29.0


^ permalink raw reply related	[flat|nested] 21+ messages in thread

end of thread, other threads:[~2022-03-29  9:54 UTC | newest]

Thread overview: 21+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-12  4:43 [PATCH] mmc: block: enable cache-flushing when mmc cache is on Michael Wu
2022-03-14  6:54 ` Adrian Hunter
2022-03-14  9:20   ` Michael Wu
2022-03-14  9:37     ` Avri Altman
2022-03-16  9:54       ` Michael Wu
2022-03-16 11:09         ` Avri Altman
2022-03-16 11:28           ` Adrian Hunter
2022-03-16 14:46             ` Christian Löhle
2022-03-16 16:05               ` Adrian Hunter
2022-03-17  9:14                 ` Ulf Hansson
2022-03-24 11:27                   ` Ulf Hansson
2022-03-25  5:45                     ` Michael Wu
2022-03-25 10:13                       ` Ulf Hansson
2022-03-28 10:11                         ` Michael Wu
2022-03-28 11:38                           ` Ulf Hansson
2022-03-29  9:08                             ` Michael Wu
2022-03-29  9:53                               ` Ulf Hansson
2022-03-27  8:09                 ` Avri Altman
2022-03-14 11:10     ` Avri Altman
2022-03-14  7:26 ` Avri Altman
2022-03-14 10:32   ` Adrian Hunter

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.