diff mbox

[v3,3/8] Driver core: wakeup the parent device before trying probe

Message ID 3252449.XN2pzxrAPQ@vostro.rjw.lan (mailing list archive)
State RFC, archived
Headers show

Commit Message

Rafael J. Wysocki June 10, 2015, 12:08 a.m. UTC
On Tuesday, June 09, 2015 01:42:00 AM Rafael J. Wysocki wrote:
> On Monday, June 01, 2015 05:47:57 PM Andy Shevchenko wrote:
> > From: Heikki Krogerus <heikki.krogerus@linux.intel.com>
> > 
> > If the parent is still suspended when driver probe is
> > attempted, the result may be failure.
> > 
> > For example, if the parent is a PCI MFD device that has been
> > suspended when we try to probe our device, any register
> > reads will return 0xffffffff.
> > 
> > To fix the problem, making sure the parent is always awake
> > before attempting driver probe.
> > 
> > Signed-off-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
> > Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> > ---
> >  drivers/base/dd.c | 8 ++++++++
> >  1 file changed, 8 insertions(+)
> > 
> > diff --git a/drivers/base/dd.c b/drivers/base/dd.c
> > index e843fdb..cfbeff3 100644
> > --- a/drivers/base/dd.c
> > +++ b/drivers/base/dd.c
> > @@ -399,6 +399,8 @@ EXPORT_SYMBOL_GPL(wait_for_device_probe);
> >   *
> >   * This function must be called with @dev lock held.  When called for a
> >   * USB interface, @dev->parent lock must be held as well.
> > + *
> > + * If device has a parent it will be powered on during device's probe().
> >   */
> >  int driver_probe_device(struct device_driver *drv, struct device *dev)
> >  {
> > @@ -410,10 +412,16 @@ int driver_probe_device(struct device_driver *drv, struct device *dev)
> >  	pr_debug("bus: '%s': %s: matched device %s with driver %s\n",
> >  		 drv->bus->name, __func__, dev_name(dev), drv->name);
> >  
> > +	if (dev->parent)
> > +		pm_runtime_get_sync(dev->parent);
> > +
> 
> For some bus types that will resume and suspend the parent for many times in
> a row in device_attach() until an appropriate driver is found.  Would it be
> more efficient to call it once before the bus_for_each_drv() loop in there?

Actually, something like the below should work too (the bumping up of the
parent's usage counter before the loop will keep it in the runtime-active
state throughout the loop).

---
 drivers/base/dd.c |   14 ++++++++++++++
 1 file changed, 14 insertions(+)


--
To unsubscribe from this list: send the line "unsubscribe linux-pm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Comments

Andy Shevchenko June 10, 2015, 9:43 a.m. UTC | #1
On Wed, 2015-06-10 at 02:08 +0200, Rafael J. Wysocki wrote:
> On Tuesday, June 09, 2015 01:42:00 AM Rafael J. Wysocki wrote:
> > On Monday, June 01, 2015 05:47:57 PM Andy Shevchenko wrote:
> > > From: Heikki Krogerus <heikki.krogerus@linux.intel.com>
> > > 
> > > If the parent is still suspended when driver probe is
> > > attempted, the result may be failure.
> > > 
> > > For example, if the parent is a PCI MFD device that has been
> > > suspended when we try to probe our device, any register
> > > reads will return 0xffffffff.
> > > 
> > > To fix the problem, making sure the parent is always awake
> > > before attempting driver probe.
> > > 
> > > Signed-off-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
> > > Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> > > ---
> > >  drivers/base/dd.c | 8 ++++++++
> > >  1 file changed, 8 insertions(+)
> > > 
> > > diff --git a/drivers/base/dd.c b/drivers/base/dd.c
> > > index e843fdb..cfbeff3 100644
> > > --- a/drivers/base/dd.c
> > > +++ b/drivers/base/dd.c
> > > @@ -399,6 +399,8 @@ EXPORT_SYMBOL_GPL(wait_for_device_probe);
> > >   *
> > >   * This function must be called with @dev lock held.  When called for a
> > >   * USB interface, @dev->parent lock must be held as well.
> > > + *
> > > + * If device has a parent it will be powered on during device's probe().
> > >   */
> > >  int driver_probe_device(struct device_driver *drv, struct device *dev)
> > >  {
> > > @@ -410,10 +412,16 @@ int driver_probe_device(struct device_driver *drv, struct device *dev)
> > >  	pr_debug("bus: '%s': %s: matched device %s with driver %s\n",
> > >  		 drv->bus->name, __func__, dev_name(dev), drv->name);
> > >  
> > > +	if (dev->parent)
> > > +		pm_runtime_get_sync(dev->parent);
> > > +
> > 
> > For some bus types that will resume and suspend the parent for many times in
> > a row in device_attach() until an appropriate driver is found.  Would it be
> > more efficient to call it once before the bus_for_each_drv() loop in there?
> 
> Actually, something like the below should work too (the bumping up of the
> parent's usage counter before the loop will keep it in the runtime-active
> state throughout the loop).
> 

Thanks for the patch! We are going to test this soon.

By the way, can you give your Ack for patches 1 and 2 if there is no
objection?


> ---
>  drivers/base/dd.c |   14 ++++++++++++++
>  1 file changed, 14 insertions(+)
> 
> Index: linux-pm/drivers/base/dd.c
> ===================================================================
> --- linux-pm.orig/drivers/base/dd.c
> +++ linux-pm/drivers/base/dd.c
> @@ -399,6 +399,8 @@ EXPORT_SYMBOL_GPL(wait_for_device_probe)
>   *
>   * This function must be called with @dev lock held.  When called for a
>   * USB interface, @dev->parent lock must be held as well.
> + *
> + * If the device has a parent, runtime-resume the parent before driver probing.
>   */
>  int driver_probe_device(struct device_driver *drv, struct device *dev)
>  {
> @@ -410,10 +412,16 @@ int driver_probe_device(struct device_dr
>  	pr_debug("bus: '%s': %s: matched device %s with driver %s\n",
>  		 drv->bus->name, __func__, dev_name(dev), drv->name);
>  
> +	if (dev->parent)
> +		pm_runtime_get_sync(dev->parent);
> +
>  	pm_runtime_barrier(dev);
>  	ret = really_probe(dev, drv);
>  	pm_request_idle(dev);
>  
> +	if (dev->parent)
> +		pm_runtime_put(dev->parent);
> +
>  	return ret;
>  }
>  
> @@ -459,8 +467,14 @@ int device_attach(struct device *dev)
>  			ret = 0;
>  		}
>  	} else {
> +		if (dev->parent)
> +			pm_runtime_get_sync(dev->parent);
> +
>  		ret = bus_for_each_drv(dev->bus, NULL, dev, __device_attach);
>  		pm_request_idle(dev);
> +
> +		if (dev->parent)
> +			pm_runtime_put(dev->parent);
>  	}
>  out_unlock:
>  	device_unlock(dev);
>
Andy Shevchenko June 10, 2015, 2:02 p.m. UTC | #2
On Wed, 2015-06-10 at 02:08 +0200, Rafael J. Wysocki wrote: 
> On Tuesday, June 09, 2015 01:42:00 AM Rafael J. Wysocki wrote:
> > On Monday, June 01, 2015 05:47:57 PM Andy Shevchenko wrote:
> > > From: Heikki Krogerus <heikki.krogerus@linux.intel.com>
> > > 
> > > If the parent is still suspended when driver probe is
> > > attempted, the result may be failure.
> > > 
> > > For example, if the parent is a PCI MFD device that has been
> > > suspended when we try to probe our device, any register
> > > reads will return 0xffffffff.
> > > 
> > > To fix the problem, making sure the parent is always awake
> > > before attempting driver probe.

[]

> Actually, something like the below should work too (the bumping up of the
> parent's usage counter before the loop will keep it in the runtime-active
> state throughout the loop).

It works. Thanks for the patch. We incorporate it instead of the
previous Heikki's patch into v4.
Rafael J. Wysocki June 10, 2015, 11:41 p.m. UTC | #3
On Wednesday, June 10, 2015 12:43:15 PM Andy Shevchenko wrote:
> On Wed, 2015-06-10 at 02:08 +0200, Rafael J. Wysocki wrote:
> > On Tuesday, June 09, 2015 01:42:00 AM Rafael J. Wysocki wrote:
> > > On Monday, June 01, 2015 05:47:57 PM Andy Shevchenko wrote:
> > > > From: Heikki Krogerus <heikki.krogerus@linux.intel.com>
> > > > 
> > > > If the parent is still suspended when driver probe is
> > > > attempted, the result may be failure.
> > > > 
> > > > For example, if the parent is a PCI MFD device that has been
> > > > suspended when we try to probe our device, any register
> > > > reads will return 0xffffffff.
> > > > 
> > > > To fix the problem, making sure the parent is always awake
> > > > before attempting driver probe.
> > > > 
> > > > Signed-off-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
> > > > Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> > > > ---
> > > >  drivers/base/dd.c | 8 ++++++++
> > > >  1 file changed, 8 insertions(+)
> > > > 
> > > > diff --git a/drivers/base/dd.c b/drivers/base/dd.c
> > > > index e843fdb..cfbeff3 100644
> > > > --- a/drivers/base/dd.c
> > > > +++ b/drivers/base/dd.c
> > > > @@ -399,6 +399,8 @@ EXPORT_SYMBOL_GPL(wait_for_device_probe);
> > > >   *
> > > >   * This function must be called with @dev lock held.  When called for a
> > > >   * USB interface, @dev->parent lock must be held as well.
> > > > + *
> > > > + * If device has a parent it will be powered on during device's probe().
> > > >   */
> > > >  int driver_probe_device(struct device_driver *drv, struct device *dev)
> > > >  {
> > > > @@ -410,10 +412,16 @@ int driver_probe_device(struct device_driver *drv, struct device *dev)
> > > >  	pr_debug("bus: '%s': %s: matched device %s with driver %s\n",
> > > >  		 drv->bus->name, __func__, dev_name(dev), drv->name);
> > > >  
> > > > +	if (dev->parent)
> > > > +		pm_runtime_get_sync(dev->parent);
> > > > +
> > > 
> > > For some bus types that will resume and suspend the parent for many times in
> > > a row in device_attach() until an appropriate driver is found.  Would it be
> > > more efficient to call it once before the bus_for_each_drv() loop in there?
> > 
> > Actually, something like the below should work too (the bumping up of the
> > parent's usage counter before the loop will keep it in the runtime-active
> > state throughout the loop).
> > 
> 
> Thanks for the patch! We are going to test this soon.
> 
> By the way, can you give your Ack for patches 1 and 2 if there is no
> objection?

OK
diff mbox

Patch

Index: linux-pm/drivers/base/dd.c
===================================================================
--- linux-pm.orig/drivers/base/dd.c
+++ linux-pm/drivers/base/dd.c
@@ -399,6 +399,8 @@  EXPORT_SYMBOL_GPL(wait_for_device_probe)
  *
  * This function must be called with @dev lock held.  When called for a
  * USB interface, @dev->parent lock must be held as well.
+ *
+ * If the device has a parent, runtime-resume the parent before driver probing.
  */
 int driver_probe_device(struct device_driver *drv, struct device *dev)
 {
@@ -410,10 +412,16 @@  int driver_probe_device(struct device_dr
 	pr_debug("bus: '%s': %s: matched device %s with driver %s\n",
 		 drv->bus->name, __func__, dev_name(dev), drv->name);
 
+	if (dev->parent)
+		pm_runtime_get_sync(dev->parent);
+
 	pm_runtime_barrier(dev);
 	ret = really_probe(dev, drv);
 	pm_request_idle(dev);
 
+	if (dev->parent)
+		pm_runtime_put(dev->parent);
+
 	return ret;
 }
 
@@ -459,8 +467,14 @@  int device_attach(struct device *dev)
 			ret = 0;
 		}
 	} else {
+		if (dev->parent)
+			pm_runtime_get_sync(dev->parent);
+
 		ret = bus_for_each_drv(dev->bus, NULL, dev, __device_attach);
 		pm_request_idle(dev);
+
+		if (dev->parent)
+			pm_runtime_put(dev->parent);
 	}
 out_unlock:
 	device_unlock(dev);