public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 1/2] i3c: Remove the const qualifier from i2c_msg pointer in i2c_xfers API
@ 2025-02-04  9:17 Billy Tsai
  2025-02-04  9:17 ` [PATCH v2 2/2] i3c: mipi-i3c-hci: Use I2C DMA-safe api Billy Tsai
                   ` (3 more replies)
  0 siblings, 4 replies; 12+ messages in thread
From: Billy Tsai @ 2025-02-04  9:17 UTC (permalink / raw)
  To: alexandre.belloni, pgaj, miquel.raynal, conor.culhane,
	aniketmaurya, billy_tsai, Shyam-sundar.S-k, jarkko.nikula,
	wsa+renesas, xiaopei01, Guruvendra.Punugupati, linux-i3c,
	linux-kernel, BMC-SW

The change is necessary to enable the use of the
`i2c_get_dma_safe_msg_buf()` API, which requires a non-const
`struct i2c_msg *` to operate. The `i2c_get_dma_safe_msg_buf()` function
ensures safe handling of I2C messages when using DMA, making it essential
for scenarios where DMA transfers are involved. By removing the `const`
qualifier, this patch allows drivers to prepare and manage DMA-safe
buffers directly.

Signed-off-by: Billy Tsai <billy_tsai@aspeedtech.com>
---
 drivers/i3c/master/dw-i3c-master.c     | 2 +-
 drivers/i3c/master/i3c-master-cdns.c   | 2 +-
 drivers/i3c/master/mipi-i3c-hci/core.c | 2 +-
 drivers/i3c/master/svc-i3c-master.c    | 2 +-
 include/linux/i3c/master.h             | 2 +-
 5 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/i3c/master/dw-i3c-master.c b/drivers/i3c/master/dw-i3c-master.c
