diff mbox series

[2/9] vfio/fsl-mc: Scan DPRC objects on vfio-fsl-mc driver bind

Message ID 20200323171911.27178-3-diana.craciun@oss.nxp.com (mailing list archive)
State New, archived
Headers show
Series vfio/fsl-mc: VFIO support for FSL-MC devices | expand

Commit Message

Diana Madalina Craciun March 23, 2020, 5:19 p.m. UTC
The DPRC (Data Path Resource Container) device is a bus device and has
child devices attached to it. When the vfio-fsl-mc driver is probed
the DPRC is scanned and the child devices discovered and initialized.

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

Comments

kernel test robot March 24, 2020, 12:32 a.m. UTC | #1
Hi Diana,

I love your patch! Yet something to improve:

[auto build test ERROR on arm-soc/for-next]
[also build test ERROR on linus/master vfio/next v5.6-rc7 next-20200323]
[if your patch is applied to the wrong git tree, please drop us a note to help
improve the system. BTW, we also suggest to use '--base' option to specify the
base tree in git format-patch, please see https://stackoverflow.com/a/37406982]

url:    https://github.com/0day-ci/linux/commits/Diana-Craciun/vfio-fsl-mc-VFIO-support-for-FSL-MC-devices/20200324-052843
base:   https://git.kernel.org/pub/scm/linux/kernel/git/arm/arm-soc.git for-next
config: i386-allyesconfig (attached as .config)
compiler: gcc-7 (Debian 7.5.0-5) 7.5.0
reproduce:
        # save the attached .config to linux build tree
        make ARCH=i386 

If you fix the issue, kindly add following tag
Reported-by: kbuild test robot <lkp@intel.com>

All errors (new ones prefixed by >>):

   drivers/vfio/fsl-mc/vfio_fsl_mc.c: In function 'vfio_fsl_mc_init_device':
>> drivers/vfio/fsl-mc/vfio_fsl_mc.c:91:8: error: implicit declaration of function 'dprc_setup'; did you mean 'x2apic_setup'? [-Werror=implicit-function-declaration]
     ret = dprc_setup(mc_dev);
           ^~~~~~~~~~
           x2apic_setup
>> drivers/vfio/fsl-mc/vfio_fsl_mc.c:97:8: error: implicit declaration of function 'dprc_scan_container'; did you mean 'init_section_contains'? [-Werror=implicit-function-declaration]
     ret = dprc_scan_container(mc_dev, mc_dev->driver_override, false);
           ^~~~~~~~~~~~~~~~~~~
           init_section_contains
>> drivers/vfio/fsl-mc/vfio_fsl_mc.c:97:42: error: 'struct fsl_mc_device' has no member named 'driver_override'
     ret = dprc_scan_container(mc_dev, mc_dev->driver_override, false);
                                             ^~
>> drivers/vfio/fsl-mc/vfio_fsl_mc.c:100:3: error: implicit declaration of function 'dprc_cleanup'; did you mean 'pud_clear'? [-Werror=implicit-function-declaration]
      dprc_cleanup(mc_dev);
      ^~~~~~~~~~~~
      pud_clear
   drivers/vfio/fsl-mc/vfio_fsl_mc.c: In function 'vfio_fsl_mc_device_remove':
   drivers/vfio/fsl-mc/vfio_fsl_mc.c:161:14: error: 'struct fsl_mc_device' has no member named 'driver_override'
     kfree(mc_dev->driver_override);
                 ^~
   drivers/vfio/fsl-mc/vfio_fsl_mc.c:162:8: error: 'struct fsl_mc_device' has no member named 'driver_override'
     mc_dev->driver_override = NULL;
           ^~
   cc1: some warnings being treated as errors

vim +91 drivers/vfio/fsl-mc/vfio_fsl_mc.c

    76	
    77	static int vfio_fsl_mc_init_device(struct vfio_fsl_mc_device *vdev)
    78	{
    79		struct fsl_mc_device *mc_dev = vdev->mc_dev;
    80		int ret = 0;
    81	
    82		/* Non-dprc devices share mc_io from parent */
    83		if (!is_fsl_mc_bus_dprc(mc_dev)) {
    84			struct fsl_mc_device *mc_cont = to_fsl_mc_device(mc_dev->dev.parent);
    85	
    86			mc_dev->mc_io = mc_cont->mc_io;
    87			return 0;
    88		}
    89	
    90		/* open DPRC, allocate a MC portal */
  > 91		ret = dprc_setup(mc_dev);
    92		if (ret < 0) {
    93			dev_err(&mc_dev->dev, "Failed to setup DPRC (error = %d)\n", ret);
    94			return ret;
    95		}
    96	
  > 97		ret = dprc_scan_container(mc_dev, mc_dev->driver_override, false);
    98		if (ret < 0) {
    99			dev_err(&mc_dev->dev, "Container scanning failed: %d\n", ret);
 > 100			dprc_cleanup(mc_dev);
   101		}
   102	
   103		return 0;
   104	}
   105	static const struct vfio_device_ops vfio_fsl_mc_ops = {
   106		.name		= "vfio-fsl-mc",
   107		.open		= vfio_fsl_mc_open,
   108		.release	= vfio_fsl_mc_release,
   109		.ioctl		= vfio_fsl_mc_ioctl,
   110		.read		= vfio_fsl_mc_read,
   111		.write		= vfio_fsl_mc_write,
   112		.mmap		= vfio_fsl_mc_mmap,
   113	};
   114	

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
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 320fb09b5691..5cc533808bc1 100644
--- a/drivers/vfio/fsl-mc/vfio_fsl_mc.c
+++ b/drivers/vfio/fsl-mc/vfio_fsl_mc.c
@@ -74,6 +74,34 @@  static int vfio_fsl_mc_mmap(void *device_data, struct vm_area_struct *vma)
 	return -EINVAL;
 }
 
