Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

usb: usbip: add initial support for USBIP server #74141

Open
wants to merge 18 commits into
base: main
Choose a base branch
from

Conversation

jfischer-no
Copy link
Collaborator

@jfischer-no jfischer-no commented Jun 12, 2024

The server uses minimal host support to export a USB device to a remote
USBIP client. It supports control and bulk transfers, interrupt
transfers may also work, but this depends on the host controller used.
Only a single USB device can be exported yet.

@jfischer-no jfischer-no added area: USB Universal Serial Bus Experimental Experimental features not enabled by default labels Jun 12, 2024
@jfischer-no jfischer-no self-assigned this Jun 12, 2024
drivers/usb/uhc/uhc_virtual.c Outdated Show resolved Hide resolved
*
* SPDX-License-Identifier: Apache-2.0
*/

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file is missing include guards.

@github-actions github-actions bot added the Stale label Aug 17, 2024
@jfischer-no jfischer-no removed the Stale label Aug 19, 2024
@zephyrproject-rtos zephyrproject-rtos deleted a comment from github-actions bot Aug 19, 2024
@github-actions github-actions bot added the Stale label Oct 19, 2024
@jfischer-no jfischer-no removed the Stale label Oct 21, 2024
@zephyrproject-rtos zephyrproject-rtos deleted a comment from github-actions bot Oct 21, 2024
@github-actions github-actions bot added the Stale label Dec 21, 2024
@github-actions github-actions bot closed this Jan 5, 2025
@jfischer-no jfischer-no reopened this Jan 6, 2025
@zephyrproject-rtos zephyrproject-rtos deleted a comment from github-actions bot Jan 6, 2025
@jfischer-no jfischer-no removed the Stale label Jan 6, 2025
@jfischer-no jfischer-no force-pushed the pr-uhc-usbip-initial branch 3 times, most recently from d123ee7 to 01328a1 Compare January 6, 2025 16:16
This allows us to use the testusb Linux kernel tool again. All tests
involving control and bulk transfers should pass. Additionally, add a
shell command that allows the user to manually enqueue bulk transfers.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
Lock the scheduler until the device is fully enabled, similar to
usbd_init();

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
Do not necessarily call k_timer_init() in the uhc_bus_resume()
implementation. Restart SOF timer after bus reset and in
uhc_sof_enable() implementation.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
The parameter should not be a pointer to type usbh_udev_cb_t.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
Implement the dequeue function and remove the timeout parameter as it is
no longer necessary and can be handled in the upper layer. The dequeue
function is required for the USBIP implementation.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
With the current implementation, NACK claims all resources and prevents
scheduling multiple transfers within a frame. Place a number of
available transfers in a list at the beginning of a frame, and process
the transfers in a limited number of slots.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
@jfischer-no jfischer-no added this to the v4.1.0 milestone Jan 17, 2025
This will allow the controller driver to access information about the
device in the future.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
Address parameter/argument is no longer needed because we have a pointer
to the USB device. The Attrib parameter has never been used and will be
replaced by the interval and start-frame parameters in the future.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
Add interrupt and start frame parameters and schedule transaction at
specific frame. Implement for virtual driver only.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
Add an opaque pointer to store upper layer private data and initialize
it with the USB host context during controller initialization. Use the
pointer in event processing to get the correct context.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
The transfers require enpoint MPS for proper transaction handling,
assign it in the common place during transfer allsocation so that it can
be reused.
Some users, such as USBIP, may need to keep a reference to private data,
add a parameter for completion callback data.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
Handle them in separate contexts so that the request completion callback
cannot be blocked, such as when a device connection is detected and
requires configuration.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
Allow dynamic allocation of USB devices on connected event.
Add very basic USB device validation and configuration.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
The server uses host support to export a USB device to a remote
USBIP client. It supports control and bulk transfers, interrupt
transfers may also work, but this depends on the host controller used.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
Snippet that helps to build USB device samples with virtual device and
host controllers and USBIP support.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
Add initial USB/IP documentation for the new USB support.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
@raveious
Copy link
Contributor

If you don't mind me asking, what environment(s) did you test this on? I'm very interested in this and would like to try and replicate the results.

struct usb_device_descriptor *const desc)
{
const uint8_t type = USB_DESC_DEVICE;
const uint16_t wLength = sizeof(struct usb_device_descriptor);
const uint16_t wLength = MIN(len, sizeof(struct usb_device_descriptor));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand this commit at all. If the only place where usbh_req_desc_dev() is called, calls this with sizeof(struct usb_device_descriptor) then this does not change anything at all.

The whole thing with bMaxPacketSize0 can be solved by just explicitly reading 8 bytes first. This will always result in single data stage packet regardless of bMaxPacketSize0. Then the stack can remember the bMaxPacketSize0 and handle futher communication without having to guess "was it a short packet, or is bMaxPacketSize0 8".

goto xfer_alloc_error;
}

mps = ep_desc->wMaxPacketSize;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How is ep_desc stored in memory? If it has bytes as-is in the descriptor, then this is missing endian conversion.

@ddavidebor
Copy link

I just want to put forward a huge thank you to @jfischer-no for your work on this! I'm really excited and looking forward to this being merged

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: Build System area: USB Universal Serial Bus Experimental Experimental features not enabled by default
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants