mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 0/2] ASoC: qcom: qdsp6: handle SMD FIFO -EAGAIN in q6asm playback
@ 2026-11-29  0:19 Vladimir Bely
  2026-11-29  0:19 ` [PATCH 1/2] ASoC: qcom: q6asm: don't advance dsp_buf on failed write or read Vladimir Bely
  2026-11-29  0:19 ` [PATCH 2/2] ASoC: qcom: q6asm-dai: retry playback queuing on -EAGAIN Vladimir Bely
  0 siblings, 2 replies; 3+ messages in thread
From: Vladimir Bely @ 2026-11-29  0:19 UTC (permalink / raw)
  To: Srinivas Kandagatla, Liam Girdwood, Mark Brown
  Cc: Jaroslav Kysela, Takashi Iwai, linux-sound, linux-arm-msm,
	linux-kernel, Vladimir Bely

On older QDSP6 SoCs with small SMD FIFOs (such as MSM8916), queuing a
burst of playback periods in q6asm_dai_ack() via rpmsg_trysend() can
temporarily fill the FIFO and return -EAGAIN, aborting playback right
at start.

This 2-patch series fixes both sides of -EAGAIN handling:

- Patch 1 keeps ac->lock held across apr_send_pkt() in
  q6asm_write_async() and q6asm_read() and only advances port->dsp_buf
  when the packet is queued, so a failed send does not leave dsp_buf
  out of sync on retry.
- Patch 2 introduces a locked q6asm_dai_queue_playback() helper in
  q6asm-dai that stops cleanly on -EAGAIN (also handling
  runtime->boundary wrap-around and initializing prtd->lock on PCM open)
  and retries when the DSP completes a buffer (DATA_WRITE_DONE).

Tested on MSM8916 (Samsung Galaxy A3, SM-A300F).

Vladimir Bely (2):
  ASoC: qcom: q6asm: don't advance dsp_buf on failed write or read
  ASoC: qcom: q6asm-dai: retry playback queuing on -EAGAIN

 sound/soc/qcom/qdsp6/q6asm-dai.c | 58 +++++++++++++++++++++++++-------
 sound/soc/qcom/qdsp6/q6asm.c     | 30 ++++++++---------
 2 files changed, 61 insertions(+), 27 deletions(-)


base-commit: 626d2233d48884f22c16011a6e44f905824bd8e0
-- 
2.43.0


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH 1/2] ASoC: qcom: q6asm: don't advance dsp_buf on failed write or read
  2026-11-29  0:19 [PATCH 0/2] ASoC: qcom: qdsp6: handle SMD FIFO -EAGAIN in q6asm playback Vladimir Bely
@ 2026-11-29  0:19 ` Vladimir Bely
  2026-11-29  0:19 ` [PATCH 2/2] ASoC: qcom: q6asm-dai: retry playback queuing on -EAGAIN Vladimir Bely
  1 sibling, 0 replies; 3+ messages in thread
From: Vladimir Bely @ 2026-11-29  0:19 UTC (permalink / raw)
  To: Srinivas Kandagatla, Liam Girdwood, Mark Brown
  Cc: Jaroslav Kysela, Takashi Iwai, linux-sound, linux-arm-msm,
	linux-kernel, Vladimir Bely, stable

Both q6asm_write_async() and q6asm_read() increment port->dsp_buf and
release ac->lock before calling apr_send_pkt(). If apr_send_pkt() fails
(for instance with -EAGAIN when the SMD FIFO is full), port->dsp_buf
has already advanced past the unsent period, leaving subsequent retries
permanently off by one period in the ring buffer.

apr_send_pkt() is already atomic-safe (it only takes the leaf
adev->svc.lock around rpmsg_trysend()). Keep ac->lock held across
apr_send_pkt() and advance port->dsp_buf only when the packet is
successfully queued.

Fixes: 68fd8480bb7b ("ASoC: qdsp6: q6asm: Add support to audio stream apis")
Cc: stable@vger.kernel.org
Signed-off-by: Vladimir Bely <vlwwwwww@gmail.com>
---
 sound/soc/qcom/qdsp6/q6asm.c | 30 +++++++++++++++---------------
 1 file changed, 15 insertions(+), 15 deletions(-)

