Skip to contentSkip to conversation

usb: dwc3: ep0: skip CLEAR_HALT on non-stalled endpoints

PATCH In review Jiazi Liu 2 participants 2 messages Jul 27 – Aug 4

Subsystems (2)
lore
Share & tools
lore

Jiazi Liu

author
#0 lore raw

PATCH 1/1 usb: dwc3: ep0: skip CLEAR_HALT on non-stalled endpoints

Mac hosts send CLEAR_FEATURE(HALT) to all endpoints immediately after SET_CONFIGURATION, even when no endpoint is actually stalled. This causes __dwc3_gadget_ep_set_halt() to be called unnecessarily, which can disrupt ongoing transfers on active endpoints.

Fix this by checking the DWC3_EP_STALL flag before processing CLEAR_FEATURE(HALT). If the endpoint is not stalled, simply acknowledge the host request without calling into the endpoint halt path.

---
 drivers/usb/dwc3/ep0.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/usb/dwc3/ep0.c +3 -0
index bfe616194dfa..b577a1b764fc 100644
@@ -554,6 +554,9 @@ static int dwc3_ep0_handle_endpoint(struct dwc3 *dwc,
 		if (set == 0 && (dep->flags & DWC3_EP_WEDGE))
 			break;
 
+		if (set == 0 && !(dep->flags & DWC3_EP_STALL))
+			break;
+
 		ret = __dwc3_gadget_ep_set_halt(dep, set, true);
 		if (ret)
 			return -EINVAL;
Signature · 1 line
2.50.1 (Apple Git-155)
maintainer
#1 lore raw
Quoted 4 lines · Jiazi Liu

Mac hosts send CLEAR_FEATURE(HALT) to all endpoints immediately after SET_CONFIGURATION, even when no endpoint is actually stalled. This causes __dwc3_gadget_ep_set_halt() to be called unnecessarily, which can disrupt ongoing transfers on active endpoints.

Can you provide more details on what disruptions you saw and on what endpoints (e.g. transfers on endpoints not targeted by this request?)

Quoted 4 lines

Fix this by checking the DWC3_EP_STALL flag before processing CLEAR_FEATURE(HALT). If the endpoint is not stalled, simply acknowledge the host request without calling into the endpoint halt path.

No. We should not do this. Host does ClEAR_FEATURE(HALT) sometime to reset the packet sequence number for various reasons such as error recovery. If we don't also perform set_halt from gadget side, then the data sequence will potentially be out of sync.

BR,
Thinh

Quoted 23 lines
---
 drivers/usb/dwc3/ep0.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/usb/dwc3/ep0.c +3 -0
index bfe616194dfa..b577a1b764fc 100644
@@ -554,6 +554,9 @@ static int dwc3_ep0_handle_endpoint(struct dwc3 *dwc,
 		if (set == 0 && (dep->flags & DWC3_EP_WEDGE))
 			break;
 
+		if (set == 0 && !(dep->flags & DWC3_EP_STALL))
+			break;
+
 		ret = __dwc3_gadget_ep_set_halt(dep, set, true);
 		if (ret)
 			return -EINVAL;
Signature · 1 line
2.50.1 (Apple Git-155)