All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Philippe Mathieu-Daudé" <f4bug@amsat.org>
To: Peter Maydell <peter.maydell@linaro.org>,
	"Edgar E . Iglesias" <edgar.iglesias@xilinx.com>
Cc: qemu-devel@nongnu.org, Paolo Bonzini <pbonzini@redhat.com>,
	Stefan Hajnoczi <stefanha@redhat.com>,
	Alistair Francis <alistair@alistair23.me>
Subject: Re: [Qemu-devel] [PATCH 17/20] sdcard: Add SDFrameData struct and data frame checksum functions
Date: Fri, 4 May 2018 23:22:17 -0300	[thread overview]
Message-ID: <d611dc36-e429-eb13-a2ec-573b0bb06413@amsat.org> (raw)
In-Reply-To: <20180504155918.21287-18-f4bug@amsat.org>

On 05/04/2018 12:59 PM, Philippe Mathieu-Daudé wrote:
> The block transfers data frames are upto 512 bytes and use a 16-bit CRC.
> 
> Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
> ---
>  include/hw/sd/sd.h     | 29 +++++++++++++++++++++++++++++
>  hw/sd/sdmmc-internal.c | 10 ++++++++++
>  2 files changed, 39 insertions(+)
> 
> diff --git a/include/hw/sd/sd.h b/include/hw/sd/sd.h
> index c76be51b32..6bf9daf559 100644
> --- a/include/hw/sd/sd.h
> +++ b/include/hw/sd/sd.h
> @@ -102,6 +102,17 @@ typedef struct SDFrame136 {
>      uint8_t crc;
>  } SDFrame136;
>  
> +/**
> + * SDFrameData: 512 bytes block transfers
> + *
> + * @content: block data
> + * @crc:     16-bit CRC checksum
> + */
> +typedef struct SDFrameData {
> +    uint8_t content[512];
> +    uint16_t crc;
> +} SDFrameData;
> +
>  typedef struct SDFrame48 SDRequest;
>  
>  typedef struct SDState SDState;
> @@ -212,6 +223,14 @@ void sd_update_frame48_checksum(SDFrame48 *frame, bool is_response);
>   */
>  void sd_update_frame136_checksum(SDFrame136 *frame);
>  
> +/**
> + * sd_update_framedata_checksum:
> + * @frame: the #SDFrameData to verify
> + *
> + * Update the 16-bit CRC checksum of a SD data frame (up to 512 bytes).
> + */
> +void sd_update_framedata_checksum(SDFrameData *frame);

Since the frame size is variable, this function needs a size_t argument.

> +
>  /**
>   * sd_verify_frame48_checksum:
>   * @frame: the #SDFrame48 to verify
> @@ -233,6 +252,16 @@ bool sd_verify_frame48_checksum(SDFrame48 *frame, bool is_response);
>   */
>  bool sd_verify_frame136_checksum(SDFrame136 *frame);
>  
> +/**
> + * sd_verify_framedata_checksum:
> + * @frame: the #SDFrameData to verify
> + *
> + * Verify the 16-bit CRC checksum of a SD data frame.
> + *
> + * Returns: A boolean indicating whether the frame 16-bit CRC is correct.
> + */
> +bool sd_verify_framedata_checksum(SDFrameData *frame);

Ditto.

> +
>  /* Legacy functions to be used only by non-qdevified callers */
>  SDState *sd_init(BlockBackend *bs, bool is_spi);
>  int sd_do_command(SDState *sd, SDRequest *req,
> diff --git a/hw/sd/sdmmc-internal.c b/hw/sd/sdmmc-internal.c
> index 68350a2304..0e82e69d99 100644
> --- a/hw/sd/sdmmc-internal.c
> +++ b/hw/sd/sdmmc-internal.c
> @@ -134,6 +134,11 @@ bool sd_verify_frame136_checksum(SDFrame136 *frame)
>      return sd_calc_frame136_crc7(frame) == frame->crc;
>  }
>  
> +bool sd_verify_framedata_checksum(SDFrameData *frame)
> +{
> +    return sd_crc16(frame->content, sizeof(frame->content)) == frame->crc;

I'll probably replace sizeof(frame->content) by a 'length' argument,
or add a 'length' member to SDFrameData.

> +}
> +
>  void sd_update_frame48_checksum(SDFrame48 *frame, bool is_response)
>  {
>      frame->crc = sd_calc_frame48_crc7(frame->cmd, frame->arg, is_response);
> @@ -144,6 +149,11 @@ void sd_update_frame136_checksum(SDFrame136 *frame)
>      frame->crc = (sd_crc7(frame->content, sizeof(frame->content)) << 1) | 1;
>  }
>  
> +void sd_update_framedata_checksum(SDFrameData *frame)
> +{
> +    frame->crc = sd_crc16(frame->content, sizeof(frame->content));
> +}
> +
>  void sd_prepare_frame48(SDFrame48 *frame, uint8_t cmd, uint32_t arg,
>                          bool is_response, bool gen_crc)
>  {
> 

  reply	other threads:[~2018-05-05  2:22 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-04 15:58 [Qemu-devel] [PATCH 00/20] sdcard: proper implementation of CRC Philippe Mathieu-Daudé
2018-05-04 15:58 ` [Qemu-devel] [PATCH 01/20] sdcard: Use the ldst API Philippe Mathieu-Daudé
2018-05-04 15:59 ` [Qemu-devel] [PATCH 02/20] sdcard: Extract sd_calc_frame48_crc7() from sd_req_crc_validate() Philippe Mathieu-Daudé
2018-05-04 15:59 ` [Qemu-devel] [PATCH 03/20] sdcard: Rename the SDRequest as SDFrame48 Philippe Mathieu-Daudé
2018-05-04 15:59 ` [Qemu-devel] [PATCH 04/20] sdcard: Add sd_prepare_request[_with_crc]() Philippe Mathieu-Daudé
2018-05-04 15:59 ` [Qemu-devel] [PATCH 05/20] sdcard: Use the sd_prepare_request*() functions Philippe Mathieu-Daudé
2018-05-04 15:59 ` [Qemu-devel] [PATCH 06/20] sdcard: Add a "validate-crc" property Philippe Mathieu-Daudé
2018-05-04 23:33   ` Alistair Francis
2018-05-04 15:59 ` [Qemu-devel] [PATCH 07/20] sdcard: Constify sd_crc*()'s message argument Philippe Mathieu-Daudé
2018-05-04 15:59 ` [Qemu-devel] [PATCH 08/20] sdcard: Fix sd_crc*() style Philippe Mathieu-Daudé
2018-05-04 23:34   ` Alistair Francis
2018-05-04 15:59 ` [Qemu-devel] [PATCH 09/20] sdcard: Expose sd_crc*() functions for QTest use Philippe Mathieu-Daudé
2018-05-04 15:59 ` [Qemu-devel] [PATCH 10/20] sdcard: Expose sd_prepare_request*() " Philippe Mathieu-Daudé
2018-05-04 15:59 ` [Qemu-devel] [PATCH 11/20] sdcard: Add test_sd_request_frame_crc7() qtest (request command CRC7) Philippe Mathieu-Daudé
2018-05-04 15:59 ` [Qemu-devel] [PATCH 12/20] sdcard: Let sd_frame48_crc7_calc() work on response frames Philippe Mathieu-Daudé
2018-05-04 15:59 ` [Qemu-devel] [PATCH 13/20] sdcard: Expose sd_prepare_frame48() for QTest use Philippe Mathieu-Daudé
2018-05-04 15:59 ` [Qemu-devel] [PATCH 14/20] sdcard: Add test_sd_response_frame48_crc7 qtest (command response CRC7) Philippe Mathieu-Daudé
2018-05-04 15:59 ` [Qemu-devel] [PATCH 15/20] sdcard: Add SDFrame136 struct and 136-bit SD response frames functions Philippe Mathieu-Daudé
2018-05-04 16:57   ` Philippe Mathieu-Daudé
2018-05-04 15:59 ` [Qemu-devel] [PATCH 16/20] sdcard: Add test_sd_response_frame136_crc7() qtest Philippe Mathieu-Daudé
2018-05-04 15:59 ` [Qemu-devel] [PATCH 17/20] sdcard: Add SDFrameData struct and data frame checksum functions Philippe Mathieu-Daudé
2018-05-05  2:22   ` Philippe Mathieu-Daudé [this message]
2018-05-04 15:59 ` [Qemu-devel] [PATCH 18/20] sdcard: Fix sd_crc16() Philippe Mathieu-Daudé
2018-05-04 15:59 ` [Qemu-devel] [PATCH 19/20] sdcard: Add test_sd_data_frame_crc16() qtest Philippe Mathieu-Daudé
2018-05-04 15:59 ` [Qemu-devel] [PATCH 20/20] sdcard: Add test_sd_verify_cksum_frame48() qtest Philippe Mathieu-Daudé
2018-05-07 20:09 ` [Qemu-devel] [PATCH 00/20] sdcard: proper implementation of CRC Philippe Mathieu-Daudé

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=d611dc36-e429-eb13-a2ec-573b0bb06413@amsat.org \
    --to=f4bug@amsat.org \
    --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.