[RFC PATCH 10/17] hw/sd: Add sd_cmd_SEND_TUNING_BLOCK() handler

Cédric Le Goater posted 17 patches 3 years, 10 months ago
Maintainers: "Philippe Mathieu-Daudé" <f4bug@amsat.org>, Bin Meng <bin.meng@windriver.com>
There is a newer version of this series
[RFC PATCH 10/17] hw/sd: Add sd_cmd_SEND_TUNING_BLOCK() handler
Posted by Cédric Le Goater 3 years, 10 months ago
From: Joel Stanley <joel@jms.id.au>

Signed-off-by: Joel Stanley <joel@jms.id.au>
Signed-off-by: Cédric Le Goater <clg@kaod.org>
---
 hw/sd/sd.c | 28 +++++++++++++++++-----------
 1 file changed, 17 insertions(+), 11 deletions(-)

diff --git a/hw/sd/sd.c b/hw/sd/sd.c
index 25e86c893bba..602ed6eb0701 100644
--- a/hw/sd/sd.c
+++ b/hw/sd/sd.c
@@ -1042,6 +1042,22 @@ static sd_rsp_type_t sd_cmd_SEND_RELATIVE_ADDR(SDState *sd, SDRequest req)
     }
 }
 
+static sd_rsp_type_t sd_cmd_SEND_TUNING_BLOCK(SDState *sd, SDRequest req)
+{
+        if (sd->spec_version < SD_PHY_SPECv3_01_VERS) {
+            return sd_invalid_state_for_cmd(sd, req);
+        }
+
+        if (sd->state != sd_transfer_state) {
+            return sd_invalid_state_for_cmd(sd, req);
+        }
+
+        sd->state = sd_sendingdata_state;
+        sd->data_offset = 0;
+
+        return sd_r1;
+}
+
 static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req)
 {
     uint32_t rca = 0x0000;
@@ -1285,17 +1301,6 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req)
         }
         break;
 
