U-Boot Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] mmc: msm_sdhci: drop SDHCI_QUIRK_WAIT_SEND_CMD
@ 2026-10-30 13:57 Igor Opaniuk
  2026-10-31 15:03 ` Aswin Murugan
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Igor Opaniuk @ 2026-10-30 13:57 UTC (permalink / raw)
  To: Sumit Garg, Tanmay Kathpalia, u-boot-qcom, u-boot
  Cc: Casey Connolly, Neil Armstrong, Peng Fan, Jaehoon Chung, Tom Rini,
	Varadarajan Narayanan, Aswin Murugan, Balaji Selvanathan,
	Igor Opaniuk

SDHCI_QUIRK_WAIT_SEND_CMD makes sdhci_send_command() sleep for 1 ms
after every command. msm_sdhci has set it since the driver was added
for APQ8016, back when it only did PIO; the commit gives no reason for
it, and the Linux sdhci-msm driver has no such delay.

The delay is invisible for large reads but dominates small ones. A
multi-block read is CMD18 followed by CMD12, so every read pays 2 ms
on top of the transfer. With the eMMC in HS400 a 128 KiB read takes
about 0.4 ms, so USB mass storage, which reads in 128 KiB (FSG_BUFLEN)
chunks, spent most of its time in udelay(). On the Arduino UNO Q,
reading 1 GiB from "ums 0 mmc 0" on a USB 3 host
(dd if=/dev/sdX of=/dev/null bs=4M count=256):

                     host throughput   time in eMMC reads (10.6k reads)
  with the quirk     46 MB/s           26.8 s (~2.5 ms per read)
  without            201 MB/s           4.5 s (~0.4 ms per read)

A single 128 MiB "mmc read" runs at 255.6 MiB/s either way.

Drop the quirk and keep SDHCI_QUIRK_BROKEN_R1B.

Tested on the Arduino UNO Q (QRB2210, qcom,sdhci-msm-v5, ADMA):
- on main (eMMC in DDR52): 128 MiB "mmc read" at 75 MiB/s as before,
  the CRC32 of the first 128 MiB read in U-Boot matches the one Linux
  computes from the same blocks, and Linux boots from the eMMC;
- with the "qcom: Enable HS200/HS400 eMMC modes" series and the
  mass_storage SuperSpeed descriptor patch applied (eMMC in HS400):
  the ums numbers above, same CRC32 check and Linux boot.
Not tested on v4 controllers or on the boards that use the driver in
PIO mode (qcom_dragonboard410c, qcom_dragonboard820c, hmibsc).

Signed-off-by: Igor Opaniuk <igor.opaniuk@oss.qualcomm.com>
---
Drop the 1 ms delay msm_sdhci adds after every SD command. It costs
2 ms per multi-block read, which capped ums on an Arduino UNO Q at
46 MB/s; without it the same read runs at 201 MB/s.

Testing on APQ8016/APQ8096 (PIO mode) would be welcome.
---
 drivers/mmc/msm_sdhci.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/mmc/msm_sdhci.c b/drivers/mmc/msm_sdhci.c
index 9cc11a5e269..ab217393a54 100644
--- a/drivers/mmc/msm_sdhci.c
+++ b/drivers/mmc/msm_sdhci.c
@@ -198,7 +198,7 @@ static int msm_sdc_probe(struct udevice *dev)
 		udelay(200);
 	}
 
-	host->quirks = SDHCI_QUIRK_WAIT_SEND_CMD | SDHCI_QUIRK_BROKEN_R1B;
+	host->quirks = SDHCI_QUIRK_BROKEN_R1B;
 
 	host->max_clk = 0;
 

---
base-commit: 3973f3c4d24df75ca90d7c0a9f03e5e5c9b48f32
change-id: 20261030-msm-sdhci-wait-send-cmd-4383f2792022

Best regards,
-- 
Igor Opaniuk <igor.opaniuk@oss.qualcomm.com>


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

* Re: [PATCH] mmc: msm_sdhci: drop SDHCI_QUIRK_WAIT_SEND_CMD
  2026-10-30 13:57 [PATCH] mmc: msm_sdhci: drop SDHCI_QUIRK_WAIT_SEND_CMD Igor Opaniuk
@ 2026-10-31 15:03 ` Aswin Murugan
  2026-11-01  9:17 ` Kathpalia, Tanmay
  2026-11-20 20:08 ` Stephan Gerhold
  2 siblings, 0 replies; 6+ messages in thread
From: Aswin Murugan @ 2026-10-31 15:03 UTC (permalink / raw)
  To: Igor Opaniuk, Sumit Garg, Tanmay Kathpalia, u-boot-qcom, u-boot
  Cc: Casey Connolly, Neil Armstrong, Peng Fan, Jaehoon Chung, Tom Rini,
	Varadarajan Narayanan, Balaji Selvanathan


On 10/30/2026 7:27 PM, Igor Opaniuk wrote:
> SDHCI_QUIRK_WAIT_SEND_CMD makes sdhci_send_command() sleep for 1 ms
> after every command. msm_sdhci has set it since the driver was added
> for APQ8016, back when it only did PIO; the commit gives no reason for
> it, and the Linux sdhci-msm driver has no such delay.
>
> The delay is invisible for large reads but dominates small ones. A
> multi-block read is CMD18 followed by CMD12, so every read pays 2 ms
> on top of the transfer. With the eMMC in HS400 a 128 KiB read takes
> about 0.4 ms, so USB mass storage, which reads in 128 KiB (FSG_BUFLEN)
> chunks, spent most of its time in udelay(). On the Arduino UNO Q,
> reading 1 GiB from "ums 0 mmc 0" on a USB 3 host
> (dd if=/dev/sdX of=/dev/null bs=4M count=256):
>
>                       host throughput   time in eMMC reads (10.6k reads)
>    with the quirk     46 MB/s           26.8 s (~2.5 ms per read)
>    without            201 MB/s           4.5 s (~0.4 ms per read)
>
> A single 128 MiB "mmc read" runs at 255.6 MiB/s either way.
>
> Drop the quirk and keep SDHCI_QUIRK_BROKEN_R1B.
>
> Tested on the Arduino UNO Q (QRB2210, qcom,sdhci-msm-v5, ADMA):
> - on main (eMMC in DDR52): 128 MiB "mmc read" at 75 MiB/s as before,
>    the CRC32 of the first 128 MiB read in U-Boot matches the one Linux
>    computes from the same blocks, and Linux boots from the eMMC;
> - with the "qcom: Enable HS200/HS400 eMMC modes" series and the
>    mass_storage SuperSpeed descriptor patch applied (eMMC in HS400):
>    the ums numbers above, same CRC32 check and Linux boot.
> Not tested on v4 controllers or on the boards that use the driver in
> PIO mode (qcom_dragonboard410c, qcom_dragonboard820c, hmibsc).
>
> Signed-off-by: Igor Opaniuk <igor.opaniuk@oss.qualcomm.com>
> ---
> Drop the 1 ms delay msm_sdhci adds after every SD command. It costs
> 2 ms per multi-block read, which capped ums on an Arduino UNO Q at
> 46 MB/s; without it the same read runs at 201 MB/s.
>
> Testing on APQ8016/APQ8096 (PIO mode) would be welcome.
> ---
>   drivers/mmc/msm_sdhci.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/mmc/msm_sdhci.c b/drivers/mmc/msm_sdhci.c
> index 9cc11a5e269..ab217393a54 100644
> --- a/drivers/mmc/msm_sdhci.c
> +++ b/drivers/mmc/msm_sdhci.c
> @@ -198,7 +198,7 @@ static int msm_sdc_probe(struct udevice *dev)
>   		udelay(200);
>   	}
>   
> -	host->quirks = SDHCI_QUIRK_WAIT_SEND_CMD | SDHCI_QUIRK_BROKEN_R1B;
> +	host->quirks = SDHCI_QUIRK_BROKEN_R1B;
>   
>   	host->max_clk = 0;
>   
>
> ---
> base-commit: 3973f3c4d24df75ca90d7c0a9f03e5e5c9b48f32
> change-id: 20261030-msm-sdhci-wait-send-cmd-4383f2792022
>
> Best regards,

Reviewed-by: Aswin Murugan <aswin.murugan@oss.qualcomm.com>


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

