mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Claudiu Beznea <claudiu.beznea@kernel.org>
To: Claudiu Beznea <claudiu.beznea.uj@bp.renesas.com>,
	vkoul@kernel.org, Frank.Li@kernel.org, lgirdwood@gmail.com,
	broonie@kernel.org, perex@perex.cz, tiwai@suse.com,
	biju.das.jz@bp.renesas.com,
	prabhakar.mahadev-lad.rj@bp.renesas.com, p.zabel@pengutronix.de,
	geert+renesas@glider.be, fabrizio.castro.jz@renesas.com,
	kuninori.morimoto.gx@renesas.com, long.luu.ur@renesas.com
Cc: dmaengine@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-sound@vger.kernel.org, linux-renesas-soc@vger.kernel.org
Subject: sashiko review (Re: [PATCH v5 14/17] dmaengine: sh: rz-dmac: Add suspend to RAM support)
Date: Mon, 25 May 2026 10:33:34 +0300	[thread overview]
Message-ID: <4c266a28-1d43-4453-a776-2c2f022f5c85@kernel.org> (raw)
In-Reply-To: <20260512121219.216159-15-claudiu.beznea.uj@bp.renesas.com>

 >commit 536ec6e9c07fa47423de7d20ebc829e45cbcedfb
 >Author: Claudiu Beznea <claudiu.beznea.uj@bp.renesas.com>
 >Subject: dmaengine: sh: rz-dmac: Add suspend to RAM support
 >This commit adds suspend to RAM support for the Renesas RZ/G3S SoC by
 >saving and restoring the DMA IP registers. It adds specific suspend and
 >resume handling for cyclic channels, and waits for non-cyclic channels
 >to finish before suspending.
 >> diff --git a/drivers/dma/sh/rz-dmac.c b/drivers/dma/sh/rz-dmac.c
 >> index df91657fd5e3d..b0a8590f4a9da 100644
 >> --- a/drivers/dma/sh/rz-dmac.c
 >> +++ b/drivers/dma/sh/rz-dmac.c
 >[ ... ]
 >> @@ -1002,20 +1008,57 @@ static int rz_dmac_device_pause(struct dma_chan *chan)
 >>      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;
 >> +    int ret;
 >>
 >>      lockdep_assert_held(&channel->vc.lock);
 >>
 >[ ... ]
 >> +    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);
 >Can this condition time out spuriously for short non-cyclic DMA transfers? If
 >a transfer finishes successfully before the first poll read, the hardware
 >would clear CHSTAT_EN to 0. The polling condition would then evaluate to
 >false, causing the macro to incorrectly return -ETIMEDOUT.

Yes, in theory that can happen.

 >>
 >>      channel->status &= ~clear_bitmask;
 >>
 >[ ... ]
 >> @@ -1406,6 +1459,151 @@ static void rz_dmac_remove(struct platform_device *pdev)
 >>      pm_runtime_disable(&pdev->dev);
 >>  }
 >>
 >> +static int rz_dmac_suspend_prepare(struct device *dev)
 >> +{
 >> +    struct rz_dmac *dmac = dev_get_drvdata(dev);
 >> +    int ret;
 >> +
 >> +    PM_RUNTIME_ACQUIRE_IF_ENABLED(dmac->dev, pm);
 >> +    ret = PM_RUNTIME_ACQUIRE_ERR(&pm);
 >> +    if (ret)
 >> +            return ret;
 >> +
 >> +    for (unsigned int i = 0; i < dmac->n_channels; i++) {
 >> +            struct rz_dmac_chan *channel = &dmac->channels[i];
 >> +
 >> +            guard(spinlock_irqsave)(&channel->vc.lock);
 >> +
 >> +            /* Wait for transfer completion, except in cyclic case. */
 >> +            if (channel->status & BIT(RZ_DMAC_CHAN_STATUS_CYCLIC))
 >> +                    continue;
 >> +
 >> +            if (rz_dmac_chan_is_enabled(channel))
 >> +                    return -EAGAIN;
 >Could returning -EAGAIN here cause a CPU livelock? In dpm_prepare(), an
 >-EAGAIN error is cleared and retried continuously in a while
 >(!list_empty(&dpm_list)) loop. Since the device is not advanced on error,
 >the PM core might loop infinitely without any backoff until the transfer
 >completes.
 >Also, is there a race condition with non-cyclic channels after this callback
 >returns 0? Since the DMA controller's prepare callback runs before consumer
 >peripherals, an active consumer could immediately submit new non-cyclic
 >transfers before the actual suspend phase begins.

The expectation was to wait until all the transfers complete. But, indeed, there 
might be some issues with this approach. E.g., the serial driver simulates 
cyclic transfers for rx by enqueuing individual SG transfers, and, after each SG 
is completed a new SG is enqueued. So, at any time, the channel is enabled. That 
would lead to the suspend being blocked at this point. As I don't see a way to 
go out of this, for the moment I will drop the prepare callback until the serial 
RX DMA will be adjusted (maybe, to use the cyclic support).


 >> +    }
 >> +
 >> +    return 0;
 >> +}
 >> +
 >[ ... ]
 >> +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);
 >This isn't a bug, but does this function mix scope-based guard() cleanup
 >with goto-based error handling? The cleanup guidelines suggest that
 >functions should either convert all resources to scope-based cleanup or
 >convert none of them to avoid confusing ownership semantics.
 >> +
 >> +            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);
 >Does saving only the NXLA register result in data loss for cyclic channels?
 >When a cyclic channel is paused, it stops at its current descriptor. Without
 >saving and restoring the Current Link Address and Current Transfer Byte
 >count, resuming the channel might force it to skip the remaining bytes of the
 >interrupted descriptor and start fetching the next one.

