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.c219
1 files changed, 134 insertions, 85 deletions
diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c
index cfc1ad92473f..7437386a9a50 100644
--- a/drivers/usb/host/xhci-ring.c
+++ b/drivers/usb/host/xhci-ring.c
@@ -93,7 +93,7 @@ dma_addr_t xhci_trb_virt_to_dma(struct xhci_segment *seg,
93/* Does this link TRB point to the first segment in a ring, 93/* Does this link TRB point to the first segment in a ring,
94 * or was the previous TRB the last TRB on the last segment in the ERST? 94 * or was the previous TRB the last TRB on the last segment in the ERST?
95 */ 95 */
96static inline bool last_trb_on_last_seg(struct xhci_hcd *xhci, struct xhci_ring *ring, 96static bool last_trb_on_last_seg(struct xhci_hcd *xhci, struct xhci_ring *ring,
97 struct xhci_segment *seg, union xhci_trb *trb) 97 struct xhci_segment *seg, union xhci_trb *trb)
98{ 98{
99 if (ring == xhci->event_ring) 99 if (ring == xhci->event_ring)
@@ -107,7 +107,7 @@ static inline bool last_trb_on_last_seg(struct xhci_hcd *xhci, struct xhci_ring
107 * segment? I.e. would the updated event TRB pointer step off the end of the 107 * segment? I.e. would the updated event TRB pointer step off the end of the
108 * event seg? 108 * event seg?
109 */ 109 */
110static inline int last_trb(struct xhci_hcd *xhci, struct xhci_ring *ring, 110static int last_trb(struct xhci_hcd *xhci, struct xhci_ring *ring,
111 struct xhci_segment *seg, union xhci_trb *trb) 111 struct xhci_segment *seg, union xhci_trb *trb)
112{ 112{
113 if (ring == xhci->event_ring) 113 if (ring == xhci->event_ring)
@@ -116,7 +116,7 @@ static inline int last_trb(struct xhci_hcd *xhci, struct xhci_ring *ring,
116 return (trb->link.control & TRB_TYPE_BITMASK) == TRB_TYPE(TRB_LINK); 116 return (trb->link.control & TRB_TYPE_BITMASK) == TRB_TYPE(TRB_LINK);
117} 117}
118 118
119static inline int enqueue_is_link_trb(struct xhci_ring *ring) 119static int enqueue_is_link_trb(struct xhci_ring *ring)
120{ 120{
121 struct xhci_link_trb *link = &ring->enqueue->link; 121 struct xhci_link_trb *link = &ring->enqueue->link;
122 return ((link->control & TRB_TYPE_BITMASK) == TRB_TYPE(TRB_LINK)); 122 return ((link->control & TRB_TYPE_BITMASK) == TRB_TYPE(TRB_LINK));
@@ -592,7 +592,7 @@ void xhci_queue_new_dequeue_state(struct xhci_hcd *xhci,
592 ep->ep_state |= SET_DEQ_PENDING; 592 ep->ep_state |= SET_DEQ_PENDING;
593} 593}
594 594
595static inline void xhci_stop_watchdog_timer_in_irq(struct xhci_hcd *xhci, 595static void xhci_stop_watchdog_timer_in_irq(struct xhci_hcd *xhci,
596 struct xhci_virt_ep *ep) 596 struct xhci_virt_ep *ep)
597{ 597{
598 ep->ep_state &= ~EP_HALT_PENDING; 598 ep->ep_state &= ~EP_HALT_PENDING;
@@ -619,6 +619,13 @@ static void xhci_giveback_urb_in_irq(struct xhci_hcd *xhci,
619 619
620 /* Only giveback urb when this is the last td in urb */ 620 /* Only giveback urb when this is the last td in urb */
621 if (urb_priv->td_cnt == urb_priv->length) { 621 if (urb_priv->td_cnt == urb_priv->length) {
622 if (usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS) {
623 xhci_to_hcd(xhci)->self.bandwidth_isoc_reqs--;
624 if (xhci_to_hcd(xhci)->self.bandwidth_isoc_reqs == 0) {
625 if (xhci->quirks & XHCI_AMD_PLL_FIX)
626 usb_amd_quirk_pll_enable();
627 }
628 }
622 usb_hcd_unlink_urb_from_ep(hcd, urb); 629 usb_hcd_unlink_urb_from_ep(hcd, urb);
623 xhci_dbg(xhci, "Giveback %s URB %p\n", adjective, urb); 630 xhci_dbg(xhci, "Giveback %s URB %p\n", adjective, urb);
624 631
@@ -1209,7 +1216,7 @@ static unsigned int find_faked_portnum_from_hw_portnum(struct usb_hcd *hcd,
1209 * Skip ports that don't have known speeds, or have duplicate 1216 * Skip ports that don't have known speeds, or have duplicate
1210 * Extended Capabilities port speed entries. 1217 * Extended Capabilities port speed entries.
1211 */ 1218 */
1212 if (port_speed == 0 || port_speed == -1) 1219 if (port_speed == 0 || port_speed == DUPLICATE_ENTRY)
1213 continue; 1220 continue;
1214 1221
1215 /* 1222 /*
@@ -1235,6 +1242,7 @@ static void handle_port_status(struct xhci_hcd *xhci,
1235 u8 major_revision; 1242 u8 major_revision;
1236 struct xhci_bus_state *bus_state; 1243 struct xhci_bus_state *bus_state;
1237 u32 __iomem **port_array; 1244 u32 __iomem **port_array;
1245 bool bogus_port_status = false;
1238 1246
1239 /* Port status change events always have a successful completion code */ 1247 /* Port status change events always have a successful completion code */
1240 if (GET_COMP_CODE(event->generic.field[2]) != COMP_SUCCESS) { 1248 if (GET_COMP_CODE(event->generic.field[2]) != COMP_SUCCESS) {
@@ -1247,6 +1255,7 @@ static void handle_port_status(struct xhci_hcd *xhci,
1247 max_ports = HCS_MAX_PORTS(xhci->hcs_params1); 1255 max_ports = HCS_MAX_PORTS(xhci->hcs_params1);
1248 if ((port_id <= 0) || (port_id > max_ports)) { 1256 if ((port_id <= 0) || (port_id > max_ports)) {
1249 xhci_warn(xhci, "Invalid port id %d\n", port_id); 1257 xhci_warn(xhci, "Invalid port id %d\n", port_id);
1258 bogus_port_status = true;
1250 goto cleanup; 1259 goto cleanup;
1251 } 1260 }
1252 1261
@@ -1258,12 +1267,14 @@ static void handle_port_status(struct xhci_hcd *xhci,
1258 xhci_warn(xhci, "Event for port %u not in " 1267 xhci_warn(xhci, "Event for port %u not in "
1259 "Extended Capabilities, ignoring.\n", 1268 "Extended Capabilities, ignoring.\n",
1260 port_id); 1269 port_id);
1270 bogus_port_status = true;
1261 goto cleanup; 1271 goto cleanup;
1262 } 1272 }
1263 if (major_revision == (u8) -1) { 1273 if (major_revision == DUPLICATE_ENTRY) {
1264 xhci_warn(xhci, "Event for port %u duplicated in" 1274 xhci_warn(xhci, "Event for port %u duplicated in"
1265 "Extended Capabilities, ignoring.\n", 1275 "Extended Capabilities, ignoring.\n",
1266 port_id); 1276 port_id);
1277 bogus_port_status = true;
1267 goto cleanup; 1278 goto cleanup;
1268 } 1279 }
1269 1280
@@ -1335,6 +1346,13 @@ cleanup:
1335 /* Update event ring dequeue pointer before dropping the lock */ 1346 /* Update event ring dequeue pointer before dropping the lock */
1336 inc_deq(xhci, xhci->event_ring, true); 1347 inc_deq(xhci, xhci->event_ring, true);
1337 1348
1349 /* Don't make the USB core poll the roothub if we got a bad port status
1350 * change event. Besides, at that point we can't tell which roothub
1351 * (USB 2.0 or USB 3.0) to kick.
1352 */
1353 if (bogus_port_status)
1354 return;
1355
1338 spin_unlock(&xhci->lock); 1356 spin_unlock(&xhci->lock);
1339 /* Pass this up to the core */ 1357 /* Pass this up to the core */
1340 usb_hcd_poll_rh_status(hcd); 1358 usb_hcd_poll_rh_status(hcd);
@@ -1554,8 +1572,17 @@ td_cleanup:
1554 1572
1555 urb_priv->td_cnt++; 1573 urb_priv->td_cnt++;
1556 /* Giveback the urb when all the tds are completed */ 1574 /* Giveback the urb when all the tds are completed */
1557 if (urb_priv->td_cnt == urb_priv->length) 1575 if (urb_priv->td_cnt == urb_priv->length) {
1558 ret = 1; 1576 ret = 1;
1577 if (usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS) {
1578 xhci_to_hcd(xhci)->self.bandwidth_isoc_reqs--;
1579 if (xhci_to_hcd(xhci)->self.bandwidth_isoc_reqs
1580 == 0) {
1581 if (xhci->quirks & XHCI_AMD_PLL_FIX)
1582 usb_amd_quirk_pll_enable();
1583 }
1584 }
1585 }
1559 } 1586 }
1560 1587
1561 return ret; 1588 return ret;
@@ -1675,71 +1702,52 @@ static int process_isoc_td(struct xhci_hcd *xhci, struct xhci_td *td,
1675 struct urb_priv *urb_priv; 1702 struct urb_priv *urb_priv;
1676 int idx; 1703 int idx;
1677 int len = 0; 1704 int len = 0;
1678 int skip_td = 0;
1679 union xhci_trb *cur_trb; 1705 union xhci_trb *cur_trb;
1680 struct xhci_segment *cur_seg; 1706 struct xhci_segment *cur_seg;
1707 struct usb_iso_packet_descriptor *frame;
1681 u32 trb_comp_code; 1708 u32 trb_comp_code;
1709 bool skip_td = false;
1682 1710
1683 ep_ring = xhci_dma_to_transfer_ring(ep, event->buffer); 1711 ep_ring = xhci_dma_to_transfer_ring(ep, event->buffer);
1684 trb_comp_code = GET_COMP_CODE(event->transfer_len); 1712 trb_comp_code = GET_COMP_CODE(event->transfer_len);
1685 urb_priv = td->urb->hcpriv; 1713 urb_priv = td->urb->hcpriv;
1686 idx = urb_priv->td_cnt; 1714 idx = urb_priv->td_cnt;
1715 frame = &td->urb->iso_frame_desc[idx];
1687 1716
1688 if (ep->skip) { 1717 /* handle completion code */
1689 /* The transfer is partly done */ 1718 switch (trb_comp_code) {
1690 *status = -EXDEV; 1719 case COMP_SUCCESS:
1691 td->urb->iso_frame_desc[idx].status = -EXDEV; 1720 frame->status = 0;
1692 } else { 1721 xhci_dbg(xhci, "Successful isoc transfer!\n");
1693 /* handle completion code */ 1722 break;
1694 switch (trb_comp_code) { 1723 case COMP_SHORT_TX:
1695 case COMP_SUCCESS: 1724 frame->status = td->urb->transfer_flags & URB_SHORT_NOT_OK ?
1696 td->urb->iso_frame_desc[idx].status = 0; 1725 -EREMOTEIO : 0;
1697 xhci_dbg(xhci, "Successful isoc transfer!\n"); 1726 break;
1698 break; 1727 case COMP_BW_OVER:
1699 case COMP_SHORT_TX: 1728 frame->status = -ECOMM;
1700 if (td->urb->transfer_flags & URB_SHORT_NOT_OK) 1729 skip_td = true;
1701 td->urb->iso_frame_desc[idx].status = 1730 break;
1702 -EREMOTEIO; 1731 case COMP_BUFF_OVER:
1703 else 1732 case COMP_BABBLE:
1704 td->urb->iso_frame_desc[idx].status = 0; 1733 frame->status = -EOVERFLOW;
1705 break; 1734 skip_td = true;
1706 case COMP_BW_OVER: 1735 break;
1707 td->urb->iso_frame_desc[idx].status = -ECOMM; 1736 case COMP_STALL:
1708 skip_td = 1; 1737 frame->status = -EPROTO;
1709 break; 1738 skip_td = true;
1710 case COMP_BUFF_OVER: 1739 break;
1711 case COMP_BABBLE: 1740 case COMP_STOP:
1712 td->urb->iso_frame_desc[idx].status = -EOVERFLOW; 1741 case COMP_STOP_INVAL:
1713 skip_td = 1; 1742 break;
1714 break; 1743 default:
1715 case COMP_STALL: 1744 frame->status = -1;
1716 td->urb->iso_frame_desc[idx].status = -EPROTO; 1745 break;
1717 skip_td = 1;
1718 break;
1719 case COMP_STOP:
1720 case COMP_STOP_INVAL:
1721 break;
1722 default:
1723 td->urb->iso_frame_desc[idx].status = -1;
1724 break;
1725 }
1726 }
1727
1728 /* calc actual length */
1729 if (ep->skip) {
1730 td->urb->iso_frame_desc[idx].actual_length = 0;
1731 /* Update ring dequeue pointer */
1732 while (ep_ring->dequeue != td->last_trb)
1733 inc_deq(xhci, ep_ring, false);
1734 inc_deq(xhci, ep_ring, false);
1735 return finish_td(xhci, td, event_trb, event, ep, status, true);
1736 } 1746 }
1737 1747
1738 if (trb_comp_code == COMP_SUCCESS || skip_td == 1) { 1748 if (trb_comp_code == COMP_SUCCESS || skip_td) {
1739 td->urb->iso_frame_desc[idx].actual_length = 1749 frame->actual_length = frame->length;
1740 td->urb->iso_frame_desc[idx].length; 1750 td->urb->actual_length += frame->length;
1741 td->urb->actual_length +=
1742 td->urb->iso_frame_desc[idx].length;
1743 } else { 1751 } else {
1744 for (cur_trb = ep_ring->dequeue, 1752 for (cur_trb = ep_ring->dequeue,
1745 cur_seg = ep_ring->deq_seg; cur_trb != event_trb; 1753 cur_seg = ep_ring->deq_seg; cur_trb != event_trb;
@@ -1755,7 +1763,7 @@ static int process_isoc_td(struct xhci_hcd *xhci, struct xhci_td *td,
1755 TRB_LEN(event->transfer_len); 1763 TRB_LEN(event->transfer_len);
1756 1764
1757 if (trb_comp_code != COMP_STOP_INVAL) { 1765 if (trb_comp_code != COMP_STOP_INVAL) {
1758 td->urb->iso_frame_desc[idx].actual_length = len; 1766 frame->actual_length = len;
1759 td->urb->actual_length += len; 1767 td->urb->actual_length += len;
1760 } 1768 }
1761 } 1769 }
@@ -1766,6 +1774,35 @@ static int process_isoc_td(struct xhci_hcd *xhci, struct xhci_td *td,
1766 return finish_td(xhci, td, event_trb, event, ep, status, false); 1774 return finish_td(xhci, td, event_trb, event, ep, status, false);
1767} 1775}
1768 1776
1777static int skip_isoc_td(struct xhci_hcd *xhci, struct xhci_td *td,
1778 struct xhci_transfer_event *event,
1779 struct xhci_virt_ep *ep, int *status)
1780{
1781 struct xhci_ring *ep_ring;
1782 struct urb_priv *urb_priv;
1783 struct usb_iso_packet_descriptor *frame;
1784 int idx;
1785
1786 ep_ring = xhci_dma_to_transfer_ring(ep, event->buffer);
1787 urb_priv = td->urb->hcpriv;
1788 idx = urb_priv->td_cnt;
1789 frame = &td->urb->iso_frame_desc[idx];
1790
1791 /* The transfer is partly done */
1792 *status = -EXDEV;
1793 frame->status = -EXDEV;
1794
1795 /* calc actual length */
1796 frame->actual_length = 0;
1797
1798 /* Update ring dequeue pointer */
1799 while (ep_ring->dequeue != td->last_trb)
1800 inc_deq(xhci, ep_ring, false);
1801 inc_deq(xhci, ep_ring, false);
1802
1803 return finish_td(xhci, td, NULL, event, ep, status, true);
1804}
1805
1769/* 1806/*
1770 * Process bulk and interrupt tds, update urb status and actual_length. 1807 * Process bulk and interrupt tds, update urb status and actual_length.
1771 */ 1808 */
@@ -2024,36 +2061,42 @@ static int handle_tx_event(struct xhci_hcd *xhci,
2024 } 2061 }
2025 2062
2026 td = list_entry(ep_ring->td_list.next, struct xhci_td, td_list); 2063 td = list_entry(ep_ring->td_list.next, struct xhci_td, td_list);
2064
2027 /* Is this a TRB in the currently executing TD? */ 2065 /* Is this a TRB in the currently executing TD? */
2028 event_seg = trb_in_td(ep_ring->deq_seg, ep_ring->dequeue, 2066 event_seg = trb_in_td(ep_ring->deq_seg, ep_ring->dequeue,
2029 td->last_trb, event_dma); 2067 td->last_trb, event_dma);
2030 if (event_seg && ep->skip) { 2068 if (!event_seg) {
2069 if (!ep->skip ||
2070 !usb_endpoint_xfer_isoc(&td->urb->ep->desc)) {
2071 /* HC is busted, give up! */
2072 xhci_err(xhci,
2073 "ERROR Transfer event TRB DMA ptr not "
2074 "part of current TD\n");
2075 return -ESHUTDOWN;
2076 }
2077
2078 ret = skip_isoc_td(xhci, td, event, ep, &status);
2079 goto cleanup;
2080 }
2081
2082 if (ep->skip) {
2031 xhci_dbg(xhci, "Found td. Clear skip flag.\n"); 2083 xhci_dbg(xhci, "Found td. Clear skip flag.\n");
2032 ep->skip = false; 2084 ep->skip = false;
2033 } 2085 }
2034 if (!event_seg &&
2035 (!ep->skip || !usb_endpoint_xfer_isoc(&td->urb->ep->desc))) {
2036 /* HC is busted, give up! */
2037 xhci_err(xhci, "ERROR Transfer event TRB DMA ptr not "
2038 "part of current TD\n");
2039 return -ESHUTDOWN;
2040 }
2041 2086
2042 if (event_seg) { 2087 event_trb = &event_seg->trbs[(event_dma - event_seg->dma) /
2043 event_trb = &event_seg->trbs[(event_dma - 2088 sizeof(*event_trb)];
2044 event_seg->dma) / sizeof(*event_trb)]; 2089 /*
2045 /* 2090 * No-op TRB should not trigger interrupts.
2046 * No-op TRB should not trigger interrupts. 2091 * If event_trb is a no-op TRB, it means the
2047 * If event_trb is a no-op TRB, it means the 2092 * corresponding TD has been cancelled. Just ignore
2048 * corresponding TD has been cancelled. Just ignore 2093 * the TD.
2049 * the TD. 2094 */
2050 */ 2095 if ((event_trb->generic.field[3] & TRB_TYPE_BITMASK)
2051 if ((event_trb->generic.field[3] & TRB_TYPE_BITMASK) 2096 == TRB_TYPE(TRB_TR_NOOP)) {
2052 == TRB_TYPE(TRB_TR_NOOP)) { 2097 xhci_dbg(xhci,
2053 xhci_dbg(xhci, "event_trb is a no-op TRB. " 2098 "event_trb is a no-op TRB. Skip it\n");
2054 "Skip it\n"); 2099 goto cleanup;
2055 goto cleanup;
2056 }
2057 } 2100 }
2058 2101
2059 /* Now update the urb's actual_length and give back to 2102 /* Now update the urb's actual_length and give back to
@@ -3126,6 +3169,12 @@ static int xhci_queue_isoc_tx(struct xhci_hcd *xhci, gfp_t mem_flags,
3126 } 3169 }
3127 } 3170 }
3128 3171
3172 if (xhci_to_hcd(xhci)->self.bandwidth_isoc_reqs == 0) {
3173 if (xhci->quirks & XHCI_AMD_PLL_FIX)
3174 usb_amd_quirk_pll_disable();
3175 }
3176 xhci_to_hcd(xhci)->self.bandwidth_isoc_reqs++;
3177
3129 giveback_first_trb(xhci, slot_id, ep_index, urb->stream_id, 3178 giveback_first_trb(xhci, slot_id, ep_index, urb->stream_id,
3130 start_cycle, start_trb); 3179 start_cycle, start_trb);
3131 return 0; 3180 return 0;