* Re: [PATCH] mmc: msm_sdhci: drop SDHCI_QUIRK_WAIT_SEND_CMD
  2026-10-30 13:57 [PATCH] mmc: msm_sdhci: drop SDHCI_QUIRK_WAIT_SEND_CMD Igor Opaniuk
  2026-10-31 15:03 ` Aswin Murugan
@ 2026-11-01  9:17 ` Kathpalia, Tanmay
  2026-11-20 20:08 ` Stephan Gerhold
  2 siblings, 0 replies; 6+ messages in thread
From: Kathpalia, Tanmay @ 2026-11-01  9:17 UTC (permalink / raw)
  To: Igor Opaniuk, Sumit Garg, u-boot-qcom, u-boot
  Cc: Casey Connolly, Neil Armstrong, Peng Fan, Jaehoon Chung, Tom Rini,
	Varadarajan Narayanan, Aswin Murugan, Balaji Selvanathan


On 30-10-2026 19:27, Igor Opaniuk wrote:
> SDHCI_QUIRK_WAIT_SEND_CMD makes sdhci_send_command() sleep for 1 ms
> after every command.

Nit: "after every command" is slightly broad - with
SDHCI_QUIRK_BROKEN_R1B also set (as msm_sdhci does), busy-response
commands without data already return early in sdhci_send_command()
before reaching this udelay(), so they never paid it. Might be worth
rephrasing to "after most commands" or similar.

Not a blocker, a commit-message polish.

> msm_sdhci has set it since the driver was added
> for APQ8016, back when it only did PIO; the commit gives no reason for
> it, and the Linux sdhci-msm driver has no such delay.
>
> The delay is invisible for large reads but dominates small ones. A
> multi-block read is CMD18 followed by CMD12, so every read pays 2 ms
> on top of the transfer. With the eMMC in HS400 a 128 KiB read takes
> about 0.4 ms, so USB mass storage, which reads in 128 KiB (FSG_BUFLEN)
> chunks, spent most of its time in udelay(). On the Arduino UNO Q,
> reading 1 GiB from "ums 0 mmc 0" on a USB 3 host
> (dd if=/dev/sdX of=/dev/null bs=4M count=256):
>
>                       host throughput   time in eMMC reads (10.6k reads)
>    with the quirk     46 MB/s           26.8 s (~2.5 ms per read)
>    without            201 MB/s           4.5 s (~0.4 ms per read)
>
> A single 128 MiB "mmc read" runs at 255.6 MiB/s either way.
>
> Drop the quirk and keep SDHCI_QUIRK_BROKEN_R1B.
>
> Tested on the Arduino UNO Q (QRB2210, qcom,sdhci-msm-v5, ADMA):
> - on main (eMMC in DDR52): 128 MiB "mmc read" at 75 MiB/s as before,
>    the CRC32 of the first 128 MiB read in U-Boot matches the one Linux
>    computes from the same blocks, and Linux boots from the eMMC;
> - with the "qcom: Enable HS200/HS400 eMMC modes" series and the
>    mass_storage SuperSpeed descriptor patch applied (eMMC in HS400):
>    the ums numbers above, same CRC32 check and Linux boot.
> Not tested on v4 controllers or on the boards that use the driver in
> PIO mode (qcom_dragonboard410c, qcom_dragonboard820c, hmibsc).
>
> Signed-off-by: Igor Opaniuk <igor.opaniuk@oss.qualcomm.com>

Reviewed-by: Tanmay Kathpalia <tanmay.kathpalia@altera.com>


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

* Re: [PATCH] mmc: msm_sdhci: drop SDHCI_QUIRK_WAIT_SEND_CMD
  2026-10-30 13:57 [PATCH] mmc: msm_sdhci: drop SDHCI_QUIRK_WAIT_SEND_CMD Igor Opaniuk
  2026-10-31 15:03 ` Aswin Murugan
  2026-11-01  9:17 ` Kathpalia, Tanmay
@ 2026-11-20 20:08 ` Stephan Gerhold
  2026-11-23  8:47   ` Igor Opaniuk
  2 siblings, 1 reply; 6+ messages in thread
From: Stephan Gerhold @ 2026-11-20 20:08 UTC (permalink / raw)
  To: Igor Opaniuk
  Cc: Sumit Garg, Tanmay Kathpalia, u-boot-qcom, u-boot, Casey Connolly,
	Neil Armstrong, Peng Fan, Jaehoon Chung, Tom Rini,
	Varadarajan Narayanan, Aswin Murugan, Balaji Selvanathan

On Fri, Oct 30, 2026 at 02:57:00PM +0100, Igor Opaniuk wrote:
> SDHCI_QUIRK_WAIT_SEND_CMD makes sdhci_send_command() sleep for 1 ms
> after every command. msm_sdhci has set it since the driver was added
> for APQ8016, back when it only did PIO; the commit gives no reason for
> it, and the Linux sdhci-msm driver has no such delay.
> 
> The delay is invisible for large reads but dominates small ones. A
> multi-block read is CMD18 followed by CMD12, so every read pays 2 ms
> on top of the transfer. With the eMMC in HS400 a 128 KiB read takes
> about 0.4 ms, so USB mass storage, which reads in 128 KiB (FSG_BUFLEN)
> chunks, spent most of its time in udelay(). On the Arduino UNO Q,
> reading 1 GiB from "ums 0 mmc 0" on a USB 3 host
> (dd if=/dev/sdX of=/dev/null bs=4M count=256):
> 
>                      host throughput   time in eMMC reads (10.6k reads)
>   with the quirk     46 MB/s           26.8 s (~2.5 ms per read)
>   without            201 MB/s           4.5 s (~0.4 ms per read)
> 
> A single 128 MiB "mmc read" runs at 255.6 MiB/s either way.
> 
> Drop the quirk and keep SDHCI_QUIRK_BROKEN_R1B.
> 
> Tested on the Arduino UNO Q (QRB2210, qcom,sdhci-msm-v5, ADMA):
> - on main (eMMC in DDR52): 128 MiB "mmc read" at 75 MiB/s as before,
>   the CRC32 of the first 128 MiB read in U-Boot matches the one Linux
>   computes from the same blocks, and Linux boots from the eMMC;
> - with the "qcom: Enable HS200/HS400 eMMC modes" series and the
>   mass_storage SuperSpeed descriptor patch applied (eMMC in HS400):
>   the ums numbers above, same CRC32 check and Linux boot.
> Not tested on v4 controllers or on the boards that use the driver in
> PIO mode (qcom_dragonboard410c, qcom_dragonboard820c, hmibsc).
> 
> Signed-off-by: Igor Opaniuk <igor.opaniuk@oss.qualcomm.com>
> ---
> Drop the 1 ms delay msm_sdhci adds after every SD command. It costs
> 2 ms per multi-block read, which capped ums on an Arduino UNO Q at
> 46 MB/s; without it the same read runs at 201 MB/s.
> 
> Testing on APQ8016/APQ8096 (PIO mode) would be welcome.

Please Cc the board maintainers (me, for DB410c/APQ8016) if you are
looking for feedback for these boards. I found this patch on the mailing
list only by coincidence.

The fact that APQ8016/APQ8096 use PIO instead of ADMA is a relic from
before ADMA support was introduced. ADMA works just fine in my tests on
these boards and makes no difference for the following test results.

This patch works for the eMMC, but it seems to break SD card detection
on all QC boards I tested.

DB410c (APQ8016):
 - eMMC: works
 - SD: broken, CMD55 response CRC error

DB820c (APQ8096):
 - eMMC: N/A
 - SD: broken, CMD55 response CRC error

RB3Gen2 (QCS6490):
 - eMMC: N/A
 - SD: broken, CMD55 response CRC error

The symptom is that the SD card is simply silently not detected at all,
I added some more logging to find the CMD55 response CRC error. AFAICT
(without investigating in detail), the following happens:

 1. In drivers/mmc/mmc.c sd_send_op_cond() U-Boot sends MMC_CMD_APP_CMD
    (CMD55), followed by SD_CMD_APP_SEND_OP_COND (ACMD41).
 2. The first CMD55 and ACMD41 succeed, cmd.response[0] is 0x00ff8000
    so BIT(31) (OCR_BUSY) isn't set yet so it polls again with the same
    commands after 1ms.
 3. The second CMD55 fails immediately (too early to come from the SD
    card with a CRC error).

The CRC error seems to origin from the previous ACMD41. With
SDHCI_QUIRK_WAIT_SEND_CMD we wait long enough after sending the previous
command to clear the CRC error before the next command sees it.

There different options to fix this:
 - A retry of CMD55 in case of an error seems to work.
 - Maybe we could check and clear unhandled errors in
   sdhci_send_command() before sending another command.

This extra diff that implements a retry works for example:

--- a/drivers/mmc/mmc.c
+++ b/drivers/mmc/mmc.c
@@ -674,7 +674,8 @@
 		cmd.resp_type = MMC_RSP_R1;
 		cmd.cmdarg = 0;
 
-		err = mmc_send_cmd(mmc, &cmd, NULL);
+		err = mmc_send_cmd_quirks(mmc, &cmd, NULL,
+					  MMC_QUIRK_RETRY_APP_CMD, 3);
 
 		if (err)
 			return err;

The real question though is why we are reliably getting this CRC error.
It might be worth to investigate that further. I would expect you can
reproduce this on any QC board with a SD card if you want to test this
further.

SDHCI_QUIRK_BROKEN_R1B on the other hand made no difference in my
testing, I think we could drop that one (Linux does not seem to do this
either).

Thanks,
Stephan

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

* Re: [PATCH] mmc: msm_sdhci: drop SDHCI_QUIRK_WAIT_SEND_CMD
  2026-11-20 20:08 ` Stephan Gerhold
