Skip to contentSkip to conversation

i2c: use proper DMAENGINE API for termination

PATCH Applied Wolfram Sang 5 participants 22 messages Jun 23, 2021 – Aug 11, 2021

Subsystems (11)
lore
Share & tools
lore

Wolfram Sang

author maintainer
#0 lore raw

cover i2c: use proper DMAENGINE API for termination

dmaengine_terminate_all() is deprecated in favor of explicitly saying if it should be sync or async. Update the drivers I audited.

Wolfram Sang (7):
i2c: at91-master: : use proper DMAENGINE API for termination
i2c: imx: : use proper DMAENGINE API for termination
i2c: mxs: : use proper DMAENGINE API for termination
i2c: qup: : use proper DMAENGINE API for termination
i2c: rcar: : use proper DMAENGINE API for termination
i2c: sh_mobile: : use proper DMAENGINE API for termination
i2c: stm32f7: : use proper DMAENGINE API for termination

 drivers/i2c/busses/i2c-at91-master.c | 4 ++--
 drivers/i2c/busses/i2c-imx.c         | 6 +++---
 drivers/i2c/busses/i2c-mxs.c         | 4 ++--
 drivers/i2c/busses/i2c-qup.c         | 2 +-
 drivers/i2c/busses/i2c-rcar.c        | 4 ++--
 drivers/i2c/busses/i2c-sh_mobile.c   | 4 ++--
 drivers/i2c/busses/i2c-stm32f7.c     | 8 ++++----
 7 files changed, 16 insertions(+), 16 deletions(-)
Signature · 1 line
2.30.2
author maintainer
#1 lore raw

PATCH 1/7 i2c: at91-master: : use proper DMAENGINE API for termination

dmaengine_terminate_all() is deprecated in favor of explicitly saying if it should be sync or async. Here, we want dmaengine_terminate_sync() because there is no other synchronization code in the driver to handle an async case.

---
 drivers/i2c/busses/i2c-at91-master.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/i2c/busses/i2c-at91-master.c +2 -2
