Skip to contentSkip to conversation

hw/usb-ohci.c: Fix handling of remote wakeup corner cases

PATCH In review Peter Maydell 2 participants 2 messages Jun 15, 2011 – Jun 16, 2011

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 hw/usb-ohci.c: Fix handling of remote wakeup corner cases

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.

---
Fixed version of ohci_wakeup(), as promised...

 hw/usb-ohci.c |   17 ++++++++++++++---
 1 files changed, 14 insertions(+), 3 deletions(-)
hw/usb-ohci.c +14 -3
index 832dcd6..755abcb 100644
@@ -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 */
Signature · 1 line
1.7.1
#1 lore raw
Quoted 9 lines · Peter Maydell

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.

Patch applied.

thanks,
Gerd