From: Saravana Kannan <saravanak@google.com>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
"Rafael J. Wysocki" <rafael@kernel.org>
Cc: Saravana Kannan <saravanak@google.com>,
linux-kernel@vger.kernel.org,
John Stultz <john.stultz@linaro.org>,
kernel-team@android.com
Subject: [PATCH v3 3/3] driver core: Add waiting_for_supplier sysfs file for devices
Date: Thu, 21 May 2020 12:18:00 -0700 [thread overview]
Message-ID: <20200521191800.136035-4-saravanak@google.com> (raw)
In-Reply-To: <20200521191800.136035-1-saravanak@google.com>
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>
---
.../sysfs-devices-waiting_for_supplier | 17 ++++++++++++
drivers/base/core.c | 26 +++++++++++++++++++
2 files changed, 43 insertions(+)
create mode 100644 Documentation/ABI/testing/sysfs-devices-waiting_for_supplier
diff --git a/Documentation/ABI/testing/sysfs-devices-waiting_for_supplier b/Documentation/ABI/testing/sysfs-devices-waiting_for_supplier
new file mode 100644
index 000000000000..59d073d20db6
--- /dev/null
+++ b/Documentation/ABI/testing/sysfs-devices-waiting_for_supplier
@@ -0,0 +1,17 @@
+What: /sys/devices/.../waiting_for_supplier
+Date: May 2020
+Contact: Saravana Kannan <saravanak@google.com>
+Description:
+ The /sys/devices/.../waiting_for_supplier attribute is only
+ present when fw_devlink kernel command line option is enabled
+ and is set to something stricter than "permissive". It is
+ removed once a device probes successfully (because the
+ information is no longer relevant). The number read from it (0
+ or 1) reflects whether the device is waiting for one or more
+ suppliers to be added and then linked to using device links
+ before the device can probe.
+
+ A value of 0 means the device is not waiting for any suppliers
+ to be added before it can probe. A value of 1 means the device
+ is waiting for one or more suppliers to be added before it can
+ probe.
diff --git a/drivers/base/core.c b/drivers/base/core.c
index 81c8ef088d3a..dfd4e94ef790 100644
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -1033,6 +1033,22 @@ static void device_link_drop_managed(struct device_link *link)
kref_put(&link->kref, __device_link_del);
}
+static ssize_t waiting_for_supplier_show(struct device *dev,
+ struct device_attribute *attr,
+ char *buf)
+{
+ bool val;
+
+ device_lock(dev);
+ mutex_lock(&wfs_lock);
+ val = !list_empty(&dev->links.needs_suppliers)
+ && dev->links.need_for_probe;
+ mutex_unlock(&wfs_lock);
+ device_unlock(dev);
+ return sprintf(buf, "%u\n", val);
+}
+static DEVICE_ATTR_RO(waiting_for_supplier);
+
/**
* device_links_driver_bound - Update device links after probing its driver.
* @dev: Device to update the links for.
@@ -1057,6 +1073,7 @@ void device_links_driver_bound(struct device *dev)
mutex_lock(&wfs_lock);
list_del_init(&dev->links.needs_suppliers);
mutex_unlock(&wfs_lock);
+ device_remove_file(dev, &dev_attr_waiting_for_supplier);
device_links_write_lock();
@@ -2126,8 +2143,16 @@ static int device_add_attrs(struct device *dev)
goto err_remove_dev_groups;
}
+ if (fw_devlink_flags && !fw_devlink_is_permissive()) {
+ error = device_create_file(dev, &dev_attr_waiting_for_supplier);
+ if (error)
+ goto err_remove_dev_online;
+ }
+
return 0;
+ err_remove_dev_online:
+ device_remove_file(dev, &dev_attr_online);
err_remove_dev_groups:
device_remove_groups(dev, dev->groups);
err_remove_type_groups:
@@ -2145,6 +2170,7 @@ static void device_remove_attrs(struct device *dev)
struct class *class = dev->class;
const struct device_type *type = dev->type;
+ device_remove_file(dev, &dev_attr_waiting_for_supplier);
device_remove_file(dev, &dev_attr_online);
device_remove_groups(dev, dev->groups);
--
2.27.0.rc0.183.gde8f92d652-goog
next prev parent reply other threads:[~2020-05-21 19:18 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-05-21 19:17 [PATCH v3 0/3] driver core: Add device link related sysfs files Saravana Kannan
2020-05-21 19:17 ` [PATCH v3 1/3] driver core: Expose device link details in sysfs Saravana Kannan
2020-07-15 22:13 ` Guenter Roeck
2020-07-15 22:36 ` Saravana Kannan
2020-05-21 19:17 ` [PATCH v3 2/3] driver core: Add state_synced sysfs file for devices that support it Saravana Kannan
2020-05-21 19:18 ` Saravana Kannan [this message]
2020-05-28 21:18 ` [PATCH v3 0/3] driver core: Add device link related sysfs files Saravana Kannan
2020-05-29 12:30 ` Greg Kroah-Hartman
2020-06-17 3:45 ` Saravana Kannan
2020-07-06 22:45 ` Saravana Kannan
2020-07-10 13:23 ` Greg Kroah-Hartman
2020-07-10 20:39 ` Saravana Kannan
[not found] ` <CGME20200715082233eucas1p261d4c5133226b800c3656c9010aa5940@eucas1p2.samsung.com>
2020-07-15 8:22 ` Marek Szyprowski
2020-07-15 8:53 ` Saravana Kannan
2020-07-15 9:02 ` Marek Szyprowski
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200521191800.136035-4-saravanak@google.com \
--to=saravanak@google.com \
--cc=gregkh@linuxfoundation.org \
--cc=john.stultz@linaro.org \
--cc=kernel-team@android.com \
--cc=linux-kernel@vger.kernel.org \
--cc=rafael@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).