All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] i2c: imx: Only DMA messages with I2C_M_DMA_SAFE flag set
@ 2022-11-09 23:59 Andrew Lunn
  2022-11-16  9:02 ` Oleksij Rempel
  2022-12-01 23:12 ` Wolfram Sang
  0 siblings, 2 replies; 3+ messages in thread
From: Andrew Lunn @ 2022-11-09 23:59 UTC (permalink / raw)
  To: linux-i2c
  Cc: Oleksij Rempel, kernel, Shawn Guo, Sascha Hauer, Fabio Estevam,
	Andrew Lunn

Recent changes to the DMA code has resulting in the IMX driver failing
I2C transfers when the buffer has been vmalloc. Only perform DMA
transfers if the message has the I2C_M_DMA_SAFE flag set, indicating
the client is providing a buffer which is DMA safe.

This is a minimal fix for stable. The I2C core provides helpers to
allocate a bounce buffer. For a fuller fix the master should make use
of these helpers.

Fixes: 4544b9f25e70 ("dma-mapping: Add vmap checks to dma_map_single()")
Signed-off-by: Andrew Lunn <andrew@lunn.ch>
---
 drivers/i2c/busses/i2c-imx.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/i2c/busses/i2c-imx.c b/drivers/i2c/busses/i2c-imx.c
