History log of /freebsd-current/sys/dev/sound/usb/uaudio.c
Revision Date Author Comments
# 923e0040 06-May-2024 Christos Margiolis <christos@FreeBSD.org>

sound: Move chip.h contents to pcm/sound.h

Sponsored by: The FreeBSD Foundation
MFC after: 1 week
Reviewed by: markj
Differential Revision: https://reviews.freebsd.org/D44997


# 44e128fe 11-Apr-2024 Christos Margiolis <christos@FreeBSD.org>

sound: Implement asynchronous device detach

Hot-unplugging a sound device, such as a USB sound card, whilst being
consumed by an application, results in an infinite loop until either the
application closes the device's file descriptor, or the channel
automatically times out after hw.snd.timeout seconds. In the case of a
detach however, the timeout approach is still not ideal, since we want
all resources to be released immediatelly, without waiting for N seconds
until we can use the bus again.

The timeout mechanism works by calling chn_sleep() in chn_read() and
chn_write() (see pcm/channel.c) in order to send the thread to sleep,
using cv_timedwait_sig(). Since chn_sleep() sets the CHN_F_SLEEPING flag
while waiting for cv_timedwait_sig() to return, we can test this flag in
pcm_unregister() (called during detach) and wakeup the sleeping
thread(s) to immediately kill the channel(s) being consumed.

Sponsored by: The FreeBSD Foundation
MFC after: 2 months
PR: 194727
Reviewed by: dev_submerge.ch, bapt, markj
Differential Revision: https://reviews.freebsd.org/D43545


# 365067e9 04-Apr-2024 Christos Margiolis <christos@FreeBSD.org>

Revert "sound: Implement asynchronous device detach"

This reverts commit 9eff58c6d52b66eb8abe7f724dabcd804a566df4.

We are reverting dc831e93bad6 ("sound: Get rid of snd_clone and use
DEVFS_CDEVPRIV(9)"), so revert this commit as well since it depends
dc831e93bad6.


# 9eff58c6 31-Mar-2024 Christos Margiolis <christos@FreeBSD.org>

sound: Implement asynchronous device detach

Hot-unplugging a sound device, such as a USB sound card, whilst being
consumed by an application, results in an infinite loop until either the
application closes the device's file descriptor, or the channel
automatically times out after hw.snd.timeout seconds. In the case of a
detach however, the timeout approach is still not ideal, since we want
all resources to be released immediatelly, without waiting for N seconds
until we can use the bus again.

The timeout mechanism works by calling chn_sleep() in chn_read() and
chn_write() (see pcm/channel.c) in order to send the thread to sleep,
using cv_timedwait_sig(). Since chn_sleep() sets the CHN_F_SLEEPING flag
while waiting for cv_timedwait_sig() to return, we can test this flag in
pcm_unregister() (called during detach) and wakeup the sleeping
thread(s) to immediately kill the channel(s) being consumed.

Sponsored by: The FreeBSD Foundation
MFC after: 2 months
PR: 194727, 278055, 202275, 220949, 272286
Reviewed by: dev_submerge.ch, markj
Differential Revision: https://reviews.freebsd.org/D43545


# a9341f0f 26-Feb-2024 Florian Walpen <dev@submerge.ch>

snd_uaudio(4): Fix sample rate selection after 42fdcd9fd917.

The sample rate selection of snd_uaudio(4) at runtime was implicitly
relying on a specific order in the device config list. In case a default
was set through the hw.usb.uaudio.default_rate sysctl tunable, commit
42fdcd9fd917 removed a duplicate sample rate entry from that list, which
inadvertently broke sample rate selection at runtime. Implement sample
rate selection in a way that works for any order in the device config
list.

Reported by: Lexi Winter <lexi@le-fay.org>
MFC after: 1 week
Reviewed by: christos
Differential Revision: https://reviews.freebsd.org/D44051


# f60e99f4 12-Feb-2024 Christos Margiolis <christos@FreeBSD.org>

snd_uaudio: mark selected configurations

snd_uaudio(4) selects the first maching rate/channel/bit/format/buffer
configuration for use during attach, even though it will print the rest
of the supported configurations detected. To make this clear, mark the
selected playback and recording configurations with a "selected" string.

Sponsored by: The FreeBSD Foundation
MFC after: 2 weeks
Reviewed by: dev_submerge.ch
Differential Revision: https://reviews.freebsd.org/D43766


# 42fdcd9f 12-Feb-2024 Florian Walpen <dev@submerge.ch>

snd_uaudio(4): Fix config detection with defaults set.

Let the USB audio descriptor iteration detect configurations with more
channels and larger sample size, even when the following global sysctl
tunables are set to a lower value:

hw.usb.uaudio.default_channels hw.usb.uaudio.default_bits

This improves utility and is closer to the meaning of default.

Also, do not create duplicate sample rate entries.

MFC after: 2 weeks
Reviewed by: christos
Differential Revision: https://reviews.freebsd.org/D43679


# b2e97edf 12-Feb-2024 Florian Walpen <dev@submerge.ch>

snd_uaudio(4): Adapt buffer length to buffer_ms tunable.

Adapt the length of the driver side audio buffer to the USB transfer
interval, which is adjustable through the buffer_ms tunable. This
eliminates unnecessary latency in USB audio playback.

To reduce power consumption caused by frequent CPU wakeups, increase the
default buffer_ms value to 4ms. In combination with adaptive buffer
length, this still results in less roundtrip latency compared to the
previous 2ms default.

Extend the buffer_ms value range to 1ms for low latency applications.

MFC after: 2 weeks
Reviewed by: christos
Differential Revision: https://reviews.freebsd.org/D41942


# f7d3d0a4 22-Jan-2024 Christos Margiolis <christos@FreeBSD.org>

sound: use device_set_descf() to set device descriptions

Commit 6b6914c1e21b introduced a printf-like version of
device_set_desc(), so use it to simplify device description setting in
the audio stack.

Sponsored by: The FreeBSD Foundation
MFC after: 2 weeks
Reviewed by: dev_submerge.ch, markj
Differential Revision: https://reviews.freebsd.org/D43467


# 06a43763 16-Jan-2024 Christos Margiolis <christos@FreeBSD.org>

snd_uaudio: prefix module declaration with "snd_"

Although the module is compiled "snd_uaudio.ko", follow the rest of the
sound modules' naming convention in the declaration as well.

Sponsored by: The FreeBSD Foundation
MFC after: 2 weeks
Reviewed by: imp, emaste
Differential Revision: https://reviews.freebsd.org/D43396


# 837cd192 16-Jan-2024 Christos Margiolis <christos@FreeBSD.org>

sound: remove PCM_KLDSTRING() and fix status strings

PCM_KLDSTRING() prints the kernel module associated with a given audio
device only when that module is not compiled in. Get rid of
PCM_KLDSTRING() altogether and print the driver name (even for modules
that are compiled in) instead, as it implies the module as well.

While here, convert all status strings to the following dmesg-like
format:

[<port|mem> <irq>] on <driver>

Sponsored by: The FreeBSD Foundation
MFC after: 2 weeks
Reviewed by: markj, imp
Differential Revision: https://reviews.freebsd.org/D43349


# 18d87fe4 16-Jan-2024 Christos Margiolis <christos@FreeBSD.org>

snd_uaudio: provide information about the device name and attached driver

Unlike the other sound drivers, snd_uaudio(4) doesn't provide
information about the device's description and the driver it's attached
to. A side-effect of this is that applications such as mixer(8), that
fetch these strings through the OSS API's SNDCTL_CARDINFO ioctl will
show a USB audio device as:

pcm0:mixer: <USB Audio> at ? kld snd_uaudio

This patch replaces the generic "USB Audio" description with the
device's actual manufacturer and product strings, and the "at ?" string
with the driver it's attached to:

pcm0:mixer: <Focusrite Scarlett Solo USB> at uaudio0 kld snd_uaudio

Sponsored by: The FreeBSD Foundation
MFC after: 2 weeks
Reviewed by: markj, emaste
Differential Revision: https://reviews.freebsd.org/D43347


# 685dc743 16-Aug-2023 Warner Losh <imp@FreeBSD.org>

sys: Remove $FreeBSD$: one-line .c pattern

Remove /^[\s*]*__FBSDID\("\$FreeBSD\$"\);?\s*\n/


# 71625ec9 16-Aug-2023 Warner Losh <imp@FreeBSD.org>

sys: Remove $FreeBSD$: one-line .c comment pattern

Remove /^/[*/]\s*\$FreeBSD\$.*\n/


# b61a5730 10-May-2023 Warner Losh <imp@FreeBSD.org>

spdx: The BSD-2-Clause-NetBSD identifier is obsolete, drop -NetBSD

The SPDX folks have obsoleted the BSD-2-Clause-NetBSD identifier. Catch
up to that fact and revert to their recommended match of BSD-2-Clause.

Discussed with: pfg
MFC After: 3 days
Sponsored by: Netflix


# 3390adfe 06-May-2022 John Baldwin <jhb@FreeBSD.org>

sound: Remove unused devclass arguments to DRIVER_MODULE.


# f190f8d1 19-Feb-2022 Hans Petter Selasky <hselasky@FreeBSD.org>

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


# 2fcd7d38 17-Dec-2021 Hans Petter Selasky <hselasky@FreeBSD.org>

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


# 11f09b17 09-Nov-2021 Hans Petter Selasky <hselasky@FreeBSD.org>

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


# 3d6ed119 07-Nov-2021 Gordon Bergling <gbe@FreeBSD.org>

usb_audio: Fix a typo in a source code comment

- s/maxium/maximum/

MFC after: 3 days


# 31070b5b 09-Mar-2021 Hans Petter Selasky <hselasky@FreeBSD.org>

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


# 12148d43 14-Feb-2021 Hans Petter Selasky <hselasky@FreeBSD.org>

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


# eead9017 01-Jan-2021 Vladimir Kondratyev <wulf@FreeBSD.org>

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)


