aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/host/xhci-ring.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/usb/host/xhci-ring.c')
-rw-r--r--drivers/usb/host/xhci-ring.c27
1 files changed, 24 insertions, 3 deletions
diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c
index 371ba4297d9c..d7e10ea8f080 100644
--- a/drivers/usb/host/xhci-ring.c
+++ b/drivers/usb/host/xhci-ring.c
@@ -1699,6 +1699,21 @@ int xhci_queue_intr_tx(struct xhci_hcd *xhci, gfp_t mem_flags,
1699 return xhci_queue_bulk_tx(xhci, GFP_ATOMIC, urb, slot_id, ep_index); 1699 return xhci_queue_bulk_tx(xhci, GFP_ATOMIC, urb, slot_id, ep_index);
1700} 1700}
1701 1701
1702/*
1703 * The TD size is the number of bytes remaining in the TD (including this TRB),
1704 * right shifted by 10.
1705 * It must fit in bits 21:17, so it can't be bigger than 31.
1706 */
1707static u32 xhci_td_remainder(unsigned int remainder)
1708{
1709 u32 max = (1 << (21 - 17 + 1)) - 1;
1710
1711 if ((remainder >> 10) >= max)
1712 return max << 17;
1713 else
1714 return (remainder >> 10) << 17;
1715}
1716
1702static int queue_bulk_sg_tx(struct xhci_hcd *xhci, gfp_t mem_flags, 1717static int queue_bulk_sg_tx(struct xhci_hcd *xhci, gfp_t mem_flags,
1703 struct urb *urb, int slot_id, unsigned int ep_index) 1718 struct urb *urb, int slot_id, unsigned int ep_index)
1704{ 1719{
@@ -1756,6 +1771,7 @@ static int queue_bulk_sg_tx(struct xhci_hcd *xhci, gfp_t mem_flags,
1756 do { 1771 do {
1757 u32 field = 0; 1772 u32 field = 0;
1758 u32 length_field = 0; 1773 u32 length_field = 0;
1774 u32 remainder = 0;
1759 1775
1760 /* Don't change the cycle bit of the first TRB until later */ 1776 /* Don't change the cycle bit of the first TRB until later */
1761 if (first_trb) 1777 if (first_trb)
@@ -1785,8 +1801,10 @@ static int queue_bulk_sg_tx(struct xhci_hcd *xhci, gfp_t mem_flags,
1785 (unsigned int) (addr + TRB_MAX_BUFF_SIZE) & ~(TRB_MAX_BUFF_SIZE - 1), 1801 (unsigned int) (addr + TRB_MAX_BUFF_SIZE) & ~(TRB_MAX_BUFF_SIZE - 1),
1786 (unsigned int) addr + trb_buff_len); 1802 (unsigned int) addr + trb_buff_len);
1787 } 1803 }
1804 remainder = xhci_td_remainder(urb->transfer_buffer_length -
1805 running_total) ;
1788 length_field = TRB_LEN(trb_buff_len) | 1806 length_field = TRB_LEN(trb_buff_len) |
1789 TD_REMAINDER(urb->transfer_buffer_length - running_total) | 1807 remainder |
1790 TRB_INTR_TARGET(0); 1808 TRB_INTR_TARGET(0);
1791 queue_trb(xhci, ep_ring, false, 1809 queue_trb(xhci, ep_ring, false,
1792 lower_32_bits(addr), 1810 lower_32_bits(addr),
@@ -1899,6 +1917,7 @@ int xhci_queue_bulk_tx(struct xhci_hcd *xhci, gfp_t mem_flags,
1899 1917
1900 /* Queue the first TRB, even if it's zero-length */ 1918 /* Queue the first TRB, even if it's zero-length */
1901 do { 1919 do {
1920 u32 remainder = 0;
1902 field = 0; 1921 field = 0;
1903 1922
1904 /* Don't change the cycle bit of the first TRB until later */ 1923 /* Don't change the cycle bit of the first TRB until later */
@@ -1917,8 +1936,10 @@ int xhci_queue_bulk_tx(struct xhci_hcd *xhci, gfp_t mem_flags,
1917 td->last_trb = ep_ring->enqueue; 1936 td->last_trb = ep_ring->enqueue;
1918 field |= TRB_IOC; 1937 field |= TRB_IOC;
1919 } 1938 }
1939 remainder = xhci_td_remainder(urb->transfer_buffer_length -
1940 running_total);
1920 length_field = TRB_LEN(trb_buff_len) | 1941 length_field = TRB_LEN(trb_buff_len) |
1921 TD_REMAINDER(urb->transfer_buffer_length - running_total) | 1942 remainder |
1922 TRB_INTR_TARGET(0); 1943 TRB_INTR_TARGET(0);
1923 queue_trb(xhci, ep_ring, false, 1944 queue_trb(xhci, ep_ring, false,
1924 lower_32_bits(addr), 1945 lower_32_bits(addr),
@@ -2006,7 +2027,7 @@ int xhci_queue_ctrl_tx(struct xhci_hcd *xhci, gfp_t mem_flags,
2006 /* If there's data, queue data TRBs */ 2027 /* If there's data, queue data TRBs */
2007 field = 0; 2028 field = 0;
2008 length_field = TRB_LEN(urb->transfer_buffer_length) | 2029 length_field = TRB_LEN(urb->transfer_buffer_length) |
2009 TD_REMAINDER(urb->transfer_buffer_length) | 2030 xhci_td_remainder(urb->transfer_buffer_length) |
2010 TRB_INTR_TARGET(0); 2031 TRB_INTR_TARGET(0);
2011 if (urb->transfer_buffer_length > 0) { 2032 if (urb->transfer_buffer_length > 0) {
2012 if (setup->bRequestType & USB_DIR_IN) 2033 if (setup->bRequestType & USB_DIR_IN)