Skip to content

Commit 35899f5

Browse files
l1kgregkh
authored andcommitted
xhci: Adjust segment numbers after ring expansion
Initial xhci_ring allocation has just been amended to assign a monotonically increasing number to each ring segment. However rings may be expanded after initial allocation. So number newly inserted segments starting from the preceding segment in the ring and renumber all segments succeeding the newly inserted ones. This is not a fix because ring expansion currently isn't done on the Event Ring and that's the only ring type using the segment number. It's just in preparation for when either Event Ring expansion is added or when other ring types start making use of the segment number. Signed-off-by: Lukas Wunner <lukas@wunner.de> Signed-off-by: Mathias Nyman <mathias.nyman@linux.intel.com> Link: https://lore.kernel.org/r/20231019102924.2797346-7-mathias.nyman@linux.intel.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 28084d3 commit 35899f5

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

drivers/usb/host/xhci-mem.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ static void xhci_link_rings(struct xhci_hcd *xhci, struct xhci_ring *ring,
130130
struct xhci_segment *first, struct xhci_segment *last,
131131
unsigned int num_segs)
132132
{
133-
struct xhci_segment *next;
133+
struct xhci_segment *next, *seg;
134134
bool chain_links;
135135

136136
if (!ring || !first || !last)
@@ -153,6 +153,9 @@ static void xhci_link_rings(struct xhci_hcd *xhci, struct xhci_ring *ring,
153153
|= cpu_to_le32(LINK_TOGGLE);
154154
ring->last_seg = last;
155155
}
156+
157+
for (seg = last; seg != ring->last_seg; seg = seg->next)
158+
seg->next->num = seg->num + 1;
156159
}
157160

158161
/*
@@ -322,11 +325,11 @@ void xhci_initialize_ring_info(struct xhci_ring *ring,
322325
/* Allocate segments and link them for a ring */
323326
static int xhci_alloc_segments_for_ring(struct xhci_hcd *xhci,
324327
struct xhci_segment **first, struct xhci_segment **last,
325-
unsigned int num_segs, unsigned int cycle_state,
326-
enum xhci_ring_type type, unsigned int max_packet, gfp_t flags)
328+
unsigned int num_segs, unsigned int num,
329+
unsigned int cycle_state, enum xhci_ring_type type,
330+
unsigned int max_packet, gfp_t flags)
327331
{
328332
struct xhci_segment *prev;
329-
unsigned int num = 0;
330333
bool chain_links;
331334

332335
/* Set chain bit for 0.95 hosts, and for isoc rings on AMD 0.96 host */
@@ -392,7 +395,7 @@ struct xhci_ring *xhci_ring_alloc(struct xhci_hcd *xhci,
392395
return ring;
393396

394397
ret = xhci_alloc_segments_for_ring(xhci, &ring->first_seg,
395-
&ring->last_seg, num_segs, cycle_state, type,
398+
&ring->last_seg, num_segs, 0, cycle_state, type,
396399
max_packet, flags);
397400
if (ret)
398401
goto fail;
@@ -432,7 +435,8 @@ int xhci_ring_expansion(struct xhci_hcd *xhci, struct xhci_ring *ring,
432435
int ret;
433436

434437
ret = xhci_alloc_segments_for_ring(xhci, &first, &last,
435-
num_new_segs, ring->cycle_state, ring->type,
438+
num_new_segs, ring->enq_seg->num + 1,
439+
ring->cycle_state, ring->type,
436440
ring->bounce_buf_len, flags);
437441
if (ret)
438442
return -ENOMEM;

0 commit comments

Comments
 (0)