Re: [PATCH RFC 1/2] rust: usb: add endpoint abstraction
Greg Kroah-Hartman <[email protected]> Sun, 2 Aug 2026 10:39:47 +0200
| Newsgroups | org.kernel.vger.rust-for-linux,org.kernel.vger.linux-kernel,org.kernel.vger.linux-usb |
|---|---|
| Message-ID | <2026080205-falsify-stalemate-175b@gregkh> |
On Sat, Aug 01, 2026 at 03:01:07AM +0300, Alexandru Radovici wrote: > Add an abstraction for `struct usb_host_endpoint`, together with the > accessors needed to reach one: `AlternateSetting` wrapping > `struct usb_host_interface`, `Interface::alternate_settings()` and > `Interface::current_alternate_setting()`, and `Device::control_endpoint()` > for the default control endpoint, which no interface descriptor lists. Why? USB drivers shouldn't be messing with usb_host_endpoint structures for the most part, what user do you have for this? > `HostEndpoint` is generic over two sealed marker traits, > `EndpointDirection` and `EndpointTransferType`, whose implementors are > 1-ZSTs held in `PhantomData`. An endpoint borrowed from an alternate > setting starts out generic in both; `as_in()`, `as_out()` and > `as_control()` check the descriptor once and return a reference > carrying the corresponding marker, so a function taking > `&HostEndpoint<In, Bulk>` needs no check of its own. The type is > `#[repr(transparent)]` over the C struct and the markers are > zero-sized, so the refinement costs nothing and a slice of endpoints > can be borrowed directly from the C array. > > Control endpoints get a distinct `Bidirectional` marker rather than an > IN or OUT one. A control transfer takes its direction from bit 7 of the > setup packet's bmRequestType, and USB 2.0 section 9.6.6 defines the > corresponding bit of bEndpointAddress as ignored for control endpoints. > `as_in()` and `as_out()` are not implemented for `Bidirectional`, making > calling them a compile error rather than a misleading result. Don't over-think USB endpoints, they are "just" a pipe that contain a numbering scheme that the USB core uses. Is that what you are trying to create here? What are you trying to "enforce" here that the C code does not already do? thanks, greg k-h