diff mbox

[13/25] usb: fold usb_generic_handle_packet into usb_handle_packet

Message ID 1327330511-16307-14-git-send-email-kraxel@redhat.com
State New
Headers show

Commit Message

Gerd Hoffmann Jan. 23, 2012, 2:54 p.m. UTC
There is no reason to have a separate usb_generic_handle_packet function
any more, fold it into usb_handle_packet().  Also call the do_token_*
functions which handle control transfer emulation for control pipe
packets only.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 hw/usb.c |   58 +++++++++++++++++++++++++---------------------------------
 1 files changed, 25 insertions(+), 33 deletions(-)
diff mbox

Patch

diff --git a/hw/usb.c b/hw/usb.c
index 70a4bc5..0bf98a0 100644
--- a/hw/usb.c
+++ b/hw/usb.c
@@ -144,8 +144,7 @@  static int do_token_in(USBDevice *s, USBPacket *p)
     int request, value, index;
     int ret = 0;
 
-    if (p->devep != 0)
-        return s->info->handle_data(s, p);
+    assert(p->devep == 0);
 
     request = (s->setup_buf[0] << 8) | s->setup_buf[1];
     value   = (s->setup_buf[3] << 8) | s->setup_buf[2];
@@ -191,8 +190,7 @@  static int do_token_in(USBDevice *s, USBPacket *p)
 
 static int do_token_out(USBDevice *s, USBPacket *p)
 {
-    if (p->devep != 0)
-        return s->info->handle_data(s, p);
+    assert(p->devep == 0);
 
     switch(s->setup_state) {
     case SETUP_STATE_ACK:
@@ -225,33 +223,6 @@  static int do_token_out(USBDevice *s, USBPacket *p)
     }
 }
 
-/*
- * Generic packet handler.
- * Called by the HC (host controller).
- *
- * Returns length of the transaction or one of the USB_RET_XXX codes.
- */
-static int usb_generic_handle_packet(USBDevice *s, USBPacket *p)
-{
-    /* Rest of the PIDs must match our address */
-    if (s->state < USB_STATE_DEFAULT || p->devaddr != s->addr)
-        return USB_RET_NODEV;
-
-    switch (p->pid) {
-    case USB_TOKEN_SETUP:
-        return do_token_setup(s, p);
-
-    case USB_TOKEN_IN:
-        return do_token_in(s, p);
-
-    case USB_TOKEN_OUT:
-        return do_token_out(s, p);
- 
-    default:
-        return USB_RET_STALL;
-    }
-}
-
 /* ctrl complete function for devices which use usb_generic_handle_packet and
    may return USB_RET_ASYNC from their handle_control callback. Device code
    which does this *must* call this function instead of the normal
@@ -326,9 +297,30 @@  int usb_handle_packet(USBDevice *dev, USBPacket *p)
         return USB_RET_NODEV;
     }
     assert(dev->addr == p->devaddr);
-
+    assert(dev->state == USB_STATE_DEFAULT);
     assert(p->owner == NULL);
-    ret = usb_generic_handle_packet(dev, p);
+
+    if (p->devep == 0) {
+        /* control pipe */
+        switch (p->pid) {
+        case USB_TOKEN_SETUP:
+            ret = do_token_setup(dev, p);
+            break;
+        case USB_TOKEN_IN:
+            ret = do_token_in(dev, p);
+            break;
+        case USB_TOKEN_OUT:
+            ret = do_token_out(dev, p);
+            break;
+        default:
+            ret = USB_RET_STALL;
+            break;
+        }
+    } else {
+        /* data pipe */
+        ret = dev->info->handle_data(dev, p);
+    }
+
     if (ret == USB_RET_ASYNC) {
         p->owner = usb_ep_get(dev, p->pid, p->devep);
     }