Skip to content

Commit 0174f58

Browse files
abhijitG-xlnxgregkh
authored andcommitted
cdx: add sysfs for bus reset
Add sysfs interface reset to reset all the devices on the CDX bus. Signed-off-by: Abhijit Gangurde <abhijit.gangurde@amd.com> Link: https://lore.kernel.org/r/20231017160505.10640-7-abhijit.gangurde@amd.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent e3cfd49 commit 0174f58

File tree

2 files changed

+26
-8
lines changed

2 files changed

+26
-8
lines changed

Documentation/ABI/testing/sysfs-bus-cdx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,10 @@ What: /sys/bus/cdx/devices/.../reset
4545
Date: March 2023
4646
Contact: nipun.gupta@amd.com
4747
Description:
48-
Writing y/1/on to this file resets the CDX device.
49-
On resetting the device, the corresponding driver is notified
50-
twice, once before the device is being reset, and again after
51-
the reset has been complete.
48+
Writing y/1/on to this file resets the CDX device or all devices
49+
on the bus. On resetting the device, the corresponding driver is
50+
notified twice, once before the device is being reset, and again
51+
after the reset has been complete.
5252

5353
For example::
5454

drivers/cdx/cdx.c

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,20 @@ int cdx_dev_reset(struct device *dev)
110110
}
111111
EXPORT_SYMBOL_GPL(cdx_dev_reset);
112112

113+
/**
114+
* reset_cdx_device - Reset a CDX device
115+
* @dev: CDX device
116+
* @data: This is always passed as NULL, and is not used in this API,
117+
* but is required here as the device_for_each_child() API expects
118+
* the passed function to have this as an argument.
119+
*
120+
* Return: -errno on failure, 0 on success.
121+
*/
122+
static int reset_cdx_device(struct device *dev, void *data)
123+
{
124+
return cdx_dev_reset(dev);
125+
}
126+
113127
/**
114128
* cdx_unregister_device - Unregister a CDX device
115129
* @dev: CDX device
@@ -343,6 +357,7 @@ static DEVICE_ATTR_WO(remove);
343357
static ssize_t reset_store(struct device *dev, struct device_attribute *attr,
344358
const char *buf, size_t count)
345359
{
360+
struct cdx_device *cdx_dev = to_cdx_device(dev);
346361
bool val;
347362
int ret;
348363

@@ -352,11 +367,13 @@ static ssize_t reset_store(struct device *dev, struct device_attribute *attr,
352367
if (!val)
353368
return -EINVAL;
354369

355-
ret = cdx_dev_reset(dev);
356-
if (ret)
357-
return ret;
370+
if (cdx_dev->is_bus)
371+
/* Reset all the devices attached to cdx bus */
372+
ret = device_for_each_child(dev, NULL, reset_cdx_device);
373+
else
374+
ret = cdx_dev_reset(dev);
358375

359-
return count;
376+
return ret < 0 ? ret : count;
360377
}
361378
static DEVICE_ATTR_WO(reset);
362379

@@ -461,6 +478,7 @@ static const struct attribute_group cdx_dev_group = {
461478

462479
static struct attribute *cdx_bus_dev_attrs[] = {
463480
&dev_attr_enable.attr,
481+
&dev_attr_reset.attr,
464482
NULL,
465483
};
466484

0 commit comments

Comments
 (0)