Skip to contentSkip to conversation

mmc: dwmmc: Enable small delay before returning error

PATCH New chee.hong.ang at intel.com 3 participants 10 messages Feb 18, 2019 – Mar 5, 2019 MMC, SD and SDIO

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mmc: dwmmc: Enable small delay before returning error

From: "Ang, Chee Hong" <[email protected]>

'SET_BLOCKLEN' may occasionally fail on first attempt. This patch enable a small delay in dwmci_send_cmd() on busy, I/O or CRC error to allow the MMC controller recovers from the failure/error on subsequent retries.

---
 drivers/mmc/dw_mmc.c | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)
drivers/mmc/dw_mmc.c +10 -4
index 7544b84..8dcc518 100644
@@ -266,8 +266,11 @@ static int dwmci_send_cmd(struct mmc *mmc, struct mmc_cmd *cmd,
 	if (data)
 		flags = dwmci_set_transfer_mode(host, data);
 
-	if ((cmd->resp_type & MMC_RSP_136) && (cmd->resp_type & MMC_RSP_BUSY))
-		return -1;
+	if ((cmd->resp_type & MMC_RSP_136) &&
+	    (cmd->resp_type & MMC_RSP_BUSY)) {
+		ret = -1;
+		goto delay_ret;
+	}
 
 	if (cmd->cmdidx == MMC_CMD_STOP_TRANSMISSION)
 		flags |= DWMCI_CMD_ABORT_STOP;
@@ -316,11 +319,13 @@ static int dwmci_send_cmd(struct mmc *mmc, struct mmc_cmd *cmd,
 		return -ETIMEDOUT;
 	} else if (mask & DWMCI_INTMSK_RE) {
 		debug("%s: Response Error.\n", __func__);
-		return -EIO;
+		ret = -EIO;
+		goto delay_ret;
 	} else if ((cmd->resp_type & MMC_RSP_CRC) &&
 		   (mask & DWMCI_INTMSK_RCRC)) {
 		debug("%s: Response CRC Error.\n", __func__);
-		return -EIO;
+		ret = -EIO;
+		goto delay_ret;
 	}
 
 
@@ -347,6 +352,7 @@ static int dwmci_send_cmd(struct mmc *mmc, struct mmc_cmd *cmd,
 		}
 	}
 
+delay_ret:
 	udelay(100);
 
 	return ret;
Signature · 1 line
2.7.4
#1 lore raw

PATCH 1/1 mmc: dwmmc: Enable small delay before returning error

Quoted 3 lines · chee.hong.ang at intel.com

From: "Ang, Chee Hong" <[email protected]>

'SET_BLOCKLEN' may occasionally fail on first attempt.

Why ?

Quoted 3 lines

This patch enable a small delay in dwmci_send_cmd() on busy, I/O or CRC error to allow the MMC controller recovers from the failure/error on subsequent retries.

Why 100 uS ?

Can we rather detect whether the controller recovered by polling some bit?

Quoted 48 lines
---
 drivers/mmc/dw_mmc.c | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)
drivers/mmc/dw_mmc.c +10 -4
index 7544b84..8dcc518 100644
@@ -266,8 +266,11 @@ static int dwmci_send_cmd(struct mmc *mmc, struct mmc_cmd *cmd,
 	if (data)
 		flags = dwmci_set_transfer_mode(host, data);
 
-	if ((cmd->resp_type & MMC_RSP_136) && (cmd->resp_type & MMC_RSP_BUSY))
-		return -1;
+	if ((cmd->resp_type & MMC_RSP_136) &&
+	    (cmd->resp_type & MMC_RSP_BUSY)) {
+		ret = -1;
+		goto delay_ret;
+	}
 
 	if (cmd->cmdidx == MMC_CMD_STOP_TRANSMISSION)
 		flags |= DWMCI_CMD_ABORT_STOP;
@@ -316,11 +319,13 @@ static int dwmci_send_cmd(struct mmc *mmc, struct mmc_cmd *cmd,
 		return -ETIMEDOUT;
 	} else if (mask & DWMCI_INTMSK_RE) {
 		debug("%s: Response Error.\n", __func__);
-		return -EIO;
+		ret = -EIO;
+		goto delay_ret;
 	} else if ((cmd->resp_type & MMC_RSP_CRC) &&
 		   (mask & DWMCI_INTMSK_RCRC)) {
 		debug("%s: Response CRC Error.\n", __func__);
-		return -EIO;
+		ret = -EIO;
+		goto delay_ret;
 	}
 
 
@@ -347,6 +352,7 @@ static int dwmci_send_cmd(struct mmc *mmc, struct mmc_cmd *cmd,
 		}
 	}
 
+delay_ret:
 	udelay(100);
 
 	return ret;
Signature · 2 lines
Best regards,
Marek Vasut
#2 lore raw

PATCH 1/1 mmc: dwmmc: Enable small delay before returning error

Quoted 6 lines · Marek Vasut
Quoted 4 lines · chee.hong.ang at intel.com

From: "Ang, Chee Hong" <[email protected]>

'SET_BLOCKLEN' may occasionally fail on first attempt.

Why ?

This is part of the workaround of mmc driver which is enabled with 'CONFIG_MMC_QUIRKS' config.
https://github.com/u-boot/u-boot/blob/dbe70c7d4e3d5c705a98d82952e05a591
efd0683/drivers/mmc/mmc.c#L272

Quoted 6 lines
Quoted 5 lines

