linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3 0/3] Add helper methods i3c_writel_fifo() and i3c_readl_fifo()
@ 2025-06-24  9:06 Jorge Marques
  2025-06-24  9:06 ` [PATCH v3 1/3] i3c: master: Add inline i3c_readl_fifo() and i3c_writel_fifo() Jorge Marques
                   ` (3 more replies)
  0 siblings, 4 replies; 14+ messages in thread
From: Jorge Marques @ 2025-06-24  9:06 UTC (permalink / raw)
  To: Alexandre Belloni, Frank Li, Przemysław Gaj
  Cc: linux-i3c, linux-kernel, Jorge Marques

The I3C abstraction expects u8 buffers, but some controllers operate with
a 32-bit bus width FIFO and cannot flag valid bytes individually. To avoid
reading or writing outside the buffer bounds, use 32-bit accesses where
possible and apply memcpy for any remaining bytes.

Add two auxiliary methods to include/linux/i3c/master.h and use in the dw
and cdns i3c controller drivers. The adi and renesas controller drivers
will also use these methods.

Related thread: https://lore.kernel.org/linux-i3c/aFNziEj7j31xy%2FmY@lizhi-Precision-Tower-5810/

Signed-off-by: Jorge Marques <jorge.marques@analog.com>
---
Changes in v3:
- Update i3c_writel_fifo/i3c_readl_fifo documentation
- Rename bytes to buffer
- Update cdns, dw commit messages
- Link to v2: https://lore.kernel.org/r/20250622-i3c-writesl-readsl-v2-0-2afd34ec6306@analog.com

Changes in v2:
- Rename to i3c_readl_fifo() and i3c_writel_fifo()
- Change type u8 *bytes to void *bytes
- Move methods to internals.h
- Reword commit messages to include new names and ().
- Fixup dw read fifo address (master -> master->reg)
- Link to v1: https://lore.kernel.org/r/20250620-i3c-writesl-readsl-v1-0-e0aa1c014dff@analog.com

---
Jorge Marques (3):
      i3c: master: Add inline i3c_readl_fifo() and i3c_writel_fifo()
      i3c: master: cdns: Use i3c_writel_fifo() and i3c_readl_fifo()
      i3c: master: dw: Use i3c_writel_fifo() and i3c_readl_fifo()

 drivers/i3c/internals.h              | 37 ++++++++++++++++++++++++++++++++++++
 drivers/i3c/master/dw-i3c-master.c   | 25 ++++--------------------
 drivers/i3c/master/i3c-master-cdns.c | 25 +++++-------------------
 3 files changed, 46 insertions(+), 41 deletions(-)
---
base-commit: 51963783b876a2f493a3eac0ea9eba271cb6809a
change-id: 20250620-i3c-writesl-readsl-e2836534b665

Best regards,
-- 
Jorge Marques <jorge.marques@analog.com>


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

* [PATCH v3 1/3] i3c: master: Add inline i3c_readl_fifo() and i3c_writel_fifo()
  2025-06-24  9:06 [PATCH v3 0/3] Add helper methods i3c_writel_fifo() and i3c_readl_fifo() Jorge Marques
