Created attachment 200478 [details] Implement sample rate table requests in two steps. The SPL Crimson Revision 1 is a (mostly) class compliant USB 2.0 audio interface for musicians. Due to a firmware bug the device will not return a sample rate table on request when using the current implementation in the snd_uaudio module. How to reproduce: 1. Set a quirk for the device to use the second USB configuration, which provides the full USB 2.0 audio interface: usbconfig add_dev_quirk_vplh 0x0a4a 0xc150 0x0000 0xffff UQ_CFG_INDEX_1 2. Plug the SPL Crimson into a USB 2.0 port. Results: The snd_uaudio module takes very long to attach to the device (some minutes). No playback or recording channels are found since the sample rates are missing. Expected: Creation of a 6 in 6 out pcm device for up to 96kHz sample rate within seconds. Hard- and Software: SPL Crimson Revision 1 at firmware 1.0.9, the newest available on their website. FreeBSD 11.2-RELEASE and 12.0-RELEASE for amd64. Analysis: For USB 2.0 audio devices, snd_uaudio sends a request to get a table of the supported sample rates, possibly multiple times. Since the length of this table is not known, it requests 255 bytes of sample rate table regardless of its actual length. Due to the firmware bug the SPL Crimson only answers requests for up to about 100 bytes length. The unanswered requests for 255 bytes will result in USB timeouts and missing sample rates. When plugged into macOS (High Sierra), the device works as expected and the sample rates are detected correctly. This is because macOS requests only one row of sample rates at first. The table header indicates the actual length, which is then used for a second request. Both approaches should be valid according to the USB 2.0 audio specs. Proposed solution: The patch provided implements exactly the behavior of macOS. It sends one short request first for the header and one table row (2 + 1 * 12 bytes). If answered, a second request is sent using the actual length derived from the header (2 + n * 12 bytes). What is not implemented yet is a wrap-up into an optional USB quirk. But it may also prove beneficial to adopt the macOS behavior in general, many class compliant devices are explicitly tested against Apple software.
I made some modification to your patch. Please verify. Please also attach the usbdevs and usb_quirk.c patch here! --HPS
A commit references this bug: Author: hselasky Date: Tue Dec 25 10:15:48 UTC 2018 New revision: 342456 URL: https://svnweb.freebsd.org/changeset/base/342456 Log: Fix reading of USB sample rate descriptor for SPL Crimson Rev 1. Read first one entry, then try to read the full rate descriptor table. PR: 234380 MFC after: 1 week Sponsored by: Mellanox Technologies Changes: head/sys/dev/sound/usb/uaudio.c
(In reply to commit-hook from comment #2) Thanks, much appreciated. I can confirm that this commit works as intended and fixes the issues with sample rate detection on the Crimson. Unfortunately I cannot test it with my other devices since they are all USB 1.1 only. The code looks robust to me functionality-wise, I think both the fallback to the old behavior (request ~255 bytes) and the support for longer tables are good ideas, I didn't consider that in my patch. Some comments if I may: 1. The comment for the fallback ("Likely the descriptor...") is confusing to me. Isn't that the case for devices that either don't support a request for only one row or don't support the request type at all? 2. Using the error code as a condition for the second request is a bit misleading I think, wouldn't it be easier to just check for 'rates > 1'? That would make the code shorter and the intention more understandable. But these are minor issues, I'm happy with fixing it either way.
Created attachment 200531 [details] Quirk to use the second USB configuration for SPL Crimson Rev 1 And here is the patch for the USB quirk based on 13.0-CURRENT, also tested. As stated before, the SPL Crimson Rev 1 has the standard compliant USB 2.0 audio interface in the second USB configuration. I hope the patch is ok like this. Thanks again Florian Walpen
A commit references this bug: Author: hselasky Date: Thu Dec 27 08:29:06 UTC 2018 New revision: 342549 URL: https://svnweb.freebsd.org/changeset/base/342549 Log: Add USB quirk for SPL Crimson Rev 1. PR: 234380 MFC after: 1 week Sponsored by: Mellanox Technologies Changes: head/sys/dev/usb/quirk/usb_quirk.c head/sys/dev/usb/usbdevs
A commit references this bug: Author: hselasky Date: Thu Jan 3 09:23:35 UTC 2019 New revision: 342722 URL: https://svnweb.freebsd.org/changeset/base/342722 Log: MFC r342456: Fix reading of USB sample rate descriptor for SPL Crimson Rev 1. Read first one entry, then try to read the full rate descriptor table. PR: 234380 Sponsored by: Mellanox Technologies Changes: _U stable/12/ stable/12/sys/dev/sound/usb/uaudio.c
A commit references this bug: Author: hselasky Date: Thu Jan 3 09:24:38 UTC 2019 New revision: 342723 URL: https://svnweb.freebsd.org/changeset/base/342723 Log: MFC r342456: Fix reading of USB sample rate descriptor for SPL Crimson Rev 1. Read first one entry, then try to read the full rate descriptor table. PR: 234380 Sponsored by: Mellanox Technologies Changes: _U stable/11/ stable/11/sys/dev/sound/usb/uaudio.c
A commit references this bug: Author: hselasky Date: Thu Jan 3 09:25:39 UTC 2019 New revision: 342724 URL: https://svnweb.freebsd.org/changeset/base/342724 Log: MFC r342456: Fix reading of USB sample rate descriptor for SPL Crimson Rev 1. Read first one entry, then try to read the full rate descriptor table. PR: 234380 Sponsored by: Mellanox Technologies Changes: _U stable/10/ stable/10/sys/dev/sound/usb/uaudio.c
A commit references this bug: Author: hselasky Date: Thu Jan 3 09:26:46 UTC 2019 New revision: 342725 URL: https://svnweb.freebsd.org/changeset/base/342725 Log: MFC r342549: Add USB quirk for SPL Crimson Rev 1. PR: 234380 Sponsored by: Mellanox Technologies Changes: _U stable/12/ stable/12/sys/dev/usb/quirk/usb_quirk.c stable/12/sys/dev/usb/usbdevs
A commit references this bug: Author: hselasky Date: Thu Jan 3 09:27:35 UTC 2019 New revision: 342726 URL: https://svnweb.freebsd.org/changeset/base/342726 Log: MFC r342549: Add USB quirk for SPL Crimson Rev 1. PR: 234380 Sponsored by: Mellanox Technologies Changes: _U stable/11/ stable/11/sys/dev/usb/quirk/usb_quirk.c stable/11/sys/dev/usb/usbdevs
A commit references this bug: Author: hselasky Date: Thu Jan 3 09:28:19 UTC 2019 New revision: 342727 URL: https://svnweb.freebsd.org/changeset/base/342727 Log: MFC r342549: Add USB quirk for SPL Crimson Rev 1. PR: 234380 Sponsored by: Mellanox Technologies Changes: _U stable/10/ stable/10/sys/dev/usb/quirk/usb_quirk.c stable/10/sys/dev/usb/usbdevs
A commit references this bug: Author: hselasky Date: Thu Jan 3 09:29:38 UTC 2019 New revision: 342728 URL: https://svnweb.freebsd.org/changeset/base/342728 Log: MFC r342456: Fix reading of USB sample rate descriptor for SPL Crimson Rev 1. Read first one entry, then try to read the full rate descriptor table. PR: 234380 Sponsored by: Mellanox Technologies Changes: _U stable/9/sys/ stable/9/sys/dev/sound/usb/uaudio.c
A commit references this bug: Author: hselasky Date: Thu Jan 3 09:30:10 UTC 2019 New revision: 342729 URL: https://svnweb.freebsd.org/changeset/base/342729 Log: MFC r342549: Add USB quirk for SPL Crimson Rev 1. PR: 234380 Sponsored by: Mellanox Technologies Changes: _U stable/9/sys/ stable/9/sys/dev/usb/quirk/usb_quirk.c stable/9/sys/dev/usb/usbdevs