From: Clemens Ladisch <clemens@ladisch.de>
To: Takashi Iwai <tiwai@suse.de>
Cc: alsa-devel@alsa-project.org, linux1394-devel@lists.sourceforge.net
Subject: [PATCH] [02/29] ALSA: dice: optimize bus reset handling
Date: Mon, 21 Oct 2013 21:21:56 +0200 [thread overview]
Message-ID: <52657ED4.7050709@ladisch.de> (raw)
In-Reply-To: <52657E3B.7040205@ladisch.de>
After a bus reset, do not stop the stream completely to avoid having to
reconfigure the device when restarting the stream.
Signed-off-by: Clemens Ladisch <clemens@ladisch.de>
---
sound/firewire/dice.c | 148 +++++++++++++++++++++++++++++++------------------
1 file changed, 93 insertions(+), 55 deletions(-)
diff --git a/sound/firewire/dice.c b/sound/firewire/dice.c
index ac71b2b..b081021 100644
--- a/sound/firewire/dice.c
+++ b/sound/firewire/dice.c
@@ -559,24 +559,92 @@ static int dice_close(struct snd_pcm_substream *substream)
return 0;
}
-static void dice_stop_stream(struct dice *dice)
+static int dice_stream_start_packets(struct dice *dice)
{
- __be32 channel;
+ int err;
+
+ if (dice->stream_running)
+ return 0;
- if (dice->stream_running) {
- dice_enable_clear(dice);
+ err = amdtp_out_stream_start(&dice->stream, dice->resources.channel,
+ fw_parent_device(dice->unit)->max_speed);
+ if (err < 0)
+ return err;
+ err = dice_enable_set(dice);
+ if (err < 0) {
amdtp_out_stream_stop(&dice->stream);
+ return err;
+ }
- channel = cpu_to_be32((u32)-1);
- snd_fw_transaction(dice->unit, TCODE_WRITE_QUADLET_REQUEST,
- rx_address(dice, RX_ISOCHRONOUS),
- &channel, 4);
+ dice->stream_running = true;
- fw_iso_resources_free(&dice->resources);
+ return 0;
+}
- dice->stream_running = false;
+static int dice_stream_start(struct dice *dice)
+{
+ __be32 channel;
+ int err;
+
+ if (!dice->resources.allocated) {
+ err = fw_iso_resources_allocate(&dice->resources,
+ amdtp_out_stream_get_max_payload(&dice->stream),
+ fw_parent_device(dice->unit)->max_speed);
+ if (err < 0)
+ goto error;
+
+ channel = cpu_to_be32(dice->resources.channel);
+ err = snd_fw_transaction(dice->unit,
+ TCODE_WRITE_QUADLET_REQUEST,
+ rx_address(dice, RX_ISOCHRONOUS),
+ &channel, 4);
+ if (err < 0)
+ goto err_resources;
}
+
+ err = dice_stream_start_packets(dice);
+ if (err < 0)
+ goto err_rx_channel;
+
+ return 0;
+
+err_rx_channel:
+ channel = cpu_to_be32((u32)-1);
+ snd_fw_transaction(dice->unit, TCODE_WRITE_QUADLET_REQUEST,
+ rx_address(dice, RX_ISOCHRONOUS), &channel, 4);
+err_resources:
+ fw_iso_resources_free(&dice->resources);
+error:
+ return err;
+}
+
+static void dice_stream_stop_packets(struct dice *dice)
+{
+ if (!dice->stream_running)
+ return;
+
+ dice_enable_clear(dice);
+
+ amdtp_out_stream_stop(&dice->stream);
+
+ dice->stream_running = false;
+}
+
+static void dice_stream_stop(struct dice *dice)
+{
+ __be32 channel;
+
+ dice_stream_stop_packets(dice);
+
+ if (!dice->resources.allocated)
+ return;
+
+ channel = cpu_to_be32((u32)-1);
+ snd_fw_transaction(dice->unit, TCODE_WRITE_QUADLET_REQUEST,
+ rx_address(dice, RX_ISOCHRONOUS), &channel, 4);
+
+ fw_iso_resources_free(&dice->resources);
}
static int dice_hw_params(struct snd_pcm_substream *substream,
@@ -586,7 +654,7 @@ static int dice_hw_params(struct snd_pcm_substream *substream,
int err;
mutex_lock(&dice->mutex);
- dice_stop_stream(dice);
+ dice_stream_stop(dice);
mutex_unlock(&dice->mutex);
err = snd_pcm_lib_alloc_vmalloc_buffer(substream,
@@ -608,7 +676,7 @@ static int dice_hw_free(struct snd_pcm_substream *substream)
struct dice *dice = substream->private_data;
mutex_lock(&dice->mutex);
- dice_stop_stream(dice);
+ dice_stream_stop(dice);
mutex_unlock(&dice->mutex);
return snd_pcm_lib_free_vmalloc_buffer(substream);
@@ -617,42 +685,17 @@ static int dice_hw_free(struct snd_pcm_substream *substream)
static int dice_prepare(struct snd_pcm_substream *substream)
{
struct dice *dice = substream->private_data;
- struct fw_device *device = fw_parent_device(dice->unit);
- __be32 channel;
int err;
mutex_lock(&dice->mutex);
if (amdtp_out_streaming_error(&dice->stream))
- dice_stop_stream(dice);
-
- if (!dice->stream_running) {
- err = fw_iso_resources_allocate(&dice->resources,
- amdtp_out_stream_get_max_payload(&dice->stream),
- device->max_speed);
- if (err < 0)
- goto error;
-
- //TODO: RX_SEQ_START
- channel = cpu_to_be32(dice->resources.channel);
- err = snd_fw_transaction(dice->unit,
- TCODE_WRITE_QUADLET_REQUEST,
- rx_address(dice, RX_ISOCHRONOUS),
- &channel, 4);
- if (err < 0)
- goto err_resources;
-
- err = amdtp_out_stream_start(&dice->stream,
- dice->resources.channel,
- device->max_speed);
- if (err < 0)
- goto err_resources;
-
- err = dice_enable_set(dice);
- if (err < 0)
- goto err_stream;
+ dice_stream_stop_packets(dice);
- dice->stream_running = true;
+ err = dice_stream_start(dice);
+ if (err < 0) {
+ mutex_unlock(&dice->mutex);
+ return err;
}
mutex_unlock(&dice->mutex);
@@ -660,15 +703,6 @@ static int dice_prepare(struct snd_pcm_substream *substream)
amdtp_out_stream_pcm_prepare(&dice->stream);
return 0;
-
-err_stream:
- amdtp_out_stream_stop(&dice->stream);
-err_resources:
- fw_iso_resources_free(&dice->resources);
-error:
- mutex_unlock(&dice->mutex);
-
- return err;
}
static int dice_trigger(struct snd_pcm_substream *substream, int cmd)
@@ -941,7 +975,7 @@ static void dice_remove(struct fw_unit *unit)
mutex_lock(&dice->mutex);
amdtp_out_stream_pcm_abort(&dice->stream);
- dice_stop_stream(dice);
+ dice_stream_stop(dice);
dice_owner_clear(dice);
mutex_unlock(&dice->mutex);
@@ -953,8 +987,8 @@ static void dice_bus_reset(struct fw_unit *unit)
struct dice *dice = dev_get_drvdata(&unit->device);
mutex_lock(&dice->mutex);
+
/*
- * XXX is the following true?
* On a bus reset, the DICE firmware disables streaming and then goes
* off contemplating its own navel for hundreds of milliseconds before
* it can react to any of our attempts to reenable streaming. This
@@ -962,9 +996,13 @@ static void dice_bus_reset(struct fw_unit *unit)
* to stop so that the application can restart them in an orderly
* manner.
*/
- dice_owner_update(dice);
amdtp_out_stream_pcm_abort(&dice->stream);
- dice_stop_stream(dice);
+ dice_stream_stop_packets(dice);
+
+ dice_owner_update(dice);
+
+ fw_iso_resources_update(&dice->resources);
+
mutex_unlock(&dice->mutex);
}
------------------------------------------------------------------------------
October Webinars: Code for Performance
Free Intel webinars can help you accelerate application performance.
Explore tips for MPI, OpenMP, advanced profiling, and more. Get the most from
the latest Intel processors and coprocessors. See abstracts and register >
http://pubads.g.doubleclick.net/gampad/clk?id=60135991&iu=/4140/ostg.clktrk
next prev parent reply other threads:[~2013-10-21 19:21 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-10-21 19:19 [GIT PULL] [00/29] playback-only DICE driver Clemens Ladisch
2013-10-21 19:21 ` [PATCH] [01/29] ALSA: add " Clemens Ladisch
2013-10-21 19:21 ` Clemens Ladisch [this message]
2013-10-21 19:22 ` [PATCH] [03/29] ALSA: dice: allow all sample rates Clemens Ladisch
2013-10-21 19:23 ` [PATCH] [04/29] ALSA: dice: reduce noisy logging Clemens Ladisch
2013-10-21 19:23 ` [PATCH] [05/29] ALSA: dice, firewire-lib: add blocking mode Clemens Ladisch
2013-10-21 19:24 ` [PATCH] [06/29] ALSA: dice: fix hang when unplugging a running device Clemens Ladisch
2013-10-21 19:24 ` [PATCH] [07/29] ALSA: dice: implement hwdep device Clemens Ladisch
2013-10-21 19:25 ` [PATCH] [08/29] ALSA: dice: clear device lock when closing " Clemens Ladisch
2013-10-21 19:25 ` [PATCH] [09/29] ALSA: firewire: introduce amdtp_out_stream_running() Clemens Ladisch
2013-10-21 19:26 ` [PATCH] [10/29] ALSA: dice: reorganize interface definitions Clemens Ladisch
2013-10-21 19:26 ` [PATCH] [11/29] ALSA: dice: fix device detection for other vendors Clemens Ladisch
2013-10-21 19:27 ` [PATCH] [12/29] ALSA: dice: support dual-wire stream format at 192 kHz Clemens Ladisch
2013-10-21 19:27 ` [PATCH] [13/29] ALSA: dice: optimize reading of consecutive registers Clemens Ladisch
2013-10-21 19:28 ` [PATCH] [14/29] ALSA: firewire: extend snd_fw_transaction() Clemens Ladisch
2013-10-21 19:29 ` [PATCH] [15/29] ALSA: dice: avoid superflous write at bus reset Clemens Ladisch
2013-10-21 19:29 ` [PATCH] [16/29] ALSA: dice: remove 10s period length limit Clemens Ladisch
2013-10-21 19:30 ` [PATCH] [17/29] ALSA: dice: remove superfluous field Clemens Ladisch
2013-10-21 19:31 ` [PATCH] [18/29] ALSA: dice: fix locking Clemens Ladisch
2013-10-21 19:31 ` [PATCH] [19/29] ALSA: dice: make amdtp_rates[] const Clemens Ladisch
2013-10-21 19:32 ` [PATCH] [20/29] ALSA: dice: get clock capabilities Clemens Ladisch
2013-10-21 19:32 ` [PATCH] [21/29] ALSA: dice: allow notifications during initialization Clemens Ladisch
2013-10-21 19:33 ` [PATCH] [22/29] ALSA: dice: get rate-dependent parameters Clemens Ladisch
2013-10-21 19:34 ` [PATCH] [23/29] ALSA: dice: dynamic sample rate selection Clemens Ladisch
2013-10-21 19:34 ` [PATCH] [24/29] ALSA: dice: check clock change timeout Clemens Ladisch
2013-10-21 19:34 ` [PATCH] [25/29] ALSA: dice: add a proc file to show device information Clemens Ladisch
2013-10-21 19:35 ` [PATCH] [26/29] ALSA: dice: document quadlet alignment Clemens Ladisch
2013-10-21 19:40 ` [PATCH] [27/29] ALSA: dice: dice_proc_read: remove wrong typecast Clemens Ladisch
2013-10-21 19:41 ` [PATCH] [28/29] ALSA: dice: fix detection of Weiss devices Clemens Ladisch
2013-10-21 19:42 ` [PATCH] [29/29] ALSA: dice: restrict the driver to playback-only devices Clemens Ladisch
2013-10-24 9:39 ` [GIT PULL] [00/29] playback-only DICE driver Takashi Iwai
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=52657ED4.7050709@ladisch.de \
--to=clemens@ladisch.de \
--cc=alsa-devel@alsa-project.org \
--cc=linux1394-devel@lists.sourceforge.net \
--cc=tiwai@suse.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.