aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/host
diff options
context:
space:
mode:
authorSarah Sharp <sarah.a.sharp@linux.intel.com>2009-11-11 13:28:30 -0500
committerGreg Kroah-Hartman <gregkh@suse.de>2009-12-11 14:55:23 -0500
commit04dd950d92f41155ed0cdf39b6bfbeea22eadb34 (patch)
tree6d88c1b0ae7f2b5bbdebd3d29da77c8e1b3eb39b /drivers/usb/host
parentf176a5d81214864904d285912da02c4bc0e9041a (diff)
USB: xhci: Set transfer descriptor size field correctly.
The transfer descriptor (TD) is a series of transfer request buffers (TRBs) that describe the buffer pointer, length, and other characteristics. The xHCI controllers want to know an estimate of how long the TD is, for caching reasons. In each TRB, there is a "TD size" field that provides a rough estimate of the remaining buffers to be transmitted, including the buffer pointed to by that TRB. The TD size is 5 bits long, and contains the remaining size in bytes, right shifted by 10 bits. So a remaining TD size less than 1024 would get a zero in the TD size field, and a remaining size greater than 32767 would get 31 in the field. This patches fixes a bug in the TD_REMAINDER macro that is triggered when the URB has a scatter gather list with a size bigger than 32767 bytes. Not all host controllers pay attention to the TD size field, so the bug will not appear on all USB 3.0 hosts. Signed-off-by: Sarah Sharp <sarah.a.sharp@linux.intel.com> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/usb/host')
-rw-r--r--drivers/usb/host/xhci-ring.c27
-rw-r--r--drivers/usb/host/xhci.h3
2 files changed, 24 insertions, 6 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)
diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h
index 3989aadcf670..bb8e6656cca4 100644
--- a/drivers/usb/host/xhci.h
+++ b/drivers/usb/host/xhci.h
@@ -828,9 +828,6 @@ struct xhci_event_cmd {
828/* Normal TRB fields */ 828/* Normal TRB fields */
829/* transfer_len bitmasks - bits 0:16 */ 829/* transfer_len bitmasks - bits 0:16 */
830#define TRB_LEN(p) ((p) & 0x1ffff) 830#define TRB_LEN(p) ((p) & 0x1ffff)
831/* TD size - number of bytes remaining in the TD (including this TRB):
832 * bits 17 - 21. Shift the number of bytes by 10. */
833#define TD_REMAINDER(p) ((((p) >> 10) & 0x1f) << 17)
834/* Interrupter Target - which MSI-X vector to target the completion event at */ 831/* Interrupter Target - which MSI-X vector to target the completion event at */
835#define TRB_INTR_TARGET(p) (((p) & 0x3ff) << 22) 832#define TRB_INTR_TARGET(p) (((p) & 0x3ff) << 22)
836#define GET_INTR_TARGET(p) (((p) >> 22) & 0x3ff) 833#define GET_INTR_TARGET(p) (((p) >> 22) & 0x3ff)