Linux kernel -stable discussions
 help / color / mirror / Atom feed
From: Frank Li <Frank.li@oss.nxp.com>
To: James Hilliard <james.hilliard1@gmail.com>
Cc: Eugeniy Paltsev <Eugeniy.Paltsev@synopsys.com>,
	Vinod Koul <vkoul@kernel.org>, Frank Li <Frank.Li@kernel.org>,
	Sergey Khimich <serghox@gmail.com>,
	Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
	Sia Jee Heng <jee.heng.sia@intel.com>,
	Baruch Siach <baruch@tkos.co.il>,
	Mitch Barnett <mitch@accuratesound.ca>,
	dmaengine@vger.kernel.org, linux-kernel@vger.kernel.org,
	stable@vger.kernel.org
Subject: Re: [PATCH v8 5/9] dmaengine: dw-axi-dmac: preserve pending pause requests
Date: Thu, 19 Nov 2026 10:27:22 -0600	[thread overview]
Message-ID: <av8jamIp8oT_M_eU@SMW015318> (raw)
In-Reply-To: <20261119-submit-dw-axi-dma-stop-pause-v1-v8-5-f8e7fe60594c@gmail.com>

On Thu, Nov 19, 2026 at 09:01:00AM -0700, James Hilliard wrote:
> dma_chan_pause() clears SUSPENDED even when polling times out. Hardware
> can set that status after the last poll, and the unconditional clear then
> discards an acknowledgment the caller never observed. Another channel's
> interrupt can also consume the status because the shared IRQ handler
> clears every channel's status before taking its lock.
>
> Leave SUSPENDED to the pause and resume paths. Track the suspend request
> separately from its acknowledgment so a timeout can be followed by either
> a pause retry or a resume. Wait for acknowledgment before clearing the
> hardware request, since hardware ignores an earlier clear. If that wait
> also times out, return -EAGAIN with the request still pending.
>
> A completed transfer is also quiescent, but its completion handler may
> still need to advance a cyclic descriptor. Defer that restart while a
> pause is pending, and resume it without reprogramming the first LLI.
> Track the active descriptor until its completion handler runs so that
> resume and issue_pending cannot restart a completed cyclic segment or
> reissue a completed noncyclic descriptor while its IRQ is pending.
> Start queued work after the active descriptor is retired, respecting the
> pause request.
>
> Clear stale suspension status at the start of a new descriptor rather
> than at each cyclic restart. Reset the software state after successful
> termination and when allocating a channel for a new client.
>
> Store the lock-protected pause flags as bitfields in existing padding.
>
> Fixes: 1fe20f1b8454 ("dmaengine: Introduce DW AXI DMAC driver")
> Cc: stable@vger.kernel.org
> Signed-off-by: James Hilliard <james.hilliard1@gmail.com>
> ---
>  drivers/dma/dw-axi-dmac/dw-axi-dmac-platform.c | 99 ++++++++++++++++++++++----
>  drivers/dma/dw-axi-dmac/dw-axi-dmac.h          |  8 ++-
>  2 files changed, 91 insertions(+), 16 deletions(-)
>
> diff --git a/drivers/dma/dw-axi-dmac/dw-axi-dmac-platform.c b/drivers/dma/dw-axi-dmac/dw-axi-dmac-platform.c
> index 8c115d20728b..99b648d4ca76 100644
> --- a/drivers/dma/dw-axi-dmac/dw-axi-dmac-platform.c
> +++ b/drivers/dma/dw-axi-dmac/dw-axi-dmac-platform.c
> @@ -482,6 +482,8 @@ static void axi_chan_block_xfer_start(struct axi_dma_chan *chan,
>  	irq_mask |= DWAXIDMAC_IRQ_SUSPENDED;
>  	axi_chan_irq_set(chan, irq_mask);
>
> +	axi_chan_irq_clear(chan, DWAXIDMAC_IRQ_SUSPENDED);
> +	chan->desc = first;
>  	axi_chan_enable(chan);
>  }
>
> @@ -490,6 +492,9 @@ static void axi_chan_start_first_queued(struct axi_dma_chan *chan)
>  	struct axi_dma_desc *desc;
>  	struct virt_dma_desc *vd;
>
> +	if (chan->desc || chan->pause_requested)
> +		return;
> +
>  	vd = vchan_next_desc(&chan->vc);
>  	if (!vd)
>  		return;
> @@ -544,6 +549,10 @@ static int dma_chan_alloc_chan_resources(struct dma_chan *dchan)
>  		pm_runtime_put(chan->chip->dev);
>  		return -ENOMEM;
>  	}
> +	chan->desc = NULL;
> +	chan->pause_requested = false;
> +	chan->is_paused = false;
> +	chan->cyclic_restart = false;
>  	dev_vdbg(dmaengine_chan_dev(dchan), "%s: allocating\n", axi_chan_name(chan));
>
>  	return 0;
> @@ -1088,6 +1097,8 @@ static noinline void axi_chan_handle_err(struct axi_dma_chan *chan, u32 status)
>  	vchan_cookie_complete(vd);
>
>  	/* Try to restart the controller */
> +	chan->desc = NULL;
> +	chan->cyclic_restart = false;
>  	axi_chan_start_first_queued(chan);
>
>  out:
> @@ -1135,11 +1146,18 @@ static void axi_chan_block_xfer_complete(struct axi_dma_chan *chan)
>  			}
>  		}
>
> -		axi_chan_enable(chan);
> +		if (chan->pause_requested) {
> +			chan->is_paused = true;
> +			chan->cyclic_restart = true;
> +		} else {
> +			axi_chan_enable(chan);
> +		}
>  	} else {
>  		/* Remove the completed descriptor from issued list before completing */
>  		list_del(&vd->node);
>  		vchan_cookie_complete(vd);
> +		chan->desc = NULL;
> +		axi_chan_start_first_queued(chan);
>  	}
>
>  out:
> @@ -1161,6 +1179,8 @@ static irqreturn_t dw_axi_dma_interrupt(int irq, void *dev_id)
>  	for (i = 0; i < dw->hdata->nr_channels; i++) {
>  		chan = &dw->chan[i];
>  		status = axi_chan_irq_read(chan);
> +		/* Leave suspension status for the pause and resume paths. */
> +		status &= ~DWAXIDMAC_IRQ_SUSPENDED;

If you don't clean DWAXIDMAC_IRQ_SUSPENDED, does it cause irq flood?

Frank
>  		axi_chan_irq_clear(chan, status);
>
>  		dev_vdbg(chip->dev, "%s %u IRQ status: 0x%08x\n",
> @@ -1200,6 +1220,12 @@ static int dma_chan_terminate_all(struct dma_chan *dchan)
>  			dw_axi_dma_set_byte_halfword(chan, false);
>
>  		vchan_get_all_descriptors(&chan->vc, &head);
> +
> +		axi_chan_irq_clear(chan, DWAXIDMAC_IRQ_SUSPENDED);
> +		chan->desc = NULL;
> +		chan->pause_requested = false;
> +		chan->is_paused = false;
> +		chan->cyclic_restart = false;
>  	}
>
>  	if (ret) {
> @@ -1215,16 +1241,49 @@ static int dma_chan_terminate_all(struct dma_chan *dchan)
>  	return 0;
>  }
>
> +static bool axi_chan_is_suspended(struct axi_dma_chan *chan)
> +{
> +	if (axi_chan_is_hw_enable(chan))
> +		return axi_chan_irq_read(chan) & DWAXIDMAC_IRQ_SUSPENDED;
> +
> +	/* A completed transfer cannot acknowledge a new suspend request. */
> +	axi_chan_disable(chan);
> +	return true;
> +}
> +
> +/* A timed-out request can still be acknowledged. */
> +static int axi_chan_wait_for_suspend(struct axi_dma_chan *chan)
> +	__must_hold(&chan->vc.lock)
> +{
> +	bool suspended;
> +	int ret;
> +
> +	if (chan->is_paused)
> +		return 0;
> +
> +	ret = read_poll_timeout_atomic(axi_chan_is_suspended, suspended, suspended,
> +				       2, 40, false, chan);
> +	if (ret)
> +		return -EAGAIN;
> +
> +	axi_chan_irq_clear(chan, DWAXIDMAC_IRQ_SUSPENDED);
> +	chan->is_paused = true;
> +	return 0;
> +}
> +
>  static int dma_chan_pause(struct dma_chan *dchan)
>  {
>  	struct axi_dma_chan *chan = dchan_to_axi_dma_chan(dchan);
>  	unsigned long flags;
> -	u32 status;
>  	int ret;
>  	u64 val;
>
>  	spin_lock_irqsave(&chan->vc.lock, flags);
>
> +	chan->pause_requested = true;
> +	if (chan->is_paused || !axi_chan_is_hw_enable(chan))
> +		goto wait;
> +
>  	if (chan->chip->dw->hdata->nr_channels >= DMAC_CHAN_16) {
>  		val = axi_dma_ioread64(chan->chip, DMAC_CHSUSPREG);
>  		if (chan->id >= DMAC_CHAN_16) {
> @@ -1251,17 +1310,11 @@ static int dma_chan_pause(struct dma_chan *dchan)
>  		}
>  	}
>
> -	ret = read_poll_timeout_atomic(axi_chan_irq_read, status,
> -				       status & DWAXIDMAC_IRQ_SUSPENDED,
> -				       2, 40, false, chan);
> -
> -	axi_chan_irq_clear(chan, DWAXIDMAC_IRQ_SUSPENDED);
> -
> -	chan->is_paused = true;
> -
> +wait:
> +	ret = axi_chan_wait_for_suspend(chan);
>  	spin_unlock_irqrestore(&chan->vc.lock, flags);
>
> -	return ret ? -EAGAIN : 0;
> +	return ret;
>  }
>
>  /* Called in chan locked context */
> @@ -1295,6 +1348,8 @@ static inline void axi_chan_resume(struct axi_dma_chan *chan)
>  		}
>  	}
>
> +	axi_chan_irq_clear(chan, DWAXIDMAC_IRQ_SUSPENDED);
> +	chan->pause_requested = false;
>  	chan->is_paused = false;
>  }
>
> @@ -1302,15 +1357,31 @@ static int dma_chan_resume(struct dma_chan *dchan)
>  {
>  	struct axi_dma_chan *chan = dchan_to_axi_dma_chan(dchan);
>  	unsigned long flags;
> +	int ret;
>
>  	spin_lock_irqsave(&chan->vc.lock, flags);
>
> -	if (chan->is_paused)
> -		axi_chan_resume(chan);
> +	ret = 0;
> +	if (!chan->pause_requested)
> +		goto out;
> +
> +	/* Hardware ignores resume until the suspend request is acknowledged. */
> +	ret = axi_chan_wait_for_suspend(chan);
> +	if (ret)
> +		goto out;
> +
> +	axi_chan_resume(chan);
> +	if (chan->cyclic_restart) {
> +		chan->cyclic_restart = false;
> +		axi_chan_enable(chan);
> +	} else {
> +		axi_chan_start_first_queued(chan);
> +	}
>
> +out:
>  	spin_unlock_irqrestore(&chan->vc.lock, flags);
>
> -	return 0;
> +	return ret;
>  }
>
>  static int axi_dma_suspend(struct axi_dma_chip *chip)
> diff --git a/drivers/dma/dw-axi-dmac/dw-axi-dmac.h b/drivers/dma/dw-axi-dmac/dw-axi-dmac.h
> index 3c86e5d468ea..b18c9880711a 100644
> --- a/drivers/dma/dw-axi-dmac/dw-axi-dmac.h
> +++ b/drivers/dma/dw-axi-dmac/dw-axi-dmac.h
> @@ -42,6 +42,12 @@ struct axi_dma_chan {
>  	void __iomem			*chan_regs;
>  	u8				id;
>  	u8				hw_handshake_num;
> +
> +	/* Protected by vc.lock. */
> +	bool				pause_requested:1;
> +	bool				is_paused:1;
> +	bool				cyclic_restart:1;
> +
>  	atomic_t			descs_allocated;
>
>  	struct dma_pool			*desc_pool;
> @@ -50,8 +56,6 @@ struct axi_dma_chan {
>  	struct axi_dma_desc		*desc;
>  	struct dma_slave_config		config;
>  	enum dma_transfer_direction	direction;
> -	/* these other elements are all protected by vc.lock */
> -	bool				is_paused;
>  };
>
>  struct dw_axi_dma {
>
> --
> 2.53.0
>

  reply	other threads:[~2026-11-19 16:27 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-19 16:00 [PATCH v8 0/9] dmaengine: dw-axi-dmac: fix termination and pause acknowledgment James Hilliard
2026-11-19 16:00 ` [PATCH v8 1/9] dmaengine: dw-axi-dmac: keep cyclic mode in the descriptor James Hilliard
2026-11-19 16:00 ` [PATCH v8 2/9] dmaengine: dw-axi-dmac: poll the correct enable bit during termination James Hilliard
2026-11-19 16:17   ` Frank Li
2026-11-19 16:00 ` [PATCH v8 3/9] dmaengine: dw-axi-dmac: retain descriptors when termination times out James Hilliard
2026-11-19 16:18   ` Frank Li
2026-11-19 16:00 ` [PATCH v8 4/9] dmaengine: dw-axi-dmac: use atomic polling for suspend acknowledgment James Hilliard
2026-11-19 16:19   ` Frank Li
2026-11-19 16:01 ` [PATCH v8 5/9] dmaengine: dw-axi-dmac: preserve pending pause requests James Hilliard
2026-11-19 16:27   ` Frank Li [this message]
2026-11-19 16:01 ` [PATCH v8 6/9] dmaengine: dw-axi-dmac: retain descriptors until callbacks drain James Hilliard
2026-11-19 16:41   ` Frank Li
2026-11-19 16:01 ` [PATCH v8 7/9] dmaengine: dw-axi-dmac: serialize interrupt status with channel reuse James Hilliard
2026-11-19 16:44   ` Frank Li
2026-11-19 16:01 ` [PATCH v8 8/9] dmaengine: dw-axi-dmac: require an IRQ before registering the controller James Hilliard

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=av8jamIp8oT_M_eU@SMW015318 \
    --to=frank.li@oss.nxp.com \
    --cc=Eugeniy.Paltsev@synopsys.com \
    --cc=Frank.Li@kernel.org \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=baruch@tkos.co.il \
    --cc=dmaengine@vger.kernel.org \
    --cc=james.hilliard1@gmail.com \
    --cc=jee.heng.sia@intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mitch@accuratesound.ca \
    --cc=serghox@gmail.com \
    --cc=stable@vger.kernel.org \
    --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