qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Thomas Huth <thuth@redhat.com>
To: Peter Maydell <peter.maydell@linaro.org>,
	qemu-arm@nongnu.org, qemu-devel@nongnu.org
Cc: Beniamino Galvani <b.galvani@gmail.com>,
	Strahinja Jankovic <strahinja.p.jankovic@gmail.com>,
	qemu-stable@nongnu.org, qemu-s390x <qemu-s390x@nongnu.org>
Subject: Re: [PATCH 2/2] hw/net/allwinner-sun8i-emac: Correctly byteswap descriptor fields
Date: Mon, 24 Apr 2023 19:36:35 +0200	[thread overview]
Message-ID: <b8d82416-26a1-06cf-ba72-46845fcbf254@redhat.com> (raw)
In-Reply-To: <20230424165053.1428857-3-peter.maydell@linaro.org>

On 24/04/2023 18.50, Peter Maydell wrote:
> In allwinner-sun8i-emac we just read directly from guest memory into
> a host FrameDescriptor struct and back.  This only works on
> little-endian hosts.  Reading and writing of descriptors is already
> abstracted into functions; make those functions also handle the
> byte-swapping so that TransferDescriptor structs as seen by the rest
> of the code are always in host-order, and fix two places that were
> doing ad-hoc descriptor reading without using the functions.
> 
> Cc: qemu-stable@nongnu.org
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
> ---
>   hw/net/allwinner-sun8i-emac.c | 22 +++++++++++++++-------
>   1 file changed, 15 insertions(+), 7 deletions(-)
> 
> diff --git a/hw/net/allwinner-sun8i-emac.c b/hw/net/allwinner-sun8i-emac.c
> index b861d8ff352..fac4405f452 100644
> --- a/hw/net/allwinner-sun8i-emac.c
> +++ b/hw/net/allwinner-sun8i-emac.c
> @@ -350,8 +350,13 @@ static void allwinner_sun8i_emac_get_desc(AwSun8iEmacState *s,
>                                             FrameDescriptor *desc,
>                                             uint32_t phys_addr)
>   {
> -    dma_memory_read(&s->dma_as, phys_addr, desc, sizeof(*desc),
> +    uint32_t desc_words[4];
> +    dma_memory_read(&s->dma_as, phys_addr, &desc_words, sizeof(desc_words),
>                       MEMTXATTRS_UNSPECIFIED);
> +    desc->status = le32_to_cpu(desc_words[0]);
> +    desc->status2 = le32_to_cpu(desc_words[1]);
> +    desc->addr = le32_to_cpu(desc_words[2]);
> +    desc->next = le32_to_cpu(desc_words[3]);
>   }
>   
>   static uint32_t allwinner_sun8i_emac_next_desc(AwSun8iEmacState *s,
> @@ -400,10 +405,15 @@ static uint32_t allwinner_sun8i_emac_tx_desc(AwSun8iEmacState *s,
>   }
>   
>   static void allwinner_sun8i_emac_flush_desc(AwSun8iEmacState *s,
> -                                            FrameDescriptor *desc,
> +                                            const FrameDescriptor *desc,
>                                               uint32_t phys_addr)
>   {
> -    dma_memory_write(&s->dma_as, phys_addr, desc, sizeof(*desc),
> +    uint32_t desc_words[4];
> +    desc_words[0] = cpu_to_le32(desc->status);
> +    desc_words[1] = cpu_to_le32(desc->status2);
> +    desc_words[2] = cpu_to_le32(desc->addr);
> +    desc_words[3] = cpu_to_le32(desc->next);
> +    dma_memory_write(&s->dma_as, phys_addr, &desc_words, sizeof(desc_words),
>                        MEMTXATTRS_UNSPECIFIED);
>   }
>   
> @@ -638,8 +648,7 @@ static uint64_t allwinner_sun8i_emac_read(void *opaque, hwaddr offset,
>           break;
>       case REG_TX_CUR_BUF:        /* Transmit Current Buffer */
>           if (s->tx_desc_curr != 0) {
> -            dma_memory_read(&s->dma_as, s->tx_desc_curr, &desc, sizeof(desc),
> -                            MEMTXATTRS_UNSPECIFIED);
> +            allwinner_sun8i_emac_get_desc(s, &desc, s->tx_desc_curr);
>               value = desc.addr;
>           } else {
>               value = 0;
> @@ -652,8 +661,7 @@ static uint64_t allwinner_sun8i_emac_read(void *opaque, hwaddr offset,
>           break;
>       case REG_RX_CUR_BUF:        /* Receive Current Buffer */
>           if (s->rx_desc_curr != 0) {
> -            dma_memory_read(&s->dma_as, s->rx_desc_curr, &desc, sizeof(desc),
> -                            MEMTXATTRS_UNSPECIFIED);
> +            allwinner_sun8i_emac_get_desc(s, &desc, s->rx_desc_curr);
>               value = desc.addr;
>           } else {
>               value = 0;

Reviewed-by: Thomas Huth <thuth@redhat.com>



  reply	other threads:[~2023-04-24 17:37 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-24 16:50 [PATCH 0/2] arm: allwinner: fix endianness bugs in sdhost and sun8i-emac Peter Maydell
2023-04-24 16:50 ` [PATCH 1/2] hw/sd/allwinner-sdhost: Correctly byteswap descriptor fields Peter Maydell
2023-04-24 17:32   ` Thomas Huth
2023-04-24 17:42   ` Alex Bennée
2023-04-25 15:46   ` Philippe Mathieu-Daudé
2023-04-24 16:50 ` [PATCH 2/2] hw/net/allwinner-sun8i-emac: " Peter Maydell
2023-04-24 17:36   ` Thomas Huth [this message]
2023-04-24 17:44   ` Alex Bennée
2023-04-25 15:45   ` Philippe Mathieu-Daudé
2023-05-02 10:34 ` [PATCH 0/2] arm: allwinner: fix endianness bugs in sdhost and sun8i-emac 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=b8d82416-26a1-06cf-ba72-46845fcbf254@redhat.com \
    --to=thuth@redhat.com \
    --cc=b.galvani@gmail.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-arm@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-s390x@nongnu.org \
    --cc=qemu-stable@nongnu.org \
    --cc=strahinja.p.jankovic@gmail.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 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).