[PATCH 2/2] staging: fsl-mc: do not print error in case of defer probe error

2017-12-06 Thread Nipun Gupta
Signed-off-by: Nipun Gupta 
---
 drivers/staging/fsl-mc/bus/fsl-mc-bus.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/staging/fsl-mc/bus/fsl-mc-bus.c 
b/drivers/staging/fsl-mc/bus/fsl-mc-bus.c
index 409f2b9..10cee00 100644
--- a/drivers/staging/fsl-mc/bus/fsl-mc-bus.c
+++ b/drivers/staging/fsl-mc/bus/fsl-mc-bus.c
@@ -171,7 +171,8 @@ static int fsl_mc_driver_probe(struct device *dev)
 
error = mc_drv->probe(mc_dev);
if (error < 0) {
-   dev_err(dev, "%s failed: %d\n", __func__, error);
+   if (error != -EPROBE_DEFER)
+   dev_err(dev, "%s failed: %d\n", __func__, error);
return error;
}
 
-- 
1.9.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 1/2] staging: fsl-mc: Allocate IRQ's before scanning DPRC objects

2017-12-06 Thread Nipun Gupta
When DPRC probing is deferred (such as where IOMMU is not probed
before the fsl-mc bus), all the devices in the DPRC containers gets
initialized one after another. As IRQ's were allocated only once the
DPRC scanning is completed, the devices like DPIO which uses these
IRQ's at initalization fails. This patch allocates the IRQ resources
before scanning all the objects in the DPRC container.

Signed-off-by: Nipun Gupta 
---
 drivers/staging/fsl-mc/bus/dprc-driver.c | 49 ++--
 1 file changed, 27 insertions(+), 22 deletions(-)