This patch enable a small delay in dwmci_send_cmd() on busy, I/O or CRC error to allow the MMC controller recovers from the failure/error on subsequent retries.

Why 100 uS ?

This is a good question. Perhaps the driver's authors can explain this. The driver delay 100us after dwmci_send_cmd() success with the command sent. But it never delay 100us whenever mmc controller response to the command sent with I/O or CRC errors. MMC drivers expect the first 'SET_BLOCKEN' command issued by dwmci_send_cmd() may fail intermittently so it will retry up to 4 times before it gave up and return error. Without this 100us delay after error response, 'SET_BLOCKEN' may sometime fail in 4 attempts in a row. Therefore, we encountered intermittent failure in loading u-boot (SSBL) from MMC.

Quoted 3 lines

Can we rather detect whether the controller recovered by polling some bit?

Hmmm...I can take a look at the databook of this controller and dig further. Probably this is the limitation of the controller itself. The mmc driver code which introduce 100us delay after every command sent in dwmci_send_cmd() looks iffy.

Quoted 55 lines
Quoted 54 lines

---
 drivers/mmc/dw_mmc.c | 14 ++++++++++----

 1 file changed, 10 insertions(+), 4 deletions(-)
drivers/mmc/dw_mmc.c +0 -0
index 7544b84..8dcc518 100644
@@ -266,8 +266,11 @@ static int dwmci_send_cmd(struct mmc *mmc,
 struct mmc_cmd *cmd,
  	if (data)
  		flags = dwmci_set_transfer_mode(host, data);

drivers/mmc/dw_mmc.c +0 -1
-	if ((cmd->resp_type & MMC_RSP_136) && (cmd->resp_type &

MMC_RSP_BUSY))

drivers/mmc/dw_mmc.c +5 -1
-		return -1;
+	if ((cmd->resp_type & MMC_RSP_136) &&
+	    (cmd->resp_type & MMC_RSP_BUSY)) {
+		ret = -1;
+		goto delay_ret;
+	}


  if (cmd->cmdidx == MMC_CMD_STOP_TRANSMISSION) flags |= DWMCI_CMD_ABORT_STOP;

drivers/mmc/dw_mmc.c +4 -2
@@ -316,11 +319,13 @@ static int dwmci_send_cmd(struct mmc *mmc,
 struct mmc_cmd *cmd,
  		return -ETIMEDOUT;
  	} else if (mask & DWMCI_INTMSK_RE) {
  		debug("%s: Response Error.\n", __func__);
-		return -EIO;
+		ret = -EIO;
+		goto delay_ret;
  	} else if ((cmd->resp_type & MMC_RSP_CRC) &&
  		   (mask & DWMCI_INTMSK_RCRC)) {
  		debug("%s: Response CRC Error.\n", __func__);
-		return -EIO;
+		ret = -EIO;
+		goto delay_ret;
  	}


drivers/mmc/dw_mmc.c +0 -0
@@ -347,6 +352,7 @@ static int dwmci_send_cmd(struct mmc *mmc,
 struct mmc_cmd *cmd,
  		}
  	}


+delay_ret:
  udelay(100);

  return ret;

#3 lore raw

PATCH 1/1 mmc: dwmmc: Enable small delay before returning error

Quoted 11 lines · Chee Hong
Quoted 6 lines · Marek Vasut
Quoted 4 lines · chee.hong.ang at intel.com

From: "Ang, Chee Hong" <[email protected]>

'SET_BLOCKLEN' may occasionally fail on first attempt.

Why ?

This is part of the workaround of mmc driver which is enabled with 'CONFIG_MMC_QUIRKS' config.
https://github.com/u-boot/u-boot/blob/dbe70c7d4e3d5c705a98d82952e05a591
efd0683/drivers/mmc/mmc.c#L272

OK, let's take a step back. What problem do you observe, that you're trying to fix ?

Quoted 4 lines
Quoted 4 lines
Quoted 3 lines

This patch enable a small delay in dwmci_send_cmd() on busy, I/O or CRC error to allow the MMC controller recovers from the failure/error on subsequent retries.

Why 100 uS ?

Quoted 9 lines

This is a good question. Perhaps the driver's authors can explain this. The driver delay 100us after dwmci_send_cmd() success with the command sent. But it never delay 100us whenever mmc controller response to the command sent with I/O or CRC errors. MMC drivers expect the first 'SET_BLOCKEN' command issued by dwmci_send_cmd() may fail intermittently so it will retry up to 4 times before it gave up and return error. Without this 100us delay after error response, 'SET_BLOCKEN' may sometime fail in 4 attempts in a row. Therefore, we encountered intermittent failure in loading u-boot (SSBL) from MMC.

Can you be more specific about the failure you saw ?

Quoted 6 lines
Quoted 2 lines

Can we rather detect whether the controller recovered by polling some bit?

Hmmm...I can take a look at the databook of this controller and dig further. Probably this is the limitation of the controller itself. The mmc driver code which introduce 100us delay after every command sent in dwmci_send_cmd() looks iffy.

If you have access to it, please do.

btw do you have the same problem if you disable caches ?

Quoted 52 lines
Quoted 52 lines
Quoted 52 lines

---
 drivers/mmc/dw_mmc.c | 14 ++++++++++----

 1 file changed, 10 insertions(+), 4 deletions(-)
drivers/mmc/dw_mmc.c +0 -0
index 7544b84..8dcc518 100644
@@ -266,8 +266,11 @@ static int dwmci_send_cmd(struct mmc *mmc,
 struct mmc_cmd *cmd,
  	if (data)
  		flags = dwmci_set_transfer_mode(host, data);

drivers/mmc/dw_mmc.c +0 -1
-	if ((cmd->resp_type & MMC_RSP_136) && (cmd->resp_type &

MMC_RSP_BUSY))

drivers/mmc/dw_mmc.c +5 -1
-		return -1;
+	if ((cmd->resp_type & MMC_RSP_136) &&
+	    (cmd->resp_type & MMC_RSP_BUSY)) {
+		ret = -1;
+		goto delay_ret;
+	}


  if (cmd->cmdidx == MMC_CMD_STOP_TRANSMISSION) flags |= DWMCI_CMD_ABORT_STOP;

drivers/mmc/dw_mmc.c +4 -2
@@ -316,11 +319,13 @@ static int dwmci_send_cmd(struct mmc *mmc,
 struct mmc_cmd *cmd,
  		return -ETIMEDOUT;
  	} else if (mask & DWMCI_INTMSK_RE) {
  		debug("%s: Response Error.\n", __func__);
-		return -EIO;
+		ret = -EIO;
+		goto delay_ret;
  	} else if ((cmd->resp_type & MMC_RSP_CRC) &&
  		   (mask & DWMCI_INTMSK_RCRC)) {
  		debug("%s: Response CRC Error.\n", __func__);
-		return -EIO;
+		ret = -EIO;
+		goto delay_ret;
  	}


drivers/mmc/dw_mmc.c +0 -0
@@ -347,6 +352,7 @@ static int dwmci_send_cmd(struct mmc *mmc,
 struct mmc_cmd *cmd,
  		}
  	}


+delay_ret:
  udelay(100);

  return ret;

Signature · 2 lines
Best regards,
Marek Vasut
#4 lore raw

PATCH 1/1 mmc: dwmmc: Enable small delay before returning error

Quoted 10 lines · Marek Vasut
Quoted 9 lines · Chee Hong
Quoted 7 lines · Marek Vasut
Quoted 5 lines · chee.hong.ang at intel.com

From: "Ang, Chee Hong" <[email protected]>

'SET_BLOCKLEN' may occasionally fail on first attempt.

Quoted 8 lines
Quoted 6 lines
Quoted 1 line

Why ?

This is part of the workaround of mmc driver which is enabled with 'CONFIG_MMC_QUIRKS' config.
https://github.com/u-boot/u-boot/blob/dbe70c7d4e3d5c705a98d82952e05
a591
efd0683/drivers/mmc/mmc.c#L272

OK, let's take a step back. What problem do you observe, that you're trying to fix ?

See my detail explanation below.

Quoted 21 lines
Quoted 8 lines
Quoted 8 lines
Quoted 7 lines

This patch enable a small delay in dwmci_send_cmd() on busy, I/O or CRC error to allow the MMC controller recovers from the failure/error on subsequent retries.

Why 100 uS ?

Quoted 13 lines

This is a good question. Perhaps the driver's authors can explain this.
The driver delay 100us after dwmci_send_cmd() success with the command
sent. But it never delay 100us whenever mmc controller response to the
command sent with I/O or CRC errors. MMC drivers expect the first 'SET_BLOCKEN' command issued by dwmci_send_cmd() may fail intermittently so it will retry up to 4 times before it gave up and return error. Without this 100us delay after error response, 'SET_BLOCKEN' may sometime fail in 4 attempts in a row. Therefore, we
encountered intermittent failure in loading u-boot (SSBL) from MMC.

Quoted 1 line

Can you be more specific about the failure you saw ?

Here are the steps for booting u-boot (SSBL) from MMC:

1) SPL (FSBL) get loaded to OCRAM
2) SPL try to load uboot as SSBL from MMC
3) SPL issue 'SET_BLOCKEN' to MMC controller
4) If MMC controller response with error continue to step 5 else go to step 7
5) If is less than 4 attempts go to step 3 else continue to step 6
6) Indicate to user there was an error loading uboot as SSBL from MMC and stop here
7) Send command to read blocks of data from MMC
8) uboot successfully loaded to DDR memory
9) SPL jumps to uboot and continue the boot flow.

So this patch actually introduce a small delay at step 4. Without this small delay, step 4 might sometime fail in all 4 attempts to issue the 'SET_BLOCKEN' command to MMC controller. Note that this failure is intermittent. If it fails at step 3 and there is no small delay in step 4, it will most likely fail in subsequent attempts.

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

Can we rather detect whether the controller recovered by polling some
bit?

Quoted 7 lines
Quoted 6 lines

Hmmm...I can take a look at the databook of this controller and dig further. Probably this is the limitation of the controller itself. The
mmc driver code which introduce 100us delay after every command sent in
dwmci_send_cmd() looks iffy.

If you have access to it, please do.

Unfortunately, I can't find any registers I can poll for the status of the readiness of the controller from DesignWare storage controller databook.

Quoted 2 lines

btw do you have the same problem if you disable caches ?

The error happen while SPL trying to load uboot as SSBL from MMC into DDR memory.At this point, the caches are disabled.

Quoted 59 lines
Quoted 58 lines
Quoted 58 lines
Quoted 58 lines

---
 drivers/mmc/dw_mmc.c | 14 ++++++++++----

 1 file changed, 10 insertions(+), 4 deletions(-)