index 1cceb6866689..b0eae94909f4 100644
@@ -138,9 +138,9 @@ static void at91_twi_dma_cleanup(struct at91_twi_dev *dev)
 
 	if (dma->xfer_in_progress) {
 		if (dma->direction == DMA_FROM_DEVICE)
-			dmaengine_terminate_all(dma->chan_rx);
+			dmaengine_terminate_sync(dma->chan_rx);
 		else
-			dmaengine_terminate_all(dma->chan_tx);
+			dmaengine_terminate_sync(dma->chan_tx);
 		dma->xfer_in_progress = false;
 	}
 	if (dma->buf_mapped) {
Signature · 1 line
2.30.2
maintainer Reviewed-by on v1 1/7
#2 lore raw

Re: [PATCH 1/7] i2c: at91-master: : use proper DMAENGINE API for termination

Quoted 8 lines · Wolfram Sang

EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe

dmaengine_terminate_all() is deprecated in favor of explicitly saying if it should be sync or async. Here, we want dmaengine_terminate_sync() because there is no other synchronization code in the driver to handle an async case.

Thanks!

author maintainer Applied
#3 lore raw

Re: [PATCH 1/7] i2c: at91-master: : use proper DMAENGINE API for termination

In reply to Wolfram Sang
Quoted 6 lines · Wolfram Sang

dmaengine_terminate_all() is deprecated in favor of explicitly saying if it should be sync or async. Here, we want dmaengine_terminate_sync() because there is no other synchronization code in the driver to handle an async case.

Applied to for-next, thanks!

#4 lore raw

Re: [PATCH 1/7] i2c: at91-master: : use proper DMAENGINE API for termination

Quoted 10 lines · Wolfram Sang
Quoted 6 lines · Wolfram Sang

dmaengine_terminate_all() is deprecated in favor of explicitly saying if it should be sync or async. Here, we want dmaengine_terminate_sync() because there is no other synchronization code in the driver to handle an async case.

Applied to for-next, thanks!

just saw it now, there is a double : : in the subject. Maybe you could fix it if it's not too late...

Thanks and best regards,
Codrin

author maintainer
#5 lore raw

PATCH 2/7 i2c: imx: : use proper DMAENGINE API for termination

In reply to Wolfram Sang

dmaengine_terminate_all() is deprecated in favor of explicitly saying if it should be sync or async. Here, we want dmaengine_terminate_sync() because there is no other synchronization code in the driver to handle an async case.

---
 drivers/i2c/busses/i2c-imx.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/i2c/busses/i2c-imx.c +3 -3
index dc5ca71906db..b224e82924d2 100644
@@ -423,7 +423,7 @@ static int i2c_imx_dma_xfer(struct imx_i2c_struct *i2c_imx,
 	return 0;
 
 err_submit:
-	dmaengine_terminate_all(dma->chan_using);
+	dmaengine_terminate_sync(dma->chan_using);
 err_desc:
 	dma_unmap_single(chan_dev, dma->dma_buf,
 			dma->dma_len, dma->dma_data_dir);
@@ -899,7 +899,7 @@ static int i2c_imx_dma_write(struct imx_i2c_struct *i2c_imx,
 				&i2c_imx->dma->cmd_complete,
 				msecs_to_jiffies(DMA_TIMEOUT));
 	if (time_left == 0) {
-		dmaengine_terminate_all(dma->chan_using);
+		dmaengine_terminate_sync(dma->chan_using);
 		return -ETIMEDOUT;
 	}
 
@@ -954,7 +954,7 @@ static int i2c_imx_dma_read(struct imx_i2c_struct *i2c_imx,
 				&i2c_imx->dma->cmd_complete,
 				msecs_to_jiffies(DMA_TIMEOUT));
 	if (time_left == 0) {
-		dmaengine_terminate_all(dma->chan_using);
+		dmaengine_terminate_sync(dma->chan_using);
 		return -ETIMEDOUT;
 	}
 
Signature · 1 line
2.30.2
maintainer Reviewed-by on v1 2/7
#6 lore raw

Re: [PATCH 2/7] i2c: imx: : use proper DMAENGINE API for termination

Hello Wolfram,

Quoted 6 lines · Wolfram Sang

dmaengine_terminate_all() is deprecated in favor of explicitly saying if it should be sync or async. Here, we want dmaengine_terminate_sync() because there is no other synchronization code in the driver to handle an async case.

Thank you!

Quoted 39 lines
---
 drivers/i2c/busses/i2c-imx.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/i2c/busses/i2c-imx.c +3 -3
index dc5ca71906db..b224e82924d2 100644
@@ -423,7 +423,7 @@ static int i2c_imx_dma_xfer(struct imx_i2c_struct *i2c_imx,
 	return 0;
 
 err_submit:
-	dmaengine_terminate_all(dma->chan_using);
+	dmaengine_terminate_sync(dma->chan_using);
 err_desc:
 	dma_unmap_single(chan_dev, dma->dma_buf,
 			dma->dma_len, dma->dma_data_dir);
@@ -899,7 +899,7 @@ static int i2c_imx_dma_write(struct imx_i2c_struct *i2c_imx,
 				&i2c_imx->dma->cmd_complete,
 				msecs_to_jiffies(DMA_TIMEOUT));
 	if (time_left == 0) {
-		dmaengine_terminate_all(dma->chan_using);
+		dmaengine_terminate_sync(dma->chan_using);
 		return -ETIMEDOUT;
 	}
 
@@ -954,7 +954,7 @@ static int i2c_imx_dma_read(struct imx_i2c_struct *i2c_imx,
 				&i2c_imx->dma->cmd_complete,
 				msecs_to_jiffies(DMA_TIMEOUT));
 	if (time_left == 0) {
-		dmaengine_terminate_all(dma->chan_using);
+		dmaengine_terminate_sync(dma->chan_using);
 		return -ETIMEDOUT;
 	}
 
Signature · 1 line
2.30.2
Signature · 4 lines
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |
author maintainer Applied
#7 lore raw

Re: [PATCH 2/7] i2c: imx: : use proper DMAENGINE API for termination

In reply to Wolfram Sang
Quoted 6 lines · Wolfram Sang

dmaengine_terminate_all() is deprecated in favor of explicitly saying if it should be sync or async. Here, we want dmaengine_terminate_sync() because there is no other synchronization code in the driver to handle an async case.

Applied to for-next, thanks!

author maintainer
#8 lore raw

PATCH 3/7 i2c: mxs: : use proper DMAENGINE API for termination

In reply to Wolfram Sang

dmaengine_terminate_all() is deprecated in favor of explicitly saying if it should be sync or async. Here, we want dmaengine_terminate_sync() because there is no other synchronization code in the driver to handle an async case.

---
 drivers/i2c/busses/i2c-mxs.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/i2c/busses/i2c-mxs.c +2 -2
index f97243f02231..864a3f1bd4e1 100644
@@ -290,14 +290,14 @@ static int mxs_i2c_dma_setup_xfer(struct i2c_adapter *adap,
 select_init_dma_fail:
 	dma_unmap_sg(i2c->dev, &i2c->sg_io[0], 1, DMA_TO_DEVICE);
 select_init_pio_fail:
-	dmaengine_terminate_all(i2c->dmach);
+	dmaengine_terminate_sync(i2c->dmach);
 	return -EINVAL;
 
 /* Write failpath. */
 write_init_dma_fail:
 	dma_unmap_sg(i2c->dev, i2c->sg_io, 2, DMA_TO_DEVICE);
 write_init_pio_fail:
-	dmaengine_terminate_all(i2c->dmach);
+	dmaengine_terminate_sync(i2c->dmach);
 	return -EINVAL;
 }
 
Signature · 1 line
2.30.2
author maintainer Applied
#9 lore raw

Re: [PATCH 3/7] i2c: mxs: : use proper DMAENGINE API for termination

Quoted 6 lines · Wolfram Sang

dmaengine_terminate_all() is deprecated in favor of explicitly saying if it should be sync or async. Here, we want dmaengine_terminate_sync() because there is no other synchronization code in the driver to handle an async case.

Applied to for-next, thanks!

author maintainer
#10 lore raw

PATCH 4/7 i2c: qup: : use proper DMAENGINE API for termination

In reply to Wolfram Sang

dmaengine_terminate_all() is deprecated in favor of explicitly saying if it should be sync or async. Here, we want dmaengine_terminate_sync() because there is no other synchronization code in the driver to handle an async case.

---
 drivers/i2c/busses/i2c-qup.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/i2c/busses/i2c-qup.c +1 -1
index 61dc20fd1191..fcd35e8de83c 100644
@@ -778,7 +778,7 @@ static int qup_i2c_bam_schedule_desc(struct qup_i2c_dev *qup)
 			ret = -EINVAL;
 
 			/* abort TX descriptors */
-			dmaengine_terminate_all(qup->btx.dma);
+			dmaengine_terminate_sync(qup->btx.dma);
 			goto desc_err;
 		}
 
Signature · 1 line
2.30.2
author maintainer Applied
#11 lore raw

Re: [PATCH 4/7] i2c: qup: : use proper DMAENGINE API for termination

Quoted 6 lines · Wolfram Sang

dmaengine_terminate_all() is deprecated in favor of explicitly saying if it should be sync or async. Here, we want dmaengine_terminate_sync() because there is no other synchronization code in the driver to handle an async case.

Applied to for-next, thanks!

author maintainer
#12 lore raw

PATCH 5/7 i2c: rcar: : use proper DMAENGINE API for termination

In reply to Wolfram Sang

dmaengine_terminate_all() is deprecated in favor of explicitly saying if it should be sync or async. Here, we want dmaengine_terminate_sync() because there is no other synchronization code in the driver to handle an async case.

---
 drivers/i2c/busses/i2c-rcar.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/i2c/busses/i2c-rcar.c +2 -2
index 327c092a4130..41ff327882ef 100644
@@ -391,9 +391,9 @@ static void rcar_i2c_cleanup_dma(struct rcar_i2c_priv *priv)
 	if (priv->dma_direction == DMA_NONE)
 		return;
 	else if (priv->dma_direction == DMA_FROM_DEVICE)
-		dmaengine_terminate_all(priv->dma_rx);
+		dmaengine_terminate_sync(priv->dma_rx);
 	else if (priv->dma_direction == DMA_TO_DEVICE)
-		dmaengine_terminate_all(priv->dma_tx);
+		dmaengine_terminate_sync(priv->dma_tx);
 
 	rcar_i2c_dma_unmap(priv);
 }
Signature · 1 line
2.30.2
#13 lore raw

Re: [PATCH 5/7] i2c: rcar: : use proper DMAENGINE API for termination

Hi Wolfram,

Quoted 6 lines · Wolfram Sang

dmaengine_terminate_all() is deprecated in favor of explicitly saying if it should be sync or async. Here, we want dmaengine_terminate_sync() because there is no other synchronization code in the driver to handle an async case.

Thanks for your patch!

Is this safe? The driver is not using a threaded irq, and DMA termination may be called from the interrupt handler.

Have you tried triggering DMA termination, with lockdep enabled?

Gr{oetje,eeting}s,

Geert

Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds
author maintainer
#14 lore raw

Re: [PATCH 5/7] i2c: rcar: : use proper DMAENGINE API for termination

Quoted 3 lines

Is this safe? The driver is not using a threaded irq, and DMA termination may be called from the interrupt handler.

You are right, this will not work. Not my best day today, I overlooked it for i2c-rcar and lost the note pointing out the same issue for stm32f7 :(

Quoted 1 line

Have you tried triggering DMA termination, with lockdep enabled?

Nope. As the code didn't show signs of async nature, I assumed sync was desired anyhow.

author maintainer
#15 lore raw

PATCH 6/7 i2c: sh_mobile: : use proper DMAENGINE API for termination

In reply to Wolfram Sang

dmaengine_terminate_all() is deprecated in favor of explicitly saying if it should be sync or async. Here, we want dmaengine_terminate_sync() because there is no other synchronization code in the driver to handle an async case.

---
 drivers/i2c/busses/i2c-sh_mobile.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/i2c/busses/i2c-sh_mobile.c +2 -2
index 2d2e630fd438..db8fa4186814 100644
@@ -458,9 +458,9 @@ static void sh_mobile_i2c_cleanup_dma(struct sh_mobile_i2c_data *pd)
 	if (pd->dma_direction == DMA_NONE)
 		return;
 	else if (pd->dma_direction == DMA_FROM_DEVICE)
-		dmaengine_terminate_all(pd->dma_rx);
+		dmaengine_terminate_sync(pd->dma_rx);
 	else if (pd->dma_direction == DMA_TO_DEVICE)
-		dmaengine_terminate_all(pd->dma_tx);
+		dmaengine_terminate_sync(pd->dma_tx);
 
 	sh_mobile_i2c_dma_unmap(pd);
 }
Signature · 1 line
2.30.2
author maintainer Applied
#16 lore raw

Re: [PATCH 6/7] i2c: sh_mobile: : use proper DMAENGINE API for termination

Quoted 6 lines · Wolfram Sang

dmaengine_terminate_all() is deprecated in favor of explicitly saying if it should be sync or async. Here, we want dmaengine_terminate_sync() because there is no other synchronization code in the driver to handle an async case.

Applied to for-next, thanks!

author maintainer
#17 lore raw

PATCH 7/7 i2c: stm32f7: : use proper DMAENGINE API for termination

In reply to Wolfram Sang

dmaengine_terminate_all() is deprecated in favor of explicitly saying if it should be sync or async. Here, we want dmaengine_terminate_sync() because there is no other synchronization code in the driver to handle an async case.

---
 drivers/i2c/busses/i2c-stm32f7.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/i2c/busses/i2c-stm32f7.c +4 -4
index 0138317ea600..9ea074a7ced6 100644
@@ -1567,7 +1567,7 @@ static irqreturn_t stm32f7_i2c_isr_event_thread(int irq, void *data)
 	if (!ret) {
 		dev_dbg(i2c_dev->dev, "<%s>: Timed out\n", __func__);
 		stm32f7_i2c_disable_dma_req(i2c_dev);
-		dmaengine_terminate_all(dma->chan_using);
+		dmaengine_terminate_sync(dma->chan_using);
 		f7_msg->result = -ETIMEDOUT;
 	}
 
@@ -1637,7 +1637,7 @@ static irqreturn_t stm32f7_i2c_isr_error(int irq, void *data)
 	/* Disable dma */
 	if (i2c_dev->use_dma) {
 		stm32f7_i2c_disable_dma_req(i2c_dev);
-		dmaengine_terminate_all(dma->chan_using);
+		dmaengine_terminate_sync(dma->chan_using);
 	}
 
 	i2c_dev->master_mode = false;
@@ -1678,7 +1678,7 @@ static int stm32f7_i2c_xfer(struct i2c_adapter *i2c_adap,
 		dev_dbg(i2c_dev->dev, "Access to slave 0x%x timed out\n",
 			i2c_dev->msg->addr);
 		if (i2c_dev->use_dma)
-			dmaengine_terminate_all(dma->chan_using);
+			dmaengine_terminate_sync(dma->chan_using);
 		ret = -ETIMEDOUT;
 	}
 
@@ -1727,7 +1727,7 @@ static int stm32f7_i2c_smbus_xfer(struct i2c_adapter *adapter, u16 addr,
 	if (!timeout) {
 		dev_dbg(dev, "Access to slave 0x%x timed out\n", f7_msg->addr);
 		if (i2c_dev->use_dma)
-			dmaengine_terminate_all(dma->chan_using);
+			dmaengine_terminate_sync(dma->chan_using);
 		ret = -ETIMEDOUT;
 		goto pm_free;
 	}
Signature · 1 line
2.30.2
author maintainer
#18 lore raw

Re: [PATCH 7/7] i2c: stm32f7: : use proper DMAENGINE API for termination

Quoted 6 lines · Wolfram Sang

dmaengine_terminate_all() is deprecated in favor of explicitly saying if it should be sync or async. Here, we want dmaengine_terminate_sync() because there is no other synchronization code in the driver to handle an async case.

Eeks, this is called from irq context as well. Broken patch :(

maintainer
#19 lore raw

Re: [PATCH 7/7] i2c: stm32f7: : use proper DMAENGINE API for termination

Hi Wolfram,

thanks for the update. If you are ok with that I modify the patch to partially rely on _async / synchronize whenever needed and push it again separately.

Regards,
Alain

Quoted 10 lines · Wolfram Sang
Quoted 6 lines · Wolfram Sang

dmaengine_terminate_all() is deprecated in favor of explicitly saying if it should be sync or async. Here, we want dmaengine_terminate_sync() because there is no other synchronization code in the driver to handle an async case.

Eeks, this is called from irq context as well. Broken patch :(

author maintainer
#20 lore raw

Re: [PATCH 7/7] i2c: stm32f7: : use proper DMAENGINE API for termination

Hi Alain,

Quoted 3 lines

thanks for the update. If you are ok with that I modify the patch to partially rely on _async / synchronize whenever needed and push it again separately.

Perfect, thanks!

All the best,

Wolfram

author maintainer
#21 lore raw
In reply to Wolfram Sang
Quoted 2 lines · Wolfram Sang

dmaengine_terminate_all() is deprecated in favor of explicitly saying if it should be sync or async. Update the drivers I audited.

I applied the patches now, except for i2c-rcar and i2c-stm32f7 where this approach can't be used because of interrupt context. I will check for i2c-rcar how to do this properly and Alain for i2c-stm32f7 and we will resend then.