diff mbox series

[v1,2/2] i3c: mipi-i3c-hci: Use DMA-safe buffer for I2C transfers

Message ID 20250121110756.214714-2-billy_tsai@aspeedtech.com (mailing list archive)
State New
Headers show
Series [v1,1/2] i3c: Remove the const qualifier from i2c_msg pointer in i2c_xfers API | expand

Commit Message

Billy Tsai Jan. 21, 2025, 11:07 a.m. UTC
The i2c_get_dma_safe_msg_buf function is used to ensure safe handling of
I2C messages in HCI DMA mode.

Signed-off-by: Billy Tsai <billy_tsai@aspeedtech.com>
---
 drivers/i3c/master/mipi-i3c-hci/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Wolfram Sang Jan. 21, 2025, 10:19 p.m. UTC | #1
> -		xfer[i].data = i2c_xfers[i].buf;
> +		xfer[i].data = i2c_get_dma_safe_msg_buf(&i2c_xfers[i], 1);

Where is a 'get' there also should be a 'put'.
Mukesh Kumar Savaliya Jan. 22, 2025, 7:11 a.m. UTC | #2
On 1/21/2025 4:37 PM, Billy Tsai wrote:
> The i2c_get_dma_safe_msg_buf function is used to ensure safe handling of
> I2C messages in HCI DMA mode.
> 
> Signed-off-by: Billy Tsai <billy_tsai@aspeedtech.com>
> ---
>   drivers/i3c/master/mipi-i3c-hci/core.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/i3c/master/mipi-i3c-hci/core.c b/drivers/i3c/master/mipi-i3c-hci/core.c
> index a408feac3e9e..3567cd566339 100644
> --- a/drivers/i3c/master/mipi-i3c-hci/core.c
> +++ b/drivers/i3c/master/mipi-i3c-hci/core.c
> @@ -382,7 +382,7 @@ static int i3c_hci_i2c_xfers(struct i2c_dev_desc *dev,
>   		return -ENOMEM;
>   
>   	for (i = 0; i < nxfers; i++) {
> -		xfer[i].data = i2c_xfers[i].buf;
> +		xfer[i].data = i2c_get_dma_safe_msg_buf(&i2c_xfers[i], 1);
Should be i2c_xfers[i].buf ? IIUC, it's iterating over many message 
buffers upto nxfers.
>   		xfer[i].data_len = i2c_xfers[i].len;
>   		xfer[i].rnw = i2c_xfers[i].flags & I2C_M_RD;
>   		hci->cmd->prep_i2c_xfer(hci, dev, &xfer[i]);
Jarkko Nikula Jan. 22, 2025, 8:28 a.m. UTC | #3
On 1/21/25 1:07 PM, Billy Tsai wrote:
> The i2c_get_dma_safe_msg_buf function is used to ensure safe handling of
> I2C messages in HCI DMA mode.
> 
> Signed-off-by: Billy Tsai <billy_tsai@aspeedtech.com>
> ---
>   drivers/i3c/master/mipi-i3c-hci/core.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/i3c/master/mipi-i3c-hci/core.c b/drivers/i3c/master/mipi-i3c-hci/core.c
> index a408feac3e9e..3567cd566339 100644
> --- a/drivers/i3c/master/mipi-i3c-hci/core.c
> +++ b/drivers/i3c/master/mipi-i3c-hci/core.c
> @@ -382,7 +382,7 @@ static int i3c_hci_i2c_xfers(struct i2c_dev_desc *dev,
>   		return -ENOMEM;
>   
>   	for (i = 0; i < nxfers; i++) {
> -		xfer[i].data = i2c_xfers[i].buf;
> +		xfer[i].data = i2c_get_dma_safe_msg_buf(&i2c_xfers[i], 1);
>   		xfer[i].data_len = i2c_xfers[i].len;
>   		xfer[i].rnw = i2c_xfers[i].flags & I2C_M_RD;
>   		hci->cmd->prep_i2c_xfer(hci, dev, &xfer[i]);

This allow to remove calls to i3c_hci_alloc_safe_xfer_buf() and 
i3c_hci_free_safe_xfer_buf() in i3c_hci_i2c_xfers().

I was pondering the i2c_get_dma_safe_msg_buf() when making commit 
4afd72876942 ("i3c: mipi-i3c-hci: Add DMA bounce buffer for private 
transfers") but decided to reuse the same (own) helper for both 
i3c_hci_priv_xfers() and i3c_hci_i2c_xfers().

In that sense I'd modify the commit log a bit that instead of ensuring 
safe handling patch switches from custom helper to 
i2c_get_dma_safe_msg_buf() and i2c_put_dma_safe_msg_buf() (please note 
the comment from Wolfram).
Billy Tsai Jan. 23, 2025, 10:23 a.m. UTC | #4
> > -             xfer[i].data = i2c_xfers[i].buf;

> > +             xfer[i].data = i2c_get_dma_safe_msg_buf(&i2c_xfers[i], 1);

> Where is a 'get' there also should be a 'put'.

Thanks.
I will add the i2c_put_dma_safe_msg_buf in the next version.

Billy Tsai
diff mbox series

Patch

diff --git a/drivers/i3c/master/mipi-i3c-hci/core.c b/drivers/i3c/master/mipi-i3c-hci/core.c
index a408feac3e9e..3567cd566339 100644
--- a/drivers/i3c/master/mipi-i3c-hci/core.c
+++ b/drivers/i3c/master/mipi-i3c-hci/core.c
@@ -382,7 +382,7 @@  static int i3c_hci_i2c_xfers(struct i2c_dev_desc *dev,
 		return -ENOMEM;
 
 	for (i = 0; i < nxfers; i++) {
-		xfer[i].data = i2c_xfers[i].buf;
+		xfer[i].data = i2c_get_dma_safe_msg_buf(&i2c_xfers[i], 1);
 		xfer[i].data_len = i2c_xfers[i].len;
 		xfer[i].rnw = i2c_xfers[i].flags & I2C_M_RD;
 		hci->cmd->prep_i2c_xfer(hci, dev, &xfer[i]);