linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/8] STM32 DMA driver fixes and improvements
@ 2020-01-29 15:36 Amelie Delaunay
  2020-01-29 15:36 ` [PATCH 1/8] dmaengine: stm32-dma: add suspend/resume power management support Amelie Delaunay
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: Amelie Delaunay @ 2020-01-29 15:36 UTC (permalink / raw)
  To: Vinod Koul, Dan Williams, Maxime Coquelin, Alexandre Torgue
  Cc: dmaengine, linux-stm32, linux-arm-kernel, linux-kernel,
	Amelie Delaunay, Pierre-Yves MORDRET

This series brings improvements to the STM32 DMA driver, with support of
power management and descriptor reuse. Probe function gets a cleanup and
properties like copy_align and max_segment_size are set.
A "sleeping function called from invalid context" bug is also fixed. And
to avoid a race with vchan_complete, driver now adopts
vchan_terminate_vdesc().

Amelie Delaunay (4):
  dmaengine: stm32-dma: use dma_set_max_seg_size to set the sg limit
  dmaengine: stm32-dma: add copy_align constraint
  dmaengine: stm32-dma: fix sleeping function called from invalid
    context
  dmaengine: stm32-dma: use vchan_terminate_vdesc() in .terminate_all

Etienne Carriere (2):
  dmaengine: stm32-dma: use reset controller only at probe time
  dmaengine: stm32-dma: driver defers probe for reset

Pierre-Yves MORDRET (2):
  dmaengine: stm32-dma: add suspend/resume power management support
  dmaengine: stm32-dma: enable descriptor_reuse

 drivers/dma/stm32-dma.c | 96 ++++++++++++++++++++++++++++-------------
 1 file changed, 67 insertions(+), 29 deletions(-)

-- 
2.17.1


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

* [PATCH 1/8] dmaengine: stm32-dma: add suspend/resume power management support
  2020-01-29 15:36 [PATCH 0/8] STM32 DMA driver fixes and improvements Amelie Delaunay
@ 2020-01-29 15:36 ` Amelie Delaunay
  2020-01-29 15:36 ` [PATCH 2/8] dmaengine: stm32-dma: use reset controller only at probe time Amelie Delaunay
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: Amelie Delaunay @ 2020-01-29 15:36 UTC (permalink / raw)
  To: Vinod Koul, Dan Williams, Maxime Coquelin, Alexandre Torgue
  Cc: dmaengine, linux-stm32, linux-arm-kernel, linux-kernel,
	Amelie Delaunay, Pierre-Yves MORDRET

From: Pierre-Yves MORDRET <pierre-yves.mordret@st.com>

Add suspend/resume power management relying on PM Runtime engine.

Signed-off-by: Pierre-Yves MORDRET <pierre-yves.mordret@st.com>
Signed-off-by: Amelie Delaunay <amelie.delaunay@st.com>
---
 drivers/dma/stm32-dma.c | 32 ++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)

diff --git a/drivers/dma/stm32-dma.c b/drivers/dma/stm32-dma.c
index 5989b0893521..136deabd1aa3 100644
--- a/drivers/dma/stm32-dma.c
+++ b/drivers/dma/stm32-dma.c
@@ -1427,7 +1427,39 @@ static int stm32_dma_runtime_resume(struct device *dev)
 }
 #endif
 
+#ifdef CONFIG_PM_SLEEP
+static int stm32_dma_suspend(struct device *dev)
+{
+	struct stm32_dma_device *dmadev = dev_get_drvdata(dev);
+	int id, ret, scr;
+
+	ret = pm_runtime_get_sync(dev);
+	if (ret < 0)
+		return ret;
+
+	for (id = 0; id < STM32_DMA_MAX_CHANNELS; id++) {
+		scr = stm32_dma_read(dmadev, STM32_DMA_SCR(id));
+		if (scr & STM32_DMA_SCR_EN) {
+			dev_warn(dev, "Suspend is prevented by Chan %i\n", id);
+			return -EBUSY;
+		}
+	}
+
+	pm_runtime_put_sync(dev);
+
+	pm_runtime_force_suspend(dev);
+
+	return 0;
+}
+
+static int stm32_dma_resume(struct device *dev)
+{
+	return pm_runtime_force_resume(dev);
+}
+#endif
+
 static const struct dev_pm_ops stm32_dma_pm_ops = {
+	SET_SYSTEM_SLEEP_PM_OPS(stm32_dma_suspend, stm32_dma_resume)
 	SET_RUNTIME_PM_OPS(stm32_dma_runtime_suspend,
 			   stm32_dma_runtime_resume, NULL)
 };
-- 
2.17.1


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

* [PATCH 2/8] dmaengine: stm32-dma: use reset controller only at probe time
  2020-01-29 15:36 [PATCH 0/8] STM32 DMA driver fixes and improvements Amelie Delaunay
  2020-01-29 15:36 ` [PATCH 1/8] dmaengine: stm32-dma: add suspend/resume power management support Amelie Delaunay
