提交 eb5e680a 编写于 作者: G Gerd Hoffmann

usb: move cancel callback to USBDeviceInfo

Remove the cancel callback from the USBPacket struct, move it over
to USBDeviceInfo.  Zap usb_defer_packet() which is obsolete now.
Signed-off-by: NGerd Hoffmann <kraxel@redhat.com>
上级 4ff658fb
...@@ -315,9 +315,9 @@ static int usb_msd_handle_control(USBDevice *dev, USBPacket *p, ...@@ -315,9 +315,9 @@ static int usb_msd_handle_control(USBDevice *dev, USBPacket *p,
return ret; return ret;
} }
static void usb_msd_cancel_io(USBPacket *p, void *opaque) static void usb_msd_cancel_io(USBDevice *dev, USBPacket *p)
{ {
MSDState *s = opaque; MSDState *s = DO_UPCAST(MSDState, dev, dev);
s->scsi_dev->info->cancel_io(s->scsi_dev, s->tag); s->scsi_dev->info->cancel_io(s->scsi_dev, s->tag);
s->packet = NULL; s->packet = NULL;
s->scsi_len = 0; s->scsi_len = 0;
...@@ -398,7 +398,6 @@ static int usb_msd_handle_data(USBDevice *dev, USBPacket *p) ...@@ -398,7 +398,6 @@ static int usb_msd_handle_data(USBDevice *dev, USBPacket *p)
} }
if (s->usb_len) { if (s->usb_len) {
DPRINTF("Deferring packet %p\n", p); DPRINTF("Deferring packet %p\n", p);
usb_defer_packet(p, usb_msd_cancel_io, s);
s->packet = p; s->packet = p;
ret = USB_RET_ASYNC; ret = USB_RET_ASYNC;
} else { } else {
...@@ -421,7 +420,6 @@ static int usb_msd_handle_data(USBDevice *dev, USBPacket *p) ...@@ -421,7 +420,6 @@ static int usb_msd_handle_data(USBDevice *dev, USBPacket *p)
if (s->data_len != 0 || len < 13) if (s->data_len != 0 || len < 13)
goto fail; goto fail;
/* Waiting for SCSI write to complete. */ /* Waiting for SCSI write to complete. */
usb_defer_packet(p, usb_msd_cancel_io, s);
s->packet = p; s->packet = p;
ret = USB_RET_ASYNC; ret = USB_RET_ASYNC;
break; break;
...@@ -455,7 +453,6 @@ static int usb_msd_handle_data(USBDevice *dev, USBPacket *p) ...@@ -455,7 +453,6 @@ static int usb_msd_handle_data(USBDevice *dev, USBPacket *p)
} }
if (s->usb_len) { if (s->usb_len) {
DPRINTF("Deferring packet %p\n", p); DPRINTF("Deferring packet %p\n", p);
usb_defer_packet(p, usb_msd_cancel_io, s);
s->packet = p; s->packet = p;
ret = USB_RET_ASYNC; ret = USB_RET_ASYNC;
} else { } else {
...@@ -604,6 +601,7 @@ static struct USBDeviceInfo msd_info = { ...@@ -604,6 +601,7 @@ static struct USBDeviceInfo msd_info = {
.usb_desc = &desc, .usb_desc = &desc,
.init = usb_msd_initfn, .init = usb_msd_initfn,
.handle_packet = usb_generic_handle_packet, .handle_packet = usb_generic_handle_packet,
.cancel_packet = usb_msd_cancel_io,
.handle_attach = usb_desc_attach, .handle_attach = usb_desc_attach,
.handle_reset = usb_msd_handle_reset, .handle_reset = usb_msd_handle_reset,
.handle_control = usb_msd_handle_control, .handle_control = usb_msd_handle_control,
......
...@@ -345,6 +345,6 @@ void usb_packet_complete(USBDevice *dev, USBPacket *p) ...@@ -345,6 +345,6 @@ void usb_packet_complete(USBDevice *dev, USBPacket *p)
void usb_cancel_packet(USBPacket * p) void usb_cancel_packet(USBPacket * p)
{ {
assert(p->owner != NULL); assert(p->owner != NULL);
p->cancel_cb(p, p->cancel_opaque); p->owner->info->cancel_packet(p->owner, p);
p->owner = NULL; p->owner = NULL;
} }
...@@ -193,6 +193,11 @@ struct USBDeviceInfo { ...@@ -193,6 +193,11 @@ struct USBDeviceInfo {
*/ */
int (*handle_packet)(USBDevice *dev, USBPacket *p); int (*handle_packet)(USBDevice *dev, USBPacket *p);
/*
* Called when a packet is canceled.
*/
void (*cancel_packet)(USBDevice *dev, USBPacket *p);
/* /*
* Called when device is destroyed. * Called when device is destroyed.
*/ */
...@@ -263,24 +268,12 @@ struct USBPacket { ...@@ -263,24 +268,12 @@ struct USBPacket {
int len; int len;
/* Internal use by the USB layer. */ /* Internal use by the USB layer. */
USBDevice *owner; USBDevice *owner;
USBCallback *cancel_cb;
void *cancel_opaque;
}; };
int usb_handle_packet(USBDevice *dev, USBPacket *p); int usb_handle_packet(USBDevice *dev, USBPacket *p);
void usb_packet_complete(USBDevice *dev, USBPacket *p); void usb_packet_complete(USBDevice *dev, USBPacket *p);
void usb_cancel_packet(USBPacket * p); void usb_cancel_packet(USBPacket * p);
/* Defer completion of a USB packet. The hadle_packet routine should then
return USB_RET_ASYNC. Packets that complete immediately (before
handle_packet returns) should not call this method. */
static inline void usb_defer_packet(USBPacket *p, USBCallback *cancel,
void * opaque)
{
p->cancel_cb = cancel;
p->cancel_opaque = opaque;
}
void usb_attach(USBPort *port, USBDevice *dev); void usb_attach(USBPort *port, USBDevice *dev);
void usb_wakeup(USBDevice *dev); void usb_wakeup(USBDevice *dev);
int usb_generic_handle_packet(USBDevice *s, USBPacket *p); int usb_generic_handle_packet(USBDevice *s, USBPacket *p);
......
...@@ -335,9 +335,9 @@ static void async_complete(void *opaque) ...@@ -335,9 +335,9 @@ static void async_complete(void *opaque)
} }
} }
static void async_cancel(USBPacket *p, void *opaque) static void usb_host_async_cancel(USBDevice *dev, USBPacket *p)
{ {
USBHostDevice *s = opaque; USBHostDevice *s = DO_UPCAST(USBHostDevice, dev, dev);
AsyncURB *aurb; AsyncURB *aurb;
QLIST_FOREACH(aurb, &s->aurbs, next) { QLIST_FOREACH(aurb, &s->aurbs, next) {
...@@ -736,7 +736,6 @@ static int usb_host_handle_data(USBDevice *dev, USBPacket *p) ...@@ -736,7 +736,6 @@ static int usb_host_handle_data(USBDevice *dev, USBPacket *p)
} }
} }
usb_defer_packet(p, async_cancel, s);
return USB_RET_ASYNC; return USB_RET_ASYNC;
} }
...@@ -868,7 +867,6 @@ static int usb_host_handle_control(USBDevice *dev, USBPacket *p, ...@@ -868,7 +867,6 @@ static int usb_host_handle_control(USBDevice *dev, USBPacket *p,
} }
} }
usb_defer_packet(p, async_cancel, s);
return USB_RET_ASYNC; return USB_RET_ASYNC;
} }
...@@ -1197,6 +1195,7 @@ static struct USBDeviceInfo usb_host_dev_info = { ...@@ -1197,6 +1195,7 @@ static struct USBDeviceInfo usb_host_dev_info = {
.qdev.size = sizeof(USBHostDevice), .qdev.size = sizeof(USBHostDevice),
.init = usb_host_initfn, .init = usb_host_initfn,
.handle_packet = usb_generic_handle_packet, .handle_packet = usb_generic_handle_packet,
.cancel_packet = usb_host_async_cancel,
.handle_data = usb_host_handle_data, .handle_data = usb_host_handle_data,
.handle_control = usb_host_handle_control, .handle_control = usb_host_handle_control,
.handle_reset = usb_host_handle_reset, .handle_reset = usb_host_handle_reset,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册