Commit Graph

166 Commits

Author SHA1 Message Date
Hans Petter Selasky
f190f8d1a2 snd_uaudio(4): Set hardware buffering to the minimum by default.
Improves the audio experience when using applications like
audio/jamulus and audio/hpsjam .

MFC after:	1 week
Sponsored by:	NVIDIA Networking
2022-02-20 00:11:51 +01:00
Hans Petter Selasky
2fcd7d380b snd_uaudio(4): Loosen up the USB MIDI permissions.
This makes USB MIDI more userfriendly for desktop users.

PR:		260489
MFC after:	1 week
Sponsored by:	NVIDIA Networking
2021-12-17 11:54:19 +01:00
Hans Petter Selasky
11f09b17fe snd_uaudio(4): Fix string index computations for iFeature.
This allows the iFeature strings to be properly read by the snd_uaudio(4) driver,
when parsing the audio feature unit descriptors.

Submitted by:	Zhichao1.Li@dell.com
MFC after:	1 week
Sponsored by:	NVIDIA Networking
2021-11-09 22:11:25 +01:00
Gordon Bergling
3d6ed119e3 usb_audio: Fix a typo in a source code comment
- s/maxium/maximum/

MFC after: 3 days
2021-11-07 14:04:26 +01:00
Hans Petter Selasky
31070b5bc7 Set default alternate setting when USB audio devices are not in use,
to activate power save features.

Suggested by:	Shichun_Ma@Dell.com
MFC after:	1 week
Sponsored by:	Mellanox Technologies // NVIDIA Networking
2021-03-25 16:49:52 +01:00
Hans Petter Selasky
12148d4300 Fix for locking order reversal in USB audio driver, when using mmap().
Locking the second lock which causes the LOR, can be skipped because
the code updating the shared variables is always executing from the
same USB thread.

lock order reversal:
  1st 0xfffff80005cc3840 pcm7:play:dsp7.p0 (pcm play channel, sleep mutex)
@ usb_transfer.c:2342
  2nd 0xfffff80005cc3860 pcm7:record:dsp7.r0 (pcm record channel, sleep mutex)
@ uaudio.c:2317

lock order pcm record channel -> pcm play channel established at:
witness_checkorder+0x461
__mtx_lock_flags+0x98
dsp_mmap_single+0x151
vm_mmap_cdev+0x65
devfs_mmap_f+0x143
kern_mmap_req+0x594
sys_mmap+0x46
amd64_syscall+0x12e
fast_syscall_common+0xf8

lock order pcm play channel -> pcm record channel attempted at:
witness_checkorder+0xd82
__mtx_lock_flags+0x98
uaudio_chan_play_callback+0xeb
usbd_callback_wrapper+0x7ec
usb_command_wrapper+0x7e
usb_callback_proc+0x8e
usb_process+0xf3
fork_exit+0x80
fork_trampoline+0xe

Found by:	Stefan Ehmann <shoesoft@gmx.net>
MFC after:	1 week
Sponsored by:	Mellanox Technologies // NVIDIA Networking
2021-02-14 20:32:33 +01:00
Vladimir Kondratyev
eead9017d2 hid: Chase for HID function name changes in existing USB HID drivers
Also hide shim code added in a previous commit under COMPAT_USBHID12.

Note: it is enough to add -DCOMPAT_USBHID12 to CFLAGS to compile old
code with new HID subsystem, but it is not enough to link it at runtime.
HID dependency has to be added explicitly with MODULE_DEPEND macro.

Reviewed by:	manu, hselasky (as part of D27887)
2021-01-08 02:18:42 +03:00
Vladimir Kondratyev
67de2db262 Factor-out hardware-independent part of USB HID support to new module
It will be used by the upcoming HID-over-i2C implementation.  Should be
no-op, except hid.ko module dependency is to be added to affected drivers.

Reviewed by:	hselasky, manu
Differential revision:	https://reviews.freebsd.org/D27867
2021-01-08 02:18:42 +03:00
Hans Petter Selasky
f14436adc6 Add a tunable sysctl, hw.usb.uaudio.handle_hid, to allow disabling the
the HID volume keys support in the USB audio driver.

While at it re-organize the USB audio sysctls a bit.

Differential Revision:	https://reviews.freebsd.org/D27180
MFC after:	1 week
Sponsored by:	Mellanox Technologies // NVIDIA Networking
2020-11-12 09:26:01 +00:00
Mateusz Guzik
378503af2e sound: clean up empty lines in .c and .h files 2020-09-01 21:27:34 +00:00
Hans Petter Selasky
42a18f328e Print current buffer latency in dmesg for the USB audio driver and not just
the maximum.

