Skip to content

Commit 124c393

Browse files
matnymangregkh
authored andcommitted
xhci: use boolean to indicate last trb in td remainder calculation
We only need to know if we are queuing the last trb for a TD when calculating the td remainder field. The total number of trbs left is not used. We won't be able to trust the pre-calculated number of trbs used if we need to align trb data by splitting or merging trbs in order to satisfy comply with data alignment requirements in xhci specs section 4.11.7.1. Signed-off-by: Mathias Nyman <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 5a83f04 commit 124c393

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

drivers/usb/host/xhci-ring.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3092,7 +3092,7 @@ int xhci_queue_intr_tx(struct xhci_hcd *xhci, gfp_t mem_flags,
30923092
*/
30933093
static u32 xhci_td_remainder(struct xhci_hcd *xhci, int transferred,
30943094
int trb_buff_len, unsigned int td_total_len,
3095-
struct urb *urb, unsigned int num_trbs_left)
3095+
struct urb *urb, bool more_trbs_coming)
30963096
{
30973097
u32 maxp, total_packet_count;
30983098

@@ -3101,7 +3101,7 @@ static u32 xhci_td_remainder(struct xhci_hcd *xhci, int transferred,
31013101
return ((td_total_len - transferred) >> 10);
31023102

31033103
/* One TRB with a zero-length data packet. */
3104-
if (num_trbs_left == 0 || (transferred == 0 && trb_buff_len == 0) ||
3104+
if (!more_trbs_coming || (transferred == 0 && trb_buff_len == 0) ||
31053105
trb_buff_len == td_total_len)
31063106
return 0;
31073107

@@ -3216,7 +3216,7 @@ int xhci_queue_bulk_tx(struct xhci_hcd *xhci, gfp_t mem_flags,
32163216
field |= TRB_CHAIN;
32173217
} else {
32183218
field |= TRB_IOC;
3219-
more_trbs_coming = need_zero_pkt;
3219+
more_trbs_coming = false;
32203220
td->last_trb = ring->enqueue;
32213221
}
32223222

@@ -3227,13 +3227,12 @@ int xhci_queue_bulk_tx(struct xhci_hcd *xhci, gfp_t mem_flags,
32273227
/* Set the TRB length, TD size, and interrupter fields. */
32283228
remainder = xhci_td_remainder(xhci, running_total,
32293229
trb_buff_len, full_len,
3230-
urb, num_trbs - i - 1);
3231-
3230+
urb, more_trbs_coming);
32323231
length_field = TRB_LEN(trb_buff_len) |
32333232
TRB_TD_SIZE(remainder) |
32343233
TRB_INTR_TARGET(0);
32353234

3236-
queue_trb(xhci, ring, more_trbs_coming,
3235+
queue_trb(xhci, ring, more_trbs_coming | need_zero_pkt,
32373236
lower_32_bits(addr),
32383237
upper_32_bits(addr),
32393238
length_field,
@@ -3657,7 +3656,7 @@ static int xhci_queue_isoc_tx(struct xhci_hcd *xhci, gfp_t mem_flags,
36573656
/* Set the TRB length, TD size, & interrupter fields. */
36583657
remainder = xhci_td_remainder(xhci, running_total,
36593658
trb_buff_len, td_len,
3660-
urb, trbs_per_td - j - 1);
3659+
urb, more_trbs_coming);
36613660

36623661
length_field = TRB_LEN(trb_buff_len) |
36633662
TRB_INTR_TARGET(0);

0 commit comments

Comments
 (0)