mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH] drivers/mci: fix read/write stalling
@ 2012-02-27 22:45 Robert Jarzmik
  2012-02-28  8:36 ` Sascha Hauer
  2012-02-29  7:39 ` Sascha Hauer
  0 siblings, 2 replies; 4+ messages in thread
From: Robert Jarzmik @ 2012-02-27 22:45 UTC (permalink / raw)
  To: barebox

If a read or write operation encounters an error, the card
might stay in "recv" or "data" state, and never get back to
"tran" state.

In these cases, the host is required to send a CMD12 (end
transmission) to switch the FSM of the card back to "tran"
state, as described in MMC Specification, chapter "Data
Transfer Mode".

Signed-off-by: Robert Jarzmik <robert.jarzmik@free.fr>
---
 drivers/mci/mci-core.c |   31 ++++++++++---------------------
 1 files changed, 10 insertions(+), 21 deletions(-)

diff --git a/drivers/mci/mci-core.c b/drivers/mci/mci-core.c
index 0bf4449..6432391 100644
--- a/drivers/mci/mci-core.c
+++ b/drivers/mci/mci-core.c
@@ -101,7 +101,7 @@ static int mci_set_blocklen(struct mci *mci, unsigned len)
 static void *sector_buf;
 
 /**
- * Write one block of data to the card
+ * Write one or several blocks of data to the card
  * @param mci_dev MCI instance
  * @param src Where to read from to write to the card
  * @param blocknum Block number to write
@@ -140,23 +140,17 @@ static int mci_block_write(struct mci *mci, const void *src, int blocknum,
 	data.flags = MMC_DATA_WRITE;
 
 	ret = mci_send_cmd(mci, &cmd, &data);
-	if (ret)
-		return ret;
-
-	if (blocks > 1) {
-		mci_setup_cmd(&cmd,
-			MMC_CMD_STOP_TRANSMISSION,
-			0, MMC_RSP_R1b);
-			ret = mci_send_cmd(mci, &cmd, NULL);
-			if (ret)
-				return ret;
+
+	if (ret || blocks > 1) {
+		mci_setup_cmd(&cmd, MMC_CMD_STOP_TRANSMISSION, 0, MMC_RSP_R1b);
+		mci_send_cmd(mci, &cmd, NULL);
         }
 
 	return ret;
 }
 
 /**
- * Read one block of data from the card
+ * Read one or several block(s) of data from the card
  * @param mci MCI instance
  * @param dst Where to store the data read from the card
  * @param blocknum Block number to read
@@ -186,15 +180,10 @@ static int mci_read_block(struct mci *mci, void *dst, int blocknum,
 	data.flags = MMC_DATA_READ;
 
 	ret = mci_send_cmd(mci, &cmd, &data);
-	if (ret)
-		return ret;
-
-	if (blocks > 1) {
-		mci_setup_cmd(&cmd,
-			MMC_CMD_STOP_TRANSMISSION,
-			0,
-			MMC_RSP_R1b);
-			ret = mci_send_cmd(mci, &cmd, NULL);
+
+	if (ret || blocks > 1) {
+		mci_setup_cmd(&cmd, MMC_CMD_STOP_TRANSMISSION, 0, MMC_RSP_R1b);
+		mci_send_cmd(mci, &cmd, NULL);
 	}
 	return ret;
 }
-- 
1.7.5.4


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] drivers/mci: fix read/write stalling
  2012-02-27 22:45 [PATCH] drivers/mci: fix read/write stalling Robert Jarzmik
@ 2012-02-28  8:36 ` Sascha Hauer
  2012-02-28 12:34   ` Robert Jarzmik
  2012-02-29  7:39 ` Sascha Hauer
  1 sibling, 1 reply; 4+ messages in thread
From: Sascha Hauer @ 2012-02-28  8:36 UTC (permalink / raw)
  To: Robert Jarzmik; +Cc: barebox

On Mon, Feb 27, 2012 at 11:45:28PM +0100, Robert Jarzmik wrote:
> If a read or write operation encounters an error, the card
> might stay in "recv" or "data" state, and never get back to
> "tran" state.
> 
> In these cases, the host is required to send a CMD12 (end
> transmission) to switch the FSM of the card back to "tran"
> state, as described in MMC Specification, chapter "Data
> Transfer Mode".
> 
> Signed-off-by: Robert Jarzmik <robert.jarzmik@free.fr>
> ---
>  drivers/mci/mci-core.c |   31 ++++++++++---------------------
>  1 files changed, 10 insertions(+), 21 deletions(-)
> 
> diff --git a/drivers/mci/mci-core.c b/drivers/mci/mci-core.c
> index 0bf4449..6432391 100644
> --- a/drivers/mci/mci-core.c
> +++ b/drivers/mci/mci-core.c
> @@ -101,7 +101,7 @@ static int mci_set_blocklen(struct mci *mci, unsigned len)
>  static void *sector_buf;
>  
>  /**
> - * Write one block of data to the card
> + * Write one or several blocks of data to the card
>   * @param mci_dev MCI instance
>   * @param src Where to read from to write to the card
>   * @param blocknum Block number to write
> @@ -140,23 +140,17 @@ static int mci_block_write(struct mci *mci, const void *src, int blocknum,
>  	data.flags = MMC_DATA_WRITE;
>  
>  	ret = mci_send_cmd(mci, &cmd, &data);
> -	if (ret)
> -		return ret;
> -
> -	if (blocks > 1) {
> -		mci_setup_cmd(&cmd,
> -			MMC_CMD_STOP_TRANSMISSION,
> -			0, MMC_RSP_R1b);
> -			ret = mci_send_cmd(mci, &cmd, NULL);
> -			if (ret)
> -				return ret;
> +
> +	if (ret || blocks > 1) {
> +		mci_setup_cmd(&cmd, MMC_CMD_STOP_TRANSMISSION, 0, MMC_RSP_R1b);
> +		mci_send_cmd(mci, &cmd, NULL);

Do we have to send CMD12 even when a single block transfer failed?

Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] drivers/mci: fix read/write stalling
  2012-02-28  8:36 ` Sascha Hauer
@ 2012-02-28 12:34   ` Robert Jarzmik
  0 siblings, 0 replies; 4+ messages in thread
From: Robert Jarzmik @ 2012-02-28 12:34 UTC (permalink / raw)
  To: Sascha Hauer; +Cc: barebox

Sascha Hauer <s.hauer@pengutronix.de> writes:

> On Mon, Feb 27, 2012 at 11:45:28PM +0100, Robert Jarzmik wrote:
> Do we have to send CMD12 even when a single block transfer failed?
Yes, we should.

For instance, the PXA host can stall even on a single block read. The spec
states that only a "Operation Complete" or "CMD12" brings back the card to
"tran" state. If a CRC error occurs in the middle of the read, the card has the
right to stay in "data" state.

-- 
Robert

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] drivers/mci: fix read/write stalling
  2012-02-27 22:45 [PATCH] drivers/mci: fix read/write stalling Robert Jarzmik
  2012-02-28  8:36 ` Sascha Hauer
@ 2012-02-29  7:39 ` Sascha Hauer
  1 sibling, 0 replies; 4+ messages in thread
From: Sascha Hauer @ 2012-02-29  7:39 UTC (permalink / raw)
  To: Robert Jarzmik; +Cc: barebox

On Mon, Feb 27, 2012 at 11:45:28PM +0100, Robert Jarzmik wrote:
> If a read or write operation encounters an error, the card
> might stay in "recv" or "data" state, and never get back to
> "tran" state.
> 
> In these cases, the host is required to send a CMD12 (end
> transmission) to switch the FSM of the card back to "tran"
> state, as described in MMC Specification, chapter "Data
> Transfer Mode".
> 
> Signed-off-by: Robert Jarzmik <robert.jarzmik@free.fr>

Applied, thanks.

I applied this one to -next instead of master, I'd like to give
it a bit of testing before this hits a release.

Sascha

> ---
>  drivers/mci/mci-core.c |   31 ++++++++++---------------------
>  1 files changed, 10 insertions(+), 21 deletions(-)
> 
> diff --git a/drivers/mci/mci-core.c b/drivers/mci/mci-core.c
> index 0bf4449..6432391 100644
> --- a/drivers/mci/mci-core.c
> +++ b/drivers/mci/mci-core.c
> @@ -101,7 +101,7 @@ static int mci_set_blocklen(struct mci *mci, unsigned len)
>  static void *sector_buf;
>  
>  /**
> - * Write one block of data to the card
> + * Write one or several blocks of data to the card
>   * @param mci_dev MCI instance
>   * @param src Where to read from to write to the card
>   * @param blocknum Block number to write
> @@ -140,23 +140,17 @@ static int mci_block_write(struct mci *mci, const void *src, int blocknum,
>  	data.flags = MMC_DATA_WRITE;
>  
>  	ret = mci_send_cmd(mci, &cmd, &data);
> -	if (ret)
> -		return ret;
> -
> -	if (blocks > 1) {
> -		mci_setup_cmd(&cmd,
> -			MMC_CMD_STOP_TRANSMISSION,
> -			0, MMC_RSP_R1b);
> -			ret = mci_send_cmd(mci, &cmd, NULL);
> -			if (ret)
> -				return ret;
> +
> +	if (ret || blocks > 1) {
> +		mci_setup_cmd(&cmd, MMC_CMD_STOP_TRANSMISSION, 0, MMC_RSP_R1b);
> +		mci_send_cmd(mci, &cmd, NULL);
>          }
>  
>  	return ret;
>  }
>  
>  /**
> - * Read one block of data from the card
> + * Read one or several block(s) of data from the card
>   * @param mci MCI instance
>   * @param dst Where to store the data read from the card
>   * @param blocknum Block number to read
> @@ -186,15 +180,10 @@ static int mci_read_block(struct mci *mci, void *dst, int blocknum,
>  	data.flags = MMC_DATA_READ;
>  
>  	ret = mci_send_cmd(mci, &cmd, &data);
> -	if (ret)
> -		return ret;
> -
> -	if (blocks > 1) {
> -		mci_setup_cmd(&cmd,
> -			MMC_CMD_STOP_TRANSMISSION,
> -			0,
> -			MMC_RSP_R1b);
> -			ret = mci_send_cmd(mci, &cmd, NULL);
> +
> +	if (ret || blocks > 1) {
> +		mci_setup_cmd(&cmd, MMC_CMD_STOP_TRANSMISSION, 0, MMC_RSP_R1b);
> +		mci_send_cmd(mci, &cmd, NULL);
>  	}
>  	return ret;
>  }
> -- 
> 1.7.5.4
> 
> 
> _______________________________________________
> barebox mailing list
> barebox@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox
> 

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2012-02-29  7:39 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-02-27 22:45 [PATCH] drivers/mci: fix read/write stalling Robert Jarzmik
2012-02-28  8:36 ` Sascha Hauer
2012-02-28 12:34   ` Robert Jarzmik
2012-02-29  7:39 ` Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox