|
@@ -721,19 +721,6 @@ static u32 mmc_sd_num_wr_blocks(struct mmc_card *card)
|
|
|
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)
|
|
|
{
|
|
|
struct mmc_command cmd = {0};
|
|
@@ -797,6 +784,51 @@ static int card_busy_detect(struct mmc_card *card, unsigned int timeout_ms,
|
|
|
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_RETRY 2
|
|
|
#define ERR_ABORT 1
|
|
@@ -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 ||
|
|
|
R1_CURRENT_STATE(status) == R1_STATE_RCV) {
|
|
|
- err = send_stop(card, &stop_status);
|
|
|
- if (err)
|
|
|
+ err = send_stop(card,
|
|
|
+ DIV_ROUND_UP(brq->data.timeout_ns, 1000000),
|
|
|
+ req, gen_err, &stop_status);
|
|
|
+ if (err) {
|
|
|
pr_err("%s: error %d sending stop command\n",
|
|
|
req->rq_disk->disk_name, err);
|
|
|
-
|
|
|
- /*
|
|
|
- * If the stop cmd also timed out, the card is probably
|
|
|
- * not present, so abort. Other errors are bad news too.
|
|
|
- */
|
|
|
- if (err)
|
|
|
+ /*
|
|
|
+ * If the stop cmd also timed out, the card is probably
|
|
|
+ * not present, so abort. Other errors are bad news too.
|
|
|
+ */
|
|
|
return ERR_ABORT;
|
|
|
+ }
|
|
|
+
|
|
|
if (stop_status & R1_CARD_ECC_FAILED)
|
|
|
*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 */
|