Skip to contentSkip to conversation

hw/i3c/dw-i3c: Fix BCR/DCR extraction and PID assembly during ENTDAA

PATCH In review Ashish Anand 3 participants 4 messages May 5 – May 12 1 message not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): CGME20260505134412epcas5p1ccd2bd43c50ec651636847fa8c516072@epcas5p1.samsung.com

#1 lore raw

PATCH v2 1/1 hw/i3c/dw-i3c: Fix BCR/DCR extraction and PID assembly during ENTDAA

The target_info union in dw_i3c_addr_assign_cmd() declares pid, bcr, and dcr as separate union members, causing them to all alias b[0] rather than their correct positions in the ENTDAA response buffer. This results in dw_i3c_update_char_table() being called with BCR and DCR both read from b[0] instead of b[6] and b[7] respectively, corrupting the device characteristics table on every ENTDAA operation. Fix by replacing the broken members with uint64_t d and extracting fields per the I3C spec ENTDAA wire format.

Additionally, dw_i3c_update_char_table() incorrectly splits PID across LOC1 and LOC2 at bit 32. Per the Linux kernel HCI driver (drivers/i3c/master/mipi-i3c-hci/dct_v1.c), the DCT layout requires LOC1 to hold pid[47:16] and LOC2 to hold pid[15:0]. Fix the split accordingly.

---

Changes from v1 :
1. Replaced broken union members with uint64_t d, added wire format comment.
2. Replaced loop with be64_to_cpu(target_info.d) >> 16.
3. Fixed LOC1/LOC2 split at bit 16 in dw_i3c_update_char_table.
4. Added comment to i3c.h clarifying how core.c transmits t->pid during ENTDAA.

Link to v1 - https://lore.kernel.org/qemu-devel/exdu52mug6fh3bwj7ofo3jlltyuwjfnddxobio4w3jhaq6uv7k@boxo3j5ocef2/T/#t

This bug was discovered during end-to-end ENTDAA testing where BCR and DCR values observed in the char table register did not match the target's actual BCR and DCR values.

 hw/i3c/dw-i3c.c      | 16 +++++++---------
 include/hw/i3c/i3c.h |  7 +++++++
 2 files changed, 14 insertions(+), 9 deletions(-)
hw/i3c/dw-i3c.c +7 -9
index d87d42be89..17ff484c5d 100644
@@ -1459,11 +1459,10 @@ static void dw_i3c_update_char_table(DWI3C *s, uint8_t offset, uint64_t pid,
                                           P_DEV_CHAR_TABLE_START_ADDR) /
                                           sizeof(uint32_t)) +
                                           (offset * sizeof(uint32_t));
-    s->regs[dev_index] = pid & 0xffffffff;
-    pid >>= 32;
+    s->regs[dev_index] = (pid >> 16) & 0xffffffff;
     s->regs[dev_index + 1] = FIELD_DP32(s->regs[dev_index + 1],
                                         DEVICE_CHARACTERISTIC_TABLE_LOC2,
-                                        MSB_PID, pid);
+                                        MSB_PID, pid & 0xffff);
     s->regs[dev_index + 2] = FIELD_DP32(s->regs[dev_index + 2],
                                         DEVICE_CHARACTERISTIC_TABLE_LOC3, DCR,
                                         dcr);
@@ -1507,10 +1506,9 @@ static void dw_i3c_addr_assign_cmd(DWI3C *s, DWI3CAddrAssignCmd cmd)
     for (i = 0; i < cmd.dev_count; i++) {
         uint8_t addr = dw_i3c_target_addr(s, cmd.dev_index + i);
         union {
-            uint64_t pid:48;
-            uint8_t bcr;
-            uint8_t dcr;
+            uint64_t d;
             uint32_t w[2];
+            /* Per I3C spec: b[0]=PID MSB, b[5]=PID LSB, b[6]=BCR, b[7]=DCR */
             uint8_t b[8];
         } target_info;
 
@@ -1544,9 +1542,9 @@ static void dw_i3c_addr_assign_cmd(DWI3C *s, DWI3CAddrAssignCmd cmd)
             err = DW_I3C_RESP_QUEUE_ERR_DAA_NACK;
             break;
         }
-        dw_i3c_update_char_table(s, cmd.dev_index + i,
-                                            target_info.pid, target_info.bcr,
-                                            target_info.dcr, addr);
+        uint64_t pid = be64_to_cpu(target_info.d) >> 16;
+        dw_i3c_update_char_table(s, cmd.dev_index + i, pid, target_info.b[6],
+                                 target_info.b[7], addr);
 
         /* Push the PID, BCR, and DCR to the RX queue. */
         dw_i3c_push_rx(s, target_info.w[0]);
