linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 1/5] ASoC: sh: rz-ssi: Drop calling rz_ssi_pio_recv() recursively
       [not found] <20220115012303.29651-1-prabhakar.mahadev-lad.rj@bp.renesas.com>
@ 2022-01-15  1:22 ` Lad Prabhakar
  2022-01-19 13:35   ` Cezary Rojewski
  2022-01-25 10:22   ` Mark Brown
  2022-01-15  1:23 ` [PATCH v2 2/5] ASoC: sh: rz-ssi: Make the data structures available before registering the handlers Lad Prabhakar
                   ` (3 subsequent siblings)
  4 siblings, 2 replies; 7+ messages in thread
From: Lad Prabhakar @ 2022-01-15  1:22 UTC (permalink / raw)
  To: Liam Girdwood, Mark Brown, Jaroslav Kysela, Takashi Iwai,
	Lad Prabhakar, Biju Das
  Cc: Pavel Machek, Cezary Rojewski, linux-renesas-soc, Prabhakar,
	alsa-devel, linux-kernel

Instead of recursively calling rz_ssi_pio_recv() use a loop instead
to read the samples from RX fifo.

Inspiration for this patch is to avoid recursion, as recursion is
unwelcome in kernel due to limited stack use. Also to add this driver
will later be used on RZ/A2 SoC's which runs with limited memory.

This also fixes an issue where the return value of rz_ssi_pio_recv()
was ignored when called recursively.

Fixes: 03e786bd4341 ("ASoC: sh: Add RZ/G2L SSIF-2 driver")
Reported-by: Pavel Machek <pavel@denx.de>
Signed-off-by: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>
Reviewed-by: Biju Das <biju.das.jz@bp.renesas.com>
---
v1->v2
* Used a do while loop
* Fixed comments pointed by Cezary.
---
 sound/soc/sh/rz-ssi.c | 65 +++++++++++++++++++++----------------------
 1 file changed, 31 insertions(+), 34 deletions(-)

diff --git a/sound/soc/sh/rz-ssi.c b/sound/soc/sh/rz-ssi.c
index fa0cc08f70ec..637802117c6c 100644
--- a/sound/soc/sh/rz-ssi.c
+++ b/sound/soc/sh/rz-ssi.c
@@ -414,51 +414,48 @@ static int rz_ssi_pio_recv(struct rz_ssi_priv *ssi, struct rz_ssi_stream *strm)
 	u16 *buf;
 	int fifo_samples;
 	int frames_left;
-	int samples = 0;
+	int samples;
 	int i;
 
 	if (!rz_ssi_stream_is_valid(ssi, strm))
 		return -EINVAL;
 
 	runtime = substream->runtime;
-	/* frames left in this period */
-	frames_left = runtime->period_size - (strm->buffer_pos %
-					      runtime->period_size);
-	if (frames_left == 0)
-		frames_left = runtime->period_size;
 
-	/* Samples in RX FIFO */
-	fifo_samples = (rz_ssi_reg_readl(ssi, SSIFSR) >>
-			SSIFSR_RDC_SHIFT) & SSIFSR_RDC_MASK;
-
-	/* Only read full frames at a time */
-	while (frames_left && (fifo_samples >= runtime->channels)) {
-		samples += runtime->channels;
-		fifo_samples -= runtime->channels;
-		frames_left--;
-	}
-
-	/* not enough samples yet */
-	if (samples == 0)
-		return 0;
+	do {
+		/* frames left in this period */
+		frames_left = runtime->period_size -
+			      (strm->buffer_pos % runtime->period_size);
+		if (!frames_left)
+			frames_left = runtime->period_size;
+
+		/* Samples in RX FIFO */
+		fifo_samples = (rz_ssi_reg_readl(ssi, SSIFSR) >>
+				SSIFSR_RDC_SHIFT) & SSIFSR_RDC_MASK;
+
+		/* Only read full frames at a time */
+		samples = 0;
+		while (frames_left && (fifo_samples >= runtime->channels)) {
+			samples += runtime->channels;
+			fifo_samples -= runtime->channels;
+			frames_left--;
+		}
 
-	/* calculate new buffer index */
-	buf = (u16 *)(runtime->dma_area);
-	buf += strm->buffer_pos * runtime->channels;
+		/* not enough samples yet */
+		if (!samples)
+			break;
 
-	/* Note, only supports 16-bit samples */
-	for (i = 0; i < samples; i++)
-		*buf++ = (u16)(rz_ssi_reg_readl(ssi, SSIFRDR) >> 16);
+		/* calculate new buffer index */
+		buf = (u16 *)runtime->dma_area;
+		buf += strm->buffer_pos * runtime->channels;
 
-	rz_ssi_reg_mask_setl(ssi, SSIFSR, SSIFSR_RDF, 0);
-	rz_ssi_pointer_update(strm, samples / runtime->channels);
+		/* Note, only supports 16-bit samples */
+		for (i = 0; i < samples; i++)
+			*buf++ = (u16)(rz_ssi_reg_readl(ssi, SSIFRDR) >> 16);
 
-	/*
-	 * If we finished this period, but there are more samples in
-	 * the RX FIFO, call this function again
-	 */
-	if (frames_left == 0 && fifo_samples >= runtime->channels)
-		rz_ssi_pio_recv(ssi, strm);
+		rz_ssi_reg_mask_setl(ssi, SSIFSR, SSIFSR_RDF, 0);
+		rz_ssi_pointer_update(strm, samples / runtime->channels);
+	} while (!frames_left && fifo_samples >= runtime->channels);
 
 	return 0;
 }
-- 
2.17.1


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

* [PATCH v2 2/5] ASoC: sh: rz-ssi: Make the data structures available before registering the handlers
       [not found] <20220115012303.29651-1-prabhakar.mahadev-lad.rj@bp.renesas.com>
  2022-01-15  1:22 ` [PATCH v2 1/5] ASoC: sh: rz-ssi: Drop calling rz_ssi_pio_recv() recursively Lad Prabhakar
