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

The i3c abstraction excepts u8 buffers, but some controllers have a bus
width of 32-bits and don't support flagging valid bytes, so it is
required to read/write long words and to use memcpy on the remainder of
the number of bytes by 32-bits to not write/read outside the buffer
bounds.

Add two auxiliary methods to include/linux/i3c/master.h and use in the dw
and cdns i3c controller drivers. The adi controller driver 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>
---
Jorge Marques (3):
      i3c: master: Add inline i3c_master_readsl and i3c_master_writesl
      i3c: master: cdns: Use i3c_master_writesl and i3c_master_readsl
      i3c: master: dw: Use i3c_master_writesl and i3c_master_readsl

 drivers/i3c/master/dw-i3c-master.c   | 24 +++---------------------
 drivers/i3c/master/i3c-master-cdns.c | 23 +++--------------------
 include/linux/i3c/master.h           | 36 ++++++++++++++++++++++++++++++++++++
 3 files changed, 42 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] 10+ messages in thread

* [PATCH 1/3] i3c: master: Add inline i3c_master_readsl and i3c_master_writesl
  2025-06-20 16:54 [PATCH 0/3] Add helper methods i3c_master_writesl and i3c_master_readsl Jorge Marques
@ 2025-06-20 16:54 ` Jorge Marques
  2025-06-20 18:41   ` Frank Li
  2025-06-20 21:15   ` Wolfram Sang
  2025-06-20 16:55 ` [PATCH 2/3] i3c: master: cdns: Use i3c_master_writesl and i3c_master_readsl Jorge Marques
  2025-06-20 16:55 ` [PATCH 3/3] i3c: master: dw: " Jorge Marques
  2 siblings, 2 replies; 10+ messages in thread
From: Jorge Marques @ 2025-06-20 16:54 UTC (permalink / raw)
  To: Alexandre Belloni, Frank Li, Przemysław Gaj
  Cc: linux-i3c, linux-kernel, Jorge Marques

The i3c abstraction excepts u8 buffers, but some controllers have a bus
width of 32-bits and don't support flagging valid bytes, so it is
required to read/write long words and to use memcpy on the remainder of
the number of bytes by 32-bits to not write/read outside the buffer
bounds.

Signed-off-by: Jorge Marques <jorge.marques@analog.com>
---
 include/linux/i3c/master.h | 36 ++++++++++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)

diff --git a/include/linux/i3c/master.h b/include/linux/i3c/master.h
index c67922ece617d6320c0c7e4838c2e7edda8c19f5..11401f2acb42e4d3a60df33b7c794d8a0360cdc2 100644
--- a/include/linux/i3c/master.h
+++ b/include/linux/i3c/master.h
@@ -674,6 +674,42 @@ i3c_master_get_bus(struct i3c_master_controller *master)
 	return &master->bus;
 }
 
+/**
+ * i3c_master_writesl- Write bytes to long memory region from byte array
+ * @addr: Register to write to
+ * @bytes: Pointer to the data bytes to write
+ * @nbytes: Number of bytes to write
+ */
+static inline void i3c_master_writesl(void __iomem *addr, const u8 *bytes,
+				      int nbytes)
+{
+writesl(addr, bytes, nbytes / 4);
+	if (nbytes & 3) {
+		u32 tmp = 0;
+
+		memcpy(&tmp, bytes + (nbytes & ~3), nbytes & 3);
+		writel(tmp, addr);
+	}
+}
+
+/**
+ * i3c_master_readsl - Read bytes from long memory region to byte array
+ * @addr: Register to read from
+ * @bytes: Pointer to the buffer to store read bytes
+ * @nbytes: Number of bytes to read
+ */
+static inline void i3c_master_readsl(const void __iomem *addr, u8 *bytes,
+				     int nbytes)
+{
+readsl(addr, bytes, nbytes / 4);
+	if (nbytes & 3) {
+		u32 tmp;
+
+		tmp = readl(addr);
+		memcpy(bytes + (nbytes & ~3), &tmp, nbytes & 3);
+	}
+}
+
 struct i3c_generic_ibi_pool;
 
 struct i3c_generic_ibi_pool *

-- 
2.49.0



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

* [PATCH 2/3] i3c: master: cdns: Use i3c_master_writesl and i3c_master_readsl
  2025-06-20 16:54 [PATCH 0/3] Add helper methods i3c_master_writesl and i3c_master_readsl Jorge Marques
  2025-06-20 16:54 ` [PATCH 1/3] i3c: master: Add inline i3c_master_readsl and i3c_master_writesl Jorge Marques
