From f53c398aa603cea135ee58fd15249aeff7b9c7ea Mon Sep 17 00:00:00 2001 From: Gerd Hoffmann Date: Thu, 12 Jan 2012 12:51:48 +0100 Subject: 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 --- hw/usb.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'hw/usb.c') 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); } -- cgit v1.2.3