Bug 218603

Summary: synaptics/conexant hi-res audio reports incorrect MaxPacketSize for 16bit output alt
Product: Drivers Reporter: Ian Malone (ibmalone)
Component: Sound(ALSA)Assignee: Jaroslav Kysela (perex)
Status: NEW ---    
Severity: normal    
Priority: P3    
Hardware: All   
OS: Linux   
Kernel Version: Subsystem:
Regression: No Bisected commit-id:
Attachments: non working quirk patch

Description Ian Malone 2024-03-15 15:18:22 UTC
Related to bug 218544, which is partly a scheduler issue, but this device (Anker USB-C to 3.5 adapter), ID 0572:1b08 Conexant Systems (Rockwell), Inc. Hi-Res Audio, appears to incorrectly report MaxPacketSize for EP 1 OUT Alt 1 (16 bit stereo). 

wMaxPacketSize / (Max sampling frequency * sample bytes * channels )
EP 1 in
Alt 1 (16b)  192 / (48kHz * 2 * 2) = 1ms
Alt 2 (24b)  288 / (48kHz * 3 * 2) = 1ms
EP 1 out
Alt 1 (16b) 768 / (96kHz * 2 * 2) = 2ms
Alt 2 (24b) 576 / (96kHz * 3 * 2) = 1ms

EP 1 out, Alt 1 is an anomaly as the maximum packet size claims to be 2 frames. If I make the change to force it to 384 (obviously just a hack) then the output sound is still good:
--- sound/usb.orig/stream.c     2024-03-08 10:19:27.430507385 +0000
+++ sound/usb/stream.c  2024-03-12 16:13:43.212737555 +0000
@@ -690,6 +690,10 @@
        fp->ep_attr = get_endpoint(alts, 0)->bmAttributes;
        fp->datainterval = snd_usb_parse_datainterval(chip, alts);
        fp->protocol = protocol;
+       if(le16_to_cpu(get_endpoint(alts, 0)->wMaxPacketSize)==768){
+         get_endpoint(alts, 0)->wMaxPacketSize = cpu_to_le16(384);
+         usb_audio_err_ratelimited(chip,"overwrote in stream");
+       }
        fp->maxpacksize = le16_to_cpu(get_endpoint(alts, 0)->wMaxPacketSize);
        fp->channels = num_channels;
        if (snd_usb_get_speed(chip->dev) == USB_SPEED_HIGH)

I guess this should be correctly addressed as a device quirk, however I haven't been able to get that working yet.
Comment 1 Ian Malone 2024-03-15 15:27:45 UTC
Created attachment 305997 [details]
non working quirk patch

This is my non-working attempt at a quirk patch for the device. However it doesn't result in working sound output; although the device does get created and pipewire will connect things to it, playback just results in silence. I suspect I'm missing some feature, even just a mixer control. Changing the ifnum2 .type to QUIRK_AUDIO_STANDARD_INTERFACE works as previously. (Also Alt 2 needs defined, I'm not sure how to override a single alt without redefining the entire device, just defining ifnum = 2 causes errors probing the device.)
Lastly, not sure this quirk alone actually works, it seems the usb driver structure's MaxPacketSize needs overwritten, other things I've tried to reduce sound/usb's maxpacksize alone don't seem to change the amount of bandwidth that gets scheduled.