Skip to contentSkip to conversation

i3c: dw-i3c: Enable support for dw-i3c controller NACK retry sysfs and DAT restore fix

PATCH Superseded [email protected] 2 participants 8 messages Nov 21, 2025 – Nov 24, 2025

Subsystems (2)

v2 of 8 Superseded Latest is v8 →

lore
Share & tools
lore
#0 lore raw

v2 cover i3c: dw-i3c: Enable support for dw-i3c controller NACK retry sysfs and DAT restore fix

From: Adrian Ng Ho Yin <[email protected]>

This patch series adds a controller-wide sysfs attribute dev_nack_retry_count for the DesignWare I3C controller, allowing runtime control of the automatic retry mechanism when a device NACKs. Some I3C slave devices may temporarily be busy and unable to respond immediately; automatic retries improve robustness in such cases. Writes are clamped to the hardware maximum of 3, and the value is applied to all active DAT entries.

The series also fixes dw_i3c_master_restore_addrs() to preserve existing DAT entry bits, preventing overwrites during runtime PM resume.

---
changelog:
v1->v2
* Drop dev_nack_retry_cnt binding and device tree changes.
* Update commit message for better clarity.
* Update to use controller wide sysfs attribute that configures dev_nack_retry_cnt during runtime.

v1 patch link:
https://lore.kernel.org/all/[email protected]/
---

Adrian Ng Ho Yin (3):
i3c: add sysfs entry for Device NACK Retry count
i3c: dw: Add sysfs support for Device NACK Retry count
i3c: dw: Preserve DAT entry bits when restoring addresses

 Documentation/ABI/testing/sysfs-bus-i3c | 11 ++++
 drivers/i3c/master/dw-i3c-master.c      | 70 ++++++++++++++++++++++++-
 drivers/i3c/master/dw-i3c-master.h      |  1 +
 3 files changed, 80 insertions(+), 2 deletions(-)
Signature · 1 line
2.49.GIT
#1 lore raw

PATCH v2 1/3 i3c: add sysfs entry for Device NACK Retry count

From: Adrian Ng Ho Yin <[email protected]>

Document sysfs attribute dev_nack_retry_cnt that controls the number of automatic retries performed by the DesignWare I3C controller when a target device returns a NACK

---
 Documentation/ABI/testing/sysfs-bus-i3c | 11 +++++++++++
 1 file changed, 11 insertions(+)
Documentation/ABI/testing/sysfs-bus-i3c +11 -0
index c812ab180ff4..d75339330067 100644
@@ -161,3 +161,14 @@ Contact:	[email protected]
 Description:
 		These directories are just symbolic links to
 		/sys/bus/i3c/devices/i3c-<bus-id>/<bus-id>-<device-pid>.
+
+What:		/sys/bus/i3c/devices/i3c-<bus-id>/<bus-id>-<device-pid>/dev_nack_retry_count
+KernelVersion:  6.18
+Contact:	[email protected]
+Description:
+		Expose the dev_nak_retry_count which controls the number of automatic
+		retries that will be performed by the controller when the target device
+		returns a NACK response. A value of 0 disables the automatic retries. A
+		max value of 3 can be configured.
+
+		Valid values: 0-3
Signature · 1 line
2.49.GIT
reviewer
#2 lore raw

Re: [PATCH v2 1/3] i3c: add sysfs entry for Device NACK Retry count

Quoted 5 lines · On Fri, Nov 21, 2025 at 02:21:48PM +0800, [email protected] wrote:

From: Adrian Ng Ho Yin <[email protected]>

Document sysfs attribute dev_nack_retry_cnt that controls the number of automatic retries performed by the DesignWare I3C controller when a target device returns a NACK

Maybe other controller also support this feature, remove 'DesignWare'.

Add

Exist only when I3C constroller support this feature.

Frank

Quoted 28 lines
---
 Documentation/ABI/testing/sysfs-bus-i3c | 11 +++++++++++
 1 file changed, 11 insertions(+)
