All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Philippe Mathieu-Daudé" <f4bug@amsat.org>
To: Alistair Francis <alistair23@gmail.com>
Cc: Peter Maydell <peter.maydell@linaro.org>,
	"Edgar E . Iglesias" <edgar.iglesias@xilinx.com>,
	Paolo Bonzini <pbonzini@redhat.com>,
	Alistair Francis <alistair@alistair23.me>,
	Stefan Hajnoczi <stefanha@redhat.com>,
	"qemu-devel@nongnu.org Developers" <qemu-devel@nongnu.org>
Subject: Re: [Qemu-devel] [PATCH v2 04/14] sdcard: Extract sd_frame48/136_calc_checksum()
Date: Wed, 9 May 2018 21:16:44 -0300	[thread overview]
Message-ID: <025447ec-d2af-4f92-9cc0-6f59877e617a@amsat.org> (raw)
In-Reply-To: <CAKmqyKPnrF93GGY9YaqpjDLrnWPmEis8xt1SDm4GRhcvP2KTRQ@mail.gmail.com>

On 05/09/2018 08:04 PM, Alistair Francis wrote:
> On Wed, May 9, 2018 at 12:15 PM, Philippe Mathieu-Daudé <f4bug@amsat.org> wrote:
>> Hi Alistair,
>>
>> On 05/09/2018 03:00 PM, Alistair Francis wrote:
>>> On Tue, May 8, 2018 at 8:46 PM, Philippe Mathieu-Daudé <f4bug@amsat.org> wrote:
>>>> It will help when moving this around for qtesting in the next commit.
>>>>
>>>> Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
>>>> ---
>>>>  hw/sd/sd.c | 21 ++++++++++++++++++---
>>>>  1 file changed, 18 insertions(+), 3 deletions(-)
>>>>
>>>> diff --git a/hw/sd/sd.c b/hw/sd/sd.c
>>>> index 27a70896cd..06607115a7 100644
>>>> --- a/hw/sd/sd.c
>>>> +++ b/hw/sd/sd.c
>>>> @@ -273,6 +273,21 @@ static uint16_t sd_crc16(const void *message, size_t width)
>>>>      return shift_reg;
>>>>  }
>>>>
>>>> +enum {
>>>> +    F48_CONTENT_LENGTH  = 1 /* command */ + 4 /* argument */,
>>>> +    F136_CONTENT_LENGTH = 15,
>>>> +};
>>>> +
>>>> +static uint8_t sd_frame48_calc_checksum(const void *content)
>>>> +{
>>>> +    return sd_crc7(content, F48_CONTENT_LENGTH);
>>>> +}
>>>> +
>>>> +static uint8_t sd_frame136_calc_checksum(const void *content)
>>>> +{
>>>> +    return (sd_crc7(content, F136_CONTENT_LENGTH) << 1) | 1;
>>>> +}
>>>> +
>>>>  #define OCR_POWER_DELAY_NS      500000 /* 0.5ms */
>>>>
>>>>  FIELD(OCR, VDD_VOLTAGE_WINDOW,          0, 24)
>>>> @@ -352,7 +367,7 @@ static void sd_set_cid(SDState *sd)
>>>>      sd->cid[13] = 0x00 |       /* Manufacture date (MDT) */
>>>>          ((MDT_YR - 2000) / 10);
>>>>      sd->cid[14] = ((MDT_YR % 10) << 4) | MDT_MON;
>>>> -    sd->cid[15] = (sd_crc7(sd->cid, 15) << 1) | 1;
>>>> +    sd->cid[15] = sd_frame136_calc_checksum(sd->cid);
>>>>  }
>>>>
>>>>  #define HWBLOCK_SHIFT  9                       /* 512 bytes */
>>>> @@ -416,7 +431,7 @@ static void sd_set_csd(SDState *sd, uint64_t size)
>>>>          sd->csd[13] = 0x40;
>>>>          sd->csd[14] = 0x00;
>>>>      }
>>>> -    sd->csd[15] = (sd_crc7(sd->csd, 15) << 1) | 1;
>>>> +    sd->csd[15] = sd_frame136_calc_checksum(sd->csd);
>>>>  }
>>>>
>>>>  static void sd_set_rca(SDState *sd)
>>>> @@ -491,7 +506,7 @@ static int sd_req_crc_validate(SDRequest *req)
>>>>      buffer[0] = 0x40 | req->cmd;
>>>>      stl_be_p(&buffer[1], req->arg);
>>>>      return 0;
>>>> -    return sd_crc7(buffer, 5) != req->crc;     /* TODO */
>>>> +    return sd_frame48_calc_checksum(buffer) != req->crc; /* TODO */
>>>
>>> This 5 has changed to a 15. Is that on purpose? It should be mentioned
>>> in the commit message if it is.
>>
>> I just extracted this function:
>>
>>   static uint8_t sd_frame48_calc_checksum(const void *content)
>>   {
>>       return sd_crc7(content, F48_CONTENT_LENGTH);
>>   }
>>
>> Having:
>>
>>   enum {
>>       F48_CONTENT_LENGTH  = 1 /* command */ + 4 /* argument */,
>>
>> So F48_CONTENT_LENGTH = 5 as previous.
> 
> Ah, I missed the '+ 4 '. I just stopped reading at the comment.

This way looked clearer to me, but it might not be...
Would this be clearer?

   F48_CONTENT_LENGTH  = 1 + 4 /* command + argument */,

> 
> Looks good then:
> 
> Reviewed-by: Alistair Francis <alistair.francis@wdc.com>

Thanks for your review time :)

