Skip to contentSkip to conversation

mmc: Remove alignment hole for cmdidx in struct mmc_cmd

PATCH In review Jonas Karlman 4 participants 6 messages Jan 27, 2024 – Jan 26, 2025

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 mmc: Remove alignment hole for cmdidx in struct mmc_cmd

The alignment hole caused by cmdidx in struct mmc_cmd cause strange issues together with the peephole2 optimization on Amlogic SoCs. Following was observed while working on SPL support for Amlogic SoCs.

sd_get_capabilities() normally issue a CMD55 followed by a CMD51. However, on at least Amlogic S905 (Cortex-A53) and S905X3 (Cortex-A55), CMD55 was instead followed by CMD8 (and a few reties) in SPL.

Code from the call site:

  cmd.cmdidx = SD_CMD_APP_SEND_SCR; // 51
  ...
  data.blocksize = 8;
  ...
  err = mmc_send_cmd_retry(mmc, &cmd, &data, 3);

Running the code with MMC_TRACE enabled shows:

CMD_SEND:55

                ARG                      0x50480000
                MMC_RSP_R1,5,6,7         0x00000920
CMD_SEND:8
                ARG                      0x00000000
                RET                      -110

Removing the alignment hole by changing cmdidx from ushort to uint or building with -fno-peephole2 flag seem to resolve this issue.

CMD_SEND:55

                ARG                      0x50480000
                MMC_RSP_R1,5,6,7         0x00000920
CMD_SEND:51
                ARG                      0x00000000
                MMC_RSP_R1,5,6,7         0x00000920

Same issue was observed building U-Boot with gcc 8 - 13.

Remove this alignment hole by changing cmdidx from ushort to uint.

---
Changes in v2:
- Drop use of -fno-peephole2 flag

Link to RFC: https://patchwork.ozlabs.org/patch/1841495/

---
 include/mmc.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/mmc.h +1 -1
