diff options
Diffstat (limited to 'drivers/usb/host/xhci-ring.c')
-rw-r--r-- | drivers/usb/host/xhci-ring.c | 34 |
1 files changed, 20 insertions, 14 deletions
diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c index 4e1a8946b8d1..cbb44b7b9d65 100644 --- a/drivers/usb/host/xhci-ring.c +++ b/drivers/usb/host/xhci-ring.c | |||
@@ -318,7 +318,7 @@ static int xhci_abort_cmd_ring(struct xhci_hcd *xhci) | |||
318 | * seconds), then it should assume that the there are | 318 | * seconds), then it should assume that the there are |
319 | * larger problems with the xHC and assert HCRST. | 319 | * larger problems with the xHC and assert HCRST. |
320 | */ | 320 | */ |
321 | ret = handshake(xhci, &xhci->op_regs->cmd_ring, | 321 | ret = xhci_handshake(xhci, &xhci->op_regs->cmd_ring, |
322 | CMD_RING_RUNNING, 0, 5 * 1000 * 1000); | 322 | CMD_RING_RUNNING, 0, 5 * 1000 * 1000); |
323 | if (ret < 0) { | 323 | if (ret < 0) { |
324 | xhci_err(xhci, "Stopped the command ring failed, " | 324 | xhci_err(xhci, "Stopped the command ring failed, " |
@@ -3071,11 +3071,11 @@ static u32 xhci_td_remainder(unsigned int remainder) | |||
3071 | } | 3071 | } |
3072 | 3072 | ||
3073 | /* | 3073 | /* |
3074 | * For xHCI 1.0 host controllers, TD size is the number of packets remaining in | 3074 | * For xHCI 1.0 host controllers, TD size is the number of max packet sized |
3075 | * the TD (*not* including this TRB). | 3075 | * packets remaining in the TD (*not* including this TRB). |
3076 | * | 3076 | * |
3077 | * Total TD packet count = total_packet_count = | 3077 | * Total TD packet count = total_packet_count = |
3078 | * roundup(TD size in bytes / wMaxPacketSize) | 3078 | * DIV_ROUND_UP(TD size in bytes / wMaxPacketSize) |
3079 | * | 3079 | * |
3080 | * Packets transferred up to and including this TRB = packets_transferred = | 3080 | * Packets transferred up to and including this TRB = packets_transferred = |
3081 | * rounddown(total bytes transferred including this TRB / wMaxPacketSize) | 3081 | * rounddown(total bytes transferred including this TRB / wMaxPacketSize) |
@@ -3083,15 +3083,16 @@ static u32 xhci_td_remainder(unsigned int remainder) | |||
3083 | * TD size = total_packet_count - packets_transferred | 3083 | * TD size = total_packet_count - packets_transferred |
3084 | * | 3084 | * |
3085 | * It must fit in bits 21:17, so it can't be bigger than 31. | 3085 | * It must fit in bits 21:17, so it can't be bigger than 31. |
3086 | * The last TRB in a TD must have the TD size set to zero. | ||
3086 | */ | 3087 | */ |
3087 | |||
3088 | static u32 xhci_v1_0_td_remainder(int running_total, int trb_buff_len, | 3088 | static u32 xhci_v1_0_td_remainder(int running_total, int trb_buff_len, |
3089 | unsigned int total_packet_count, struct urb *urb) | 3089 | unsigned int total_packet_count, struct urb *urb, |
3090 | unsigned int num_trbs_left) | ||
3090 | { | 3091 | { |
3091 | int packets_transferred; | 3092 | int packets_transferred; |
3092 | 3093 | ||
3093 | /* One TRB with a zero-length data packet. */ | 3094 | /* One TRB with a zero-length data packet. */ |
3094 | if (running_total == 0 && trb_buff_len == 0) | 3095 | if (num_trbs_left == 0 || (running_total == 0 && trb_buff_len == 0)) |
3095 | return 0; | 3096 | return 0; |
3096 | 3097 | ||
3097 | /* All the TRB queueing functions don't count the current TRB in | 3098 | /* All the TRB queueing functions don't count the current TRB in |
@@ -3100,7 +3101,9 @@ static u32 xhci_v1_0_td_remainder(int running_total, int trb_buff_len, | |||
3100 | packets_transferred = (running_total + trb_buff_len) / | 3101 | packets_transferred = (running_total + trb_buff_len) / |
3101 | usb_endpoint_maxp(&urb->ep->desc); | 3102 | usb_endpoint_maxp(&urb->ep->desc); |
3102 | 3103 | ||
3103 | return xhci_td_remainder(total_packet_count - packets_transferred); | 3104 | if ((total_packet_count - packets_transferred) > 31) |
3105 | return 31 << 17; | ||
3106 | return (total_packet_count - packets_transferred) << 17; | ||
3104 | } | 3107 | } |
3105 | 3108 | ||
3106 | static int queue_bulk_sg_tx(struct xhci_hcd *xhci, gfp_t mem_flags, | 3109 | static int queue_bulk_sg_tx(struct xhci_hcd *xhci, gfp_t mem_flags, |
@@ -3127,7 +3130,7 @@ static int queue_bulk_sg_tx(struct xhci_hcd *xhci, gfp_t mem_flags, | |||
3127 | 3130 | ||
3128 | num_trbs = count_sg_trbs_needed(xhci, urb); | 3131 | num_trbs = count_sg_trbs_needed(xhci, urb); |
3129 | num_sgs = urb->num_mapped_sgs; | 3132 | num_sgs = urb->num_mapped_sgs; |
3130 | total_packet_count = roundup(urb->transfer_buffer_length, | 3133 | total_packet_count = DIV_ROUND_UP(urb->transfer_buffer_length, |
3131 | usb_endpoint_maxp(&urb->ep->desc)); | 3134 | usb_endpoint_maxp(&urb->ep->desc)); |
3132 | 3135 | ||
3133 | trb_buff_len = prepare_transfer(xhci, xhci->devs[slot_id], | 3136 | trb_buff_len = prepare_transfer(xhci, xhci->devs[slot_id], |
@@ -3210,7 +3213,8 @@ static int queue_bulk_sg_tx(struct xhci_hcd *xhci, gfp_t mem_flags, | |||
3210 | running_total); | 3213 | running_total); |
3211 | } else { | 3214 | } else { |
3212 | remainder = xhci_v1_0_td_remainder(running_total, | 3215 | remainder = xhci_v1_0_td_remainder(running_total, |
3213 | trb_buff_len, total_packet_count, urb); | 3216 | trb_buff_len, total_packet_count, urb, |
3217 | num_trbs - 1); | ||
3214 | } | 3218 | } |
3215 | length_field = TRB_LEN(trb_buff_len) | | 3219 | length_field = TRB_LEN(trb_buff_len) | |
3216 | remainder | | 3220 | remainder | |
@@ -3318,7 +3322,7 @@ int xhci_queue_bulk_tx(struct xhci_hcd *xhci, gfp_t mem_flags, | |||
3318 | start_cycle = ep_ring->cycle_state; | 3322 | start_cycle = ep_ring->cycle_state; |
3319 | 3323 | ||
3320 | running_total = 0; | 3324 | running_total = 0; |
3321 | total_packet_count = roundup(urb->transfer_buffer_length, | 3325 | total_packet_count = DIV_ROUND_UP(urb->transfer_buffer_length, |
3322 | usb_endpoint_maxp(&urb->ep->desc)); | 3326 | usb_endpoint_maxp(&urb->ep->desc)); |
3323 | /* How much data is in the first TRB? */ | 3327 | /* How much data is in the first TRB? */ |
3324 | addr = (u64) urb->transfer_dma; | 3328 | addr = (u64) urb->transfer_dma; |
@@ -3364,7 +3368,8 @@ int xhci_queue_bulk_tx(struct xhci_hcd *xhci, gfp_t mem_flags, | |||
3364 | running_total); | 3368 | running_total); |
3365 | } else { | 3369 | } else { |
3366 | remainder = xhci_v1_0_td_remainder(running_total, | 3370 | remainder = xhci_v1_0_td_remainder(running_total, |
3367 | trb_buff_len, total_packet_count, urb); | 3371 | trb_buff_len, total_packet_count, urb, |
3372 | num_trbs - 1); | ||
3368 | } | 3373 | } |
3369 | length_field = TRB_LEN(trb_buff_len) | | 3374 | length_field = TRB_LEN(trb_buff_len) | |
3370 | remainder | | 3375 | remainder | |
@@ -3627,7 +3632,7 @@ static int xhci_queue_isoc_tx(struct xhci_hcd *xhci, gfp_t mem_flags, | |||
3627 | addr = start_addr + urb->iso_frame_desc[i].offset; | 3632 | addr = start_addr + urb->iso_frame_desc[i].offset; |
3628 | td_len = urb->iso_frame_desc[i].length; | 3633 | td_len = urb->iso_frame_desc[i].length; |
3629 | td_remain_len = td_len; | 3634 | td_remain_len = td_len; |
3630 | total_packet_count = roundup(td_len, | 3635 | total_packet_count = DIV_ROUND_UP(td_len, |
3631 | usb_endpoint_maxp(&urb->ep->desc)); | 3636 | usb_endpoint_maxp(&urb->ep->desc)); |
3632 | /* A zero-length transfer still involves at least one packet. */ | 3637 | /* A zero-length transfer still involves at least one packet. */ |
3633 | if (total_packet_count == 0) | 3638 | if (total_packet_count == 0) |
@@ -3706,7 +3711,8 @@ static int xhci_queue_isoc_tx(struct xhci_hcd *xhci, gfp_t mem_flags, | |||
3706 | } else { | 3711 | } else { |
3707 | remainder = xhci_v1_0_td_remainder( | 3712 | remainder = xhci_v1_0_td_remainder( |
3708 | running_total, trb_buff_len, | 3713 | running_total, trb_buff_len, |
3709 | total_packet_count, urb); | 3714 | total_packet_count, urb, |
3715 | (trbs_per_td - j - 1)); | ||
3710 | } | 3716 | } |
3711 | length_field = TRB_LEN(trb_buff_len) | | 3717 | length_field = TRB_LEN(trb_buff_len) | |
3712 | remainder | | 3718 | remainder | |