[2/4] cdx: add sysfs for reset_all

Message ID 20230711121027.936487-3-abhijit.gangurde@amd.com
State New
Headers
Series cdx: provide sysfs interface for cdx device resources |

Commit Message

Gangurde, Abhijit July 11, 2023, 12:10 p.m. UTC
  Add sysfs for reset_all entry which resets 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>
---
 Documentation/ABI/testing/sysfs-bus-cdx | 11 ++++++++++
 drivers/cdx/cdx.c                       | 29 +++++++++++++++++++++++++
 2 files changed, 40 insertions(+)
  

Comments

Greg KH July 11, 2023, 1:59 p.m. UTC | #1
On Tue, Jul 11, 2023 at 05:40:25PM +0530, Abhijit Gangurde wrote:
> Add sysfs for reset_all entry which resets all the
> devices on the CDX bus.

On all CDX busses, right?  Why all?  Why not per-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>
> ---
>  Documentation/ABI/testing/sysfs-bus-cdx | 11 ++++++++++
>  drivers/cdx/cdx.c                       | 29 +++++++++++++++++++++++++
>  2 files changed, 40 insertions(+)
> 
> diff --git a/Documentation/ABI/testing/sysfs-bus-cdx b/Documentation/ABI/testing/sysfs-bus-cdx
> index 0afa85b3c63b..d9e00058471d 100644
> --- a/Documentation/ABI/testing/sysfs-bus-cdx
> +++ b/Documentation/ABI/testing/sysfs-bus-cdx
> @@ -22,6 +22,17 @@ Description:
>  
>  		  # echo 0 > /sys/bus/cdx/enable
>  
> +What:		/sys/bus/cdx/reset_all
> +Date:		July 2023
> +Contact:	puneet.gupta@amd.com
> +Description:
> +		Writing y/1/on to this file resets all the devices
> +		present on the CDX bus
> +
> +		For example::
> +
> +		  # echo 1 > /sys/bus/cdx/reset_all

What does resetting a device mean will happen?

> +
>  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 48c493a43491..4d20047b55bb 100644
> --- a/drivers/cdx/cdx.c
> +++ b/drivers/cdx/cdx.c
> @@ -106,6 +106,11 @@ int cdx_dev_reset(struct device *dev)
>  }
>  EXPORT_SYMBOL_GPL(cdx_dev_reset);
>  
> +static int reset_cdx_device(struct device *dev, void *data)
> +{
> +	return cdx_dev_reset(dev);
> +}
> +
>  /**
>   * cdx_unregister_device - Unregister a CDX device
>   * @dev: CDX device
> @@ -433,9 +438,33 @@ static ssize_t rescan_store(const struct bus_type *bus,
>  }
>  static BUS_ATTR_WO(rescan);
>  
> +static ssize_t reset_all_store(const struct bus_type *bus,
> +			       const char *buf, size_t count)
> +{
> +	bool val;
> +	int ret;
> +
> +	if (kstrtobool(buf, &val) < 0)
> +		return -EINVAL;
> +
> +	if (!val)
> +		return -EINVAL;
> +
> +	/* Reset all the devices attached to cdx bus */
> +	ret = bus_for_each_dev(bus, NULL, NULL, reset_cdx_device);

No locking needed?


