i3c: dw-i3c: Enable support for dw-i3c controller NACK retry sysfs and DAT restore fix
Subsystems (2)
v3 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:v2->v3
* Update commit message for better clarity
* Update function name to maintain consistency.
* Update store function to return error when retry value exceeds hw limit.
* Add lock to protect DAT to avoid concurrent during transfers.
* Clear the address field in the DAT entry before setting new values to ensure correct dynamic/static address configuration
v2 patch link:
https://lore.kernel.org/all/[email protected]/
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 | 12 ++++ drivers/i3c/master/dw-i3c-master.c | 82 +++++++++++++++++++++++-- drivers/i3c/master/dw-i3c-master.h | 1 + 3 files changed, 91 insertions(+), 4 deletions(-)
Signature · 1 line
2.49.GIT
PATCH v3 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 I3C controller when a target device returns a NACK
--- Documentation/ABI/testing/sysfs-bus-i3c | 12 ++++++++++++ 1 file changed, 12 insertions(+)
Documentation/ABI/testing/sysfs-bus-i3c +12 -0
@@ -161,3 +161,15 @@ 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. Exist + only when I3C constroller supports this retry on nack feature. + + Valid values: 0-3
Signature · 1 line
2.49.GIT
Re: [PATCH v3 1/3] i3c: add sysfs entry for Device NACK Retry count
Quoted 8 lines · On Sat, Nov 22, 2025 at 02:00:39AM +0800, [email protected] wrote:
From: Adrian Ng Ho Yin <[email protected]>
Document sysfs attribute
dev_nack_retry_cntthat controls the number of automatic retries performed by the I3C controller when a target device returns a NACKSigned-off-by Adrian Ng Ho Yin <[email protected]>---
Quoted 26 lines
Documentation/ABI/testing/sysfs-bus-i3c | 12 ++++++++++++ 1 file changed, 12 insertions(+)Documentation/ABI/testing/sysfs-bus-i3c +12
-1@@ -161,3 +161,15 @@ 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. Exist + only when I3C constroller supports this retry on nack feature. + + Valid values: 0-3 --2.49.GIT
PATCH v3 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. Returns error when value exceeds hw specified limit, and the updated value is programmed into all active DAT entries.
--- drivers/i3c/master/dw-i3c-master.c | 69 ++++++++++++++++++++++++++++++ drivers/i3c/master/dw-i3c-master.h | 1 + 2 files changed, 70 insertions(+)
drivers/i3c/master/dw-i3c-master.c +69 -0
@@ -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,64 @@ to_dw_i3c_master(struct i3c_master_controller *master) return container_of(master, struct dw_i3c_master, base); } +static ssize_t dw_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 dw_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, flags; +int ret, i; +u32 reg; + + ret =kstrtoul (buf,0 , &val); +if (ret) +return ret; + +if (val >DW_I3C_DEV_NACK_RETRY_CNT_MAX ) { +dev_err (dev, +"Value %lu exceeds maximum %d\n" , + val,DW_I3C_DEV_NACK_RETRY_CNT_MAX ); +return -ERANGE ; + } + + master->dev_nack_retry_cnt = val; + +spin_lock_irqsave (&master->devs_lock, flags); +/* +* 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)); + } +spin_unlock_irqrestore (&master->devs_lock, flags); + +return count; +} + +static struct device_attribute dev_attr_dev_nack_retry_count = +__ATTR (dev_nack_retry_count,0644 , + dw_dev_nack_retry_count_show, + dw_dev_nack_retry_count_store); +static void dw_i3c_master_disable (struct dw_i3c_master *master) { writel(readl(master->regs + DEVICE_CTRL) & ~DEV_CTRL_ENABLE,
@@ -1598,6 +1658,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 +1683,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
@@ -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 · 7 lines
2.49.GIT -- linux-i3c mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-i3c
Frank Li
reviewerRe: [PATCH v3 2/3] i3c: dw: Add sysfs support for Device NACK Retry count
Quoted 36 lines · On Sat, Nov 22, 2025 at 02:00:40AM +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. Returns error when value exceeds hw specified limit, and the updated value is programmed into all active DAT entries.Signed-off-by Adrian Ng Ho Yin <[email protected]>--- drivers/i3c/master/dw-i3c-master.c | 69 ++++++++++++++++++++++++++++++ drivers/i3c/master/dw-i3c-master.h | 1 + 2 files changed, 70 insertions(+)drivers/i3c/master/dw-i3c-master.c +2
-0@@ -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,64 @@ to_dw_i3c_master(struct i3c_master_controller *master) return container_of(master, struct dw_i3c_master, base); }
...
Quoted 13 lines
drivers/i3c/master/dw-i3c-master.c +13
-0+static ssize_t dw_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, flags; +int ret, i; +u32 reg; + + ret =kstrtoul (buf,0 , &val); +if (ret) +return ret; +
drivers/i3c/master/dw-i3c-master.c to_dw_i3c_master(struct i3c_master_controller *master) · line 331
Quoted 10 lines
drivers/i3c/master/dw-i3c-master.c +10
-0+if (val >DW_I3C_DEV_NACK_RETRY_CNT_MAX ) { +dev_err (dev, +"Value %lu exceeds maximum %d\n" , + val,DW_I3C_DEV_NACK_RETRY_CNT_MAX ); +return -ERANGE ; + } + + master->dev_nack_retry_cnt = val; + +spin_lock_irqsave (&master->devs_lock, flags);
I think you'd better to hold i3c_bus_maintenance_lock() lock to make sure not transfer on going.
Frank
Quoted 21 lines
drivers/i3c/master/dw-i3c-master.c +21
-0+/* +* 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)); + } +spin_unlock_irqrestore (&master->devs_lock, flags); + +return count; +} +
...
Quoted 3 lines
--
2.49.GIT
Re: [PATCH v3 2/3] i3c: dw: Add sysfs support for Device NACK Retry count
Quoted 9 lines · Frank Li
drivers/i3c/master/dw-i3c-master.c to_dw_i3c_master(struct i3c_master_controller *master) · line 331
Quoted 4 lines
drivers/i3c/master/dw-i3c-master.c +4
-0+ + master->dev_nack_retry_cnt = val; + +spin_lock_irqsave (&master->devs_lock, flags);I think you'd better to hold
i3c_bus_maintenance_lock()lock to make sure not transfer on going.Frank
Hi Frank
i3c_bus_maintenance_lock is a static function in master.c. So should i update it and expose a public helper to take the maintenance lock or continue using the existing spin lock to protect the DAT updates?
Thank You
Adrian
Quoted 6 lines
Quoted 6 lines
drivers/i3c/master/dw-i3c-master.c +6
-0+/* +* 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 */
Re: [PATCH v3 2/3] i3c: dw: Add sysfs support for Device NACK Retry count
Quoted 10 lines · Adrian Ho Yin
Quoted 8 lines · Frank Li
drivers/i3c/master/dw-i3c-master.c to_dw_i3c_master(struct i3c_master_controller *master) · line 331
Quoted 4 lines
drivers/i3c/master/dw-i3c-master.c +4
-0+ + master->dev_nack_retry_cnt = val; + + spin_lock_irqsave(&master->devs_lock, flags);I think you'd better to hold
i3c_bus_maintenance_lock()lock to make sure not transfer on going.
Quoted 7 lines
Quoted 1 line
Frank
Hi Frank
i3c_bus_maintenance_lockis a static function inmaster.c. So should i update it and expose a public helper to take the maintenance lock or continue using the existing spin lock to protect the DAT updates?Thank You
Adrian
Other controllers (e.g. MIPI I3C) support dev_nack_retry_cnt.
Seems to me this should be in master.c anyway, so it can be shared.
Frank Li
reviewerRe: [PATCH v3 2/3] i3c: dw: Add sysfs support for Device NACK Retry count
Quoted 14 lines · Adrian Hunter
Quoted 13 lines · Adrian Ho Yin
Quoted 9 lines · Frank Li
drivers/i3c/master/dw-i3c-master.c to_dw_i3c_master(struct i3c_master_controller *master) · line 331
Quoted 4 lines
drivers/i3c/master/dw-i3c-master.c +4
-0+ + master->dev_nack_retry_cnt = val; + + spin_lock_irqsave(&master->devs_lock, flags);I think you'd better to hold
i3c_bus_maintenance_lock()lock to make sure not transfer on going.Frank
Hi Frank
Quoted 9 lines
Quoted 4 lines
i3c_bus_maintenance_lockis a static function inmaster.c. So should i update it and expose a public helper to take the maintenance lock or continue using the existing spin lock to protect the DAT updates?Thank You
AdrianOther controllers (e.g. MIPI I3C) support
dev_nack_retry_cnt.Seems to me this should be in
master.canyway, so it can be shared.
Agree.
Frank
PATCH v3 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 | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)
drivers/i3c/master/dw-i3c-master.c +9 -4
@@ -1723,11 +1723,16 @@ static void dw_i3c_master_restore_addrs(struct dw_i3c_master *master)if (master->free_pos &BIT (pos))continue ; -if (master->devs[pos].is_i2c_addr) - reg_val =DEV_ADDR_TABLE_LEGACY_I2C_DEV | + reg_val =readl (master->regs +DEV_ADDR_TABLE_LOC (master->datstartaddr, pos)); + +if (master->devs[pos].is_i2c_addr) { + reg_val &= ~(GENMASK (6 ,0 )); + 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); + }else { + reg_val &= ~(GENMASK (23 ,16 )); + 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
Frank Li
reviewerRe: [PATCH v3 3/3] i3c: dw: Preserve DAT entry bits when restoring addresses
Quoted 16 lines · On Sat, Nov 22, 2025 at 02:00:41AM +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.Signed-off-by Adrian Ng Ho Yin <[email protected]>--- drivers/i3c/master/dw-i3c-master.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)drivers/i3c/master/dw-i3c-master.c +0
-0
drivers/i3c/master/dw-i3c-master.c static void dw_i3c_master_restore_addrs(struct dw_i3c_master *master) · line 1729
Quoted 9 lines
drivers/i3c/master/dw-i3c-master.c +4
-2@@ -1723,11 +1723,16 @@ static void dw_i3c_master_restore_addrs(struct dw_i3c_master *master)if (master->free_pos &BIT (pos))continue ; -if (master->devs[pos].is_i2c_addr) - reg_val = DEV_ADDR_TABLE_LEGACY_I2C_DEV | + reg_val =readl (master->regs +DEV_ADDR_TABLE_LOC (master->datstartaddr, pos)); + +if (master->devs[pos].is_i2c_addr) { + reg_val &= ~(GENMASK (6 ,0 ));
#define at MASK for it
#define DEV_ADDR_TABLE_DYNAMIC_MASK GENMASK(23, 16);
#define DEV_ADDR_TABLE_DYNAMIC_ADDR(x) FIELD_PREP(DEV_ADDR_TABLE_DYNAMIC_MASK, x) //(((x) << 16) & GENMASK(23, 16))
Create a patch to just change it. And use DEV_ADDR_TABLE_DYNAMIC_MASK at this patch.
Frank
Quoted 14 lines
drivers/i3c/master/dw-i3c-master.c +5
-3+ 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); + }else { + reg_val &= ~(GENMASK (23 ,16 )); + 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