From nobody Mon Jun 8 21:46:47 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BBA06313534; Tue, 26 May 2026 08:47:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779785248; cv=none; b=W7+IEloQ/Ia4zoaYqHaRLcZWtCWMPm1L7+Fnpo6ABJ24eHnVYP5Vpgeumfohf7jeVsKMyiGGsNVW+/T1vBm27ag70/zkahPPz1a9NXn2Ax2OuLK1U3RksbHOg5tlQoxH7INmgp8BWUcw1J+DIYzAAKkaxW9RdCQb/mfHf4ifYN8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779785248; c=relaxed/simple; bh=rGmk+aRvwZHemphDVw2DSidKFuqGLSOAAK3nTf4c6XM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hju1b4mcrqIEOV0ZQMwHgRnIqTs4EzFbtfG+ZRI4MLFwX8gpcUAENI4l76HXN2Sxjnw/7V+O1XQnJeB8mmKMjnkuQuUbj9Lt6qCRNOkzz7hCy2kra9jDE7m3aB5leATXh0jeCTQH10hBeii+8zYuO0Sjr52UyFRdHmi2GUQrYB4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=TWSE398b; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="TWSE398b" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 406B41F00A3A; Tue, 26 May 2026 08:47:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1779785246; bh=oXZDe2HD4PFCzhVKiGOwCFw4izD60puGS18pY29Fm8E=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=TWSE398brq52YA4Y9SxBzNWcScByBrVURjhNMUjePuzIkeYknHzx3Yo/btnzo/i+L t9hwEz48RUtyws4+0mKFqrc/KXZcCRO/W6dfZFP9W44fZaTipRQ3/Roq+vaz+nyGoH 4LzhII/PWwbMW9r3ZkgsopAZYGOyVa+g5fij3UAXHgskDLm+F/vpgCTsM8ndnyj5xc vfb6JAmQ1zp5cOR5vLLL86o89WOLaHq9Y+2kLmBmpuGiRR7hsxzAAL/goZ2yI1Zm7q uq/7fR7nUzHvi0tqqcGnV57S+zsfpQV6I31Qfnhw+/0nELkclJMkvzzcXk9cu1dS0Q defuPDnAAWd9A== From: Claudiu Beznea To: vkoul@kernel.org, Frank.Li@kernel.org, lgirdwood@gmail.com, broonie@kernel.org, perex@perex.cz, tiwai@suse.com, biju.das.jz@bp.renesas.com, prabhakar.mahadev-lad.rj@bp.renesas.com, p.zabel@pengutronix.de, geert+renesas@glider.be, kuninori.morimoto.gx@renesas.com, long.luu.ur@renesas.com Cc: claudiu.beznea@kernel.org, claudiu.beznea@tuxon.dev, dmaengine@vger.kernel.org, linux-kernel@vger.kernel.org, linux-sound@vger.kernel.org, linux-renesas-soc@vger.kernel.org, Claudiu Beznea , stable@vger.kernel.org, Frank Li , John Madieu Subject: [PATCH v6 01/18] dmaengine: sh: rz-dmac: Move interrupt request after everything is set up Date: Tue, 26 May 2026 11:46:53 +0300 Message-ID: <20260526084710.3491480-2-claudiu.beznea@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260526084710.3491480-1-claudiu.beznea@kernel.org> References: <20260526084710.3491480-1-claudiu.beznea@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Claudiu Beznea Once the interrupt is requested, the interrupt handler may run immediately. Since the IRQ handler can access channel->ch_base, which is initialized only after requesting the IRQ, this may lead to invalid memory access. Likewise, the IRQ thread may access uninitialized data (the ld_free, ld_queue, and ld_active lists), which may also lead to issues. Request the interrupts only after everything is set up. To keep the error path simpler, use dmam_alloc_coherent() instead of dma_alloc_coherent(). Fixes: 5000d37042a6 ("dmaengine: sh: Add DMAC driver for RZ/G2L SoC") Cc: stable@vger.kernel.org Reviewed-by: Frank Li Tested-by: John Madieu Signed-off-by: Claudiu Beznea Tested-by: Tommaso Merciai --- Changes in v6: - collected tags Changes in v5: - none Changes in v4: - none, this patch is new drivers/dma/sh/rz-dmac.c | 88 +++++++++++++++------------------------- 1 file changed, 33 insertions(+), 55 deletions(-) diff --git a/drivers/dma/sh/rz-dmac.c b/drivers/dma/sh/rz-dmac.c index 625ff29024de..9f206a33dcc6 100644 --- a/drivers/dma/sh/rz-dmac.c +++ b/drivers/dma/sh/rz-dmac.c @@ -981,25 +981,6 @@ static int rz_dmac_chan_probe(struct rz_dmac *dmac, channel->index =3D index; channel->mid_rid =3D -EINVAL; =20 - /* Request the channel interrupt. */ - scnprintf(pdev_irqname, sizeof(pdev_irqname), "ch%u", index); - irq =3D platform_get_irq_byname(pdev, pdev_irqname); - if (irq < 0) - return irq; - - irqname =3D devm_kasprintf(dmac->dev, GFP_KERNEL, "%s:%u", - dev_name(dmac->dev), index); - if (!irqname) - return -ENOMEM; - - ret =3D devm_request_threaded_irq(dmac->dev, irq, rz_dmac_irq_handler, - rz_dmac_irq_handler_thread, 0, - irqname, channel); - if (ret) { - dev_err(dmac->dev, "failed to request IRQ %u (%d)\n", irq, ret); - return ret; - } - /* Set io base address for each channel */ if (index < 8) { channel->ch_base =3D dmac->base + CHANNEL_0_7_OFFSET + @@ -1012,9 +993,9 @@ static int rz_dmac_chan_probe(struct rz_dmac *dmac, } =20 /* Allocate descriptors */ - lmdesc =3D dma_alloc_coherent(&pdev->dev, - sizeof(struct rz_lmdesc) * DMAC_NR_LMDESC, - &channel->lmdesc.base_dma, GFP_KERNEL); + lmdesc =3D dmam_alloc_coherent(&pdev->dev, + sizeof(struct rz_lmdesc) * DMAC_NR_LMDESC, + &channel->lmdesc.base_dma, GFP_KERNEL); if (!lmdesc) { dev_err(&pdev->dev, "Can't allocate memory (lmdesc)\n"); return -ENOMEM; @@ -1030,7 +1011,24 @@ static int rz_dmac_chan_probe(struct rz_dmac *dmac, INIT_LIST_HEAD(&channel->ld_free); INIT_LIST_HEAD(&channel->ld_active); =20 - return 0; + /* Request the channel interrupt. */ + scnprintf(pdev_irqname, sizeof(pdev_irqname), "ch%u", index); + irq =3D platform_get_irq_byname(pdev, pdev_irqname); + if (irq < 0) + return irq; + + irqname =3D devm_kasprintf(dmac->dev, GFP_KERNEL, "%s:%u", + dev_name(dmac->dev), index); + if (!irqname) + return -ENOMEM; + + ret =3D devm_request_threaded_irq(dmac->dev, irq, rz_dmac_irq_handler, + rz_dmac_irq_handler_thread, 0, + irqname, channel); + if (ret) + dev_err(dmac->dev, "failed to request IRQ %u (%d)\n", irq, ret); + + return ret; } =20 static void rz_dmac_put_device(void *_dev) @@ -1099,7 +1097,6 @@ static int rz_dmac_probe(struct platform_device *pdev) const char *irqname =3D "error"; struct dma_device *engine; struct rz_dmac *dmac; - int channel_num; int ret; int irq; u8 i; @@ -1132,18 +1129,6 @@ static int rz_dmac_probe(struct platform_device *pde= v) return PTR_ERR(dmac->ext_base); } =20 - /* Register interrupt handler for error */ - irq =3D platform_get_irq_byname_optional(pdev, irqname); - if (irq > 0) { - ret =3D devm_request_irq(&pdev->dev, irq, rz_dmac_irq_handler, 0, - irqname, NULL); - if (ret) { - dev_err(&pdev->dev, "failed to request IRQ %u (%d)\n", - irq, ret); - return ret; - } - } - /* Initialize the channels. */ INIT_LIST_HEAD(&dmac->engine.channels); =20 @@ -1169,6 +1154,18 @@ static int rz_dmac_probe(struct platform_device *pde= v) goto err; } =20 + /* Register interrupt handler for error */ + irq =3D platform_get_irq_byname_optional(pdev, irqname); + if (irq > 0) { + ret =3D devm_request_irq(&pdev->dev, irq, rz_dmac_irq_handler, 0, + irqname, NULL); + if (ret) { + dev_err(&pdev->dev, "failed to request IRQ %u (%d)\n", + irq, ret); + goto err; + } + } + /* Register the DMAC as a DMA provider for DT. */ ret =3D of_dma_controller_register(pdev->dev.of_node, rz_dmac_of_xlate, NULL); @@ -1210,16 +1207,6 @@ static int rz_dmac_probe(struct platform_device *pde= v) dma_register_err: of_dma_controller_free(pdev->dev.of_node); err: - channel_num =3D i ? i - 1 : 0; - for (i =3D 0; i < channel_num; i++) { - struct rz_dmac_chan *channel =3D &dmac->channels[i]; - - dma_free_coherent(&pdev->dev, - sizeof(struct rz_lmdesc) * DMAC_NR_LMDESC, - channel->lmdesc.base, - channel->lmdesc.base_dma); - } - reset_control_assert(dmac->rstc); err_pm_runtime_put: pm_runtime_put(&pdev->dev); @@ -1232,18 +1219,9 @@ static int rz_dmac_probe(struct platform_device *pde= v) static void rz_dmac_remove(struct platform_device *pdev) { struct rz_dmac *dmac =3D platform_get_drvdata(pdev); - unsigned int i; =20 dma_async_device_unregister(&dmac->engine); of_dma_controller_free(pdev->dev.of_node); - for (i =3D 0; i < dmac->n_channels; i++) { - struct rz_dmac_chan *channel =3D &dmac->channels[i]; - - dma_free_coherent(&pdev->dev, - sizeof(struct rz_lmdesc) * DMAC_NR_LMDESC, - channel->lmdesc.base, - channel->lmdesc.base_dma); - } reset_control_assert(dmac->rstc); pm_runtime_put(&pdev->dev); pm_runtime_disable(&pdev->dev); --=20 2.43.0 From nobody Mon Jun 8 21:46:47 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C5EC4313534; Tue, 26 May 2026 08:47:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779785252; cv=none; b=sMlLz3M+ttyx9pMWZhSM7ON09jChEERTZGwvMFzAqdIna1z7CAkyZdHC1lSRt8FfbkIx3rwZt3YUFIic1qCxV9GiwLbu/aeNEjoUReMadQpLWAN/TOAfakr5HviH7Drea784AWmUXlObR0FcSzdqmXL6hF7g0u1qxZQEDM8tD6M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779785252; c=relaxed/simple; bh=Em4TGyXCgUjHyYhSI61lFhPDE7mV1YFdAchhWA6h32o=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=k6Oj/vEQgb7grbemuNT3itVTkkG8pjEUOGO8BsvJk+Vu14h7b7TRdOIsJjDJO/IeJqnbXB2JjWDDO9q6Tk0XyjpiJfGNuIOwsTu9/nCn3OAnUzRAziFs0gQYJmQy2SPYZnyG4IRBL66ZeD5EiPgwYCA7t/q6gBBY2lWVT1ztPqA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=TTAV1XSu; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="TTAV1XSu" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D6C4C1F000E9; Tue, 26 May 2026 08:47:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1779785251; bh=q+xvWTRQdtA9TmNdQAgrWOSu3zCjt6VhewfshtUD8bI=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=TTAV1XSuxR6duoDe0Jlln6YT9b4m5/zHOzMcYDHJ2f/sb2q5bp4vT7BYOjdnuoWoP 0UumyappC50MQ20tXdjK7JWP3YWMqhKeJNy4vYqPne4IZK8zoQ8//Z/EVxao6Y1OAf W1kTHFO7S/hsmpMyuKqW5u8mKjBxBoz+LPStpcjqbRHAH5N/49UExav2Fy5ViI1VaT ZvsNqqmvGk1AjOnzXrTL1Y8L+/HFu5WZxpCHDfPvr1tl+1KecGD7qCN1gPUPEst3N4 vaHpGAQc6aXvlglmkq5QGjYvk/76kCc3El2EQB9HjsEwVUL7m/KECmONeBilm+x456 YOtpnTCMJYCxg== From: Claudiu Beznea To: vkoul@kernel.org, Frank.Li@kernel.org, lgirdwood@gmail.com, broonie@kernel.org, perex@perex.cz, tiwai@suse.com, biju.das.jz@bp.renesas.com, prabhakar.mahadev-lad.rj@bp.renesas.com, p.zabel@pengutronix.de, geert+renesas@glider.be, kuninori.morimoto.gx@renesas.com, long.luu.ur@renesas.com Cc: claudiu.beznea@kernel.org, claudiu.beznea@tuxon.dev, dmaengine@vger.kernel.org, linux-kernel@vger.kernel.org, linux-sound@vger.kernel.org, linux-renesas-soc@vger.kernel.org, Claudiu Beznea , stable@vger.kernel.org, John Madieu Subject: [PATCH v6 02/18] dmaengine: sh: rz-dmac: Fix incorrect NULL check for list_first_entry() Date: Tue, 26 May 2026 11:46:54 +0300 Message-ID: <20260526084710.3491480-3-claudiu.beznea@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260526084710.3491480-1-claudiu.beznea@kernel.org> References: <20260526084710.3491480-1-claudiu.beznea@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Claudiu Beznea list_first_entry() does not return NULL when the list is empty, making the existing NULL check invalid. Use list_first_entry_or_null() instead. Fixes: 21323b118c16 ("dmaengine: sh: rz-dmac: Add device_tx_status() callba= ck") Cc: stable@vger.kernel.org Tested-by: John Madieu Signed-off-by: Claudiu Beznea Tested-by: Tommaso Merciai --- Changes in v6: - collected tags - updated the patch title and description to reflect better the changes Changes in v5: - none Changes in v4: - none, this patch is new drivers/dma/sh/rz-dmac.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/dma/sh/rz-dmac.c b/drivers/dma/sh/rz-dmac.c index 9f206a33dcc6..6d80cb668957 100644 --- a/drivers/dma/sh/rz-dmac.c +++ b/drivers/dma/sh/rz-dmac.c @@ -723,8 +723,8 @@ static u32 rz_dmac_chan_get_residue(struct rz_dmac_chan= *channel, u32 crla, crtb, i; =20 /* Get current processing virtual descriptor */ - current_desc =3D list_first_entry(&channel->ld_active, - struct rz_dmac_desc, node); + current_desc =3D list_first_entry_or_null(&channel->ld_active, + struct rz_dmac_desc, node); if (!current_desc) return 0; =20 --=20 2.43.0 From nobody Mon Jun 8 21:46:47 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D246D3CE0AF; Tue, 26 May 2026 08:47:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779785257; cv=none; b=nvP3TBY3zKOR387+EvhLj1/18JjZqDO0HyTnfwRqHF6zMf7mSpK4OZv5GemGR2eFm+wzrSC1YHL45agE7RNxhdWvzEeZMyBY0Z0LsbVwtX6PpjwIUOWLEZ5Rb3AhjpGuMCpXQAuhp1BiMuV4AkknUkzYbNONBz9g1uAhnNsVRlY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779785257; c=relaxed/simple; bh=dOXXO6smS/hgkgXlh7QjPIQvG5iQs5dkEYEFowcS2zU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=pcAWhBebM5Cy4iSE2uLFV0SUJalNnOKwwT3JPRDnTCjX5jQHuZBR9jgeS0nYTyuNmv4CsbZI/prOloYqCwYBs82Css2CIqJPt5q6I2LTjdeKP8+4eDu6a4dg+P80bHihIZcpjvs5eVY1Pe8TWvOdL8QpAX13tdSCXnJ4dnkedzA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=aa6yauWi; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="aa6yauWi" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1819D1F00A3A; Tue, 26 May 2026 08:47:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1779785256; bh=vCNRTrFYWrhBaJRY6mUheb5Drs3QTKVC1HA4HvxgwHA=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=aa6yauWibIfIdDyXDfB8faeaEhzY8fDi6INerRQ3je18j+AGrqpi7tTZ3vM8Oiq8P 5urmktaI4VoMkWxdgSztx6g66WaEFl3mRf0xjVuVpq39FStitBr7ilj0B68sOqN70L NJeugFSgaBblc8diT94XX7XlSxFA/BpRb+nZjoicIworG9mqRUShaoTImwRTHMpau+ 8G2q24b/PoNcrnV/ra4XhOGjCGGAtLXYoL5+QtcmpJzvmtph8nT6w4V3ObYKJ7HcbM ethRZ4OHul3D54a0eMV4C3gSauoAN4N2/cr9xpLsVKOPoRTPDF3LribyDtnpctBLgK ZGqpopHg1lk+w== From: Claudiu Beznea To: vkoul@kernel.org, Frank.Li@kernel.org, lgirdwood@gmail.com, broonie@kernel.org, perex@perex.cz, tiwai@suse.com, biju.das.jz@bp.renesas.com, prabhakar.mahadev-lad.rj@bp.renesas.com, p.zabel@pengutronix.de, geert+renesas@glider.be, kuninori.morimoto.gx@renesas.com, long.luu.ur@renesas.com Cc: claudiu.beznea@kernel.org, claudiu.beznea@tuxon.dev, dmaengine@vger.kernel.org, linux-kernel@vger.kernel.org, linux-sound@vger.kernel.org, linux-renesas-soc@vger.kernel.org, Claudiu Beznea , Frank Li , John Madieu Subject: [PATCH v6 03/18] dmaengine: sh: rz-dmac: Use list_first_entry_or_null() Date: Tue, 26 May 2026 11:46:55 +0300 Message-ID: <20260526084710.3491480-4-claudiu.beznea@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260526084710.3491480-1-claudiu.beznea@kernel.org> References: <20260526084710.3491480-1-claudiu.beznea@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Claudiu Beznea Use list_first_entry_or_null() instead of open-coding it with a list_empty() check and list_first_entry(). This simplifies the code. Reviewed-by: Frank Li Tested-by: John Madieu Signed-off-by: Claudiu Beznea Tested-by: Tommaso Merciai --- Changes in v6: - collected tags Changes in v5: - none Changes in v4: - none Changes in v3: - none, this patch is new drivers/dma/sh/rz-dmac.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/drivers/dma/sh/rz-dmac.c b/drivers/dma/sh/rz-dmac.c index 6d80cb668957..1717b407ab9e 100644 --- a/drivers/dma/sh/rz-dmac.c +++ b/drivers/dma/sh/rz-dmac.c @@ -503,11 +503,10 @@ rz_dmac_prep_dma_memcpy(struct dma_chan *chan, dma_ad= dr_t dest, dma_addr_t src, __func__, channel->index, &src, &dest, len); =20 scoped_guard(spinlock_irqsave, &channel->vc.lock) { - if (list_empty(&channel->ld_free)) + desc =3D list_first_entry_or_null(&channel->ld_free, struct rz_dmac_desc= , node); + if (!desc) return NULL; =20 - desc =3D list_first_entry(&channel->ld_free, struct rz_dmac_desc, node); - desc->type =3D RZ_DMAC_DESC_MEMCPY; desc->src =3D src; desc->dest =3D dest; @@ -533,11 +532,10 @@ rz_dmac_prep_slave_sg(struct dma_chan *chan, struct s= catterlist *sgl, int i =3D 0; =20 scoped_guard(spinlock_irqsave, &channel->vc.lock) { - if (list_empty(&channel->ld_free)) + desc =3D list_first_entry_or_null(&channel->ld_free, struct rz_dmac_desc= , node); + if (!desc) return NULL; =20 - desc =3D list_first_entry(&channel->ld_free, struct rz_dmac_desc, node); - for_each_sg(sgl, sg, sg_len, i) dma_length +=3D sg_dma_len(sg); =20 --=20 2.43.0 From nobody Mon Jun 8 21:46:47 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CDF5C3CB90B; Tue, 26 May 2026 08:47:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779785262; cv=none; b=H0ZOhd0FuigvsENV3gtBDQmATNqRnwwecMHoMH5AcEOs1uqvIf9WIlsmHmY97+hbEVtYv+nYXCl+OF82jy+nEGbk1j8Ndb/FSwMwhl8fTP7FVobFVOTMyqjzV8+0bmmt4/GhgwW0FIY/r4Wb+W1vbuY+TA57eVmd9PlvVY+Gl8o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779785262; c=relaxed/simple; bh=zHOsvF3r8My9+a/blX5s4gYbAnSonFaADUYLxSO1XtI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ffoAJvbMD+JcVXtwFWquxX7Ji4tbhwPVag/xk7f5hlmvMowQcyrw/Nyhewh4J/qovUSxkk3y1AkcLEI6YIMzEaXYRpMUuNLzL6Q98LOjFw/tZPkihznZxNCnqm3mZL8y0Y8M5VGSC4rjga/9ZTazEzF02s+QnCZsuq13BTxMe3s= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Ak9C+P+x; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Ak9C+P+x" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 054301F00A3C; Tue, 26 May 2026 08:47:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1779785261; bh=h/Xo6c7rA6ZkqK8zsLmYgGZUvj28siO3yG2ezNiZLmE=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=Ak9C+P+x89kPXgciryi5UHVEy7Tqw8/8AWOvEYtPMpsr8ygDEpunPdu89SkVtts6k 2MxaOeR2RpdMdjBD5S0yGf9nlsxiTdMB7dK7Mam3SdHf8VTNQXBeI7CJCB1py3xcjd enW1QeESDneNffDzMAKU6vHoUcqWGb7mnlAJCtiVanGtFeD2AcmZWOeiT+STXTUXLA SrKuP2UG2QKFzEnWwMNT1sAqDYqxEoErtwLc83JIEMXBTEdtJQRuOlrYQaSUB1RTge xY7KOPciDybBxKJDs/Mg9HVcwEZ0VZSMk+k+1A7gzAQmddwQWgvsMNw0GHJCKs/CRM IEv3m25hFad2Q== From: Claudiu Beznea To: vkoul@kernel.org, Frank.Li@kernel.org, lgirdwood@gmail.com, broonie@kernel.org, perex@perex.cz, tiwai@suse.com, biju.das.jz@bp.renesas.com, prabhakar.mahadev-lad.rj@bp.renesas.com, p.zabel@pengutronix.de, geert+renesas@glider.be, kuninori.morimoto.gx@renesas.com, long.luu.ur@renesas.com Cc: claudiu.beznea@kernel.org, claudiu.beznea@tuxon.dev, dmaengine@vger.kernel.org, linux-kernel@vger.kernel.org, linux-sound@vger.kernel.org, linux-renesas-soc@vger.kernel.org, Claudiu Beznea , Frank Li , John Madieu Subject: [PATCH v6 04/18] dmaengine: sh: rz-dmac: Use rz_dmac_disable_hw() Date: Tue, 26 May 2026 11:46:56 +0300 Message-ID: <20260526084710.3491480-5-claudiu.beznea@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260526084710.3491480-1-claudiu.beznea@kernel.org> References: <20260526084710.3491480-1-claudiu.beznea@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Claudiu Beznea Use rz_dmac_disable_hw() instead of open coding it. This unifies the code and prepares it for the addition of suspend to RAM and cyclic DMA. The rz_dmac_disable_hw() from rz_dmac_chan_probe() was moved after vchan_init() as it initializes the channel->vc.chan.device used in rz_dmac_disable_hw(). Reviewed-by: Frank Li Tested-by: John Madieu Signed-off-by: Claudiu Beznea Tested-by: Tommaso Merciai --- Changes in v6: - fixed typo in patch description - collected tags Changes in v5: - none Changes in v4: - in rz_dmac_chan_probe(): moved rz_dmac_disable_hw() after the vchan_init(&channel->vc, &dmac->engine) call as this is the one which initializes data structures used by the debug code from rz_dmac_disable_hw(); updated the patch description to reflect this =20 Changes in v3: - none, this patch is new drivers/dma/sh/rz-dmac.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/dma/sh/rz-dmac.c b/drivers/dma/sh/rz-dmac.c index 1717b407ab9e..40ddf534c094 100644 --- a/drivers/dma/sh/rz-dmac.c +++ b/drivers/dma/sh/rz-dmac.c @@ -873,7 +873,7 @@ static void rz_dmac_irq_handle_channel(struct rz_dmac_c= han *channel) channel->index, chstat); =20 scoped_guard(spinlock_irqsave, &channel->vc.lock) - rz_dmac_ch_writel(channel, CHCTRL_DEFAULT, CHCTRL, 1); + rz_dmac_disable_hw(channel); return; } =20 @@ -1000,15 +1000,15 @@ static int rz_dmac_chan_probe(struct rz_dmac *dmac, } rz_lmdesc_setup(channel, lmdesc); =20 - /* Initialize register for each channel */ - rz_dmac_ch_writel(channel, CHCTRL_DEFAULT, CHCTRL, 1); - channel->vc.desc_free =3D rz_dmac_virt_desc_free; vchan_init(&channel->vc, &dmac->engine); INIT_LIST_HEAD(&channel->ld_queue); INIT_LIST_HEAD(&channel->ld_free); INIT_LIST_HEAD(&channel->ld_active); =20 + /* Initialize register for each channel */ + rz_dmac_disable_hw(channel); + /* Request the channel interrupt. */ scnprintf(pdev_irqname, sizeof(pdev_irqname), "ch%u", index); irq =3D platform_get_irq_byname(pdev, pdev_irqname); --=20 2.43.0 From nobody Mon Jun 8 21:46:47 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F2E473CDBD3; Tue, 26 May 2026 08:47:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779785268; cv=none; b=E0otGNcpvcyut/HS2ycp1AIC47ScajoYIdBbhKIAYgANug9hjj/T2nOiEAKV2Zc6MSXMl8GCSMWT5pJqdypuWJi3kVeg7O+V84aAEIx3CA7kIlFos1Fi4Eur32hHpFgYOSFz2ekRMLqf+UlQVA855pwkqhhoEW5iNYkeHwbxvMQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779785268; c=relaxed/simple; bh=3+WQEB1tCHft4J06EvUiUd460PHjj8UHaQXaNA31Up4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=EMhWXnSM7zZpQOUqt9/YwafSI+tdM29c2hCay/6e9ODROqYrCt2JlIOOEV7H47s/bdVr6v4Xmq7mf4af2h0a9SiyT3ow6BepGPByzWB0f8mlE77IRoRp6UM6amv6035HmsqpFZP7OeSnqS4WrFLap79mr1Buq6Ndhl02pfSAMA4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=mC6qd64I; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="mC6qd64I" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E33041F000E9; Tue, 26 May 2026 08:47:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1779785266; bh=u38Mn20jaBcjJJKPeB5LG08OBQ5jyQmIULL1EIPQ35c=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=mC6qd64Iz8Gz70qgPxl31HWr4Z+G1NFuB6Ed9k5SJb6VxIQUudONfqcXFISbbPOSZ /sBTGFdxgeeavVk97m8yBA/52f0An+nkNx8yXse+CO7nm5AGrUgxe3i4X7CeC+LyHr GSVl+VYja9jzwLbCNkVv39HNUhYY3Wj0Y7J3TUtQj13tNAAG8GqNlrRCPehFgJko75 26mrp13eMBzJR0hCXJm4yKjJlwqIB0vUMvQ7XHWVnUbYlFxC4BCtwNDffEiDC/q03d +tJV+XUDJU8fICijgiZKpqHVgqcaNBi1mFqSmh8qy9BPybCJu0ZjxVPYk6YfS7C7rZ R5YlFxMVhaaoA== From: Claudiu Beznea To: vkoul@kernel.org, Frank.Li@kernel.org, lgirdwood@gmail.com, broonie@kernel.org, perex@perex.cz, tiwai@suse.com, biju.das.jz@bp.renesas.com, prabhakar.mahadev-lad.rj@bp.renesas.com, p.zabel@pengutronix.de, geert+renesas@glider.be, kuninori.morimoto.gx@renesas.com, long.luu.ur@renesas.com Cc: claudiu.beznea@kernel.org, claudiu.beznea@tuxon.dev, dmaengine@vger.kernel.org, linux-kernel@vger.kernel.org, linux-sound@vger.kernel.org, linux-renesas-soc@vger.kernel.org, Claudiu Beznea , Frank Li , John Madieu Subject: [PATCH v6 05/18] dmaengine: sh: rz-dmac: Add helper to compute the lmdesc address Date: Tue, 26 May 2026 11:46:57 +0300 Message-ID: <20260526084710.3491480-6-claudiu.beznea@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260526084710.3491480-1-claudiu.beznea@kernel.org> References: <20260526084710.3491480-1-claudiu.beznea@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Claudiu Beznea Add a the rz_dmac_lmdesc_addr() helper function to compute the lmdesc address, to make the code easier to understand. The helper will be used in subsequent patches. Reviewed-by: Frank Li Tested-by: John Madieu Signed-off-by: Claudiu Beznea Tested-by: Tommaso Merciai --- Changes in v6: - updated patch description - collected tags Changes in v5: - none Changes in v4: - none Changes in v3: - none, this patch is new drivers/dma/sh/rz-dmac.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/drivers/dma/sh/rz-dmac.c b/drivers/dma/sh/rz-dmac.c index 40ddf534c094..c48858b68dee 100644 --- a/drivers/dma/sh/rz-dmac.c +++ b/drivers/dma/sh/rz-dmac.c @@ -259,6 +259,12 @@ static void rz_lmdesc_setup(struct rz_dmac_chan *chann= el, * Descriptors preparation */ =20 +static u32 rz_dmac_lmdesc_addr(struct rz_dmac_chan *channel, struct rz_lmd= esc *lmdesc) +{ + return channel->lmdesc.base_dma + + (sizeof(struct rz_lmdesc) * (lmdesc - channel->lmdesc.base)); +} + static void rz_dmac_lmdesc_recycle(struct rz_dmac_chan *channel) { struct rz_lmdesc *lmdesc =3D channel->lmdesc.head; @@ -284,9 +290,7 @@ static void rz_dmac_enable_hw(struct rz_dmac_chan *chan= nel) =20 rz_dmac_lmdesc_recycle(channel); =20 - nxla =3D channel->lmdesc.base_dma + - (sizeof(struct rz_lmdesc) * (channel->lmdesc.head - - channel->lmdesc.base)); + nxla =3D rz_dmac_lmdesc_addr(channel, channel->lmdesc.head); =20 chstat =3D rz_dmac_ch_readl(channel, CHSTAT, 1); if (!(chstat & CHSTAT_EN)) { --=20 2.43.0 From nobody Mon Jun 8 21:46:47 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 998B63CB90B; Tue, 26 May 2026 08:47:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779785272; cv=none; b=bWmfbNlyjNTLb++SpWZWEb1yoWdfbnlWCULo0iNz0+yAYBmJ8I2Hwft3AZpTPAwijKFH6DzmskO+Lu2FH8/g1M7ocfesgNePdSrBcLf5F+CKTfMHaWhlVe0fGIuzcPIXMiFcYI00VuvoR+7RKCeX0a1ZU1PBVcQkW35wrBs9bBk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779785272; c=relaxed/simple; bh=LM1f+K7t6TYKKobqHrpVTEm41o7msjjzymMZrtuGH78=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=aOyRB0BLfz90K7/tt2gLOEN4oYYPwnQjxdgdovPJpw0lz1shLciNmJhJh+QzUT1igUzA5hBZIp/7yoHpWGD77pmtjfar4P5Pi7+Rs+vLRsi3GWe4b47KuIFwiU328erfbZ3uKtSNFl2Kb6UAmkdz04hAEl447Nj6SfGErPvHkAU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=DDW5HIeu; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="DDW5HIeu" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0F5541F00A3A; Tue, 26 May 2026 08:47:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1779785271; bh=8p2kKCAJLqQkQxs3mctL/1IplJ0yad6mXOuWmw8USPQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=DDW5HIeuaSC66mZMvi1YzCZKsQjBJcupwPsO+ctTHzMqG0HLtWqX9O+0HDm8XVU1o Edfqgx0LCN7O/NP2ofQIB/dWVRJpBsUeYx1aFE2aw2S8BSyeBGsVykCJZYa0UONcr9 zNoakU0fZ38ZGMhqGaZTe4R02Cqvp7qHeL+wq9+aPys1zYhLix74B3UA8QsyuE+tC+ w2tf6f6p7eqSQfTDgV734b9PB1s2Q2RAn2w17F1sYOzWGPO4NpYgqyCFsJ/eBdPfSx Qs8q75oQFlc3qiEJIkvmkmWfgdWx3PHXvb25IFLL5B6D1A0PO2foHpJFuOyMd9nEyT t9BHxSmdfEGAg== From: Claudiu Beznea To: vkoul@kernel.org, Frank.Li@kernel.org, lgirdwood@gmail.com, broonie@kernel.org, perex@perex.cz, tiwai@suse.com, biju.das.jz@bp.renesas.com, prabhakar.mahadev-lad.rj@bp.renesas.com, p.zabel@pengutronix.de, geert+renesas@glider.be, kuninori.morimoto.gx@renesas.com, long.luu.ur@renesas.com Cc: claudiu.beznea@kernel.org, claudiu.beznea@tuxon.dev, dmaengine@vger.kernel.org, linux-kernel@vger.kernel.org, linux-sound@vger.kernel.org, linux-renesas-soc@vger.kernel.org, Claudiu Beznea , John Madieu Subject: [PATCH v6 06/18] dmaengine: sh: rz-dmac: Save the start LM descriptor Date: Tue, 26 May 2026 11:46:58 +0300 Message-ID: <20260526084710.3491480-7-claudiu.beznea@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260526084710.3491480-1-claudiu.beznea@kernel.org> References: <20260526084710.3491480-1-claudiu.beznea@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Claudiu Beznea Save the start LM descriptor to avoid starting from the beginning of the channel's LM descriptor list in rz_dmac_calculate_residue_bytes_in_vd(). This avoids unnecessary iterations. Tested-by: John Madieu Signed-off-by: Claudiu Beznea Tested-by: Tommaso Merciai --- Changes in v6: - updated patch description to describe better the changes - collected tags Changes in v5: - none Changes in v4: - none Changes in v3: - none, this patch is new drivers/dma/sh/rz-dmac.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/drivers/dma/sh/rz-dmac.c b/drivers/dma/sh/rz-dmac.c index c48858b68dee..d3926ecd63ac 100644 --- a/drivers/dma/sh/rz-dmac.c +++ b/drivers/dma/sh/rz-dmac.c @@ -58,6 +58,7 @@ struct rz_dmac_desc { /* For slave sg */ struct scatterlist *sg; unsigned int sgcount; + struct rz_lmdesc *start_lmdesc; }; =20 #define to_rz_dmac_desc(d) container_of(d, struct rz_dmac_desc, vd) @@ -343,6 +344,8 @@ static void rz_dmac_prepare_desc_for_memcpy(struct rz_d= mac_chan *channel) struct rz_dmac_desc *d =3D channel->desc; u32 chcfg =3D CHCFG_MEM_COPY; =20 + d->start_lmdesc =3D lmdesc; + /* prepare descriptor */ lmdesc->sa =3D d->src; lmdesc->da =3D d->dest; @@ -377,6 +380,7 @@ static void rz_dmac_prepare_descs_for_slave_sg(struct r= z_dmac_chan *channel) } =20 lmdesc =3D channel->lmdesc.tail; + d->start_lmdesc =3D lmdesc; =20 for (i =3D 0, sg =3D sgl; i < sg_len; i++, sg =3D sg_next(sg)) { if (d->direction =3D=3D DMA_DEV_TO_MEM) { @@ -693,9 +697,10 @@ rz_dmac_get_next_lmdesc(struct rz_lmdesc *base, struct= rz_lmdesc *lmdesc) return next; } =20 -static u32 rz_dmac_calculate_residue_bytes_in_vd(struct rz_dmac_chan *chan= nel, u32 crla) +static u32 rz_dmac_calculate_residue_bytes_in_vd(struct rz_dmac_chan *chan= nel, + struct rz_dmac_desc *desc, u32 crla) { - struct rz_lmdesc *lmdesc =3D channel->lmdesc.head; + struct rz_lmdesc *lmdesc =3D desc->start_lmdesc; struct dma_chan *chan =3D &channel->vc.chan; struct rz_dmac *dmac =3D to_rz_dmac(chan->device); u32 residue =3D 0, i =3D 0; @@ -794,7 +799,7 @@ static u32 rz_dmac_chan_get_residue(struct rz_dmac_chan= *channel, * Calculate number of bytes transferred in processing virtual descriptor. * One virtual descriptor can have many lmdesc. */ - return crtb + rz_dmac_calculate_residue_bytes_in_vd(channel, crla); + return crtb + rz_dmac_calculate_residue_bytes_in_vd(channel, current_desc= , crla); } =20 static enum dma_status rz_dmac_tx_status(struct dma_chan *chan, --=20 2.43.0 From nobody Mon Jun 8 21:46:47 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 208893CDBD3; Tue, 26 May 2026 08:47:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779785278; cv=none; b=rGVx/EaGWKlpFfVi3ga6/4mHSAscnOtKpcyM9FKH26yUvJc3z2/iugDC/tuiTitZPku98I17nDjsnyhT/kwPtSoXc0blgswQc5nAI1Y92k80LpA9pz7gHboNbl3LXUiEHRQPj5L35fQPqNtBuZcE5oUfPTFY+41+o+MKVlLT22Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779785278; c=relaxed/simple; bh=pKWJIrWwULK7MPPuh4dScm97Qn6DeLGIoD1s9Cj52J0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=JgnGOvBLSUWJuof0uEymiqiz58Mwx5OUib7uCLJfTDTLUkQx4IENGDOGvaVeQei7fHKYM1RBFLCoJk1046Yxdb7anIAz7hVm5Paerw4y6ygAy0xP01K6kVD/neplppLAHF/sbwiaZ9DXqq+Oqzn/M3HdaFpkJV8WsDZSS/xQG9M= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=dRRyk4PP; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="dRRyk4PP" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0120B1F000E9; Tue, 26 May 2026 08:47:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1779785276; bh=i5Nn6yL11taMy19yhSsiN9EMkHGwtd+/hvtzhxnGpO4=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=dRRyk4PP4MbXw8jCvgJuAa1eETEnugdc9NMrqoTzE/TgPCgIIDZrKBvH6ShYeZlV8 IaRmGQWT+MTrAy2YziUpwsf2L7dab0FNDD7XJkUj84Iw8htDUtYBBmpXAxgnCb1Epv uKMz1v/aAJujWaxgjqZWCUTYuSNZ0YZIi+ZRQt1VXtf/iswqyq71uRWtixKKY/oF8D KmJs9aY9A3ADVMKPTAz5/739fyGu3JNcgLY6tV9bNt2pZM2mzCNPtgX3nreMfeigZg wucA4KckivxUpR6Zkv6A3EOeFSsvHReuUnJiVOnuaiYXmjBHMHwwygpvGitdIE9mlC sRi9RQmltzlJA== From: Claudiu Beznea To: vkoul@kernel.org, Frank.Li@kernel.org, lgirdwood@gmail.com, broonie@kernel.org, perex@perex.cz, tiwai@suse.com, biju.das.jz@bp.renesas.com, prabhakar.mahadev-lad.rj@bp.renesas.com, p.zabel@pengutronix.de, geert+renesas@glider.be, kuninori.morimoto.gx@renesas.com, long.luu.ur@renesas.com Cc: claudiu.beznea@kernel.org, claudiu.beznea@tuxon.dev, dmaengine@vger.kernel.org, linux-kernel@vger.kernel.org, linux-sound@vger.kernel.org, linux-renesas-soc@vger.kernel.org, Claudiu Beznea , Frank Li , John Madieu Subject: [PATCH v6 07/18] dmaengine: sh: rz-dmac: Add helper to check if the channel is enabled Date: Tue, 26 May 2026 11:46:59 +0300 Message-ID: <20260526084710.3491480-8-claudiu.beznea@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260526084710.3491480-1-claudiu.beznea@kernel.org> References: <20260526084710.3491480-1-claudiu.beznea@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Claudiu Beznea Add the rz_dmac_chan_is_enabled() helper to check if a channel is enabled. This helper will be reused in subsequent patches. Reviewed-by: Frank Li Tested-by: John Madieu Signed-off-by: Claudiu Beznea Tested-by: Tommaso Merciai --- Changes in v6: - updated the patch description to describe better the changes - collected tags - s/chan/channel in rz_dmac_chan_is_enabled() to follow the naming conventi= on accross the driver for the variable of type struct rz_dmac_chan Changes in v5: - none Changes in v4: - none Changes in v3: - none, this patch is new drivers/dma/sh/rz-dmac.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/drivers/dma/sh/rz-dmac.c b/drivers/dma/sh/rz-dmac.c index d3926ecd63ac..76bac11c217c 100644 --- a/drivers/dma/sh/rz-dmac.c +++ b/drivers/dma/sh/rz-dmac.c @@ -279,6 +279,13 @@ static void rz_dmac_lmdesc_recycle(struct rz_dmac_chan= *channel) channel->lmdesc.head =3D lmdesc; } =20 +static bool rz_dmac_chan_is_enabled(struct rz_dmac_chan *channel) +{ + u32 val =3D rz_dmac_ch_readl(channel, CHSTAT, 1); + + return !!(val & CHSTAT_EN); +} + static void rz_dmac_enable_hw(struct rz_dmac_chan *channel) { struct dma_chan *chan =3D &channel->vc.chan; @@ -840,8 +847,7 @@ static int rz_dmac_device_pause(struct dma_chan *chan) =20 guard(spinlock_irqsave)(&channel->vc.lock); =20 - val =3D rz_dmac_ch_readl(channel, CHSTAT, 1); - if (!(val & CHSTAT_EN)) + if (!rz_dmac_chan_is_enabled(channel)) return 0; =20 rz_dmac_ch_writel(channel, CHCTRL_SETSUS, CHCTRL, 1); --=20 2.43.0 From nobody Mon Jun 8 21:46:47 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2587C3CEBBC; Tue, 26 May 2026 08:48:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779785283; cv=none; b=hiCiUl7BlAlV4CIRMqrXhJjbGU+OT318B7DQo6w0XMJNlb9g1ELieUMLWwTv4dEuFFpziFiZKdMh1Mf/DM9rwzxM1z0rx705bZYY6pKGc4jVzLHGFjAni52mP/yZ1v+/nGRwR5OPdtt/xXayEWaEI+8mW8dMonOFv8nYW1rjJ94= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779785283; c=relaxed/simple; bh=Ix63j2ZVDp+zmFw7/HmTbwuDBZAfwIj21b78ccIHkEg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=FpgVOhyPFqUDmn1Nyd0mT+lfHcsHkCPAsY6CPBz4VSB0MCdNsD4r/wqYRb1GoBiw4fm0+mN323hsQ2uhKFJ3n3C59f4FexATPKxaVfSk8f0aXAml3SzhISczeIWBvoqEKmq6sPem3BB0oQdj7f8/8XbZ+7jdCu2nLlXFctttnrU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=OgMDwijR; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="OgMDwijR" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4BB081F00A3A; Tue, 26 May 2026 08:47:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1779785282; bh=eBq2EtSdW18GdR3eVuCaJSBPEyIAcAZy8dUcYAo1pSA=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=OgMDwijR07UHDSqhzp1stEW0tUVszC+6gLS9j6Sfb0Ujs7gbvSc46l1Itp2aRjaFG 81yb1TCV22VBNWanxDiJz2NCIxvWz76L4BzBrHgx1bjfjLiP+d+I5WQ99T3oMYi0Fs TrsTnugpMqahVb4X09x2Kl36WSHPlBjlPmvkF0wEc5PykKHwac/FtwwOSc8PHQvhqW iSoE4tvJyR35v6j2cRYTfWJBRyzqsKSuvAtr3S1c3uZogDtQQGeHAraLOwFKUPbBUI hoxwhKAmDi3xqrJpaWQTUj0haXjnDbdOtfJN/Z06cKnNBygR8aAkmXxRNo8i9D89TZ r4ZtOv7cPqu7A== From: Claudiu Beznea To: vkoul@kernel.org, Frank.Li@kernel.org, lgirdwood@gmail.com, broonie@kernel.org, perex@perex.cz, tiwai@suse.com, biju.das.jz@bp.renesas.com, prabhakar.mahadev-lad.rj@bp.renesas.com, p.zabel@pengutronix.de, geert+renesas@glider.be, kuninori.morimoto.gx@renesas.com, long.luu.ur@renesas.com Cc: claudiu.beznea@kernel.org, claudiu.beznea@tuxon.dev, dmaengine@vger.kernel.org, linux-kernel@vger.kernel.org, linux-sound@vger.kernel.org, linux-renesas-soc@vger.kernel.org, Claudiu Beznea , Frank Li , John Madieu Subject: [PATCH v6 08/18] dmaengine: sh: rz-dmac: Add helper to check if the channel is paused Date: Tue, 26 May 2026 11:47:00 +0300 Message-ID: <20260526084710.3491480-9-claudiu.beznea@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260526084710.3491480-1-claudiu.beznea@kernel.org> References: <20260526084710.3491480-1-claudiu.beznea@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Claudiu Beznea Add the rz_dmac_chan_is_paused() helper to check if the channel is paused. This helper will be reused in subsequent patches. Reviewed-by: Frank Li Tested-by: John Madieu Signed-off-by: Claudiu Beznea Tested-by: Tommaso Merciai --- Changes in v6: - updated patch description to reflect better the changes - collected tags - s/chan/channel in rz_dmac_chan_is_paused() to follow the naming convention accross the driver for the variable of type struct rz_dmac_chan Changes in v5: - none Changes in v4: - none Changes in v3: - none, this patch is new drivers/dma/sh/rz-dmac.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/drivers/dma/sh/rz-dmac.c b/drivers/dma/sh/rz-dmac.c index 76bac11c217c..217657513fa7 100644 --- a/drivers/dma/sh/rz-dmac.c +++ b/drivers/dma/sh/rz-dmac.c @@ -286,6 +286,13 @@ static bool rz_dmac_chan_is_enabled(struct rz_dmac_cha= n *channel) return !!(val & CHSTAT_EN); } =20 +static bool rz_dmac_chan_is_paused(struct rz_dmac_chan *channel) +{ + u32 val =3D rz_dmac_ch_readl(channel, CHSTAT, 1); + + return !!(val & CHSTAT_SUS); +} + static void rz_dmac_enable_hw(struct rz_dmac_chan *channel) { struct dma_chan *chan =3D &channel->vc.chan; @@ -822,12 +829,9 @@ static enum dma_status rz_dmac_tx_status(struct dma_ch= an *chan, return status; =20 scoped_guard(spinlock_irqsave, &channel->vc.lock) { - u32 val; - residue =3D rz_dmac_chan_get_residue(channel, cookie); =20 - val =3D rz_dmac_ch_readl(channel, CHSTAT, 1); - if (val & CHSTAT_SUS) + if (rz_dmac_chan_is_paused(channel)) status =3D DMA_PAUSED; } =20 --=20 2.43.0 From nobody Mon Jun 8 21:46:47 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 620FA3CEBBD; Tue, 26 May 2026 08:48:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779785289; cv=none; b=rbHtUuvEdLQNKJfEfhCZ5sVfJD84GLI4Y9RpgU/6aMVFGygVfyepyjvDnGlb89dWFq32bbRsR19D6HF0sdynn3X5JP3PsHbL5gM9zD94ZyoIvfFSiUt+f8iZprOVD94j+QCYdigp+ISg9M999DnXHCK8bpdQ1T8oAPaUlUaqmfw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779785289; c=relaxed/simple; bh=/mPYLQlMXC+E68sfWJk8pFpnC8M5M3d7l3tjusv6WRg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZcZsRcXQYLqUXcSQVwKgCc6zK18Z9VQmKDlzJh3rIB8qAbFLs8zo1ab3rTAKGz6RA0F0rAo1qLX1qf8iSMyadPWuIdLOBNJtDNEEEHAuY6qVfcURPiB3aOuDfpknzU5KLUa0jwnJ16hFPhZNYw38J1QUOHEbSVUkK5Wc34akOVo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=PpuIXhNY; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="PpuIXhNY" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 86F291F000E9; Tue, 26 May 2026 08:48:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1779785286; bh=k91dWFt0ymKodPPvZmmR55xgb4aQRHNzFX1xgTdltT4=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=PpuIXhNYSLYLME8JkSRYSuSV+doRlQc+Z9CpZrOZLZ7zhnT+E2Ee1p6eHZBNdNzwn Y6j2H5DiCyNV4UwzUbUAm8/82ysoc4JMFnvi5hLI+v2CxVLKvNtsS99JNdPnXpHlhf lLa0o/14B+D/klK2cZOp5hnp9Nx83NJA+QDBcQOzVGP8SDvv4ztVDzwxZTQNSDVvB+ waxnC9qMr+y1dPnkz96lRyIKAwp5NFkqGt4L/GiIRpWtfaTGTD0DsAMn62O1H2zEuO E+1VQTrw7OW/QTTKOEoiqDkmLn9ImPC1OKpFTJlVSo87ew6deARlVVNETl3RcJn1xF rvUDkaMxR368g== From: Claudiu Beznea To: vkoul@kernel.org, Frank.Li@kernel.org, lgirdwood@gmail.com, broonie@kernel.org, perex@perex.cz, tiwai@suse.com, biju.das.jz@bp.renesas.com, prabhakar.mahadev-lad.rj@bp.renesas.com, p.zabel@pengutronix.de, geert+renesas@glider.be, kuninori.morimoto.gx@renesas.com, long.luu.ur@renesas.com Cc: claudiu.beznea@kernel.org, claudiu.beznea@tuxon.dev, dmaengine@vger.kernel.org, linux-kernel@vger.kernel.org, linux-sound@vger.kernel.org, linux-renesas-soc@vger.kernel.org, Claudiu Beznea , John Madieu Subject: [PATCH v6 09/18] dmaengine: sh: rz-dmac: Use virt-dma APIs for channel descriptor processing Date: Tue, 26 May 2026 11:47:01 +0300 Message-ID: <20260526084710.3491480-10-claudiu.beznea@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260526084710.3491480-1-claudiu.beznea@kernel.org> References: <20260526084710.3491480-1-claudiu.beznea@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Claudiu Beznea The driver used a mix of virt-dma APIs and driver specific logic to process descriptors. It maintained three internal queues: ld_free, ld_queue, and ld_active as follows: - ld_free: stores the descriptors pre-allocated at probe time - ld_queue: stores descriptors after they are taken from ld_free and prepared. At the same time, vchan_tx_prep() queues them to vc->desc_allocated. The vc->desc_allocated list is then checked in rz_dmac_issue_pending() and rz_dmac_irq_handler_thread() before starting a new transfer via rz_dmac_xfer_desc(). In turn, rz_dmac_xfer_desc() grabs the next descriptor from vc->desc_issued and submits it for transfer - ld_active: stores the descriptors currently being transferred The interrupt handler moved a completed descriptor to ld_free before invoking its completion callback. Once returned to ld_free, the descriptor can be reused to prepare a new transfer. In theory, this means the descriptor could be re-prepared before its completion callback is called. Commit fully back the driver by the virt-dma APIs. With this, only ld_free need to be kept to track how many free descriptors are available. This is now done as follows: - the prepare stage removes the first descriptor from the ld_free and prepares it - the completion calls for it vc->desc_free() (rz_dmac_virt_desc_free()) which re-adds the descriptor at the end of ld_free With this, the critical areas in prepare callbacks were minimized to only getting the descriptor from the ld_free list. Introduce struct rz_dmac_chan::desc to keep track of the currently transferred descriptor. It is cleared in rz_dmac_terminate_all(), referenced from rz_dmac_issue_pending() to determine whether a new transfer can be started, and from rz_dmac_irq_handler_thread() once a descriptor has completed. Finally, the rz_dmac_device_synchronize() was updated with vchan_synchronize() call to ensure the terminated descriptor is freed and the tasklet is killed. With this, residue computation is also simplified, as it can now be handled entirely through the virt-dma APIs. The spin_lock/unlock operations from rz_dmac_irq_handler_thread() were replaced by guard as the final code after rework is simpler this way. As subsequent commits will set the Link End bit on the last descriptor of a transfer, rz_dmac_enable_hw() is also adjusted as part of the full conversion to virt-dma APIs. It no longer checks the channel enable status itself; instead, its callers verify whether the channel is enabled and whether the previous transfer has completed before starting a new one. Tested-by: John Madieu Signed-off-by: Claudiu Beznea Tested-by: Tommaso Merciai --- Changes in v6: - updated patch description as suggested in the review process - collected tags Changes in v5: - none Changes in v4: - in rz_dmac_tx_status(): return DMA_PAUSED if the channel is paused; call rz_dmac_chan_get_residue() only if status is not complete Changes in v3: - none, this patch is new drivers/dma/sh/rz-dmac.c | 233 +++++++++++++++------------------------ 1 file changed, 86 insertions(+), 147 deletions(-) diff --git a/drivers/dma/sh/rz-dmac.c b/drivers/dma/sh/rz-dmac.c index 217657513fa7..1f884ec101f8 100644 --- a/drivers/dma/sh/rz-dmac.c +++ b/drivers/dma/sh/rz-dmac.c @@ -79,8 +79,6 @@ struct rz_dmac_chan { int mid_rid; =20 struct list_head ld_free; - struct list_head ld_queue; - struct list_head ld_active; =20 struct { struct rz_lmdesc *base; @@ -299,7 +297,6 @@ static void rz_dmac_enable_hw(struct rz_dmac_chan *chan= nel) struct rz_dmac *dmac =3D to_rz_dmac(chan->device); u32 nxla; u32 chctrl; - u32 chstat; =20 dev_dbg(dmac->dev, "%s channel %d\n", __func__, channel->index); =20 @@ -307,14 +304,11 @@ static void rz_dmac_enable_hw(struct rz_dmac_chan *ch= annel) =20 nxla =3D rz_dmac_lmdesc_addr(channel, channel->lmdesc.head); =20 - chstat =3D rz_dmac_ch_readl(channel, CHSTAT, 1); - if (!(chstat & CHSTAT_EN)) { - chctrl =3D (channel->chctrl | CHCTRL_SETEN); - rz_dmac_ch_writel(channel, nxla, NXLA, 1); - rz_dmac_ch_writel(channel, channel->chcfg, CHCFG, 1); - rz_dmac_ch_writel(channel, CHCTRL_SWRST, CHCTRL, 1); - rz_dmac_ch_writel(channel, chctrl, CHCTRL, 1); - } + chctrl =3D (channel->chctrl | CHCTRL_SETEN); + rz_dmac_ch_writel(channel, nxla, NXLA, 1); + rz_dmac_ch_writel(channel, channel->chcfg, CHCFG, 1); + rz_dmac_ch_writel(channel, CHCTRL_SWRST, CHCTRL, 1); + rz_dmac_ch_writel(channel, chctrl, CHCTRL, 1); } =20 static void rz_dmac_disable_hw(struct rz_dmac_chan *channel) @@ -426,18 +420,20 @@ static void rz_dmac_prepare_descs_for_slave_sg(struct= rz_dmac_chan *channel) channel->chctrl =3D CHCTRL_SETEN; } =20 -static int rz_dmac_xfer_desc(struct rz_dmac_chan *chan) +static void rz_dmac_xfer_desc(struct rz_dmac_chan *chan) { - struct rz_dmac_desc *d =3D chan->desc; struct virt_dma_desc *vd; =20 vd =3D vchan_next_desc(&chan->vc); - if (!vd) - return 0; + if (!vd) { + chan->desc =3D NULL; + return; + } =20 list_del(&vd->node); + chan->desc =3D to_rz_dmac_desc(vd); =20 - switch (d->type) { + switch (chan->desc->type) { case RZ_DMAC_DESC_MEMCPY: rz_dmac_prepare_desc_for_memcpy(chan); break; @@ -445,14 +441,9 @@ static int rz_dmac_xfer_desc(struct rz_dmac_chan *chan) case RZ_DMAC_DESC_SLAVE_SG: rz_dmac_prepare_descs_for_slave_sg(chan); break; - - default: - return -EINVAL; } =20 rz_dmac_enable_hw(chan); - - return 0; } =20 /* @@ -494,8 +485,6 @@ static void rz_dmac_free_chan_resources(struct dma_chan= *chan) rz_lmdesc_setup(channel, channel->lmdesc.base); =20 rz_dmac_disable_hw(channel); - list_splice_tail_init(&channel->ld_active, &channel->ld_free); - list_splice_tail_init(&channel->ld_queue, &channel->ld_free); =20 if (channel->mid_rid >=3D 0) { clear_bit(channel->mid_rid, dmac->modules); @@ -504,13 +493,19 @@ static void rz_dmac_free_chan_resources(struct dma_ch= an *chan) =20 spin_unlock_irqrestore(&channel->vc.lock, flags); =20 + vchan_free_chan_resources(&channel->vc); + + spin_lock_irqsave(&channel->vc.lock, flags); + list_for_each_entry_safe(desc, _desc, &channel->ld_free, node) { + list_del(&desc->node); kfree(desc); channel->descs_allocated--; } =20 INIT_LIST_HEAD(&channel->ld_free); - vchan_free_chan_resources(&channel->vc); + + spin_unlock_irqrestore(&channel->vc.lock, flags); } =20 static struct dma_async_tx_descriptor * @@ -529,15 +524,15 @@ rz_dmac_prep_dma_memcpy(struct dma_chan *chan, dma_ad= dr_t dest, dma_addr_t src, if (!desc) return NULL; =20 - desc->type =3D RZ_DMAC_DESC_MEMCPY; - desc->src =3D src; - desc->dest =3D dest; - desc->len =3D len; - desc->direction =3D DMA_MEM_TO_MEM; - - list_move_tail(channel->ld_free.next, &channel->ld_queue); + list_del(&desc->node); } =20 + desc->type =3D RZ_DMAC_DESC_MEMCPY; + desc->src =3D src; + desc->dest =3D dest; + desc->len =3D len; + desc->direction =3D DMA_MEM_TO_MEM; + return vchan_tx_prep(&channel->vc, &desc->vd, flags); } =20 @@ -558,22 +553,22 @@ rz_dmac_prep_slave_sg(struct dma_chan *chan, struct s= catterlist *sgl, if (!desc) return NULL; =20 - for_each_sg(sgl, sg, sg_len, i) - dma_length +=3D sg_dma_len(sg); + list_del(&desc->node); + } =20 - desc->type =3D RZ_DMAC_DESC_SLAVE_SG; - desc->sg =3D sgl; - desc->sgcount =3D sg_len; - desc->len =3D dma_length; - desc->direction =3D direction; + for_each_sg(sgl, sg, sg_len, i) + dma_length +=3D sg_dma_len(sg); =20 - if (direction =3D=3D DMA_DEV_TO_MEM) - desc->src =3D channel->src_per_address; - else - desc->dest =3D channel->dst_per_address; + desc->type =3D RZ_DMAC_DESC_SLAVE_SG; + desc->sg =3D sgl; + desc->sgcount =3D sg_len; + desc->len =3D dma_length; + desc->direction =3D direction; =20 - list_move_tail(channel->ld_free.next, &channel->ld_queue); - } + if (direction =3D=3D DMA_DEV_TO_MEM) + desc->src =3D channel->src_per_address; + else + desc->dest =3D channel->dst_per_address; =20 return vchan_tx_prep(&channel->vc, &desc->vd, flags); } @@ -588,8 +583,11 @@ static int rz_dmac_terminate_all(struct dma_chan *chan) rz_dmac_disable_hw(channel); rz_lmdesc_setup(channel, channel->lmdesc.base); =20 - list_splice_tail_init(&channel->ld_active, &channel->ld_free); - list_splice_tail_init(&channel->ld_queue, &channel->ld_free); + if (channel->desc) { + vchan_terminate_vdesc(&channel->desc->vd); + channel->desc =3D NULL; + } + vchan_get_all_descriptors(&channel->vc, &head); spin_unlock_irqrestore(&channel->vc.lock, flags); vchan_dma_desc_free_list(&channel->vc, &head); @@ -600,25 +598,16 @@ static int rz_dmac_terminate_all(struct dma_chan *cha= n) static void rz_dmac_issue_pending(struct dma_chan *chan) { struct rz_dmac_chan *channel =3D to_rz_dmac_chan(chan); - struct rz_dmac *dmac =3D to_rz_dmac(chan->device); - struct rz_dmac_desc *desc; unsigned long flags; =20 spin_lock_irqsave(&channel->vc.lock, flags); =20 - if (!list_empty(&channel->ld_queue)) { - desc =3D list_first_entry(&channel->ld_queue, - struct rz_dmac_desc, node); - channel->desc =3D desc; - if (vchan_issue_pending(&channel->vc)) { - if (rz_dmac_xfer_desc(channel) < 0) - dev_warn(dmac->dev, "ch: %d couldn't issue DMA xfer\n", - channel->index); - else - list_move_tail(channel->ld_queue.next, - &channel->ld_active); - } - } + /* + * Issue the descriptor. If another transfer is already in progress, the + * issued descriptor will be handled after the current transfer finishes. + */ + if (vchan_issue_pending(&channel->vc) && !channel->desc) + rz_dmac_xfer_desc(channel); =20 spin_unlock_irqrestore(&channel->vc.lock, flags); } @@ -676,13 +665,13 @@ static int rz_dmac_config(struct dma_chan *chan, =20 static void rz_dmac_virt_desc_free(struct virt_dma_desc *vd) { - /* - * Place holder - * Descriptor allocation is done during alloc_chan_resources and - * get freed during free_chan_resources. - * list is used to manage the descriptors and avoid any memory - * allocation/free during DMA read/write. - */ + struct rz_dmac_chan *channel =3D to_rz_dmac_chan(vd->tx.chan); + struct virt_dma_chan *vc =3D to_virt_chan(vd->tx.chan); + struct rz_dmac_desc *desc =3D to_rz_dmac_desc(vd); + + guard(spinlock_irqsave)(&vc->lock); + + list_add_tail(&desc->node, &channel->ld_free); } =20 static void rz_dmac_device_synchronize(struct dma_chan *chan) @@ -692,6 +681,8 @@ static void rz_dmac_device_synchronize(struct dma_chan = *chan) u32 chstat; int ret; =20 + vchan_synchronize(&channel->vc); + ret =3D read_poll_timeout(rz_dmac_ch_readl, chstat, !(chstat & CHSTAT_EN), 100, 100000, false, channel, CHSTAT, 1); if (ret < 0) @@ -739,58 +730,22 @@ static u32 rz_dmac_calculate_residue_bytes_in_vd(stru= ct rz_dmac_chan *channel, static u32 rz_dmac_chan_get_residue(struct rz_dmac_chan *channel, dma_cookie_t cookie) { - struct rz_dmac_desc *current_desc, *desc; - enum dma_status status; + struct rz_dmac_desc *desc =3D NULL; + struct virt_dma_desc *vd; u32 crla, crtb, i; =20 - /* Get current processing virtual descriptor */ - current_desc =3D list_first_entry_or_null(&channel->ld_active, - struct rz_dmac_desc, node); - if (!current_desc) - return 0; - - /* - * If the cookie corresponds to a descriptor that has been completed - * there is no residue. The same check has already been performed by the - * caller but without holding the channel lock, so the descriptor could - * now be complete. - */ - status =3D dma_cookie_status(&channel->vc.chan, cookie, NULL); - if (status =3D=3D DMA_COMPLETE) - return 0; - - /* - * If the cookie doesn't correspond to the currently processing virtual - * descriptor then the descriptor hasn't been processed yet, and the - * residue is equal to the full descriptor size. Also, a client driver - * is possible to call this function before rz_dmac_irq_handler_thread() - * runs. In this case, the running descriptor will be the next - * descriptor, and will appear in the done list. So, if the argument - * cookie matches the done list's cookie, we can assume the residue is - * zero. - */ - if (cookie !=3D current_desc->vd.tx.cookie) { - list_for_each_entry(desc, &channel->ld_free, node) { - if (cookie =3D=3D desc->vd.tx.cookie) - return 0; - } - - list_for_each_entry(desc, &channel->ld_queue, node) { - if (cookie =3D=3D desc->vd.tx.cookie) - return desc->len; - } - - list_for_each_entry(desc, &channel->ld_active, node) { - if (cookie =3D=3D desc->vd.tx.cookie) - return desc->len; - } + vd =3D vchan_find_desc(&channel->vc, cookie); + if (vd) { + /* Descriptor has been issued but not yet processed. */ + desc =3D to_rz_dmac_desc(vd); + return desc->len; + } else if (channel->desc && channel->desc->vd.tx.cookie =3D=3D cookie) { + /* Descriptor is currently processed. */ + desc =3D channel->desc; + } =20 - /* - * No descriptor found for the cookie, there's thus no residue. - * This shouldn't happen if the calling driver passes a correct - * cookie value. - */ - WARN(1, "No descriptor for cookie!"); + if (!desc) { + /* Descriptor was not found. May be already completed by now. */ return 0; } =20 @@ -813,7 +768,7 @@ static u32 rz_dmac_chan_get_residue(struct rz_dmac_chan= *channel, * Calculate number of bytes transferred in processing virtual descriptor. * One virtual descriptor can have many lmdesc. */ - return crtb + rz_dmac_calculate_residue_bytes_in_vd(channel, current_desc= , crla); + return crtb + rz_dmac_calculate_residue_bytes_in_vd(channel, desc, crla); } =20 static enum dma_status rz_dmac_tx_status(struct dma_chan *chan, @@ -824,21 +779,17 @@ static enum dma_status rz_dmac_tx_status(struct dma_c= han *chan, enum dma_status status; u32 residue; =20 - status =3D dma_cookie_status(chan, cookie, txstate); - if (status =3D=3D DMA_COMPLETE || !txstate) - return status; - scoped_guard(spinlock_irqsave, &channel->vc.lock) { + status =3D dma_cookie_status(chan, cookie, txstate); + if (status =3D=3D DMA_COMPLETE || !txstate) + return status; + residue =3D rz_dmac_chan_get_residue(channel, cookie); =20 - if (rz_dmac_chan_is_paused(channel)) + if (status =3D=3D DMA_IN_PROGRESS && rz_dmac_chan_is_paused(channel)) status =3D DMA_PAUSED; } =20 - /* if there's no residue and no paused, the cookie is complete */ - if (!residue && status !=3D DMA_PAUSED) - return DMA_COMPLETE; - dma_set_residue(txstate, residue); =20 return status; @@ -918,28 +869,18 @@ static irqreturn_t rz_dmac_irq_handler(int irq, void = *dev_id) static irqreturn_t rz_dmac_irq_handler_thread(int irq, void *dev_id) { struct rz_dmac_chan *channel =3D dev_id; - struct rz_dmac_desc *desc =3D NULL; - unsigned long flags; + struct rz_dmac_desc *desc; =20 - spin_lock_irqsave(&channel->vc.lock, flags); + guard(spinlock_irqsave)(&channel->vc.lock); =20 - if (list_empty(&channel->ld_active)) { - /* Someone might have called terminate all */ - goto out; - } + desc =3D channel->desc; + if (!desc) + return IRQ_HANDLED; =20 - desc =3D list_first_entry(&channel->ld_active, struct rz_dmac_desc, node); vchan_cookie_complete(&desc->vd); - list_move_tail(channel->ld_active.next, &channel->ld_free); - if (!list_empty(&channel->ld_queue)) { - desc =3D list_first_entry(&channel->ld_queue, struct rz_dmac_desc, - node); - channel->desc =3D desc; - if (rz_dmac_xfer_desc(channel) =3D=3D 0) - list_move_tail(channel->ld_queue.next, &channel->ld_active); - } -out: - spin_unlock_irqrestore(&channel->vc.lock, flags); + channel->desc =3D NULL; + + rz_dmac_xfer_desc(channel); =20 return IRQ_HANDLED; } @@ -1021,9 +962,7 @@ static int rz_dmac_chan_probe(struct rz_dmac *dmac, =20 channel->vc.desc_free =3D rz_dmac_virt_desc_free; vchan_init(&channel->vc, &dmac->engine); - INIT_LIST_HEAD(&channel->ld_queue); INIT_LIST_HEAD(&channel->ld_free); - INIT_LIST_HEAD(&channel->ld_active); =20 /* Initialize register for each channel */ rz_dmac_disable_hw(channel); --=20 2.43.0 From nobody Mon Jun 8 21:46:47 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 160653CEBB7; Tue, 26 May 2026 08:48:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779785293; cv=none; b=fyoOkeWds3ye3hi1sKliimBoosnu6nVqWiXnBcZ+hFuFfJ2NXiVT5Wq/DEemQmaEVIjIf60k7bjBXDorir0tXTghUHagBulfBSkrZ3946FLUMYGsiiuKzfbEeLnRgKowt6+afV/C27/DeXZ0tItglLhKcemqsiJJXT86rihQ22A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779785293; c=relaxed/simple; bh=I3V+MZJeUrJmTY5EM3NLNs+vytZspxCjwYRZrhyWHms=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=krG/b5w6KChv7VS414MSHPgmBkS9EuWWf5OKkagBSLlzsA0o7HLOotBPlHXU3LkWd4R2L86W7OM5ZGlbj60ie3UWlaXuCeBFJLS7FsIG7JPzDyv6z5GvRk8plgpdOm4Bvz6JAT2q/djtjeFLTUQiB2tU2WnfnJTMJq7K9ls6lqs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=bHeL4qS8; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="bHeL4qS8" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6AAC31F00A3A; Tue, 26 May 2026 08:48:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1779785291; bh=s+5oQkS0ctJPorySv0Wf7N8noj5KZXuB7v8SJnjyOEk=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=bHeL4qS82QMMz3zB1U/sOaz8kbF/cW28g0P3xn3GNoTAKRguM3IagP1LUs9X3ESfO Nfg3kRAb5T8gzg+2sC/HEG53E7sAL6nML1tQy0pXcQIV87aIr4s99sV4GcaCjWAuoF /JFKdlIsVfetq+CnFLcuAU8I58dpV63PRLEQ3sgZuL2AaTIi9vwZFL0LP7iU5BGp3H rycleLPlQkhmMZUWvi7hWFdM224HA7SGSWZGtj2mpL2ot0yH2JKWSQaA675CEuRz5L JrR4YyVBiYDryhqwmqXn+hKBUKI7ZyZRD2cU9sqV+Md5OQUK5gN6gR2XJe9PqXiPAZ BiFsB9tBnR7Jw== From: Claudiu Beznea To: vkoul@kernel.org, Frank.Li@kernel.org, lgirdwood@gmail.com, broonie@kernel.org, perex@perex.cz, tiwai@suse.com, biju.das.jz@bp.renesas.com, prabhakar.mahadev-lad.rj@bp.renesas.com, p.zabel@pengutronix.de, geert+renesas@glider.be, kuninori.morimoto.gx@renesas.com, long.luu.ur@renesas.com Cc: claudiu.beznea@kernel.org, claudiu.beznea@tuxon.dev, dmaengine@vger.kernel.org, linux-kernel@vger.kernel.org, linux-sound@vger.kernel.org, linux-renesas-soc@vger.kernel.org, Claudiu Beznea , John Madieu Subject: [PATCH v6 10/18] dmaengine: sh: rz-dmac: Refactor pause/resume code Date: Tue, 26 May 2026 11:47:02 +0300 Message-ID: <20260526084710.3491480-11-claudiu.beznea@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260526084710.3491480-1-claudiu.beznea@kernel.org> References: <20260526084710.3491480-1-claudiu.beznea@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Claudiu Beznea Subsequent patches will add suspend/resume and cyclic DMA support to the rz-dmac driver. This support needs to work on SoCs where power to most components (including DMA) is turned off during system suspend. For this, some channels (for example cyclic ones) may need to be paused and resumed manually by the DMA driver during system suspend/resume. Refactor the pause/resume support so the same code can be reused in the system suspend/resume path. Tested-by: John Madieu Signed-off-by: Claudiu Beznea Tested-by: Tommaso Merciai --- Changes in v6: - collected tags Changes in v5: - none Changes in v4: - reset channel->status in rz_dmac_free_chan_resources() and rz_dmac_terminate_all() Changes in v3: - none, this patch new new drivers/dma/sh/rz-dmac.c | 73 ++++++++++++++++++++++++++++++++++------ 1 file changed, 62 insertions(+), 11 deletions(-) diff --git a/drivers/dma/sh/rz-dmac.c b/drivers/dma/sh/rz-dmac.c index 1f884ec101f8..557364443a5f 100644 --- a/drivers/dma/sh/rz-dmac.c +++ b/drivers/dma/sh/rz-dmac.c @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -63,6 +64,14 @@ struct rz_dmac_desc { =20 #define to_rz_dmac_desc(d) container_of(d, struct rz_dmac_desc, vd) =20 +/** + * enum rz_dmac_chan_status: RZ DMAC channel status + * @RZ_DMAC_CHAN_STATUS_PAUSED: Channel is paused though DMA engine callba= cks + */ +enum rz_dmac_chan_status { + RZ_DMAC_CHAN_STATUS_PAUSED, +}; + struct rz_dmac_chan { struct virt_dma_chan vc; void __iomem *ch_base; @@ -74,6 +83,8 @@ struct rz_dmac_chan { dma_addr_t src_per_address; dma_addr_t dst_per_address; =20 + unsigned long status; + u32 chcfg; u32 chctrl; int mid_rid; @@ -491,6 +502,8 @@ static void rz_dmac_free_chan_resources(struct dma_chan= *chan) channel->mid_rid =3D -EINVAL; } =20 + channel->status =3D 0; + spin_unlock_irqrestore(&channel->vc.lock, flags); =20 vchan_free_chan_resources(&channel->vc); @@ -589,6 +602,9 @@ static int rz_dmac_terminate_all(struct dma_chan *chan) } =20 vchan_get_all_descriptors(&channel->vc, &head); + + channel->status =3D 0; + spin_unlock_irqrestore(&channel->vc.lock, flags); vchan_dma_desc_free_list(&channel->vc, &head); =20 @@ -795,35 +811,70 @@ static enum dma_status rz_dmac_tx_status(struct dma_c= han *chan, return status; } =20 -static int rz_dmac_device_pause(struct dma_chan *chan) +static int rz_dmac_device_pause_set(struct rz_dmac_chan *channel, + unsigned long set_bitmask) { - struct rz_dmac_chan *channel =3D to_rz_dmac_chan(chan); + int ret =3D 0; u32 val; =20 - guard(spinlock_irqsave)(&channel->vc.lock); + lockdep_assert_held(&channel->vc.lock); =20 if (!rz_dmac_chan_is_enabled(channel)) return 0; =20 + if (rz_dmac_chan_is_paused(channel)) + goto set_bit; + rz_dmac_ch_writel(channel, CHCTRL_SETSUS, CHCTRL, 1); - return read_poll_timeout_atomic(rz_dmac_ch_readl, val, - (val & CHSTAT_SUS), 1, 1024, - false, channel, CHSTAT, 1); + ret =3D read_poll_timeout_atomic(rz_dmac_ch_readl, val, + (val & CHSTAT_SUS), 1, 1024, false, + channel, CHSTAT, 1); + +set_bit: + channel->status |=3D set_bitmask; + + return ret; } =20 -static int rz_dmac_device_resume(struct dma_chan *chan) +static int rz_dmac_device_pause(struct dma_chan *chan) { struct rz_dmac_chan *channel =3D to_rz_dmac_chan(chan); - u32 val; =20 guard(spinlock_irqsave)(&channel->vc.lock); =20 + return rz_dmac_device_pause_set(channel, BIT(RZ_DMAC_CHAN_STATUS_PAUSED)); +} + +static int rz_dmac_device_resume_set(struct rz_dmac_chan *channel, + unsigned long clear_bitmask) +{ + int ret =3D 0; + u32 val; + + lockdep_assert_held(&channel->vc.lock); + /* Do not check CHSTAT_SUS but rely on HW capabilities. */ =20 rz_dmac_ch_writel(channel, CHCTRL_CLRSUS, CHCTRL, 1); - return read_poll_timeout_atomic(rz_dmac_ch_readl, val, - !(val & CHSTAT_SUS), 1, 1024, - false, channel, CHSTAT, 1); + ret =3D read_poll_timeout_atomic(rz_dmac_ch_readl, val, + !(val & CHSTAT_SUS), 1, 1024, false, + channel, CHSTAT, 1); + + channel->status &=3D ~clear_bitmask; + + return ret; +} + +static int rz_dmac_device_resume(struct dma_chan *chan) +{ + struct rz_dmac_chan *channel =3D to_rz_dmac_chan(chan); + + guard(spinlock_irqsave)(&channel->vc.lock); + + if (!(channel->status & BIT(RZ_DMAC_CHAN_STATUS_PAUSED))) + return 0; + + return rz_dmac_device_resume_set(channel, BIT(RZ_DMAC_CHAN_STATUS_PAUSED)= ); } =20 /* --=20 2.43.0 From nobody Mon Jun 8 21:46:47 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 37E283CEB8E; Tue, 26 May 2026 08:48:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779785298; cv=none; b=dMSKN7SfF50h+3o/XcrwE1TyFqfQCxVulqXSQR9JnzdzfTST2q+06g+vaTC+92rVl02G7i8yVXZs0gO8tEg7EkyOPMjtxQSHt02h0LxlElvDRFY0bk4YRxzN5Hipac8WDUmbfPnOLLBG2qkZZWpDzIEIlIpM57qEHDQ7g6VWBUI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779785298; c=relaxed/simple; bh=iMvwQ/BKtWP57urrh8T+L5p5HB3eyMvJMt5pylBUT4o=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hRZK3l556jn9LS6g/oRoznjCNHVcOWl4rwuSbv3VOd+UhCeNjwM2+nFMjy/PjgmgpiJsDHc0rUduUqUOkixBMVFZvVoYE9f61z9e54SEfnEgvSAhEfP4tQ9R7mA3UiZ/cwpXtXwEEaEHnfauzy9ElXDq3FlEjV0vt1/qZ63xatM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=au8YZC0s; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="au8YZC0s" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2CDCE1F000E9; Tue, 26 May 2026 08:48:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1779785296; bh=EhJnlm7aIME3IueJM+kqi3yB/0TLHFEMSHwT+k+SpW4=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=au8YZC0slTD1baJkep3zFR1mDr3gC6Jtkua693GksXrmsDATeaCq0zUJ7NU+SdX6o bAAb34agqhoFuln0Oq+mbbEzGu5tCgjPzVc3O4LAydNLSS5SG3++TUgvbUfR4892Fn AHrEs875lk+0Q3fc9M/5AiDvkolhq56PYBOoE9ZvMUj4u9+0AUst6bnlZ4hMao+jaQ ftrSeF/EduJeSLZReYa79eQVGy3721oGGAQoaVmkWDotXRKLzHm4CpcyRnagwHKA6N zqnynefmnWrZxOCyWLvb8Q/ZJbhaJsBol40rXLYgU+CdG+HFEoGRFAlsXPTVUy7zJB yms3moFO0uZeg== From: Claudiu Beznea To: vkoul@kernel.org, Frank.Li@kernel.org, lgirdwood@gmail.com, broonie@kernel.org, perex@perex.cz, tiwai@suse.com, biju.das.jz@bp.renesas.com, prabhakar.mahadev-lad.rj@bp.renesas.com, p.zabel@pengutronix.de, geert+renesas@glider.be, kuninori.morimoto.gx@renesas.com, long.luu.ur@renesas.com Cc: claudiu.beznea@kernel.org, claudiu.beznea@tuxon.dev, dmaengine@vger.kernel.org, linux-kernel@vger.kernel.org, linux-sound@vger.kernel.org, linux-renesas-soc@vger.kernel.org, Claudiu Beznea , Frank Li , John Madieu Subject: [PATCH v6 11/18] dmaengine: sh: rz-dmac: Drop the update of channel->chctrl with CHCTRL_SETEN Date: Tue, 26 May 2026 11:47:03 +0300 Message-ID: <20260526084710.3491480-12-claudiu.beznea@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260526084710.3491480-1-claudiu.beznea@kernel.org> References: <20260526084710.3491480-1-claudiu.beznea@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Claudiu Beznea The CHCTRL_SETEN bit is explicitly set in rz_dmac_enable_hw(). Updating struct rz_dmac_chan::chctrl with this bit in rz_dmac_prepare_desc_for_memcpy() and rz_dmac_prepare_descs_for_slave_sg() is unnecessary in the current code base. Moreover, it conflicts with the configuration sequence that will be used for cyclic DMA channels during suspend to RAM. Cyclic DMA support will be introduced in subsequent commits. This is a preparatory commit for cyclic DMA suspend to RAM support. Reviewed-by: Frank Li Tested-by: John Madieu Signed-off-by: Claudiu Beznea Tested-by: Tommaso Merciai --- Changes in v6: - collected tags Changes in v5: - none Changes in v4: - set channel->chctrl =3D 0 in rz_dmac_prepare_descs_for_slave_sg() Changes in v3: - none Changes in v2: - fixed typos in patch title and patch description drivers/dma/sh/rz-dmac.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/dma/sh/rz-dmac.c b/drivers/dma/sh/rz-dmac.c index 557364443a5f..c9c00650ddd5 100644 --- a/drivers/dma/sh/rz-dmac.c +++ b/drivers/dma/sh/rz-dmac.c @@ -377,7 +377,7 @@ static void rz_dmac_prepare_desc_for_memcpy(struct rz_d= mac_chan *channel) rz_dmac_set_dma_req_no(dmac, channel->index, dmac->info->default_dma_req_= no); =20 channel->chcfg =3D chcfg; - channel->chctrl =3D CHCTRL_STG | CHCTRL_SETEN; + channel->chctrl =3D CHCTRL_STG; } =20 static void rz_dmac_prepare_descs_for_slave_sg(struct rz_dmac_chan *channe= l) @@ -428,7 +428,7 @@ static void rz_dmac_prepare_descs_for_slave_sg(struct r= z_dmac_chan *channel) =20 rz_dmac_set_dma_req_no(dmac, channel->index, channel->mid_rid); =20 - channel->chctrl =3D CHCTRL_SETEN; + channel->chctrl =3D 0; } =20 static void rz_dmac_xfer_desc(struct rz_dmac_chan *chan) --=20 2.43.0 From nobody Mon Jun 8 21:46:47 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F1D3E3CEBA6; Tue, 26 May 2026 08:48:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779785303; cv=none; b=eJTIxnTdDK5XCqYZe5o0ZmkYG/Cns9gW0jkZUuYD2tXUFXl/NizVz/geyZJQxxFXMUdpziJfKGdv5WzcjJQsHbcTUuAw93SStcCaYIvH5KkyNtfuXN2p66nv+/dYeBuI747twHHe9J+ev+eFO+fdhAIg0OgouAYHEmVQK3dQ/Dw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779785303; c=relaxed/simple; bh=BAh79Zx9Pq4A2NQ1OT4BXJQVmEv+rOv76cr8T6eeDo0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=EwZJvT9W6c7U3ZR19oCNMdYMQes/GgqIMiOUs2yt0Xk+mIKTep568EDi96sLUs4mVJ3VuOr0xqHFZW1FEcsEctWwlcLCY7P9OBSePF6cL5H4dyjUOpXzuhk9gwNEkE6FYNOypl2ooMaHkd3QP5DPCrq/C/zhO1YEzorhS+vBJEo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=amX/NiJn; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="amX/NiJn" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4D82E1F00A3A; Tue, 26 May 2026 08:48:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1779785301; bh=lzHqMZktDs87AOFrn/5S21ZY/oV/x9CjWC/cBwDYMSY=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=amX/NiJn/+4pp2GeGjAGTCL5xLNa895RzbIawfuOiqZ2WfIP2rx3R/ETrM4Q8xTD4 Cyi/ArKmBU/i6QcONKAnIfGdJ2awRmTtyfduTVklvAHaU+8IEVXotlH5MftJfrrd9L Tha6qWI2fx7oWhYJ6wJnTbrkfTkWc/LgsV0k9ZgkXq08Tn1W6Xya1zzT2oTrNy9B8u /X7xy71vecStHlWo0IwRz6znnIedO8SixwGdbqL3M5mfB9ejOH3uPZDtXCTRHr8dLS qRg/rRbBGPJIiFNd/p4n+swR7oQgzVmZCzOzpRDFYFMrl4dByw03mQTZrfxK79YwZ/ BOYXt5SowhqiA== From: Claudiu Beznea To: vkoul@kernel.org, Frank.Li@kernel.org, lgirdwood@gmail.com, broonie@kernel.org, perex@perex.cz, tiwai@suse.com, biju.das.jz@bp.renesas.com, prabhakar.mahadev-lad.rj@bp.renesas.com, p.zabel@pengutronix.de, geert+renesas@glider.be, kuninori.morimoto.gx@renesas.com, long.luu.ur@renesas.com Cc: claudiu.beznea@kernel.org, claudiu.beznea@tuxon.dev, dmaengine@vger.kernel.org, linux-kernel@vger.kernel.org, linux-sound@vger.kernel.org, linux-renesas-soc@vger.kernel.org, Claudiu Beznea , John Madieu Subject: [PATCH v6 12/18] dmaengine: sh: rz-dmac: Add cyclic DMA support Date: Tue, 26 May 2026 11:47:04 +0300 Message-ID: <20260526084710.3491480-13-claudiu.beznea@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260526084710.3491480-1-claudiu.beznea@kernel.org> References: <20260526084710.3491480-1-claudiu.beznea@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Claudiu Beznea Add cyclic DMA support to the RZ DMAC driver. A per-channel status bit is introduced to mark cyclic channels and is set during the DMA prepare callback. The IRQ handler checks this status bit and calls vchan_cyclic_callback() accordingly. Tested-by: John Madieu Signed-off-by: Claudiu Beznea Tested-by: Tommaso Merciai --- Changes in v6: - collected tags Changes in v5: - none Changes in v4: - drop the nxla update logic in rz_dmac_lmdesc_recycle() as this is not needed for any kind of transfers - drop the update of channel->status =3D 0 from rz_dmac_free_chan_resources= () and rz_dmac_terminate_all() as this was moved in patch 09/17 Changes in v3: - updated rz_dmac_lmdesc_recycle() to restore the lmdesc->nxla - in rz_dmac_prepare_descs_for_cyclic() update directly the desc->start_lmdesc with the descriptor pointer insted of the descriptor address - used rz_dmac_lmdesc_addr() to compute the descritor address - set channel->status =3D 0 in rz_dmac_free_chan_resources() - in rz_dmac_prep_dma_cyclic() check for invalid periods or buffer len and limit the critical area protected by spinlock - set channel->status =3D 0 in rz_dmac_terminate_all() - updated rz_dmac_calculate_residue_bytes_in_vd() to use=20 rz_dmac_lmdesc_addr() - dropped goto in rz_dmac_irq_handler_thread() as it is not needed anymore; dropped also the local variable desc Changes in v2: - none drivers/dma/sh/rz-dmac.c | 136 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 130 insertions(+), 6 deletions(-) diff --git a/drivers/dma/sh/rz-dmac.c b/drivers/dma/sh/rz-dmac.c index c9c00650ddd5..8fd8a4bd9cc9 100644 --- a/drivers/dma/sh/rz-dmac.c +++ b/drivers/dma/sh/rz-dmac.c @@ -35,6 +35,7 @@ enum rz_dmac_prep_type { RZ_DMAC_DESC_MEMCPY, RZ_DMAC_DESC_SLAVE_SG, + RZ_DMAC_DESC_CYCLIC, }; =20 struct rz_lmdesc { @@ -67,9 +68,11 @@ struct rz_dmac_desc { /** * enum rz_dmac_chan_status: RZ DMAC channel status * @RZ_DMAC_CHAN_STATUS_PAUSED: Channel is paused though DMA engine callba= cks + * @RZ_DMAC_CHAN_STATUS_CYCLIC: Channel is cyclic */ enum rz_dmac_chan_status { RZ_DMAC_CHAN_STATUS_PAUSED, + RZ_DMAC_CHAN_STATUS_CYCLIC, }; =20 struct rz_dmac_chan { @@ -191,6 +194,7 @@ struct rz_dmac { =20 /* LINK MODE DESCRIPTOR */ #define HEADER_LV BIT(0) +#define HEADER_WBD BIT(2) =20 #define RZ_DMAC_MAX_CHAN_DESCRIPTORS 16 #define RZ_DMAC_MAX_CHANNELS 16 @@ -431,6 +435,57 @@ static void rz_dmac_prepare_descs_for_slave_sg(struct = rz_dmac_chan *channel) channel->chctrl =3D 0; } =20 +static void rz_dmac_prepare_descs_for_cyclic(struct rz_dmac_chan *channel) +{ + struct dma_chan *chan =3D &channel->vc.chan; + struct rz_dmac *dmac =3D to_rz_dmac(chan->device); + struct rz_dmac_desc *d =3D channel->desc; + size_t period_len =3D d->sgcount; + struct rz_lmdesc *lmdesc; + size_t buf_len =3D d->len; + size_t periods =3D buf_len / period_len; + + lockdep_assert_held(&channel->vc.lock); + + channel->chcfg |=3D CHCFG_SEL(channel->index) | CHCFG_DMS; + + if (d->direction =3D=3D DMA_DEV_TO_MEM) { + channel->chcfg |=3D CHCFG_SAD; + channel->chcfg &=3D ~CHCFG_REQD; + } else { + channel->chcfg |=3D CHCFG_DAD | CHCFG_REQD; + } + + lmdesc =3D channel->lmdesc.tail; + d->start_lmdesc =3D lmdesc; + + for (size_t i =3D 0; i < periods; i++) { + if (d->direction =3D=3D DMA_DEV_TO_MEM) { + lmdesc->sa =3D d->src; + lmdesc->da =3D d->dest + (i * period_len); + } else { + lmdesc->sa =3D d->src + (i * period_len); + lmdesc->da =3D d->dest; + } + + lmdesc->tb =3D period_len; + lmdesc->chitvl =3D 0; + lmdesc->chext =3D 0; + lmdesc->chcfg =3D channel->chcfg; + lmdesc->header =3D HEADER_LV | HEADER_WBD; + + if (i =3D=3D periods - 1) + lmdesc->nxla =3D rz_dmac_lmdesc_addr(channel, d->start_lmdesc); + + if (++lmdesc >=3D (channel->lmdesc.base + DMAC_NR_LMDESC)) + lmdesc =3D channel->lmdesc.base; + } + + channel->lmdesc.tail =3D lmdesc; + + rz_dmac_set_dma_req_no(dmac, channel->index, channel->mid_rid); +} + static void rz_dmac_xfer_desc(struct rz_dmac_chan *chan) { struct virt_dma_desc *vd; @@ -452,6 +507,10 @@ static void rz_dmac_xfer_desc(struct rz_dmac_chan *cha= n) case RZ_DMAC_DESC_SLAVE_SG: rz_dmac_prepare_descs_for_slave_sg(chan); break; + + case RZ_DMAC_DESC_CYCLIC: + rz_dmac_prepare_descs_for_cyclic(chan); + break; } =20 rz_dmac_enable_hw(chan); @@ -586,6 +645,55 @@ rz_dmac_prep_slave_sg(struct dma_chan *chan, struct sc= atterlist *sgl, return vchan_tx_prep(&channel->vc, &desc->vd, flags); } =20 +static struct dma_async_tx_descriptor * +rz_dmac_prep_dma_cyclic(struct dma_chan *chan, dma_addr_t buf_addr, + size_t buf_len, size_t period_len, + enum dma_transfer_direction direction, + unsigned long flags) +{ + struct rz_dmac_chan *channel =3D to_rz_dmac_chan(chan); + struct rz_dmac_desc *desc; + size_t periods; + + if (!is_slave_direction(direction)) + return NULL; + + if (!period_len || !buf_len) + return NULL; + + periods =3D buf_len / period_len; + if (!periods || periods > DMAC_NR_LMDESC) + return NULL; + + scoped_guard(spinlock_irqsave, &channel->vc.lock) { + if (channel->status & BIT(RZ_DMAC_CHAN_STATUS_CYCLIC)) + return NULL; + + desc =3D list_first_entry_or_null(&channel->ld_free, struct rz_dmac_desc= , node); + if (!desc) + return NULL; + + list_del(&desc->node); + + channel->status |=3D BIT(RZ_DMAC_CHAN_STATUS_CYCLIC); + } + + desc->type =3D RZ_DMAC_DESC_CYCLIC; + desc->sgcount =3D period_len; + desc->len =3D buf_len; + desc->direction =3D direction; + + if (direction =3D=3D DMA_DEV_TO_MEM) { + desc->src =3D channel->src_per_address; + desc->dest =3D buf_addr; + } else { + desc->src =3D buf_addr; + desc->dest =3D channel->dst_per_address; + } + + return vchan_tx_prep(&channel->vc, &desc->vd, flags); +} + static int rz_dmac_terminate_all(struct dma_chan *chan) { struct rz_dmac_chan *channel =3D to_rz_dmac_chan(chan); @@ -733,9 +841,18 @@ static u32 rz_dmac_calculate_residue_bytes_in_vd(struc= t rz_dmac_chan *channel, } =20 /* Calculate residue from next lmdesc to end of virtual desc */ - while (lmdesc->chcfg & CHCFG_DEM) { - residue +=3D lmdesc->tb; - lmdesc =3D rz_dmac_get_next_lmdesc(channel->lmdesc.base, lmdesc); + if (channel->status & BIT(RZ_DMAC_CHAN_STATUS_CYCLIC)) { + u32 start_lmdesc_addr =3D rz_dmac_lmdesc_addr(channel, desc->start_lmdes= c); + + while (lmdesc->nxla !=3D start_lmdesc_addr) { + residue +=3D lmdesc->tb; + lmdesc =3D rz_dmac_get_next_lmdesc(channel->lmdesc.base, lmdesc); + } + } else { + while (lmdesc->chcfg & CHCFG_DEM) { + residue +=3D lmdesc->tb; + lmdesc =3D rz_dmac_get_next_lmdesc(channel->lmdesc.base, lmdesc); + } } =20 dev_dbg(dmac->dev, "%s: VD residue is %u\n", __func__, residue); @@ -928,10 +1045,14 @@ static irqreturn_t rz_dmac_irq_handler_thread(int ir= q, void *dev_id) if (!desc) return IRQ_HANDLED; =20 - vchan_cookie_complete(&desc->vd); - channel->desc =3D NULL; + if (channel->status & BIT(RZ_DMAC_CHAN_STATUS_CYCLIC)) { + vchan_cyclic_callback(&desc->vd); + } else { + vchan_cookie_complete(&desc->vd); + channel->desc =3D NULL; =20 - rz_dmac_xfer_desc(channel); + rz_dmac_xfer_desc(channel); + } =20 return IRQ_HANDLED; } @@ -1183,6 +1304,8 @@ static int rz_dmac_probe(struct platform_device *pdev) engine =3D &dmac->engine; dma_cap_set(DMA_SLAVE, engine->cap_mask); dma_cap_set(DMA_MEMCPY, engine->cap_mask); + dma_cap_set(DMA_CYCLIC, engine->cap_mask); + engine->directions =3D BIT(DMA_DEV_TO_MEM) | BIT(DMA_MEM_TO_DEV); engine->residue_granularity =3D DMA_RESIDUE_GRANULARITY_BURST; rz_dmac_writel(dmac, DCTRL_DEFAULT, CHANNEL_0_7_COMMON_BASE + DCTRL); rz_dmac_writel(dmac, DCTRL_DEFAULT, CHANNEL_8_15_COMMON_BASE + DCTRL); @@ -1194,6 +1317,7 @@ static int rz_dmac_probe(struct platform_device *pdev) engine->device_tx_status =3D rz_dmac_tx_status; engine->device_prep_slave_sg =3D rz_dmac_prep_slave_sg; engine->device_prep_dma_memcpy =3D rz_dmac_prep_dma_memcpy; + engine->device_prep_dma_cyclic =3D rz_dmac_prep_dma_cyclic; engine->device_config =3D rz_dmac_config; engine->device_terminate_all =3D rz_dmac_terminate_all; engine->device_issue_pending =3D rz_dmac_issue_pending; --=20 2.43.0 From nobody Mon Jun 8 21:46:47 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CA3AD3CEBB6; Tue, 26 May 2026 08:48:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779785307; cv=none; b=qn//ltF1jsPAYaUbNwEm5/F7FTy7xjMSae3uSkZ6Ylr9j1GzDpsOHWnME55ecpk8WDtFTnbpqAw+hfqcghGnisvrGhNstkSJtwwWCYS+mA2sB/o5ipsVw6CX8IOZiXgV8Uiwr0Q5tjeGWeK06CjGUJJvdvAffogW6UQzFpQptoY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779785307; c=relaxed/simple; bh=RGJ2GhZieeHp2+dVykslQCZ+byUuf4/vU3zgWYqSOgA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=FPStrA0HpAODJyxSKu53hDWedttB/vmKsuJimOmQK/54bnpNxVlIuupG1rEjZzRIeZrgzhWsRHWj6yLP8mQNSdy/4UEtKmZP0e2xIilJlUfzcJCGmHxdqihEYldIMN/SGMMOl7d8LDQM1O1aralmmuyqOQ7AYMCaCgubWYmkYAo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Ko/XsXhq; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Ko/XsXhq" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2385F1F000E9; Tue, 26 May 2026 08:48:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1779785306; bh=t2Z7RErh2Nd3ARXirxEzn17ObeWEMX6ORjGzypm37vU=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=Ko/XsXhqGYte9fwoUVkYHKJ8D/14gJ+2tusWsiL2D3sNgi0C0ttDakslgTGdmky6q WJJPXNfkqt7RIXEmcBHBZmLbjnpZeUK341vFBDFRKmWIVAAqUl1u2/QA/7Vpk/0t07 1DnDCbaEbu4CgcI0KCwoUI97pCZ8TOMNQK36mln9aiKDMxEMcEl0CjejJ+RjM+orP1 WxzeCLqpeQw0+xM2WwK42Cu5rEGP0U72tI2yKDbmOnIPwkst7GSIGxyTZhb/yJbinw 5gqo46kA14cmiAWPLSilCgBlcGA1Gtb4VecKeusjqD7MxC5tqTVEmTRGMsGH6tr1lg Gi/e6vpcTCxSw== From: Claudiu Beznea To: vkoul@kernel.org, Frank.Li@kernel.org, lgirdwood@gmail.com, broonie@kernel.org, perex@perex.cz, tiwai@suse.com, biju.das.jz@bp.renesas.com, prabhakar.mahadev-lad.rj@bp.renesas.com, p.zabel@pengutronix.de, geert+renesas@glider.be, kuninori.morimoto.gx@renesas.com, long.luu.ur@renesas.com Cc: claudiu.beznea@kernel.org, claudiu.beznea@tuxon.dev, dmaengine@vger.kernel.org, linux-kernel@vger.kernel.org, linux-sound@vger.kernel.org, linux-renesas-soc@vger.kernel.org, Claudiu Beznea Subject: [PATCH v6 13/18] dmaengine: sh: rz-dmac: Adjust rz_dmac_chan_get_residue() to return error codes Date: Tue, 26 May 2026 11:47:05 +0300 Message-ID: <20260526084710.3491480-14-claudiu.beznea@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260526084710.3491480-1-claudiu.beznea@kernel.org> References: <20260526084710.3491480-1-claudiu.beznea@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Claudiu Beznea Adjust rz_dmac_chan_get_residue() to return error codes on failure and provide the residue to callers through the residue parameter. This prepares the code for the addition of runtime PM support. Signed-off-by: Claudiu Beznea Tested-by: Tommaso Merciai --- Changes in v6: - none, this patch is new drivers/dma/sh/rz-dmac.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/drivers/dma/sh/rz-dmac.c b/drivers/dma/sh/rz-dmac.c index 8fd8a4bd9cc9..93394b9934c8 100644 --- a/drivers/dma/sh/rz-dmac.c +++ b/drivers/dma/sh/rz-dmac.c @@ -860,8 +860,8 @@ static u32 rz_dmac_calculate_residue_bytes_in_vd(struct= rz_dmac_chan *channel, return residue; } =20 -static u32 rz_dmac_chan_get_residue(struct rz_dmac_chan *channel, - dma_cookie_t cookie) +static int rz_dmac_chan_get_residue(struct device *dev, struct rz_dmac_cha= n *channel, + dma_cookie_t cookie, u32 *residue) { struct rz_dmac_desc *desc =3D NULL; struct virt_dma_desc *vd; @@ -871,7 +871,8 @@ static u32 rz_dmac_chan_get_residue(struct rz_dmac_chan= *channel, if (vd) { /* Descriptor has been issued but not yet processed. */ desc =3D to_rz_dmac_desc(vd); - return desc->len; + *residue =3D desc->len; + return 0; } else if (channel->desc && channel->desc->vd.tx.cookie =3D=3D cookie) { /* Descriptor is currently processed. */ desc =3D channel->desc; @@ -879,6 +880,7 @@ static u32 rz_dmac_chan_get_residue(struct rz_dmac_chan= *channel, =20 if (!desc) { /* Descriptor was not found. May be already completed by now. */ + *residue =3D 0; return 0; } =20 @@ -901,7 +903,9 @@ static u32 rz_dmac_chan_get_residue(struct rz_dmac_chan= *channel, * Calculate number of bytes transferred in processing virtual descriptor. * One virtual descriptor can have many lmdesc. */ - return crtb + rz_dmac_calculate_residue_bytes_in_vd(channel, desc, crla); + *residue =3D crtb + rz_dmac_calculate_residue_bytes_in_vd(channel, desc, = crla); + + return 0; } =20 static enum dma_status rz_dmac_tx_status(struct dma_chan *chan, @@ -909,15 +913,20 @@ static enum dma_status rz_dmac_tx_status(struct dma_c= han *chan, struct dma_tx_state *txstate) { struct rz_dmac_chan *channel =3D to_rz_dmac_chan(chan); + struct rz_dmac *dmac =3D to_rz_dmac(chan->device); enum dma_status status; u32 residue; =20 scoped_guard(spinlock_irqsave, &channel->vc.lock) { + int ret; + status =3D dma_cookie_status(chan, cookie, txstate); if (status =3D=3D DMA_COMPLETE || !txstate) return status; =20 - residue =3D rz_dmac_chan_get_residue(channel, cookie); + ret =3D rz_dmac_chan_get_residue(dmac->dev, channel, cookie, &residue); + if (ret) + return DMA_ERROR; =20 if (status =3D=3D DMA_IN_PROGRESS && rz_dmac_chan_is_paused(channel)) status =3D DMA_PAUSED; --=20 2.43.0 From nobody Mon Jun 8 21:46:47 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 843E03CF024; Tue, 26 May 2026 08:48:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779785312; cv=none; b=Omj86nKzKWpteDvJauepAOS1Yc4Kb6u0BtVp7BFB1obe2/vv1wFuZj1YKKydKcU2pJalrsKqfqHjoyKkaslmTrDodcuJ636mx6IOdLB7PTW8RTsrtsOcdz62srTChQ9Hs+l1UMtivJSaXIgfZiJDf8Kphk2v2ICsbH3BRtAvarw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779785312; c=relaxed/simple; bh=m1KlBWocMTaKeL2I7DjJjPCsBJsX0O/2ZVJ/+9qVpDU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Hkud3OFGsN5IKBhoDf4Qin/Y0OmIP+wDVbeJ63ybJS5r2XN6SMM98VpyHjL3UzKxp5YAx+Z9dP+W++Wn9f9U4nK598EWE9a4WMNz//YORHQX6fDKnejffGX3pCTwAavhW9ed+INdIXkMf0beAE3ELA++HftB9N5VJxIxtTzJhfQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=GIEoEaYN; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="GIEoEaYN" Received: by smtp.kernel.org (Postfix) with ESMTPSA id F15EE1F00A3A; Tue, 26 May 2026 08:48:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1779785311; bh=/mw3tHwxqJxGzAwNQxvMiWiETvEIWUbWQPBUbh+bwdI=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=GIEoEaYNcAVYoU8IEHiAqSSmH6ZksKVh/VfQPRQ/biBK9Hea5ddaCZM42QoIFULTC HFUFsCGBPXxmX8BFfWDepxIj7r7FVHyRpkxjZCQNDQB/QDcCmzheTpv10Qsyls6Nbj +hSwGRRv2/DSNJjN13lHUZVCVMCRgssyLYlOxt6vuXi7whrpdxlIqojp2TPez2PF4v xMuy6hIWFilUrJ+kvvqDy+fBetC//n5bbS6JwH6J/0DFob5mQ270qexTYKiXIdDw3p Wb8Q9/TusYW21NJcm/TooOCEt9ZGs59nz1VTwXa/epxK5pfnx5ZqEJ5U5MBu2xqdtH Jw4e2v1ZMPwvw== From: Claudiu Beznea To: vkoul@kernel.org, Frank.Li@kernel.org, lgirdwood@gmail.com, broonie@kernel.org, perex@perex.cz, tiwai@suse.com, biju.das.jz@bp.renesas.com, prabhakar.mahadev-lad.rj@bp.renesas.com, p.zabel@pengutronix.de, geert+renesas@glider.be, kuninori.morimoto.gx@renesas.com, long.luu.ur@renesas.com Cc: claudiu.beznea@kernel.org, claudiu.beznea@tuxon.dev, dmaengine@vger.kernel.org, linux-kernel@vger.kernel.org, linux-sound@vger.kernel.org, linux-renesas-soc@vger.kernel.org, Claudiu Beznea , John Madieu Subject: [PATCH v6 14/18] dmaengine: sh: rz-dmac: Add runtime PM support Date: Tue, 26 May 2026 11:47:06 +0300 Message-ID: <20260526084710.3491480-15-claudiu.beznea@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260526084710.3491480-1-claudiu.beznea@kernel.org> References: <20260526084710.3491480-1-claudiu.beznea@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Claudiu Beznea Protect the driver exposed APIs with runtime PM suspend/resume calls before accessing HW registers. As the current driver leaves runtime PM enabled in probe, the purpose of the changes in this patch is to avoid accessing HW registers after a failed system suspend leaves the runtime PM state of the device improperly reinitialized. In that case, the driver remains bound to the device, the APIs are still exposed, and any access to HW registers without runtime resuming the device may lead to synchronous aborts. To avoid leaking resources in case of runtime PM failures, save the error code returned by PM_RUNTIME_ACQUIRE_ERR() in rz_dmac_terminate_all() and return it only at the end of the function to allow the cleanup code to run. A similar approach is used in rz_dmac_free_chan_resources(). Because some exposed APIs (e.g. ->device_terminate_all()) may be called from atomic context according to the documentation, mark the DMA device as pm_runtime_irq_safe(). This patch prepares the driver for suspend-to-RAM support. Tested-by: John Madieu Signed-off-by: Claudiu Beznea Tested-by: Tommaso Merciai --- Changes in v6: - updated patch description - collected tags - in rz_dmac_free_chan_resources() and rz_dmac_terminate_all() don't touch the HW registers if runtime resume failed but allow freeing resources as suggested by sashiko; along with it added debug messages in case the RPM resume failed - dropped the runtime resume from rz_dmac_xfer_desc() and move it instead in rz_dmac_issue_pending() only to avoid calling rpm resume code in interrupt path as, if we are in the interrupt path the device is sanely in runtime resume state - moved the RPM resume code in from rz_dmac_tx_status to rz_dmac_chan_get_residue(), as close as possible to the HW registers read to avoid RPM resume in case the residue could be returned w/o interracting with the HW - updated patch description Changes in v5: - none, this patch is new drivers/dma/sh/rz-dmac.c | 60 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 57 insertions(+), 3 deletions(-) diff --git a/drivers/dma/sh/rz-dmac.c b/drivers/dma/sh/rz-dmac.c index 93394b9934c8..bd4ca8e939f1 100644 --- a/drivers/dma/sh/rz-dmac.c +++ b/drivers/dma/sh/rz-dmac.c @@ -549,12 +549,22 @@ static void rz_dmac_free_chan_resources(struct dma_ch= an *chan) struct rz_dmac *dmac =3D to_rz_dmac(chan->device); struct rz_dmac_desc *desc, *_desc; unsigned long flags; + int ret; + + PM_RUNTIME_ACQUIRE_IF_ENABLED(dmac->dev, pm); + ret =3D PM_RUNTIME_ACQUIRE_ERR(&pm); + if (ret) { + dev_err(dmac->dev, "RPM resume failed for channel %s, ret=3D%d\n!", + dma_chan_name(chan), ret); + } =20 spin_lock_irqsave(&channel->vc.lock, flags); =20 rz_lmdesc_setup(channel, channel->lmdesc.base); =20 - rz_dmac_disable_hw(channel); + /* Skip touching HW if RPM resume failed. Let the cleanup do its jobs. */ + if (!ret) + rz_dmac_disable_hw(channel); =20 if (channel->mid_rid >=3D 0) { clear_bit(channel->mid_rid, dmac->modules); @@ -697,11 +707,22 @@ rz_dmac_prep_dma_cyclic(struct dma_chan *chan, dma_ad= dr_t buf_addr, static int rz_dmac_terminate_all(struct dma_chan *chan) { struct rz_dmac_chan *channel =3D to_rz_dmac_chan(chan); + struct rz_dmac *dmac =3D to_rz_dmac(chan->device); unsigned long flags; LIST_HEAD(head); + int ret; + + PM_RUNTIME_ACQUIRE_IF_ENABLED(dmac->dev, pm); + ret =3D PM_RUNTIME_ACQUIRE_ERR(&pm); + if (ret) { + dev_err(dmac->dev, "RPM resume failed for channel %s, ret=3D%d\n!", + dma_chan_name(chan), ret); + } =20 spin_lock_irqsave(&channel->vc.lock, flags); - rz_dmac_disable_hw(channel); + /* Don't return if RPM failed. Let the cleanup do its jobs. */ + if (!ret) + rz_dmac_disable_hw(channel); rz_lmdesc_setup(channel, channel->lmdesc.base); =20 if (channel->desc) { @@ -716,13 +737,20 @@ static int rz_dmac_terminate_all(struct dma_chan *cha= n) spin_unlock_irqrestore(&channel->vc.lock, flags); vchan_dma_desc_free_list(&channel->vc, &head); =20 - return 0; + return ret; } =20 static void rz_dmac_issue_pending(struct dma_chan *chan) { struct rz_dmac_chan *channel =3D to_rz_dmac_chan(chan); + struct rz_dmac *dmac =3D to_rz_dmac(chan->device); unsigned long flags; + int ret; + + PM_RUNTIME_ACQUIRE_IF_ENABLED(dmac->dev, pm); + ret =3D PM_RUNTIME_ACQUIRE_ERR(&pm); + if (ret) + return; =20 spin_lock_irqsave(&channel->vc.lock, flags); =20 @@ -807,6 +835,11 @@ static void rz_dmac_device_synchronize(struct dma_chan= *chan) =20 vchan_synchronize(&channel->vc); =20 + PM_RUNTIME_ACQUIRE_IF_ENABLED(dmac->dev, pm); + ret =3D PM_RUNTIME_ACQUIRE_ERR(&pm); + if (ret) + return; + ret =3D read_poll_timeout(rz_dmac_ch_readl, chstat, !(chstat & CHSTAT_EN), 100, 100000, false, channel, CHSTAT, 1); if (ret < 0) @@ -866,6 +899,7 @@ static int rz_dmac_chan_get_residue(struct device *dev,= struct rz_dmac_chan *cha struct rz_dmac_desc *desc =3D NULL; struct virt_dma_desc *vd; u32 crla, crtb, i; + int ret; =20 vd =3D vchan_find_desc(&channel->vc, cookie); if (vd) { @@ -884,6 +918,11 @@ static int rz_dmac_chan_get_residue(struct device *dev= , struct rz_dmac_chan *cha return 0; } =20 + PM_RUNTIME_ACQUIRE_IF_ENABLED(dev, pm); + ret =3D PM_RUNTIME_ACQUIRE_ERR(&pm); + if (ret) + return ret; + /* * We need to read two registers. Make sure the hardware does not move * to next lmdesc while reading the current lmdesc. Trying it 3 times @@ -965,6 +1004,13 @@ static int rz_dmac_device_pause_set(struct rz_dmac_ch= an *channel, static int rz_dmac_device_pause(struct dma_chan *chan) { struct rz_dmac_chan *channel =3D to_rz_dmac_chan(chan); + struct rz_dmac *dmac =3D to_rz_dmac(chan->device); + int ret; + + PM_RUNTIME_ACQUIRE_IF_ENABLED(dmac->dev, pm); + ret =3D PM_RUNTIME_ACQUIRE_ERR(&pm); + if (ret) + return ret; =20 guard(spinlock_irqsave)(&channel->vc.lock); =20 @@ -994,6 +1040,13 @@ static int rz_dmac_device_resume_set(struct rz_dmac_c= han *channel, static int rz_dmac_device_resume(struct dma_chan *chan) { struct rz_dmac_chan *channel =3D to_rz_dmac_chan(chan); + struct rz_dmac *dmac =3D to_rz_dmac(chan->device); + int ret; + + PM_RUNTIME_ACQUIRE_IF_ENABLED(dmac->dev, pm); + ret =3D PM_RUNTIME_ACQUIRE_ERR(&pm); + if (ret) + return ret; =20 guard(spinlock_irqsave)(&channel->vc.lock); =20 @@ -1274,6 +1327,7 @@ static int rz_dmac_probe(struct platform_device *pdev) return dev_err_probe(&pdev->dev, PTR_ERR(dmac->rstc), "failed to get resets\n"); =20 + pm_runtime_irq_safe(&pdev->dev); pm_runtime_enable(&pdev->dev); ret =3D pm_runtime_resume_and_get(&pdev->dev); if (ret < 0) { --=20 2.43.0 From nobody Mon Jun 8 21:46:47 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DF5643CF024; Tue, 26 May 2026 08:48:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779785318; cv=none; b=kkBhBD+DordJ06a3LjLapPZiEmE0UA8HVGS+EFdAm13fEYU64gT6mJaFXb1xu8V2oFLbOnXNOsgmdOJJlxd376bt7niZJFUlzjEaAJyXAXtwBa581OLoMkuq7S0PJiiGQVGMWPRfS2CCvhYhk3Smrsgd+Bz2frNHWXwDFJulCEs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779785318; c=relaxed/simple; bh=PGoodW0KLCMdw8CaZbGQxwB/elja+UDEo59ylVRJrFw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QJeWE0RxpATJpmHbsAOqKqbHggHLghfBjsPFy83CItDn75RWwS5QG6D2YSPDc+Pul5aTvfyIwoTQTZZ5d7wytwQxXgaWxs72qZHEIooSt5NzBFQ5UG+P73QYDWZpSxSpKzapJhGymJHPbzoA0c2pm/hcuEy2UHZzfUj+zsNLbiE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=MUa9Zs5U; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="MUa9Zs5U" Received: by smtp.kernel.org (Postfix) with ESMTPSA id EB08E1F000E9; Tue, 26 May 2026 08:48:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1779785316; bh=tdGQA/ew96xuRX3BMQQpGES94Qbpnn7ifKeil/gP3vw=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=MUa9Zs5UY8v5rwUJQ+IKy9LhBbrOpyGj+GZ+qVCufcDAbcqAZ0EAALdXnHicmwyUr T0IdDvLzsiB7CUl9Hf1SBK8Q4dy6C9Nbc9NCIWK/pGWkadEnTnnSWO77KGvS72dJXG 0D0kU3/9PKXyeL4BlssKt+4EvUMHBepb3r8T2QF6noDIPHUxi5rg5NxS0Dr7iv0wid 28EVZqKkTaAh+Mlunarc8t3FTTGKcJ20jzY5+qM+co8uU4a3A3DKLrD7jCF1s2Smt+ 28t0NAgHsoLpK6U+jQMaIoCin+xoTc2YcG9Mq4qJxBLJbQoQf2SoJFnYRfXA0/kc+m ihlv54vpsJk8A== From: Claudiu Beznea To: vkoul@kernel.org, Frank.Li@kernel.org, lgirdwood@gmail.com, broonie@kernel.org, perex@perex.cz, tiwai@suse.com, biju.das.jz@bp.renesas.com, prabhakar.mahadev-lad.rj@bp.renesas.com, p.zabel@pengutronix.de, geert+renesas@glider.be, kuninori.morimoto.gx@renesas.com, long.luu.ur@renesas.com Cc: claudiu.beznea@kernel.org, claudiu.beznea@tuxon.dev, dmaengine@vger.kernel.org, linux-kernel@vger.kernel.org, linux-sound@vger.kernel.org, linux-renesas-soc@vger.kernel.org, Claudiu Beznea , John Madieu Subject: [PATCH v6 15/18] dmaengine: sh: rz-dmac: Add suspend to RAM support Date: Tue, 26 May 2026 11:47:07 +0300 Message-ID: <20260526084710.3491480-16-claudiu.beznea@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260526084710.3491480-1-claudiu.beznea@kernel.org> References: <20260526084710.3491480-1-claudiu.beznea@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Claudiu Beznea The Renesas RZ/G3S SoC supports a power saving mode in which power to most of the SoC components is turned off, including the DMA IP. Add suspend to RAM support to save and restore the DMA IP registers. Cyclic DMA channels require special handling. Since they can be paused and resumed during system suspend/resume, the driver restores additional registers for these channels during the system resume phase. If a channel was not explicitly paused during suspend, the driver ensures that it is paused and resumed as part of the system suspend/resume flow. Tested-by: John Madieu Signed-off-by: Claudiu Beznea Tested-by: Tommaso Merciai --- Changes in v6: - collected tags - dropped rz_dmac_suspend_prepare() as I found issues with it and updated t= he patch description - with it used DEFINE_SIMPLE_DEV_PM_OPS() for PM ops - used pm_ptr() instead of pm_sleep_ptr() Changes in v5: - runtime PM enable in rz_dmac_suspend_prepare() and rz_dmac_suspend_recove= r() - initialize ret in rz_dmac_suspend() - in suspend/resume APIs changed the order b/w runtime PM and reset calls to follow the sequence present in remove and probe - in rz_dmac_suspend(): take into account the error code returned by pm_runtime_put_sync() - in rz_dmac_resume(): use "return errors ? : 0;" instead of "return errors ? : ret;" Changes in v4: - in rz_dmac_device_synchronize() kept the read_poll_timeout() as this doesn't fail anymore with the proper status return from ->device_tx_status() API in case the channel is paused; with it the patch description was updated - keep the cleanup path in rz_dmac_suspend() simpler to avoid confusion when using guard() - used SYSTEM_SLEEP_PM_OPS() as there is no need for having the suspend/resume callbacks being called in NOIRQ phase Changes in v3: - dropped RZ_DMAC_CHAN_STATUS_SYS_SUSPENDED - dropped read_poll_timeout() from rz_dmac_device_synchronze() as with audio drivers this times out all the time on suspend because the audio DMA is already paused when the rz_dmac_device_synchronize() is called; updated the commit description to describe this change - call rz_dmac_device_pause_internal() only if RZ_DMAC_CHAN_STATUS_PAUSED bit is not set or the device is enabled in HW - updated rz_dmac_device_resume_set() to have it simpler and cover the cases when it is called with the channel enabled or paused; updated the comment describing the covered use cases - call rz_dmac_device_resume_internal() only if RZ_DMAC_CHAN_STATUS_PAUSED_INTERNAL bit is set - in rz_dmac_chan_is_enabled() return -EAGAIN only if the channel is enabled in HW - in rz_dmac_suspend_recover() drop the update of RZ_DMAC_CHAN_STATUS_SYS_SUSPENDED as this is not available anymore - in rz_dmac_suspend() call rz_dmac_device_pause_internal() unconditionally as the logic is now handled inside the called function; also, do not ignore anymore the failure of internal suspend and abort the suspend instead - report channel internal resume failures in rz_dmac_resume() - use rz_dmac_disable_hw() instead of open coding it in rz_dmac_resume() - call rz_dmac_device_resume_internal() uncoditionally as the skip logic is now handled in the function itself - use NOIRQ_SYSTEM_SLEEP_PM_OPS() - didn't collect Tommaso's Tb tag as the series was changed a lot since v2 Changes in v2: - fixed typos in patch description - in rz_dmac_suspend_prepare(): return -EAGAIN based on the value returned by vchan_issue_pending() - in rz_dmac_suspend_recover(): clear RZ_DMAC_CHAN_STATUS_SYS_SUSPENDED for non cyclic channels - in rz_dmac_resume(): call rz_dmac_set_dma_req_no() only for cyclic channe= ls drivers/dma/sh/rz-dmac.c | 180 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 175 insertions(+), 5 deletions(-) diff --git a/drivers/dma/sh/rz-dmac.c b/drivers/dma/sh/rz-dmac.c index bd4ca8e939f1..2a7124e4aea3 100644 --- a/drivers/dma/sh/rz-dmac.c +++ b/drivers/dma/sh/rz-dmac.c @@ -69,10 +69,12 @@ struct rz_dmac_desc { * enum rz_dmac_chan_status: RZ DMAC channel status * @RZ_DMAC_CHAN_STATUS_PAUSED: Channel is paused though DMA engine callba= cks * @RZ_DMAC_CHAN_STATUS_CYCLIC: Channel is cyclic + * @RZ_DMAC_CHAN_STATUS_PAUSED_INTERNAL: Channel is paused through driver = internal logic */ enum rz_dmac_chan_status { RZ_DMAC_CHAN_STATUS_PAUSED, RZ_DMAC_CHAN_STATUS_CYCLIC, + RZ_DMAC_CHAN_STATUS_PAUSED_INTERNAL, }; =20 struct rz_dmac_chan { @@ -92,6 +94,10 @@ struct rz_dmac_chan { u32 chctrl; int mid_rid; =20 + struct { + u32 nxla; + } pm_state; + struct list_head ld_free; =20 struct { @@ -1017,20 +1023,57 @@ static int rz_dmac_device_pause(struct dma_chan *ch= an) return rz_dmac_device_pause_set(channel, BIT(RZ_DMAC_CHAN_STATUS_PAUSED)); } =20 +static int rz_dmac_device_pause_internal(struct rz_dmac_chan *channel) +{ + lockdep_assert_held(&channel->vc.lock); + + /* Skip channels explicitly paused by consummers or disabled. */ + if (channel->status & BIT(RZ_DMAC_CHAN_STATUS_PAUSED) || + !rz_dmac_chan_is_enabled(channel)) + return 0; + + return rz_dmac_device_pause_set(channel, BIT(RZ_DMAC_CHAN_STATUS_PAUSED_I= NTERNAL)); +} + static int rz_dmac_device_resume_set(struct rz_dmac_chan *channel, unsigned long clear_bitmask) { - int ret =3D 0; u32 val; + int ret; =20 lockdep_assert_held(&channel->vc.lock); =20 - /* Do not check CHSTAT_SUS but rely on HW capabilities. */ + /* + * We can be: + * + * 1/ after the channel was paused by a consummer and now it + * needs to be resummed + * 2/ after the channel was paused internally (as a result of + * a system suspend with power loss or not) + * 3/ after the channel was paused by a consummer, the system + * went through a system suspend (with power loss or not) + * and the consummer wants to resume the channel + * + * To cover all the above cases we set both CLRSUS and SETEN. + * + * In case 1/ setting SETEN while the channel is still enabled + * is harmless for the controller. + * + * In case 2/ the channel is disabled when calling this function + * and setting CLRSUS is harmless for the controller as the + * channel is disabled anyway. + * + * In case 3/ the channel is disabled/enabled if the system + * went though a suspend with power loss/or not and setting + * CLRSUS/SETEN is harmless for the controller as the channel + * is enabled/disabled anyway. + */ + + rz_dmac_ch_writel(channel, CHCTRL_CLRSUS | CHCTRL_SETEN, CHCTRL, 1); =20 - rz_dmac_ch_writel(channel, CHCTRL_CLRSUS, CHCTRL, 1); ret =3D read_poll_timeout_atomic(rz_dmac_ch_readl, val, - !(val & CHSTAT_SUS), 1, 1024, false, - channel, CHSTAT, 1); + ((val & (CHSTAT_SUS | CHSTAT_EN)) =3D=3D CHSTAT_EN), + 1, 1024, false, channel, CHSTAT, 1); =20 channel->status &=3D ~clear_bitmask; =20 @@ -1056,6 +1099,16 @@ static int rz_dmac_device_resume(struct dma_chan *ch= an) return rz_dmac_device_resume_set(channel, BIT(RZ_DMAC_CHAN_STATUS_PAUSED)= ); } =20 +static int rz_dmac_device_resume_internal(struct rz_dmac_chan *channel) +{ + lockdep_assert_held(&channel->vc.lock); + + if (!(channel->status & BIT(RZ_DMAC_CHAN_STATUS_PAUSED_INTERNAL))) + return 0; + + return rz_dmac_device_resume_set(channel, BIT(RZ_DMAC_CHAN_STATUS_PAUSED_= INTERNAL)); +} + /* * -----------------------------------------------------------------------= ------ * IRQ handling @@ -1421,6 +1474,122 @@ static void rz_dmac_remove(struct platform_device *= pdev) pm_runtime_disable(&pdev->dev); } =20 +static void rz_dmac_suspend_recover(struct rz_dmac *dmac) +{ + int ret; + + PM_RUNTIME_ACQUIRE_IF_ENABLED(dmac->dev, pm); + ret =3D PM_RUNTIME_ACQUIRE_ERR(&pm); + if (ret) + return; + + for (unsigned int i =3D 0; i < dmac->n_channels; i++) { + struct rz_dmac_chan *channel =3D &dmac->channels[i]; + + guard(spinlock_irqsave)(&channel->vc.lock); + + if (!(channel->status & BIT(RZ_DMAC_CHAN_STATUS_CYCLIC))) + continue; + + rz_dmac_device_resume_internal(channel); + } +} + +static int rz_dmac_suspend(struct device *dev) +{ + struct rz_dmac *dmac =3D dev_get_drvdata(dev); + int ret =3D 0; + + for (unsigned int i =3D 0; i < dmac->n_channels; i++) { + struct rz_dmac_chan *channel =3D &dmac->channels[i]; + + guard(spinlock_irqsave)(&channel->vc.lock); + + if (!(channel->status & BIT(RZ_DMAC_CHAN_STATUS_CYCLIC))) + continue; + + ret =3D rz_dmac_device_pause_internal(channel); + if (ret) { + dev_err(dev, "Failed to suspend channel %s\n", + dma_chan_name(&channel->vc.chan)); + break; + } + + channel->pm_state.nxla =3D rz_dmac_ch_readl(channel, NXLA, 1); + } + + if (ret) + goto suspend_recover; + + ret =3D reset_control_assert(dmac->rstc); + if (ret) + goto suspend_recover; + + ret =3D pm_runtime_put_sync(dev); + if (ret < 0) + goto reset_deassert; + + return 0; + +reset_deassert: + reset_control_deassert(dmac->rstc); +suspend_recover: + rz_dmac_suspend_recover(dmac); + return ret; +} + +static int rz_dmac_resume(struct device *dev) +{ + struct rz_dmac *dmac =3D dev_get_drvdata(dev); + int errors =3D 0, ret; + + ret =3D pm_runtime_resume_and_get(dev); + if (ret) + return ret; + + ret =3D reset_control_deassert(dmac->rstc); + if (ret) { + /* + * Do not put runtime PM here and keep the same state as in + * probe. As subsequent suspend/resume cycles may follow, leave + * the runtime PM as is, here, to avoid imbalances. + */ + return ret; + } + + rz_dmac_writel(dmac, DCTRL_DEFAULT, CHANNEL_0_7_COMMON_BASE + DCTRL); + rz_dmac_writel(dmac, DCTRL_DEFAULT, CHANNEL_8_15_COMMON_BASE + DCTRL); + + for (unsigned int i =3D 0; i < dmac->n_channels; i++) { + struct rz_dmac_chan *channel =3D &dmac->channels[i]; + + guard(spinlock_irqsave)(&channel->vc.lock); + + rz_dmac_disable_hw(&dmac->channels[i]); + + if (!(channel->status & BIT(RZ_DMAC_CHAN_STATUS_CYCLIC))) + continue; + + rz_dmac_set_dma_req_no(dmac, channel->index, channel->mid_rid); + + rz_dmac_ch_writel(channel, channel->pm_state.nxla, NXLA, 1); + rz_dmac_ch_writel(channel, channel->chcfg, CHCFG, 1); + rz_dmac_ch_writel(channel, CHCTRL_SWRST, CHCTRL, 1); + rz_dmac_ch_writel(channel, channel->chctrl, CHCTRL, 1); + + ret =3D rz_dmac_device_resume_internal(channel); + if (ret) { + errors =3D ret; + dev_err(dev, "Failed to resume channel %s, ret=3D%d\n", + dma_chan_name(&channel->vc.chan), ret); + } + } + + return errors ? : 0; +} + +static DEFINE_SIMPLE_DEV_PM_OPS(rz_dmac_pm_ops, rz_dmac_suspend, rz_dmac_r= esume); + static const struct rz_dmac_info rz_dmac_v2h_info =3D { .icu_register_dma_req =3D rzv2h_icu_register_dma_req, .default_dma_req_no =3D RZV2H_ICU_DMAC_REQ_NO_DEFAULT, @@ -1447,6 +1616,7 @@ static struct platform_driver rz_dmac_driver =3D { .driver =3D { .name =3D "rz-dmac", .of_match_table =3D of_rz_dmac_match, + .pm =3D pm_ptr(&rz_dmac_pm_ops), }, .probe =3D rz_dmac_probe, .remove =3D rz_dmac_remove, --=20 2.43.0 From nobody Mon Jun 8 21:46:47 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DD62D3CFF77; Tue, 26 May 2026 08:48:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779785323; cv=none; b=Vw80Hy2iA0qGCy2apX39I7sihMTjeQUZk0Fl18Dlds/KgYMGcMYswU3OMXpu8dc/BO2Aeku0PGcBTu5ZGuDOtevP1OXgRe14igMfVX+56KyBrPEqzMkWIsPAzwg6xU34iR/tyGQ2NNliu8sty6b2mQG5PFxF5W6EpCH7bV97FjA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779785323; c=relaxed/simple; bh=CeZEu3pwBJjDFmuL0EL+T+CD1lovZV0s4zpb/Tqh9bQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=h5fcgoxZ7dIgVZJSpQRXzOuBr8r88exj/2lxkDL/Gr88q8culAaS3td8AsbHl3Vp4RSVYahL/kICuxJioPzC1wkavWwNuVfciwogU6DFlTTxGHOaW3Yc5pJ/8pP9PPi1aeEuC50eX3kRzUCtbg53VufY6ZkO1ppDx05iuZsgcTY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=e00TlGJi; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="e00TlGJi" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2088A1F00A3A; Tue, 26 May 2026 08:48:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1779785321; bh=TQbRwZQ7d4FlsIbqnLU4W3y/SMw7SJU8/ZByZ98sVx8=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=e00TlGJi/Rraef95y8MEeGjsJI4PVUX9b8lQgtfz8pIIH3U6s3SMoYm5krw8yorpn Tqj3lk8Zm5nnKHFKo2lUkzA1GmeYUAE5q1VyAAP576CcUJbGO3JY8KhmJ6fQoKCvvj nxPSSTIXRAM41qBszuUc2gjj2mU4d1Y+VBh7gPYxPrZExGltrQhqXWoCX6fjQhB08o DZinvz+kBXsv4l21khOn97+tmw5VE0g5DXaxAfjxUD6hM21o3eIqdPdliX+Uet2wYv J3a4OFfeyBLnNEQh0aDIbZx+ajWX9BK/31JpAN9oJZGNHHrlTOyrROseXmUkWWDy/b RhwDJrGhmWKhw== From: Claudiu Beznea To: vkoul@kernel.org, Frank.Li@kernel.org, lgirdwood@gmail.com, broonie@kernel.org, perex@perex.cz, tiwai@suse.com, biju.das.jz@bp.renesas.com, prabhakar.mahadev-lad.rj@bp.renesas.com, p.zabel@pengutronix.de, geert+renesas@glider.be, kuninori.morimoto.gx@renesas.com, long.luu.ur@renesas.com Cc: claudiu.beznea@kernel.org, claudiu.beznea@tuxon.dev, dmaengine@vger.kernel.org, linux-kernel@vger.kernel.org, linux-sound@vger.kernel.org, linux-renesas-soc@vger.kernel.org, Claudiu Beznea , John Madieu Subject: [PATCH v6 16/18] ASoC: renesas: rz-ssi: Add pause support Date: Tue, 26 May 2026 11:47:08 +0300 Message-ID: <20260526084710.3491480-17-claudiu.beznea@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260526084710.3491480-1-claudiu.beznea@kernel.org> References: <20260526084710.3491480-1-claudiu.beznea@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Claudiu Beznea Add pause support as a preparatory step to switch to PCM dmaengine APIs. Acked-by: Mark Brown Tested-by: John Madieu Signed-off-by: Claudiu Beznea --- Changes in v6: - collected tags Changes in v5: - none Changes in v4: - collected tags Changes in v3: - none, this patch is new sound/soc/renesas/rz-ssi.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/sound/soc/renesas/rz-ssi.c b/sound/soc/renesas/rz-ssi.c index 71e434cfe07b..d4e1dded3a9c 100644 --- a/sound/soc/renesas/rz-ssi.c +++ b/sound/soc/renesas/rz-ssi.c @@ -847,6 +847,7 @@ static int rz_ssi_dai_trigger(struct snd_pcm_substream = *substream, int cmd, =20 switch (cmd) { case SNDRV_PCM_TRIGGER_RESUME: + case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: ret =3D rz_ssi_trigger_resume(ssi, strm); if (ret) return ret; @@ -888,6 +889,7 @@ static int rz_ssi_dai_trigger(struct snd_pcm_substream = *substream, int cmd, break; =20 case SNDRV_PCM_TRIGGER_SUSPEND: + case SNDRV_PCM_TRIGGER_PAUSE_PUSH: rz_ssi_stop(ssi, strm); break; =20 @@ -1054,7 +1056,8 @@ static const struct snd_pcm_hardware rz_ssi_pcm_hardw= are =3D { .info =3D SNDRV_PCM_INFO_INTERLEAVED | SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_MMAP_VALID | - SNDRV_PCM_INFO_RESUME, + SNDRV_PCM_INFO_RESUME | + SNDRV_PCM_INFO_PAUSE, .buffer_bytes_max =3D PREALLOC_BUFFER, .period_bytes_min =3D 32, .period_bytes_max =3D 8192, --=20 2.43.0 From nobody Mon Jun 8 21:46:47 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7D8543CFF4D; Tue, 26 May 2026 08:48:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779785328; cv=none; b=G93vDrmVs+ZXX5hyawHJyiEjCyt+AFWXCEHpRklEW8hesNmtVO+2oPSwip4CaPXFzckJSY8uXiyeDoWGjcAGdtJ+XEhQ3VqC7hZwad9se4J4iMYHnDJQ49qaR7nUAsMDd4E2TaEQtZdBYQ0iaW0jynNwpDjW0y1HdPPUenLLWrE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779785328; c=relaxed/simple; bh=BZ8T8t6Z/GwXbDAsAYVZ1FdnKvmmtyXc0VCxnm7ipho=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=JUQLI1tkqit30+pj6S5WP1dpmmcnZKoV+nf/8Xg6tzG0zOx2KU2ii0OddU8NM/bp7HSMrehYlRyTLGL1E9pTLlJmeigLen2wN49+bzQHx0LIc2r6eiEB7+mnY5zcopXDpcanl8UCJNswGw4YuN3wSmdKmxAcltQ4Fy6grGgZ4Og= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=PBEpyu0S; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="PBEpyu0S" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0BE061F000E9; Tue, 26 May 2026 08:48:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1779785326; bh=0ukiRAjs+pKhEN0LMMkNyZXCYn+c2SLSyeX32mRunwM=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=PBEpyu0SM1pT49x2brc4w83zugp44itLMymxj6BXQInQxHrpAQVxoIH/UPFYWKrNu 10eJrCmCzw4F984iHPTuxZjYQ0J6WH0pQC4BjxSie32XHJbTsQAsDHXXhTU3G3QNBn LFET5vwzmpyqMpTJgDbZqhmUhFlt2NoLyu7U54JyENe59f5+UWolGYIWQFNKXIiz1I 6/ND+eNzXYCzVKGWHL6L4RFzghbzDfYnuZxZ3r4lMRLvx2BvtL7Cwm1dQ8V3hyCaCf 1/p+zvRXh3eg/TtpLSisvrTdaXNlTa1kqq1YJ7K0u5REWbu+YWzbZTCXRhWNHOemkB mjq0cCsh99ZfQ== From: Claudiu Beznea To: vkoul@kernel.org, Frank.Li@kernel.org, lgirdwood@gmail.com, broonie@kernel.org, perex@perex.cz, tiwai@suse.com, biju.das.jz@bp.renesas.com, prabhakar.mahadev-lad.rj@bp.renesas.com, p.zabel@pengutronix.de, geert+renesas@glider.be, kuninori.morimoto.gx@renesas.com, long.luu.ur@renesas.com Cc: claudiu.beznea@kernel.org, claudiu.beznea@tuxon.dev, dmaengine@vger.kernel.org, linux-kernel@vger.kernel.org, linux-sound@vger.kernel.org, linux-renesas-soc@vger.kernel.org, Claudiu Beznea , John Madieu Subject: [PATCH v6 17/18] ASoC: renesas: rz-ssi: Use generic PCM dmaengine APIs Date: Tue, 26 May 2026 11:47:09 +0300 Message-ID: <20260526084710.3491480-18-claudiu.beznea@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260526084710.3491480-1-claudiu.beznea@kernel.org> References: <20260526084710.3491480-1-claudiu.beznea@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Claudiu Beznea On Renesas RZ/G2L and RZ/G3S SoCs (where this was tested), captured audio files occasionally contained random spikes when viewed with a tool such as Audacity. These spikes were also audible as popping noises. Using cyclic DMA resolves this issue. The driver was reworked to use the existing support provided by the generic PCM dmaengine APIs. In addition to eliminating the random spikes, the following issues were addressed: - blank periods at the beginning of recorded files, which occurred intermittently, are no longer present - no overruns or underruns were observed when continuously recording short audio files (e.g. 5 seconds long) in a loop - concurrency issues in the SSI driver when enqueuing DMA requests were eliminated; previously, DMA requests could be prepared and submitted both from the DMA completion callback and the interrupt handler, which led to crashes after several hours of testing - the SSI driver logic is simplified - the number of generated interrupts is reduced by approximately 250% In the SSI platform driver probe function, the following changes were made: - the driver-specific DMA configuration was removed in favor of the generic PCM dmaengine APIs. As a result, explicit cleanup goto labels are no longer required and the driver remove callback was dropped, since resource management is now handled via devres helpers - special handling was added for IP variants operating in half-duplex mode, where the DMA channel name in the device tree is "rt"; this DMA channel name is taken into account and passed to the generic PCM dmaengine configuration data All code previously responsible for preparing and completing DMA transfers was removed, as this functionality is now handled entirely by the generic PCM dmaengine APIs. Since DMA channels must be paused and resumed during recovery paths (overruns and underruns reported by the hardware), the DMA channel references are stored in rz_ssi_hw_params(). The logic in rz_ssi_is_dma_enabled() was updated to reflect that the driver no longer manages DMA transfers directly. To avoid software reported underruns (e.g. when running aplay during consecutive suspend/resume cycles, or when the CPU is nearly 100% loaded), rz_ssi_pcm_hardware.buffer_bytes_max was increased to 192K. At the same time, rz_ssi_pcm_hardware.period_bytes_max was set to 48K to reduce interrupt overhead. Finally, rz_ssi_stream_is_play() was removed, as it had only a single remaining user after this rework, and its logic was inlined at the call site. Acked-by: Mark Brown Tested-by: John Madieu Signed-off-by: Claudiu Beznea --- Changes in v6: - collected tags - in rz_ssi_interrupt() added extra validity checkes for playback/capture substream and the ssi->dmas[] as suggested by sashiko - still preserved the Mark's Ack Changes in v5: - in rz_ssi_interrupt(): check if playback and capture dmas are the same to avoid calling dmaengine_pause() twice, on the same DMA channel - in rz_ssi_shutdown(): set ssi->dmas[i] =3D NULL - still preserved the Mark's Ack Changes in v4: - collected tags - in rz_ssi_interrupt() checked the dma channel is valid before calling dmaengine_pause(); at the same time initialized the rz_ssi->dmas[] with NULL in case the DMA is not available in rz_ssi_dai_hw_params() - set rz_ssi_dmaengine_pcm_conf.prealloc_buffer_size - dinamically allocate the object of type snd_dmaengine_pcm_config passed to devm_snd_dmaengine_pcm_register() to avoid issues when the driver is instantiated for more than one HW instance - I considered keeping the ack was still OK; Mark, please let me know if you consider otherwise Changes in v3: - s/CONFIG_SND_SOC_GENERIC_DMAENGINE_PCM/SND_SOC_GENERIC_DMAENGINE_PCM in Kconfig - in rz_ssi_clk_setup(): drop the update of dma_dai->maxburst - in rz_ssi_interrupt(): pause the DMA channels in case of HW over/underruns - add different open APIs for rz_ssi_soc_component_pio and rz_ssi_soc_component_dma=20 - set rz_ssi_pcm_hardware to rz_ssi_dmaengine_pcm_conf.pcm_hardware and updated the buffer_bytes_max to avoid underruns detected by applications just before suspending; along with it updated period_bytes_max for lower interrupt overhead; updated the patch description for this; with it updated the snd_pcm_set_managed_buffer_all() arguments to use the rz_ssi_pcm_hardware - added back rz_ssi_soc_component_pio.pcm_new instantiation as the PIO mode was broken w/o it - use specific rz_ssi_soc_component_dma.open implementation for DMA - updated rz_ssi_dmaengine_pcm_conf.chan_names[].{tx, rx} either if there is about full or half duplex instantiation and move the flags variable local to the code block that uses it - check devm_snd_dmaengine_pcm_register() for defer errors Changes in v2: - fixed typos in patch description - select CONFIG_SND_SOC_GENERIC_DMAENGINE_PCM for rz-ssi driver - in rz_ssi_dai_hw_params() check if DMA is enabled before calling snd_dmaengine_pcm_get_chan() to avoid failures for PIO mode - do not drop rz_ssi_pcm_pointer() and rz_ssi_pcm_new() as these are necessary for PIO mode - added 2 struct snd_soc_component_driver, one for PIO mode, one for DMA and updated probe() to register the proper snd_soc_component_driver based on the working mode sound/soc/renesas/Kconfig | 1 + sound/soc/renesas/rz-ssi.c | 394 +++++++++++++------------------------ 2 files changed, 136 insertions(+), 259 deletions(-) diff --git a/sound/soc/renesas/Kconfig b/sound/soc/renesas/Kconfig index 11c2027c88a7..6520217e7407 100644 --- a/sound/soc/renesas/Kconfig +++ b/sound/soc/renesas/Kconfig @@ -56,6 +56,7 @@ config SND_SOC_MSIOF config SND_SOC_RZ tristate "RZ/G2L series SSIF-2 support" depends on ARCH_RZG2L || COMPILE_TEST + select SND_SOC_GENERIC_DMAENGINE_PCM help This option enables RZ/G2L SSIF-2 sound support. =20 diff --git a/sound/soc/renesas/rz-ssi.c b/sound/soc/renesas/rz-ssi.c index d4e1dded3a9c..9fe8a639c47c 100644 --- a/sound/soc/renesas/rz-ssi.c +++ b/sound/soc/renesas/rz-ssi.c @@ -13,6 +13,8 @@ #include #include #include +#include +#include #include #include =20 @@ -87,8 +89,6 @@ struct rz_ssi_stream { struct rz_ssi_priv *priv; struct snd_pcm_substream *substream; int fifo_sample_size; /* sample capacity of SSI FIFO */ - int dma_buffer_pos; /* The address for the next DMA descriptor */ - int completed_dma_buf_pos; /* The address of the last completed DMA descr= iptor. */ int period_counter; /* for keeping track of periods transferred */ int buffer_pos; /* current frame position in the buffer */ int running; /* 0=3Dstopped, 1=3Drunning */ @@ -96,8 +96,6 @@ struct rz_ssi_stream { int uerr_num; int oerr_num; =20 - struct dma_chan *dma_ch; - int (*transfer)(struct rz_ssi_priv *ssi, struct rz_ssi_stream *strm); }; =20 @@ -108,7 +106,6 @@ struct rz_ssi_priv { struct clk *sfr_clk; struct clk *clk; =20 - phys_addr_t phys; int irq_int; int irq_tx; int irq_rx; @@ -148,9 +145,10 @@ struct rz_ssi_priv { unsigned int sample_width; unsigned int sample_bits; } hw_params_cache; -}; =20 -static void rz_ssi_dma_complete(void *data); + struct snd_dmaengine_dai_dma_data dma_dais[SNDRV_PCM_STREAM_LAST + 1]; + struct dma_chan *dmas[SNDRV_PCM_STREAM_LAST + 1]; +}; =20 static void rz_ssi_reg_writel(struct rz_ssi_priv *priv, uint reg, u32 data) { @@ -172,11 +170,6 @@ static void rz_ssi_reg_mask_setl(struct rz_ssi_priv *p= riv, uint reg, writel(val, (priv->base + reg)); } =20 -static inline bool rz_ssi_stream_is_play(struct snd_pcm_substream *substre= am) -{ - return substream->stream =3D=3D SNDRV_PCM_STREAM_PLAYBACK; -} - static inline struct rz_ssi_stream * rz_ssi_stream_get(struct rz_ssi_priv *ssi, struct snd_pcm_substream *subst= ream) { @@ -185,7 +178,7 @@ rz_ssi_stream_get(struct rz_ssi_priv *ssi, struct snd_p= cm_substream *substream) =20 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)); + return !ssi->playback.transfer && !ssi->capture.transfer; } =20 static void rz_ssi_set_substream(struct rz_ssi_stream *strm, @@ -215,8 +208,6 @@ static void rz_ssi_stream_init(struct rz_ssi_stream *st= rm, struct snd_pcm_substream *substream) { rz_ssi_set_substream(strm, substream); - strm->dma_buffer_pos =3D 0; - strm->completed_dma_buf_pos =3D 0; strm->period_counter =3D 0; strm->buffer_pos =3D 0; =20 @@ -242,12 +233,13 @@ static void rz_ssi_stream_quit(struct rz_ssi_priv *ss= i, dev_info(dev, "underrun =3D %d\n", strm->uerr_num); } =20 -static int rz_ssi_clk_setup(struct rz_ssi_priv *ssi, unsigned int rate, - unsigned int channels) +static int rz_ssi_clk_setup(struct rz_ssi_priv *ssi, struct snd_pcm_substr= eam *substream, + unsigned int rate, unsigned int channels) { static u8 ckdv[] =3D { 1, 2, 4, 8, 16, 32, 64, 128, 6, 12, 24, 48, 96 = }; unsigned int channel_bits =3D 32; /* System Word Length */ unsigned long bclk_rate =3D rate * channels * channel_bits; + struct snd_dmaengine_dai_dma_data *dma_dai; unsigned int div; unsigned int i; u32 ssicr =3D 0; @@ -290,6 +282,8 @@ static int rz_ssi_clk_setup(struct rz_ssi_priv *ssi, un= signed int rate, return -EINVAL; } =20 + dma_dai =3D &ssi->dma_dais[substream->stream]; + /* * DWL: Data Word Length =3D {16, 24, 32} bits * SWL: System Word Length =3D 32 bits @@ -298,12 +292,15 @@ static int rz_ssi_clk_setup(struct rz_ssi_priv *ssi, = unsigned int rate, switch (ssi->hw_params_cache.sample_width) { case 16: ssicr |=3D SSICR_DWL(1); + dma_dai->addr_width =3D DMA_SLAVE_BUSWIDTH_2_BYTES; break; case 24: ssicr |=3D SSICR_DWL(5) | SSICR_PDTA; + dma_dai->addr_width =3D DMA_SLAVE_BUSWIDTH_4_BYTES; break; case 32: ssicr |=3D SSICR_DWL(6); + dma_dai->addr_width =3D DMA_SLAVE_BUSWIDTH_4_BYTES; break; default: dev_err(ssi->dev, "Not support %u data width", @@ -344,7 +341,7 @@ static void rz_ssi_set_idle(struct rz_ssi_priv *ssi) =20 static int rz_ssi_start(struct rz_ssi_priv *ssi, struct rz_ssi_stream *str= m) { - bool is_play =3D rz_ssi_stream_is_play(strm->substream); + bool is_play =3D strm->substream->stream =3D=3D SNDRV_PCM_STREAM_PLAYBACK; bool is_full_duplex; u32 ssicr, ssifcr; =20 @@ -423,14 +420,6 @@ static int rz_ssi_stop(struct rz_ssi_priv *ssi, struct= rz_ssi_stream *strm) /* Disable TX/RX */ rz_ssi_reg_mask_setl(ssi, SSICR, SSICR_TEN | SSICR_REN, 0); =20 - /* Cancel all remaining DMA transactions */ - if (rz_ssi_is_dma_enabled(ssi)) { - if (ssi->playback.dma_ch) - dmaengine_terminate_async(ssi->playback.dma_ch); - if (ssi->capture.dma_ch) - dmaengine_terminate_async(ssi->capture.dma_ch); - } - rz_ssi_set_idle(ssi); =20 return 0; @@ -458,10 +447,6 @@ static void rz_ssi_pointer_update(struct rz_ssi_stream= *strm, int frames) snd_pcm_period_elapsed(strm->substream); strm->period_counter =3D current_period; } - - strm->completed_dma_buf_pos +=3D runtime->period_size; - if (strm->completed_dma_buf_pos >=3D runtime->buffer_size) - strm->completed_dma_buf_pos =3D 0; } =20 static int rz_ssi_pio_recv(struct rz_ssi_priv *ssi, struct rz_ssi_stream *= strm) @@ -606,12 +591,6 @@ static irqreturn_t rz_ssi_interrupt(int irq, void *dat= a) if (irq =3D=3D ssi->irq_int) { /* error or idle */ bool is_stopped =3D !!(ssisr & (SSISR_RUIRQ | SSISR_ROIRQ | SSISR_TUIRQ | SSISR_TOIRQ)); - int i, count; - - if (rz_ssi_is_dma_enabled(ssi)) - count =3D 4; - else - count =3D 1; =20 if (ssi->capture.substream && is_stopped) { if (ssisr & SSISR_RUIRQ) @@ -631,19 +610,41 @@ static irqreturn_t rz_ssi_interrupt(int irq, void *da= ta) rz_ssi_stop(ssi, strm_playback); } =20 + if (!rz_ssi_is_stream_running(&ssi->playback) && + !rz_ssi_is_stream_running(&ssi->capture) && + rz_ssi_is_dma_enabled(ssi) && is_stopped) { + if (ssi->playback.substream && + ssi->dmas[SNDRV_PCM_STREAM_PLAYBACK]) + dmaengine_pause(ssi->dmas[SNDRV_PCM_STREAM_PLAYBACK]); + if (ssi->capture.substream && + ssi->dmas[SNDRV_PCM_STREAM_CAPTURE] && + /* Avoid calling pause twice in case of half duplex. */ + ssi->dmas[SNDRV_PCM_STREAM_PLAYBACK] !=3D + ssi->dmas[SNDRV_PCM_STREAM_CAPTURE]) + dmaengine_pause(ssi->dmas[SNDRV_PCM_STREAM_CAPTURE]); + } + /* Clear all flags */ rz_ssi_reg_mask_setl(ssi, SSISR, SSISR_TOIRQ | SSISR_TUIRQ | SSISR_ROIRQ | SSISR_RUIRQ, 0); =20 /* Add/remove more data */ if (ssi->capture.substream && is_stopped) { - for (i =3D 0; i < count; i++) + if (rz_ssi_is_dma_enabled(ssi)) { + if (ssi->dmas[SNDRV_PCM_STREAM_CAPTURE]) + dmaengine_resume(ssi->dmas[SNDRV_PCM_STREAM_CAPTURE]); + } else { strm_capture->transfer(ssi, strm_capture); + } } =20 if (ssi->playback.substream && is_stopped) { - for (i =3D 0; i < count; i++) + if (rz_ssi_is_dma_enabled(ssi)) { + if (ssi->dmas[SNDRV_PCM_STREAM_PLAYBACK]) + dmaengine_resume(ssi->dmas[SNDRV_PCM_STREAM_PLAYBACK]); + } else { strm_playback->transfer(ssi, strm_playback); + } } =20 /* Resume */ @@ -679,153 +680,11 @@ static irqreturn_t rz_ssi_interrupt(int irq, void *d= ata) return IRQ_HANDLED; } =20 -static int rz_ssi_dma_slave_config(struct rz_ssi_priv *ssi, - struct dma_chan *dma_ch, bool is_play) -{ - struct dma_slave_config cfg; - - memset(&cfg, 0, sizeof(cfg)); - - cfg.direction =3D is_play ? DMA_MEM_TO_DEV : DMA_DEV_TO_MEM; - cfg.dst_addr =3D ssi->phys + SSIFTDR; - cfg.src_addr =3D ssi->phys + SSIFRDR; - if (ssi->hw_params_cache.sample_width =3D=3D 16) { - cfg.src_addr_width =3D DMA_SLAVE_BUSWIDTH_2_BYTES; - cfg.dst_addr_width =3D DMA_SLAVE_BUSWIDTH_2_BYTES; - } else { - cfg.src_addr_width =3D DMA_SLAVE_BUSWIDTH_4_BYTES; - cfg.dst_addr_width =3D DMA_SLAVE_BUSWIDTH_4_BYTES; - } - - return dmaengine_slave_config(dma_ch, &cfg); -} - -static int rz_ssi_dma_transfer(struct rz_ssi_priv *ssi, - struct rz_ssi_stream *strm) -{ - struct snd_pcm_substream *substream =3D strm->substream; - struct dma_async_tx_descriptor *desc; - struct snd_pcm_runtime *runtime; - enum dma_transfer_direction dir; - u32 dma_paddr, dma_size; - int amount; - - if (!rz_ssi_stream_is_valid(ssi, strm)) - return -EINVAL; - - runtime =3D substream->runtime; - if (runtime->state =3D=3D SNDRV_PCM_STATE_DRAINING) - /* - * Stream is ending, so do not queue up any more DMA - * transfers otherwise we play partial sound clips - * because we can't shut off the DMA quick enough. - */ - return 0; - - dir =3D rz_ssi_stream_is_play(substream) ? DMA_MEM_TO_DEV : DMA_DEV_TO_ME= M; - - /* Always transfer 1 period */ - amount =3D runtime->period_size; - - /* DMA physical address and size */ - dma_paddr =3D runtime->dma_addr + frames_to_bytes(runtime, - strm->dma_buffer_pos); - dma_size =3D frames_to_bytes(runtime, amount); - desc =3D dmaengine_prep_slave_single(strm->dma_ch, dma_paddr, dma_size, - dir, - DMA_PREP_INTERRUPT | DMA_CTRL_ACK); - if (!desc) { - dev_err(ssi->dev, "dmaengine_prep_slave_single() fail\n"); - return -ENOMEM; - } - - desc->callback =3D rz_ssi_dma_complete; - desc->callback_param =3D strm; - - if (dmaengine_submit(desc) < 0) { - dev_err(ssi->dev, "dmaengine_submit() fail\n"); - return -EIO; - } - - /* Update DMA pointer */ - strm->dma_buffer_pos +=3D amount; - if (strm->dma_buffer_pos >=3D runtime->buffer_size) - strm->dma_buffer_pos =3D 0; - - /* Start DMA */ - dma_async_issue_pending(strm->dma_ch); - - return 0; -} - -static void rz_ssi_dma_complete(void *data) -{ - struct rz_ssi_stream *strm =3D (struct rz_ssi_stream *)data; - - if (!strm->running || !strm->substream || !strm->substream->runtime) - return; - - /* Note that next DMA transaction has probably already started */ - rz_ssi_pointer_update(strm, strm->substream->runtime->period_size); - - /* Queue up another DMA transaction */ - rz_ssi_dma_transfer(strm->priv, strm); -} - -static void rz_ssi_release_dma_channels(struct rz_ssi_priv *ssi) -{ - if (ssi->playback.dma_ch) { - dma_release_channel(ssi->playback.dma_ch); - ssi->playback.dma_ch =3D NULL; - if (ssi->dma_rt) - ssi->dma_rt =3D false; - } - - if (ssi->capture.dma_ch) { - dma_release_channel(ssi->capture.dma_ch); - ssi->capture.dma_ch =3D NULL; - } -} - -static int rz_ssi_dma_request(struct rz_ssi_priv *ssi, struct device *dev) -{ - ssi->playback.dma_ch =3D dma_request_chan(dev, "tx"); - if (IS_ERR(ssi->playback.dma_ch)) - ssi->playback.dma_ch =3D NULL; - - ssi->capture.dma_ch =3D dma_request_chan(dev, "rx"); - if (IS_ERR(ssi->capture.dma_ch)) - ssi->capture.dma_ch =3D NULL; - - if (!ssi->playback.dma_ch && !ssi->capture.dma_ch) { - ssi->playback.dma_ch =3D dma_request_chan(dev, "rt"); - if (IS_ERR(ssi->playback.dma_ch)) { - ssi->playback.dma_ch =3D NULL; - goto no_dma; - } - - ssi->dma_rt =3D true; - } - - if (!rz_ssi_is_dma_enabled(ssi)) - goto no_dma; - - return 0; - -no_dma: - rz_ssi_release_dma_channels(ssi); - - return -ENODEV; -} - static int rz_ssi_trigger_resume(struct rz_ssi_priv *ssi, struct rz_ssi_st= ream *strm) { struct snd_pcm_substream *substream =3D strm->substream; - struct snd_pcm_runtime *runtime =3D substream->runtime; int ret; =20 - strm->dma_buffer_pos =3D strm->completed_dma_buf_pos + runtime->period_si= ze; - if (rz_ssi_is_stream_running(&ssi->playback) || rz_ssi_is_stream_running(&ssi->capture)) return 0; @@ -834,7 +693,7 @@ static int rz_ssi_trigger_resume(struct rz_ssi_priv *ss= i, struct rz_ssi_stream * if (ret) return ret; =20 - return rz_ssi_clk_setup(ssi, ssi->hw_params_cache.rate, + return rz_ssi_clk_setup(ssi, substream, ssi->hw_params_cache.rate, ssi->hw_params_cache.channels); } =20 @@ -843,7 +702,7 @@ static int rz_ssi_dai_trigger(struct snd_pcm_substream = *substream, int cmd, { struct rz_ssi_priv *ssi =3D snd_soc_dai_get_drvdata(dai); struct rz_ssi_stream *strm =3D rz_ssi_stream_get(ssi, substream); - int ret =3D 0, i, num_transfer =3D 1; + int ret =3D 0; =20 switch (cmd) { case SNDRV_PCM_TRIGGER_RESUME: @@ -858,28 +717,7 @@ static int rz_ssi_dai_trigger(struct snd_pcm_substream= *substream, int cmd, if (cmd =3D=3D SNDRV_PCM_TRIGGER_START) rz_ssi_stream_init(strm, substream); =20 - if (rz_ssi_is_dma_enabled(ssi)) { - bool is_playback =3D rz_ssi_stream_is_play(substream); - - if (ssi->dma_rt) - ret =3D rz_ssi_dma_slave_config(ssi, ssi->playback.dma_ch, - is_playback); - else - ret =3D rz_ssi_dma_slave_config(ssi, strm->dma_ch, - is_playback); - - /* Fallback to pio */ - if (ret < 0) { - ssi->playback.transfer =3D rz_ssi_pio_send; - ssi->capture.transfer =3D rz_ssi_pio_recv; - rz_ssi_release_dma_channels(ssi); - } else { - /* For DMA, queue up multiple DMA descriptors */ - num_transfer =3D 4; - } - } - - for (i =3D 0; i < num_transfer; i++) { + if (!rz_ssi_is_dma_enabled(ssi)) { ret =3D strm->transfer(ssi, strm); if (ret) return ret; @@ -975,6 +813,8 @@ static void rz_ssi_shutdown(struct snd_pcm_substream *s= ubstream, ssi->dup.tx_active =3D false; else ssi->dup.rx_active =3D false; + + ssi->dmas[substream->stream] =3D NULL; } =20 static bool rz_ssi_is_valid_hw_params(struct rz_ssi_priv *ssi, unsigned in= t rate, @@ -1026,6 +866,12 @@ static int rz_ssi_dai_hw_params(struct snd_pcm_substr= eam *substream, return -EINVAL; } =20 + /* Save the DMA channels for recovery. */ + if (rz_ssi_is_dma_enabled(ssi)) + ssi->dmas[substream->stream] =3D snd_dmaengine_pcm_get_chan(substream); + else + ssi->dmas[substream->stream] =3D NULL; + if (rz_ssi_is_stream_running(&ssi->playback) || rz_ssi_is_stream_running(&ssi->capture)) { if (rz_ssi_is_valid_hw_params(ssi, rate, channels, sample_width, sample_= bits)) @@ -1041,10 +887,21 @@ static int rz_ssi_dai_hw_params(struct snd_pcm_subst= ream *substream, if (ret) return ret; =20 - return rz_ssi_clk_setup(ssi, rate, channels); + return rz_ssi_clk_setup(ssi, substream, rate, channels); +} + +static int rz_ssi_dai_probe(struct snd_soc_dai *dai) +{ + struct rz_ssi_priv *ssi =3D snd_soc_dai_get_drvdata(dai); + + snd_soc_dai_init_dma_data(dai, &ssi->dma_dais[SNDRV_PCM_STREAM_PLAYBACK], + &ssi->dma_dais[SNDRV_PCM_STREAM_CAPTURE]); + + return 0; } =20 static const struct snd_soc_dai_ops rz_ssi_dai_ops =3D { + .probe =3D rz_ssi_dai_probe, .startup =3D rz_ssi_startup, .shutdown =3D rz_ssi_shutdown, .trigger =3D rz_ssi_dai_trigger, @@ -1058,9 +915,9 @@ static const struct snd_pcm_hardware rz_ssi_pcm_hardwa= re =3D { SNDRV_PCM_INFO_MMAP_VALID | SNDRV_PCM_INFO_RESUME | SNDRV_PCM_INFO_PAUSE, - .buffer_bytes_max =3D PREALLOC_BUFFER, + .buffer_bytes_max =3D 192 * 1024, .period_bytes_min =3D 32, - .period_bytes_max =3D 8192, + .period_bytes_max =3D 48 * 1024, .channels_min =3D SSI_CHAN_MIN, .channels_max =3D SSI_CHAN_MAX, .periods_min =3D 1, @@ -1068,8 +925,8 @@ static const struct snd_pcm_hardware rz_ssi_pcm_hardwa= re =3D { .fifo_size =3D 32 * 2, }; =20 -static int rz_ssi_pcm_open(struct snd_soc_component *component, - struct snd_pcm_substream *substream) +static int rz_ssi_pcm_open_pio(struct snd_soc_component *component, + struct snd_pcm_substream *substream) { snd_soc_set_runtime_hwparams(substream, &rz_ssi_pcm_hardware); =20 @@ -1077,6 +934,13 @@ static int rz_ssi_pcm_open(struct snd_soc_component *= component, SNDRV_PCM_HW_PARAM_PERIODS); } =20 +static int rz_ssi_pcm_open_dma(struct snd_soc_component *component, + struct snd_pcm_substream *substream) +{ + return snd_pcm_hw_constraint_integer(substream->runtime, + SNDRV_PCM_HW_PARAM_PERIODS); +} + static snd_pcm_uframes_t rz_ssi_pcm_pointer(struct snd_soc_component *comp= onent, struct snd_pcm_substream *substream) { @@ -1093,7 +957,8 @@ static int rz_ssi_pcm_new(struct snd_soc_component *co= mponent, { snd_pcm_set_managed_buffer_all(rtd->pcm, SNDRV_DMA_TYPE_DEV, rtd->card->snd_card->dev, - PREALLOC_BUFFER, PREALLOC_BUFFER_MAX); + rz_ssi_pcm_hardware.buffer_bytes_max, + rz_ssi_pcm_hardware.buffer_bytes_max); return 0; } =20 @@ -1116,16 +981,30 @@ static struct snd_soc_dai_driver rz_ssi_soc_dai[] = =3D { }, }; =20 -static const struct snd_soc_component_driver rz_ssi_soc_component =3D { +static const struct snd_soc_component_driver rz_ssi_soc_component_pio =3D { .name =3D "rz-ssi", - .open =3D rz_ssi_pcm_open, + .open =3D rz_ssi_pcm_open_pio, .pointer =3D rz_ssi_pcm_pointer, .pcm_new =3D rz_ssi_pcm_new, .legacy_dai_naming =3D 1, }; =20 +static const struct snd_soc_component_driver rz_ssi_soc_component_dma =3D { + .name =3D "rz-ssi", + .open =3D rz_ssi_pcm_open_dma, + .legacy_dai_naming =3D 1, +}; + +static const struct snd_dmaengine_pcm_config rz_ssi_dmaengine_pcm_conf =3D= { + .pcm_hardware =3D &rz_ssi_pcm_hardware, + .prealloc_buffer_size =3D 192 * 1024, + .prepare_slave_config =3D snd_dmaengine_pcm_prepare_slave_config, +}; + static int rz_ssi_probe(struct platform_device *pdev) { + const struct snd_soc_component_driver *component_driver; + struct device_node *np =3D pdev->dev.of_node; struct device *dev =3D &pdev->dev; struct rz_ssi_priv *ssi; struct clk *audio_clk; @@ -1141,7 +1020,6 @@ static int rz_ssi_probe(struct platform_device *pdev) if (IS_ERR(ssi->base)) return PTR_ERR(ssi->base); =20 - ssi->phys =3D res->start; ssi->clk =3D devm_clk_get(dev, "ssi"); if (IS_ERR(ssi->clk)) return PTR_ERR(ssi->clk); @@ -1165,16 +1043,43 @@ static int rz_ssi_probe(struct platform_device *pde= v) =20 ssi->audio_mck =3D ssi->audio_clk_1 ? ssi->audio_clk_1 : ssi->audio_clk_2; =20 - /* Detect DMA support */ - ret =3D rz_ssi_dma_request(ssi, dev); - if (ret < 0) { + ssi->dma_dais[SNDRV_PCM_STREAM_PLAYBACK].addr =3D (dma_addr_t)res->start = + SSIFTDR; + ssi->dma_dais[SNDRV_PCM_STREAM_CAPTURE].addr =3D (dma_addr_t)res->start = + SSIFRDR; + + if (of_property_present(np, "dma-names")) { + struct snd_dmaengine_pcm_config *config; + unsigned int flags =3D 0; + + config =3D devm_kzalloc(dev, sizeof(*config), GFP_KERNEL); + if (!config) + return -ENOMEM; + + config->pcm_hardware =3D rz_ssi_dmaengine_pcm_conf.pcm_hardware; + config->prealloc_buffer_size =3D rz_ssi_dmaengine_pcm_conf.prealloc_buff= er_size; + config->prepare_slave_config =3D rz_ssi_dmaengine_pcm_conf.prepare_slave= _config; + + if (of_property_match_string(np, "dma-names", "rt") =3D=3D 0) { + flags =3D SND_DMAENGINE_PCM_FLAG_HALF_DUPLEX; + config->chan_names[SNDRV_PCM_STREAM_PLAYBACK] =3D "rt"; + } else { + config->chan_names[SNDRV_PCM_STREAM_PLAYBACK] =3D "tx"; + config->chan_names[SNDRV_PCM_STREAM_CAPTURE] =3D "rx"; + } + ret =3D devm_snd_dmaengine_pcm_register(&pdev->dev, config, flags); + } else { + ret =3D -ENODEV; + } + + if (ret =3D=3D -EPROBE_DEFER) { + return ret; + } else if (ret) { dev_warn(dev, "DMA not available, using PIO\n"); ssi->playback.transfer =3D rz_ssi_pio_send; ssi->capture.transfer =3D rz_ssi_pio_recv; + component_driver =3D &rz_ssi_soc_component_pio; } else { - dev_info(dev, "DMA enabled"); - ssi->playback.transfer =3D rz_ssi_dma_transfer; - ssi->capture.transfer =3D rz_ssi_dma_transfer; + dev_info(dev, "DMA enabled\n"); + component_driver =3D &rz_ssi_soc_component_dma; } =20 ssi->playback.priv =3D ssi; @@ -1185,17 +1090,13 @@ static int rz_ssi_probe(struct platform_device *pde= v) =20 /* Error Interrupt */ ssi->irq_int =3D platform_get_irq_byname(pdev, "int_req"); - if (ssi->irq_int < 0) { - ret =3D ssi->irq_int; - goto err_release_dma_chs; - } + if (ssi->irq_int < 0) + return ssi->irq_int; =20 ret =3D devm_request_irq(dev, ssi->irq_int, rz_ssi_interrupt, 0, dev_name(dev), ssi); - if (ret < 0) { - dev_err_probe(dev, ret, "irq request error (int_req)\n"); - goto err_release_dma_chs; - } + if (ret < 0) + return dev_err_probe(dev, ret, "irq request error (int_req)\n"); =20 if (!rz_ssi_is_dma_enabled(ssi)) { /* Tx and Rx interrupts (pio only) */ @@ -1236,43 +1137,19 @@ static int rz_ssi_probe(struct platform_device *pde= v) } =20 ssi->rstc =3D devm_reset_control_get_exclusive(dev, NULL); - if (IS_ERR(ssi->rstc)) { - ret =3D PTR_ERR(ssi->rstc); - goto err_release_dma_chs; - } + if (IS_ERR(ssi->rstc)) + return dev_err_probe(dev, PTR_ERR(ssi->rstc), "Failed to get reset\n"); =20 /* Default 0 for power saving. Can be overridden via sysfs. */ pm_runtime_set_autosuspend_delay(dev, 0); pm_runtime_use_autosuspend(dev); ret =3D devm_pm_runtime_enable(dev); - if (ret < 0) { - dev_err(dev, "Failed to enable runtime PM!\n"); - goto err_release_dma_chs; - } - - ret =3D devm_snd_soc_register_component(dev, &rz_ssi_soc_component, - rz_ssi_soc_dai, - ARRAY_SIZE(rz_ssi_soc_dai)); - if (ret < 0) { - dev_err(dev, "failed to register snd component\n"); - goto err_release_dma_chs; - } - - return 0; - -err_release_dma_chs: - rz_ssi_release_dma_channels(ssi); - - return ret; -} - -static void rz_ssi_remove(struct platform_device *pdev) -{ - struct rz_ssi_priv *ssi =3D dev_get_drvdata(&pdev->dev); - - rz_ssi_release_dma_channels(ssi); + if (ret < 0) + return dev_err_probe(dev, ret, "Failed to enable runtime PM!\n"); =20 - reset_control_assert(ssi->rstc); + return devm_snd_soc_register_component(dev, component_driver, + rz_ssi_soc_dai, + ARRAY_SIZE(rz_ssi_soc_dai)); } =20 static const struct of_device_id rz_ssi_of_match[] =3D { @@ -1307,7 +1184,6 @@ static struct platform_driver rz_ssi_driver =3D { .pm =3D pm_ptr(&rz_ssi_pm_ops), }, .probe =3D rz_ssi_probe, - .remove =3D rz_ssi_remove, }; =20 module_platform_driver(rz_ssi_driver); --=20 2.43.0 From nobody Mon Jun 8 21:46:47 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EBE963CF68E; Tue, 26 May 2026 08:48:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779785333; cv=none; b=XgV45UehsImvTi5RftHCdBOs95dLSc4tXJV5HlzkSsfiGzIpXM/ccb+smaeTS6pGMr62IaljT+4gKOdJqJUInyMkD5qMwWERGWmUXiN/2BudPhRPzSbOCDasL4Xo2N7o3z4QRvHzLEm9pVo4s+M0RX1Z8O4MB9RznLniZNKF1DA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779785333; c=relaxed/simple; bh=yvgeFKF1lxj68nJj1F02veizJ6oL6zjIexlKwl/89nE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=FRDbiS/GqY3XwRbe9PVl9Yg6YffDHDbeEqQS4Vci7ghAy3RMr78LKxDBXb8BLbaOfk4RwuEu3aQAujXWG9YaHiPT7OP4pRZR4VwJs4T8c51OsvthgTgrBKdlkJN/NZlUEb0iwv+aQUiMz4WXt9hZ15+NQXutIbchsd/sXX6R5O0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=FlIcJAhB; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="FlIcJAhB" Received: by smtp.kernel.org (Postfix) with ESMTPSA id DA04D1F00A3A; Tue, 26 May 2026 08:48:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1779785331; bh=ZkizuxwMrkjBcE6tO2uEvys7AHOh8iY86fCmxYrdhW4=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=FlIcJAhB4+HPCjoi2v1/DWzFXkx5SwED2Rosdo3T5qVCvOlBmD9PDmZTBLAJleYtv nJPOYWcfQ1wux0m68qnLrPHCTSqIsE2uI197krmPc2bQzxjCrPIDzUk7tJz5F8ZbTh pEQDgdigmKI/WMg2RuG/wPgWakGjhvT/ST6cQbSsJwzkb+jxglAgNpcsAv7PN0FyjW Yp6OFrsolUQRB5A5uT9wMxJnGBIdH6fVBuNsS4SsI3DisO7xyqU8OxCjzAw52prUNk m4KqkOSEZ1Cgrh2tDUUUA4h4wnHf5E3q+OVYbI9f1H+RXj+VPW2aKyHyZT9iZLTBtO BKiw8EAI4OS/g== From: Claudiu Beznea To: vkoul@kernel.org, Frank.Li@kernel.org, lgirdwood@gmail.com, broonie@kernel.org, perex@perex.cz, tiwai@suse.com, biju.das.jz@bp.renesas.com, prabhakar.mahadev-lad.rj@bp.renesas.com, p.zabel@pengutronix.de, geert+renesas@glider.be, kuninori.morimoto.gx@renesas.com, long.luu.ur@renesas.com Cc: claudiu.beznea@kernel.org, claudiu.beznea@tuxon.dev, dmaengine@vger.kernel.org, linux-kernel@vger.kernel.org, linux-sound@vger.kernel.org, linux-renesas-soc@vger.kernel.org, Claudiu Beznea , John Madieu Subject: [PATCH v6 18/18] dmaengine: sh: rz-dmac: Set the Link End (LE) bit on the last descriptor Date: Tue, 26 May 2026 11:47:10 +0300 Message-ID: <20260526084710.3491480-19-claudiu.beznea@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260526084710.3491480-1-claudiu.beznea@kernel.org> References: <20260526084710.3491480-1-claudiu.beznea@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Claudiu Beznea On an RZ/G2L-based system, it has been observed that when the DMA channels for all enabled IPs are active (TX and RX for one serial IP, TX and RX for one audio IP, and TX and RX for one SPI IP), shortly after all of them are started, the system can become irrecoverably blocked. In one debug session the system did not block, and the DMA HW registers were inspected. It was found that the DER (Descriptor Error) bit in the CHSTAT register for one of the SPI DMA channels was set. According to the RZ/G2L HW Manual, Rev. 1.30, chapter 14.4.7 Channel Status Register n/nS (CHSTAT_n/nS), description of the DER bit, the DER bit is set when the LV (Link Valid) value loaded with a descriptor in link mode is 0. This means that the DMA engine has loaded an invalid descriptor (as defined in Table 14.14, Header Area, of the same manual). The same chapter states that when a descriptor error occurs, the transfer is stopped, but no DMA error interrupt is generated. Set the LE bit on the last descriptor of a transfer. This informs the DMA engine that this is the final descriptor for the transfer. Tested-by: John Madieu Signed-off-by: Claudiu Beznea Tested-by: Tommaso Merciai --- Changes in v6: - collected tags Changes in v5: - none Changes in v4: - none Changes in v3: - none Changes in v2: - none drivers/dma/sh/rz-dmac.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/dma/sh/rz-dmac.c b/drivers/dma/sh/rz-dmac.c index 2a7124e4aea3..f1174d25da84 100644 --- a/drivers/dma/sh/rz-dmac.c +++ b/drivers/dma/sh/rz-dmac.c @@ -200,6 +200,7 @@ struct rz_dmac { =20 /* LINK MODE DESCRIPTOR */ #define HEADER_LV BIT(0) +#define HEADER_LE BIT(1) #define HEADER_WBD BIT(2) =20 #define RZ_DMAC_MAX_CHAN_DESCRIPTORS 16 @@ -382,7 +383,7 @@ static void rz_dmac_prepare_desc_for_memcpy(struct rz_d= mac_chan *channel) lmdesc->chcfg =3D chcfg; lmdesc->chitvl =3D 0; lmdesc->chext =3D 0; - lmdesc->header =3D HEADER_LV; + lmdesc->header =3D HEADER_LV | HEADER_LE; =20 rz_dmac_set_dma_req_no(dmac, channel->index, dmac->info->default_dma_req_= no); =20 @@ -425,7 +426,7 @@ static void rz_dmac_prepare_descs_for_slave_sg(struct r= z_dmac_chan *channel) lmdesc->chext =3D 0; if (i =3D=3D (sg_len - 1)) { lmdesc->chcfg =3D (channel->chcfg & ~CHCFG_DEM); - lmdesc->header =3D HEADER_LV; + lmdesc->header =3D HEADER_LV | HEADER_LE; } else { lmdesc->chcfg =3D channel->chcfg; lmdesc->header =3D HEADER_LV; --=20 2.43.0