include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit...
[linux-2.6-block.git] / drivers / usb / host / xhci-mem.c
index bffcef7a5545ec87dbdcc24cd0d43a45be401f60..c09539bad1ee0ab15c5ad3def5fed46ef68c117f 100644 (file)
@@ -22,6 +22,7 @@
 
 #include <linux/usb.h>
 #include <linux/pci.h>
+#include <linux/slab.h>
 #include <linux/dmapool.h>
 
 #include "xhci.h"
@@ -198,6 +199,31 @@ fail:
        return 0;
 }
 
+void xhci_free_or_cache_endpoint_ring(struct xhci_hcd *xhci,
+               struct xhci_virt_device *virt_dev,
+               unsigned int ep_index)
+{
+       int rings_cached;
+
+       rings_cached = virt_dev->num_rings_cached;
+       if (rings_cached < XHCI_MAX_RINGS_CACHED) {
+               virt_dev->num_rings_cached++;
+               rings_cached = virt_dev->num_rings_cached;
+               virt_dev->ring_cache[rings_cached] =
+                       virt_dev->eps[ep_index].ring;
+               xhci_dbg(xhci, "Cached old ring, "
+                               "%d ring%s cached\n",
+                               rings_cached,
+                               (rings_cached > 1) ? "s" : "");
+       } else {
+               xhci_ring_free(xhci, virt_dev->eps[ep_index].ring);
+               xhci_dbg(xhci, "Ring cache full (%d rings), "
+                               "freeing ring\n",
+                               virt_dev->num_rings_cached);
+       }
+       virt_dev->eps[ep_index].ring = NULL;
+}
+
 /* Zero an endpoint ring (except for link TRBs) and move the enqueue and dequeue
  * pointers to the beginning of the ring.
  */
@@ -242,6 +268,8 @@ struct xhci_container_ctx *xhci_alloc_container_ctx(struct xhci_hcd *xhci,
 void xhci_free_container_ctx(struct xhci_hcd *xhci,
                             struct xhci_container_ctx *ctx)
 {
+       if (!ctx)
+               return;
        dma_pool_free(xhci->device_pool, ctx->bytes, ctx->dma);
        kfree(ctx);
 }
@@ -427,7 +455,7 @@ int xhci_setup_addressable_virt_dev(struct xhci_hcd *xhci, struct usb_device *ud
        case USB_SPEED_LOW:
                slot_ctx->dev_info |= (u32) SLOT_SPEED_LS;
                break;
-       case USB_SPEED_VARIABLE:
+       case USB_SPEED_WIRELESS:
                xhci_dbg(xhci, "FIXME xHCI doesn't support wireless speeds\n");
                return -EINVAL;
                break;
@@ -471,7 +499,7 @@ int xhci_setup_addressable_virt_dev(struct xhci_hcd *xhci, struct usb_device *ud
        case USB_SPEED_LOW:
                ep0_ctx->ep_info2 |= MAX_PACKET(8);
                break;
-       case USB_SPEED_VARIABLE:
+       case USB_SPEED_WIRELESS:
                xhci_dbg(xhci, "FIXME xHCI doesn't support wireless speeds\n");
                return -EINVAL;
                break;
@@ -539,8 +567,13 @@ static inline unsigned int xhci_get_endpoint_interval(struct usb_device *udev,
                        if (interval < 3)
                                interval = 3;
                        if ((1 << interval) != 8*ep->desc.bInterval)
-                               dev_warn(&udev->dev, "ep %#x - rounding interval to %d microframes\n",
-                                               ep->desc.bEndpointAddress, 1 << interval);
+                               dev_warn(&udev->dev,
+                                               "ep %#x - rounding interval"
+                                               " to %d microframes, "
+                                               "ep desc says %d microframes\n",
+                                               ep->desc.bEndpointAddress,
+                                               1 << interval,
+                                               8*ep->desc.bInterval);
                }
                break;
        default:
@@ -819,7 +852,8 @@ static void scratchpad_free(struct xhci_hcd *xhci)
 }
 
 struct xhci_command *xhci_alloc_command(struct xhci_hcd *xhci,
-               bool allocate_completion, gfp_t mem_flags)
+               bool allocate_in_ctx, bool allocate_completion,
+               gfp_t mem_flags)
 {
        struct xhci_command *command;
 
@@ -827,11 +861,14 @@ struct xhci_command *xhci_alloc_command(struct xhci_hcd *xhci,
        if (!command)
                return NULL;
 
-       command->in_ctx =
-               xhci_alloc_container_ctx(xhci, XHCI_CTX_TYPE_INPUT, mem_flags);
-       if (!command->in_ctx) {
-               kfree(command);
-               return NULL;
+       if (allocate_in_ctx) {
+               command->in_ctx =
+                       xhci_alloc_container_ctx(xhci, XHCI_CTX_TYPE_INPUT,
+                                       mem_flags);
+               if (!command->in_ctx) {
+                       kfree(command);
+                       return NULL;
+               }
        }
 
        if (allocate_completion) {