@ 2025-06-24  9:06 ` Jorge Marques
  2025-06-24 18:08   ` Frank Li
  2025-06-25  7:24   ` Wolfram Sang
  2025-06-24  9:06 ` [PATCH v3 2/3] i3c: master: cdns: Use i3c_writel_fifo() and i3c_readl_fifo() Jorge Marques
                   ` (2 subsequent siblings)
  3 siblings, 2 replies; 14+ messages in thread
From: Jorge Marques @ 2025-06-24  9:06 UTC (permalink / raw)
  To: Alexandre Belloni, Frank Li, Przemysław Gaj
  Cc: linux-i3c, linux-kernel, Jorge Marques

The I3C abstraction expects u8 buffers, but some controllers operate with
a 32-bit bus width FIFO and cannot flag valid bytes individually. To avoid
reading or writing outside the buffer bounds, use 32-bit accesses where
possible and apply memcpy for any remaining bytes

Signed-off-by: Jorge Marques <jorge.marques@analog.com>
---
 drivers/i3c/internals.h | 37 +++++++++++++++++++++++++++++++++++++
 1 file changed, 37 insertions(+)

diff --git a/drivers/i3c/internals.h b/drivers/i3c/internals.h
index 433f6088b7cec8c77288ee24dbee8b18338aa1eb..6a11437fee47bd1d19354e983d4a561a4356b08d 100644
--- a/drivers/i3c/internals.h
+++ b/drivers/i3c/internals.h
@@ -22,4 +22,41 @@ int i3c_dev_enable_ibi_locked(struct i3c_dev_desc *dev);
 int i3c_dev_request_ibi_locked(struct i3c_dev_desc *dev,
 			       const struct i3c_ibi_setup *req);
 void i3c_dev_free_ibi_locked(struct i3c_dev_desc *dev);
+
+/**
+ * i3c_writel_fifo - Write data buffer to 32bit FIFO
+ * @addr: FIFO Address to write to
+ * @buf: Pointer to the data bytes to write
+ * @nbytes: Number of bytes to write
+ */
+static inline void i3c_writel_fifo(void __iomem *addr, const void *buf,
+				   int nbytes)
+{
+	writesl(addr, buf, nbytes / 4);
+	if (nbytes & 3) {
+		u32 tmp = 0;
+
+		memcpy(&tmp, buf + (nbytes & ~3), nbytes & 3);
+		writel(tmp, addr);
+	}
+}
+
+/**
+ * i3c_readl_fifo - Read data buffer from 32bit FIFO
+ * @addr: FIFO Address to read from
+ * @buf: Pointer to the buffer to store read bytes
+ * @nbytes: Number of bytes to read
+ */
+static inline void i3c_readl_fifo(const void __iomem *addr, void *buf,
+				  int nbytes)
+{
+	readsl(addr, buf, nbytes / 4);
+	if (nbytes & 3) {
+		u32 tmp;
+
+		tmp = readl(addr);
+		memcpy(buf + (nbytes & ~3), &tmp, nbytes & 3);
+	}
+}
+
 #endif /* I3C_INTERNAL_H */

-- 
2.49.0


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

* [PATCH v3 2/3] i3c: master: cdns: Use i3c_writel_fifo() and i3c_readl_fifo()
  2025-06-24  9:06 [PATCH v3 0/3] Add helper methods i3c_writel_fifo() and i3c_readl_fifo() Jorge Marques
  2025-06-24  9:06 ` [PATCH v3 1/3] i3c: master: Add inline i3c_readl_fifo() and i3c_writel_fifo() Jorge Marques
