Skip to content

USB: notifications overhaul #51034

@carlescufi

Description

@carlescufi

USB notifications currently use callbacks. This issue is to document the requirements of USB notifications to be able to decide which mechanism to use in the new, overhauled USB support (both Device and Host).

Notification examples/types:

  • Device connected to Vbus (presence of voltage in Vbus). Could then trigger power management logic
  • Device is configured
  • Device is suspended
  • Device is resumed
  • Class-specific notifications
    • Interface active (eg. network interface up)
    • CDC ACM line state change request arrived from the Host (even if the line state itself doesn't change)
    • Audio stream started

High-frequency events such as SoF are not going through this notification mechanism.
Data itself is not going through the notification mechanism.
Notifications are purely informational: i.e. they are not designed to ask the user/app for a response to be included in a response packet to a request packet from the USB Host. Those instead will go through the class-specific synchronous internal callback API.

Requirements of USB notifications:

  • Intended only for USB users/clients. USB classes (including custom ones) use a synchronous internal callback API
  • Intended only for notification purposes, not as a mechanism to execute any action that then maps to a "response packet over the wire"
  • One-way notifications
  • Pub/sub: Multiple listener/observer support
  • Common publishing mechanism for class implementations as well as core USB stack notifications
  • Execution in a context that does not impact the USB functionality
  • Try to avoid immediate context-switch upon posting of a notification, instead the USB stack should be able to enqueue multiple notifications without being swapped out, and then the thread/context that processes the notifications and invokes the listeners gets to run
  • Notifications shall not be dropped/lost (except potentially isochronous ones). Instead, the USB stack should block/NAK or error out (depending on which decision is taken wrt the synchronicity) if the event "slots" run out. Once the app has processed an event and freed it, the host can proceed.

Options available:

~~a. Traditional synchronous callbacks

  • Block the USB stack execution until the notification has been acknowledged (i.e. callback returns)
  • Called always from the same context (never from ISR or driver thread): the main USB context~~

b. Traditional callbacks, with the following provisions in order to fulfill the requirements:

  • Callback registration both at compile-time (i.e. places the callback in a linker sections) and runtime (i.e. the linker section is extended with a linked list in RAM)
  • Dedicated workqueue/thread/context to execute the callbacks
  • Linked List of events instead of FIFO to avoid rescheduling
  • Potentially configurable execution context (dedicated workqueue, user-supplied workqueue or even other mechanisms)

c. An event manager/bus

CC @desowin @anangl @gmarull

Metadata

Metadata

Assignees

Labels

EnhancementChanges/Updates/Additions to existing featuresarea: USBUniversal Serial Bus

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions