Commit bb5cba40 authored by Ulf Hansson's avatar Ulf Hansson Committed by Chris Ball

mmc: block: Fixup busy detection while invoking stop cmd at recovery

When sending a stop command at the recovery path, use a R1B response
when the failing data request are a WRITE. Thus we also care about the
busy detection completion in this case.

For a failing READ request, we use a R1 response for the stop command,
since we don't need to care about busy detection in this case.

To align behavior between hosts supporting MMC_CAP_WAIT_WHILE_BUSY and
those who are not, we add a CMD13 polling method for the card's status.

We also respect whether the host has specified the max_busy_timeout,
which means we may fallback to CMD13 polling if the timeout is greater
than what the host are able to support.
Signed-off-by: default avatarUlf Hansson <ulf.hansson@linaro.org>
Signed-off-by: default avatarChris Ball <chris@printf.net>
parent 95a91298
...@@ -721,19 +721,6 @@ static u32 mmc_sd_num_wr_blocks(struct mmc_card *card) ...@@ -721,19 +721,6 @@ static u32 mmc_sd_num_wr_blocks(struct mmc_card *card)
return result; return result;
} }
static int send_stop(struct mmc_card *card, u32 *status)
{
struct mmc_command cmd = {0};
int err;
cmd.opcode = MMC_STOP_TRANSMISSION;
cmd.flags = MMC_RSP_SPI_R1B | MMC_RSP_R1B | MMC_CMD_AC;
err = mmc_wait_for_cmd(card->host, &cmd, 5);
if (err == 0)
*status = cmd.resp[0];
return err;
}
static int get_card_status(struct mmc_card *card, u32 *status, int retries) static int get_card_status(struct mmc_card *card, u32 *status, int retries)
{ {
struct mmc_command cmd = {0}; struct mmc_command cmd = {0};
...@@ -797,6 +784,51 @@ static int card_busy_detect(struct mmc_card *card, unsigned int timeout_ms, ...@@ -797,6 +784,51 @@ static int card_busy_detect(struct mmc_card *card, unsigned int timeout_ms,
return err; return err;
} }
static int send_stop(struct mmc_card *card, unsigned int timeout_ms,
struct request *req, int *gen_err, u32 *stop_status)
{
struct mmc_host *host = card->host;
struct mmc_command cmd = {0};
int err;
bool use_r1b_resp = rq_data_dir(req) == WRITE;
/*
* Normally we use R1B responses for WRITE, but in cases where the host
* has specified a max_busy_timeout we need to validate it. A failure
* means we need to prevent the host from doing hw busy detection, which
* is done by converting to a R1 response instead.
*/
if (host->max_busy_timeout && (timeout_ms > host->max_busy_timeout))
use_r1b_resp = false;
cmd.opcode = MMC_STOP_TRANSMISSION;
if (use_r1b_resp) {
cmd.flags = MMC_RSP_SPI_R1B | MMC_RSP_R1B | MMC_CMD_AC;
cmd.busy_timeout = timeout_ms;
} else {
cmd.flags = MMC_RSP_SPI_R1 | MMC_RSP_R1 | MMC_CMD_AC;
}
err = mmc_wait_for_cmd(host, &cmd, 5);
if (err)
return err;
*stop_status = cmd.resp[0];
/* No need to check card status in case of READ. */
if (rq_data_dir(req) == READ)
return 0;
if (!mmc_host_is_spi(host) &&
(*stop_status & R1_ERROR)) {
pr_err("%s: %s: general error sending stop command, resp %#x\n",
req->rq_disk->disk_name, __func__, *stop_status);
*gen_err = 1;
}
return card_busy_detect(card, timeout_ms, use_r1b_resp, req, gen_err);
}
#define ERR_NOMEDIUM 3 #define ERR_NOMEDIUM 3
#define ERR_RETRY 2 #define ERR_RETRY 2
#define ERR_ABORT 1 #define ERR_ABORT 1
...@@ -913,26 +945,21 @@ static int mmc_blk_cmd_recovery(struct mmc_card *card, struct request *req, ...@@ -913,26 +945,21 @@ static int mmc_blk_cmd_recovery(struct mmc_card *card, struct request *req,
*/ */
if (R1_CURRENT_STATE(status) == R1_STATE_DATA || if (R1_CURRENT_STATE(status) == R1_STATE_DATA ||
R1_CURRENT_STATE(status) == R1_STATE_RCV) { R1_CURRENT_STATE(status) == R1_STATE_RCV) {
err = send_stop(card, &stop_status); err = send_stop(card,
if (err) DIV_ROUND_UP(brq->data.timeout_ns, 1000000),
req, gen_err, &stop_status);
if (err) {
pr_err("%s: error %d sending stop command\n", pr_err("%s: error %d sending stop command\n",
req->rq_disk->disk_name, err); req->rq_disk->disk_name, err);
/* /*
* If the stop cmd also timed out, the card is probably * If the stop cmd also timed out, the card is probably
* not present, so abort. Other errors are bad news too. * not present, so abort. Other errors are bad news too.
*/ */
if (err)
return ERR_ABORT; return ERR_ABORT;
}
if (stop_status & R1_CARD_ECC_FAILED) if (stop_status & R1_CARD_ECC_FAILED)
*ecc_err = 1; *ecc_err = 1;
if (!mmc_host_is_spi(card->host) && rq_data_dir(req) != READ)
if (stop_status & R1_ERROR) {
pr_err("%s: %s: general error sending stop command, stop cmd response %#x\n",
req->rq_disk->disk_name, __func__,
stop_status);
*gen_err = 1;
}
} }
/* Check for set block count errors */ /* Check for set block count errors */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment