qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Philippe Mathieu-Daudé" <philmd@linaro.org>
To: Klaus Jensen <its@irrelevant.dk>, qemu-devel@nongnu.org
Cc: "Corey Minyard" <cminyard@mvista.com>,
	"Keith Busch" <kbusch@kernel.org>,
	"Jason Wang" <jasowang@redhat.com>,
	"Lior Weintraub" <liorw@pliops.com>,
	"Paolo Bonzini" <pbonzini@redhat.com>,
	"Jeremy Kerr" <jk@codeconstruct.com.au>,
	qemu-arm@nongnu.org, "Matt Johnston" <matt@codeconstruct.com.au>,
	"Peter Delevoryas" <peter@pjd.dev>,
	"Jonathan Cameron" <Jonathan.Cameron@huawei.com>,
	qemu-block@nongnu.org, "Cédric Le Goater" <clg@kaod.org>,
	"Klaus Jensen" <k.jensen@samsung.com>,
	"Peter Maydell" <peter.maydell@linaro.org>,
	gost.dev@samsung.com
Subject: Re: [PATCH v3 1/3] hw/i2c: add smbus pec utility function
Date: Thu, 1 Jun 2023 22:34:01 +0200	[thread overview]
Message-ID: <c2ed4756-1a5e-88b4-b02b-21660c041f7c@linaro.org> (raw)
In-Reply-To: <20230531114744.9946-2-its@irrelevant.dk>

On 31/5/23 13:47, Klaus Jensen wrote:
> From: Klaus Jensen <k.jensen@samsung.com>
> 
> Add i2c_smbus_pec() to calculate the SMBus Packet Error Code for a
> message.
> 
> Signed-off-by: Klaus Jensen <k.jensen@samsung.com>
> ---
>   hw/i2c/smbus_master.c         | 28 ++++++++++++++++++++++++++++
>   include/hw/i2c/smbus_master.h |  2 ++
>   2 files changed, 30 insertions(+)
> 
> diff --git a/hw/i2c/smbus_master.c b/hw/i2c/smbus_master.c
> index 6a53c34e70b7..47f9eb24e033 100644
> --- a/hw/i2c/smbus_master.c
> +++ b/hw/i2c/smbus_master.c
> @@ -15,6 +15,34 @@
>   #include "hw/i2c/i2c.h"
>   #include "hw/i2c/smbus_master.h"
>   
> +static uint8_t crc8(uint16_t data)
> +{
> +#define POLY (0x1070U << 3)

static const unsigned crc8_poly = ..., but why not inline the single use?
   data ^= 0x1070U << 3;
and
   data <<= 1;

> +    int i;
> +
> +    for (i = 0; i < 8; i++) {
> +        if (data & 0x8000) {
> +            data = data ^ POLY;
> +        }
> +
> +        data = data << 1;
> +    }
> +
> +    return (uint8_t)(data >> 8);
> +#undef POLY
> +}

We have "qemu/crc32c.h", maybe we could have a similar crc8.h. Just 
wondering...


  parent reply	other threads:[~2023-06-01 20:34 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-31 11:47 [PATCH v3 0/3] hw/{i2c, nvme}: mctp endpoint, nvme management interface model Klaus Jensen
2023-05-31 11:47 ` [PATCH v3 1/3] hw/i2c: add smbus pec utility function Klaus Jensen
2023-05-31 13:13   ` Jonathan Cameron via
2023-06-01 20:34   ` Philippe Mathieu-Daudé [this message]
2023-05-31 11:47 ` [PATCH v3 2/3] hw/i2c: add mctp core Klaus Jensen
2023-05-31 14:59   ` Jonathan Cameron via
2023-05-31 15:04     ` Jonathan Cameron via
2023-05-31 11:47 ` [PATCH v3 3/3] hw/nvme: add nvme management interface model Klaus Jensen
2023-05-31 15:39   ` Jonathan Cameron via
2023-06-01 19:42 ` [PATCH v3 0/3] hw/{i2c, nvme}: mctp endpoint, " Corey Minyard

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=c2ed4756-1a5e-88b4-b02b-21660c041f7c@linaro.org \
    --to=philmd@linaro.org \
    --cc=Jonathan.Cameron@huawei.com \
    --cc=clg@kaod.org \
    --cc=cminyard@mvista.com \
    --cc=gost.dev@samsung.com \
    --cc=its@irrelevant.dk \
    --cc=jasowang@redhat.com \
    --cc=jk@codeconstruct.com.au \
    --cc=k.jensen@samsung.com \
    --cc=kbusch@kernel.org \
    --cc=liorw@pliops.com \
    --cc=matt@codeconstruct.com.au \
    --cc=pbonzini@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=peter@pjd.dev \
    --cc=qemu-arm@nongnu.org \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).