@ 2020-01-29 15:36 ` Amelie Delaunay
  2020-01-29 15:36 ` [PATCH 3/8] dmaengine: stm32-dma: driver defers probe for reset Amelie Delaunay
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: Amelie Delaunay @ 2020-01-29 15:36 UTC (permalink / raw)
  To: Vinod Koul, Dan Williams, Maxime Coquelin, Alexandre Torgue
  Cc: dmaengine, linux-stm32, linux-arm-kernel, linux-kernel,
	Amelie Delaunay, Pierre-Yves MORDRET

From: Etienne Carriere <etienne.carriere@st.com>

Remove reset controller reference from device instance since it is
used only at probe time.

Signed-off-by: Etienne Carriere <etienne.carriere@st.com>
Signed-off-by: Amelie Delaunay <amelie.delaunay@st.com>
---
 drivers/dma/stm32-dma.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/dma/stm32-dma.c b/drivers/dma/stm32-dma.c
index 136deabd1aa3..e31414796ec4 100644
--- a/drivers/dma/stm32-dma.c
+++ b/drivers/dma/stm32-dma.c
@@ -207,7 +207,6 @@ struct stm32_dma_device {
 	struct dma_device ddev;
 	void __iomem *base;
 	struct clk *clk;
-	struct reset_control *rst;
 	bool mem2mem;
 	struct stm32_dma_chan chan[STM32_DMA_MAX_CHANNELS];
 };
@@ -1275,6 +1274,7 @@ static int stm32_dma_probe(struct platform_device *pdev)
 	struct dma_device *dd;
 	const struct of_device_id *match;
 	struct resource *res;
+	struct reset_control *rst;
 	int i, ret;
 
 	match = of_match_device(stm32_dma_of_match, &pdev->dev);
@@ -1309,11 +1309,11 @@ static int stm32_dma_probe(struct platform_device *pdev)
 	dmadev->mem2mem = of_property_read_bool(pdev->dev.of_node,
 						"st,mem2mem");
 
