linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v1 1/2] at_hdmac: check and return DMA_PAUSED status when suitable
@ 2022-11-08  7:49 Andy Shevchenko
  2022-11-08  7:49 ` [PATCH v1 2/2] at_hdmac: return actual status when txstatus parameter is NULL Andy Shevchenko
  2022-11-08 11:50 ` [PATCH v1 1/2] at_hdmac: check and return DMA_PAUSED status when suitable Tudor.Ambarus
  0 siblings, 2 replies; 5+ messages in thread
From: Andy Shevchenko @ 2022-11-08  7:49 UTC (permalink / raw)
  To: Vinod Koul, Tudor Ambarus, Nicolas Ferre, linux-arm-kernel,
	dmaengine, linux-kernel
  Cc: Ludovic Desroches, Andy Shevchenko

device_tx_status() may return DMA_PAUSED status when driver supports it.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/dma/at_hdmac.c | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/drivers/dma/at_hdmac.c b/drivers/dma/at_hdmac.c
index 8858470246e1..a9d8dd990d6e 100644
--- a/drivers/dma/at_hdmac.c
+++ b/drivers/dma/at_hdmac.c
@@ -1669,9 +1669,19 @@ atc_tx_status(struct dma_chan *chan,
 	int ret;
 
 	dma_status = dma_cookie_status(chan, cookie, txstate);
-	if (dma_status == DMA_COMPLETE || !txstate)
+	if (dma_status == DMA_COMPLETE)
 		return dma_status;
 
+	/*
+	 * There's no point in calculating the residue if there's
+	 * no txstate to store the value.
+	 */
+	if (!txstate) {
+		if (test_bit(ATC_IS_PAUSED, &atchan->status))
+			return DMA_PAUSED;
+		return DMA_ERROR;
+	}
+
 	spin_lock_irqsave(&atchan->vc.lock, flags);
 	/*  Get number of bytes left in the active transactions */
 	ret = atc_get_residue(chan, cookie, &residue);
@@ -1684,6 +1694,9 @@ atc_tx_status(struct dma_chan *chan,
 		dma_set_residue(txstate, residue);
 	}
 
+	if (test_bit(ATC_IS_PAUSED, &atchan->status))
+		dma_status = DMA_PAUSED;
+
 	dev_vdbg(chan2dev(chan), "tx_status %d: cookie = %d residue = %u\n",
 		 dma_status, cookie, residue);
 
-- 
2.35.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* [PATCH v1 2/2] at_hdmac: return actual status when txstatus parameter is NULL
  2022-11-08  7:49 [PATCH v1 1/2] at_hdmac: check and return DMA_PAUSED status when suitable Andy Shevchenko
@ 2022-11-08  7:49 ` Andy Shevchenko
  2022-11-08 11:51   ` Tudor.Ambarus
  2022-11-08 11:50 ` [PATCH v1 1/2] at_hdmac: check and return DMA_PAUSED status when suitable Tudor.Ambarus
  1 sibling, 1 reply; 5+ messages in thread
From: Andy Shevchenko @ 2022-11-08  7:49 UTC (permalink / raw)
  To: Vinod Koul, Tudor Ambarus, Nicolas Ferre, linux-arm-kernel,
	dmaengine, linux-kernel
  Cc: Ludovic Desroches, Andy Shevchenko

There is no point to return DMA_ERROR if txstatus parameter is NULL. It's a
valid case and should be handled correspondingly.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/dma/at_hdmac.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/dma/at_hdmac.c b/drivers/dma/at_hdmac.c
index a9d8dd990d6e..4035d5438530 100644
--- a/drivers/dma/at_hdmac.c
+++ b/drivers/dma/at_hdmac.c
@@ -1679,7 +1679,7 @@ atc_tx_status(struct dma_chan *chan,
 	if (!txstate) {
 		if (test_bit(ATC_IS_PAUSED, &atchan->status))
 			return DMA_PAUSED;
-		return DMA_ERROR;
+		return dma_status;
 	}
 
 	spin_lock_irqsave(&atchan->vc.lock, flags);
-- 
2.35.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v1 1/2] at_hdmac: check and return DMA_PAUSED status when suitable
  2022-11-08  7:49 [PATCH v1 1/2] at_hdmac: check and return DMA_PAUSED status when suitable Andy Shevchenko
  2022-11-08  7:49 ` [PATCH v1 2/2] at_hdmac: return actual status when txstatus parameter is NULL Andy Shevchenko
@ 2022-11-08 11:50 ` Tudor.Ambarus
  2022-11-08 12:18   ` Andy Shevchenko
  1 sibling, 1 reply; 5+ messages in thread
From: Tudor.Ambarus @ 2022-11-08 11:50 UTC (permalink / raw)
  To: andriy.shevchenko, vkoul, Nicolas.Ferre, linux-arm-kernel,
	dmaengine, linux-kernel
  Cc: Ludovic.Desroches

Hi, Andy,

On 11/8/22 09:49, Andy Shevchenko wrote:
> EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe
> 
> device_tx_status() may return DMA_PAUSED status when driver supports it.

Yeah, but you haven't described the why. And that's because dma_cookie_status()
currently considers just DMA_COMPLETE and DMA_IN_PROGRESS for the status of the
cookie, so the controller drivers are forced to query the DMA_PAUSED state
themselves.

Also, I noticed that Vinod prefers that you use the full paragraph in the commit
message, and not a continuation of the patch title, so you may want to reword
the commit message.

> 
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> ---
>  drivers/dma/at_hdmac.c | 15 ++++++++++++++-
>  1 file changed, 14 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/dma/at_hdmac.c b/drivers/dma/at_hdmac.c
> index 8858470246e1..a9d8dd990d6e 100644
> --- a/drivers/dma/at_hdmac.c
> +++ b/drivers/dma/at_hdmac.c
> @@ -1669,9 +1669,19 @@ atc_tx_status(struct dma_chan *chan,
>         int ret;
> 
>         dma_status = dma_cookie_status(chan, cookie, txstate);
> -       if (dma_status == DMA_COMPLETE || !txstate)
> +       if (dma_status == DMA_COMPLETE)
>                 return dma_status;
> 
> +       /*
> +        * There's no point in calculating the residue if there's
> +        * no txstate to store the value.
> +        */
> +       if (!txstate) {
> +               if (test_bit(ATC_IS_PAUSED, &atchan->status))

there's a helper function that you can use instead: atc_chan_is_paused()

> +                       return DMA_PAUSED;
> +               return DMA_ERROR;

return dma_status please

> +       }
> +
>         spin_lock_irqsave(&atchan->vc.lock, flags);
>         /*  Get number of bytes left in the active transactions */
>         ret = atc_get_residue(chan, cookie, &residue);
> @@ -1684,6 +1694,9 @@ atc_tx_status(struct dma_chan *chan,
>                 dma_set_residue(txstate, residue);
>         }
> 
> +       if (test_bit(ATC_IS_PAUSED, &atchan->status))

The status may change after spin_unlock_irqrestore(). Should the residue
be in sync with the dma status? If yes, you should check the status while
holding the lock.

> +               dma_status = DMA_PAUSED;
> +
>         dev_vdbg(chan2dev(chan), "tx_status %d: cookie = %d residue = %u\n",
>                  dma_status, cookie, residue);
> 
> --
> 2.35.1
> 

-- 
Cheers,
ta

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v1 2/2] at_hdmac: return actual status when txstatus parameter is NULL
  2022-11-08  7:49 ` [PATCH v1 2/2] at_hdmac: return actual status when txstatus parameter is NULL Andy Shevchenko
@ 2022-11-08 11:51   ` Tudor.Ambarus
  0 siblings, 0 replies; 5+ messages in thread
From: Tudor.Ambarus @ 2022-11-08 11:51 UTC (permalink / raw)
  To: andriy.shevchenko, vkoul, Nicolas.Ferre, linux-arm-kernel,
	dmaengine, linux-kernel
  Cc: Ludovic.Desroches

On 11/8/22 09:49, Andy Shevchenko wrote:
> EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe
> 
> There is no point to return DMA_ERROR if txstatus parameter is NULL. It's a
> valid case and should be handled correspondingly.
> 
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> ---
>  drivers/dma/at_hdmac.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/dma/at_hdmac.c b/drivers/dma/at_hdmac.c
> index a9d8dd990d6e..4035d5438530 100644
> --- a/drivers/dma/at_hdmac.c
> +++ b/drivers/dma/at_hdmac.c
> @@ -1679,7 +1679,7 @@ atc_tx_status(struct dma_chan *chan,
>         if (!txstate) {
>                 if (test_bit(ATC_IS_PAUSED, &atchan->status))
>                         return DMA_PAUSED;
> -               return DMA_ERROR;
> +               return dma_status;

oh, I see you do it here, please squash this patch to the previous one,
you introduced DMA_ERROR in the previous patch.

>         }
> 
>         spin_lock_irqsave(&atchan->vc.lock, flags);
> --
> 2.35.1
> 

-- 
Cheers,
ta

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v1 1/2] at_hdmac: check and return DMA_PAUSED status when suitable
  2022-11-08 11:50 ` [PATCH v1 1/2] at_hdmac: check and return DMA_PAUSED status when suitable Tudor.Ambarus
@ 2022-11-08 12:18   ` Andy Shevchenko
  0 siblings, 0 replies; 5+ messages in thread
From: Andy Shevchenko @ 2022-11-08 12:18 UTC (permalink / raw)
  To: Tudor.Ambarus
  Cc: linux-kernel, Ludovic.Desroches, vkoul, dmaengine,
	linux-arm-kernel

On Tue, Nov 08, 2022 at 11:50:19AM +0000, Tudor.Ambarus@microchip.com wrote:
> On 11/8/22 09:49, Andy Shevchenko wrote:
> > EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe
> > 
> > device_tx_status() may return DMA_PAUSED status when driver supports it.
> 
> Yeah, but you haven't described the why. And that's because dma_cookie_status()
> currently considers just DMA_COMPLETE and DMA_IN_PROGRESS for the status of the
> cookie, so the controller drivers are forced to query the DMA_PAUSED state
> themselves.

At last without this change it's inconvenient and requires a lot of additional
(unneeded) code to be written by the caller. Moreover, it's racy. If you query
status twice in a raw, it may be well changed (for example from PAUSED to
IN_PROGRESS or COMPETE).

I will add a word summarizing this.

> Also, I noticed that Vinod prefers that you use the full paragraph in the commit
> message, and not a continuation of the patch title, so you may want to reword
> the commit message.

Yes, I will fix that.

...

> > +       if (!txstate) {
> > +               if (test_bit(ATC_IS_PAUSED, &atchan->status))
> 
> there's a helper function that you can use instead: atc_chan_is_paused()

Will use it.

> > +                       return DMA_PAUSED;
> > +               return DMA_ERROR;
> 
> return dma_status please

Will squash the patch.

> > +       }

...

> > +       if (test_bit(ATC_IS_PAUSED, &atchan->status))
> 
> The status may change after spin_unlock_irqrestore(). Should the residue
> be in sync with the dma status? If yes, you should check the status while
> holding the lock.

You should tell me actually. Because I'm a bit puzzled why we need a spin lock
_and_ atomic bit operations together.

> > +               dma_status = DMA_PAUSED;

...

Thank you for the review.

-- 
With Best Regards,
Andy Shevchenko



_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

end of thread, other threads:[~2022-11-08 12:20 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-11-08  7:49 [PATCH v1 1/2] at_hdmac: check and return DMA_PAUSED status when suitable Andy Shevchenko
2022-11-08  7:49 ` [PATCH v1 2/2] at_hdmac: return actual status when txstatus parameter is NULL Andy Shevchenko
2022-11-08 11:51   ` Tudor.Ambarus
2022-11-08 11:50 ` [PATCH v1 1/2] at_hdmac: check and return DMA_PAUSED status when suitable Tudor.Ambarus
2022-11-08 12:18   ` Andy Shevchenko

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