Patchwork ehci: honor frame expiration, async list picks up where it left off

login
register
mail settings
Submitter David S. Ahern
Date July 9, 2010, 7:19 p.m.
Message ID <1278703173-18486-1-git-send-email-daahern@cisco.com>
Download mbox | patch
Permalink /patch/58430/
State New
Headers show

Comments

David S. Ahern - July 9, 2010, 7:19 p.m.
Per Section 4 of the EHCI spec the HC should not start transactions that
will not be completed before the end of the micro-frame. For async
lists processing in the next frame should pick up where it left off.

However, when debugging is enabled we need to allow an overrun since the
printfs take too much time.

Signed-off-by: David Ahern <daahern@cisco.com>
---
 hw/usb-ehci.c |   24 ++++++++++++------------
 1 files changed, 12 insertions(+), 12 deletions(-)

Patch

diff --git a/hw/usb-ehci.c b/hw/usb-ehci.c
index 6e455a2..53ee1fb 100644
--- a/hw/usb-ehci.c
+++ b/hw/usb-ehci.c
@@ -1308,14 +1308,10 @@  static int ehci_state_fetchentry(EHCIState *ehci, int async, int *state)
     int again = 0;
     uint32_t entry = ehci->fetch_addr;
 
-#if 0
-    if (qemu_get_clock(vm_clock) / 1000 > ehci->frame_end_usec) {
+#if EHCI_DEBUG == 0
+    if (qemu_get_clock(vm_clock) / 1000 >= ehci->frame_end_usec) {
         if (async) {
-/* TO-DO: supposed to be saving the horizontal QH and picking up
- *        from there on next frame
- */
-            printf("FETCHENTRY: FRAME timer elapsed, exit state machine\n");
-            *state = EST_ACTIVE;
+            DPRINTF("FETCHENTRY: FRAME timer elapsed, exit state machine\n");
             goto out;
         } else {
             DPRINTF("FETCHENTRY: WARNING "
@@ -1773,8 +1769,9 @@  static int ehci_advance_state(EHCIState *ehci,
 static void ehci_advance_async_state(EHCIState *ehci)
 {
     EHCIqh qh;
+    int state = ehci->astate;
 
-    switch(ehci->astate) {
+    switch(state) {
     case EST_INACTIVE:
         if (!(ehci->usbcmd & USBCMD_ASE)) {
             break;
@@ -1815,13 +1812,16 @@  static void ehci_advance_async_state(EHCIState *ehci)
             break;
         }
 
-        ehci->astate = ehci_advance_state(ehci, 1, EST_WAITLISTHEAD);
-        break;
+        state = EST_WAITLISTHEAD;
+        /* fall through */
+
+    case EST_FETCHENTRY:
+        /* fall through */
 
     case EST_EXECUTING:
         get_dwords(NLPTR_GET(ehci->qhaddr), (uint32_t *) &qh,
                    sizeof(EHCIqh) >> 2);
-        ehci->astate = ehci_advance_state(ehci, 1, EST_EXECUTING);
+        ehci->astate = ehci_advance_state(ehci, 1, state);
         break;
 
     default:
@@ -1905,7 +1905,7 @@  static void ehci_frame_timer(void *opaque)
     usec_now = t_now / 1000;
     usec_elapsed = usec_now - ehci->last_run_usec;
     frames = usec_elapsed / FRAME_TIMER_USEC;
-    ehci->frame_end_usec = usec_now + FRAME_TIMER_USEC;
+    ehci->frame_end_usec = usec_now + FRAME_TIMER_USEC - 10;
 
     for(i = 0; i < frames; i++) {
         if ( !(ehci->usbsts & USBSTS_HALT)) {