Documentation/ABI/testing/sysfs-bus-i3c +11 -1
index c812ab180ff4..d75339330067 100644
@@ -161,3 +161,14 @@ Contact:	[email protected]
 Description:
 		These directories are just symbolic links to
 		/sys/bus/i3c/devices/i3c-<bus-id>/<bus-id>-<device-pid>.
+
+What:		/sys/bus/i3c/devices/i3c-<bus-id>/<bus-id>-<device-pid>/dev_nack_retry_count
+KernelVersion:  6.18
+Contact:	[email protected]
+Description:
+		Expose the dev_nak_retry_count which controls the number of automatic
+		retries that will be performed by the controller when the target device
+		returns a NACK response. A value of 0 disables the automatic retries. A
+		max value of 3 can be configured.
+
+		Valid values: 0-3
--

2.49.GIT

reviewer Reviewed-by on v2 1/3
#3 lore raw

Re: [PATCH v2 1/3] i3c: add sysfs entry for Device NACK Retry count

In reply to [email protected]
Quoted 8 lines · On Fri, Nov 21, 2025 at 02:21:48PM +0800, [email protected] wrote:

From: Adrian Ng Ho Yin <[email protected]>

Document sysfs attribute dev_nack_retry_cnt that controls the number of automatic retries performed by the DesignWare I3C controller when a target device returns a NACK

---

Quoted 30 lines
 Documentation/ABI/testing/sysfs-bus-i3c | 11 +++++++++++
 1 file changed, 11 insertions(+)
Documentation/ABI/testing/sysfs-bus-i3c +11 -1
index c812ab180ff4..d75339330067 100644
@@ -161,3 +161,14 @@ Contact:	[email protected]
 Description:
 		These directories are just symbolic links to
 		/sys/bus/i3c/devices/i3c-<bus-id>/<bus-id>-<device-pid>.
+
+What:		/sys/bus/i3c/devices/i3c-<bus-id>/<bus-id>-<device-pid>/dev_nack_retry_count
+KernelVersion:  6.18
+Contact:	[email protected]
+Description:
+		Expose the dev_nak_retry_count which controls the number of automatic
+		retries that will be performed by the controller when the target device
+		returns a NACK response. A value of 0 disables the automatic retries. A
+		max value of 3 can be configured.
+
+		Valid values: 0-3
--

2.49.GIT

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

#4 lore raw

PATCH v2 2/3 i3c: dw: Add sysfs support for Device NACK Retry count

In reply to [email protected]

From: Adrian Ng Ho Yin <[email protected]>

The DesignWare I3C controller supports automatically retrying transactions when a device NACKs. This is useful for slave devices that may be temporarily busy and not ready to respond immediately.

Adds a controller-wide sysfs attribute, dev_nack_retry_count, to read or adjust the retry count at runtime. Writes are clamped to the hardware maximum of 3, and the updated value is programmed into all active DAT entries.

---
 drivers/i3c/master/dw-i3c-master.c | 64 ++++++++++++++++++++++++++++++
 drivers/i3c/master/dw-i3c-master.h |  1 +
 2 files changed, 65 insertions(+)
drivers/i3c/master/dw-i3c-master.c +64 -0
index 9ceedf09c3b6..c43eba615d8a 100644
@@ -204,8 +204,10 @@
 #define EXTENDED_CAPABILITY		0xe8
 #define SLAVE_CONFIG			0xec
 
+#define DW_I3C_DEV_NACK_RETRY_CNT_MAX	0x3
 #define DEV_ADDR_TABLE_IBI_MDB		BIT(12)
 #define DEV_ADDR_TABLE_SIR_REJECT	BIT(13)
+#define DEV_ADDR_TABLE_DEV_NACK_RETRY_CNT(x)	(((x) << 29) & GENMASK(30, 29))
 #define DEV_ADDR_TABLE_LEGACY_I2C_DEV	BIT(31)
 #define DEV_ADDR_TABLE_DYNAMIC_ADDR(x)	(((x) << 16) & GENMASK(23, 16))
 #define DEV_ADDR_TABLE_STATIC_ADDR(x)	((x) & GENMASK(6, 0))