@ 2026-11-23  8:47   ` Igor Opaniuk
  2026-11-23 13:31     ` Stephan Gerhold
  0 siblings, 1 reply; 6+ messages in thread
From: Igor Opaniuk @ 2026-11-23  8:47 UTC (permalink / raw)
  To: Stephan Gerhold
  Cc: Sumit Garg, Tanmay Kathpalia, u-boot-qcom, u-boot, Casey Connolly,
	Neil Armstrong, Peng Fan, Jaehoon Chung, Tom Rini,
	Varadarajan Narayanan, Aswin Murugan, Balaji Selvanathan

Hi Stephan,

On Fri, Nov 20, 2026 at 9:08 PM Stephan Gerhold
<stephan.gerhold@linaro.org> wrote:
>
> On Fri, Oct 30, 2026 at 02:57:00PM +0100, Igor Opaniuk wrote:
> > SDHCI_QUIRK_WAIT_SEND_CMD makes sdhci_send_command() sleep for 1 ms
> > after every command. msm_sdhci has set it since the driver was added
> > for APQ8016, back when it only did PIO; the commit gives no reason for
> > it, and the Linux sdhci-msm driver has no such delay.
> >
> > The delay is invisible for large reads but dominates small ones. A
> > multi-block read is CMD18 followed by CMD12, so every read pays 2 ms
> > on top of the transfer. With the eMMC in HS400 a 128 KiB read takes
> > about 0.4 ms, so USB mass storage, which reads in 128 KiB (FSG_BUFLEN)
> > chunks, spent most of its time in udelay(). On the Arduino UNO Q,
> > reading 1 GiB from "ums 0 mmc 0" on a USB 3 host
> > (dd if=/dev/sdX of=/dev/null bs=4M count=256):
> >
> >                      host throughput   time in eMMC reads (10.6k reads)
> >   with the quirk     46 MB/s           26.8 s (~2.5 ms per read)
> >   without            201 MB/s           4.5 s (~0.4 ms per read)
> >
> > A single 128 MiB "mmc read" runs at 255.6 MiB/s either way.
> >
> > Drop the quirk and keep SDHCI_QUIRK_BROKEN_R1B.
> >
> > Tested on the Arduino UNO Q (QRB2210, qcom,sdhci-msm-v5, ADMA):
> > - on main (eMMC in DDR52): 128 MiB "mmc read" at 75 MiB/s as before,
> >   the CRC32 of the first 128 MiB read in U-Boot matches the one Linux
> >   computes from the same blocks, and Linux boots from the eMMC;
> > - with the "qcom: Enable HS200/HS400 eMMC modes" series and the
> >   mass_storage SuperSpeed descriptor patch applied (eMMC in HS400):
> >   the ums numbers above, same CRC32 check and Linux boot.
> > Not tested on v4 controllers or on the boards that use the driver in
> > PIO mode (qcom_dragonboard410c, qcom_dragonboard820c, hmibsc).
> >
> > Signed-off-by: Igor Opaniuk <igor.opaniuk@oss.qualcomm.com>
> > ---
> > Drop the 1 ms delay msm_sdhci adds after every SD command. It costs
> > 2 ms per multi-block read, which capped ums on an Arduino UNO Q at
> > 46 MB/s; without it the same read runs at 201 MB/s.
> >
> > Testing on APQ8016/APQ8096 (PIO mode) would be welcome.
>
> Please Cc the board maintainers (me, for DB410c/APQ8016) if you are
> looking for feedback for these boards. I found this patch on the mailing
> list only by coincidence.

