Skip to contentSkip to conversation

i3c: master: some improvment for i3c master

PATCH Superseded Frank Li 5 participants 17 messages Oct 16, 2023 – Oct 18, 2023

Subsystems (3)

v1 of 5 Superseded Latest is v5 →

lore
Share & tools
lore

Frank Li

author maintainer
#0 lore raw

cover i3c: master: some improvment for i3c master

These are dependent on bugs fixed serial: https://lore.kernel.org/imx/[email protected]/T/#t
There are two major improment

1. Add actual size in i3c_transfer because i3c allow target early termiate transfer.
2. Add API for i3c_dev_gettstatus_format1 for i3c comand GET_STATUS.
3. svc master enable hotjoin default

Frank Li (5):
i3c: master: svc: enable hotjoin default
i3c: add actual in i3c_priv_xfer
i3c: svc: rename read_len as actual_len
i3c: master: svc return actual transfer data len
i3c: add API i3c_dev_gettstatus_format1() to get target device status

 drivers/i3c/device.c                | 24 ++++++++++++++++
 drivers/i3c/internals.h             |  1 +
 drivers/i3c/master.c                | 27 ++++++++++++++++++
 drivers/i3c/master/svc-i3c-master.c | 44 +++++++++++++++++++----------
 include/linux/i3c/device.h          |  2 ++
 5 files changed, 83 insertions(+), 15 deletions(-)
Signature · 1 line
2.34.1
author maintainer
#1 lore raw

PATCH 1/5 i3c: master: svc: enable hotjoin default

Hotjoin require clock running and enable SLVSTART irq.
Add module parameter 'hotjoin' to disable hotjoin and enable runtime_pm to save power.

---
 drivers/i3c/master/svc-i3c-master.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
drivers/i3c/master/svc-i3c-master.c +9 -2
index 18bc277edc8a..f0d99b029e5f 100644
@@ -128,6 +128,9 @@
 /* This parameter depends on the implementation and may be tuned */
 #define SVC_I3C_FIFO_SIZE 16
 