> 
> Alistair
> 
>>
>> This function is later verified with tests from patch 12 of this series.
>>
>>>
>>> Alistair
>>>
>>>>  }
>>>>
>>>>  static void sd_response_r1_make(SDState *sd, uint8_t *response)
>>>> --
>>>> 2.17.0
>>>>
>>>>

  reply	other threads:[~2018-05-10  0:16 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-09  3:46 [Qemu-devel] [PATCH v2 00/14] sdcard: Proper implementation of CRC7 Philippe Mathieu-Daudé
2018-05-09  3:46 ` [Qemu-devel] [PATCH v2 01/14] sdcard: Use the ldst API Philippe Mathieu-Daudé
2018-06-28 17:13   ` Peter Maydell
2018-05-09  3:46 ` [Qemu-devel] [PATCH v2 02/14] sdcard: Constify sd_crc*()'s message argument Philippe Mathieu-Daudé
2018-05-09 17:58   ` Alistair Francis
2018-05-09  3:46 ` [Qemu-devel] [PATCH v2 03/14] sdcard: Fix sd_crc*() style Philippe Mathieu-Daudé
2018-05-09  3:46 ` [Qemu-devel] [PATCH v2 04/14] sdcard: Extract sd_frame48/136_calc_checksum() Philippe Mathieu-Daudé
2018-05-09 18:00   ` Alistair Francis
2018-05-09 19:15     ` Philippe Mathieu-Daudé
2018-05-09 23:04       ` Alistair Francis
2018-05-10  0:16         ` Philippe Mathieu-Daudé [this message]
2018-05-10 17:41           ` Alistair Francis
2018-05-09  3:46 ` [Qemu-devel] [PATCH v2 05/14] sdcard: Move sd_crc7() and calc_checksum() out for qtesting Philippe Mathieu-Daudé
2018-05-09  3:46 ` [Qemu-devel] [PATCH v2 06/14] sdcard: Add test_sd_verify_cksum_frame136() Philippe Mathieu-Daudé
2018-05-09  3:46 ` [Qemu-devel] [PATCH v2 07/14] sdcard: Invert the sd_req_crc_is_valid() logic Philippe Mathieu-Daudé
2018-05-09 18:02   ` Alistair Francis
2018-05-09  3:46 ` [Qemu-devel] [PATCH v2 08/14] sdcard: Extract sd_frame48_verify_checksum() out for qtesting Philippe Mathieu-Daudé
2018-05-10  0:02   ` Alistair Francis
2018-05-09  3:46 ` [Qemu-devel] [PATCH v2 09/14] sdcard: Add sd_frame136_verify_checksum() Philippe Mathieu-Daudé
2018-05-09  3:46 ` [Qemu-devel] [PATCH v2 10/14] sdcard: Remove the SDRequest argument from internal functions Philippe Mathieu-Daudé
2018-05-09  3:46 ` [Qemu-devel] [PATCH v2 11/14] sdcard: Add sd_frame48_init(), replace SDRequest by a raw buffer Philippe Mathieu-Daudé
2018-05-09  3:46 ` [Qemu-devel] [PATCH v2 12/14] sdcard: Add tests to validate the 7-bit CRC checksum of 48-bit SD frame Philippe Mathieu-Daudé
2018-05-09  3:46 ` [Qemu-devel] [PATCH v2 13/14] sdcard: Add a "validate-crc" property Philippe Mathieu-Daudé
2018-05-21 12:59   ` Michael Walle
2018-05-09  3:46 ` [Qemu-devel] [RFC PATCH v2 14/14] hw/sd/ssi-sd: Enable CRC validation Philippe Mathieu-Daudé
2018-05-09 23:06   ` Alistair Francis
2018-05-10 15:18 ` [Qemu-devel] [PATCH v2 00/14] sdcard: Proper implementation of CRC7 Peter Maydell

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=025447ec-d2af-4f92-9cc0-6f59877e617a@amsat.org \
    --to=f4bug@amsat.org \
    --cc=alistair23@gmail.com \
    --cc=alistair@alistair23.me \
    --cc=edgar.iglesias@xilinx.com \
    --cc=pbonzini@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.