2019-05-27 13:55:05 +07:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2010-03-05 01:46:13 +07:00
|
|
|
/*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/usb.h>
|
|
|
|
|
|
|
|
#include <sound/core.h>
|
|
|
|
#include <sound/info.h>
|
|
|
|
#include <sound/pcm.h>
|
|
|
|
|
|
|
|
#include "usbaudio.h"
|
|
|
|
#include "helper.h"
|
|
|
|
#include "card.h"
|
2012-04-21 18:52:12 +07:00
|
|
|
#include "endpoint.h"
|
2010-03-05 01:46:13 +07:00
|
|
|
#include "proc.h"
|
|
|
|
|
|
|
|
/* convert our full speed USB rate into sampling rate in Hz */
|
|
|
|
static inline unsigned get_full_speed_hz(unsigned int usb_rate)
|
|
|
|
{
|
|
|
|
return (usb_rate * 125 + (1 << 12)) >> 13;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* convert our high speed USB rate into sampling rate in Hz */
|
|
|
|
static inline unsigned get_high_speed_hz(unsigned int usb_rate)
|
|
|
|
{
|
|
|
|
return (usb_rate * 125 + (1 << 9)) >> 10;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* common proc files to show the usb device info
|
|
|
|
*/
|
|
|
|
static void proc_audio_usbbus_read(struct snd_info_entry *entry, struct snd_info_buffer *buffer)
|
|
|
|
{
|
|
|
|
struct snd_usb_audio *chip = entry->private_data;
|
ALSA: usb-audio: Avoid nested autoresume calls
After the recent fix of runtime PM for USB-audio driver, we got a
lockdep warning like:
=============================================
[ INFO: possible recursive locking detected ]
4.2.0-rc8+ #61 Not tainted
---------------------------------------------
pulseaudio/980 is trying to acquire lock:
(&chip->shutdown_rwsem){.+.+.+}, at: [<ffffffffa0355dac>] snd_usb_autoresume+0x1d/0x52 [snd_usb_audio]
but task is already holding lock:
(&chip->shutdown_rwsem){.+.+.+}, at: [<ffffffffa0355dac>] snd_usb_autoresume+0x1d/0x52 [snd_usb_audio]
This comes from snd_usb_autoresume() invoking down_read() and it's
used in a nested way. Although it's basically safe, per se (as these
are read locks), it's better to reduce such spurious warnings.
The read lock is needed to guarantee the execution of "shutdown"
(cleanup at disconnection) task after all concurrent tasks are
finished. This can be implemented in another better way.
Also, the current check of chip->in_pm isn't good enough for
protecting the racy execution of multiple auto-resumes.
This patch rewrites the logic of snd_usb_autoresume() & co; namely,
- The recursive call of autopm is avoided by the new refcount,
chip->active. The chip->in_pm flag is removed accordingly.
- Instead of rwsem, another refcount, chip->usage_count, is introduced
for tracking the period to delay the shutdown procedure. At
the last clear of this refcount, wake_up() to the shutdown waiter is
called.
- The shutdown flag is replaced with shutdown atomic count; this is
for reducing the lock.
- Two new helpers are introduced to simplify the management of these
refcounts; snd_usb_lock_shutdown() increases the usage_count, checks
the shutdown state, and does autoresume. snd_usb_unlock_shutdown()
does the opposite. Most of mixer and other codes just need this,
and simply returns an error if it receives an error from lock.
Fixes: 9003ebb13f61 ('ALSA: usb-audio: Fix runtime PM unbalance')
Reported-and-tested-by: Alexnader Kuleshov <kuleshovmail@gmail.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-08-25 21:09:00 +07:00
|
|
|
if (!atomic_read(&chip->shutdown))
|
2010-03-05 01:46:13 +07:00
|
|
|
snd_iprintf(buffer, "%03d/%03d\n", chip->dev->bus->busnum, chip->dev->devnum);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void proc_audio_usbid_read(struct snd_info_entry *entry, struct snd_info_buffer *buffer)
|
|
|
|
{
|
|
|
|
struct snd_usb_audio *chip = entry->private_data;
|
ALSA: usb-audio: Avoid nested autoresume calls
After the recent fix of runtime PM for USB-audio driver, we got a
lockdep warning like:
=============================================
[ INFO: possible recursive locking detected ]
4.2.0-rc8+ #61 Not tainted
---------------------------------------------
pulseaudio/980 is trying to acquire lock:
(&chip->shutdown_rwsem){.+.+.+}, at: [<ffffffffa0355dac>] snd_usb_autoresume+0x1d/0x52 [snd_usb_audio]
but task is already holding lock:
(&chip->shutdown_rwsem){.+.+.+}, at: [<ffffffffa0355dac>] snd_usb_autoresume+0x1d/0x52 [snd_usb_audio]
This comes from snd_usb_autoresume() invoking down_read() and it's
used in a nested way. Although it's basically safe, per se (as these
are read locks), it's better to reduce such spurious warnings.
The read lock is needed to guarantee the execution of "shutdown"
(cleanup at disconnection) task after all concurrent tasks are
finished. This can be implemented in another better way.
Also, the current check of chip->in_pm isn't good enough for
protecting the racy execution of multiple auto-resumes.
This patch rewrites the logic of snd_usb_autoresume() & co; namely,
- The recursive call of autopm is avoided by the new refcount,
chip->active. The chip->in_pm flag is removed accordingly.
- Instead of rwsem, another refcount, chip->usage_count, is introduced
for tracking the period to delay the shutdown procedure. At
the last clear of this refcount, wake_up() to the shutdown waiter is
called.
- The shutdown flag is replaced with shutdown atomic count; this is
for reducing the lock.
- Two new helpers are introduced to simplify the management of these
refcounts; snd_usb_lock_shutdown() increases the usage_count, checks
the shutdown state, and does autoresume. snd_usb_unlock_shutdown()
does the opposite. Most of mixer and other codes just need this,
and simply returns an error if it receives an error from lock.
Fixes: 9003ebb13f61 ('ALSA: usb-audio: Fix runtime PM unbalance')
Reported-and-tested-by: Alexnader Kuleshov <kuleshovmail@gmail.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-08-25 21:09:00 +07:00
|
|
|
if (!atomic_read(&chip->shutdown))
|
2010-03-05 01:46:13 +07:00
|
|
|
snd_iprintf(buffer, "%04x:%04x\n",
|
|
|
|
USB_ID_VENDOR(chip->usb_id),
|
|
|
|
USB_ID_PRODUCT(chip->usb_id));
|
|
|
|
}
|
|
|
|
|
|
|
|
void snd_usb_audio_create_proc(struct snd_usb_audio *chip)
|
|
|
|
{
|
2019-02-04 22:07:35 +07:00
|
|
|
snd_card_ro_proc_new(chip->card, "usbbus", chip,
|
|
|
|
proc_audio_usbbus_read);
|
|
|
|
snd_card_ro_proc_new(chip->card, "usbid", chip,
|
|
|
|
proc_audio_usbid_read);
|
2010-03-05 01:46:13 +07:00
|
|
|
}
|
|
|
|
|
2020-04-20 04:21:34 +07:00
|
|
|
static const char * const channel_labels[] = {
|
|
|
|
[SNDRV_CHMAP_NA] = "N/A",
|
|
|
|
[SNDRV_CHMAP_MONO] = "MONO",
|
|
|
|
[SNDRV_CHMAP_FL] = "FL",
|
|
|
|
[SNDRV_CHMAP_FR] = "FR",
|
|
|
|
[SNDRV_CHMAP_FC] = "FC",
|
|
|
|
[SNDRV_CHMAP_LFE] = "LFE",
|
|
|
|
[SNDRV_CHMAP_RL] = "RL",
|
|
|
|
[SNDRV_CHMAP_RR] = "RR",
|
|
|
|
[SNDRV_CHMAP_FLC] = "FLC",
|
|
|
|
[SNDRV_CHMAP_FRC] = "FRC",
|
|
|
|
[SNDRV_CHMAP_RC] = "RC",
|
|
|
|
[SNDRV_CHMAP_SL] = "SL",
|
|
|
|
[SNDRV_CHMAP_SR] = "SR",
|
|
|
|
[SNDRV_CHMAP_TC] = "TC",
|
|
|
|
[SNDRV_CHMAP_TFL] = "TFL",
|
|
|
|
[SNDRV_CHMAP_TFC] = "TFC",
|
|
|
|
[SNDRV_CHMAP_TFR] = "TFR",
|
|
|
|
[SNDRV_CHMAP_TRL] = "TRL",
|
|
|
|
[SNDRV_CHMAP_TRC] = "TRC",
|
|
|
|
[SNDRV_CHMAP_TRR] = "TRR",
|
|
|
|
[SNDRV_CHMAP_TFLC] = "TFLC",
|
|
|
|
[SNDRV_CHMAP_TFRC] = "TFRC",
|
|
|
|
[SNDRV_CHMAP_LLFE] = "LLFE",
|
|
|
|
[SNDRV_CHMAP_RLFE] = "RLFE",
|
|
|
|
[SNDRV_CHMAP_TSL] = "TSL",
|
|
|
|
[SNDRV_CHMAP_TSR] = "TSR",
|
|
|
|
[SNDRV_CHMAP_BC] = "BC",
|
|
|
|
[SNDRV_CHMAP_RLC] = "RLC",
|
|
|
|
[SNDRV_CHMAP_RRC] = "RRC",
|
|
|
|
};
|
|
|
|
|
2010-03-05 01:46:13 +07:00
|
|
|
/*
|
|
|
|
* proc interface for list the supported pcm formats
|
|
|
|
*/
|
|
|
|
static void proc_dump_substream_formats(struct snd_usb_substream *subs, struct snd_info_buffer *buffer)
|
|
|
|
{
|
2013-04-04 04:18:49 +07:00
|
|
|
struct audioformat *fp;
|
2020-01-05 21:47:26 +07:00
|
|
|
static const char * const sync_types[4] = {
|
2010-03-05 01:46:13 +07:00
|
|
|
"NONE", "ASYNC", "ADAPTIVE", "SYNC"
|
|
|
|
};
|
|
|
|
|
2013-04-04 04:18:49 +07:00
|
|
|
list_for_each_entry(fp, &subs->fmt_list, list) {
|
2010-03-05 01:46:15 +07:00
|
|
|
snd_pcm_format_t fmt;
|
2013-04-04 04:18:49 +07:00
|
|
|
|
2010-03-05 01:46:13 +07:00
|
|
|
snd_iprintf(buffer, " Interface %d\n", fp->iface);
|
|
|
|
snd_iprintf(buffer, " Altset %d\n", fp->altsetting);
|
2010-03-05 01:46:15 +07:00
|
|
|
snd_iprintf(buffer, " Format:");
|
2020-02-06 23:39:40 +07:00
|
|
|
pcm_for_each_format(fmt)
|
2013-04-23 06:00:41 +07:00
|
|
|
if (fp->formats & pcm_format_to_bits(fmt))
|
2010-03-05 01:46:15 +07:00
|
|
|
snd_iprintf(buffer, " %s",
|
|
|
|
snd_pcm_format_name(fmt));
|
|
|
|
snd_iprintf(buffer, "\n");
|
2010-03-05 01:46:13 +07:00
|
|
|
snd_iprintf(buffer, " Channels: %d\n", fp->channels);
|
|
|
|
snd_iprintf(buffer, " Endpoint: %d %s (%s)\n",
|
|
|
|
fp->endpoint & USB_ENDPOINT_NUMBER_MASK,
|
|
|
|
fp->endpoint & USB_DIR_IN ? "IN" : "OUT",
|
|
|
|
sync_types[(fp->ep_attr & USB_ENDPOINT_SYNCTYPE) >> 2]);
|
|
|
|
if (fp->rates & SNDRV_PCM_RATE_CONTINUOUS) {
|
|
|
|
snd_iprintf(buffer, " Rates: %d - %d (continuous)\n",
|
|
|
|
fp->rate_min, fp->rate_max);
|
|
|
|
} else {
|
|
|
|
unsigned int i;
|
|
|
|
snd_iprintf(buffer, " Rates: ");
|
|
|
|
for (i = 0; i < fp->nr_rates; i++) {
|
|
|
|
if (i > 0)
|
|
|
|
snd_iprintf(buffer, ", ");
|
|
|
|
snd_iprintf(buffer, "%d", fp->rate_table[i]);
|
|
|
|
}
|
|
|
|
snd_iprintf(buffer, "\n");
|
|
|
|
}
|
2012-10-12 20:12:55 +07:00
|
|
|
if (subs->speed != USB_SPEED_FULL)
|
2010-03-05 01:46:13 +07:00
|
|
|
snd_iprintf(buffer, " Data packet interval: %d us\n",
|
|
|
|
125 * (1 << fp->datainterval));
|
2019-02-18 05:17:21 +07:00
|
|
|
snd_iprintf(buffer, " Bits: %d\n", fp->fmt_bits);
|
2020-04-20 04:21:34 +07:00
|
|
|
|
|
|
|
if (fp->dsd_raw)
|
|
|
|
snd_iprintf(buffer, " DSD raw: DOP=%d, bitrev=%d\n",
|
|
|
|
fp->dsd_dop, fp->dsd_bitrev);
|
|
|
|
|
|
|
|
if (fp->chmap) {
|
|
|
|
const struct snd_pcm_chmap_elem *map = fp->chmap;
|
|
|
|
int c;
|
|
|
|
|
|
|
|
snd_iprintf(buffer, " Channel map:");
|
|
|
|
for (c = 0; c < map->channels; c++) {
|
2020-04-22 16:22:55 +07:00
|
|
|
if (map->map[c] >= ARRAY_SIZE(channel_labels) ||
|
2020-04-20 04:21:34 +07:00
|
|
|
!channel_labels[map->map[c]])
|
|
|
|
snd_iprintf(buffer, " --");
|
|
|
|
else
|
|
|
|
snd_iprintf(buffer, " %s",
|
|
|
|
channel_labels[map->map[c]]);
|
|
|
|
}
|
|
|
|
snd_iprintf(buffer, "\n");
|
|
|
|
}
|
|
|
|
|
2010-03-05 01:46:13 +07:00
|
|
|
// snd_iprintf(buffer, " Max Packet Size = %d\n", fp->maxpacksize);
|
|
|
|
// snd_iprintf(buffer, " EP Attribute = %#x\n", fp->attributes);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-13 17:57:39 +07:00
|
|
|
static void proc_dump_ep_status(struct snd_usb_substream *subs,
|
2013-05-17 01:26:17 +07:00
|
|
|
struct snd_usb_endpoint *data_ep,
|
|
|
|
struct snd_usb_endpoint *sync_ep,
|
2012-04-13 17:57:39 +07:00
|
|
|
struct snd_info_buffer *buffer)
|
|
|
|
{
|
2013-05-17 01:26:17 +07:00
|
|
|
if (!data_ep)
|
2012-04-13 17:57:39 +07:00
|
|
|
return;
|
2013-05-17 01:26:17 +07:00
|
|
|
snd_iprintf(buffer, " Packet Size = %d\n", data_ep->curpacksize);
|
2012-04-13 17:57:39 +07:00
|
|
|
snd_iprintf(buffer, " Momentary freq = %u Hz (%#x.%04x)\n",
|
2012-10-12 20:12:55 +07:00
|
|
|
subs->speed == USB_SPEED_FULL
|
2013-05-17 01:26:17 +07:00
|
|
|
? get_full_speed_hz(data_ep->freqm)
|
|
|
|
: get_high_speed_hz(data_ep->freqm),
|
|
|
|
data_ep->freqm >> 16, data_ep->freqm & 0xffff);
|
|
|
|
if (sync_ep && data_ep->freqshift != INT_MIN) {
|
|
|
|
int res = 16 - data_ep->freqshift;
|
2012-04-13 17:57:39 +07:00
|
|
|
snd_iprintf(buffer, " Feedback Format = %d.%d\n",
|
2013-05-17 01:26:17 +07:00
|
|
|
(sync_ep->syncmaxsize > 3 ? 32 : 24) - res, res);
|
2012-04-13 17:57:39 +07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-05 01:46:13 +07:00
|
|
|
static void proc_dump_substream_status(struct snd_usb_substream *subs, struct snd_info_buffer *buffer)
|
|
|
|
{
|
|
|
|
if (subs->running) {
|
|
|
|
snd_iprintf(buffer, " Status: Running\n");
|
|
|
|
snd_iprintf(buffer, " Interface = %d\n", subs->interface);
|
2010-03-05 01:46:14 +07:00
|
|
|
snd_iprintf(buffer, " Altset = %d\n", subs->altset_idx);
|
2013-05-17 01:26:17 +07:00
|
|
|
proc_dump_ep_status(subs, subs->data_endpoint, subs->sync_endpoint, buffer);
|
2010-03-05 01:46:13 +07:00
|
|
|
} else {
|
|
|
|
snd_iprintf(buffer, " Status: Stop\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void proc_pcm_format_read(struct snd_info_entry *entry, struct snd_info_buffer *buffer)
|
|
|
|
{
|
|
|
|
struct snd_usb_stream *stream = entry->private_data;
|
|
|
|
|
|
|
|
snd_iprintf(buffer, "%s : %s\n", stream->chip->card->longname, stream->pcm->name);
|
|
|
|
|
|
|
|
if (stream->substream[SNDRV_PCM_STREAM_PLAYBACK].num_formats) {
|
|
|
|
snd_iprintf(buffer, "\nPlayback:\n");
|
|
|
|
proc_dump_substream_status(&stream->substream[SNDRV_PCM_STREAM_PLAYBACK], buffer);
|
|
|
|
proc_dump_substream_formats(&stream->substream[SNDRV_PCM_STREAM_PLAYBACK], buffer);
|
|
|
|
}
|
|
|
|
if (stream->substream[SNDRV_PCM_STREAM_CAPTURE].num_formats) {
|
|
|
|
snd_iprintf(buffer, "\nCapture:\n");
|
|
|
|
proc_dump_substream_status(&stream->substream[SNDRV_PCM_STREAM_CAPTURE], buffer);
|
|
|
|
proc_dump_substream_formats(&stream->substream[SNDRV_PCM_STREAM_CAPTURE], buffer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void snd_usb_proc_pcm_format_add(struct snd_usb_stream *stream)
|
|
|
|
{
|
|
|
|
char name[32];
|
|
|
|
struct snd_card *card = stream->chip->card;
|
|
|
|
|
|
|
|
sprintf(name, "stream%d", stream->pcm_index);
|
2019-02-04 22:07:35 +07:00
|
|
|
snd_card_ro_proc_new(card, name, stream, proc_pcm_format_read);
|
2010-03-05 01:46:13 +07:00
|
|
|
}
|
|
|
|
|