qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Amos Kong <akong@redhat.com>
To: qemu-devel@nongnu.org
Cc: somlo@cmu.edu, marcel.a@redhat.com, jasowang@redhat.com,
	stefanha@redhat.com, mst@redhat.com
Subject: [Qemu-devel] [PATCH 1/2] e1000: defer packets until BM enabled
Date: Thu, 18 Dec 2014 17:22:18 +0800	[thread overview]
Message-ID: <1418894539-13990-2-git-send-email-akong@redhat.com> (raw)
In-Reply-To: <1418894539-13990-1-git-send-email-akong@redhat.com>

From: "Michael S. Tsirkin" <mst@redhat.com>

Some guests seem to set BM for e1000 after enabling RX.
If packets arrive in the window, device is wedged.
Probably works by luck on real hardware, work around
this by making can_receive depend on BM. This patch
defer transmit packets, only start transmit when BM
is enabled.

Tested-by: Gabriel Somlo <somlo@cmu.edu>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Amos Kong <akong@redhat.com>
---
 hw/net/e1000.c | 27 ++++++++++++++++++++++++++-
 1 file changed, 26 insertions(+), 1 deletion(-)

diff --git a/hw/net/e1000.c b/hw/net/e1000.c
index e33a4da..ec9224b 100644
--- a/hw/net/e1000.c
+++ b/hw/net/e1000.c
@@ -33,6 +33,7 @@
 #include "sysemu/sysemu.h"
 #include "sysemu/dma.h"
 #include "qemu/iov.h"
+#include "qemu/range.h"
 
 #include "e1000_regs.h"
 
@@ -790,6 +791,11 @@ start_xmit(E1000State *s)
     struct e1000_tx_desc desc;
     uint32_t tdh_start = s->mac_reg[TDH], cause = E1000_ICS_TXQE;
 
+    if (!(d->config[PCI_COMMAND] & PCI_COMMAND_MASTER)) {
+        DBGOUT(TX, "BM disabled\n");
+        return;
+    }
+
     if (!(s->mac_reg[TCTL] & E1000_TCTL_EN)) {
         DBGOUT(TX, "tx disabled\n");
         return;
@@ -923,7 +929,9 @@ e1000_can_receive(NetClientState *nc)
     E1000State *s = qemu_get_nic_opaque(nc);
 
     return (s->mac_reg[STATUS] & E1000_STATUS_LU) &&
-        (s->mac_reg[RCTL] & E1000_RCTL_EN) && e1000_has_rxbufs(s, 1);
+        (s->mac_reg[RCTL] & E1000_RCTL_EN) &&
+        (s->parent_obj.config[PCI_COMMAND] & PCI_COMMAND_MASTER) &&
+        e1000_has_rxbufs(s, 1);
 }
 
 static uint64_t rx_desc_base(E1000State *s)
@@ -1529,6 +1537,21 @@ static NetClientInfo net_e1000_info = {
     .link_status_changed = e1000_set_link_status,
 };
 
+static void e1000_write_config(PCIDevice *pci_dev, uint32_t address,
+                                uint32_t val, int len)
+{
+    E1000State *s = E1000(pci_dev);
+
+    pci_default_write_config(pci_dev, address, val, len);
+
+    if (range_covers_byte(address, len, PCI_COMMAND) &&
+        (pci_dev->config[PCI_COMMAND] & PCI_COMMAND_MASTER)) {
+        qemu_flush_queued_packets(qemu_get_queue(s->nic));
+        start_xmit(s);
+    }
+}
+
+
 static int pci_e1000_init(PCIDevice *pci_dev)
 {
     DeviceState *dev = DEVICE(pci_dev);
@@ -1539,6 +1562,8 @@ static int pci_e1000_init(PCIDevice *pci_dev)
     int i;
     uint8_t *macaddr;
 
+    pci_dev->config_write = e1000_write_config;
+
     pci_conf = pci_dev->config;
 
     /* TODO: RST# value should be 0, PCI spec 6.2.4 */
-- 
2.1.0

  reply	other threads:[~2014-12-18  9:22 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-12-18  9:22 [Qemu-devel] [PATCH 0/2] ignore bus master for e1000 Amos Kong
2014-12-18  9:22 ` Amos Kong [this message]
2014-12-18  9:22 ` [Qemu-devel] [PATCH 2/2] e1000: unconditionally enable bus mastering Amos Kong
2014-12-18  9:49   ` Jason Wang
2014-12-18 10:30     ` Amos Kong
2015-01-07 16:08   ` Stefan Hajnoczi
2015-02-06 13:46     ` Stefan Hajnoczi
2015-02-10 16:11       ` Amos Kong
2014-12-18 10:05 ` [Qemu-devel] [PATCH 0/2] ignore bus master for e1000 Jason Wang
2014-12-18 11:01   ` Denis V. Lunev
2014-12-18 11:11     ` Denis V. Lunev
2014-12-19  4:59       ` Jason Wang
2014-12-19  3:09   ` Amos Kong
2014-12-19  5:00     ` Jason Wang

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=1418894539-13990-2-git-send-email-akong@redhat.com \
    --to=akong@redhat.com \
    --cc=jasowang@redhat.com \
    --cc=marcel.a@redhat.com \
    --cc=mst@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=somlo@cmu.edu \
    --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).