[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <aTCfQIWkZ4/U2U/6@lizhi-Precision-Tower-5810>
Date: Wed, 3 Dec 2025 15:36:16 -0500
From: Frank Li <Frank.li@....com>
To: adrianhoyin.ng@...era.com
Cc: alexandre.belloni@...tlin.com, linux-i3c@...ts.infradead.org,
linux-kernel@...r.kernel.org
Subject: Re: [PATCH v6 2/5] i3c: add sysfs attribute for device NACK retry
On Wed, Dec 03, 2025 at 03:21:03PM +0800, adrianhoyin.ng@...era.com wrote:
> From: Adrian Ng Ho Yin <adrianhoyin.ng@...era.com>
>
> Add a `dev_nack_retry` sysfs attribute to allow reading and updating the
> device NACK retry count. A new `dev_nack_retry` field and an optional
> `set_dev_nack_retry()` callback are added to i3c_master_controller.
> The attribute is created only when the callback is implemented.
>
> Updates are applied under the I3C bus maintenance lock to ensure safe
> hardware reconfiguration.
>
> Signed-off-by: Adrian Ng Ho Yin <adrianhoyin.ng@...era.com>
> ---
> drivers/i3c/master.c | 41 ++++++++++++++++++++++++++++++++++++++
> include/linux/i3c/master.h | 5 +++++
> 2 files changed, 46 insertions(+)
>
> diff --git a/drivers/i3c/master.c b/drivers/i3c/master.c
> index d946db75df70..e67f54c6e865 100644
> --- a/drivers/i3c/master.c
> +++ b/drivers/i3c/master.c
> @@ -685,6 +685,41 @@ static ssize_t hotjoin_show(struct device *dev, struct device_attribute *da, cha
>
> static DEVICE_ATTR_RW(hotjoin);
>
> +static ssize_t dev_nack_retry_show(struct device *dev, struct device_attribute *attr,
> + char *buf)
> +{
> + struct i3c_bus *i3cbus = dev_to_i3cbus(dev);
> +
> + return sysfs_emit(buf, "%u\n", i3cbus->cur_master->common.master->dev_nack_retry);
dev_to_i3cmaster(dev)->dev_nack_retry.
needn't i3cbus varaible.
> +}
> +
> +static ssize_t dev_nack_retry_store(struct device *dev, struct device_attribute *attr,
> + const char *buf, size_t count)
> +{
> + struct i3c_bus *i3cbus = dev_to_i3cbus(dev);
> + struct i3c_master_controller *master;
> + unsigned long val;
> + int ret;
> +
> + ret = kstrtoul(buf, 0, &val);
> + if (ret)
> + return ret;
> +
> + master = dev_to_i3cmaster(dev);
you move it to top
struct i3c_master_controller *master = dev_to_i3cmaster(dev);
> + master->dev_nack_retry = val;
save retry value after set_dev_nack_retry(), in case set_dev_nack_retry()
return failue. master->dev_nack_retry should keep previous correct value.
So you need add argument at set_dev_nack_retry(master, val).
Frank
> +
> + i3c_bus_maintenance_lock(i3cbus);
> + ret = master->ops->set_dev_nack_retry(master);
> + i3c_bus_maintenance_unlock(i3cbus);
> +
> + if (ret)
> + return ret;
> +
> + return count;
> +}
> +
> +static DEVICE_ATTR_RW(dev_nack_retry);
> +
> static struct attribute *i3c_masterdev_attrs[] = {
> &dev_attr_mode.attr,
> &dev_attr_current_master.attr,
> @@ -2962,6 +2997,9 @@ int i3c_master_register(struct i3c_master_controller *master,
> i3c_master_register_new_i3c_devs(master);
> i3c_bus_normaluse_unlock(&master->bus);
>
> + if (master->ops->set_dev_nack_retry)
> + device_create_file(&master->dev, &dev_attr_dev_nack_retry);
> +
> return 0;
>
> err_del_dev:
> @@ -2987,6 +3025,9 @@ void i3c_master_unregister(struct i3c_master_controller *master)
> {
> i3c_bus_notify(&master->bus, I3C_NOTIFY_BUS_REMOVE);
>
> + if (master->ops->set_dev_nack_retry)
> + device_remove_file(&master->dev, &dev_attr_dev_nack_retry);
> +
> i3c_master_i2c_adapter_cleanup(master);
> i3c_master_unregister_i3c_devs(master);
> i3c_master_bus_cleanup(master);
> diff --git a/include/linux/i3c/master.h b/include/linux/i3c/master.h
> index c52a82dd79a6..ee254864c8d2 100644
> --- a/include/linux/i3c/master.h
> +++ b/include/linux/i3c/master.h
> @@ -462,6 +462,8 @@ struct i3c_bus {
> * @enable_hotjoin: enable hot join event detect.
> * @disable_hotjoin: disable hot join event detect.
> * @set_speed: adjust I3C open drain mode timing.
> + * @set_dev_nack_retry: configure device NACK retry count for the master
> + * controller.
> */
> struct i3c_master_controller_ops {
> int (*bus_init)(struct i3c_master_controller *master);
> @@ -491,6 +493,7 @@ struct i3c_master_controller_ops {
> int (*enable_hotjoin)(struct i3c_master_controller *master);
> int (*disable_hotjoin)(struct i3c_master_controller *master);
> int (*set_speed)(struct i3c_master_controller *master, enum i3c_open_drain_speed speed);
> + int (*set_dev_nack_retry)(struct i3c_master_controller *master);
> };
>
> /**
> @@ -510,6 +513,7 @@ struct i3c_master_controller_ops {
> * @boardinfo: board-level information attached to devices connected on the bus
> * @bus: I3C bus exposed by this master
> * @wq: workqueue which can be used by master
> + * @dev_nack_retry: retry count when slave device nack
> * drivers if they need to postpone operations that need to take place
> * in a thread context. Typical examples are Hot Join processing which
> * requires taking the bus lock in maintenance, which in turn, can only
> @@ -534,6 +538,7 @@ struct i3c_master_controller {
> } boardinfo;
> struct i3c_bus bus;
> struct workqueue_struct *wq;
> + unsigned int dev_nack_retry;
> };
>
> /**
> --
> 2.49.GIT
>
Powered by blists - more mailing lists