fedora core 6 1.2949 + vserver 2.2.0
[linux-2.6.git] / drivers / usb / core / urb.c
index 0faf18d..9801d08 100644 (file)
@@ -1,15 +1,8 @@
-#include <linux/config.h>
 #include <linux/module.h>
 #include <linux/string.h>
 #include <linux/bitops.h>
 #include <linux/slab.h>
 #include <linux/init.h>
-
-#ifdef CONFIG_USB_DEBUG
-       #define DEBUG
-#else
-       #undef DEBUG
-#endif
 #include <linux/usb.h>
 #include "hcd.h"
 
@@ -60,11 +53,11 @@ void usb_init_urb(struct urb *urb)
  *
  * The driver must call usb_free_urb() when it is finished with the urb.
  */
-struct urb *usb_alloc_urb(int iso_packets, int mem_flags)
+struct urb *usb_alloc_urb(int iso_packets, gfp_t mem_flags)
 {
        struct urb *urb;
 
-       urb = (struct urb *)kmalloc(sizeof(struct urb) + 
+       urb = kmalloc(sizeof(struct urb) +
                iso_packets * sizeof(struct usb_iso_packet_descriptor),
                mem_flags);
        if (!urb) {
@@ -224,11 +217,10 @@ struct urb * usb_get_urb(struct urb *urb)
  *      GFP_NOIO, unless b) or c) apply
  *
  */
-int usb_submit_urb(struct urb *urb, int mem_flags)
+int usb_submit_urb(struct urb *urb, gfp_t mem_flags)
 {
        int                     pipe, temp, max;
        struct usb_device       *dev;
-       struct usb_operations   *op;
        int                     is_out;
 
        if (!urb || urb->hcpriv || !urb->complete)
@@ -237,10 +229,9 @@ int usb_submit_urb(struct urb *urb, int mem_flags)
            (dev->state < USB_STATE_DEFAULT) ||
            (!dev->bus) || (dev->devnum <= 0))
                return -ENODEV;
-       if (dev->state == USB_STATE_SUSPENDED)
+       if (dev->bus->controller->power.power_state.event != PM_EVENT_ON
+                       || dev->state == USB_STATE_SUSPENDED)
                return -EHOSTUNREACH;
-       if (!(op = dev->bus->op) || !op->submit_urb)
-               return -ENODEV;
 
        urb->status = -EINPROGRESS;
        urb->actual_length = 0;
@@ -309,9 +300,8 @@ int usb_submit_urb(struct urb *urb, int mem_flags)
        unsigned int    allowed;
 
        /* enforce simple/standard policy */
-       allowed = URB_ASYNC_UNLINK;     // affects later unlinks
-       allowed |= (URB_NO_TRANSFER_DMA_MAP | URB_NO_SETUP_DMA_MAP);
-       allowed |= URB_NO_INTERRUPT;
+       allowed = (URB_NO_TRANSFER_DMA_MAP | URB_NO_SETUP_DMA_MAP |
+                       URB_NO_INTERRUPT);
        switch (temp) {
        case PIPE_BULK:
                if (is_out)
@@ -383,7 +373,7 @@ int usb_submit_urb(struct urb *urb, int mem_flags)
                urb->interval = temp;
        }
 
-       return op->submit_urb (urb, mem_flags);
+       return usb_hcd_submit_urb (urb, mem_flags);
 }
 
 /*-------------------------------------------------------------------*/
@@ -400,14 +390,8 @@ int usb_submit_urb(struct urb *urb, int mem_flags)
  * canceled (rather than any other code) and will quickly be removed
  * from host controller data structures.
  *
- * In the past, clearing the URB_ASYNC_UNLINK transfer flag for the
- * URB indicated that the request was synchronous.  This usage is now
- * deprecated; if the flag is clear the call will be forwarded to
- * usb_kill_urb() and the return value will be 0.  In the future, drivers
- * should call usb_kill_urb() directly for synchronous unlinking.
- *
- * When the URB_ASYNC_UNLINK transfer flag for the URB is set, this
- * request is asynchronous.  Success is indicated by returning -EINPROGRESS,
+ * This request is always asynchronous.
+ * Success is indicated by returning -EINPROGRESS,
  * at which time the URB will normally have been unlinked but not yet
  * given back to the device driver.  When it is called, the completion
  * function will see urb->status == -ECONNRESET.  Failure is indicated
@@ -453,20 +437,9 @@ int usb_unlink_urb(struct urb *urb)
 {
        if (!urb)
                return -EINVAL;
-       if (!(urb->transfer_flags & URB_ASYNC_UNLINK)) {
-#ifdef CONFIG_DEBUG_KERNEL
-               if (printk_ratelimit()) {
-                       printk(KERN_NOTICE "usb_unlink_urb() is deprecated for "
-                               "synchronous unlinks.  Use usb_kill_urb() instead.\n");
-                       WARN_ON(1);
-               }
-#endif
-               usb_kill_urb(urb);
-               return 0;
-       }
-       if (!(urb->dev && urb->dev->bus && urb->dev->bus->op))
+       if (!(urb->dev && urb->dev->bus))
                return -ENODEV;
-       return urb->dev->bus->op->unlink_urb(urb, -ECONNRESET);
+       return usb_hcd_unlink_urb(urb, -ECONNRESET);
 }
 
 /**
@@ -491,13 +464,14 @@ int usb_unlink_urb(struct urb *urb)
  */
 void usb_kill_urb(struct urb *urb)
 {
-       if (!(urb && urb->dev && urb->dev->bus && urb->dev->bus->op))
+       might_sleep();
+       if (!(urb && urb->dev && urb->dev->bus))
                return;
        spin_lock_irq(&urb->lock);
        ++urb->reject;
        spin_unlock_irq(&urb->lock);
 
-       urb->dev->bus->op->unlink_urb(urb, -ENOENT);
+       usb_hcd_unlink_urb(urb, -ENOENT);
        wait_event(usb_kill_urb_queue, atomic_read(&urb->use_count) == 0);
 
        spin_lock_irq(&urb->lock);