Skip to content

Commit da6d647

Browse files
Saravana Kannangregkh
authored andcommitted
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 <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 8fd456e commit da6d647

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
What: /sys/devices/.../waiting_for_supplier
2+
Date: May 2020
3+
Contact: Saravana Kannan <[email protected]>
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.

drivers/base/core.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1041,6 +1041,22 @@ static void device_link_drop_managed(struct device_link *link)
10411041
kref_put(&link->kref, __device_link_del);
10421042
}
10431043

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+
10441060
/**
10451061
* device_links_driver_bound - Update device links after probing its driver.
10461062
* @dev: Device to update the links for.
@@ -1065,6 +1081,7 @@ void device_links_driver_bound(struct device *dev)
10651081
mutex_lock(&wfs_lock);
10661082
list_del_init(&dev->links.needs_suppliers);
10671083
mutex_unlock(&wfs_lock);
1084+
device_remove_file(dev, &dev_attr_waiting_for_supplier);
10681085

10691086
device_links_write_lock();
10701087

@@ -2144,8 +2161,16 @@ static int device_add_attrs(struct device *dev)
21442161
goto err_remove_dev_groups;
21452162
}
21462163

2164+
if (fw_devlink_flags && !fw_devlink_is_permissive()) {
2165+
error = device_create_file(dev, &dev_attr_waiting_for_supplier);
2166+
if (error)
2167+
goto err_remove_dev_online;
2168+
}
2169+
21472170
return 0;
21482171

2172+
err_remove_dev_online:
2173+
device_remove_file(dev, &dev_attr_online);
21492174
err_remove_dev_groups:
21502175
device_remove_groups(dev, dev->groups);
21512176
err_remove_type_groups:
@@ -2163,6 +2188,7 @@ static void device_remove_attrs(struct device *dev)
21632188
struct class *class = dev->class;
21642189
const struct device_type *type = dev->type;
21652190

2191+
device_remove_file(dev, &dev_attr_waiting_for_supplier);
21662192
device_remove_file(dev, &dev_attr_online);
21672193
device_remove_groups(dev, dev->groups);
21682194

0 commit comments

Comments
 (0)