mmc: core: Avoid hogging the CPU while polling for busy in the I/O err path
authorUlf Hansson <ulf.hansson@linaro.org>
Fri, 2 Jul 2021 13:42:27 +0000 (15:42 +0200)
committerUlf Hansson <ulf.hansson@linaro.org>
Tue, 24 Aug 2021 08:15:31 +0000 (10:15 +0200)
When mmc_blk_fix_state() sends a CMD12 to try to move the card into the
transfer state, it calls card_busy_detect() to poll for the card's state
with CMD13. This is done without any delays in between the commands being
sent.

Rather than fixing card_busy_detect() in this regards, let's instead
convert into using the common mmc_poll_for_busy(), which also helps us to
avoid open-coding.

Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
Reviewed-by: Shawn Lin <shawn.lin@rock-chips.com>
Link: https://lore.kernel.org/r/20210702134229.357717-2-ulf.hansson@linaro.org
drivers/mmc/core/block.c
drivers/mmc/core/mmc_ops.c
drivers/mmc/core/mmc_ops.h

index ce8aed5629295ddbb21de7ecdf749563436b66e3..170343411f5348051261566ff6f3b0db22a4261a 100644 (file)
@@ -1636,7 +1636,7 @@ static int mmc_blk_fix_state(struct mmc_card *card, struct request *req)
 
        mmc_blk_send_stop(card, timeout);
 
-       err = card_busy_detect(card, timeout, NULL);
+       err = mmc_poll_for_busy(card, timeout, false, MMC_BUSY_IO);
 
        mmc_retune_release(card->host);
 
index 973756ed4016f1a6e0d1f604c3100d9b57cd277c..e2c431c0ce5df0940b48acc0828d60ed320c1f8c 100644 (file)
@@ -435,7 +435,7 @@ static int mmc_busy_cb(void *cb_data, bool *busy)
        u32 status = 0;
        int err;
 
-       if (host->ops->card_busy) {
+       if (data->busy_cmd != MMC_BUSY_IO && host->ops->card_busy) {
                *busy = host->ops->card_busy(host);
                return 0;
        }
@@ -457,6 +457,7 @@ static int mmc_busy_cb(void *cb_data, bool *busy)
                break;
        case MMC_BUSY_HPI:
        case MMC_BUSY_EXTR_SINGLE:
+       case MMC_BUSY_IO:
                break;
        default:
                err = -EINVAL;
@@ -521,6 +522,7 @@ int mmc_poll_for_busy(struct mmc_card *card, unsigned int timeout_ms,
 
        return __mmc_poll_for_busy(card, timeout_ms, &mmc_busy_cb, &cb_data);
 }
+EXPORT_SYMBOL_GPL(mmc_poll_for_busy);
 
 bool mmc_prepare_busy_cmd(struct mmc_host *host, struct mmc_command *cmd,
                          unsigned int timeout_ms)
index 41ab4f573a310dd1c805b80ad4056711d4a14670..ae25ffc2e8704a50f41c040a6d425167567ff257 100644 (file)
@@ -15,6 +15,7 @@ enum mmc_busy_cmd {
        MMC_BUSY_ERASE,
        MMC_BUSY_HPI,
        MMC_BUSY_EXTR_SINGLE,
+       MMC_BUSY_IO,
 };
 
 struct mmc_host;