# 67de2db2 04-Oct-2020 Vladimir Kondratyev <wulf@FreeBSD.org>

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


# f14436ad 12-Nov-2020 Hans Petter Selasky <hselasky@FreeBSD.org>

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


# 378503af 01-Sep-2020 Mateusz Guzik <mjg@FreeBSD.org>

sound: clean up empty lines in .c and .h files


# 42a18f32 19-Aug-2020 Hans Petter Selasky <hselasky@FreeBSD.org>

Print current buffer latency in dmesg for the USB audio driver and not just
the maximum.

MFC after: 1 week
Sponsored by: Mellanox Technologies


# 94140f47 22-Jul-2020 Mark Johnston <markj@FreeBSD.org>

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


# 75dc9c41 20-Jun-2020 Hans Petter Selasky <hselasky@FreeBSD.org>

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


# 86c9b3f3 30-Mar-2020 Hans Petter Selasky <hselasky@FreeBSD.org>

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


# c2bc9ff7 27-Mar-2020 Hans Petter Selasky <hselasky@FreeBSD.org>

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


# a0be3628 26-Mar-2020 Hans Petter Selasky <hselasky@FreeBSD.org>

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


# 91feacd1 26-Mar-2020 Hans Petter Selasky <hselasky@FreeBSD.org>

Make mute controls available for USB audio mixers.

Submitted by: Horse Ma <Shichun.Ma@dell.com>
MFC after: 1 week
Sponsored by: Mellanox Technologies


# edabe1ee 26-Mar-2020 Hans Petter Selasky <hselasky@FreeBSD.org>

Factor out USB audio mixer value range check.

MFC after: 1 week
Sponsored by: Mellanox Technologies


# 7e88777b 26-Mar-2020 Hans Petter Selasky <hselasky@FreeBSD.org>

Avoid scaling USB audio mixer values twice.

MFC after: 1 week
Sponsored by: Mellanox Technologies


# f8d2b1f3 15-Feb-2020 Pawel Biernacki <kaktus@FreeBSD.org>

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


# 9de921ee 30-Jan-2019 Hans Petter Selasky <hselasky@FreeBSD.org>

Export vendor specific USB MIDI device list to PnP info.

MFC after: 1 week
Sponsored by: Mellanox Technologies


# f4dbf0d8 12-Jan-2019 Hans Petter Selasky <hselasky@FreeBSD.org>

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


# a89c8065 25-Dec-2018 Hans Petter Selasky <hselasky@FreeBSD.org>

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


# fb8a716d 07-Nov-2018 Hans Petter Selasky <hselasky@FreeBSD.org>

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


# 718cf2cc 27-Nov-2017 Pedro F. Giffuni <pfg@FreeBSD.org>

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.


# 067e471a 17-Jan-2017 Hans Petter Selasky <hselasky@FreeBSD.org>

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


# 82364f24 09-Nov-2016 Hans Petter Selasky <hselasky@FreeBSD.org>

Allow higher sample rates to have more jitter than lower ones.

PR: 208791
MFC after: 3 days


# dd3dde98 08-Nov-2016 Hans Petter Selasky <hselasky@FreeBSD.org>

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


# 4d76235f 19-Oct-2016 Hans Petter Selasky <hselasky@FreeBSD.org>

Add support for adjusting the hardware buffering delay for USB audio.

Requested by: Goran Mekic <meka@tilda.center>
MFC after: 1 week


# d56d9e27 31-May-2016 Hans Petter Selasky <hselasky@FreeBSD.org>

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


# 057b4402 26-Apr-2016 Pedro F. Giffuni <pfg@FreeBSD.org>

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.


# f809f280 10-Dec-2015 Warner Losh <imp@FreeBSD.org>

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


# 8c20de92 08-May-2015 Hans Petter Selasky <hselasky@FreeBSD.org>

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


# 9dd12733 08-May-2015 Hans Petter Selasky <hselasky@FreeBSD.org>

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


# 87087b85 24-Mar-2015 Hans Petter Selasky <hselasky@FreeBSD.org>

Use the feedback value from the synchronization endpoint as fallback
when there is no recording channel.

MFC after: 3 days
PR: 198444


# 85bad582 21-Mar-2015 Hans Petter Selasky <hselasky@FreeBSD.org>

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


# a931ce67 09-Feb-2015 Hans Petter Selasky <hselasky@FreeBSD.org>

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


# ece4b0bd 05-Jan-2015 Hans Petter Selasky <hselasky@FreeBSD.org>

Make a bunch of USB debug SYSCTLs tunable, so that their value(s) can
be set before the USB device(s) are probed.


# 26ec3491 23-Nov-2014 Hans Petter Selasky <hselasky@FreeBSD.org>

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


# 8bf51ab5 27-Sep-2014 Hans Petter Selasky <hselasky@FreeBSD.org>

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


