From nobody Fri Jul 24 11:20:40 2026 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4h65C25bh4z6lj91 for ; Fri, 24 Jul 2026 11:20:46 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "YR1" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 4h65C22Dn2z4PNf for ; Fri, 24 Jul 2026 11:20:46 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1784892046; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=m7ztGspuS/rCBk5VI8lb4DDo4uhPKL3SkqMhDW2/x28=; b=S4L86TGODNLx8dZx1dyYKynfTdlQPupM/Lk5hmhhVzDhzS5c7reuNUCSpznJo5IYybTnsf +ZA85Gz10tRdXMZ1ykSzFo/ZxCbzY5LHwNuLIeaF91vst4qZf/unNdymUOL6+EPd2pWdW4 OA4AJIkEc5FPVBPZOgmAWNa1714VEdHXZ3u/lJkJ/3lfHRlSs7eU8hiIuMSp0D45yUE3zU zvn79E7XMCkhYF5Mf2Bv5ZP394Bwm0Z3uIIExpUSIBMKI72TMMgEtw90V+eVlcAykIhyzx YH2f8/ytpnR9GSplT80AEktS6CMPminHngdx90p/psB+RN/vC1gbnu3qCn/l7g== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1784892046; a=rsa-sha256; cv=none; b=R9P1FQnypWfyIUr45nCTmaq0A+F8FVWCOEIxwrok2lwbEhVZF15fuQXud9qycNedV6sX8g ezZpangowD5ErL30NNW2O0RuGwnmkpA0V6no44Jx+vtczzlrThxkmB+sCcl/ICEIHN5vEY CbInm6KA9DwRc1/T95LcfX96f2J7gl+PrmETiSspS1VDUUYvYe8BJmRrh31/2hmJJvqiM/ 0djjcOYneLboZ69xRE5f5pwEwHxmKZHhx7Ww8li/uZxonUEoaxNkqG1JMF5FZFzcckE4O6 +yPAfA4GLL95lidgEcF1E7Xrtxr8tVSIIAv9w0jwFr1LQFFhVGSlM7gFT/PT3Q== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1784892046; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=m7ztGspuS/rCBk5VI8lb4DDo4uhPKL3SkqMhDW2/x28=; b=crdUj+6JTsb7xEWZzLhu3WlLyoplVrIx+JiUhSVk1GN1q31DojMbh8lFqspFUexaMhJzyt FCl4cA8vRl0zE764QYtDQu5YxiMEmjfWYfD05tiIstEEgiY+X0yCnUlf1MqcQoAn0zo30n bAHU7znaGeWoJH1PMEqTHRRHO9Tb4jeEu53cBqr+MUX+TwX+1bf9YjBdffZZj3+98KOTyQ 8CmE6UaBbXilgs4932I7T7VK/9lelCITArCkFk9ZF8uHL+W1KF5sMqs+ArR5Xzdm9YSP17 JRk5B84HrLJcow4wRovFNK5UKOLB+fWYGqLCdtQKt8XSfT6nM1Q87byrzhmijg== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4h65C20T4JzprB for ; Fri, 24 Jul 2026 11:20:46 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 45716 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Fri, 24 Jul 2026 11:20:40 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org Cc: giacomo From: Christos Margiolis Subject: git: 755685dd665e - main - snd_uaudio: Don't let an idle stream reprogram a shared UAC2 clock List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@FreeBSD.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: christos X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 755685dd665ef209912c59da6a7d0e7f2c9f464b Auto-Submitted: auto-generated Date: Fri, 24 Jul 2026 11:20:40 +0000 Message-Id: <6a634a88.45716.3ab0676@gitrepo.freebsd.org> The branch main has been updated by christos: URL: https://cgit.FreeBSD.org/src/commit/?id=755685dd665ef209912c59da6a7d0e7f2c9f464b commit 755685dd665ef209912c59da6a7d0e7f2c9f464b Author: giacomo AuthorDate: 2026-07-15 11:34:34 +0000 Commit: Christos Margiolis CommitDate: 2026-07-24 11:20:08 +0000 snd_uaudio: Don't let an idle stream reprogram a shared UAC2 clock Some UAC2 devices expose a single Clock Source entity that is shared between their playback and capture interfaces (it appears in both the output and input clock bitmaps). On such a device uaudio(4) programs the sample rate for both directions when a stream starts. If playback runs at a 44.1 kHz-family rate while the idle capture channel is left at its 48 kHz-family default, the capture SET_CUR(UA20_CS_SAM_FREQ_CONTROL) is issued after the playback one and overwrites the rate on the shared clock. The device then runs at ~48 kHz while the playback stream carries 44.1 kHz data. Consuming samples faster than they arrive, the device repeatedly runs out of data, loses sync with the playback stream, and re-locks onto it (audible dropouts, front-panel play/idle flicker). The 48 kHz family is unaffected because both directions then agree on the rate. Fix it in three parts: - Add a shared-clock guard: before issuing SET_CUR to a clock id, if that clock is shared between playback and capture and the other direction is already streaming at a different rate, skip it. The first active stream owns the clock; a later one follows it. - When the recording channel is auto-started only as a source of jitter information for asynchronous playback, align its nominal rate to the playback rate before starting it, so it neither reprograms the shared clock to a conflicting rate nor produces mismatched frame sizes. - Always submit the explicit-feedback SYNC transfer so dev.pcm.%d.feedback_rate stays live as a diagnostic even when a capture stream is present. Reproduced on an OKTO RESEARCH DAC8 STEREO (0x152a:0x88c5), whose vestigial capture interface never streams; the same device plays the 44.1 kHz family correctly under Linux's snd-usb-audio. As a side effect, this patch also fixes the sample rate bug mentioned in the BUGS section of sound(4)'s man page, where a device needs to have the same sample rate set for both playback and recording in order to work properly. PR: 295933 Assisted-By: Claude Opus 4.8 (claude-opus-4-8) Signed-off-by: giacomo MFC after: 2 weeks Reviewed by: christos Pull-Request: https://github.com/freebsd/freebsd-src/pull/2323 --- sys/dev/sound/usb/uaudio.c | 103 +++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 95 insertions(+), 8 deletions(-) diff --git a/sys/dev/sound/usb/uaudio.c b/sys/dev/sound/usb/uaudio.c index 4cdd20315258..c2de07abf0a5 100644 --- a/sys/dev/sound/usb/uaudio.c +++ b/sys/dev/sound/usb/uaudio.c @@ -1358,6 +1358,46 @@ uaudio_max_buffer_size(struct uaudio_chan *ch, uint8_t alt) return (buf_size); } +static bool +uaudio20_clock_is_shared(struct uaudio_softc *sc, unsigned int x) +{ + /* + * A clock entity that feeds both an OUTPUT (playback) and an + * INPUT (capture) terminal shows up in both bitmaps: it is a + * sample clock shared between the two directions. + */ + return ((sc->sc_mixer_clocks.bit_output[x / 8] & (1 << (x % 8))) != 0 && + (sc->sc_mixer_clocks.bit_input[x / 8] & (1 << (x % 8))) != 0); +} + +static uint32_t +uaudio_dir_running_rate(struct uaudio_chan *chans) +{ + unsigned int i; + + for (i = 0; i != UAUDIO_MAX_CHILD; i++) { + struct uaudio_chan *ch = &chans[i]; + + if (ch->running != 0 && ch->cur_alt < ch->num_alt) + return (ch->usb_alt[ch->cur_alt].sample_rate); + } + return (0); /* nothing streaming in this direction */ +} + +static bool +uaudio_chan_match_rate(struct uaudio_chan *ch, uint32_t rate, uint8_t *p_alt) +{ + uint8_t x; + + for (x = 0; x != ch->num_alt; x++) { + if (ch->usb_alt[x].sample_rate == rate) { + *p_alt = x; + return (true); + } + } + return (false); +} + static void uaudio_configure_msg_sub(struct uaudio_softc *sc, struct uaudio_chan *chan, int dir) @@ -1455,6 +1495,35 @@ uaudio_configure_msg_sub(struct uaudio_softc *sc, } } + /* + * Shared-clock guard. If this clock entity is + * shared between the playback and capture paths, + * and the OTHER direction is already streaming at + * a different rate, do not reprogram the clock -- + * the rate that is already locked wins. This + * stops an idle or secondary stream from yanking + * the shared clock out from under an active + * stream and dropping USB stream lock. The first + * active stream owns the clock; a later one + * follows it (see uaudio_chan_start(), which + * re-aligns the jitter-info record stream to the + * playback rate before it is started). + */ + if (uaudio20_clock_is_shared(sc, x)) { + uint32_t other = (dir == PCMDIR_PLAY) ? + uaudio_dir_running_rate(sc->sc_rec_chan) : + uaudio_dir_running_rate(sc->sc_play_chan); + + if (other != 0 && + other != chan_alt->sample_rate) { + DPRINTF("shared clock ID=%u busy at " + "%u Hz; not reprogramming to " + "%u Hz\n", x, other, + chan_alt->sample_rate); + continue; + } + } + if (uaudio20_set_speed(sc->sc_udev, sc->sc_mixer_iface_no, x, chan_alt->sample_rate)) { /* @@ -2334,13 +2403,10 @@ uaudio_chan_play_sync_callback(struct usb_xfer *xfer, usb_error_t error) case USB_ST_SETUP: /* - * Check if the recording stream can be used as a - * source of jitter information to save some - * isochronous bandwidth: + * Submit the transfer even when the recording stream + * provides the jitter information, so that the feedback + * rate keeps being sampled for diagnostic purposes. */ - if (ch->priv_sc->sc_rec_chan[i].num_alt != 0 && - uaudio_debug == 0) - break; usbd_xfer_set_frames(xfer, 1); usbd_xfer_set_frame_len(xfer, 0, usbd_xfer_max_framelen(xfer)); usbd_transfer_submit(xfer); @@ -2884,12 +2950,33 @@ uaudio_chan_start(struct uaudio_chan *ch) if (uaudio_chan_need_both( &sc->sc_play_chan[i], &sc->sc_rec_chan[i])) { + struct uaudio_chan *ch_play = &sc->sc_play_chan[i]; + struct uaudio_chan *ch_rec = &sc->sc_rec_chan[i]; + uint8_t rec_alt; + + /* + * The recording channel is only being started as a + * source of jitter information for the playback + * stream. Align its nominal rate with the + * playback rate so that (a) it does not reprogram + * a sample clock shared with the playback path to + * a conflicting rate, and (b) its expected frame + * sizes match what the device actually produces, + * keeping the derived jitter information valid. + * The USB explore lock is held here, which also + * serializes against uaudio_chan_set_param_speed(). + */ + if (uaudio_chan_match_rate(ch_rec, + ch_play->usb_alt[ch_play->set_alt].sample_rate, + &rec_alt)) + ch_rec->set_alt = rec_alt; + /* * Start both endpoints because of need for * jitter information: */ - uaudio_chan_reconfigure(&sc->sc_rec_chan[i], CHAN_OP_START); - uaudio_chan_reconfigure(&sc->sc_play_chan[i], CHAN_OP_START); + uaudio_chan_reconfigure(ch_rec, CHAN_OP_START); + uaudio_chan_reconfigure(ch_play, CHAN_OP_START); } else { uaudio_chan_reconfigure(ch, CHAN_OP_START); }