linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3] i3c: master: svc: Fix npcm845 FIFO_EMPTY quirk
@ 2025-07-30  0:37 Stanley Chu
  2025-07-30  7:59 ` Miquel Raynal
  2025-07-30 23:40 ` Alexandre Belloni
  0 siblings, 2 replies; 3+ messages in thread
From: Stanley Chu @ 2025-07-30  0:37 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>

In a private write transfer, the driver pre-fills the FIFO to work around
the FIFO_EMPTY quirk. However, if an IBIWON event occurs, the hardware
emits a NACK and the driver initiates a retry. During the retry, driver
attempts to pre-fill the FIFO again if there is remaining data, but since
the FIFO is already full, this leads to data loss.

Check available space in FIFO to prevent overflow.

Fixes: 4008a74e0f9b ("i3c: master: svc: Fix npcm845 FIFO empty issue")
Signed-off-by: Stanley Chu <yschu@nuvoton.com>
---
Changes since v2:
 update commit message

 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 7e1a7cb94b43..ece563353895 100644
--- a/drivers/i3c/master/svc-i3c-master.c
+++ b/drivers/i3c/master/svc-i3c-master.c
@@ -104,6 +104,7 @@
 #define   SVC_I3C_MDATACTRL_TXTRIG_FIFO_NOT_FULL GENMASK(5, 4)
 #define   SVC_I3C_MDATACTRL_RXTRIG_FIFO_NOT_EMPTY 0
 #define   SVC_I3C_MDATACTRL_RXCOUNT(x) FIELD_GET(GENMASK(28, 24), (x))
+#define   SVC_I3C_MDATACTRL_TXCOUNT(x) FIELD_GET(GENMASK(20, 16), (x))
 #define   SVC_I3C_MDATACTRL_TXFULL BIT(30)
 #define   SVC_I3C_MDATACTRL_RXEMPTY BIT(31)
 
@@ -1304,14 +1305,19 @@ static int svc_i3c_master_xfer(struct svc_i3c_master *master,
 		 * FIFO start filling as soon as possible after EmitStartAddr.
 		 */
 		if (svc_has_quirk(master, SVC_I3C_QUIRK_FIFO_EMPTY) && !rnw && xfer_len) {
-			u32 end = xfer_len > SVC_I3C_FIFO_SIZE ? 0 : SVC_I3C_MWDATAB_END;
-			u32 len = min_t(u32, xfer_len, SVC_I3C_FIFO_SIZE);
-
-			writesb(master->regs + SVC_I3C_MWDATAB1, out, len - 1);
-			/* Mark END bit if this is the last byte */
-			writel(out[len - 1] | end, master->regs + SVC_I3C_MWDATAB);
-			xfer_len -= len;
-			out += len;
+			u32 space, end, len;
+
+			reg = readl(master->regs + SVC_I3C_MDATACTRL);
+			space = SVC_I3C_FIFO_SIZE - SVC_I3C_MDATACTRL_TXCOUNT(reg);
+			if (space) {
+				end = xfer_len > space ? 0 : SVC_I3C_MWDATAB_END;
+				len = min_t(u32, xfer_len, space);
+				writesb(master->regs + SVC_I3C_MWDATAB1, out, len - 1);
+				/* Mark END bit if this is the last byte */
+				writel(out[len - 1] | end, master->regs + SVC_I3C_MWDATAB);
+				xfer_len -= len;
+				out += len;
+			}
 		}
 
 		ret = readl_poll_timeout(master->regs + SVC_I3C_MSTATUS, reg,
-- 
2.34.1


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

* Re: [PATCH v3] i3c: master: svc: Fix npcm845 FIFO_EMPTY quirk
  2025-07-30  0:37 [PATCH v3] i3c: master: svc: Fix npcm845 FIFO_EMPTY quirk Stanley Chu
@ 2025-07-30  7:59 ` Miquel Raynal
  2025-07-30 23:40 ` Alexandre Belloni
  1 sibling, 0 replies; 3+ messages in thread
From: Miquel Raynal @ 2025-07-30  7:59 UTC (permalink / raw)
  To: Stanley Chu
  Cc: frank.li, alexandre.belloni, linux-i3c, linux-kernel,
	tomer.maimon, kwliu, yschu

Hi Stanley,

On 30/07/2025 at 08:37:19 +08, Stanley Chu <stanley.chuys@gmail.com> wrote:

> From: Stanley Chu <yschu@nuvoton.com>
>
> In a private write transfer, the driver pre-fills the FIFO to work around
> the FIFO_EMPTY quirk. However, if an IBIWON event occurs, the hardware
> emits a NACK and the driver initiates a retry. During the retry, driver
> attempts to pre-fill the FIFO again if there is remaining data, but since
> the FIFO is already full, this leads to data loss.
>
> Check available space in FIFO to prevent overflow.
>
> Fixes: 4008a74e0f9b ("i3c: master: svc: Fix npcm845 FIFO empty issue")

Still missing Cc: stable here

> Signed-off-by: Stanley Chu <yschu@nuvoton.com>
> ---

Thanks,
Miquèl

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

* Re: [PATCH v3] i3c: master: svc: Fix npcm845 FIFO_EMPTY quirk
  2025-07-30  0:37 [PATCH v3] i3c: master: svc: Fix npcm845 FIFO_EMPTY quirk Stanley Chu
  2025-07-30  7:59 ` Miquel Raynal
@ 2025-07-30 23:40 ` Alexandre Belloni
  1 sibling, 0 replies; 3+ messages in thread
From: Alexandre Belloni @ 2025-07-30 23:40 UTC (permalink / raw)
  To: frank.li, miquel.raynal, linux-i3c, Stanley Chu
  Cc: linux-kernel, tomer.maimon, kwliu, yschu

On Wed, 30 Jul 2025 08:37:19 +0800, Stanley Chu wrote:
> In a private write transfer, the driver pre-fills the FIFO to work around
> the FIFO_EMPTY quirk. However, if an IBIWON event occurs, the hardware
> emits a NACK and the driver initiates a retry. During the retry, driver
> attempts to pre-fill the FIFO again if there is remaining data, but since
> the FIFO is already full, this leads to data loss.
> 
> Check available space in FIFO to prevent overflow.
> 
> [...]

Applied, thanks!

[1/1] i3c: master: svc: Fix npcm845 FIFO_EMPTY quirk
      https://git.kernel.org/abelloni/c/bc4a09d8e79c

Best regards,

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

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

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

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-07-30  0:37 [PATCH v3] i3c: master: svc: Fix npcm845 FIFO_EMPTY quirk Stanley Chu
2025-07-30  7:59 ` Miquel Raynal
2025-07-30 23:40 ` 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).