Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

i3c: add sysfs entry and attribute for Device NACK Retry count

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

Add a `dev_nack_retry_count` sysfs attribute to allow reading and updating
the device NACK retry count. A new `dev_nack_retry_count` 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@altera.com>
Reviewed-by: Frank Li <Frank.Li@nxp.com>
Link: https://patch.msgid.link/3c4b5082bde64024fc383c44bebeef89ad3c7ed3.1765529948.git.adrianhoyin.ng@altera.com
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>

authored by

Adrian Ng Ho Yin and committed by
Alexandre Belloni
b58f47eb 8f0b4cce

+56
+11
Documentation/ABI/testing/sysfs-bus-i3c
··· 161 161 Description: 162 162 These directories are just symbolic links to 163 163 /sys/bus/i3c/devices/i3c-<bus-id>/<bus-id>-<device-pid>. 164 + 165 + What: /sys/bus/i3c/devices/i3c-<bus-id>/<bus-id>-<device-pid>/dev_nack_retry_count 166 + KernelVersion: 6.18 167 + Contact: linux-i3c@vger.kernel.org 168 + Description: 169 + Expose the dev_nak_retry_count which controls the number of 170 + automatic retries that will be performed by the controller when 171 + the target device returns a NACK response. A value of 0 disables 172 + the automatic retries. Exist only when I3C constroller supports 173 + this retry on nack feature. 174 +
+39
drivers/i3c/master.c
··· 683 683 684 684 static DEVICE_ATTR_RW(hotjoin); 685 685 686 + static ssize_t dev_nack_retry_count_show(struct device *dev, 687 + struct device_attribute *attr, char *buf) 688 + { 689 + return sysfs_emit(buf, "%u\n", dev_to_i3cmaster(dev)->dev_nack_retry_count); 690 + } 691 + 692 + static ssize_t dev_nack_retry_count_store(struct device *dev, 693 + struct device_attribute *attr, 694 + const char *buf, size_t count) 695 + { 696 + struct i3c_bus *i3cbus = dev_to_i3cbus(dev); 697 + struct i3c_master_controller *master = dev_to_i3cmaster(dev); 698 + unsigned long val; 699 + int ret; 700 + 701 + ret = kstrtoul(buf, 0, &val); 702 + if (ret) 703 + return ret; 704 + 705 + i3c_bus_maintenance_lock(i3cbus); 706 + ret = master->ops->set_dev_nack_retry(master, val); 707 + i3c_bus_maintenance_unlock(i3cbus); 708 + 709 + if (ret) 710 + return ret; 711 + 712 + master->dev_nack_retry_count = val; 713 + 714 + return count; 715 + } 716 + 717 + static DEVICE_ATTR_RW(dev_nack_retry_count); 718 + 686 719 static struct attribute *i3c_masterdev_attrs[] = { 687 720 &dev_attr_mode.attr, 688 721 &dev_attr_current_master.attr, ··· 2992 2959 i3c_master_register_new_i3c_devs(master); 2993 2960 i3c_bus_normaluse_unlock(&master->bus); 2994 2961 2962 + if (master->ops->set_dev_nack_retry) 2963 + device_create_file(&master->dev, &dev_attr_dev_nack_retry_count); 2964 + 2995 2965 return 0; 2996 2966 2997 2967 err_del_dev: ··· 3019 2983 void i3c_master_unregister(struct i3c_master_controller *master) 3020 2984 { 3021 2985 i3c_bus_notify(&master->bus, I3C_NOTIFY_BUS_REMOVE); 2986 + 2987 + if (master->ops->set_dev_nack_retry) 2988 + device_remove_file(&master->dev, &dev_attr_dev_nack_retry_count); 3022 2989 3023 2990 i3c_master_i2c_adapter_cleanup(master); 3024 2991 i3c_master_unregister_i3c_devs(master);
+6
include/linux/i3c/master.h
··· 462 462 * @enable_hotjoin: enable hot join event detect. 463 463 * @disable_hotjoin: disable hot join event detect. 464 464 * @set_speed: adjust I3C open drain mode timing. 465 + * @set_dev_nack_retry: configure device NACK retry count for the master 466 + * controller. 465 467 */ 466 468 struct i3c_master_controller_ops { 467 469 int (*bus_init)(struct i3c_master_controller *master); ··· 493 491 int (*enable_hotjoin)(struct i3c_master_controller *master); 494 492 int (*disable_hotjoin)(struct i3c_master_controller *master); 495 493 int (*set_speed)(struct i3c_master_controller *master, enum i3c_open_drain_speed speed); 494 + int (*set_dev_nack_retry)(struct i3c_master_controller *master, 495 + unsigned long dev_nack_retry_cnt); 496 496 }; 497 497 498 498 /** ··· 518 514 * in a thread context. Typical examples are Hot Join processing which 519 515 * requires taking the bus lock in maintenance, which in turn, can only 520 516 * be done from a sleep-able context 517 + * @dev_nack_retry_count: retry count when slave device nack 521 518 * 522 519 * A &struct i3c_master_controller has to be registered to the I3C subsystem 523 520 * through i3c_master_register(). None of &struct i3c_master_controller fields ··· 539 534 } boardinfo; 540 535 struct i3c_bus bus; 541 536 struct workqueue_struct *wq; 537 + unsigned int dev_nack_retry_count; 542 538 }; 543 539 544 540 /**