-	dmadev->rst = devm_reset_control_get(&pdev->dev, NULL);
-	if (!IS_ERR(dmadev->rst)) {
-		reset_control_assert(dmadev->rst);
+	rst = devm_reset_control_get(&pdev->dev, NULL);
+	if (!IS_ERR(rst)) {
+		reset_control_assert(rst);
 		udelay(2);
-		reset_control_deassert(dmadev->rst);
+		reset_control_deassert(rst);
 	}
 
 	dma_cap_set(DMA_SLAVE, dd->cap_mask);
-- 
2.17.1


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

* [PATCH 3/8] dmaengine: stm32-dma: driver defers probe for reset
  2020-01-29 15:36 [PATCH 0/8] STM32 DMA driver fixes and improvements Amelie Delaunay
  2020-01-29 15:36 ` [PATCH 1/8] dmaengine: stm32-dma: add suspend/resume power management support Amelie Delaunay
  2020-01-29 15:36 ` [PATCH 2/8] dmaengine: stm32-dma: use reset controller only at probe time Amelie Delaunay
@ 2020-01-29 15:36 ` Amelie Delaunay
  2020-01-29 15:36 ` [PATCH 4/8] dmaengine: stm32-dma: enable descriptor_reuse Amelie Delaunay
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: Amelie Delaunay @ 2020-01-29 15:36 UTC (permalink / raw)
  To: Vinod Koul, Dan Williams, Maxime Coquelin, Alexandre Torgue
  Cc: dmaengine, linux-stm32, linux-arm-kernel, linux-kernel,
	Amelie Delaunay, Pierre-Yves MORDRET

From: Etienne Carriere <etienne.carriere@st.com>

Change STM32 DMA driver to defer its probe operation when reset
controller is expected but has not been probed yet when DMA
device is probed.

Changes error traces when failing to get a system resource so that
it is not printed on failure with deferred probing.

Signed-off-by: Etienne Carriere <etienne.carriere@st.com>
Signed-off-by: Amelie Delaunay <amelie.delaunay@st.com>
---
 drivers/dma/stm32-dma.c | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/drivers/dma/stm32-dma.c b/drivers/dma/stm32-dma.c
index e31414796ec4..c8bbe08b8e32 100644
--- a/drivers/dma/stm32-dma.c
+++ b/drivers/dma/stm32-dma.c
@@ -1296,8 +1296,10 @@ static int stm32_dma_probe(struct platform_device *pdev)
 
 	dmadev->clk = devm_clk_get(&pdev->dev, NULL);
 	if (IS_ERR(dmadev->clk)) {
-		dev_err(&pdev->dev, "Error: Missing controller clock\n");
-		return PTR_ERR(dmadev->clk);
+		ret = PTR_ERR(dmadev->clk);
+		if (ret != -EPROBE_DEFER)
+			dev_err(&pdev->dev, "Can't get clock\n");
+		return ret;
 	}
 
 	ret = clk_prepare_enable(dmadev->clk);
@@ -1310,7 +1312,11 @@ static int stm32_dma_probe(struct platform_device *pdev)
 						"st,mem2mem");
 
 	rst = devm_reset_control_get(&pdev->dev, NULL);
