Bug 214493 - [Regression] Missing audio profile for soundcard after 5.11 upgrade for USB interface
Summary: [Regression] Missing audio profile for soundcard after 5.11 upgrade for USB i...
Status: RESOLVED CODE_FIX
Alias: None
Product: Drivers
Classification: Unclassified
Component: Sound(ALSA) (show other bugs)
Hardware: All Linux
: P1 normal
Assignee: Jaroslav Kysela
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-09-22 19:15 UTC by Sebastian Rose
Modified: 2021-10-09 08:22 UTC (History)
1 user (show)

See Also:
Kernel Version: 5.11
Subsystem:
Regression: No
Bisected commit-id:


Attachments
alsa-info.sh 5.14 (146.52 KB, text/plain)
2021-09-28 20:53 UTC, Sebastian Rose
Details
alsa-info.sh 5.14-.8 (147.35 KB, application/x-troff-man)
2021-10-03 18:17 UTC, Sebastian Rose
Details
alsa-info.sh output for 5.14.8 after patching (146.88 KB, text/plain)
2021-10-03 18:18 UTC, Sebastian Rose
Details

Description Sebastian Rose 2021-09-22 19:15:59 UTC
When using a USB interface for audio such as the Scarlett 18i8 (https://focusrite.com/de/audio-interface/scarlett/scarlett-18i8) with kernel 5.11 the duplex profile for using audio input as well as output disappears. Instead I'm only able to select either output or input, preventing me from using the speakers as the same time as the microphone.

This problem appeared in 5.11 kernel version and does not appear in 5.10 (currently running the 5.10 LTS which does not exhibit this problem).

When using Pulseaudio to list the available profiles for a card, I get the following on 5.10:

```
	Profiles:
		off: Off (sinks: 0, sources: 0, priority: 0, available: yes)
		output:analog-surround-71: Analog Surround 7.1 Output (sinks: 1, sources: 0, priority: 1200, available: yes)
		pro-audio: Pro Audio (sinks: 1, sources: 1, priority: 1, available: yes)
		input:multichannel-input: Multichannel Input (sinks: 0, sources: 1, priority: 1, available: yes)
```

However, when booing any Kernel version above 5.10, i.e. 5.11 or 5.12 I get the following:

```
	Profiles:
		off: Off (sinks: 0, sources: 0, priority: 0, available: yes)
		output:analog-surround-71: Analog Surround 7.1 Output (sinks: 1, sources: 0, priority: 1200, available: yes)
		pro-audio: Pro Audio (sinks: 1, sources: 1, priority: 1, available: yes)
		input:multichannel-input: Multichannel Input (sinks: 0, sources: 1, priority: 1, available: yes)
```

I have bisected this bug, the problematic commit seems to be

```506c203cc3de6e26666b8476d287dee81595d6dc is the first bad commit
commit 506c203cc3de6e26666b8476d287dee81595d6dc
Author: Takashi Iwai <tiwai@suse.de>
Date:   Wed Jan 20 21:45:54 2021 +0100

    ALSA: usb-audio: Fix hw constraints dependencies
    
    Since the recent refactoring, it's been reported that some USB-audio
    devices (typically webcams) are no longer detected properly by
    PulseAudio.  The debug session revealed that it's failing at probing
    by PA to try the sample rate 44.1kHz while the device has discrete
    sample rates other than 44.1kHz.  But the puzzle was that arecord
    works as is, and some other devices with the discrete rates work,
    either.
    
    After all, this turned out to be the lack of the dependencies in a few
    hw constraint rules: snd_pcm_hw_rule_add() has the (variable)
    arguments specifying the dependent parameters, and some functions
    didn't set the target parameter itself as the dependencies.  This
    resulted in an invalid parameter that could be generated only in a
    certain call pattern.  This bug itself has been present in the code,
    but it didn't trigger errors just because the rules were casually
    avoiding such a corner case.  After the recent refactoring and
    cleanup, however, the hw constraints work "as expected", and the
    problem surfaced now.
    
    For fixing the problem above, this patch adds the missing dependent
    parameters to each snd_pcm_hw_rule() call.
    
    Fixes: bc4e94aa8e72 ("ALSA: usb-audio: Handle discrete rates properly in hw constraints")
    BugLink: http://bugzilla.opensuse.org/show_bug.cgi?id=1181014
    Link: https://lore.kernel.org/r/20210120204554.30177-1-tiwai@suse.de
    Signed-off-by: Takashi Iwai <tiwai@suse.de>

 sound/usb/pcm.c | 3 +++
 1 file changed, 3 insertions(+)
```
Comment 1 Sebastian Rose 2021-09-23 20:50:38 UTC
There is a copy & paste error in the description. The list of profiles for 5.10 looks like this:

```	
Profiles:
		off: Off (sinks: 0, sources: 0, priority: 0, available: yes)
		output:analog-surround-71+input:multichannel-input: Analog Surround 7.1 Output + Multichannel Input (sinks: 1, sources: 1, priority: 1201, available: yes)
		output:analog-surround-71: Analog Surround 7.1 Output (sinks: 1, sources: 0, priority: 1200, available: yes)
		pro-audio: Pro Audio (sinks: 1, sources: 1, priority: 1, available: yes)
		input:multichannel-input: Multichannel Input (sinks: 0, sources: 1, priority: 1, available: yes)
```
Comment 2 Takashi Iwai 2021-09-28 13:22:12 UTC
First off, could you verify whether the problem remains with the latest 5.14.x stable tree or 5.15-rc3?

If yes, please give the output of alsa-info.sh.  Run the script with --no-upload option and attach to Bugzilla.
Comment 3 Sebastian Rose 2021-09-28 20:53:21 UTC
Created attachment 299013 [details]
alsa-info.sh 5.14

It happens with the latest stable kernel as well, 5.14.8. List of profiles looks like this

```
	Profiles:
		off: Off (sinks: 0, sources: 0, priority: 0, available: yes)
		output:analog-surround-71: Analog Surround 7.1 Output (sinks: 1, sources: 0, priority: 1200, available: yes)
		pro-audio: Pro Audio (sinks: 1, sources: 1, priority: 1, available: yes)
		input:multichannel-input: Multichannel Input (sinks: 0, sources: 1, priority: 1, available: yes)
```

I've attached the requested alsa-info.sh output.
Comment 4 Takashi Iwai 2021-09-29 07:46:54 UTC
Thanks.  And reverting the commit on top of 5.14.x fixes the problem?
Comment 5 Takashi Iwai 2021-09-29 07:53:35 UTC
Also, define HW_CONST_DEBUG in sound/usb/pcm.c, and check the kernel debug messages at plugging and configuring PulesAudio.  It might help understanding what's going on.

Since you have multiple usb devices, better to plug it later to get the messages only from the Scarlett device.
Comment 6 Sebastian Rose 2021-09-30 13:48:42 UTC
(In reply to Takashi Iwai from comment #4)
> Thanks.  And reverting the commit on top of 5.14.x fixes the problem?

Strangely enough, it does not. Just reverting 506c203cc3de6e26666b8476d287dee81595d6dc does not work. After some digging around I found it necessary to revert

```
commit be4a338596a40b914d906dcfae94286841aceacc
Merge: 757fed1d0898 4961167bf748
Author: Linus Torvalds <torvalds@linux-foundation.org>
Date:   Thu Jan 28 09:06:52 2021 -0800

    Merge tag 'sound-5.11-rc6' of git://git.kernel.org/pub/scm/linux/kernel/git/tiwai/sound
    
    Pull sound fixes from Takashi Iwai:
     "Although the incoming fixes haven't settled down yet, all changes here
      are small and mostly device-specific fixes, so nothing look worrisome.
    
       - Yet another USB-audio regression fixes
    
       - HD-audio ID fix and device-specific quirks
    
       - SOF Intel / SoundWire fixes including topology
    
       - ASoC Qualcomm and Mediatek fixes"
    
    * tag 'sound-5.11-rc6' of git://git.kernel.org/pub/scm/linux/kernel/git/tiwai/sound: (24 commits)
      ALSA: hda/via: Apply the workaround generically for Clevo machines
      ASoC: Intel: sof_sdw: set proper flags for Dell TGL-H SKU 0A5E
      ASoC: qcom: lpass: Fix out-of-bounds DAI ID lookup
      ASoC: mediatek: mt8192-mt6359: add format constraints for RT5682
      ASoC: ak4458: correct reset polarity
      ASoC: SOF: SND_INTEL_DSP_CONFIG dependency
      ASoC: SOF: Intel: soundwire: fix select/depend unmet dependencies
      ALSA: hda: intel-dsp-config: add PCI id for TGL-H
      ALSA: usb-audio: workaround for iface reset issue
      ALSA: pcm: One more dependency for hw constraints
      ALSA: hda/realtek: Enable headset of ASUS B1400CEPE with ALC256
      ASoC: Intel: Skylake: Zero snd_ctl_elem_value
      ASoC: Intel: Skylake: skl-topology: Fix OOPs ib skl_tplg_complete
      ASoC: qcom: Fix number of HDMI RDMA channels on sc7180
      ASoC: mediatek: mt8183-da7219: ignore TDM DAI link by default
      ASoC: mediatek: mt8183-mt6358: ignore TDM DAI link by default
      ASoC: topology: Properly unregister DAI on removal
      ASoC: topology: Fix memory corruption in soc_tplg_denum_create_values()
      ASoC: qcom: lpass-ipq806x: fix bitwidth regmap field
      ASoC: AMD Renoir - refine DMI entries for some Lenovo products
      ...
```

as well. Since that is a merge commit, I reverted it towards mainline (-m 1 option). Reverting be4a338596a40b914d906dcfae94286841aceacc against 5.14.8 gives a lot of merge conflicts but reverting against 5.11 works. I assume there is a commit in there somewhere that in conjunction with `506c203cc3de6e26666b8476d287dee81595d6dc` causes the issue.
Comment 7 Sebastian Rose 2021-10-01 13:47:15 UTC
It seems like git bisect led me down a stray path, I'm pretty sure that 506c203cc3de6e26666b8476d287dee81595d6dc is not at fault. Sorry for the bad lead.

With some more testing I've managed to whittle the issue down to a single commit that I'm able to revert on top of 5.14.8 which fixes the issue. Reverting [fe773b8711e3be4190994ea54bf7a5a0564245a1](https://lore.kernel.org/all/20210123155842.22652-1-tiwai@suse.de/) makes the correct list of profiles show up

```
	Profiles:
		off: Off (sinks: 0, sources: 0, priority: 0, available: yes)
		output:analog-surround-71+input:multichannel-input: Analog Surround 7.1 Output + Multichannel Input (sinks: 1, sources: 1, priority: 1201, available: yes)
		output:analog-surround-71: Analog Surround 7.1 Output (sinks: 1, sources: 0, priority: 1200, available: yes)
		pro-audio: Pro Audio (sinks: 1, sources: 1, priority: 1, available: yes)
		input:multichannel-input: Multichannel Input (sinks: 0, sources: 1, priority: 1, available: yes)
```

Running 5.14.8 without reverting this commit causes the output:analog-surround-71+input:multichannel-input profile to go missing.
Comment 8 Takashi Iwai 2021-10-01 16:02:29 UTC
Thanks for the input.  So it seems that your device needs the validation like MOTU ones.  Interesting that this rather makes the things re-appearing, instead of restricting.  Or it might be some cargo effect that casually make BIOS happier.  Who knows.

Allowing validation is a good thing in general, so I'd happily add the vendor id 0x1235 there.  Could you verify that it works like below?

--- a/sound/usb/format.c
+++ b/sound/usb/format.c
@@ -471,6 +471,7 @@ static int validate_sample_rate_table_v2v3(struct snd_usb_audio *chip,
 	 * known devices.
 	 */
 	switch (USB_ID_VENDOR(chip->usb_id)) {
+	case 0x1235: /* Focusrite-Novation */
 	case 0x07fd: /* MOTU */
 		break;
 	default:

Unfortunately, there has been a major rewrite of quirk handling in 5.15, and we'd need two different fixes.
Comment 9 Sebastian Rose 2021-10-01 19:27:31 UTC
Thanks for the help. I can confirm that adding the vendor id for Focusrite-Novation makes the missing profile appear. What changed in 5.15, can I help somehow?
Comment 10 Takashi Iwai 2021-10-03 08:12:15 UTC
(In reply to Sebastian Rose from comment #9)
> Thanks for the help. I can confirm that adding the vendor id for
> Focusrite-Novation makes the missing profile appear.

Good to hear.  Could you upload alsa-info.sh outputs before and after the patch?

> What changed in 5.15,
> can I help somehow?

Don't worry, it's just that a different patch is needed for 5.15 due to the code change.  It'd be like below instead:

--- a/sound/usb/quirks.c
+++ b/sound/usb/quirks.c
@@ -1900,6 +1900,8 @@ static const struct usb_audio_quirk_flags_table quirk_flags_table[] = {
                   QUIRK_FLAG_CTL_MSG_DELAY | QUIRK_FLAG_IFACE_DELAY),
        VENDOR_FLG(0x07fd, /* MOTU */
                   QUIRK_FLAG_VALIDATE_RATES),
+       VENDOR_FLG(0x1235, /* Focusrite Novation */
+                  QUIRK_FLAG_VALIDATE_RATES),
        VENDOR_FLG(0x152a, /* Thesycon devices */
                   QUIRK_FLAG_DSD_RAW),
        VENDOR_FLG(0x1de7, /* Phoenix Audio */

But it means that the patch can't be backported to 5.14.x and older, hence a step for stable trees would be slightly complicated (an individual patch has to be submitted to stable).

After checking the alsa-info.sh outputs to understand what really mattered, I'm going to submit the fix to the upstream.
Comment 11 Sebastian Rose 2021-10-03 18:17:24 UTC
Created attachment 299075 [details]
alsa-info.sh 5.14-.8

alsa-info.sh output for 5.14.8 before patching
Comment 12 Sebastian Rose 2021-10-03 18:18:00 UTC
Created attachment 299077 [details]
alsa-info.sh output for 5.14.8 after patching

alsa-info.sh output for 5.14.8 after applying the proposed patch
Comment 13 Takashi Iwai 2021-10-04 07:42:41 UTC
Thanks!  This revealed that the sample rate validation made some rates excluded from the audioformat lists, and this ended up for the driver picking up the right entry.

I submitted the proper for 5.15 kernel to the upstream and will merge it soon later:
  https://lore.kernel.org/r/20211004074050.28241-1-tiwai@suse.de

The fix for 5.14.x kernel will be submitted later to stable tree once after the 5.15 fix landed in Linus tree.  Until then, please keep your local fix.
Comment 14 Sebastian Rose 2021-10-09 08:22:05 UTC
Amazing, it makes the audio interface usable again with recent kernels, thank you!

Note You need to log in before you can comment on or make changes to this bug.