index 3082183bd66a..fc70920c4dda 100644
--- a/drivers/i2c/busses/i2c-imx.c
+++ b/drivers/i2c/busses/i2c-imx.c
@@ -1132,7 +1132,8 @@ static int i2c_imx_read(struct imx_i2c_struct *i2c_imx, struct i2c_msg *msgs,
 	int i, result;
 	unsigned int temp;
 	int block_data = msgs->flags & I2C_M_RECV_LEN;
-	int use_dma = i2c_imx->dma && msgs->len >= DMA_THRESHOLD && !block_data;
+	int use_dma = i2c_imx->dma && msgs->flags & I2C_M_DMA_SAFE &&
+		msgs->len >= DMA_THRESHOLD && !block_data;
 
 	dev_dbg(&i2c_imx->adapter.dev,
 		"<%s> write slave address: addr=0x%x\n",
@@ -1298,7 +1299,8 @@ static int i2c_imx_xfer_common(struct i2c_adapter *adapter,
 			result = i2c_imx_read(i2c_imx, &msgs[i], is_lastmsg, atomic);
 		} else {
 			if (!atomic &&
-			    i2c_imx->dma && msgs[i].len >= DMA_THRESHOLD)
+			    i2c_imx->dma && msgs[i].len >= DMA_THRESHOLD &&
+				msgs[i].flags & I2C_M_DMA_SAFE)
 				result = i2c_imx_dma_write(i2c_imx, &msgs[i]);
 			else
 				result = i2c_imx_write(i2c_imx, &msgs[i], atomic);
-- 
2.37.2


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

* Re: [PATCH] i2c: imx: Only DMA messages with I2C_M_DMA_SAFE flag set
  2022-11-09 23:59 [PATCH] i2c: imx: Only DMA messages with I2C_M_DMA_SAFE flag set Andrew Lunn
@ 2022-11-16  9:02 ` Oleksij Rempel
  2022-12-01 23:12 ` Wolfram Sang
  1 sibling, 0 replies; 3+ messages in thread
From: Oleksij Rempel @ 2022-11-16  9:02 UTC (permalink / raw)
  To: Andrew Lunn
  Cc: linux-i2c, Oleksij Rempel, kernel, Shawn Guo, Sascha Hauer,
	Fabio Estevam

On Thu, Nov 10, 2022 at 12:59:02AM +0100, Andrew Lunn wrote:
> Recent changes to the DMA code has resulting in the IMX driver failing
> I2C transfers when the buffer has been vmalloc. Only perform DMA
> transfers if the message has the I2C_M_DMA_SAFE flag set, indicating
> the client is providing a buffer which is DMA safe.
> 
> This is a minimal fix for stable. The I2C core provides helpers to
> allocate a bounce buffer. For a fuller fix the master should make use
> of these helpers.
> 
> Fixes: 4544b9f25e70 ("dma-mapping: Add vmap checks to dma_map_single()")
> Signed-off-by: Andrew Lunn <andrew@lunn.ch>

Acked-by: Oleksij Rempel <o.rempel@pengutronix.de>

> ---
>  drivers/i2c/busses/i2c-imx.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/i2c/busses/i2c-imx.c b/drivers/i2c/busses/i2c-imx.c
> index 3082183bd66a..fc70920c4dda 100644
> --- a/drivers/i2c/busses/i2c-imx.c
> +++ b/drivers/i2c/busses/i2c-imx.c
> @@ -1132,7 +1132,8 @@ static int i2c_imx_read(struct imx_i2c_struct *i2c_imx, struct i2c_msg *msgs,
>  	int i, result;
>  	unsigned int temp;
>  	int block_data = msgs->flags & I2C_M_RECV_LEN;
> -	int use_dma = i2c_imx->dma && msgs->len >= DMA_THRESHOLD && !block_data;
> +	int use_dma = i2c_imx->dma && msgs->flags & I2C_M_DMA_SAFE &&
> +		msgs->len >= DMA_THRESHOLD && !block_data;
>  
>  	dev_dbg(&i2c_imx->adapter.dev,
>  		"<%s> write slave address: addr=0x%x\n",
> @@ -1298,7 +1299,8 @@ static int i2c_imx_xfer_common(struct i2c_adapter *adapter,
>  			result = i2c_imx_read(i2c_imx, &msgs[i], is_lastmsg, atomic);
>  		} else {
>  			if (!atomic &&
> -			    i2c_imx->dma && msgs[i].len >= DMA_THRESHOLD)
> +			    i2c_imx->dma && msgs[i].len >= DMA_THRESHOLD &&
> +				msgs[i].flags & I2C_M_DMA_SAFE)
>  				result = i2c_imx_dma_write(i2c_imx, &msgs[i]);
>  			else
>  				result = i2c_imx_write(i2c_imx, &msgs[i], atomic);
> -- 
> 2.37.2
> 
> 

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

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

* Re: [PATCH] i2c: imx: Only DMA messages with I2C_M_DMA_SAFE flag set
  2022-11-09 23:59 [PATCH] i2c: imx: Only DMA messages with I2C_M_DMA_SAFE flag set Andrew Lunn
  2022-11-16  9:02 ` Oleksij Rempel
@ 2022-12-01 23:12 ` Wolfram Sang
  1 sibling, 0 replies; 3+ messages in thread
From: Wolfram Sang @ 2022-12-01 23:12 UTC (permalink / raw)
  To: Andrew Lunn
  Cc: linux-i2c, Oleksij Rempel, kernel, Shawn Guo, Sascha Hauer,
	Fabio Estevam

[-- Attachment #1: Type: text/plain, Size: 663 bytes --]

On Thu, Nov 10, 2022 at 12:59:02AM +0100, Andrew Lunn wrote:
> Recent changes to the DMA code has resulting in the IMX driver failing
> I2C transfers when the buffer has been vmalloc. Only perform DMA
> transfers if the message has the I2C_M_DMA_SAFE flag set, indicating
> the client is providing a buffer which is DMA safe.
> 
> This is a minimal fix for stable. The I2C core provides helpers to
> allocate a bounce buffer. For a fuller fix the master should make use
> of these helpers.
> 
> Fixes: 4544b9f25e70 ("dma-mapping: Add vmap checks to dma_map_single()")
> Signed-off-by: Andrew Lunn <andrew@lunn.ch>

Applied to for-current, thanks!


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

end of thread, other threads:[~2022-12-01 23:13 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-09 23:59 [PATCH] i2c: imx: Only DMA messages with I2C_M_DMA_SAFE flag set Andrew Lunn
2022-11-16  9:02 ` Oleksij Rempel
2022-12-01 23:12 ` Wolfram Sang

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.