qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Hans de Goede <hdegoede@redhat.com>
To: qemu-devel@nongnu.org
Cc: Hans de Goede <hdegoede@redhat.com>, Gerd Hoffmann <kraxel@redhat.com>
Subject: [Qemu-devel] [PATCH 11/22] usb: Move clearing of queue on halt to the core
Date: Mon, 15 Oct 2012 12:38:20 +0200	[thread overview]
Message-ID: <1350297511-25437-12-git-send-email-hdegoede@redhat.com> (raw)
In-Reply-To: <1350297511-25437-1-git-send-email-hdegoede@redhat.com>

hcds which queue up more then one packet at once (uhci, ehci and xhci),
must clear the queue after an error which has caused the queue to halt.

Currently this is handled as a special case inside the hcd code, this
patch instead adds an USB_RET_REMOVE_FROM_QUEUE packet result code, teaches
the 3 hcds about this and moves the clearing of the queue on a halt into
the USB core.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
 hw/usb.h          |  1 +
 hw/usb/core.c     |  8 +++++++-
 hw/usb/hcd-ehci.c | 22 ++++++++--------------
 hw/usb/hcd-uhci.c | 22 ++++++----------------
 hw/usb/hcd-xhci.c |  4 ++++
 5 files changed, 26 insertions(+), 31 deletions(-)

diff --git a/hw/usb.h b/hw/usb.h
index 435cd42..ead03c9 100644
--- a/hw/usb.h
+++ b/hw/usb.h
@@ -45,6 +45,7 @@
 #define USB_RET_IOERROR           (-5)
 #define USB_RET_ASYNC             (-6)
 #define USB_RET_ADD_TO_QUEUE      (-7)
+#define USB_RET_REMOVE_FROM_QUEUE (-8)
 
 #define USB_SPEED_LOW   0
 #define USB_SPEED_FULL  1
diff --git a/hw/usb/core.c b/hw/usb/core.c
index 014e3ac..5a97a0e 100644
--- a/hw/usb/core.c
+++ b/hw/usb/core.c
@@ -442,8 +442,14 @@ void usb_packet_complete(USBDevice *dev, USBPacket *p)
     usb_packet_check_state(p, USB_PACKET_ASYNC);
     usb_packet_complete_one(dev, p);
 
