From: Gerd Hoffmann <kraxel@redhat.com>
To: qemu-devel@nongnu.org
Cc: Gerd Hoffmann <kraxel@redhat.com>
Subject: [Qemu-devel] [PATCH 17/28] usb: USBPacket: add status, rename owner -> ep
Date: Fri, 10 Feb 2012 12:43:13 +0100 [thread overview]
Message-ID: <1328874204-20920-18-git-send-email-kraxel@redhat.com> (raw)
In-Reply-To: <1328874204-20920-1-git-send-email-kraxel@redhat.com>
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>
---
hw/usb-ehci.c | 4 ++--
hw/usb-musb.c | 4 ++--
hw/usb-ohci.c | 4 ++--
hw/usb-uhci.c | 4 ++--
hw/usb.c | 18 +++++++++++-------
hw/usb.h | 19 ++++++++++++++++---
6 files changed, 35 insertions(+), 18 deletions(-)
diff --git a/hw/usb-ehci.c b/hw/usb-ehci.c
index 8f7b3c4..f0213ad 100644
--- a/hw/usb-ehci.c
+++ b/hw/usb-ehci.c
@@ -715,8 +715,8 @@ static void ehci_queues_rip_device(EHCIState *ehci, USBDevice *dev)
EHCIQueue *q, *tmp;
QTAILQ_FOREACH_SAFE(q, &ehci->queues, next, tmp) {
- if (q->packet.owner == NULL ||
- q->packet.owner->dev != dev) {
+ if (!usb_packet_is_inflight(&q->packet) ||
+ q->packet.ep->dev != dev) {
continue;
}
ehci_free_queue(q);
diff --git a/hw/usb-musb.c b/hw/usb-musb.c
index ecac631..f4e52f1 100644
--- a/hw/usb-musb.c
+++ b/hw/usb-musb.c
@@ -811,8 +811,8 @@ static void musb_async_cancel_device(MUSBState *s, USBDevice *dev)
for (ep = 0; ep < 16; ep++) {
for (dir = 0; dir < 2; dir++) {
- if (s->ep[ep].packey[dir].p.owner == NULL ||
- s->ep[ep].packey[dir].p.owner->dev != dev) {
+ if (!usb_packet_is_inflight(&s->ep[ep].packey[dir].p) ||
+ s->ep[ep].packey[dir].p.ep->dev != dev) {
continue;
}
usb_cancel_packet(&s->ep[ep].packey[dir].p);
diff --git a/hw/usb-ohci.c b/hw/usb-ohci.c
index ba854c7..8a8f3bc 100644
--- a/hw/usb-ohci.c
+++ b/hw/usb-ohci.c
@@ -1709,8 +1709,8 @@ static void ohci_mem_write(void *opaque,
static void ohci_async_cancel_device(OHCIState *ohci, USBDevice *dev)
{
if (ohci->async_td &&
- ohci->usb_packet.owner != NULL &&
- ohci->usb_packet.owner->dev == dev) {
+ usb_packet_is_inflight(&ohci->usb_packet) &&
+ ohci->usb_packet.ep->dev == dev) {
usb_cancel_packet(&ohci->usb_packet);
ohci->async_td = 0;
}
diff --git a/hw/usb-uhci.c b/hw/usb-uhci.c
index a1f597a..ef08145 100644
--- a/hw/usb-uhci.c
+++ b/hw/usb-uhci.c
@@ -236,8 +236,8 @@ static void uhci_async_cancel_device(UHCIState *s, USBDevice *dev)
UHCIAsync *curr, *n;
QTAILQ_FOREACH_SAFE(curr, &s->async_pending, next, n) {
- if (curr->packet.owner == NULL ||
- curr->packet.owner->dev != dev) {
+ if (!usb_packet_is_inflight(&curr->packet) ||
+ curr->packet.ep->dev != dev) {
continue;
}
uhci_async_unlink(s, curr);
diff --git a/hw/usb.c b/hw/usb.c
index 91107f9..8584db0 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);
}
diff --git a/hw/usb.h b/hw/usb.h
index 294c33d..4e878d3 100644
--- a/hw/usb.h
+++ b/hw/usb.h
@@ -289,8 +289,7 @@ typedef struct USBPortOps {
void (*wakeup)(USBPort *port);
/*
* Note that port->dev will be different then the device from which
- * the packet originated when a hub is involved, if you want the orginating
- * device use p->owner
+ * the packet originated when a hub is involved.
*/
void (*complete)(USBPort *port, USBPacket *p);
} USBPortOps;
@@ -309,15 +308,24 @@ struct USBPort {
typedef void USBCallback(USBPacket * packet, void *opaque);
/* Structure used to hold information about an active USB packet. */
+typedef enum USBPacketState {
+ USB_PACKET_UNDEFINED = 0,
+ USB_PACKET_SETUP,
+ USB_PACKET_ASYNC,
+ USB_PACKET_COMPLETE,
+ USB_PACKET_CANCELED,
+} USBPacketState;
+
struct USBPacket {
/* Data fields for use by the driver. */
int pid;
uint8_t devaddr;
uint8_t devep;
+ USBEndpoint *ep;
QEMUIOVector iov;
int result; /* transfer length or USB_RET_* status code */
/* Internal use by the USB layer. */
- USBEndpoint *owner;
+ USBPacketState state;
};
void usb_packet_init(USBPacket *p);
@@ -329,6 +337,11 @@ void usb_packet_copy(USBPacket *p, void *ptr, size_t bytes);
void usb_packet_skip(USBPacket *p, size_t bytes);
void usb_packet_cleanup(USBPacket *p);
+static inline bool usb_packet_is_inflight(USBPacket *p)
+{
+ return p->state == USB_PACKET_ASYNC;
+}
+
USBDevice *usb_find_device(USBPort *port, uint8_t addr);
int usb_handle_packet(USBDevice *dev, USBPacket *p);
--
1.7.1
next prev parent reply other threads:[~2012-02-10 11:44 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-02-10 11:42 [Qemu-devel] [PULL 00/28] usb patch queue Gerd Hoffmann
2012-02-10 11:42 ` [Qemu-devel] [PATCH 01/28] usb-uhci: implement bandwidth management Gerd Hoffmann
2012-02-10 11:42 ` [Qemu-devel] [PATCH 02/28] usb-ehci: Clear the portstatus powner bit on device disconnect Gerd Hoffmann
2012-02-10 11:42 ` [Qemu-devel] [PATCH 03/28] usb-redir: Add the posibility to filter out certain devices from redirecion Gerd Hoffmann
2012-02-10 11:43 ` [Qemu-devel] [PATCH 04/28] usb: kill USB_MSG_{ATTACH,DETACH} Gerd Hoffmann
2012-02-10 11:43 ` [Qemu-devel] [PATCH 05/28] usb: kill USB_MSG_RESET Gerd Hoffmann
2012-02-10 11:43 ` [Qemu-devel] [PATCH 06/28] usb: kill usb_send_msg Gerd Hoffmann
2012-02-10 11:43 ` [Qemu-devel] [PATCH 07/28] usb: add usb_find_device() Gerd Hoffmann
2012-02-10 11:43 ` [Qemu-devel] [PATCH 08/28] usb-hub: implement find_device Gerd Hoffmann
2012-02-10 11:43 ` [Qemu-devel] [PATCH 09/28] usb: handle dev == NULL in usb_handle_packet() Gerd Hoffmann
2012-02-10 11:43 ` [Qemu-devel] [PATCH 10/28] usb-uhci: switch to usb_find_device() Gerd Hoffmann
2012-02-10 11:43 ` [Qemu-devel] [PATCH 11/28] usb-ehci: " Gerd Hoffmann
2012-02-10 11:43 ` [Qemu-devel] [PATCH 12/28] usb-ohci: " Gerd Hoffmann
2012-02-10 11:43 ` [Qemu-devel] [PATCH 13/28] usb-musb: " Gerd Hoffmann
2012-02-10 11:43 ` [Qemu-devel] [PATCH 14/28] usb-xhci: " Gerd Hoffmann
2012-02-10 11:43 ` [Qemu-devel] [PATCH 15/28] usb: kill handle_packet callback Gerd Hoffmann
2012-02-10 11:43 ` [Qemu-devel] [PATCH 16/28] usb: fold usb_generic_handle_packet into usb_handle_packet Gerd Hoffmann
2012-02-10 11:43 ` Gerd Hoffmann [this message]
2012-02-10 11:43 ` [Qemu-devel] [PATCH 18/28] usb: add USBEndpoint->{nr,pid} Gerd Hoffmann
2012-02-10 11:43 ` [Qemu-devel] [PATCH 19/28] usb: Set USBEndpoint in usb_packet_setup() Gerd Hoffmann
2012-02-10 11:43 ` [Qemu-devel] [PATCH 20/28] usb: maintain async packet list per endpoint Gerd Hoffmann
2012-02-10 11:43 ` [Qemu-devel] [PATCH 21/28] usb: pass USBEndpoint to usb_wakeup Gerd Hoffmann
2012-02-10 11:43 ` [Qemu-devel] [PATCH 22/28] usb: add USBBusOps->wakeup_endpoint Gerd Hoffmann
2012-02-10 11:43 ` [Qemu-devel] [PATCH 23/28] xhci: signal low- and fullspeed support Gerd Hoffmann
2012-02-10 11:43 ` [Qemu-devel] [PATCH 24/28] xhci: add trb type name lookup support Gerd Hoffmann
2012-02-10 11:43 ` [Qemu-devel] [PATCH 25/28] xhci: stop on errors Gerd Hoffmann
2012-02-10 11:43 ` [Qemu-devel] [PATCH 26/28] xhci: kill port arg from xhci_setup_packet Gerd Hoffmann
2012-02-10 11:43 ` [Qemu-devel] [PATCH 27/28] xhci: remote wakeup support Gerd Hoffmann
2012-02-10 11:43 ` [Qemu-devel] [PATCH 28/28] xhci: handle USB_RET_NAK Gerd Hoffmann
2012-02-16 0:32 ` [Qemu-devel] [PULL 00/28] usb patch queue Anthony Liguori
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1328874204-20920-18-git-send-email-kraxel@redhat.com \
--to=kraxel@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).