[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20230826044944.4161017-5-abhijit.gangurde@amd.com>
Date: Sat, 26 Aug 2023 10:19:43 +0530
From: Abhijit Gangurde <abhijit.gangurde@....com>
To: <gregkh@...uxfoundation.org>, <masahiroy@...nel.org>,
<linux-kernel@...r.kernel.org>
CC: <Nipun.Gupta@....com>, <nikhil.agarwal@....com>,
<puneet.gupta@....com>, <git@....com>, <michal.simek@....com>,
Abhijit Gangurde <abhijit.gangurde@....com>,
Nipun Gupta <nipun.gupta@....com>,
"Pieter Jansen van Vuuren" <pieter.jansen-van-vuuren@....com>
Subject: [PATCH v4 4/5] cdx: add sysfs for bus reset
Add sysfs interface reset to reset all the devices on the CDX bus.
Co-developed-by: Puneet Gupta <puneet.gupta@....com>
Signed-off-by: Puneet Gupta <puneet.gupta@....com>
Co-developed-by: Nipun Gupta <nipun.gupta@....com>
Signed-off-by: Nipun Gupta <nipun.gupta@....com>
Signed-off-by: Abhijit Gangurde <abhijit.gangurde@....com>
Reviewed-by: Pieter Jansen van Vuuren <pieter.jansen-van-vuuren@....com>
Tested-by: Nikhil Agarwal <nikhil.agarwal@....com>
---
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@....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@....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
Powered by blists - more mailing lists