diff --git a/sound/soc/qcom/qdsp6/q6asm.c b/sound/soc/qcom/qdsp6/q6asm.c
index ee1930e41..d4c1cff3f 100644
--- a/sound/soc/qcom/qdsp6/q6asm.c
+++ b/sound/soc/qcom/qdsp6/q6asm.c
@@ -1552,17 +1552,17 @@ int q6asm_read(struct audio_client *ac, uint32_t stream_id)
 	read->seq_id = port->dsp_buf;
 	pkt->hdr.token = port->dsp_buf;
 
-	port->dsp_buf++;
-
-	if (port->dsp_buf >= port->num_periods)
-		port->dsp_buf = 0;
-
-	spin_unlock_irqrestore(&ac->lock, flags);
 	rc = apr_send_pkt(ac->adev, pkt);
-	if (rc == pkt_size)
+	if (rc == pkt_size) {
 		rc = 0;
-	else
+		port->dsp_buf++;
+		if (port->dsp_buf >= port->num_periods)
+			port->dsp_buf = 0;
+	} else {
 		pr_err("read op[0x%x]rc[%d]\n", pkt->hdr.opcode, rc);
+	}
+
+	spin_unlock_irqrestore(&ac->lock, flags);
 
 	return rc;
 }
@@ -1673,15 +1673,15 @@ int q6asm_write_async(struct audio_client *ac, uint32_t stream_id, uint32_t len,
 
 	write->flags = wflags;
 
-	port->dsp_buf++;
-
-	if (port->dsp_buf >= port->num_periods)
-		port->dsp_buf = 0;
-
-	spin_unlock_irqrestore(&ac->lock, flags);
 	rc = apr_send_pkt(ac->adev, pkt);
-	if (rc == pkt_size)
+	if (rc == pkt_size) {
 		rc = 0;
+		port->dsp_buf++;
+		if (port->dsp_buf >= port->num_periods)
+			port->dsp_buf = 0;
+	}
+
+	spin_unlock_irqrestore(&ac->lock, flags);
 
 	return rc;
 }
-- 
2.43.0


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH 2/2] ASoC: qcom: q6asm-dai: retry playback queuing on -EAGAIN
  2026-11-29  0:19 [PATCH 0/2] ASoC: qcom: qdsp6: handle SMD FIFO -EAGAIN in q6asm playback Vladimir Bely
  2026-11-29  0:19 ` [PATCH 1/2] ASoC: qcom: q6asm: don't advance dsp_buf on failed write or read Vladimir Bely
@ 2026-11-29  0:19 ` Vladimir Bely
  1 sibling, 0 replies; 3+ messages in thread
From: Vladimir Bely @ 2026-11-29  0:19 UTC (permalink / raw)
  To: Srinivas Kandagatla, Liam Girdwood, Mark Brown
  Cc: Jaroslav Kysela, Takashi Iwai, linux-sound, linux-arm-msm,
	linux-kernel, Vladimir Bely, stable

q6asm_dai_ack() tries to queue every available playback period to the
DSP in a single burst via q6asm_write_async(). Each period sends an APR
packet using rpmsg_trysend(), which can fill the small SMD FIFO on older
SoCs such as MSM8916 and return -EAGAIN. Currently q6asm_dai_ack()
treats -EAGAIN as a fatal error and aborts playback right at start.

Extract a locked helper q6asm_dai_queue_playback() (initializing
prtd->lock in q6asm_dai_open(), which was previously only initialized in
q6asm_dai_compr_open()) that stops cleanly on -EAGAIN without advancing
queue_ptr, and call it again from ASM_CLIENT_EVENT_DATA_WRITE_DONE once
the DSP hands a buffer back. Also wrap queue_ptr against
runtime->boundary so long-running playback does not underflow.

Tested on MSM8916 (Samsung Galaxy A3, SM-A300F).

Fixes: e386c2cf3df2 ("ASoC: qcom: q6asm-dai: schedule all available frames to avoid dsp under-runs")
Cc: stable@vger.kernel.org
Signed-off-by: Vladimir Bely <vlwwwwww@gmail.com>
---
 sound/soc/qcom/qdsp6/q6asm-dai.c | 58 +++++++++++++++++++++++++-------
 1 file changed, 46 insertions(+), 12 deletions(-)

diff --git a/sound/soc/qcom/qdsp6/q6asm-dai.c b/sound/soc/qcom/qdsp6/q6asm-dai.c
index 57cbce2bb..a21b93c3e 100644
--- a/sound/soc/qcom/qdsp6/q6asm-dai.c
+++ b/sound/soc/qcom/qdsp6/q6asm-dai.c
@@ -179,6 +179,42 @@ static const struct snd_compr_codec_caps q6asm_compr_caps = {
 	.descriptor[0].formats = 0,
 };
 
