Skip to contentSkip to conversation

i3c: dw: reduce do_daa time if there's no client

PATCH Applied Jisheng Zhang 3 participants 3 messages Aug 19

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 i3c: dw: reduce do_daa time if there's no client

dw_i3c_master_daa() derives the number of newly assigned dynamic addresses from cmd->rx_len, the ISR sets it to the number of address slots ENTDAA left unassigned. It starts out as zero, which already means "every address was assigned", so a timed out transfer leaves that value in place and it gets used as a result.

If there's no client connected, the addr assign cmd times out, then the driver calls i3c_master_add_i3c_dev_locked() to add devices that are not there, each costing about 1s, thus adds non necessary boot time up to (maxdev * 1)s.

Start from maxdevs instead: no address is assigned before ENTDAA runs, and the existing rx_count >= maxdevs check then reports an empty bus.

---

since v2:
- rebase on the lastest i3c/next
- collect Reviewed-by tag

since v1:
- use another method to remove the non-necessary calling of i3c_master_add_i3c_dev_locked() if there's no client
- update commit msg

 drivers/i3c/master/dw-i3c-master.c | 1 +
 1 file changed, 1 insertion(+)
drivers/i3c/master/dw-i3c-master.c +1 -0
index 0a3799a4ce87..4563d8761ba0 100644
@@ -921,6 +921,7 @@ static int dw_i3c_master_daa(struct i3c_master_controller *m)
 		goto rpm_out;
 	}
 	cmd = &xfer->cmds[0];
+	cmd->rx_len = master->maxdevs;
 	cmd->cmd_hi = COMMAND_PORT_TRANSFER_ARG;
 	cmd->cmd_lo = COMMAND_PORT_DEV_COUNT(master->maxdevs - pos) |
 		      COMMAND_PORT_DEV_INDEX(pos) |
Signature · 1 line
2.51.0
#1 lore raw
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Pre-existing issues:
- [High] Preexisting bug: dw_i3c_master_daa assumes master->free_pos is contiguous. A fragmented DAT can cause the hardware to overwrite existing devices and the software to drop newly assigned devices. --

--- Patch [1]: [PATCH v3] i3c: dw: reduce do_daa time if there's no client --- commit e31611e77943457ade6c812c1e49e6efc9e01ce2
Author: Jisheng Zhang <[email protected]>

i3c: dw: reduce do_daa time if there's no client

This commit modifies dw_i3c_master_daa() to initialize cmd->rx_len to master->maxdevs. This prevents the driver from attempting to add nonexistent devices when an address assignment command times out on an empty bus.

drivers/i3c/master/dw-i3c-master.c static int dw_i3c_master_daa(struct i3c_master_controller *m) · line 927

Quoted 12 lines
drivers/i3c/master/dw-i3c-master.c +1 -0
index 0a3799a4ce872..4563d8761ba0b 100644
@@ -921,6 +921,7 @@ static int dw_i3c_master_daa(struct i3c_master_controller *m)
 		goto rpm_out;
 	}
 	cmd = &xfer->cmds[0];
+	cmd->rx_len = master->maxdevs;
 	cmd->cmd_hi = COMMAND_PORT_TRANSFER_ARG;
 	cmd->cmd_lo = COMMAND_PORT_DEV_COUNT(master->maxdevs - pos) |
 		      COMMAND_PORT_DEV_INDEX(pos) |

[Severity: High]
This is a pre-existing issue, but does this hardware instruction safely handle fragmented Device Address Tables (DAT)?

If master->free_pos is fragmented (for example, devices are present at index 0 and 2, but index 1 is detached), dw_i3c_master_get_free_pos() returns pos = 1. The hardware is then instructed to assign addresses sequentially for master->maxdevs - 1 devices starting at DEV_INDEX 1.

If the DesignWare I3C hardware sequentially iterates from DEV_INDEX without skipping occupied slots, won't it assign a new device to the pre-existing address at DAT[2] during a DAA (like Hot-Join), causing a bus collision?

Furthermore, looking later in dw_i3c_master_daa():

	newdevs &= ~olddevs;

If the hardware sequentially overwrote slot 2, that index was originally in olddevs and is now masked out by this calculation. Won't the driver then silently drop the newly assigned device since it gets cleared from the newdevs bitmask?

Signature · 6 lines
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1

-- 
linux-i3c mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-i3c
maintainer Applied
#2 lore raw
In reply to Jisheng Zhang
Quoted 6 lines · Jisheng Zhang

dw_i3c_master_daa() derives the number of newly assigned dynamic addresses from cmd->rx_len, the ISR sets it to the number of address slots ENTDAA left unassigned. It starts out as zero, which already means "every address was assigned", so a timed out transfer leaves that value in place and it gets used as a result.

Quoted 6 lines

If there's no client connected, the addr assign cmd times out, then the driver calls i3c_master_add_i3c_dev_locked() to add devices that are not there, each costing about 1s, thus adds non necessary boot time up to (maxdev * 1)s.

[...]

Applied, thanks!

[1/1] i3c: dw: reduce do_daa time if there's no client

      https://git.kernel.org/i3c/c/cab40cfc9e11

Best regards,

Signature · 3 lines
Alexandre Belloni, co-owner and COO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com