Revision 4ff658fb

b/hw/usb.c
313 313
{
314 314
    int ret;
315 315

  
316
    assert(p->owner == NULL);
316 317
    ret = dev->info->handle_packet(dev, p);
318
    if (ret == USB_RET_ASYNC) {
319
        if (p->owner == NULL) {
320
            p->owner = dev;
321
        } else {
322
            /* We'll end up here when usb_handle_packet is called
323
             * recursively due to a hub being in the chain.  Nothing
324
             * to do.  Leave p->owner pointing to the device, not the
325
             * hub. */;
326
        }
327
    }
317 328
    return ret;
318 329
}
330

  
331
/* Notify the controller that an async packet is complete.  This should only
332
   be called for packets previously deferred by returning USB_RET_ASYNC from
333
   handle_packet. */
334
void usb_packet_complete(USBDevice *dev, USBPacket *p)
335
{
336
    /* Note: p->owner != dev is possible in case dev is a hub */
337
    assert(p->owner != NULL);
338
    dev->port->ops->complete(dev, p);
339
    p->owner = NULL;
340
}
341

  
342
/* Cancel an active packet.  The packed must have been deferred by
343
   returning USB_RET_ASYNC from handle_packet, and not yet
344
   completed.  */
345
void usb_cancel_packet(USBPacket * p)
346
{
347
    assert(p->owner != NULL);
348
    p->cancel_cb(p, p->cancel_opaque);
349
    p->owner = NULL;
350
}
b/hw/usb.h
262 262
    uint8_t *data;
263 263
    int len;
264 264
    /* Internal use by the USB layer.  */
265
    USBDevice *owner;
265 266
    USBCallback *cancel_cb;
266 267
    void *cancel_opaque;
267 268
};
268 269

  
269 270
int usb_handle_packet(USBDevice *dev, USBPacket *p);
271
void usb_packet_complete(USBDevice *dev, USBPacket *p);
272
void usb_cancel_packet(USBPacket * p);
270 273

  
271 274
/* Defer completion of a USB packet.  The hadle_packet routine should then
272 275
   return USB_RET_ASYNC.  Packets that complete immediately (before
......
278 281
    p->cancel_opaque = opaque;
279 282
}
280 283

  
281
/* Notify the controller that an async packet is complete.  This should only
282
   be called for packets previously deferred with usb_defer_packet, and
283
   should never be called from within handle_packet.  */
284
static inline void usb_packet_complete(USBDevice *dev, USBPacket *p)
285
{
286
    dev->port->ops->complete(dev, p);
287
}
288

  
289
/* Cancel an active packet.  The packed must have been deferred with
290
   usb_defer_packet,  and not yet completed.  */
291
static inline void usb_cancel_packet(USBPacket * p)
292
{
293
    p->cancel_cb(p, p->cancel_opaque);
294
}
295

  
296 284
void usb_attach(USBPort *port, USBDevice *dev);
297 285
void usb_wakeup(USBDevice *dev);
298 286
int usb_generic_handle_packet(USBDevice *s, USBPacket *p);

Also available in: Unified diff