@ 2025-06-24  9:06 ` Jorge Marques
  2025-06-24 18:09   ` Frank Li
  2025-06-25  7:26   ` Wolfram Sang
  2025-06-24  9:06 ` [PATCH v3 3/3] i3c: master: dw: " Jorge Marques
  2025-07-30 23:40 ` [PATCH v3 0/3] Add helper methods " Alexandre Belloni
  3 siblings, 2 replies; 14+ messages in thread
From: Jorge Marques @ 2025-06-24  9:06 UTC (permalink / raw)
  To: Alexandre Belloni, Frank Li, Przemysław Gaj
  Cc: linux-i3c, linux-kernel, Jorge Marques

Use common inline i3c_writel_fifo()/i3c_readl_fifo() methods to
simplify code since the FIFO of controller is a 32bit width.

Signed-off-by: Jorge Marques <jorge.marques@analog.com>
---
 drivers/i3c/master/i3c-master-cdns.c | 25 +++++--------------------
 1 file changed, 5 insertions(+), 20 deletions(-)

diff --git a/drivers/i3c/master/i3c-master-cdns.c b/drivers/i3c/master/i3c-master-cdns.c
index fd3752cea654954ed1e37337754e45fddbbbf68e..321c04d2109ec1951f2b07a9d1b88c6aaf055c95 100644
--- a/drivers/i3c/master/i3c-master-cdns.c
+++ b/drivers/i3c/master/i3c-master-cdns.c
@@ -23,6 +23,8 @@
 #include <linux/spinlock.h>
 #include <linux/workqueue.h>
 
+#include "../internals.h"
+
 #define DEV_ID				0x0
 #define DEV_ID_I3C_MASTER		0x5034
 
@@ -427,25 +429,13 @@ to_cdns_i3c_master(struct i3c_master_controller *master)
 static void cdns_i3c_master_wr_to_tx_fifo(struct cdns_i3c_master *master,
 					  const u8 *bytes, int nbytes)
 {
-	writesl(master->regs + TX_FIFO, bytes, nbytes / 4);
-	if (nbytes & 3) {
-		u32 tmp = 0;
-
-		memcpy(&tmp, bytes + (nbytes & ~3), nbytes & 3);
-		writesl(master->regs + TX_FIFO, &tmp, 1);
-	}
+	i3c_writel_fifo(master->regs + TX_FIFO, bytes, nbytes);
 }
 
 static void cdns_i3c_master_rd_from_rx_fifo(struct cdns_i3c_master *master,
 					    u8 *bytes, int nbytes)
 {
-	readsl(master->regs + RX_FIFO, bytes, nbytes / 4);
-	if (nbytes & 3) {
-		u32 tmp;
-
-		readsl(master->regs + RX_FIFO, &tmp, 1);
-		memcpy(bytes + (nbytes & ~3), &tmp, nbytes & 3);
-	}
+	i3c_readl_fifo(master->regs + RX_FIFO, bytes, nbytes);
 }
 
 static bool cdns_i3c_master_supports_ccc_cmd(struct i3c_master_controller *m,
@@ -1330,12 +1320,7 @@ static void cdns_i3c_master_handle_ibi(struct cdns_i3c_master *master,
 	buf = slot->data;
 
 	nbytes = IBIR_XFER_BYTES(ibir);
-	readsl(master->regs + IBI_DATA_FIFO, buf, nbytes / 4);
-	if (nbytes % 3) {
-		u32 tmp = __raw_readl(master->regs + IBI_DATA_FIFO);
-
-		memcpy(buf + (nbytes & ~3), &tmp, nbytes & 3);
-	}
+	i3c_readl_fifo(master->regs + IBI_DATA_FIFO, buf, nbytes);
 
 	slot->len = min_t(unsigned int, IBIR_XFER_BYTES(ibir),
 			  dev->ibi->max_payload_len);

-- 
2.49.0


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

* [PATCH v3 3/3] i3c: master: dw: Use i3c_writel_fifo() and i3c_readl_fifo()
  2025-06-24  9:06 [PATCH v3 0/3] Add helper methods i3c_writel_fifo() and i3c_readl_fifo() Jorge Marques
  2025-06-24  9:06 ` [PATCH v3 1/3] i3c: master: Add inline i3c_readl_fifo() and i3c_writel_fifo() Jorge Marques
  2025-06-24  9:06 ` [PATCH v3 2/3] i3c: master: cdns: Use i3c_writel_fifo() and i3c_readl_fifo() Jorge Marques
@ 2025-06-24  9:06 ` Jorge Marques
  2025-06-24 18:10   ` Frank Li
  2025-06-25  7:27   ` Wolfram Sang
  2025-07-30 23:40 ` [PATCH v3 0/3] Add helper methods " Alexandre Belloni
  3 siblings, 2 replies; 14+ messages in thread
From: Jorge Marques @ 2025-06-24  9:06 UTC (permalink / raw)
  To: Alexandre Belloni, Frank Li, Przemysław Gaj
  Cc: linux-i3c, linux-kernel, Jorge Marques

Use common inline i3c_writel_fifo()/i3c_readl_fifo() methods to
simplify code since the FIFO of controller is a 32bit width.

Signed-off-by: Jorge Marques <jorge.marques@analog.com>
---
 drivers/i3c/master/dw-i3c-master.c | 25 ++++---------------------
 1 file changed, 4 insertions(+), 21 deletions(-)

diff --git a/drivers/i3c/master/dw-i3c-master.c b/drivers/i3c/master/dw-i3c-master.c
index 611c22b72c1572ddf717c8ad473e44a3b8fcceaf..886f8b74defda31ae93248467d144f9c8c561581 100644
--- a/drivers/i3c/master/dw-i3c-master.c
+++ b/drivers/i3c/master/dw-i3c-master.c
@@ -23,6 +23,7 @@
 #include <linux/reset.h>
 #include <linux/slab.h>
 
+#include "../internals.h"
 #include "dw-i3c-master.h"
 
 #define DEVICE_CTRL			0x0
@@ -336,37 +337,19 @@ static int dw_i3c_master_get_free_pos(struct dw_i3c_master *master)
 static void dw_i3c_master_wr_tx_fifo(struct dw_i3c_master *master,
 				     const u8 *bytes, int nbytes)
 {
-	writesl(master->regs + RX_TX_DATA_PORT, bytes, nbytes / 4);
-	if (nbytes & 3) {
-		u32 tmp = 0;
-
-		memcpy(&tmp, bytes + (nbytes & ~3), nbytes & 3);
-		writesl(master->regs + RX_TX_DATA_PORT, &tmp, 1);
-	}
-}
-
-static void dw_i3c_master_read_fifo(struct dw_i3c_master *master,
-				    int reg,  u8 *bytes, int nbytes)
-{
-	readsl(master->regs + reg, bytes, nbytes / 4);
-	if (nbytes & 3) {
-		u32 tmp;
-
-		readsl(master->regs + reg, &tmp, 1);
-		memcpy(bytes + (nbytes & ~3), &tmp, nbytes & 3);
-	}
+	i3c_writel_fifo(master->regs + RX_TX_DATA_PORT, bytes, nbytes);
 }
 
 static void dw_i3c_master_read_rx_fifo(struct dw_i3c_master *master,
 				       u8 *bytes, int nbytes)
 {
-	return dw_i3c_master_read_fifo(master, RX_TX_DATA_PORT, bytes, nbytes);
+	i3c_readl_fifo(master->regs + RX_TX_DATA_PORT, bytes, nbytes);
 }
 
 static void dw_i3c_master_read_ibi_fifo(struct dw_i3c_master *master,
 					u8 *bytes, int nbytes)
 {
-	return dw_i3c_master_read_fifo(master, IBI_QUEUE_STATUS, bytes, nbytes);
+	i3c_readl_fifo(master->regs + IBI_QUEUE_STATUS, bytes, nbytes);
 }
 
 static struct dw_i3c_xfer *

-- 
2.49.0


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

* Re: [PATCH v3 1/3] i3c: master: Add inline i3c_readl_fifo() and i3c_writel_fifo()
  2025-06-24  9:06 ` [PATCH v3 1/3] i3c: master: Add inline i3c_readl_fifo() and i3c_writel_fifo() Jorge Marques