# 113336ee 07-Sep-2014 Hans Petter Selasky <hselasky@FreeBSD.org>

Update mixer description for FastTrackPro.

MFC after: 3 days


# f09566d3 18-Aug-2014 Hans Petter Selasky <hselasky@FreeBSD.org>

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


# af3b2549 27-Jun-2014 Hans Petter Selasky <hselasky@FreeBSD.org>

Pull in r267961 and r267973 again. Fix for issues reported will follow.


# 37a107a4 27-Jun-2014 Glen Barber <gjb@FreeBSD.org>

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


# 3da1cf1e 27-Jun-2014 Hans Petter Selasky <hselasky@FreeBSD.org>

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


# af26e3df 14-May-2014 Hans Petter Selasky <hselasky@FreeBSD.org>

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


# e91fe3a9 14-Mar-2014 Hans Petter Selasky <hselasky@FreeBSD.org>

Workaround for USB MIDI adapters which use non-supported values of
wMaxPacketSize for BULK endpoints.

MFC after: 1 week


# 2c2752d3 14-Mar-2014 Hans Petter Selasky <hselasky@FreeBSD.org>

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


# e5359a3b 18-May-2013 Hans Petter Selasky <hselasky@FreeBSD.org>

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


# 33da3daa 18-May-2013 Hans Petter Selasky <hselasky@FreeBSD.org>

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


# ffae621e 24-Apr-2013 Hans Petter Selasky <hselasky@FreeBSD.org>

Fix for duplicate sample rate detection after recent patches.


# bf02c706 24-Apr-2013 Hans Petter Selasky <hselasky@FreeBSD.org>

Fix the USB audio feedback endpoint algorithm. There should not
be any need to bias the returned value.

Reported by: Craig Leres <leres@ee.lbl.gov>


# 9b2842ba 24-Apr-2013 Hans Petter Selasky <hselasky@FreeBSD.org>

Fix playback for Focusrite Scarlett 2i2 USB recording interface.

Submitted by: Ed Maste, emaste @


# 455a367f 23-Apr-2013 Hans Petter Selasky <hselasky@FreeBSD.org>

Add support for runtime switching of sample rate for
USB audio devices. Previously the highest sample
rate was unconditionally selected.

Requested by: Craig Leres <leres@ee.lbl.gov>


# 2ba0f361 07-Feb-2013 Hans Petter Selasky <hselasky@FreeBSD.org>

Add support for mute buttons on USB audio devices and
use the hwvol interface to adjust the mixer settings.

MFC after: 1 week


# 76b71212 06-Feb-2013 Hans Petter Selasky <hselasky@FreeBSD.org>

Add support for buttons on USB audio devices,
like Volume Up and Volume Down.

Reviewed by: mav @
MFC after: 1 week


# f7e62ad0 21-Dec-2012 Hans Petter Selasky <hselasky@FreeBSD.org>

Reduce stack usage in the USB audio driver by moving some large stack
elements to the USB audio softc structure. This fixes a double CPU
fault when attaching USB audio devices in 10-current for i386 at
least.

MFC after: 1 week


# 46f0b27a 08-Dec-2012 Hans Petter Selasky <hselasky@FreeBSD.org>

Add support for various Yamaha keyboards.

MFC after: 1 week
PR: usb/174254


# d3e08ca9 01-Nov-2012 Hans Petter Selasky <hselasky@FreeBSD.org>

Correct buffer size printout.

MFC after: 1 week


# 58e8ac5c 01-Nov-2012 Hans Petter Selasky <hselasky@FreeBSD.org>

Increase default volume for FastTracker playback channels.

MFC after: 1 week


# ff4d5953 01-Nov-2012 Hans Petter Selasky <hselasky@FreeBSD.org>

Fix sysctl free bug in last commit, which eventually leads to a panic.
Add software mixer table for FastTrack Ultra.
Only set volume controls which are valid at startup for standard
USB audio devices, so that settings like treble and bass use
the reset defaults.

MFC after: 1 week


# 902514f6 01-Nov-2012 Hans Petter Selasky <hselasky@FreeBSD.org>

Export all mixer nodes into dev.pcm.X.mixer.Y sysctl nodes, hence the
PCM API doesn't support showing all the knobs. Make sure all the USB audio
mixer nodes are freed at detach. Before this patch USB audio would leak
some memory at detach. Print out buffer sizes in number of samples at attach.
Fix setting of volume controls when the number of channels is greater than two.

MFC after: 1 week


# b4380da7 28-Oct-2012 Hans Petter Selasky <hselasky@FreeBSD.org>

Implement support for the so-called USB feedback endpoint for USB
audio devices. This endpoint gives clues to the USB host about the
actual data rate on asynchronous endpoints and makes the more
expensive USB audio devices usable under FreeBSD.
The Linux USB audio driver was used as reference for the
automagic shift of the received value.

MFC after: 1 week


# 76eaf537 25-Oct-2012 Hans Petter Selasky <hselasky@FreeBSD.org>

Make sure the vendor class quirk only matches the vendor specific
class, else multiple pcm devices can appear on certain USB audio
devices.

MFC after: 1 week


# 1234097e 24-Oct-2012 Hans Petter Selasky <hselasky@FreeBSD.org>

Fix USB audio specification compliance by filtering which descriptors can
appear on which interface. This fixes detection of some USB audio adapters.
Also increase the channel limit for FULL speed devices to 4 channels.

Tested by: gavin
MFC after: 1 week


# e2524b2e 17-Sep-2012 Hans Petter Selasky <hselasky@FreeBSD.org>

Implement support for USB Audio v2.0. Remove some redundant
USB audio v1.0 debug data, hence userspace tools like lsusb
exist to show this information properly.


# 6d917491 02-Apr-2012 Hans Petter Selasky <hselasky@FreeBSD.org>

Fix compiler warnings, mostly signed issues,
when USB modules are compiled with WARNS=9.

MFC after: 1 weeks


# 9b5da816 23-Feb-2012 Hans Petter Selasky <hselasky@FreeBSD.org>

Avoid creating PCM devices for MIDI adapters.

MFC after: 3 days


# 11b81ced 13-Dec-2011 Hans Petter Selasky <hselasky@FreeBSD.org>

Use usbd_transfer_unsetup() instead of usbd_transfer_stop() so that
we don't have to worry about locking.

MFC after: 1 weeks


# a6ed4937 13-Dec-2011 Hans Petter Selasky <hselasky@FreeBSD.org>

Stop USB audio transfers early so that any audio applications
will time out and close opened /dev/dspX.Y device(s), if
any. This is a workaround because we cannot unregister PCM
devices while the audio character device is in use.

Add a missing inclusion guard.

MFC after: 1 weeks


# 4b7ec270 22-Nov-2011 Marius Strobl <marius@FreeBSD.org>

- There's no need to overwrite the default device method with the default
one. Interestingly, these are actually the default for quite some time
(bus_generic_driver_added(9) since r52045 and bus_generic_print_child(9)
since r52045) but even recently added device drivers do this unnecessarily.
Discussed with: jhb, marcel
- While at it, use DEVMETHOD_END.
Discussed with: jhb
- Also while at it, use __FBSDID.


# 6472ac3d 07-Nov-2011 Ed Schouten <ed@FreeBSD.org>

Mark all SYSCTL_NODEs static that have no corresponding SYSCTL_DECLs.

The SYSCTL_NODE macro defines a list that stores all child-elements of
that node. If there's no SYSCTL_DECL macro anywhere else, there's no
reason why it shouldn't be static.


# 5dc9d765 06-Sep-2011 Hans Petter Selasky <hselasky@FreeBSD.org>

Fix precedence warning when compiling kernel with clang.

Approved by: re (kib)
Submitted by: dim
MFC after: 1 week


# e0b17a62 14-Jul-2011 Hans Petter Selasky <hselasky@FreeBSD.org>

Restore USB MIDI transmit buffer size to 1Kbyte.

MFC after: 1 week


# 4944c3a8 03-Jul-2011 Hans Petter Selasky <hselasky@FreeBSD.org>

Introduce a quirk for broken USB MIDI hardware instead of limiting performance
in general.

MFC after: 1 week


# 910f1dcf 02-Jul-2011 Hans Petter Selasky <hselasky@FreeBSD.org>

Fix problem about USB MIDI TX data format, that some devices only accept
a maximum of 4 bytes (one command) per short terminated USB transfer.
Optimise the TX case by sending multiple USB frames.

MFC after: 1 week


# f1a16106 23-Jun-2011 Hans Petter Selasky <hselasky@FreeBSD.org>

- Move all USB device ID arrays into so-called sections,
sorted according to the mode which they support:
host, device or dual mode
- Add generic tool to extract these data:
tools/bus_autoconf

Discussed with: imp
Suggested by: Robert Millan <rmh@debian.org>
PR: misc/157903
MFC after: 14 days


# cd10bffa 18-May-2011 Andriy Gapon <avg@FreeBSD.org>

usb: change to one-pass probing of device drivers

This brings USB bus more in line with how newbus is supposed to be used.
Also, because of the two-pass probing the following message was produced
by devd in default configuration when almost any USB device was
connected:
Unknown USB device: vendor <> product <> bus <>
This should be fixed now.

Note that many USB device drivers pass some information from probe
method to attach method via ivars. For this to continue working we rely
on the fact that the subr_bus code calls probe method of a winning driver
again before calling its attach method in the case where multiple
drivers claim to support a device. This is done because device
description is set in successful probe methods and we want to get a correct
device description from a winning driver. So now this logic is re-used
for setting ivars too.

Reviewed by: hselasky
MFC after: 1 month


# f895cc0c 09-May-2011 Hans Petter Selasky <hselasky@FreeBSD.org>

Workaround for broken no-name USB audio devices sold by dealextreme
called "3D sound" and the alike.

MFC after: 14 days


# aca2249d 20-Apr-2011 Hans Petter Selasky <hselasky@FreeBSD.org>

Only set the sample rate if the USB audio channel reports
that it supports the frequency control request.

MFC after: 7 days
Approved by: thompsa (mentor)


# 25b74dab 24-Feb-2011 Hans Petter Selasky <hselasky@FreeBSD.org>

- Add support for some non-standard USB MIDI devices from Roland, by
means of allowing vendor specific interface class for audio and MIDI devices.
- Add new quirks for this. The vendor and product list in OpenBSD's
dev/usb/umidi_quirks.c was used as reference.

MFC after: 14 days
Approved by: thompsa (mentor)


# 6f068a43 18-Feb-2011 Hans Petter Selasky <hselasky@FreeBSD.org>

- Make an enum for all the umidi USB transfers.
- Use the USB stack's builtin clear-stall feature.
- Wrap some long lines.
- Use memcpy() instead of bcopy().
- Use memset() instead of bzero().
- Tested applications:
/usr/ports/audio/fluidsynth

MFC after: 7 days
Approved by: thompsa (mentor)


# 58ccf5b4 11-Jan-2011 John Baldwin <jhb@FreeBSD.org>

Remove unneeded includes of <sys/linker_set.h>. Other headers that use
it internally contain nested includes.

Reviewed by: bde


# a7d5f7eb 19-Oct-2010 Jamie Gritton <jamie@FreeBSD.org>

A new jail(8) with a configuration file, to replace the work currently done
by /etc/rc.d/jail.


# e3e05e50 22-Jun-2010 Andrew Thompson <thompsa@FreeBSD.org>

- fix for USB audio devices which use the 7-byte endpoint descriptor instead of
the 9-byte one.
- remove sync-endpoint code, which is currently unused.

Reported by: Antun Matanovi
Submitted by: Hans Petter Selasky


# 3851442c 22-Jun-2010 Andrew Thompson <thompsa@FreeBSD.org>

Reduce MIDI input buffer size to one USB packet, hence some USB devices don't
properly short terminate their transfers. This fixes a problem where input
appears several seconds late.

Reported by: Alexander Yerenkow
Submitted by: Hans Petter Selasky


# ad658060 29-Apr-2010 Andrew Thompson <thompsa@FreeBSD.org>

MFC r207077

Change USB_DEBUG to #ifdef and allow it to be turned off. Previously this had
the illusion of a tunable setting but was always turned on regardless.


# b850ecc1 22-Apr-2010 Andrew Thompson <thompsa@FreeBSD.org>

Change USB_DEBUG to #ifdef and allow it to be turned off. Previously this had
the illusion of a tunable setting but was always turned on regardless.

MFC after: 1 week


# 82521c15 18-Feb-2010 Rebecca Cran <brucec@FreeBSD.org>

MFC r203678:

Rename usb2_ structures and variables to usb_.

Approved by: rrs (mentor)


# 4c21be9b 08-Feb-2010 Rebecca Cran <brucec@FreeBSD.org>

Rename usb2_ structures and variables to usb_.

Approved by: rrs (mentor)
Discussed with: hps


# a33c9e72 30-Dec-2009 Andrew Thompson <thompsa@FreeBSD.org>

MFC r200825

- add support for more than 2 audio channels. [1]
- add support for more sample rates

Submitted by: [1] ariff (earlier version), Hans Petter Selasky


# afbfddd9 21-Dec-2009 Andrew Thompson <thompsa@FreeBSD.org>

- add support for more than 2 audio channels. [1]
- add support for more sample rates

Submitted by: [1] ariff (earlier version), Hans Petter Selasky


# c9e072d0 09-Dec-2009 Andrew Thompson <thompsa@FreeBSD.org>

MFC r199677

add support for MIDI devices without audio control stream.

Submitted by: Hans Petter Selasky


# e4f658ce 09-Dec-2009 Andrew Thompson <thompsa@FreeBSD.org>

MFC r199576

remove volume alignment (was previously not correctly implemented)


# 9d294893 09-Dec-2009 Andrew Thompson <thompsa@FreeBSD.org>

MFC r199060

Improve support for High-speed USB audio devices.
- fix issues regarding the mixer, where the interface number was not set in
time.
- fix wrong use of resolution parameter.

Submitted by: Hans Petter Selasky


# 40e55da3 09-Dec-2009 Andrew Thompson <thompsa@FreeBSD.org>

MFC r196487

Remove redundant Giant reference. Giant will be dropped
automatically when the mutex argument is NULL.


# dc694251 22-Nov-2009 Andrew Thompson <thompsa@FreeBSD.org>

add support for MIDI devices without audio control stream.

Submitted by: Hans Petter Selasky


# 7fb43570 20-Nov-2009 Andrew Thompson <thompsa@FreeBSD.org>

remove volume alignment (was previously not correctly implemented)

Submitted by: HPS
Reported by: Jaakko Heinonen


