From patchwork Wed Jun 15 17:22:35 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 1946 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id 0BC1523DE6 for ; Wed, 15 Jun 2011 17:22:42 +0000 (UTC) Received: from mail-vx0-f180.google.com (mail-vx0-f180.google.com [209.85.220.180]) by fiordland.canonical.com (Postfix) with ESMTP id C38D6A1880A for ; Wed, 15 Jun 2011 17:22:41 +0000 (UTC) Received: by vxk12 with SMTP id 12so685053vxk.11 for ; Wed, 15 Jun 2011 10:22:41 -0700 (PDT) Received: by 10.52.175.197 with SMTP id cc5mr1117450vdc.287.1308158561075; Wed, 15 Jun 2011 10:22:41 -0700 (PDT) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.52.183.130 with SMTP id em2cs138346vdc; Wed, 15 Jun 2011 10:22:40 -0700 (PDT) Received: by 10.216.230.215 with SMTP id j65mr843037weq.24.1308158559304; Wed, 15 Jun 2011 10:22:39 -0700 (PDT) Received: from mnementh.archaic.org.uk (mnementh.archaic.org.uk [81.2.115.146]) by mx.google.com with ESMTPS id o53si1915224weq.102.2011.06.15.10.22.38 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 15 Jun 2011 10:22:39 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of pm215@archaic.org.uk designates 81.2.115.146 as permitted sender) client-ip=81.2.115.146; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of pm215@archaic.org.uk designates 81.2.115.146 as permitted sender) smtp.mail=pm215@archaic.org.uk Received: from pm215 by mnementh.archaic.org.uk with local (Exim 4.72) (envelope-from ) id 1QWtnY-0001eR-09; Wed, 15 Jun 2011 18:22:36 +0100 From: Peter Maydell To: qemu-devel@nongnu.org Cc: patches@linaro.org, Gerd Hoffmann Subject: [PATCH] hw/usb-ohci.c: Fix handling of remote wakeup corner cases Date: Wed, 15 Jun 2011 18:22:35 +0100 Message-Id: <1308158555-6324-1-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 1.7.2.5 Correct a number of minor errors in the OHCI wakeup implementation: * when the port is suspended but the controller is not, raise RHSC * when the controller is suspended but the port is not, raise RD * when the controller is suspended, move it to resume state These fix some edge cases where a USB device might not successfully get the attention of the guest OS if it tried to do so at the wrong time. Signed-off-by: Peter Maydell --- Fixed version of ohci_wakeup(), as promised... hw/usb-ohci.c | 17 ++++++++++++++--- 1 files changed, 14 insertions(+), 3 deletions(-) diff --git a/hw/usb-ohci.c b/hw/usb-ohci.c index 832dcd6..755abcb 100644 --- a/hw/usb-ohci.c +++ b/hw/usb-ohci.c @@ -373,14 +373,25 @@ static void ohci_wakeup(USBDevice *dev) OHCIState *s = container_of(bus, OHCIState, bus); int portnum = dev->port->index; OHCIPort *port = &s->rhport[portnum]; + uint32_t intr = 0; if (port->ctrl & OHCI_PORT_PSS) { DPRINTF("usb-ohci: port %d: wakeup\n", portnum); port->ctrl |= OHCI_PORT_PSSC; port->ctrl &= ~OHCI_PORT_PSS; - if ((s->ctl & OHCI_CTL_HCFS) == OHCI_USB_SUSPEND) { - ohci_set_interrupt(s, OHCI_INTR_RD); - } + intr = OHCI_INTR_RHSC; + } + /* Note that the controller can be suspended even if this port is not */ + if ((s->ctl & OHCI_CTL_HCFS) == OHCI_USB_SUSPEND) { + DPRINTF("usb-ohci: remote-wakeup: SUSPEND->RESUME\n"); + /* This is the one state transition the controller can do by itself */ + s->ctl &= ~OHCI_CTL_HCFS; + s->ctl |= OHCI_USB_RESUME; + /* In suspend mode only ResumeDetected is possible, not RHSC: + * see the OHCI spec 5.1.2.3. + */ + intr = OHCI_INTR_RD; } + ohci_set_interrupt(s, intr); } /* Reset the controller */