@ 2025-06-24 18:08   ` Frank Li
  2025-06-24 20:30     ` Wolfram Sang
  2025-06-25  7:24   ` Wolfram Sang
  1 sibling, 1 reply; 14+ messages in thread
From: Frank Li @ 2025-06-24 18:08 UTC (permalink / raw)
  To: Jorge Marques
  Cc: Alexandre Belloni, Przemysław Gaj, linux-i3c, linux-kernel

On Tue, Jun 24, 2025 at 11:06:04AM +0200, Jorge Marques wrote:
> The I3C abstraction expects u8 buffers, but some controllers operate with
> a 32-bit bus width FIFO and cannot flag valid bytes individually. To avoid
> reading or writing outside the buffer bounds, use 32-bit accesses where
> possible and apply memcpy for any remaining bytes
>
> Signed-off-by: Jorge Marques <jorge.marques@analog.com>

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

> ---
>  drivers/i3c/internals.h | 37 +++++++++++++++++++++++++++++++++++++
>  1 file changed, 37 insertions(+)
>
> diff --git a/drivers/i3c/internals.h b/drivers/i3c/internals.h
> index 433f6088b7cec8c77288ee24dbee8b18338aa1eb..6a11437fee47bd1d19354e983d4a561a4356b08d 100644
> --- a/drivers/i3c/internals.h
> +++ b/drivers/i3c/internals.h
> @@ -22,4 +22,41 @@ int i3c_dev_enable_ibi_locked(struct i3c_dev_desc *dev);
>  int i3c_dev_request_ibi_locked(struct i3c_dev_desc *dev,
>  			       const struct i3c_ibi_setup *req);
>  void i3c_dev_free_ibi_locked(struct i3c_dev_desc *dev);
> +
> +/**
> + * i3c_writel_fifo - Write data buffer to 32bit FIFO
> + * @addr: FIFO Address to write to
> + * @buf: Pointer to the data bytes to write
> + * @nbytes: Number of bytes to write
> + */
> +static inline void i3c_writel_fifo(void __iomem *addr, const void *buf,
> +				   int nbytes)
> +{
> +	writesl(addr, buf, nbytes / 4);
> +	if (nbytes & 3) {
> +		u32 tmp = 0;
> +
> +		memcpy(&tmp, buf + (nbytes & ~3), nbytes & 3);
> +		writel(tmp, addr);
> +	}
> +}
> +
> +/**
> + * i3c_readl_fifo - Read data buffer from 32bit FIFO
> + * @addr: FIFO Address to read from
> + * @buf: Pointer to the buffer to store read bytes
> + * @nbytes: Number of bytes to read
> + */
> +static inline void i3c_readl_fifo(const void __iomem *addr, void *buf,
> +				  int nbytes)
> +{
> +	readsl(addr, buf, nbytes / 4);
> +	if (nbytes & 3) {
> +		u32 tmp;
> +
> +		tmp = readl(addr);
> +		memcpy(buf + (nbytes & ~3), &tmp, nbytes & 3);
> +	}
> +}
> +
>  #endif /* I3C_INTERNAL_H */
>
> --
> 2.49.0
>

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

* Re: [PATCH v3 2/3] i3c: master: cdns: Use i3c_writel_fifo() and i3c_readl_fifo()
  2025-06-24  9:06 ` [PATCH v3 2/3] i3c: master: cdns: Use i3c_writel_fifo() and i3c_readl_fifo() Jorge Marques
@ 2025-06-24 18:09   ` Frank Li
  2025-06-25  7:26   ` Wolfram Sang
  1 sibling, 0 replies; 14+ messages in thread
From: Frank Li @ 2025-06-24 18:09 UTC (permalink / raw)
  To: Jorge Marques
  Cc: Alexandre Belloni, Przemysław Gaj, linux-i3c, linux-kernel

On Tue, Jun 24, 2025 at 11:06:05AM +0200, Jorge Marques wrote:
> Use common inline i3c_writel_fifo()/i3c_readl_fifo() methods to
> simplify code since the FIFO of controller is a 32bit width.
>
> Signed-off-by: Jorge Marques <jorge.marques@analog.com>

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

