qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Jason Wang <jasowang@redhat.com>
To: qemu-devel@nongnu.org
Cc: Peter Maydell <peter.maydell@linaro.org>,
	Jason Wang <jasowang@redhat.com>
Subject: [PULL 04/12] hw/net/npcm_gmac.c: Unify length and prev_buf_size variables
Date: Mon, 21 Jul 2025 13:59:19 +0800	[thread overview]
Message-ID: <20250721055927.75951-5-jasowang@redhat.com> (raw)
In-Reply-To: <20250721055927.75951-1-jasowang@redhat.com>

From: Peter Maydell <peter.maydell@linaro.org>

After the bug fix in the previous commit, the length and prev_buf_size
variables are identical, except that prev_buf_size is uint32_t and
length is uint16_t. We can therefore unify them. The only place where
the type makes a difference is that we will truncate the packet
at 64K when sending it; this commit preserves that behaviour
by using a local variable when doing the packet send.

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Jason Wang <jasowang@redhat.com>
---
 hw/net/npcm_gmac.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/hw/net/npcm_gmac.c b/hw/net/npcm_gmac.c
index 921327dd8c..a0050a7725 100644
--- a/hw/net/npcm_gmac.c
+++ b/hw/net/npcm_gmac.c
@@ -516,7 +516,6 @@ static void gmac_try_send_next_packet(NPCMGMACState *gmac)
     uint32_t desc_addr;
     struct NPCMGMACTxDesc tx_desc;
     uint32_t tx_buf_addr, tx_buf_len;
-    uint16_t length = 0;
     uint8_t *buf = tx_send_buffer;
     uint32_t prev_buf_size = 0;
     int csum = 0;
@@ -583,7 +582,6 @@ static void gmac_try_send_next_packet(NPCMGMACState *gmac)
                         __func__, tx_buf_addr);
             return;
         }
-        length += tx_buf_len;
         prev_buf_size += tx_buf_len;
 
         /* If not chained we'll have a second buffer. */
@@ -606,15 +604,18 @@ static void gmac_try_send_next_packet(NPCMGMACState *gmac)
                               __func__, tx_buf_addr);
                 return;
             }
-            length += tx_buf_len;
             prev_buf_size += tx_buf_len;
         }
         if (tx_desc.tdes1 & TX_DESC_TDES1_LAST_SEG_MASK) {
+            /*
+             * This will truncate the packet at 64K.
+             * TODO: find out if this is the correct behaviour.
+             */
+            uint16_t length = prev_buf_size;
             net_checksum_calculate(tx_send_buffer, length, csum);
             qemu_send_packet(qemu_get_queue(gmac->nic), tx_send_buffer, length);
             trace_npcm_gmac_packet_sent(DEVICE(gmac)->canonical_path, length);
             buf = tx_send_buffer;
-            length = 0;
             prev_buf_size = 0;
         }
 
-- 
2.42.0



  parent reply	other threads:[~2025-07-21  6:03 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-07-21  5:59 [PULL 00/12] Net patches Jason Wang
2025-07-21  5:59 ` [PULL 01/12] net/tap: drop too small packets Jason Wang
2025-07-21  5:59 ` [PULL 02/12] tap: fix net_init_tap() return code Jason Wang
2025-07-21  5:59 ` [PULL 03/12] hw/net/npcm_gmac.c: Send the right data for second packet in a row Jason Wang
2025-07-21  5:59 ` Jason Wang [this message]
2025-07-21  5:59 ` [PULL 05/12] hw/net/npcm_gmac.c: Correct test for when to reallocate packet buffer Jason Wang
2025-07-21  5:59 ` [PULL 06/12] hw/net/npcm_gmac.c: Drop 'buf' local variable Jason Wang
2025-07-21  5:59 ` [PULL 07/12] net/passt: Remove unused "err" from passt_vhost_user_event() (CID 1612375) Jason Wang
2025-07-21  5:59 ` [PULL 08/12] net/vhost-user: Remove unused "err" from net_vhost_user_event() (CID 1612372) Jason Wang
2025-07-21  5:59 ` [PULL 09/12] net/passt: Remove dead code in passt_vhost_user_start error path (CID 1612371) Jason Wang
2025-07-21  5:59 ` [PULL 10/12] net/passt: Check return value of g_remove() in net_passt_cleanup() (CID 1612369) Jason Wang
2025-07-21  5:59 ` [PULL 11/12] net/passt: Initialize "error" variable in net_passt_send() (CID 1612368) Jason Wang
2025-07-21  5:59 ` [PULL 12/12] net/vhost-user: Remove unused "err" from chr_closed_bh() (CID 1612365) Jason Wang
2025-07-21 13:59 ` [PULL 00/12] Net patches Stefan Hajnoczi

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=20250721055927.75951-5-jasowang@redhat.com \
    --to=jasowang@redhat.com \
    --cc=peter.maydell@linaro.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).