# b029f6bb 08-Nov-2009 Andrew Thompson <thompsa@FreeBSD.org>

Improve support for High-speed USB audio devices.
- fix issues regarding the mixer, where the interface number was not set in
time.
- fix wrong use of resolution parameter.

Submitted by: Hans Petter Selasky


# f24b6817 23-Aug-2009 Alfred Perlstein <alfred@FreeBSD.org>

Remove redundant Giant reference. Giant will be dropped
automatically when the mutex argument is NULL.

Reported by: Various people
Submitted by: hps


# 3d11bc19 29-Jul-2009 Alfred Perlstein <alfred@FreeBSD.org>

USB audio:
- code factoring patch from "Eygene Ryabinkin"
- P4 ID: 166149

Submitted by: hps
Approved by: re


# c5e2d188 12-Jul-2009 Marcel Moolenaar <marcel@FreeBSD.org>

Isochronous transfers only have 1 frame buffer, but multiple
frame lengths. The frame buffer is at index 0.

Approved by: re (kensmith)
Obtained from: HPS


# 7e6e6b67 27-Jun-2009 Andrew Thompson <thompsa@FreeBSD.org>

Use the correct mutex in umidi_open()

Submitted by: Hans Petter Selasky
Approved by: re (kib)


# 8f9e0ef9 23-Jun-2009 Andrew Thompson <thompsa@FreeBSD.org>

Fix a typeo in the frame len function to unbreak the build, make it shorter
while I am here.


# ed6d949a 22-Jun-2009 Andrew Thompson <thompsa@FreeBSD.org>

- Make struct usb_xfer opaque so that drivers can not access the internals
- Reduce the number of headers needed for a usb driver, the common case is just usb.h and usbdi.h


# a593f6b8 14-Jun-2009 Andrew Thompson <thompsa@FreeBSD.org>

s/usb2_/usb_|usbd_/ on all function names for the USB stack.


# 90da2b28 07-Jun-2009 Ariff Abdullah <ariff@FreeBSD.org>

Sound Mega-commit. Expect further cleanup until code freeze.

For a slightly thorough explaination, please refer to
[1] http://people.freebsd.org/~ariff/SOUND_4.TXT.html .

Summary of changes includes:

1 Volume Per-Channel (vpc). Provides private / standalone volume control
unique per-stream pcm channel without touching master volume / pcm.
Applications can directly use SNDCTL_DSP_[GET|SET][PLAY|REC]VOL, or for
backwards compatibility, SOUND_MIXER_PCM through the opened dsp device
instead of /dev/mixer. Special "bypass" mode is enabled through
/dev/mixer which will automatically detect if the adjustment is made
through /dev/mixer and forward its request to this private volume
controller. Changes to this volume object will not interfere with
other channels.

Requirements:
- SNDCTL_DSP_[GET|SET][PLAY|REC]_VOL are newer ioctls (OSSv4) which
require specific application modifications (preferred).
- No modifications required for using bypass mode, so applications
like mplayer or xmms should work out of the box.

Kernel hints:
- hint.pcm.%d.vpc (0 = disable vpc).

Kernel sysctls:
- hw.snd.vpc_mixer_bypass (default: 1). Enable or disable /dev/mixer
bypass mode.
- hw.snd.vpc_autoreset (default: 1). By default, closing/opening
/dev/dsp will reset the volume back to 0 db gain/attenuation.
Setting this to 0 will preserve its settings across device
closing/opening.
- hw.snd.vpc_reset (default: 0). Panic/reset button to reset all
volume settings back to 0 db.
- hw.snd.vpc_0db (default: 45). 0 db relative to linear mixer value.

2 High quality fixed-point Bandlimited SINC sampling rate converter,
based on Julius O'Smith's Digital Audio Resampling -
http://ccrma.stanford.edu/~jos/resample/. It includes a filter design
script written in awk (the clumsiest joke I've ever written)
- 100% 32bit fixed-point, 64bit accumulator.
- Possibly among the fastest (if not fastest) of its kind.
- Resampling quality is tunable, either runtime or during kernel
compilation (FEEDER_RATE_PRESETS).
- Quality can be further customized during kernel compilation by
defining FEEDER_RATE_PRESETS in /etc/make.conf.

Kernel sysctls:
- hw.snd.feeder_rate_quality.
0 - Zero-order Hold (ZOH). Fastest, bad quality.
1 - Linear Interpolation (LINEAR). Slightly slower than ZOH,
better quality but still does not eliminate aliasing.
2 - (and above) - Sinc Interpolation(SINC). Best quality. SINC
quality always start from 2 and above.

Rough quality comparisons:
- http://people.freebsd.org/~ariff/z_comparison/

3 Bit-perfect mode. Bypasses all feeder/dsp effects. Pure sound will be
directly fed into the hardware.

4 Parametric (compile time) Software Equalizer (Bass/Treble mixer). Can
be customized by defining FEEDER_EQ_PRESETS in /etc/make.conf.

5 Transparent/Adaptive Virtual Channel. Now you don't have to disable
vchans in order to make digital format pass through. It also makes
vchans more dynamic by choosing a better format/rate among all the
concurrent streams, which means that dev.pcm.X.play.vchanformat/rate
becomes sort of optional.

6 Exclusive Stream, with special open() mode O_EXCL. This will "mute"
other concurrent vchan streams and only allow a single channel with
O_EXCL set to keep producing sound.

Other Changes:
* most feeder_* stuffs are compilable in userland. Let's not
speculate whether we should go all out for it (save that for
FreeBSD 16.0-RELEASE).
* kobj signature fixups, thanks to Andriy Gapon <avg@freebsd.org>
* pull out channel mixing logic out of vchan.c and create its own
feeder_mixer for world justice.
* various refactoring here and there, for good or bad.
* activation of few more OSSv4 ioctls() (see [1] above).
* opt_snd.h for possible compile time configuration:
(mostly for debugging purposes, don't try these at home)
SND_DEBUG
SND_DIAGNOSTIC
SND_FEEDER_MULTIFORMAT
SND_FEEDER_FULL_MULTIFORMAT
SND_FEEDER_RATE_HP
SND_PCM_64
SND_OLDSTEREO

Manual page updates are on the way.

Tested by: joel, Olivier SMEDTS <olivier at gid0 d org>, too many
unsung / unnamed heroes.


# c737a632 04-Jun-2009 Andrew Thompson <thompsa@FreeBSD.org>

revert r162516. We only support 1 or 2 channels per stream
which reflects mono and stereo.

Submitted by: Hans Petter Selasky


# e0a69b51 29-May-2009 Andrew Thompson <thompsa@FreeBSD.org>

s/usb2_/usb_/ on all typedefs for the USB stack.


# 760bc48e 28-May-2009 Andrew Thompson <thompsa@FreeBSD.org>

s/usb2_/usb_/ on all C structs for the USB stack.


# 1ff76828 27-May-2009 Andrew Thompson <thompsa@FreeBSD.org>

Provide a workaround for USB devices that do not support mono or stereo
operation by overriding the channel count.

Submitted by: Hans Petter Selasky
Reported by: MIHIRA Sanpei Yoshiro


# fadc970b 20-May-2009 Andrew Thompson <thompsa@FreeBSD.org>

Fix a few variable renames of usb2_mode outside dev/usb.


# 1d631ee6 20-May-2009 Joel Dahl <joel@FreeBSD.org>

Remove license clauses 3 and 4 as per rev. 1.112 of uaudio.c and rev. 1.15 of
uaudioreg.h in NetBSD.


# 4eae601e 05-Apr-2009 Andrew Thompson <thompsa@FreeBSD.org>

MFp4 //depot/projects/usb@159909

- make usb2_power_mask_t 16-bit
- remove "usb2_config_sub" structure from "usb2_config". To compensate for this
"usb2_config" has a new field called "usb_mode" which select for which mode
the current xfer entry is active. Options are: a) Device mode only b) Host
mode only (default-by-zero) c) Both modes. This change was scripted using
the following sed script: "s/\.mh\././g".
- the standard packet size table in "usb_transfer.c" is now a function, hence
the code for the function uses less memory than the table itself.

