From e189769e478dd16c8ca4c4133943bd7032a09c22 Mon Sep 17 00:00:00 2001 From: Hemant Kumar Date: Thu, 20 Jun 2019 18:14:54 -0700 Subject: [PATCH] usb: dwc3: Stop active transfer on control endpoints If cable disconnects before data stage completion dwc3_remove_requests() gets called for ep0 in and out but dwc3_ep0_complete_data() does not get called. dwc3_ep0_complete_data() function resets TRB enqueue count to 0. As a result upon next cable connect start transfer is called with wrong TRB address because trb_enqueue is set to 1. Since this TRB was completed in the past, HWO bit is cleared for this TRB. This results into usb enumeration failure due to control transfer stall. Fix this issue by issuing end transfer command on control endpoints after ep0 requests are removed for IN and OUT and reset trb_enqueue counters to 0. Change-Id: Ic5364f11372d85ec7c133024dc48bbc5d848ebf4 Signed-off-by: Hemant Kumar Signed-off-by: Jack Pham --- drivers/usb/dwc3/gadget.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c index b0672c299a00..f2b4b53866a8 100644 --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c @@ -821,6 +821,22 @@ static void dwc3_remove_requests(struct dwc3 *dwc, struct dwc3_ep *dep) dwc3_gadget_giveback(dep, req, -ESHUTDOWN); } + + if (dep->number == 1 && dwc->ep0state != EP0_SETUP_PHASE) { + unsigned int dir; + + dbg_log_string("CTRLPEND", dwc->ep0state); + dir = !!dwc->ep0_expect_in; + if (dwc->ep0state == EP0_DATA_PHASE) + dwc3_ep0_end_control_data(dwc, dwc->eps[dir]); + else + dwc3_ep0_end_control_data(dwc, dwc->eps[!dir]); + + dwc->eps[0]->trb_enqueue = 0; + dwc->eps[1]->trb_enqueue = 0; + } + + dbg_log_string("DONE for %s(%d)", dep->name, dep->number); } /**