[PATCH v42 35/98] hw/sd/sdcard: Convert GEN_CMD to generic_write_byte (CMD56)

Philippe Mathieu-Daudé posted 98 patches 6 months ago
There is a newer version of this series
[PATCH v42 35/98] hw/sd/sdcard: Convert GEN_CMD to generic_write_byte (CMD56)
Posted by Philippe Mathieu-Daudé 6 months ago
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 hw/sd/sd.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/hw/sd/sd.c b/hw/sd/sd.c
index 0cb528b0b2..f9708064d0 100644
--- a/hw/sd/sd.c
+++ b/hw/sd/sd.c
@@ -1657,14 +1657,12 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req)
     case 56:  /* CMD56:  GEN_CMD */
         switch (sd->state) {
         case sd_transfer_state:
-            sd->data_offset = 0;
             if (req.arg & 1) {
                 return sd_cmd_to_sendingdata(sd, req, 0,
                                              sd->vendor_data,
                                              sizeof(sd->vendor_data));
             }
-            sd->state = sd_receivingdata_state;
-            return sd_r1;
+            return sd_cmd_to_receivingdata(sd, req, 0, sizeof(sd->vendor_data));
 
         default:
             break;
@@ -2109,9 +2107,8 @@ void sd_write_byte(SDState *sd, uint8_t value)
         break;
 
     case 56:  /* CMD56:  GEN_CMD */
-        sd->vendor_data[sd->data_offset ++] = value;
-        if (sd->data_offset >= sizeof(sd->vendor_data)) {
-            sd->state = sd_transfer_state;
+        if (sd_generic_write_byte(sd, value)) {
+            memcpy(sd->vendor_data, sd->data, sizeof(sd->vendor_data));
         }
         break;
 
-- 
2.41.0


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


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

Thanks,

C.


> ---
>   hw/sd/sd.c | 9 +++------
>   1 file changed, 3 insertions(+), 6 deletions(-)
> 
> diff --git a/hw/sd/sd.c b/hw/sd/sd.c
> index 0cb528b0b2..f9708064d0 100644
> --- a/hw/sd/sd.c
> +++ b/hw/sd/sd.c
> @@ -1657,14 +1657,12 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req)
>       case 56:  /* CMD56:  GEN_CMD */
>           switch (sd->state) {
>           case sd_transfer_state:
> -            sd->data_offset = 0;
>               if (req.arg & 1) {
>                   return sd_cmd_to_sendingdata(sd, req, 0,
>                                                sd->vendor_data,
>                                                sizeof(sd->vendor_data));
>               }
> -            sd->state = sd_receivingdata_state;
> -            return sd_r1;
> +            return sd_cmd_to_receivingdata(sd, req, 0, sizeof(sd->vendor_data));
>   
>           default:
>               break;
> @@ -2109,9 +2107,8 @@ void sd_write_byte(SDState *sd, uint8_t value)
>           break;
>   
>       case 56:  /* CMD56:  GEN_CMD */
> -        sd->vendor_data[sd->data_offset ++] = value;
> -        if (sd->data_offset >= sizeof(sd->vendor_data)) {
> -            sd->state = sd_transfer_state;
> +        if (sd_generic_write_byte(sd, value)) {
> +            memcpy(sd->vendor_data, sd->data, sizeof(sd->vendor_data));
>           }
>           break;
>