index 1022db3ffa7c..031ea0fb3545 100644
@@ -413,7 +413,7 @@ struct mmc_cid {
 };
 
 struct mmc_cmd {
-	ushort cmdidx;
+	uint cmdidx;
 	uint resp_type;
 	uint cmdarg;
 	uint response[4];
Signature · 1 line
2.43.0
#1 lore raw

Hi,

Quoted 7 lines · Jonas Karlman

The alignment hole caused by cmdidx in struct mmc_cmd cause strange issues together with the peephole2 optimization on Amlogic SoCs. Following was observed while working on SPL support for Amlogic SoCs.

sd_get_capabilities() normally issue a CMD55 followed by a CMD51. However, on at least Amlogic S905 (Cortex-A53) and S905X3 (Cortex-A55), CMD55 was instead followed by CMD8 (and a few reties) in SPL.

I read your RFC "https://patchwork.ozlabs.org/patch/1841495/".

First, I will retry to reproduce your case with other compiler. After that, I will inform again about this patch.

Best Regards,
Jaehoon Chung

Quoted 55 lines

Code from the call site:

  cmd.cmdidx = SD_CMD_APP_SEND_SCR; // 51
  ...
  data.blocksize = 8;
  ...
  err = mmc_send_cmd_retry(mmc, &cmd, &data, 3);

Running the code with MMC_TRACE enabled shows:

CMD_SEND:55

                ARG                      0x50480000
                MMC_RSP_R1,5,6,7         0x00000920
CMD_SEND:8
                ARG                      0x00000000
                RET                      -110

Removing the alignment hole by changing cmdidx from ushort to uint or building with -fno-peephole2 flag seem to resolve this issue.

CMD_SEND:55

                ARG                      0x50480000
                MMC_RSP_R1,5,6,7         0x00000920
CMD_SEND:51
                ARG                      0x00000000
                MMC_RSP_R1,5,6,7         0x00000920

Same issue was observed building U-Boot with gcc 8 - 13.

Remove this alignment hole by changing cmdidx from ushort to uint.

---
Changes in v2:
- Drop use of -fno-peephole2 flag

Link to RFC: https://patchwork.ozlabs.org/patch/1841495/

---
 include/mmc.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/mmc.h +1 -1
index 1022db3ffa7c..031ea0fb3545 100644
@@ -413,7 +413,7 @@ struct mmc_cid {
 };
 
 struct mmc_cmd {
-	ushort cmdidx;
+	uint cmdidx;
 	uint resp_type;
 	uint cmdarg;
 	uint response[4];
#2 lore raw

Hi,

Quoted 7 lines · Jaehoon Chung

Hi,

Quoted 4 lines · Jonas Karlman

The alignment hole caused by cmdidx in struct mmc_cmd cause strange issues together with the peephole2 optimization on Amlogic SoCs. Following was observed while working on SPL support for Amlogic SoCs.

Quoted 8 lines
Quoted 3 lines

sd_get_capabilities() normally issue a CMD55 followed by a CMD51. However, on at least Amlogic S905 (Cortex-A53) and S905X3 (Cortex-A55), CMD55 was instead followed by CMD8 (and a few reties) in SPL.

I read your RFC "https://patchwork.ozlabs.org/patch/1841495/

First, I will retry to reproduce your case with other compiler. After that, I will inform again about this patch.

Gentle ping, this patch has been on list for almost a year now.

Have you had any time to reproduce this or can this be merged as-is?

For some reason only Amlogic seem to be affected by this issue.

Regards,
Jonas

Quoted 60 lines

Best Regards,
Jaehoon Chung

Quoted 55 lines

Code from the call site:

  cmd.cmdidx = SD_CMD_APP_SEND_SCR; // 51
  ...
  data.blocksize = 8;
  ...
  err = mmc_send_cmd_retry(mmc, &cmd, &data, 3);

Running the code with MMC_TRACE enabled shows:

CMD_SEND:55

                ARG                      0x50480000
                MMC_RSP_R1,5,6,7         0x00000920
CMD_SEND:8
                ARG                      0x00000000
                RET                      -110

Removing the alignment hole by changing cmdidx from ushort to uint or building with -fno-peephole2 flag seem to resolve this issue.

CMD_SEND:55

                ARG                      0x50480000
                MMC_RSP_R1,5,6,7         0x00000920
CMD_SEND:51
                ARG                      0x00000000
                MMC_RSP_R1,5,6,7         0x00000920

Same issue was observed building U-Boot with gcc 8 - 13.

Remove this alignment hole by changing cmdidx from ushort to uint.

---
Changes in v2:
- Drop use of -fno-peephole2 flag

Link to RFC: https://patchwork.ozlabs.org/patch/1841495/

---
 include/mmc.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/mmc.h +1 -1
index 1022db3ffa7c..031ea0fb3545 100644
@@ -413,7 +413,7 @@ struct mmc_cid {
 };
 
 struct mmc_cmd {
-	ushort cmdidx;
+	uint cmdidx;
 	uint resp_type;
 	uint cmdarg;
 	uint response[4];
#3 lore raw
Quoted 14 lines · Jonas Karlman

<...>
On 2024-04-03 02:00, Jaehoon Chung wrote:
<...>

Quoted 11 lines · Jonas Karlman
Quoted 7 lines

The alignment hole caused by cmdidx in struct mmc_cmd cause strange issues together with the peephole2 optimization on Amlogic SoCs. Following was observed while working on SPL support for Amlogic SoCs.

sd_get_capabilities() normally issue a CMD55 followed by a CMD51. However, on at least Amlogic S905 (Cortex-A53) and S905X3 (Cortex-A55), CMD55 was instead followed by CMD8 (and a few reties) in SPL.

I read your RFC "https://patchwork.ozlabs.org/patch/1841495/

Quoted 8 lines
Quoted 2 lines

First, I will retry to reproduce your case with other compiler. After that, I will inform again about this patch.

Gentle ping, this patch has been on list for almost a year now.

Have you had any time to reproduce this or can this be merged as-is?

For some reason only Amlogic seem to be affected by this issue.

It is somewhat reproducible with gcc 14 on Amlogic S905X (Libre Computer lepotato), except instead of CMD55 followed by CMD8, I get CMD0 followed by CMD8 directly:

[...]
<debug_uart>

U-Boot SPL 2025.01-00633-gf79293cffe53 (Jan 19 2025 - 14:59:34 +0000) Trying to boot from MMC1
CMD_SEND:0

                ARG                      0x00000000
                MMC_RSP_NONE
CMD_SEND:8
                ARG                      0x000001aa
                MMC_RSP_R1,5,6,7         0x000001aa 
CMD_SEND:0
                ARG                      0x00000000
                RET                      -110
CMD_SEND:0
                ARG                      0x00000000
                MMC_RSP_NONE
CMD_SEND:0
                ARG                      0x00000000
                RET                      -110

Card did not respond to voltage select! : -110
[...]

And the board refuses to boot afterwards. Changing cmdidx type to uint fixes my issue as well.

Reviewed-by
#4 lore raw
In reply to Jonas Karlman
Quoted 16 lines · Jonas Karlman

Hi,

Quoted 13 lines · Jaehoon Chung

Hi,

Quoted 7 lines · Jonas Karlman

The alignment hole caused by cmdidx in struct mmc_cmd cause strange issues together with the peephole2 optimization on Amlogic SoCs. Following was observed while working on SPL support for Amlogic SoCs.

sd_get_capabilities() normally issue a CMD55 followed by a CMD51. However, on at least Amlogic S905 (Cortex-A53) and S905X3 (Cortex-A55), CMD55 was instead followed by CMD8 (and a few reties) in SPL.

I read your RFC "https://patchwork.ozlabs.org/patch/1841495/

Quoted 8 lines
Quoted 2 lines

First, I will retry to reproduce your case with other compiler. After that, I will inform again about this patch.

Gentle ping, this patch has been on list for almost a year now.

Have you had any time to reproduce this or can this be merged as-is?

For some reason only Amlogic seem to be affected by this issue.

Poking around in Linux, it looks like this is equivalent to 'struct mmc_command' in include/linux/mmc/core.h and so this makes us equivalent.

Signature · 1 line
Tom
#5 lore raw
In reply to Jonas Karlman
Quoted 9 lines · Jonas Karlman

The alignment hole caused by cmdidx in struct mmc_cmd cause strange issues together with the peephole2 optimization on Amlogic SoCs. Following was observed while working on SPL support for Amlogic SoCs.

sd_get_capabilities() normally issue a CMD55 followed by a CMD51. However, on at least Amlogic S905 (Cortex-A53) and S905X3 (Cortex-A55), CMD55 was instead followed by CMD8 (and a few reties) in SPL.

[...]

Applied to u-boot/master, thanks!

Signature · 1 line
Tom