aboutsummaryrefslogtreecommitdiff
path: root/hw/usb.c
diff options
context:
space:
mode:
authorGerd Hoffmann <kraxel@redhat.com>2012-01-12 12:51:48 +0100
committerGerd Hoffmann <kraxel@redhat.com>2012-02-10 11:31:57 +0100
commitf53c398aa603cea135ee58fd15249aeff7b9c7ea (patch)
treeb36b1a2b09a720a3d9e20a838914f3549cc90b16 /hw/usb.c
parent1977f93dacf60466cd23b562ae498446b77d3b48 (diff)
usb: USBPacket: add status, rename owner -> ep
Add enum to track the status of USBPackets, use that instead of the owner pointer to figure whenever a usb packet is currently in flight or not. Add some more packet status sanity checks. Also rename the USBEndpoint pointer from "owner" to "ep". Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Diffstat (limited to 'hw/usb.c')
-rw-r--r--hw/usb.c18
1 files changed, 11 insertions, 7 deletions
diff --git a/hw/usb.c b/hw/usb.c
index 91107f938d..8584db0dec 100644
--- a/hw/usb.c
+++ b/hw/usb.c
@@ -291,7 +291,7 @@ int usb_handle_packet(USBDevice *dev, USBPacket *p)
}
assert(dev->addr == p->devaddr);
assert(dev->state == USB_STATE_DEFAULT);
- assert(p->owner == NULL);
+ assert(p->state == USB_PACKET_SETUP);
if (p->devep == 0) {
/* control pipe */
@@ -315,7 +315,8 @@ int usb_handle_packet(USBDevice *dev, USBPacket *p)
}
if (ret == USB_RET_ASYNC) {
- p->owner = usb_ep_get(dev, p->pid, p->devep);
+ p->ep = usb_ep_get(dev, p->pid, p->devep);
+ p->state = USB_PACKET_ASYNC;
}
return ret;
}
@@ -325,8 +326,8 @@ int usb_handle_packet(USBDevice *dev, USBPacket *p)
handle_packet. */
void usb_packet_complete(USBDevice *dev, USBPacket *p)
{
- assert(p->owner != NULL);
- p->owner = NULL;
+ assert(p->state == USB_PACKET_ASYNC);
+ p->state = USB_PACKET_COMPLETE;
dev->port->ops->complete(dev->port, p);
}
@@ -335,9 +336,9 @@ void usb_packet_complete(USBDevice *dev, USBPacket *p)
completed. */
void usb_cancel_packet(USBPacket * p)
{
- assert(p->owner != NULL);
- usb_device_cancel_packet(p->owner->dev, p);
- p->owner = NULL;
+ assert(p->state == USB_PACKET_ASYNC);
+ p->state = USB_PACKET_CANCELED;
+ usb_device_cancel_packet(p->ep->dev, p);
}
@@ -348,6 +349,8 @@ void usb_packet_init(USBPacket *p)
void usb_packet_setup(USBPacket *p, int pid, uint8_t addr, uint8_t ep)
{
+ assert(!usb_packet_is_inflight(p));
+ p->state = USB_PACKET_SETUP;
p->pid = pid;
p->devaddr = addr;
p->devep = ep;
@@ -391,6 +394,7 @@ void usb_packet_skip(USBPacket *p, size_t bytes)
void usb_packet_cleanup(USBPacket *p)
{
+ assert(!usb_packet_is_inflight(p));
qemu_iovec_destroy(&p->iov);
}