Submitted by: Hans Petter Selasky


# 9aef556d 01-Mar-2009 Andrew Thompson <thompsa@FreeBSD.org>

Rename the ushub device class back to uhub as it was in the old usb stack,
moused(8) looks for "uhub/ums" to decide if needs to load the module.

Reported by: Garrett Cooper


# ee3e3ff5 27-Feb-2009 Andrew Thompson <thompsa@FreeBSD.org>

Change USB over to make_dev() for all device nodes, previously it hooked into
the devfs clone handler to open the (invisible) devices on the fly.

The /dev entries are layed out as follows,

/dev/usbctl = master device
/dev/usb/0.1.0.5 = usb device, (<bus>.<dev>.<iface>.<endpoint>)
/dev/ugen0.1 -> usb/0.1.0.0 = ugen link to ctrl endpoint

This also removes the custom permissions model from USB. Bump
__FreeBSD_version to 800066.

Submitted by: rink (earlier version)


# 3a3f90c6 23-Feb-2009 Andrew Thompson <thompsa@FreeBSD.org>

Move the uaudio and ata-usb drivers into their correct locations.


# d7f03759 19-Oct-2008 Ulf Lilleengen <lulf@FreeBSD.org>

- Import the HEAD csup code which is the basis for the cvsmode work.


# 25ee8cca 23-Aug-2008 Warner Losh <imp@FreeBSD.org>

Handle the error case properly for device_get_children.


# 7bd250d8 19-Jun-2007 Warner Losh <imp@FreeBSD.org>

s/logprintf/printf/g

Approved by: re@


# 528fb030 18-Jun-2007 Warner Losh <imp@FreeBSD.org>

Explicitly use usb_port.h to get compat macros.


# e4e61333 15-Jun-2007 Ariff Abdullah <ariff@FreeBSD.org>

Last (again ?!?) major commit for RELENG_7, featuring total Giant
eradication in/from userland path, countless locking fixes, etc.

- General sleep call through msleep(9) has been converted to condvar(9)
with better consistencies.
- Heavily guard every possible "slow path" entries (open(), close(),
few ioctl()s, sysctls), but once it entering "fast path" (io, interrupt
started), they are free to fly on their own.
- Rearrange locking sequences, resulting better concurrency and
serialization. Large part doesn't even need locking at all, and will be
removed in future. Less clutter, except in few places due to lock
ordering.
- Anonymous mixer object creation/deletion to simplify mixer handling
beyond typical mixer ioctls.
Submitted by: chibis (with modifications)
- Add few mix_[get|set|..] functions to avoid calling mixer_ioctl()
directly using cryptic arguments.
- Locking fixes to avoid possible deadlock with (still under Giant) USB.
- Better simplex/duplex device handling.
- Recover mmap() functionality for recording, which has been lost
since 2.2.x - 3.x (the introduction of newpcm). Full-duplex mmap still
doesn't work (due to VM/page design), but people still can mmap
both by opening each direction separately. mmaped playback is guarantee
to work either way.
- New sysctl: "hw.snd.compat_linux_mmap" to allow PROT_EXEC page
mapping, due to recent changes in linux compatibility layer which
require it. All linux applications that using sound + mmap() (mostly games)
require this to be enabled. Disabled by default.
- Other goodies.. too many, that will increase releng7 shareholder value
and make users of releng6 (and below) cry ;)

* This commit should be atomic. If anything goes wrong (not counting problem
originated from elsewhere), I will not hesitate to revert everything back
within 12 hours. This substantial changes itself not a rocket science
and the process has begun for almost 2 years, and lots of incremental
changes are already in place during that period of time.
* Some issues does occur in snd_emu10kx (note the 'x') due to various
internal locking issues and it is currently being worked on by chibis.

Tested by: chibis (Yuriy Tsibizov), joel, Alexandre Vieira,
many innocent souls...


# 645016c0 12-Jun-2007 Warner Losh <imp@FreeBSD.org>

Expand USB_ATTACH_{ERROR,SUCCESS}_RETURN inline and eliminate from
usb_port.h. They aren't needed, and are a legacy of this code's past.


# 471f8f34 10-Jun-2007 Matt Jacob <mjacob@FreeBSD.org>

Remove const type qualifier from a function- gcc4.2 doesn't accept it.

Reviewed by: Ariff


# 1f082787 09-Jun-2007 Ruslan Ermilov <ru@FreeBSD.org>

Make this compile.


# 8d58ce65 09-Jun-2007 Warner Losh <imp@FreeBSD.org>

Expand USB_ATTACH_SETUP inline + devinfo tweaks

# looks like there's a chance that uaudio might compile on otherBSD, so leave
# those #defines alone as well as make this change in a compatible way.


# bba4862c 31-May-2007 Ariff Abdullah <ariff@FreeBSD.org>

Last major commit and updates for RELENG_7:

- Rework the entire pcm_channel structure:
* Remove rarely used link placeholder, instead, make each pcm_channel
as head/link of each own/each other. Unlock - Lock sequence due to
sleep malloc has been reduced.
* Implement "busy" queue which will contain list of busy/active
channels. This greatly reduce locking contention for example while
servicing interrupt for hardware with many channels or when virtual
channels reach its 256 peak channels.

- So I heard you like v chan ... O RLY?
Welcome to Virtual **Record** Channels (vrec, rec vchans, vchans for
recording, Rec-Chan, you decide), the ultimate solutions for your
nagging O_RDWR full-duplex wannabe (note: flash plugins) monopolizing
single record channel causing EBUSY. Vrec works exactly like Vchans
(or, should I rename it to "Vplay" :) , except that it operates on the
opposite direction (recording). Up to 256 vrecs (like vchans) are
possible.

Notes:
* Relocate dev.pcm.%d.{vchans,vchanformat,vchanrate} to each of its
respective node/direction:
dev.pcm.%d.play.* for "play" (cdev = dsp%d.vp%d)
dev.pcm.%d.rec.* for "record" (cdev = dsp%d.vr%d)
* Don't expect that it will magically give you ability to split
"recording source" (eg: 1 channel for cdrom, 1 channel for mic,
etc). Just admit that you only have a *single* recording source /
channel. Please bug your hardware vendor instead :)

- Bump maxautovchans from 4 to 16. For a full-fledged multimedia
desktop/workstation with too many soundservers installed (esound,
artsd, jackd, pulse/polypaudio, ding-dong pling plong mudkip fuh fuh,
etc), 4 seems inadequate. There will be no memory penalty here, since
virtual channels are allocate only by demand.

