Skip to content

Commit 0a2d404

Browse files
Russell King - ARM Linuxcjb
authored andcommitted
mmc: block: allow get_card_status() to return error status
If the MMC_SEND_STATUS command is not successful, we should not return a zero status word, but instead allow the caller to know positively that an error occurred. Convert the open-coded get_card_status() to use the helper function, and provide definitions for the card state field. Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk> Acked-by: Linus Walleij <linus.walleij@linaro.org> Tested-by: Pawel Moll <pawel.moll@arm.com> Signed-off-by: Chris Ball <cjb@laptop.org>
1 parent 6e83e10 commit 0a2d404

2 files changed

Lines changed: 19 additions & 24 deletions

File tree

‎drivers/mmc/card/block.c‎

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,7 @@ static u32 mmc_sd_num_wr_blocks(struct mmc_card *card)
525525
return result;
526526
}
527527

528-
static u32 get_card_status(struct mmc_card *card, struct request *req)
528+
static int get_card_status(struct mmc_card *card, u32 *status, int retries)
529529
{
530530
struct mmc_command cmd = {0};
531531
int err;
@@ -534,11 +534,10 @@ static u32 get_card_status(struct mmc_card *card, struct request *req)
534534
if (!mmc_host_is_spi(card->host))
535535
cmd.arg = card->rca << 16;
536536
cmd.flags = MMC_RSP_SPI_R2 | MMC_RSP_R1 | MMC_CMD_AC;
537-
err = mmc_wait_for_cmd(card->host, &cmd, 0);
538-
if (err)
539-
printk(KERN_ERR "%s: error %d sending status command",
540-
req->rq_disk->disk_name, err);
541-
return cmd.resp[0];
537+
err = mmc_wait_for_cmd(card->host, &cmd, retries);
538+
if (err == 0)
539+
*status = cmd.resp[0];
540+
return err;
542541
}
543542

544543
static int mmc_blk_issue_discard_rq(struct mmc_queue *mq, struct request *req)
@@ -686,7 +685,6 @@ static int mmc_blk_issue_rw_rq(struct mmc_queue *mq, struct request *req)
686685
(md->flags & MMC_BLK_REL_WR);
687686

688687
do {
689-
struct mmc_command cmd = {0};
690688
u32 readcmd, writecmd, status = 0;
691689

692690
memset(&brq, 0, sizeof(struct mmc_blk_request));
@@ -817,7 +815,7 @@ static int mmc_blk_issue_rw_rq(struct mmc_queue *mq, struct request *req)
817815
disable_multi = 1;
818816
continue;
819817
}
820-
status = get_card_status(card, req);
818+
get_card_status(card, &status, 0);
821819
}
822820

823821
if (brq.sbc.error) {
@@ -854,12 +852,7 @@ static int mmc_blk_issue_rw_rq(struct mmc_queue *mq, struct request *req)
854852

855853
if (!mmc_host_is_spi(card->host) && rq_data_dir(req) != READ) {
856854
do {
857-
int err;
858-
859-
cmd.opcode = MMC_SEND_STATUS;
860-
cmd.arg = card->rca << 16;
861-
cmd.flags = MMC_RSP_R1 | MMC_CMD_AC;
862-
err = mmc_wait_for_cmd(card->host, &cmd, 5);
855+
int err = get_card_status(card, &status, 5);
863856
if (err) {
864857
printk(KERN_ERR "%s: error %d requesting status\n",
865858
req->rq_disk->disk_name, err);
@@ -870,16 +863,8 @@ static int mmc_blk_issue_rw_rq(struct mmc_queue *mq, struct request *req)
870863
* so make sure to check both the busy
871864
* indication and the card state.
872865
*/
873-
} while (!(cmd.resp[0] & R1_READY_FOR_DATA) ||
874-
(R1_CURRENT_STATE(cmd.resp[0]) == 7));
875-
876-
#if 0
877-
if (cmd.resp[0] & ~0x00000900)
878-
printk(KERN_ERR "%s: status = %08x\n",
879-
req->rq_disk->disk_name, cmd.resp[0]);
880-
if (mmc_decode_status(cmd.resp))
881-
goto cmd_err;
882-
#endif
866+
} while (!(status & R1_READY_FOR_DATA) ||
867+
(R1_CURRENT_STATE(status) == R1_STATE_PRG));
883868
}
884869

885870
if (brq.cmd.error || brq.stop.error || brq.data.error) {

‎include/linux/mmc/mmc.h‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,16 @@ static inline bool mmc_op_multi(u32 opcode)
140140
#define R1_SWITCH_ERROR (1 << 7) /* sx, c */
141141
#define R1_APP_CMD (1 << 5) /* sr, c */
142142

143+
#define R1_STATE_IDLE 0
144+
#define R1_STATE_READY 1
145+
#define R1_STATE_IDENT 2
146+
#define R1_STATE_STBY 3
147+
#define R1_STATE_TRAN 4
148+
#define R1_STATE_DATA 5
149+
#define R1_STATE_RCV 6
150+
#define R1_STATE_PRG 7
151+
#define R1_STATE_DIS 8
152+
143153
/*
144154
* MMC/SD in SPI mode reports R1 status always, and R2 for SEND_STATUS
145155
* R1 is the low order byte; R2 is the next highest byte, when present.

0 commit comments

Comments
 (0)