All of lore.kernel.org
 help / color / mirror / Atom feed
From: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
To: alsa-devel@alsa-project.org
Cc: tiwai@suse.de, broonie@kernel.org,
	Pan Xiuli <xiuli.pan@linux.intel.com>,
	Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
Subject: [alsa-devel] [PATCH 06/13] ASoC: SOF: pcm: harden PCM STOP sequence
Date: Fri, 27 Sep 2019 15:05:31 -0500	[thread overview]
Message-ID: <20190927200538.660-7-pierre-louis.bossart@linux.intel.com> (raw)
In-Reply-To: <20190927200538.660-1-pierre-louis.bossart@linux.intel.com>

From: Pan Xiuli <xiuli.pan@linux.intel.com>

The old STOP sequence is: 1. stop DMA 2. send STOP ipc
If delay happen before the steps 1 and 2, the DMA buffer will be empty in
short time and cause pipeline xrun then stop the pipeline.
Then the step 2 ipc stop will return error as pipeline is already stopped.

Suggested change to avoid the issue is to switch the order of steps 1 and 2
for the stop sequence.

Signed-off-by: Pan Xiuli <xiuli.pan@linux.intel.com>
Signed-off-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
---
 sound/soc/sof/pcm.c | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/sound/soc/sof/pcm.c b/sound/soc/sof/pcm.c
index fa7769dd825c..2b876d497447 100644
--- a/sound/soc/sof/pcm.c
+++ b/sound/soc/sof/pcm.c
@@ -323,6 +323,7 @@ static int sof_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
 	struct sof_ipc_stream stream;
 	struct sof_ipc_reply reply;
 	bool reset_hw_params = false;
+	bool ipc_first = false;
 	int ret;
 
 	/* nothing to do for BE */
@@ -343,6 +344,7 @@ static int sof_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
 	switch (cmd) {
 	case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
 		stream.hdr.cmd |= SOF_IPC_STREAM_TRIG_PAUSE;
+		ipc_first = true;
 		break;
 	case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
 		stream.hdr.cmd |= SOF_IPC_STREAM_TRIG_RELEASE;
@@ -363,6 +365,7 @@ static int sof_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
 	case SNDRV_PCM_TRIGGER_SUSPEND:
 	case SNDRV_PCM_TRIGGER_STOP:
 		stream.hdr.cmd |= SOF_IPC_STREAM_TRIG_STOP;
+		ipc_first = true;
 		reset_hw_params = true;
 		break;
 	default:
@@ -370,12 +373,22 @@ static int sof_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
 		return -EINVAL;
 	}
 
-	snd_sof_pcm_platform_trigger(sdev, substream, cmd);
+	/*
+	 * DMA and IPC sequence is different for start and stop. Need to send
+	 * STOP IPC before stop DMA
+	 */
+	if (!ipc_first)
+		snd_sof_pcm_platform_trigger(sdev, substream, cmd);
 
 	/* send IPC to the DSP */
 	ret = sof_ipc_tx_message(sdev->ipc, stream.hdr.cmd, &stream,
 				 sizeof(stream), &reply, sizeof(reply));
 
+	/* need to STOP DMA even if STOP IPC failed */
+	if (ipc_first)
+		snd_sof_pcm_platform_trigger(sdev, substream, cmd);
+
+	/* free PCM if reset_hw_params is set and the STOP IPC is successful */
 	if (!ret && reset_hw_params)
 		ret = sof_pcm_dsp_pcm_free(substream, sdev, spcm);
 
-- 
2.20.1