@@ -295,6 +297,58 @@ to_dw_i3c_master(struct i3c_master_controller *master)
 	return container_of(master, struct dw_i3c_master, base);
 }
 
+static ssize_t dev_nack_retry_count_show(struct device *dev,
+					 struct device_attribute *attr,
+					 char *buf)
+{
+	struct dw_i3c_master *master = dev_get_drvdata(dev);
+
+	return sysfs_emit(buf, "%u\n", master->dev_nack_retry_cnt);
+}
+
+static ssize_t dev_nack_retry_count_store(struct device *dev,
+					  struct device_attribute *attr,
+					  const char *buf, size_t count)
+{
+	struct dw_i3c_master *master = dev_get_drvdata(dev);
+	unsigned long val;
+	int ret, i;
+	u32 reg;
+
+	ret = kstrtoul(buf, 0, &val);
+	if (ret)
+		return ret;
+
+	if (val > DW_I3C_DEV_NACK_RETRY_CNT_MAX) {
+		dev_warn(dev, "Value %lu exceeds maximum %d, clamping to max\n",
+			 val, DW_I3C_DEV_NACK_RETRY_CNT_MAX);
+		val = DW_I3C_DEV_NACK_RETRY_CNT_MAX;
+	}
+
+	master->dev_nack_retry_cnt = val;
+
+	/*
+	 * Update DAT entries for all currently attached devices.
+	 * We directly iterate through the master's device array.
+	 */
+	for (i = 0; i < master->maxdevs; i++) {
+		/* Skip free/empty slots */
+		if (master->free_pos & BIT(i))
+			continue;
+
+		reg = readl(master->regs +
+				DEV_ADDR_TABLE_LOC(master->datstartaddr, i));
+		reg &= ~GENMASK(30, 29);
+		reg |= DEV_ADDR_TABLE_DEV_NACK_RETRY_CNT(val);
+		writel(reg, master->regs +
+			DEV_ADDR_TABLE_LOC(master->datstartaddr, i));
+	}
+
+	return count;
+}
+
+static DEVICE_ATTR_RW(dev_nack_retry_count);
+
 static void dw_i3c_master_disable(struct dw_i3c_master *master)
 {
 	writel(readl(master->regs + DEVICE_CTRL) & ~DEV_CTRL_ENABLE,
@@ -1032,6 +1086,7 @@ static int dw_i3c_master_attach_i3c_dev(struct i3c_dev_desc *dev)
 	data->index = pos;
 	master->devs[pos].addr = dev->info.dyn_addr ? : dev->info.static_addr;
 	master->free_pos &= ~BIT(pos);
+	master->dev_nack_retry_cnt = 0;
 	i3c_dev_set_master_data(dev, data);
 
 	writel(DEV_ADDR_TABLE_DYNAMIC_ADDR(master->devs[pos].addr),
@@ -1598,6 +1653,12 @@ int dw_i3c_common_probe(struct dw_i3c_master *master,
 	if (ret)
 		goto err_disable_pm;
 
+	dev_set_drvdata(&master->base.dev, master);
+	ret = device_create_file(&master->base.dev, &dev_attr_dev_nack_retry_count);
+	if (ret)
+		dev_warn(&master->base.dev,
+			 "Failed to create dev_nack_retry_count sysfs: %d\n", ret);
+
 	return 0;
 
 err_disable_pm:
@@ -1617,6 +1678,9 @@ void dw_i3c_common_remove(struct dw_i3c_master *master)
 	cancel_work_sync(&master->hj_work);
 	i3c_master_unregister(&master->base);
 
+	device_remove_file(&master->base.dev, &dev_attr_dev_nack_retry_count);
+	dev_set_drvdata(&master->base.dev, NULL);
+
 	pm_runtime_disable(master->dev);
 	pm_runtime_set_suspended(master->dev);
 	pm_runtime_dont_use_autosuspend(master->dev);
drivers/i3c/master/dw-i3c-master.h +1 -0
index c5cb695c16ab..c87a0e87bfd9 100644
@@ -51,6 +51,7 @@ struct dw_i3c_master {
 	u32 i2c_fm_timing;
 	u32 i2c_fmp_timing;
 	u32 quirks;
+	u32	dev_nack_retry_cnt;
 	/*
 	 * Per-device hardware data, used to manage the device address table
 	 * (DAT)
Signature · 1 line
2.49.GIT
reviewer
#5 lore raw

Re: [PATCH v2 2/3] i3c: dw: Add sysfs support for Device NACK Retry count

Quoted 33 lines · On Fri, Nov 21, 2025 at 02:21:49PM +0800, [email protected] wrote:

From: Adrian Ng Ho Yin <[email protected]>

The DesignWare I3C controller supports automatically retrying transactions when a device NACKs. This is useful for slave devices that may be temporarily busy and not ready to respond immediately.

Adds a controller-wide sysfs attribute, dev_nack_retry_count, to read or adjust the retry count at runtime. Writes are clamped to the hardware maximum of 3, and the updated value is programmed into all active DAT entries.

---
 drivers/i3c/master/dw-i3c-master.c | 64 ++++++++++++++++++++++++++++++
 drivers/i3c/master/dw-i3c-master.h |  1 +
 2 files changed, 65 insertions(+)
drivers/i3c/master/dw-i3c-master.c +2 -0
index 9ceedf09c3b6..c43eba615d8a 100644
@@ -204,8 +204,10 @@
 #define EXTENDED_CAPABILITY		0xe8
 #define SLAVE_CONFIG			0xec
 
+#define DW_I3C_DEV_NACK_RETRY_CNT_MAX	0x3
 #define DEV_ADDR_TABLE_IBI_MDB		BIT(12)
 #define DEV_ADDR_TABLE_SIR_REJECT	BIT(13)
+#define DEV_ADDR_TABLE_DEV_NACK_RETRY_CNT(x)	(((x) << 29) & GENMASK(30, 29))
 #define DEV_ADDR_TABLE_LEGACY_I2C_DEV	BIT(31)
 #define DEV_ADDR_TABLE_DYNAMIC_ADDR(x)	(((x) << 16) & GENMASK(23, 16))
 #define DEV_ADDR_TABLE_STATIC_ADDR(x)	((x) & GENMASK(6, 0))

drivers/i3c/master/dw-i3c-master.c to_dw_i3c_master(struct i3c_master_controller *master) · line 302

Quoted 6 lines
drivers/i3c/master/dw-i3c-master.c +3 -0
@@ -295,6 +297,58 @@ to_dw_i3c_master(struct i3c_master_controller *master)
 	return container_of(master, struct dw_i3c_master, base);
 }
 
+static ssize_t dev_nack_retry_count_show(struct device *dev,
+					 struct device_attribute *attr,
+					 char *buf)

keep consistent with other function's naming. Maybe "dw_i3c_master" too long, add "dw_" prefix should be fine.

Quoted 13 lines
drivers/i3c/master/dw-i3c-master.c +13 -0
+{
+	struct dw_i3c_master *master = dev_get_drvdata(dev);
+
+	return sysfs_emit(buf, "%u\n", master->dev_nack_retry_cnt);
+}
+
+static ssize_t dev_nack_retry_count_store(struct device *dev,
+					  struct device_attribute *attr,
+					  const char *buf, size_t count)
+{
+	struct dw_i3c_master *master = dev_get_drvdata(dev);
+	unsigned long val;
+	int ret, i;

drivers/i3c/master/dw-i3c-master.c to_dw_i3c_master(struct i3c_master_controller *master) · line 325

Quoted 10 lines
drivers/i3c/master/dw-i3c-master.c +10 -0
+	u32 reg;
+
+	ret = kstrtoul(buf, 0, &val);
+	if (ret)
+		return ret;
+
+	if (val > DW_I3C_DEV_NACK_RETRY_CNT_MAX) {
+		dev_warn(dev, "Value %lu exceeds maximum %d, clamping to max\n",
+			 val, DW_I3C_DEV_NACK_RETRY_CNT_MAX);
+		val = DW_I3C_DEV_NACK_RETRY_CNT_MAX;

return err.

Quoted 9 lines
drivers/i3c/master/dw-i3c-master.c +9 -0
+	}
+
+	master->dev_nack_retry_cnt = val;
+
+	/*
+	 * Update DAT entries for all currently attached devices.
+	 * We directly iterate through the master's device array.
+	 */
+	for (i = 0; i < master->maxdevs; i++) {

drivers/i3c/master/dw-i3c-master.c to_dw_i3c_master(struct i3c_master_controller *master) · line 344

Quoted 10 lines
drivers/i3c/master/dw-i3c-master.c +10 -0
+		/* Skip free/empty slots */
+		if (master->free_pos & BIT(i))
+			continue;
+
+		reg = readl(master->regs +
+				DEV_ADDR_TABLE_LOC(master->datstartaddr, i));
+		reg &= ~GENMASK(30, 29);
+		reg |= DEV_ADDR_TABLE_DEV_NACK_RETRY_CNT(val);
+		writel(reg, master->regs +
+			DEV_ADDR_TABLE_LOC(master->datstartaddr, i));

do you need lock here? In case data is transferring.

Quoted 11 lines
drivers/i3c/master/dw-i3c-master.c +7 -0
+	}
+
+	return count;
+}
+
+static DEVICE_ATTR_RW(dev_nack_retry_count);
+
 static void dw_i3c_master_disable(struct dw_i3c_master *master)
 {
 	writel(readl(master->regs + DEVICE_CTRL) & ~DEV_CTRL_ENABLE,

drivers/i3c/master/dw-i3c-master.c static int dw_i3c_master_attach_i3c_dev(struct i3c_dev_desc *dev) · line 1089

Quoted 4 lines
drivers/i3c/master/dw-i3c-master.c +1 -0
@@ -1032,6 +1086,7 @@ static int dw_i3c_master_attach_i3c_dev(struct i3c_dev_desc *dev)
 	data->index = pos;
 	master->devs[pos].addr = dev->info.dyn_addr ? : dev->info.static_addr;
 	master->free_pos &= ~BIT(pos);
+	master->dev_nack_retry_cnt = 0;

suppose needn't init to 0 here again, it is already 0 when alloc master.

Quoted 29 lines
drivers/i3c/master/dw-i3c-master.c +9 -0
 	writel(DEV_ADDR_TABLE_DYNAMIC_ADDR(master->devs[pos].addr),
@@ -1598,6 +1653,12 @@ int dw_i3c_common_probe(struct dw_i3c_master *master,
 	if (ret)
 		goto err_disable_pm;
 
+	dev_set_drvdata(&master->base.dev, master);
+	ret = device_create_file(&master->base.dev, &dev_attr_dev_nack_retry_count);
+	if (ret)
+		dev_warn(&master->base.dev,
+			 "Failed to create dev_nack_retry_count sysfs: %d\n", ret);
+
 	return 0;
 
 err_disable_pm:
@@ -1617,6 +1678,9 @@ void dw_i3c_common_remove(struct dw_i3c_master *master)
 	cancel_work_sync(&master->hj_work);
 	i3c_master_unregister(&master->base);
 
+	device_remove_file(&master->base.dev, &dev_attr_dev_nack_retry_count);
+	dev_set_drvdata(&master->base.dev, NULL);
+
 	pm_runtime_disable(master->dev);
 	pm_runtime_set_suspended(master->dev);
 	pm_runtime_dont_use_autosuspend(master->dev);
drivers/i3c/master/dw-i3c-master.h +0 -0
index c5cb695c16ab..c87a0e87bfd9 100644

drivers/i3c/master/dw-i3c-master.h struct dw_i3c_master { · line 54

Quoted 4 lines
drivers/i3c/master/dw-i3c-master.h +1 -0
@@ -51,6 +51,7 @@ struct dw_i3c_master {
 	u32 i2c_fm_timing;
 	u32 i2c_fmp_timing;
 	u32 quirks;
+	u32	dev_nack_retry_cnt;

just one space between u32 and dev_nack_retry_cnt

Frank

Quoted 6 lines
drivers/i3c/master/dw-i3c-master.h +0 -1
 	/*
 	 * Per-device hardware data, used to manage the device address table
 	 * (DAT)
--

2.49.GIT

#6 lore raw

PATCH v2 3/3 i3c: dw: Preserve DAT entry bits when restoring addresses

In reply to [email protected]

From: Adrian Ng Ho Yin <[email protected]>

Update dw_i3c_master_restore_addrs() to preserve existing bits in each Device Address Table (DAT) entry when restoring addresses. This prevents overwriting configuration bits during PM runtime resumes.

---
 drivers/i3c/master/dw-i3c-master.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/i3c/master/dw-i3c-master.c +4 -2
index c43eba615d8a..ac3c2d3136d0 100644
@@ -1718,11 +1718,13 @@ static void dw_i3c_master_restore_addrs(struct dw_i3c_master *master)
 		if (master->free_pos & BIT(pos))
 			continue;
 
+		reg_val = readl(master->regs + DEV_ADDR_TABLE_LOC(master->datstartaddr, pos));
+
 		if (master->devs[pos].is_i2c_addr)
-			reg_val = DEV_ADDR_TABLE_LEGACY_I2C_DEV |
+			reg_val |= DEV_ADDR_TABLE_LEGACY_I2C_DEV |
 			       DEV_ADDR_TABLE_STATIC_ADDR(master->devs[pos].addr);
 		else
-			reg_val = DEV_ADDR_TABLE_DYNAMIC_ADDR(master->devs[pos].addr);
+			reg_val |= DEV_ADDR_TABLE_DYNAMIC_ADDR(master->devs[pos].addr);
 
 		writel(reg_val, master->regs + DEV_ADDR_TABLE_LOC(master->datstartaddr, pos));
 	}
Signature · 1 line
2.49.GIT
reviewer
#7 lore raw

Re: [PATCH v2 3/3] i3c: dw: Preserve DAT entry bits when restoring addresses

Quoted 16 lines · On Fri, Nov 21, 2025 at 02:21:50PM +0800, [email protected] wrote:

From: Adrian Ng Ho Yin <[email protected]>

Update dw_i3c_master_restore_addrs() to preserve existing bits in each Device Address Table (DAT) entry when restoring addresses. This prevents overwriting configuration bits during PM runtime resumes.

---
 drivers/i3c/master/dw-i3c-master.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/i3c/master/dw-i3c-master.c +0 -0
index c43eba615d8a..ac3c2d3136d0 100644

drivers/i3c/master/dw-i3c-master.c static void dw_i3c_master_restore_addrs(struct dw_i3c_master *master) · line 1725

Quoted 9 lines
drivers/i3c/master/dw-i3c-master.c +3 -1
@@ -1718,11 +1718,13 @@ static void dw_i3c_master_restore_addrs(struct dw_i3c_master *master)
 		if (master->free_pos & BIT(pos))
 			continue;
 
+		reg_val = readl(master->regs + DEV_ADDR_TABLE_LOC(master->datstartaddr, pos));
+
 		if (master->devs[pos].is_i2c_addr)
-			reg_val = DEV_ADDR_TABLE_LEGACY_I2C_DEV |
+			reg_val |= DEV_ADDR_TABLE_LEGACY_I2C_DEV |
 			       DEV_ADDR_TABLE_STATIC_ADDR(master->devs[pos].addr);

Suppose need clean addr field of reg_val before |=

address value may be wrong if addr feild is not 0 in DAT. Or you can make sure it is zero.

Frank

Quoted 9 lines
drivers/i3c/master/dw-i3c-master.c +1 -2
 		else
-			reg_val = DEV_ADDR_TABLE_DYNAMIC_ADDR(master->devs[pos].addr);
+			reg_val |= DEV_ADDR_TABLE_DYNAMIC_ADDR(master->devs[pos].addr);
 
 		writel(reg_val, master->regs + DEV_ADDR_TABLE_LOC(master->datstartaddr, pos));
 	}
--

2.49.GIT