i3c: master: svc: use repeat start when IBI WIN happens

There is a possibility of an IBI WIN occurring when addressing issues, even
when sending CCC commands. Most of the time, returning -EAGAIN is
acceptable, but the case below becomes highly complex.

When a Hotjoin event occurs:
- i3c_master_do_daa()
  - i3c_master_add_i3c_dev_locked()
    - A dynamic address (e.g., 0x9) is already set during DAA.
    - i3c_master_getpid_locked()
      - Another device issues HJ or IBI here. Returning -EAGAIN causes
        failure in adding the new device. However, the dynamic address(0x9)
        has already been assigned to this device. If another device issues
        HJ, it will get this address 0x9 again, causing two devices on the
        bus to use the same dynamic address 0x9.
      - Attempting to send RSTDAA when the first device fails at
        i3c_master_getpid_locked() could also fail when sending RSTDAA for
        the same reason.

According to the I3C spec, address arbitration only happens at START, never
at REPEAT start. Using repeat start when an IBI WIN occurs simplifies this
case, as i3c_master_getpid_locked() will not return an error when another
device tries to send HJ or IBI.

Acked-by: Miquel Raynal <miquel.raynal@bootlin.com>
Signed-off-by: Frank Li <Frank.Li@nxp.com>
Link: https://lore.kernel.org/r/20241002-svc-i3c-hj-v6-1-7e6e1d3569ae@nxp.com
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
This commit is contained in:
Frank Li 2024-10-02 10:50:33 -04:00 committed by Alexandre Belloni
parent 851bd21cdb
commit 3c6684a150

View File

@ -1163,6 +1163,24 @@ static int svc_i3c_master_xfer(struct svc_i3c_master *master,
if (ret)
goto emit_stop;
/*
* According to I3C spec ver 1.1.1, 5.1.2.2.3 Consequence of Controller Starting a
* Frame with I3C Target Address.
*
* The I3C Controller normally should start a Frame, the Address may be arbitrated,
* and so the Controller shall monitor to see whether an In-Band Interrupt request,
* a Controller Role Request (i.e., Secondary Controller requests to become the
* Active Controller), or a Hot-Join Request has been made.
*
* If missed IBIWON check, the wrong data will be return. When IBIWON happen, issue
* repeat start. Address arbitrate only happen at START, never happen at REPEAT
* start.
*/
if (SVC_I3C_MSTATUS_IBIWON(reg)) {
writel(SVC_I3C_MINT_IBIWON, master->regs + SVC_I3C_MSTATUS);
continue;
}
if (readl(master->regs + SVC_I3C_MERRWARN) & SVC_I3C_MERRWARN_NACK) {
/*
* According to I3C Spec 1.1.1, 11-Jun-2021, section: 5.1.2.2.3.
@ -1196,24 +1214,6 @@ static int svc_i3c_master_xfer(struct svc_i3c_master *master,
}
}
/*
* According to I3C spec ver 1.1.1, 5.1.2.2.3 Consequence of Controller Starting a Frame
* with I3C Target Address.
*
* The I3C Controller normally should start a Frame, the Address may be arbitrated, and so
* the Controller shall monitor to see whether an In-Band Interrupt request, a Controller
* Role Request (i.e., Secondary Controller requests to become the Active Controller), or
* a Hot-Join Request has been made.
*
* If missed IBIWON check, the wrong data will be return. When IBIWON happen, return failure
* and yield the above events handler.
*/
if (SVC_I3C_MSTATUS_IBIWON(reg)) {
ret = -EAGAIN;
*actual_len = 0;
goto emit_stop;
}
if (rnw)
ret = svc_i3c_master_read(master, in, xfer_len);
else