index d09ea5b6467c..54c7d86997d5 100644
--- a/drivers/i3c/master/dw-i3c-master.c
+++ b/drivers/i3c/master/dw-i3c-master.c
@@ -1079,7 +1079,7 @@ static void dw_i3c_master_detach_i3c_dev(struct i3c_dev_desc *dev)
 }
 
 static int dw_i3c_master_i2c_xfers(struct i2c_dev_desc *dev,
-				   const struct i2c_msg *i2c_xfers,
+				   struct i2c_msg *i2c_xfers,
 				   int i2c_nxfers)
 {
 	struct dw_i3c_i2c_dev_data *data = i2c_dev_get_master_data(dev);
diff --git a/drivers/i3c/master/i3c-master-cdns.c b/drivers/i3c/master/i3c-master-cdns.c
index 8d69a34986d9..c9e4c129454c 100644
--- a/drivers/i3c/master/i3c-master-cdns.c
+++ b/drivers/i3c/master/i3c-master-cdns.c
@@ -813,7 +813,7 @@ static int cdns_i3c_master_priv_xfers(struct i3c_dev_desc *dev,
 }
 
 static int cdns_i3c_master_i2c_xfers(struct i2c_dev_desc *dev,
-				     const struct i2c_msg *xfers, int nxfers)
+				     struct i2c_msg *xfers, int nxfers)
 {
 	struct i3c_master_controller *m = i2c_dev_get_master(dev);
 	struct cdns_i3c_master *master = to_cdns_i3c_master(m);
diff --git a/drivers/i3c/master/mipi-i3c-hci/core.c b/drivers/i3c/master/mipi-i3c-hci/core.c
index e6e482a259b4..a408feac3e9e 100644
--- a/drivers/i3c/master/mipi-i3c-hci/core.c
+++ b/drivers/i3c/master/mipi-i3c-hci/core.c
@@ -367,7 +367,7 @@ static int i3c_hci_priv_xfers(struct i3c_dev_desc *dev,
 }
 
 static int i3c_hci_i2c_xfers(struct i2c_dev_desc *dev,
-			     const struct i2c_msg *i2c_xfers, int nxfers)
+			     struct i2c_msg *i2c_xfers, int nxfers)
 {
 	struct i3c_master_controller *m = i2c_dev_get_master(dev);
 	struct i3c_hci *hci = to_i3c_hci(m);
diff --git a/drivers/i3c/master/svc-i3c-master.c b/drivers/i3c/master/svc-i3c-master.c
index c1ee3828e7ee..24bd701b5de0 100644
--- a/drivers/i3c/master/svc-i3c-master.c
+++ b/drivers/i3c/master/svc-i3c-master.c
@@ -1584,7 +1584,7 @@ static int svc_i3c_master_priv_xfers(struct i3c_dev_desc *dev,
 }
 
 static int svc_i3c_master_i2c_xfers(struct i2c_dev_desc *dev,
-				    const struct i2c_msg *xfers,
+				    struct i2c_msg *xfers,
 				    int nxfers)
 {
 	struct i3c_master_controller *m = i2c_dev_get_master(dev);
diff --git a/include/linux/i3c/master.h b/include/linux/i3c/master.h
index 12d532b012c5..c67922ece617 100644
--- a/include/linux/i3c/master.h
+++ b/include/linux/i3c/master.h
@@ -475,7 +475,7 @@ struct i3c_master_controller_ops {
 	int (*attach_i2c_dev)(struct i2c_dev_desc *dev);
 	void (*detach_i2c_dev)(struct i2c_dev_desc *dev);
 	int (*i2c_xfers)(struct i2c_dev_desc *dev,
-			 const struct i2c_msg *xfers, int nxfers);
+			 struct i2c_msg *xfers, int nxfers);
 	int (*request_ibi)(struct i3c_dev_desc *dev,
 			   const struct i3c_ibi_setup *req);
 	void (*free_ibi)(struct i3c_dev_desc *dev);
-- 
2.25.1


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

* [PATCH v2 2/2] i3c: mipi-i3c-hci: Use I2C DMA-safe api
  2025-02-04  9:17 [PATCH v2 1/2] i3c: Remove the const qualifier from i2c_msg pointer in i2c_xfers API Billy Tsai
@ 2025-02-04  9:17 ` Billy Tsai
  2025-02-04 15:16   ` Mukesh Kumar Savaliya
  2025-02-05 16:51   ` Frank Li
  2025-02-04  9:50 ` [PATCH v2 1/2] i3c: Remove the const qualifier from i2c_msg pointer in i2c_xfers API Thomas Weißschuh
                   ` (2 subsequent siblings)
  3 siblings, 2 replies; 12+ messages in thread
From: Billy Tsai @ 2025-02-04  9:17 UTC (permalink / raw)
  To: alexandre.belloni, pgaj, miquel.raynal, conor.culhane,
	aniketmaurya, billy_tsai, Shyam-sundar.S-k, jarkko.nikula,
	wsa+renesas, xiaopei01, Guruvendra.Punugupati, linux-i3c,
	linux-kernel, BMC-SW

Use the i2c_get/put_dma_safe_msg_buf for I2C transfers instead of using
the I3C-specific API.

Signed-off-by: Billy Tsai <billy_tsai@aspeedtech.com>
---
 drivers/i3c/master/mipi-i3c-hci/core.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/drivers/i3c/master/mipi-i3c-hci/core.c b/drivers/i3c/master/mipi-i3c-hci/core.c
index a408feac3e9e..4f3738beb0f2 100644
--- a/drivers/i3c/master/mipi-i3c-hci/core.c
+++ b/drivers/i3c/master/mipi-i3c-hci/core.c
@@ -382,14 +382,11 @@ 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]);
 		xfer[i].cmd_desc[0] |= CMD_0_ROC;
-		ret = i3c_hci_alloc_safe_xfer_buf(hci, &xfer[i]);
-		if (ret)
-			goto out;
 	}
 	last = i - 1;
 	xfer[last].cmd_desc[0] |= CMD_0_TOC;
@@ -412,7 +409,8 @@ static int i3c_hci_i2c_xfers(struct i2c_dev_desc *dev,
 
 out:
 	for (i = 0; i < nxfers; i++)
-		i3c_hci_free_safe_xfer_buf(hci, &xfer[i]);
+		i2c_put_dma_safe_msg_buf(xfer[i].data, &i2c_xfers[i],
+					 ret ? false : true);
 
 	hci_free_xfer(xfer, nxfers);
 	return ret;
-- 
2.25.1


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

* Re: [PATCH v2 1/2] i3c: Remove the const qualifier from i2c_msg pointer in i2c_xfers API
  2025-02-04  9:17 [PATCH v2 1/2] i3c: Remove the const qualifier from i2c_msg pointer in i2c_xfers API Billy Tsai
  2025-02-04  9:17 ` [PATCH v2 2/2] i3c: mipi-i3c-hci: Use I2C DMA-safe api Billy Tsai
@ 2025-02-04  9:50 ` Thomas Weißschuh
  2025-02-04 10:09   ` Billy Tsai
  2025-02-05 16:50 ` Frank Li
  2025-02-20 22:09 ` Alexandre Belloni
  3 siblings, 1 reply; 12+ messages in thread
From: Thomas Weißschuh @ 2025-02-04  9:50 UTC (permalink / raw)
  To: Billy Tsai
  Cc: alexandre.belloni, pgaj, miquel.raynal, conor.culhane,
	aniketmaurya, Shyam-sundar.S-k, jarkko.nikula, wsa+renesas,
	xiaopei01, Guruvendra.Punugupati, linux-i3c, linux-kernel, BMC-SW

Hi Billy,

On 2025-02-04 17:17:01+0800, Billy Tsai wrote:
> The change is necessary to enable the use of the
> `i2c_get_dma_safe_msg_buf()` API, which requires a non-const
> `struct i2c_msg *` to operate. The `i2c_get_dma_safe_msg_buf()` function
> ensures safe handling of I2C messages when using DMA, making it essential
> for scenarios where DMA transfers are involved. By removing the `const`
> qualifier, this patch allows drivers to prepare and manage DMA-safe
> buffers directly.

This is missing a changelog to v1 of the series.

Also I asked before why it is not possible to change the signature of
i2c_get_dma_safe_msg_buf() to accept 'const struct i2c_msg *' [0].
That looks like the nicer solution to me.

> Signed-off-by: Billy Tsai <billy_tsai@aspeedtech.com>
> ---
>  drivers/i3c/master/dw-i3c-master.c     | 2 +-
>  drivers/i3c/master/i3c-master-cdns.c   | 2 +-
>  drivers/i3c/master/mipi-i3c-hci/core.c | 2 +-
>  drivers/i3c/master/svc-i3c-master.c    | 2 +-
>  include/linux/i3c/master.h             | 2 +-
>  5 files changed, 5 insertions(+), 5 deletions(-)

<snip>

[0] https://lore.kernel.org/lkml/23854752-435e-432e-ba21-caf690c0cecc@t-8ch.de/

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

* Re: [PATCH v2 1/2] i3c: Remove the const qualifier from i2c_msg pointer in i2c_xfers API
  2025-02-04  9:50 ` [PATCH v2 1/2] i3c: Remove the const qualifier from i2c_msg pointer in i2c_xfers API Thomas Weißschuh
@ 2025-02-04 10:09   ` Billy Tsai
  2025-02-04 16:50     ` Thomas Weißschuh
  0 siblings, 1 reply; 12+ messages in thread
From: Billy Tsai @ 2025-02-04 10:09 UTC (permalink / raw)
  To: Thomas Weißschuh
  Cc: alexandre.belloni@bootlin.com, pgaj@cadence.com,
	miquel.raynal@bootlin.com, conor.culhane@silvaco.com,
	aniketmaurya@google.com, Shyam-sundar.S-k@amd.com,
	jarkko.nikula@linux.intel.com, wsa+renesas@sang-engineering.com,
	xiaopei01@kylinos.cn, Guruvendra.Punugupati@amd.com,
	linux-i3c@lists.infradead.org, linux-kernel@vger.kernel.org,
	BMC-SW

> On 2025-02-04 17:17:01+0800, Billy Tsai wrote:
> > The change is necessary to enable the use of the
> > `i2c_get_dma_safe_msg_buf()` API, which requires a non-const
> > `struct i2c_msg *` to operate. The `i2c_get_dma_safe_msg_buf()` function
> > ensures safe handling of I2C messages when using DMA, making it essential
> > for scenarios where DMA transfers are involved. By removing the `const`
> > qualifier, this patch allows drivers to prepare and manage DMA-safe
> > buffers directly.

> This is missing a changelog to v1 of the series.

> Also I asked before why it is not possible to change the signature of
> i2c_get_dma_safe_msg_buf() to accept 'const struct i2c_msg *' [0].
> That looks like the nicer solution to me.

Hi Thomas,

The i2c_get_dma_safe_msg_buf() function has existed for a long time, but I do not know the original reason why it declares struct i2c_msg * without const. However, I believe this is because the i2c_put_dma_safe_msg_buf() function modifies the buffer data, so for consistency, it is declared without const.

Best regards,
Billy Tsai.

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

* Re: [PATCH v2 2/2] i3c: mipi-i3c-hci: Use I2C DMA-safe api
  2025-02-04  9:17 ` [PATCH v2 2/2] i3c: mipi-i3c-hci: Use I2C DMA-safe api Billy Tsai
@ 2025-02-04 15:16   ` Mukesh Kumar Savaliya
  2025-02-05 11:28     ` Jarkko Nikula
  2025-02-05 16:51   ` Frank Li
  1 sibling, 1 reply; 12+ messages in thread
From: Mukesh Kumar Savaliya @ 2025-02-04 15:16 UTC (permalink / raw)
  To: Billy Tsai, alexandre.belloni, pgaj, miquel.raynal, conor.culhane,
	aniketmaurya, Shyam-sundar.S-k, jarkko.nikula, wsa+renesas,
	xiaopei01, Guruvendra.Punugupati, linux-i3c, linux-kernel, BMC-SW

Looks good to me !

On 2/4/2025 2:47 PM, Billy Tsai wrote:
> Use the i2c_get/put_dma_safe_msg_buf for I2C transfers instead of using
> the I3C-specific API.
> 
> Signed-off-by: Billy Tsai <billy_tsai@aspeedtech.com>
Acked-by: Mukesh Kumar Savaliya <quic_msavaliy@quicinc.com>
> ---
>   drivers/i3c/master/mipi-i3c-hci/core.c | 8 +++-----
>   1 file changed, 3 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/i3c/master/mipi-i3c-hci/core.c b/drivers/i3c/master/mipi-i3c-hci/core.c
> index a408feac3e9e..4f3738beb0f2 100644
> --- a/drivers/i3c/master/mipi-i3c-hci/core.c
> +++ b/drivers/i3c/master/mipi-i3c-hci/core.c
> @@ -382,14 +382,11 @@ 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]);
>   		xfer[i].cmd_desc[0] |= CMD_0_ROC;
> -		ret = i3c_hci_alloc_safe_xfer_buf(hci, &xfer[i]);
> -		if (ret)
> -			goto out;
>   	}
>   	last = i - 1;
>   	xfer[last].cmd_desc[0] |= CMD_0_TOC;
> @@ -412,7 +409,8 @@ static int i3c_hci_i2c_xfers(struct i2c_dev_desc *dev,
>   
>   out:
>   	for (i = 0; i < nxfers; i++)
> -		i3c_hci_free_safe_xfer_buf(hci, &xfer[i]);
> +		i2c_put_dma_safe_msg_buf(xfer[i].data, &i2c_xfers[i],
> +					 ret ? false : true);
>   
>   	hci_free_xfer(xfer, nxfers);
>   	return ret;


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

* Re: [PATCH v2 1/2] i3c: Remove the const qualifier from i2c_msg pointer in i2c_xfers API
  2025-02-04 10:09   ` Billy Tsai
@ 2025-02-04 16:50     ` Thomas Weißschuh
  2025-02-04 16:56       ` Alexandre Belloni
  0 siblings, 1 reply; 12+ messages in thread
From: Thomas Weißschuh @ 2025-02-04 16:50 UTC (permalink / raw)
  To: Billy Tsai
  Cc: alexandre.belloni@bootlin.com, pgaj@cadence.com,
	miquel.raynal@bootlin.com, conor.culhane@silvaco.com,
	aniketmaurya@google.com, Shyam-sundar.S-k@amd.com,
	jarkko.nikula@linux.intel.com, wsa+renesas@sang-engineering.com,
	xiaopei01@kylinos.cn, Guruvendra.Punugupati@amd.com,
	linux-i3c@lists.infradead.org, linux-kernel@vger.kernel.org,
	BMC-SW

Hi Billy,

On 2025-02-04 10:09:31+0000, Billy Tsai wrote:
> > On 2025-02-04 17:17:01+0800, Billy Tsai wrote:
> > > The change is necessary to enable the use of the
> > > `i2c_get_dma_safe_msg_buf()` API, which requires a non-const
> > > `struct i2c_msg *` to operate. The `i2c_get_dma_safe_msg_buf()` function
> > > ensures safe handling of I2C messages when using DMA, making it essential
> > > for scenarios where DMA transfers are involved. By removing the `const`
> > > qualifier, this patch allows drivers to prepare and manage DMA-safe
> > > buffers directly.
> 
> > This is missing a changelog to v1 of the series.
> 
> > Also I asked before why it is not possible to change the signature of
> > i2c_get_dma_safe_msg_buf() to accept 'const struct i2c_msg *' [0].
> > That looks like the nicer solution to me.

> The i2c_get_dma_safe_msg_buf() function has existed for a long time,
> but I do not know the original reason why it declares struct i2c_msg *
> without const.

I would guess that nobody ever cared before.

> However, I believe this is because the
> i2c_put_dma_safe_msg_buf() function modifies the buffer data, so for
> consistency, it is declared without const.

IMO that's a weak argument.
Maybe the maintainers have a preference?


Thomas

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

* Re: [PATCH v2 1/2] i3c: Remove the const qualifier from i2c_msg pointer in i2c_xfers API
  2025-02-04 16:50     ` Thomas Weißschuh
@ 2025-02-04 16:56       ` Alexandre Belloni
  2025-02-17  9:57         ` wsa+renesas
  0 siblings, 1 reply; 12+ messages in thread
From: Alexandre Belloni @ 2025-02-04 16:56 UTC (permalink / raw)
  To: Thomas Weißschuh
  Cc: Billy Tsai, pgaj@cadence.com, miquel.raynal@bootlin.com,
	conor.culhane@silvaco.com, aniketmaurya@google.com,
	Shyam-sundar.S-k@amd.com, jarkko.nikula@linux.intel.com,
	wsa+renesas@sang-engineering.com, xiaopei01@kylinos.cn,
	Guruvendra.Punugupati@amd.com, linux-i3c@lists.infradead.org,
	linux-kernel@vger.kernel.org, BMC-SW

On 04/02/2025 17:50:14+0100, Thomas Weißschuh wrote:
> Hi Billy,
> 
> On 2025-02-04 10:09:31+0000, Billy Tsai wrote:
> > > On 2025-02-04 17:17:01+0800, Billy Tsai wrote:
> > > > The change is necessary to enable the use of the
> > > > `i2c_get_dma_safe_msg_buf()` API, which requires a non-const
> > > > `struct i2c_msg *` to operate. The `i2c_get_dma_safe_msg_buf()` function
> > > > ensures safe handling of I2C messages when using DMA, making it essential
> > > > for scenarios where DMA transfers are involved. By removing the `const`
> > > > qualifier, this patch allows drivers to prepare and manage DMA-safe
> > > > buffers directly.
> > 
> > > This is missing a changelog to v1 of the series.
> > 
> > > Also I asked before why it is not possible to change the signature of
> > > i2c_get_dma_safe_msg_buf() to accept 'const struct i2c_msg *' [0].
> > > That looks like the nicer solution to me.
> 
> > The i2c_get_dma_safe_msg_buf() function has existed for a long time,
> > but I do not know the original reason why it declares struct i2c_msg *
> > without const.
> 
> I would guess that nobody ever cared before.
> 
> > However, I believe this is because the
> > i2c_put_dma_safe_msg_buf() function modifies the buffer data, so for
> > consistency, it is declared without const.
> 
> IMO that's a weak argument.
> Maybe the maintainers have a preference?
> 

I guess Wolfram will be the one have the preference, I'm fine using the
existing API as-is.

-- 
Alexandre Belloni, co-owner and COO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com

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

* Re: [PATCH v2 2/2] i3c: mipi-i3c-hci: Use I2C DMA-safe api
  2025-02-04 15:16   ` Mukesh Kumar Savaliya
@ 2025-02-05 11:28     ` Jarkko Nikula
  0 siblings, 0 replies; 12+ messages in thread
From: Jarkko Nikula @ 2025-02-05 11:28 UTC (permalink / raw)
  To: Mukesh Kumar Savaliya, Billy Tsai, alexandre.belloni, pgaj,
	miquel.raynal, conor.culhane, aniketmaurya, Shyam-sundar.S-k,
	wsa+renesas, xiaopei01, Guruvendra.Punugupati, linux-i3c,
	linux-kernel, BMC-SW

On 2/4/25 5:16 PM, Mukesh Kumar Savaliya wrote:
> Looks good to me !
> 
> On 2/4/2025 2:47 PM, Billy Tsai wrote:
>> Use the i2c_get/put_dma_safe_msg_buf for I2C transfers instead of using
>> the I3C-specific API.
>>
>> Signed-off-by: Billy Tsai <billy_tsai@aspeedtech.com>
> Acked-by: Mukesh Kumar Savaliya <quic_msavaliy@quicinc.com>

Reviewed-by: Jarkko Nikula <jarkko.nikula@linux.intel.com>

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

* Re: [PATCH v2 1/2] i3c: Remove the const qualifier from i2c_msg pointer in i2c_xfers API
  2025-02-04  9:17 [PATCH v2 1/2] i3c: Remove the const qualifier from i2c_msg pointer in i2c_xfers API Billy Tsai
  2025-02-04  9:17 ` [PATCH v2 2/2] i3c: mipi-i3c-hci: Use I2C DMA-safe api Billy Tsai
  2025-02-04  9:50 ` [PATCH v2 1/2] i3c: Remove the const qualifier from i2c_msg pointer in i2c_xfers API Thomas Weißschuh
@ 2025-02-05 16:50 ` Frank Li
  2025-02-20 22:09 ` Alexandre Belloni
  3 siblings, 0 replies; 12+ messages in thread
From: Frank Li @ 2025-02-05 16:50 UTC (permalink / raw)
  To: Billy Tsai
  Cc: alexandre.belloni, pgaj, miquel.raynal, conor.culhane,
	aniketmaurya, Shyam-sundar.S-k, jarkko.nikula, wsa+renesas,
	xiaopei01, Guruvendra.Punugupati, linux-i3c, linux-kernel, BMC-SW

On Tue, Feb 04, 2025 at 05:17:01PM +0800, Billy Tsai wrote:
> The change is necessary to enable the use of the
> `i2c_get_dma_safe_msg_buf()` API, which requires a non-const
> `struct i2c_msg *` to operate. The `i2c_get_dma_safe_msg_buf()` function
> ensures safe handling of I2C messages when using DMA, making it essential
> for scenarios where DMA transfers are involved. By removing the `const`
> qualifier, this patch allows drivers to prepare and manage DMA-safe
> buffers directly.
>
> Signed-off-by: Billy Tsai <billy_tsai@aspeedtech.com>
> ---

Reviewed-by: Frank Li <Frank.Li@nxp.com>

>  drivers/i3c/master/dw-i3c-master.c     | 2 +-
>  drivers/i3c/master/i3c-master-cdns.c   | 2 +-
>  drivers/i3c/master/mipi-i3c-hci/core.c | 2 +-
>  drivers/i3c/master/svc-i3c-master.c    | 2 +-
>  include/linux/i3c/master.h             | 2 +-
>  5 files changed, 5 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/i3c/master/dw-i3c-master.c b/drivers/i3c/master/dw-i3c-master.c
> index d09ea5b6467c..54c7d86997d5 100644
> --- a/drivers/i3c/master/dw-i3c-master.c
> +++ b/drivers/i3c/master/dw-i3c-master.c
> @@ -1079,7 +1079,7 @@ static void dw_i3c_master_detach_i3c_dev(struct i3c_dev_desc *dev)
>  }
>
>  static int dw_i3c_master_i2c_xfers(struct i2c_dev_desc *dev,
> -				   const struct i2c_msg *i2c_xfers,
> +				   struct i2c_msg *i2c_xfers,
>  				   int i2c_nxfers)
>  {
>  	struct dw_i3c_i2c_dev_data *data = i2c_dev_get_master_data(dev);
> diff --git a/drivers/i3c/master/i3c-master-cdns.c b/drivers/i3c/master/i3c-master-cdns.c
> index 8d69a34986d9..c9e4c129454c 100644
> --- a/drivers/i3c/master/i3c-master-cdns.c
> +++ b/drivers/i3c/master/i3c-master-cdns.c
> @@ -813,7 +813,7 @@ static int cdns_i3c_master_priv_xfers(struct i3c_dev_desc *dev,
>  }
>
>  static int cdns_i3c_master_i2c_xfers(struct i2c_dev_desc *dev,
> -				     const struct i2c_msg *xfers, int nxfers)
> +				     struct i2c_msg *xfers, int nxfers)
>  {
>  	struct i3c_master_controller *m = i2c_dev_get_master(dev);
>  	struct cdns_i3c_master *master = to_cdns_i3c_master(m);
> diff --git a/drivers/i3c/master/mipi-i3c-hci/core.c b/drivers/i3c/master/mipi-i3c-hci/core.c
> index e6e482a259b4..a408feac3e9e 100644
> --- a/drivers/i3c/master/mipi-i3c-hci/core.c
> +++ b/drivers/i3c/master/mipi-i3c-hci/core.c
> @@ -367,7 +367,7 @@ static int i3c_hci_priv_xfers(struct i3c_dev_desc *dev,
>  }
>
>  static int i3c_hci_i2c_xfers(struct i2c_dev_desc *dev,
> -			     const struct i2c_msg *i2c_xfers, int nxfers)
> +			     struct i2c_msg *i2c_xfers, int nxfers)
>  {
>  	struct i3c_master_controller *m = i2c_dev_get_master(dev);
>  	struct i3c_hci *hci = to_i3c_hci(m);
> diff --git a/drivers/i3c/master/svc-i3c-master.c b/drivers/i3c/master/svc-i3c-master.c
> index c1ee3828e7ee..24bd701b5de0 100644
> --- a/drivers/i3c/master/svc-i3c-master.c
> +++ b/drivers/i3c/master/svc-i3c-master.c
> @@ -1584,7 +1584,7 @@ static int svc_i3c_master_priv_xfers(struct i3c_dev_desc *dev,
>  }
>
>  static int svc_i3c_master_i2c_xfers(struct i2c_dev_desc *dev,
> -				    const struct i2c_msg *xfers,
> +				    struct i2c_msg *xfers,
>  				    int nxfers)
>  {
>  	struct i3c_master_controller *m = i2c_dev_get_master(dev);
> diff --git a/include/linux/i3c/master.h b/include/linux/i3c/master.h
> index 12d532b012c5..c67922ece617 100644
> --- a/include/linux/i3c/master.h
> +++ b/include/linux/i3c/master.h
> @@ -475,7 +475,7 @@ struct i3c_master_controller_ops {
>  	int (*attach_i2c_dev)(struct i2c_dev_desc *dev);
>  	void (*detach_i2c_dev)(struct i2c_dev_desc *dev);
>  	int (*i2c_xfers)(struct i2c_dev_desc *dev,
> -			 const struct i2c_msg *xfers, int nxfers);
> +			 struct i2c_msg *xfers, int nxfers);
>  	int (*request_ibi)(struct i3c_dev_desc *dev,
>  			   const struct i3c_ibi_setup *req);
>  	void (*free_ibi)(struct i3c_dev_desc *dev);
> --
> 2.25.1
>
>
> --
> linux-i3c mailing list
> linux-i3c@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-i3c

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

* Re: [PATCH v2 2/2] i3c: mipi-i3c-hci: Use I2C DMA-safe api
  2025-02-04  9:17 ` [PATCH v2 2/2] i3c: mipi-i3c-hci: Use I2C DMA-safe api Billy Tsai
  2025-02-04 15:16   ` Mukesh Kumar Savaliya
@ 2025-02-05 16:51   ` Frank Li
  1 sibling, 0 replies; 12+ messages in thread
From: Frank Li @ 2025-02-05 16:51 UTC (permalink / raw)
  To: Billy Tsai
  Cc: alexandre.belloni, pgaj, miquel.raynal, conor.culhane,
	aniketmaurya, Shyam-sundar.S-k, jarkko.nikula, wsa+renesas,
	xiaopei01, Guruvendra.Punugupati, linux-i3c, linux-kernel, BMC-SW

On Tue, Feb 04, 2025 at 05:17:02PM +0800, Billy Tsai wrote:
> Use the i2c_get/put_dma_safe_msg_buf for I2C transfers instead of using
> the I3C-specific API.
>
> Signed-off-by: Billy Tsai <billy_tsai@aspeedtech.com>
> ---
>  drivers/i3c/master/mipi-i3c-hci/core.c | 8 +++-----
>  1 file changed, 3 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/i3c/master/mipi-i3c-hci/core.c b/drivers/i3c/master/mipi-i3c-hci/core.c
> index a408feac3e9e..4f3738beb0f2 100644
> --- a/drivers/i3c/master/mipi-i3c-hci/core.c
> +++ b/drivers/i3c/master/mipi-i3c-hci/core.c
> @@ -382,14 +382,11 @@ 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);

1 should true?

Frank
>  		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]);
>  		xfer[i].cmd_desc[0] |= CMD_0_ROC;
> -		ret = i3c_hci_alloc_safe_xfer_buf(hci, &xfer[i]);
> -		if (ret)
> -			goto out;
>  	}
>  	last = i - 1;
>  	xfer[last].cmd_desc[0] |= CMD_0_TOC;
> @@ -412,7 +409,8 @@ static int i3c_hci_i2c_xfers(struct i2c_dev_desc *dev,
>
>  out:
>  	for (i = 0; i < nxfers; i++)
> -		i3c_hci_free_safe_xfer_buf(hci, &xfer[i]);
> +		i2c_put_dma_safe_msg_buf(xfer[i].data, &i2c_xfers[i],
> +					 ret ? false : true);
>
>  	hci_free_xfer(xfer, nxfers);
>  	return ret;
> --
> 2.25.1
>
>
> --
> linux-i3c mailing list
> linux-i3c@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-i3c

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

* Re: [PATCH v2 1/2] i3c: Remove the const qualifier from i2c_msg pointer in i2c_xfers API
  2025-02-04 16:56       ` Alexandre Belloni
@ 2025-02-17  9:57         ` wsa+renesas
  0 siblings, 0 replies; 12+ messages in thread
From: wsa+renesas @ 2025-02-17  9:57 UTC (permalink / raw)
  To: Alexandre Belloni
  Cc: Thomas Weißschuh, Billy Tsai, pgaj@cadence.com,
	miquel.raynal@bootlin.com, conor.culhane@silvaco.com,
	aniketmaurya@google.com, Shyam-sundar.S-k@amd.com,
	jarkko.nikula@linux.intel.com, xiaopei01@kylinos.cn,
	Guruvendra.Punugupati@amd.com, linux-i3c@lists.infradead.org,
	linux-kernel@vger.kernel.org, BMC-SW

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


> I guess Wolfram will be the one have the preference, I'm fine using the
> existing API as-is.

Happy to take (tested) patches.


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

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

* Re: [PATCH v2 1/2] i3c: Remove the const qualifier from i2c_msg pointer in i2c_xfers API
  2025-02-04  9:17 [PATCH v2 1/2] i3c: Remove the const qualifier from i2c_msg pointer in i2c_xfers API Billy Tsai
                   ` (2 preceding siblings ...)
  2025-02-05 16:50 ` Frank Li
@ 2025-02-20 22:09 ` Alexandre Belloni
  3 siblings, 0 replies; 12+ messages in thread
From: Alexandre Belloni @ 2025-02-20 22:09 UTC (permalink / raw)
  To: pgaj, miquel.raynal, conor.culhane, aniketmaurya,
	Shyam-sundar.S-k, jarkko.nikula, wsa+renesas, xiaopei01,
	Guruvendra.Punugupati, linux-i3c, linux-kernel, BMC-SW,
	Billy Tsai

On Tue, 04 Feb 2025 17:17:01 +0800, Billy Tsai wrote:
> The change is necessary to enable the use of the
> `i2c_get_dma_safe_msg_buf()` API, which requires a non-const
> `struct i2c_msg *` to operate. The `i2c_get_dma_safe_msg_buf()` function
> ensures safe handling of I2C messages when using DMA, making it essential
> for scenarios where DMA transfers are involved. By removing the `const`
> qualifier, this patch allows drivers to prepare and manage DMA-safe
> buffers directly.
> 
> [...]

Applied, thanks!

[1/2] i3c: Remove the const qualifier from i2c_msg pointer in i2c_xfers API
      https://git.kernel.org/abelloni/c/6866c91f8c23
[2/2] i3c: mipi-i3c-hci: Use I2C DMA-safe api
      https://git.kernel.org/abelloni/c/effed5dac8f8

Best regards,

-- 
Alexandre Belloni, co-owner and COO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com

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

end of thread, other threads:[~2025-02-20 22:09 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-02-04  9:17 [PATCH v2 1/2] i3c: Remove the const qualifier from i2c_msg pointer in i2c_xfers API Billy Tsai
2025-02-04  9:17 ` [PATCH v2 2/2] i3c: mipi-i3c-hci: Use I2C DMA-safe api Billy Tsai
2025-02-04 15:16   ` Mukesh Kumar Savaliya
2025-02-05 11:28     ` Jarkko Nikula
2025-02-05 16:51   ` Frank Li
2025-02-04  9:50 ` [PATCH v2 1/2] i3c: Remove the const qualifier from i2c_msg pointer in i2c_xfers API Thomas Weißschuh
2025-02-04 10:09   ` Billy Tsai
2025-02-04 16:50     ` Thomas Weißschuh
2025-02-04 16:56       ` Alexandre Belloni
2025-02-17  9:57         ` wsa+renesas
2025-02-05 16:50 ` Frank Li
2025-02-20 22:09 ` Alexandre Belloni

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox