Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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: Ulf Hansson <ulf.hansson@linaro.org>
Signed-off-by: Chris Ball <chris@printf.net>

authored by

Ulf Hansson and committed by
Chris Ball
bb5cba40 95a91298

+55 -28
+55 -28
drivers/mmc/card/block.c
··· 721 721 return result; 722 722 } 723 723 724 - static 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 - 737 724 static int get_card_status(struct mmc_card *card, u32 *status, int retries) 738 725 { 739 726 struct mmc_command cmd = {0}; ··· 782 795 (R1_CURRENT_STATE(status) == R1_STATE_PRG)); 783 796 784 797 return err; 798 + } 799 + 800 + static int send_stop(struct mmc_card *card, unsigned int timeout_ms, 801 + struct request *req, int *gen_err, u32 *stop_status) 802 + { 803 + struct mmc_host *host = card->host; 804 + struct mmc_command cmd = {0}; 805 + int err; 806 + bool use_r1b_resp = rq_data_dir(req) == WRITE; 807 + 808 + /* 809 + * Normally we use R1B responses for WRITE, but in cases where the host 810 + * has specified a max_busy_timeout we need to validate it. A failure 811 + * means we need to prevent the host from doing hw busy detection, which 812 + * is done by converting to a R1 response instead. 813 + */ 814 + if (host->max_busy_timeout && (timeout_ms > host->max_busy_timeout)) 815 + use_r1b_resp = false; 816 + 817 + cmd.opcode = MMC_STOP_TRANSMISSION; 818 + if (use_r1b_resp) { 819 + cmd.flags = MMC_RSP_SPI_R1B | MMC_RSP_R1B | MMC_CMD_AC; 820 + cmd.busy_timeout = timeout_ms; 821 + } else { 822 + cmd.flags = MMC_RSP_SPI_R1 | MMC_RSP_R1 | MMC_CMD_AC; 823 + } 824 + 825 + err = mmc_wait_for_cmd(host, &cmd, 5); 826 + if (err) 827 + return err; 828 + 829 + *stop_status = cmd.resp[0]; 830 + 831 + /* No need to check card status in case of READ. */ 832 + if (rq_data_dir(req) == READ) 833 + return 0; 834 + 835 + if (!mmc_host_is_spi(host) && 836 + (*stop_status & R1_ERROR)) { 837 + pr_err("%s: %s: general error sending stop command, resp %#x\n", 838 + req->rq_disk->disk_name, __func__, *stop_status); 839 + *gen_err = 1; 840 + } 841 + 842 + return card_busy_detect(card, timeout_ms, use_r1b_resp, req, gen_err); 785 843 } 786 844 787 845 #define ERR_NOMEDIUM 3 ··· 945 913 */ 946 914 if (R1_CURRENT_STATE(status) == R1_STATE_DATA || 947 915 R1_CURRENT_STATE(status) == R1_STATE_RCV) { 948 - err = send_stop(card, &stop_status); 949 - if (err) 916 + err = send_stop(card, 917 + DIV_ROUND_UP(brq->data.timeout_ns, 1000000), 918 + req, gen_err, &stop_status); 919 + if (err) { 950 920 pr_err("%s: error %d sending stop command\n", 951 921 req->rq_disk->disk_name, err); 952 - 953 - /* 954 - * If the stop cmd also timed out, the card is probably 955 - * not present, so abort. Other errors are bad news too. 956 - */ 957 - if (err) 922 + /* 923 + * If the stop cmd also timed out, the card is probably 924 + * not present, so abort. Other errors are bad news too. 925 + */ 958 926 return ERR_ABORT; 927 + } 928 + 959 929 if (stop_status & R1_CARD_ECC_FAILED) 960 930 *ecc_err = 1; 961 - if (!mmc_host_is_spi(card->host) && rq_data_dir(req) != READ) 962 - if (stop_status & R1_ERROR) { 963 - pr_err("%s: %s: general error sending stop command, stop cmd response %#x\n", 964 - req->rq_disk->disk_name, __func__, 965 - stop_status); 966 - *gen_err = 1; 967 - } 968 931 } 969 932 970 933 /* Check for set block count errors */