Skip to content

Commit 08ebf90

Browse files
Michael Wustorulf
authored andcommitted
mmc: core: Fixup support for writeback-cache for eMMC and SD
During the card initialization process, the mmc core checks whether the eMMC/SD card supports an internal writeback-cache and then enables it inside the card. Unfortunately, this isn't according to what the mmc core reports to the upper block layer. Instead, the writeback-cache support with REQ_FLUSH and REQ_FUA, are being enabled depending on whether the host supports the CMD23 (MMC_CAP_CMD23) and whether an eMMC supports the reliable-write command. This is wrong and it may also sound awkward. In fact, it's a remnant from when both eMMC/SD cards didn't have dedicated commands/support to control the internal writeback-cache. In other words, it was the best we could do at that point in time. To fix the problem, but also without breaking backwards compatibility, let's align the REQ_FLUSH support with whether the writeback-cache became successfully enabled - for both eMMC and SD cards. Cc: stable@kernel.org Fixes: 881d1c2 ("mmc: core: Add cache control for eMMC4.5 device") Fixes: 130206a ("mmc: core: Add support for cache ctrl for SD cards") Depends-on: 97fce12 ("mmc: block: Issue a cache flush only when it's enabled") Reviewed-by: Avri Altman <Avri.Altman@wdc.com> Signed-off-by: Michael Wu <michael@allwinnertech.com> Link: https://lore.kernel.org/r/20220331073223.106415-1-michael@allwinnertech.com [Ulf: Re-wrote the commit message] Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
1 parent 5d43593 commit 08ebf90

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

drivers/mmc/core/block.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2382,6 +2382,8 @@ static struct mmc_blk_data *mmc_blk_alloc_req(struct mmc_card *card,
23822382
struct mmc_blk_data *md;
23832383
int devidx, ret;
23842384
char cap_str[10];
2385+
bool cache_enabled = false;
2386+
bool fua_enabled = false;
23852387

23862388
devidx = ida_simple_get(&mmc_blk_ida, 0, max_devices, GFP_KERNEL);
23872389
if (devidx < 0) {
@@ -2461,13 +2463,17 @@ static struct mmc_blk_data *mmc_blk_alloc_req(struct mmc_card *card,
24612463
md->flags |= MMC_BLK_CMD23;
24622464
}
24632465

2464-
if (mmc_card_mmc(card) &&
2465-
md->flags & MMC_BLK_CMD23 &&
2466+
if (md->flags & MMC_BLK_CMD23 &&
24662467
((card->ext_csd.rel_param & EXT_CSD_WR_REL_PARAM_EN) ||
24672468
card->ext_csd.rel_sectors)) {
24682469
md->flags |= MMC_BLK_REL_WR;
2469-
blk_queue_write_cache(md->queue.queue, true, true);
2470+
fua_enabled = true;
2471+
cache_enabled = true;
24702472
}
2473+
if (mmc_cache_enabled(card->host))
2474+
cache_enabled = true;
2475+
2476+
blk_queue_write_cache(md->queue.queue, cache_enabled, fua_enabled);
24712477

24722478
string_get_size((u64)size, 512, STRING_UNITS_2,
24732479
cap_str, sizeof(cap_str));

0 commit comments

Comments
 (0)