@ 2025-06-20 16:55 ` Jorge Marques
  2025-06-20 18:46   ` Frank Li
  2025-06-20 16:55 ` [PATCH 3/3] i3c: master: dw: " Jorge Marques
  2 siblings, 1 reply; 10+ messages in thread
From: Jorge Marques @ 2025-06-20 16:55 UTC (permalink / raw)
  To: Alexandre Belloni, Frank Li, Przemysław Gaj
  Cc: linux-i3c, linux-kernel, Jorge Marques

Use the inline write/read methods common to controllers that have a
bus width of 32-bits.

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

diff --git a/drivers/i3c/master/i3c-master-cdns.c b/drivers/i3c/master/i3c-master-cdns.c
index fd3752cea654954ed1e37337754e45fddbbbf68e..6775751144ae86c1795abf45ceede17e1961bb74 100644
--- a/drivers/i3c/master/i3c-master-cdns.c
+++ b/drivers/i3c/master/i3c-master-cdns.c
@@ -427,25 +427,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_master_writesl(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_master_readsl(master->regs + RX_FIFO, bytes, nbytes);
 }
 
 static bool cdns_i3c_master_supports_ccc_cmd(struct i3c_master_controller *m,
@@ -1330,12 +1318,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_master_readsl(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] 10+ messages in thread

* [PATCH 3/3] i3c: master: dw: Use i3c_master_writesl and i3c_master_readsl
  2025-06-20 16:54 [PATCH 0/3] Add helper methods i3c_master_writesl and i3c_master_readsl Jorge Marques
  2025-06-20 16:54 ` [PATCH 1/3] i3c: master: Add inline i3c_master_readsl and i3c_master_writesl Jorge Marques
  2025-06-20 16:55 ` [PATCH 2/3] i3c: master: cdns: Use i3c_master_writesl and i3c_master_readsl Jorge Marques
@ 2025-06-20 16:55 ` Jorge Marques
  2025-06-20 18:48   ` Frank Li
  2 siblings, 1 reply; 10+ messages in thread
From: Jorge Marques @ 2025-06-20 16:55 UTC (permalink / raw)
  To: Alexandre Belloni, Frank Li, Przemysław Gaj
  Cc: linux-i3c, linux-kernel, Jorge Marques

Use the inline write/read methods common to controllers that have a
bus width of 32-bits.

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

diff --git a/drivers/i3c/master/dw-i3c-master.c b/drivers/i3c/master/dw-i3c-master.c
index 611c22b72c1572ddf717c8ad473e44a3b8fcceaf..eb1346409829dc64cdd1d738e9870993d38bbb0f 100644
--- a/drivers/i3c/master/dw-i3c-master.c
+++ b/drivers/i3c/master/dw-i3c-master.c
@@ -336,37 +336,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_master_writesl(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_master_readsl(master + 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_master_readsl(master + IBI_QUEUE_STATUS, bytes, nbytes);
 }
 
 static struct dw_i3c_xfer *

-- 
2.49.0



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

* Re: [PATCH 1/3] i3c: master: Add inline i3c_master_readsl and i3c_master_writesl
  2025-06-20 16:54 ` [PATCH 1/3] i3c: master: Add inline i3c_master_readsl and i3c_master_writesl Jorge Marques
