|
|
5544c1 |
From 111194442fa38ba6dc26bc695ba0d3b76584663b Mon Sep 17 00:00:00 2001
|
|
Hans de Goede |
c8dfc6 |
From: Hans de Goede <hdegoede@redhat.com>
|
|
Hans de Goede |
c8dfc6 |
Date: Tue, 28 Aug 2012 11:30:13 +0200
|
|
|
5544c1 |
Subject: [PATCH] usb-redir: Move to core packet id and queue handling
|
|
Hans de Goede |
c8dfc6 |
|
|
Hans de Goede |
c8dfc6 |
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
|
|
Hans de Goede |
c8dfc6 |
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
|
|
|
5544c1 |
(cherry picked from commit de550a6afb468ed3b8171019e19b63ae8254886d)
|
|
|
5544c1 |
|
|
|
5544c1 |
Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
|
|
Hans de Goede |
c8dfc6 |
---
|
|
Hans de Goede |
c8dfc6 |
hw/usb/redirect.c | 226 ++++++++++++++++++++++--------------------------------
|
|
Hans de Goede |
c8dfc6 |
1 file changed, 92 insertions(+), 134 deletions(-)
|
|
Hans de Goede |
c8dfc6 |
|
|
Hans de Goede |
c8dfc6 |
diff --git a/hw/usb/redirect.c b/hw/usb/redirect.c
|
|
|
5544c1 |
index 6593d50..fd1f8cc 100644
|
|
Hans de Goede |
c8dfc6 |
--- a/hw/usb/redirect.c
|
|
Hans de Goede |
c8dfc6 |
+++ b/hw/usb/redirect.c
|
|
Hans de Goede |
c8dfc6 |
@@ -43,7 +43,7 @@
|
|
Hans de Goede |
c8dfc6 |
#define EP2I(ep_address) (((ep_address & 0x80) >> 3) | (ep_address & 0x0f))
|
|
Hans de Goede |
c8dfc6 |
#define I2EP(i) (((i & 0x10) << 3) | (i & 0x0f))
|
|
Hans de Goede |
c8dfc6 |
|
|
Hans de Goede |
c8dfc6 |
-typedef struct AsyncURB AsyncURB;
|
|
Hans de Goede |
c8dfc6 |
+typedef struct Cancelled Cancelled;
|
|
Hans de Goede |
c8dfc6 |
typedef struct USBRedirDevice USBRedirDevice;
|
|
Hans de Goede |
c8dfc6 |
|
|
Hans de Goede |
c8dfc6 |
/* Struct to hold buffered packets (iso or int input packets) */
|
|
Hans de Goede |
c8dfc6 |
@@ -86,8 +86,7 @@ struct USBRedirDevice {
|
|
Hans de Goede |
c8dfc6 |
int64_t next_attach_time;
|
|
Hans de Goede |
c8dfc6 |
struct usbredirparser *parser;
|
|
Hans de Goede |
c8dfc6 |
struct endp_data endpoint[MAX_ENDPOINTS];
|
|
Hans de Goede |
c8dfc6 |
- uint32_t packet_id;
|
|
Hans de Goede |
c8dfc6 |
- QTAILQ_HEAD(, AsyncURB) asyncq;
|
|
Hans de Goede |
c8dfc6 |
+ QTAILQ_HEAD(, Cancelled) cancelled;
|
|
Hans de Goede |
c8dfc6 |
/* Data for device filtering */
|
|
Hans de Goede |
c8dfc6 |
struct usb_redir_device_connect_header device_info;
|
|
Hans de Goede |
c8dfc6 |
struct usb_redir_interface_info_header interface_info;
|
|
Hans de Goede |
c8dfc6 |
@@ -95,10 +94,9 @@ struct USBRedirDevice {
|
|
Hans de Goede |
c8dfc6 |
int filter_rules_count;
|
|
Hans de Goede |
c8dfc6 |
};
|
|
Hans de Goede |
c8dfc6 |
|
|
Hans de Goede |
c8dfc6 |
-struct AsyncURB {
|
|
Hans de Goede |
c8dfc6 |
- USBPacket *packet;
|
|
Hans de Goede |
c8dfc6 |
- uint32_t packet_id;
|
|
Hans de Goede |
c8dfc6 |
- QTAILQ_ENTRY(AsyncURB)next;
|
|
Hans de Goede |
c8dfc6 |
+struct Cancelled {
|
|
Hans de Goede |
c8dfc6 |
+ uint64_t id;
|
|
Hans de Goede |
c8dfc6 |
+ QTAILQ_ENTRY(Cancelled)next;
|
|
Hans de Goede |
c8dfc6 |
};
|
|
Hans de Goede |
c8dfc6 |
|
|
Hans de Goede |
c8dfc6 |
static void usbredir_hello(void *priv, struct usb_redir_hello_header *h);
|
|
|
5544c1 |
@@ -238,57 +236,58 @@ static int usbredir_write(void *priv, uint8_t *data, int count)
|
|
Hans de Goede |
c8dfc6 |
}
|
|
Hans de Goede |
c8dfc6 |
|
|
Hans de Goede |
c8dfc6 |
/*
|
|
Hans de Goede |
c8dfc6 |
- * Async and buffered packets helpers
|
|
Hans de Goede |
c8dfc6 |
+ * Cancelled and buffered packets helpers
|
|
Hans de Goede |
c8dfc6 |
*/
|
|
Hans de Goede |
c8dfc6 |
|
|
Hans de Goede |
c8dfc6 |
-static AsyncURB *async_alloc(USBRedirDevice *dev, USBPacket *p)
|
|
Hans de Goede |
c8dfc6 |
+static void usbredir_cancel_packet(USBDevice *udev, USBPacket *p)
|
|
Hans de Goede |
c8dfc6 |
{
|
|
Hans de Goede |
c8dfc6 |
- AsyncURB *aurb = (AsyncURB *) g_malloc0(sizeof(AsyncURB));
|
|
Hans de Goede |
c8dfc6 |
- aurb->packet = p;
|
|
Hans de Goede |
c8dfc6 |
- aurb->packet_id = dev->packet_id;
|
|
Hans de Goede |
c8dfc6 |
- QTAILQ_INSERT_TAIL(&dev->asyncq, aurb, next);
|
|
Hans de Goede |
c8dfc6 |
- dev->packet_id++;
|
|
Hans de Goede |
c8dfc6 |
+ USBRedirDevice *dev = DO_UPCAST(USBRedirDevice, dev, udev);
|
|
Hans de Goede |
c8dfc6 |
+ Cancelled *c;
|
|
Hans de Goede |
c8dfc6 |
|
|
Hans de Goede |
c8dfc6 |
- return aurb;
|
|
Hans de Goede |
c8dfc6 |
-}
|
|
Hans de Goede |
c8dfc6 |
+ DPRINTF("cancel packet id %"PRIu64"\n", p->id);
|
|
Hans de Goede |
c8dfc6 |
|
|
Hans de Goede |
c8dfc6 |
-static void async_free(USBRedirDevice *dev, AsyncURB *aurb)
|
|
Hans de Goede |
c8dfc6 |
-{
|
|
Hans de Goede |
c8dfc6 |
- QTAILQ_REMOVE(&dev->asyncq, aurb, next);
|
|
Hans de Goede |
c8dfc6 |
- g_free(aurb);
|
|
Hans de Goede |
c8dfc6 |
+ c = g_malloc0(sizeof(Cancelled));
|
|
Hans de Goede |
c8dfc6 |
+ c->id = p->id;
|
|
Hans de Goede |
c8dfc6 |
+ QTAILQ_INSERT_TAIL(&dev->cancelled, c, next);
|
|
Hans de Goede |
c8dfc6 |
+
|
|
Hans de Goede |
c8dfc6 |
+ usbredirparser_send_cancel_data_packet(dev->parser, p->id);
|
|
Hans de Goede |
c8dfc6 |
+ usbredirparser_do_write(dev->parser);
|
|
Hans de Goede |
c8dfc6 |
}
|
|
Hans de Goede |
c8dfc6 |
|
|
Hans de Goede |
c8dfc6 |
-static AsyncURB *async_find(USBRedirDevice *dev, uint32_t packet_id)
|
|
Hans de Goede |
c8dfc6 |
+static int usbredir_is_cancelled(USBRedirDevice *dev, uint64_t id)
|
|
Hans de Goede |
c8dfc6 |
{
|
|
Hans de Goede |
c8dfc6 |
- AsyncURB *aurb;
|
|
Hans de Goede |
c8dfc6 |
+ Cancelled *c;
|
|
Hans de Goede |
c8dfc6 |
+
|
|
Hans de Goede |
c8dfc6 |
+ if (!dev->dev.attached) {
|
|
Hans de Goede |
c8dfc6 |
+ return 1; /* Treat everything as cancelled after a disconnect */
|
|
Hans de Goede |
c8dfc6 |
+ }
|
|
Hans de Goede |
c8dfc6 |
|
|
Hans de Goede |
c8dfc6 |
- QTAILQ_FOREACH(aurb, &dev->asyncq, next) {
|
|
Hans de Goede |
c8dfc6 |
- if (aurb->packet_id == packet_id) {
|
|
Hans de Goede |
c8dfc6 |
- return aurb;
|
|
Hans de Goede |
c8dfc6 |
+ QTAILQ_FOREACH(c, &dev->cancelled, next) {
|
|
Hans de Goede |
c8dfc6 |
+ if (c->id == id) {
|
|
Hans de Goede |
c8dfc6 |
+ QTAILQ_REMOVE(&dev->cancelled, c, next);
|
|
Hans de Goede |
c8dfc6 |
+ g_free(c);
|
|
Hans de Goede |
c8dfc6 |
+ return 1;
|
|
Hans de Goede |
c8dfc6 |
}
|
|
Hans de Goede |
c8dfc6 |
}
|
|
Hans de Goede |
c8dfc6 |
- DPRINTF("could not find async urb for packet_id %u\n", packet_id);
|
|
Hans de Goede |
c8dfc6 |
- return NULL;
|
|
Hans de Goede |
c8dfc6 |
+ return 0;
|
|
Hans de Goede |
c8dfc6 |
}
|
|
Hans de Goede |
c8dfc6 |
|
|
Hans de Goede |
c8dfc6 |
-static void usbredir_cancel_packet(USBDevice *udev, USBPacket *p)
|
|
Hans de Goede |
c8dfc6 |
+static USBPacket *usbredir_find_packet_by_id(USBRedirDevice *dev,
|
|
Hans de Goede |
c8dfc6 |
+ uint8_t ep, uint64_t id)
|
|
Hans de Goede |
c8dfc6 |
{
|
|
Hans de Goede |
c8dfc6 |
- USBRedirDevice *dev = DO_UPCAST(USBRedirDevice, dev, udev);
|
|
Hans de Goede |
c8dfc6 |
- AsyncURB *aurb;
|
|
Hans de Goede |
c8dfc6 |
-
|
|
Hans de Goede |
c8dfc6 |
- QTAILQ_FOREACH(aurb, &dev->asyncq, next) {
|
|
Hans de Goede |
c8dfc6 |
- if (p != aurb->packet) {
|
|
Hans de Goede |
c8dfc6 |
- continue;
|
|
Hans de Goede |
c8dfc6 |
- }
|
|
Hans de Goede |
c8dfc6 |
+ USBPacket *p;
|
|
Hans de Goede |
c8dfc6 |
|
|
Hans de Goede |
c8dfc6 |
- DPRINTF("async cancel id %u\n", aurb->packet_id);
|
|
Hans de Goede |
c8dfc6 |
- usbredirparser_send_cancel_data_packet(dev->parser, aurb->packet_id);
|
|
Hans de Goede |
c8dfc6 |
- usbredirparser_do_write(dev->parser);
|
|
Hans de Goede |
c8dfc6 |
+ if (usbredir_is_cancelled(dev, id)) {
|
|
Hans de Goede |
c8dfc6 |
+ return NULL;
|
|
Hans de Goede |
c8dfc6 |
+ }
|
|
Hans de Goede |
c8dfc6 |
|
|
Hans de Goede |
c8dfc6 |
- /* Mark it as dead */
|
|
Hans de Goede |
c8dfc6 |
- aurb->packet = NULL;
|
|
Hans de Goede |
c8dfc6 |
- break;
|
|
Hans de Goede |
c8dfc6 |
+ p = usb_ep_find_packet_by_id(&dev->dev,
|
|
Hans de Goede |
c8dfc6 |
+ (ep & USB_DIR_IN) ? USB_TOKEN_IN : USB_TOKEN_OUT,
|
|
Hans de Goede |
c8dfc6 |
+ ep & 0x0f, id);
|
|
Hans de Goede |
c8dfc6 |
+ if (p == NULL) {
|
|
Hans de Goede |
c8dfc6 |
+ ERROR("could not find packet with id %"PRIu64"\n", id);
|
|
Hans de Goede |
c8dfc6 |
}
|
|
Hans de Goede |
c8dfc6 |
+ return p;
|
|
Hans de Goede |
c8dfc6 |
}
|
|
Hans de Goede |
c8dfc6 |
|
|
Hans de Goede |
c8dfc6 |
static void bufp_alloc(USBRedirDevice *dev,
|
|
|
5544c1 |
@@ -484,24 +483,22 @@ static void usbredir_stop_iso_stream(USBRedirDevice *dev, uint8_t ep)
|
|
Hans de Goede |
c8dfc6 |
static int usbredir_handle_bulk_data(USBRedirDevice *dev, USBPacket *p,
|
|
Hans de Goede |
c8dfc6 |
uint8_t ep)
|
|
Hans de Goede |
c8dfc6 |
{
|
|
Hans de Goede |
c8dfc6 |
- AsyncURB *aurb = async_alloc(dev, p);
|
|
Hans de Goede |
c8dfc6 |
struct usb_redir_bulk_packet_header bulk_packet;
|
|
Hans de Goede |
c8dfc6 |
|
|
Hans de Goede |
c8dfc6 |
- DPRINTF("bulk-out ep %02X len %zd id %u\n", ep,
|
|
Hans de Goede |
c8dfc6 |
- p->iov.size, aurb->packet_id);
|
|
Hans de Goede |
c8dfc6 |
+ DPRINTF("bulk-out ep %02X len %zd id %"PRIu64"\n", ep, p->iov.size, p->id);
|
|
Hans de Goede |
c8dfc6 |
|
|
Hans de Goede |
c8dfc6 |
bulk_packet.endpoint = ep;
|
|
Hans de Goede |
c8dfc6 |
bulk_packet.length = p->iov.size;
|
|
Hans de Goede |
c8dfc6 |
bulk_packet.stream_id = 0;
|
|
Hans de Goede |
c8dfc6 |
|
|
Hans de Goede |
c8dfc6 |
if (ep & USB_DIR_IN) {
|
|
Hans de Goede |
c8dfc6 |
- usbredirparser_send_bulk_packet(dev->parser, aurb->packet_id,
|
|
Hans de Goede |
c8dfc6 |
+ usbredirparser_send_bulk_packet(dev->parser, p->id,
|
|
Hans de Goede |
c8dfc6 |
&bulk_packet, NULL, 0);
|
|
Hans de Goede |
c8dfc6 |
} else {
|
|
Hans de Goede |
c8dfc6 |
uint8_t buf[p->iov.size];
|
|
Hans de Goede |
c8dfc6 |
usb_packet_copy(p, buf, p->iov.size);
|
|
Hans de Goede |
c8dfc6 |
usbredir_log_data(dev, "bulk data out:", buf, p->iov.size);
|
|
Hans de Goede |
c8dfc6 |
- usbredirparser_send_bulk_packet(dev->parser, aurb->packet_id,
|
|
Hans de Goede |
c8dfc6 |
+ usbredirparser_send_bulk_packet(dev->parser, p->id,
|
|
Hans de Goede |
c8dfc6 |
&bulk_packet, buf, p->iov.size);
|
|
Hans de Goede |
c8dfc6 |
}
|
|
Hans de Goede |
c8dfc6 |
usbredirparser_do_write(dev->parser);
|
|
|
5544c1 |
@@ -564,19 +561,18 @@ static int usbredir_handle_interrupt_data(USBRedirDevice *dev,
|
|
Hans de Goede |
c8dfc6 |
return len;
|
|
Hans de Goede |
c8dfc6 |
} else {
|
|
Hans de Goede |
c8dfc6 |
/* Output interrupt endpoint, normal async operation */
|
|
Hans de Goede |
c8dfc6 |
- AsyncURB *aurb = async_alloc(dev, p);
|
|
Hans de Goede |
c8dfc6 |
struct usb_redir_interrupt_packet_header interrupt_packet;
|
|
Hans de Goede |
c8dfc6 |
uint8_t buf[p->iov.size];
|
|
Hans de Goede |
c8dfc6 |
|
|
Hans de Goede |
c8dfc6 |
- DPRINTF("interrupt-out ep %02X len %zd id %u\n", ep, p->iov.size,
|
|
Hans de Goede |
c8dfc6 |
- aurb->packet_id);
|
|
Hans de Goede |
c8dfc6 |
+ DPRINTF("interrupt-out ep %02X len %zd id %"PRIu64"\n", ep,
|
|
Hans de Goede |
c8dfc6 |
+ p->iov.size, p->id);
|
|
Hans de Goede |
c8dfc6 |
|
|
Hans de Goede |
c8dfc6 |
interrupt_packet.endpoint = ep;
|
|
Hans de Goede |
c8dfc6 |
interrupt_packet.length = p->iov.size;
|
|
Hans de Goede |
c8dfc6 |
|
|
Hans de Goede |
c8dfc6 |
usb_packet_copy(p, buf, p->iov.size);
|
|
Hans de Goede |
c8dfc6 |
usbredir_log_data(dev, "interrupt data out:", buf, p->iov.size);
|
|
Hans de Goede |
c8dfc6 |
- usbredirparser_send_interrupt_packet(dev->parser, aurb->packet_id,
|
|
Hans de Goede |
c8dfc6 |
+ usbredirparser_send_interrupt_packet(dev->parser, p->id,
|
|
Hans de Goede |
c8dfc6 |
&interrupt_packet, buf, p->iov.size);
|
|
Hans de Goede |
c8dfc6 |
usbredirparser_do_write(dev->parser);
|
|
Hans de Goede |
c8dfc6 |
return USB_RET_ASYNC;
|
|
|
5544c1 |
@@ -630,10 +626,9 @@ static int usbredir_set_config(USBRedirDevice *dev, USBPacket *p,
|
|
Hans de Goede |
c8dfc6 |
int config)
|
|
Hans de Goede |
c8dfc6 |
{
|
|
Hans de Goede |
c8dfc6 |
struct usb_redir_set_configuration_header set_config;
|
|
Hans de Goede |
c8dfc6 |
- AsyncURB *aurb = async_alloc(dev, p);
|
|
Hans de Goede |
c8dfc6 |
int i;
|
|
Hans de Goede |
c8dfc6 |
|
|
Hans de Goede |
c8dfc6 |
- DPRINTF("set config %d id %u\n", config, aurb->packet_id);
|
|
Hans de Goede |
c8dfc6 |
+ DPRINTF("set config %d id %"PRIu64"\n", config, p->id);
|
|
Hans de Goede |
c8dfc6 |
|
|
Hans de Goede |
c8dfc6 |
for (i = 0; i < MAX_ENDPOINTS; i++) {
|
|
Hans de Goede |
c8dfc6 |
switch (dev->endpoint[i].type) {
|
|
|
5544c1 |
@@ -650,19 +645,16 @@ static int usbredir_set_config(USBRedirDevice *dev, USBPacket *p,
|
|
Hans de Goede |
c8dfc6 |
}
|
|
Hans de Goede |
c8dfc6 |
|
|
Hans de Goede |
c8dfc6 |
set_config.configuration = config;
|
|
Hans de Goede |
c8dfc6 |
- usbredirparser_send_set_configuration(dev->parser, aurb->packet_id,
|
|
Hans de Goede |
c8dfc6 |
- &set_config);
|
|
Hans de Goede |
c8dfc6 |
+ usbredirparser_send_set_configuration(dev->parser, p->id, &set_config);
|
|
Hans de Goede |
c8dfc6 |
usbredirparser_do_write(dev->parser);
|
|
Hans de Goede |
c8dfc6 |
return USB_RET_ASYNC;
|
|
Hans de Goede |
c8dfc6 |
}
|
|
Hans de Goede |
c8dfc6 |
|
|
Hans de Goede |
c8dfc6 |
static int usbredir_get_config(USBRedirDevice *dev, USBPacket *p)
|
|
Hans de Goede |
c8dfc6 |
{
|
|
Hans de Goede |
c8dfc6 |
- AsyncURB *aurb = async_alloc(dev, p);
|
|
Hans de Goede |
c8dfc6 |
-
|
|
Hans de Goede |
c8dfc6 |
- DPRINTF("get config id %u\n", aurb->packet_id);
|
|
Hans de Goede |
c8dfc6 |
+ DPRINTF("get config id %"PRIu64"\n", p->id);
|
|
Hans de Goede |
c8dfc6 |
|
|
Hans de Goede |
c8dfc6 |
- usbredirparser_send_get_configuration(dev->parser, aurb->packet_id);
|
|
Hans de Goede |
c8dfc6 |
+ usbredirparser_send_get_configuration(dev->parser, p->id);
|
|
Hans de Goede |
c8dfc6 |
usbredirparser_do_write(dev->parser);
|
|
Hans de Goede |
c8dfc6 |
return USB_RET_ASYNC;
|
|
Hans de Goede |
c8dfc6 |
}
|
|
|
5544c1 |
@@ -671,11 +663,9 @@ static int usbredir_set_interface(USBRedirDevice *dev, USBPacket *p,
|
|
Hans de Goede |
c8dfc6 |
int interface, int alt)
|
|
Hans de Goede |
c8dfc6 |
{
|
|
Hans de Goede |
c8dfc6 |
struct usb_redir_set_alt_setting_header set_alt;
|
|
Hans de Goede |
c8dfc6 |
- AsyncURB *aurb = async_alloc(dev, p);
|
|
Hans de Goede |
c8dfc6 |
int i;
|
|
Hans de Goede |
c8dfc6 |
|
|
Hans de Goede |
c8dfc6 |
- DPRINTF("set interface %d alt %d id %u\n", interface, alt,
|
|
Hans de Goede |
c8dfc6 |
- aurb->packet_id);
|
|
Hans de Goede |
c8dfc6 |
+ DPRINTF("set interface %d alt %d id %"PRIu64"\n", interface, alt, p->id);
|
|
Hans de Goede |
c8dfc6 |
|
|
Hans de Goede |
c8dfc6 |
for (i = 0; i < MAX_ENDPOINTS; i++) {
|
|
Hans de Goede |
c8dfc6 |
if (dev->endpoint[i].interface == interface) {
|
|
|
5544c1 |
@@ -695,8 +685,7 @@ static int usbredir_set_interface(USBRedirDevice *dev, USBPacket *p,
|
|
Hans de Goede |
c8dfc6 |
|
|
Hans de Goede |
c8dfc6 |
set_alt.interface = interface;
|
|
Hans de Goede |
c8dfc6 |
set_alt.alt = alt;
|
|
Hans de Goede |
c8dfc6 |
- usbredirparser_send_set_alt_setting(dev->parser, aurb->packet_id,
|
|
Hans de Goede |
c8dfc6 |
- &set_alt);
|
|
Hans de Goede |
c8dfc6 |
+ usbredirparser_send_set_alt_setting(dev->parser, p->id, &set_alt);
|
|
Hans de Goede |
c8dfc6 |
usbredirparser_do_write(dev->parser);
|
|
Hans de Goede |
c8dfc6 |
return USB_RET_ASYNC;
|
|
Hans de Goede |
c8dfc6 |
}
|
|
|
5544c1 |
@@ -705,13 +694,11 @@ static int usbredir_get_interface(USBRedirDevice *dev, USBPacket *p,
|
|
Hans de Goede |
c8dfc6 |
int interface)
|
|
Hans de Goede |
c8dfc6 |
{
|
|
Hans de Goede |
c8dfc6 |
struct usb_redir_get_alt_setting_header get_alt;
|
|
Hans de Goede |
c8dfc6 |
- AsyncURB *aurb = async_alloc(dev, p);
|
|
Hans de Goede |
c8dfc6 |
|
|
Hans de Goede |
c8dfc6 |
- DPRINTF("get interface %d id %u\n", interface, aurb->packet_id);
|
|
Hans de Goede |
c8dfc6 |
+ DPRINTF("get interface %d id %"PRIu64"\n", interface, p->id);
|
|
Hans de Goede |
c8dfc6 |
|
|
Hans de Goede |
c8dfc6 |
get_alt.interface = interface;
|
|
Hans de Goede |
c8dfc6 |
- usbredirparser_send_get_alt_setting(dev->parser, aurb->packet_id,
|
|
Hans de Goede |
c8dfc6 |
- &get_alt);
|
|
Hans de Goede |
c8dfc6 |
+ usbredirparser_send_get_alt_setting(dev->parser, p->id, &get_alt);
|
|
Hans de Goede |
c8dfc6 |
usbredirparser_do_write(dev->parser);
|
|
Hans de Goede |
c8dfc6 |
return USB_RET_ASYNC;
|
|
Hans de Goede |
c8dfc6 |
}
|
|
|
5544c1 |
@@ -721,7 +708,6 @@ static int usbredir_handle_control(USBDevice *udev, USBPacket *p,
|
|
Hans de Goede |
c8dfc6 |
{
|
|
Hans de Goede |
c8dfc6 |
USBRedirDevice *dev = DO_UPCAST(USBRedirDevice, dev, udev);
|
|
Hans de Goede |
c8dfc6 |
struct usb_redir_control_packet_header control_packet;
|
|
Hans de Goede |
c8dfc6 |
- AsyncURB *aurb;
|
|
Hans de Goede |
c8dfc6 |
|
|
Hans de Goede |
c8dfc6 |
/* Special cases for certain standard device requests */
|
|
Hans de Goede |
c8dfc6 |
switch (request) {
|
|
|
5544c1 |
@@ -739,13 +725,10 @@ static int usbredir_handle_control(USBDevice *udev, USBPacket *p,
|
|
Hans de Goede |
c8dfc6 |
return usbredir_get_interface(dev, p, index);
|
|
Hans de Goede |
c8dfc6 |
}
|
|
Hans de Goede |
c8dfc6 |
|
|
Hans de Goede |
c8dfc6 |
- /* "Normal" ctrl requests */
|
|
Hans de Goede |
c8dfc6 |
- aurb = async_alloc(dev, p);
|
|
Hans de Goede |
c8dfc6 |
-
|
|
Hans de Goede |
c8dfc6 |
- /* Note request is (bRequestType << 8) | bRequest */
|
|
Hans de Goede |
c8dfc6 |
- DPRINTF("ctrl-out type 0x%x req 0x%x val 0x%x index %d len %d id %u\n",
|
|
Hans de Goede |
c8dfc6 |
- request >> 8, request & 0xff, value, index, length,
|
|
Hans de Goede |
c8dfc6 |
- aurb->packet_id);
|
|
Hans de Goede |
c8dfc6 |
+ /* Normal ctrl requests, note request is (bRequestType << 8) | bRequest */
|
|
Hans de Goede |
c8dfc6 |
+ DPRINTF(
|
|
Hans de Goede |
c8dfc6 |
+ "ctrl-out type 0x%x req 0x%x val 0x%x index %d len %d id %"PRIu64"\n",
|
|
Hans de Goede |
c8dfc6 |
+ request >> 8, request & 0xff, value, index, length, p->id);
|
|
Hans de Goede |
c8dfc6 |
|
|
Hans de Goede |
c8dfc6 |
control_packet.request = request & 0xFF;
|
|
Hans de Goede |
c8dfc6 |
control_packet.requesttype = request >> 8;
|
|
|
5544c1 |
@@ -755,11 +738,11 @@ static int usbredir_handle_control(USBDevice *udev, USBPacket *p,
|
|
Hans de Goede |
c8dfc6 |
control_packet.length = length;
|
|
Hans de Goede |
c8dfc6 |
|
|
Hans de Goede |
c8dfc6 |
if (control_packet.requesttype & USB_DIR_IN) {
|
|
Hans de Goede |
c8dfc6 |
- usbredirparser_send_control_packet(dev->parser, aurb->packet_id,
|
|
Hans de Goede |
c8dfc6 |
+ usbredirparser_send_control_packet(dev->parser, p->id,
|
|
Hans de Goede |
c8dfc6 |
&control_packet, NULL, 0);
|
|
Hans de Goede |
c8dfc6 |
} else {
|
|
Hans de Goede |
c8dfc6 |
usbredir_log_data(dev, "ctrl data out:", data, length);
|
|
Hans de Goede |
c8dfc6 |
- usbredirparser_send_control_packet(dev->parser, aurb->packet_id,
|
|
Hans de Goede |
c8dfc6 |
+ usbredirparser_send_control_packet(dev->parser, p->id,
|
|
Hans de Goede |
c8dfc6 |
&control_packet, data, length);
|
|
Hans de Goede |
c8dfc6 |
}
|
|
Hans de Goede |
c8dfc6 |
usbredirparser_do_write(dev->parser);
|
|
|
5544c1 |
@@ -913,7 +896,7 @@ static int usbredir_initfn(USBDevice *udev)
|
|
Hans de Goede |
c8dfc6 |
dev->chardev_close_bh = qemu_bh_new(usbredir_chardev_close_bh, dev);
|
|
Hans de Goede |
c8dfc6 |
dev->attach_timer = qemu_new_timer_ms(vm_clock, usbredir_do_attach, dev);
|
|
Hans de Goede |
c8dfc6 |
|
|
Hans de Goede |
c8dfc6 |
- QTAILQ_INIT(&dev->asyncq);
|
|
Hans de Goede |
c8dfc6 |
+ QTAILQ_INIT(&dev->cancelled);
|
|
Hans de Goede |
c8dfc6 |
for (i = 0; i < MAX_ENDPOINTS; i++) {
|
|
Hans de Goede |
c8dfc6 |
QTAILQ_INIT(&dev->endpoint[i].bufpq);
|
|
Hans de Goede |
c8dfc6 |
}
|
|
|
5544c1 |
@@ -932,11 +915,12 @@ static int usbredir_initfn(USBDevice *udev)
|
|
Hans de Goede |
c8dfc6 |
|
|
Hans de Goede |
c8dfc6 |
static void usbredir_cleanup_device_queues(USBRedirDevice *dev)
|
|
Hans de Goede |
c8dfc6 |
{
|
|
Hans de Goede |
c8dfc6 |
- AsyncURB *aurb, *next_aurb;
|
|
Hans de Goede |
c8dfc6 |
+ Cancelled *c, *next_c;
|
|
Hans de Goede |
c8dfc6 |
int i;
|
|
Hans de Goede |
c8dfc6 |
|
|
Hans de Goede |
c8dfc6 |
- QTAILQ_FOREACH_SAFE(aurb, &dev->asyncq, next, next_aurb) {
|
|
Hans de Goede |
c8dfc6 |
- async_free(dev, aurb);
|
|
Hans de Goede |
c8dfc6 |
+ QTAILQ_FOREACH_SAFE(c, &dev->cancelled, next, next_c) {
|
|
Hans de Goede |
c8dfc6 |
+ QTAILQ_REMOVE(&dev->cancelled, c, next);
|
|
Hans de Goede |
c8dfc6 |
+ g_free(c);
|
|
Hans de Goede |
c8dfc6 |
}
|
|
Hans de Goede |
c8dfc6 |
for (i = 0; i < MAX_ENDPOINTS; i++) {
|
|
Hans de Goede |
c8dfc6 |
usbredir_free_bufpq(dev, I2EP(i));
|
|
|
5544c1 |
@@ -1202,33 +1186,28 @@ static void usbredir_configuration_status(void *priv, uint32_t id,
|
|
Hans de Goede |
c8dfc6 |
struct usb_redir_configuration_status_header *config_status)
|
|
Hans de Goede |
c8dfc6 |
{
|
|
Hans de Goede |
c8dfc6 |
USBRedirDevice *dev = priv;
|
|
Hans de Goede |
c8dfc6 |
- AsyncURB *aurb;
|
|
Hans de Goede |
c8dfc6 |
+ USBPacket *p;
|
|
Hans de Goede |
c8dfc6 |
int len = 0;
|
|
Hans de Goede |
c8dfc6 |
|
|
Hans de Goede |
c8dfc6 |
DPRINTF("set config status %d config %d id %u\n", config_status->status,
|
|
Hans de Goede |
c8dfc6 |
config_status->configuration, id);
|
|
Hans de Goede |
c8dfc6 |
|
|
Hans de Goede |
c8dfc6 |
- aurb = async_find(dev, id);
|
|
Hans de Goede |
c8dfc6 |
- if (!aurb) {
|
|
Hans de Goede |
c8dfc6 |
- return;
|
|
Hans de Goede |
c8dfc6 |
- }
|
|
Hans de Goede |
c8dfc6 |
- if (aurb->packet) {
|
|
Hans de Goede |
c8dfc6 |
+ p = usbredir_find_packet_by_id(dev, 0, id);
|
|
Hans de Goede |
c8dfc6 |
+ if (p) {
|
|
Hans de Goede |
c8dfc6 |
if (dev->dev.setup_buf[0] & USB_DIR_IN) {
|
|
Hans de Goede |
c8dfc6 |
dev->dev.data_buf[0] = config_status->configuration;
|
|
Hans de Goede |
c8dfc6 |
len = 1;
|
|
Hans de Goede |
c8dfc6 |
}
|
|
Hans de Goede |
c8dfc6 |
- aurb->packet->result =
|
|
Hans de Goede |
c8dfc6 |
- usbredir_handle_status(dev, config_status->status, len);
|
|
Hans de Goede |
c8dfc6 |
- usb_generic_async_ctrl_complete(&dev->dev, aurb->packet);
|
|
Hans de Goede |
c8dfc6 |
+ p->result = usbredir_handle_status(dev, config_status->status, len);
|
|
Hans de Goede |
c8dfc6 |
+ usb_generic_async_ctrl_complete(&dev->dev, p);
|
|
Hans de Goede |
c8dfc6 |
}
|
|
Hans de Goede |
c8dfc6 |
- async_free(dev, aurb);
|
|
Hans de Goede |
c8dfc6 |
}
|
|
Hans de Goede |
c8dfc6 |
|
|
Hans de Goede |
c8dfc6 |
static void usbredir_alt_setting_status(void *priv, uint32_t id,
|
|
Hans de Goede |
c8dfc6 |
struct usb_redir_alt_setting_status_header *alt_setting_status)
|
|
Hans de Goede |
c8dfc6 |
{
|
|
Hans de Goede |
c8dfc6 |
USBRedirDevice *dev = priv;
|
|
Hans de Goede |
c8dfc6 |
- AsyncURB *aurb;
|
|
Hans de Goede |
c8dfc6 |
+ USBPacket *p;
|
|
Hans de Goede |
c8dfc6 |
int len = 0;
|
|
Hans de Goede |
c8dfc6 |
|
|
Hans de Goede |
c8dfc6 |
DPRINTF("alt status %d intf %d alt %d id: %u\n",
|
|
|
5544c1 |
@@ -1236,20 +1215,16 @@ static void usbredir_alt_setting_status(void *priv, uint32_t id,
|
|
Hans de Goede |
c8dfc6 |
alt_setting_status->interface,
|
|
Hans de Goede |
c8dfc6 |
alt_setting_status->alt, id);
|
|
Hans de Goede |
c8dfc6 |
|
|
Hans de Goede |
c8dfc6 |
- aurb = async_find(dev, id);
|
|
Hans de Goede |
c8dfc6 |
- if (!aurb) {
|
|
Hans de Goede |
c8dfc6 |
- return;
|
|
Hans de Goede |
c8dfc6 |
- }
|
|
Hans de Goede |
c8dfc6 |
- if (aurb->packet) {
|
|
Hans de Goede |
c8dfc6 |
+ p = usbredir_find_packet_by_id(dev, 0, id);
|
|
Hans de Goede |
c8dfc6 |
+ if (p) {
|
|
Hans de Goede |
c8dfc6 |
if (dev->dev.setup_buf[0] & USB_DIR_IN) {
|
|
Hans de Goede |
c8dfc6 |
dev->dev.data_buf[0] = alt_setting_status->alt;
|
|
Hans de Goede |
c8dfc6 |
len = 1;
|
|
Hans de Goede |
c8dfc6 |
}
|
|
Hans de Goede |
c8dfc6 |
- aurb->packet->result =
|
|
Hans de Goede |
c8dfc6 |
+ p->result =
|
|
Hans de Goede |
c8dfc6 |
usbredir_handle_status(dev, alt_setting_status->status, len);
|
|
Hans de Goede |
c8dfc6 |
- usb_generic_async_ctrl_complete(&dev->dev, aurb->packet);
|
|
Hans de Goede |
c8dfc6 |
+ usb_generic_async_ctrl_complete(&dev->dev, p);
|
|
Hans de Goede |
c8dfc6 |
}
|
|
Hans de Goede |
c8dfc6 |
- async_free(dev, aurb);
|
|
Hans de Goede |
c8dfc6 |
}
|
|
Hans de Goede |
c8dfc6 |
|
|
Hans de Goede |
c8dfc6 |
static void usbredir_iso_stream_status(void *priv, uint32_t id,
|
|
|
5544c1 |
@@ -1304,19 +1279,14 @@ static void usbredir_control_packet(void *priv, uint32_t id,
|
|
Hans de Goede |
c8dfc6 |
uint8_t *data, int data_len)
|
|
Hans de Goede |
c8dfc6 |
{
|
|
Hans de Goede |
c8dfc6 |
USBRedirDevice *dev = priv;
|
|
Hans de Goede |
c8dfc6 |
+ USBPacket *p;
|
|
Hans de Goede |
c8dfc6 |
int len = control_packet->length;
|
|
Hans de Goede |
c8dfc6 |
- AsyncURB *aurb;
|
|
Hans de Goede |
c8dfc6 |
|
|
Hans de Goede |
c8dfc6 |
DPRINTF("ctrl-in status %d len %d id %u\n", control_packet->status,
|
|
Hans de Goede |
c8dfc6 |
len, id);
|
|
Hans de Goede |
c8dfc6 |
|
|
Hans de Goede |
c8dfc6 |
- aurb = async_find(dev, id);
|
|
Hans de Goede |
c8dfc6 |
- if (!aurb) {
|
|
Hans de Goede |
c8dfc6 |
- free(data);
|
|
Hans de Goede |
c8dfc6 |
- return;
|
|
Hans de Goede |
c8dfc6 |
- }
|
|
Hans de Goede |
c8dfc6 |
-
|
|
Hans de Goede |
c8dfc6 |
- if (aurb->packet) {
|
|
Hans de Goede |
c8dfc6 |
+ p = usbredir_find_packet_by_id(dev, 0, id);
|
|
Hans de Goede |
c8dfc6 |
+ if (p) {
|
|
Hans de Goede |
c8dfc6 |
len = usbredir_handle_status(dev, control_packet->status, len);
|
|
Hans de Goede |
c8dfc6 |
if (len > 0) {
|
|
Hans de Goede |
c8dfc6 |
usbredir_log_data(dev, "ctrl data in:", data, data_len);
|
|
|
5544c1 |
@@ -1328,10 +1298,9 @@ static void usbredir_control_packet(void *priv, uint32_t id,
|
|
Hans de Goede |
c8dfc6 |
len = USB_RET_STALL;
|
|
Hans de Goede |
c8dfc6 |
}
|
|
Hans de Goede |
c8dfc6 |
}
|
|
Hans de Goede |
c8dfc6 |
- aurb->packet->result = len;
|
|
Hans de Goede |
c8dfc6 |
- usb_generic_async_ctrl_complete(&dev->dev, aurb->packet);
|
|
Hans de Goede |
c8dfc6 |
+ p->result = len;
|
|
Hans de Goede |
c8dfc6 |
+ usb_generic_async_ctrl_complete(&dev->dev, p);
|
|
Hans de Goede |
c8dfc6 |
}
|
|
Hans de Goede |
c8dfc6 |
- async_free(dev, aurb);
|
|
Hans de Goede |
c8dfc6 |
free(data);
|
|
Hans de Goede |
c8dfc6 |
}
|
|
Hans de Goede |
c8dfc6 |
|
|
|
5544c1 |
@@ -1342,33 +1311,27 @@ static void usbredir_bulk_packet(void *priv, uint32_t id,
|
|
Hans de Goede |
c8dfc6 |
USBRedirDevice *dev = priv;
|
|
Hans de Goede |
c8dfc6 |
uint8_t ep = bulk_packet->endpoint;
|
|
Hans de Goede |
c8dfc6 |
int len = bulk_packet->length;
|
|
Hans de Goede |
c8dfc6 |
- AsyncURB *aurb;
|
|
Hans de Goede |
c8dfc6 |
+ USBPacket *p;
|
|
Hans de Goede |
c8dfc6 |
|
|
Hans de Goede |
c8dfc6 |
DPRINTF("bulk-in status %d ep %02X len %d id %u\n", bulk_packet->status,
|
|
Hans de Goede |
c8dfc6 |
ep, len, id);
|
|
Hans de Goede |
c8dfc6 |
|
|
Hans de Goede |
c8dfc6 |
- aurb = async_find(dev, id);
|
|
Hans de Goede |
c8dfc6 |
- if (!aurb) {
|
|
Hans de Goede |
c8dfc6 |
- free(data);
|
|
Hans de Goede |
c8dfc6 |
- return;
|
|
Hans de Goede |
c8dfc6 |
- }
|
|
Hans de Goede |
c8dfc6 |
-
|
|
Hans de Goede |
c8dfc6 |
- if (aurb->packet) {
|
|
Hans de Goede |
c8dfc6 |
+ p = usbredir_find_packet_by_id(dev, ep, id);
|
|
Hans de Goede |
c8dfc6 |
+ if (p) {
|
|
Hans de Goede |
c8dfc6 |
len = usbredir_handle_status(dev, bulk_packet->status, len);
|
|
Hans de Goede |
c8dfc6 |
if (len > 0) {
|
|
Hans de Goede |
c8dfc6 |
usbredir_log_data(dev, "bulk data in:", data, data_len);
|
|
Hans de Goede |
c8dfc6 |
- if (data_len <= aurb->packet->iov.size) {
|
|
Hans de Goede |
c8dfc6 |
- usb_packet_copy(aurb->packet, data, data_len);
|
|
Hans de Goede |
c8dfc6 |
+ if (data_len <= p->iov.size) {
|
|
Hans de Goede |
c8dfc6 |
+ usb_packet_copy(p, data, data_len);
|
|
Hans de Goede |
c8dfc6 |
} else {
|
|
Hans de Goede |
c8dfc6 |
ERROR("bulk buffer too small (%d > %zd)\n", data_len,
|
|
Hans de Goede |
c8dfc6 |
- aurb->packet->iov.size);
|
|
Hans de Goede |
c8dfc6 |
+ p->iov.size);
|
|
Hans de Goede |
c8dfc6 |
len = USB_RET_STALL;
|
|
Hans de Goede |
c8dfc6 |
}
|
|
Hans de Goede |
c8dfc6 |
}
|
|
Hans de Goede |
c8dfc6 |
- aurb->packet->result = len;
|
|
Hans de Goede |
c8dfc6 |
- usb_packet_complete(&dev->dev, aurb->packet);
|
|
Hans de Goede |
c8dfc6 |
+ p->result = len;
|
|
Hans de Goede |
c8dfc6 |
+ usb_packet_complete(&dev->dev, p);
|
|
Hans de Goede |
c8dfc6 |
}
|
|
Hans de Goede |
c8dfc6 |
- async_free(dev, aurb);
|
|
Hans de Goede |
c8dfc6 |
free(data);
|
|
Hans de Goede |
c8dfc6 |
}
|
|
Hans de Goede |
c8dfc6 |
|
|
|
5544c1 |
@@ -1426,17 +1389,12 @@ static void usbredir_interrupt_packet(void *priv, uint32_t id,
|
|
Hans de Goede |
c8dfc6 |
} else {
|
|
Hans de Goede |
c8dfc6 |
int len = interrupt_packet->length;
|
|
Hans de Goede |
c8dfc6 |
|
|
Hans de Goede |
c8dfc6 |
- AsyncURB *aurb = async_find(dev, id);
|
|
Hans de Goede |
c8dfc6 |
- if (!aurb) {
|
|
Hans de Goede |
c8dfc6 |
- return;
|
|
Hans de Goede |
c8dfc6 |
- }
|
|
Hans de Goede |
c8dfc6 |
-
|
|
Hans de Goede |
c8dfc6 |
- if (aurb->packet) {
|
|
Hans de Goede |
c8dfc6 |
- aurb->packet->result = usbredir_handle_status(dev,
|
|
Hans de Goede |
c8dfc6 |
+ USBPacket *p = usbredir_find_packet_by_id(dev, ep, id);
|
|
Hans de Goede |
c8dfc6 |
+ if (p) {
|
|
Hans de Goede |
c8dfc6 |
+ p->result = usbredir_handle_status(dev,
|
|
Hans de Goede |
c8dfc6 |
interrupt_packet->status, len);
|
|
Hans de Goede |
c8dfc6 |
- usb_packet_complete(&dev->dev, aurb->packet);
|
|
Hans de Goede |
c8dfc6 |
+ usb_packet_complete(&dev->dev, p);
|
|
Hans de Goede |
c8dfc6 |
}
|
|
Hans de Goede |
c8dfc6 |
- async_free(dev, aurb);
|
|
Hans de Goede |
c8dfc6 |
}
|
|
Hans de Goede |
c8dfc6 |
}
|
|
Hans de Goede |
c8dfc6 |
|
|
Hans de Goede |
c8dfc6 |
--
|
|
|
5544c1 |
1.7.12.1
|
|
Hans de Goede |
c8dfc6 |
|