Skip to content

Commit fe026bc

Browse files
stanleychuysgregkh
authored andcommitted
i3c: master: svc: Fix npcm845 FIFO_EMPTY quirk
[ Upstream commit bc4a09d ] 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: 4008a74 ("i3c: master: svc: Fix npcm845 FIFO empty issue") Signed-off-by: Stanley Chu <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Alexandre Belloni <[email protected]> Signed-off-by: Sasha Levin <[email protected]>
1 parent 12df2a6 commit fe026bc

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

drivers/i3c/master/svc-i3c-master.c

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@
104104
#define SVC_I3C_MDATACTRL_TXTRIG_FIFO_NOT_FULL GENMASK(5, 4)
105105
#define SVC_I3C_MDATACTRL_RXTRIG_FIFO_NOT_EMPTY 0
106106
#define SVC_I3C_MDATACTRL_RXCOUNT(x) FIELD_GET(GENMASK(28, 24), (x))
107+
#define SVC_I3C_MDATACTRL_TXCOUNT(x) FIELD_GET(GENMASK(20, 16), (x))
107108
#define SVC_I3C_MDATACTRL_TXFULL BIT(30)
108109
#define SVC_I3C_MDATACTRL_RXEMPTY BIT(31)
109110

@@ -1304,14 +1305,19 @@ static int svc_i3c_master_xfer(struct svc_i3c_master *master,
13041305
* FIFO start filling as soon as possible after EmitStartAddr.
13051306
*/
13061307
if (svc_has_quirk(master, SVC_I3C_QUIRK_FIFO_EMPTY) && !rnw && xfer_len) {
1307-
u32 end = xfer_len > SVC_I3C_FIFO_SIZE ? 0 : SVC_I3C_MWDATAB_END;
1308-
u32 len = min_t(u32, xfer_len, SVC_I3C_FIFO_SIZE);
1309-
1310-
writesb(master->regs + SVC_I3C_MWDATAB1, out, len - 1);
1311-
/* Mark END bit if this is the last byte */
1312-
writel(out[len - 1] | end, master->regs + SVC_I3C_MWDATAB);
1313-
xfer_len -= len;
1314-
out += len;
1308+
u32 space, end, len;
1309+
1310+
reg = readl(master->regs + SVC_I3C_MDATACTRL);
1311+
space = SVC_I3C_FIFO_SIZE - SVC_I3C_MDATACTRL_TXCOUNT(reg);
1312+
if (space) {
1313+
end = xfer_len > space ? 0 : SVC_I3C_MWDATAB_END;
1314+
len = min_t(u32, xfer_len, space);
1315+
writesb(master->regs + SVC_I3C_MWDATAB1, out, len - 1);
1316+
/* Mark END bit if this is the last byte */
1317+
writel(out[len - 1] | end, master->regs + SVC_I3C_MWDATAB);
1318+
xfer_len -= len;
1319+
out += len;
1320+
}
13151321
}
13161322

13171323
ret = readl_poll_timeout(master->regs + SVC_I3C_MSTATUS, reg,

0 commit comments

Comments
 (0)