Skip to content

Commit 97fce12

Browse files
avri-altman-sndkstorulf
authored andcommitted
mmc: block: Issue a cache flush only when it's enabled
In command queueing mode, the cache isn't flushed via the mmc_flush_cache() function, but instead by issuing a CMDQ_TASK_MGMT (CMD48) with a FLUSH_CACHE opcode. In this path, we need to check if cache has been enabled, before deciding to flush the cache, along the lines of what's being done in mmc_flush_cache(). To fix this problem, let's add a new bus ops callback ->cache_enabled() and implement it for the mmc bus type. In this way, the mmc block device driver can call it to know whether cache flushing should be done. Fixes: 1e8e55b (mmc: block: Add CQE support) Cc: [email protected] Reported-by: Brendan Peter <[email protected]> Signed-off-by: Avri Altman <[email protected]> Tested-by: Brendan Peter <[email protected]> Acked-by: Adrian Hunter <[email protected]> Link: https://lore.kernel.org/r/[email protected] Link: https://lore.kernel.org/r/[email protected] [Ulf: Squashed the two patches and made some minor updates] Signed-off-by: Ulf Hansson <[email protected]>
1 parent 2f15671 commit 97fce12

File tree

4 files changed

+21
-3
lines changed

4 files changed

+21
-3
lines changed

drivers/mmc/core/block.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2237,6 +2237,10 @@ enum mmc_issued mmc_blk_mq_issue_rq(struct mmc_queue *mq, struct request *req)
22372237
case MMC_ISSUE_ASYNC:
22382238
switch (req_op(req)) {
22392239
case REQ_OP_FLUSH:
2240+
if (!mmc_cache_enabled(host)) {
2241+
blk_mq_end_request(req, BLK_STS_OK);
2242+
return MMC_REQ_FINISHED;
2243+
}
22402244
ret = mmc_blk_cqe_issue_flush(mq, req);
22412245
break;
22422246
case REQ_OP_READ:

drivers/mmc/core/core.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ struct mmc_bus_ops {
2929
int (*shutdown)(struct mmc_host *);
3030
int (*hw_reset)(struct mmc_host *);
3131
int (*sw_reset)(struct mmc_host *);
32+
bool (*cache_enabled)(struct mmc_host *);
3233
};
3334

3435
void mmc_attach_bus(struct mmc_host *host, const struct mmc_bus_ops *ops);
@@ -163,4 +164,12 @@ static inline void mmc_post_req(struct mmc_host *host, struct mmc_request *mrq,
163164
host->ops->post_req(host, mrq, err);
164165
}
165166

167+
static inline bool mmc_cache_enabled(struct mmc_host *host)
168+
{
169+
if (host->bus_ops->cache_enabled)
170+
return host->bus_ops->cache_enabled(host);
171+
172+
return false;
173+
}
174+
166175
#endif

drivers/mmc/core/mmc.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2029,6 +2029,12 @@ static void mmc_detect(struct mmc_host *host)
20292029
}
20302030
}
20312031

2032+
static bool _mmc_cache_enabled(struct mmc_host *host)
2033+
{
2034+
return host->card->ext_csd.cache_size > 0 &&
2035+
host->card->ext_csd.cache_ctrl & 1;
2036+
}
2037+
20322038
static int _mmc_suspend(struct mmc_host *host, bool is_suspend)
20332039
{
20342040
int err = 0;
@@ -2208,6 +2214,7 @@ static const struct mmc_bus_ops mmc_ops = {
22082214
.alive = mmc_alive,
22092215
.shutdown = mmc_shutdown,
22102216
.hw_reset = _mmc_hw_reset,
2217+
.cache_enabled = _mmc_cache_enabled,
22112218
};
22122219

22132220
/*

drivers/mmc/core/mmc_ops.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -968,9 +968,7 @@ int mmc_flush_cache(struct mmc_card *card)
968968
{
969969
int err = 0;
970970

971-
if (mmc_card_mmc(card) &&
972-
(card->ext_csd.cache_size > 0) &&
973-
(card->ext_csd.cache_ctrl & 1)) {
971+
if (mmc_cache_enabled(card->host)) {
974972
err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL,
975973
EXT_CSD_FLUSH_CACHE, 1,
976974
MMC_CACHE_FLUSH_TIMEOUT_MS);

0 commit comments

Comments
 (0)