Sorry about that (I relied too much on get_maintaners script),
and thanks a lot for testing on three boards anyway. v2 has you and
the other board maintainers on Cc.

>
> The fact that APQ8016/APQ8096 use PIO instead of ADMA is a relic from
> before ADMA support was introduced. ADMA works just fine in my tests on
> these boards and makes no difference for the following test results.
>
> This patch works for the eMMC, but it seems to break SD card detection
> on all QC boards I tested.
>
> DB410c (APQ8016):
>  - eMMC: works
>  - SD: broken, CMD55 response CRC error
>
> DB820c (APQ8096):
>  - eMMC: N/A
>  - SD: broken, CMD55 response CRC error
>
> RB3Gen2 (QCS6490):
>  - eMMC: N/A
>  - SD: broken, CMD55 response CRC error
>
> The symptom is that the SD card is simply silently not detected at all,
> I added some more logging to find the CMD55 response CRC error. AFAICT
> (without investigating in detail), the following happens:
>
>  1. In drivers/mmc/mmc.c sd_send_op_cond() U-Boot sends MMC_CMD_APP_CMD
>     (CMD55), followed by SD_CMD_APP_SEND_OP_COND (ACMD41).
>  2. The first CMD55 and ACMD41 succeed, cmd.response[0] is 0x00ff8000
>     so BIT(31) (OCR_BUSY) isn't set yet so it polls again with the same
>     commands after 1ms.
>  3. The second CMD55 fails immediately (too early to come from the SD
>     card with a CRC error).
>
> The CRC error seems to origin from the previous ACMD41. With
> SDHCI_QUIRK_WAIT_SEND_CMD we wait long enough after sending the previous
> command to clear the CRC error before the next command sees it.
>
> There different options to fix this:
>  - A retry of CMD55 in case of an error seems to work.
>  - Maybe we could check and clear unhandled errors in
>    sdhci_send_command() before sending another command.
>
> This extra diff that implements a retry works for example:
>
> --- a/drivers/mmc/mmc.c
> +++ b/drivers/mmc/mmc.c
> @@ -674,7 +674,8 @@
>                 cmd.resp_type = MMC_RSP_R1;
>                 cmd.cmdarg = 0;
>
> -               err = mmc_send_cmd(mmc, &cmd, NULL);
> +               err = mmc_send_cmd_quirks(mmc, &cmd, NULL,
> +                                         MMC_QUIRK_RETRY_APP_CMD, 3);
>
>                 if (err)
>                         return err;
>
> The real question though is why we are reliably getting this CRC error.
> It might be worth to investigate that further. I would expect you can
> reproduce this on any QC board with a SD card if you want to test this
> further.

