Skip to contentSkip to conversation

Fallback mechanism for GETMXDS CCC

PATCH Superseded Joshua Yeong 2 participants 4 messages Sep 11, 2023 – Sep 13, 2023 I3C

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

cover Fallback mechanism for GETMXDS CCC

Some I3C hardware will report error when incorrect length is received from device. GETMXDS CCC are availble in 2 formats; without turnaround time (format
1) and with turnaround time (format 2). There is no mechanics to determine which format is supported by device. In case sending GETMXDS CCC format 2 resulted failure, try sending GETMXDS CCC format 1 instead.

Joshua Yeong (1):
i3c: Add fallback method for GETMXDS CCC

 drivers/i3c/master.c    | 33 ++++++++++++++++++++++++++++-----
 include/linux/i3c/ccc.h | 17 +++++++++++++++--
 2 files changed, 43 insertions(+), 7 deletions(-)

--
2.25.1

Signature · 3 lines
linux-i3c mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-i3c
#1 lore raw

PATCH 1/1 i3c: Add fallback method for GETMXDS CCC

Some I3C hardware will report error when incorrect length is received from device. GETMXDS CCC are availble in 2 formats; without turnaround time (format
1) and with turnaround time (format 2). There is no mechanics to determine which format is supported by device. In case sending GETMXDS CCC format 2 resulted failure, try sending GETMXDS CCC format 1 instead.

---
 drivers/i3c/master.c    | 33 ++++++++++++++++++++++++++++-----
 include/linux/i3c/ccc.h | 17 +++++++++++++++--
 2 files changed, 43 insertions(+), 7 deletions(-)