diff --git a/drivers/staging/fsl-mc/bus/dprc-driver.c 
b/drivers/staging/fsl-mc/bus/dprc-driver.c
index 06df528..7265431 100644
--- a/drivers/staging/fsl-mc/bus/dprc-driver.c
+++ b/drivers/staging/fsl-mc/bus/dprc-driver.c
@@ -206,7 +206,8 @@ static void dprc_add_new_devices(struct fsl_mc_device 
*mc_bus_dev,
  * dprc_scan_objects - Discover objects in a DPRC
  *
  * @mc_bus_dev: pointer to the fsl-mc device that represents a DPRC object
- * @total_irq_count: total number of IRQs needed by objects in the DPRC.
+ * @total_irq_count: If argument is provided the function populates the
+ * total number of IRQs created by objects in the DPRC.
  *
  * Detects objects added and removed from a DPRC and synchronizes the
  * state of the Linux bus driver, MC by adding and removing
@@ -228,6 +229,7 @@ static int dprc_scan_objects(struct fsl_mc_device 
*mc_bus_dev,
int error;
unsigned int irq_count = mc_bus_dev->obj_desc.irq_count;
struct fsl_mc_obj_desc *child_obj_desc_array = NULL;
+   struct fsl_mc_bus *mc_bus = to_fsl_mc_bus(mc_bus_dev);
 
error = dprc_get_obj_count(mc_bus_dev->mc_io,
   0,
@@ -297,7 +299,26 @@ static int dprc_scan_objects(struct fsl_mc_device 
*mc_bus_dev,
}
}
 
-   *total_irq_count = irq_count;
+   /*
+* Allocate IRQ's before scanning objects in DPRC as some devices like
+* DPIO needs them on being probed.
+*/
+   if (dev_get_msi_domain(&mc_bus_dev->dev) && !mc_bus->irq_resources) {
+   if (irq_count > FSL_MC_IRQ_POOL_MAX_TOTAL_IRQS) {
+   dev_warn(&mc_bus_dev->dev,
+"IRQs needed (%u) exceed IRQs preallocated 
(%u)\n",
+irq_count, FSL_MC_IRQ_POOL_MAX_TOTAL_IRQS);
+   }
+
+   error = fsl_mc_populate_irq_pool(mc_bus,
+   FSL_MC_IRQ_POOL_MAX_TOTAL_IRQS);
+   if (error < 0)
+   return error;
+   }
+
+   if (total_irq_count)
+   *total_irq_count = irq_count;
+
dprc_remove_devices(mc_bus_dev, child_obj_desc_array,
num_child_objects);
 
@@ -322,7 +343,6 @@ static int dprc_scan_objects(struct fsl_mc_device 
*mc_bus_dev,
 static int dprc_scan_container(struct fsl_mc_device *mc_bus_dev)
 {
int error;
-   unsigned int irq_count;
struct fsl_mc_bus *mc_bus = to_fsl_mc_bus(mc_bus_dev);
 
fsl_mc_init_all_resource_pools(mc_bus_dev);
@@ -331,29 +351,14 @@ static int dprc_scan_container(struct fsl_mc_device 
*mc_bus_dev)
 * Discover objects in the DPRC:
 */
mutex_lock(&mc_bus->scan_mutex);
-   error = dprc_scan_objects(mc_bus_dev, &irq_count);
+   error = dprc_scan_objects(mc_bus_dev, NULL);
mutex_unlock(&mc_bus->scan_mutex);
-   if (error < 0)
-   goto error;
-
-   if (dev_get_msi_domain(&mc_bus_dev->dev) && !mc_bus->irq_resources) {
-   if (irq_count > FSL_MC_IRQ_POOL_MAX_TOTAL_IRQS) {
-   dev_warn(&mc_bus_dev->dev,
-"IRQs needed (%u) exceed IRQs preallocated 
(%u)\n",
-irq_count, FSL_MC_IRQ_POOL_MAX_TOTAL_IRQS);
-   }
-
-   error = fsl_mc_populate_irq_pool(
-   mc_bus,
-   FSL_MC_IRQ_POOL_MAX_TOTAL_IRQS);
-   if (error < 0)
-   goto error;
+   if (error < 0) {
+   fsl_mc_cleanup_all_resource_pools(mc_bus_dev);
+   return error;
}
 
return 0;
-error:
-   fsl_mc_cleanup_all_resource_pools(mc_bus_dev);
-   return error;
 }
 
 /**
-- 
1.9.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


RE: [PATCH 2/2] staging: fsl-mc: do not print error in case of defer probe error

2017-12-06 Thread Nipun Gupta


> -Original Message-
> From: Greg KH [mailto:gre...@linuxfoundation.org]
> Sent: Wednesday, December 06, 2017 16:46
> To: Nipun Gupta 
> Cc: Laurentiu Tudor ; stuyo...@gmail.com; Bharat
> Bhushan ; cakt...@gmail.com;
> bretth...@gmail.com; a...@arndb.de; de...@driverdev.osuosl.org; linux-
> ker...@vger.kernel.org
> Subject: Re: [PATCH 2/2] staging: fsl-mc: do not print error in case of defer
> probe error
> 
> On Wed, Dec 06, 2017 at 09:48:07PM +0530, Nipun Gupta wrote:
> > Signed-off-by: Nipun Gupta 
> > ---
> 
> I can't take patches without any changelog text :(

I thought it is a small patch and you may take it without any changelog ;)
Ill resend updating this.

Thanks,
Nipun

> 
> Please fix and resend the series.
> 
> greg k-h
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


RE: [PATCH 1/2] staging: fsl-mc: Allocate IRQ's before scanning DPRC objects

2017-12-07 Thread Nipun Gupta


> -Original Message-
> From: Laurentiu Tudor
> Sent: Wednesday, December 06, 2017 19:00
> To: Nipun Gupta ; stuyo...@gmail.com; Bharat
> Bhushan ; gre...@linuxfoundation.org;
> cakt...@gmail.com; bretth...@gmail.com; a...@arndb.de
> Cc: linux-ker...@vger.kernel.org; de...@driverdev.osuosl.org
> Subject: Re: [PATCH 1/2] staging: fsl-mc: Allocate IRQ's before scanning DPRC
> objects
> 
> Hi Nipun,
> 
> Can you polish a bit this commit message? It doesn't seem to explain why
> this is needed.

Sure. Ill update the message.

> 
> On 12/06/2017 06:18 PM, Nipun Gupta wrote:
> > When DPRC probing is deferred (such as where IOMMU is not probed
> > before the fsl-mc bus), all the devices in the DPRC containers gets
> > initialized one after another.
> 
> Are you referring to dprc probing being deferred (do we ever do that?)
> or devices inside the dprc deferring the probe?

Yes.. Currently following is the scenario when the devices are probed
(please correct me if I am wrong):

FSL_MC Bus probe ---> dprc probe ---> dprc devices scan --->
probe of devices in DPRC container ---> allocate IRQ's.

In case the devices being probed in the DPRC container need the IRQ's;
probing of that device will fail.
In the current scenario DPIO device while getting probed for the first time
gets deferred because the DPIO driver is not yet registered.
So there is no impact seen in the current code.

In case the DPRC probing gets deferred, does in case IOMMU is enabled
(though it is not enabled till now for fsl-mc bus but we plan to add the
support as soon as mc bus is out from staging); the DPIO gets probed
before IRQ's being allocated. This causes DPIO probe to fail.

So I think it makes sense that IRQ's are allocated before any devices
In the DPRC container are probed.

> 
> > As IRQ's were allocated only once the
> > DPRC scanning is completed, the devices like DPIO which uses these
> > IRQ's at initalization fails. This patch allocates the IRQ resources
> 
> s/initalization/initialization
> 
> > before scanning all the objects in the DPRC container.
> >
> > Signed-off-by: Nipun Gupta 
> > ---
> >   drivers/staging/fsl-mc/bus/dprc-driver.c | 49 
> > ++
> --
> >   1 file changed, 27 insertions(+), 22 deletions(-)
> >
> > diff --git a/drivers/staging/fsl-mc/bus/dprc-driver.c b/drivers/staging/fsl-
> mc/bus/dprc-driver.c
> > index 06df528..7265431 100644
> > --- a/drivers/staging/fsl-mc/bus/dprc-driver.c
> > +++ b/drivers/staging/fsl-mc/bus/dprc-driver.c
> > @@ -206,7 +206,8 @@ static void dprc_add_new_devices(struct
> fsl_mc_device *mc_bus_dev,
> >* dprc_scan_objects - Discover objects in a DPRC
> >*
> >* @mc_bus_dev: pointer to the fsl-mc device that represents a DPRC object
> > - * @total_irq_count: total number of IRQs needed by objects in the DPRC.
> > + * @total_irq_count: If argument is provided the function populates the
> > + * total number of IRQs created by objects in the DPRC.
> 
> As a side node, after a cursory look i noticed that this total_irq_count
> parameter is used only for some sanity checks. I'm thinking of dropping
> it in a follow-up cleanup patch.

Do you plan to send it very recently.
In that case I can rebase my patch on top of it.

Regards,
Nipun

> 
> ---
> Best Regards, Laurentiu
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 1/2 v2] staging: fsl-mc: Allocate IRQ's before scanning DPRC objects

2017-12-11 Thread Nipun Gupta
Following is the current scenario when the devices are probed:

  FSL_MC Bus probe ---> dprc probe ---> dprc devices scan --->
probe devices in DPRC container ---> allocate IRQ's

In case the devices being probed in the DPRC container need the IRQ's;
probing of that device will fail.

In current scenario the devices which need IRQ's such as DPIO gets
deferred because they aren't registered when first time the probing
of these devices is done in the dprc scan.
So they are probed once IRQ's have been allocated.

In case where DPRC probing itself gets deferred, which does in case
IOMMU is enabled; all the devices in DPRC container gets probed before
IRQ's are allocated. This causes devices using IRQ's (such as DPIO)
to fail.

So having IRQ's allocated before any of the devices in the DPRC container
are probed is more legitimate.

After this patch following is the flow of execution:

  FSL_MC Bus probe ---> dprc probe ---> dprc devices scan --->
allocate IRQ's ---> probe of devices in DPRC container.

Signed-off-by: Nipun Gupta 
---
 drivers/staging/fsl-mc/bus/dprc-driver.c | 49 ++--
 1 file changed, 27 insertions(+), 22 deletions(-)

diff --git a/drivers/staging/fsl-mc/bus/dprc-driver.c 
b/drivers/staging/fsl-mc/bus/dprc-driver.c
index 06df528..f4bde58 100644
--- a/drivers/staging/fsl-mc/bus/dprc-driver.c
+++ b/drivers/staging/fsl-mc/bus/dprc-driver.c
@@ -206,7 +206,8 @@ static void dprc_add_new_devices(struct fsl_mc_device 
*mc_bus_dev,
  * dprc_scan_objects - Discover objects in a DPRC
  *
  * @mc_bus_dev: pointer to the fsl-mc device that represents a DPRC object
- * @total_irq_count: total number of IRQs needed by objects in the DPRC.
+ * @total_irq_count: If argument is provided the function populates the
+ * total number of IRQs created by objects in the DPRC.
  *
  * Detects objects added and removed from a DPRC and synchronizes the
  * state of the Linux bus driver, MC by adding and removing
@@ -228,6 +229,7 @@ static int dprc_scan_objects(struct fsl_mc_device 
*mc_bus_dev,
int error;
unsigned int irq_count = mc_bus_dev->obj_desc.irq_count;
struct fsl_mc_obj_desc *child_obj_desc_array = NULL;
+   struct fsl_mc_bus *mc_bus = to_fsl_mc_bus(mc_bus_dev);
 
error = dprc_get_obj_count(mc_bus_dev->mc_io,
   0,
@@ -297,7 +299,26 @@ static int dprc_scan_objects(struct fsl_mc_device 
*mc_bus_dev,
}
}
 
-   *total_irq_count = irq_count;
+   /*
+* Allocate IRQ's before binding the scanned devices with their
+* respective drivers.
+*/
+   if (dev_get_msi_domain(&mc_bus_dev->dev) && !mc_bus->irq_resources) {
+   if (irq_count > FSL_MC_IRQ_POOL_MAX_TOTAL_IRQS) {
+   dev_warn(&mc_bus_dev->dev,
+"IRQs needed (%u) exceed IRQs preallocated 
(%u)\n",
+irq_count, FSL_MC_IRQ_POOL_MAX_TOTAL_IRQS);
+   }
+
+   error = fsl_mc_populate_irq_pool(mc_bus,
+   FSL_MC_IRQ_POOL_MAX_TOTAL_IRQS);
+   if (error < 0)
+   return error;
+   }
+
+   if (total_irq_count)
+   *total_irq_count = irq_count;
+
dprc_remove_devices(mc_bus_dev, child_obj_desc_array,
num_child_objects);
 
@@ -322,7 +343,6 @@ static int dprc_scan_objects(struct fsl_mc_device 
*mc_bus_dev,
 static int dprc_scan_container(struct fsl_mc_device *mc_bus_dev)
 {
int error;
-   unsigned int irq_count;
struct fsl_mc_bus *mc_bus = to_fsl_mc_bus(mc_bus_dev);
 
fsl_mc_init_all_resource_pools(mc_bus_dev);
@@ -331,29 +351,14 @@ static int dprc_scan_container(struct fsl_mc_device 
*mc_bus_dev)
 * Discover objects in the DPRC:
 */
mutex_lock(&mc_bus->scan_mutex);
-   error = dprc_scan_objects(mc_bus_dev, &irq_count);
+   error = dprc_scan_objects(mc_bus_dev, NULL);
mutex_unlock(&mc_bus->scan_mutex);
-   if (error < 0)
-   goto error;
-
-   if (dev_get_msi_domain(&mc_bus_dev->dev) && !mc_bus->irq_resources) {
-   if (irq_count > FSL_MC_IRQ_POOL_MAX_TOTAL_IRQS) {
-   dev_warn(&mc_bus_dev->dev,
-"IRQs needed (%u) exceed IRQs preallocated 
(%u)\n",
-irq_count, FSL_MC_IRQ_POOL_MAX_TOTAL_IRQS);
-   }
-
-   error = fsl_mc_populate_irq_pool(
-   mc_bus,
-   FSL_MC_IRQ_POOL_MAX_TOTAL_IRQS);
-   if (error < 0)
-   goto error;
+   if (error < 0) {
+   fsl_mc_cleanup_all_resour

[PATCH 2/2 v2] staging: fsl-mc: do not print error in case of defer probe error

2017-12-11 Thread Nipun Gupta
Devices on MC bus can be deferred because of dependencies on other modules
(such as IOMMU). Those are not the actual errors; as probing is again
done by the kernel at later stages. So this patch avoids the error print
in such case.

Signed-off-by: Nipun Gupta 
---
 drivers/staging/fsl-mc/bus/fsl-mc-bus.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/staging/fsl-mc/bus/fsl-mc-bus.c 
b/drivers/staging/fsl-mc/bus/fsl-mc-bus.c
index 409f2b9..10cee00 100644
--- a/drivers/staging/fsl-mc/bus/fsl-mc-bus.c
+++ b/drivers/staging/fsl-mc/bus/fsl-mc-bus.c
@@ -171,7 +171,8 @@ static int fsl_mc_driver_probe(struct device *dev)
 
error = mc_drv->probe(mc_dev);
if (error < 0) {
-   dev_err(dev, "%s failed: %d\n", __func__, error);
+   if (error != -EPROBE_DEFER)
+   dev_err(dev, "%s failed: %d\n", __func__, error);
return error;
}
 
-- 
1.9.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[RESEND PATCH 2/2 v2] staging: fsl-mc: do not print error in case of defer probe error

2017-12-11 Thread Nipun Gupta
Devices on MC bus can be deferred because of dependencies on other modules
(such as IOMMU). Those are not the actual errors; as probing is again
done by the kernel at later stages. So this patch avoids the error print
in such case.

Signed-off-by: Nipun Gupta 
---
Resending v2 as missed mentioning the changes in the version
Changes in v2:
  - Added commit message

 drivers/staging/fsl-mc/bus/fsl-mc-bus.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/staging/fsl-mc/bus/fsl-mc-bus.c 
b/drivers/staging/fsl-mc/bus/fsl-mc-bus.c
index 409f2b9..10cee00 100644
--- a/drivers/staging/fsl-mc/bus/fsl-mc-bus.c
+++ b/drivers/staging/fsl-mc/bus/fsl-mc-bus.c
@@ -171,7 +171,8 @@ static int fsl_mc_driver_probe(struct device *dev)
 
error = mc_drv->probe(mc_dev);
if (error < 0) {
-   dev_err(dev, "%s failed: %d\n", __func__, error);
+   if (error != -EPROBE_DEFER)
+   dev_err(dev, "%s failed: %d\n", __func__, error);
return error;
}
 
-- 
1.9.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[RESEND PATCH 1/2 v2] staging: fsl-mc: Allocate IRQ's before scanning DPRC objects

2017-12-11 Thread Nipun Gupta
Following is the current scenario when the devices are probed:

  FSL_MC Bus probe ---> dprc probe ---> dprc devices scan --->
probe devices in DPRC container ---> allocate IRQ's

In case the devices being probed in the DPRC container need the IRQ's;
probing of that device will fail.

In current scenario the devices which need IRQ's such as DPIO gets
deferred because they aren't registered when first time the probing
of these devices is done in the dprc scan.
So they are probed once IRQ's have been allocated.

In case where DPRC probing itself gets deferred, which does in case
IOMMU is enabled; all the devices in DPRC container gets probed before
IRQ's are allocated. This causes devices using IRQ's (such as DPIO)
to fail.

So having IRQ's allocated before any of the devices in the DPRC container
are probed is more legitimate.

After this patch following is the flow of execution:

  FSL_MC Bus probe ---> dprc probe ---> dprc devices scan --->
allocate IRQ's ---> probe of devices in DPRC container.

Signed-off-by: Nipun Gupta 
---
Resending v2 as missed mentioning the changes in the version
Changes in v2:
  - Polished the commit message
  - Minor updation in the comment added in the code 'Allocate IRQ's...'

 drivers/staging/fsl-mc/bus/dprc-driver.c | 49 ++--
 1 file changed, 27 insertions(+), 22 deletions(-)

diff --git a/drivers/staging/fsl-mc/bus/dprc-driver.c 
b/drivers/staging/fsl-mc/bus/dprc-driver.c
index 06df528..f4bde58 100644
--- a/drivers/staging/fsl-mc/bus/dprc-driver.c
+++ b/drivers/staging/fsl-mc/bus/dprc-driver.c
@@ -206,7 +206,8 @@ static void dprc_add_new_devices(struct fsl_mc_device 
*mc_bus_dev,
  * dprc_scan_objects - Discover objects in a DPRC
  *
  * @mc_bus_dev: pointer to the fsl-mc device that represents a DPRC object
- * @total_irq_count: total number of IRQs needed by objects in the DPRC.
+ * @total_irq_count: If argument is provided the function populates the
+ * total number of IRQs created by objects in the DPRC.
  *
  * Detects objects added and removed from a DPRC and synchronizes the
  * state of the Linux bus driver, MC by adding and removing
@@ -228,6 +229,7 @@ static int dprc_scan_objects(struct fsl_mc_device 
*mc_bus_dev,
int error;
unsigned int irq_count = mc_bus_dev->obj_desc.irq_count;
struct fsl_mc_obj_desc *child_obj_desc_array = NULL;
+   struct fsl_mc_bus *mc_bus = to_fsl_mc_bus(mc_bus_dev);
 
error = dprc_get_obj_count(mc_bus_dev->mc_io,
   0,
@@ -297,7 +299,26 @@ static int dprc_scan_objects(struct fsl_mc_device 
*mc_bus_dev,
}
}
 
-   *total_irq_count = irq_count;
+   /*
+* Allocate IRQ's before binding the scanned devices with their
+* respective drivers.
+*/
+   if (dev_get_msi_domain(&mc_bus_dev->dev) && !mc_bus->irq_resources) {
+   if (irq_count > FSL_MC_IRQ_POOL_MAX_TOTAL_IRQS) {
+   dev_warn(&mc_bus_dev->dev,
+"IRQs needed (%u) exceed IRQs preallocated 
(%u)\n",
+irq_count, FSL_MC_IRQ_POOL_MAX_TOTAL_IRQS);
+   }
+
+   error = fsl_mc_populate_irq_pool(mc_bus,
+   FSL_MC_IRQ_POOL_MAX_TOTAL_IRQS);
+   if (error < 0)
+   return error;
+   }
+
+   if (total_irq_count)
+   *total_irq_count = irq_count;
+
dprc_remove_devices(mc_bus_dev, child_obj_desc_array,
num_child_objects);
 
@@ -322,7 +343,6 @@ static int dprc_scan_objects(struct fsl_mc_device 
*mc_bus_dev,
 static int dprc_scan_container(struct fsl_mc_device *mc_bus_dev)
 {
int error;
-   unsigned int irq_count;
struct fsl_mc_bus *mc_bus = to_fsl_mc_bus(mc_bus_dev);
 
fsl_mc_init_all_resource_pools(mc_bus_dev);
@@ -331,29 +351,14 @@ static int dprc_scan_container(struct fsl_mc_device 
*mc_bus_dev)
 * Discover objects in the DPRC:
 */
mutex_lock(&mc_bus->scan_mutex);
-   error = dprc_scan_objects(mc_bus_dev, &irq_count);
+   error = dprc_scan_objects(mc_bus_dev, NULL);
mutex_unlock(&mc_bus->scan_mutex);
-   if (error < 0)
-   goto error;
-
-   if (dev_get_msi_domain(&mc_bus_dev->dev) && !mc_bus->irq_resources) {
-   if (irq_count > FSL_MC_IRQ_POOL_MAX_TOTAL_IRQS) {
-   dev_warn(&mc_bus_dev->dev,
-"IRQs needed (%u) exceed IRQs preallocated 
(%u)\n",
-irq_count, FSL_MC_IRQ_POOL_MAX_TOTAL_IRQS);
-   }
-
-   error = fsl_mc_populate_irq_pool(
-   mc_bus,
- 

[PATCH] fsl-mc: add helper macro to determine if a device is of fsl_mc type

2016-06-28 Thread Nipun Gupta
Add a helper macro to return if a device has a bus type of fsl_mc.
This makes the bus driver code more readable and provides a way for
drivers like the SMMU driver to easily check the bus type.

Signed-off-by: Nipun Gupta 
Signed-off-by: Bharat Bhushan 
---
 drivers/staging/fsl-mc/bus/dprc-driver.c   | 4 ++--
 drivers/staging/fsl-mc/bus/irq-gic-v3-its-fsl-mc-msi.c | 2 +-
 drivers/staging/fsl-mc/bus/mc-allocator.c  | 6 +++---
 drivers/staging/fsl-mc/bus/mc-bus.c| 6 +++---
 drivers/staging/fsl-mc/include/mc.h| 2 ++
 5 files changed, 11 insertions(+), 9 deletions(-)

diff --git a/drivers/staging/fsl-mc/bus/dprc-driver.c 
b/drivers/staging/fsl-mc/bus/dprc-driver.c
index 7fc4717..cd6d75a 100644
--- a/drivers/staging/fsl-mc/bus/dprc-driver.c
+++ b/drivers/staging/fsl-mc/bus/dprc-driver.c
@@ -649,7 +649,7 @@ static int dprc_probe(struct fsl_mc_device *mc_dev)
/*
 * This is a child DPRC:
 */
-   if (WARN_ON(parent_dev->bus != &fsl_mc_bus_type))
+   if (WARN_ON(!dev_is_fsl_mc(parent_dev)))
return -EINVAL;
 
if (WARN_ON(mc_dev->obj_desc.region_count == 0))
@@ -681,7 +681,7 @@ static int dprc_probe(struct fsl_mc_device *mc_dev)
 */
struct irq_domain *mc_msi_domain;
 
-   if (WARN_ON(parent_dev->bus == &fsl_mc_bus_type))
+   if (WARN_ON(dev_is_fsl_mc(parent_dev)))
return -EINVAL;
 
error = fsl_mc_find_msi_domain(parent_dev,
diff --git a/drivers/staging/fsl-mc/bus/irq-gic-v3-its-fsl-mc-msi.c 
b/drivers/staging/fsl-mc/bus/irq-gic-v3-its-fsl-mc-msi.c
index 720e2b0..d0c20d6 100644
--- a/drivers/staging/fsl-mc/bus/irq-gic-v3-its-fsl-mc-msi.c
+++ b/drivers/staging/fsl-mc/bus/irq-gic-v3-its-fsl-mc-msi.c
@@ -35,7 +35,7 @@ static int its_fsl_mc_msi_prepare(struct irq_domain 
*msi_domain,
struct fsl_mc_device *mc_bus_dev;
struct msi_domain_info *msi_info;
 
-   if (WARN_ON(dev->bus != &fsl_mc_bus_type))
+   if (WARN_ON(!dev_is_fsl_mc(dev)))
return -EINVAL;
 
mc_bus_dev = to_fsl_mc_device(dev);
diff --git a/drivers/staging/fsl-mc/bus/mc-allocator.c 
b/drivers/staging/fsl-mc/bus/mc-allocator.c
index fb08f22..9216c32 100644
--- a/drivers/staging/fsl-mc/bus/mc-allocator.c
+++ b/drivers/staging/fsl-mc/bus/mc-allocator.c
@@ -281,7 +281,7 @@ int __must_check fsl_mc_portal_allocate(struct 
fsl_mc_device *mc_dev,
if (mc_dev->flags & FSL_MC_IS_DPRC) {
mc_bus_dev = mc_dev;
} else {
-   if (WARN_ON(mc_dev->dev.parent->bus != &fsl_mc_bus_type))
+   if (WARN_ON(!dev_is_fsl_mc(mc_dev->dev.parent)))
return error;
 
mc_bus_dev = to_fsl_mc_device(mc_dev->dev.parent);
@@ -420,7 +420,7 @@ int __must_check fsl_mc_object_allocate(struct 
fsl_mc_device *mc_dev,
if (WARN_ON(mc_dev->flags & FSL_MC_IS_DPRC))
goto error;
 
-   if (WARN_ON(mc_dev->dev.parent->bus != &fsl_mc_bus_type))
+   if (WARN_ON(!dev_is_fsl_mc(mc_dev->dev.parent)))
goto error;
 
if (WARN_ON(pool_type == FSL_MC_POOL_DPMCP))
@@ -678,7 +678,7 @@ static int fsl_mc_allocator_probe(struct fsl_mc_device 
*mc_dev)
return -EINVAL;
 
mc_bus_dev = to_fsl_mc_device(mc_dev->dev.parent);
-   if (WARN_ON(mc_bus_dev->dev.bus != &fsl_mc_bus_type))
+   if (WARN_ON(!dev_is_fsl_mc(&mc_bus_dev->dev)))
return -EINVAL;
 
mc_bus = to_fsl_mc_bus(mc_bus_dev);
diff --git a/drivers/staging/fsl-mc/bus/mc-bus.c 
b/drivers/staging/fsl-mc/bus/mc-bus.c
index 4053643..098f07c 100644
--- a/drivers/staging/fsl-mc/bus/mc-bus.c
+++ b/drivers/staging/fsl-mc/bus/mc-bus.c
@@ -207,11 +207,11 @@ static void fsl_mc_get_root_dprc(struct device *dev,
 {
if (WARN_ON(!dev)) {
*root_dprc_dev = NULL;
-   } else if (WARN_ON(dev->bus != &fsl_mc_bus_type)) {
+   } else if (WARN_ON(!dev_is_fsl_mc(dev))) {
*root_dprc_dev = NULL;
} else {
*root_dprc_dev = dev;
-   while ((*root_dprc_dev)->parent->bus == &fsl_mc_bus_type)
+   while (dev_is_fsl_mc((*root_dprc_dev)->parent))
*root_dprc_dev = (*root_dprc_dev)->parent;
}
 }
@@ -405,7 +405,7 @@ int fsl_mc_device_add(struct dprc_obj_desc *obj_desc,
struct fsl_mc_bus *mc_bus = NULL;
struct fsl_mc_device *parent_mc_dev;
 
-   if (parent_dev->bus == &fsl_mc_bus_type)
+   if (dev_is_fsl_mc(parent_dev))
parent_mc_dev = to_fsl_mc_device(parent_dev);
else
parent_mc_dev = NULL;
diff --git a/drivers/staging/fsl-mc/include/mc.h 
b/drivers/staging/fsl-mc/include/mc.h
index ac7c1ce..3

[PATCH v2] fsl-mc: add helper macro to determine if a device is of fsl_mc type

2016-06-29 Thread Nipun Gupta
Add a helper macro to return if a device has a bus type of fsl_mc.
This makes the bus driver code more readable and provides a way for
drivers like the SMMU driver to easily check the bus type.

Signed-off-by: Nipun Gupta 
Signed-off-by: Bharat Bhushan 
---
 drivers/staging/fsl-mc/bus/dprc-driver.c   | 4 ++--
 drivers/staging/fsl-mc/bus/irq-gic-v3-its-fsl-mc-msi.c | 2 +-
 drivers/staging/fsl-mc/bus/mc-allocator.c  | 6 +++---
 drivers/staging/fsl-mc/bus/mc-bus.c| 6 +++---
 drivers/staging/fsl-mc/include/mc.h| 7 +++
 5 files changed, 16 insertions(+), 9 deletions(-)

diff --git a/drivers/staging/fsl-mc/bus/dprc-driver.c 
b/drivers/staging/fsl-mc/bus/dprc-driver.c
index 7fc4717..cd6d75a 100644
--- a/drivers/staging/fsl-mc/bus/dprc-driver.c
+++ b/drivers/staging/fsl-mc/bus/dprc-driver.c
@@ -649,7 +649,7 @@ static int dprc_probe(struct fsl_mc_device *mc_dev)
/*
 * This is a child DPRC:
 */
-   if (WARN_ON(parent_dev->bus != &fsl_mc_bus_type))
+   if (WARN_ON(!dev_is_fsl_mc(parent_dev)))
return -EINVAL;
 
if (WARN_ON(mc_dev->obj_desc.region_count == 0))
@@ -681,7 +681,7 @@ static int dprc_probe(struct fsl_mc_device *mc_dev)
 */
struct irq_domain *mc_msi_domain;
 
-   if (WARN_ON(parent_dev->bus == &fsl_mc_bus_type))
+   if (WARN_ON(dev_is_fsl_mc(parent_dev)))
return -EINVAL;
 
error = fsl_mc_find_msi_domain(parent_dev,
diff --git a/drivers/staging/fsl-mc/bus/irq-gic-v3-its-fsl-mc-msi.c 
b/drivers/staging/fsl-mc/bus/irq-gic-v3-its-fsl-mc-msi.c
index 720e2b0..d0c20d6 100644
--- a/drivers/staging/fsl-mc/bus/irq-gic-v3-its-fsl-mc-msi.c
+++ b/drivers/staging/fsl-mc/bus/irq-gic-v3-its-fsl-mc-msi.c
@@ -35,7 +35,7 @@ static int its_fsl_mc_msi_prepare(struct irq_domain 
*msi_domain,
struct fsl_mc_device *mc_bus_dev;
struct msi_domain_info *msi_info;
 
-   if (WARN_ON(dev->bus != &fsl_mc_bus_type))
+   if (WARN_ON(!dev_is_fsl_mc(dev)))
return -EINVAL;
 
mc_bus_dev = to_fsl_mc_device(dev);
diff --git a/drivers/staging/fsl-mc/bus/mc-allocator.c 
b/drivers/staging/fsl-mc/bus/mc-allocator.c
index fb08f22..9216c32 100644
--- a/drivers/staging/fsl-mc/bus/mc-allocator.c
+++ b/drivers/staging/fsl-mc/bus/mc-allocator.c
@@ -281,7 +281,7 @@ int __must_check fsl_mc_portal_allocate(struct 
fsl_mc_device *mc_dev,
if (mc_dev->flags & FSL_MC_IS_DPRC) {
mc_bus_dev = mc_dev;
} else {
-   if (WARN_ON(mc_dev->dev.parent->bus != &fsl_mc_bus_type))
+   if (WARN_ON(!dev_is_fsl_mc(mc_dev->dev.parent)))
return error;
 
mc_bus_dev = to_fsl_mc_device(mc_dev->dev.parent);
@@ -420,7 +420,7 @@ int __must_check fsl_mc_object_allocate(struct 
fsl_mc_device *mc_dev,
if (WARN_ON(mc_dev->flags & FSL_MC_IS_DPRC))
goto error;
 
-   if (WARN_ON(mc_dev->dev.parent->bus != &fsl_mc_bus_type))
+   if (WARN_ON(!dev_is_fsl_mc(mc_dev->dev.parent)))
goto error;
 
if (WARN_ON(pool_type == FSL_MC_POOL_DPMCP))
@@ -678,7 +678,7 @@ static int fsl_mc_allocator_probe(struct fsl_mc_device 
*mc_dev)
return -EINVAL;
 
mc_bus_dev = to_fsl_mc_device(mc_dev->dev.parent);
-   if (WARN_ON(mc_bus_dev->dev.bus != &fsl_mc_bus_type))
+   if (WARN_ON(!dev_is_fsl_mc(&mc_bus_dev->dev)))
return -EINVAL;
 
mc_bus = to_fsl_mc_bus(mc_bus_dev);
diff --git a/drivers/staging/fsl-mc/bus/mc-bus.c 
b/drivers/staging/fsl-mc/bus/mc-bus.c
index 4053643..098f07c 100644
--- a/drivers/staging/fsl-mc/bus/mc-bus.c
+++ b/drivers/staging/fsl-mc/bus/mc-bus.c
@@ -207,11 +207,11 @@ static void fsl_mc_get_root_dprc(struct device *dev,
 {
if (WARN_ON(!dev)) {
*root_dprc_dev = NULL;
-   } else if (WARN_ON(dev->bus != &fsl_mc_bus_type)) {
+   } else if (WARN_ON(!dev_is_fsl_mc(dev))) {
*root_dprc_dev = NULL;
} else {
*root_dprc_dev = dev;
-   while ((*root_dprc_dev)->parent->bus == &fsl_mc_bus_type)
+   while (dev_is_fsl_mc((*root_dprc_dev)->parent))
*root_dprc_dev = (*root_dprc_dev)->parent;
}
 }
@@ -405,7 +405,7 @@ int fsl_mc_device_add(struct dprc_obj_desc *obj_desc,
struct fsl_mc_bus *mc_bus = NULL;
struct fsl_mc_device *parent_mc_dev;
 
-   if (parent_dev->bus == &fsl_mc_bus_type)
+   if (dev_is_fsl_mc(parent_dev))
parent_mc_dev = to_fsl_mc_device(parent_dev);
else
parent_mc_dev = NULL;
diff --git a/drivers/staging/fsl-mc/include/mc.h 
b/drivers/staging/fsl-mc/include/mc.h
index ac7