I looked into it. The UNO Q has no SD slot, but the same thing happens
on its eMMC, only hidden -  on every mmc rescan the first CMD2 after
the last CMD1 fails on the first status read with INT_STATUS
0x00028000 and then passes on the MMC_QUIRK_RETRY_SEND_CID retry. So
the common factor is a CRC-checked command that follows an R3 response
(CMD1 here, ACMD41 in your case).

With a status trace in sdhci_send_command() (card clock 188 kHz):

1. INT_STATUS reads 0 right before the failing command, even 10 ms after
  the R3 response, so clearing unhandled errors before the next command
  would not see anything;
2. Waiting before that command does not help (50 us to 10 ms, all fail);
3. Delaying the final status clear of the R3 command itself does: 8 us
  still fails 6/6, 12 us and more pass 6/6.

So the R3 response seems to leave a latent CRC error that only a status
clear a few SD clock cycles after completion removes, and the clear
done right at completion comes too early. That is what
SDHCI_QUIRK_WAIT_SEND_CMD was hiding with its 1 ms.

In v2 I'll add a patch that waits 16 SD clock periods before the final status
clear when the response carries no CRC (CMD1 and ACMD41 only). With it
the CMD2 passes 50/50 here and is sent only once.

Unfortuantely I cannot test the SD case now. Could you try v2 on one of your
boards? It does not include your CMD55 retry you shared, and if the delay
does not cover SD, I will add the retry you mentioned in v3.

>
> SDHCI_QUIRK_BROKEN_R1B on the other hand made no difference in my
> testing, I think we could drop that one (Linux does not seem to do this
> either).

I would do that as a separate patch if you don't mind once I have run an erase
test here, since R1b commands then wait for the data-end interrupt.
>
> Thanks,
> Stephan

Best regards,
Igor

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

* Re: [PATCH] mmc: msm_sdhci: drop SDHCI_QUIRK_WAIT_SEND_CMD
  2026-11-23  8:47   ` Igor Opaniuk
@ 2026-11-23 13:31     ` Stephan Gerhold
  0 siblings, 0 replies; 6+ messages in thread
