-
Couldn't load subscription status.
- Fork 8.2k
drivers: udc: disable SOF interrupt by default #88072
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
drivers: udc: disable SOF interrupt by default #88072
Conversation
7550c10 to
9e31ee0
Compare
Could you elaborate on this? |
|
Hi @jfischer-no Could I add one commit in your pr to disable USB_DEVICE_CONFIG_SOF_NOTIFICATIONS based on CONFIG_UDC_ENABLE_SOF for NXP EHCI and IP3511 controller wrapper driver. |
| CONFIG_USBD_AUDIO2_CLASS=y | ||
| CONFIG_UDC_ENABLE_SOF=y |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should the class depend on CONFIG_UDC_ENABLE_SOF? UAC2 cannot work at all without SOF. Changing the default here just makes the actual samples work, but does not prevent in any way configuring an completely not working software.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can add depends on UDC_ENABLE_SOF. I was not sure when I finished the commit. I am thinking about moving the SoF call to be in driver thread context, which could also be meta IRQ or have its own SoF meta IRQ thread, but that needs to be per usbd_context or have its own message queue and is IMO too much. Unfortunately, few drivers use the UDC work queue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't quite think meta IRQ is the way to go. One very important feature of SOF is that if the SW is too late, then all the past work does not really matter (any missed isochronous data is lost forever). The SW has always to worry only what to do within current SOF and the fact how many was missed is not really important.
Using queue for deferring SOF handling allows the queue to become full. I don't think it is about ensuring how fast the queue is handled, but rather about how to avoid the now-obsolete (past deadline) work.
drivers/usb/udc/udc_dwc2.c
Outdated
| IF_ENABLED(CONFIG_UDC_ENABLE_SOF, (USB_DWC2_GINTSTS_SOF |)) | ||
| USB_DWC2_GINTSTS_INCOMPISOOUT | USB_DWC2_GINTSTS_INCOMPISOIN, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isochronous transfers won't work without SOF and therefore there is no point in having INCOMPISOOUT and INCOMPISOIN enabled without SOF.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't quite understand. Will these interrupts be triggered even if SOF is disabled and must not be enabled here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
INCOMPISOIN/INCOMPISOOUT will be triggered if SOF is disabled if an isochronous transfer was scheduled and host did not send the IN or OUT token within first 80% of the (micro-)frame.
Isochronous transfers won't really work on DWC2 without SOF interrupt due to how the scheduling works (even/odd bit) and that this manual reschedule is required from driver.
I will try it very briefly. What started with shim drivers in Zephyr, bad idea, is now some kind of interface to the HAL driver. HAL drivers, code that vendors claim to reuse, but that is not true, because then it would finally be a native driver; use Zephyr primitives, Kconfig options, and enable/disable IRQ in their own or obfuscated way. |
@MarkWangChinese Yes. You can also wait for it to be merged and open a PR to disable interrupts. The driver will not send SoF events anyway, but there will be ISR noise. |
9e31ee0 to
4cc21ef
Compare
4cc21ef to
f2702ad
Compare
|
|
||
| config USBD_AUDIO2_CLASS | ||
| bool "USB Audio 2 class support [EXPERIMENTAL]" | ||
| depends on UDC_ENABLE_SOF |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually select UDC_ENABLE_SOF is better than depends on UDC_ENABLE_SOF because:
- USB Audio 2 class support is then always visible in "New USB device stack" menu
- The requirement is reflected by showing
-*- SOF interrupt processing(can only be disabled if UAC2 is disabled)
With depends on UDC_ENABLE_SOF, disabling SOF interrupt processing disables USB Audio 2 class without any notice to the user.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs to be addressed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed it to 'select' for now, but using 'depends on' is just fine and follows https://docs.zephyrproject.org/latest/build/kconfig/tips.html. We've already experienced a few terrible 'select -> depends on' changes in the past.
173e047 to
0e18cab
Compare
drivers/usb/udc/udc_common.h
Outdated
| * @brief Helper function to store UDC SOF stamp. | ||
| * | ||
| * @param[in] dev Pointer to device struct of the driver instance | ||
| * @param[in] fnumber Frame number |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While for Full-Speed this is enough, the description is insufficient regarding to what value is expected at High-Speed.
Universal Serial Bus Specification Revision 2.0 10.2.3 Frame and Microframe Generation
Host controllers operating with full-speed devices maintain a current frame number (at least 11 bits) that
increments at a 1 ms period. The host transmits the lower 11 bits of the current frame number in each SOF
token transmission.
Host controllers operating with high-speed devices maintain a current microframe number (at least 14 bits)
that increments at a 125 µs period. The host transmits bits 3 through 13 of the current microframe number
in each SOF token transmission. This results in the same SOF packet value being transmitted for eight
consecutive microframes before the SOF packet value increments.
Is the fnumber parameter supposed to be the actual microframe number (i.e. contain the bits 0 through 2, derived by device controller) when operating at High-Speed?
include/zephyr/drivers/usb/udc.h
Outdated
| struct net_buf *setup; | ||
| /** Driver private data */ | ||
| void *priv; | ||
| #if CONFIG_UDC_ENABLE_SOF |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this new functionality be split away from this PR?
subsys/usb/device_next/usbd_core.c
Outdated
| /* | ||
| * Queue the SOF events only if they are from the ISR context. | ||
| * Primarily to avoid message queue flooding from high speed | ||
| * controllers. | ||
| */ | ||
| if (event->type == UDC_EVT_SOF && !k_is_in_isr()) { | ||
| usbd_class_bcast_event(uds_ctx, event); | ||
| return 0; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the real point here? Isn't this just guarding against broken drivers? Shouldn't this be an assert?
|
|
||
| config USBD_AUDIO2_CLASS | ||
| bool "USB Audio 2 class support [EXPERIMENTAL]" | ||
| depends on UDC_ENABLE_SOF |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs to be addressed.
drivers/usb/udc/udc_dwc2.c
Outdated
| } | ||
|
|
||
| if (evt & BIT(DWC2_DRV_EVT_SOF)) { | ||
| udc_update_sof_stamp(dev, priv->sof_num); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't make sense. The timestamp will have a way too big jitter for any practical use.
0e18cab to
ff9c253
Compare
Add helper to handle SOF interrupts/events and new Kconfig option to disable SOF interrupt. Signed-off-by: Johann Fischer <[email protected]>
If the new Kconfig option is disabled, no SOF events are passed to the higher layer. Signed-off-by: Johann Fischer <[email protected]>
ff9c253 to
b3d6234
Compare
|



Add UDC Kconfig option to enable SOF interrupts.
Disable SOF interrupt in drivers that are maintainable and do not obfuscate how interrupts are enabled. If the new Kconfig option is disabled, no SOF events are passed to the higher layer.
Resolves: #87732
I also wanted to address #74058 in the same PR, but that requires more upfront work.