[PATCH] hw/net/allwinner-sun8i-emac: Flush queued packets when rx is enabled

iyzsong@envs.net posted 1 patch 1 month ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20260430040753.3337-1-iyzsong@envs.net
Maintainers: Peter Maydell <peter.maydell@linaro.org>, Strahinja Jankovic <strahinja.p.jankovic@gmail.com>, Jason Wang <jasowang@redhat.com>
hw/net/allwinner-sun8i-emac.c | 4 ++++
1 file changed, 4 insertions(+)
[PATCH] hw/net/allwinner-sun8i-emac: Flush queued packets when rx is enabled
Posted by iyzsong@envs.net 1 month ago
From: 宋文武 <iyzsong@member.fsf.org>

Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3459
Signed-off-by: 宋文武 <iyzsong@member.fsf.org>
---
 hw/net/allwinner-sun8i-emac.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/hw/net/allwinner-sun8i-emac.c b/hw/net/allwinner-sun8i-emac.c
index 9b7c67ae8e..7cc06b73c2 100644
--- a/hw/net/allwinner-sun8i-emac.c
+++ b/hw/net/allwinner-sun8i-emac.c
@@ -727,6 +727,10 @@ static void allwinner_sun8i_emac_write(void *opaque, hwaddr offset,
         break;
     case REG_RX_CTL_0:          /* Receive Control 0 */
         s->rx_ctl0 = value;
+        if ((value & RX_CTL0_RX_EN) &&
+             allwinner_sun8i_emac_can_receive(nc)) {
+            qemu_flush_queued_packets(nc);
+        }
         break;
     case REG_RX_CTL_1:          /* Receive Control 1 */
         s->rx_ctl1 = value | RX_CTL1_RX_MD;
-- 
2.52.0


Re: [PATCH] hw/net/allwinner-sun8i-emac: Flush queued packets when rx is enabled
Posted by Peter Maydell 1 month ago
On Thu, 30 Apr 2026 at 05:08, <iyzsong@envs.net> wrote:
>
> From: 宋文武 <iyzsong@member.fsf.org>
>
> Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3459
> Signed-off-by: 宋文武 <iyzsong@member.fsf.org>
> ---
>  hw/net/allwinner-sun8i-emac.c | 4 ++++
>  1 file changed, 4 insertions(+)
>
> diff --git a/hw/net/allwinner-sun8i-emac.c b/hw/net/allwinner-sun8i-emac.c
> index 9b7c67ae8e..7cc06b73c2 100644
> --- a/hw/net/allwinner-sun8i-emac.c
> +++ b/hw/net/allwinner-sun8i-emac.c
> @@ -727,6 +727,10 @@ static void allwinner_sun8i_emac_write(void *opaque, hwaddr offset,
>          break;
>      case REG_RX_CTL_0:          /* Receive Control 0 */
>          s->rx_ctl0 = value;
> +        if ((value & RX_CTL0_RX_EN) &&
> +             allwinner_sun8i_emac_can_receive(nc)) {
> +            qemu_flush_queued_packets(nc);
> +        }
>          break;
>      case REG_RX_CTL_1:          /* Receive Control 1 */
>          s->rx_ctl1 = value | RX_CTL1_RX_MD;

Thanks for this patch; I've queued it to target-arm.next with
an expanded commit message.

I dropped the direct check on (value & RX_CTL0_RX_EN), because
allwinner_sun8i_emac_can_receive() also checks
(s->rx_ctl0 & RX_CTL0_RX_EN) and won't return true unless it's
set, so we don't need to check the same thing twice; so the
patch as I have it is:

@@ -727,6 +727,9 @@ static void allwinner_sun8i_emac_write(void
*opaque, hwaddr offset,
         break;
     case REG_RX_CTL_0:          /* Receive Control 0 */
         s->rx_ctl0 = value;
+        if (allwinner_sun8i_emac_can_receive(nc)) {
+            qemu_flush_queued_packets(nc);
+        }
         break;
     case REG_RX_CTL_1:          /* Receive Control 1 */
         s->rx_ctl1 = value | RX_CTL1_RX_MD;

thanks
-- PMM