include/hw/i3c/i3c.h +7 -0
index 6ba90793ad..dcf8d9b143 100644
@@ -138,6 +138,13 @@ struct I3CTarget {
     uint8_t static_address;
     uint8_t dcr;
     uint8_t bcr;
+    /*
+     * Provisioned ID. Since core.c sends this LSB-first during ENTDAA
+     * via (pid >> (offset * 8)) & 0xff, targets must store it
+     * pre-reversed so that pid[47:40] goes on the wire first, as
+     * required by the I3C spec.
+     *  e.g. for a device with pid 0xAABBCCDDEEFF, store 0xFFEEDDCCBBAA.
+     */
     uint64_t pid;
 
     /* CCC State tracking. */
Signature · 1 line
2.43.0
#2 lore raw

Jamin,

Does that look good ?

Thanks,

C.

Quoted 96 lines · Ashish Anand

The target_info union in dw_i3c_addr_assign_cmd() declares pid, bcr, and dcr as separate union members, causing them to all alias b[0] rather than their correct positions in the ENTDAA response buffer. This results in dw_i3c_update_char_table() being called with BCR and DCR both read from b[0] instead of b[6] and b[7] respectively, corrupting the device characteristics table on every ENTDAA operation. Fix by replacing the broken members with uint64_t d and extracting fields per the I3C spec ENTDAA wire format.

Additionally, dw_i3c_update_char_table() incorrectly splits PID across LOC1 and LOC2 at bit 32. Per the Linux kernel HCI driver (drivers/i3c/master/mipi-i3c-hci/dct_v1.c), the DCT layout requires LOC1 to hold pid[47:16] and LOC2 to hold pid[15:0]. Fix the split accordingly.

---

Changes from v1 :
1. Replaced broken union members with uint64_t d, added wire format comment.
2. Replaced loop with be64_to_cpu(target_info.d) >> 16.
3. Fixed LOC1/LOC2 split at bit 16 in dw_i3c_update_char_table.
4. Added comment to i3c.h clarifying how core.c transmits t->pid during ENTDAA.

Link to v1 - https://lore.kernel.org/qemu-devel/exdu52mug6fh3bwj7ofo3jlltyuwjfnddxobio4w3jhaq6uv7k@boxo3j5ocef2/T/#t

This bug was discovered during end-to-end ENTDAA testing where BCR and DCR values observed in the char table register did not match the target's actual BCR and DCR values.

  hw/i3c/dw-i3c.c      | 16 +++++++---------
  include/hw/i3c/i3c.h |  7 +++++++
  2 files changed, 14 insertions(+), 9 deletions(-)
hw/i3c/dw-i3c.c +7 -9
index d87d42be89..17ff484c5d 100644
@@ -1459,11 +1459,10 @@ static void dw_i3c_update_char_table(DWI3C *s, uint8_t offset, uint64_t pid,
                                            P_DEV_CHAR_TABLE_START_ADDR) /
                                            sizeof(uint32_t)) +
                                            (offset * sizeof(uint32_t));
-    s->regs[dev_index] = pid & 0xffffffff;
-    pid >>= 32;
+    s->regs[dev_index] = (pid >> 16) & 0xffffffff;
      s->regs[dev_index + 1] = FIELD_DP32(s->regs[dev_index + 1],
                                          DEVICE_CHARACTERISTIC_TABLE_LOC2,
-                                        MSB_PID, pid);
+                                        MSB_PID, pid & 0xffff);
      s->regs[dev_index + 2] = FIELD_DP32(s->regs[dev_index + 2],
                                          DEVICE_CHARACTERISTIC_TABLE_LOC3, DCR,
                                          dcr);
@@ -1507,10 +1506,9 @@ static void dw_i3c_addr_assign_cmd(DWI3C *s, DWI3CAddrAssignCmd cmd)
      for (i = 0; i < cmd.dev_count; i++) {
          uint8_t addr = dw_i3c_target_addr(s, cmd.dev_index + i);
          union {
-            uint64_t pid:48;
-            uint8_t bcr;
-            uint8_t dcr;
+            uint64_t d;
              uint32_t w[2];
+            /* Per I3C spec: b[0]=PID MSB, b[5]=PID LSB, b[6]=BCR, b[7]=DCR */
              uint8_t b[8];
          } target_info;
 
@@ -1544,9 +1542,9 @@ static void dw_i3c_addr_assign_cmd(DWI3C *s, DWI3CAddrAssignCmd cmd)
              err = DW_I3C_RESP_QUEUE_ERR_DAA_NACK;
              break;
          }
-        dw_i3c_update_char_table(s, cmd.dev_index + i,
-                                            target_info.pid, target_info.bcr,
-                                            target_info.dcr, addr);
+        uint64_t pid = be64_to_cpu(target_info.d) >> 16;
+        dw_i3c_update_char_table(s, cmd.dev_index + i, pid, target_info.b[6],
+                                 target_info.b[7], addr);
 
          /* Push the PID, BCR, and DCR to the RX queue. */
          dw_i3c_push_rx(s, target_info.w[0]);
include/hw/i3c/i3c.h +7 -0
index 6ba90793ad..dcf8d9b143 100644
@@ -138,6 +138,13 @@ struct I3CTarget {
      uint8_t static_address;
      uint8_t dcr;
      uint8_t bcr;
+    /*
+     * Provisioned ID. Since core.c sends this LSB-first during ENTDAA
+     * via (pid >> (offset * 8)) & 0xff, targets must store it
+     * pre-reversed so that pid[47:40] goes on the wire first, as
+     * required by the I3C spec.
+     *  e.g. for a device with pid 0xAABBCCDDEEFF, store 0xFFEEDDCCBBAA.
+     */
      uint64_t pid;
 
      /* CCC State tracking. */
#3 lore raw

Hi Cédric

Quoted 7 lines

Jamin,

Does that look good ?

Thanks,

Looks good to me.
Added review tag

Thanks,
Jamin

Quoted 114 lines

C.

Quoted 15 lines · Ashish Anand

The target_info union in dw_i3c_addr_assign_cmd() declares pid, bcr, and dcr as separate union members, causing them to all alias b[0] rather than their correct positions in the ENTDAA response buffer. This results in dw_i3c_update_char_table() being called with BCR and DCR both read from b[0] instead of b[6] and b[7] respectively, corrupting the device characteristics table on every ENTDAA operation. Fix by replacing the broken members with uint64_t d and extracting fields per the I3C spec ENTDAA wire format.

Additionally, dw_i3c_update_char_table() incorrectly splits PID across LOC1 and LOC2 at bit 32. Per the Linux kernel HCI driver (drivers/i3c/master/mipi-i3c-hci/dct_v1.c), the DCT layout requires LOC1 to hold pid[47:16] and LOC2 to hold pid[15:0]. Fix the split accordingly.

Quoted 5 lines

---

Changes from v1 :
1. Replaced broken union members with uint64_t d, added wire format

comment.

Quoted 3 lines

2. Replaced loop with be64_to_cpu(target_info.d) >> 16.
3. Fixed LOC1/LOC2 split at bit 16 in dw_i3c_update_char_table.
4. Added comment to i3c.h clarifying how core.c transmits t->pid during

ENTDAA.

hw/i3c/dw-i3c.c static void dw_i3c_update_char_table(DWI3C

Quoted 18 lines

Link to v1 -
https://lore.kernel.org/qemu-devel/exdu52mug6fh3bwj7ofo3jlltyuwjfnddxo
bio4w3jhaq6uv7k@boxo3j5ocef2/T/#t

This bug was discovered during end-to-end ENTDAA testing where BCR and DCR values observed in the char table register did not match the target's actual BCR and DCR values.

  hw/i3c/dw-i3c.c      | 16 +++++++---------
  include/hw/i3c/i3c.h |  7 +++++++
  2 files changed, 14 insertions(+), 9 deletions(-)
hw/i3c/dw-i3c.c index renamed from hw/i3c/dw-i3c.c +0 -0

d87d42be89..17ff484c5d 100644

hw/i3c/dw-i3c.c +0 -0
@@ -1459,11 +1459,10 @@ static void dw_i3c_update_char_table(DWI3C

*s, uint8_t offset, uint64_t pid,

Quoted 1 line

P_DEV_CHAR_TABLE_START_ADDR) /

Quoted 2 lines
                                            sizeof(uint32_t)) +
                                            (offset *

sizeof(uint32_t));

hw/i3c/dw-i3c.c static void dw_i3c_update_char_table(DWI3C *s, uint8_t offset, uint64_t pid, · line 1463

Quoted 5 lines
hw/i3c/dw-i3c.c +1 -2
-    s->regs[dev_index] = pid & 0xffffffff;
-    pid >>= 32;
+    s->regs[dev_index] = (pid >> 16) & 0xffffffff;
      s->regs[dev_index + 1] = FIELD_DP32(s->regs[dev_index + 1],

DEVICE_CHARACTERISTIC_TABLE_LOC2,

hw/i3c/dw-i3c.c static void dw_i3c_update_char_table(DWI3C *s, uint8_t offset, uint64_t pid, · line 1466

Quoted 4 lines
hw/i3c/dw-i3c.c +1 -1
-                                        MSB_PID, pid);
+                                        MSB_PID, pid & 0xffff);
      s->regs[dev_index + 2] = FIELD_DP32(s->regs[dev_index + 2],

DEVICE_CHARACTERISTIC_TABLE_LOC3, DCR,

Quoted 1 line
                                          dcr); @@ -1507,10

+1506,9 @@

hw/i3c/dw-i3c.c static void dw_i3c_addr_assign_cmd(DWI3C *s,

Quoted 15 lines

static void dw_i3c_addr_assign_cmd(DWI3C *s, DWI3CAddrAssignCmd cmd)

      for (i = 0; i < cmd.dev_count; i++) {
          uint8_t addr = dw_i3c_target_addr(s, cmd.dev_index + i);
          union {
hw/i3c/dw-i3c.c +3 -3
-            uint64_t pid:48;
-            uint8_t bcr;
-            uint8_t dcr;
+            uint64_t d;
              uint32_t w[2];
+            /* Per I3C spec: b[0]=PID MSB, b[5]=PID LSB, b[6]=BCR,
+ b[7]=DCR */
              uint8_t b[8];
          } target_info;
@@ -1544,9 +1542,9 @@ static void dw_i3c_addr_assign_cmd(DWI3C *s,

DWI3CAddrAssignCmd cmd)

hw/i3c/dw-i3c.c static void dw_i3c_addr_assign_cmd(DWI3C *s, DWI3CAddrAssignCmd cmd)

Quoted 5 lines
hw/i3c/dw-i3c.c +0 -2
              err = DW_I3C_RESP_QUEUE_ERR_DAA_NACK;
              break;
          }
-        dw_i3c_update_char_table(s, cmd.dev_index + i,
-                                            target_info.pid,

target_info.bcr,

hw/i3c/dw-i3c.c static void dw_i3c_addr_assign_cmd(DWI3C *s, DWI3CAddrAssignCmd cmd)

Quoted 3 lines
hw/i3c/dw-i3c.c +2 -1
-                                            target_info.dcr, addr);
+        uint64_t pid = be64_to_cpu(target_info.d) >> 16;
+        dw_i3c_update_char_table(s, cmd.dev_index + i, pid,

target_info.b[6],

Quoted 9 lines
hw/i3c/dw-i3c.c +1 -0
+                                 target_info.b[7], addr);
 
          /* Push the PID, BCR, and DCR to the RX queue. */
          dw_i3c_push_rx(s, target_info.w[0]); diff --git

a/include/hw/i3c/i3c.h b/include/hw/i3c/i3c.h index 6ba90793ad..dcf8d9b143 100644

include/hw/i3c/i3c.h struct I3CTarget { · line 146

Quoted 9 lines
include/hw/i3c/i3c.h +6 -0
@@ -138,6 +138,13 @@ struct I3CTarget {
      uint8_t static_address;
      uint8_t dcr;
      uint8_t bcr;
+    /*
+     * Provisioned ID. Since core.c sends this LSB-first during ENTDAA
+     * via (pid >> (offset * 8)) & 0xff, targets must store it
+     * pre-reversed so that pid[47:40] goes on the wire first, as
+     * required by the I3C spec.
+     *  e.g. for a device with pid 0xAABBCCDDEEFF, store

0xFFEEDDCCBBAA.

Quoted 4 lines
include/hw/i3c/i3c.h +1 -0
+     */
      uint64_t pid;
 
      /* CCC State tracking. */
Reviewed-by on v2 1/1
#4 lore raw
In reply to Ashish Anand

Hi Ashish

Quoted 109 lines

Subject: [PATCH v2] hw/i3c/dw-i3c: Fix BCR/DCR extraction and PID assembly during ENTDAA

The target_info union in dw_i3c_addr_assign_cmd() declares pid, bcr, and dcr as separate union members, causing them to all alias b[0] rather than their correct positions in the ENTDAA response buffer.
This results in dw_i3c_update_char_table() being called with BCR and DCR both read from b[0] instead of b[6] and b[7] respectively, corrupting the device characteristics table on every ENTDAA operation.
Fix by replacing the broken members with uint64_t d and extracting fields per the I3C spec ENTDAA wire format.

Additionally, dw_i3c_update_char_table() incorrectly splits PID across LOC1 and LOC2 at bit 32. Per the Linux kernel HCI driver (drivers/i3c/master/mipi-i3c-hci/dct_v1.c), the DCT layout requires LOC1 to hold pid[47:16] and LOC2 to hold pid[15:0]. Fix the split accordingly.

---

Changes from v1 :
1. Replaced broken union members with uint64_t d, added wire format comment.
2. Replaced loop with be64_to_cpu(target_info.d) >> 16.
3. Fixed LOC1/LOC2 split at bit 16 in dw_i3c_update_char_table.
4. Added comment to i3c.h clarifying how core.c transmits t->pid during ENTDAA.

Link to v1 -
https://lore.kernel.org/qemu-devel/exdu52mug6fh3bwj7ofo3jlltyuwjfnddxobio
4w3jhaq6uv7k@boxo3j5ocef2/T/#t

This bug was discovered during end-to-end ENTDAA testing where BCR and DCR values observed in the char table register did not match the target's actual BCR and DCR values.

 hw/i3c/dw-i3c.c      | 16 +++++++---------
 include/hw/i3c/i3c.h |  7 +++++++
 2 files changed, 14 insertions(+), 9 deletions(-)
hw/i3c/dw-i3c.c index d87d42be89..17ff484c5d renamed from hw/i3c/dw-i3c.c +0 -0

100644

hw/i3c/dw-i3c.c +0 -0
@@ -1459,11 +1459,10 @@ static void dw_i3c_update_char_table(DWI3C *s,
 uint8_t offset, uint64_t pid,
 

P_DEV_CHAR_TABLE_START_ADDR) /

                                           sizeof(uint32_t)) +
                                           (offset * sizeof(uint32_t));
hw/i3c/dw-i3c.c +1 -2
-    s->regs[dev_index] = pid & 0xffffffff;
-    pid >>= 32;
+    s->regs[dev_index] = (pid >> 16) & 0xffffffff;
     s->regs[dev_index + 1] = FIELD_DP32(s->regs[dev_index + 1],

DEVICE_CHARACTERISTIC_TABLE_LOC2,

hw/i3c/dw-i3c.c +1 -1
-                                        MSB_PID, pid);
+                                        MSB_PID, pid & 0xffff);
     s->regs[dev_index + 2] = FIELD_DP32(s->regs[dev_index + 2],

DEVICE_CHARACTERISTIC_TABLE_LOC3, DCR,

                                         dcr); @@ -1507,10 +1506,9
@@ static void dw_i3c_addr_assign_cmd(DWI3C *s, DWI3CAddrAssignCmd
cmd)
     for (i = 0; i < cmd.dev_count; i++) {
         uint8_t addr = dw_i3c_target_addr(s, cmd.dev_index + i);
         union {
hw/i3c/dw-i3c.c +6 -6
-            uint64_t pid:48;
-            uint8_t bcr;
-            uint8_t dcr;
+            uint64_t d;
             uint32_t w[2];
+            /* Per I3C spec: b[0]=PID MSB, b[5]=PID LSB, b[6]=BCR,
+ b[7]=DCR */
             uint8_t b[8];
         } target_info;
@@ -1544,9 +1542,9 @@ static void dw_i3c_addr_assign_cmd(DWI3C *s,
 DWI3CAddrAssignCmd cmd)
             err = DW_I3C_RESP_QUEUE_ERR_DAA_NACK;
             break;
         }
-        dw_i3c_update_char_table(s, cmd.dev_index + i,
-                                            target_info.pid,
 target_info.bcr,
-                                            target_info.dcr, addr);
+        uint64_t pid = be64_to_cpu(target_info.d) >> 16;
+        dw_i3c_update_char_table(s, cmd.dev_index + i, pid,
 target_info.b[6],
+                                 target_info.b[7], addr);
         /* Push the PID, BCR, and DCR to the RX queue. */
         dw_i3c_push_rx(s, target_info.w[0]); diff --git

a/include/hw/i3c/i3c.h b/include/hw/i3c/i3c.h index 6ba90793ad..dcf8d9b143 100644

include/hw/i3c/i3c.h +6 -0
@@ -138,6 +138,13 @@ struct I3CTarget {
     uint8_t static_address;
     uint8_t dcr;
     uint8_t bcr;
+    /*
+     * Provisioned ID. Since core.c sends this LSB-first during ENTDAA
+     * via (pid >> (offset * 8)) & 0xff, targets must store it
+     * pre-reversed so that pid[47:40] goes on the wire first, as
+     * required by the I3C spec.
+     *  e.g. for a device with pid 0xAABBCCDDEEFF, store

0xFFEEDDCCBBAA.
+ */

Quoted 5 lines
     uint64_t pid;

     /* CCC State tracking. */

--
2.43.0