drivers/mmc/dw_mmc.c +0 -0
index 7544b84..8dcc518 100644
@@ -266,8 +266,11 @@ static int dwmci_send_cmd(struct mmc *mmc,
 struct mmc_cmd *cmd,
  	if (data)
  		flags = dwmci_set_transfer_mode(host, data);

drivers/mmc/dw_mmc.c +0 -1
-	if ((cmd->resp_type & MMC_RSP_136) && (cmd->resp_type

&
MMC_RSP_BUSY))

drivers/mmc/dw_mmc.c +5 -1
-		return -1;
+	if ((cmd->resp_type & MMC_RSP_136) &&
+	    (cmd->resp_type & MMC_RSP_BUSY)) {
+		ret = -1;
+		goto delay_ret;
+	}


  if (cmd->cmdidx == MMC_CMD_STOP_TRANSMISSION) flags |= DWMCI_CMD_ABORT_STOP;

drivers/mmc/dw_mmc.c +4 -2
@@ -316,11 +319,13 @@ static int dwmci_send_cmd(struct mmc
 *mmc,
 struct mmc_cmd *cmd,
  		return -ETIMEDOUT;
  	} else if (mask & DWMCI_INTMSK_RE) {
  		debug("%s: Response Error.\n", __func__);
-		return -EIO;
+		ret = -EIO;
+		goto delay_ret;
  	} else if ((cmd->resp_type & MMC_RSP_CRC) &&
  		   (mask & DWMCI_INTMSK_RCRC)) {
  		debug("%s: Response CRC Error.\n", __func__);
-		return -EIO;
+		ret = -EIO;
+		goto delay_ret;
  	}


drivers/mmc/dw_mmc.c +0 -0
@@ -347,6 +352,7 @@ static int dwmci_send_cmd(struct mmc *mmc,
 struct mmc_cmd *cmd,
  		}
  	}


+delay_ret:
  udelay(100);

  return ret;

#5 lore raw

PATCH 1/1 mmc: dwmmc: Enable small delay before returning error

Quoted 41 lines · Chee Hong
Quoted 10 lines · Marek Vasut
Quoted 9 lines · Chee Hong
Quoted 7 lines · Marek Vasut
Quoted 5 lines · chee.hong.ang at intel.com

From: "Ang, Chee Hong" <[email protected]>

'SET_BLOCKLEN' may occasionally fail on first attempt.

Quoted 8 lines
Quoted 6 lines
Quoted 1 line

Why ?

This is part of the workaround of mmc driver which is enabled with 'CONFIG_MMC_QUIRKS' config.
https://github.com/u-boot/u-boot/blob/dbe70c7d4e3d5c705a98d82952e05
a591
efd0683/drivers/mmc/mmc.c#L272

OK, let's take a step back. What problem do you observe, that you're trying to fix ?

See my detail explanation below.

Quoted 21 lines
Quoted 21 lines
Quoted 8 lines
Quoted 7 lines

This patch enable a small delay in dwmci_send_cmd() on busy, I/O or CRC error to allow the MMC controller recovers from the failure/error on subsequent retries.

Why 100 uS ?

This is a good question. Perhaps the driver's authors can explain this.
The driver delay 100us after dwmci_send_cmd() success with the command
sent. But it never delay 100us whenever mmc controller response to the
command sent with I/O or CRC errors. MMC drivers expect the first 'SET_BLOCKEN' command issued by dwmci_send_cmd() may fail intermittently so it will retry up to 4 times before it gave up and return error. Without this 100us delay after error response, 'SET_BLOCKEN' may sometime fail in 4 attempts in a row. Therefore, we
encountered intermittent failure in loading u-boot (SSBL) from MMC.

Quoted 7 lines
Quoted 1 line

Can you be more specific about the failure you saw ?

Here are the steps for booting u-boot (SSBL) from MMC:

1) SPL (FSBL) get loaded to OCRAM
2) SPL try to load uboot as SSBL from MMC
3) SPL issue 'SET_BLOCKEN' to MMC controller

s/SPL/MMC framework via DWMMC driver/

Quoted 9 lines

4) If MMC controller response with error continue to step 5 else go to step 7
5) If is less than 4 attempts go to step 3 else continue to step 6
6) Indicate to user there was an error loading uboot as SSBL from MMC and stop here
7) Send command to read blocks of data from MMC
8) uboot successfully loaded to DDR memory
9) SPL jumps to uboot and continue the boot flow.

Quoted 3 lines

So this patch actually introduce a small delay at step 4. Without this small delay, step 4 might sometime fail in all 4 attempts to issue the 'SET_BLOCKEN' command to MMC controller.

Isn't what you observe here some sort of timeout which you need to respect when the card rejects a command ? If so, such timeout should be described in either of the SD or MMC specification and it should be in the MMC framework core instead of a driver.

Quoted 15 lines

Note that this failure is
intermittent. If it fails at step 3 and there is no small delay in step 4, it will most likely fail in subsequent attempts.

Quoted 12 lines
Quoted 12 lines
Quoted 6 lines

Can we rather detect whether the controller recovered by polling some
bit?

Hmmm...I can take a look at the databook of this controller and dig further. Probably this is the limitation of the controller itself. The
mmc driver code which introduce 100us delay after every command sent in
dwmci_send_cmd() looks iffy.

Quoted 8 lines
Quoted 1 line

If you have access to it, please do.

Unfortunately, I can't find any registers I can poll for the status of the readiness of the controller from DesignWare storage controller databook.

Quoted 2 lines

btw do you have the same problem if you disable caches ?

The error happen while SPL trying to load uboot as SSBL from MMC into DDR memory.At this point, the caches are disabled.

I-Cache is enabled in SPL, D-cache _might_ be too.

