[RFC PATCH 3/9] i3c: master: svc return actual transfer data len

Frank Li
2023-09-05T21:39:18Z

I3C allow devices early terminate data transfer. So set "actual" to
indicate how much data get by i3c_priv_xfer.

Signed-off-by: Frank Li <Frank.Li@nxp.com>
---
drivers/i3c/master/svc-i3c-master.c | 26 +++++++++++++++++++-------
1 file changed, 19 insertions(+), 7 deletions(-)

diff --git a/drivers/i3c/master/svc-i3c-master.c b/drivers/i3c/master/svc-i3c-master.c
index 14185ee7dd19b..74c4ce8789daf 100644
--- a/drivers/i3c/master/svc-i3c-master.c
+++ b/drivers/i3c/master/svc-i3c-master.c
@@ -134,6 +134,7 @@ struct svc_i3c_cmd {
const void *out;
unsigned int len;
unsigned int actual_len;
+ struct i3c_priv_xfer *xfer;
bool continued;
};

@@ -972,12 +973,14 @@ static int svc_i3c_master_read(struct svc_i3c_master *master,
}

static int svc_i3c_master_write(struct svc_i3c_master *master,
- const u8 *out, unsigned int len)
+ const u8 *out, unsigned int len, unsigned int *actual)
{
- int offset = 0, ret;
+ int ret;
u32 mdctrl;

- while (offset < len) {
+ *actual = 0;
+
+ while (*actual < len) {
ret = readl_poll_timeout(master->regs + SVC_I3C_MDATACTRL,
mdctrl,
!(mdctrl & SVC_I3C_MDATACTRL_TXFULL),
@@ -989,10 +992,10 @@ static int svc_i3c_master_write(struct svc_i3c_master *master,
* The last byte to be sent over the bus must either have the
* "end" bit set or be written in MWDATABE.
*/
- if (likely(offset < (len - 1)))
- writel(out[offset++], master->regs + SVC_I3C_MWDATAB);
+ if (likely(*actual < (len - 1)))
+ writel(out[(*actual)++], master->regs + SVC_I3C_MWDATAB);
else
- writel(out[offset++], master->regs + SVC_I3C_MWDATABE);
+ writel(out[(*actual)++], master->regs + SVC_I3C_MWDATABE);
}

return 0;
@@ -1027,7 +1030,8 @@ static int svc_i3c_master_xfer(struct svc_i3c_master *master,
if (rnw)
ret = svc_i3c_master_read(master, in, xfer_len);
else
- ret = svc_i3c_master_write(master, out, xfer_len);
+ ret = svc_i3c_master_write(master, out, xfer_len, actual_len);
+
if (ret < 0)
goto emit_stop;

@@ -1047,6 +1051,10 @@ static int svc_i3c_master_xfer(struct svc_i3c_master *master,
/* Wait idle if stop is sent. */
readl_poll_timeout(master->regs + SVC_I3C_MSTATUS, reg,
SVC_I3C_MSTATUS_STATE_IDLE(reg), 0, 1000);
+
+ if (!rnw)
+ *actual_len -= SVC_I3C_MDATACTRL_RXCOUNT(
+ readl(master->regs + SVC_I3C_MDATACTRL));
}

return 0;
@@ -1116,6 +1124,9 @@ static void svc_i3c_master_start_xfer_locked(struct svc_i3c_master *master)
cmd->addr, cmd->in, cmd->out,
cmd->len, &cmd->actual_len,
cmd->continued);
+ if (cmd->xfer)
+ cmd->xfer->actual = cmd->actual_len;
+
if (ret)
break;
}
@@ -1299,6 +1310,7 @@ static int svc_i3c_master_priv_xfers(struct i3c_dev_desc *dev,
for (i = 0; i < nxfers; i++) {
struct svc_i3c_cmd *cmd = &xfer->cmds[i];

+ cmd->xfer = xfers + i;
cmd->addr = master->addrs[data->index];
cmd->rnw = xfers[i].rnw;
cmd->in = xfers[i].rnw ? xfers[i].data.in : NULL;