@ 2022-01-15  1:23 ` Lad Prabhakar
  2022-01-15  1:23 ` [PATCH v2 3/5] ASoC: sh: rz-ssi: Drop ssi parameter from rz_ssi_stream_init() Lad Prabhakar
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 7+ messages in thread
From: Lad Prabhakar @ 2022-01-15  1:23 UTC (permalink / raw)
  To: Liam Girdwood, Mark Brown, Jaroslav Kysela, Takashi Iwai
  Cc: Biju Das, Pavel Machek, Cezary Rojewski, linux-renesas-soc,
	Prabhakar, Lad Prabhakar, alsa-devel, linux-kernel

Initialize the spinlock and make the data structures available before
registering the interrupt handlers.

Reported-by: Pavel Machek <pavel@denx.de>
Signed-off-by: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>
Reviewed-by: Biju Das <biju.das.jz@bp.renesas.com>
---
v1->v2
* No change
---
 sound/soc/sh/rz-ssi.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/sound/soc/sh/rz-ssi.c b/sound/soc/sh/rz-ssi.c
index 637802117c6c..89428945d48b 100644
--- a/sound/soc/sh/rz-ssi.c
+++ b/sound/soc/sh/rz-ssi.c
@@ -972,6 +972,9 @@ static int rz_ssi_probe(struct platform_device *pdev)
 	ssi->playback.priv = ssi;
 	ssi->capture.priv = ssi;
 
+	spin_lock_init(&ssi->lock);
+	dev_set_drvdata(&pdev->dev, ssi);
+
 	/* Error Interrupt */
 	ssi->irq_int = platform_get_irq_byname(pdev, "int_req");
 	if (ssi->irq_int < 0)
@@ -1019,8 +1022,6 @@ static int rz_ssi_probe(struct platform_device *pdev)
 	pm_runtime_enable(&pdev->dev);
 	pm_runtime_resume_and_get(&pdev->dev);
 
-	spin_lock_init(&ssi->lock);
-	dev_set_drvdata(&pdev->dev, ssi);
 	ret = devm_snd_soc_register_component(&pdev->dev, &rz_ssi_soc_component,
 					      rz_ssi_soc_dai,
 					      ARRAY_SIZE(rz_ssi_soc_dai));
-- 
2.17.1


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

* [PATCH v2 3/5] ASoC: sh: rz-ssi: Drop ssi parameter from rz_ssi_stream_init()
       [not found] <20220115012303.29651-1-prabhakar.mahadev-lad.rj@bp.renesas.com>
  2022-01-15  1:22 ` [PATCH v2 1/5] ASoC: sh: rz-ssi: Drop calling rz_ssi_pio_recv() recursively Lad Prabhakar
  2022-01-15  1:23 ` [PATCH v2 2/5] ASoC: sh: rz-ssi: Make the data structures available before registering the handlers Lad Prabhakar
@ 2022-01-15  1:23 ` Lad Prabhakar
  2022-01-15  1:23 ` [PATCH v2 4/5] ASoC: sh: rz-ssi: Change return type of rz_ssi_stream_is_valid() to bool Lad Prabhakar
  2022-01-15  1:23 ` [PATCH v2 5/5] ASoC: sh: rz-ssi: Add rz_ssi_set_substream() helper function Lad Prabhakar
  4 siblings, 0 replies; 7+ messages in thread
From: Lad Prabhakar @ 2022-01-15  1:23 UTC (permalink / raw)
  To: Liam Girdwood, Mark Brown, Jaroslav Kysela, Takashi Iwai
  Cc: Biju Das, Pavel Machek, Cezary Rojewski, linux-renesas-soc,
	Prabhakar, Lad Prabhakar, alsa-devel, linux-kernel

ssi parameter is unused in rz_ssi_stream_init() so just drop it.

While at it, change the return type of rz_ssi_stream_init() to void
instead of int.

Signed-off-by: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>
Reviewed-by: Biju Das <biju.das.jz@bp.renesas.com>
---
v1->v2
* No change
---
 sound/soc/sh/rz-ssi.c | 11 +++--------
 1 file changed, 3 insertions(+), 8 deletions(-)

diff --git a/sound/soc/sh/rz-ssi.c b/sound/soc/sh/rz-ssi.c
index 89428945d48b..50699e94772b 100644
--- a/sound/soc/sh/rz-ssi.c
+++ b/sound/soc/sh/rz-ssi.c
@@ -201,9 +201,8 @@ static int rz_ssi_stream_is_valid(struct rz_ssi_priv *ssi,
 	return ret;
 }
 
-static int rz_ssi_stream_init(struct rz_ssi_priv *ssi,
-			      struct rz_ssi_stream *strm,
-			      struct snd_pcm_substream *substream)
+static void rz_ssi_stream_init(struct rz_ssi_stream *strm,
+			       struct snd_pcm_substream *substream)
 {
 	struct snd_pcm_runtime *runtime = substream->runtime;
 
@@ -219,8 +218,6 @@ static int rz_ssi_stream_init(struct rz_ssi_priv *ssi,
 
 	/* fifo init */
 	strm->fifo_sample_size = SSI_FIFO_DEPTH;
-
-	return 0;
 }
 
 static void rz_ssi_stream_quit(struct rz_ssi_priv *ssi,
@@ -723,9 +720,7 @@ static int rz_ssi_dai_trigger(struct snd_pcm_substream *substream, int cmd,
 		rz_ssi_reg_mask_setl(ssi, SSIFCR, SSIFCR_SSIRST, 0);
 		udelay(5);
 
-		ret = rz_ssi_stream_init(ssi, strm, substream);
-		if (ret)
-			goto done;
+		rz_ssi_stream_init(strm, substream);
 
 		if (ssi->dma_rt) {
 			bool is_playback;
-- 
2.17.1


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

* [PATCH v2 4/5] ASoC: sh: rz-ssi: Change return type of rz_ssi_stream_is_valid() to bool
       [not found] <20220115012303.29651-1-prabhakar.mahadev-lad.rj@bp.renesas.com>
                   ` (2 preceding siblings ...)
  2022-01-15  1:23 ` [PATCH v2 3/5] ASoC: sh: rz-ssi: Drop ssi parameter from rz_ssi_stream_init() Lad Prabhakar
@ 2022-01-15  1:23 ` Lad Prabhakar
  2022-01-15  1:23 ` [PATCH v2 5/5] ASoC: sh: rz-ssi: Add rz_ssi_set_substream() helper function Lad Prabhakar
  4 siblings, 0 replies; 7+ messages in thread
From: Lad Prabhakar @ 2022-01-15  1:23 UTC (permalink / raw)
  To: Liam Girdwood, Mark Brown, Jaroslav Kysela, Takashi Iwai
  Cc: Biju Das, Pavel Machek, Cezary Rojewski, linux-renesas-soc,
	Prabhakar, Lad Prabhakar, alsa-devel, linux-kernel

rz_ssi_stream_is_valid() never returns an int, it returns the result of
a condition which is either true or false.

While at it, drop "!!" as the expression is boolean.

Reported-by: Pavel Machek <pavel@denx.de>
Signed-off-by: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>
Reviewed-by: Biju Das <biju.das.jz@bp.renesas.com>
---
v1->v2
* No change
---
 sound/soc/sh/rz-ssi.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/sound/soc/sh/rz-ssi.c b/sound/soc/sh/rz-ssi.c
index 50699e94772b..2da43eecfb3e 100644
--- a/sound/soc/sh/rz-ssi.c
+++ b/sound/soc/sh/rz-ssi.c
@@ -188,14 +188,14 @@ static inline bool rz_ssi_is_dma_enabled(struct rz_ssi_priv *ssi)
 	return (ssi->playback.dma_ch && (ssi->dma_rt || ssi->capture.dma_ch));
 }
 
-static int rz_ssi_stream_is_valid(struct rz_ssi_priv *ssi,
-				  struct rz_ssi_stream *strm)
+static bool rz_ssi_stream_is_valid(struct rz_ssi_priv *ssi,
+				   struct rz_ssi_stream *strm)
 {
 	unsigned long flags;
-	int ret;
+	bool ret;
 
 	spin_lock_irqsave(&ssi->lock, flags);
-	ret = !!(strm->substream && strm->substream->runtime);
+	ret = strm->substream && strm->substream->runtime;
 	spin_unlock_irqrestore(&ssi->lock, flags);
 
 	return ret;
-- 
2.17.1


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

* [PATCH v2 5/5] ASoC: sh: rz-ssi: Add rz_ssi_set_substream() helper function
       [not found] <20220115012303.29651-1-prabhakar.mahadev-lad.rj@bp.renesas.com>
                   ` (3 preceding siblings ...)
  2022-01-15  1:23 ` [PATCH v2 4/5] ASoC: sh: rz-ssi: Change return type of rz_ssi_stream_is_valid() to bool Lad Prabhakar
@ 2022-01-15  1:23 ` Lad Prabhakar
  4 siblings, 0 replies; 7+ messages in thread
From: Lad Prabhakar @ 2022-01-15  1:23 UTC (permalink / raw)
  To: Liam Girdwood, Mark Brown, Jaroslav Kysela, Takashi Iwai
  Cc: Biju Das, Pavel Machek, Cezary Rojewski, linux-renesas-soc,
	Prabhakar, Lad Prabhakar, alsa-devel, linux-kernel

A copy of substream pointer is stored in priv structure during
rz_ssi_dai_trigger() callback ie in SNDRV_PCM_TRIGGER_START case
and the pointer is assigned to NULL in case of SNDRV_PCM_TRIGGER_STOP.

The driver used the locks only in rz_ssi_stream_is_valid() and assigned
the local substream pointer to NULL in rz_ssi_dai_trigger() callback but
never locked it while making a local copy.

This patch adds the rz_ssi_set_substream() helper function to set the
substream pointer with locks acquired and replaces the instances of
setting the local substream pointer with the rz_ssi_set_substream()
function.

Reported-by: Pavel Machek <pavel@denx.de>
Signed-off-by: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>
Reviewed-by: Biju Das <biju.das.jz@bp.renesas.com>
---
v1->v2
* Dropped rz_ssi_get_substream() helper.
---
 sound/soc/sh/rz-ssi.c | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)

diff --git a/sound/soc/sh/rz-ssi.c b/sound/soc/sh/rz-ssi.c
index 2da43eecfb3e..07fdbcfa5b63 100644
--- a/sound/soc/sh/rz-ssi.c
+++ b/sound/soc/sh/rz-ssi.c
@@ -188,6 +188,17 @@ static inline bool rz_ssi_is_dma_enabled(struct rz_ssi_priv *ssi)
 	return (ssi->playback.dma_ch && (ssi->dma_rt || ssi->capture.dma_ch));
 }
 
+static void rz_ssi_set_substream(struct rz_ssi_stream *strm,
+				 struct snd_pcm_substream *substream)
+{
+	struct rz_ssi_priv *ssi = strm->priv;
+	unsigned long flags;
+
+	spin_lock_irqsave(&ssi->lock, flags);
+	strm->substream = substream;
+	spin_unlock_irqrestore(&ssi->lock, flags);
+}
+
 static bool rz_ssi_stream_is_valid(struct rz_ssi_priv *ssi,
 				   struct rz_ssi_stream *strm)
 {
@@ -206,7 +217,7 @@ static void rz_ssi_stream_init(struct rz_ssi_stream *strm,
 {
 	struct snd_pcm_runtime *runtime = substream->runtime;
 
-	strm->substream = substream;
+	rz_ssi_set_substream(strm, substream);
 	strm->sample_width = samples_to_bytes(runtime, 1);
 	strm->dma_buffer_pos = 0;
 	strm->period_counter = 0;
@@ -224,11 +235,8 @@ static void rz_ssi_stream_quit(struct rz_ssi_priv *ssi,
 			       struct rz_ssi_stream *strm)
 {
 	struct snd_soc_dai *dai = rz_ssi_get_dai(strm->substream);
-	unsigned long flags;
 
-	spin_lock_irqsave(&ssi->lock, flags);
-	strm->substream = NULL;
-	spin_unlock_irqrestore(&ssi->lock, flags);
+	rz_ssi_set_substream(strm, NULL);
 
 	if (strm->oerr_num > 0)
 		dev_info(dai->dev, "overrun = %d\n", strm->oerr_num);
-- 
2.17.1


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

* Re: [PATCH v2 1/5] ASoC: sh: rz-ssi: Drop calling rz_ssi_pio_recv() recursively
  2022-01-15  1:22 ` [PATCH v2 1/5] ASoC: sh: rz-ssi: Drop calling rz_ssi_pio_recv() recursively Lad Prabhakar
@ 2022-01-19 13:35   ` Cezary Rojewski
  2022-01-25 10:22   ` Mark Brown
  1 sibling, 0 replies; 7+ messages in thread
From: Cezary Rojewski @ 2022-01-19 13:35 UTC (permalink / raw)
  To: Lad Prabhakar, Liam Girdwood, Mark Brown, Jaroslav Kysela,
	Takashi Iwai, Biju Das
  Cc: Pavel Machek, linux-renesas-soc, Prabhakar, alsa-devel, linux-kernel

On 2022-01-15 2:22 AM, Lad Prabhakar wrote:
> Instead of recursively calling rz_ssi_pio_recv() use a loop instead
> to read the samples from RX fifo.
> 
> Inspiration for this patch is to avoid recursion, as recursion is
> unwelcome in kernel due to limited stack use. Also to add this driver
> will later be used on RZ/A2 SoC's which runs with limited memory.
> 
> This also fixes an issue where the return value of rz_ssi_pio_recv()
> was ignored when called recursively.
> 
> Fixes: 03e786bd4341 ("ASoC: sh: Add RZ/G2L SSIF-2 driver")
> Reported-by: Pavel Machek <pavel@denx.de>
> Signed-off-by: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>
> Reviewed-by: Biju Das <biju.das.jz@bp.renesas.com>
> ---
> v1->v2
> * Used a do while loop
> * Fixed comments pointed by Cezary.

Apart from my previous suggestions which have already been addressed, I 
don't see any issues with the patch, so:

Reviewed-by: Cezary Rojewski <cezary.rojewski@intel.com>


Regards,
Czarek

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

* Re: [PATCH v2 1/5] ASoC: sh: rz-ssi: Drop calling rz_ssi_pio_recv() recursively
  2022-01-15  1:22 ` [PATCH v2 1/5] ASoC: sh: rz-ssi: Drop calling rz_ssi_pio_recv() recursively Lad Prabhakar
  2022-01-19 13:35   ` Cezary Rojewski
@ 2022-01-25 10:22   ` Mark Brown
  1 sibling, 0 replies; 7+ messages in thread
From: Mark Brown @ 2022-01-25 10:22 UTC (permalink / raw)
  To: Lad Prabhakar
  Cc: Liam Girdwood, Jaroslav Kysela, Takashi Iwai, Biju Das,
	Pavel Machek, Cezary Rojewski, linux-renesas-soc, Prabhakar,
	alsa-devel, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 236 bytes --]

On Sat, Jan 15, 2022 at 01:22:59AM +0000, Lad Prabhakar wrote:
> Instead of recursively calling rz_ssi_pio_recv() use a loop instead
> to read the samples from RX fifo.

This doesn't apply against current code, please check and resend.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

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

end of thread, other threads:[~2022-01-25 10:26 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <20220115012303.29651-1-prabhakar.mahadev-lad.rj@bp.renesas.com>
2022-01-15  1:22 ` [PATCH v2 1/5] ASoC: sh: rz-ssi: Drop calling rz_ssi_pio_recv() recursively Lad Prabhakar
2022-01-19 13:35   ` Cezary Rojewski
2022-01-25 10:22   ` Mark Brown
2022-01-15  1:23 ` [PATCH v2 2/5] ASoC: sh: rz-ssi: Make the data structures available before registering the handlers Lad Prabhakar
2022-01-15  1:23 ` [PATCH v2 3/5] ASoC: sh: rz-ssi: Drop ssi parameter from rz_ssi_stream_init() Lad Prabhakar
2022-01-15  1:23 ` [PATCH v2 4/5] ASoC: sh: rz-ssi: Change return type of rz_ssi_stream_is_valid() to bool Lad Prabhakar
2022-01-15  1:23 ` [PATCH v2 5/5] ASoC: sh: rz-ssi: Add rz_ssi_set_substream() helper function Lad Prabhakar

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).