diff mbox

[U-Boot,3/4] mmc: dw_mmc: Improve handling of data transfer failure

Message ID 1438029579-9352-3-git-send-email-marex@denx.de
State Accepted
Delegated to: Pantelis Antoniou
Headers show

Commit Message

Marek Vasut July 27, 2015, 8:39 p.m. UTC
In case the data transfer failure happens, instead of returning
immediatelly, make sure the DMA is disabled, status register is
cleared and the bounce buffer is stopped.

Signed-off-by: Marek Vasut <marex@denx.de>
Cc: Dinh Nguyen <dinguyen@opensource.altera.com>
Cc: Pantelis Antoniou <panto@antoniou-consulting.com>
Cc: Tom Rini <trini@konsulko.com>
---
 drivers/mmc/dw_mmc.c | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)

Comments

Pantelis Antoniou Aug. 12, 2015, 7:27 a.m. UTC | #1
Hi Marek,

> On Jul 27, 2015, at 23:39 , Marek Vasut <marex@denx.de> wrote:
> 
> In case the data transfer failure happens, instead of returning
> immediatelly, make sure the DMA is disabled, status register is
> cleared and the bounce buffer is stopped.
> 
> Signed-off-by: Marek Vasut <marex@denx.de>
> Cc: Dinh Nguyen <dinguyen@opensource.altera.com>
> Cc: Pantelis Antoniou <panto@antoniou-consulting.com>
> Cc: Tom Rini <trini@konsulko.com>
> ---
> drivers/mmc/dw_mmc.c | 16 +++++++++-------
> 1 file changed, 9 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/mmc/dw_mmc.c b/drivers/mmc/dw_mmc.c
> index 0f61f16..fcd5784 100644
> --- a/drivers/mmc/dw_mmc.c
> +++ b/drivers/mmc/dw_mmc.c
> @@ -110,7 +110,7 @@ static int dwmci_send_cmd(struct mmc *mmc, struct mmc_cmd *cmd,
> 	struct dwmci_host *host = mmc->priv;
> 	ALLOC_CACHE_ALIGN_BUFFER(struct dwmci_idmac, cur_idmac,
> 				 data ? DIV_ROUND_UP(data->blocks, 8) : 0);
> -	int flags = 0, i;
> +	int ret = 0, flags = 0, i;
> 	unsigned int timeout = 100000;
> 	u32 retry = 10000;
> 	u32 mask, ctrl;
> @@ -218,20 +218,22 @@ static int dwmci_send_cmd(struct mmc *mmc, struct mmc_cmd *cmd,
> 			/* Error during data transfer. */
> 			if (mask & (DWMCI_DATA_ERR | DWMCI_DATA_TOUT)) {
> 				printf("%s: DATA ERROR!\n", __func__);
> -				bounce_buffer_stop(&bbstate);
> -				return -1;
> +				ret = -EINVAL;
> +				break;
> 			}
> 
> 			/* Data arrived correctly. */
> -			if (mask & DWMCI_INTMSK_DTO)
> +			if (mask & DWMCI_INTMSK_DTO) {
> +				ret = 0;
> 				break;
> +			}
> 
> 			/* Check for timeout. */
> 			if (get_timer(start) > timeout) {
> 				printf("%s: Timeout waiting for data!\n",
> 				       __func__);
> -				bounce_buffer_stop(&bbstate);
> -				return TIMEOUT;
> +				ret = TIMEOUT;
> +				break;
> 			}
> 		}
> 
> @@ -246,7 +248,7 @@ static int dwmci_send_cmd(struct mmc *mmc, struct mmc_cmd *cmd,
> 
> 	udelay(100);
> 
> -	return 0;
> +	return ret;
> }
> 
> static int dwmci_setup_bus(struct dwmci_host *host, u32 freq)
> -- 
> 2.1.4

Applied, thanks

— Pantelis
diff mbox

Patch

diff --git a/drivers/mmc/dw_mmc.c b/drivers/mmc/dw_mmc.c
index 0f61f16..fcd5784 100644
--- a/drivers/mmc/dw_mmc.c
+++ b/drivers/mmc/dw_mmc.c
@@ -110,7 +110,7 @@  static int dwmci_send_cmd(struct mmc *mmc, struct mmc_cmd *cmd,
 	struct dwmci_host *host = mmc->priv;
 	ALLOC_CACHE_ALIGN_BUFFER(struct dwmci_idmac, cur_idmac,
 				 data ? DIV_ROUND_UP(data->blocks, 8) : 0);
-	int flags = 0, i;
+	int ret = 0, flags = 0, i;
 	unsigned int timeout = 100000;
 	u32 retry = 10000;
 	u32 mask, ctrl;
@@ -218,20 +218,22 @@  static int dwmci_send_cmd(struct mmc *mmc, struct mmc_cmd *cmd,
 			/* Error during data transfer. */
 			if (mask & (DWMCI_DATA_ERR | DWMCI_DATA_TOUT)) {
 				printf("%s: DATA ERROR!\n", __func__);
-				bounce_buffer_stop(&bbstate);
-				return -1;
+				ret = -EINVAL;
+				break;
 			}
 
 			/* Data arrived correctly. */
-			if (mask & DWMCI_INTMSK_DTO)
+			if (mask & DWMCI_INTMSK_DTO) {
+				ret = 0;
 				break;
+			}
 
 			/* Check for timeout. */
 			if (get_timer(start) > timeout) {
 				printf("%s: Timeout waiting for data!\n",
 				       __func__);
-				bounce_buffer_stop(&bbstate);
-				return TIMEOUT;
+				ret = TIMEOUT;
+				break;
 			}
 		}
 
@@ -246,7 +248,7 @@  static int dwmci_send_cmd(struct mmc *mmc, struct mmc_cmd *cmd,
 
 	udelay(100);
 
-	return 0;
+	return ret;
 }
 
 static int dwmci_setup_bus(struct dwmci_host *host, u32 freq)