-    while (!ep->halted && !QTAILQ_EMPTY(&ep->queue)) {
+    while (!QTAILQ_EMPTY(&ep->queue)) {
         p = QTAILQ_FIRST(&ep->queue);
+        if (ep->halted) {
+            /* Empty the queue on a halt */
+            p->result = USB_RET_REMOVE_FROM_QUEUE;
+            dev->port->ops->complete(dev->port, p);
+            continue;
+        }
         if (p->state == USB_PACKET_ASYNC) {
             break;
         }
diff --git a/hw/usb/hcd-ehci.c b/hw/usb/hcd-ehci.c
index 29365d9..e6f7642 100644
--- a/hw/usb/hcd-ehci.c
+++ b/hw/usb/hcd-ehci.c
@@ -1456,8 +1456,15 @@ static void ehci_async_complete_packet(USBPort *port, USBPacket *packet)
     }
 
     p = container_of(packet, EHCIPacket, packet);
-    trace_usb_ehci_packet_action(p->queue, p, "wakeup");
     assert(p->async == EHCI_ASYNC_INFLIGHT);
+
+    if (packet->result == USB_RET_REMOVE_FROM_QUEUE) {
+        trace_usb_ehci_packet_action(p->queue, p, "remove");
+        ehci_free_packet(p);
+        return;
+    }
+
+    trace_usb_ehci_packet_action(p->queue, p, "wakeup");
     p->async = EHCI_ASYNC_FINISHED;
     p->usb_status = packet->result;
 
@@ -2214,19 +2221,6 @@ static int ehci_state_writeback(EHCIQueue *q)
      * bit is clear.
      */
     if (q->qh.token & QTD_TOKEN_HALT) {
-        /*
-         * We should not do any further processing on a halted queue!
-         * This is esp. important for bulk endpoints with pipelining enabled
-         * (redirection to a real USB device), where we must cancel all the
-         * transfers after this one so that:
-         * 1) If they've completed already, they are not processed further
-         *    causing more stalls, originating from the same failed transfer
-         * 2) If still in flight, they are cancelled before the guest does
-         *    a clear stall, otherwise the guest and device can loose sync!
-         */
-        while ((p = QTAILQ_FIRST(&q->packets)) != NULL) {
-            ehci_free_packet(p);
-        }
         ehci_set_state(q->ehci, q->async, EST_HORIZONTALQH);
         again = 1;
     } else {
diff --git a/hw/usb/hcd-uhci.c b/hw/usb/hcd-uhci.c
index 46e544b..00dc9d5 100644
--- a/hw/usb/hcd-uhci.c
+++ b/hw/usb/hcd-uhci.c
@@ -744,22 +744,6 @@ static int uhci_complete_td(UHCIState *s, UHCI_TD *td, UHCIAsync *async, uint32_
     return TD_RESULT_COMPLETE;
 
 out:
-    /*
-     * We should not do any further processing on a queue with errors!
-     * This is esp. important for bulk endpoints with pipelining enabled
-     * (redirection to a real USB device), where we must cancel all the
-     * transfers after this one so that:
-     * 1) If they've completed already, they are not processed further
-     *    causing more stalls, originating from the same failed transfer
-     * 2) If still in flight, they are cancelled before the guest does
-     *    a clear stall, otherwise the guest and device can loose sync!
-     */
-    while (!QTAILQ_EMPTY(&async->queue->asyncs)) {
-        UHCIAsync *as = QTAILQ_FIRST(&async->queue->asyncs);
-        uhci_async_unlink(as);
-        uhci_async_cancel(as);
-    }
-
     switch(ret) {
     case USB_RET_STALL:
         td->ctrl |= TD_CTRL_STALL;
@@ -918,6 +902,12 @@ static void uhci_async_complete(USBPort *port, USBPacket *packet)
     UHCIAsync *async = container_of(packet, UHCIAsync, packet);
     UHCIState *s = async->queue->uhci;
 
+    if (packet->result == USB_RET_REMOVE_FROM_QUEUE) {
+        uhci_async_unlink(async);
+        uhci_async_cancel(async);
+        return;
+    }
+
     if (async->isoc) {
         UHCI_TD td;
         uint32_t link = async->td;
diff --git a/hw/usb/hcd-xhci.c b/hw/usb/hcd-xhci.c
index 53e1ea3..5648cc7 100644
--- a/hw/usb/hcd-xhci.c
+++ b/hw/usb/hcd-xhci.c
@@ -2834,6 +2834,10 @@ static void xhci_complete(USBPort *port, USBPacket *packet)
 {
     XHCITransfer *xfer = container_of(packet, XHCITransfer, packet);
 
+    if (packet->result == USB_RET_REMOVE_FROM_QUEUE) {
+        xhci_ep_nuke_one_xfer(xfer);
+        return;
+    }
     xhci_complete_packet(xfer, packet->result);
     xhci_kick_ep(xfer->xhci, xfer->slotid, xfer->epid);
 }
-- 
1.7.12.1

  parent reply	other threads:[~2012-10-15 10:38 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-10-15 10:38 [Qemu-devel] RFC: usb input pipelining / speedup patchset v2 Hans de Goede
2012-10-15 10:38 ` [Qemu-devel] [PATCH 01/22] uhci: Properly unmap packets on cancel / invalid pid Hans de Goede
2012-10-15 10:38 ` [Qemu-devel] [PATCH 02/22] uhci: Move checks to continue queuing to uhci_fill_queue() Hans de Goede
2012-10-15 10:38 ` [Qemu-devel] [PATCH 03/22] ehci: Get rid of packet tbytes field Hans de Goede
2012-10-15 10:38 ` [Qemu-devel] [PATCH 04/22] ehci: Set int flag on a short input packet Hans de Goede
2012-10-15 10:38 ` [Qemu-devel] [PATCH 05/22] ehci: Improve latency of interrupt delivery and async schedule scanning Hans de Goede
2012-10-15 10:38 ` [Qemu-devel] [PATCH 06/22] ehci: Speed up the timer of raising int from the async schedule Hans de Goede
2012-10-15 11:17   ` Gerd Hoffmann
2012-10-15 13:00     ` Hans de Goede
2012-10-17 11:01       ` Gerd Hoffmann
2012-10-17 11:11         ` Hans de Goede
2012-10-17 11:37           ` Gerd Hoffmann
2012-10-15 10:38 ` [Qemu-devel] [PATCH 07/22] ehci: Detect going in circles when filling the queue Hans de Goede
2012-10-15 10:38 ` [Qemu-devel] [PATCH 08/22] xhci: Add a xhci_ep_nuke_one_xfer helper function Hans de Goede
2012-10-15 10:38 ` [Qemu-devel] [PATCH 09/22] usb: Rename __usb_packet_complete to usb_packet_complete_one Hans de Goede
2012-10-15 10:38 ` [Qemu-devel] [PATCH 10/22] usb: Add USB_RET_ADD_TO_QUEUE packet result code Hans de Goede
2012-10-15 10:38 ` Hans de Goede [this message]
2012-10-15 10:38 ` [Qemu-devel] [PATCH 12/22] usb: Move short-not-ok handling to the core Hans de Goede
2012-10-15 10:38 ` [Qemu-devel] [PATCH 13/22] usb: Add an int_req flag to USBPacket Hans de Goede
2012-10-17 11:04   ` Gerd Hoffmann
2012-10-17 11:11     ` Hans de Goede
2012-10-15 10:38 ` [Qemu-devel] [PATCH 14/22] usb: Add packet combining functions Hans de Goede
2012-10-17 11:29   ` Gerd Hoffmann
2012-10-17 14:41     ` Hans de Goede
2012-10-18  6:00       ` Gerd Hoffmann
2012-10-15 10:38 ` [Qemu-devel] [PATCH 15/22] combined-packet: Add a workaround for Linux usbfs + live migration Hans de Goede
2012-10-15 10:38 ` [Qemu-devel] [PATCH 16/22] usb-redir: When a packet contains data on a stall, ignore the stall Hans de Goede
2012-10-15 10:38 ` [Qemu-devel] [PATCH 17/22] usb-redir: Add support for 32 bits bulk packet length Hans de Goede
2012-10-15 10:38 ` [Qemu-devel] [PATCH 18/22] usb-redir: Add support for input pipelining Hans de Goede
2012-10-15 10:38 ` [Qemu-devel] [PATCH 19/22] usb-redir: Add an usbredir_setup_usb_eps() helper function Hans de Goede
2012-10-15 10:38 ` [Qemu-devel] [PATCH 20/22] usb-redir: Use reject rather the disconnect on bad ep info Hans de Goede
2012-10-15 10:38 ` [Qemu-devel] [PATCH 21/22] usb-redir: Allow to attach USB 2.0 devices to 1.1 host controller Hans de Goede
2012-10-15 10:38 ` [Qemu-devel] [PATCH 22/22] usb-redir: Allow redirecting super speed devices to high speed controllers Hans de Goede

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=1350297511-25437-12-git-send-email-hdegoede@redhat.com \
    --to=hdegoede@redhat.com \
    --cc=kraxel@redhat.com \
    --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).