+static int vfio_fsl_mc_init_device(struct vfio_fsl_mc_device *vdev)
+{
+	struct fsl_mc_device *mc_dev = vdev->mc_dev;
+	int ret = 0;
+
+	/* Non-dprc devices share mc_io from parent */
+	if (!is_fsl_mc_bus_dprc(mc_dev)) {
+		struct fsl_mc_device *mc_cont = to_fsl_mc_device(mc_dev->dev.parent);
+
+		mc_dev->mc_io = mc_cont->mc_io;
+		return 0;
+	}
+
+	/* open DPRC, allocate a MC portal */
+	ret = dprc_setup(mc_dev);
+	if (ret < 0) {
+		dev_err(&mc_dev->dev, "Failed to setup DPRC (error = %d)\n", ret);
+		return ret;
+	}
+
+	ret = dprc_scan_container(mc_dev, mc_dev->driver_override, false);
+	if (ret < 0) {
+		dev_err(&mc_dev->dev, "Container scanning failed: %d\n", ret);
+		dprc_cleanup(mc_dev);
+	}
+
+	return 0;
+}
 static const struct vfio_device_ops vfio_fsl_mc_ops = {
 	.name		= "vfio-fsl-mc",
 	.open		= vfio_fsl_mc_open,
@@ -112,9 +140,42 @@  static int vfio_fsl_mc_probe(struct fsl_mc_device *mc_dev)
 		return ret;
 	}
 
+	ret = vfio_fsl_mc_init_device(vdev);
+	if (ret) {
+		vfio_iommu_group_put(group, dev);
+		return ret;
+	}
+
 	return ret;
 }
 
+static int vfio_fsl_mc_device_remove(struct device *dev, void *data)
+{
+	struct fsl_mc_device *mc_dev;
+
+	WARN_ON(!dev);
+	mc_dev = to_fsl_mc_device(dev);
+	if (WARN_ON(!mc_dev))
+		return -ENODEV;
+
+	kfree(mc_dev->driver_override);
+	mc_dev->driver_override = NULL;
+
+	/*
+	 * The device-specific remove callback will get invoked by device_del()
+	 */
+	device_del(&mc_dev->dev);
+	put_device(&mc_dev->dev);
+
+	return 0;
+}
+
+static void vfio_fsl_mc_cleanup_dprc(struct fsl_mc_device *mc_dev)
+{
+	device_for_each_child(&mc_dev->dev, NULL, vfio_fsl_mc_device_remove);
+	dprc_cleanup(mc_dev);
+}
+
 static int vfio_fsl_mc_remove(struct fsl_mc_device *mc_dev)
 {
 	struct vfio_fsl_mc_device *vdev;
@@ -124,6 +185,11 @@  static int vfio_fsl_mc_remove(struct fsl_mc_device *mc_dev)
 	if (!vdev)
 		return -EINVAL;
 
+	if (is_fsl_mc_bus_dprc(mc_dev))
+		vfio_fsl_mc_cleanup_dprc(vdev->mc_dev);
+
+	mc_dev->mc_io = NULL;
+
 	vfio_iommu_group_put(mc_dev->dev.iommu_group, dev);
 	devm_kfree(dev, vdev);