diff options
Diffstat (limited to 'drivers/usb/host/ehci-sched.c')
-rw-r--r-- | drivers/usb/host/ehci-sched.c | 152 |
1 files changed, 84 insertions, 68 deletions
diff --git a/drivers/usb/host/ehci-sched.c b/drivers/usb/host/ehci-sched.c index 80d99bce2b38..8a8e08a51ba3 100644 --- a/drivers/usb/host/ehci-sched.c +++ b/drivers/usb/host/ehci-sched.c | |||
@@ -119,7 +119,8 @@ periodic_usecs (struct ehci_hcd *ehci, unsigned frame, unsigned uframe) | |||
119 | q = &q->fstn->fstn_next; | 119 | q = &q->fstn->fstn_next; |
120 | break; | 120 | break; |
121 | case Q_TYPE_ITD: | 121 | case Q_TYPE_ITD: |
122 | usecs += q->itd->usecs [uframe]; | 122 | if (q->itd->hw_transaction[uframe]) |
123 | usecs += q->itd->stream->usecs; | ||
123 | hw_p = &q->itd->hw_next; | 124 | hw_p = &q->itd->hw_next; |
124 | q = &q->itd->itd_next; | 125 | q = &q->itd->itd_next; |
125 | break; | 126 | break; |
@@ -211,7 +212,7 @@ static inline void carryover_tt_bandwidth(unsigned short tt_usecs[8]) | |||
211 | * low/fullspeed transfer can "carry over" from one uframe to the next, | 212 | * low/fullspeed transfer can "carry over" from one uframe to the next, |
212 | * since the TT just performs downstream transfers in sequence. | 213 | * since the TT just performs downstream transfers in sequence. |
213 | * | 214 | * |
214 | * For example two seperate 100 usec transfers can start in the same uframe, | 215 | * For example two separate 100 usec transfers can start in the same uframe, |
215 | * and the second one would "carry over" 75 usecs into the next uframe. | 216 | * and the second one would "carry over" 75 usecs into the next uframe. |
216 | */ | 217 | */ |
217 | static void | 218 | static void |
@@ -1536,7 +1537,6 @@ itd_link_urb ( | |||
1536 | uframe = next_uframe & 0x07; | 1537 | uframe = next_uframe & 0x07; |
1537 | frame = next_uframe >> 3; | 1538 | frame = next_uframe >> 3; |
1538 | 1539 | ||
1539 | itd->usecs [uframe] = stream->usecs; | ||
1540 | itd_patch(ehci, itd, iso_sched, packet, uframe); | 1540 | itd_patch(ehci, itd, iso_sched, packet, uframe); |
1541 | 1541 | ||
1542 | next_uframe += stream->interval; | 1542 | next_uframe += stream->interval; |
@@ -1565,6 +1565,16 @@ itd_link_urb ( | |||
1565 | 1565 | ||
1566 | #define ISO_ERRS (EHCI_ISOC_BUF_ERR | EHCI_ISOC_BABBLE | EHCI_ISOC_XACTERR) | 1566 | #define ISO_ERRS (EHCI_ISOC_BUF_ERR | EHCI_ISOC_BABBLE | EHCI_ISOC_XACTERR) |
1567 | 1567 | ||
1568 | /* Process and recycle a completed ITD. Return true iff its urb completed, | ||
1569 | * and hence its completion callback probably added things to the hardware | ||
1570 | * schedule. | ||
1571 | * | ||
1572 | * Note that we carefully avoid recycling this descriptor until after any | ||
1573 | * completion callback runs, so that it won't be reused quickly. That is, | ||
1574 | * assuming (a) no more than two urbs per frame on this endpoint, and also | ||
1575 | * (b) only this endpoint's completions submit URBs. It seems some silicon | ||
1576 | * corrupts things if you reuse completed descriptors very quickly... | ||
1577 | */ | ||
1568 | static unsigned | 1578 | static unsigned |
1569 | itd_complete ( | 1579 | itd_complete ( |
1570 | struct ehci_hcd *ehci, | 1580 | struct ehci_hcd *ehci, |
@@ -1577,6 +1587,7 @@ itd_complete ( | |||
1577 | int urb_index = -1; | 1587 | int urb_index = -1; |
1578 | struct ehci_iso_stream *stream = itd->stream; | 1588 | struct ehci_iso_stream *stream = itd->stream; |
1579 | struct usb_device *dev; | 1589 | struct usb_device *dev; |
1590 | unsigned retval = false; | ||
1580 | 1591 | ||
1581 | /* for each uframe with a packet */ | 1592 | /* for each uframe with a packet */ |
1582 | for (uframe = 0; uframe < 8; uframe++) { | 1593 | for (uframe = 0; uframe < 8; uframe++) { |
@@ -1610,30 +1621,21 @@ itd_complete ( | |||
1610 | } | 1621 | } |
1611 | } | 1622 | } |
1612 | 1623 | ||
1613 | usb_put_urb (urb); | ||
1614 | itd->urb = NULL; | ||
1615 | itd->stream = NULL; | ||
1616 | list_move (&itd->itd_list, &stream->free_list); | ||
1617 | iso_stream_put (ehci, stream); | ||
1618 | |||
1619 | /* handle completion now? */ | 1624 | /* handle completion now? */ |
1620 | if (likely ((urb_index + 1) != urb->number_of_packets)) | 1625 | if (likely ((urb_index + 1) != urb->number_of_packets)) |
1621 | return 0; | 1626 | goto done; |
1622 | 1627 | ||
1623 | /* ASSERT: it's really the last itd for this urb | 1628 | /* ASSERT: it's really the last itd for this urb |
1624 | list_for_each_entry (itd, &stream->td_list, itd_list) | 1629 | list_for_each_entry (itd, &stream->td_list, itd_list) |
1625 | BUG_ON (itd->urb == urb); | 1630 | BUG_ON (itd->urb == urb); |
1626 | */ | 1631 | */ |
1627 | 1632 | ||
1628 | /* give urb back to the driver ... can be out-of-order */ | 1633 | /* give urb back to the driver; completion often (re)submits */ |
1629 | dev = urb->dev; | 1634 | dev = urb->dev; |
1630 | ehci_urb_done(ehci, urb, 0); | 1635 | ehci_urb_done(ehci, urb, 0); |
1636 | retval = true; | ||
1631 | urb = NULL; | 1637 | urb = NULL; |
1632 | |||
1633 | /* defer stopping schedule; completion can submit */ | ||
1634 | ehci->periodic_sched--; | 1638 | ehci->periodic_sched--; |
1635 | if (unlikely (!ehci->periodic_sched)) | ||
1636 | (void) disable_periodic (ehci); | ||
1637 | ehci_to_hcd(ehci)->self.bandwidth_isoc_reqs--; | 1639 | ehci_to_hcd(ehci)->self.bandwidth_isoc_reqs--; |
1638 | 1640 | ||
1639 | if (unlikely (list_empty (&stream->td_list))) { | 1641 | if (unlikely (list_empty (&stream->td_list))) { |
@@ -1645,8 +1647,15 @@ itd_complete ( | |||
1645 | (stream->bEndpointAddress & USB_DIR_IN) ? "in" : "out"); | 1647 | (stream->bEndpointAddress & USB_DIR_IN) ? "in" : "out"); |
1646 | } | 1648 | } |
1647 | iso_stream_put (ehci, stream); | 1649 | iso_stream_put (ehci, stream); |
1650 | /* OK to recycle this ITD now that its completion callback ran. */ | ||
1651 | done: | ||
1652 | usb_put_urb(urb); | ||
1653 | itd->urb = NULL; | ||
1654 | itd->stream = NULL; | ||
1655 | list_move(&itd->itd_list, &stream->free_list); | ||
1656 | iso_stream_put(ehci, stream); | ||
1648 | 1657 | ||
1649 | return 1; | 1658 | return retval; |
1650 | } | 1659 | } |
1651 | 1660 | ||
1652 | /*-------------------------------------------------------------------------*/ | 1661 | /*-------------------------------------------------------------------------*/ |
@@ -1712,8 +1721,6 @@ done: | |||
1712 | return status; | 1721 | return status; |
1713 | } | 1722 | } |
1714 | 1723 | ||
1715 | #ifdef CONFIG_USB_EHCI_SPLIT_ISO | ||
1716 | |||
1717 | /*-------------------------------------------------------------------------*/ | 1724 | /*-------------------------------------------------------------------------*/ |
1718 | 1725 | ||
1719 | /* | 1726 | /* |
@@ -1950,6 +1957,16 @@ sitd_link_urb ( | |||
1950 | #define SITD_ERRS (SITD_STS_ERR | SITD_STS_DBE | SITD_STS_BABBLE \ | 1957 | #define SITD_ERRS (SITD_STS_ERR | SITD_STS_DBE | SITD_STS_BABBLE \ |
1951 | | SITD_STS_XACT | SITD_STS_MMF) | 1958 | | SITD_STS_XACT | SITD_STS_MMF) |
1952 | 1959 | ||
1960 | /* Process and recycle a completed SITD. Return true iff its urb completed, | ||
1961 | * and hence its completion callback probably added things to the hardware | ||
1962 | * schedule. | ||
1963 | * | ||
1964 | * Note that we carefully avoid recycling this descriptor until after any | ||
1965 | * completion callback runs, so that it won't be reused quickly. That is, | ||
1966 | * assuming (a) no more than two urbs per frame on this endpoint, and also | ||
1967 | * (b) only this endpoint's completions submit URBs. It seems some silicon | ||
1968 | * corrupts things if you reuse completed descriptors very quickly... | ||
1969 | */ | ||
1953 | static unsigned | 1970 | static unsigned |
1954 | sitd_complete ( | 1971 | sitd_complete ( |
1955 | struct ehci_hcd *ehci, | 1972 | struct ehci_hcd *ehci, |
@@ -1961,6 +1978,7 @@ sitd_complete ( | |||
1961 | int urb_index = -1; | 1978 | int urb_index = -1; |
1962 | struct ehci_iso_stream *stream = sitd->stream; | 1979 | struct ehci_iso_stream *stream = sitd->stream; |
1963 | struct usb_device *dev; | 1980 | struct usb_device *dev; |
1981 | unsigned retval = false; | ||
1964 | 1982 | ||
1965 | urb_index = sitd->index; | 1983 | urb_index = sitd->index; |
1966 | desc = &urb->iso_frame_desc [urb_index]; | 1984 | desc = &urb->iso_frame_desc [urb_index]; |
@@ -1981,32 +1999,23 @@ sitd_complete ( | |||
1981 | desc->status = 0; | 1999 | desc->status = 0; |
1982 | desc->actual_length = desc->length - SITD_LENGTH (t); | 2000 | desc->actual_length = desc->length - SITD_LENGTH (t); |
1983 | } | 2001 | } |
1984 | |||
1985 | usb_put_urb (urb); | ||
1986 | sitd->urb = NULL; | ||
1987 | sitd->stream = NULL; | ||
1988 | list_move (&sitd->sitd_list, &stream->free_list); | ||
1989 | stream->depth -= stream->interval << 3; | 2002 | stream->depth -= stream->interval << 3; |
1990 | iso_stream_put (ehci, stream); | ||
1991 | 2003 | ||
1992 | /* handle completion now? */ | 2004 | /* handle completion now? */ |
1993 | if ((urb_index + 1) != urb->number_of_packets) | 2005 | if ((urb_index + 1) != urb->number_of_packets) |
1994 | return 0; | 2006 | goto done; |
1995 | 2007 | ||
1996 | /* ASSERT: it's really the last sitd for this urb | 2008 | /* ASSERT: it's really the last sitd for this urb |
1997 | list_for_each_entry (sitd, &stream->td_list, sitd_list) | 2009 | list_for_each_entry (sitd, &stream->td_list, sitd_list) |
1998 | BUG_ON (sitd->urb == urb); | 2010 | BUG_ON (sitd->urb == urb); |
1999 | */ | 2011 | */ |
2000 | 2012 | ||
2001 | /* give urb back to the driver */ | 2013 | /* give urb back to the driver; completion often (re)submits */ |
2002 | dev = urb->dev; | 2014 | dev = urb->dev; |
2003 | ehci_urb_done(ehci, urb, 0); | 2015 | ehci_urb_done(ehci, urb, 0); |
2016 | retval = true; | ||
2004 | urb = NULL; | 2017 | urb = NULL; |
2005 | |||
2006 | /* defer stopping schedule; completion can submit */ | ||
2007 | ehci->periodic_sched--; | 2018 | ehci->periodic_sched--; |
2008 | if (!ehci->periodic_sched) | ||
2009 | (void) disable_periodic (ehci); | ||
2010 | ehci_to_hcd(ehci)->self.bandwidth_isoc_reqs--; | 2019 | ehci_to_hcd(ehci)->self.bandwidth_isoc_reqs--; |
2011 | 2020 | ||
2012 | if (list_empty (&stream->td_list)) { | 2021 | if (list_empty (&stream->td_list)) { |
@@ -2018,8 +2027,15 @@ sitd_complete ( | |||
2018 | (stream->bEndpointAddress & USB_DIR_IN) ? "in" : "out"); | 2027 | (stream->bEndpointAddress & USB_DIR_IN) ? "in" : "out"); |
2019 | } | 2028 | } |
2020 | iso_stream_put (ehci, stream); | 2029 | iso_stream_put (ehci, stream); |
2030 | /* OK to recycle this SITD now that its completion callback ran. */ | ||
2031 | done: | ||
2032 | usb_put_urb(urb); | ||
2033 | sitd->urb = NULL; | ||
2034 | sitd->stream = NULL; | ||
2035 | list_move(&sitd->sitd_list, &stream->free_list); | ||
2036 | iso_stream_put(ehci, stream); | ||
2021 | 2037 | ||
2022 | return 1; | 2038 | return retval; |
2023 | } | 2039 | } |
2024 | 2040 | ||
2025 | 2041 | ||
@@ -2082,26 +2098,6 @@ done: | |||
2082 | return status; | 2098 | return status; |
2083 | } | 2099 | } |
2084 | 2100 | ||
2085 | #else | ||
2086 | |||
2087 | static inline int | ||
2088 | sitd_submit (struct ehci_hcd *ehci, struct urb *urb, gfp_t mem_flags) | ||
2089 | { | ||
2090 | ehci_dbg (ehci, "split iso support is disabled\n"); | ||
2091 | return -ENOSYS; | ||
2092 | } | ||
2093 | |||
2094 | static inline unsigned | ||
2095 | sitd_complete ( | ||
2096 | struct ehci_hcd *ehci, | ||
2097 | struct ehci_sitd *sitd | ||
2098 | ) { | ||
2099 | ehci_err (ehci, "sitd_complete %p?\n", sitd); | ||
2100 | return 0; | ||
2101 | } | ||
2102 | |||
2103 | #endif /* USB_EHCI_SPLIT_ISO */ | ||
2104 | |||
2105 | /*-------------------------------------------------------------------------*/ | 2101 | /*-------------------------------------------------------------------------*/ |
2106 | 2102 | ||
2107 | static void | 2103 | static void |
@@ -2127,17 +2123,9 @@ scan_periodic (struct ehci_hcd *ehci) | |||
2127 | for (;;) { | 2123 | for (;;) { |
2128 | union ehci_shadow q, *q_p; | 2124 | union ehci_shadow q, *q_p; |
2129 | __hc32 type, *hw_p; | 2125 | __hc32 type, *hw_p; |
2130 | unsigned uframes; | 2126 | unsigned incomplete = false; |
2131 | 2127 | ||
2132 | /* don't scan past the live uframe */ | ||
2133 | frame = now_uframe >> 3; | 2128 | frame = now_uframe >> 3; |
2134 | if (frame == (clock >> 3)) | ||
2135 | uframes = now_uframe & 0x07; | ||
2136 | else { | ||
2137 | /* safe to scan the whole frame at once */ | ||
2138 | now_uframe |= 0x07; | ||
2139 | uframes = 8; | ||
2140 | } | ||
2141 | 2129 | ||
2142 | restart: | 2130 | restart: |
2143 | /* scan each element in frame's queue for completions */ | 2131 | /* scan each element in frame's queue for completions */ |
@@ -2175,12 +2163,15 @@ restart: | |||
2175 | q = q.fstn->fstn_next; | 2163 | q = q.fstn->fstn_next; |
2176 | break; | 2164 | break; |
2177 | case Q_TYPE_ITD: | 2165 | case Q_TYPE_ITD: |
2178 | /* skip itds for later in the frame */ | 2166 | /* If this ITD is still active, leave it for |
2167 | * later processing ... check the next entry. | ||
2168 | */ | ||
2179 | rmb (); | 2169 | rmb (); |
2180 | for (uf = live ? uframes : 8; uf < 8; uf++) { | 2170 | for (uf = 0; uf < 8 && live; uf++) { |
2181 | if (0 == (q.itd->hw_transaction [uf] | 2171 | if (0 == (q.itd->hw_transaction [uf] |
2182 | & ITD_ACTIVE(ehci))) | 2172 | & ITD_ACTIVE(ehci))) |
2183 | continue; | 2173 | continue; |
2174 | incomplete = true; | ||
2184 | q_p = &q.itd->itd_next; | 2175 | q_p = &q.itd->itd_next; |
2185 | hw_p = &q.itd->hw_next; | 2176 | hw_p = &q.itd->hw_next; |
2186 | type = Q_NEXT_TYPE(ehci, | 2177 | type = Q_NEXT_TYPE(ehci, |
@@ -2188,10 +2179,12 @@ restart: | |||
2188 | q = *q_p; | 2179 | q = *q_p; |
2189 | break; | 2180 | break; |
2190 | } | 2181 | } |
2191 | if (uf != 8) | 2182 | if (uf < 8 && live) |
2192 | break; | 2183 | break; |
2193 | 2184 | ||
2194 | /* this one's ready ... HC won't cache the | 2185 | /* Take finished ITDs out of the schedule |
2186 | * and process them: recycle, maybe report | ||
2187 | * URB completion. HC won't cache the | ||
2195 | * pointer for much longer, if at all. | 2188 | * pointer for much longer, if at all. |
2196 | */ | 2189 | */ |
2197 | *q_p = q.itd->itd_next; | 2190 | *q_p = q.itd->itd_next; |
@@ -2202,8 +2195,12 @@ restart: | |||
2202 | q = *q_p; | 2195 | q = *q_p; |
2203 | break; | 2196 | break; |
2204 | case Q_TYPE_SITD: | 2197 | case Q_TYPE_SITD: |
2198 | /* If this SITD is still active, leave it for | ||
2199 | * later processing ... check the next entry. | ||
2200 | */ | ||
2205 | if ((q.sitd->hw_results & SITD_ACTIVE(ehci)) | 2201 | if ((q.sitd->hw_results & SITD_ACTIVE(ehci)) |
2206 | && live) { | 2202 | && live) { |
2203 | incomplete = true; | ||
2207 | q_p = &q.sitd->sitd_next; | 2204 | q_p = &q.sitd->sitd_next; |
2208 | hw_p = &q.sitd->hw_next; | 2205 | hw_p = &q.sitd->hw_next; |
2209 | type = Q_NEXT_TYPE(ehci, | 2206 | type = Q_NEXT_TYPE(ehci, |
@@ -2211,6 +2208,11 @@ restart: | |||
2211 | q = *q_p; | 2208 | q = *q_p; |
2212 | break; | 2209 | break; |
2213 | } | 2210 | } |
2211 | |||
2212 | /* Take finished SITDs out of the schedule | ||
2213 | * and process them: recycle, maybe report | ||
2214 | * URB completion. | ||
2215 | */ | ||
2214 | *q_p = q.sitd->sitd_next; | 2216 | *q_p = q.sitd->sitd_next; |
2215 | *hw_p = q.sitd->hw_next; | 2217 | *hw_p = q.sitd->hw_next; |
2216 | type = Q_NEXT_TYPE(ehci, q.sitd->hw_next); | 2218 | type = Q_NEXT_TYPE(ehci, q.sitd->hw_next); |
@@ -2226,11 +2228,24 @@ restart: | |||
2226 | } | 2228 | } |
2227 | 2229 | ||
2228 | /* assume completion callbacks modify the queue */ | 2230 | /* assume completion callbacks modify the queue */ |
2229 | if (unlikely (modified)) | 2231 | if (unlikely (modified)) { |
2230 | goto restart; | 2232 | if (likely(ehci->periodic_sched > 0)) |
2233 | goto restart; | ||
2234 | /* maybe we can short-circuit this scan! */ | ||
2235 | disable_periodic(ehci); | ||
2236 | now_uframe = clock; | ||
2237 | break; | ||
2238 | } | ||
2231 | } | 2239 | } |
2232 | 2240 | ||
2233 | /* stop when we catch up to the HC */ | 2241 | /* If we can tell we caught up to the hardware, stop now. |
2242 | * We can't advance our scan without collecting the ISO | ||
2243 | * transfers that are still pending in this frame. | ||
2244 | */ | ||
2245 | if (incomplete && HC_IS_RUNNING(ehci_to_hcd(ehci)->state)) { | ||
2246 | ehci->next_uframe = now_uframe; | ||
2247 | break; | ||
2248 | } | ||
2234 | 2249 | ||
2235 | // FIXME: this assumes we won't get lapped when | 2250 | // FIXME: this assumes we won't get lapped when |
2236 | // latencies climb; that should be rare, but... | 2251 | // latencies climb; that should be rare, but... |
@@ -2243,7 +2258,8 @@ restart: | |||
2243 | if (now_uframe == clock) { | 2258 | if (now_uframe == clock) { |
2244 | unsigned now; | 2259 | unsigned now; |
2245 | 2260 | ||
2246 | if (!HC_IS_RUNNING (ehci_to_hcd(ehci)->state)) | 2261 | if (!HC_IS_RUNNING (ehci_to_hcd(ehci)->state) |
2262 | || ehci->periodic_sched == 0) | ||
2247 | break; | 2263 | break; |
2248 | ehci->next_uframe = now_uframe; | 2264 | ehci->next_uframe = now_uframe; |
2249 | now = ehci_readl(ehci, &ehci->regs->frame_index) % mod; | 2265 | now = ehci_readl(ehci, &ehci->regs->frame_index) % mod; |