> ---
>  drivers/i3c/master/i3c-master-cdns.c | 25 +++++--------------------
>  1 file changed, 5 insertions(+), 20 deletions(-)
>
> diff --git a/drivers/i3c/master/i3c-master-cdns.c b/drivers/i3c/master/i3c-master-cdns.c
> index fd3752cea654954ed1e37337754e45fddbbbf68e..321c04d2109ec1951f2b07a9d1b88c6aaf055c95 100644
> --- a/drivers/i3c/master/i3c-master-cdns.c
> +++ b/drivers/i3c/master/i3c-master-cdns.c
> @@ -23,6 +23,8 @@
>  #include <linux/spinlock.h>
>  #include <linux/workqueue.h>
>
> +#include "../internals.h"
> +
>  #define DEV_ID				0x0
>  #define DEV_ID_I3C_MASTER		0x5034
>
> @@ -427,25 +429,13 @@ to_cdns_i3c_master(struct i3c_master_controller *master)
>  static void cdns_i3c_master_wr_to_tx_fifo(struct cdns_i3c_master *master,
>  					  const u8 *bytes, int nbytes)
>  {
> -	writesl(master->regs + TX_FIFO, bytes, nbytes / 4);
> -	if (nbytes & 3) {
> -		u32 tmp = 0;
> -
> -		memcpy(&tmp, bytes + (nbytes & ~3), nbytes & 3);
> -		writesl(master->regs + TX_FIFO, &tmp, 1);
> -	}
> +	i3c_writel_fifo(master->regs + TX_FIFO, bytes, nbytes);
>  }
>
>  static void cdns_i3c_master_rd_from_rx_fifo(struct cdns_i3c_master *master,
>  					    u8 *bytes, int nbytes)
>  {
> -	readsl(master->regs + RX_FIFO, bytes, nbytes / 4);
> -	if (nbytes & 3) {
> -		u32 tmp;
> -
> -		readsl(master->regs + RX_FIFO, &tmp, 1);
> -		memcpy(bytes + (nbytes & ~3), &tmp, nbytes & 3);
> -	}
> +	i3c_readl_fifo(master->regs + RX_FIFO, bytes, nbytes);
>  }
>
>  static bool cdns_i3c_master_supports_ccc_cmd(struct i3c_master_controller *m,
> @@ -1330,12 +1320,7 @@ static void cdns_i3c_master_handle_ibi(struct cdns_i3c_master *master,
>  	buf = slot->data;
>
>  	nbytes = IBIR_XFER_BYTES(ibir);
> -	readsl(master->regs + IBI_DATA_FIFO, buf, nbytes / 4);
> -	if (nbytes % 3) {
> -		u32 tmp = __raw_readl(master->regs + IBI_DATA_FIFO);
> -
> -		memcpy(buf + (nbytes & ~3), &tmp, nbytes & 3);
> -	}
> +	i3c_readl_fifo(master->regs + IBI_DATA_FIFO, buf, nbytes);
>
>  	slot->len = min_t(unsigned int, IBIR_XFER_BYTES(ibir),
>  			  dev->ibi->max_payload_len);
>
> --
> 2.49.0
>
>
> --
> linux-i3c mailing list
> linux-i3c@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-i3c

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

* Re: [PATCH v3 3/3] i3c: master: dw: Use i3c_writel_fifo() and i3c_readl_fifo()
  2025-06-24  9:06 ` [PATCH v3 3/3] i3c: master: dw: " Jorge Marques
@ 2025-06-24 18:10   ` Frank Li
  2025-06-25  7:27   ` Wolfram Sang
  1 sibling, 0 replies; 14+ messages in thread
From: Frank Li @ 2025-06-24 18:10 UTC (permalink / raw)
  To: Jorge Marques
  Cc: Alexandre Belloni, Przemysław Gaj, linux-i3c, linux-kernel

On Tue, Jun 24, 2025 at 11:06:06AM +0200, Jorge Marques wrote:
> Use common inline i3c_writel_fifo()/i3c_readl_fifo() methods to
> simplify code since the FIFO of controller is a 32bit width.
>
> Signed-off-by: Jorge Marques <jorge.marques@analog.com>

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

> ---
>  drivers/i3c/master/dw-i3c-master.c | 25 ++++---------------------
>  1 file changed, 4 insertions(+), 21 deletions(-)
>
> diff --git a/drivers/i3c/master/dw-i3c-master.c b/drivers/i3c/master/dw-i3c-master.c
> index 611c22b72c1572ddf717c8ad473e44a3b8fcceaf..886f8b74defda31ae93248467d144f9c8c561581 100644
> --- a/drivers/i3c/master/dw-i3c-master.c
> +++ b/drivers/i3c/master/dw-i3c-master.c
> @@ -23,6 +23,7 @@
>  #include <linux/reset.h>
>  #include <linux/slab.h>
>
> +#include "../internals.h"
>  #include "dw-i3c-master.h"
>
>  #define DEVICE_CTRL			0x0
> @@ -336,37 +337,19 @@ static int dw_i3c_master_get_free_pos(struct dw_i3c_master *master)
>  static void dw_i3c_master_wr_tx_fifo(struct dw_i3c_master *master,
>  				     const u8 *bytes, int nbytes)
>  {
> -	writesl(master->regs + RX_TX_DATA_PORT, bytes, nbytes / 4);
> -	if (nbytes & 3) {
> -		u32 tmp = 0;
> -
> -		memcpy(&tmp, bytes + (nbytes & ~3), nbytes & 3);
> -		writesl(master->regs + RX_TX_DATA_PORT, &tmp, 1);
> -	}
> -}
> -
> -static void dw_i3c_master_read_fifo(struct dw_i3c_master *master,
> -				    int reg,  u8 *bytes, int nbytes)
> -{
> -	readsl(master->regs + reg, bytes, nbytes / 4);
> -	if (nbytes & 3) {
> -		u32 tmp;
> -
> -		readsl(master->regs + reg, &tmp, 1);
> -		memcpy(bytes + (nbytes & ~3), &tmp, nbytes & 3);
> -	}
> +	i3c_writel_fifo(master->regs + RX_TX_DATA_PORT, bytes, nbytes);
>  }
>
>  static void dw_i3c_master_read_rx_fifo(struct dw_i3c_master *master,
>  				       u8 *bytes, int nbytes)
>  {
> -	return dw_i3c_master_read_fifo(master, RX_TX_DATA_PORT, bytes, nbytes);
> +	i3c_readl_fifo(master->regs + RX_TX_DATA_PORT, bytes, nbytes);
>  }
>
>  static void dw_i3c_master_read_ibi_fifo(struct dw_i3c_master *master,
>  					u8 *bytes, int nbytes)
>  {
> -	return dw_i3c_master_read_fifo(master, IBI_QUEUE_STATUS, bytes, nbytes);
> +	i3c_readl_fifo(master->regs + IBI_QUEUE_STATUS, bytes, nbytes);
>  }
>
>  static struct dw_i3c_xfer *
>
> --
> 2.49.0
>

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

* Re: [PATCH v3 1/3] i3c: master: Add inline i3c_readl_fifo() and i3c_writel_fifo()
  2025-06-24 18:08   ` Frank Li
@ 2025-06-24 20:30     ` Wolfram Sang
  2025-06-24 21:13       ` Frank Li
  0 siblings, 1 reply; 14+ messages in thread
From: Wolfram Sang @ 2025-06-24 20:30 UTC (permalink / raw)
  To: Frank Li
  Cc: Jorge Marques, Alexandre Belloni, Przemysław Gaj, linux-i3c,
	linux-kernel

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

On Tue, Jun 24, 2025 at 02:08:45PM -0400, Frank Li wrote:
> On Tue, Jun 24, 2025 at 11:06:04AM +0200, Jorge Marques wrote:
> > The I3C abstraction expects u8 buffers, but some controllers operate with
> > a 32-bit bus width FIFO and cannot flag valid bytes individually. To avoid
> > reading or writing outside the buffer bounds, use 32-bit accesses where
> > possible and apply memcpy for any remaining bytes
> >
> > Signed-off-by: Jorge Marques <jorge.marques@analog.com>
> 
> Reviewed-by: Frank Li <Frank.Li@nxp.com>
> 
> > ---
> >  drivers/i3c/internals.h | 37 +++++++++++++++++++++++++++++++++++++

Is there a reason we don't put this in 'include/linux/i3c/master.h'?
'internals.h' is used for the core only so far, and '#include
<../something.h>' also looks a bit like a layering violation.


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

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

* Re: [PATCH v3 1/3] i3c: master: Add inline i3c_readl_fifo() and i3c_writel_fifo()
  2025-06-24 20:30     ` Wolfram Sang
@ 2025-06-24 21:13       ` Frank Li
  2025-06-25  7:20         ` Wolfram Sang
  0 siblings, 1 reply; 14+ messages in thread
From: Frank Li @ 2025-06-24 21:13 UTC (permalink / raw)
  To: Wolfram Sang
  Cc: Jorge Marques, Alexandre Belloni, Przemysław Gaj, linux-i3c,
	linux-kernel

On Tue, Jun 24, 2025 at 10:30:42PM +0200, Wolfram Sang wrote:
> On Tue, Jun 24, 2025 at 02:08:45PM -0400, Frank Li wrote:
> > On Tue, Jun 24, 2025 at 11:06:04AM +0200, Jorge Marques wrote:
> > > The I3C abstraction expects u8 buffers, but some controllers operate with
> > > a 32-bit bus width FIFO and cannot flag valid bytes individually. To avoid
> > > reading or writing outside the buffer bounds, use 32-bit accesses where
> > > possible and apply memcpy for any remaining bytes
> > >
> > > Signed-off-by: Jorge Marques <jorge.marques@analog.com>
> >
> > Reviewed-by: Frank Li <Frank.Li@nxp.com>
> >
> > > ---
> > >  drivers/i3c/internals.h | 37 +++++++++++++++++++++++++++++++++++++
>
> Is there a reason we don't put this in 'include/linux/i3c/master.h'?

master.h can be accessed in whole kernel tree. The scope is too big for these
helper functions, which should only limited to i3c drivers.

> 'internals.h' is used for the core only so far, and '#include
> <../something.h>' also looks a bit like a layering violation.

Not yet, you can look driver/pci/controller/*,  which include ../pci.h.

Frank
>



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

* Re: [PATCH v3 1/3] i3c: master: Add inline i3c_readl_fifo() and i3c_writel_fifo()
  2025-06-24 21:13       ` Frank Li
@ 2025-06-25  7:20         ` Wolfram Sang
  0 siblings, 0 replies; 14+ messages in thread
From: Wolfram Sang @ 2025-06-25  7:20 UTC (permalink / raw)
  To: Frank Li
  Cc: Jorge Marques, Alexandre Belloni, Przemysław Gaj, linux-i3c,
	linux-kernel


> > Is there a reason we don't put this in 'include/linux/i3c/master.h'?
> 
> master.h can be accessed in whole kernel tree. The scope is too big for these
> helper functions, which should only limited to i3c drivers.

Yet, who is going to include 'linux/i3c/master.h' outside of an I3C
controller driver?

> 
> > 'internals.h' is used for the core only so far, and '#include
> > <../something.h>' also looks a bit like a layering violation.
> 
> Not yet, you can look driver/pci/controller/*,  which include ../pci.h.

I never denied that it already exists in the kernel. But it still looks
fragile to me.

Whatever, it's not worth a big discussion. We can move this code if
there ever comes a reason to do so.


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

* Re: [PATCH v3 1/3] i3c: master: Add inline i3c_readl_fifo() and i3c_writel_fifo()
  2025-06-24  9:06 ` [PATCH v3 1/3] i3c: master: Add inline i3c_readl_fifo() and i3c_writel_fifo() Jorge Marques
  2025-06-24 18:08   ` Frank Li
@ 2025-06-25  7:24   ` Wolfram Sang
  1 sibling, 0 replies; 14+ messages in thread
From: Wolfram Sang @ 2025-06-25  7:24 UTC (permalink / raw)
  To: Jorge Marques
  Cc: Alexandre Belloni, Frank Li, Przemysław Gaj, linux-i3c,
	linux-kernel

On Tue, Jun 24, 2025 at 11:06:04AM +0200, Jorge Marques wrote:
> The I3C abstraction expects u8 buffers, but some controllers operate with
> a 32-bit bus width FIFO and cannot flag valid bytes individually. To avoid
> reading or writing outside the buffer bounds, use 32-bit accesses where
> possible and apply memcpy for any remaining bytes
> 
> Signed-off-by: Jorge Marques <jorge.marques@analog.com>

As per [1]:
Suggested-by: Wolfram Sang <wsa+renesas@sang-engineering.com>

My concern is rejected, and the rest looks good to me, so:
Reviewed-by: Wolfram Sang <wsa+renesas@sang-engineering.com>

It still works nicely with the Renesas driver:
Tested-by: Wolfram Sang <wsa+renesas@sang-engineering.com>

[1] https://lore.kernel.org/r/20250611093934.4208-5-wsa+renesas@sang-engineering.com

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

* Re: [PATCH v3 2/3] i3c: master: cdns: Use i3c_writel_fifo() and i3c_readl_fifo()
  2025-06-24  9:06 ` [PATCH v3 2/3] i3c: master: cdns: Use i3c_writel_fifo() and i3c_readl_fifo() Jorge Marques
  2025-06-24 18:09   ` Frank Li
@ 2025-06-25  7:26   ` Wolfram Sang
  1 sibling, 0 replies; 14+ messages in thread
From: Wolfram Sang @ 2025-06-25  7:26 UTC (permalink / raw)
  To: Jorge Marques
  Cc: Alexandre Belloni, Frank Li, Przemysław Gaj, linux-i3c,
	linux-kernel

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


>  static void cdns_i3c_master_wr_to_tx_fifo(struct cdns_i3c_master *master,
>  					  const u8 *bytes, int nbytes)
>  {
> -	writesl(master->regs + TX_FIFO, bytes, nbytes / 4);
> -	if (nbytes & 3) {
> -		u32 tmp = 0;
> -
> -		memcpy(&tmp, bytes + (nbytes & ~3), nbytes & 3);
> -		writesl(master->regs + TX_FIFO, &tmp, 1);
> -	}
> +	i3c_writel_fifo(master->regs + TX_FIFO, bytes, nbytes);
>  }

What about getting rid of the surrounding function and use the helper
directly?


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

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

* Re: [PATCH v3 3/3] i3c: master: dw: Use i3c_writel_fifo() and i3c_readl_fifo()
  2025-06-24  9:06 ` [PATCH v3 3/3] i3c: master: dw: " Jorge Marques
  2025-06-24 18:10   ` Frank Li
@ 2025-06-25  7:27   ` Wolfram Sang
  1 sibling, 0 replies; 14+ messages in thread
From: Wolfram Sang @ 2025-06-25  7:27 UTC (permalink / raw)
  To: Jorge Marques
  Cc: Alexandre Belloni, Frank Li, Przemysław Gaj, linux-i3c,
	linux-kernel


>  static void dw_i3c_master_read_rx_fifo(struct dw_i3c_master *master,
>  				       u8 *bytes, int nbytes)
>  {
> -	return dw_i3c_master_read_fifo(master, RX_TX_DATA_PORT, bytes, nbytes);
> +	i3c_readl_fifo(master->regs + RX_TX_DATA_PORT, bytes, nbytes);
>  }

Same question as patch 2, why not remove the surrounding functions?


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

* Re: [PATCH v3 0/3] Add helper methods i3c_writel_fifo() and i3c_readl_fifo()
  2025-06-24  9:06 [PATCH v3 0/3] Add helper methods i3c_writel_fifo() and i3c_readl_fifo() Jorge Marques
                   ` (2 preceding siblings ...)
  2025-06-24  9:06 ` [PATCH v3 3/3] i3c: master: dw: " Jorge Marques
@ 2025-07-30 23:40 ` Alexandre Belloni
  3 siblings, 0 replies; 14+ messages in thread
From: Alexandre Belloni @ 2025-07-30 23:40 UTC (permalink / raw)
  To: Frank Li, Przemysław Gaj, Jorge Marques; +Cc: linux-i3c, linux-kernel

On Tue, 24 Jun 2025 11:06:03 +0200, Jorge Marques wrote:
> The I3C abstraction expects u8 buffers, but some controllers operate with
> a 32-bit bus width FIFO and cannot flag valid bytes individually. To avoid
> reading or writing outside the buffer bounds, use 32-bit accesses where
> possible and apply memcpy for any remaining bytes.
> 
> Add two auxiliary methods to include/linux/i3c/master.h and use in the dw
> and cdns i3c controller drivers. The adi and renesas controller drivers
> will also use these methods.
> 
> [...]

Applied, thanks!

[1/3] i3c: master: Add inline i3c_readl_fifo() and i3c_writel_fifo()
      https://git.kernel.org/abelloni/c/733b439375b4
[2/3] i3c: master: cdns: Use i3c_writel_fifo() and i3c_readl_fifo()
      https://git.kernel.org/abelloni/c/c20d3fa70491
[3/3] i3c: master: dw: Use i3c_writel_fifo() and i3c_readl_fifo()
      https://git.kernel.org/abelloni/c/6e055b1fb2fc

Best regards,

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

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

end of thread, other threads:[~2025-07-30 23:40 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-24  9:06 [PATCH v3 0/3] Add helper methods i3c_writel_fifo() and i3c_readl_fifo() Jorge Marques
2025-06-24  9:06 ` [PATCH v3 1/3] i3c: master: Add inline i3c_readl_fifo() and i3c_writel_fifo() Jorge Marques
2025-06-24 18:08   ` Frank Li
2025-06-24 20:30     ` Wolfram Sang
2025-06-24 21:13       ` Frank Li
2025-06-25  7:20         ` Wolfram Sang
2025-06-25  7:24   ` Wolfram Sang
2025-06-24  9:06 ` [PATCH v3 2/3] i3c: master: cdns: Use i3c_writel_fifo() and i3c_readl_fifo() Jorge Marques
2025-06-24 18:09   ` Frank Li
2025-06-25  7:26   ` Wolfram Sang
2025-06-24  9:06 ` [PATCH v3 3/3] i3c: master: dw: " Jorge Marques
2025-06-24 18:10   ` Frank Li
2025-06-25  7:27   ` Wolfram Sang
2025-07-30 23:40 ` [PATCH v3 0/3] Add helper methods " Alexandre Belloni

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