Repository navigation
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
The FIFO prefilter can admit streams that exceed their allocated capacity and cause silent audio corruption, while rate-only refinement can accept unsupported sample rates.
2 open issues
What changed in this PR
Enables USB audio offload on Intel Lunar Lake and newer platforms, allowing the SOF DSP to stream through xHCI Audio Sideband while snd-usb-audio retains device ownership.
Changes:
- Adds xHCI sideband resource management and USB audio offload ownership APIs.
- Integrates SOF UAOL streams, feedback DMA, device constraints, suspend/resume handling, and per-stream route controls.
- Adds machine-driver integration, build configuration, documentation, and 384-kHz stream-format support.
| File | Description |
|---|---|
sound/usb/quirks.c |
Exports format quirks for offload use. |
sound/usb/pcm.h |
Declares substream claim/release APIs. |
sound/usb/pcm.c |
Adds exclusive substream claims and propagates endpoint errors. |
sound/usb/offload/offload.h |
Defines internal offload context and bridge interfaces. |
sound/usb/offload/Makefile |
Builds the offload library. |
sound/usb/offload/Kconfig |
Adds offload library configuration. |
sound/usb/offload/init.c |
Implements registration, notifications, and resource placement callbacks. |
sound/usb/Makefile |
Includes the offload build directory. |
sound/usb/Kconfig |
Includes offload configuration. |
sound/usb/endpoint.h |
Declares endpoint ownership APIs. |
sound/usb/endpoint.c |
Prevents host sharing of offloaded endpoints. |
sound/usb/card.h |
Adds ownership state and platform-release declaration. |
sound/usb/card.c |
Disconnects tracked devices before releasing platform operations. |
sound/soc/sof/topology.c |
Recognizes the UAOL DAI type. |
sound/soc/sof/sof-priv.h |
Adds machine-parameter finalization callback. |
sound/soc/sof/ipc4-topology.h |
Defines UAOL gateway configuration and stream mapping. |
sound/soc/sof/ipc4-topology.c |
Configures UAOL FIFOs and refreshes gateway data. |
sound/soc/sof/ipc4-priv.h |
Stores firmware UAOL support and capabilities. |
sound/soc/sof/ipc4-loader.c |
Parses firmware UAOL capabilities. |
sound/soc/sof/intel/Makefile |
Builds Intel UAOL integration. |
sound/soc/sof/intel/Kconfig |
Adds SOF USB offload configuration. |
sound/soc/sof/intel/hda.h |
Defines UAOL state, limits, and shared interfaces. |
sound/soc/sof/intel/hda.c |
Registers offload support and reports usable UAOL links. |
sound/soc/sof/intel/hda-uaol.c |
Implements UAOL routing, constraints, and stream lifecycle. |
sound/soc/sof/intel/hda-pcm.c |
Applies backend constraints and supports 384-kHz formats. |
sound/soc/sof/intel/hda-mlink.c |
Adds UAOL link lookup. |
sound/soc/sof/intel/hda-dai.c |
Adds UAOL DAIs and shares common callbacks. |
sound/soc/sof/intel/hda-dai-ops.c |
Adds UAOL DMA operations and feedback DMA allocation. |
sound/soc/sof/intel/hda-common-ops.c |
Wires UAOL-aware machine registration callbacks. |
sound/soc/sof/core.c |
Finalizes copied machine parameters before registration. |
sound/soc/soc-usb.c |
Adds non-DT matching and per-stream route controls. |
sound/soc/intel/common/sof-function-topology-lib.c |
Recognizes optional UAOL topology fragments. |
sound/soc/intel/boards/sof_uaol_common.h |
Shares UAOL backend naming and counting helpers. |
sound/soc/intel/boards/sof_sdw.c |
Creates UAOL backend links for SoundWire cards. |
sound/soc/intel/boards/sof_board_helpers.h |
Adds UAOL link type and board parameters. |
sound/soc/intel/boards/sof_board_helpers.c |
Creates UAOL links through shared board helpers. |
sound/soc/intel/boards/skl_hda_dsp_generic.c |
Includes UAOL links in generic HDA cards. |
sound/hda/core/device.c |
Adds 384-kHz HDA stream-format encoding. |
include/sound/usb-offload.h |
Defines the public USB audio offload interface. |
include/sound/sof/ipc4/header.h |
Defines firmware UAOL capability messages. |
include/sound/soc-usb.h |
Exposes route state, controls, and selection APIs. |
include/sound/soc-acpi.h |
Adds UAOL machine parameters. |
include/sound/hda-mlink.h |
Declares UAOL link lookup and its stub. |
include/linux/usb/xhci-sideband.h |
Exposes resource, endpoint-property, and restart APIs. |
drivers/usb/host/xhci.h |
Defines extended-property commands and resource tracking. |
drivers/usb/host/xhci.c |
Implements extended-property command execution. |
drivers/usb/host/xhci-sideband.c |
Implements audio endpoint handover and resource management. |
drivers/usb/host/xhci-ring.c |
Queues and handles extended-property commands. |
drivers/usb/host/xhci-mem.c |
Initializes and destroys sideband resource tracking. |
Documentation/sound/soc/usb.rst |
Documents routing APIs and platform-card controls. |
Documentation/sound/soc/index.rst |
Adds the UAOL documentation entry. |
Review effort: Balanced
5465b53 to
60134a0
Compare
|
Changes since v1 Folded into the existing UAOL patches in
Tested on PTL (SoundWire and HDA): 384 kHz S16 on a high-speed adapter, two |
There was a problem hiding this comment.
🟡 Changes recommended
Critical shutdown-ordering and sample-width accounting errors can stop USB endpoint service while the DSP remains active and underestimate FIFO requirements, risking stalled streams and corrupted audio.
3 open issues
2 resolved since last review
Review effort: Balanced
60134a0 to
43ee753
Compare
|
Changes since v2:
Changelog since the "UAOL diet" marker (12 commits, all fixup! or amend! on top of a239254, so squashing them folds each change into its target patch) Library
ASoC and SOF
Docs (c2d0a93, 2d7ea53, bd7019f): updated for all of the above. Behaviour changes to be aware of
|
There was a problem hiding this comment.
🟡 Changes recommended
Ignored Stop Endpoint failures can allow unsafe link teardown and controller stalls, while endpoint validation outside the lock can race with device removal and crash the kernel.
5 open issues
Serialize endpoint validation with device removal and doorbell writes · New Propagate endpoint stop failures before quiescing the stream · New Do not quiesce USB endpoints when the DSP stop fails Use the resolved physical sample width for FIFO sizing Resume the USB interface before querying offload capabilities
Review effort: Balanced
43ee753 to
d97558a
Compare
|
Changes since v3:
|
There was a problem hiding this comment.
🟡 Changes recommended
Format filtering checks only rate bounds rather than discrete entries, allowing ALSA to select an incompatible format and fail rate refinement despite a valid configuration being available.
4 open issues
2 resolved since last review
Review effort: Balanced
|
@ujfalusi there's already support for USB offload on QCOM platforms, I reviewed their patches a very long time ago, see https://lore.kernel.org/linux-sound/20250409194804.3773260-1-quic_wcheng@quicinc.com/ The main difference with your solution is that the USB card exposes a control that tells the sound server if there's a matching offloaded card/device, see below excerpt from the introduction |
Yes, I'm aware of that and the SOF implementation is following as much as possible from that design.
Yes, and this is deliberate. QC is locking the offload to the last appearing USB audio device, so if you insert a USB device, the offload can go there, then if you insert another, the offload moves there, so on. On Intel hardware we have 2x playback stream and 4 rx streams: 2 capture and 2 for playback feedback) support and laptops tends to have multiple USB ports and users can insert multiple devices. There are also devices with multiple PCMs... What I wanted to have is to be able to select the destination for the two possible playback and capture for the offload, so we give this to user space with the 4x route selection enums, for example for the playback 0 stream: and you select where to direct the offload. If QC wants, they can adapt this fro flexibility, but using the last (or first) endpoint was too limiting for my liking. We also support capture, hence the 2x 2x route selection The documentation patch have some use case diagram on how I think this can be handled in a user friendly way. |
d97558a to
9ca2c3e
Compare
The UAOL backend DAI only sets up the link DMA, the DSP side of the link. Nothing claims the USB side, so the endpoint the DSP is supposed to read from is still owned by the host and its transfer ring does not even exist: a ring is only allocated once the streaming altsetting is selected. Acquire the stream from the offload library in hw_params and release it in hw_free. This starts the device on the USB side, hands its endpoint ring to the DSP and takes the device away from user space for as long as the DAI holds it. Every UAOL CPU DAI claims a struct hda_uaol_stream of its own when it probes, found from the DAI on every callback: that is where the acquired device and its USB PCM, the backend substream and the suspended flag of the backend live, so the backends of a direction do not step on each other. The ASoC USB route a backend plays to is the pin number of its DAI name, "UAOL0 Playback Pin1" playing to playback route 1. DPCM runs a backend's hw_params once for every frontend that reaches its own hw_params while the backend is still in the OPEN, HW_PARAMS or HW_FREE state, so with a playback PCM and its deep buffer opened at once the backend sees two calls. The stream is acquired by the first one only, and released from hw_free, which DPCM runs once the last frontend is gone. A system suspend resets the pipeline and frees the DAI copier while the stream stays open, taking the device's streaming altsetting with it. DPCM brings such a stream back through the backend's prepare, not hw_params, so acquire the stream again from prepare when the backend saw a suspend trigger. The trigger runs under the PCM stream lock and only records the fact. Which device and which of its PCMs a backend offloads is the ASoC USB route control's decision: the DAI resolves the selection of its route when acquiring the stream and reports the route as busy while it holds one, so the selection cannot change under a running stream. Unplugging the device a stream plays to would otherwise leave that stream running: the library gives the USB side back and the host drops the device from the port, but nothing reaches the frontend, so the link keeps running into a dead endpoint and the application keeps feeding it. The USB audio card ends its users' streams when it goes away, by stopping them into the DISCONNECTED state; do the same for the frontends routed to the backends whose stream belongs to the unplugged device, so that the application sees the device disappear the way it does when playing to the card directly. The backend substream is remembered along with the device for that, and the frontends are walked under the card's DPCM mutex, which the backend's hw_params and hw_free also hold. The backend then forgets the device: the library has given the USB side back already and the usb_device goes away with the disconnect, so the hw_free of the frontends' teardown must not hand it to the library again. SOF only hands this DAI S24_LE, while a USB device commonly packs 24-bit audio into 3 bytes. The library reports the container the acquired stream runs in, so set the link DMA up from that, so that it runs the same 24-bit container and the DSP packs the samples on their way to the link. DPCM hands hw_params a copy of the params, while prepare programs the link DMA again after a stop from the backend's own copy, so prepare applies the container to that one as well. A second frontend, the deep buffer, can share the backend with the one which has it open. They share the one endpoint and the one mixer, so the second one can only run what the first one opened the backend with: the rate, the channel count and the format. Remember those when the stream is acquired and refuse a joining frontend which asks for anything else, before the core prepares anything for it. The route control refuses to change a route while its backend holds a stream, but the selection is read before the device is acquired and the route is marked busy once it is held. Read the selection back once the stream is set: the control decides whether the route is busy under the lock the selection is read with, so a change made during the acquisition is seen there and a later one is refused. Release the stream and fail with -EBUSY when the selection moved, the stream has not started yet. Keep a stream suspended by the SUSPEND trigger marked until it is acquired again: a prepare retried after a failed one, after a route change in between or after the device went away, must not run the common prepare and start the DSP on a gateway whose xHCI sideband resources were released and may belong to another stream by then. Clear the flag only once the stream is acquired again, or the stream is closed, and fail prepare when the backend has no device. Signed-off-by: Peter Ujfalusi <peter.ujfalusi@linux.intel.com>
The UAOL gateway needs a configuration blob the topology cannot provide: it describes the link and the USB endpoint behind it, neither of which is known before the stream is opened. The firmware reads it as a sequence of TLVs: the xHCI bus address, the link configuration, the FIFO start address offsets, the data and feedback endpoint information, the ART divider and the endpoint's service interval. Define the blob and build it when the DAI widget is set up, since its size is part of the copier IPC. The link index, the ART divider and the FIFO layout are known at that point: the link FIFO is divided evenly between the streams of a direction, with the T output streams carrying playback and the I input streams carrying the capture and the clock feedback. The fields which describe the USB endpoint are left for the platform code to fill in once the stream has been acquired. The number of streams per direction the link is advertised with comes from sof_ipc4_uaol_get_stream_counts(), which the FIFO layout uses as well: a link the gateway configuration cannot be built for, because the firmware reports more streams than it has room for or none to play to, is not offered with UAOL PCMs which would fail to set up. Signed-off-by: Peter Ujfalusi <peter.ujfalusi@linux.intel.com>
The UAOL gateway configuration blob describes the USB endpoint behind the link, which is only known once the stream has been acquired. Complete the blob in hw_params with the xHCI address, the endpoint information, the sideband resource the endpoint was given and the endpoint's service interval. The resource number is also the UAOL stream, which selects the gateway node index. The service interval lets the firmware size the FIFO time slot to the endpoint's real cadence (1000 us for a standard isochronous endpoint, 125-500 us for high bandwidth ones) instead of assuming one. The feedback fields of the configuration are cleared when the acquired stream has no feedback endpoint, as they can be left over from a previously offloaded device. A widget freed on system suspend stays prepared, so on resume its IPC payload is not rebuilt and sof_ipc4_widget_setup() refreshes only the copier data and the DMA config TLVs; the gateway configuration in between would be sent as it was copied at prepare time. The stream is acquired again on resume, and the sideband resource, with it the UAOL stream index the blob carries, and the slot of the device need not come back the same. Refresh the gateway configuration from copier_config at setup as well. For the other DAI types it has not changed since prepare and the copy is the same. Signed-off-by: Peter Ujfalusi <peter.ujfalusi@linux.intel.com>
…FIFO The share of the link FIFO a UAOL stream is given is decided when the gateway is configured, and the rate, the channel count and the format together decide whether the stream fits in it. An overrun is not reported anywhere, the audio just comes out corrupted. The limit is a single byte rate, so it cuts across all three parameters at once: 192kHz stereo S32_LE needs exactly as much room as 48kHz 8 channel S32_LE. Add hardware rules for the three parameters to the frontend so that only the combinations which fit are offered. The real service interval is not known before a device's altsetting is resolved, so the rule assumes the shortest possible one (125 us) as a coarse pre-filter rather than capping high-bandwidth devices needlessly. Once the USB stream is acquired, the actual service interval is known: check the payload of two such intervals, rounded to whole sample frames, against the FIFO share and refuse the stream if it is larger. A payload which is exactly as large as the share fits. The frontend's backends are resolved before it is opened, and everything the core does to runtime->hw afterwards only narrows it, so the rules are added from the platform PCM open. The hook looks at the backends the frontend routes to and acts on the UAOL ones only; others whose capabilities are only known at runtime could be added to it. The limit is the FIFO share the layout computed for the gateway configuration gives a stream. Add sof_ipc4_uaol_get_fifo_size(), returning the bytes a stream of a direction can use on a link, so that the platform code and the gateway agree on the number. Signed-off-by: Peter Ujfalusi <peter.ujfalusi@linux.intel.com>
The capabilities of the connected device cannot be coded into the topology file, the user can connect a wide range of devices. The topology provides a broad set of formats, rates and channels for the UAOL PCM, which is then narrowed down to what the actual USB device supports. For example: tplg: S16_LE/S24_LE/S32_LE, 48K/96K, stereo, headset: S16_LE only, 8-192K, stereo/2ch result on PCM: S16_LE (S24_LE/S32_LE dropped), 48K/96K, stereo The device is brought in as hardware rules and not as plain ranges, because what one parameter can be depends on the other two: a device can have a multichannel stream at one rate and a stereo one at another, and the ranges alone would offer the combination of the two that it does not have. The rules resolve the selected device on every call, so a device connected, removed or selected while a PCM sits open is picked up on the next negotiation. Each rule also depends on the parameter it refines, so that a request which changes only that parameter is checked against the device as well. A frontend which shares the backend with one that has it open, the deep buffer, can only run what the first one opened the backend with. Add rules which clone those parameters as the only ones allowed to the second frontend, so that userspace negotiates against the running stream. They read what the first frontend opened the backend with when they are evaluated, so they allow everything while the backend is idle. Signed-off-by: Peter Ujfalusi <peter.ujfalusi@linux.intel.com>
The firmware reads a USB device's clock feedback endpoint through a link DMA of its own, which it expects as a second DMA config TLV in the UAOL gateway configuration (host_dma_config[1]). The driver only ever supplied the audio link DMA, so the firmware ran every playback stream without rate feedback. When the acquired USB stream has a feedback endpoint, allocate a second link DMA stream on the UAOL link, in the capture direction, and describe it in dma_config_tlv[1] the same way the audio one is described in dma_config_tlv[0]. It belongs to the playback substream but is neither the DAI's DMA data nor a stream of its own, so it is kept with the backend's stream state, is not registered as the link_substream, and is run and stopped from the UAOL trigger alongside the audio stream. It is released, and its TLV cleared, together with the USB stream, so that a following device without feedback does not inherit it. hda_link_stream_assign() gets the stream direction as a parameter for that, and the release of a link stream is factored out so that it can be undone without a DAI DMA data pointer. Co-developed-by: Serhiy Katsyuba <serhiy.katsyuba@intel.com> Signed-off-by: Serhiy Katsyuba <serhiy.katsyuba@intel.com> Signed-off-by: Peter Ujfalusi <peter.ujfalusi@linux.intel.com>
The offloaded stream is released from the host's hw_free, which runs only after the DSP has stopped and freed its side of the link. Until then the xHCI keeps servicing the offloaded endpoints. An isochronous IN endpoint, the feedback endpoint of a playback stream in particular, then has nowhere to deliver its packets, which can stall the controller's periodic schedule and lock it up. Add usb_offload_quiesce_stream() so that the host can stop the endpoints on the controller once its own side of the link has stopped, before it is torn down. The feedback endpoint is stopped first, then the data endpoint. The sideband resources stay claimed and usb_offload_release_stream() still has to follow. The stream is named the way release_stream() names it, by its direction and USB PCM device number. Co-developed-by: Serhiy Katsyuba <serhiy.katsyuba@intel.com> Signed-off-by: Serhiy Katsyuba <serhiy.katsyuba@intel.com> Signed-off-by: Peter Ujfalusi <peter.ujfalusi@linux.intel.com>
usb_offload_quiesce_stream() stops the endpoints of an offloaded stream when the host stops it. A stream can be started again without being released in between, which is how an xrun is recovered from, and its endpoints then stay stopped: the stream stalls. Add usb_offload_restart_stream() for the host to run before it starts its own side of the link again. The data endpoint is restarted first, the feedback endpoint, which the quiesce stops first, last. The stream lookup is shared with the quiesce. Signed-off-by: Peter Ujfalusi <peter.ujfalusi@linux.intel.com>
The library claims the USB substream it offloads, but the endpoints the DSP drives can still be shared with a host stream: with implicit feedback the capture data endpoint is also the sync source of the device's playback. An offloaded capture stream and the host's playback then both run that endpoint, the host submitting URBs on a ring the sideband owns, and both stall. Claim the data endpoint, and an explicit feedback endpoint, with snd_usb_endpoint_claim_offload() right after their hw_params, before anything is set up on them, and release them before the stream's hw_free. An endpoint which another stream has open already fails the acquisition with -EBUSY, and the host cannot open one while the stream is held. The test whether a stream has an explicit feedback endpoint is shared with the feedback reservation. Signed-off-by: Peter Ujfalusi <peter.ujfalusi@linux.intel.com>
snd_usb_pcm_prepare() runs snd_usb_set_format_quirk() whenever it sets up the data endpoint afresh. The library prepares the endpoints itself and skipped it, leaving a device which takes its sample rate through vendor requests at whatever rate it ran last. Export the quirk and run it the same way. Some quirks only set up the host's URB path: the MacroSilicon MS2100 and MS2109 capture cards need the first two bytes of the stream dropped, or the channels come out swapped and out of phase, and the E-Mu devices need the start of each packet skipped at 176.4 and 192kHz. The DSP gets the data as the device sends it, so refuse a stream that is left with such an offset with -EOPNOTSUPP. The E-Mu devices are vendor class and never pass the candidate filter, the MacroSilicon cards do. Signed-off-by: Peter Ujfalusi <peter.ujfalusi@linux.intel.com>
…s UAOL The USB stream is released from hw_free, after the DAI copier has been freed and the UAOL link powered off. Until then the xHCI keeps servicing the offloaded endpoints, and the feedback IN endpoint has nowhere to deliver its packets, which can lock up the controller. On TRIGGER_STOP and TRIGGER_SUSPEND, stop the xHCI endpoints with usb_offload_quiesce_stream() right after hda_dai_trigger() has stopped the DAI pipeline. They cannot be stopped any earlier: a UAOL stream cannot go idle once the xHCI no longer services an endpoint still bound to it, so the DSP would time out stopping both the audio and the feedback stream and fall back to resetting them. A stopped endpoint stays stopped until it is restarted, and only a hw_free followed by hw_params, or the reacquire after a system suspend, brings up fresh ones. A stream started again right after a stop, which is how an xrun is recovered from (STOP, prepare, START), would run the DSP against stopped endpoints: the link makes no progress and the application's next write fails with -EIO. Remember that the endpoints were stopped and restart them with usb_offload_restart_stream() on TRIGGER_START, before the DSP starts its side of the link, so that they run then as they do on the first start. Releasing the stream, at hw_free or before a reacquire, forgets it. Co-developed-by: Serhiy Katsyuba <serhiy.katsyuba@intel.com> Signed-off-by: Serhiy Katsyuba <serhiy.katsyuba@intel.com> Signed-off-by: Peter Ujfalusi <peter.ujfalusi@linux.intel.com>
The pieces of the USB audio offload are in place: the device notifications reach the ASoC USB port, the UAOL DAIs acquire, configure, quiesce and restart the USB stream, and the frontends are constrained to what the link and the device can carry. Install hda_machine_register() as the machine_register op, so that the driver registers with the USB audio offload library once the firmware has booted and the library starts reporting the offloadable devices. Signed-off-by: Peter Ujfalusi <peter.ujfalusi@linux.intel.com>
Create the UAOL backend DAI links from the link mask and the stream counts reported in mach_params, following the BT offload link, with their own function topology so that the PCMs they add do not collide with the other functions of the card. Each stream of each direction gets a link of its own: the backend hw_params fixup is called without the stream direction, so a duplex link could not tell which of the two DAI copiers describes the stream being configured and would have to constrain both directions to the same format. With two streams per direction the backends are "UAOL0-Play0", "UAOL0-Play1", "UAOL0-Cap0" and "UAOL0-Cap1", on the CPU DAIs "UAOL0 Playback Pin0" and so on. The link and CPU DAI names are kept in sof_uaol_common.h for the other boards to share. The backends are created ordinal first, playback before capture within an ordinal, so the first playback and capture backend keep two consecutive IDs whatever the stream count, and a topology describing one stream per direction stays valid. The ordinal only tells the backends of a direction apart: it is not the UAOL stream the backend runs on, which is decided by the xHCI sideband resource the endpoint gets when the USB device is acquired. The backend names are abbreviated on purpose: the topology names its DAI copier widget "dai-copier.UAOL.<backend>.<direction>", and alsa-lib keeps element ids in SNDRV_CTL_ELEM_ID_NAME_MAXLEN bytes, so from 38 characters on the ids of the widget's "dai.word" and "dai.string" tuple sections collide and one set is silently dropped from the topology. The topology is named sof-uaol-id<BE id>.tplg after the id of the first playback link. The function name carries no link index, like dmic and hdmi, as the host driver reports a single link. A missing UAOL function topology file is not fatal for the card: like with best_effort the link is skipped when the topology files are collected, and the card comes up without USB offload. Signed-off-by: Peter Ujfalusi <peter.ujfalusi@linux.intel.com>
Add a link type creating the UAOL backend DAI links from a link mask and the stream counts per direction, so that boards using the helpers can place them in their link order like any other backend. Each stream of each direction gets a link of its own, named like sof_sdw does it, see sof_uaol_common.h. The backends are created ordinal first, playback before capture within an ordinal, so the IDs of the first playback and capture backend do not depend on how many streams the link has. Signed-off-by: Peter Ujfalusi <peter.ujfalusi@linux.intel.com>
Create the UAOL backend DAI links from the link mask and the stream counts reported in mach_params, following the BT offload link. The board assigns fixed backend ids, so the UAOL links can take the ids after the BT offload one regardless of which other functions are present. A topology describing the UAOL therefore does not need a variant per board configuration. Signed-off-by: Peter Ujfalusi <peter.ujfalusi@linux.intel.com>
The firmware may only access the UAOL registers once the host enabled the DSP access to the UAOL links, which is a platform decision made before the firmware is booted. Add uaol_host_enabled to struct sof_ipc4_fw_data for the platform code to record this, so that the firmware can be told about it. Signed-off-by: Peter Ujfalusi <peter.ujfalusi@linux.intel.com>
The DSP offload is enabled for the UAOL links at probe time, before the firmware is booted. The firmware may access the UAOL registers after this, but there is no point in it doing so if the kernel is built without USB audio offload support. Set uaol_host_enabled if the controller has a UAOL link and the USB audio offload support is enabled. Signed-off-by: Peter Ujfalusi <peter.ujfalusi@linux.intel.com>
…CONFIG Linux 7.0 and older do not enable access to the UAOL registers, and the firmware reading the UAOL capabilities for the HW_CONFIG reply causes a DSP panic with them. To stay compatible with these kernels the firmware must not touch the UAOL hardware unless the host tells it that it is safe to do so. Add a handshake for this: when the firmware reports UAOL support in its FW_CONFIG reply, send back a FW_CONFIG set with the UAOL_SUPPORT tuple before requesting the HW_CONFIG. The value of the tuple is uaol_host_enabled, set by the platform code if it enabled the DSP access to the UAOL links, so a platform without usable UAOL links tells the firmware to keep away from them with 0. The firmware keeps the UAOL capabilities out of the HW_CONFIG reply unless it receives 1, so a host not sending the tuple (or sending 0) gets no UAOL capabilities and the UAOL registers are left alone. The configuration is only queried on first boot, the handshake does not need to be repeated on later firmware boots. Firmware which does not handle the set yet only prints a warning and reports the capabilities regardless. A failing set is not fatal either, the firmware is not going to report the UAOL capabilities and UAOL is not going to be used. Signed-off-by: Peter Ujfalusi <peter.ujfalusi@linux.intel.com>
Add Documentation/sound/soc/sof-uaol.rst, describing the USB audio offload on Intel platforms with SOF: how the xHCI Audio Sideband, the USB audio offload library, the ASoC USB framework, the SOF HDA driver and the machine drivers fit together, what the user visible interface is (the route controls and the jack), how a stream is acquired and released, how the UAOL gateway is configured and how the firmware's FIFO layout decides where an endpoint may be placed, the asynchronous playback policy, and the current limits. Signed-off-by: Peter Ujfalusi <peter.ujfalusi@linux.intel.com>
A USB device states how many bits of its audio subslot it uses, the bit resolution of its format descriptor, which can well be less than the subslot carries: a 24 bit device with a 4 byte subslot is run at S32_LE and only uses the 24 most significant bits of the sample. The driver parses the resolution into fmt_bits but only prints it in proc, and the PCM says that all 32 bits count, so userspace has no way of knowing that it should prepare 24 bit samples. Report it as the subformat and the msbits of S32_LE, which is where the core keeps it. The subformats the alternate settings can run S32_LE at narrow the subformat as the other parameters narrow down the alternate settings, and a subformat chosen by userspace narrows the alternate settings, and so the rate, the channels and the format, in turn. A device can have alternate settings which only differ in the bit resolution, the Topping E30 runs S32_LE at 32 and at 24 bits on the same endpoint, of which the first one has always been picked so far. Once the format is S32_LE the msbits are the highest resolution the alternate settings still allowed have at the rates still allowed, and at hw_params time the alternate setting with the resolution the msbits tell is picked. What is reported is thus what runs, whichever of the alternate settings would have been picked before, and a subformat chosen by userspace gets the alternate setting running it. The parameters an offloading PCM looks up the alternate setting with have not necessarily been negotiated with the device, so the lookup for them still settles for the format, rate and channels when the device has nothing at their subformat. Signed-off-by: Peter Ujfalusi <peter.ujfalusi@linux.intel.com>
A driver which offloads the streams of a USB device has to tell userspace how many bits of an S32_LE sample the device uses, like the PCM of the USB device does. Export snd_usb_audioformat_subformats() and snd_usb_audioformat_msbits() so the USB offload helpers can tell the subformats and the msbits of the alternate settings with the rules of the USB PCM. Signed-off-by: Peter Ujfalusi <peter.ujfalusi@linux.intel.com>
The PCM which offloads a USB stream has to tell userspace how many bits of an S32_LE sample the device uses, like the PCM of the USB device does. It only knows the device through usb_offload_refine_hw_params(), which refines the rate, the channels and the format. Let it refine the subformat as well, from the bit resolution of the alternate settings the other parameters still allow, and set the msbits to the highest of those resolutions once the format is S32_LE, the one the acquire goes for with the parameters of the backend. The subformat narrows the alternate settings considered for the other parameters in turn, so a subformat chosen by userspace is honored. Signed-off-by: Peter Ujfalusi <peter.ujfalusi@linux.intel.com>
When ASoC sets up the runtime of a DPCM frontend it narrows the subformats the PCM open set to the ones of the frontend DAI, which are not set for a DAI created from topology. The subformats of S32_LE are lost that way, whatever the open decided from the backend reached. Allow all of them on the frontend DAIs, so that the open decides. Nothing sets any of them yet, so nothing changes until something does. Signed-off-by: Peter Ujfalusi <peter.ujfalusi@linux.intel.com>
A USB device can use fewer of the bits of an S32_LE sample than its 32, a 24 bit device with a 4 byte subslot does. The UAOL frontend says that all of them count, so userspace cannot know that it should prepare 24 bit samples, while the PCM of the USB device does tell. Refine the subformat of the frontend to the device as well, which also sets the msbits. The data path is not affected, the backend stays on the full 32 bits and the device ignores the ones it does not use. Signed-off-by: Peter Ujfalusi <peter.ujfalusi@linux.intel.com>
…s behind a hub" This reverts commit 99615fd. Signed-off-by: Peter Ujfalusi <peter.ujfalusi@linux.intel.com>
4cbe015 to
2c2e941
Compare
|
Changes since v8:
|
There was a problem hiding this comment.
🔵 Needs a closer look
Cross-subsystem xHCI/DSP ownership, firmware contracts, and suspend/restart sequencing require hardware-aware maintainer validation beyond what static source review can establish.
No open issues 🎉
1 resolved since last review
Review effort: Balanced