+/*
+ * Queue the periods the application has written so far. Each period is one
+ * APR packet sent with rpmsg_trysend(), and a burst can fill the small SMD
+ * FIFO (-EAGAIN). That is not an error: stop and retry when the DSP hands a
+ * buffer back (DATA_WRITE_DONE).
+ */
+static int q6asm_dai_queue_playback(struct q6asm_dai_rtd *prtd)
+{
+	struct snd_pcm_runtime *runtime = prtd->substream->runtime;
+	int ret;
+
+	guard(spinlock_irqsave)(&prtd->lock);
+
+	while (prtd->state == Q6ASM_STREAM_RUNNING) {
+		snd_pcm_sframes_t avail = runtime->control->appl_ptr - prtd->queue_ptr;
+
+		if (avail < 0)
+			avail += runtime->boundary;
+		if (avail < runtime->period_size)
+			break;
+
+		ret = q6asm_write_async(prtd->audio_client, prtd->stream_id,
+					prtd->pcm_count, 0, 0, 0);
+		if (ret == -EAGAIN)
+			break;
+		if (ret < 0)
+			return ret;
+
+		prtd->queue_ptr += runtime->period_size;
+		if (prtd->queue_ptr >= runtime->boundary)
+			prtd->queue_ptr -= runtime->boundary;
+	}
+
+	return 0;
+}
+
 static void event_handler(uint32_t opcode, uint32_t token,
 			  void *payload, void *priv)
 {
@@ -192,6 +228,9 @@ static void event_handler(uint32_t opcode, uint32_t token,
 		break;
 	case ASM_CLIENT_EVENT_DATA_WRITE_DONE:
 		snd_pcm_period_elapsed(substream);
+		/* Push the periods left behind by a full SMD FIFO */
+		if (q6asm_dai_queue_playback(prtd) < 0)
+			pr_err_ratelimited("q6asm-dai: Error queuing playback buffer\n");
 		break;
 	case ASM_CLIENT_EVENT_DATA_READ_DONE:
 		snd_pcm_period_elapsed(substream);
@@ -321,19 +360,13 @@ static int q6asm_dai_ack(struct snd_soc_component *component, struct snd_pcm_sub
 {
 	struct snd_pcm_runtime *runtime = substream->runtime;
 	struct q6asm_dai_rtd *prtd = runtime->private_data;
-	int i, ret = 0, avail_periods;
-
-	if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK && prtd->state == Q6ASM_STREAM_RUNNING) {
-		avail_periods = (runtime->control->appl_ptr - prtd->queue_ptr)/runtime->period_size;
-		for (i = 0; i < avail_periods; i++) {
-			ret = q6asm_write_async(prtd->audio_client, prtd->stream_id,
-					   prtd->pcm_count, 0, 0, 0);
+	int ret = 0;
 
-			if (ret < 0) {
-				dev_err(component->dev, "Error queuing playback buffer %d\n", ret);
-				return ret;
-			}
-			prtd->queue_ptr += runtime->period_size;
+	if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
+		ret = q6asm_dai_queue_playback(prtd);
+		if (ret < 0) {
+			dev_err(component->dev, "Error queuing playback buffer %d\n", ret);
+			return ret;
 		}
 	}
 
@@ -395,6 +428,7 @@ static int q6asm_dai_open(struct snd_soc_component *component,
 	if (prtd == NULL)
 		return -ENOMEM;
 
+	spin_lock_init(&prtd->lock);
 	prtd->substream = substream;
 	prtd->audio_client = q6asm_audio_client_alloc(dev,
 				(q6asm_cb)event_handler, prtd, stream_id,
-- 
2.43.0


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-11-29  0:19 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-29  0:19 [PATCH 0/2] ASoC: qcom: qdsp6: handle SMD FIFO -EAGAIN in q6asm playback Vladimir Bely
2026-11-29  0:19 ` [PATCH 1/2] ASoC: qcom: q6asm: don't advance dsp_buf on failed write or read Vladimir Bely
2026-11-29  0:19 ` [PATCH 2/2] ASoC: qcom: q6asm-dai: retry playback queuing on -EAGAIN Vladimir Bely

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®