diff mbox series

[v2,2/2] vfio/fsl-mc: Add per device reset support

Message ID 20210922110530.24736-2-diana.craciun@oss.nxp.com (mailing list archive)
State New, archived
Headers show
Series [v2,1/2] bus/fsl-mc: Add generic implementation for open/reset/close commands | expand

Commit Message

Diana Madalina Craciun Sept. 22, 2021, 11:05 a.m. UTC
Currently when a fsl-mc device is reset, the entire DPRC container
is reset which is very inefficient because the devices within a
container will be reset multiple times.
Add support for individually resetting a device.

Signed-off-by: Diana Craciun <diana.craciun@oss.nxp.com>
---
 drivers/vfio/fsl-mc/vfio_fsl_mc.c | 45 ++++++++++++++++++++-----------
 1 file changed, 30 insertions(+), 15 deletions(-)

Comments

Laurentiu Tudor Sept. 28, 2021, 1:55 p.m. UTC | #1
On 9/22/2021 2:05 PM, Diana Craciun wrote:
> Currently when a fsl-mc device is reset, the entire DPRC container
> is reset which is very inefficient because the devices within a
> container will be reset multiple times.
> Add support for individually resetting a device.
> 
> Signed-off-by: Diana Craciun <diana.craciun@oss.nxp.com>
> ---

Reviewed-by: Laurentiu Tudor <laurentiu.tudor@nxp.com>

---
Best Regards, Laurentiu

>  drivers/vfio/fsl-mc/vfio_fsl_mc.c | 45 ++++++++++++++++++++-----------
>  1 file changed, 30 insertions(+), 15 deletions(-)
> 
> diff --git a/drivers/vfio/fsl-mc/vfio_fsl_mc.c b/drivers/vfio/fsl-mc/vfio_fsl_mc.c
> index 0ead91bfa838..6d7b2d2571a2 100644
> --- a/drivers/vfio/fsl-mc/vfio_fsl_mc.c
> +++ b/drivers/vfio/fsl-mc/vfio_fsl_mc.c
> @@ -65,6 +65,34 @@ static void vfio_fsl_mc_regions_cleanup(struct vfio_fsl_mc_device *vdev)
>  	kfree(vdev->regions);
>  }
>  
> +static int vfio_fsl_mc_reset_device(struct vfio_fsl_mc_device *vdev)
> +{
> +	struct fsl_mc_device *mc_dev = vdev->mc_dev;
> +	int ret = 0;
> +
> +	if (is_fsl_mc_bus_dprc(vdev->mc_dev)) {
> +		return dprc_reset_container(mc_dev->mc_io, 0,
> +					mc_dev->mc_handle,
> +					mc_dev->obj_desc.id,
> +					DPRC_RESET_OPTION_NON_RECURSIVE);
> +	} else {
> +		u16 token;
> +
> +		ret = fsl_mc_obj_open(mc_dev->mc_io, 0, mc_dev->obj_desc.id,
> +				      mc_dev->obj_desc.type,
> +				      &token);
> +		if (ret)
> +			goto out;
> +		ret = fsl_mc_obj_reset(mc_dev->mc_io, 0, token);
> +		if (ret) {
> +			fsl_mc_obj_close(mc_dev->mc_io, 0, token);
> +			goto out;
> +		}
> +		ret = fsl_mc_obj_close(mc_dev->mc_io, 0, token);
> +	}
> +out:
> +	return ret;
> +}
>  
>  static void vfio_fsl_mc_close_device(struct vfio_device *core_vdev)
>  {
> @@ -78,9 +106,7 @@ static void vfio_fsl_mc_close_device(struct vfio_device *core_vdev)
>  	vfio_fsl_mc_regions_cleanup(vdev);
>  
>  	/* reset the device before cleaning up the interrupts */
> -	ret = dprc_reset_container(mc_cont->mc_io, 0, mc_cont->mc_handle,
> -				   mc_cont->obj_desc.id,
> -				   DPRC_RESET_OPTION_NON_RECURSIVE);
> +	ret = vfio_fsl_mc_reset_device(vdev);
>  
>  	if (WARN_ON(ret))
>  		dev_warn(&mc_cont->dev,
> @@ -203,18 +229,7 @@ static long vfio_fsl_mc_ioctl(struct vfio_device *core_vdev,
>  	}
>  	case VFIO_DEVICE_RESET:
>  	{
> -		int ret;
> -		struct fsl_mc_device *mc_dev = vdev->mc_dev;
> -
> -		/* reset is supported only for the DPRC */
> -		if (!is_fsl_mc_bus_dprc(mc_dev))
> -			return -ENOTTY;
> -
> -		ret = dprc_reset_container(mc_dev->mc_io, 0,
> -					   mc_dev->mc_handle,
> -					   mc_dev->obj_desc.id,
> -					   DPRC_RESET_OPTION_NON_RECURSIVE);
> -		return ret;
> +		return vfio_fsl_mc_reset_device(vdev);
>  
>  	}
>  	default:
>
Alex Williamson Oct. 11, 2021, 10:19 p.m. UTC | #2
On Tue, 28 Sep 2021 16:55:06 +0300
Laurentiu Tudor <laurentiu.tudor@nxp.com> wrote:

> On 9/22/2021 2:05 PM, Diana Craciun wrote:
> > Currently when a fsl-mc device is reset, the entire DPRC container
> > is reset which is very inefficient because the devices within a
> > container will be reset multiple times.
> > Add support for individually resetting a device.
> > 
> > Signed-off-by: Diana Craciun <diana.craciun@oss.nxp.com>
> > ---  
> 
> Reviewed-by: Laurentiu Tudor <laurentiu.tudor@nxp.com>

Applied both to vfio next branch for v5.16, with Laurentiu's R-b added
here.  Thanks,

Alex
diff mbox series

Patch

diff --git a/drivers/vfio/fsl-mc/vfio_fsl_mc.c b/drivers/vfio/fsl-mc/vfio_fsl_mc.c
index 0ead91bfa838..6d7b2d2571a2 100644
--- a/drivers/vfio/fsl-mc/vfio_fsl_mc.c
+++ b/drivers/vfio/fsl-mc/vfio_fsl_mc.c
@@ -65,6 +65,34 @@  static void vfio_fsl_mc_regions_cleanup(struct vfio_fsl_mc_device *vdev)
 	kfree(vdev->regions);
 }
 
+static int vfio_fsl_mc_reset_device(struct vfio_fsl_mc_device *vdev)
+{
+	struct fsl_mc_device *mc_dev = vdev->mc_dev;
+	int ret = 0;
+
+	if (is_fsl_mc_bus_dprc(vdev->mc_dev)) {
+		return dprc_reset_container(mc_dev->mc_io, 0,
+					mc_dev->mc_handle,
+					mc_dev->obj_desc.id,
+					DPRC_RESET_OPTION_NON_RECURSIVE);
+	} else {
+		u16 token;
+
+		ret = fsl_mc_obj_open(mc_dev->mc_io, 0, mc_dev->obj_desc.id,
+				      mc_dev->obj_desc.type,
+				      &token);
+		if (ret)
+			goto out;
+		ret = fsl_mc_obj_reset(mc_dev->mc_io, 0, token);
+		if (ret) {
+			fsl_mc_obj_close(mc_dev->mc_io, 0, token);
+			goto out;
+		}
+		ret = fsl_mc_obj_close(mc_dev->mc_io, 0, token);
+	}
+out:
+	return ret;
+}
 
 static void vfio_fsl_mc_close_device(struct vfio_device *core_vdev)
 {
@@ -78,9 +106,7 @@  static void vfio_fsl_mc_close_device(struct vfio_device *core_vdev)
 	vfio_fsl_mc_regions_cleanup(vdev);
 
 	/* reset the device before cleaning up the interrupts */
-	ret = dprc_reset_container(mc_cont->mc_io, 0, mc_cont->mc_handle,
-				   mc_cont->obj_desc.id,
-				   DPRC_RESET_OPTION_NON_RECURSIVE);
+	ret = vfio_fsl_mc_reset_device(vdev);
 
 	if (WARN_ON(ret))
 		dev_warn(&mc_cont->dev,
@@ -203,18 +229,7 @@  static long vfio_fsl_mc_ioctl(struct vfio_device *core_vdev,
 	}
 	case VFIO_DEVICE_RESET:
 	{
-		int ret;
-		struct fsl_mc_device *mc_dev = vdev->mc_dev;
-
-		/* reset is supported only for the DPRC */
-		if (!is_fsl_mc_bus_dprc(mc_dev))
-			return -ENOTTY;
-
-		ret = dprc_reset_container(mc_dev->mc_io, 0,
-					   mc_dev->mc_handle,
-					   mc_dev->obj_desc.id,
-					   DPRC_RESET_OPTION_NON_RECURSIVE);
-		return ret;
+		return vfio_fsl_mc_reset_device(vdev);
 
 	}
 	default: