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

driver core: Add waiting_for_supplier sysfs file for devices

This would be useful to check if a device is not probing because it's
waiting for a supplier to be added and then linked to before it can
probe.

To reduce sysfs clutter, this file is added only if it can ever be 1.
So, if fw_devlink is disabled or set to permissive, this file is not
added. Also, this file is removed once the device probes as it's no
longer relevant.

Signed-off-by: Saravana Kannan <saravanak@google.com>
Link: https://lore.kernel.org/r/20200521191800.136035-4-saravanak@google.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Saravana Kannan and committed by
Greg Kroah-Hartman
da6d6475 8fd456ec

+43
+17
Documentation/ABI/testing/sysfs-devices-waiting_for_supplier
··· 1 + What: /sys/devices/.../waiting_for_supplier 2 + Date: May 2020 3 + Contact: Saravana Kannan <saravanak@google.com> 4 + Description: 5 + The /sys/devices/.../waiting_for_supplier attribute is only 6 + present when fw_devlink kernel command line option is enabled 7 + and is set to something stricter than "permissive". It is 8 + removed once a device probes successfully (because the 9 + information is no longer relevant). The number read from it (0 10 + or 1) reflects whether the device is waiting for one or more 11 + suppliers to be added and then linked to using device links 12 + before the device can probe. 13 + 14 + A value of 0 means the device is not waiting for any suppliers 15 + to be added before it can probe. A value of 1 means the device 16 + is waiting for one or more suppliers to be added before it can 17 + probe.
+26
drivers/base/core.c
··· 1041 1041 kref_put(&link->kref, __device_link_del); 1042 1042 } 1043 1043 1044 + static ssize_t waiting_for_supplier_show(struct device *dev, 1045 + struct device_attribute *attr, 1046 + char *buf) 1047 + { 1048 + bool val; 1049 + 1050 + device_lock(dev); 1051 + mutex_lock(&wfs_lock); 1052 + val = !list_empty(&dev->links.needs_suppliers) 1053 + && dev->links.need_for_probe; 1054 + mutex_unlock(&wfs_lock); 1055 + device_unlock(dev); 1056 + return sprintf(buf, "%u\n", val); 1057 + } 1058 + static DEVICE_ATTR_RO(waiting_for_supplier); 1059 + 1044 1060 /** 1045 1061 * device_links_driver_bound - Update device links after probing its driver. 1046 1062 * @dev: Device to update the links for. ··· 1081 1065 mutex_lock(&wfs_lock); 1082 1066 list_del_init(&dev->links.needs_suppliers); 1083 1067 mutex_unlock(&wfs_lock); 1068 + device_remove_file(dev, &dev_attr_waiting_for_supplier); 1084 1069 1085 1070 device_links_write_lock(); 1086 1071 ··· 2161 2144 goto err_remove_dev_groups; 2162 2145 } 2163 2146 2147 + if (fw_devlink_flags && !fw_devlink_is_permissive()) { 2148 + error = device_create_file(dev, &dev_attr_waiting_for_supplier); 2149 + if (error) 2150 + goto err_remove_dev_online; 2151 + } 2152 + 2164 2153 return 0; 2165 2154 2155 + err_remove_dev_online: 2156 + device_remove_file(dev, &dev_attr_online); 2166 2157 err_remove_dev_groups: 2167 2158 device_remove_groups(dev, dev->groups); 2168 2159 err_remove_type_groups: ··· 2188 2163 struct class *class = dev->class; 2189 2164 const struct device_type *type = dev->type; 2190 2165 2166 + device_remove_file(dev, &dev_attr_waiting_for_supplier); 2191 2167 device_remove_file(dev, &dev_attr_online); 2192 2168 device_remove_groups(dev, dev->groups); 2193 2169