[PATCH v3] usb: xhci Use TRB_CYCLE instead of the constant 0x1.

2013-12-18 Thread David Laight
Using TRB_CYCLE makes it clearer that the ring-cycle_state value is used when
writing to the actual ring itself.

Always use ^= TRB_CYCLE to invert the bit.

Revert the part of 186a7ef13a8f (xHCI: set cycle state when allocate rings)
that passed the cycle state to xhci_ring_alloc() and xhci_initialize_ring_info()
as these are only called for new rings and always passed 1 (TRB_CYCLE).

Signed-off-by: David Laight david.lai...@aculab.com
---

Changes for v2:
1: Adjusted so that is applies to HEAD
2: Added signed-off

Changes for v3:
1: Changed for additional lines (assignd to new_cycle_state).
2: Removed the cycle_state parameter - also shortens some overlong lines.

 drivers/usb/host/xhci-mem.c  | 37 ++---
 drivers/usb/host/xhci-ring.c | 22 +++---
 drivers/usb/host/xhci.c  |  2 +-
 3 files changed, 26 insertions(+), 35 deletions(-)

diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c
index 49b8bd0..706b530 100644
--- a/drivers/usb/host/xhci-mem.c
+++ b/drivers/usb/host/xhci-mem.c
@@ -161,8 +161,7 @@ void xhci_ring_free(struct xhci_hcd *xhci, struct xhci_ring 
*ring)
kfree(ring);
 }
 
-static void xhci_initialize_ring_info(struct xhci_ring *ring,
-   unsigned int cycle_state)
+static void xhci_initialize_ring_info(struct xhci_ring *ring)
 {
/* The ring is empty, so the enqueue pointer == dequeue pointer */
ring-enqueue = ring-first_seg-trbs;
@@ -173,10 +172,9 @@ static void xhci_initialize_ring_info(struct xhci_ring 
*ring,
 * bit to handover ownership of the TRB, so PCS = 1.  The consumer must
 * compare CCS to the cycle bit to check ownership, so CCS = 1.
 *
-* New rings are initialized with cycle state equal to 1; if we are
-* handling ring expansion, set the cycle state equal to the old ring.
+* New rings are initialized with cycle state equal to 1.
 */
-   ring-cycle_state = cycle_state;
+   ring-cycle_state = TRB_CYCLE;
/* Not necessary for new rings, but needed for re-initialized rings */
ring-enq_updates = 0;
ring-deq_updates = 0;
@@ -234,8 +232,7 @@ static int xhci_alloc_segments_for_ring(struct xhci_hcd 
*xhci,
  * See section 4.9.1 and figures 15 and 16.
  */
 static struct xhci_ring *xhci_ring_alloc(struct xhci_hcd *xhci,
-   unsigned int num_segs, unsigned int cycle_state,
-   enum xhci_ring_type type, gfp_t flags)
+   unsigned int num_segs, enum xhci_ring_type type, gfp_t flags)
 {
struct xhci_ring*ring;
int ret;
@@ -251,7 +248,7 @@ static struct xhci_ring *xhci_ring_alloc(struct xhci_hcd 
*xhci,
return ring;
 
ret = xhci_alloc_segments_for_ring(xhci, ring-first_seg,
-   ring-last_seg, num_segs, cycle_state, type, flags);
+   ring-last_seg, num_segs, TRB_CYCLE, type, flags);
if (ret)
goto fail;
 
@@ -261,7 +258,7 @@ static struct xhci_ring *xhci_ring_alloc(struct xhci_hcd 
*xhci,
ring-last_seg-trbs[TRBS_PER_SEGMENT - 1].link.control |=
cpu_to_le32(LINK_TOGGLE);
}
-   xhci_initialize_ring_info(ring, cycle_state);
+   xhci_initialize_ring_info(ring);
return ring;
 
 fail:
@@ -297,25 +294,19 @@ void xhci_free_or_cache_endpoint_ring(struct xhci_hcd 
*xhci,
  * pointers to the beginning of the ring.
  */
 static void xhci_reinit_cached_ring(struct xhci_hcd *xhci,
-   struct xhci_ring *ring, unsigned int cycle_state,
-   enum xhci_ring_type type)
+   struct xhci_ring *ring, enum xhci_ring_type type)
 {
struct xhci_segment *seg = ring-first_seg;
-   int i;
 
do {
memset(seg-trbs, 0,
sizeof(union xhci_trb)*TRBS_PER_SEGMENT);
-   if (cycle_state == 0) {
-   for (i = 0; i  TRBS_PER_SEGMENT; i++)
-   seg-trbs[i].link.control |= TRB_CYCLE;
-   }
/* All endpoint rings have link TRBs */
xhci_link_segments(xhci, seg, seg-next, type);
seg = seg-next;
} while (seg != ring-first_seg);
ring-type = type;
-   xhci_initialize_ring_info(ring, cycle_state);
+   xhci_initialize_ring_info(ring);
/* td list should be empty since all URBs have been cancelled,
 * but just in case...
 */
@@ -597,7 +588,7 @@ struct xhci_stream_info *xhci_alloc_stream_info(struct 
xhci_hcd *xhci,
 */
for (cur_stream = 1; cur_stream  num_streams; cur_stream++) {
stream_info-stream_rings[cur_stream] =
-   xhci_ring_alloc(xhci, 2, 1, TYPE_STREAM, mem_flags);
+   xhci_ring_alloc(xhci, 2, TYPE_STREAM, mem_flags);
cur_ring = 

RE: [PATCH v3] usb: xhci Use TRB_CYCLE instead of the constant 0x1.

2013-12-18 Thread David Laight
 From: Of David Laight
 Using TRB_CYCLE makes it clearer that the ring-cycle_state value is used when
 writing to the actual ring itself.

FWIW this patch is against Linus's tree.
This hunk probably fails to apply to some trees because the patch
to force TRB_CYCLE to be little endian hasn't got there yet.

 @@ -297,25 +294,19 @@ void xhci_free_or_cache_endpoint_ring(struct xhci_hcd 
 *xhci,
   * pointers to the beginning of the ring.
   */
  static void xhci_reinit_cached_ring(struct xhci_hcd *xhci,
 - struct xhci_ring *ring, unsigned int cycle_state,
 - enum xhci_ring_type type)
 + struct xhci_ring *ring, enum xhci_ring_type type)
  {
   struct xhci_segment *seg = ring-first_seg;
 - int i;
 
   do {
   memset(seg-trbs, 0,
   sizeof(union xhci_trb)*TRBS_PER_SEGMENT);
 - if (cycle_state == 0) {
 - for (i = 0; i  TRBS_PER_SEGMENT; i++)
 - seg-trbs[i].link.control |= TRB_CYCLE;
 - }
   /* All endpoint rings have link TRBs */
   xhci_link_segments(xhci, seg, seg-next, type);
   seg = seg-next;
   } while (seg != ring-first_seg);
   ring-type = type;
 - xhci_initialize_ring_info(ring, cycle_state);
 + xhci_initialize_ring_info(ring);
   /* td list should be empty since all URBs have been cancelled,
* but just in case...
*/

David



--
To unsubscribe from this list: send the line unsubscribe linux-usb in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html