Do you get this error after cold boot too ?

Signature · 2 lines
Best regards,
Marek Vasut
#6 lore raw

PATCH 1/1 mmc: dwmmc: Enable small delay before returning error

Quoted 60 lines · Marek Vasut
Quoted 59 lines · Chee Hong
Quoted 22 lines · Marek Vasut
Quoted 12 lines · Chee Hong
Quoted 9 lines · Marek Vasut
Quoted 6 lines · chee.hong.ang at intel.com

From: "Ang, Chee Hong" <[email protected]>

'SET_BLOCKLEN' may occasionally fail on first attempt.

Quoted 8 lines
Quoted 1 line

Why ?

This is part of the workaround of mmc driver which is enabled with
'CONFIG_MMC_QUIRKS' config.
https://github.com/u-boot/u-boot/blob/dbe70c7d4e3d5c705a98d8295
2e05
a591
efd0683/drivers/mmc/mmc.c#L272

Quoted 3 lines

OK, let's take a step back. What problem do you observe, that you're
trying to fix ?

See my detail explanation below.

Quoted 31 lines
Quoted 31 lines
Quoted 8 lines
Quoted 8 lines
Quoted 4 lines
Quoted 3 lines

This patch enable a small delay in dwmci_send_cmd() on busy, I/O or CRC error to allow the MMC controller recovers from the failure/error on subsequent retries.

Why 100 uS ?

This is a good question. Perhaps the driver's authors can explain
this.
The driver delay 100us after dwmci_send_cmd() success with the command
sent. But it never delay 100us whenever mmc controller response to
the
command sent with I/O or CRC errors. MMC drivers expect the first
'SET_BLOCKEN' command issued by dwmci_send_cmd() may fail intermittently so it will retry up to 4 times before it gave up and
return error. Without this 100us delay after error response, 'SET_BLOCKEN' may sometime fail in 4 attempts in a row. Therefore,
we
encountered intermittent failure in loading u-boot (SSBL) from MMC.

Quoted 7 lines
Quoted 6 lines
Quoted 1 line

Can you be more specific about the failure you saw ?

Here are the steps for booting u-boot (SSBL) from MMC:

1) SPL (FSBL) get loaded to OCRAM
2) SPL try to load uboot as SSBL from MMC
3) SPL issue 'SET_BLOCKEN' to MMC controller

s/SPL/MMC framework via DWMMC driver/

Yes. It is done in drivers/mmc/mmc.c (Line 276)

Quoted 18 lines
Quoted 13 lines

4) If MMC controller response with error continue to step 5 else go to
step 7
5) If is less than 4 attempts go to step 3 else continue to step 6
6) Indicate to user there was an error loading uboot as SSBL from MMC
and stop here
7) Send command to read blocks of data from MMC
8) uboot successfully loaded to DDR memory
9) SPL jumps to uboot and continue the boot flow.

Quoted 5 lines

So this patch actually introduce a small delay at step 4. Without this
small delay, step 4 might sometime fail in all 4 attempts to issue the
'SET_BLOCKEN' command to MMC controller.

Quoted 6 lines

Isn't what you observe here some sort of timeout which you need to respect when the card rejects a command ? If so, such timeout should be
described in either of the SD or MMC specification and it should be in
the MMC framework core instead of a driver.

I don't have chance to test other MMC drivers and I am not sure other MMC drivers need such small delay for next retry if the card reject this command. This DW MMC driver already enforce a small delay even the command is success, so this makes me think that this 'time out' issue is only specific to this DW MMC driver.
Is it necessary to 'enforce' this small delay in common MMC framework (affecting all other MMC drivers as well) as shown below:

drivers/mmc/mmc.c

#ifdef CONFIG_MMC_QUIRKS
	if (err && (mmc->quirks & MMC_QUIRK_RETRY_SET_BLOCKLEN)) {
		int retries = 4;
		/*
		 * It has been seen that SET_BLOCKLEN may fail on the
first
		 * attempt, let's try a few more time
		 */
		do {
			err = mmc_send_cmd(mmc, &cmd, NULL);
			if (!err)
				break;
+			/* Enforce small delay before retry */
+			udelay(100);
		} while (retries--);
	}

#endif

Quoted 31 lines
Quoted 31 lines

Note that this failure is
intermittent. If it fails at step 3 and there is no small delay in step
4, it will most likely fail in subsequent attempts.

Quoted 18 lines
Quoted 10 lines
Quoted 10 lines

Can we rather detect whether the controller recovered by polling
some
bit?

Quoted 8 lines

Hmmm...I can take a look at the databook of this controller and dig
further. Probably this is the limitation of the controller itself.
The
mmc driver code which introduce 100us delay after every command sent in
dwmci_send_cmd() looks iffy.

Quoted 1 line

If you have access to it, please do.

Unfortunately, I can't find any registers I can poll for the status of
the readiness of the controller from DesignWare storage controller databook.

Quoted 2 lines
Quoted 7 lines
Quoted 4 lines
Quoted 1 line

btw do you have the same problem if you disable caches ?

The error happen while SPL trying to load uboot as SSBL from MMC into
DDR memory.At this point, the caches are disabled.

I-Cache is enabled in SPL, D-cache _might_ be too.

Do you get this error after cold boot too ?

Yes. It happened after cold boot too.

Quoted 1 line
#7 lore raw

PATCH 1/1 mmc: dwmmc: Enable small delay before returning error

Quoted 93 lines · Chee Hong
Quoted 60 lines · Marek Vasut
Quoted 59 lines · Chee Hong
Quoted 22 lines · Marek Vasut
Quoted 12 lines · Chee Hong
Quoted 9 lines · Marek Vasut
Quoted 6 lines · chee.hong.ang at intel.com

From: "Ang, Chee Hong" <[email protected]>

'SET_BLOCKLEN' may occasionally fail on first attempt.

Quoted 8 lines
Quoted 1 line

Why ?

This is part of the workaround of mmc driver which is enabled with
'CONFIG_MMC_QUIRKS' config.
https://github.com/u-boot/u-boot/blob/dbe70c7d4e3d5c705a98d8295
2e05
a591
efd0683/drivers/mmc/mmc.c#L272

Quoted 3 lines

OK, let's take a step back. What problem do you observe, that you're
trying to fix ?

See my detail explanation below.

Quoted 31 lines
Quoted 31 lines
Quoted 8 lines
Quoted 8 lines
Quoted 4 lines
Quoted 3 lines

This patch enable a small delay in dwmci_send_cmd() on busy, I/O or CRC error to allow the MMC controller recovers from the failure/error on subsequent retries.

Why 100 uS ?

This is a good question. Perhaps the driver's authors can explain
this.
The driver delay 100us after dwmci_send_cmd() success with the command
sent. But it never delay 100us whenever mmc controller response to
the
command sent with I/O or CRC errors. MMC drivers expect the first
'SET_BLOCKEN' command issued by dwmci_send_cmd() may fail intermittently so it will retry up to 4 times before it gave up and
return error. Without this 100us delay after error response, 'SET_BLOCKEN' may sometime fail in 4 attempts in a row. Therefore,
we
encountered intermittent failure in loading u-boot (SSBL) from MMC.

Quoted 7 lines
Quoted 6 lines
Quoted 1 line

Can you be more specific about the failure you saw ?

Here are the steps for booting u-boot (SSBL) from MMC:

1) SPL (FSBL) get loaded to OCRAM
2) SPL try to load uboot as SSBL from MMC
3) SPL issue 'SET_BLOCKEN' to MMC controller

s/SPL/MMC framework via DWMMC driver/

Yes. It is done in drivers/mmc/mmc.c (Line 276)

Quoted 18 lines
Quoted 13 lines

4) If MMC controller response with error continue to step 5 else go to
step 7
5) If is less than 4 attempts go to step 3 else continue to step 6
6) Indicate to user there was an error loading uboot as SSBL from MMC
and stop here
7) Send command to read blocks of data from MMC
8) uboot successfully loaded to DDR memory
9) SPL jumps to uboot and continue the boot flow.

Quoted 5 lines

So this patch actually introduce a small delay at step 4. Without this
small delay, step 4 might sometime fail in all 4 attempts to issue the
'SET_BLOCKEN' command to MMC controller.

Quoted 6 lines

Isn't what you observe here some sort of timeout which you need to respect when the card rejects a command ? If so, such timeout should be
described in either of the SD or MMC specification and it should be in
the MMC framework core instead of a driver.

Quoted 3 lines

I don't have chance to test other MMC drivers and I am not sure other MMC drivers need such small delay for next retry if the card reject this command.

Does the SD or MMC JEDEC spec say something about such delay?

Quoted 3 lines

This DW MMC driver already enforce a small delay even the command is success, so this makes me think that this 'time out' issue is only specific to this DW MMC driver.

So why is there that 100 uS delay ? Does the Linux DWMMC driver have such a delay too?

Quoted 21 lines

Is it necessary to 'enforce' this small delay in common MMC framework (affecting all other MMC drivers as well) as shown below:

drivers/mmc/mmc.c

#ifdef CONFIG_MMC_QUIRKS
	if (err && (mmc->quirks & MMC_QUIRK_RETRY_SET_BLOCKLEN)) {
		int retries = 4;
		/*
		 * It has been seen that SET_BLOCKLEN may fail on the
first
		 * attempt, let's try a few more time
		 */
		do {
			err = mmc_send_cmd(mmc, &cmd, NULL);
			if (!err)
				break;
(quoted diff) +2 -0
+			/* Enforce small delay before retry */
+			udelay(100);
		} while (retries--);
	}
Quoted 1 line

#endif

Expanding the CC to other DWMMC users, maybe their datasheets contain something about the 100 uS delay.

Quoted 29 lines
Quoted 29 lines
Quoted 29 lines

Note that this failure is
intermittent. If it fails at step 3 and there is no small delay in step
4, it will most likely fail in subsequent attempts.

Quoted 18 lines
Quoted 10 lines
Quoted 10 lines

Can we rather detect whether the controller recovered by polling
some
bit?

Quoted 8 lines

Hmmm...I can take a look at the databook of this controller and dig
further. Probably this is the limitation of the controller itself.
The
mmc driver code which introduce 100us delay after every command sent in
dwmci_send_cmd() looks iffy.

Quoted 1 line

If you have access to it, please do.

Unfortunately, I can't find any registers I can poll for the status of
the readiness of the controller from DesignWare storage controller databook.

Quoted 2 lines
Quoted 8 lines
Quoted 7 lines
Quoted 4 lines
Quoted 1 line

btw do you have the same problem if you disable caches ?

The error happen while SPL trying to load uboot as SSBL from MMC into
DDR memory.At this point, the caches are disabled.

I-Cache is enabled in SPL, D-cache _might_ be too.

Do you get this error after cold boot too ?

Yes. It happened after cold boot too.