MFC after:	1 week
Sponsored by:	Mellanox Technologies
2020-08-19 08:05:37 +00:00
Mark Johnston
94140f4781 usb(4): Stop checking for failures from malloc(M_WAITOK).
Handle the fact that parts of usb(4) can be compiled into the boot
loader, where M_WAITOK does not guarantee a successful allocation.

PR:		240545
Submitted by:	Andrew Reiter <arr@watson.org> (original version)
Reviewed by:	hselasky
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D25706
2020-07-22 14:32:47 +00:00
Hans Petter Selasky
75dc9c41ab Improve debug message to be more precise and clear.
For the sake of the record, this is the last use of the words master and slave
in the FreeBSD's USB stack, drivers and subsystems.

MFC after:	1 week
Sponsored by:	Mellanox Technologies
2020-06-20 14:16:24 +00:00
Hans Petter Selasky
86c9b3f3a6 Add support for multiple playback and recording devices per physical USB audio
device. This requires some structural refactoring inside the driver, mostly
about converting existing audio channel structures into arrays.

The main audio mixer is provided by the first PCM instance.
The non-first audio instances may only have a software mixer for PCM playback.

Tested by:	Horse Ma <Shichun.Ma@dell.com>
MFC after:	1 week
Sponsored by:	Mellanox Technologies
2020-03-30 16:50:32 +00:00
Hans Petter Selasky
c2bc9ff72a Improve USB audio mixer support for USB audio class 1 and 2.
- make sure volume controls are correctly mapped to "pcm" and "rec" depending
  on how they deliver audio to the USB host.
- make sure there are no duplicate record selections.
- remove internal only mixer class type.
- don't add software volume controls for recording only.
- some minor mixer code cleanup.

Tested by:	Horse Ma <Shichun.Ma@dell.com>
MFC after:	1 week
Sponsored by:	Mellanox Technologies
2020-03-27 10:22:35 +00:00
Hans Petter Selasky
a0be362828 Be more intelligent when classifying USB audio terminal types, so that we
don't end up using SOUND_MIXER_VOLUME for all undefined types.

MFC after:	1 week
Sponsored by:	Mellanox Technologies
2020-03-26 07:52:04 +00:00
Hans Petter Selasky
91feacd19e Make mute controls available for USB audio mixers.
Submitted by:	Horse Ma <Shichun.Ma@dell.com>
MFC after:	1 week
Sponsored by:	Mellanox Technologies
2020-03-26 07:46:16 +00:00
Hans Petter Selasky
edabe1ee6d Factor out USB audio mixer value range check.
MFC after:	1 week
Sponsored by:	Mellanox Technologies
2020-03-26 07:42:36 +00:00
Hans Petter Selasky
7e88777b24 Avoid scaling USB audio mixer values twice.
MFC after:	1 week
Sponsored by:	Mellanox Technologies
2020-03-26 07:37:00 +00:00
Pawel Biernacki
f8d2b1f3f7 Mark more nodes as CTLFLAG_MPSAFE or CTLFLAG_NEEDGIANT (2 of many)
r357614 added CTLFLAG_NEEDGIANT to make it easier to find nodes that are
still not MPSAFE (or already are but aren’t properly marked). Use it in
preparation for a general review of all nodes.
This is non-functional change that adds annotations to SYSCTL_NODE and
SYSCTL_PROC nodes using one of the soon-to-be-required flags.

Reviewed by:	hselasky, kib
Approved by:	kib (mentor)
Differential Revision:	https://reviews.freebsd.org/D23632
2020-02-15 18:52:12 +00:00
Hans Petter Selasky
9de921ee59 Export vendor specific USB MIDI device list to PnP info.
MFC after:		1 week
Sponsored by:		Mellanox Technologies
2019-01-30 17:11:08 +00:00
Hans Petter Selasky
f4dbf0d82d snd_uaudio: Add quirks for Edirol UA-25EX in advanced driver mode.
Extend the vendor class USB audio quirk to cover devices without
the USB audio control descriptor.

PR:			234794
MFC after:		1 week
Sponsored by:		Mellanox Technologies
2019-01-12 11:14:59 +00:00
Hans Petter Selasky
a89c806508 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
2018-12-25 10:15:48 +00:00
Hans Petter Selasky
fb8a716d28 Don't read the USB audio sync endpoint when we don't use it to save
isochronous bandwidth.

MFC after:		3 days
Sponsored by:		Mellanox Technologies
2018-11-08 12:46:47 +00:00
Pedro F. Giffuni
718cf2ccb9 sys/dev: further adoption of SPDX licensing ID tags.
Mainly focus on files that use BSD 2-Clause license, however the tool I
was using misidentified many licenses so this was mostly a manual - error
prone - task.

The Software Package Data Exchange (SPDX) group provides a specification
to make it easier for automated tools to detect and summarize well known
opensource licenses. We are gradually adopting the specification, noting
that the tags are considered only advisory and do not, in any way,
superceed or replace the license texts.
2017-11-27 14:52:40 +00:00
Hans Petter Selasky
067e471a24 Add USB audio support for S/PDIF output with C-Media CM6206 devices.
Submitted by:		Julien Nadeau <vedge@hypertriton.com>
PR:			216131
MFC after:		1 week
2017-01-17 08:15:10 +00:00
Hans Petter Selasky
82364f24b5 Allow higher sample rates to have more jitter than lower ones.
PR:		208791
MFC after:	3 days
2016-11-09 07:09:27 +00:00
Hans Petter Selasky
dd3dde9828 Range check the jitter values to avoid bogus sample rate adjustments.
The expected deviation should not be more than 1Hz per second. The USB
v2.0 specification also mandates this requirement. Refer to chapter
5.12.4.2 about feedback.

PR:		208791
MFC after:	3 days
2016-11-08 08:09:48 +00:00
Hans Petter Selasky
4d76235fe3 Add support for adjusting the hardware buffering delay for USB audio.
Requested by:	Goran Mekic <meka@tilda.center>
MFC after:	1 week
2016-10-19 18:45:06 +00:00
Hans Petter Selasky
d56d9e27c7 Add support for simplex USB MIDI devices, which only provide BULK or
INTERRUPT endpoints for moving data in one direction, like the KeyRig
49 from M-Audio.

Requested by:	Ivan Klymenko <fidaj@ukr.net>
MFC after:	1 week
2016-05-31 15:05:50 +00:00
Pedro F. Giffuni
057b4402bf sys/dev: extend use of the howmany() macro when available.
We have a howmany() macro in the <sys/param.h> header that is
convenient to re-use as it makes things easier to read.
2016-04-26 15:03:15 +00:00
Warner Losh
f809f280e0 Create a USB_PNP_INFO and use it to export the existing PNP
tables. Some drivers needed some slight re-arrangement of declarations
to accommodate this. Change the USB pnp tables slightly to allow
better compatibility with the system by moving linux driver info from
start of each entry to the end. All other PNP tables in the system
have the per-device flags and such at the end of the elements rather
that at the beginning.

Differential Review: https://reviews.freebsd.org/D3458
2015-12-11 05:28:00 +00:00
Hans Petter Selasky
8c20de927a Ensure the USB audio driver doesn't attach twice on the same USB
device by grabbing all the USB audio device interfaces.

MFC after:	1 week
2015-05-08 17:48:48 +00:00
Hans Petter Selasky
9dd1273385 Add support for more than 8 audio channels per PCM stream for USB
audio class compliant devices under FreeBSD. Tested using 16 recording
and 16 playback audio channels simultaneously.

MFC after:	2 weeks
2015-05-08 17:07:11 +00:00
Hans Petter Selasky
87087b85a7 Use the feedback value from the synchronization endpoint as fallback
when there is no recording channel.

MFC after:	3 days
PR: 		198444
2015-03-24 09:21:53 +00:00
Hans Petter Selasky
85bad58226 The synchronisation value returned by the so-called feedback endpoint
appears to be too inaccurate that it can be used to synchronize the
playback data stream. If there is a recording endpoint associated with
the playback endpoint, use that instead. That means if the isochronous
OUT endpoint is asynchronus the USB audio driver will automatically
start recording, if possible, to get exact information about the
needed sample rate adjustments. In no recording endpoint is present,
no rate adaption will be done.

While at it fix an issue where the hardware buffer pointers don't get
reset at the first device PCM trigger.

Make some variables 32-bit to avoid problems with multithreading.

MFC after:	3 days
PR: 		198444
2015-03-21 09:45:45 +00:00
Hans Petter Selasky
a931ce6758 Revert r274918 and make a better solution. Poll the synchronisation
endpoint less frequently to make the sample rate adjustment more
accurate. This should resolve problems with the DN32-USB module for
Midas audio systems and possibly other similar products from Klark
Teknik.

MFC after:	3 days
2015-02-10 12:08:52 +00:00
Hans Petter Selasky
ece4b0bd43 Make a bunch of USB debug SYSCTLs tunable, so that their value(s) can
be set before the USB device(s) are probed.
2015-01-05 15:04:17 +00:00
Hans Petter Selasky
26ec349199 Don't use the synchronization endpoint unless referenced by the
isochronous endpoint descriptor used for the data transfers, hence the
synchronization feature might not be supposed to be supported [yet].
This makes seamless playback synced with the USB HOST clock work with
the DN32-USB module for Midas audio systems and possibly other similar
products from Klark Teknik.

