2727 * "All components of all Command and Transfer TRBs shall be initialized to '0'"
2828 */
2929static struct xhci_segment * xhci_segment_alloc (struct xhci_hcd * xhci ,
30+ unsigned int cycle_state ,
3031 unsigned int max_packet ,
3132 unsigned int num ,
3233 gfp_t flags )
3334{
3435 struct xhci_segment * seg ;
3536 dma_addr_t dma ;
37+ int i ;
3638 struct device * dev = xhci_to_hcd (xhci )-> self .sysdev ;
3739
3840 seg = kzalloc_node (sizeof (* seg ), flags , dev_to_node (dev ));
@@ -54,6 +56,11 @@ static struct xhci_segment *xhci_segment_alloc(struct xhci_hcd *xhci,
5456 return NULL ;
5557 }
5658 }
59+ /* If the cycle state is 0, set the cycle bit to 1 for all the TRBs */
60+ if (cycle_state == 0 ) {
61+ for (i = 0 ; i < TRBS_PER_SEGMENT ; i ++ )
62+ seg -> trbs [i ].link .control = cpu_to_le32 (TRB_CYCLE );
63+ }
5764 seg -> num = num ;
5865 seg -> dma = dma ;
5966 seg -> next = NULL ;
@@ -131,14 +138,6 @@ static void xhci_link_rings(struct xhci_hcd *xhci, struct xhci_ring *ring,
131138
132139 chain_links = xhci_link_chain_quirk (xhci , ring -> type );
133140
134- /* If the cycle state is 0, set the cycle bit to 1 for all the TRBs */
135- if (ring -> cycle_state == 0 ) {
136- xhci_for_each_ring_seg (ring -> first_seg , seg ) {
137- for (int i = 0 ; i < TRBS_PER_SEGMENT ; i ++ )
138- seg -> trbs [i ].link .control |= cpu_to_le32 (TRB_CYCLE );
139- }
140- }
141-
142141 next = ring -> enq_seg -> next ;
143142 xhci_link_segments (ring -> enq_seg , first , ring -> type , chain_links );
144143 xhci_link_segments (last , next , ring -> type , chain_links );
@@ -288,7 +287,8 @@ void xhci_ring_free(struct xhci_hcd *xhci, struct xhci_ring *ring)
288287 kfree (ring );
289288}
290289
291- void xhci_initialize_ring_info (struct xhci_ring * ring )
290+ void xhci_initialize_ring_info (struct xhci_ring * ring ,
291+ unsigned int cycle_state )
292292{
293293 /* The ring is empty, so the enqueue pointer == dequeue pointer */
294294 ring -> enqueue = ring -> first_seg -> trbs ;
@@ -302,7 +302,7 @@ void xhci_initialize_ring_info(struct xhci_ring *ring)
302302 * New rings are initialized with cycle state equal to 1; if we are
303303 * handling ring expansion, set the cycle state equal to the old ring.
304304 */
305- ring -> cycle_state = 1 ;
305+ ring -> cycle_state = cycle_state ;
306306
307307 /*
308308 * Each segment has a link TRB, and leave an extra TRB for SW
@@ -317,6 +317,7 @@ static int xhci_alloc_segments_for_ring(struct xhci_hcd *xhci,
317317 struct xhci_segment * * first ,
318318 struct xhci_segment * * last ,
319319 unsigned int num_segs ,
320+ unsigned int cycle_state ,
320321 enum xhci_ring_type type ,
321322 unsigned int max_packet ,
322323 gfp_t flags )
@@ -327,7 +328,7 @@ static int xhci_alloc_segments_for_ring(struct xhci_hcd *xhci,
327328
328329 chain_links = xhci_link_chain_quirk (xhci , type );
329330
330- prev = xhci_segment_alloc (xhci , max_packet , num , flags );
331+ prev = xhci_segment_alloc (xhci , cycle_state , max_packet , num , flags );
331332 if (!prev )
332333 return - ENOMEM ;
333334 num ++ ;
@@ -336,7 +337,8 @@ static int xhci_alloc_segments_for_ring(struct xhci_hcd *xhci,
336337 while (num < num_segs ) {
337338 struct xhci_segment * next ;
338339
339- next = xhci_segment_alloc (xhci , max_packet , num , flags );
340+ next = xhci_segment_alloc (xhci , cycle_state , max_packet , num ,
341+ flags );
340342 if (!next )
341343 goto free_segments ;
342344
@@ -361,8 +363,9 @@ static int xhci_alloc_segments_for_ring(struct xhci_hcd *xhci,
361363 * Set the end flag and the cycle toggle bit on the last segment.
362364 * See section 4.9.1 and figures 15 and 16.
363365 */
364- struct xhci_ring * xhci_ring_alloc (struct xhci_hcd * xhci , unsigned int num_segs ,
365- enum xhci_ring_type type , unsigned int max_packet , gfp_t flags )
366+ struct xhci_ring * xhci_ring_alloc (struct xhci_hcd * xhci ,
367+ unsigned int num_segs , unsigned int cycle_state ,
368+ enum xhci_ring_type type , unsigned int max_packet , gfp_t flags )
366369{
367370 struct xhci_ring * ring ;
368371 int ret ;
@@ -380,7 +383,7 @@ struct xhci_ring *xhci_ring_alloc(struct xhci_hcd *xhci, unsigned int num_segs,
380383 return ring ;
381384
382385 ret = xhci_alloc_segments_for_ring (xhci , & ring -> first_seg , & ring -> last_seg , num_segs ,
383- type , max_packet , flags );
386+ cycle_state , type , max_packet , flags );
384387 if (ret )
385388 goto fail ;
386389
@@ -390,7 +393,7 @@ struct xhci_ring *xhci_ring_alloc(struct xhci_hcd *xhci, unsigned int num_segs,
390393 ring -> last_seg -> trbs [TRBS_PER_SEGMENT - 1 ].link .control |=
391394 cpu_to_le32 (LINK_TOGGLE );
392395 }
393- xhci_initialize_ring_info (ring );
396+ xhci_initialize_ring_info (ring , cycle_state );
394397 trace_xhci_ring_alloc (ring );
395398 return ring ;
396399
@@ -418,8 +421,8 @@ int xhci_ring_expansion(struct xhci_hcd *xhci, struct xhci_ring *ring,
418421 struct xhci_segment * last ;
419422 int ret ;
420423
421- ret = xhci_alloc_segments_for_ring (xhci , & first , & last , num_new_segs , ring -> type ,
422- ring -> bounce_buf_len , flags );
424+ ret = xhci_alloc_segments_for_ring (xhci , & first , & last , num_new_segs , ring -> cycle_state ,
425+ ring -> type , ring -> bounce_buf_len , flags );
423426 if (ret )
424427 return - ENOMEM ;
425428
@@ -629,7 +632,8 @@ struct xhci_stream_info *xhci_alloc_stream_info(struct xhci_hcd *xhci,
629632
630633 for (cur_stream = 1 ; cur_stream < num_streams ; cur_stream ++ ) {
631634 stream_info -> stream_rings [cur_stream ] =
632- xhci_ring_alloc (xhci , 2 , TYPE_STREAM , max_packet , mem_flags );
635+ xhci_ring_alloc (xhci , 2 , 1 , TYPE_STREAM , max_packet ,
636+ mem_flags );
633637 cur_ring = stream_info -> stream_rings [cur_stream ];
634638 if (!cur_ring )
635639 goto cleanup_rings ;
@@ -970,7 +974,7 @@ int xhci_alloc_virt_device(struct xhci_hcd *xhci, int slot_id,
970974 }
971975
972976 /* Allocate endpoint 0 ring */
973- dev -> eps [0 ].ring = xhci_ring_alloc (xhci , 2 , TYPE_CTRL , 0 , flags );
977+ dev -> eps [0 ].ring = xhci_ring_alloc (xhci , 2 , 1 , TYPE_CTRL , 0 , flags );
974978 if (!dev -> eps [0 ].ring )
975979 goto fail ;
976980
@@ -1453,7 +1457,7 @@ int xhci_endpoint_init(struct xhci_hcd *xhci,
14531457
14541458 /* Set up the endpoint ring */
14551459 virt_dev -> eps [ep_index ].new_ring =
1456- xhci_ring_alloc (xhci , 2 , ring_type , max_packet , mem_flags );
1460+ xhci_ring_alloc (xhci , 2 , 1 , ring_type , max_packet , mem_flags );
14571461 if (!virt_dev -> eps [ep_index ].new_ring )
14581462 return - ENOMEM ;
14591463
@@ -2262,7 +2266,7 @@ xhci_alloc_interrupter(struct xhci_hcd *xhci, unsigned int segs, gfp_t flags)
22622266 if (!ir )
22632267 return NULL ;
22642268
2265- ir -> event_ring = xhci_ring_alloc (xhci , segs , TYPE_EVENT , 0 , flags );
2269+ ir -> event_ring = xhci_ring_alloc (xhci , segs , 1 , TYPE_EVENT , 0 , flags );
22662270 if (!ir -> event_ring ) {
22672271 xhci_warn (xhci , "Failed to allocate interrupter event ring\n" );
22682272 kfree (ir );
@@ -2468,7 +2472,7 @@ int xhci_mem_init(struct xhci_hcd *xhci, gfp_t flags)
24682472 goto fail ;
24692473
24702474 /* Set up the command ring to have one segments for now. */
2471- xhci -> cmd_ring = xhci_ring_alloc (xhci , 1 , TYPE_COMMAND , 0 , flags );
2475+ xhci -> cmd_ring = xhci_ring_alloc (xhci , 1 , 1 , TYPE_COMMAND , 0 , flags );
24722476 if (!xhci -> cmd_ring )
24732477 goto fail ;
24742478 xhci_dbg_trace (xhci , trace_xhci_dbg_init ,
0 commit comments