From: Stephan Gerhold @ 2026-11-23 13:31 UTC (permalink / raw)
  To: Igor Opaniuk
  Cc: Sumit Garg, Tanmay Kathpalia, u-boot-qcom, u-boot, Casey Connolly,
	Neil Armstrong, Peng Fan, Jaehoon Chung, Tom Rini,
	Varadarajan Narayanan, Aswin Murugan, Balaji Selvanathan

On Mon, Nov 23, 2026 at 09:47:32AM +0100, Igor Opaniuk wrote:
> On Fri, Nov 20, 2026 at 9:08 PM Stephan Gerhold
> <stephan.gerhold@linaro.org> wrote:
> >
> > On Fri, Oct 30, 2026 at 02:57:00PM +0100, Igor Opaniuk wrote:
> > > SDHCI_QUIRK_WAIT_SEND_CMD makes sdhci_send_command() sleep for 1 ms
> > > after every command. msm_sdhci has set it since the driver was added
> > > for APQ8016, back when it only did PIO; the commit gives no reason for
> > > it, and the Linux sdhci-msm driver has no such delay.
> > >
> > > The delay is invisible for large reads but dominates small ones. A
> > > multi-block read is CMD18 followed by CMD12, so every read pays 2 ms
> > > on top of the transfer. With the eMMC in HS400 a 128 KiB read takes
> > > about 0.4 ms, so USB mass storage, which reads in 128 KiB (FSG_BUFLEN)
> > > chunks, spent most of its time in udelay(). On the Arduino UNO Q,
> > > reading 1 GiB from "ums 0 mmc 0" on a USB 3 host
> > > (dd if=/dev/sdX of=/dev/null bs=4M count=256):
> > >
> > >                      host throughput   time in eMMC reads (10.6k reads)
> > >   with the quirk     46 MB/s           26.8 s (~2.5 ms per read)
> > >   without            201 MB/s           4.5 s (~0.4 ms per read)
> > >
> > > A single 128 MiB "mmc read" runs at 255.6 MiB/s either way.
> > >
> > > Drop the quirk and keep SDHCI_QUIRK_BROKEN_R1B.
> > >
> > > Tested on the Arduino UNO Q (QRB2210, qcom,sdhci-msm-v5, ADMA):
> > > - on main (eMMC in DDR52): 128 MiB "mmc read" at 75 MiB/s as before,
> > >   the CRC32 of the first 128 MiB read in U-Boot matches the one Linux
> > >   computes from the same blocks, and Linux boots from the eMMC;
> > > - with the "qcom: Enable HS200/HS400 eMMC modes" series and the
> > >   mass_storage SuperSpeed descriptor patch applied (eMMC in HS400):
> > >   the ums numbers above, same CRC32 check and Linux boot.
> > > Not tested on v4 controllers or on the boards that use the driver in
> > > PIO mode (qcom_dragonboard410c, qcom_dragonboard820c, hmibsc).
> > >
> > > Signed-off-by: Igor Opaniuk <igor.opaniuk@oss.qualcomm.com>
> > > ---
> > > Drop the 1 ms delay msm_sdhci adds after every SD command. It costs
> > > 2 ms per multi-block read, which capped ums on an Arduino UNO Q at
> > > 46 MB/s; without it the same read runs at 201 MB/s.
> > >
> > > Testing on APQ8016/APQ8096 (PIO mode) would be welcome.
> >
> > Please Cc the board maintainers (me, for DB410c/APQ8016) if you are
> > looking for feedback for these boards. I found this patch on the mailing
> > list only by coincidence.
> 
> Sorry about that (I relied too much on get_maintaners script),
> and thanks a lot for testing on three boards anyway. v2 has you and
> the other board maintainers on Cc.
> 
> >
> > The fact that APQ8016/APQ8096 use PIO instead of ADMA is a relic from
> > before ADMA support was introduced. ADMA works just fine in my tests on
> > these boards and makes no difference for the following test results.
> >
> > This patch works for the eMMC, but it seems to break SD card detection
> > on all QC boards I tested.
> >
> > DB410c (APQ8016):
> >  - eMMC: works
> >  - SD: broken, CMD55 response CRC error
> >
> > DB820c (APQ8096):
> >  - eMMC: N/A
> >  - SD: broken, CMD55 response CRC error
> >
> > RB3Gen2 (QCS6490):
> >  - eMMC: N/A
> >  - SD: broken, CMD55 response CRC error
> >
> > The symptom is that the SD card is simply silently not detected at all,
> > I added some more logging to find the CMD55 response CRC error. AFAICT
> > (without investigating in detail), the following happens:
> >
> >  1. In drivers/mmc/mmc.c sd_send_op_cond() U-Boot sends MMC_CMD_APP_CMD
> >     (CMD55), followed by SD_CMD_APP_SEND_OP_COND (ACMD41).
> >  2. The first CMD55 and ACMD41 succeed, cmd.response[0] is 0x00ff8000
> >     so BIT(31) (OCR_BUSY) isn't set yet so it polls again with the same
> >     commands after 1ms.
> >  3. The second CMD55 fails immediately (too early to come from the SD
> >     card with a CRC error).
> >
> > The CRC error seems to origin from the previous ACMD41. With
> > SDHCI_QUIRK_WAIT_SEND_CMD we wait long enough after sending the previous
> > command to clear the CRC error before the next command sees it.
> >
> > There different options to fix this:
> >  - A retry of CMD55 in case of an error seems to work.
> >  - Maybe we could check and clear unhandled errors in
> >    sdhci_send_command() before sending another command.
> >
> > This extra diff that implements a retry works for example:
> >
> > --- a/drivers/mmc/mmc.c
> > +++ b/drivers/mmc/mmc.c
> > @@ -674,7 +674,8 @@
> >                 cmd.resp_type = MMC_RSP_R1;
> >                 cmd.cmdarg = 0;
> >
> > -               err = mmc_send_cmd(mmc, &cmd, NULL);
> > +               err = mmc_send_cmd_quirks(mmc, &cmd, NULL,
> > +                                         MMC_QUIRK_RETRY_APP_CMD, 3);
> >
> >                 if (err)
> >                         return err;
> >
> > The real question though is why we are reliably getting this CRC error.
> > It might be worth to investigate that further. I would expect you can
> > reproduce this on any QC board with a SD card if you want to test this
> > further.
> 
> I looked into it. The UNO Q has no SD slot, but the same thing happens
> on its eMMC, only hidden -  on every mmc rescan the first CMD2 after
> the last CMD1 fails on the first status read with INT_STATUS
> 0x00028000 and then passes on the MMC_QUIRK_RETRY_SEND_CID retry. So
> the common factor is a CRC-checked command that follows an R3 response
> (CMD1 here, ACMD41 in your case).
> 
> With a status trace in sdhci_send_command() (card clock 188 kHz):
> 
> 1. INT_STATUS reads 0 right before the failing command, even 10 ms after
>   the R3 response, so clearing unhandled errors before the next command
>   would not see anything;
> 2. Waiting before that command does not help (50 us to 10 ms, all fail);
> 3. Delaying the final status clear of the R3 command itself does: 8 us
>   still fails 6/6, 12 us and more pass 6/6.
> 
> So the R3 response seems to leave a latent CRC error that only a status
> clear a few SD clock cycles after completion removes, and the clear
> done right at completion comes too early. That is what
> SDHCI_QUIRK_WAIT_SEND_CMD was hiding with its 1 ms.
> 
> In v2 I'll add a patch that waits 16 SD clock periods before the final status
> clear when the response carries no CRC (CMD1 and ACMD41 only). With it
> the CMD2 passes 50/50 here and is sent only once.
> 
> Unfortuantely I cannot test the SD case now. Could you try v2 on one of your
> boards? It does not include your CMD55 retry you shared, and if the delay
> does not cover SD, I will add the retry you mentioned in v3.
> 

Thanks, I replied directly to v2 (works fine for eMMC/SD on DB410c).

> >
> > SDHCI_QUIRK_BROKEN_R1B on the other hand made no difference in my
> > testing, I think we could drop that one (Linux does not seem to do this
> > either).
> 
> I would do that as a separate patch if you don't mind once I have run an erase
> test here, since R1b commands then wait for the data-end interrupt.

FWIW, I did a couple of erase tests on DB410c and the data-end interrupt
was triggered just fine in all cases.

Thanks,
Stephan

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

end of thread, other threads:[~2026-11-23 13:31 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-30 13:57 [PATCH] mmc: msm_sdhci: drop SDHCI_QUIRK_WAIT_SEND_CMD Igor Opaniuk
2026-10-31 15:03 ` Aswin Murugan
2026-11-01  9:17 ` Kathpalia, Tanmay
2026-11-20 20:08 ` Stephan Gerhold
2026-11-23  8:47   ` Igor Opaniuk
2026-11-23 13:31     ` Stephan Gerhold

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