@ 2025-06-20 18:41   ` Frank Li
  2025-06-22  8:43     ` Jorge Marques
  2025-06-20 21:15   ` Wolfram Sang
  1 sibling, 1 reply; 10+ messages in thread
From: Frank Li @ 2025-06-20 18:41 UTC (permalink / raw)
  To: Jorge Marques
  Cc: Alexandre Belloni, Przemysław Gaj, linux-i3c, linux-kernel

On Fri, Jun 20, 2025 at 06:54:59PM +0200, Jorge Marques wrote:
> The i3c abstraction excepts u8 buffers, but some controllers have a bus
> width of 32-bits and don't support flagging valid bytes, so it is
> required to read/write long words and to use memcpy on the remainder of
> the number of bytes by 32-bits to not write/read outside the buffer
> bounds.
>
> Signed-off-by: Jorge Marques <jorge.marques@analog.com>
> ---
>  include/linux/i3c/master.h | 36 ++++++++++++++++++++++++++++++++++++
>  1 file changed, 36 insertions(+)
>
> diff --git a/include/linux/i3c/master.h b/include/linux/i3c/master.h
> index c67922ece617d6320c0c7e4838c2e7edda8c19f5..11401f2acb42e4d3a60df33b7c794d8a0360cdc2 100644
> --- a/include/linux/i3c/master.h
> +++ b/include/linux/i3c/master.h

suggest move to drivers/i3c/internals.h becaue only master drivers use it.

> @@ -674,6 +674,42 @@ i3c_master_get_bus(struct i3c_master_controller *master)
>  	return &master->bus;
>  }
>
> +/**
> + * i3c_master_writesl- Write bytes to long memory region from byte array
> + * @addr: Register to write to
> + * @bytes: Pointer to the data bytes to write
> + * @nbytes: Number of bytes to write
> + */
> +static inline void i3c_master_writesl(void __iomem *addr, const u8 *bytes,
> +				      int nbytes)

const void *bytes

> +{
> +writesl(addr, bytes, nbytes / 4);

fix indention

Frank

> +	if (nbytes & 3) {
> +		u32 tmp = 0;
> +
> +		memcpy(&tmp, bytes + (nbytes & ~3), nbytes & 3);
> +		writel(tmp, addr);
> +	}
> +}
> +
> +/**
> + * i3c_master_readsl - Read bytes from long memory region to byte array
> + * @addr: Register to read from
> + * @bytes: Pointer to the buffer to store read bytes
> + * @nbytes: Number of bytes to read
> + */
> +static inline void i3c_master_readsl(const void __iomem *addr, u8 *bytes,
> +				     int nbytes)
> +{
> +readsl(addr, bytes, nbytes / 4);
> +	if (nbytes & 3) {
> +		u32 tmp;
> +
> +		tmp = readl(addr);
> +		memcpy(bytes + (nbytes & ~3), &tmp, nbytes & 3);
> +	}
> +}
> +
>  struct i3c_generic_ibi_pool;
>
>  struct i3c_generic_ibi_pool *
>
> --
> 2.49.0
>
>

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

* Re: [PATCH 2/3] i3c: master: cdns: Use i3c_master_writesl and i3c_master_readsl
  2025-06-20 16:55 ` [PATCH 2/3] i3c: master: cdns: Use i3c_master_writesl and i3c_master_readsl Jorge Marques
@ 2025-06-20 18:46   ` Frank Li
  0 siblings, 0 replies; 10+ messages in thread
From: Frank Li @ 2025-06-20 18:46 UTC (permalink / raw)
  To: Jorge Marques
  Cc: Alexandre Belloni, Przemysław Gaj, linux-i3c, linux-kernel

On Fri, Jun 20, 2025 at 06:55:00PM +0200, Jorge Marques wrote:
> Use the inline write/read methods common to controllers that have a
> bus width of 32-bits.

Subject function need add "()".

i3c: master: cdns: Use i3c_master_writesl() and i3c_master_readsl()

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

Frank
>
> Signed-off-by: Jorge Marques <jorge.marques@analog.com>
> ---
>  drivers/i3c/master/i3c-master-cdns.c | 23 +++--------------------
>  1 file changed, 3 insertions(+), 20 deletions(-)
>
> diff --git a/drivers/i3c/master/i3c-master-cdns.c b/drivers/i3c/master/i3c-master-cdns.c
> index fd3752cea654954ed1e37337754e45fddbbbf68e..6775751144ae86c1795abf45ceede17e1961bb74 100644
> --- a/drivers/i3c/master/i3c-master-cdns.c
> +++ b/drivers/i3c/master/i3c-master-cdns.c
> @@ -427,25 +427,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_master_writesl(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_master_readsl(master->regs + RX_FIFO, bytes, nbytes);
>  }
>
>  static bool cdns_i3c_master_supports_ccc_cmd(struct i3c_master_controller *m,
> @@ -1330,12 +1318,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_master_readsl(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	[flat|nested] 10+ messages in thread

* Re: [PATCH 3/3] i3c: master: dw: Use i3c_master_writesl and i3c_master_readsl
  2025-06-20 16:55 ` [PATCH 3/3] i3c: master: dw: " Jorge Marques
@ 2025-06-20 18:48   ` Frank Li
  0 siblings, 0 replies; 10+ messages in thread
From: Frank Li @ 2025-06-20 18:48 UTC (permalink / raw)
  To: Jorge Marques
  Cc: Alexandre Belloni, Przemysław Gaj, linux-i3c, linux-kernel

On Fri, Jun 20, 2025 at 06:55:01PM +0200, Jorge Marques wrote:
> Use the inline write/read methods common to controllers that have a
> bus width of 32-bits.

please update commit message and subject according to previous patch's
comments.

Frank
>
> Signed-off-by: Jorge Marques <jorge.marques@analog.com>
> ---
>  drivers/i3c/master/dw-i3c-master.c | 24 +++---------------------
>  1 file changed, 3 insertions(+), 21 deletions(-)
>
> diff --git a/drivers/i3c/master/dw-i3c-master.c b/drivers/i3c/master/dw-i3c-master.c
> index 611c22b72c1572ddf717c8ad473e44a3b8fcceaf..eb1346409829dc64cdd1d738e9870993d38bbb0f 100644
> --- a/drivers/i3c/master/dw-i3c-master.c
> +++ b/drivers/i3c/master/dw-i3c-master.c
> @@ -336,37 +336,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_master_writesl(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_master_readsl(master + 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_master_readsl(master + IBI_QUEUE_STATUS, bytes, nbytes);
>  }
>
>  static struct dw_i3c_xfer *
>
> --
> 2.49.0
>
>

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

* Re: [PATCH 1/3] i3c: master: Add inline i3c_master_readsl and i3c_master_writesl
  2025-06-20 16:54 ` [PATCH 1/3] i3c: master: Add inline i3c_master_readsl and i3c_master_writesl Jorge Marques
  2025-06-20 18:41   ` Frank Li
@ 2025-06-20 21:15   ` Wolfram Sang
  2025-06-22  8:31     ` Jorge Marques
  1 sibling, 1 reply; 10+ messages in thread
From: Wolfram Sang @ 2025-06-20 21:15 UTC (permalink / raw)
  To: Jorge Marques
  Cc: Alexandre Belloni, Frank Li, Przemysław Gaj, linux-i3c,
	linux-kernel

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

On Fri, Jun 20, 2025 at 06:54:59PM +0200, Jorge Marques wrote:
> The i3c abstraction excepts u8 buffers, but some controllers have a bus
> width of 32-bits and don't support flagging valid bytes, so it is
> required to read/write long words and to use memcpy on the remainder of
> the number of bytes by 32-bits to not write/read outside the buffer
> bounds.
> 
> Signed-off-by: Jorge Marques <jorge.marques@analog.com>

Suggested-by: Wolfram Sang <wsa+renesas@sang-engineering.com>

> + * i3c_master_writesl- Write bytes to long memory region from byte array

Frank proposed the name 'i3c_writel_fifo' which I like a tad better.
Opinions?


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

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

* Re: [PATCH 1/3] i3c: master: Add inline i3c_master_readsl and i3c_master_writesl
  2025-06-20 21:15   ` Wolfram Sang
@ 2025-06-22  8:31     ` Jorge Marques
  0 siblings, 0 replies; 10+ messages in thread
From: Jorge Marques @ 2025-06-22  8:31 UTC (permalink / raw)
  To: Wolfram Sang
  Cc: Jorge Marques, Alexandre Belloni, Frank Li, Przemysław Gaj,
	linux-i3c, linux-kernel

On Fri, Jun 20, 2025 at 11:15:09PM +0200, Wolfram Sang wrote:
> On Fri, Jun 20, 2025 at 06:54:59PM +0200, Jorge Marques wrote:
> > The i3c abstraction excepts u8 buffers, but some controllers have a bus
> > width of 32-bits and don't support flagging valid bytes, so it is
> > required to read/write long words and to use memcpy on the remainder of
> > the number of bytes by 32-bits to not write/read outside the buffer
> > bounds.
> > 
> > Signed-off-by: Jorge Marques <jorge.marques@analog.com>
> 
> Suggested-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
> 
> > + * i3c_master_writesl- Write bytes to long memory region from byte array
> 
Hi Wolfram,
> Frank proposed the name 'i3c_writel_fifo' which I like a tad better.
> Opinions?
>
I don't oppose the change and I'll rename, as well moving the method to
internals.h

  i3c_master_writesl -> i3c_writel_fifo
  i3c_master_readsl -> i3c_readl_fifo

Best Regards,
Jorge

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

* Re: [PATCH 1/3] i3c: master: Add inline i3c_master_readsl and i3c_master_writesl
  2025-06-20 18:41   ` Frank Li
