aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/mmc/card/block.c83
1 files changed, 55 insertions, 28 deletions
diff --git a/drivers/mmc/card/block.c b/drivers/mmc/card/block.c
index 813ec83b74c9..452782bffebc 100644
--- a/drivers/mmc/card/block.c
+++ b/drivers/mmc/card/block.c
@@ -721,19 +721,6 @@ static u32 mmc_sd_num_wr_blocks(struct mmc_card *card)
721 return result; 721 return result;
722} 722}
723 723
724static int send_stop(struct mmc_card *card, u32 *status)
725{
726 struct mmc_command cmd = {0};
727 int err;
728
729 cmd.opcode = MMC_STOP_TRANSMISSION;
730 cmd.flags = MMC_RSP_SPI_R1B | MMC_RSP_R1B | MMC_CMD_AC;
731 err = mmc_wait_for_cmd(card->host, &cmd, 5);
732 if (err == 0)
733 *status = cmd.resp[0];
734 return err;
735}
736
737static int get_card_status(struct mmc_card *card, u32 *status, int retries) 724static int get_card_status(struct mmc_card *card, u32 *status, int retries)
738{ 725{
739 struct mmc_command cmd = {0}; 726 struct mmc_command cmd = {0};
@@ -797,6 +784,51 @@ static int card_busy_detect(struct mmc_card *card, unsigned int timeout_ms,
797 return err; 784 return err;
798} 785}
799 786
787static int send_stop(struct mmc_card *card, unsigned int timeout_ms,
788 struct request *req, int *gen_err, u32 *stop_status)
789{
790 struct mmc_host *host = card->host;
791 struct mmc_command cmd = {0};
792 int err;
793 bool use_r1b_resp = rq_data_dir(req) == WRITE;
794
795 /*
796 * Normally we use R1B responses for WRITE, but in cases where the host
797 * has specified a max_busy_timeout we need to validate it. A failure
798 * means we need to prevent the host from doing hw busy detection, which
799 * is done by converting to a R1 response instead.
800 */
801 if (host->max_busy_timeout && (timeout_ms > host->max_busy_timeout))
802 use_r1b_resp = false;
803
804 cmd.opcode = MMC_STOP_TRANSMISSION;
805 if (use_r1b_resp) {
806 cmd.flags = MMC_RSP_SPI_R1B | MMC_RSP_R1B | MMC_CMD_AC;
807 cmd.busy_timeout = timeout_ms;
808 } else {
809 cmd.flags = MMC_RSP_SPI_R1 | MMC_RSP_R1 | MMC_CMD_AC;
810 }
811
812 err = mmc_wait_for_cmd(host, &cmd, 5);
813 if (err)
814 return err;
815
816 *stop_status = cmd.resp[0];
817
818 /* No need to check card status in case of READ. */
819 if (rq_data_dir(req) == READ)
820 return 0;
821
822 if (!mmc_host_is_spi(host) &&
823 (*stop_status & R1_ERROR)) {
824 pr_err("%s: %s: general error sending stop command, resp %#x\n",
825 req->rq_disk->disk_name, __func__, *stop_status);
826 *gen_err = 1;
827 }
828
829 return card_busy_detect(card, timeout_ms, use_r1b_resp, req, gen_err);
830}
831
800#define ERR_NOMEDIUM 3 832#define ERR_NOMEDIUM 3
801#define ERR_RETRY 2 833#define ERR_RETRY 2
802#define ERR_ABORT 1 834#define ERR_ABORT 1
@@ -913,26 +945,21 @@ static int mmc_blk_cmd_recovery(struct mmc_card *card, struct request *req,
913 */ 945 */
914 if (R1_CURRENT_STATE(status) == R1_STATE_DATA || 946 if (R1_CURRENT_STATE(status) == R1_STATE_DATA ||
915 R1_CURRENT_STATE(status) == R1_STATE_RCV) { 947 R1_CURRENT_STATE(status) == R1_STATE_RCV) {
916 err = send_stop(card, &stop_status); 948 err = send_stop(card,
917 if (err) 949 DIV_ROUND_UP(brq->data.timeout_ns, 1000000),
950 req, gen_err, &stop_status);
951 if (err) {
918 pr_err("%s: error %d sending stop command\n", 952 pr_err("%s: error %d sending stop command\n",
919 req->rq_disk->disk_name, err); 953 req->rq_disk->disk_name, err);
920 954 /*
921 /* 955 * If the stop cmd also timed out, the card is probably
922 * If the stop cmd also timed out, the card is probably 956 * not present, so abort. Other errors are bad news too.
923 * not present, so abort. Other errors are bad news too. 957 */
924 */
925 if (err)
926 return ERR_ABORT; 958 return ERR_ABORT;
959 }
960
927 if (stop_status & R1_CARD_ECC_FAILED) 961 if (stop_status & R1_CARD_ECC_FAILED)
928 *ecc_err = 1; 962 *ecc_err = 1;
929 if (!mmc_host_is_spi(card->host) && rq_data_dir(req) != READ)
930 if (stop_status & R1_ERROR) {
931 pr_err("%s: %s: general error sending stop command, stop cmd response %#x\n",
932 req->rq_disk->disk_name, __func__,
933 stop_status);
934 *gen_err = 1;
935 }
936 } 963 }
937 964
938 /* Check for set block count errors */ 965 /* Check for set block count errors */