USB: Allow transfer_buffer with transfer_dma
[safe/jmp/linux-2.6] / drivers / usb / core / urb.c
index c0feee2..94ea972 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, unsigned 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, unsigned 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,23 +229,21 @@ int usb_submit_urb(struct urb *urb, unsigned 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;
-       urb->bandwidth = 0;
 
        /* Lots of sanity checks, so HCDs can rely on clean data
         * and don't need to duplicate tests
         */
        pipe = urb->pipe;
-       temp = usb_pipetype (pipe);
-       is_out = usb_pipeout (pipe);
+       temp = usb_pipetype(pipe);
+       is_out = usb_pipeout(pipe);
 
-       if (!usb_pipecontrol (pipe) && dev->state < USB_STATE_CONFIGURED)
+       if (!usb_pipecontrol(pipe) && dev->state < USB_STATE_CONFIGURED)
                return -ENODEV;
 
        /* FIXME there should be a sharable lock protecting us against
@@ -262,11 +252,11 @@ int usb_submit_urb(struct urb *urb, unsigned mem_flags)
         * checks get made.)
         */
 
-       max = usb_maxpacket (dev, pipe, is_out);
+       max = usb_maxpacket(dev, pipe, is_out);
        if (max <= 0) {
                dev_dbg(&dev->dev,
                        "bogus endpoint ep%d%s in %s (bad maxpacket %d)\n",
-                       usb_pipeendpoint (pipe), is_out ? "out" : "in",
+                       usb_pipeendpoint(pipe), is_out ? "out" : "in",
                        __FUNCTION__, max);
                return -EMSGSIZE;
        }
@@ -288,11 +278,11 @@ int usb_submit_urb(struct urb *urb, unsigned mem_flags)
                if (urb->number_of_packets <= 0)                    
                        return -EINVAL;
                for (n = 0; n < urb->number_of_packets; n++) {
-                       len = urb->iso_frame_desc [n].length;
+                       len = urb->iso_frame_desc[n].length;
                        if (len < 0 || len > max) 
                                return -EMSGSIZE;
-                       urb->iso_frame_desc [n].status = -EXDEV;
-                       urb->iso_frame_desc [n].actual_length = 0;
+                       urb->iso_frame_desc[n].status = -EXDEV;
+                       urb->iso_frame_desc[n].actual_length = 0;
                }
        }
 
@@ -309,9 +299,8 @@ int usb_submit_urb(struct urb *urb, unsigned 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)
@@ -332,7 +321,7 @@ int usb_submit_urb(struct urb *urb, unsigned mem_flags)
 
        /* fail if submitter gave bogus flags */
        if (urb->transfer_flags != orig_flags) {
-               err ("BOGUS urb flags, %x --> %x",
+               err("BOGUS urb flags, %x --> %x",
                        orig_flags, urb->transfer_flags);
                return -EINVAL;
        }
@@ -383,7 +372,7 @@ int usb_submit_urb(struct urb *urb, unsigned mem_flags)
                urb->interval = temp;
        }
 
-       return op->submit_urb (urb, mem_flags);
+       return usb_hcd_submit_urb(urb, mem_flags);
 }
 
 /*-------------------------------------------------------------------*/
@@ -400,14 +389,8 @@ int usb_submit_urb(struct urb *urb, unsigned 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 +436,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 +463,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);