Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

usb: xhci: Add Clear_TT_Buffer

USB 2.0 specification chapter 11.17.5 says "as part of endpoint halt
processing for full-/low-speed endpoints connected via a TT, the host
software must use the Clear_TT_Buffer request to the TT to ensure
that the buffer is not in the busy state".

In our case, a full-speed speaker (ConferenceCam) is behind a high-
speed hub (ConferenceCam Connect), sometimes once we get STALL on a
request we may continue to get STALL with the folllowing requests,
like Set_Interface.

Here we invoke usb_hub_clear_tt_buffer() to send Clear_TT_Buffer
request to the hub of the device for the following Set_Interface
requests to the device to get ACK successfully.

Signed-off-by: Jim Lin <jilin@nvidia.com>
Acked-by: Mathias Nyman <mathias.nyman@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Jim Lin and committed by
Greg Kroah-Hartman
ef513be0 4998f1ef

+52 -1
+26 -1
drivers/usb/host/xhci-ring.c
··· 399 399 * stream once the endpoint is on the HW schedule. 400 400 */ 401 401 if ((ep_state & EP_STOP_CMD_PENDING) || (ep_state & SET_DEQ_PENDING) || 402 - (ep_state & EP_HALTED)) 402 + (ep_state & EP_HALTED) || (ep_state & EP_CLEARING_TT)) 403 403 return; 404 404 writel(DB_VALUE(ep_index, stream_id), db_addr); 405 405 /* The CPU has better things to do at this point than wait for a ··· 431 431 xhci_ring_ep_doorbell(xhci, slot_id, ep_index, 432 432 stream_id); 433 433 } 434 + } 435 + 436 + void xhci_ring_doorbell_for_active_rings(struct xhci_hcd *xhci, 437 + unsigned int slot_id, 438 + unsigned int ep_index) 439 + { 440 + ring_doorbell_for_active_rings(xhci, slot_id, ep_index); 434 441 } 435 442 436 443 /* Get the right ring for the given slot_id, ep_index and stream_id. ··· 1801 1794 return NULL; 1802 1795 } 1803 1796 1797 + static void xhci_clear_hub_tt_buffer(struct xhci_hcd *xhci, struct xhci_td *td, 1798 + struct xhci_virt_ep *ep) 1799 + { 1800 + /* 1801 + * As part of low/full-speed endpoint-halt processing 1802 + * we must clear the TT buffer (USB 2.0 specification 11.17.5). 1803 + */ 1804 + if (td->urb->dev->tt && !usb_pipeint(td->urb->pipe) && 1805 + (td->urb->dev->tt->hub != xhci_to_hcd(xhci)->self.root_hub) && 1806 + !(ep->ep_state & EP_CLEARING_TT)) { 1807 + ep->ep_state |= EP_CLEARING_TT; 1808 + td->urb->ep->hcpriv = td->urb->dev; 1809 + if (usb_hub_clear_tt_buffer(td->urb)) 1810 + ep->ep_state &= ~EP_CLEARING_TT; 1811 + } 1812 + } 1813 + 1804 1814 static void xhci_cleanup_halted_endpoint(struct xhci_hcd *xhci, 1805 1815 unsigned int slot_id, unsigned int ep_index, 1806 1816 unsigned int stream_id, struct xhci_td *td, ··· 1836 1812 if (reset_type == EP_HARD_RESET) { 1837 1813 ep->ep_state |= EP_HARD_CLEAR_TOGGLE; 1838 1814 xhci_cleanup_stalled_ring(xhci, ep_index, stream_id, td); 1815 + xhci_clear_hub_tt_buffer(xhci, td, ep); 1839 1816 } 1840 1817 xhci_ring_cmd_db(xhci); 1841 1818 }
+21
drivers/usb/host/xhci.c
··· 5163 5163 } 5164 5164 EXPORT_SYMBOL_GPL(xhci_gen_setup); 5165 5165 5166 + static void xhci_clear_tt_buffer_complete(struct usb_hcd *hcd, 5167 + struct usb_host_endpoint *ep) 5168 + { 5169 + struct xhci_hcd *xhci; 5170 + struct usb_device *udev; 5171 + unsigned int slot_id; 5172 + unsigned int ep_index; 5173 + unsigned long flags; 5174 + 5175 + xhci = hcd_to_xhci(hcd); 5176 + udev = (struct usb_device *)ep->hcpriv; 5177 + slot_id = udev->slot_id; 5178 + ep_index = xhci_get_endpoint_index(&ep->desc); 5179 + 5180 + spin_lock_irqsave(&xhci->lock, flags); 5181 + xhci->devs[slot_id]->eps[ep_index].ep_state &= ~EP_CLEARING_TT; 5182 + xhci_ring_doorbell_for_active_rings(xhci, slot_id, ep_index); 5183 + spin_unlock_irqrestore(&xhci->lock, flags); 5184 + } 5185 + 5166 5186 static const struct hc_driver xhci_hc_driver = { 5167 5187 .description = "xhci-hcd", 5168 5188 .product_desc = "xHCI Host Controller", ··· 5244 5224 .enable_usb3_lpm_timeout = xhci_enable_usb3_lpm_timeout, 5245 5225 .disable_usb3_lpm_timeout = xhci_disable_usb3_lpm_timeout, 5246 5226 .find_raw_port_number = xhci_find_raw_port_number, 5227 + .clear_tt_buffer_complete = xhci_clear_tt_buffer_complete, 5247 5228 }; 5248 5229 5249 5230 void xhci_init_driver(struct hc_driver *drv,
+5
drivers/usb/host/xhci.h
··· 936 936 #define EP_GETTING_NO_STREAMS (1 << 5) 937 937 #define EP_HARD_CLEAR_TOGGLE (1 << 6) 938 938 #define EP_SOFT_CLEAR_TOGGLE (1 << 7) 939 + /* usb_hub_clear_tt_buffer is in progress */ 940 + #define EP_CLEARING_TT (1 << 8) 939 941 /* ---- Related to URB cancellation ---- */ 940 942 struct list_head cancelled_td_list; 941 943 /* Watchdog timer for stop endpoint command to cancel URBs */ ··· 2104 2102 2105 2103 void xhci_ring_ep_doorbell(struct xhci_hcd *xhci, unsigned int slot_id, 2106 2104 unsigned int ep_index, unsigned int stream_id); 2105 + void xhci_ring_doorbell_for_active_rings(struct xhci_hcd *xhci, 2106 + unsigned int slot_id, 2107 + unsigned int ep_index); 2107 2108 void xhci_cleanup_command_queue(struct xhci_hcd *xhci); 2108 2109 void inc_deq(struct xhci_hcd *xhci, struct xhci_ring *ring); 2109 2110 unsigned int count_trbs(u64 addr, u64 len);