This is something expected, hardware have no capability to overcome this issue.

 >> +    }
 >> +
 >> +    if (ret)
 >> +            goto suspend_recover;
 >> +
 >> +    ret = reset_control_assert(dmac->rstc);
 >Since non-cyclic channels are unconditionally skipped in the loop above and
 >the hardware reset is asserted here, could newly queued non-cyclic requests
 >from consumers be violently interrupted mid-transfer?

The expectation is that non-cyclic transfers have already been paused by the 
time this code executes.

 >> +    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 const struct dev_pm_ops rz_dmac_pm_ops = {
 >> +    .prepare = rz_dmac_suspend_prepare,
 >This isn't a bug, but should rz_dmac_suspend_prepare be wrapped in
 >pm_sleep_ptr() here? The power management subsystem guidelines recommend
 >using pm_sleep_ptr() for individual callbacks within the ops structure to
 >prevent dead code and unused variable warnings when CONFIG_PM_SLEEP is
 >disabled.

I will drop this function here in the next version as I discovered some issues 
with it and the serial RX DMA.

 >> +    SYSTEM_SLEEP_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,
 >> @@ -1432,6 +1630,7 @@ static struct platform_driver rz_dmac_driver = {
 >>      .driver         = {
 >>              .name   = "rz-dmac",
 >>              .of_match_table = of_rz_dmac_match,
 >> +            .pm     = pm_sleep_ptr(&rz_dmac_pm_ops),
 >This isn't a bug, but should pm_ptr() be used for the dev_pm_ops structure
 >pointer instead of pm_sleep_ptr()? The power management guidelines recommend
 >using pm_ptr() for the structure pointer, while reserving pm_sleep_ptr() for
 >the individual sleep callbacks inside the structure.

OK, will switch to pm_ptr()

 >>      },
 >>      .probe          = rz_dmac_probe,
 >>      .remove         = rz_dmac_remove,

  reply	other threads:[~2026-05-25  7:33 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-12 12:12 [PATCH v5 00/17] Renesas: dmaengine and ASoC fixes Claudiu Beznea
2026-05-12 12:12 ` [PATCH v5 01/17] dmaengine: sh: rz-dmac: Move interrupt request after everything is set up Claudiu Beznea
2026-05-12 20:28   ` Frank Li
2026-05-12 12:12 ` [PATCH v5 02/17] dmaengine: sh: rz-dmac: Fix incorrect NULL check on list_first_entry() Claudiu Beznea
2026-05-12 20:35   ` Frank Li
2026-05-13 13:31     ` Claudiu Beznea
2026-05-12 12:12 ` [PATCH v5 03/17] dmaengine: sh: rz-dmac: Use list_first_entry_or_null() Claudiu Beznea
2026-05-12 20:38   ` Frank Li
2026-05-12 12:12 ` [PATCH v5 04/17] dmaengine: sh: rz-dmac: Use rz_dmac_disable_hw() Claudiu Beznea
2026-05-12 20:42   ` Frank Li
2026-05-12 12:12 ` [PATCH v5 05/17] dmaengine: sh: rz-dmac: Add helper to compute the lmdesc address Claudiu Beznea
2026-05-12 20:44   ` Frank Li
2026-05-12 12:12 ` [PATCH v5 06/17] dmaengine: sh: rz-dmac: Save the start LM descriptor Claudiu Beznea
2026-05-12 20:48   ` Frank Li
2026-05-13 13:33     ` Claudiu Beznea
2026-05-12 12:12 ` [PATCH v5 07/17] dmaengine: sh: rz-dmac: Add helper to check if the channel is enabled Claudiu Beznea
2026-05-12 20:49   ` Frank Li
2026-05-12 12:12 ` [PATCH v5 08/17] dmaengine: sh: rz-dmac: Add helper to check if the channel is paused Claudiu Beznea
2026-05-12 20:57   ` Frank Li
2026-05-12 12:12 ` [PATCH v5 09/17] dmaengine: sh: rz-dmac: Use virt-dma APIs for channel descriptor processing Claudiu Beznea
2026-05-12 21:38   ` Frank Li
2026-05-13 13:34     ` Claudiu Beznea
2026-05-12 12:12 ` [PATCH v5 10/17] dmaengine: sh: rz-dmac: Refactor pause/resume code Claudiu Beznea
2026-05-12 21:43   ` Frank Li
2026-05-13 13:35     ` Claudiu Beznea
2026-05-12 12:12 ` [PATCH v5 11/17] dmaengine: sh: rz-dmac: Drop the update of channel->chctrl with CHCTRL_SETEN Claudiu Beznea
2026-05-12 21:55   ` Frank Li
2026-05-12 12:12 ` [PATCH v5 12/17] dmaengine: sh: rz-dmac: Add cyclic DMA support Claudiu Beznea
2026-05-12 22:00   ` Frank Li
2026-05-13 13:38     ` Claudiu Beznea
2026-05-25  7:28   ` sashiko review (Re: [PATCH v5 12/17] dmaengine: sh: rz-dmac: Add cyclic DMA support) Claudiu Beznea
2026-05-12 12:12 ` [PATCH v5 13/17] dmaengine: sh: rz-dmac: Add runtime PM support Claudiu Beznea
2026-05-12 22:03   ` Frank Li
2026-05-13 13:39     ` Claudiu Beznea
2026-05-13 19:56       ` Frank Li
2026-05-14  9:20         ` Claudiu Beznea
2026-05-25  7:30   ` sashiko review (Re: [PATCH v5 13/17] dmaengine: sh: rz-dmac: Add runtime PM support) Claudiu Beznea
2026-05-12 12:12 ` [PATCH v5 14/17] dmaengine: sh: rz-dmac: Add suspend to RAM support Claudiu Beznea
2026-05-25  7:33   ` Claudiu Beznea [this message]
2026-05-12 12:12 ` [PATCH v5 15/17] ASoC: renesas: rz-ssi: Add pause support Claudiu Beznea
2026-05-12 12:12 ` [PATCH v5 16/17] ASoC: renesas: rz-ssi: Use generic PCM dmaengine APIs Claudiu Beznea
2026-05-12 12:12 ` [PATCH v5 17/17] dmaengine: sh: rz-dmac: Set the Link End (LE) bit on the last descriptor Claudiu Beznea
2026-05-15  8:44 ` [PATCH v5 00/17] Renesas: dmaengine and ASoC fixes John Madieu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4c266a28-1d43-4453-a776-2c2f022f5c85@kernel.org \
    --to=claudiu.beznea@kernel.org \
    --cc=Frank.Li@kernel.org \
    --cc=biju.das.jz@bp.renesas.com \
    --cc=broonie@kernel.org \
    --cc=claudiu.beznea.uj@bp.renesas.com \
    --cc=dmaengine@vger.kernel.org \
    --cc=fabrizio.castro.jz@renesas.com \
    --cc=geert+renesas@glider.be \
    --cc=kuninori.morimoto.gx@renesas.com \
    --cc=lgirdwood@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-renesas-soc@vger.kernel.org \
    --cc=linux-sound@vger.kernel.org \
    --cc=long.luu.ur@renesas.com \
    --cc=p.zabel@pengutronix.de \
    --cc=perex@perex.cz \
    --cc=prabhakar.mahadev-lad.rj@bp.renesas.com \
    --cc=tiwai@suse.com \
    --cc=vkoul@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®