- Nuke/Rework the entire statically created cdev entries. Everything is
clonable through snd own clone manager which designed to withstand many
kind of abusive devfs droids such as:
* while : ; do /bin/test -e /dev/dsp ; done
* jot 16777216 0 | while read x ; do ls /dev/dsp0.$x ; done
* hundreds (could be thousands) concurrent threads/process opening
"/dev/dsp" (previously, this might result EBUSY even with just
3 contesting threads/procs).
o Reusable clone objects (instead of creating new one like there's no
tomorrow) after certain expiration deadline. The clone allocator will
decide whether to reuse, share, or creating new clone.
o Automatic garbage collector.

- Dynamic unit magic allocator. Maximum attached soundcards can be tuned
using tunable "hw.snd.maxunit" (Default to 512). Minimum is 16, and
maximum is 2048.

- ..other fixes, mostly related to concurrency issues.

joel@ will do the manpage updates on sound(4).

Have fun.


# a9be51ac 01-Apr-2007 Ariff Abdullah <ariff@FreeBSD.org>

Provide hint / tunable for possible asynchronous USB execution. Async
execution should help us avoiding potential deadlock and illegal locking
while sleeping in various mixer -> usb calls. To enable it, use
hint.uaudio.%d.async="1" or sysctl dev.uaudio.%d.async=1. Default is
disable, to remain compatible with old behaviour (with slight risk of
potential deadlock).


# c2bb6a54 31-Mar-2007 Alexander Leidinger <netchild@FreeBSD.org>

Tell interested readers of the source that the return value is not
checked by intend.

Found by: Coverity Prevent (tm)
CID: 55
Reviewed by: ariff


# 7ab4fa8e 16-Mar-2007 Ariff Abdullah <ariff@FreeBSD.org>

[stage: 9/9]

- SWAPLR quirk for (unknown, luckily it is mine) broken uaudio stick.
Fixing by rewiring is impossible without damaging it. Luckily,
we can fix it using "other" methods :) .
- Add uaudio_get_vendor(), _product() and _release() in uaudio.c
(currently used by uaudio_pcm quirk).
- Implement CHANNEL_SETFRAGMENTS().
- Drop channel locking in few places where it is about to sleep
somewhere. This should help eliminating illegal locking acquisition
where the current thread is about to sleep, and also few deadlock
cases. Dropping it right here is quite safe since it is already
protected by CHN_F_BUSY flag and other threads won't bother to touch it.
Solving other illegal locking issues are quite tricky without converting
most usbd_do_request() calls to its equivalent _async() calls,
which I intend to do it later after getting full test report from
other people with different uaudio hardwares.
- Fix memory leak issues during detach. This seems common to any drivers
(notably emu10kx, csapcm?) with bridge functions.


# 3ad47bdd 26-Jan-2007 Ariff Abdullah <ariff@FreeBSD.org>

Sync uaudio_sndstat_prepare_pcm() output with sndstat_prepare_pcm() to get
simmilar (debugging) output.


# cea9c751 06-Jan-2007 Alexander Leidinger <netchild@FreeBSD.org>

Sync with NetBSD:
revision 1.98 is NOT merged, because FreeBSD does not support this
syntax.
revision 1.99 is NOT merged, "const poisoning" part is not applicable
to FreeBSD. There is no variable shadowing, GCC can't find
this one (but there are others)
revision 1.100 is NOT merged, because it was null patch (no changes)
revision 1.101 is NOT merged, there is no BIT() macro in FreeBSD
revision 1.102 is merged
revision 1.103 is partially merged. There is no ai.ifaceh in FreeBSD
revision 1.104 is NOT merged
revision 1.105 is merged
revision 1.106 is not merged, because of rev. 1.107
revision 1.107 is a backuout of 1.106

Submitted by: Yuriy Tsibizov <Yuriy.Tsibizov@gfk.ru>


# a580b31a 25-Nov-2006 Ariff Abdullah <ariff@FreeBSD.org>

Welcome to Once-a-year Sound Mega-Commit. Enjoy numerous updates and fixes
in every sense.

General
-------

- Multichannel safe, endian safe, format safe
* Large part of critical pcm filters such as vchan.c, feeder_rate.c,
feeder_volume.c, feeder_fmt.c and feeder.c has been rewritten so that
using them does not cause the pcm data to be converted to 16bit little
endian.
* Macrosses for accessing pcm data safely are defined within sound.h in
the form of PCM_READ_* / PCM_WRITE_*
* Currently, most of them are probably limited for mono/stereo handling,
but the future addition of true multichannel will be much easier.

- Low latency operation
* Well, this require lot more works to do not just within sound driver,
but we're heading towards right direction. Buffer/block sizing within
channel.c is rewritten to calculate precise allocation for various
combination of sample/data/rate size. As a result, applying correct
SNDCTL_DSP_POLICY value will achive expected latency behaviour simmilar
to what commercial 4front driver do.
* Signal handling fix. ctrl+c of "cat /dev/zero > /dev/dsp" does not
result long delay.
* Eliminate sound truncation if the sound data is too small.
DIY:
1) Download / extract
http://people.freebsd.org/~ariff/lowlatency/shortfiles.tar.gz
2) Do a comparison between "cat state*.au > /dev/dsp" and
"for x in state*.au ; do cat $x > /dev/dsp ; done"
- there should be no "perceivable" differences.
Double close for PR kern/31445.

CAVEAT: Low latency come with (unbearable) price especially for poorly
written applications. Applications that trying to act smarter
by requesting (wrong) blocksize/blockcount will suffer the most.
Fixup samples/patches can be found at:
http://people.freebsd.org/~ariff/ports/

- Switch minimum/maximum sampling rate limit to "1" and "2016000" (48k * 42)
due to closer compatibility with 4front driver.
Discussed with: marcus@ (long time ago?)

- All driver specific sysctls in the form of "hw.snd.pcm%d.*" have been
moved to their own dev sysctl nodes, notably:
hw.snd.pcm%d.vchans -> dev.pcm.%d.vchans
Bump __FreeBSD_version.

Driver specific
---------------

- Ditto for sysctls.

- snd_atiixp, snd_es137x, snd_via8233, snd_hda
* Numerous cleanups and fixes.
* _EXPERIMENTAL_ polling mode support using simple callout_* mechanisme.
This was intended for pure debugging and latency measurement, but proven
good enough in few unexpected and rare cases (such as problematic shared
IRQ with GIANT devices - USB). Polling can be enabled/disabled through
dev.pcm.0.polling. Disabled by default.

- snd_ich
* Fix possible overflow during speed calibration. Delay final
initialization (pcm_setstatus) after calibration finished.
PR: kern/100169
Tested by: Kevin Overman <oberman@es.net>
* Inverted EAPD for few Nec VersaPro.
PR: kern/104715
Submitted by: KAWATA Masahiko <kawata@mta.biglobe.ne.jp>

Thanks to various people, notably Joel Dahl, Yuriy Tsibizov, Kevin Oberman,
those at #freebsd-azalia @ freenode and others for testing.

Joel Dahl will do the manpage update.


# f3ed5ebb 09-Sep-2006 Alexander Leidinger <netchild@FreeBSD.org>

Fix the check where we want to use the end of the supported range if the
value is out of the supported range.

Noticed by: Ed Schouten <ed@fxq.nl>
Reviewed by: Kazuhito HONDA <kazuhito@ph.noda.tus.ac.jp>


# 448ddd74 06-Sep-2006 Scott Long <scottl@FreeBSD.org>

Catch up to USB changes.


# 9d978cc7 05-Feb-2006 Alexander Leidinger <netchild@FreeBSD.org>

Convert NULL checks into KASSERT (and move them before the first
dereferencing) since a NULL value would be a bug here.

Note: Both affected functions look very similar. A refactoring may
be beneficial.

CID: 483, 485
Found with: Coverity Prevent(tm)
Discussed with: ariff
MFC after: 5 days


# 293b843c 29-Dec-2005 Alexander Leidinger <netchild@FreeBSD.org>

Fix some kind of "off by one"-error: the min or max sample rate the
device is able to reproduce should be usable too instead of failing
in such a case.

PR: 89269
Submitted by: Don L. Belcher <don@siad.net>


# 1e558b7e 18-Dec-2005 Ariff Abdullah <ariff@FreeBSD.org>

Precision for AFMT_x24_yE and AFMT_x32_yE should be 24 and 32, respectively.

Submitted by: Kazuhito HONDA <kazuhito@ph.noda.tus.ac.jp>


# f9dff1f9 13-Nov-2005 Alexander Leidinger <netchild@FreeBSD.org>

Add support for 24/32 bit audio formats/conversion.

It may be the case that you may hear some unwanted noise while
playing back with 24/32 bit. This is a problem in the USB system.
Explanation from Hans Petter Selasky:
---snip---
The current USB sound driver only uses one isochronous
buffer, that is restarted when it is completed. This will lead to a short
period of time, +1ms, where no sound data is sent to the external USB device.
Depending on the load of your computer, this can be as much as 50ms. So the
USB sound driver must use 2 isochronous transfers. At the beginning one will
queue both. Then these are restarted on completion. This will result in a
constant-rate data stream to the external sound device, a minimum sound
buffer equal to the size of the isochronous buffer, and possibly the sound
will reach your ears with less delay. Little delay is a result of constant
data rate. Currently only my USB driver will support that. If one tries that
with the USB driver in *BSD, then it will crash at the first moment one gets
a buffer underrun.
---snip---

Submitted by: Kazuhito HONDA <kazuhito@ph.noda.tus.ac.jp>
Mono-recording still not tested by: julian


# c61957b5 18-Sep-2005 Alexander Leidinger <netchild@FreeBSD.org>

Merge NetBSD fixes (except for 1.97 there should be no functional change):
1.94: ansify and KNF (NetBSD KNF).
1.95: Fix DPRINTF (bug from change in 1.94).
1.96: NetBSD specific.
1.97: Fix memory leak reported by Ted Unangst as bug #3 on tech-kern.

Obtained from: NetBSD


# caad7408 11-Sep-2005 Alexander Leidinger <netchild@FreeBSD.org>

Fix a bug in volume calculation, this sometimes gives a USB audio device an
unexpected value (when the volume is high).

Submitted by: Kazuhito HONDA <kazuhito@ph.noda.tus.ac.jp>


# 7f05203a 27-Apr-2005 Julian Elischer <julian@FreeBSD.org>

Add code from Kazuhito HONDA that allows the user to see
the available modes in /dev/sndstat.
e.g.
pcm1: <USB Audio> at addr ? (0p/1r/0v channels duplex)
mode 1:(input) 1ch, 16/16bit, pcm, 44100Hz
mode 2:(input) 1ch, 16/16bit, pcm, 22050Hz
mode 3:(input) 1ch, 16/16bit, pcm, 11025Hz
mode 4:(input) 1ch, 16/16bit, pcm, 8000Hz


# 098ca2bd 05-Jan-2005 Warner Losh <imp@FreeBSD.org>

Start each of the license/copyright comments with /*-, minor shuffle of lines


# 587161d9 25-Dec-2004 Julian Elischer <julian@FreeBSD.org>

Allow selection of a recording source on USB audio devices.

PR: 75316
Submitted by: Kazuhito HONDA <kazuhito at ph dot noda dot tus dot ac dot jp>
Obtained from: NetBSD plus changes
MFC after: 2 weeks


# 65046f86 25-Dec-2004 Julian Elischer <julian@FreeBSD.org>

Allow recording on at least some USB audio devices.

PR: 75311
Submitted by: Kazuhito HONDA <kazuhito at ph dot noda dot tus dot ac dot jp>
Obtained from: NetBSD plus changes
MFC after: 2 weeks


# 2baaf9c2 25-Dec-2004 Julian Elischer <julian@FreeBSD.org>

Allow volume control on more channels/inputs

PR: 75276
Submitted by: Kazuhito HONDA <kazuhito at ph dot noda dot tus dot ac dot jp>
Obtained from: NetBSD with changes
MFC after: 2 weeks


# d28a8145 24-Dec-2004 Julian Elischer <julian@FreeBSD.org>

MFNetBSD:
One of a set of patches submitted by Kazuhito HONDA
to make the usb audio driver a lot more capable.

PR: 75274
Submitted by: Kazuhito HONDA (kazuhito at ph dot noda dot tus dot ac dot jp)
Obtained from: NetBSD (indirectly)
MFC after: 2 weeks


# ba7cd7b6 22-Dec-2004 Poul-Henning Kamp <phk@FreeBSD.org>

Don't include vnode.h


# 760e2cb0 24-Aug-2002 Bruce Evans <bde@FreeBSD.org>

Fixed editing errors in rev.1.4 which manifested as printf format errors
at compile time and probably as panics at runtime.


# 3b7efc56 07-Aug-2002 Josef Karthauser <joe@FreeBSD.org>

Use the hw.usb sysctl tree instead of debug.usb.

Requested by: imp


# 528d1a7f 31-Jul-2002 Josef Karthauser <joe@FreeBSD.org>

Replace the FOO_DEBUG definitions with USB_DEBUG, and switch the
debugging levels to off by default. Now that debug levels can be
tweaked by sysctl we don't need to go through hoops to get the
different usb parts to produce debug data.


# 6ada40b0 31-Jul-2002 Josef Karthauser <joe@FreeBSD.org>

Make this compile with the debugging options switched on.


# 0e6b1966 31-Jul-2002 Josef Karthauser <joe@FreeBSD.org>

Get bored with hard coded debug level variables and introduce a debug.usb
sysctl tree for tweaking them real-time.

Reviewed by: iedowse


# 7c654165 21-Jul-2002 Peter Wemm <peter@FreeBSD.org>

Make this compile.
uaudio.c:1822: warning: `uaudio_ctl_get' defined but not used


# d807a231 21-Jul-2002 Nick Sayer <nsayer@FreeBSD.org>

Add uaudio -- a USB audio device driver.

This driver actually works slightly better on -stable than on -current
(the system locks on detach on -current), so it should be MFC'd somewhat
sooner.

This driver currently points out a difficulty in the sound device framework.
The PCM unregister routine is allowed to refuse the detach if the device is
in use. In the case of a USB device, however, this unregistration is much more
mandatory in nature, since the device is *actually* gone when this call is
made. The sound subsystem really should not refuse an unregistration and
should take its own steps to reject further I/O. As a result, if you detach
a USB sound device while it is in use, you can expect a panic shortly
thereafter.

This device cannot currently record audio. Some routines are unwritten as
of yet in uaudio.c to support recording.

This device hangs my -current box on detach. I don't know why. This does
not happen on my -stable machine.

Obtained from: Hiroyuki Aizu
MFC after: 2 weeks