-	if (!IS_ERR(rst)) {
+	if (IS_ERR(rst)) {
+		ret = PTR_ERR(rst);
+		if (ret == -EPROBE_DEFER)
+			goto clk_free;
+	} else {
 		reset_control_assert(rst);
 		udelay(2);
 		reset_control_deassert(rst);
@@ -1470,10 +1476,11 @@ static struct platform_driver stm32_dma_driver = {
 		.of_match_table = stm32_dma_of_match,
 		.pm = &stm32_dma_pm_ops,
 	},
+	.probe = stm32_dma_probe,
 };
 
 static int __init stm32_dma_init(void)
 {
-	return platform_driver_probe(&stm32_dma_driver, stm32_dma_probe);
+	return platform_driver_register(&stm32_dma_driver);
 }
 subsys_initcall(stm32_dma_init);
-- 
2.17.1


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

* [PATCH 4/8] dmaengine: stm32-dma: enable descriptor_reuse
  2020-01-29 15:36 [PATCH 0/8] STM32 DMA driver fixes and improvements Amelie Delaunay
                   ` (2 preceding siblings ...)
  2020-01-29 15:36 ` [PATCH 3/8] dmaengine: stm32-dma: driver defers probe for reset Amelie Delaunay
@ 2020-01-29 15:36 ` Amelie Delaunay
  2020-01-29 15:36 ` [PATCH 5/8] dmaengine: stm32-dma: use dma_set_max_seg_size to set the sg limit Amelie Delaunay
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: Amelie Delaunay @ 2020-01-29 15:36 UTC (permalink / raw)
  To: Vinod Koul, Dan Williams, Maxime Coquelin, Alexandre Torgue
  Cc: dmaengine, linux-stm32, linux-arm-kernel, linux-kernel,
	Amelie Delaunay, Pierre-Yves MORDRET

From: Pierre-Yves MORDRET <pierre-yves.mordret@st.com>

Enable client to resubmit already processed descriptors
in order to save descriptor creation time.

Signed-off-by: Pierre-Yves MORDRET <pierre-yves.mordret@st.com>
Signed-off-by: Amelie Delaunay <amelie.delaunay@st.com>
---
 drivers/dma/stm32-dma.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/dma/stm32-dma.c b/drivers/dma/stm32-dma.c
index c8bbe08b8e32..25f7281932bd 100644
--- a/drivers/dma/stm32-dma.c
+++ b/drivers/dma/stm32-dma.c
@@ -554,6 +554,7 @@ static void stm32_dma_start_transfer(struct stm32_dma_chan *chan)
 	sg_req = &chan->desc->sg_req[chan->next_sg];
 	reg = &sg_req->chan_reg;
 
+	reg->dma_scr &= ~STM32_DMA_SCR_EN;
 	stm32_dma_write(dmadev, STM32_DMA_SCR(chan->id), reg->dma_scr);
 	stm32_dma_write(dmadev, STM32_DMA_SPAR(chan->id), reg->dma_spar);
 	stm32_dma_write(dmadev, STM32_DMA_SM0AR(chan->id), reg->dma_sm0ar);
@@ -1343,6 +1344,7 @@ static int stm32_dma_probe(struct platform_device *pdev)
 	dd->directions = BIT(DMA_DEV_TO_MEM) | BIT(DMA_MEM_TO_DEV);
 	dd->residue_granularity = DMA_RESIDUE_GRANULARITY_BURST;
 	dd->max_burst = STM32_DMA_MAX_BURST;
+	dd->descriptor_reuse = true;
 	dd->dev = &pdev->dev;
 	INIT_LIST_HEAD(&dd->channels);
 
-- 
2.17.1


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

* [PATCH 5/8] dmaengine: stm32-dma: use dma_set_max_seg_size to set the sg limit
  2020-01-29 15:36 [PATCH 0/8] STM32 DMA driver fixes and improvements Amelie Delaunay
                   ` (3 preceding siblings ...)
  2020-01-29 15:36 ` [PATCH 4/8] dmaengine: stm32-dma: enable descriptor_reuse Amelie Delaunay
@ 2020-01-29 15:36 ` Amelie Delaunay
  2020-01-29 15:36 ` [PATCH 6/8] dmaengine: stm32-dma: add copy_align constraint Amelie Delaunay
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: Amelie Delaunay @ 2020-01-29 15:36 UTC (permalink / raw)
  To: Vinod Koul, Dan Williams, Maxime Coquelin, Alexandre Torgue
  Cc: dmaengine, linux-stm32, linux-arm-kernel, linux-kernel,
	Amelie Delaunay, Pierre-Yves MORDRET

This patch adds dma_set_max_seg_size to define sg dma constraint.
This constraint may be taken into account by client to scatter/gather
its buffer.

Signed-off-by: Ludovic Barre <ludovic.barre@st.com>
Signed-off-by: Amelie Delaunay <amelie.delaunay@st.com>
---
 drivers/dma/stm32-dma.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/dma/stm32-dma.c b/drivers/dma/stm32-dma.c
index 25f7281932bd..b7e18cfcd439 100644
--- a/drivers/dma/stm32-dma.c
+++ b/drivers/dma/stm32-dma.c
@@ -1323,6 +1323,8 @@ static int stm32_dma_probe(struct platform_device *pdev)
 		reset_control_deassert(rst);
 	}
 
+	dma_set_max_seg_size(&pdev->dev, STM32_DMA_ALIGNED_MAX_DATA_ITEMS);
+
 	dma_cap_set(DMA_SLAVE, dd->cap_mask);
 	dma_cap_set(DMA_PRIVATE, dd->cap_mask);
 	dma_cap_set(DMA_CYCLIC, dd->cap_mask);
-- 
2.17.1


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

* [PATCH 6/8] dmaengine: stm32-dma: add copy_align constraint
  2020-01-29 15:36 [PATCH 0/8] STM32 DMA driver fixes and improvements Amelie Delaunay
                   ` (4 preceding siblings ...)
  2020-01-29 15:36 ` [PATCH 5/8] dmaengine: stm32-dma: use dma_set_max_seg_size to set the sg limit Amelie Delaunay
@ 2020-01-29 15:36 ` Amelie Delaunay
  2020-01-29 15:36 ` [PATCH 7/8] dmaengine: stm32-dma: fix sleeping function called from invalid context Amelie Delaunay
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: Amelie Delaunay @ 2020-01-29 15:36 UTC (permalink / raw)
  To: Vinod Koul, Dan Williams, Maxime Coquelin, Alexandre Torgue
  Cc: dmaengine, linux-stm32, linux-arm-kernel, linux-kernel,
	Amelie Delaunay, Pierre-Yves MORDRET

This patch adds copy_align property in accordance with hardware
restriction.

Signed-off-by: Ludovic Barre <ludovic.barre@st.com>
Signed-off-by: Amelie Delaunay <amelie.delaunay@st.com>
---
 drivers/dma/stm32-dma.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/dma/stm32-dma.c b/drivers/dma/stm32-dma.c
index b7e18cfcd439..01a2374ae03a 100644
--- a/drivers/dma/stm32-dma.c
+++ b/drivers/dma/stm32-dma.c
@@ -1345,6 +1345,7 @@ static int stm32_dma_probe(struct platform_device *pdev)
 		BIT(DMA_SLAVE_BUSWIDTH_4_BYTES);
 	dd->directions = BIT(DMA_DEV_TO_MEM) | BIT(DMA_MEM_TO_DEV);
 	dd->residue_granularity = DMA_RESIDUE_GRANULARITY_BURST;
+	dd->copy_align = DMAENGINE_ALIGN_32_BYTES;
 	dd->max_burst = STM32_DMA_MAX_BURST;
 	dd->descriptor_reuse = true;
 	dd->dev = &pdev->dev;
-- 
2.17.1


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

* [PATCH 7/8] dmaengine: stm32-dma: fix sleeping function called from invalid context
  2020-01-29 15:36 [PATCH 0/8] STM32 DMA driver fixes and improvements Amelie Delaunay
                   ` (5 preceding siblings ...)
  2020-01-29 15:36 ` [PATCH 6/8] dmaengine: stm32-dma: add copy_align constraint Amelie Delaunay