kconfig patch: thesofproject/kconfig#111
sof-test patch for sof_remove.sh: thesofproject/sof-test#1366
USB Audio Offload Link (UAOL) support. The series lets an Intel audio DSP
source and sink isochronous USB audio directly through the xHCI Audio Sideband,
bypassing the host URB path, while
snd-usb-audiokeeps full ownership of thedevice (descriptors, alternate settings, mixer, PM).
Base:
topic/sof-dev. 54 patches (+1 test-only revert at the tip, see below),53 files, +7248/-141.
Design in brief
sideband registration, resource ID reservation, endpoint hand-over and
property query.
xhci_sideband_start_endpoint()restarts an endpoint stoppedon the sideband.
hands to the DSP; the host cannot open them meanwhile (
-EBUSY).snd_usb_release_platform_ops()lets a platform let go of all devices whenit unregisters.
sound/usb/offload): a host registers oncewith
usb_offload_register(). The library:explicit feedback only);
sideband resources and runs the device's format quirk;
USB Offload <n> Playback/Capture Route, enumerating<card>,<pcm>pairs,and a
USB Offload Jack.constraints on the frontends;
recovery works;
refreshed for the resources it gets;
hda-uaol.cholds the Intel glue.the UAOL backend links. A missing
sof-uaolfunction topology only leavesUSB offload out.
USB Offload <n>frontend; the kernel never migrates a stream.
snd_usb_offload.allow_feedback=1to test the explicit feedback path).
to stay on the host. Devices with nothing to offload are not reported.
Layout
sof-uaol.rst,usb.rst)Testing
-fanalyzer: clean on the CI directories.checkpatch.pl --strict: clean apart from MAINTAINERS notes on the newfiles (xhci patches as provided).
capture.
explicit-feedback playback with
allow_feedback=1.plays there while other devices are offloaded.
capture.
384 kHz on the second PCM, and capture on both.
deep-buffer frontends, and with host playback on another device;
different sideband resource.
Known limitations
is not reacquired: ALSA only sends
TRIGGER_SUSPENDto running streams.This applies to all PCMs, not UAOL specific
test-only revert at the tip lifts that restriction.