Skip to content

xHCI: endpoint state maintainability and small fixes

Michal Pecio linux-usb lkml 1 version In review

Get series with b4
b4 am 20250310093605.2b3d0425@foxbook

Versions newest first

  1. v1 Latest6 patches 7 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/6usb: xhci: Document endpoint state managementdrivers/usb/host/xhci.h+31 -131 reply
2/6usb: xhci: Deduplicate some endpoint state flag listsdrivers/usb/host/xhci-ring.c drivers/usb/host/xhci.c drivers/usb/host/xhci.h+28 -142 replies
3/6usb: xhci: Only set EP_HARD_CLEAR_TOGGLE after queuing Reset Endpointdrivers/usb/host/xhci-ring.c+2 -10 replies
4/6usb: xhci: Don't change the status of stalled TDs on failed Stop EPdrivers/usb/host/xhci-ring.c+11 -11 reply
5/6usb: xhci: Avoid Stop Endpoint retry loop if the endpoint seems Runningdrivers/usb/host/xhci-ring.c+7 -40 replies
6/6usb: xhci: Update comments about Stop Endpoint racesdrivers/usb/host/xhci-ring.c+39 -310 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.

Read the v1 thread

Cover letter [PATCH 0/6] xHCI: endpoint state maintainability and small fixes

These patches are mostly independent, except
- 2/6 depends on 1/6
- 6/6 depends on 4/5 and 5/6

It is assumed that issues with EP_STALLED are resolved like below.

They document assumptions currently made by xhci_urb_dequeue() and xhci_handle_cmd_stop_ep() and clean up this code a little to make it more maintainable.

Some potential issues with no known significant impact are fixed. I haven't tagged them for stable. Maybe 5/6 could go, just in case?

Michal

drivers/usb/host/xhci.c +6 -2
@@ -1770,7 +1770,7 @@ static int xhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
 	}
 
 	/* In this case no commands are pending but the endpoint is stopped */
-	if (ep->ep_state & EP_CLEARING_TT) {
+	if (ep->ep_state & (EP_CLEARING_TT | EP_STALLED)) {
 		/* and cancelled TDs can be given back right away */
 		xhci_dbg(xhci, "Invalidating TDs instantly on slot %d ep %d in state 0x%x\n",
 				urb->dev->slot_id, ep_index, ep->ep_state);
@@ -3207,10 +3207,14 @@ static void xhci_endpoint_reset(struct usb_hcd *hcd,
 		return;
 
 	ep = &vdev->eps[ep_index];
+
+	spin_lock_irqsave(&xhci->lock, flags);
+
+	/* Unblock the endpoint as device side is unstalled now */
 	ep->ep_state &= ~EP_STALLED;
+	xhci_ring_doorbell_for_active_rings(xhci, udev->slot_id, ep_index);
 
 	/* Bail out if toggle is already being cleared by a endpoint reset */
-	spin_lock_irqsave(&xhci->lock, flags);
 	if (ep->ep_state & EP_HARD_CLEAR_TOGGLE) {
 		ep->ep_state &= ~EP_HARD_CLEAR_TOGGLE;
 		spin_unlock_irqrestore(&xhci->lock, flags);

Michal Pecio (6):
usb: xhci: Document endpoint state management
usb: xhci: Deduplicate some endpoint state flag lists
usb: xhci: Only set EP_HARD_CLEAR_TOGGLE after queuing Reset Endpoint
usb: xhci: Don't change the status of stalled TDs on failed Stop EP
usb: xhci: Avoid Stop Endpoint retry loop if the endpoint seems
Running
usb: xhci: Update comments about Stop Endpoint races

 drivers/usb/host/xhci-ring.c | 102 ++++++++++++++++++++---------------
 drivers/usb/host/xhci.c      |  16 ++++--
 drivers/usb/host/xhci.h      |  58 +++++++++++++++-----
 3 files changed, 115 insertions(+), 61 deletions(-)
Signature · 1 line
2.48.1