USB: xhci: Refactor code to free or cache endpoint rings.
authorSarah Sharp <sarah.a.sharp@linux.intel.com>
Wed, 9 Dec 2009 23:59:01 +0000 (15:59 -0800)
committerGreg Kroah-Hartman <gregkh@suse.de>
Tue, 2 Mar 2010 22:53:08 +0000 (14:53 -0800)
Refactor out the code to cache or free endpoint rings from recently
dropped or disabled endpoints.  This code will be used by a new function
to reset a device and disable all endpoints except control endpoint 0.

Signed-off-by: Sarah Sharp <sarah.a.sharp@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
drivers/usb/host/xhci-hcd.c
drivers/usb/host/xhci-mem.c
drivers/usb/host/xhci.h

index 0c5c1b2f3263e70ba9c89a252ce6cdad1e21e95d..451f53eec6d7ba3a3497735ef45f9ec4f264140c 100644 (file)
@@ -1266,30 +1266,13 @@ int xhci_check_bandwidth(struct usb_hcd *hcd, struct usb_device *udev)
        xhci_zero_in_ctx(xhci, virt_dev);
        /* Install new rings and free or cache any old rings */
        for (i = 1; i < 31; ++i) {
-               int rings_cached;
-
                if (!virt_dev->eps[i].new_ring)
                        continue;
                /* Only cache or free the old ring if it exists.
                 * It may not if this is the first add of an endpoint.
                 */
                if (virt_dev->eps[i].ring) {
-                       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[i].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[i].ring);
-                               xhci_dbg(xhci, "Ring cache full (%d rings), "
-                                               "freeing ring\n",
-                                               virt_dev->num_rings_cached);
-                       }
+                       xhci_free_or_cache_endpoint_ring(xhci, virt_dev, i);
                }
                virt_dev->eps[i].ring = virt_dev->eps[i].new_ring;
                virt_dev->eps[i].new_ring = NULL;
index bffcef7a5545ec87dbdcc24cd0d43a45be401f60..1f1f8a0f2e66d3a8aa6f167384361f92f354b9a9 100644 (file)
@@ -198,6 +198,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.
  */
index 877813505ef2044d062a1f66b8215b4a952aeda2..61747f3c5c8fb26b87592da9d3cefa39d6063394 100644 (file)
@@ -1233,6 +1233,9 @@ int xhci_endpoint_init(struct xhci_hcd *xhci, struct xhci_virt_device *virt_dev,
                struct usb_device *udev, struct usb_host_endpoint *ep,
                gfp_t mem_flags);
 void xhci_ring_free(struct xhci_hcd *xhci, struct xhci_ring *ring);
+void xhci_free_or_cache_endpoint_ring(struct xhci_hcd *xhci,
+               struct xhci_virt_device *virt_dev,
+               unsigned int ep_index);
 struct xhci_command *xhci_alloc_command(struct xhci_hcd *xhci,
                bool allocate_completion, gfp_t mem_flags);
 void xhci_free_command(struct xhci_hcd *xhci,