MFC after:	1 week
2014-11-23 16:27:31 +00:00
Hans Petter Selasky
8bf51ab563 Instead of creating the full range of possible ports, try to figure
out the actual number of so-called "embedded jacks" which are present
when a USB MIDI device is attaching.

MFC after:	3 days
2014-09-28 12:55:13 +00:00
Hans Petter Selasky
113336eec2 Update mixer description for FastTrackPro.
MFC after:	3 days
2014-09-07 07:23:33 +00:00
Hans Petter Selasky
f09566d3bd Use the "bSubslotSize" and "bSubFrameSize" fields to obtain the actual
sample size. According to the USB audio frame format specification
from USB.org, the value in the "bBitResolution" field can be less than
the actual sample size, depending on the actual hardware, and should
not be used for this computation.

PR:		192755
MFC after:	1 week
2014-08-18 14:30:43 +00:00
Hans Petter Selasky
af3b2549c4 Pull in r267961 and r267973 again. Fix for issues reported will follow. 2014-06-28 03:56:17 +00:00
Glen Barber
37a107a407 Revert r267961, r267973:
These changes prevent sysctl(8) from returning proper output,
such as:

 1) no output from sysctl(8)
 2) erroneously returning ENOMEM with tools like truss(1)
    or uname(1)
 truss: can not get etype: Cannot allocate memory
2014-06-27 22:05:21 +00:00
Hans Petter Selasky
3da1cf1e88 Extend the meaning of the CTLFLAG_TUN flag to automatically check if
there is an environment variable which shall initialize the SYSCTL
during early boot. This works for all SYSCTL types both statically and
dynamically created ones, except for the SYSCTL NODE type and SYSCTLs
which belong to VNETs. A new flag, CTLFLAG_NOFETCH, has been added to
be used in the case a tunable sysctl has a custom initialisation
function allowing the sysctl to still be marked as a tunable. The
kernel SYSCTL API is mostly the same, with a few exceptions for some
special operations like iterating childrens of a static/extern SYSCTL
node. This operation should probably be made into a factored out
common macro, hence some device drivers use this. The reason for
changing the SYSCTL API was the need for a SYSCTL parent OID pointer
and not only the SYSCTL parent OID list pointer in order to quickly
generate the sysctl path. The motivation behind this patch is to avoid
parameter loading cludges inside the OFED driver subsystem. Instead of
adding special code to the OFED driver subsystem to post-load tunables
into dynamically created sysctls, we generalize this in the kernel.

Other changes:
- Corrected a possibly incorrect sysctl name from "hw.cbb.intr_mask"
to "hw.pcic.intr_mask".
- Removed redundant TUNABLE statements throughout the kernel.
- Some minor code rewrites in connection to removing not needed
TUNABLE statements.
- Added a missing SYSCTL_DECL().
- Wrapped two very long lines.
- Avoid malloc()/free() inside sysctl string handling, in case it is
called to initialize a sysctl from a tunable, hence malloc()/free() is
not ready when sysctls from the sysctl dataset are registered.
- Bumped FreeBSD version to indicate SYSCTL API change.

MFC after:	2 weeks
Sponsored by:	Mellanox Technologies
2014-06-27 16:33:43 +00:00
Hans Petter Selasky
af26e3dfe7 Make sure the USB audio driver is loaded last. This is important when
built as part of a kernel module to prevent panics when the USB audio
driver kernel module is unloaded.

Suggested by:	marius @
MFC after:	1 week
2014-05-14 11:25:59 +00:00
Hans Petter Selasky
e91fe3a904 Workaround for USB MIDI adapters which use non-supported values of
wMaxPacketSize for BULK endpoints.

MFC after:	1 week
2014-03-14 08:42:30 +00:00
Hans Petter Selasky
2c2752d351 Add support for more sample rates to USB audio driver.
Submitted by:	Shunsuke Suganuma <3226388001@jcom.home.ne.jp>
PR:		usb/171254
MFC after:	1 week
2014-03-14 07:11:33 +00:00
Hans Petter Selasky
e5359a3bba Don't clear stall at first time use of USB MIDI endpoints.
Most likely some non-USB compliant devices will choke on it
sooner or later. Clear stall is strictly speaking not needed.
If the first MIDI command sent or transmitted is lost, this
is not a big problem for us.

MFC after:	1 week
2013-05-18 07:16:20 +00:00
Hans Petter Selasky
33da3daa40 Fix issue with "Logitech Webcam C525":
Set a valid alternate interface setting
when enumerating USB audio devices else
the device mentioned will not work like
expected.

PR:		usb/178722
MFC after:	1 week
2013-05-18 07:03:06 +00:00