@ 2025-06-22  8:43     ` Jorge Marques
  0 siblings, 0 replies; 10+ messages in thread
From: Jorge Marques @ 2025-06-22  8:43 UTC (permalink / raw)
  To: Frank Li
  Cc: Jorge Marques, Alexandre Belloni, Przemysław Gaj, linux-i3c,
	linux-kernel

On Fri, Jun 20, 2025 at 02:41:12PM -0400, Frank Li wrote:
> On Fri, Jun 20, 2025 at 06:54:59PM +0200, Jorge Marques wrote:
> > The i3c abstraction excepts u8 buffers, but some controllers have a bus
> > width of 32-bits and don't support flagging valid bytes, so it is
> > required to read/write long words and to use memcpy on the remainder of
> > the number of bytes by 32-bits to not write/read outside the buffer
> > bounds.
> >
> > Signed-off-by: Jorge Marques <jorge.marques@analog.com>
> > ---
> >  include/linux/i3c/master.h | 36 ++++++++++++++++++++++++++++++++++++
> >  1 file changed, 36 insertions(+)
> >
> > diff --git a/include/linux/i3c/master.h b/include/linux/i3c/master.h
> > index c67922ece617d6320c0c7e4838c2e7edda8c19f5..11401f2acb42e4d3a60df33b7c794d8a0360cdc2 100644
> > --- a/include/linux/i3c/master.h
> > +++ b/include/linux/i3c/master.h
> 
> suggest move to drivers/i3c/internals.h becaue only master drivers use it.
> 
Hi Frank,
Ok, also renaming to i3c_writel_fifo() and i3c_readl_fifo() as well
reworking the commit messages.
> > @@ -674,6 +674,42 @@ i3c_master_get_bus(struct i3c_master_controller *master)
> >  	return &master->bus;
> >  }
> >
> > +/**
> > + * i3c_master_writesl- Write bytes to long memory region from byte array
> > + * @addr: Register to write to
> > + * @bytes: Pointer to the data bytes to write
> > + * @nbytes: Number of bytes to write
> > + */
> > +static inline void i3c_master_writesl(void __iomem *addr, const u8 *bytes,
> > +				      int nbytes)
> 
> const void *bytes
> 
Ack.

> > +{
> > +writesl(addr, bytes, nbytes / 4);
> 
> fix indention
> 
> Frank
> 
Ack.

Best regards,
Jorge
> > +	if (nbytes & 3) {
> > +		u32 tmp = 0;
> > +
> > +		memcpy(&tmp, bytes + (nbytes & ~3), nbytes & 3);
> > +		writel(tmp, addr);
> > +	}
> > +}
> > +
> > +/**
> > + * i3c_master_readsl - Read bytes from long memory region to byte array
> > + * @addr: Register to read from
> > + * @bytes: Pointer to the buffer to store read bytes
> > + * @nbytes: Number of bytes to read
> > + */
> > +static inline void i3c_master_readsl(const void __iomem *addr, u8 *bytes,
> > +				     int nbytes)
> > +{
> > +readsl(addr, bytes, nbytes / 4);
> > +	if (nbytes & 3) {
> > +		u32 tmp;
> > +
> > +		tmp = readl(addr);
> > +		memcpy(bytes + (nbytes & ~3), &tmp, nbytes & 3);
> > +	}
> > +}
> > +
> >  struct i3c_generic_ibi_pool;
> >
> >  struct i3c_generic_ibi_pool *
> >
> > --
> > 2.49.0
> >
> >

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

end of thread, other threads:[~2025-06-22  8:43 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-20 16:54 [PATCH 0/3] Add helper methods i3c_master_writesl and i3c_master_readsl Jorge Marques
2025-06-20 16:54 ` [PATCH 1/3] i3c: master: Add inline i3c_master_readsl and i3c_master_writesl Jorge Marques
2025-06-20 18:41   ` Frank Li
2025-06-22  8:43     ` Jorge Marques
2025-06-20 21:15   ` Wolfram Sang
2025-06-22  8:31     ` Jorge Marques
2025-06-20 16:55 ` [PATCH 2/3] i3c: master: cdns: Use i3c_master_writesl and i3c_master_readsl Jorge Marques
2025-06-20 18:46   ` Frank Li
2025-06-20 16:55 ` [PATCH 3/3] i3c: master: dw: " Jorge Marques
2025-06-20 18:48   ` Frank Li

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