Commit a38ea35f authored by Sarah Sharp's avatar Sarah Sharp Committed by Stephen Rothwell

USB: xhci: Handle stalled control endpoints.

When a control endpoint stalls, the next control transfer will clear the
stall.  The USB core doesn't call down to the host controller driver's
endpoint_reset() method when control endpoints stall, so the xHCI driver
has to do all its stall handling for internal state in its interrupt handler.

When the host stalls on a control endpoint, it may stop on the data phase
or status phase of the control transfer.  Like other stalled endpoints,
the xHCI driver needs to queue a Reset Endpoint command and move the
hardware's control endpoint ring dequeue pointer past the failed control
transfer (with a Set TR Dequeue Pointer or a Configure Endpoint command).

Since the USB core doesn't call usb_hcd_reset_endpoint() for control
endpoints, we need to do this in interrupt context when we get notified of
the stalled transfer.  URBs may be queued to the hardware before these two
commands complete.  The endpoint queue will be restarted once both
commands complete.
Signed-off-by: default avatarSarah Sharp <sarah.a.sharp@linux.intel.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent 731c177a
...@@ -1230,6 +1230,25 @@ void xhci_reset_bandwidth(struct usb_hcd *hcd, struct usb_device *udev) ...@@ -1230,6 +1230,25 @@ void xhci_reset_bandwidth(struct usb_hcd *hcd, struct usb_device *udev)
xhci_zero_in_ctx(xhci, virt_dev); xhci_zero_in_ctx(xhci, virt_dev);
} }
void xhci_cleanup_stalled_ring(struct xhci_hcd *xhci,
struct usb_device *udev, struct usb_host_endpoint *ep,
unsigned int ep_index, struct xhci_ring *ep_ring)
{
struct xhci_dequeue_state deq_state;
xhci_dbg(xhci, "Cleaning up stalled endpoint ring\n");
/* We need to move the HW's dequeue pointer past this TD,
* or it will attempt to resend it on the next doorbell ring.
*/
xhci_find_new_dequeue_state(xhci, udev->slot_id,
ep_index, ep_ring->stopped_td, &deq_state);
xhci_dbg(xhci, "Queueing new dequeue state\n");
xhci_queue_new_dequeue_state(xhci, ep_ring,
udev->slot_id,
ep_index, &deq_state);
}
/* Deal with stalled endpoints. The core should have sent the control message /* Deal with stalled endpoints. The core should have sent the control message
* to clear the halt condition. However, we need to make the xHCI hardware * to clear the halt condition. However, we need to make the xHCI hardware
* reset its sequence number, since a device will expect a sequence number of * reset its sequence number, since a device will expect a sequence number of
...@@ -1244,7 +1263,6 @@ void xhci_endpoint_reset(struct usb_hcd *hcd, ...@@ -1244,7 +1263,6 @@ void xhci_endpoint_reset(struct usb_hcd *hcd,
unsigned int ep_index; unsigned int ep_index;
unsigned long flags; unsigned long flags;
int ret; int ret;
struct xhci_dequeue_state deq_state;
struct xhci_ring *ep_ring; struct xhci_ring *ep_ring;
xhci = hcd_to_xhci(hcd); xhci = hcd_to_xhci(hcd);
...@@ -1261,6 +1279,10 @@ void xhci_endpoint_reset(struct usb_hcd *hcd, ...@@ -1261,6 +1279,10 @@ void xhci_endpoint_reset(struct usb_hcd *hcd,
ep->desc.bEndpointAddress); ep->desc.bEndpointAddress);
return; return;
} }
if (usb_endpoint_xfer_control(&ep->desc)) {
xhci_dbg(xhci, "Control endpoint stall already handled.\n");
return;
}
xhci_dbg(xhci, "Queueing reset endpoint command\n"); xhci_dbg(xhci, "Queueing reset endpoint command\n");
spin_lock_irqsave(&xhci->lock, flags); spin_lock_irqsave(&xhci->lock, flags);
...@@ -1271,16 +1293,7 @@ void xhci_endpoint_reset(struct usb_hcd *hcd, ...@@ -1271,16 +1293,7 @@ void xhci_endpoint_reset(struct usb_hcd *hcd,
* command. Better hope that last command worked! * command. Better hope that last command worked!
*/ */
if (!ret) { if (!ret) {
xhci_dbg(xhci, "Cleaning up stalled endpoint ring\n"); xhci_cleanup_stalled_ring(xhci, udev, ep, ep_index, ep_ring);
/* We need to move the HW's dequeue pointer past this TD,
* or it will attempt to resend it on the next doorbell ring.
*/
xhci_find_new_dequeue_state(xhci, udev->slot_id,
ep_index, ep_ring->stopped_td, &deq_state);
xhci_dbg(xhci, "Queueing new dequeue state\n");
xhci_queue_new_dequeue_state(xhci, ep_ring,
udev->slot_id,
ep_index, &deq_state);
kfree(ep_ring->stopped_td); kfree(ep_ring->stopped_td);
xhci_ring_cmd_db(xhci); xhci_ring_cmd_db(xhci);
} }
......
...@@ -817,6 +817,7 @@ static int handle_tx_event(struct xhci_hcd *xhci, ...@@ -817,6 +817,7 @@ static int handle_tx_event(struct xhci_hcd *xhci,
{ {
struct xhci_virt_device *xdev; struct xhci_virt_device *xdev;
struct xhci_ring *ep_ring; struct xhci_ring *ep_ring;
unsigned int slot_id;
int ep_index; int ep_index;
struct xhci_td *td = 0; struct xhci_td *td = 0;
dma_addr_t event_dma; dma_addr_t event_dma;
...@@ -827,7 +828,8 @@ static int handle_tx_event(struct xhci_hcd *xhci, ...@@ -827,7 +828,8 @@ static int handle_tx_event(struct xhci_hcd *xhci,
struct xhci_ep_ctx *ep_ctx; struct xhci_ep_ctx *ep_ctx;
xhci_dbg(xhci, "In %s\n", __func__); xhci_dbg(xhci, "In %s\n", __func__);
xdev = xhci->devs[TRB_TO_SLOT_ID(event->flags)]; slot_id = TRB_TO_SLOT_ID(event->flags);
xdev = xhci->devs[slot_id];
if (!xdev) { if (!xdev) {
xhci_err(xhci, "ERROR Transfer event pointed to bad slot\n"); xhci_err(xhci, "ERROR Transfer event pointed to bad slot\n");
return -ENODEV; return -ENODEV;
...@@ -941,6 +943,25 @@ static int handle_tx_event(struct xhci_hcd *xhci, ...@@ -941,6 +943,25 @@ static int handle_tx_event(struct xhci_hcd *xhci,
xhci_warn(xhci, "WARN: short transfer on control ep\n"); xhci_warn(xhci, "WARN: short transfer on control ep\n");
status = -EREMOTEIO; status = -EREMOTEIO;
break; break;
case COMP_STALL:
/* Did we transfer part of the data (middle) phase? */
if (event_trb != ep_ring->dequeue &&
event_trb != td->last_trb)
td->urb->actual_length =
td->urb->transfer_buffer_length
- TRB_LEN(event->transfer_len);
else
td->urb->actual_length = 0;
ep_ring->stopped_td = td;
ep_ring->stopped_trb = event_trb;
xhci_queue_reset_ep(xhci, slot_id, ep_index);
xhci_cleanup_stalled_ring(xhci,
td->urb->dev,
td->urb->ep,
ep_index, ep_ring);
xhci_ring_cmd_db(xhci);
goto td_cleanup;
default: default:
/* Others already handled above */ /* Others already handled above */
break; break;
...@@ -1083,6 +1104,7 @@ static int handle_tx_event(struct xhci_hcd *xhci, ...@@ -1083,6 +1104,7 @@ static int handle_tx_event(struct xhci_hcd *xhci,
inc_deq(xhci, ep_ring, false); inc_deq(xhci, ep_ring, false);
} }
td_cleanup:
/* Clean up the endpoint's TD list */ /* Clean up the endpoint's TD list */
urb = td->urb; urb = td->urb;
list_del(&td->td_list); list_del(&td->td_list);
...@@ -1091,8 +1113,13 @@ static int handle_tx_event(struct xhci_hcd *xhci, ...@@ -1091,8 +1113,13 @@ static int handle_tx_event(struct xhci_hcd *xhci,
list_del(&td->cancelled_td_list); list_del(&td->cancelled_td_list);
ep_ring->cancels_pending--; ep_ring->cancels_pending--;
} }
/* Leave the TD around for the reset endpoint function to use */ /* Leave the TD around for the reset endpoint function to use
if (GET_COMP_CODE(event->transfer_len) != COMP_STALL) { * (but only if it's not a control endpoint, since we already
* queued the Set TR dequeue pointer command for stalled
* control endpoints).
*/
if (usb_endpoint_xfer_control(&urb->ep->desc) ||
GET_COMP_CODE(event->transfer_len) != COMP_STALL) {
kfree(td); kfree(td);
} }
urb->hcpriv = NULL; urb->hcpriv = NULL;
......
...@@ -589,6 +589,7 @@ struct xhci_ep_ctx { ...@@ -589,6 +589,7 @@ struct xhci_ep_ctx {
*/ */
#define FORCE_EVENT (0x1) #define FORCE_EVENT (0x1)
#define ERROR_COUNT(p) (((p) & 0x3) << 1) #define ERROR_COUNT(p) (((p) & 0x3) << 1)
#define CTX_TO_EP_TYPE(p) (((p) >> 3) & 0x7)
#define EP_TYPE(p) ((p) << 3) #define EP_TYPE(p) ((p) << 3)
#define ISOC_OUT_EP 1 #define ISOC_OUT_EP 1
#define BULK_OUT_EP 2 #define BULK_OUT_EP 2
...@@ -1231,6 +1232,9 @@ void xhci_find_new_dequeue_state(struct xhci_hcd *xhci, ...@@ -1231,6 +1232,9 @@ void xhci_find_new_dequeue_state(struct xhci_hcd *xhci,
void xhci_queue_new_dequeue_state(struct xhci_hcd *xhci, void xhci_queue_new_dequeue_state(struct xhci_hcd *xhci,
struct xhci_ring *ep_ring, unsigned int slot_id, struct xhci_ring *ep_ring, unsigned int slot_id,
unsigned int ep_index, struct xhci_dequeue_state *deq_state); unsigned int ep_index, struct xhci_dequeue_state *deq_state);
void xhci_cleanup_stalled_ring(struct xhci_hcd *xhci,
struct usb_device *udev, struct usb_host_endpoint *ep,
unsigned int ep_index, struct xhci_ring *ep_ring);
/* xHCI roothub code */ /* xHCI roothub code */
int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue, u16 wIndex, int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue, u16 wIndex,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment