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: device_next: usb3 support #82801

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

josuah
Copy link
Collaborator

@josuah josuah commented Dec 10, 2024

This adds definitions needed for USB3 support.

There is no USB3 controller supported upstream yet. Should I wait to have the driver contributed in the same PR?

Here is the result of USB3CV for a this upcoming driver:
https://josuah.net/paste/rOzDHBjCbAIWO8d4qZu3/Chapter_9_Tests_USB_3_Gen_X_Failed_2024_12_10_08_18_16.html

It fails at SetFeature, as well as re-enumerating as USB2 (but this is related to the driver, not the USB3 handling).
But everything else is passing.

It also runs well with Twister on SuperSpeed configuration:

west twister --platform native_sim --scenario tests/subsys/usb/device_next/usb.device_next --inline-logs
Renaming output directory to /home/tinyvision/zephyrproject/zephyr/twister-out.1
INFO    - Using Ninja..
INFO    - Zephyr version: v4.0.0-1781-gbb86ae133c77
INFO    - Using 'zephyr' toolchain.
INFO    - Building initial testsuite list...
INFO    - Writing JSON report /home/tinyvision/zephyrproject/zephyr/twister-out/testplan.json
INFO    - JOBS: 1
INFO    - Adding tasks to the queue...
INFO    - Added initial list of jobs to queue
INFO    - Total complete:    1/   1  100%  built (not run):    0, filtered:    0, failed:    0, error:    0
INFO    - 1 test scenarios (1 configurations) selected, 0 configurations filtered (0 by static filter, 0 at runtime).
INFO    - 1 of 1 executed test configurations passed (100.00%), 0 built (not run), 0 failed, 0 errored, with no warnings in 25.02 seconds.
INFO    - 2 of 2 executed test cases passed (100.00%) on 1 out of total 880 platforms (0.11%).
INFO    - 1 test configurations executed on platforms, 0 test configurations were only built.
INFO    - Saving reports...
INFO    - Writing JSON report /home/tinyvision/zephyrproject/zephyr/twister-out/twister.json
INFO    - Writing xunit report /home/tinyvision/zephyrproject/zephyr/twister-out/twister.xml...
INFO    - Writing xunit report /home/tinyvision/zephyrproject/zephyr/twister-out/twister_report.xml...
INFO    - Run completed

@josuah josuah added the Experimental Experimental features not enabled by default label Dec 10, 2024
@zephyrbot zephyrbot added the area: USB Universal Serial Bus label Dec 10, 2024
@josuah josuah force-pushed the pr-usb3 branch 2 times, most recently from 74d2fa4 to d5fda25 Compare December 10, 2024 18:10
@josuah
Copy link
Collaborator Author

josuah commented Dec 10, 2024

force-push:

  • CI fixes
  • doc fixes

@@ -36,6 +37,8 @@ enum udc_mps0 {
struct udc_device_caps {
/** USB high speed capable controller */
uint32_t hs : 1;
/** USB high speed capable controller */
Copy link
Member

Choose a reason for hiding this comment

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

Copy and paste typo here. Should be "super" rather than "high"

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good catch, thank you!

@josuah
Copy link
Collaborator Author

josuah commented Dec 19, 2024

force-push:

  • Fix a typo for the udc caps struct
  • Add SET_ISOCH_DELAY as a no-op, as the host informs the device of an end-to-end delay observed, not used at this stage, but it might help with compliance to support it even if it does nothing.

@josuah
Copy link
Collaborator Author

josuah commented Dec 19, 2024

The USB3 driver in question is soon to be contributed, and the implementation lives here in the meantime:

Copy link
Contributor

@tmon-nordic tmon-nordic left a comment

Choose a reason for hiding this comment

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

The fact that Super-Speed requires bulk endpoints wMaxPacketSize to be 1024 makes #76255 even more important

@@ -41,6 +42,13 @@ struct usb_bos_capability_lpm {
uint32_t bmAttributes;
} __packed;

/** Fields for @ref usb_bos_capability_lpm bmAttributes */
Copy link
Contributor

Choose a reason for hiding this comment

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

LPM is for USB 2.0 EXTENSION capability descriptor and LTM is for SUPERSPEED USB capability descriptor. Please do not mix different bmAttributes bits in single enum.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I adjusted this in the latest commits, thank you!

* device can configure the hardware to match what is on the host.
* That way, both side of the session have the same properties.
*/
struct udc_exit_latency {
Copy link
Contributor

Choose a reason for hiding this comment

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

The specification refers to these as "System Exit Latency". udc_exit_latency seems to suggests it is some software construct and not a standard requirement. Not sure what would be a better name though.

Copy link
Collaborator Author

@josuah josuah Jan 11, 2025

Choose a reason for hiding this comment

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

Good point. It is a packed struct defined by the standard (chapter 9 of USB3 too), so could go to the USB headers rather than UDC ones.
scrot_20250111_135633_1422x684

#define USB_SREQ_SET_WUSB_DATA 0x14
#define USB_SREQ_LOOPBACK_DATA_WRITE 0x15
#define USB_SREQ_LOOPBACK_DATA_READ 0x16
#define USB_SREQ_SET_INTERFACE_DS 0x17
Copy link
Contributor

Choose a reason for hiding this comment

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

What about GET_FW_STATUS and SET_FW_STATUS?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I found something for the link layers: [UCSI]
scrot_20250111_185848_1042x284

I found something for the Type-C Power Delivery (alternative to DFU) [PDFU]
scrot_20250111_190538_1282x465

But nothing about GET_FW_UPDATE itself... Any hint?

Copy link
Contributor

Choose a reason for hiding this comment

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

Get USB 3.2 Revision 1.1 Specification from https://www.usb.org/document-library/usb-32-revision-11-june-2022

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I had the 2017 version somehow. Thank you!

@@ -121,6 +135,7 @@ static inline bool usb_reqtype_is_to_device(const struct usb_setup_packet *setup
#define USB_DESC_INTERFACE_ASSOC 11
#define USB_DESC_BOS 15
#define USB_DESC_DEVICE_CAPABILITY 16
#define USB_DESC_ENDPOINT_COMPANION 48
Copy link
Contributor

Choose a reason for hiding this comment

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

There is also SUPERSPEEDPLUS_ISOCHRONOUS_ENDPOINT_COMPANION

Copy link
Collaborator Author

@josuah josuah Jan 11, 2025

Choose a reason for hiding this comment

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

That makes sense, SuperSpeed Plus devices using an RTOS are already on the market (but chips not available yet).

I might also need to add the structs for it then...

@@ -248,6 +263,15 @@ struct usb_association_descriptor {
uint8_t iFunction;
} __packed;

/** USB Endpoint Companion Descriptor defined in USB3 spec. Table 9-27. */
struct usb_co_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 would go with usb_ss_endpoint_companion_descriptor.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I did not dare to break the regularity of every class.

https://github.com/zephyrproject-rtos/zephyr/blob/5750b720b37a8756a8578eae319a9c0e3f0fe1df/subsys/usb/device_next/class/loopback.c#L34-L64

Should that be usb_ss_ep_companion_descriptor for consistency with usb_ep_descriptor?

I am applying usb_ss_endpoint_companion_descriptor currently...

Copy link
Collaborator Author

@josuah josuah Jan 11, 2025

Choose a reason for hiding this comment

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

I also renamed if..._ss_..._co to if..._ss_..._ep_co.

@josuah josuah force-pushed the pr-usb3 branch 2 times, most recently from 74cf9e3 to 7249333 Compare January 11, 2025 18:10
@josuah
Copy link
Collaborator Author

josuah commented Jan 11, 2025

force-push:

  • Renamed udc_exit_latency into usb_system_exit_latency and moved it to usb_ch9.h
  • Added USB3 SuperSpeedPlus capability descriptor (untested)
  • Added USB_BOS_CAPABILITY_PRECISION_TIME_MEASUREMENT
  • Renamed and moved capabilities as requested.
  • Wording, and section number typo fixups

SuperSpeedPlus still lacks other modifications to be enabled: everywhere SuperSpeed (SS) is introduced, SuperSpeedPlus (SSP) needs to be introduced as well.

@josuah
Copy link
Collaborator Author

josuah commented Jan 11, 2025

The fact that Super-Speed requires bulk endpoints wMaxPacketSize to be 1024 makes #76255 even more important

Here is what this PR it looks like on top of #76255:
tmon-nordic/zephyr@max-speed...tinyvision-ai-inc:zephyr:pr-usb3-max-speed

I thought it would be more suited to wait #76255 to be rebased before force-pushing this here.
Thank you for this review, and thanks all for this long-term maintenance effort of the new USB stack!

@josuah
Copy link
Collaborator Author

josuah commented Jan 13, 2025

force-push:

Introduce definitions to enable USB3 device controllers to be written.
The USB3 support got added to the core implementaiton, and to the Loopback
and CDC-ACM class only.

Signed-off-by: Josuah Demangeon <me@josuah.net>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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