@ 2020-01-29 15:36 ` Amelie Delaunay
  2020-01-29 15:36 ` [PATCH 8/8] dmaengine: stm32-dma: use vchan_terminate_vdesc() in .terminate_all Amelie Delaunay
  2020-02-25  5:45 ` [PATCH 0/8] STM32 DMA driver fixes and improvements Vinod Koul
  8 siblings, 0 replies; 10+ messages in thread
From: Amelie Delaunay @ 2020-01-29 15:36 UTC (permalink / raw)
  To: Vinod Koul, Dan Williams, Maxime Coquelin, Alexandre Torgue
  Cc: dmaengine, linux-stm32, linux-arm-kernel, linux-kernel,
	Amelie Delaunay, Pierre-Yves MORDRET

This patch fixes BUG: sleeping function called from invalid context in
stm32_dma_disable_chan function.

The goal of this function is to force channel disable if it has not been
disabled by hardware. This consists in clearing STM32_DMA_SCR_EN bit and
read it as 0 to ensure the channel is well disabled and the last transfer
is over.

In previous implementation, the waiting loop was based on a do...while (1)
with a call to cond_resched to give the scheduler a chance to run a higher
priority process.

But in some conditions, stm32_dma_disable_chan can be called while
preemption is disabled, on a stm32_dma_stop call for example. So
cond_resched must not be used.

To avoid this, use readl_relaxed_poll_timeout_atomic to poll
STM32_DMA_SCR_EN bit cleared.

Signed-off-by: Amelie Delaunay <amelie.delaunay@st.com>
---
 drivers/dma/stm32-dma.c | 27 +++++++++------------------
 1 file changed, 9 insertions(+), 18 deletions(-)

diff --git a/drivers/dma/stm32-dma.c b/drivers/dma/stm32-dma.c
index 01a2374ae03a..b585e11c2168 100644
--- a/drivers/dma/stm32-dma.c
+++ b/drivers/dma/stm32-dma.c
@@ -15,6 +15,7 @@
 #include <linux/dma-mapping.h>
 #include <linux/err.h>
 #include <linux/init.h>
+#include <linux/iopoll.h>
 #include <linux/jiffies.h>
 #include <linux/list.h>
 #include <linux/module.h>
@@ -421,29 +422,19 @@ static void stm32_dma_irq_clear(struct stm32_dma_chan *chan, u32 flags)
 static int stm32_dma_disable_chan(struct stm32_dma_chan *chan)
 {
 	struct stm32_dma_device *dmadev = stm32_dma_get_dev(chan);
-	unsigned long timeout = jiffies + msecs_to_jiffies(5000);
-	u32 dma_scr, id;
+	u32 dma_scr, id, reg;
 
 	id = chan->id;
-	dma_scr = stm32_dma_read(dmadev, STM32_DMA_SCR(id));
+	reg = STM32_DMA_SCR(id);
+	dma_scr = stm32_dma_read(dmadev, reg);
 
 	if (dma_scr & STM32_DMA_SCR_EN) {
 		dma_scr &= ~STM32_DMA_SCR_EN;
-		stm32_dma_write(dmadev, STM32_DMA_SCR(id), dma_scr);
-
-		do {
-			dma_scr = stm32_dma_read(dmadev, STM32_DMA_SCR(id));
-			dma_scr &= STM32_DMA_SCR_EN;
-			if (!dma_scr)
-				break;
-
-			if (time_after_eq(jiffies, timeout)) {
-				dev_err(chan2dev(chan), "%s: timeout!\n",
-					__func__);
-				return -EBUSY;
-			}
-			cond_resched();
-		} while (1);
+		stm32_dma_write(dmadev, reg, dma_scr);
+
+		return readl_relaxed_poll_timeout_atomic(dmadev->base + reg,
+					dma_scr, !(dma_scr & STM32_DMA_SCR_EN),
+					10, 1000000);
 	}
 
 	return 0;
-- 
2.17.1


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

* [PATCH 8/8] dmaengine: stm32-dma: use vchan_terminate_vdesc() in .terminate_all
  2020-01-29 15:36 [PATCH 0/8] STM32 DMA driver fixes and improvements Amelie Delaunay
                   ` (6 preceding siblings ...)
  2020-01-29 15:36 ` [PATCH 7/8] dmaengine: stm32-dma: fix sleeping function called from invalid context Amelie Delaunay
@ 2020-01-29 15:36 ` Amelie Delaunay
  2020-02-25  5:45 ` [PATCH 0/8] STM32 DMA driver fixes and improvements Vinod Koul
  8 siblings, 0 replies; 10+ messages in thread
From: Amelie Delaunay @ 2020-01-29 15:36 UTC (permalink / raw)
  To: Vinod Koul, Dan Williams, Maxime Coquelin, Alexandre Torgue
  Cc: dmaengine, linux-stm32, linux-arm-kernel, linux-kernel,
	Amelie Delaunay, Pierre-Yves MORDRET

To avoid race with vchan_complete, use the race free way to terminate
running transfer.

Move vdesc->node list_del in stm32_dma_start_transfer instead of in
stm32_mdma_chan_complete to avoid another race in vchan_dma_desc_free_list.

Signed-off-by: Amelie Delaunay <amelie.delaunay@st.com>
---
 drivers/dma/stm32-dma.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/drivers/dma/stm32-dma.c b/drivers/dma/stm32-dma.c
index b585e11c2168..0ddbaa4b4f0b 100644
--- a/drivers/dma/stm32-dma.c
+++ b/drivers/dma/stm32-dma.c
@@ -478,8 +478,10 @@ static int stm32_dma_terminate_all(struct dma_chan *c)
 
 	spin_lock_irqsave(&chan->vchan.lock, flags);
 
-	if (chan->busy) {
-		stm32_dma_stop(chan);
+	if (chan->desc) {
+		vchan_terminate_vdesc(&chan->desc->vdesc);
+		if (chan->busy)
+			stm32_dma_stop(chan);
 		chan->desc = NULL;
 	}
 
@@ -535,6 +537,8 @@ static void stm32_dma_start_transfer(struct stm32_dma_chan *chan)
 		if (!vdesc)
 			return;
 
+		list_del(&vdesc->node);
+
 		chan->desc = to_stm32_dma_desc(vdesc);
 		chan->next_sg = 0;
 	}
@@ -613,7 +617,6 @@ static void stm32_dma_handle_chan_done(struct stm32_dma_chan *chan)
 		} else {
 			chan->busy = false;
 			if (chan->next_sg == chan->desc->num_sgs) {
-				list_del(&chan->desc->vdesc.node);
 				vchan_cookie_complete(&chan->desc->vdesc);
 				chan->desc = NULL;
 			}
-- 
2.17.1


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

* Re: [PATCH 0/8] STM32 DMA driver fixes and improvements
  2020-01-29 15:36 [PATCH 0/8] STM32 DMA driver fixes and improvements Amelie Delaunay
                   ` (7 preceding siblings ...)
  2020-01-29 15:36 ` [PATCH 8/8] dmaengine: stm32-dma: use vchan_terminate_vdesc() in .terminate_all Amelie Delaunay
@ 2020-02-25  5:45 ` Vinod Koul
  8 siblings, 0 replies; 10+ messages in thread
From: Vinod Koul @ 2020-02-25  5:45 UTC (permalink / raw)
  To: Amelie Delaunay
  Cc: Dan Williams, Maxime Coquelin, Alexandre Torgue, dmaengine,
	linux-stm32, linux-arm-kernel, linux-kernel, Pierre-Yves MORDRET

On 29-01-20, 16:36, Amelie Delaunay wrote:
> This series brings improvements to the STM32 DMA driver, with support of
> power management and descriptor reuse. Probe function gets a cleanup and
> properties like copy_align and max_segment_size are set.
> A "sleeping function called from invalid context" bug is also fixed. And
> to avoid a race with vchan_complete, driver now adopts
> vchan_terminate_vdesc().

Applied, thanks

-- 
~Vinod

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

end of thread, other threads:[~2020-02-25  5:45 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-29 15:36 [PATCH 0/8] STM32 DMA driver fixes and improvements Amelie Delaunay
2020-01-29 15:36 ` [PATCH 1/8] dmaengine: stm32-dma: add suspend/resume power management support Amelie Delaunay
2020-01-29 15:36 ` [PATCH 2/8] dmaengine: stm32-dma: use reset controller only at probe time Amelie Delaunay
2020-01-29 15:36 ` [PATCH 3/8] dmaengine: stm32-dma: driver defers probe for reset Amelie Delaunay
2020-01-29 15:36 ` [PATCH 4/8] dmaengine: stm32-dma: enable descriptor_reuse Amelie Delaunay
2020-01-29 15:36 ` [PATCH 5/8] dmaengine: stm32-dma: use dma_set_max_seg_size to set the sg limit Amelie Delaunay
2020-01-29 15:36 ` [PATCH 6/8] dmaengine: stm32-dma: add copy_align constraint Amelie Delaunay
2020-01-29 15:36 ` [PATCH 7/8] dmaengine: stm32-dma: fix sleeping function called from invalid context Amelie Delaunay
2020-01-29 15:36 ` [PATCH 8/8] dmaengine: stm32-dma: use vchan_terminate_vdesc() in .terminate_all Amelie Delaunay
2020-02-25  5:45 ` [PATCH 0/8] STM32 DMA driver fixes and improvements Vinod Koul

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).