Hmmmm, try applying

[PATCH V2] ARM: socfpga: Clear PL310 early in SPL

I wonder if this might be what you're hitting.

Signature · 2 lines
Best regards,
Marek Vasut
#8 lore raw

PATCH 1/1 mmc: dwmmc: Enable small delay before returning error

Quoted 123 lines · Marek Vasut
Quoted 122 lines · Chee Hong
Quoted 78 lines · Marek Vasut
Quoted 76 lines · Chee Hong
Quoted 28 lines · Marek Vasut
Quoted 16 lines · Chee Hong
Quoted 8 lines · Marek Vasut
Quoted 4 lines · chee.hong.ang at intel.com
Quoted 4 lines
Quoted 3 lines

From: "Ang, Chee Hong" <[email protected]>

'SET_BLOCKLEN' may occasionally fail on first attempt.

Why ?

Quoted 9 lines

This is part of the workaround of mmc driver which is enabled
with
'CONFIG_MMC_QUIRKS' config.
https://github.com/u-boot/u-boot/blob/dbe70c7d4e3d5c705a98d
8295
2e05
a591
efd0683/drivers/mmc/mmc.c#L272

Quoted 3 lines

OK, let's take a step back. What problem do you observe, that you're
trying to fix ?

See my detail explanation below.

Quoted 41 lines
Quoted 41 lines
Quoted 12 lines
Quoted 12 lines
Quoted 5 lines
Quoted 4 lines

This patch enable a small delay in dwmci_send_cmd() on busy, I/O or CRC error to allow the MMC controller recovers
from the failure/error on subsequent retries.

Why 100 uS ?

This is a good question. Perhaps the driver's authors can explain
this.
The driver delay 100us after dwmci_send_cmd() success with the
command
sent. But it never delay 100us whenever mmc controller response
to
the
command sent with I/O or CRC errors. MMC drivers expect the first
'SET_BLOCKEN' command issued by dwmci_send_cmd() may fail intermittently so it will retry up to 4 times before it gave up
and
return error. Without this 100us delay after error response,
'SET_BLOCKEN' may sometime fail in 4 attempts in a row. Therefore,
we
encountered intermittent failure in loading u-boot (SSBL) from
MMC.

Quoted 7 lines
Quoted 6 lines
Quoted 1 line

Can you be more specific about the failure you saw ?

Here are the steps for booting u-boot (SSBL) from MMC:

1) SPL (FSBL) get loaded to OCRAM
2) SPL try to load uboot as SSBL from MMC
3) SPL issue 'SET_BLOCKEN' to MMC controller

s/SPL/MMC framework via DWMMC driver/

Yes. It is done in drivers/mmc/mmc.c (Line 276)

Quoted 34 lines
Quoted 18 lines

4) If MMC controller response with error continue to step 5 else go
to
step 7
5) If is less than 4 attempts go to step 3 else continue to step 6
6) Indicate to user there was an error loading uboot as SSBL from
MMC
and stop here
7) Send command to read blocks of data from MMC
8) uboot successfully loaded to DDR memory
9) SPL jumps to uboot and continue the boot flow.

Quoted 7 lines

So this patch actually introduce a small delay at step 4. Without
this
small delay, step 4 might sometime fail in all 4 attempts to issue
the
'SET_BLOCKEN' command to MMC controller.

Isn't what you observe here some sort of timeout which you need to
respect when the card rejects a command ? If so, such timeout should
be
described in either of the SD or MMC specification and it should be
in
the MMC framework core instead of a driver.

Quoted 5 lines
Quoted 4 lines

I don't have chance to test other MMC drivers and I am not sure other
MMC drivers need such small delay for next retry if the card reject this command.

Does the SD or MMC JEDEC spec say something about such delay?

I checked the SD/MMC JEDEC. Nothing about this delay is mentioned in the spec.

Quoted 8 lines
Quoted 6 lines

This DW MMC driver already enforce a small delay even the command is success, so this makes me think that this 'time out' issue
is only specific to this DW MMC driver.

So why is there that 100 uS delay ? Does the Linux DWMMC driver have such a delay too?

Linux DWMMC has only the delay for card detection and I think is quite common because this is needed to make sure the memory card is properly inserted before any operations can be started.

Quoted 77 lines
Quoted 24 lines

Is it necessary to 'enforce' this small delay in common MMC framework
(affecting all other MMC drivers as well) as shown below:

drivers/mmc/mmc.c

#ifdef CONFIG_MMC_QUIRKS
	if (err && (mmc->quirks & MMC_QUIRK_RETRY_SET_BLOCKLEN)) {
		int retries = 4;
		/*
		 * It has been seen that SET_BLOCKLEN may fail on the
first
		 * attempt, let's try a few more time
		 */
		do {
			err = mmc_send_cmd(mmc, &cmd, NULL);
			if (!err)
				break;
(quoted diff) +2 -0
+			/* Enforce small delay before retry */
+			udelay(100);
		} while (retries--);
	}
Quoted 1 line

#endif

Expanding the CC to other DWMMC users, maybe their datasheets contain something about the 100 uS delay.

Quoted 48 lines
Quoted 48 lines
Quoted 41 lines

Note that this failure is
intermittent. If it fails at step 3 and there is no small delay in
step
4, it will most likely fail in subsequent attempts.

Quoted 23 lines
Quoted 13 lines
Quoted 9 lines
Quoted 4 lines

Can we rather detect whether the controller recovered by polling
some
bit?

Quoted 10 lines

