Skip to content

Commit 5d43593

Browse files
cloehlestorulf
authored andcommitted
mmc: block: Check for errors after write on SPI
Introduce a SEND_STATUS check for writes through SPI to not mark an unsuccessful write as successful. Since SPI SD/MMC does not have states, after a write, the card will just hold the line LOW until it is ready again. The driver marks the write therefore as completed as soon as it reads something other than all zeroes. The driver does not distinguish from a card no longer signalling busy and it being disconnected (and the line being pulled-up by the host). This lead to writes being marked as successful when disconnecting a busy card. Now the card is ensured to be still connected by an additional CMD13, just like non-SPI is ensured to go back to TRAN state. While at it and since we already poll for the post-write status anyway, we might as well check for SPIs error bits (any of them). The disconnecting card problem is reproducable for me after continuous write activity and randomly disconnecting, around every 20-50 tries on SPI DS for some card. Fixes: 7213d17 ("MMC/SD card driver learns SPI") Cc: stable@vger.kernel.org Signed-off-by: Christian Loehle <cloehle@hyperstone.com> Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Link: https://lore.kernel.org/r/76f6f5d2b35543bab3dfe438f268609c@hyperstone.com Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
1 parent 0d319dd commit 5d43593

File tree

1 file changed

+33
-1
lines changed

1 file changed

+33
-1
lines changed

drivers/mmc/core/block.c

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1880,6 +1880,31 @@ static inline bool mmc_blk_rq_error(struct mmc_blk_request *brq)
18801880
brq->data.error || brq->cmd.resp[0] & CMD_ERRORS;
18811881
}
18821882

1883+
static int mmc_spi_err_check(struct mmc_card *card)
1884+
{
1885+
u32 status = 0;
1886+
int err;
1887+
1888+
/*
1889+
* SPI does not have a TRAN state we have to wait on, instead the
1890+
* card is ready again when it no longer holds the line LOW.
1891+
* We still have to ensure two things here before we know the write
1892+
* was successful:
1893+
* 1. The card has not disconnected during busy and we actually read our
1894+
* own pull-up, thinking it was still connected, so ensure it
1895+
* still responds.
1896+
* 2. Check for any error bits, in particular R1_SPI_IDLE to catch a
1897+
* just reconnected card after being disconnected during busy.
1898+
*/
1899+
err = __mmc_send_status(card, &status, 0);
1900+
if (err)
1901+
return err;
1902+
/* All R1 and R2 bits of SPI are errors in our case */
1903+
if (status)
1904+
return -EIO;
1905+
return 0;
1906+
}
1907+
18831908
static int mmc_blk_busy_cb(void *cb_data, bool *busy)
18841909
{
18851910
struct mmc_blk_busy_data *data = cb_data;
@@ -1903,9 +1928,16 @@ static int mmc_blk_card_busy(struct mmc_card *card, struct request *req)
19031928
struct mmc_blk_busy_data cb_data;
19041929
int err;
19051930

1906-
if (mmc_host_is_spi(card->host) || rq_data_dir(req) == READ)
1931+
if (rq_data_dir(req) == READ)
19071932
return 0;
19081933

1934+
if (mmc_host_is_spi(card->host)) {
1935+
err = mmc_spi_err_check(card);
1936+
if (err)
1937+
mqrq->brq.data.bytes_xfered = 0;
1938+
return err;
1939+
}
1940+
19091941
cb_data.card = card;
19101942
cb_data.status = 0;
19111943
err = __mmc_poll_for_busy(card->host, 0, MMC_BLK_TIMEOUT_MS,

0 commit comments

Comments
 (0)