_______________________________________________
Alsa-devel mailing list
Alsa-devel@alsa-project.org
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel

  parent reply	other threads:[~2019-09-27 20:09 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-27 20:05 [alsa-devel] [PATCH 00/13] ASoC: SOF: fixes and improvements Pierre-Louis Bossart
2019-09-27 20:05 ` [alsa-devel] [PATCH 01/13] ASoC: SOF: loader: fix kernel oops on firmware boot failure Pierre-Louis Bossart
2019-10-01 17:56   ` [alsa-devel] Applied "ASoC: SOF: loader: fix kernel oops on firmware boot failure" to the asoc tree Mark Brown
2019-09-27 20:05 ` [alsa-devel] [PATCH 02/13] ASoC: SOF: topology: fix parse fail issue for byte/bool tuple types Pierre-Louis Bossart
2019-10-01 17:56   ` [alsa-devel] Applied "ASoC: SOF: topology: fix parse fail issue for byte/bool tuple types" to the asoc tree Mark Brown
2019-09-27 20:05 ` [alsa-devel] [PATCH 03/13] ASoC: SOF: trace: move to opt-in with Kconfig and module parameter Pierre-Louis Bossart
2019-10-01 17:56   ` [alsa-devel] Applied "ASoC: SOF: trace: move to opt-in with Kconfig and module parameter" to the asoc tree Mark Brown
2019-09-27 20:05 ` [alsa-devel] [PATCH 04/13] ASoC: SOF: ipc: retain DSP context after FW exception Pierre-Louis Bossart
2019-10-01 17:56   ` [alsa-devel] Applied "ASoC: SOF: ipc: retain DSP context after FW exception." to the asoc tree Mark Brown
2019-09-27 20:05 ` [alsa-devel] [PATCH 05/13] ASoC: SOF: pcm: fix resource leak in hw_free Pierre-Louis Bossart
2019-10-01 17:56   ` [alsa-devel] Applied "ASoC: SOF: pcm: fix resource leak in hw_free" to the asoc tree Mark Brown
2019-09-27 20:05 ` Pierre-Louis Bossart [this message]
2019-10-01 17:56   ` [alsa-devel] Applied "ASoC: SOF: pcm: harden PCM STOP sequence" " Mark Brown
2019-09-27 20:05 ` [alsa-devel] [PATCH 07/13] ASoC: SOF: core: check for mandatory fw_ready op during SOF probe Pierre-Louis Bossart
2019-10-01 17:56   ` [alsa-devel] Applied "ASoC: SOF: core: check for mandatory fw_ready op during SOF probe" to the asoc tree Mark Brown
2019-09-27 20:05 ` [alsa-devel] [PATCH 08/13] ASoC: SOF: ipc: introduce no_stream_position in sof_ipc_stream_params struct Pierre-Louis Bossart
2019-10-01 17:56   ` [alsa-devel] Applied "ASoC: SOF: ipc: introduce no_stream_position in sof_ipc_stream_params struct" to the asoc tree Mark Brown
2019-09-27 20:05 ` [alsa-devel] [PATCH 09/13] ASoC: SOF: Intel: hda: fix reset of host_period_bytes Pierre-Louis Bossart
2019-10-01 17:56   ` [alsa-devel] Applied "ASoC: SOF: Intel: hda: fix reset of host_period_bytes" to the asoc tree Mark Brown
2019-09-27 20:05 ` [alsa-devel] [PATCH 10/13] ASoC: SOF: Intel: hda: fix warnings during FW load Pierre-Louis Bossart
2019-10-01 17:56   ` [alsa-devel] Applied "ASoC: SOF: Intel: hda: fix warnings during FW load" to the asoc tree Mark Brown
2019-09-27 20:05 ` [alsa-devel] [PATCH 11/13] ASoC: SOF: Intel: initialise and verify FW crash dump data Pierre-Louis Bossart
2019-10-01 17:56   ` [alsa-devel] Applied "ASoC: SOF: Intel: initialise and verify FW crash dump data." to the asoc tree Mark Brown
2019-09-27 20:05 ` [alsa-devel] [PATCH 12/13] ASoC: SOF: Intel: Add context data to any IPC timeout Pierre-Louis Bossart
2019-10-01 17:56   ` [alsa-devel] Applied "ASoC: SOF: Intel: Add context data to any IPC timeout." to the asoc tree Mark Brown
2019-09-27 20:05 ` [alsa-devel] [PATCH 13/13] ASoC: SOF: Intel: hda: Disable DMI L1 entry during capture Pierre-Louis Bossart
2019-10-01 17:56   ` [alsa-devel] Applied "ASoC: SOF: Intel: hda: Disable DMI L1 entry during capture" to the asoc tree Mark Brown

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=20190927200538.660-7-pierre-louis.bossart@linux.intel.com \
    --to=pierre-louis.bossart@linux.intel.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=broonie@kernel.org \
    --cc=tiwai@suse.de \
    --cc=xiuli.pan@linux.intel.com \
    /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.