* [PATCH 6.1.y-cip 00/27] Renesas: Backport DMA fixes and improvements
@ 2026-11-26 15:47 Tommaso Merciai
2026-11-26 15:47 ` [PATCH 6.1.y-cip 01/27] dmaengine: sh: rz-dmac: Convert to platform remove callback returning void Tommaso Merciai
` (28 more replies)
0 siblings, 29 replies; 30+ messages in thread
From: Tommaso Merciai @ 2026-11-26 15:47 UTC (permalink / raw)
To: cip-dev, Nobuhiro Iwamatsu, Pavel Machek
Cc: Biju Das, Lad Prabhakar, tomm.merciai
Hi,
This series backports cyclic DMA, runtime PM and suspend to RAM
along with preparatory and cleanup patches into linux-6.1.y-cip.
This is the equivalent work done for linux-5.10.y-cip kernel [1].
[1] https://lore.kernel.org/cip-dev/20261126152204.1297798-1-claudiu.beznea@tuxon.dev/T/#t
Thanks,
Tommaso
Biju Das (1):
dmaengine: sh: rz-dmac: Add device_tx_status() callback
Claudiu Beznea (19):
dmaengine: sh: rz-dmac: Drop read of CHCTRL register
dmaengine: sh: rz-dmac: Drop goto instruction and label
dmaengine: sh: rz-dmac: Drop unnecessary local_irq_save() call
dmaengine: sh: rz-dmac: Add device_{pause,resume}() callbacks
dmaengine: sh: rz-dmac: Fix incorrect NULL check for
list_first_entry()
dmaengine: sh: rz-dmac: Use list_first_entry_or_null()
dmaengine: sh: rz-dmac: Use rz_dmac_disable_hw()
dmaengine: sh: rz-dmac: Add helper to compute the lmdesc address
dmaengine: sh: rz-dmac: Save the start LM descriptor
dmaengine: sh: rz-dmac: Add helper to check if the channel is enabled
dmaengine: sh: rz-dmac: Add helper to check if the channel is paused
dmaengine: sh: rz-dmac: Use virt-dma APIs for channel descriptor
processing
dmaengine: sh: rz-dmac: Refactor pause/resume code
dmaengine: sh: rz-dmac: Drop the update of channel->chctrl with
CHCTRL_SETEN
dmaengine: sh: rz-dmac: Add cyclic DMA support
dmaengine: sh: rz-dmac: Adjust rz_dmac_chan_get_residue() to return
error codes
dmaengine: sh: rz-dmac: Add runtime PM support
dmaengine: sh: rz-dmac: Add suspend to RAM support
dmaengine: sh: rz-dmac: Set the Link End (LE) bit on the last
descriptor
Cosmin Tanislav (2):
dmaengine: sh: rz_dmac: make error interrupt optional
dmaengine: sh: rz_dmac: make register_dma_req() chip-specific
Geert Uytterhoeven (1):
dmaengine: sh: rz-dmac: Make channel irq local
John Madieu (1):
dmaengine: sh: rz-dmac: Use rz_lmdesc_setup() to invalidate
descriptors
Lad Prabhakar (1):
dmaengine: sh: rz-dmac: Avoid format-overflow warning
Tommaso Merciai (1):
dmaengine: sh: rz-dmac: Fix off-by-one in residue lmdesc lookup
Uwe Kleine-König (1):
dmaengine: sh: rz-dmac: Convert to platform remove callback returning
void
drivers/dma/sh/rz-dmac.c | 906 +++++++++++++++++++++++++++++++--------
1 file changed, 730 insertions(+), 176 deletions(-)
--
2.54.0
^ permalink raw reply [flat|nested] 30+ messages in thread
* [PATCH 6.1.y-cip 01/27] dmaengine: sh: rz-dmac: Convert to platform remove callback returning void
2026-11-26 15:47 [PATCH 6.1.y-cip 00/27] Renesas: Backport DMA fixes and improvements Tommaso Merciai
@ 2026-11-26 15:47 ` Tommaso Merciai
2026-11-26 15:47 ` [PATCH 6.1.y-cip 02/27] dmaengine: sh: rz-dmac: Avoid format-overflow warning Tommaso Merciai
` (27 subsequent siblings)
28 siblings, 0 replies; 30+ messages in thread
From: Tommaso Merciai @ 2026-11-26 15:47 UTC (permalink / raw)
To: cip-dev, Nobuhiro Iwamatsu, Pavel Machek
Cc: Biju Das, Lad Prabhakar, tomm.merciai
From: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
commit bd4205f52310a158c78171d3a5f68c7301a532fd upstream.
The .remove() callback for a platform driver returns an int which makes
many driver authors wrongly assume it's possible to do error handling by
returning an error code. However the value returned is ignored (apart
from emitting a warning) and this typically results in resource leaks.
To improve here there is a quest to make the remove callback return
void. In the first step of this quest all drivers are converted to
.remove_new() which already returns void. Eventually after all drivers
are converted, .remove_new() is renamed to .remove().
Trivially convert this driver from always returning zero in the remove
callback to the void returning variant.
Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be>
Link: https://lore.kernel.org/r/20230919133207.1400430-41-u.kleine-koenig@pengutronix.de
Signed-off-by: Vinod Koul <vkoul@kernel.org>
[tm: Local rz_dmac_remove() already ends with
platform_device_put(dmac->icu.pdev) for RZ/V2H(P) support (282d5dfb9147),
which upstream doesn't have at this commit. Dropped the return 0; after
that call instead of right after pm_runtime_disable() as in upstream's
hunk, keeping the ICU cleanup intact while still converting to
.remove_new().]
Signed-off-by: Tommaso Merciai <tommaso.merciai.xr@bp.renesas.com>
---
drivers/dma/sh/rz-dmac.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/drivers/dma/sh/rz-dmac.c b/drivers/dma/sh/rz-dmac.c
index da566fe13c3a..aec3abf49185 100644
--- a/drivers/dma/sh/rz-dmac.c
+++ b/drivers/dma/sh/rz-dmac.c
@@ -1048,7 +1048,7 @@ static int rz_dmac_probe(struct platform_device *pdev)
return ret;
}
-static int rz_dmac_remove(struct platform_device *pdev)
+static void rz_dmac_remove(struct platform_device *pdev)
{
struct rz_dmac *dmac = platform_get_drvdata(pdev);
@@ -1057,8 +1057,6 @@ static int rz_dmac_remove(struct platform_device *pdev)
reset_control_assert(dmac->rstc);
pm_runtime_put(&pdev->dev);
pm_runtime_disable(&pdev->dev);
-
- return 0;
}
static const struct of_device_id of_rz_dmac_match[] = {
@@ -1074,7 +1072,7 @@ static struct platform_driver rz_dmac_driver = {
.of_match_table = of_rz_dmac_match,
},
.probe = rz_dmac_probe,
- .remove = rz_dmac_remove,
+ .remove_new = rz_dmac_remove,
};
module_platform_driver(rz_dmac_driver);
--
2.54.0
^ permalink raw reply related [flat|nested] 30+ messages in thread
* [PATCH 6.1.y-cip 02/27] dmaengine: sh: rz-dmac: Avoid format-overflow warning
2026-11-26 15:47 [PATCH 6.1.y-cip 00/27] Renesas: Backport DMA fixes and improvements Tommaso Merciai
2026-11-26 15:47 ` [PATCH 6.1.y-cip 01/27] dmaengine: sh: rz-dmac: Convert to platform remove callback returning void Tommaso Merciai
@ 2026-11-26 15:47 ` Tommaso Merciai
2026-11-26 15:47 ` [PATCH 6.1.y-cip 03/27] dmaengine: sh: rz-dmac: Make channel irq local Tommaso Merciai
` (26 subsequent siblings)
28 siblings, 0 replies; 30+ messages in thread
From: Tommaso Merciai @ 2026-11-26 15:47 UTC (permalink / raw)
To: cip-dev, Nobuhiro Iwamatsu, Pavel Machek
Cc: Biju Das, Lad Prabhakar, tomm.merciai
From: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>
commit c4d6dcb3b6250ea546a952ad33382daf7cd32425 upstream.
The max channel count for RZ DMAC is 16, hence use u8 instead of unsigned
int and make the pdev_irqname string long enough to avoid the warning.
This fixes the below issue:
drivers/dma/sh/rz-dmac.c: In function ‘rz_dmac_probe’:
drivers/dma/sh/rz-dmac.c:770:34: warning: ‘%u’ directive writing between 1 and 10 bytes into a region of size 3 [-Wformat-overflow=]
770 | sprintf(pdev_irqname, "ch%u", index);
| ^~
In function ‘rz_dmac_chan_probe’,
inlined from ‘rz_dmac_probe’ at drivers/dma/sh/rz-dmac.c:910:9:
drivers/dma/sh/rz-dmac.c:770:31: note: directive argument in the range [0, 4294967294]
770 | sprintf(pdev_irqname, "ch%u", index);
| ^~~~~~
drivers/dma/sh/rz-dmac.c:770:9: note: ‘sprintf’ output between 4 and 13 bytes into a destination of size 5
770 | sprintf(pdev_irqname, "ch%u", index);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
While at it use scnprintf() instead of sprintf() to make the code
more robust.
Signed-off-by: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>
Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be>
Link: https://lore.kernel.org/r/20240110222717.193719-1-prabhakar.mahadev-lad.rj@bp.renesas.com
Signed-off-by: Vinod Koul <vkoul@kernel.org>
Signed-off-by: Tommaso Merciai <tommaso.merciai.xr@bp.renesas.com>
---
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 aec3abf49185..8bde48cce20a 100644
--- a/drivers/dma/sh/rz-dmac.c
+++ b/drivers/dma/sh/rz-dmac.c
@@ -800,11 +800,11 @@ static struct dma_chan *rz_dmac_of_xlate(struct of_phandle_args *dma_spec,
static int rz_dmac_chan_probe(struct rz_dmac *dmac,
struct rz_dmac_chan *channel,
- unsigned int index)
+ u8 index)
{
struct platform_device *pdev = to_platform_device(dmac->dev);
struct rz_lmdesc *lmdesc;
- char pdev_irqname[5];
+ char pdev_irqname[6];
char *irqname;
int ret;
@@ -842,7 +842,7 @@ static int rz_dmac_chan_probe(struct rz_dmac *dmac,
INIT_LIST_HEAD(&channel->ld_active);
/* Request the channel interrupt. */
- sprintf(pdev_irqname, "ch%u", index);
+ scnprintf(pdev_irqname, sizeof(pdev_irqname), "ch%u", index);
channel->irq = platform_get_irq_byname(pdev, pdev_irqname);
if (channel->irq < 0)
return channel->irq;
@@ -930,9 +930,9 @@ static int rz_dmac_probe(struct platform_device *pdev)
const char *irqname = "error";
struct dma_device *engine;
struct rz_dmac *dmac;
- unsigned int i;
int ret;
int irq;
+ u8 i;
dmac = devm_kzalloc(&pdev->dev, sizeof(*dmac), GFP_KERNEL);
if (!dmac)
--
2.54.0
^ permalink raw reply related [flat|nested] 30+ messages in thread
* [PATCH 6.1.y-cip 03/27] dmaengine: sh: rz-dmac: Make channel irq local
2026-11-26 15:47 [PATCH 6.1.y-cip 00/27] Renesas: Backport DMA fixes and improvements Tommaso Merciai
2026-11-26 15:47 ` [PATCH 6.1.y-cip 01/27] dmaengine: sh: rz-dmac: Convert to platform remove callback returning void Tommaso Merciai
2026-11-26 15:47 ` [PATCH 6.1.y-cip 02/27] dmaengine: sh: rz-dmac: Avoid format-overflow warning Tommaso Merciai
@ 2026-11-26 15:47 ` Tommaso Merciai
2026-11-26 15:47 ` [PATCH 6.1.y-cip 04/27] dmaengine: sh: rz_dmac: make error interrupt optional Tommaso Merciai
` (25 subsequent siblings)
28 siblings, 0 replies; 30+ messages in thread
From: Tommaso Merciai @ 2026-11-26 15:47 UTC (permalink / raw)
To: cip-dev, Nobuhiro Iwamatsu, Pavel Machek
Cc: Biju Das, Lad Prabhakar, tomm.merciai
From: Geert Uytterhoeven <geert+renesas@glider.be>
commit e0c51fd02f9cfab341907f6764d2f15c134eea55 upstream.
The channel IRQ is only used inside the function rz_dmac_chan_probe(),
so there is no need to store it in the rz_dmac_chan structure for later
use.
Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
Reviewed-by: Biju Das <biju.das.jz@bp.renesas.com>
Link: https://patch.msgid.link/312c2e3349f4747e0bca861632bfc3592224b012.1767718556.git.geert+renesas@glider.be
Signed-off-by: Vinod Koul <vkoul@kernel.org>
[tm: channel->irq is now stored in the local variable irq at the end
of the function instead of at the beginning, since commit ("dmaengine:
sh: rz-dmac: Move interrupt request after everything is set up")
already moved the IRQ request there.]
Signed-off-by: Tommaso Merciai <tommaso.merciai.xr@bp.renesas.com>
---
drivers/dma/sh/rz-dmac.c | 15 ++++++---------
1 file changed, 6 insertions(+), 9 deletions(-)
diff --git a/drivers/dma/sh/rz-dmac.c b/drivers/dma/sh/rz-dmac.c
index 8bde48cce20a..cac91e45805d 100644
--- a/drivers/dma/sh/rz-dmac.c
+++ b/drivers/dma/sh/rz-dmac.c
@@ -66,7 +66,6 @@ struct rz_dmac_chan {
void __iomem *ch_base;
void __iomem *ch_cmn_base;
unsigned int index;
- int irq;
struct rz_dmac_desc *desc;
int descs_allocated;
@@ -806,7 +805,7 @@ static int rz_dmac_chan_probe(struct rz_dmac *dmac,
struct rz_lmdesc *lmdesc;
char pdev_irqname[6];
char *irqname;
- int ret;
+ int irq, ret;
channel->index = index;
channel->mid_rid = -EINVAL;
@@ -843,22 +842,20 @@ static int rz_dmac_chan_probe(struct rz_dmac *dmac,
/* Request the channel interrupt. */
scnprintf(pdev_irqname, sizeof(pdev_irqname), "ch%u", index);
- channel->irq = platform_get_irq_byname(pdev, pdev_irqname);
- if (channel->irq < 0)
- return channel->irq;
+ irq = platform_get_irq_byname(pdev, pdev_irqname);
+ if (irq < 0)
+ return irq;
irqname = devm_kasprintf(dmac->dev, GFP_KERNEL, "%s:%u",
dev_name(dmac->dev), index);
if (!irqname)
return -ENOMEM;
- ret = devm_request_threaded_irq(dmac->dev, channel->irq,
- rz_dmac_irq_handler,
+ ret = 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",
- channel->irq, ret);
+ dev_err(dmac->dev, "failed to request IRQ %u (%d)\n", irq, ret);
return ret;
}
--
2.54.0
^ permalink raw reply related [flat|nested] 30+ messages in thread
* [PATCH 6.1.y-cip 04/27] dmaengine: sh: rz_dmac: make error interrupt optional
2026-11-26 15:47 [PATCH 6.1.y-cip 00/27] Renesas: Backport DMA fixes and improvements Tommaso Merciai
` (2 preceding siblings ...)
2026-11-26 15:47 ` [PATCH 6.1.y-cip 03/27] dmaengine: sh: rz-dmac: Make channel irq local Tommaso Merciai
@ 2026-11-26 15:47 ` Tommaso Merciai
2026-11-26 15:47 ` [PATCH 6.1.y-cip 05/27] dmaengine: sh: rz_dmac: make register_dma_req() chip-specific Tommaso Merciai
` (24 subsequent siblings)
28 siblings, 0 replies; 30+ messages in thread
From: Tommaso Merciai @ 2026-11-26 15:47 UTC (permalink / raw)
To: cip-dev, Nobuhiro Iwamatsu, Pavel Machek
Cc: Biju Das, Lad Prabhakar, tomm.merciai
From: Cosmin Tanislav <cosmin-gabriel.tanislav.xa@renesas.com>
commit b34f3fcae72a0afdd1a966fd68309b461bf678e6 upstream.
The Renesas RZ/T2H (R9A09G077) and RZ/N2H (R9A09G087) SoCs do not have
an error interrupt for the DMACs, and the current driver implementation
does not make much use of it.
To prepare for adding support for these SoCs, do not error out if the
error interrupt is missing.
Signed-off-by: Cosmin Tanislav <cosmin-gabriel.tanislav.xa@renesas.com>
Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be>
Link: https://patch.msgid.link/20260105114445.878262-2-cosmin-gabriel.tanislav.xa@renesas.com
Signed-off-by: Vinod Koul <vkoul@kernel.org>
[tm: goto err instead of return, since ("dmaengine: sh: rz-dmac: Move
interrupt request after everything is set up") already moved this block
past the err: label.]
Signed-off-by: Tommaso Merciai <tommaso.merciai.xr@bp.renesas.com>
---
drivers/dma/sh/rz-dmac.c | 21 +++++++++------------
1 file changed, 9 insertions(+), 12 deletions(-)
diff --git a/drivers/dma/sh/rz-dmac.c b/drivers/dma/sh/rz-dmac.c
index cac91e45805d..6f8f109b8294 100644
--- a/drivers/dma/sh/rz-dmac.c
+++ b/drivers/dma/sh/rz-dmac.c
@@ -984,18 +984,15 @@ static int rz_dmac_probe(struct platform_device *pdev)
}
/* Register interrupt handler for error */
- irq = platform_get_irq_byname(pdev, irqname);
- if (irq < 0) {
- ret = irq;
- goto err;
- }
-
- ret = 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;
+ irq = platform_get_irq_byname_optional(pdev, irqname);
+ if (irq > 0) {
+ ret = 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. */
--
2.54.0
^ permalink raw reply related [flat|nested] 30+ messages in thread
* [PATCH 6.1.y-cip 05/27] dmaengine: sh: rz_dmac: make register_dma_req() chip-specific
2026-11-26 15:47 [PATCH 6.1.y-cip 00/27] Renesas: Backport DMA fixes and improvements Tommaso Merciai
` (3 preceding siblings ...)
2026-11-26 15:47 ` [PATCH 6.1.y-cip 04/27] dmaengine: sh: rz_dmac: make error interrupt optional Tommaso Merciai
@ 2026-11-26 15:47 ` Tommaso Merciai
2026-11-26 15:47 ` [PATCH 6.1.y-cip 06/27] dmaengine: sh: rz-dmac: Drop read of CHCTRL register Tommaso Merciai
` (23 subsequent siblings)
28 siblings, 0 replies; 30+ messages in thread
From: Tommaso Merciai @ 2026-11-26 15:47 UTC (permalink / raw)
To: cip-dev, Nobuhiro Iwamatsu, Pavel Machek
Cc: Biju Das, Lad Prabhakar, tomm.merciai
From: Cosmin Tanislav <cosmin-gabriel.tanislav.xa@renesas.com>
commit bbb8b402d798f9f211376cee3d649d64dfc17880 upstream.
The Renesas RZ/T2H (R9A09G077) and RZ/N2H (R9A09G087) SoCs use a
completely different ICU unit compared to RZ/V2H, which requires a
separate implementation.
To prepare for adding support for these SoCs, add a chip-specific
structure and put a pointer to the rzv2h_icu_register_dma_req() function
in the .register_dma_req field of the chip-specific structure to allow
for other implementations. Do the same for the default request value,
RZV2H_ICU_DMAC_REQ_NO_DEFAULT, and place it into .dma_req_no_default.
While at it, factor out the logic that calls .register_dma_req() or
rz_dmac_set_dmars_register() into a separate function to remove some
code duplication.
Signed-off-by: Cosmin Tanislav <cosmin-gabriel.tanislav.xa@renesas.com>
Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be>
Link: https://patch.msgid.link/20260105114445.878262-3-cosmin-gabriel.tanislav.xa@renesas.com
Signed-off-by: Vinod Koul <vkoul@kernel.org>
Signed-off-by: Tommaso Merciai <tommaso.merciai.xr@bp.renesas.com>
---
drivers/dma/sh/rz-dmac.c | 65 ++++++++++++++++++++++------------------
1 file changed, 36 insertions(+), 29 deletions(-)
diff --git a/drivers/dma/sh/rz-dmac.c b/drivers/dma/sh/rz-dmac.c
index 6f8f109b8294..dd24908bb2d8 100644
--- a/drivers/dma/sh/rz-dmac.c
+++ b/drivers/dma/sh/rz-dmac.c
@@ -95,9 +95,16 @@ struct rz_dmac_icu {
u8 dmac_index;
};
+struct rz_dmac_info {
+ void (*icu_register_dma_req)(struct platform_device *icu_dev,
+ u8 dmac_index, u8 dmac_channel, u16 req_no);
+ u16 default_dma_req_no;
+};
+
struct rz_dmac {
struct dma_device engine;
struct rz_dmac_icu icu;
+ const struct rz_dmac_info *info;
struct device *dev;
struct reset_control *rstc;
void __iomem *base;
@@ -106,8 +113,6 @@ struct rz_dmac {
unsigned int n_channels;
struct rz_dmac_chan *channels;
- bool has_icu;
-
DECLARE_BITMAP(modules, 1024);
};
@@ -316,6 +321,16 @@ static void rz_dmac_set_dmars_register(struct rz_dmac *dmac, int nr, u32 dmars)
rz_dmac_ext_writel(dmac, dmars32, dmars_offset);
}
+static void rz_dmac_set_dma_req_no(struct rz_dmac *dmac, unsigned int index,
+ int req_no)
+{
+ if (dmac->info->icu_register_dma_req)
+ dmac->info->icu_register_dma_req(dmac->icu.pdev, dmac->icu.dmac_index,
+ index, req_no);
+ else
+ rz_dmac_set_dmars_register(dmac, index, req_no);
+}
+
static void rz_dmac_prepare_desc_for_memcpy(struct rz_dmac_chan *channel)
{
struct dma_chan *chan = &channel->vc.chan;
@@ -333,13 +348,7 @@ static void rz_dmac_prepare_desc_for_memcpy(struct rz_dmac_chan *channel)
lmdesc->chext = 0;
lmdesc->header = HEADER_LV;
- if (dmac->has_icu) {
- rzv2h_icu_register_dma_req(dmac->icu.pdev, dmac->icu.dmac_index,
- channel->index,
- RZV2H_ICU_DMAC_REQ_NO_DEFAULT);
- } else {
- rz_dmac_set_dmars_register(dmac, channel->index, 0);
- }
+ rz_dmac_set_dma_req_no(dmac, channel->index, dmac->info->default_dma_req_no);
channel->chcfg = chcfg;
channel->chctrl = CHCTRL_STG | CHCTRL_SETEN;
@@ -390,12 +399,7 @@ static void rz_dmac_prepare_descs_for_slave_sg(struct rz_dmac_chan *channel)
channel->lmdesc.tail = lmdesc;
- if (dmac->has_icu) {
- rzv2h_icu_register_dma_req(dmac->icu.pdev, dmac->icu.dmac_index,
- channel->index, channel->mid_rid);
- } else {
- rz_dmac_set_dmars_register(dmac, channel->index, channel->mid_rid);
- }
+ rz_dmac_set_dma_req_no(dmac, channel->index, channel->mid_rid);
channel->chctrl = CHCTRL_SETEN;
}
@@ -679,13 +683,7 @@ static void rz_dmac_device_synchronize(struct dma_chan *chan)
if (ret < 0)
dev_warn(dmac->dev, "DMA Timeout");
- if (dmac->has_icu) {
- rzv2h_icu_register_dma_req(dmac->icu.pdev, dmac->icu.dmac_index,
- channel->index,
- RZV2H_ICU_DMAC_REQ_NO_DEFAULT);
- } else {
- rz_dmac_set_dmars_register(dmac, channel->index, 0);
- }
+ rz_dmac_set_dma_req_no(dmac, channel->index, dmac->info->default_dma_req_no);
}
/*
@@ -874,14 +872,13 @@ static int rz_dmac_parse_of_icu(struct device *dev, struct rz_dmac *dmac)
uint32_t dmac_index;
int ret;
- ret = of_parse_phandle_with_fixed_args(np, "renesas,icu", 1, 0, &args);
- if (ret == -ENOENT)
+ if (!dmac->info->icu_register_dma_req)
return 0;
+
+ ret = of_parse_phandle_with_fixed_args(np, "renesas,icu", 1, 0, &args);
if (ret)
return ret;
- dmac->has_icu = true;
-
dmac->icu.pdev = of_find_device_by_node(args.np);
of_node_put(args.np);
if (!dmac->icu.pdev) {
@@ -935,6 +932,7 @@ static int rz_dmac_probe(struct platform_device *pdev)
if (!dmac)
return -ENOMEM;
+ dmac->info = device_get_match_data(&pdev->dev);
dmac->dev = &pdev->dev;
platform_set_drvdata(pdev, dmac);
@@ -952,7 +950,7 @@ static int rz_dmac_probe(struct platform_device *pdev)
if (IS_ERR(dmac->base))
return PTR_ERR(dmac->base);
- if (!dmac->has_icu) {
+ if (!dmac->info->icu_register_dma_req) {
dmac->ext_base = devm_platform_ioremap_resource(pdev, 1);
if (IS_ERR(dmac->ext_base))
return PTR_ERR(dmac->ext_base);
@@ -1053,9 +1051,18 @@ static void rz_dmac_remove(struct platform_device *pdev)
pm_runtime_disable(&pdev->dev);
}
+static const struct rz_dmac_info rz_dmac_v2h_info = {
+ .icu_register_dma_req = rzv2h_icu_register_dma_req,
+ .default_dma_req_no = RZV2H_ICU_DMAC_REQ_NO_DEFAULT,
+};
+
+static const struct rz_dmac_info rz_dmac_generic_info = {
+ .default_dma_req_no = 0,
+};
+
static const struct of_device_id of_rz_dmac_match[] = {
- { .compatible = "renesas,r9a09g057-dmac", },
- { .compatible = "renesas,rz-dmac", },
+ { .compatible = "renesas,r9a09g057-dmac", .data = &rz_dmac_v2h_info },
+ { .compatible = "renesas,rz-dmac", .data = &rz_dmac_generic_info },
{ /* Sentinel */ }
};
MODULE_DEVICE_TABLE(of, of_rz_dmac_match);
--
2.54.0
^ permalink raw reply related [flat|nested] 30+ messages in thread
* [PATCH 6.1.y-cip 06/27] dmaengine: sh: rz-dmac: Drop read of CHCTRL register
2026-11-26 15:47 [PATCH 6.1.y-cip 00/27] Renesas: Backport DMA fixes and improvements Tommaso Merciai
` (4 preceding siblings ...)
2026-11-26 15:47 ` [PATCH 6.1.y-cip 05/27] dmaengine: sh: rz_dmac: make register_dma_req() chip-specific Tommaso Merciai
@ 2026-11-26 15:47 ` Tommaso Merciai
2026-11-26 15:47 ` [PATCH 6.1.y-cip 07/27] dmaengine: sh: rz-dmac: Drop goto instruction and label Tommaso Merciai
` (22 subsequent siblings)
28 siblings, 0 replies; 30+ messages in thread
From: Tommaso Merciai @ 2026-11-26 15:47 UTC (permalink / raw)
To: cip-dev, Nobuhiro Iwamatsu, Pavel Machek
Cc: Biju Das, Lad Prabhakar, tomm.merciai
From: Claudiu Beznea <claudiu.beznea@tuxon.dev>
commit be342fb7f2bb5f641419fef3109eaffd469b0d44 upstream.
The CHCTRL register has 11 bits that can be updated by software. The
documentation for all these bits states the following:
- A read operation results in 0 being read
- Writing zero does not affect the operation
All bits in the CHCTRL register accessible by software are set and clear
bits.
The documentation for the CLREND bit of CHCTRL states:
Setting this bit to 1 can clear the END bit of the CHSTAT_n/nS register.
Also, the DMA transfer end interrupt is cleared. An attempt to read this
bit results in 0 being read.
1: Clears the END bit.
0: Does not affect the operation.
Since writing zero to any bit in this register does not affect controller
operation and reads always return zero, there is no need to perform
read-modify-write accesses to set the CLREND bit. Drop the read of the
CHCTRL register.
Also, since setting the CLREND bit does not interact with other
functionalities exposed through this register and only clears the END
interrupt, there is no need to lock around this operation. Add a comment
to document this.
Reviewed-by: Biju Das <biju.das.jz@bp.renesas.com>
Reviewed-by: Frank Li <Frank.Li@nxp.com>
Signed-off-by: Claudiu Beznea <claudiu.beznea.uj@bp.renesas.com>
Link: https://patch.msgid.link/20260316133252.240348-4-claudiu.beznea.uj@bp.renesas.com
Signed-off-by: Vinod Koul <vkoul@kernel.org>
Signed-off-by: Tommaso Merciai <tommaso.merciai.xr@bp.renesas.com>
---
drivers/dma/sh/rz-dmac.c | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/drivers/dma/sh/rz-dmac.c b/drivers/dma/sh/rz-dmac.c
index dd24908bb2d8..dbc575a943bb 100644
--- a/drivers/dma/sh/rz-dmac.c
+++ b/drivers/dma/sh/rz-dmac.c
@@ -695,7 +695,7 @@ static void rz_dmac_irq_handle_channel(struct rz_dmac_chan *channel)
{
struct dma_chan *chan = &channel->vc.chan;
struct rz_dmac *dmac = to_rz_dmac(chan->device);
- u32 chstat, chctrl;
+ u32 chstat;
chstat = rz_dmac_ch_readl(channel, CHSTAT, 1);
if (chstat & CHSTAT_ER) {
@@ -707,8 +707,11 @@ static void rz_dmac_irq_handle_channel(struct rz_dmac_chan *channel)
goto done;
}
- chctrl = rz_dmac_ch_readl(channel, CHCTRL, 1);
- rz_dmac_ch_writel(channel, chctrl | CHCTRL_CLREND, CHCTRL, 1);
+ /*
+ * No need to lock. This just clears the END interrupt. Writing
+ * zeros to CHCTRL is just ignored by HW.
+ */
+ rz_dmac_ch_writel(channel, CHCTRL_CLREND, CHCTRL, 1);
done:
return;
}
--
2.54.0
^ permalink raw reply related [flat|nested] 30+ messages in thread
* [PATCH 6.1.y-cip 07/27] dmaengine: sh: rz-dmac: Drop goto instruction and label
2026-11-26 15:47 [PATCH 6.1.y-cip 00/27] Renesas: Backport DMA fixes and improvements Tommaso Merciai
` (5 preceding siblings ...)
2026-11-26 15:47 ` [PATCH 6.1.y-cip 06/27] dmaengine: sh: rz-dmac: Drop read of CHCTRL register Tommaso Merciai
@ 2026-11-26 15:47 ` Tommaso Merciai
2026-11-26 15:47 ` [PATCH 6.1.y-cip 08/27] dmaengine: sh: rz-dmac: Drop unnecessary local_irq_save() call Tommaso Merciai
` (21 subsequent siblings)
28 siblings, 0 replies; 30+ messages in thread
From: Tommaso Merciai @ 2026-11-26 15:47 UTC (permalink / raw)
To: cip-dev, Nobuhiro Iwamatsu, Pavel Machek
Cc: Biju Das, Lad Prabhakar, tomm.merciai
From: Claudiu Beznea <claudiu.beznea@tuxon.dev>
commit 7badd294fc82629378b153327c57b8ba453688c7 upstream.
There is no need to jump to the done label, so return immediately.
Reviewed-by: Frank Li <Frank.Li@nxp.com>
Signed-off-by: Claudiu Beznea <claudiu.beznea.uj@bp.renesas.com>
Link: https://patch.msgid.link/20260316133252.240348-5-claudiu.beznea.uj@bp.renesas.com
Signed-off-by: Vinod Koul <vkoul@kernel.org>
Signed-off-by: Tommaso Merciai <tommaso.merciai.xr@bp.renesas.com>
---
drivers/dma/sh/rz-dmac.c | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/drivers/dma/sh/rz-dmac.c b/drivers/dma/sh/rz-dmac.c
index dbc575a943bb..fddf9148277e 100644
--- a/drivers/dma/sh/rz-dmac.c
+++ b/drivers/dma/sh/rz-dmac.c
@@ -704,7 +704,7 @@ static void rz_dmac_irq_handle_channel(struct rz_dmac_chan *channel)
scoped_guard(spinlock_irqsave, &channel->vc.lock)
rz_dmac_ch_writel(channel, CHCTRL_DEFAULT, CHCTRL, 1);
- goto done;
+ return;
}
/*
@@ -712,8 +712,6 @@ static void rz_dmac_irq_handle_channel(struct rz_dmac_chan *channel)
* zeros to CHCTRL is just ignored by HW.
*/
rz_dmac_ch_writel(channel, CHCTRL_CLREND, CHCTRL, 1);
-done:
- return;
}
static irqreturn_t rz_dmac_irq_handler(int irq, void *dev_id)
--
2.54.0
^ permalink raw reply related [flat|nested] 30+ messages in thread
* [PATCH 6.1.y-cip 08/27] dmaengine: sh: rz-dmac: Drop unnecessary local_irq_save() call
2026-11-26 15:47 [PATCH 6.1.y-cip 00/27] Renesas: Backport DMA fixes and improvements Tommaso Merciai
` (6 preceding siblings ...)
2026-11-26 15:47 ` [PATCH 6.1.y-cip 07/27] dmaengine: sh: rz-dmac: Drop goto instruction and label Tommaso Merciai
@ 2026-11-26 15:47 ` Tommaso Merciai
2026-11-26 15:47 ` [PATCH 6.1.y-cip 09/27] dmaengine: sh: rz-dmac: Use rz_lmdesc_setup() to invalidate descriptors Tommaso Merciai
` (20 subsequent siblings)
28 siblings, 0 replies; 30+ messages in thread
From: Tommaso Merciai @ 2026-11-26 15:47 UTC (permalink / raw)
To: cip-dev, Nobuhiro Iwamatsu, Pavel Machek
Cc: Biju Das, Lad Prabhakar, tomm.merciai
From: Claudiu Beznea <claudiu.beznea@tuxon.dev>
commit be25945d0ca3ac736c448b530c47e854c82a0343 upstream.
rz_dmac_enable_hw() calls local_irq_save()/local_irq_restore(), but
this is not needed because the callers of rz_dmac_enable_hw() already
protect the critical section using
spin_lock_irqsave()/spin_lock_irqrestore().
Remove the local_irq_save()/local_irq_restore() calls.
Reviewed-by: Frank Li <Frank.Li@nxp.com>
Signed-off-by: Claudiu Beznea <claudiu.beznea.uj@bp.renesas.com>
Link: https://patch.msgid.link/20260316133252.240348-6-claudiu.beznea.uj@bp.renesas.com
Signed-off-by: Vinod Koul <vkoul@kernel.org>
Signed-off-by: Tommaso Merciai <tommaso.merciai.xr@bp.renesas.com>
---
drivers/dma/sh/rz-dmac.c | 5 -----
1 file changed, 5 deletions(-)
diff --git a/drivers/dma/sh/rz-dmac.c b/drivers/dma/sh/rz-dmac.c
index fddf9148277e..13d964c0b126 100644
--- a/drivers/dma/sh/rz-dmac.c
+++ b/drivers/dma/sh/rz-dmac.c
@@ -271,15 +271,12 @@ static void rz_dmac_enable_hw(struct rz_dmac_chan *channel)
{
struct dma_chan *chan = &channel->vc.chan;
struct rz_dmac *dmac = to_rz_dmac(chan->device);
- unsigned long flags;
u32 nxla;
u32 chctrl;
u32 chstat;
dev_dbg(dmac->dev, "%s channel %d\n", __func__, channel->index);
- local_irq_save(flags);
-
rz_dmac_lmdesc_recycle(channel);
nxla = channel->lmdesc.base_dma +
@@ -294,8 +291,6 @@ static void rz_dmac_enable_hw(struct rz_dmac_chan *channel)
rz_dmac_ch_writel(channel, CHCTRL_SWRST, CHCTRL, 1);
rz_dmac_ch_writel(channel, chctrl, CHCTRL, 1);
}
-
- local_irq_restore(flags);
}
static void rz_dmac_disable_hw(struct rz_dmac_chan *channel)
--
2.54.0
^ permalink raw reply related [flat|nested] 30+ messages in thread
* [PATCH 6.1.y-cip 09/27] dmaengine: sh: rz-dmac: Use rz_lmdesc_setup() to invalidate descriptors
2026-11-26 15:47 [PATCH 6.1.y-cip 00/27] Renesas: Backport DMA fixes and improvements Tommaso Merciai
` (7 preceding siblings ...)
2026-11-26 15:47 ` [PATCH 6.1.y-cip 08/27] dmaengine: sh: rz-dmac: Drop unnecessary local_irq_save() call Tommaso Merciai
@ 2026-11-26 15:47 ` Tommaso Merciai
2026-11-26 15:47 ` [PATCH 6.1.y-cip 10/27] dmaengine: sh: rz-dmac: Add device_tx_status() callback Tommaso Merciai
` (19 subsequent siblings)
28 siblings, 0 replies; 30+ messages in thread
From: Tommaso Merciai @ 2026-11-26 15:47 UTC (permalink / raw)
To: cip-dev, Nobuhiro Iwamatsu, Pavel Machek
Cc: Biju Das, Lad Prabhakar, tomm.merciai
From: John Madieu <john.madieu.xa@bp.renesas.com>
commit bfaa60be647842cece968769f208e57fa5dee594 upstream.
rz_lmdesc_setup() invalidates DMA descriptors more comprehensively.
It resets the base, head, and tail pointers of the descriptor list and
clears the descriptor headers and their NXLA pointers. Use
rz_lmdesc_setup() instead of open-coding parts of its logic.
Signed-off-by: John Madieu <john.madieu.xa@bp.renesas.com>
Signed-off-by: Claudiu Beznea <claudiu.beznea.uj@bp.renesas.com>
Reviewed-by: Frank Li <Frank.Li@nxp.com>
Link: https://patch.msgid.link/20260316133252.240348-7-claudiu.beznea.uj@bp.renesas.com
Signed-off-by: Vinod Koul <vkoul@kernel.org>
Signed-off-by: Tommaso Merciai <tommaso.merciai.xr@bp.renesas.com>
---
drivers/dma/sh/rz-dmac.c | 10 ++--------
1 file changed, 2 insertions(+), 8 deletions(-)
diff --git a/drivers/dma/sh/rz-dmac.c b/drivers/dma/sh/rz-dmac.c
index 13d964c0b126..b4ec34a86f91 100644
--- a/drivers/dma/sh/rz-dmac.c
+++ b/drivers/dma/sh/rz-dmac.c
@@ -459,15 +459,12 @@ static void rz_dmac_free_chan_resources(struct dma_chan *chan)
{
struct rz_dmac_chan *channel = to_rz_dmac_chan(chan);
struct rz_dmac *dmac = to_rz_dmac(chan->device);
- struct rz_lmdesc *lmdesc = channel->lmdesc.base;
struct rz_dmac_desc *desc, *_desc;
unsigned long flags;
- unsigned int i;
spin_lock_irqsave(&channel->vc.lock, flags);
- for (i = 0; i < DMAC_NR_LMDESC; i++)
- lmdesc[i].header = 0;
+ rz_lmdesc_setup(channel, channel->lmdesc.base);
rz_dmac_disable_hw(channel);
list_splice_tail_init(&channel->ld_active, &channel->ld_free);
@@ -559,15 +556,12 @@ rz_dmac_prep_slave_sg(struct dma_chan *chan, struct scatterlist *sgl,
static int rz_dmac_terminate_all(struct dma_chan *chan)
{
struct rz_dmac_chan *channel = to_rz_dmac_chan(chan);
- struct rz_lmdesc *lmdesc = channel->lmdesc.base;
unsigned long flags;
- unsigned int i;
LIST_HEAD(head);
spin_lock_irqsave(&channel->vc.lock, flags);
rz_dmac_disable_hw(channel);
- for (i = 0; i < DMAC_NR_LMDESC; i++)
- lmdesc[i].header = 0;
+ rz_lmdesc_setup(channel, channel->lmdesc.base);
list_splice_tail_init(&channel->ld_active, &channel->ld_free);
list_splice_tail_init(&channel->ld_queue, &channel->ld_free);
--
2.54.0
^ permalink raw reply related [flat|nested] 30+ messages in thread
* [PATCH 6.1.y-cip 10/27] dmaengine: sh: rz-dmac: Add device_tx_status() callback
2026-11-26 15:47 [PATCH 6.1.y-cip 00/27] Renesas: Backport DMA fixes and improvements Tommaso Merciai
` (8 preceding siblings ...)
2026-11-26 15:47 ` [PATCH 6.1.y-cip 09/27] dmaengine: sh: rz-dmac: Use rz_lmdesc_setup() to invalidate descriptors Tommaso Merciai
@ 2026-11-26 15:47 ` Tommaso Merciai
2026-11-26 15:47 ` [PATCH 6.1.y-cip 11/27] dmaengine: sh: rz-dmac: Add device_{pause,resume}() callbacks Tommaso Merciai
` (18 subsequent siblings)
28 siblings, 0 replies; 30+ messages in thread
From: Tommaso Merciai @ 2026-11-26 15:47 UTC (permalink / raw)
To: cip-dev, Nobuhiro Iwamatsu, Pavel Machek
Cc: Biju Das, Lad Prabhakar, tomm.merciai
From: Biju Das <biju.das.jz@bp.renesas.com>
commit 21323b118c16d287355e6497e1098ce1ca348bd6 upstream.
The RZ/G2L SCIFA driver uses dmaengine_prep_slave_sg() to enqueue DMA
transfers and implements a timeout mechanism on RX to handle cases where
a DMA transfer does not complete. The timeout is implemented using an
hrtimer.
In the hrtimer callback, dmaengine_tx_status() is called (along with
dmaengine_pause()) to retrieve the transfer residue and handle incomplete
DMA transfers.
Add support for the device_tx_status() callback.
Co-developed-by: Long Luu <long.luu.ur@renesas.com>
Signed-off-by: Long Luu <long.luu.ur@renesas.com>
Signed-off-by: Biju Das <biju.das.jz@bp.renesas.com>
Co-developed-by: Claudiu Beznea <claudiu.beznea.uj@bp.renesas.com>
Signed-off-by: Claudiu Beznea <claudiu.beznea.uj@bp.renesas.com>
Reviewed-by: Frank Li <Frank.Li@nxp.com>
Link: https://patch.msgid.link/20260316133252.240348-8-claudiu.beznea.uj@bp.renesas.com
Signed-off-by: Vinod Koul <vkoul@kernel.org>
Signed-off-by: Tommaso Merciai <tommaso.merciai.xr@bp.renesas.com>
---
drivers/dma/sh/rz-dmac.c | 144 ++++++++++++++++++++++++++++++++++++++-
1 file changed, 143 insertions(+), 1 deletion(-)
diff --git a/drivers/dma/sh/rz-dmac.c b/drivers/dma/sh/rz-dmac.c
index b4ec34a86f91..bf0d7b6f5511 100644
--- a/drivers/dma/sh/rz-dmac.c
+++ b/drivers/dma/sh/rz-dmac.c
@@ -123,10 +123,12 @@ struct rz_dmac {
* Registers
*/
+#define CRTB 0x0020
#define CHSTAT 0x0024
#define CHCTRL 0x0028
#define CHCFG 0x002c
#define NXLA 0x0038
+#define CRLA 0x003c
#define DCTRL 0x0000
@@ -675,6 +677,145 @@ static void rz_dmac_device_synchronize(struct dma_chan *chan)
rz_dmac_set_dma_req_no(dmac, channel->index, dmac->info->default_dma_req_no);
}
+static struct rz_lmdesc *
+rz_dmac_get_next_lmdesc(struct rz_lmdesc *base, struct rz_lmdesc *lmdesc)
+{
+ struct rz_lmdesc *next = ++lmdesc;
+
+ if (next >= base + DMAC_NR_LMDESC)
+ next = base;
+
+ return next;
+}
+
+static u32 rz_dmac_calculate_residue_bytes_in_vd(struct rz_dmac_chan *channel, u32 crla)
+{
+ struct rz_lmdesc *lmdesc = channel->lmdesc.head;
+ struct dma_chan *chan = &channel->vc.chan;
+ struct rz_dmac *dmac = to_rz_dmac(chan->device);
+ u32 residue = 0, i = 0;
+
+ while (lmdesc->nxla != crla) {
+ lmdesc = rz_dmac_get_next_lmdesc(channel->lmdesc.base, lmdesc);
+ if (++i >= DMAC_NR_LMDESC)
+ return 0;
+ }
+
+ /* Calculate residue from next lmdesc to end of virtual desc */
+ while (lmdesc->chcfg & CHCFG_DEM) {
+ residue += lmdesc->tb;
+ lmdesc = rz_dmac_get_next_lmdesc(channel->lmdesc.base, lmdesc);
+ }
+
+ dev_dbg(dmac->dev, "%s: VD residue is %u\n", __func__, residue);
+
+ return residue;
+}
+
+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;
+ u32 crla, crtb, i;
+
+ /* Get current processing virtual descriptor */
+ current_desc = list_first_entry(&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 = dma_cookie_status(&channel->vc.chan, cookie, NULL);
+ if (status == 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 != current_desc->vd.tx.cookie) {
+ list_for_each_entry(desc, &channel->ld_free, node) {
+ if (cookie == desc->vd.tx.cookie)
+ return 0;
+ }
+
+ list_for_each_entry(desc, &channel->ld_queue, node) {
+ if (cookie == desc->vd.tx.cookie)
+ return desc->len;
+ }
+
+ list_for_each_entry(desc, &channel->ld_active, node) {
+ if (cookie == desc->vd.tx.cookie)
+ return desc->len;
+ }
+
+ /*
+ * 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!");
+ return 0;
+ }
+
+ /*
+ * 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
+ * should be enough: initial read, retry, retry for the paranoid.
+ */
+ for (i = 0; i < 3; i++) {
+ crla = rz_dmac_ch_readl(channel, CRLA, 1);
+ crtb = rz_dmac_ch_readl(channel, CRTB, 1);
+ /* Still the same? */
+ if (crla == rz_dmac_ch_readl(channel, CRLA, 1))
+ break;
+ }
+
+ WARN_ONCE(i >= 3, "residue might not be continuous!");
+
+ /*
+ * 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);
+}
+
+static enum dma_status rz_dmac_tx_status(struct dma_chan *chan,
+ dma_cookie_t cookie,
+ struct dma_tx_state *txstate)
+{
+ struct rz_dmac_chan *channel = to_rz_dmac_chan(chan);
+ enum dma_status status;
+ u32 residue;
+
+ status = dma_cookie_status(chan, cookie, txstate);
+ if (status == DMA_COMPLETE || !txstate)
+ return status;
+
+ scoped_guard(spinlock_irqsave, &channel->vc.lock)
+ residue = rz_dmac_chan_get_residue(channel, cookie);
+
+ /* if there's no residue, the cookie is complete */
+ if (!residue)
+ return DMA_COMPLETE;
+
+ dma_set_residue(txstate, residue);
+
+ return status;
+}
+
/*
* -----------------------------------------------------------------------------
* IRQ handling
@@ -993,6 +1134,7 @@ static int rz_dmac_probe(struct platform_device *pdev)
engine = &dmac->engine;
dma_cap_set(DMA_SLAVE, engine->cap_mask);
dma_cap_set(DMA_MEMCPY, engine->cap_mask);
+ engine->residue_granularity = 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);
@@ -1000,7 +1142,7 @@ static int rz_dmac_probe(struct platform_device *pdev)
engine->device_alloc_chan_resources = rz_dmac_alloc_chan_resources;
engine->device_free_chan_resources = rz_dmac_free_chan_resources;
- engine->device_tx_status = dma_cookie_status;
+ engine->device_tx_status = rz_dmac_tx_status;
engine->device_prep_slave_sg = rz_dmac_prep_slave_sg;
engine->device_prep_dma_memcpy = rz_dmac_prep_dma_memcpy;
engine->device_config = rz_dmac_config;
--
2.54.0
^ permalink raw reply related [flat|nested] 30+ messages in thread
* [PATCH 6.1.y-cip 11/27] dmaengine: sh: rz-dmac: Add device_{pause,resume}() callbacks
2026-11-26 15:47 [PATCH 6.1.y-cip 00/27] Renesas: Backport DMA fixes and improvements Tommaso Merciai
` (9 preceding siblings ...)
2026-11-26 15:47 ` [PATCH 6.1.y-cip 10/27] dmaengine: sh: rz-dmac: Add device_tx_status() callback Tommaso Merciai
@ 2026-11-26 15:47 ` Tommaso Merciai
2026-11-26 15:47 ` [PATCH 6.1.y-cip 12/27] dmaengine: sh: rz-dmac: Fix incorrect NULL check for list_first_entry() Tommaso Merciai
` (17 subsequent siblings)
28 siblings, 0 replies; 30+ messages in thread
From: Tommaso Merciai @ 2026-11-26 15:47 UTC (permalink / raw)
To: cip-dev, Nobuhiro Iwamatsu, Pavel Machek
Cc: Biju Das, Lad Prabhakar, tomm.merciai
From: Claudiu Beznea <claudiu.beznea@tuxon.dev>
commit 44f991bd6e01bb6a3f78da98eafa6d2a72819a2f upstream.
The RZ/G2L SCIFA driver uses dmaengine_prep_slave_sg() to enqueue DMA
transfers and implements a timeout mechanism on RX to handle cases where
a DMA transfer does not complete. The timeout is implemented using an
hrtimer.
In the hrtimer callback, dmaengine_tx_status() is called (along with
dmaengine_pause()) to retrieve the transfer residue and handle incomplete
DMA transfers.
Add support for device_{pause, resume}() callbacks.
Signed-off-by: Claudiu Beznea <claudiu.beznea.uj@bp.renesas.com>
Link: https://patch.msgid.link/20260316133252.240348-9-claudiu.beznea.uj@bp.renesas.com
Signed-off-by: Vinod Koul <vkoul@kernel.org>
Signed-off-by: Tommaso Merciai <tommaso.merciai.xr@bp.renesas.com>
---
drivers/dma/sh/rz-dmac.c | 49 +++++++++++++++++++++++++++++++++++++---
1 file changed, 46 insertions(+), 3 deletions(-)
diff --git a/drivers/dma/sh/rz-dmac.c b/drivers/dma/sh/rz-dmac.c
index bf0d7b6f5511..84d662ad798d 100644
--- a/drivers/dma/sh/rz-dmac.c
+++ b/drivers/dma/sh/rz-dmac.c
@@ -139,10 +139,12 @@ struct rz_dmac {
#define CHANNEL_8_15_COMMON_BASE 0x0700
#define CHSTAT_ER BIT(4)
+#define CHSTAT_SUS BIT(3)
#define CHSTAT_EN BIT(0)
#define CHCTRL_CLRINTMSK BIT(17)
#define CHCTRL_CLRSUS BIT(9)
+#define CHCTRL_SETSUS BIT(8)
#define CHCTRL_CLRTC BIT(6)
#define CHCTRL_CLREND BIT(5)
#define CHCTRL_CLRRQ BIT(4)
@@ -804,11 +806,18 @@ static enum dma_status rz_dmac_tx_status(struct dma_chan *chan,
if (status == DMA_COMPLETE || !txstate)
return status;
- scoped_guard(spinlock_irqsave, &channel->vc.lock)
+ scoped_guard(spinlock_irqsave, &channel->vc.lock) {
+ u32 val;
+
residue = rz_dmac_chan_get_residue(channel, cookie);
- /* if there's no residue, the cookie is complete */
- if (!residue)
+ val = rz_dmac_ch_readl(channel, CHSTAT, 1);
+ if (val & CHSTAT_SUS)
+ status = DMA_PAUSED;
+ }
+
+ /* if there's no residue and no paused, the cookie is complete */
+ if (!residue && status != DMA_PAUSED)
return DMA_COMPLETE;
dma_set_residue(txstate, residue);
@@ -816,6 +825,38 @@ static enum dma_status rz_dmac_tx_status(struct dma_chan *chan,
return status;
}
+static int rz_dmac_device_pause(struct dma_chan *chan)
+{
+ struct rz_dmac_chan *channel = to_rz_dmac_chan(chan);
+ u32 val;
+
+ guard(spinlock_irqsave)(&channel->vc.lock);
+
+ val = rz_dmac_ch_readl(channel, CHSTAT, 1);
+ if (!(val & CHSTAT_EN))
+ return 0;
+
+ 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);
+}
+
+static int rz_dmac_device_resume(struct dma_chan *chan)
+{
+ struct rz_dmac_chan *channel = to_rz_dmac_chan(chan);
+ u32 val;
+
+ guard(spinlock_irqsave)(&channel->vc.lock);
+
+ /* Do not check CHSTAT_SUS but rely on HW capabilities. */
+
+ 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);
+}
+
/*
* -----------------------------------------------------------------------------
* IRQ handling
@@ -1149,6 +1190,8 @@ static int rz_dmac_probe(struct platform_device *pdev)
engine->device_terminate_all = rz_dmac_terminate_all;
engine->device_issue_pending = rz_dmac_issue_pending;
engine->device_synchronize = rz_dmac_device_synchronize;
+ engine->device_pause = rz_dmac_device_pause;
+ engine->device_resume = rz_dmac_device_resume;
engine->copy_align = DMAENGINE_ALIGN_1_BYTE;
dma_set_max_seg_size(engine->dev, U32_MAX);
--
2.54.0
^ permalink raw reply related [flat|nested] 30+ messages in thread
* [PATCH 6.1.y-cip 12/27] dmaengine: sh: rz-dmac: Fix incorrect NULL check for list_first_entry()
2026-11-26 15:47 [PATCH 6.1.y-cip 00/27] Renesas: Backport DMA fixes and improvements Tommaso Merciai
` (10 preceding siblings ...)
2026-11-26 15:47 ` [PATCH 6.1.y-cip 11/27] dmaengine: sh: rz-dmac: Add device_{pause,resume}() callbacks Tommaso Merciai
@ 2026-11-26 15:47 ` Tommaso Merciai
2026-11-26 15:47 ` [PATCH 6.1.y-cip 13/27] dmaengine: sh: rz-dmac: Use list_first_entry_or_null() Tommaso Merciai
` (16 subsequent siblings)
28 siblings, 0 replies; 30+ messages in thread
From: Tommaso Merciai @ 2026-11-26 15:47 UTC (permalink / raw)
To: cip-dev, Nobuhiro Iwamatsu, Pavel Machek
Cc: Biju Das, Lad Prabhakar, tomm.merciai
From: Claudiu Beznea <claudiu.beznea.uj@bp.renesas.com>
commit 5fbf3a2a3b96ef5810e6e0fbc601f82067629bc5 upstream.
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() callback")
Cc: stable@vger.kernel.org
Tested-by: John Madieu <john.madieu.xa@bp.renesas.com>
Signed-off-by: Claudiu Beznea <claudiu.beznea.uj@bp.renesas.com>
Tested-by: Tommaso Merciai <tommaso.merciai.xr@bp.renesas.com>
Link: https://patch.msgid.link/20260526084710.3491480-3-claudiu.beznea@kernel.org
Signed-off-by: Vinod Koul <vkoul@kernel.org>
Signed-off-by: Tommaso Merciai <tommaso.merciai.xr@bp.renesas.com>
---
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 84d662ad798d..3cd3687f1949 100644
--- a/drivers/dma/sh/rz-dmac.c
+++ b/drivers/dma/sh/rz-dmac.c
@@ -722,8 +722,8 @@ static u32 rz_dmac_chan_get_residue(struct rz_dmac_chan *channel,
u32 crla, crtb, i;
/* Get current processing virtual descriptor */
- current_desc = list_first_entry(&channel->ld_active,
- struct rz_dmac_desc, node);
+ current_desc = list_first_entry_or_null(&channel->ld_active,
+ struct rz_dmac_desc, node);
if (!current_desc)
return 0;
--
2.54.0
^ permalink raw reply related [flat|nested] 30+ messages in thread
* [PATCH 6.1.y-cip 13/27] dmaengine: sh: rz-dmac: Use list_first_entry_or_null()
2026-11-26 15:47 [PATCH 6.1.y-cip 00/27] Renesas: Backport DMA fixes and improvements Tommaso Merciai
` (11 preceding siblings ...)
2026-11-26 15:47 ` [PATCH 6.1.y-cip 12/27] dmaengine: sh: rz-dmac: Fix incorrect NULL check for list_first_entry() Tommaso Merciai
@ 2026-11-26 15:47 ` Tommaso Merciai
2026-11-26 15:47 ` [PATCH 6.1.y-cip 14/27] dmaengine: sh: rz-dmac: Use rz_dmac_disable_hw() Tommaso Merciai
` (15 subsequent siblings)
28 siblings, 0 replies; 30+ messages in thread
From: Tommaso Merciai @ 2026-11-26 15:47 UTC (permalink / raw)
To: cip-dev, Nobuhiro Iwamatsu, Pavel Machek
Cc: Biju Das, Lad Prabhakar, tomm.merciai
From: Claudiu Beznea <claudiu.beznea.uj@bp.renesas.com>
commit 89975baaa9ea2490b75d69842561a32ca888b7e5 upstream.
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 <Frank.Li@nxp.com>
Tested-by: John Madieu <john.madieu.xa@bp.renesas.com>
Signed-off-by: Claudiu Beznea <claudiu.beznea.uj@bp.renesas.com>
Tested-by: Tommaso Merciai <tommaso.merciai.xr@bp.renesas.com>
Link: https://patch.msgid.link/20260526084710.3491480-4-claudiu.beznea@kernel.org
Signed-off-by: Vinod Koul <vkoul@kernel.org>
Signed-off-by: Tommaso Merciai <tommaso.merciai.xr@bp.renesas.com>
---
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 3cd3687f1949..0adb1e372116 100644
--- a/drivers/dma/sh/rz-dmac.c
+++ b/drivers/dma/sh/rz-dmac.c
@@ -502,11 +502,10 @@ rz_dmac_prep_dma_memcpy(struct dma_chan *chan, dma_addr_t dest, dma_addr_t src,
__func__, channel->index, &src, &dest, len);
scoped_guard(spinlock_irqsave, &channel->vc.lock) {
- if (list_empty(&channel->ld_free))
+ desc = list_first_entry_or_null(&channel->ld_free, struct rz_dmac_desc, node);
+ if (!desc)
return NULL;
- desc = list_first_entry(&channel->ld_free, struct rz_dmac_desc, node);
-
desc->type = RZ_DMAC_DESC_MEMCPY;
desc->src = src;
desc->dest = dest;
@@ -532,11 +531,10 @@ rz_dmac_prep_slave_sg(struct dma_chan *chan, struct scatterlist *sgl,
int i = 0;
scoped_guard(spinlock_irqsave, &channel->vc.lock) {
- if (list_empty(&channel->ld_free))
+ desc = list_first_entry_or_null(&channel->ld_free, struct rz_dmac_desc, node);
+ if (!desc)
return NULL;
- desc = list_first_entry(&channel->ld_free, struct rz_dmac_desc, node);
-
for_each_sg(sgl, sg, sg_len, i)
dma_length += sg_dma_len(sg);
--
2.54.0
^ permalink raw reply related [flat|nested] 30+ messages in thread
* [PATCH 6.1.y-cip 14/27] dmaengine: sh: rz-dmac: Use rz_dmac_disable_hw()
2026-11-26 15:47 [PATCH 6.1.y-cip 00/27] Renesas: Backport DMA fixes and improvements Tommaso Merciai
` (12 preceding siblings ...)
2026-11-26 15:47 ` [PATCH 6.1.y-cip 13/27] dmaengine: sh: rz-dmac: Use list_first_entry_or_null() Tommaso Merciai
@ 2026-11-26 15:47 ` Tommaso Merciai
2026-11-26 15:47 ` [PATCH 6.1.y-cip 15/27] dmaengine: sh: rz-dmac: Add helper to compute the lmdesc address Tommaso Merciai
` (14 subsequent siblings)
28 siblings, 0 replies; 30+ messages in thread
From: Tommaso Merciai @ 2026-11-26 15:47 UTC (permalink / raw)
To: cip-dev, Nobuhiro Iwamatsu, Pavel Machek
Cc: Biju Das, Lad Prabhakar, tomm.merciai
From: Claudiu Beznea <claudiu.beznea.uj@bp.renesas.com>
commit 38d4d021228386b8e3fbef2bca5f1e91eacd4fe6 upstream.
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 <Frank.Li@nxp.com>
Tested-by: John Madieu <john.madieu.xa@bp.renesas.com>
Signed-off-by: Claudiu Beznea <claudiu.beznea.uj@bp.renesas.com>
Tested-by: Tommaso Merciai <tommaso.merciai.xr@bp.renesas.com>
Link: https://patch.msgid.link/20260526084710.3491480-5-claudiu.beznea@kernel.org
Signed-off-by: Vinod Koul <vkoul@kernel.org>
Signed-off-by: Tommaso Merciai <tommaso.merciai.xr@bp.renesas.com>
---
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 0adb1e372116..882a8d84219d 100644
--- a/drivers/dma/sh/rz-dmac.c
+++ b/drivers/dma/sh/rz-dmac.c
@@ -872,7 +872,7 @@ static void rz_dmac_irq_handle_channel(struct rz_dmac_chan *channel)
channel->index, chstat);
scoped_guard(spinlock_irqsave, &channel->vc.lock)
- rz_dmac_ch_writel(channel, CHCTRL_DEFAULT, CHCTRL, 1);
+ rz_dmac_disable_hw(channel);
return;
}
@@ -999,15 +999,15 @@ static int rz_dmac_chan_probe(struct rz_dmac *dmac,
}
rz_lmdesc_setup(channel, lmdesc);
- /* Initialize register for each channel */
- rz_dmac_ch_writel(channel, CHCTRL_DEFAULT, CHCTRL, 1);
-
channel->vc.desc_free = 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);
+ /* Initialize register for each channel */
+ rz_dmac_disable_hw(channel);
+
/* Request the channel interrupt. */
scnprintf(pdev_irqname, sizeof(pdev_irqname), "ch%u", index);
irq = platform_get_irq_byname(pdev, pdev_irqname);
--
2.54.0
^ permalink raw reply related [flat|nested] 30+ messages in thread
* [PATCH 6.1.y-cip 15/27] dmaengine: sh: rz-dmac: Add helper to compute the lmdesc address
2026-11-26 15:47 [PATCH 6.1.y-cip 00/27] Renesas: Backport DMA fixes and improvements Tommaso Merciai
` (13 preceding siblings ...)
2026-11-26 15:47 ` [PATCH 6.1.y-cip 14/27] dmaengine: sh: rz-dmac: Use rz_dmac_disable_hw() Tommaso Merciai
@ 2026-11-26 15:47 ` Tommaso Merciai
2026-11-26 15:47 ` [PATCH 6.1.y-cip 16/27] dmaengine: sh: rz-dmac: Save the start LM descriptor Tommaso Merciai
` (13 subsequent siblings)
28 siblings, 0 replies; 30+ messages in thread
From: Tommaso Merciai @ 2026-11-26 15:47 UTC (permalink / raw)
To: cip-dev, Nobuhiro Iwamatsu, Pavel Machek
Cc: Biju Das, Lad Prabhakar, tomm.merciai
From: Claudiu Beznea <claudiu.beznea.uj@bp.renesas.com>
commit 32a69f1487819766d2084ed32b1350b18f971c10 upstream.
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 <Frank.Li@nxp.com>
Tested-by: John Madieu <john.madieu.xa@bp.renesas.com>
Signed-off-by: Claudiu Beznea <claudiu.beznea.uj@bp.renesas.com>
Tested-by: Tommaso Merciai <tommaso.merciai.xr@bp.renesas.com>
Link: https://patch.msgid.link/20260526084710.3491480-6-claudiu.beznea@kernel.org
Signed-off-by: Vinod Koul <vkoul@kernel.org>
Signed-off-by: Tommaso Merciai <tommaso.merciai.xr@bp.renesas.com>
---
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 882a8d84219d..196fc5aba6c8 100644
--- a/drivers/dma/sh/rz-dmac.c
+++ b/drivers/dma/sh/rz-dmac.c
@@ -258,6 +258,12 @@ static void rz_lmdesc_setup(struct rz_dmac_chan *channel,
* Descriptors preparation
*/
+static u32 rz_dmac_lmdesc_addr(struct rz_dmac_chan *channel, struct rz_lmdesc *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 = channel->lmdesc.head;
@@ -283,9 +289,7 @@ static void rz_dmac_enable_hw(struct rz_dmac_chan *channel)
rz_dmac_lmdesc_recycle(channel);
- nxla = channel->lmdesc.base_dma +
- (sizeof(struct rz_lmdesc) * (channel->lmdesc.head -
- channel->lmdesc.base));
+ nxla = rz_dmac_lmdesc_addr(channel, channel->lmdesc.head);
chstat = rz_dmac_ch_readl(channel, CHSTAT, 1);
if (!(chstat & CHSTAT_EN)) {
--
2.54.0
^ permalink raw reply related [flat|nested] 30+ messages in thread
* [PATCH 6.1.y-cip 16/27] dmaengine: sh: rz-dmac: Save the start LM descriptor
2026-11-26 15:47 [PATCH 6.1.y-cip 00/27] Renesas: Backport DMA fixes and improvements Tommaso Merciai
` (14 preceding siblings ...)
2026-11-26 15:47 ` [PATCH 6.1.y-cip 15/27] dmaengine: sh: rz-dmac: Add helper to compute the lmdesc address Tommaso Merciai
@ 2026-11-26 15:47 ` Tommaso Merciai
2026-11-26 15:47 ` [PATCH 6.1.y-cip 17/27] dmaengine: sh: rz-dmac: Add helper to check if the channel is enabled Tommaso Merciai
` (12 subsequent siblings)
28 siblings, 0 replies; 30+ messages in thread
From: Tommaso Merciai @ 2026-11-26 15:47 UTC (permalink / raw)
To: cip-dev, Nobuhiro Iwamatsu, Pavel Machek
Cc: Biju Das, Lad Prabhakar, tomm.merciai
From: Claudiu Beznea <claudiu.beznea.uj@bp.renesas.com>
commit e21aa306e82067457f2297ae56af4c91db86c59a upstream.
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 <john.madieu.xa@bp.renesas.com>
Signed-off-by: Claudiu Beznea <claudiu.beznea.uj@bp.renesas.com>
Tested-by: Tommaso Merciai <tommaso.merciai.xr@bp.renesas.com>
Link: https://patch.msgid.link/20260526084710.3491480-7-claudiu.beznea@kernel.org
Signed-off-by: Vinod Koul <vkoul@kernel.org>
Signed-off-by: Tommaso Merciai <tommaso.merciai.xr@bp.renesas.com>
---
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 196fc5aba6c8..0a632dc8f534 100644
--- a/drivers/dma/sh/rz-dmac.c
+++ b/drivers/dma/sh/rz-dmac.c
@@ -57,6 +57,7 @@ struct rz_dmac_desc {
/* For slave sg */
struct scatterlist *sg;
unsigned int sgcount;
+ struct rz_lmdesc *start_lmdesc;
};
#define to_rz_dmac_desc(d) container_of(d, struct rz_dmac_desc, vd)
@@ -342,6 +343,8 @@ static void rz_dmac_prepare_desc_for_memcpy(struct rz_dmac_chan *channel)
struct rz_dmac_desc *d = channel->desc;
u32 chcfg = CHCFG_MEM_COPY;
+ d->start_lmdesc = lmdesc;
+
/* prepare descriptor */
lmdesc->sa = d->src;
lmdesc->da = d->dest;
@@ -376,6 +379,7 @@ static void rz_dmac_prepare_descs_for_slave_sg(struct rz_dmac_chan *channel)
}
lmdesc = channel->lmdesc.tail;
+ d->start_lmdesc = lmdesc;
for (i = 0, sg = sgl; i < sg_len; i++, sg = sg_next(sg)) {
if (d->direction == DMA_DEV_TO_MEM) {
@@ -692,9 +696,10 @@ rz_dmac_get_next_lmdesc(struct rz_lmdesc *base, struct rz_lmdesc *lmdesc)
return next;
}
-static u32 rz_dmac_calculate_residue_bytes_in_vd(struct rz_dmac_chan *channel, u32 crla)
+static u32 rz_dmac_calculate_residue_bytes_in_vd(struct rz_dmac_chan *channel,
+ struct rz_dmac_desc *desc, u32 crla)
{
- struct rz_lmdesc *lmdesc = channel->lmdesc.head;
+ struct rz_lmdesc *lmdesc = desc->start_lmdesc;
struct dma_chan *chan = &channel->vc.chan;
struct rz_dmac *dmac = to_rz_dmac(chan->device);
u32 residue = 0, i = 0;
@@ -793,7 +798,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);
}
static enum dma_status rz_dmac_tx_status(struct dma_chan *chan,
--
2.54.0
^ permalink raw reply related [flat|nested] 30+ messages in thread
* [PATCH 6.1.y-cip 17/27] dmaengine: sh: rz-dmac: Add helper to check if the channel is enabled
2026-11-26 15:47 [PATCH 6.1.y-cip 00/27] Renesas: Backport DMA fixes and improvements Tommaso Merciai
` (15 preceding siblings ...)
2026-11-26 15:47 ` [PATCH 6.1.y-cip 16/27] dmaengine: sh: rz-dmac: Save the start LM descriptor Tommaso Merciai
@ 2026-11-26 15:47 ` Tommaso Merciai
2026-11-26 15:47 ` [PATCH 6.1.y-cip 18/27] dmaengine: sh: rz-dmac: Add helper to check if the channel is paused Tommaso Merciai
` (11 subsequent siblings)
28 siblings, 0 replies; 30+ messages in thread
From: Tommaso Merciai @ 2026-11-26 15:47 UTC (permalink / raw)
To: cip-dev, Nobuhiro Iwamatsu, Pavel Machek
Cc: Biju Das, Lad Prabhakar, tomm.merciai
From: Claudiu Beznea <claudiu.beznea.uj@bp.renesas.com>
commit 7a94c109a5def4f0f25705a82ed5870f794ff4ed upstream.
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 <Frank.Li@nxp.com>
Tested-by: John Madieu <john.madieu.xa@bp.renesas.com>
Signed-off-by: Claudiu Beznea <claudiu.beznea.uj@bp.renesas.com>
Tested-by: Tommaso Merciai <tommaso.merciai.xr@bp.renesas.com>
Link: https://patch.msgid.link/20260526084710.3491480-8-claudiu.beznea@kernel.org
Signed-off-by: Vinod Koul <vkoul@kernel.org>
Signed-off-by: Tommaso Merciai <tommaso.merciai.xr@bp.renesas.com>
---
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 0a632dc8f534..73a2b61e718d 100644
--- a/drivers/dma/sh/rz-dmac.c
+++ b/drivers/dma/sh/rz-dmac.c
@@ -278,6 +278,13 @@ static void rz_dmac_lmdesc_recycle(struct rz_dmac_chan *channel)
channel->lmdesc.head = lmdesc;
}
+static bool rz_dmac_chan_is_enabled(struct rz_dmac_chan *channel)
+{
+ u32 val = 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 = &channel->vc.chan;
@@ -839,8 +846,7 @@ static int rz_dmac_device_pause(struct dma_chan *chan)
guard(spinlock_irqsave)(&channel->vc.lock);
- val = rz_dmac_ch_readl(channel, CHSTAT, 1);
- if (!(val & CHSTAT_EN))
+ if (!rz_dmac_chan_is_enabled(channel))
return 0;
rz_dmac_ch_writel(channel, CHCTRL_SETSUS, CHCTRL, 1);
--
2.54.0
^ permalink raw reply related [flat|nested] 30+ messages in thread
* [PATCH 6.1.y-cip 18/27] dmaengine: sh: rz-dmac: Add helper to check if the channel is paused
2026-11-26 15:47 [PATCH 6.1.y-cip 00/27] Renesas: Backport DMA fixes and improvements Tommaso Merciai
` (16 preceding siblings ...)
2026-11-26 15:47 ` [PATCH 6.1.y-cip 17/27] dmaengine: sh: rz-dmac: Add helper to check if the channel is enabled Tommaso Merciai
@ 2026-11-26 15:47 ` Tommaso Merciai
2026-11-26 15:47 ` [PATCH 6.1.y-cip 19/27] dmaengine: sh: rz-dmac: Use virt-dma APIs for channel descriptor processing Tommaso Merciai
` (10 subsequent siblings)
28 siblings, 0 replies; 30+ messages in thread
From: Tommaso Merciai @ 2026-11-26 15:47 UTC (permalink / raw)
To: cip-dev, Nobuhiro Iwamatsu, Pavel Machek
Cc: Biju Das, Lad Prabhakar, tomm.merciai
From: Claudiu Beznea <claudiu.beznea.uj@bp.renesas.com>
commit 1dddc864dfa844efaf36345eb58b121b2cdffa5f upstream.
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 <Frank.Li@nxp.com>
Tested-by: John Madieu <john.madieu.xa@bp.renesas.com>
Signed-off-by: Claudiu Beznea <claudiu.beznea.uj@bp.renesas.com>
Tested-by: Tommaso Merciai <tommaso.merciai.xr@bp.renesas.com>
Link: https://patch.msgid.link/20260526084710.3491480-9-claudiu.beznea@kernel.org
Signed-off-by: Vinod Koul <vkoul@kernel.org>
Signed-off-by: Tommaso Merciai <tommaso.merciai.xr@bp.renesas.com>
---
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 73a2b61e718d..0ba6bc545e61 100644
--- a/drivers/dma/sh/rz-dmac.c
+++ b/drivers/dma/sh/rz-dmac.c
@@ -285,6 +285,13 @@ static bool rz_dmac_chan_is_enabled(struct rz_dmac_chan *channel)
return !!(val & CHSTAT_EN);
}
+static bool rz_dmac_chan_is_paused(struct rz_dmac_chan *channel)
+{
+ u32 val = 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 = &channel->vc.chan;
@@ -821,12 +828,9 @@ static enum dma_status rz_dmac_tx_status(struct dma_chan *chan,
return status;
scoped_guard(spinlock_irqsave, &channel->vc.lock) {
- u32 val;
-
residue = rz_dmac_chan_get_residue(channel, cookie);
- val = rz_dmac_ch_readl(channel, CHSTAT, 1);
- if (val & CHSTAT_SUS)
+ if (rz_dmac_chan_is_paused(channel))
status = DMA_PAUSED;
}
--
2.54.0
^ permalink raw reply related [flat|nested] 30+ messages in thread
* [PATCH 6.1.y-cip 19/27] dmaengine: sh: rz-dmac: Use virt-dma APIs for channel descriptor processing
2026-11-26 15:47 [PATCH 6.1.y-cip 00/27] Renesas: Backport DMA fixes and improvements Tommaso Merciai
` (17 preceding siblings ...)
2026-11-26 15:47 ` [PATCH 6.1.y-cip 18/27] dmaengine: sh: rz-dmac: Add helper to check if the channel is paused Tommaso Merciai
@ 2026-11-26 15:47 ` Tommaso Merciai
2026-11-26 15:47 ` [PATCH 6.1.y-cip 20/27] dmaengine: sh: rz-dmac: Refactor pause/resume code Tommaso Merciai
` (9 subsequent siblings)
28 siblings, 0 replies; 30+ messages in thread
From: Tommaso Merciai @ 2026-11-26 15:47 UTC (permalink / raw)
To: cip-dev, Nobuhiro Iwamatsu, Pavel Machek
Cc: Biju Das, Lad Prabhakar, tomm.merciai
From: Claudiu Beznea <claudiu.beznea.uj@bp.renesas.com>
commit daa6d4617bee722e83f7d8584416e83b709c958a upstream.
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 <john.madieu.xa@bp.renesas.com>
Signed-off-by: Claudiu Beznea <claudiu.beznea.uj@bp.renesas.com>
Tested-by: Tommaso Merciai <tommaso.merciai.xr@bp.renesas.com>
Link: https://patch.msgid.link/20260526084710.3491480-10-claudiu.beznea@kernel.org
Signed-off-by: Vinod Koul <vkoul@kernel.org>
Signed-off-by: Tommaso Merciai <tommaso.merciai.xr@bp.renesas.com>
---
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 0ba6bc545e61..e6eeb4fa55c4 100644
--- a/drivers/dma/sh/rz-dmac.c
+++ b/drivers/dma/sh/rz-dmac.c
@@ -78,8 +78,6 @@ struct rz_dmac_chan {
int mid_rid;
struct list_head ld_free;
- struct list_head ld_queue;
- struct list_head ld_active;
struct {
struct rz_lmdesc *base;
@@ -298,7 +296,6 @@ static void rz_dmac_enable_hw(struct rz_dmac_chan *channel)
struct rz_dmac *dmac = to_rz_dmac(chan->device);
u32 nxla;
u32 chctrl;
- u32 chstat;
dev_dbg(dmac->dev, "%s channel %d\n", __func__, channel->index);
@@ -306,14 +303,11 @@ static void rz_dmac_enable_hw(struct rz_dmac_chan *channel)
nxla = rz_dmac_lmdesc_addr(channel, channel->lmdesc.head);
- chstat = rz_dmac_ch_readl(channel, CHSTAT, 1);
- if (!(chstat & CHSTAT_EN)) {
- chctrl = (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 = (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);
}
static void rz_dmac_disable_hw(struct rz_dmac_chan *channel)
@@ -425,18 +419,20 @@ static void rz_dmac_prepare_descs_for_slave_sg(struct rz_dmac_chan *channel)
channel->chctrl = CHCTRL_SETEN;
}
-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 = chan->desc;
struct virt_dma_desc *vd;
vd = vchan_next_desc(&chan->vc);
- if (!vd)
- return 0;
+ if (!vd) {
+ chan->desc = NULL;
+ return;
+ }
list_del(&vd->node);
+ chan->desc = to_rz_dmac_desc(vd);
- switch (d->type) {
+ switch (chan->desc->type) {
case RZ_DMAC_DESC_MEMCPY:
rz_dmac_prepare_desc_for_memcpy(chan);
break;
@@ -444,14 +440,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;
}
rz_dmac_enable_hw(chan);
-
- return 0;
}
/*
@@ -493,8 +484,6 @@ static void rz_dmac_free_chan_resources(struct dma_chan *chan)
rz_lmdesc_setup(channel, channel->lmdesc.base);
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);
if (channel->mid_rid >= 0) {
clear_bit(channel->mid_rid, dmac->modules);
@@ -503,13 +492,19 @@ static void rz_dmac_free_chan_resources(struct dma_chan *chan)
spin_unlock_irqrestore(&channel->vc.lock, flags);
+ 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--;
}
INIT_LIST_HEAD(&channel->ld_free);
- vchan_free_chan_resources(&channel->vc);
+
+ spin_unlock_irqrestore(&channel->vc.lock, flags);
}
static struct dma_async_tx_descriptor *
@@ -528,15 +523,15 @@ rz_dmac_prep_dma_memcpy(struct dma_chan *chan, dma_addr_t dest, dma_addr_t src,
if (!desc)
return NULL;
- desc->type = RZ_DMAC_DESC_MEMCPY;
- desc->src = src;
- desc->dest = dest;
- desc->len = len;
- desc->direction = DMA_MEM_TO_MEM;
-
- list_move_tail(channel->ld_free.next, &channel->ld_queue);
+ list_del(&desc->node);
}
+ desc->type = RZ_DMAC_DESC_MEMCPY;
+ desc->src = src;
+ desc->dest = dest;
+ desc->len = len;
+ desc->direction = DMA_MEM_TO_MEM;
+
return vchan_tx_prep(&channel->vc, &desc->vd, flags);
}
@@ -557,22 +552,22 @@ rz_dmac_prep_slave_sg(struct dma_chan *chan, struct scatterlist *sgl,
if (!desc)
return NULL;
- for_each_sg(sgl, sg, sg_len, i)
- dma_length += sg_dma_len(sg);
+ list_del(&desc->node);
+ }
- desc->type = RZ_DMAC_DESC_SLAVE_SG;
- desc->sg = sgl;
- desc->sgcount = sg_len;
- desc->len = dma_length;
- desc->direction = direction;
+ for_each_sg(sgl, sg, sg_len, i)
+ dma_length += sg_dma_len(sg);
- if (direction == DMA_DEV_TO_MEM)
- desc->src = channel->src_per_address;
- else
- desc->dest = channel->dst_per_address;
+ desc->type = RZ_DMAC_DESC_SLAVE_SG;
+ desc->sg = sgl;
+ desc->sgcount = sg_len;
+ desc->len = dma_length;
+ desc->direction = direction;
- list_move_tail(channel->ld_free.next, &channel->ld_queue);
- }
+ if (direction == DMA_DEV_TO_MEM)
+ desc->src = channel->src_per_address;
+ else
+ desc->dest = channel->dst_per_address;
return vchan_tx_prep(&channel->vc, &desc->vd, flags);
}
@@ -587,8 +582,11 @@ static int rz_dmac_terminate_all(struct dma_chan *chan)
rz_dmac_disable_hw(channel);
rz_lmdesc_setup(channel, channel->lmdesc.base);
- 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 = NULL;
+ }
+
vchan_get_all_descriptors(&channel->vc, &head);
spin_unlock_irqrestore(&channel->vc.lock, flags);
vchan_dma_desc_free_list(&channel->vc, &head);
@@ -599,25 +597,16 @@ static int rz_dmac_terminate_all(struct dma_chan *chan)
static void rz_dmac_issue_pending(struct dma_chan *chan)
{
struct rz_dmac_chan *channel = to_rz_dmac_chan(chan);
- struct rz_dmac *dmac = to_rz_dmac(chan->device);
- struct rz_dmac_desc *desc;
unsigned long flags;
spin_lock_irqsave(&channel->vc.lock, flags);
- if (!list_empty(&channel->ld_queue)) {
- desc = list_first_entry(&channel->ld_queue,
- struct rz_dmac_desc, node);
- channel->desc = 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);
spin_unlock_irqrestore(&channel->vc.lock, flags);
}
@@ -675,13 +664,13 @@ static int rz_dmac_config(struct dma_chan *chan,
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 = to_rz_dmac_chan(vd->tx.chan);
+ struct virt_dma_chan *vc = to_virt_chan(vd->tx.chan);
+ struct rz_dmac_desc *desc = to_rz_dmac_desc(vd);
+
+ guard(spinlock_irqsave)(&vc->lock);
+
+ list_add_tail(&desc->node, &channel->ld_free);
}
static void rz_dmac_device_synchronize(struct dma_chan *chan)
@@ -691,6 +680,8 @@ static void rz_dmac_device_synchronize(struct dma_chan *chan)
u32 chstat;
int ret;
+ vchan_synchronize(&channel->vc);
+
ret = read_poll_timeout(rz_dmac_ch_readl, chstat, !(chstat & CHSTAT_EN),
100, 100000, false, channel, CHSTAT, 1);
if (ret < 0)
@@ -738,58 +729,22 @@ static u32 rz_dmac_calculate_residue_bytes_in_vd(struct 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 = NULL;
+ struct virt_dma_desc *vd;
u32 crla, crtb, i;
- /* Get current processing virtual descriptor */
- current_desc = 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 = dma_cookie_status(&channel->vc.chan, cookie, NULL);
- if (status == 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 != current_desc->vd.tx.cookie) {
- list_for_each_entry(desc, &channel->ld_free, node) {
- if (cookie == desc->vd.tx.cookie)
- return 0;
- }
-
- list_for_each_entry(desc, &channel->ld_queue, node) {
- if (cookie == desc->vd.tx.cookie)
- return desc->len;
- }
-
- list_for_each_entry(desc, &channel->ld_active, node) {
- if (cookie == desc->vd.tx.cookie)
- return desc->len;
- }
+ vd = vchan_find_desc(&channel->vc, cookie);
+ if (vd) {
+ /* Descriptor has been issued but not yet processed. */
+ desc = to_rz_dmac_desc(vd);
+ return desc->len;
+ } else if (channel->desc && channel->desc->vd.tx.cookie == cookie) {
+ /* Descriptor is currently processed. */
+ desc = channel->desc;
+ }
- /*
- * 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;
}
@@ -812,7 +767,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);
}
static enum dma_status rz_dmac_tx_status(struct dma_chan *chan,
@@ -823,21 +778,17 @@ static enum dma_status rz_dmac_tx_status(struct dma_chan *chan,
enum dma_status status;
u32 residue;
- status = dma_cookie_status(chan, cookie, txstate);
- if (status == DMA_COMPLETE || !txstate)
- return status;
-
scoped_guard(spinlock_irqsave, &channel->vc.lock) {
+ status = dma_cookie_status(chan, cookie, txstate);
+ if (status == DMA_COMPLETE || !txstate)
+ return status;
+
residue = rz_dmac_chan_get_residue(channel, cookie);
- if (rz_dmac_chan_is_paused(channel))
+ if (status == DMA_IN_PROGRESS && rz_dmac_chan_is_paused(channel))
status = DMA_PAUSED;
}
- /* if there's no residue and no paused, the cookie is complete */
- if (!residue && status != DMA_PAUSED)
- return DMA_COMPLETE;
-
dma_set_residue(txstate, residue);
return status;
@@ -917,28 +868,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 = dev_id;
- struct rz_dmac_desc *desc = NULL;
- unsigned long flags;
+ struct rz_dmac_desc *desc;
- spin_lock_irqsave(&channel->vc.lock, flags);
+ guard(spinlock_irqsave)(&channel->vc.lock);
- if (list_empty(&channel->ld_active)) {
- /* Someone might have called terminate all */
- goto out;
- }
+ desc = channel->desc;
+ if (!desc)
+ return IRQ_HANDLED;
- desc = 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 = list_first_entry(&channel->ld_queue, struct rz_dmac_desc,
- node);
- channel->desc = desc;
- if (rz_dmac_xfer_desc(channel) == 0)
- list_move_tail(channel->ld_queue.next, &channel->ld_active);
- }
-out:
- spin_unlock_irqrestore(&channel->vc.lock, flags);
+ channel->desc = NULL;
+
+ rz_dmac_xfer_desc(channel);
return IRQ_HANDLED;
}
@@ -1020,9 +961,7 @@ static int rz_dmac_chan_probe(struct rz_dmac *dmac,
channel->vc.desc_free = 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);
/* Initialize register for each channel */
rz_dmac_disable_hw(channel);
--
2.54.0
^ permalink raw reply related [flat|nested] 30+ messages in thread
* [PATCH 6.1.y-cip 20/27] dmaengine: sh: rz-dmac: Refactor pause/resume code
2026-11-26 15:47 [PATCH 6.1.y-cip 00/27] Renesas: Backport DMA fixes and improvements Tommaso Merciai
` (18 preceding siblings ...)
2026-11-26 15:47 ` [PATCH 6.1.y-cip 19/27] dmaengine: sh: rz-dmac: Use virt-dma APIs for channel descriptor processing Tommaso Merciai
@ 2026-11-26 15:47 ` Tommaso Merciai
2026-11-26 15:47 ` [PATCH 6.1.y-cip 21/27] dmaengine: sh: rz-dmac: Drop the update of channel->chctrl with CHCTRL_SETEN Tommaso Merciai
` (8 subsequent siblings)
28 siblings, 0 replies; 30+ messages in thread
From: Tommaso Merciai @ 2026-11-26 15:47 UTC (permalink / raw)
To: cip-dev, Nobuhiro Iwamatsu, Pavel Machek
Cc: Biju Das, Lad Prabhakar, tomm.merciai
From: Claudiu Beznea <claudiu.beznea.uj@bp.renesas.com>
commit dc86e47ca9b1021e258c366a5a9aa15d71c814a5 upstream.
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 <john.madieu.xa@bp.renesas.com>
Signed-off-by: Claudiu Beznea <claudiu.beznea.uj@bp.renesas.com>
Tested-by: Tommaso Merciai <tommaso.merciai.xr@bp.renesas.com>
Link: https://patch.msgid.link/20260526084710.3491480-11-claudiu.beznea@kernel.org
Signed-off-by: Vinod Koul <vkoul@kernel.org>
Signed-off-by: Tommaso Merciai <tommaso.merciai.xr@bp.renesas.com>
---
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 e6eeb4fa55c4..f96d1ce45271 100644
--- a/drivers/dma/sh/rz-dmac.c
+++ b/drivers/dma/sh/rz-dmac.c
@@ -17,6 +17,7 @@
#include <linux/iopoll.h>
#include <linux/irqchip/irq-renesas-rzv2h.h>
#include <linux/list.h>
+#include <linux/lockdep.h>
#include <linux/module.h>
#include <linux/of.h>
#include <linux/of_dma.h>
@@ -62,6 +63,14 @@ struct rz_dmac_desc {
#define to_rz_dmac_desc(d) container_of(d, struct rz_dmac_desc, vd)
+/**
+ * enum rz_dmac_chan_status: RZ DMAC channel status
+ * @RZ_DMAC_CHAN_STATUS_PAUSED: Channel is paused though DMA engine callbacks
+ */
+enum rz_dmac_chan_status {
+ RZ_DMAC_CHAN_STATUS_PAUSED,
+};
+
struct rz_dmac_chan {
struct virt_dma_chan vc;
void __iomem *ch_base;
@@ -73,6 +82,8 @@ struct rz_dmac_chan {
dma_addr_t src_per_address;
dma_addr_t dst_per_address;
+ unsigned long status;
+
u32 chcfg;
u32 chctrl;
int mid_rid;
@@ -490,6 +501,8 @@ static void rz_dmac_free_chan_resources(struct dma_chan *chan)
channel->mid_rid = -EINVAL;
}
+ channel->status = 0;
+
spin_unlock_irqrestore(&channel->vc.lock, flags);
vchan_free_chan_resources(&channel->vc);
@@ -588,6 +601,9 @@ static int rz_dmac_terminate_all(struct dma_chan *chan)
}
vchan_get_all_descriptors(&channel->vc, &head);
+
+ channel->status = 0;
+
spin_unlock_irqrestore(&channel->vc.lock, flags);
vchan_dma_desc_free_list(&channel->vc, &head);
@@ -794,35 +810,70 @@ static enum dma_status rz_dmac_tx_status(struct dma_chan *chan,
return status;
}
-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 = to_rz_dmac_chan(chan);
+ int ret = 0;
u32 val;
- guard(spinlock_irqsave)(&channel->vc.lock);
+ lockdep_assert_held(&channel->vc.lock);
if (!rz_dmac_chan_is_enabled(channel))
return 0;
+ 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 = read_poll_timeout_atomic(rz_dmac_ch_readl, val,
+ (val & CHSTAT_SUS), 1, 1024, false,
+ channel, CHSTAT, 1);
+
+set_bit:
+ channel->status |= set_bitmask;
+
+ return ret;
}
-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 = to_rz_dmac_chan(chan);
- u32 val;
guard(spinlock_irqsave)(&channel->vc.lock);
+ 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 = 0;
+ u32 val;
+
+ lockdep_assert_held(&channel->vc.lock);
+
/* Do not check CHSTAT_SUS but rely on HW capabilities. */
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 = read_poll_timeout_atomic(rz_dmac_ch_readl, val,
+ !(val & CHSTAT_SUS), 1, 1024, false,
+ channel, CHSTAT, 1);
+
+ channel->status &= ~clear_bitmask;
+
+ return ret;
+}
+
+static int rz_dmac_device_resume(struct dma_chan *chan)
+{
+ struct rz_dmac_chan *channel = 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));
}
/*
--
2.54.0
^ permalink raw reply related [flat|nested] 30+ messages in thread
* [PATCH 6.1.y-cip 21/27] dmaengine: sh: rz-dmac: Drop the update of channel->chctrl with CHCTRL_SETEN
2026-11-26 15:47 [PATCH 6.1.y-cip 00/27] Renesas: Backport DMA fixes and improvements Tommaso Merciai
` (19 preceding siblings ...)
2026-11-26 15:47 ` [PATCH 6.1.y-cip 20/27] dmaengine: sh: rz-dmac: Refactor pause/resume code Tommaso Merciai
@ 2026-11-26 15:47 ` Tommaso Merciai
2026-11-26 15:47 ` [PATCH 6.1.y-cip 22/27] dmaengine: sh: rz-dmac: Add cyclic DMA support Tommaso Merciai
` (7 subsequent siblings)
28 siblings, 0 replies; 30+ messages in thread
From: Tommaso Merciai @ 2026-11-26 15:47 UTC (permalink / raw)
To: cip-dev, Nobuhiro Iwamatsu, Pavel Machek
Cc: Biju Das, Lad Prabhakar, tomm.merciai
From: Claudiu Beznea <claudiu.beznea.uj@bp.renesas.com>
commit e8baee1d1cddc8e2be7bc362d6dc3fcb2021e873 upstream.
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 <Frank.Li@nxp.com>
Tested-by: John Madieu <john.madieu.xa@bp.renesas.com>
Signed-off-by: Claudiu Beznea <claudiu.beznea.uj@bp.renesas.com>
Tested-by: Tommaso Merciai <tommaso.merciai.xr@bp.renesas.com>
Link: https://patch.msgid.link/20260526084710.3491480-12-claudiu.beznea@kernel.org
Signed-off-by: Vinod Koul <vkoul@kernel.org>
Signed-off-by: Tommaso Merciai <tommaso.merciai.xr@bp.renesas.com>
---
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 f96d1ce45271..1ebac606bb4b 100644
--- a/drivers/dma/sh/rz-dmac.c
+++ b/drivers/dma/sh/rz-dmac.c
@@ -376,7 +376,7 @@ static void rz_dmac_prepare_desc_for_memcpy(struct rz_dmac_chan *channel)
rz_dmac_set_dma_req_no(dmac, channel->index, dmac->info->default_dma_req_no);
channel->chcfg = chcfg;
- channel->chctrl = CHCTRL_STG | CHCTRL_SETEN;
+ channel->chctrl = CHCTRL_STG;
}
static void rz_dmac_prepare_descs_for_slave_sg(struct rz_dmac_chan *channel)
@@ -427,7 +427,7 @@ static void rz_dmac_prepare_descs_for_slave_sg(struct rz_dmac_chan *channel)
rz_dmac_set_dma_req_no(dmac, channel->index, channel->mid_rid);
- channel->chctrl = CHCTRL_SETEN;
+ channel->chctrl = 0;
}
static void rz_dmac_xfer_desc(struct rz_dmac_chan *chan)
--
2.54.0
^ permalink raw reply related [flat|nested] 30+ messages in thread
* [PATCH 6.1.y-cip 22/27] dmaengine: sh: rz-dmac: Add cyclic DMA support
2026-11-26 15:47 [PATCH 6.1.y-cip 00/27] Renesas: Backport DMA fixes and improvements Tommaso Merciai
` (20 preceding siblings ...)
2026-11-26 15:47 ` [PATCH 6.1.y-cip 21/27] dmaengine: sh: rz-dmac: Drop the update of channel->chctrl with CHCTRL_SETEN Tommaso Merciai
@ 2026-11-26 15:47 ` Tommaso Merciai
2026-11-26 15:47 ` [PATCH 6.1.y-cip 23/27] dmaengine: sh: rz-dmac: Adjust rz_dmac_chan_get_residue() to return error codes Tommaso Merciai
` (6 subsequent siblings)
28 siblings, 0 replies; 30+ messages in thread
From: Tommaso Merciai @ 2026-11-26 15:47 UTC (permalink / raw)
To: cip-dev, Nobuhiro Iwamatsu, Pavel Machek
Cc: Biju Das, Lad Prabhakar, tomm.merciai
From: Claudiu Beznea <claudiu.beznea.uj@bp.renesas.com>
commit 172bfb57481c65fcc94ebcae3a730f6df2f953d4 upstream.
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 <john.madieu.xa@bp.renesas.com>
Signed-off-by: Claudiu Beznea <claudiu.beznea.uj@bp.renesas.com>
Tested-by: Tommaso Merciai <tommaso.merciai.xr@bp.renesas.com>
Link: https://patch.msgid.link/20260526084710.3491480-13-claudiu.beznea@kernel.org
Signed-off-by: Vinod Koul <vkoul@kernel.org>
Signed-off-by: Tommaso Merciai <tommaso.merciai.xr@bp.renesas.com>
---
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 1ebac606bb4b..d332907901d1 100644
--- a/drivers/dma/sh/rz-dmac.c
+++ b/drivers/dma/sh/rz-dmac.c
@@ -34,6 +34,7 @@
enum rz_dmac_prep_type {
RZ_DMAC_DESC_MEMCPY,
RZ_DMAC_DESC_SLAVE_SG,
+ RZ_DMAC_DESC_CYCLIC,
};
struct rz_lmdesc {
@@ -66,9 +67,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 callbacks
+ * @RZ_DMAC_CHAN_STATUS_CYCLIC: Channel is cyclic
*/
enum rz_dmac_chan_status {
RZ_DMAC_CHAN_STATUS_PAUSED,
+ RZ_DMAC_CHAN_STATUS_CYCLIC,
};
struct rz_dmac_chan {
@@ -190,6 +193,7 @@ struct rz_dmac {
/* LINK MODE DESCRIPTOR */
#define HEADER_LV BIT(0)
+#define HEADER_WBD BIT(2)
#define RZ_DMAC_MAX_CHAN_DESCRIPTORS 16
#define RZ_DMAC_MAX_CHANNELS 16
@@ -430,6 +434,57 @@ static void rz_dmac_prepare_descs_for_slave_sg(struct rz_dmac_chan *channel)
channel->chctrl = 0;
}
+static void rz_dmac_prepare_descs_for_cyclic(struct rz_dmac_chan *channel)
+{
+ struct dma_chan *chan = &channel->vc.chan;
+ struct rz_dmac *dmac = to_rz_dmac(chan->device);
+ struct rz_dmac_desc *d = channel->desc;
+ size_t period_len = d->sgcount;
+ struct rz_lmdesc *lmdesc;
+ size_t buf_len = d->len;
+ size_t periods = buf_len / period_len;
+
+ lockdep_assert_held(&channel->vc.lock);
+
+ channel->chcfg |= CHCFG_SEL(channel->index) | CHCFG_DMS;
+
+ if (d->direction == DMA_DEV_TO_MEM) {
+ channel->chcfg |= CHCFG_SAD;
+ channel->chcfg &= ~CHCFG_REQD;
+ } else {
+ channel->chcfg |= CHCFG_DAD | CHCFG_REQD;
+ }
+
+ lmdesc = channel->lmdesc.tail;
+ d->start_lmdesc = lmdesc;
+
+ for (size_t i = 0; i < periods; i++) {
+ if (d->direction == DMA_DEV_TO_MEM) {
+ lmdesc->sa = d->src;
+ lmdesc->da = d->dest + (i * period_len);
+ } else {
+ lmdesc->sa = d->src + (i * period_len);
+ lmdesc->da = d->dest;
+ }
+
+ lmdesc->tb = period_len;
+ lmdesc->chitvl = 0;
+ lmdesc->chext = 0;
+ lmdesc->chcfg = channel->chcfg;
+ lmdesc->header = HEADER_LV | HEADER_WBD;
+
+ if (i == periods - 1)
+ lmdesc->nxla = rz_dmac_lmdesc_addr(channel, d->start_lmdesc);
+
+ if (++lmdesc >= (channel->lmdesc.base + DMAC_NR_LMDESC))
+ lmdesc = channel->lmdesc.base;
+ }
+
+ channel->lmdesc.tail = 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;
@@ -451,6 +506,10 @@ static void rz_dmac_xfer_desc(struct rz_dmac_chan *chan)
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;
}
rz_dmac_enable_hw(chan);
@@ -585,6 +644,55 @@ rz_dmac_prep_slave_sg(struct dma_chan *chan, struct scatterlist *sgl,
return vchan_tx_prep(&channel->vc, &desc->vd, flags);
}
+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 = 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 = 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 = list_first_entry_or_null(&channel->ld_free, struct rz_dmac_desc, node);
+ if (!desc)
+ return NULL;
+
+ list_del(&desc->node);
+
+ channel->status |= BIT(RZ_DMAC_CHAN_STATUS_CYCLIC);
+ }
+
+ desc->type = RZ_DMAC_DESC_CYCLIC;
+ desc->sgcount = period_len;
+ desc->len = buf_len;
+ desc->direction = direction;
+
+ if (direction == DMA_DEV_TO_MEM) {
+ desc->src = channel->src_per_address;
+ desc->dest = buf_addr;
+ } else {
+ desc->src = buf_addr;
+ desc->dest = 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 = to_rz_dmac_chan(chan);
@@ -732,9 +840,18 @@ static u32 rz_dmac_calculate_residue_bytes_in_vd(struct rz_dmac_chan *channel,
}
/* Calculate residue from next lmdesc to end of virtual desc */
- while (lmdesc->chcfg & CHCFG_DEM) {
- residue += lmdesc->tb;
- lmdesc = rz_dmac_get_next_lmdesc(channel->lmdesc.base, lmdesc);
+ if (channel->status & BIT(RZ_DMAC_CHAN_STATUS_CYCLIC)) {
+ u32 start_lmdesc_addr = rz_dmac_lmdesc_addr(channel, desc->start_lmdesc);
+
+ while (lmdesc->nxla != start_lmdesc_addr) {
+ residue += lmdesc->tb;
+ lmdesc = rz_dmac_get_next_lmdesc(channel->lmdesc.base, lmdesc);
+ }
+ } else {
+ while (lmdesc->chcfg & CHCFG_DEM) {
+ residue += lmdesc->tb;
+ lmdesc = rz_dmac_get_next_lmdesc(channel->lmdesc.base, lmdesc);
+ }
}
dev_dbg(dmac->dev, "%s: VD residue is %u\n", __func__, residue);
@@ -927,10 +1044,14 @@ static irqreturn_t rz_dmac_irq_handler_thread(int irq, void *dev_id)
if (!desc)
return IRQ_HANDLED;
- vchan_cookie_complete(&desc->vd);
- channel->desc = NULL;
+ if (channel->status & BIT(RZ_DMAC_CHAN_STATUS_CYCLIC)) {
+ vchan_cyclic_callback(&desc->vd);
+ } else {
+ vchan_cookie_complete(&desc->vd);
+ channel->desc = NULL;
- rz_dmac_xfer_desc(channel);
+ rz_dmac_xfer_desc(channel);
+ }
return IRQ_HANDLED;
}
@@ -1182,6 +1303,8 @@ static int rz_dmac_probe(struct platform_device *pdev)
engine = &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 = BIT(DMA_DEV_TO_MEM) | BIT(DMA_MEM_TO_DEV);
engine->residue_granularity = 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);
@@ -1193,6 +1316,7 @@ static int rz_dmac_probe(struct platform_device *pdev)
engine->device_tx_status = rz_dmac_tx_status;
engine->device_prep_slave_sg = rz_dmac_prep_slave_sg;
engine->device_prep_dma_memcpy = rz_dmac_prep_dma_memcpy;
+ engine->device_prep_dma_cyclic = rz_dmac_prep_dma_cyclic;
engine->device_config = rz_dmac_config;
engine->device_terminate_all = rz_dmac_terminate_all;
engine->device_issue_pending = rz_dmac_issue_pending;
--
2.54.0
^ permalink raw reply related [flat|nested] 30+ messages in thread
* [PATCH 6.1.y-cip 23/27] dmaengine: sh: rz-dmac: Adjust rz_dmac_chan_get_residue() to return error codes
2026-11-26 15:47 [PATCH 6.1.y-cip 00/27] Renesas: Backport DMA fixes and improvements Tommaso Merciai
` (21 preceding siblings ...)
2026-11-26 15:47 ` [PATCH 6.1.y-cip 22/27] dmaengine: sh: rz-dmac: Add cyclic DMA support Tommaso Merciai
@ 2026-11-26 15:47 ` Tommaso Merciai
2026-11-26 15:47 ` [PATCH 6.1.y-cip 24/27] dmaengine: sh: rz-dmac: Add runtime PM support Tommaso Merciai
` (5 subsequent siblings)
28 siblings, 0 replies; 30+ messages in thread
From: Tommaso Merciai @ 2026-11-26 15:47 UTC (permalink / raw)
To: cip-dev, Nobuhiro Iwamatsu, Pavel Machek
Cc: Biju Das, Lad Prabhakar, tomm.merciai
From: Claudiu Beznea <claudiu.beznea.uj@bp.renesas.com>
commit 16ba40151b1e6a52b28296a2173457bc6c31f022 upstream.
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 <claudiu.beznea.uj@bp.renesas.com>
Tested-by: Tommaso Merciai <tommaso.merciai.xr@bp.renesas.com>
Link: https://patch.msgid.link/20260526084710.3491480-14-claudiu.beznea@kernel.org
Signed-off-by: Vinod Koul <vkoul@kernel.org>
Signed-off-by: Tommaso Merciai <tommaso.merciai.xr@bp.renesas.com>
---
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 d332907901d1..7b79795a54d9 100644
--- a/drivers/dma/sh/rz-dmac.c
+++ b/drivers/dma/sh/rz-dmac.c
@@ -859,8 +859,8 @@ static u32 rz_dmac_calculate_residue_bytes_in_vd(struct rz_dmac_chan *channel,
return residue;
}
-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_chan *channel,
+ dma_cookie_t cookie, u32 *residue)
{
struct rz_dmac_desc *desc = NULL;
struct virt_dma_desc *vd;
@@ -870,7 +870,8 @@ static u32 rz_dmac_chan_get_residue(struct rz_dmac_chan *channel,
if (vd) {
/* Descriptor has been issued but not yet processed. */
desc = to_rz_dmac_desc(vd);
- return desc->len;
+ *residue = desc->len;
+ return 0;
} else if (channel->desc && channel->desc->vd.tx.cookie == cookie) {
/* Descriptor is currently processed. */
desc = channel->desc;
@@ -878,6 +879,7 @@ static u32 rz_dmac_chan_get_residue(struct rz_dmac_chan *channel,
if (!desc) {
/* Descriptor was not found. May be already completed by now. */
+ *residue = 0;
return 0;
}
@@ -900,7 +902,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 = crtb + rz_dmac_calculate_residue_bytes_in_vd(channel, desc, crla);
+
+ return 0;
}
static enum dma_status rz_dmac_tx_status(struct dma_chan *chan,
@@ -908,15 +912,20 @@ static enum dma_status rz_dmac_tx_status(struct dma_chan *chan,
struct dma_tx_state *txstate)
{
struct rz_dmac_chan *channel = to_rz_dmac_chan(chan);
+ struct rz_dmac *dmac = to_rz_dmac(chan->device);
enum dma_status status;
u32 residue;
scoped_guard(spinlock_irqsave, &channel->vc.lock) {
+ int ret;
+
status = dma_cookie_status(chan, cookie, txstate);
if (status == DMA_COMPLETE || !txstate)
return status;
- residue = rz_dmac_chan_get_residue(channel, cookie);
+ ret = rz_dmac_chan_get_residue(dmac->dev, channel, cookie, &residue);
+ if (ret)
+ return DMA_ERROR;
if (status == DMA_IN_PROGRESS && rz_dmac_chan_is_paused(channel))
status = DMA_PAUSED;
--
2.54.0
^ permalink raw reply related [flat|nested] 30+ messages in thread
* [PATCH 6.1.y-cip 24/27] dmaengine: sh: rz-dmac: Add runtime PM support
2026-11-26 15:47 [PATCH 6.1.y-cip 00/27] Renesas: Backport DMA fixes and improvements Tommaso Merciai
` (22 preceding siblings ...)
2026-11-26 15:47 ` [PATCH 6.1.y-cip 23/27] dmaengine: sh: rz-dmac: Adjust rz_dmac_chan_get_residue() to return error codes Tommaso Merciai
@ 2026-11-26 15:47 ` Tommaso Merciai
2026-11-26 15:47 ` [PATCH 6.1.y-cip 25/27] dmaengine: sh: rz-dmac: Add suspend to RAM support Tommaso Merciai
` (4 subsequent siblings)
28 siblings, 0 replies; 30+ messages in thread
From: Tommaso Merciai @ 2026-11-26 15:47 UTC (permalink / raw)
To: cip-dev, Nobuhiro Iwamatsu, Pavel Machek
Cc: Biju Das, Lad Prabhakar, tomm.merciai
From: Claudiu Beznea <claudiu.beznea.uj@bp.renesas.com>
commit 7c27a4d54d48d0774518390e4ce6cf3309aac141 upstream.
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 <john.madieu.xa@bp.renesas.com>
Signed-off-by: Claudiu Beznea <claudiu.beznea.uj@bp.renesas.com>
Tested-by: Tommaso Merciai <tommaso.merciai.xr@bp.renesas.com>
Link: https://patch.msgid.link/20260526084710.3491480-15-claudiu.beznea@kernel.org
Signed-off-by: Vinod Koul <vkoul@kernel.org>
[tm: Replaced PM_RUNTIME_ACQUIRE_IF_ENABLED()/PM_RUNTIME_ACQUIRE_ERR()
with the equivalent open-coded pm_runtime_resume_and_get()/
pm_runtime_put(), as the DEFINE_GUARD_COND()/ACQUIRE()/ACQUIRE_ERR()
infrastructure they rely on is not present in 6.1.y.
Converted the guard(spinlock_irqsave) in rz_dmac_device_pause()/
rz_dmac_device_resume() to explicit scoped_guard() section to preserve
the same release order (unlock before pm_runtime_put())]
Signed-off-by: Tommaso Merciai <tommaso.merciai.xr@bp.renesas.com>
---
drivers/dma/sh/rz-dmac.c | 86 +++++++++++++++++++++++++++++++++++-----
1 file changed, 77 insertions(+), 9 deletions(-)
diff --git a/drivers/dma/sh/rz-dmac.c b/drivers/dma/sh/rz-dmac.c
index 7b79795a54d9..90a8625f84b3 100644
--- a/drivers/dma/sh/rz-dmac.c
+++ b/drivers/dma/sh/rz-dmac.c
@@ -548,12 +548,21 @@ static void rz_dmac_free_chan_resources(struct dma_chan *chan)
struct rz_dmac *dmac = to_rz_dmac(chan->device);
struct rz_dmac_desc *desc, *_desc;
unsigned long flags;
+ int ret;
+
+ ret = pm_runtime_resume_and_get(dmac->dev);
+ if (ret) {
+ dev_err(dmac->dev, "RPM resume failed for channel %s, ret=%d\n!",
+ dma_chan_name(chan), ret);
+ }
spin_lock_irqsave(&channel->vc.lock, flags);
rz_lmdesc_setup(channel, channel->lmdesc.base);
- 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);
if (channel->mid_rid >= 0) {
clear_bit(channel->mid_rid, dmac->modules);
@@ -577,6 +586,9 @@ static void rz_dmac_free_chan_resources(struct dma_chan *chan)
INIT_LIST_HEAD(&channel->ld_free);
spin_unlock_irqrestore(&channel->vc.lock, flags);
+
+ if (!ret)
+ pm_runtime_put(dmac->dev);
}
static struct dma_async_tx_descriptor *
@@ -696,11 +708,21 @@ rz_dmac_prep_dma_cyclic(struct dma_chan *chan, dma_addr_t buf_addr,
static int rz_dmac_terminate_all(struct dma_chan *chan)
{
struct rz_dmac_chan *channel = to_rz_dmac_chan(chan);
+ struct rz_dmac *dmac = to_rz_dmac(chan->device);
unsigned long flags;
LIST_HEAD(head);
+ int ret;
+
+ ret = pm_runtime_resume_and_get(dmac->dev);
+ if (ret) {
+ dev_err(dmac->dev, "RPM resume failed for channel %s, ret=%d\n!",
+ dma_chan_name(chan), ret);
+ }
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);
if (channel->desc) {
@@ -715,13 +737,22 @@ static int rz_dmac_terminate_all(struct dma_chan *chan)
spin_unlock_irqrestore(&channel->vc.lock, flags);
vchan_dma_desc_free_list(&channel->vc, &head);
- return 0;
+ if (!ret)
+ pm_runtime_put(dmac->dev);
+
+ return ret;
}
static void rz_dmac_issue_pending(struct dma_chan *chan)
{
struct rz_dmac_chan *channel = to_rz_dmac_chan(chan);
+ struct rz_dmac *dmac = to_rz_dmac(chan->device);
unsigned long flags;
+ int ret;
+
+ ret = pm_runtime_resume_and_get(dmac->dev);
+ if (ret)
+ return;
spin_lock_irqsave(&channel->vc.lock, flags);
@@ -733,6 +764,8 @@ static void rz_dmac_issue_pending(struct dma_chan *chan)
rz_dmac_xfer_desc(channel);
spin_unlock_irqrestore(&channel->vc.lock, flags);
+
+ pm_runtime_put(dmac->dev);
}
static u8 rz_dmac_ds_to_val_mapping(enum dma_slave_buswidth ds)
@@ -806,12 +839,18 @@ static void rz_dmac_device_synchronize(struct dma_chan *chan)
vchan_synchronize(&channel->vc);
+ ret = pm_runtime_resume_and_get(dmac->dev);
+ if (ret)
+ return;
+
ret = read_poll_timeout(rz_dmac_ch_readl, chstat, !(chstat & CHSTAT_EN),
100, 100000, false, channel, CHSTAT, 1);
if (ret < 0)
dev_warn(dmac->dev, "DMA Timeout");
rz_dmac_set_dma_req_no(dmac, channel->index, dmac->info->default_dma_req_no);
+
+ pm_runtime_put(dmac->dev);
}
static struct rz_lmdesc *
@@ -865,6 +904,7 @@ static int rz_dmac_chan_get_residue(struct device *dev, struct rz_dmac_chan *cha
struct rz_dmac_desc *desc = NULL;
struct virt_dma_desc *vd;
u32 crla, crtb, i;
+ int ret;
vd = vchan_find_desc(&channel->vc, cookie);
if (vd) {
@@ -883,6 +923,10 @@ static int rz_dmac_chan_get_residue(struct device *dev, struct rz_dmac_chan *cha
return 0;
}
+ ret = pm_runtime_resume_and_get(dev);
+ 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
@@ -904,6 +948,8 @@ static int rz_dmac_chan_get_residue(struct device *dev, struct rz_dmac_chan *cha
*/
*residue = crtb + rz_dmac_calculate_residue_bytes_in_vd(channel, desc, crla);
+ pm_runtime_put(dev);
+
return 0;
}
@@ -964,10 +1010,21 @@ static int rz_dmac_device_pause_set(struct rz_dmac_chan *channel,
static int rz_dmac_device_pause(struct dma_chan *chan)
{
struct rz_dmac_chan *channel = to_rz_dmac_chan(chan);
+ struct rz_dmac *dmac = to_rz_dmac(chan->device);
+ int ret;
- guard(spinlock_irqsave)(&channel->vc.lock);
+ ret = pm_runtime_resume_and_get(dmac->dev);
+ if (ret)
+ return ret;
+
+ scoped_guard(spinlock_irqsave, &channel->vc.lock) {
+ ret = rz_dmac_device_pause_set(channel,
+ BIT(RZ_DMAC_CHAN_STATUS_PAUSED));
+ }
+
+ pm_runtime_put(dmac->dev);
- return rz_dmac_device_pause_set(channel, BIT(RZ_DMAC_CHAN_STATUS_PAUSED));
+ return ret;
}
static int rz_dmac_device_resume_set(struct rz_dmac_chan *channel,
@@ -993,13 +1050,23 @@ static int rz_dmac_device_resume_set(struct rz_dmac_chan *channel,
static int rz_dmac_device_resume(struct dma_chan *chan)
{
struct rz_dmac_chan *channel = to_rz_dmac_chan(chan);
+ struct rz_dmac *dmac = to_rz_dmac(chan->device);
+ int ret;
- guard(spinlock_irqsave)(&channel->vc.lock);
+ ret = pm_runtime_resume_and_get(dmac->dev);
+ if (ret)
+ return ret;
- if (!(channel->status & BIT(RZ_DMAC_CHAN_STATUS_PAUSED)))
- return 0;
+ scoped_guard(spinlock_irqsave, &channel->vc.lock) {
+ if (channel->status & BIT(RZ_DMAC_CHAN_STATUS_PAUSED)) {
+ ret = rz_dmac_device_resume_set(channel,
+ BIT(RZ_DMAC_CHAN_STATUS_PAUSED));
+ }
+ }
+
+ pm_runtime_put(dmac->dev);
- return rz_dmac_device_resume_set(channel, BIT(RZ_DMAC_CHAN_STATUS_PAUSED));
+ return ret;
}
/*
@@ -1273,6 +1340,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");
+ pm_runtime_irq_safe(&pdev->dev);
pm_runtime_enable(&pdev->dev);
ret = pm_runtime_resume_and_get(&pdev->dev);
if (ret < 0) {
--
2.54.0
^ permalink raw reply related [flat|nested] 30+ messages in thread
* [PATCH 6.1.y-cip 25/27] dmaengine: sh: rz-dmac: Add suspend to RAM support
2026-11-26 15:47 [PATCH 6.1.y-cip 00/27] Renesas: Backport DMA fixes and improvements Tommaso Merciai
` (23 preceding siblings ...)
2026-11-26 15:47 ` [PATCH 6.1.y-cip 24/27] dmaengine: sh: rz-dmac: Add runtime PM support Tommaso Merciai
@ 2026-11-26 15:47 ` Tommaso Merciai
2026-11-26 15:47 ` [PATCH 6.1.y-cip 26/27] dmaengine: sh: rz-dmac: Set the Link End (LE) bit on the last descriptor Tommaso Merciai
` (3 subsequent siblings)
28 siblings, 0 replies; 30+ messages in thread
From: Tommaso Merciai @ 2026-11-26 15:47 UTC (permalink / raw)
To: cip-dev, Nobuhiro Iwamatsu, Pavel Machek
Cc: Biju Das, Lad Prabhakar, tomm.merciai
From: Claudiu Beznea <claudiu.beznea.uj@bp.renesas.com>
commit c13ce43e70719dead7009e7e708971ba1c447568 upstream.
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 <john.madieu.xa@bp.renesas.com>
Signed-off-by: Claudiu Beznea <claudiu.beznea.uj@bp.renesas.com>
Tested-by: Tommaso Merciai <tommaso.merciai.xr@bp.renesas.com>
Link: https://patch.msgid.link/20260526084710.3491480-16-claudiu.beznea@kernel.org
Signed-off-by: Vinod Koul <vkoul@kernel.org>
[tm: Replaced PM_RUNTIME_ACQUIRE_IF_ENABLED()/PM_RUNTIME_ACQUIRE_ERR()
in rz_dmac_suspend_recover() with the equivalent open-coded
pm_runtime_resume_and_get()/pm_runtime_put(), as the
DEFINE_GUARD_COND()/ACQUIRE()/ACQUIRE_ERR() infrastructure they
rely on is not present in linux-6.1.y-cip]
Signed-off-by: Tommaso Merciai <tommaso.merciai.xr@bp.renesas.com>
---
drivers/dma/sh/rz-dmac.c | 181 +++++++++++++++++++++++++++++++++++++--
1 file changed, 176 insertions(+), 5 deletions(-)
diff --git a/drivers/dma/sh/rz-dmac.c b/drivers/dma/sh/rz-dmac.c
index 90a8625f84b3..351753dd5049 100644
--- a/drivers/dma/sh/rz-dmac.c
+++ b/drivers/dma/sh/rz-dmac.c
@@ -68,10 +68,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 callbacks
* @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,
};
struct rz_dmac_chan {
@@ -91,6 +93,10 @@ struct rz_dmac_chan {
u32 chctrl;
int mid_rid;
+ struct {
+ u32 nxla;
+ } pm_state;
+
struct list_head ld_free;
struct {
@@ -1027,20 +1033,57 @@ static int rz_dmac_device_pause(struct dma_chan *chan)
return ret;
}
+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_INTERNAL));
+}
+
static int rz_dmac_device_resume_set(struct rz_dmac_chan *channel,
unsigned long clear_bitmask)
{
- int ret = 0;
u32 val;
+ int ret;
lockdep_assert_held(&channel->vc.lock);
- /* 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);
- rz_dmac_ch_writel(channel, CHCTRL_CLRSUS, CHCTRL, 1);
ret = read_poll_timeout_atomic(rz_dmac_ch_readl, val,
- !(val & CHSTAT_SUS), 1, 1024, false,
- channel, CHSTAT, 1);
+ ((val & (CHSTAT_SUS | CHSTAT_EN)) == CHSTAT_EN),
+ 1, 1024, false, channel, CHSTAT, 1);
channel->status &= ~clear_bitmask;
@@ -1069,6 +1112,16 @@ static int rz_dmac_device_resume(struct dma_chan *chan)
return ret;
}
+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
@@ -1434,6 +1487,123 @@ static void rz_dmac_remove(struct platform_device *pdev)
pm_runtime_disable(&pdev->dev);
}
+static void rz_dmac_suspend_recover(struct rz_dmac *dmac)
+{
+ int ret;
+
+ ret = pm_runtime_resume_and_get(dmac->dev);
+ if (ret)
+ return;
+
+ for (unsigned int i = 0; i < dmac->n_channels; i++) {
+ struct rz_dmac_chan *channel = &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);
+ }
+
+ pm_runtime_put(dmac->dev);
+}
+
+static int rz_dmac_suspend(struct device *dev)
+{
+ struct rz_dmac *dmac = dev_get_drvdata(dev);
+ int ret = 0;
+
+ for (unsigned int i = 0; i < dmac->n_channels; i++) {
+ struct rz_dmac_chan *channel = &dmac->channels[i];
+
+ guard(spinlock_irqsave)(&channel->vc.lock);
+
+ if (!(channel->status & BIT(RZ_DMAC_CHAN_STATUS_CYCLIC)))
+ continue;
+
+ ret = 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 = rz_dmac_ch_readl(channel, NXLA, 1);
+ }
+
+ if (ret)
+ goto suspend_recover;
+
+ ret = reset_control_assert(dmac->rstc);
+ if (ret)
+ goto suspend_recover;
+
+ ret = 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 = dev_get_drvdata(dev);
+ int errors = 0, ret;
+
+ ret = pm_runtime_resume_and_get(dev);
+ if (ret)
+ return ret;
+
+ ret = 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 = 0; i < dmac->n_channels; i++) {
+ struct rz_dmac_chan *channel = &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 = rz_dmac_device_resume_internal(channel);
+ if (ret) {
+ errors = ret;
+ dev_err(dev, "Failed to resume channel %s, ret=%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_resume);
+
static const struct rz_dmac_info rz_dmac_v2h_info = {
.icu_register_dma_req = rzv2h_icu_register_dma_req,
.default_dma_req_no = RZV2H_ICU_DMAC_REQ_NO_DEFAULT,
@@ -1454,6 +1624,7 @@ static struct platform_driver rz_dmac_driver = {
.driver = {
.name = "rz-dmac",
.of_match_table = of_rz_dmac_match,
+ .pm = pm_ptr(&rz_dmac_pm_ops),
},
.probe = rz_dmac_probe,
.remove_new = rz_dmac_remove,
--
2.54.0
^ permalink raw reply related [flat|nested] 30+ messages in thread
* [PATCH 6.1.y-cip 26/27] dmaengine: sh: rz-dmac: Set the Link End (LE) bit on the last descriptor
2026-11-26 15:47 [PATCH 6.1.y-cip 00/27] Renesas: Backport DMA fixes and improvements Tommaso Merciai
` (24 preceding siblings ...)
2026-11-26 15:47 ` [PATCH 6.1.y-cip 25/27] dmaengine: sh: rz-dmac: Add suspend to RAM support Tommaso Merciai
@ 2026-11-26 15:47 ` Tommaso Merciai
2026-11-26 15:47 ` [PATCH 6.1.y-cip 27/27] dmaengine: sh: rz-dmac: Fix off-by-one in residue lmdesc lookup Tommaso Merciai
` (2 subsequent siblings)
28 siblings, 0 replies; 30+ messages in thread
From: Tommaso Merciai @ 2026-11-26 15:47 UTC (permalink / raw)
To: cip-dev, Nobuhiro Iwamatsu, Pavel Machek
Cc: Biju Das, Lad Prabhakar, tomm.merciai
From: Claudiu Beznea <claudiu.beznea.uj@bp.renesas.com>
commit cd2d36e8ae61832aaac3bddf5aafdab72821e6b9 upstream.
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 <john.madieu.xa@bp.renesas.com>
Signed-off-by: Claudiu Beznea <claudiu.beznea.uj@bp.renesas.com>
Tested-by: Tommaso Merciai <tommaso.merciai.xr@bp.renesas.com>
Link: https://patch.msgid.link/20260526084710.3491480-19-claudiu.beznea@kernel.org
Signed-off-by: Vinod Koul <vkoul@kernel.org>
Signed-off-by: Tommaso Merciai <tommaso.merciai.xr@bp.renesas.com>
---
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 351753dd5049..c72e76a1d926 100644
--- a/drivers/dma/sh/rz-dmac.c
+++ b/drivers/dma/sh/rz-dmac.c
@@ -199,6 +199,7 @@ struct rz_dmac {
/* LINK MODE DESCRIPTOR */
#define HEADER_LV BIT(0)
+#define HEADER_LE BIT(1)
#define HEADER_WBD BIT(2)
#define RZ_DMAC_MAX_CHAN_DESCRIPTORS 16
@@ -381,7 +382,7 @@ static void rz_dmac_prepare_desc_for_memcpy(struct rz_dmac_chan *channel)
lmdesc->chcfg = chcfg;
lmdesc->chitvl = 0;
lmdesc->chext = 0;
- lmdesc->header = HEADER_LV;
+ lmdesc->header = HEADER_LV | HEADER_LE;
rz_dmac_set_dma_req_no(dmac, channel->index, dmac->info->default_dma_req_no);
@@ -424,7 +425,7 @@ static void rz_dmac_prepare_descs_for_slave_sg(struct rz_dmac_chan *channel)
lmdesc->chext = 0;
if (i == (sg_len - 1)) {
lmdesc->chcfg = (channel->chcfg & ~CHCFG_DEM);
- lmdesc->header = HEADER_LV;
+ lmdesc->header = HEADER_LV | HEADER_LE;
} else {
lmdesc->chcfg = channel->chcfg;
lmdesc->header = HEADER_LV;
--
2.54.0
^ permalink raw reply related [flat|nested] 30+ messages in thread
* [PATCH 6.1.y-cip 27/27] dmaengine: sh: rz-dmac: Fix off-by-one in residue lmdesc lookup
2026-11-26 15:47 [PATCH 6.1.y-cip 00/27] Renesas: Backport DMA fixes and improvements Tommaso Merciai
` (25 preceding siblings ...)
2026-11-26 15:47 ` [PATCH 6.1.y-cip 26/27] dmaengine: sh: rz-dmac: Set the Link End (LE) bit on the last descriptor Tommaso Merciai
@ 2026-11-26 15:47 ` Tommaso Merciai
2026-11-30 22:18 ` [PATCH 6.1.y-cip 00/27] Renesas: Backport DMA fixes and improvements Pavel Machek
2026-12-01 12:34 ` Pavel Machek
28 siblings, 0 replies; 30+ messages in thread
From: Tommaso Merciai @ 2026-11-26 15:47 UTC (permalink / raw)
To: cip-dev, Nobuhiro Iwamatsu, Pavel Machek
Cc: Biju Das, Lad Prabhakar, tomm.merciai
commit 9db8e502b34bc1df8078abd0169a4fa0624de3bb upstream.
lmdesc->nxla is the address of the next descriptor, so comparing it
against CRLA, which is the address of the current descriptor,
finds the descriptor before the active one, not the active one.
The residue loops below then summed one lmdesc too many on top of
that.
Compare each descriptor's own address to CRLA instead, and add tb
after advancing to the next lmdesc.
Fixes: 21323b118c16 ("dmaengine: sh: rz-dmac: Add device_tx_status() callback")
Fixes: 172bfb57481c ("dmaengine: sh: rz-dmac: Add cyclic DMA support")
Cc: stable@vger.kernel.org
Suggested-by: Claudiu Beznea <claudiu.beznea.uj@bp.renesas.com>
Signed-off-by: Tommaso Merciai <tommaso.merciai.xr@bp.renesas.com>
Signed-off-by: Claudiu Beznea <claudiu.beznea.uj@bp.renesas.com>
Reviewed-by: Frank Li <Frank.Li@nxp.com>
Link: https://patch.msgid.link/20260922092037.224884-1-claudiu.beznea@kernel.org
Signed-off-by: Vinod Koul <vkoul@kernel.org>
Signed-off-by: Tommaso Merciai <tommaso.merciai.xr@bp.renesas.com>
---
drivers/dma/sh/rz-dmac.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/drivers/dma/sh/rz-dmac.c b/drivers/dma/sh/rz-dmac.c
index c72e76a1d926..681495c4f2c4 100644
--- a/drivers/dma/sh/rz-dmac.c
+++ b/drivers/dma/sh/rz-dmac.c
@@ -879,7 +879,7 @@ static u32 rz_dmac_calculate_residue_bytes_in_vd(struct rz_dmac_chan *channel,
struct rz_dmac *dmac = to_rz_dmac(chan->device);
u32 residue = 0, i = 0;
- while (lmdesc->nxla != crla) {
+ while (rz_dmac_lmdesc_addr(channel, lmdesc) != crla) {
lmdesc = rz_dmac_get_next_lmdesc(channel->lmdesc.base, lmdesc);
if (++i >= DMAC_NR_LMDESC)
return 0;
@@ -890,13 +890,13 @@ static u32 rz_dmac_calculate_residue_bytes_in_vd(struct rz_dmac_chan *channel,
u32 start_lmdesc_addr = rz_dmac_lmdesc_addr(channel, desc->start_lmdesc);
while (lmdesc->nxla != start_lmdesc_addr) {
- residue += lmdesc->tb;
lmdesc = rz_dmac_get_next_lmdesc(channel->lmdesc.base, lmdesc);
+ residue += lmdesc->tb;
}
} else {
while (lmdesc->chcfg & CHCFG_DEM) {
- residue += lmdesc->tb;
lmdesc = rz_dmac_get_next_lmdesc(channel->lmdesc.base, lmdesc);
+ residue += lmdesc->tb;
}
}
--
2.54.0
^ permalink raw reply related [flat|nested] 30+ messages in thread
* Re: [PATCH 6.1.y-cip 00/27] Renesas: Backport DMA fixes and improvements
2026-11-26 15:47 [PATCH 6.1.y-cip 00/27] Renesas: Backport DMA fixes and improvements Tommaso Merciai
` (26 preceding siblings ...)
2026-11-26 15:47 ` [PATCH 6.1.y-cip 27/27] dmaengine: sh: rz-dmac: Fix off-by-one in residue lmdesc lookup Tommaso Merciai
@ 2026-11-30 22:18 ` Pavel Machek
2026-12-01 12:34 ` Pavel Machek
28 siblings, 0 replies; 30+ messages in thread
From: Pavel Machek @ 2026-11-30 22:18 UTC (permalink / raw)
To: Tommaso Merciai
Cc: cip-dev, Nobuhiro Iwamatsu, Pavel Machek, Biju Das, Lad Prabhakar,
tomm.merciai
[-- Attachment #1: Type: text/plain, Size: 561 bytes --]
Hi!
> This series backports cyclic DMA, runtime PM and suspend to RAM
> along with preparatory and cleanup patches into linux-6.1.y-cip.
>
> This is the equivalent work done for linux-5.10.y-cip kernel [1].
>
> [1]
> https://lore.kernel.org/cip-dev/20261126152204.1297798-1-claudiu.beznea@tuxon.dev/T/#t
This looks okay to me.
Reviewed-by: Pavel Machek <pavel@nabladev.com>
I can apply the series if it passes testing and there are no other
comments.
Best regards,
Pavel
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: [PATCH 6.1.y-cip 00/27] Renesas: Backport DMA fixes and improvements
2026-11-26 15:47 [PATCH 6.1.y-cip 00/27] Renesas: Backport DMA fixes and improvements Tommaso Merciai
` (27 preceding siblings ...)
2026-11-30 22:18 ` [PATCH 6.1.y-cip 00/27] Renesas: Backport DMA fixes and improvements Pavel Machek
@ 2026-12-01 12:34 ` Pavel Machek
28 siblings, 0 replies; 30+ messages in thread
From: Pavel Machek @ 2026-12-01 12:34 UTC (permalink / raw)
To: Tommaso Merciai
Cc: cip-dev, Nobuhiro Iwamatsu, Pavel Machek, Biju Das, Lad Prabhakar,
tomm.merciai
[-- Attachment #1: Type: text/plain, Size: 269 bytes --]
Hi!
> This series backports cyclic DMA, runtime PM and suspend to RAM
> along with preparatory and cleanup patches into linux-6.1.y-cip.
>
> This is the equivalent work done for linux-5.10.y-cip kernel [1].
Thank you, applied.
Best regards,
Pavel
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]
^ permalink raw reply [flat|nested] 30+ messages in thread
end of thread, other threads:[~2026-12-01 12:34 UTC | newest]
Thread overview: 30+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-26 15:47 [PATCH 6.1.y-cip 00/27] Renesas: Backport DMA fixes and improvements Tommaso Merciai
2026-11-26 15:47 ` [PATCH 6.1.y-cip 01/27] dmaengine: sh: rz-dmac: Convert to platform remove callback returning void Tommaso Merciai
2026-11-26 15:47 ` [PATCH 6.1.y-cip 02/27] dmaengine: sh: rz-dmac: Avoid format-overflow warning Tommaso Merciai
2026-11-26 15:47 ` [PATCH 6.1.y-cip 03/27] dmaengine: sh: rz-dmac: Make channel irq local Tommaso Merciai
2026-11-26 15:47 ` [PATCH 6.1.y-cip 04/27] dmaengine: sh: rz_dmac: make error interrupt optional Tommaso Merciai
2026-11-26 15:47 ` [PATCH 6.1.y-cip 05/27] dmaengine: sh: rz_dmac: make register_dma_req() chip-specific Tommaso Merciai
2026-11-26 15:47 ` [PATCH 6.1.y-cip 06/27] dmaengine: sh: rz-dmac: Drop read of CHCTRL register Tommaso Merciai
2026-11-26 15:47 ` [PATCH 6.1.y-cip 07/27] dmaengine: sh: rz-dmac: Drop goto instruction and label Tommaso Merciai
2026-11-26 15:47 ` [PATCH 6.1.y-cip 08/27] dmaengine: sh: rz-dmac: Drop unnecessary local_irq_save() call Tommaso Merciai
2026-11-26 15:47 ` [PATCH 6.1.y-cip 09/27] dmaengine: sh: rz-dmac: Use rz_lmdesc_setup() to invalidate descriptors Tommaso Merciai
2026-11-26 15:47 ` [PATCH 6.1.y-cip 10/27] dmaengine: sh: rz-dmac: Add device_tx_status() callback Tommaso Merciai
2026-11-26 15:47 ` [PATCH 6.1.y-cip 11/27] dmaengine: sh: rz-dmac: Add device_{pause,resume}() callbacks Tommaso Merciai
2026-11-26 15:47 ` [PATCH 6.1.y-cip 12/27] dmaengine: sh: rz-dmac: Fix incorrect NULL check for list_first_entry() Tommaso Merciai
2026-11-26 15:47 ` [PATCH 6.1.y-cip 13/27] dmaengine: sh: rz-dmac: Use list_first_entry_or_null() Tommaso Merciai
2026-11-26 15:47 ` [PATCH 6.1.y-cip 14/27] dmaengine: sh: rz-dmac: Use rz_dmac_disable_hw() Tommaso Merciai
2026-11-26 15:47 ` [PATCH 6.1.y-cip 15/27] dmaengine: sh: rz-dmac: Add helper to compute the lmdesc address Tommaso Merciai
2026-11-26 15:47 ` [PATCH 6.1.y-cip 16/27] dmaengine: sh: rz-dmac: Save the start LM descriptor Tommaso Merciai
2026-11-26 15:47 ` [PATCH 6.1.y-cip 17/27] dmaengine: sh: rz-dmac: Add helper to check if the channel is enabled Tommaso Merciai
2026-11-26 15:47 ` [PATCH 6.1.y-cip 18/27] dmaengine: sh: rz-dmac: Add helper to check if the channel is paused Tommaso Merciai
2026-11-26 15:47 ` [PATCH 6.1.y-cip 19/27] dmaengine: sh: rz-dmac: Use virt-dma APIs for channel descriptor processing Tommaso Merciai
2026-11-26 15:47 ` [PATCH 6.1.y-cip 20/27] dmaengine: sh: rz-dmac: Refactor pause/resume code Tommaso Merciai
2026-11-26 15:47 ` [PATCH 6.1.y-cip 21/27] dmaengine: sh: rz-dmac: Drop the update of channel->chctrl with CHCTRL_SETEN Tommaso Merciai
2026-11-26 15:47 ` [PATCH 6.1.y-cip 22/27] dmaengine: sh: rz-dmac: Add cyclic DMA support Tommaso Merciai
2026-11-26 15:47 ` [PATCH 6.1.y-cip 23/27] dmaengine: sh: rz-dmac: Adjust rz_dmac_chan_get_residue() to return error codes Tommaso Merciai
2026-11-26 15:47 ` [PATCH 6.1.y-cip 24/27] dmaengine: sh: rz-dmac: Add runtime PM support Tommaso Merciai
2026-11-26 15:47 ` [PATCH 6.1.y-cip 25/27] dmaengine: sh: rz-dmac: Add suspend to RAM support Tommaso Merciai
2026-11-26 15:47 ` [PATCH 6.1.y-cip 26/27] dmaengine: sh: rz-dmac: Set the Link End (LE) bit on the last descriptor Tommaso Merciai
2026-11-26 15:47 ` [PATCH 6.1.y-cip 27/27] dmaengine: sh: rz-dmac: Fix off-by-one in residue lmdesc lookup Tommaso Merciai
2026-11-30 22:18 ` [PATCH 6.1.y-cip 00/27] Renesas: Backport DMA fixes and improvements Pavel Machek
2026-12-01 12:34 ` Pavel Machek
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox