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.
Unified · Split
| @@ -2237,6 +2237,10 @@ enum mmc_issued mmc_blk_mq_issue_rq(struct mmc_queue *mq, struct request *req) · 2236 unmodified lines | |||
| 2237 | case MMC_ISSUE_ASYNC: | 2237 | case MMC_ISSUE_ASYNC: |
| 2238 | switch (req_op(req)) { | 2238 | switch (req_op(req)) { |
| 2239 | case REQ_OP_FLUSH: | 2239 | 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 | } | ||
| 2240 | ret = mmc_blk_cqe_issue_flush(mq, req); | 2244 | ret = mmc_blk_cqe_issue_flush(mq, req); |
| 2241 | break; | 2245 | break; |
| 2242 | case REQ_OP_READ: | 2246 | case REQ_OP_READ: |
| @@ -29,6 +29,7 @@ struct mmc_bus_ops { · 28 unmodified lines | |||
| 29 | int (*shutdown)(struct mmc_host *); | 29 | int (*shutdown)(struct mmc_host *); |
| 30 | int (*hw_reset)(struct mmc_host *); | 30 | int (*hw_reset)(struct mmc_host *); |
| 31 | int (*sw_reset)(struct mmc_host *); | 31 | int (*sw_reset)(struct mmc_host *); |
| 32 | bool (*cache_enabled)(struct mmc_host *); | ||
| 32 | }; | 33 | }; |
| 33 | 34 | ||
| 34 | void mmc_attach_bus(struct mmc_host *host, const struct mmc_bus_ops *ops); | 35 | 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, · 128 unmodified lines | |||
| 163 | host->ops->post_req(host, mrq, err); | 164 | host->ops->post_req(host, mrq, err); |
| 164 | } | 165 | } |
| 165 | 166 | ||
| 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 | |||
| 166 | #endif | 175 | #endif |
| @@ -2029,6 +2029,12 @@ static void mmc_detect(struct mmc_host *host) · 2028 unmodified lines | |||
| 2029 | } | 2029 | } |
| 2030 | } | 2030 | } |
| 2031 | 2031 | ||
| 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 | |||
| 2032 | static int _mmc_suspend(struct mmc_host *host, bool is_suspend) | 2038 | static int _mmc_suspend(struct mmc_host *host, bool is_suspend) |
| 2033 | { | 2039 | { |
| 2034 | int err = 0; | 2040 | int err = 0; |
| @@ -2208,6 +2214,7 @@ static const struct mmc_bus_ops mmc_ops = { · 173 unmodified lines | |||
| 2208 | .alive = mmc_alive, | 2214 | .alive = mmc_alive, |
| 2209 | .shutdown = mmc_shutdown, | 2215 | .shutdown = mmc_shutdown, |
| 2210 | .hw_reset = _mmc_hw_reset, | 2216 | .hw_reset = _mmc_hw_reset, |
| 2217 | .cache_enabled = _mmc_cache_enabled, | ||
| 2211 | }; | 2218 | }; |
| 2212 | 2219 | ||
| 2213 | /* | 2220 | /* |
| @@ -968,9 +968,7 @@ int mmc_flush_cache(struct mmc_card *card) · 967 unmodified lines | |||
| 968 | { | 968 | { |
| 969 | int err = 0; | 969 | int err = 0; |
| 970 | 970 | ||
| 971 | if (mmc_card_mmc(card) && | 971 | if (mmc_cache_enabled(card->host)) { |
| 972 | (card->ext_csd.cache_size > 0) && | ||
| 973 | (card->ext_csd.cache_ctrl & 1)) { | ||
| 974 | err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, | 972 | err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, |
| 975 | EXT_CSD_FLUSH_CACHE, 1, | 973 | EXT_CSD_FLUSH_CACHE, 1, |
| 976 | MMC_CACHE_FLUSH_TIMEOUT_MS); | 974 | MMC_CACHE_FLUSH_TIMEOUT_MS); |