+static bool hotjoin = true;
+module_param(hotjoin, bool, S_IRUGO | S_IWUSR);
+
 struct svc_i3c_cmd {
 	u8 addr;
 	bool rnw;
@@ -1623,8 +1626,12 @@ static int svc_i3c_master_probe(struct platform_device *pdev)
 	if (ret)
 		goto rpm_disable;
 
-	pm_runtime_mark_last_busy(&pdev->dev);
-	pm_runtime_put_autosuspend(&pdev->dev);
+	if (hotjoin) {
+		svc_i3c_master_enable_interrupts(master, SVC_I3C_MINT_SLVSTART);
+	} else {
+		pm_runtime_mark_last_busy(&pdev->dev);
+		pm_runtime_put_autosuspend(&pdev->dev);
+	}
 
 	return 0;
 
Signature · 1 line
2.34.1
#2 lore raw

Re: [PATCH 1/5] i3c: master: svc: enable hotjoin default

Quoted 3 lines · Frank Li

Hotjoin require clock running and enable SLVSTART irq.
Add module parameter 'hotjoin' to disable hotjoin and enable runtime_pm to save power.

[]

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

Quoted 1 line
drivers/i3c/master/svc-i3c-master.c +0 -0

[]

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

Quoted 6 lines
drivers/i3c/master/svc-i3c-master.c +2 -0
@@ -128,6 +128,9 @@
 /* This parameter depends on the implementation and may be tuned */
 #define SVC_I3C_FIFO_SIZE 16
 
+static bool hotjoin = true;
+module_param(hotjoin, bool, S_IRUGO | S_IWUSR);

Might be nicer using 0644

Consider using checkpatch --strict on the series.

maintainer
#3 lore raw

Re: [PATCH 1/5] i3c: master: svc: enable hotjoin default

In reply to Frank Li

Hi Frank,

[email protected] wrote on Mon, 16 Oct 2023 11:46:28 -0400:

Quoted 3 lines

Hotjoin require clock running and enable SLVSTART irq.
Add module parameter 'hotjoin' to disable hotjoin and enable runtime_pm to save power.

I am really not a big fan of the use of modules parameters. Maybe it makes sense here. Alex, a better idea?

Thanks,
Miquèl

author maintainer
#4 lore raw

Re: [PATCH 1/5] i3c: master: svc: enable hotjoin default

Quoted 10 lines · Miquel Raynal

Hi Frank,

[email protected] wrote on Mon, 16 Oct 2023 11:46:28 -0400:

Quoted 3 lines

Hotjoin require clock running and enable SLVSTART irq.
Add module parameter 'hotjoin' to disable hotjoin and enable runtime_pm to save power.

I am really not a big fan of the use of modules parameters. Maybe it makes sense here. Alex, a better idea?

Maybe we can create sys entry to enable/disable hotjoin. I think i3c should default support hotjoin, but it exist user case that needn't hj and want more aggressive power saving.

If create /sys/ entry, it need change driver/i3c/master.c.

Frank

Quoted 3 lines

Thanks,
Miquèl

#5 lore raw

Re: [PATCH 1/5] i3c: master: svc: enable hotjoin default

Hello,

Quoted 9 lines · Frank Li
Quoted 8 lines · Miquel Raynal

Hi Frank,

[email protected] wrote on Mon, 16 Oct 2023 11:46:28 -0400:

Quoted 3 lines

Hotjoin require clock running and enable SLVSTART irq.
Add module parameter 'hotjoin' to disable hotjoin and enable runtime_pm to save power.

Quoted 9 lines
Quoted 2 lines

I am really not a big fan of the use of modules parameters. Maybe it makes sense here. Alex, a better idea?

Maybe we can create sys entry to enable/disable hotjoin. I think i3c should default support hotjoin, but it exist user case that needn't hj and want more aggressive power saving.

If create /sys/ entry, it need change driver/i3c/master.c.

If this can be changed dynamically, I guess ideally, we should be able to set it independently per controller so it could be disabled on a bus but kept enabled on others.

Signature · 3 lines
Alexandre Belloni, co-owner and COO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
author maintainer
#6 lore raw

PATCH 2/5 i3c: add actual in i3c_priv_xfer

In reply to Frank Li

In MIPI I3C Specification:

"Ninth Bit of SDR Target Returned (Read) Data as End-of-Data: In I2C, the ninth Data bit from Target to Controller is an ACK by the Controller. By contrast, in I3C this bit allows the Target to end a Read, and allows the Controller to Abort a Read. In SDR terms, the ninth bit of Read data is referred to as the T-Bit (for ‘Transition’)"

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

---
 include/linux/i3c/device.h | 1 +
 1 file changed, 1 insertion(+)
include/linux/i3c/device.h +1 -0
index 90fa83464f00..f2fa7ee5d96d 100644
@@ -66,6 +66,7 @@ struct i3c_priv_xfer {
 		void *in;
 		const void *out;
 	} data;
+	u16 actual;
 	enum i3c_error_code err;
 };
 
Signature · 1 line
2.34.1
#7 lore raw

Re: [PATCH 2/5] i3c: add actual in i3c_priv_xfer

Hi

Quoted 21 lines · Frank Li

In MIPI I3C Specification:

"Ninth Bit of SDR Target Returned (Read) Data as End-of-Data: In I2C, the ninth Data bit from Target to Controller is an ACK by the Controller. By contrast, in I3C this bit allows the Target to end a Read, and allows the Controller to Abort a Read. In SDR terms, the ninth bit of Read data is referred to as the T-Bit (for ‘Transition’)"

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

---
  include/linux/i3c/device.h | 1 +
  1 file changed, 1 insertion(+)
include/linux/i3c/device.h +0 -0
index 90fa83464f00..f2fa7ee5d96d 100644

include/linux/i3c/device.h struct i3c_priv_xfer { · line 72

Quoted 7 lines
include/linux/i3c/device.h +1 -0
@@ -66,6 +66,7 @@ struct i3c_priv_xfer {
  		void *in;
  		const void *out;
  	} data;
+	u16 actual;
  	enum i3c_error_code err;
  };
 

Would this be more clear if named as "actual_len" and put next after "len" field in this structure? Also kerneldoc comment is missing.

author maintainer
#8 lore raw

PATCH 3/5 i3c: svc: rename read_len as actual_len

In reply to Frank Li

I3C transfer, target can early terminate transfer. I2C transfer, target can NACK write transfer.

'actual_len' is better name than 'read_len'.

---
 drivers/i3c/master/svc-i3c-master.c | 26 +++++++++++++-------------
 1 file changed, 13 insertions(+), 13 deletions(-)
drivers/i3c/master/svc-i3c-master.c +13 -13
index f0d99b029e5f..3570b709cf60 100644
@@ -137,7 +137,7 @@ struct svc_i3c_cmd {
 	u8 *in;
 	const void *out;
 	unsigned int len;
-	unsigned int read_len;
+	unsigned int actual_len;
 	bool continued;
 };
 
@@ -1022,7 +1022,7 @@ static int svc_i3c_master_write(struct svc_i3c_master *master,
 static int svc_i3c_master_xfer(struct svc_i3c_master *master,
 			       bool rnw, unsigned int xfer_type, u8 addr,
 			       u8 *in, const u8 *out, unsigned int xfer_len,
-			       unsigned int *read_len, bool continued)
+			       unsigned int *actual_len, bool continued)
 {
 	u32 reg;
 	int ret;
@@ -1035,7 +1035,7 @@ static int svc_i3c_master_xfer(struct svc_i3c_master *master,
 	       SVC_I3C_MCTRL_IBIRESP_NACK |
 	       SVC_I3C_MCTRL_DIR(rnw) |
 	       SVC_I3C_MCTRL_ADDR(addr) |
-	       SVC_I3C_MCTRL_RDTERM(*read_len),
+	       SVC_I3C_MCTRL_RDTERM(*actual_len),
 	       master->regs + SVC_I3C_MCTRL);
 
 	ret = readl_poll_timeout(master->regs + SVC_I3C_MSTATUS, reg,
@@ -1073,7 +1073,7 @@ static int svc_i3c_master_xfer(struct svc_i3c_master *master,
 		goto emit_stop;
 
 	if (rnw)
-		*read_len = ret;
+		*actual_len = ret;
 
 	ret = readl_poll_timeout(master->regs + SVC_I3C_MSTATUS, reg,
 				 SVC_I3C_MSTATUS_COMPLETE(reg), 0, 1000);
@@ -1155,7 +1155,7 @@ static void svc_i3c_master_start_xfer_locked(struct svc_i3c_master *master)
 
 		ret = svc_i3c_master_xfer(master, cmd->rnw, xfer->type,
 					  cmd->addr, cmd->in, cmd->out,
-					  cmd->len, &cmd->read_len,
+					  cmd->len, &cmd->actual_len,
 					  cmd->continued);
 		if (ret)
 			break;
@@ -1241,7 +1241,7 @@ static int svc_i3c_master_send_bdcast_ccc_cmd(struct svc_i3c_master *master,
 	cmd->in = NULL;
 	cmd->out = buf;
 	cmd->len = xfer_len;
-	cmd->read_len = 0;
+	cmd->actual_len = 0;
 	cmd->continued = false;
 
 	mutex_lock(&master->lock);
@@ -1261,7 +1261,7 @@ static int svc_i3c_master_send_direct_ccc_cmd(struct svc_i3c_master *master,
 					      struct i3c_ccc_cmd *ccc)
 {
 	unsigned int xfer_len = ccc->dests[0].payload.len;
-	unsigned int read_len = ccc->rnw ? xfer_len : 0;
+	unsigned int actual_len = ccc->rnw ? xfer_len : 0;
 	struct svc_i3c_xfer *xfer;
 	struct svc_i3c_cmd *cmd;
 	int ret;
@@ -1279,7 +1279,7 @@ static int svc_i3c_master_send_direct_ccc_cmd(struct svc_i3c_master *master,
 	cmd->in = NULL;
 	cmd->out = &ccc->id;
 	cmd->len = 1;
-	cmd->read_len = 0;
+	cmd->actual_len = 0;
 	cmd->continued = true;
 
 	/* Directed message */
@@ -1289,7 +1289,7 @@ static int svc_i3c_master_send_direct_ccc_cmd(struct svc_i3c_master *master,
 	cmd->in = ccc->rnw ? ccc->dests[0].payload.data : NULL;
 	cmd->out = ccc->rnw ? NULL : ccc->dests[0].payload.data,
 	cmd->len = xfer_len;
-	cmd->read_len = read_len;
+	cmd->actual_len = actual_len;
 	cmd->continued = false;
 
 	mutex_lock(&master->lock);
@@ -1298,8 +1298,8 @@ static int svc_i3c_master_send_direct_ccc_cmd(struct svc_i3c_master *master,
 		svc_i3c_master_dequeue_xfer(master, xfer);
 	mutex_unlock(&master->lock);
 
-	if (cmd->read_len != xfer_len)
-		ccc->dests[0].payload.len = cmd->read_len;
+	if (cmd->actual_len != xfer_len)
+		ccc->dests[0].payload.len = cmd->actual_len;
 
 	ret = xfer->ret;
 	svc_i3c_master_free_xfer(xfer);
@@ -1349,7 +1349,7 @@ static int svc_i3c_master_priv_xfers(struct i3c_dev_desc *dev,
 		cmd->in = xfers[i].rnw ? xfers[i].data.in : NULL;
 		cmd->out = xfers[i].rnw ? NULL : xfers[i].data.out;
 		cmd->len = xfers[i].len;
-		cmd->read_len = xfers[i].rnw ? xfers[i].len : 0;
+		cmd->actual_len = xfers[i].rnw ? xfers[i].len : 0;
 		cmd->continued = (i + 1) < nxfers;
 	}
 
@@ -1389,7 +1389,7 @@ static int svc_i3c_master_i2c_xfers(struct i2c_dev_desc *dev,
 		cmd->in = cmd->rnw ? xfers[i].buf : NULL;
 		cmd->out = cmd->rnw ? NULL : xfers[i].buf;
 		cmd->len = xfers[i].len;
-		cmd->read_len = cmd->rnw ? xfers[i].len : 0;
+		cmd->actual_len = cmd->rnw ? xfers[i].len : 0;
 		cmd->continued = (i + 1 < nxfers);
 	}
 
Signature · 1 line
2.34.1
maintainer Reviewed-by on v1 3/5
#9 lore raw

Re: [PATCH 3/5] i3c: svc: rename read_len as actual_len

Hi Frank,

[email protected] wrote on Mon, 16 Oct 2023 11:46:30 -0400:

Quoted 4 lines

I3C transfer, target can early terminate transfer. I2C transfer, target can NACK write transfer.

'actual_len' is better name than 'read_len'.

I don't find read_len confusing because it may mean "how much bytes were actually read" rather than "how much we need to read". But if actual_len sounds better, I'm fine.

Quoted 2 lines

Thanks,
Miquèl

author maintainer
#10 lore raw

Re: [PATCH 3/5] i3c: svc: rename read_len as actual_len

Quoted 4 lines · Miquel Raynal

Hi Frank,

[email protected] wrote on Mon, 16 Oct 2023 11:46:30 -0400:

Quoted 8 lines
Quoted 4 lines

I3C transfer, target can early terminate transfer. I2C transfer, target can NACK write transfer.

'actual_len' is better name than 'read_len'.

I don't find read_len confusing because it may mean "how much bytes were actually read" rather than "how much we need to read". But if actual_len sounds better, I'm fine.

Another reason: According to i3c spec. 5.2.2.3.6 line 6090. Target ends or continues the write transfer.

in HDR mode, target can end write transfer. So use 'actual_len'

Do you think I need add it to commit message

Frank

Quoted 8 lines
Quoted 2 lines

Thanks,
Miquèl

author maintainer
#11 lore raw

PATCH 4/5 i3c: master: svc return actual transfer data len

In reply to Frank Li

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

---
 drivers/i3c/master/svc-i3c-master.c | 7 +++++++
 1 file changed, 7 insertions(+)
drivers/i3c/master/svc-i3c-master.c +7 -0
index 3570b709cf60..444825aafa6f 100644
@@ -138,6 +138,7 @@ struct svc_i3c_cmd {
 	const void *out;
 	unsigned int len;
 	unsigned int actual_len;
+	struct i3c_priv_xfer *xfer;
 	bool continued;
 };
 
@@ -1045,6 +1046,7 @@ static int svc_i3c_master_xfer(struct svc_i3c_master *master,
 
 	if (readl(master->regs + SVC_I3C_MERRWARN) & SVC_I3C_MERRWARN_NACK) {
 		ret = -ENXIO;
+		*actual_len = 0;
 		goto emit_stop;
 	}
 
@@ -1062,6 +1064,7 @@ static int svc_i3c_master_xfer(struct svc_i3c_master *master,
 	 */
 	if (SVC_I3C_MSTATUS_IBIWON(reg)) {
 		ret = -ENXIO;
+		*actual_len = 0;
 		goto emit_stop;
 	}
 
@@ -1157,6 +1160,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;
 	}
@@ -1344,6 +1350,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;
Signature · 1 line
2.34.1
#12 lore raw

Re: [PATCH 4/5] i3c: master: svc return actual transfer data len

Hi

Quoted 13 lines · Frank Li

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

---
  drivers/i3c/master/svc-i3c-master.c | 7 +++++++
  1 file changed, 7 insertions(+)
drivers/i3c/master/svc-i3c-master.c +0 -0
index 3570b709cf60..444825aafa6f 100644

drivers/i3c/master/svc-i3c-master.c struct svc_i3c_cmd { · line 144

Quoted 7 lines
drivers/i3c/master/svc-i3c-master.c +1 -0
@@ -138,6 +138,7 @@ struct svc_i3c_cmd {
  	const void *out;
  	unsigned int len;
  	unsigned int actual_len;
+	struct i3c_priv_xfer *xfer;
  	bool continued;
  };
 

I'm thinking would it make sense to combine this and previous patch by removing the read_len/actual_len variable from this structure and use the added one (by the patch 2/5) from "struct i3c_priv_xfer" directly?

author maintainer
#13 lore raw

Re: [PATCH 4/5] i3c: master: svc return actual transfer data len

Quoted 11 lines · Jarkko Nikula

Hi

Quoted 8 lines · Frank Li

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

---
  drivers/i3c/master/svc-i3c-master.c | 7 +++++++
  1 file changed, 7 insertions(+)
Quoted 14 lines

drivers/i3c/master/svc-i3c-master.c struct svc_i3c_cmd { · line 143

Quoted 11 lines
drivers/i3c/master/svc-i3c-master.c +1 -0
index 3570b709cf60..444825aafa6f 100644
@@ -138,6 +138,7 @@ struct svc_i3c_cmd {
  	const void *out;
  	unsigned int len;
  	unsigned int actual_len;
+	struct i3c_priv_xfer *xfer;
  	bool continued;
  };

I'm thinking would it make sense to combine this and previous patch by removing the read_len/actual_len variable from this structure and use the added one (by the patch 2/5) from "struct i3c_priv_xfer" directly?

Some I2C transfer and CCC use svc_i3c_cmd, in such case xfer is NULL. Keep len/actual_len is more simple.

Frank

maintainer
#14 lore raw

Re: [PATCH 4/5] i3c: master: svc return actual transfer data len

In reply to Frank Li

Hi Frank,

[email protected] wrote on Mon, 16 Oct 2023 11:46:31 -0400:

Quoted 37 lines

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

---
 drivers/i3c/master/svc-i3c-master.c | 7 +++++++
 1 file changed, 7 insertions(+)
drivers/i3c/master/svc-i3c-master.c +3 -0
index 3570b709cf60..444825aafa6f 100644
@@ -138,6 +138,7 @@ struct svc_i3c_cmd {
 	const void *out;
 	unsigned int len;
 	unsigned int actual_len;
+	struct i3c_priv_xfer *xfer;
 	bool continued;
 };
 
@@ -1045,6 +1046,7 @@ static int svc_i3c_master_xfer(struct svc_i3c_master *master,
 
 	if (readl(master->regs + SVC_I3C_MERRWARN) & SVC_I3C_MERRWARN_NACK) {
 		ret = -ENXIO;
+		*actual_len = 0;
 		goto emit_stop;
 	}
 
@@ -1062,6 +1064,7 @@ static int svc_i3c_master_xfer(struct svc_i3c_master *master,
 	 */
 	if (SVC_I3C_MSTATUS_IBIWON(reg)) {
 		ret = -ENXIO;
+		*actual_len = 0;
 		goto emit_stop;
 	}
 

drivers/i3c/master/svc-i3c-master.c static void svc_i3c_master_start_xfer_locked(struct svc_i3c_master *master) · line 1164

Quoted 5 lines
drivers/i3c/master/svc-i3c-master.c +2 -0
@@ -1157,6 +1160,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;

Just to be sure, wouldn't it be more natural to always fill cmd->xfer rather than checking it here?

drivers/i3c/master/svc-i3c-master.c static int svc_i3c_master_priv_xfers(struct i3c_dev_desc *dev, · line 1353

Quoted 9 lines
drivers/i3c/master/svc-i3c-master.c +2 -0
+
 		if (ret)
 			break;
 	}
@@ -1344,6 +1350,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;

Please follow the same pattern as below: = &xfers[i]

drivers/i3c/master/svc-i3c-master.c static int svc_i3c_master_priv_xfers(struct i3c_dev_desc *dev, · line 1356

Quoted 3 lines
drivers/i3c/master/svc-i3c-master.c +0 -0
 		cmd->addr = master->addrs[data->index];
 		cmd->rnw = xfers[i].rnw;
 		cmd->in = xfers[i].rnw ? xfers[i].data.in : NULL;

Thanks,
Miquèl

author maintainer
#15 lore raw

Re: [PATCH 4/5] i3c: master: svc return actual transfer data len

Quoted 40 lines · Miquel Raynal

Hi Frank,

[email protected] wrote on Mon, 16 Oct 2023 11:46:31 -0400:

Quoted 36 lines

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

---
 drivers/i3c/master/svc-i3c-master.c | 7 +++++++
 1 file changed, 7 insertions(+)
drivers/i3c/master/svc-i3c-master.c +3 -0
index 3570b709cf60..444825aafa6f 100644
@@ -138,6 +138,7 @@ struct svc_i3c_cmd {
 	const void *out;
 	unsigned int len;
 	unsigned int actual_len;
+	struct i3c_priv_xfer *xfer;
 	bool continued;
 };
 
@@ -1045,6 +1046,7 @@ static int svc_i3c_master_xfer(struct svc_i3c_master *master,
 
 	if (readl(master->regs + SVC_I3C_MERRWARN) & SVC_I3C_MERRWARN_NACK) {
 		ret = -ENXIO;
+		*actual_len = 0;
 		goto emit_stop;
 	}
 
@@ -1062,6 +1064,7 @@ static int svc_i3c_master_xfer(struct svc_i3c_master *master,
 	 */
 	if (SVC_I3C_MSTATUS_IBIWON(reg)) {
 		ret = -ENXIO;
+		*actual_len = 0;
 		goto emit_stop;
 	}
 
Quoted 9 lines

drivers/i3c/master/svc-i3c-master.c static void svc_i3c_master_start_xfer_locked(struct svc_i3c_master *master) · line 1164

Quoted 6 lines
drivers/i3c/master/svc-i3c-master.c +2 -0
@@ -1157,6 +1160,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;

Just to be sure, wouldn't it be more natural to always fill cmd->xfer rather than checking it here?

cmd->xfer is NULL for i2c and ccc transfer. So need check it. I will add comments here

Frank

Quoted 20 lines

drivers/i3c/master/svc-i3c-master.c static int svc_i3c_master_priv_xfers(struct i3c_dev_desc *dev, · line 1353

Quoted 10 lines
drivers/i3c/master/svc-i3c-master.c +2 -0
+
 		if (ret)
 			break;
 	}
@@ -1344,6 +1350,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;

Please follow the same pattern as below: = &xfers[i]

drivers/i3c/master/svc-i3c-master.c static int svc_i3c_master_priv_xfers(struct i3c_dev_desc *dev, · line 1356

Quoted 3 lines
drivers/i3c/master/svc-i3c-master.c +0 -0
 		cmd->addr = master->addrs[data->index];
 		cmd->rnw = xfers[i].rnw;
 		cmd->in = xfers[i].rnw ? xfers[i].data.in : NULL;

Thanks,
Miquèl

author maintainer
#16 lore raw

PATCH 5/5 i3c: add API i3c_dev_gettstatus_format1() to get target device status

In reply to Frank Li

I3C standard 5.1.9.3.15 Get Device Status (GETSTATUS):
Get request for one I3C Target Device to return its current status.

Add API to fetch it with format1.

---
 drivers/i3c/device.c       | 24 ++++++++++++++++++++++++
 drivers/i3c/internals.h    |  1 +
 drivers/i3c/master.c       | 27 +++++++++++++++++++++++++++
 include/linux/i3c/device.h |  1 +
 4 files changed, 53 insertions(+)
drivers/i3c/device.c +24 -0
index 1a6a8703dbc3..0566ab9f1498 100644
@@ -196,6 +196,30 @@ void i3c_device_free_ibi(struct i3c_device *dev)
 }
 EXPORT_SYMBOL_GPL(i3c_device_free_ibi);
 
+/**
+ * i3c_device_getstatus_format1() - Get device status with format 1.
+ * @dev: device for which you want to get status.
+ * @status: I3C status format 1
+ *
+ * Return: 0 in case of success, a negative error core otherwise.
+ */
+int i3c_device_getstatus_format1(struct i3c_device *dev, u16 *status)
+{
+	int ret = -EINVAL;
+
+	if (!status)
+		return -EINVAL;
+
+	i3c_bus_normaluse_lock(dev->bus);
+	if (dev->desc) {
+		ret = i3c_dev_getstatus_format1_locked(dev->desc, status);
+	}
+	i3c_bus_normaluse_unlock(dev->bus);
+
+	return ret;
+}
+EXPORT_SYMBOL_GPL(i3c_device_getstatus_format1);
+
 /**
  * i3cdev_to_dev() - Returns the device embedded in @i3cdev
  * @i3cdev: I3C device
drivers/i3c/internals.h +1 -0
index 908a807badaf..976ad26ca79c 100644
@@ -24,4 +24,5 @@ int i3c_dev_enable_ibi_locked(struct i3c_dev_desc *dev);
 int i3c_dev_request_ibi_locked(struct i3c_dev_desc *dev,
 			       const struct i3c_ibi_setup *req);
 void i3c_dev_free_ibi_locked(struct i3c_dev_desc *dev);
+int i3c_dev_getstatus_format1_locked(struct i3c_dev_desc *dev, u16 *status);
 #endif /* I3C_INTERNAL_H */
drivers/i3c/master.c +27 -0
index 08aeb69a7800..fa831721f305 100644
@@ -2840,6 +2840,33 @@ void i3c_dev_free_ibi_locked(struct i3c_dev_desc *dev)
 	dev->ibi = NULL;
 }
 
+int i3c_dev_getstatus_format1_locked(struct i3c_dev_desc *dev, u16 *status)
+{
+	struct i3c_master_controller *master = i3c_dev_get_master(dev);
+	struct i3c_ccc_getstatus *format1;
+	struct i3c_ccc_cmd_dest dest;
+	struct i3c_ccc_cmd cmd;
+	int ret;
+
+	format1 = i3c_ccc_cmd_dest_init(&dest, dev->info.dyn_addr,
+					  sizeof(*format1));
+	if (!format1)
+		return -ENOMEM;
+
+	i3c_ccc_cmd_init(&cmd, true, I3C_CCC_GETSTATUS, &dest, 1);
+
+	ret = i3c_master_send_ccc_cmd_locked(master, &cmd);
+	if (ret)
+		goto out;
+
+	*status = be16_to_cpu(format1->status);
+
+out:
+	i3c_ccc_cmd_dest_cleanup(&dest);
+
+	return ret;
+}
+
 static int __init i3c_init(void)
 {
 	int res;
include/linux/i3c/device.h +1 -0
index f2fa7ee5d96d..212cdcd17179 100644
@@ -344,4 +344,5 @@ void i3c_device_free_ibi(struct i3c_device *dev);
 int i3c_device_enable_ibi(struct i3c_device *dev);
 int i3c_device_disable_ibi(struct i3c_device *dev);
 
+int i3c_device_getstatus_format1(struct i3c_device *dev, u16 *status);
 #endif /* I3C_DEV_H */
Signature · 1 line
2.34.1