Hmmm...I can take a look at the databook of this controller and
dig
further. Probably this is the limitation of the controller itself.
The
mmc driver code which introduce 100us delay after every command
sent in
dwmci_send_cmd() looks iffy.

Quoted 1 line

If you have access to it, please do.

Unfortunately, I can't find any registers I can poll for the status
of
the readiness of the controller from DesignWare storage controller
databook.

Quoted 3 lines
Quoted 5 lines
Quoted 1 line

btw do you have the same problem if you disable caches ?

The error happen while SPL trying to load uboot as SSBL from MMC
into
DDR memory.At this point, the caches are disabled.

I-Cache is enabled in SPL, D-cache _might_ be too.

Quoted 7 lines
Quoted 2 lines
Quoted 1 line

Do you get this error after cold boot too ?

Yes. It happened after cold boot too.

Hmmmm, try applying

[PATCH V2] ARM: socfpga: Clear PL310 early in SPL

I wonder if this might be what you're hitting.

Nope. This patch only apply to Aaria 10 and this problem is found on Stratix 10 platform.

Quoted 1 line
#9 lore raw

PATCH 1/1 mmc: dwmmc: Enable small delay before returning error

On 3/5/19 8:10 AM, Ang, Chee Hong wrote:
[...]

Quoted 30 lines
Quoted 30 lines
Quoted 30 lines
Quoted 30 lines
Quoted 14 lines

4) If MMC controller response with error continue to step 5 else go
to
step 7
5) If is less than 4 attempts go to step 3 else continue to step 6
6) Indicate to user there was an error loading uboot as SSBL from
MMC
and stop here
7) Send command to read blocks of data from MMC
8) uboot successfully loaded to DDR memory
9) SPL jumps to uboot and continue the boot flow.

Quoted 7 lines

So this patch actually introduce a small delay at step 4. Without
this
small delay, step 4 might sometime fail in all 4 attempts to issue
the
'SET_BLOCKEN' command to MMC controller.

Isn't what you observe here some sort of timeout which you need to
respect when the card rejects a command ? If so, such timeout should
be
described in either of the SD or MMC specification and it should be
in
the MMC framework core instead of a driver.

Quoted 7 lines
Quoted 5 lines
Quoted 4 lines

I don't have chance to test other MMC drivers and I am not sure other
MMC drivers need such small delay for next retry if the card reject this command.

Does the SD or MMC JEDEC spec say something about such delay?

I checked the SD/MMC JEDEC. Nothing about this delay is mentioned in the spec.

OK, neither of the specs say anything, hmmmm

Quoted 9 lines
Quoted 6 lines
Quoted 4 lines

This DW MMC driver already enforce a small delay even the command is success, so this makes me think that this 'time out' issue
is only specific to this DW MMC driver.

So why is there that 100 uS delay ? Does the Linux DWMMC driver have such a delay too?

Linux DWMMC has only the delay for card detection and I think is quite common because this is needed to make sure the memory card is properly inserted before any operations can be started.

So why doesn't Linux need this special 100 uS delay , but U-Boot does ?

Quoted 76 lines
Quoted 76 lines
Quoted 22 lines

Is it necessary to 'enforce' this small delay in common MMC framework
(affecting all other MMC drivers as well) as shown below:

drivers/mmc/mmc.c

#ifdef CONFIG_MMC_QUIRKS
	if (err && (mmc->quirks & MMC_QUIRK_RETRY_SET_BLOCKLEN)) {
		int retries = 4;
		/*
		 * It has been seen that SET_BLOCKLEN may fail on the
first
		 * attempt, let's try a few more time
		 */
		do {
			err = mmc_send_cmd(mmc, &cmd, NULL);
			if (!err)
				break;
(quoted diff) +2 -0
+			/* Enforce small delay before retry */
+			udelay(100);
		} while (retries--);
	}
Quoted 1 line

#endif

Expanding the CC to other DWMMC users, maybe their datasheets contain something about the 100 uS delay.

Quoted 49 lines
Quoted 49 lines
Quoted 41 lines

Note that this failure is
intermittent. If it fails at step 3 and there is no small delay in
step
4, it will most likely fail in subsequent attempts.

Quoted 23 lines
Quoted 13 lines
Quoted 9 lines
Quoted 4 lines

Can we rather detect whether the controller recovered by polling
some
bit?

Quoted 10 lines

Hmmm...I can take a look at the databook of this controller and
dig
further. Probably this is the limitation of the controller itself.
The
mmc driver code which introduce 100us delay after every command
sent in
dwmci_send_cmd() looks iffy.

Quoted 1 line

If you have access to it, please do.

Unfortunately, I can't find any registers I can poll for the status
of
the readiness of the controller from DesignWare storage controller
databook.

Quoted 3 lines
Quoted 5 lines
Quoted 1 line

btw do you have the same problem if you disable caches ?

The error happen while SPL trying to load uboot as SSBL from MMC
into
DDR memory.At this point, the caches are disabled.

I-Cache is enabled in SPL, D-cache _might_ be too.

Do you get this error after cold boot too ?

Quoted 8 lines
Quoted 6 lines
Quoted 1 line

Yes. It happened after cold boot too.

Hmmmm, try applying

[PATCH V2] ARM: socfpga: Clear PL310 early in SPL

I wonder if this might be what you're hitting.

Nope. This patch only apply to Aaria 10 and this problem is found on Stratix 10 platform.

The patch I referenced applies to Gen5, but OK.

Signature · 2 lines
Best regards,
Marek Vasut