mmc: block: Issue a cache flush only when it's enabled
authorAvri Altman <avri.altman@wdc.com>
Sun, 25 Apr 2021 06:02:06 +0000 (09:02 +0300)
committerUlf Hansson <ulf.hansson@linaro.org>
Mon, 26 Apr 2021 09:37:23 +0000 (11:37 +0200)
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: 1e8e55b67030 (mmc: block: Add CQE support)
Cc: stable@vger.kernel.org
Reported-by: Brendan Peter <bpeter@lytx.com>
Signed-off-by: Avri Altman <avri.altman@wdc.com>
Tested-by: Brendan Peter <bpeter@lytx.com>
Acked-by: Adrian Hunter <adrian.hunter@intel.com>
Link: https://lore.kernel.org/r/20210425060207.2591-2-avri.altman@wdc.com
Link: https://lore.kernel.org/r/20210425060207.2591-3-avri.altman@wdc.com
[Ulf: Squashed the two patches and made some minor updates]
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
drivers/mmc/core/block.c
drivers/mmc/core/core.h
drivers/mmc/core/mmc.c
drivers/mmc/core/mmc_ops.c

index 6cd5d03bcc6466dc62c1268858d34bdb08369888..689eb9afeeed10868890cae049161de72d198f83 100644 (file)
@@ -2237,6 +2237,10 @@ enum mmc_issued mmc_blk_mq_issue_rq(struct mmc_queue *mq, struct request *req)
        case MMC_ISSUE_ASYNC:
                switch (req_op(req)) {
                case REQ_OP_FLUSH:
+                       if (!mmc_cache_enabled(host)) {
+                               blk_mq_end_request(req, BLK_STS_OK);
+                               return MMC_REQ_FINISHED;
+                       }
                        ret = mmc_blk_cqe_issue_flush(mq, req);
                        break;
                case REQ_OP_READ:
index 8032451abaea9c732d4640ee0ffec2a7ae808793..db3c9c68875d8adbdf59830619d1895fc959d2dd 100644 (file)
@@ -29,6 +29,7 @@ struct mmc_bus_ops {
        int (*shutdown)(struct mmc_host *);
        int (*hw_reset)(struct mmc_host *);
        int (*sw_reset)(struct mmc_host *);
+       bool (*cache_enabled)(struct mmc_host *);
 };
 
 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,
                host->ops->post_req(host, mrq, err);
 }
 
+static inline bool mmc_cache_enabled(struct mmc_host *host)
+{
+       if (host->bus_ops->cache_enabled)
+               return host->bus_ops->cache_enabled(host);
+
+       return false;
+}
+
 #endif
index d35231feac68d45106a28f371ed92ed51008e738..8674c3e0c02c22056cdbb8b071df3c1b17ead335 100644 (file)
@@ -2029,6 +2029,12 @@ static void mmc_detect(struct mmc_host *host)
        }
 }
 
+static bool _mmc_cache_enabled(struct mmc_host *host)
+{
+       return host->card->ext_csd.cache_size > 0 &&
+              host->card->ext_csd.cache_ctrl & 1;
+}
+
 static int _mmc_suspend(struct mmc_host *host, bool is_suspend)
 {
        int err = 0;
@@ -2208,6 +2214,7 @@ static const struct mmc_bus_ops mmc_ops = {
        .alive = mmc_alive,
        .shutdown = mmc_shutdown,
        .hw_reset = _mmc_hw_reset,
+       .cache_enabled = _mmc_cache_enabled,
 };
 
 /*
index cdf02d88fe920848f30ffbd62b37fbf3581fbb67..5756781fef376af0b528956a30a4594503f5969e 100644 (file)
@@ -968,9 +968,7 @@ int mmc_flush_cache(struct mmc_card *card)
 {
        int err = 0;
 
-       if (mmc_card_mmc(card) &&
-                       (card->ext_csd.cache_size > 0) &&
-                       (card->ext_csd.cache_ctrl & 1)) {
+       if (mmc_cache_enabled(card->host)) {
                err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL,
                                 EXT_CSD_FLUSH_CACHE, 1,
                                 MMC_CACHE_FLUSH_TIMEOUT_MS);