lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <1287263976-9578-1-git-send-email-vapier@gentoo.org>
Date:	Sat, 16 Oct 2010 17:19:36 -0400
From:	Mike Frysinger <vapier@...too.org>
To:	linux-mmc@...r.kernel.org, Adrian Hunter <adrian.hunter@...ia.com>,
	Andrew Morton <akpm@...ux-foundation.org>
Cc:	uclinux-dist-devel@...ckfin.uclinux.org,
	linux-kernel@...r.kernel.org,
	David Brownell <dbrownell@...rs.sourceforge.net>,
	Grant Likely <grant.likely@...retlab.ca>,
	Anton Vorontsov <avorontsov@...sta.com>,
	Ernst Schwab <eschwab@...ine.de>,
	Sonic Zhang <sonic.zhang@...log.com>,
	Chris Ball <cjb@...top.org>
Subject: [PATCH] MMC:mmc_spi: Recover from CRC error for SD read/write operation over SPI.

From: Sonic Zhang <sonic.zhang@...log.com>

SPI bus is not reliable on all platforms when doing large data transfer.
Current mmc spi driver fails SD read/write command immediately, if
occasional CRC error is reported by SD device. This patch makes the
operation recover from the CRC error by doing last SD command again.
The retry count is set to 5 to ensure the driver pass any stress test.

Signed-off-by: Sonic Zhang <sonic.zhang@...log.com>
[cjb: fixed merge conflict against current Linus]
Signed-off-by: Chris Ball <cjb@...top.org>
Signed-off-by: Mike Frysinger <vapier@...too.org>
---
Andrew: we posted this months ago with no feedback ... could you pick it up ?

 drivers/mmc/host/mmc_spi.c |   22 ++++++++++++++++++++++
 1 files changed, 22 insertions(+), 0 deletions(-)

diff --git a/drivers/mmc/host/mmc_spi.c b/drivers/mmc/host/mmc_spi.c
index 62a3582..fbd673e 100644
--- a/drivers/mmc/host/mmc_spi.c
+++ b/drivers/mmc/host/mmc_spi.c
@@ -1055,6 +1055,8 @@ static void mmc_spi_request(struct mmc_host *mmc, struct mmc_request *mrq)
 {
 	struct mmc_spi_host	*host = mmc_priv(mmc);
 	int			status = -EINVAL;
+	int			crc_retry = 5;
+	struct mmc_command	stop;
 
 #ifdef DEBUG
 	/* MMC core and layered drivers *MUST* issue SPI-aware commands */
@@ -1087,10 +1089,30 @@ static void mmc_spi_request(struct mmc_host *mmc, struct mmc_request *mrq)
 	/* request exclusive bus access */
 	spi_bus_lock(host->spi->master);
 
+ crc_recover:
 	/* issue command; then optionally data and stop */
 	status = mmc_spi_command_send(host, mrq, mrq->cmd, mrq->data != NULL);
 	if (status == 0 && mrq->data) {
 		mmc_spi_data_do(host, mrq->cmd, mrq->data, mrq->data->blksz);
+
+		/*
+		 * SPI bus is not reliable when doing large data transfer.
+		 * If occasional crc error is reported by SD device when do
+		 * data read/write over SPI, it can be recovered by doing
+		 * last SD command again. The retry count is set to 5 to
+		 * ensure the driver pass any stress test.
+		 */
+		if (mrq->data->error == -EILSEQ && crc_retry) {
+			stop.opcode = MMC_STOP_TRANSMISSION;
+			stop.arg = 0;
+			stop.flags = MMC_RSP_SPI_R1B | MMC_RSP_R1B | MMC_CMD_AC;
+
+			status = mmc_spi_command_send(host, mrq, &stop, 0);
+			crc_retry--;
+			mrq->data->error = 0;
+			goto crc_recover;
+		}
+
 		if (mrq->stop)
 			status = mmc_spi_command_send(host, mrq, mrq->stop, 0);
 		else
-- 
1.7.3.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