usb: gadget: f_fs: Add R/W proxy EPs and ZLP support
Get series with b4
b4 am [email protected]Versions newest first · linked by author and title
- v2 Latest4 patches 0 repliesNew
- v13 patches 5 repliesSuperseded
Changes in v2 from the cover letter
- Added Cc: stable... tag to epfile-in early initialization bugfix
- Added Tie read_buffer lifetime to ffs_epfile bugfix change to address read buffer lifecycle
- Removed 'opened_count' and associated logic to track file open/close
- Reduced name char array from 10 to 8 to match size required
- Updated coverletter to reflect above
---
Patches in v2 No applies recorded yet
| # | Subject and files | Size | Replies | Applied |
|---|---|---|---|---|
| 1/4 | usb: gadget: f_fs: Initialize epfile->in early to fix endpoint direction checksdrivers/ | +1 | 0 replies | |
| 2/4 | usb: gadget: f_fs: Tie read_buffer lifetime to ffs_epfiledrivers/ | +1 | 0 replies | |
| 3/4 | usb: gadget: f_fs: Add zero-length packet ioctlDocumentation/ drivers/ include/ | +71 | 0 replies | |
| 4/4 | usb: gadget: f_fs: Introduce rw_proxy file descriptorsDocumentation/ drivers/ drivers/ +1 more | +136 | 0 replies |
Reviews trailers per patch
No Reviewed-by, Acked-by or Tested-by trailers for v2 yet.
Cover letter [PATCH v2 0/4] usb: gadget: f_fs: Add R/W proxy EPs and ZLP support
We are working to deprecate a widely used, out of tree gadget driver by moving the functionality to userspace via functionfs. To do so, we have to maintain strict compatibility with the legacy driver, as there are many third party applications which can’t be modified and are reliant on this interface. Specifically, the following requirements must be met:
- The function must expose a single file descriptor to userspace for both reads and writes,
- It must block on writes when it can not handle more data,
- It must handle arbitrary write transaction sizes,
- It must automatically append a zero length packet (ZLP) when the write transaction ends on a boundary of a multiple of the max packet size.
Initially, we pursued a compatibility layer in userspace which implemented a socket pair to combine the OUT and IN endpoint files. This approach proved problematic for several reasons.
To preserve the write transaction boundary for ZLP calculation, we attempted to use SOCK_SEQPACKET. This created problems as larger transactions required contiguous buffers to be allocated, and, even if we ignore the constraint to the arbitrary write size and limited it to 1MB, the socket would occasionally return -ENOBUFS to the end user if a write operation was attempted when other sockets on the system were consuming more than 7MB of the 8MB wmem_max limit.
After significant investigation including switching to SOCK_STREAM and attempting a heuristic timeout approach, we decided the best path forward was to pursue a native proxy endpoint approach in the functionfs driver itself.
This patchset introduces the FUNCTIONFS_RW_PROXY_EPS flag to functionfs which, when set, creates an additional proxy file for reading or writing to a pair of endpoints. In an attempt to limit the change to the UAPI surface, we added several constraints to this proxy file. We chose not to handle ioctls on this proxy file, as the current ioctls do not have a directionality associated with them, and would require essentially creating duplicate ioctls with a direction argument. To use this flag, an even number of in/out endpoints must be created, and a proxy ep is created for each pair of endpoints in the descriptors.
With this new r/w proxy ep, we are able to transparently hand it to the end application. However, to match the legacy driver’s ZLP functionality, a new ioctl is added, FUNCTIONFS_ENDPOINT_ENABLE_ZLP. This allows the userspace functionfs daemon to write the necessary descriptors, configure the auto ZLP functionality on the IN EP, then handoff the proxy ep to the application. When enabled, functionfs sets the req->zero flag. The UDC driver then automatically adds the ZLP if the transaction length % max packet size is 0.
An addition, several bugfix patches are added.
- A patch which fixes an issue if certain ioctls (like the new FUNCTIONFS_ENDPOINT_ENABLE_ZLP or FUNCTIONFS_DMABUF_ATTACH) are called prior to the host being connected.
- A patch which moves the read buffer lifecyle from ffs_epfile_release() to ffs_epfiles_destroy, fixing an issue where ep's which have been opened() more than once free the read buffer with the first closure.
This patchset has been tested on a kernel based on 7.1-rc7, as well as a backported version tested on 6.1. Existing functionfs implementations continue to work without modification, and the new functionality passes tests designed for our legacy kernel driver implementation.
---
Changes in V2:
- Added Cc: stable... tag to epfile-in early initialization bugfix
- Added Tie read_buffer lifetime to ffs_epfile bugfix change to address read buffer lifecycle
- Removed 'opened_count' and associated logic to track file open/close
- Reduced name char array from 10 to 8 to match size required
- Updated coverletter to reflect above
---
Neill Kapron (4):
usb: gadget: f_fs: Initialize epfile->in early to fix endpoint
direction checks
usb: gadget: f_fs: Tie read_buffer lifetime to ffs_epfile
usb: gadget: f_fs: Add zero-length packet ioctl
usb: gadget: f_fs: Introduce rw_proxy file descriptors
Documentation/usb/functionfs.rst | 80 ++++++++++++++++++++ drivers/usb/gadget/function/f_fs.c | 112 ++++++++++++++++++++++++---- drivers/usb/gadget/function/u_fs.h | 8 +- include/uapi/linux/usb/functionfs.h | 24 ++++++ 4 files changed, 207 insertions(+), 17 deletions(-)
Signature · 1 line
2.54.0.1136.gdb2ca164c4-goog