Re: [PATCH v7 18/22] hw/i3c: Add Mock target

Jithu Joseph
2026-02-27T01:52:30Z

Apologies for chiming in this late ... I only got a chance to test this last week
This really is a minor comment ... can be addressed subsequently

On 2/24/2026 6:12 PM, Jamin Lin wrote:
> Adds a simple i3c device to be used for testing in lieu of a real
> device.
>
> The mock target supports the following features:
> - A buffer that users can read and write to.
> - CCC support for commonly used CCCs when probing devices on an I3C bus.
> - IBI sending upon receiving a user-defined byte.
>
> Signed-off-by: Joe Komlodi <komlodi@google.com>
> Reviewed-by: Titus Rwantare <titusr@google.com>
> Reviewed-by: Patrick Venture <venture@google.com>
> Reviewed-by: Jamin Lin <jamin_lin@aspeedtech.com>
> Signed-off-by: Jamin Lin <jamin_lin@aspeedtech.com>
> ---
> include/hw/i3c/mock-i3c-target.h | 52 ++++++
> hw/i3c/mock-i3c-target.c | 298 +++++++++++++++++++++++++++++++
> hw/i3c/Kconfig | 10 ++
> hw/i3c/meson.build | 1 +
> hw/i3c/trace-events | 10 ++
> 5 files changed, 371 insertions(+)
> create mode 100644 include/hw/i3c/mock-i3c-target.h
> create mode 100644 hw/i3c/mock-i3c-target.c
>
> diff --git a/include/hw/i3c/mock-i3c-target.h b/include/hw/i3c/mock-i3c-target.h
> new file mode 100644

...

> +static int mock_i3c_target_tx(I3CTarget *i3c, const uint8_t *data,
> + uint32_t num_to_send, uint32_t *num_sent)
> +{
> + MockI3cTargetState *s = MOCK_I3C_TARGET(i3c);
> + int ret;
> + uint32_t to_write;
> +
> + if (s->cfg.ibi_magic && num_to_send == 1 && s->cfg.ibi_magic == *data) {
> + mock_i3c_target_ibi_timer_start(s);
> + return 0;
> + }
> +
> + /* Bounds check. */
> + if (num_to_send + s->p_buf > s->cfg.buf_size) {
> + to_write = s->cfg.buf_size - s->p_buf;
> + ret = -1;
> + } else {
> + to_write = num_to_send;
> + ret = 0;
> + }
> + for (uint32_t i = 0; i < to_write; i++) {
> + trace_mock_i3c_target_tx(data[i]);
> + s->buf[s->p_buf] = data[i];
> + s->p_buf++;
> + }

num_sent is never updated prior to return, so the traces (from caller i3c_send) looked a bit confusing

<snip>
mock_i3c_target_tx I3C mock target write 0x12
i3c_send I3C send 0/1 bytes, ack=1 ---------------------> instead of 1/1 bytes
mock_i3c_target_tx I3C mock target write 0x34
i3c_send I3C send 0/1 bytes, ack=1
</snip>

Something like below is needed
+ *num_sent = to_write
(might also needed in the ibi magic path above)

> + return ret;
> +}
> +

Thanks
Jithu