From: Thinh Nguyen <Thinh.Nguyen@synopsys.com>
To: "Michał Pecio" <michal.pecio@gmail.com>
Cc: "linux-usb@vger.kernel.org" <linux-usb@vger.kernel.org>,
Mathias Nyman <mathias.nyman@linux.intel.com>,
Alan Stern <stern@rowland.harvard.edu>
Subject: Re: How are halted endpoints supposed to be handled in Linux?
Date: Thu, 21 Nov 2024 00:02:19 +0000 [thread overview]
Message-ID: <20241121000216.kif557p3p6xyahax@synopsys.com> (raw)
In-Reply-To: <20241121001138.23a45f6c@foxbook>
++Alan
Hi,
On Thu, Nov 21, 2024, Michał Pecio wrote:
> Hi,
>
> I have been wondering about it after seeing how it's done in xhci_hcd,
> which looks wrong to me.
>
> USB 2.0 spec 5.7.5/5.8.5 states that halt condition due to either STALL
> handshake or "transmission error" should cause both the device and host
> endpoints to be reset. I presume "transmission error" means any error
> detected by the HC which causes it to halt, various examples exist.
>
> USB 3.0 just refers to USB 2.0.
>
> Linux appears to ignore this part and only reset on STALL handshake, as
> advised in Documentation/driver-api/usb/error-codes.rst and practiced
> by drivers - they don't seem to bother with usb_clear_halt() on -EPROTO.
> This wouldn't necessarily be bad in itself, but:
>
> On the HCD side, xHCI will:
> - give back the current URB with -EPROTO/-EPIPE status
> - reset the host side endpoint, clearing its toggle state
> - point the HC at the next URB if one exist
> - restart the endpoint without waiting for hcd->endpoint_reset()
> - ignore one subsequent call to hcd->endpoint_reset()
>
> For STALL, I think it's a little awkward, but acceptable. The ultimate
> result appears to be that all pending URBs are given back with -EPIPE
> and things start moving again after usb_clear_halt().
>
> But if the device isn't stalled, the next URB may execute right away if
> the failure was transient. This makes it impossible to ensure in-order
> delivery on bulk OUT pipes, because one URB is skipped and the driver
> has no reliable way to retry it before some later ones may get executed.
The class driver will know of this error, and the retry/recovery should
be done at the class driver base on this error and not from the HCD.
>
> This behavior also creates an opportunity for toggle mismatch, and as
> far as I understand, the hardware will resolve it by silently dropping
> one packet. Another could be dropped if usb_clear_halt() were called.
>
>
> Either I'm missing something, or it seems quite broken?
>
> I wonder what other HCDs are doing in this case, and what's the idea
> behind it all?
>
> Regards,
> Michal
>
This long discussion may be relevant to your query:
https://lore.kernel.org/linux-usb/ba06679f-93d2-4cb4-9218-9e288065bdfb@rowland.harvard.edu/#t
The concensus is that these error recovery should be handled by the
class drivers. How they should be handled may be different between
different OSes. If you follow the thread discussion, it may not
necessarily a good idea to use usb_clear_halt() to recover.
BR,
Thinh
next prev parent reply other threads:[~2024-11-21 0:02 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-20 23:11 How are halted endpoints supposed to be handled in Linux? Michał Pecio
2024-11-21 0:02 ` Thinh Nguyen [this message]
2024-11-21 2:31 ` Alan Stern
2024-11-21 10:26 ` Michał Pecio
2024-11-21 14:08 ` Mathias Nyman
2024-11-22 11:54 ` Michał Pecio
2024-11-21 15:06 ` Alan Stern
2024-11-22 12:57 ` Michał Pecio
2024-11-22 19:28 ` Alan Stern
2024-11-22 23:25 ` Michał Pecio
2024-11-23 2:39 ` Alan Stern
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20241121000216.kif557p3p6xyahax@synopsys.com \
--to=thinh.nguyen@synopsys.com \
--cc=linux-usb@vger.kernel.org \
--cc=mathias.nyman@linux.intel.com \
--cc=michal.pecio@gmail.com \
--cc=stern@rowland.harvard.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox