summaryrefslogtreecommitdiff
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.c73
1 files changed, 62 insertions, 11 deletions
diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c
index c23434001e9c..a1fa188680f5 100644
--- a/drivers/usb/host/xhci-ring.c
+++ b/drivers/usb/host/xhci-ring.c
@@ -65,6 +65,7 @@
static int queue_command(struct xhci_hcd *xhci, struct xhci_command *cmd,
u32 field1, u32 field2,
u32 field3, u32 field4, bool command_must_succeed);
+static void xhci_kill_endpoint_urbs(struct xhci_hcd *xhci, int slot_id, int ep_index);
/*
* Returns zero if the TRB isn't in this segment, otherwise it returns the DMA
@@ -962,6 +963,24 @@ static void xhci_giveback_invalidated_tds(struct xhci_hcd *xhci, struct xhci_vir
}
}
+static void xhci_cancel_ring_tds(struct xhci_hcd *xhci, struct xhci_virt_ep *ep,
+ struct xhci_ring *ring, int td_status)
+{
+ struct xhci_td *tmp_td;
+ struct xhci_td *td;
+
+ /* Add all TDs on ring to cancelled td list */
+ list_for_each_entry_safe(td, tmp_td, &ring->td_list, td_list) {
+ if (list_empty(&td->cancelled_td_list)) {
+ list_add_tail(&td->cancelled_td_list,
+ &ep->cancelled_td_list);
+ td->cancel_status = TD_DIRTY;
+ if (!td->status)
+ td->status = td_status;
+ }
+ }
+}
+
static int xhci_reset_halted_ep(struct xhci_hcd *xhci, unsigned int slot_id,
unsigned int ep_index, enum xhci_ep_reset_type reset_type)
{
@@ -993,33 +1012,64 @@ static int xhci_handle_halted_endpoint(struct xhci_hcd *xhci,
{
struct xhci_port *rhub_port = ep->vdev->rhub_port;
unsigned int slot_id = ep->vdev->slot_id;
+ bool disconnected = false;
+ struct xhci_ring *ring;
int err;
- /*
- * Avoid resetting endpoint if link is inactive or device disconnected.
- * Can cause host hang.
- * Device will be reset to recover an inactive link, so don't do anything
- */
+ /* link is inactive or device disconnected */
if (rhub_port->link_inactive || !rhub_port->connected) {
ep->ep_state |= EP_DROP_PENDING;
- return -ENODEV;
+ disconnected = true;
+ if (!td && ep->ep_index != 0) {
+ xhci_kill_endpoint_urbs(xhci, slot_id, ep->ep_index);
+ return -ENODEV;
+ }
}
- /* add td to cancelled list and let reset ep handler take care of it */
- if (reset_type == EP_HARD_RESET) {
- ep->ep_state |= EP_HARD_CLEAR_TOGGLE;
+ /* Add halted td to cancelled list and let reset ep handler take care of it */
+ if (reset_type == EP_HARD_RESET || disconnected) {
if (td && list_empty(&td->cancelled_td_list)) {
list_add_tail(&td->cancelled_td_list, &ep->cancelled_td_list);
td->cancel_status = TD_HALTED;
+ if (disconnected && !td->status)
+ td->status = -EPROTO;
}
}
+ /*
+ * Avoid resetting non-ep0 endpoints if link is inactive or device
+ * disconnected. Can cause host hang.
+ * Endpoints other than ep0 won't restart before the device is reset or
+ * the endpoint is dropped, so cancel all TDs, and give back non-ep0 TDs
+ * now instead of letting them time out. Ep0 can survive a short device
+ * disconnect during enumeration so reset ep0 normally and clean it up.
+ */
+ if (disconnected) {
+ ring = td ? xhci_urb_to_transfer_ring(xhci, td->urb) : ep->ring;
+ xhci_cancel_ring_tds(xhci, ep, ring, -ESHUTDOWN);
+ if (ep->ep_index != 0) {
+ xhci_dbg(xhci, "Not resetting ep %u slot %u after disconnect\n",
+ ep->ep_index, slot_id);
+
+ xhci_process_cancelled_tds(xhci, ep);
+ xhci_kill_endpoint_urbs(xhci, slot_id, ep->ep_index);
+ return -ENODEV;
+ }
+ /* hard-reset a halted disconnected ep0 */
+ xhci_dbg(xhci, "Reset and clean up ep0 slot %u after disconnect\n",
+ slot_id);
+ reset_type = EP_HARD_RESET;
+ }
+
if (ep->ep_state & EP_HALTED) {
xhci_dbg(xhci, "Reset ep command for ep_index %d already pending\n",
ep->ep_index);
return 0;
}
+ if (reset_type == EP_HARD_RESET)
+ ep->ep_state |= EP_HARD_CLEAR_TOGGLE;
+
err = xhci_reset_halted_ep(xhci, slot_id, ep->ep_index, reset_type);
if (err)
return err;
@@ -1070,8 +1120,9 @@ static int xhci_invalidate_cancelled_tds(struct xhci_hcd *xhci, struct xhci_virt
continue;
}
- /* device disconnected or link error, ep will be dropped */
- if (ep->ep_state & EP_DROP_PENDING) {
+ /* device disconnected or link error, non-ep0 endpoints will be dropped */
+ if (ep->ep_state & EP_DROP_PENDING && ep->ep_index != 0) {
+ td_to_noop(xhci, ep, td, false);
td->cancel_status = TD_CLEARED;
continue;
}