public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 1/1] i3c: master: svc: Prevent incomplete IBI transaction
@ 2025-10-27  3:47 Stanley Chu
  2025-10-27 21:06 ` Frank Li
  2025-10-30 23:43 ` Alexandre Belloni
  0 siblings, 2 replies; 4+ messages in thread
From: Stanley Chu @ 2025-10-27  3:47 UTC (permalink / raw)
  To: frank.li, miquel.raynal, alexandre.belloni, linux-i3c
  Cc: linux-kernel, tomer.maimon, kwliu, yschu

From: Stanley Chu <yschu@nuvoton.com>

If no free IBI slot is available, svc_i3c_master_handle_ibi returns
immediately. This causes the STOP condition to be missed because the
EmitStop request is sent when the transfer is not complete. To resolve
this, svc_i3c_master_handle_ibi must wait for the transfer to complete
before returning.

Fixes: dd3c52846d59 ("i3c: master: svc: Add Silvaco I3C master driver")
Signed-off-by: Stanley Chu <yschu@nuvoton.com>
---
Changes since v1:
 * do not touch coding style change
---
 drivers/i3c/master/svc-i3c-master.c | 22 ++++++++++++++--------
 1 file changed, 14 insertions(+), 8 deletions(-)

diff --git a/drivers/i3c/master/svc-i3c-master.c b/drivers/i3c/master/svc-i3c-master.c
index 9641e66a4e5f..e70a64f2a32f 100644
--- a/drivers/i3c/master/svc-i3c-master.c
+++ b/drivers/i3c/master/svc-i3c-master.c
@@ -406,21 +406,27 @@ static int svc_i3c_master_handle_ibi(struct svc_i3c_master *master,
 	int ret, val;
 	u8 *buf;
 
-	slot = i3c_generic_ibi_get_free_slot(data->ibi_pool);
-	if (!slot)
-		return -ENOSPC;
-
-	slot->len = 0;
-	buf = slot->data;
-
+	/*
+	 * Wait for transfer to complete before returning. Otherwise, the EmitStop
+	 * request might be sent when the transfer is not complete.
+	 */
 	ret = readl_relaxed_poll_timeout(master->regs + SVC_I3C_MSTATUS, val,
 						SVC_I3C_MSTATUS_COMPLETE(val), 0, 1000);
 	if (ret) {
 		dev_err(master->dev, "Timeout when polling for COMPLETE\n");
-		i3c_generic_ibi_recycle_slot(data->ibi_pool, slot);
 		return ret;
 	}
 
+	slot = i3c_generic_ibi_get_free_slot(data->ibi_pool);
+	if (!slot) {
+		dev_dbg(master->dev, "No free ibi slot, drop the data\n");
+		writel(SVC_I3C_MDATACTRL_FLUSHRB, master->regs + SVC_I3C_MDATACTRL);
+		return -ENOSPC;
+	}
+
+	slot->len = 0;
+	buf = slot->data;
+
 	while (SVC_I3C_MSTATUS_RXPEND(readl(master->regs + SVC_I3C_MSTATUS))  &&
 	       slot->len < SVC_I3C_FIFO_SIZE) {
 		mdatactrl = readl(master->regs + SVC_I3C_MDATACTRL);
-- 
2.34.1


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

* Re: [PATCH v2 1/1] i3c: master: svc: Prevent incomplete IBI transaction
  2025-10-27  3:47 [PATCH v2 1/1] i3c: master: svc: Prevent incomplete IBI transaction Stanley Chu
@ 2025-10-27 21:06 ` Frank Li
  2025-10-28  8:27   ` Miquel Raynal
  2025-10-30 23:43 ` Alexandre Belloni
  1 sibling, 1 reply; 4+ messages in thread
From: Frank Li @ 2025-10-27 21:06 UTC (permalink / raw)
  To: Stanley Chu
  Cc: miquel.raynal, alexandre.belloni, linux-i3c, linux-kernel,
	tomer.maimon, kwliu, yschu

On Mon, Oct 27, 2025 at 11:47:15AM +0800, Stanley Chu wrote:
> From: Stanley Chu <yschu@nuvoton.com>
>
> If no free IBI slot is available, svc_i3c_master_handle_ibi returns
> immediately. This causes the STOP condition to be missed because the
> EmitStop request is sent when the transfer is not complete. To resolve
> this, svc_i3c_master_handle_ibi must wait for the transfer to complete
> before returning.
>
> Fixes: dd3c52846d59 ("i3c: master: svc: Add Silvaco I3C master driver")
> Signed-off-by: Stanley Chu <yschu@nuvoton.com>
> ---

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

> Changes since v1:
>  * do not touch coding style change
> ---
>  drivers/i3c/master/svc-i3c-master.c | 22 ++++++++++++++--------
>  1 file changed, 14 insertions(+), 8 deletions(-)
>
> diff --git a/drivers/i3c/master/svc-i3c-master.c b/drivers/i3c/master/svc-i3c-master.c
> index 9641e66a4e5f..e70a64f2a32f 100644
> --- a/drivers/i3c/master/svc-i3c-master.c
> +++ b/drivers/i3c/master/svc-i3c-master.c
> @@ -406,21 +406,27 @@ static int svc_i3c_master_handle_ibi(struct svc_i3c_master *master,
>  	int ret, val;
>  	u8 *buf;
>
> -	slot = i3c_generic_ibi_get_free_slot(data->ibi_pool);
> -	if (!slot)
> -		return -ENOSPC;
> -
> -	slot->len = 0;
> -	buf = slot->data;
> -
> +	/*
> +	 * Wait for transfer to complete before returning. Otherwise, the EmitStop
> +	 * request might be sent when the transfer is not complete.
> +	 */
>  	ret = readl_relaxed_poll_timeout(master->regs + SVC_I3C_MSTATUS, val,
>  						SVC_I3C_MSTATUS_COMPLETE(val), 0, 1000);
>  	if (ret) {
>  		dev_err(master->dev, "Timeout when polling for COMPLETE\n");
> -		i3c_generic_ibi_recycle_slot(data->ibi_pool, slot);
>  		return ret;
>  	}
>
> +	slot = i3c_generic_ibi_get_free_slot(data->ibi_pool);
> +	if (!slot) {
> +		dev_dbg(master->dev, "No free ibi slot, drop the data\n");
> +		writel(SVC_I3C_MDATACTRL_FLUSHRB, master->regs + SVC_I3C_MDATACTRL);
> +		return -ENOSPC;
> +	}
> +
> +	slot->len = 0;
> +	buf = slot->data;
> +
>  	while (SVC_I3C_MSTATUS_RXPEND(readl(master->regs + SVC_I3C_MSTATUS))  &&
>  	       slot->len < SVC_I3C_FIFO_SIZE) {
>  		mdatactrl = readl(master->regs + SVC_I3C_MDATACTRL);
> --
> 2.34.1
>

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

* Re: [PATCH v2 1/1] i3c: master: svc: Prevent incomplete IBI transaction
  2025-10-27 21:06 ` Frank Li
@ 2025-10-28  8:27   ` Miquel Raynal
  0 siblings, 0 replies; 4+ messages in thread
From: Miquel Raynal @ 2025-10-28  8:27 UTC (permalink / raw)
  To: Frank Li
  Cc: Stanley Chu, alexandre.belloni, linux-i3c, linux-kernel,
	tomer.maimon, kwliu, yschu

Hello,

On 27/10/2025 at 17:06:20 -04, Frank Li <Frank.li@nxp.com> wrote:

> On Mon, Oct 27, 2025 at 11:47:15AM +0800, Stanley Chu wrote:
>> From: Stanley Chu <yschu@nuvoton.com>
>>
>> If no free IBI slot is available, svc_i3c_master_handle_ibi returns
>> immediately. This causes the STOP condition to be missed because the
>> EmitStop request is sent when the transfer is not complete. To resolve
>> this, svc_i3c_master_handle_ibi must wait for the transfer to complete
>> before returning.
>>
>> Fixes: dd3c52846d59 ("i3c: master: svc: Add Silvaco I3C master driver")
>> Signed-off-by: Stanley Chu <yschu@nuvoton.com>
>> ---
>
> Reviewed-by: Frank Li <Frank.Li@nxp.com>

Reviewed-by: Miquel Raynal <miquel.raynal@bootlin.com>

Thanks,
Miquèl

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

* Re: [PATCH v2 1/1] i3c: master: svc: Prevent incomplete IBI transaction
  2025-10-27  3:47 [PATCH v2 1/1] i3c: master: svc: Prevent incomplete IBI transaction Stanley Chu
  2025-10-27 21:06 ` Frank Li
@ 2025-10-30 23:43 ` Alexandre Belloni
  1 sibling, 0 replies; 4+ messages in thread
From: Alexandre Belloni @ 2025-10-30 23:43 UTC (permalink / raw)
  To: frank.li, miquel.raynal, linux-i3c, Stanley Chu
  Cc: linux-kernel, tomer.maimon, kwliu, yschu

On Mon, 27 Oct 2025 11:47:15 +0800, Stanley Chu wrote:
> If no free IBI slot is available, svc_i3c_master_handle_ibi returns
> immediately. This causes the STOP condition to be missed because the
> EmitStop request is sent when the transfer is not complete. To resolve
> this, svc_i3c_master_handle_ibi must wait for the transfer to complete
> before returning.
> 
> 
> [...]

Applied, thanks!

[1/1] i3c: master: svc: Prevent incomplete IBI transaction
      https://git.kernel.org/abelloni/c/3a36273e5a07

Best regards,

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

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

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

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-10-27  3:47 [PATCH v2 1/1] i3c: master: svc: Prevent incomplete IBI transaction Stanley Chu
2025-10-27 21:06 ` Frank Li
2025-10-28  8:27   ` Miquel Raynal
2025-10-30 23:43 ` Alexandre Belloni

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