diff mbox series

[3/3] xhci: Always restore EP_SOFT_CLEAR_TOGGLE even if ep reset failed

Message ID 20200821091549.20556-4-mathias.nyman@linux.intel.com (mailing list archive)
State Mainlined
Commit f1ec7ae6c9f8c016db320e204cb519a1da1581b8
Headers show
Series xhci fixes for usb-linus | expand

Commit Message

Mathias Nyman Aug. 21, 2020, 9:15 a.m. UTC
From: Ding Hui <dinghui@sangfor.com.cn>

Some device drivers call libusb_clear_halt when target ep queue
is not empty. (eg. spice client connected to qemu for usb redir)

Before commit f5249461b504 ("xhci: Clear the host side toggle
manually when endpoint is soft reset"), that works well.
But now, we got the error log:

    EP not empty, refuse reset

xhci_endpoint_reset failed and left ep_state's EP_SOFT_CLEAR_TOGGLE
bit still set

So all the subsequent urb sumbits to the ep will fail with the
warn log:

    Can't enqueue URB while manually clearing toggle

We need to clear ep_state EP_SOFT_CLEAR_TOGGLE bit after
xhci_endpoint_reset, even if it failed.

Fixes: f5249461b504 ("xhci: Clear the host side toggle manually when endpoint is soft reset"
Cc: stable <stable@vger.kernel.org> # v4.17+
Signed-off-by: Ding Hui <dinghui@sangfor.com.cn>
Signed-off-by: Mathias Nyman <mathias.nyman@linux.intel.com>
---
 drivers/usb/host/xhci.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Comments

Greg KH Aug. 23, 2020, 3:12 p.m. UTC | #1
On Fri, Aug 21, 2020 at 12:15:49PM +0300, Mathias Nyman wrote:
> From: Ding Hui <dinghui@sangfor.com.cn>
> 
> Some device drivers call libusb_clear_halt when target ep queue
> is not empty. (eg. spice client connected to qemu for usb redir)
> 
> Before commit f5249461b504 ("xhci: Clear the host side toggle
> manually when endpoint is soft reset"), that works well.
> But now, we got the error log:
> 
>     EP not empty, refuse reset
> 
> xhci_endpoint_reset failed and left ep_state's EP_SOFT_CLEAR_TOGGLE
> bit still set
> 
> So all the subsequent urb sumbits to the ep will fail with the
> warn log:
> 
>     Can't enqueue URB while manually clearing toggle
> 
> We need to clear ep_state EP_SOFT_CLEAR_TOGGLE bit after
> xhci_endpoint_reset, even if it failed.
> 
> Fixes: f5249461b504 ("xhci: Clear the host side toggle manually when endpoint is soft reset"

Nit, you forgot the trailing ')' here...
Mathias Nyman Aug. 24, 2020, 10:26 a.m. UTC | #2
On 23.8.2020 18.12, Greg KH wrote:
> On Fri, Aug 21, 2020 at 12:15:49PM +0300, Mathias Nyman wrote:
>> From: Ding Hui <dinghui@sangfor.com.cn>
>>
>> Some device drivers call libusb_clear_halt when target ep queue
>> is not empty. (eg. spice client connected to qemu for usb redir)
>>
>> Before commit f5249461b504 ("xhci: Clear the host side toggle
>> manually when endpoint is soft reset"), that works well.
>> But now, we got the error log:
>>
>>     EP not empty, refuse reset
>>
>> xhci_endpoint_reset failed and left ep_state's EP_SOFT_CLEAR_TOGGLE
>> bit still set
>>
>> So all the subsequent urb sumbits to the ep will fail with the
>> warn log:
>>
>>     Can't enqueue URB while manually clearing toggle
>>
>> We need to clear ep_state EP_SOFT_CLEAR_TOGGLE bit after
>> xhci_endpoint_reset, even if it failed.
>>
>> Fixes: f5249461b504 ("xhci: Clear the host side toggle manually when endpoint is soft reset"
> 
> Nit, you forgot the trailing ')' here...
> 

Argh, I had one job.. 
Odd that checkpatch didn't catch that.
Thanks for fixing and applying

-Mathias
diff mbox series

Patch

diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c
index 3c41b14ecce7..e9884ae9c77d 100644
--- a/drivers/usb/host/xhci.c
+++ b/drivers/usb/host/xhci.c
@@ -3236,10 +3236,11 @@  static void xhci_endpoint_reset(struct usb_hcd *hcd,
 
 	wait_for_completion(cfg_cmd->completion);
 
-	ep->ep_state &= ~EP_SOFT_CLEAR_TOGGLE;
 	xhci_free_command(xhci, cfg_cmd);
 cleanup:
 	xhci_free_command(xhci, stop_cmd);
+	if (ep->ep_state & EP_SOFT_CLEAR_TOGGLE)
+		ep->ep_state &= ~EP_SOFT_CLEAR_TOGGLE;
 }
 
 static int xhci_check_streams_endpoint(struct xhci_hcd *xhci,