qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Fam Zheng <famz@redhat.com>
To: qemu-devel@nongnu.org
Cc: Peter Maydell <peter.maydell@linaro.org>,
	Peter Crosthwaite <peter.crosthwaite@xilinx.com>,
	Rob Herring <robh@kernel.org>,
	jasowang@redhat.com, Michael Walle <michael@walle.cc>,
	Gerd Hoffmann <kraxel@redhat.com>,
	stefanha@redhat.com,
	"Edgar E. Iglesias" <edgar.iglesias@gmail.com>
Subject: [Qemu-devel] [PATCH v2 for-2.4 08/12] milkymist-minimac2: Flush queued packets when link comes up
Date: Wed, 15 Jul 2015 18:19:09 +0800	[thread overview]
Message-ID: <1436955553-22791-9-git-send-email-famz@redhat.com> (raw)
In-Reply-To: <1436955553-22791-1-git-send-email-famz@redhat.com>

Drop .can_receive and move the semantics into minimac2_rx, by returning
0.

That is once minimac2_rx returns 0, incoming packets will be queued
until the queue is explicitly flushed. We do this when s->regs[R_STATE0]
or s->regs[R_STATE1] is changed in minimac2_write.

Also drop the unused trace point.

Signed-off-by: Fam Zheng <famz@redhat.com>
---
 hw/net/milkymist-minimac2.c | 33 ++++++++++++++++-----------------
 trace-events                |  1 -
 2 files changed, 16 insertions(+), 18 deletions(-)

diff --git a/hw/net/milkymist-minimac2.c b/hw/net/milkymist-minimac2.c
index f06afaa..5d1cf08 100644
--- a/hw/net/milkymist-minimac2.c
+++ b/hw/net/milkymist-minimac2.c
@@ -303,8 +303,7 @@ static ssize_t minimac2_rx(NetClientState *nc, const uint8_t *buf, size_t size)
         r_state = R_STATE1;
         rx_buf = s->rx1_buf;
     } else {
-        trace_milkymist_minimac2_drop_rx_frame(buf);
-        return size;
+        return 0;
     }
 
     /* assemble frame */
@@ -354,6 +353,18 @@ minimac2_read(void *opaque, hwaddr addr, unsigned size)
     return r;
 }
 
+static int minimac2_can_rx(MilkymistMinimac2State *s)
+{
+    if (s->regs[R_STATE0] == STATE_LOADED) {
+        return 1;
+    }
+    if (s->regs[R_STATE1] == STATE_LOADED) {
+        return 1;
+    }
+
+    return 0;
+}
+
 static void
 minimac2_write(void *opaque, hwaddr addr, uint64_t value,
                unsigned size)
@@ -387,6 +398,9 @@ minimac2_write(void *opaque, hwaddr addr, uint64_t value,
     case R_STATE1:
         s->regs[addr] = value;
         update_rx_interrupt(s);
+        if (minimac2_can_rx(s)) {
+            qemu_flush_queued_packets(qemu_get_queue(s->nic));
+        }
         break;
     case R_SETUP:
     case R_COUNT0:
@@ -411,20 +425,6 @@ static const MemoryRegionOps minimac2_ops = {
     .endianness = DEVICE_NATIVE_ENDIAN,
 };
 
-static int minimac2_can_rx(NetClientState *nc)
-{
-    MilkymistMinimac2State *s = qemu_get_nic_opaque(nc);
-
-    if (s->regs[R_STATE0] == STATE_LOADED) {
-        return 1;
-    }
-    if (s->regs[R_STATE1] == STATE_LOADED) {
-        return 1;
-    }
-
-    return 0;
-}
-
 static void milkymist_minimac2_reset(DeviceState *d)
 {
     MilkymistMinimac2State *s = MILKYMIST_MINIMAC2(d);
@@ -445,7 +445,6 @@ static void milkymist_minimac2_reset(DeviceState *d)
 static NetClientInfo net_milkymist_minimac2_info = {
     .type = NET_CLIENT_OPTIONS_KIND_NIC,
     .size = sizeof(NICState),
-    .can_receive = minimac2_can_rx,
     .receive = minimac2_rx,
 };
 
diff --git a/trace-events b/trace-events
index 2d395c5..94bf3bb 100644
--- a/trace-events
+++ b/trace-events
@@ -828,7 +828,6 @@ milkymist_minimac2_mdio_write(uint8_t phy_addr, uint8_t addr, uint16_t value) "p
 milkymist_minimac2_mdio_read(uint8_t phy_addr, uint8_t addr, uint16_t value) "phy_addr %02x addr %02x value %04x"
 milkymist_minimac2_tx_frame(uint32_t length) "length %u"
 milkymist_minimac2_rx_frame(const void *buf, uint32_t length) "buf %p length %u"
-milkymist_minimac2_drop_rx_frame(const void *buf) "buf %p"
 milkymist_minimac2_rx_transfer(const void *buf, uint32_t length) "buf %p length %d"
 milkymist_minimac2_raise_irq_rx(void) "Raise IRQ RX"
 milkymist_minimac2_lower_irq_rx(void) "Lower IRQ RX"
-- 
2.4.3

  parent reply	other threads:[~2015-07-15 10:20 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-15 10:19 [Qemu-devel] [PATCH v2 for-2.4 00/12] hw/net: Fix .can_receive() for NICs Fam Zheng
2015-07-15 10:19 ` [Qemu-devel] [PATCH v2 for-2.4 01/12] xgmac: Drop packets with eth_can_rx is false Fam Zheng
2015-07-15 10:19 ` [Qemu-devel] [PATCH v2 for-2.4 02/12] pcnet: Drop pcnet_can_receive Fam Zheng
2015-07-15 10:19 ` [Qemu-devel] [PATCH v2 for-2.4 03/12] eepro100: Drop nic_can_receive Fam Zheng
2015-07-15 10:19 ` [Qemu-devel] [PATCH v2 for-2.4 04/12] usbnet: Drop usbnet_can_receive Fam Zheng
2015-07-15 10:19 ` [Qemu-devel] [PATCH v2 for-2.4 05/12] etsec: Move etsec_can_receive into etsec_receive Fam Zheng
2015-07-15 10:19 ` [Qemu-devel] [PATCH v2 for-2.4 06/12] etsec: Flush queue when rx buffer is consumed Fam Zheng
2015-07-15 10:19 ` [Qemu-devel] [PATCH v2 for-2.4 07/12] mcf_fec: Drop mcf_fec_can_receive Fam Zheng
2015-07-15 10:19 ` Fam Zheng [this message]
2015-07-15 10:19 ` [Qemu-devel] [PATCH v2 for-2.4 09/12] mipsnet: Flush queued packets when receiving is enabled Fam Zheng
2015-07-15 10:19 ` [Qemu-devel] [PATCH v2 for-2.4 10/12] stellaris_enet: Flush queued packets when read done Fam Zheng
2015-07-15 10:19 ` [Qemu-devel] [PATCH v2 for-2.4 11/12] dp8393x: Flush packets when link comes up Fam Zheng
2015-07-15 10:19 ` [Qemu-devel] [PATCH v2 for-2.4 12/12] axienet: Flush queued packets when rx is done Fam Zheng
2015-07-16  2:58   ` Jason Wang
2015-07-16  3:32     ` Fam Zheng
2015-07-16  5:38       ` Jason Wang
2015-07-16  5:38 ` [Qemu-devel] [PATCH v2 for-2.4 00/12] hw/net: Fix .can_receive() for NICs Jason Wang
2015-07-20 17:09 ` 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=1436955553-22791-9-git-send-email-famz@redhat.com \
    --to=famz@redhat.com \
    --cc=edgar.iglesias@gmail.com \
    --cc=jasowang@redhat.com \
    --cc=kraxel@redhat.com \
    --cc=michael@walle.cc \
    --cc=peter.crosthwaite@xilinx.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=robh@kernel.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 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).