From: Abhijit Gangurde <abhijit.gangurde@amd.com>
To: <gregkh@linuxfoundation.org>, <masahiroy@kernel.org>,
<linux-kernel@vger.kernel.org>
Cc: <Nipun.Gupta@amd.com>, <nikhil.agarwal@amd.com>,
<puneet.gupta@amd.com>, <git@amd.com>, <michal.simek@amd.com>,
Abhijit Gangurde <abhijit.gangurde@amd.com>,
Nipun Gupta <nipun.gupta@amd.com>,
"Pieter Jansen van Vuuren" <pieter.jansen-van-vuuren@amd.com>
Subject: [PATCH v5 4/5] cdx: add sysfs for bus reset
Date: Fri, 22 Sep 2023 15:48:27 +0530 [thread overview]
Message-ID: <20230922101828.33456-5-abhijit.gangurde@amd.com> (raw)
In-Reply-To: <20230922101828.33456-1-abhijit.gangurde@amd.com>
Add sysfs interface reset to reset all the devices on the CDX bus.
Co-developed-by: Puneet Gupta <puneet.gupta@amd.com>
Signed-off-by: Puneet Gupta <puneet.gupta@amd.com>
Co-developed-by: Nipun Gupta <nipun.gupta@amd.com>
Signed-off-by: Nipun Gupta <nipun.gupta@amd.com>
Signed-off-by: Abhijit Gangurde <abhijit.gangurde@amd.com>
Reviewed-by: Pieter Jansen van Vuuren <pieter.jansen-van-vuuren@amd.com>
Tested-by: Nikhil Agarwal <nikhil.agarwal@amd.com>
---
Changes in v5:
- None
Changes in v4:
- None
Changes in v3:
- None
Changes in v2:
- Improve documentation
- sysfs entry reset takes bus number as an argument
Documentation/ABI/testing/sysfs-bus-cdx | 15 +++++++++
drivers/cdx/cdx.c | 41 +++++++++++++++++++++++++
2 files changed, 56 insertions(+)
diff --git a/Documentation/ABI/testing/sysfs-bus-cdx b/Documentation/ABI/testing/sysfs-bus-cdx
index 04c8dfe7e201..d25875359741 100644
--- a/Documentation/ABI/testing/sysfs-bus-cdx
+++ b/Documentation/ABI/testing/sysfs-bus-cdx
@@ -38,6 +38,21 @@ Description:
# echo 00 > /sys/bus/cdx/disable
+What: /sys/bus/cdx/reset
+Date: July 2023
+Contact: puneet.gupta@amd.com
+Description:
+ Writing bus number in hex to this file will attempt to reset
+ all the devices present on the bus. Resetting a device would
+ clear all existing configuration of the device and put the
+ device in default state. The bus number for the cdx devices can
+ be found at /sys/bus/cdx/devices/cdx-BB:DD, where BB denotes
+ the bus number for the respective device.
+
+ For example ::
+
+ # echo 00 > /sys/bus/cdx/reset
+
What: /sys/bus/cdx/devices/.../vendor
Date: March 2023
Contact: nipun.gupta@amd.com
diff --git a/drivers/cdx/cdx.c b/drivers/cdx/cdx.c
index 8da043756fa4..7687b9371210 100644
--- a/drivers/cdx/cdx.c
+++ b/drivers/cdx/cdx.c
@@ -114,6 +114,26 @@ int cdx_dev_reset(struct device *dev)
}
EXPORT_SYMBOL_GPL(cdx_dev_reset);
+/**
+ * reset_cdx_device - Reset a CDX device
+ * @dev: CDX device
+ * @data: Bus number
+ * If bus number matches to the device's bus then this device
+ * is reset else this is no op.
+ *
+ * Return: -errno on failure, 0 on success.
+ */
+static int reset_cdx_device(struct device *dev, void *data)
+{
+ struct cdx_device *cdx_dev = to_cdx_device(dev);
+ u8 bus_num = *((u8 *)data);
+
+ if (cdx_dev->bus_num == bus_num)
+ return cdx_dev_reset(dev);
+
+ return 0;
+}
+
/**
* cdx_unregister_device - Unregister a CDX device
* @dev: CDX device
@@ -520,10 +540,31 @@ static ssize_t rescan_store(const struct bus_type *bus,
}
static BUS_ATTR_WO(rescan);
+static ssize_t bus_reset_store(const struct bus_type *bus,
+ const char *buf, size_t count)
+{
+ u8 bus_id;
+ int ret;
+
+ if (kstrtou8(buf, 16, &bus_id))
+ return -EINVAL;
+
+ bus_id = BUS_ID(bus_id);
+ mutex_lock(&cdx_controller_lock);
+ /* Reset all the devices attached to cdx bus */
+ ret = bus_for_each_dev(bus, NULL, (void *)&bus_id, reset_cdx_device);
+ mutex_unlock(&cdx_controller_lock);
+
+ return ret < 0 ? ret : count;
+}
+static struct bus_attribute bus_attr_reset = __ATTR(reset, 0200, NULL,
+ bus_reset_store);
+
static struct attribute *cdx_bus_attrs[] = {
&bus_attr_enable.attr,
&bus_attr_disable.attr,
&bus_attr_rescan.attr,
+ &bus_attr_reset.attr,
NULL,
};
ATTRIBUTE_GROUPS(cdx_bus);
--
2.25.1
next prev parent reply other threads:[~2023-09-22 10:20 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-22 10:18 [PATCH v5 0/5] cdx: provide sysfs interface for cdx device resources Abhijit Gangurde
2023-09-22 10:18 ` [PATCH v5 1/5] cdx: Remove cdx controller list from cdx bus system Abhijit Gangurde
2023-09-22 10:18 ` [PATCH v5 2/5] cdx: Introduce lock to protect controller ops Abhijit Gangurde
2023-09-22 10:18 ` [PATCH v5 3/5] cdx: add support for bus enable and disable Abhijit Gangurde
2023-09-26 10:05 ` Greg KH
2023-10-05 11:30 ` Gangurde, Abhijit
2023-09-22 10:18 ` Abhijit Gangurde [this message]
2023-09-22 10:18 ` [PATCH v5 5/5] cdx: add sysfs for subsystem, class and revision Abhijit Gangurde
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=20230922101828.33456-5-abhijit.gangurde@amd.com \
--to=abhijit.gangurde@amd.com \
--cc=Nipun.Gupta@amd.com \
--cc=git@amd.com \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=masahiroy@kernel.org \
--cc=michal.simek@amd.com \
--cc=nikhil.agarwal@amd.com \
--cc=pieter.jansen-van-vuuren@amd.com \
--cc=puneet.gupta@amd.com \
/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
all inboxes | Powered by JetHome®