[PATCH v42 28/98] hw/sd/sdcard: Convert SEND_SCR to generic_read_byte (ACMD51)

Philippe Mathieu-Daudé posted 98 patches 6 months ago
There is a newer version of this series
[PATCH v42 28/98] hw/sd/sdcard: Convert SEND_SCR to generic_read_byte (ACMD51)
Posted by Philippe Mathieu-Daudé 6 months ago
From: Philippe Mathieu-Daudé <f4bug@amsat.org>

Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 hw/sd/sd.c | 13 ++-----------
 1 file changed, 2 insertions(+), 11 deletions(-)

diff --git a/hw/sd/sd.c b/hw/sd/sd.c
index 8d02cd9a26..cd308e9a89 100644
--- a/hw/sd/sd.c
+++ b/hw/sd/sd.c
@@ -1785,10 +1785,7 @@ static sd_rsp_type_t sd_app_command(SDState *sd,
     case 51:  /* ACMD51: SEND_SCR */
         switch (sd->state) {
         case sd_transfer_state:
-            sd->state = sd_sendingdata_state;
-            sd->data_start = 0;
-            sd->data_offset = 0;
-            return sd_r1;
+            return sd_cmd_to_sendingdata(sd, req, 0, sd->scr, sizeof(sd->scr));
 
         default:
             break;
@@ -2138,6 +2135,7 @@ uint8_t sd_read_byte(SDState *sd)
     case 19: /* CMD19:  SEND_TUNING_BLOCK (SD) */
     case 22: /* ACMD22: SEND_NUM_WR_BLOCKS */
     case 30: /* CMD30:  SEND_WRITE_PROT */
+    case 51: /* ACMD51: SEND_SCR */
     case 56: /* CMD56:  GEN_CMD */
         sd_generic_read_byte(sd, &ret);
         break;
@@ -2166,13 +2164,6 @@ uint8_t sd_read_byte(SDState *sd)
         }
         break;
 
-    case 51:  /* ACMD51: SEND_SCR */
-        ret = sd->scr[sd->data_offset ++];
-
-        if (sd->data_offset >= sizeof(sd->scr))
-            sd->state = sd_transfer_state;
-        break;
-
     default:
         qemu_log_mask(LOG_GUEST_ERROR, "%s: unknown command\n", __func__);
         return 0x00;
-- 
2.41.0


Re: [PATCH v42 28/98] hw/sd/sdcard: Convert SEND_SCR to generic_read_byte (ACMD51)
Posted by Cédric Le Goater 6 months ago
On 6/28/24 9:01 AM, Philippe Mathieu-Daudé wrote:
> From: Philippe Mathieu-Daudé <f4bug@amsat.org>
> 
> Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>


Reviewed-by: Cédric Le Goater <clg@redhat.com>

Thanks,

C.


> ---
>   hw/sd/sd.c | 13 ++-----------
>   1 file changed, 2 insertions(+), 11 deletions(-)
> 
> diff --git a/hw/sd/sd.c b/hw/sd/sd.c
> index 8d02cd9a26..cd308e9a89 100644
> --- a/hw/sd/sd.c
> +++ b/hw/sd/sd.c
> @@ -1785,10 +1785,7 @@ static sd_rsp_type_t sd_app_command(SDState *sd,
>       case 51:  /* ACMD51: SEND_SCR */
>           switch (sd->state) {
>           case sd_transfer_state:
> -            sd->state = sd_sendingdata_state;
> -            sd->data_start = 0;
> -            sd->data_offset = 0;
> -            return sd_r1;
> +            return sd_cmd_to_sendingdata(sd, req, 0, sd->scr, sizeof(sd->scr));
>   
>           default:
>               break;
> @@ -2138,6 +2135,7 @@ uint8_t sd_read_byte(SDState *sd)
>       case 19: /* CMD19:  SEND_TUNING_BLOCK (SD) */
>       case 22: /* ACMD22: SEND_NUM_WR_BLOCKS */
>       case 30: /* CMD30:  SEND_WRITE_PROT */
> +    case 51: /* ACMD51: SEND_SCR */
>       case 56: /* CMD56:  GEN_CMD */
>           sd_generic_read_byte(sd, &ret);
>           break;
> @@ -2166,13 +2164,6 @@ uint8_t sd_read_byte(SDState *sd)
>           }
>           break;
>   
> -    case 51:  /* ACMD51: SEND_SCR */
> -        ret = sd->scr[sd->data_offset ++];
> -
> -        if (sd->data_offset >= sizeof(sd->scr))
> -            sd->state = sd_transfer_state;
> -        break;
> -
>       default:
>           qemu_log_mask(LOG_GUEST_ERROR, "%s: unknown command\n", __func__);
>           return 0x00;