-    case 19:    /* CMD19: SEND_TUNING_BLOCK (SD) */
-        if (sd->spec_version < SD_PHY_SPECv3_01_VERS) {
-            break;
-        }
-        if (sd->state == sd_transfer_state) {
-            sd->state = sd_sendingdata_state;
-            sd->data_offset = 0;
-            return sd_r1;
-        }
-        break;
-
     case 23:    /* CMD23: SET_BLOCK_COUNT */
         if (sd->spec_version < SD_PHY_SPECv3_01_VERS) {
             break;
@@ -2132,6 +2137,7 @@ static const SDProto sd_proto_sd = {
         [2]         = sd_cmd_ALL_SEND_CID,
         [3]         = sd_cmd_SEND_RELATIVE_ADDR,
         [5]         = sd_cmd_illegal,
+        [19]        = sd_cmd_SEND_TUNING_BLOCK,
         [52 ... 54] = sd_cmd_illegal,
         [58]        = sd_cmd_illegal,
         [59]        = sd_cmd_illegal,
-- 
2.34.1
Re: [RFC PATCH 10/17] hw/sd: Add sd_cmd_SEND_TUNING_BLOCK() handler
Posted by Philippe Mathieu-Daudé via 3 years, 9 months ago
On 18/3/22 14:28, Cédric Le Goater wrote:
> From: Joel Stanley <joel@jms.id.au>
> 
> Signed-off-by: Joel Stanley <joel@jms.id.au>
> Signed-off-by: Cédric Le Goater <clg@kaod.org>
> ---
>   hw/sd/sd.c | 28 +++++++++++++++++-----------
>   1 file changed, 17 insertions(+), 11 deletions(-)
> 
> diff --git a/hw/sd/sd.c b/hw/sd/sd.c
> index 25e86c893bba..602ed6eb0701 100644
> --- a/hw/sd/sd.c
> +++ b/hw/sd/sd.c
> @@ -1042,6 +1042,22 @@ static sd_rsp_type_t sd_cmd_SEND_RELATIVE_ADDR(SDState *sd, SDRequest req)
>       }
>   }
>   
> +static sd_rsp_type_t sd_cmd_SEND_TUNING_BLOCK(SDState *sd, SDRequest req)
> +{
> +        if (sd->spec_version < SD_PHY_SPECv3_01_VERS) {
> +            return sd_invalid_state_for_cmd(sd, req);

There was a bug here, this should be:

                return sd_illegal;

(see 
https://lore.kernel.org/qemu-devel/20220509141320.98374-1-philippe.mathieu.daude@gmail.com/. 
I can fix upon applying).

Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>

> +        }
> +
> +        if (sd->state != sd_transfer_state) {
> +            return sd_invalid_state_for_cmd(sd, req);
> +        }
> +
> +        sd->state = sd_sendingdata_state;
> +        sd->data_offset = 0;
> +
> +        return sd_r1;
> +}
> +
>   static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req)
>   {
>       uint32_t rca = 0x0000;
> @@ -1285,17 +1301,6 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req)
>           }
>           break;
>   
> -    case 19:    /* CMD19: SEND_TUNING_BLOCK (SD) */
> -        if (sd->spec_version < SD_PHY_SPECv3_01_VERS) {
> -            break;
> -        }
> -        if (sd->state == sd_transfer_state) {
> -            sd->state = sd_sendingdata_state;
> -            sd->data_offset = 0;
> -            return sd_r1;
> -        }
> -        break;
> -
>       case 23:    /* CMD23: SET_BLOCK_COUNT */
>           if (sd->spec_version < SD_PHY_SPECv3_01_VERS) {
>               break;
> @@ -2132,6 +2137,7 @@ static const SDProto sd_proto_sd = {
>           [2]         = sd_cmd_ALL_SEND_CID,
>           [3]         = sd_cmd_SEND_RELATIVE_ADDR,
>           [5]         = sd_cmd_illegal,
> +        [19]        = sd_cmd_SEND_TUNING_BLOCK,
>           [52 ... 54] = sd_cmd_illegal,
>           [58]        = sd_cmd_illegal,
>           [59]        = sd_cmd_illegal,


Re: [RFC PATCH 10/17] hw/sd: Add sd_cmd_SEND_TUNING_BLOCK() handler
Posted by Cédric Le Goater 3 years, 9 months ago
On 5/9/22 23:05, Philippe Mathieu-Daudé wrote:
> On 18/3/22 14:28, Cédric Le Goater wrote:
>> From: Joel Stanley <joel@jms.id.au>
>>
>> Signed-off-by: Joel Stanley <joel@jms.id.au>
>> Signed-off-by: Cédric Le Goater <clg@kaod.org>
>> ---
>>   hw/sd/sd.c | 28 +++++++++++++++++-----------
>>   1 file changed, 17 insertions(+), 11 deletions(-)
>>
>> diff --git a/hw/sd/sd.c b/hw/sd/sd.c
>> index 25e86c893bba..602ed6eb0701 100644
>> --- a/hw/sd/sd.c
>> +++ b/hw/sd/sd.c
>> @@ -1042,6 +1042,22 @@ static sd_rsp_type_t sd_cmd_SEND_RELATIVE_ADDR(SDState *sd, SDRequest req)
>>       }
>>   }
>> +static sd_rsp_type_t sd_cmd_SEND_TUNING_BLOCK(SDState *sd, SDRequest req)
>> +{
>> +        if (sd->spec_version < SD_PHY_SPECv3_01_VERS) {
>> +            return sd_invalid_state_for_cmd(sd, req);
> 
> There was a bug here, this should be:
> 
>                 return sd_illegal;
> 
> (see https://lore.kernel.org/qemu-devel/20220509141320.98374-1-philippe.mathieu.daude@gmail.com/. I can fix upon applying).

I missed that.

> 
> Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>

Thanks,

C.

>> +        }
>> +
>> +        if (sd->state != sd_transfer_state) {
>> +            return sd_invalid_state_for_cmd(sd, req);
>> +        }
>> +
>> +        sd->state = sd_sendingdata_state;
>> +        sd->data_offset = 0;
>> +
>> +        return sd_r1;
>> +}
>> +
>>   static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req)
>>   {
>>       uint32_t rca = 0x0000;
>> @@ -1285,17 +1301,6 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req)
>>           }
>>           break;
>> -    case 19:    /* CMD19: SEND_TUNING_BLOCK (SD) */
>> -        if (sd->spec_version < SD_PHY_SPECv3_01_VERS) {
>> -            break;
>> -        }
>> -        if (sd->state == sd_transfer_state) {
>> -            sd->state = sd_sendingdata_state;
>> -            sd->data_offset = 0;
>> -            return sd_r1;
>> -        }
>> -        break;
>> -
>>       case 23:    /* CMD23: SET_BLOCK_COUNT */
>>           if (sd->spec_version < SD_PHY_SPECv3_01_VERS) {
>>               break;
>> @@ -2132,6 +2137,7 @@ static const SDProto sd_proto_sd = {
>>           [2]         = sd_cmd_ALL_SEND_CID,
>>           [3]         = sd_cmd_SEND_RELATIVE_ADDR,
>>           [5]         = sd_cmd_illegal,
>> +        [19]        = sd_cmd_SEND_TUNING_BLOCK,
>>           [52 ... 54] = sd_cmd_illegal,
>>           [58]        = sd_cmd_illegal,
>>           [59]        = sd_cmd_illegal,
>