> +	if (ret) {
> +		pr_err("error in CDX bus reset\n");

What error?  For what device?  Put the error message in the reset
callback, not here, as you have no idea what device failed.

thanks,

greg k-h
  
Gangurde, Abhijit July 12, 2023, 1:22 p.m. UTC | #2
[AMD Official Use Only - General]

> > Add sysfs for reset_all entry which resets all the
> > devices on the CDX bus.
>
> On all CDX busses, right?  Why all?  Why not per-bus?
>

This was on similar line to bus enable/disable. Would extend this to support per bus in v2.

>
> >
> > 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>
> > ---
> >  Documentation/ABI/testing/sysfs-bus-cdx | 11 ++++++++++
> >  drivers/cdx/cdx.c                       | 29 +++++++++++++++++++++++++
> >  2 files changed, 40 insertions(+)
> >
> > diff --git a/Documentation/ABI/testing/sysfs-bus-cdx
> b/Documentation/ABI/testing/sysfs-bus-cdx
> > index 0afa85b3c63b..d9e00058471d 100644
> > --- a/Documentation/ABI/testing/sysfs-bus-cdx
> > +++ b/Documentation/ABI/testing/sysfs-bus-cdx
> > @@ -22,6 +22,17 @@ Description:
> >
> >               # echo 0 > /sys/bus/cdx/enable
> >
> > +What:              /sys/bus/cdx/reset_all
> > +Date:              July 2023
> > +Contact:   puneet.gupta@amd.com
> > +Description:
> > +           Writing y/1/on to this file resets all the devices
> > +           present on the CDX bus
> > +
> > +           For example::
> > +
> > +             # echo 1 > /sys/bus/cdx/reset_all
>
> What does resetting a device mean will happen?

It would be same of pcie flr to the device. Would add more description in v2.

>
> > +
> >  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 48c493a43491..4d20047b55bb 100644
> > --- a/drivers/cdx/cdx.c
> > +++ b/drivers/cdx/cdx.c
> > @@ -106,6 +106,11 @@ int cdx_dev_reset(struct device *dev)
> >  }
> >  EXPORT_SYMBOL_GPL(cdx_dev_reset);
> >
> > +static int reset_cdx_device(struct device *dev, void *data)
> > +{
> > +   return cdx_dev_reset(dev);
> > +}
> > +
> >  /**
> >   * cdx_unregister_device - Unregister a CDX device
> >   * @dev: CDX device
> > @@ -433,9 +438,33 @@ static ssize_t rescan_store(const struct bus_type
> *bus,
> >  }
> >  static BUS_ATTR_WO(rescan);
> >
> > +static ssize_t reset_all_store(const struct bus_type *bus,
> > +                          const char *buf, size_t count)
> > +{
> > +   bool val;
> > +   int ret;
> > +
> > +   if (kstrtobool(buf, &val) < 0)
> > +           return -EINVAL;
> > +
> > +   if (!val)
> > +           return -EINVAL;
> > +
> > +   /* Reset all the devices attached to cdx bus */
> > +   ret = bus_for_each_dev(bus, NULL, NULL, reset_cdx_device);
>
> No locking needed?

Would protect this with  a lock.

>
> > +   if (ret) {
> > +           pr_err("error in CDX bus reset\n");
>
> What error?  For what device?  Put the error message in the reset
> callback, not here, as you have no idea what device failed.

Would correct in v2.

Thanks,
Abhijit
  

Patch

diff --git a/Documentation/ABI/testing/sysfs-bus-cdx b/Documentation/ABI/testing/sysfs-bus-cdx
index 0afa85b3c63b..d9e00058471d 100644
--- a/Documentation/ABI/testing/sysfs-bus-cdx
+++ b/Documentation/ABI/testing/sysfs-bus-cdx
@@ -22,6 +22,17 @@  Description:
 
 		  # echo 0 > /sys/bus/cdx/enable
 
+What:		/sys/bus/cdx/reset_all
+Date:		July 2023
+Contact:	puneet.gupta@amd.com
+Description:
+		Writing y/1/on to this file resets all the devices
+		present on the CDX bus
+
+		For example::
+
+		  # echo 1 > /sys/bus/cdx/reset_all
+
 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 48c493a43491..4d20047b55bb 100644
--- a/drivers/cdx/cdx.c
+++ b/drivers/cdx/cdx.c
@@ -106,6 +106,11 @@  int cdx_dev_reset(struct device *dev)
 }
 EXPORT_SYMBOL_GPL(cdx_dev_reset);
 
+static int reset_cdx_device(struct device *dev, void *data)
+{
+	return cdx_dev_reset(dev);
+}
+
 /**
  * cdx_unregister_device - Unregister a CDX device
  * @dev: CDX device
@@ -433,9 +438,33 @@  static ssize_t rescan_store(const struct bus_type *bus,
 }
 static BUS_ATTR_WO(rescan);
 
+static ssize_t reset_all_store(const struct bus_type *bus,
+			       const char *buf, size_t count)
+{
+	bool val;
+	int ret;
+
+	if (kstrtobool(buf, &val) < 0)
+		return -EINVAL;
+
+	if (!val)
+		return -EINVAL;
+
+	/* Reset all the devices attached to cdx bus */
+	ret = bus_for_each_dev(bus, NULL, NULL, reset_cdx_device);
+	if (ret) {
+		pr_err("error in CDX bus reset\n");
+		return 0;
+	}
+
+	return count;
+}
+static BUS_ATTR_WO(reset_all);
+
 static struct attribute *cdx_bus_attrs[] = {
 	&bus_attr_enable.attr,
 	&bus_attr_rescan.attr,
+	&bus_attr_reset_all.attr,
 	NULL,
 };
 ATTRIBUTE_GROUPS(cdx_bus);