drivers/i3c/master.c +28 -5
index 87283e4a4607..084f64bef155 100644
@@ -1088,10 +1088,37 @@ static int i3c_master_getmxds_locked(struct i3c_master_controller *master,
 				     struct i3c_device_info *info)
 {
 	struct i3c_ccc_getmxds *getmaxds;
+	struct i3c_ccc_getmxds_turnaround *getmaxds_ta;
 	struct i3c_ccc_cmd_dest dest;
 	struct i3c_ccc_cmd cmd;
 	int ret;
 
+	getmaxds_ta = i3c_ccc_cmd_dest_init(&dest, info->dyn_addr,
+					 sizeof(*getmaxds_ta));
+	if (!getmaxds_ta)
+		return -ENOMEM;
+
+	i3c_ccc_cmd_init(&cmd, true, I3C_CCC_GETMXDS, &dest, 1);
+	ret = i3c_master_send_ccc_cmd_locked(master, &cmd);
+	if (ret) {
+		goto alternative;
+	}
+
+	if (dest.payload.len != 2 && dest.payload.len != 5) {
+		ret = -EIO;
+		goto out;
+	}
+
+	info->max_read_ds = getmaxds_ta->maxrd;
+	info->max_write_ds = getmaxds_ta->maxwr;
+	if (dest.payload.len == 5)
+		info->max_read_turnaround = getmaxds_ta->maxrdturn[0] |
+					    ((u32)getmaxds_ta->maxrdturn[1] << 8) |
+					    ((u32)getmaxds_ta->maxrdturn[2] << 16);
+
+alternative:
+	i3c_ccc_cmd_dest_cleanup(&dest);
+
 	getmaxds = i3c_ccc_cmd_dest_init(&dest, info->dyn_addr,
 					 sizeof(*getmaxds));
 	if (!getmaxds)
@@ -1102,17 +1129,13 @@ static int i3c_master_getmxds_locked(struct i3c_master_controller *master,
 	if (ret)
 		goto out;
 
-	if (dest.payload.len != 2 && dest.payload.len != 5) {
+	if (dest.payload.len != 2) {
 		ret = -EIO;
 		goto out;
 	}
 
 	info->max_read_ds = getmaxds->maxrd;
 	info->max_write_ds = getmaxds->maxwr;
-	if (dest.payload.len == 5)
-		info->max_read_turnaround = getmaxds->maxrdturn[0] |
-					    ((u32)getmaxds->maxrdturn[1] << 8) |
-					    ((u32)getmaxds->maxrdturn[2] << 16);
 
 out:
 	i3c_ccc_cmd_dest_cleanup(&dest);
include/linux/i3c/ccc.h +15 -2
index ad59a4ae60d1..50ed41d4d5a1 100644
@@ -269,14 +269,27 @@ enum i3c_tsco {
 #define I3C_CCC_MAX_SDR_FSCL(x)		((x) & I3C_CCC_MAX_SDR_FSCL_MASK)
 
 /**
- * struct i3c_ccc_getmxds - payload passed to GETMXDS CCC
+ * struct i3c_ccc_getmxds - payload passed to GETMXDS CCC without turnaround
+ * (format 1)
+ *
+ * @maxwr: write limitations
+ * @maxrd: read limitations
+ */
+struct i3c_ccc_getmxds {
+	u8 maxwr;
+	u8 maxrd;
+} __packed;
+
+/**
+ * struct i3c_ccc_getmxds_ta - payload passed to GETMXDS CCC with turnaround
+ * (format 2)
  *
  * @maxwr: write limitations
  * @maxrd: read limitations
  * @maxrdturn: maximum read turn-around expressed micro-seconds and
  *	       little-endian formatted
  */
-struct i3c_ccc_getmxds {
+struct i3c_ccc_getmxds_turnaround {
 	u8 maxwr;
 	u8 maxrd;
 	u8 maxrdturn[3];
Signature · 7 lines
2.25.1


-- 
linux-i3c mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-i3c
#2 lore raw

Re: [PATCH 1/1] i3c: Add fallback method for GETMXDS CCC

Hi Joshua,

[email protected] wrote on Mon, 11 Sep 2023 16:24:56 +0800:

Quoted 27 lines

Some I3C hardware will report error when incorrect length is received from device. GETMXDS CCC are availble in 2 formats; without turnaround time (format
1) and with turnaround time (format 2). There is no mechanics to determine which format is supported by device. In case sending GETMXDS CCC format 2 resulted failure, try sending GETMXDS CCC format 1 instead.

---
 drivers/i3c/master.c    | 33 ++++++++++++++++++++++++++++-----
 include/linux/i3c/ccc.h | 17 +++++++++++++++--
 2 files changed, 43 insertions(+), 7 deletions(-)
drivers/i3c/master.c +3 -0
index 87283e4a4607..084f64bef155 100644
@@ -1088,10 +1088,37 @@ static int i3c_master_getmxds_locked(struct i3c_master_controller *master,
 				     struct i3c_device_info *info)
 {
 	struct i3c_ccc_getmxds *getmaxds;
+	struct i3c_ccc_getmxds_turnaround *getmaxds_ta;
 	struct i3c_ccc_cmd_dest dest;
 	struct i3c_ccc_cmd cmd;
 	int ret;
 
+	getmaxds_ta = i3c_ccc_cmd_dest_init(&dest, info->dyn_addr,
+					 sizeof(*getmaxds_ta));

drivers/i3c/master.c static int i3c_master_getmxds_locked(struct i3c_master_controller *master, · line 1107

Quoted 10 lines
drivers/i3c/master.c +10 -0
+	if (!getmaxds_ta)
+		return -ENOMEM;
+
+	i3c_ccc_cmd_init(&cmd, true, I3C_CCC_GETMXDS, &dest, 1);
+	ret = i3c_master_send_ccc_cmd_locked(master, &cmd);
+	if (ret) {
+		goto alternative;
+	}
+
+	if (dest.payload.len != 2 && dest.payload.len != 5) {

Can len be 2 here?

drivers/i3c/master.c static int i3c_master_getmxds_locked(struct i3c_master_controller *master, · line 1117

Quoted 10 lines
drivers/i3c/master.c +10 -0
+		ret = -EIO;
+		goto out;
+	}
+
+	info->max_read_ds = getmaxds_ta->maxrd;
+	info->max_write_ds = getmaxds_ta->maxwr;
+	if (dest.payload.len == 5)
+		info->max_read_turnaround = getmaxds_ta->maxrdturn[0] |
+					    ((u32)getmaxds_ta->maxrdturn[1] << 8) |
+					    ((u32)getmaxds_ta->maxrdturn[2] << 16);

Don't you want to avoid the "alternative" if it worked?

drivers/i3c/master.c static int i3c_master_getmxds_locked(struct i3c_master_controller *master, · line 1119

Quoted 2 lines
drivers/i3c/master.c +2 -0
+
+alternative:

I would expect a comment somewhere to explain the subtlety.

Quoted 48 lines
drivers/i3c/master.c +3 -5
+	i3c_ccc_cmd_dest_cleanup(&dest);
+
 	getmaxds = i3c_ccc_cmd_dest_init(&dest, info->dyn_addr,
 					 sizeof(*getmaxds));
 	if (!getmaxds)
@@ -1102,17 +1129,13 @@ static int i3c_master_getmxds_locked(struct i3c_master_controller *master,
 	if (ret)
 		goto out;
 
-	if (dest.payload.len != 2 && dest.payload.len != 5) {
+	if (dest.payload.len != 2) {
 		ret = -EIO;
 		goto out;
 	}
 
 	info->max_read_ds = getmaxds->maxrd;
 	info->max_write_ds = getmaxds->maxwr;
-	if (dest.payload.len == 5)
-		info->max_read_turnaround = getmaxds->maxrdturn[0] |
-					    ((u32)getmaxds->maxrdturn[1] << 8) |
-					    ((u32)getmaxds->maxrdturn[2] << 16);
 
 out:
 	i3c_ccc_cmd_dest_cleanup(&dest);
include/linux/i3c/ccc.h +14 -1
index ad59a4ae60d1..50ed41d4d5a1 100644
@@ -269,14 +269,27 @@ enum i3c_tsco {
 #define I3C_CCC_MAX_SDR_FSCL(x)		((x) & I3C_CCC_MAX_SDR_FSCL_MASK)
 
 /**
- * struct i3c_ccc_getmxds - payload passed to GETMXDS CCC
+ * struct i3c_ccc_getmxds - payload passed to GETMXDS CCC without turnaround
+ * (format 1)
+ *
+ * @maxwr: write limitations
+ * @maxrd: read limitations
+ */
+struct i3c_ccc_getmxds {
+	u8 maxwr;
+	u8 maxrd;
+} __packed;
+
+/**
+ * struct i3c_ccc_getmxds_ta - payload passed to GETMXDS CCC with turnaround
+ * (format 2)
  *

include/linux/i3c/ccc.h enum i3c_tsco { · line 295

Quoted 10 lines
include/linux/i3c/ccc.h +1 -1
  * @maxwr: write limitations
  * @maxrd: read limitations
  * @maxrdturn: maximum read turn-around expressed micro-seconds and
  *	       little-endian formatted
  */
-struct i3c_ccc_getmxds {
+struct i3c_ccc_getmxds_turnaround {
 	u8 maxwr;
 	u8 maxrd;
 	u8 maxrdturn[3];

Thanks,
Miquèl

Signature · 3 lines
linux-i3c mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-i3c
#3 lore raw

Re: [PATCH 1/1] i3c: Add fallback method for GETMXDS CCC

Hi Miquel,

Quoted 29 lines · Miquel Raynal

Hi Joshua,

[email protected] wrote on Mon, 11 Sep 2023 16:24:56 +0800:

Quoted 25 lines

Some I3C hardware will report error when incorrect length is received from device. GETMXDS CCC are availble in 2 formats; without turnaround time (format
1) and with turnaround time (format 2). There is no mechanics to determine which format is supported by device. In case sending GETMXDS CCC format 2 resulted failure, try sending GETMXDS CCC format 1 instead.

---
  drivers/i3c/master.c    | 33 ++++++++++++++++++++++++++++-----
  include/linux/i3c/ccc.h | 17 +++++++++++++++--
  2 files changed, 43 insertions(+), 7 deletions(-)
drivers/i3c/master.c +1 -0
index 87283e4a4607..084f64bef155 100644
@@ -1088,10 +1088,37 @@ static int i3c_master_getmxds_locked(struct i3c_master_controller *master,
  				     struct i3c_device_info *info)
  {
  	struct i3c_ccc_getmxds *getmaxds;
+	struct i3c_ccc_getmxds_turnaround *getmaxds_ta;
  	struct i3c_ccc_cmd_dest dest;
  	struct i3c_ccc_cmd cmd;
  	int ret;
 
Quoted 13 lines

drivers/i3c/master.c static int i3c_master_getmxds_locked(struct i3c_master_controller *master, · line 1107

Quoted 12 lines
drivers/i3c/master.c +12 -0
+	getmaxds_ta = i3c_ccc_cmd_dest_init(&dest, info->dyn_addr,
+					 sizeof(*getmaxds_ta));
+	if (!getmaxds_ta)
+		return -ENOMEM;
+
+	i3c_ccc_cmd_init(&cmd, true, I3C_CCC_GETMXDS, &dest, 1);
+	ret = i3c_master_send_ccc_cmd_locked(master, &cmd);
+	if (ret) {
+		goto alternative;
+	}
+
+	if (dest.payload.len != 2 && dest.payload.len != 5) {

Can len be 2 here?

I do not know if other IP allows lower payload length. The Cadence IP will trigger an error in case the GET CCC length is mismatch. May need Vitor/Conor to confirm this behavior in Synopsys/Silvaco.

Quoted 11 lines

drivers/i3c/master.c static int i3c_master_getmxds_locked(struct i3c_master_controller *master, · line 1117

Quoted 10 lines
drivers/i3c/master.c +10 -0
+		ret = -EIO;
+		goto out;
+	}
+
+	info->max_read_ds = getmaxds_ta->maxrd;
+	info->max_write_ds = getmaxds_ta->maxwr;
+	if (dest.payload.len == 5)
+		info->max_read_turnaround = getmaxds_ta->maxrdturn[0] |
+					    ((u32)getmaxds_ta->maxrdturn[1] << 8) |
+					    ((u32)getmaxds_ta->maxrdturn[2] << 16);

Don't you want to avoid the "alternative" if it worked?

Thank you, will fix this.

Quoted 4 lines

drivers/i3c/master.c static int i3c_master_getmxds_locked(struct i3c_master_controller *master, · line 1119

Quoted 3 lines
drivers/i3c/master.c +2 -0
+
+alternative:

I would expect a comment somewhere to explain the subtlety.

Will add comments to explain this code.

Quoted 62 lines
Quoted 49 lines
drivers/i3c/master.c +3 -5
+	i3c_ccc_cmd_dest_cleanup(&dest);
+
  	getmaxds = i3c_ccc_cmd_dest_init(&dest, info->dyn_addr,
  					 sizeof(*getmaxds));
  	if (!getmaxds)
@@ -1102,17 +1129,13 @@ static int i3c_master_getmxds_locked(struct i3c_master_controller *master,
  	if (ret)
  		goto out;
 
-	if (dest.payload.len != 2 && dest.payload.len != 5) {
+	if (dest.payload.len != 2) {
  		ret = -EIO;
  		goto out;
  	}
 
  	info->max_read_ds = getmaxds->maxrd;
  	info->max_write_ds = getmaxds->maxwr;
-	if (dest.payload.len == 5)
-		info->max_read_turnaround = getmaxds->maxrdturn[0] |
-					    ((u32)getmaxds->maxrdturn[1] << 8) |
-					    ((u32)getmaxds->maxrdturn[2] << 16);
 
  out:
  	i3c_ccc_cmd_dest_cleanup(&dest);
include/linux/i3c/ccc.h +14 -1
index ad59a4ae60d1..50ed41d4d5a1 100644
@@ -269,14 +269,27 @@ enum i3c_tsco {
  #define I3C_CCC_MAX_SDR_FSCL(x)		((x) & I3C_CCC_MAX_SDR_FSCL_MASK)
 
  /**
- * struct i3c_ccc_getmxds - payload passed to GETMXDS CCC
+ * struct i3c_ccc_getmxds - payload passed to GETMXDS CCC without turnaround
+ * (format 1)
+ *
+ * @maxwr: write limitations
+ * @maxrd: read limitations
+ */
+struct i3c_ccc_getmxds {
+	u8 maxwr;
+	u8 maxrd;
+} __packed;
+
+/**
+ * struct i3c_ccc_getmxds_ta - payload passed to GETMXDS CCC with turnaround
+ * (format 2)
   *

include/linux/i3c/ccc.h enum i3c_tsco { · line 295

Quoted 10 lines
include/linux/i3c/ccc.h +1 -1
   * @maxwr: write limitations
   * @maxrd: read limitations
   * @maxrdturn: maximum read turn-around expressed micro-seconds and
   *	       little-endian formatted
   */
-struct i3c_ccc_getmxds {
+struct i3c_ccc_getmxds_turnaround {
  	u8 maxwr;
  	u8 maxrd;
  	u8 maxrdturn[3];

Thanks,
Miquèl