Linux-Devicetree Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH v4 2/2] usb: overridable hub bInterval by device node
@ 2019-12-03 10:15 Ikjoon Jang
  2019-12-03 15:23 ` Alan Stern
  2019-12-03 16:53 ` Johan Hovold
  0 siblings, 2 replies; 14+ messages in thread
From: Ikjoon Jang @ 2019-12-03 10:15 UTC (permalink / raw)
  To: linux-usb
  Cc: GregKroah-Hartman, RobHerring, MarkRutland, AlanStern, SuwanKim,
	GustavoA . R . Silva, IkjoonJang, JohanHovold, devicetree,
	linux-kernel, drinkcat

This patch enables hub device to override its own endpoint descriptor's
bInterval when the hub has a device node with "hub,interval" property.

When we know reducing autosuspend delay for built-in HIDs is better for
power saving, we can reduce it to the optimal value. But if a parent hub
has a long bInterval, mouse lags a lot from more frequent autosuspend.
So this enables overriding bInterval for a hard wired hub device only
when we know that reduces the power consumption.

Signed-off-by: Ikjoon Jang <ikjn@chromium.org>
Acked-by: Alan Stern <stern@rowland.harvard.edu>
---
 drivers/usb/core/config.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/drivers/usb/core/config.c b/drivers/usb/core/config.c
index 5f40117e68e7..95ec5af42a1c 100644
--- a/drivers/usb/core/config.c
+++ b/drivers/usb/core/config.c
@@ -6,6 +6,7 @@
 #include <linux/usb.h>
 #include <linux/usb/ch9.h>
 #include <linux/usb/hcd.h>
+#include <linux/usb/of.h>
 #include <linux/usb/quirks.h>
 #include <linux/module.h>
 #include <linux/slab.h>
@@ -257,6 +258,14 @@ static int usb_parse_endpoint(struct device *ddev, int cfgno, int inum,
 	memcpy(&endpoint->desc, d, n);
 	INIT_LIST_HEAD(&endpoint->urb_list);
 
+	/* device node property overrides bInterval */
+	if (usb_of_has_combined_node(to_usb_device(ddev))) {
+		u32 interval = 0;
+		if (!of_property_read_u32(ddev->of_node, "hub,interval",
+				    &interval))
+			d->bInterval = min_t(u8, interval, 255);
+	}
+
 	/*
 	 * Fix up bInterval values outside the legal range.
 	 * Use 10 or 8 ms if no proper value can be guessed.
-- 
2.24.0.393.g34dc348eaf-goog


^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH v4 2/2] usb: overridable hub bInterval by device node
  2019-12-03 10:15 [PATCH v4 2/2] usb: overridable hub bInterval by device node Ikjoon Jang
@ 2019-12-03 15:23 ` Alan Stern
  2019-12-04  7:07   ` Ikjoon Jang
  2019-12-03 16:53 ` Johan Hovold
  1 sibling, 1 reply; 14+ messages in thread
From: Alan Stern @ 2019-12-03 15:23 UTC (permalink / raw)
  To: Ikjoon Jang
  Cc: linux-usb, GregKroah-Hartman, RobHerring, MarkRutland, SuwanKim,
	GustavoA . R . Silva, JohanHovold, devicetree, linux-kernel,
	drinkcat

On Tue, 3 Dec 2019, Ikjoon Jang wrote:

> This patch enables hub device to override its own endpoint descriptor's
> bInterval when the hub has a device node with "hub,interval" property.
> 
> When we know reducing autosuspend delay for built-in HIDs is better for
> power saving, we can reduce it to the optimal value. But if a parent hub
> has a long bInterval, mouse lags a lot from more frequent autosuspend.
> So this enables overriding bInterval for a hard wired hub device only
> when we know that reduces the power consumption.
> 
> Signed-off-by: Ikjoon Jang <ikjn@chromium.org>
> Acked-by: Alan Stern <stern@rowland.harvard.edu>
> ---
>  drivers/usb/core/config.c | 9 +++++++++
>  1 file changed, 9 insertions(+)
> 
> diff --git a/drivers/usb/core/config.c b/drivers/usb/core/config.c
> index 5f40117e68e7..95ec5af42a1c 100644
> --- a/drivers/usb/core/config.c
> +++ b/drivers/usb/core/config.c
> @@ -6,6 +6,7 @@
>  #include <linux/usb.h>
>  #include <linux/usb/ch9.h>
>  #include <linux/usb/hcd.h>
> +#include <linux/usb/of.h>
>  #include <linux/usb/quirks.h>
>  #include <linux/module.h>
>  #include <linux/slab.h>
> @@ -257,6 +258,14 @@ static int usb_parse_endpoint(struct device *ddev, int cfgno, int inum,
>  	memcpy(&endpoint->desc, d, n);
>  	INIT_LIST_HEAD(&endpoint->urb_list);
>  
> +	/* device node property overrides bInterval */
> +	if (usb_of_has_combined_node(to_usb_device(ddev))) {
> +		u32 interval = 0;

Coding style: there should be a blank line here.  Also, you don't need 
the "= 0" initializer.

Otherwise okay.

Alan Stern

> +		if (!of_property_read_u32(ddev->of_node, "hub,interval",
> +				    &interval))
> +			d->bInterval = min_t(u8, interval, 255);
> +	}
> +
>  	/*
>  	 * Fix up bInterval values outside the legal range.
>  	 * Use 10 or 8 ms if no proper value can be guessed.


^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH v4 2/2] usb: overridable hub bInterval by device node
  2019-12-03 10:15 [PATCH v4 2/2] usb: overridable hub bInterval by device node Ikjoon Jang
  2019-12-03 15:23 ` Alan Stern
@ 2019-12-03 16:53 ` Johan Hovold
  2019-12-04  7:04   ` Ikjoon Jang
  1 sibling, 1 reply; 14+ messages in thread
From: Johan Hovold @ 2019-12-03 16:53 UTC (permalink / raw)
  To: Ikjoon Jang
  Cc: linux-usb, GregKroah-Hartman, RobHerring, MarkRutland, AlanStern,
	SuwanKim, GustavoA . R . Silva, JohanHovold, devicetree,
	linux-kernel, drinkcat

On Tue, Dec 03, 2019 at 06:15:52PM +0800, Ikjoon Jang wrote:
> This patch enables hub device to override its own endpoint descriptor's
> bInterval when the hub has a device node with "hub,interval" property.
> 
> When we know reducing autosuspend delay for built-in HIDs is better for
> power saving, we can reduce it to the optimal value. But if a parent hub
> has a long bInterval, mouse lags a lot from more frequent autosuspend.
> So this enables overriding bInterval for a hard wired hub device only
> when we know that reduces the power consumption.

I think I saw you argue about why this shouldn't simply be configured at
runtime. Please include that here too, I can't seem to remember why...

> Signed-off-by: Ikjoon Jang <ikjn@chromium.org>
> Acked-by: Alan Stern <stern@rowland.harvard.edu>
> ---
>  drivers/usb/core/config.c | 9 +++++++++
>  1 file changed, 9 insertions(+)
> 
> diff --git a/drivers/usb/core/config.c b/drivers/usb/core/config.c
> index 5f40117e68e7..95ec5af42a1c 100644
> --- a/drivers/usb/core/config.c
> +++ b/drivers/usb/core/config.c
> @@ -6,6 +6,7 @@
>  #include <linux/usb.h>
>  #include <linux/usb/ch9.h>
>  #include <linux/usb/hcd.h>
> +#include <linux/usb/of.h>
>  #include <linux/usb/quirks.h>
>  #include <linux/module.h>
>  #include <linux/slab.h>
> @@ -257,6 +258,14 @@ static int usb_parse_endpoint(struct device *ddev, int cfgno, int inum,
>  	memcpy(&endpoint->desc, d, n);
>  	INIT_LIST_HEAD(&endpoint->urb_list);
>  
> +	/* device node property overrides bInterval */
> +	if (usb_of_has_combined_node(to_usb_device(ddev))) {

Not only hubs have combined nodes so you probably need to check
bDeviceClass here instead.

> +		u32 interval = 0;
> +		if (!of_property_read_u32(ddev->of_node, "hub,interval",
> +				    &interval))
> +			d->bInterval = min_t(u8, interval, 255);

You want min_t(u32, ...) here to avoid surprises when someone specifies
a value > 255.

> +	}
> +
>  	/*
>  	 * Fix up bInterval values outside the legal range.
>  	 * Use 10 or 8 ms if no proper value can be guessed.

Johan

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH v4 2/2] usb: overridable hub bInterval by device node
  2019-12-03 16:53 ` Johan Hovold
@ 2019-12-04  7:04   ` Ikjoon Jang
  2019-12-04  7:55     ` Johan Hovold
  0 siblings, 1 reply; 14+ messages in thread
From: Ikjoon Jang @ 2019-12-04  7:04 UTC (permalink / raw)
  To: Johan Hovold
  Cc: linux-usb, GregKroah-Hartman, RobHerring, MarkRutland, AlanStern,
	SuwanKim, GustavoA . R . Silva, devicetree, linux-kernel,
	Nicolas Boichat

On Wed, Dec 4, 2019 at 12:52 AM Johan Hovold <johan@kernel.org> wrote:
>
> On Tue, Dec 03, 2019 at 06:15:52PM +0800, Ikjoon Jang wrote:
> > This patch enables hub device to override its own endpoint descriptor's
> > bInterval when the hub has a device node with "hub,interval" property.
> >
> > When we know reducing autosuspend delay for built-in HIDs is better for
> > power saving, we can reduce it to the optimal value. But if a parent hub
> > has a long bInterval, mouse lags a lot from more frequent autosuspend.
> > So this enables overriding bInterval for a hard wired hub device only
> > when we know that reduces the power consumption.
>
> I think I saw you argue about why this shouldn't simply be configured at
> runtime. Please include that here too, I can't seem to remember why...

Okay.

>
> > Signed-off-by: Ikjoon Jang <ikjn@chromium.org>
> > Acked-by: Alan Stern <stern@rowland.harvard.edu>
> > ---
> >  drivers/usb/core/config.c | 9 +++++++++
> >  1 file changed, 9 insertions(+)
> >
> > diff --git a/drivers/usb/core/config.c b/drivers/usb/core/config.c
> > index 5f40117e68e7..95ec5af42a1c 100644
> > --- a/drivers/usb/core/config.c
> > +++ b/drivers/usb/core/config.c
> > @@ -6,6 +6,7 @@
> >  #include <linux/usb.h>
> >  #include <linux/usb/ch9.h>
> >  #include <linux/usb/hcd.h>
> > +#include <linux/usb/of.h>
> >  #include <linux/usb/quirks.h>
> >  #include <linux/module.h>
> >  #include <linux/slab.h>
> > @@ -257,6 +258,14 @@ static int usb_parse_endpoint(struct device *ddev, int cfgno, int inum,
> >       memcpy(&endpoint->desc, d, n);
> >       INIT_LIST_HEAD(&endpoint->urb_list);
> >
> > +     /* device node property overrides bInterval */
> > +     if (usb_of_has_combined_node(to_usb_device(ddev))) {
>
> Not only hubs have combined nodes so you probably need to check
> bDeviceClass here instead.

yes, you're right, I didn't think of that case:
if (to_usb_device(ddev)->descriptor.bDeviceClass == USB_CLASS_HUB &&
ddev->of_node && !of_property_read_u32(...))

Or is it better to check bInterfaceClass, for composite devices with a
hub interface inside?
if (ifp->desc.bInterfaceClass == USB_CLASS_HUB && ddev->of_node &&
!of_property_read_u32(...))

I think checking bInterfaceClass is better.

>
> > +             u32 interval = 0;
> > +             if (!of_property_read_u32(ddev->of_node, "hub,interval",
> > +                                 &interval))
> > +                     d->bInterval = min_t(u8, interval, 255);
>
> You want min_t(u32, ...) here to avoid surprises when someone specifies
> a value > 255.

yes, thanks.

>
> > +     }
> > +
> >       /*
> >        * Fix up bInterval values outside the legal range.
> >        * Use 10 or 8 ms if no proper value can be guessed.
>
> Johan

I will send v5 soon, thank you.

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH v4 2/2] usb: overridable hub bInterval by device node
  2019-12-03 15:23 ` Alan Stern
@ 2019-12-04  7:07   ` Ikjoon Jang
  0 siblings, 0 replies; 14+ messages in thread
From: Ikjoon Jang @ 2019-12-04  7:07 UTC (permalink / raw)
  To: Alan Stern
  Cc: linux-usb, GregKroah-Hartman, RobHerring, MarkRutland, SuwanKim,
	GustavoA . R . Silva, JohanHovold, devicetree, linux-kernel,
	Nicolas Boichat

On Tue, Dec 3, 2019 at 11:23 PM Alan Stern <stern@rowland.harvard.edu> wrote:
>
> On Tue, 3 Dec 2019, Ikjoon Jang wrote:
>
> > This patch enables hub device to override its own endpoint descriptor's
> > bInterval when the hub has a device node with "hub,interval" property.
> >
> > When we know reducing autosuspend delay for built-in HIDs is better for
> > power saving, we can reduce it to the optimal value. But if a parent hub
> > has a long bInterval, mouse lags a lot from more frequent autosuspend.
> > So this enables overriding bInterval for a hard wired hub device only
> > when we know that reduces the power consumption.
> >
> > Signed-off-by: Ikjoon Jang <ikjn@chromium.org>
> > Acked-by: Alan Stern <stern@rowland.harvard.edu>
> > ---
> >  drivers/usb/core/config.c | 9 +++++++++
> >  1 file changed, 9 insertions(+)
> >
> > diff --git a/drivers/usb/core/config.c b/drivers/usb/core/config.c
> > index 5f40117e68e7..95ec5af42a1c 100644
> > --- a/drivers/usb/core/config.c
> > +++ b/drivers/usb/core/config.c
> > @@ -6,6 +6,7 @@
> >  #include <linux/usb.h>
> >  #include <linux/usb/ch9.h>
> >  #include <linux/usb/hcd.h>
> > +#include <linux/usb/of.h>
> >  #include <linux/usb/quirks.h>
> >  #include <linux/module.h>
> >  #include <linux/slab.h>
> > @@ -257,6 +258,14 @@ static int usb_parse_endpoint(struct device *ddev, int cfgno, int inum,
> >       memcpy(&endpoint->desc, d, n);
> >       INIT_LIST_HEAD(&endpoint->urb_list);
> >
> > +     /* device node property overrides bInterval */
> > +     if (usb_of_has_combined_node(to_usb_device(ddev))) {
> > +             u32 interval = 0;
>
> Coding style: there should be a blank line here.  Also, you don't need
> the "= 0" initializer.
>
> Otherwise okay.

Okay, I will fix that.
Thank you!

>
> Alan Stern
>
> > +             if (!of_property_read_u32(ddev->of_node, "hub,interval",
> > +                                 &interval))
> > +                     d->bInterval = min_t(u8, interval, 255);
> > +     }
> > +
> >       /*
> >        * Fix up bInterval values outside the legal range.
> >        * Use 10 or 8 ms if no proper value can be guessed.
>

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH v4 2/2] usb: overridable hub bInterval by device node
  2019-12-04  7:04   ` Ikjoon Jang
@ 2019-12-04  7:55     ` Johan Hovold
  2019-12-05  7:32       ` Ikjoon Jang
  0 siblings, 1 reply; 14+ messages in thread
From: Johan Hovold @ 2019-12-04  7:55 UTC (permalink / raw)
  To: Ikjoon Jang
  Cc: Johan Hovold, linux-usb, GregKroah-Hartman, RobHerring,
	MarkRutland, AlanStern, SuwanKim, GustavoA . R . Silva,
	devicetree, linux-kernel, Nicolas Boichat

On Wed, Dec 04, 2019 at 03:04:53PM +0800, Ikjoon Jang wrote:
> On Wed, Dec 4, 2019 at 12:52 AM Johan Hovold <johan@kernel.org> wrote:
> >
> > On Tue, Dec 03, 2019 at 06:15:52PM +0800, Ikjoon Jang wrote:
> > > This patch enables hub device to override its own endpoint descriptor's
> > > bInterval when the hub has a device node with "hub,interval" property.
> > >
> > > When we know reducing autosuspend delay for built-in HIDs is better for
> > > power saving, we can reduce it to the optimal value. But if a parent hub
> > > has a long bInterval, mouse lags a lot from more frequent autosuspend.
> > > So this enables overriding bInterval for a hard wired hub device only
> > > when we know that reduces the power consumption.
> >
> > I think I saw you argue about why this shouldn't simply be configured at
> > runtime. Please include that here too, I can't seem to remember why...
> 
> Okay.
> 
> >
> > > Signed-off-by: Ikjoon Jang <ikjn@chromium.org>
> > > Acked-by: Alan Stern <stern@rowland.harvard.edu>
> > > ---
> > >  drivers/usb/core/config.c | 9 +++++++++
> > >  1 file changed, 9 insertions(+)
> > >
> > > diff --git a/drivers/usb/core/config.c b/drivers/usb/core/config.c
> > > index 5f40117e68e7..95ec5af42a1c 100644
> > > --- a/drivers/usb/core/config.c
> > > +++ b/drivers/usb/core/config.c
> > > @@ -6,6 +6,7 @@
> > >  #include <linux/usb.h>
> > >  #include <linux/usb/ch9.h>
> > >  #include <linux/usb/hcd.h>
> > > +#include <linux/usb/of.h>
> > >  #include <linux/usb/quirks.h>
> > >  #include <linux/module.h>
> > >  #include <linux/slab.h>
> > > @@ -257,6 +258,14 @@ static int usb_parse_endpoint(struct device *ddev, int cfgno, int inum,
> > >       memcpy(&endpoint->desc, d, n);
> > >       INIT_LIST_HEAD(&endpoint->urb_list);
> > >
> > > +     /* device node property overrides bInterval */
> > > +     if (usb_of_has_combined_node(to_usb_device(ddev))) {
> >
> > Not only hubs have combined nodes so you probably need to check
> > bDeviceClass here instead.
> 
> yes, you're right, I didn't think of that case:
> if (to_usb_device(ddev)->descriptor.bDeviceClass == USB_CLASS_HUB &&
> ddev->of_node && !of_property_read_u32(...))
> 
> Or is it better to check bInterfaceClass, for composite devices with a
> hub interface inside?
> if (ifp->desc.bInterfaceClass == USB_CLASS_HUB && ddev->of_node &&
> !of_property_read_u32(...))
> 
> I think checking bInterfaceClass is better.

Yep, that seems better (but please use two conditionals for
readability).

But related to my question above, why do you need to do this during
enumeration? Why not just set the lower interval value in the hub
driver?

> > > +             u32 interval = 0;
> > > +             if (!of_property_read_u32(ddev->of_node, "hub,interval",
> > > +                                 &interval))
> > > +                     d->bInterval = min_t(u8, interval, 255);
> >
> > You want min_t(u32, ...) here to avoid surprises when someone specifies
> > a value > 255.
> 
> yes, thanks.

And I guess you should really be honouring bInterval as a maximum value,
right?

> > > +     }
> > > +
> > >       /*
> > >        * Fix up bInterval values outside the legal range.
> > >        * Use 10 or 8 ms if no proper value can be guessed.

Johan

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH v4 2/2] usb: overridable hub bInterval by device node
  2019-12-04  7:55     ` Johan Hovold
@ 2019-12-05  7:32       ` Ikjoon Jang
  2019-12-05 14:26         ` Johan Hovold
  0 siblings, 1 reply; 14+ messages in thread
From: Ikjoon Jang @ 2019-12-05  7:32 UTC (permalink / raw)
  To: Johan Hovold
  Cc: linux-usb, GregKroah-Hartman, RobHerring, MarkRutland, AlanStern,
	SuwanKim, GustavoA . R . Silva, devicetree, linux-kernel,
	Nicolas Boichat

On Wed, Dec 4, 2019 at 3:55 PM Johan Hovold <johan@kernel.org> wrote:

> > > > @@ -257,6 +258,14 @@ static int usb_parse_endpoint(struct device *ddev, int cfgno, int inum,
> > > >       memcpy(&endpoint->desc, d, n);
> > > >       INIT_LIST_HEAD(&endpoint->urb_list);
> > > >
> > > > +     /* device node property overrides bInterval */
> > > > +     if (usb_of_has_combined_node(to_usb_device(ddev))) {
> > >
> > > Not only hubs have combined nodes so you probably need to check
> > > bDeviceClass here instead.
> >
> > yes, you're right, I didn't think of that case:
> > if (to_usb_device(ddev)->descriptor.bDeviceClass == USB_CLASS_HUB &&
> > ddev->of_node && !of_property_read_u32(...))
> >
> > Or is it better to check bInterfaceClass, for composite devices with a
> > hub interface inside?
> > if (ifp->desc.bInterfaceClass == USB_CLASS_HUB && ddev->of_node &&
> > !of_property_read_u32(...))
> >
> > I think checking bInterfaceClass is better.
>
> Yep, that seems better (but please use two conditionals for
> readability).
>
> But related to my question above, why do you need to do this during
> enumeration? Why not just set the lower interval value in the hub
> driver?
>

Because I want device tree's bInterval to be checked against the same rules
defined in usb_parse_endpoint(). e.g. although hardware says its maximum
is 255, but the practical limit is still 0 to 16, so the code can
print warnings when
bInterval from device node is too weird.

> > > > +             u32 interval = 0;
> > > > +             if (!of_property_read_u32(ddev->of_node, "hub,interval",
> > > > +                                 &interval))
> > > > +                     d->bInterval = min_t(u8, interval, 255);
> > >
> > > You want min_t(u32, ...) here to avoid surprises when someone specifies
> > > a value > 255.
> >
> > yes, thanks.
>
> And I guess you should really be honouring bInterval as a maximum value,
> right?

Yes, right, not masking.

>
> > > > +     }
> > > > +
> > > >       /*
> > > >        * Fix up bInterval values outside the legal range.
> > > >        * Use 10 or 8 ms if no proper value can be guessed.
>
> Johan

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH v4 2/2] usb: overridable hub bInterval by device node
  2019-12-05  7:32       ` Ikjoon Jang
@ 2019-12-05 14:26         ` Johan Hovold
  2019-12-06  3:57           ` Ikjoon Jang
  0 siblings, 1 reply; 14+ messages in thread
From: Johan Hovold @ 2019-12-05 14:26 UTC (permalink / raw)
  To: Ikjoon Jang
  Cc: Johan Hovold, linux-usb, GregKroah-Hartman, RobHerring,
	MarkRutland, AlanStern, SuwanKim, GustavoA . R . Silva,
	devicetree, linux-kernel, Nicolas Boichat

On Thu, Dec 05, 2019 at 03:32:38PM +0800, Ikjoon Jang wrote:
> On Wed, Dec 4, 2019 at 3:55 PM Johan Hovold <johan@kernel.org> wrote:

> > But related to my question above, why do you need to do this during
> > enumeration? Why not just set the lower interval value in the hub
> > driver?
> 
> Because I want device tree's bInterval to be checked against the same rules
> defined in usb_parse_endpoint(). e.g. although hardware says its maximum
> is 255, but the practical limit is still 0 to 16, so the code can
> print warnings when bInterval from device node is too weird.

But that could be handled refactoring the code in question or similar.

The fundamental problem here is that you're using devicetree, which is
supposed to only describe the hardware, to encode policy which should be
deferred to user space.

So I think you need to figure out an interface that allows user space to
set the polling interval for any hub at runtime instead.

Johan

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH v4 2/2] usb: overridable hub bInterval by device node
  2019-12-05 14:26         ` Johan Hovold
@ 2019-12-06  3:57           ` Ikjoon Jang
  2019-12-06 15:00             ` Alan Stern
  2019-12-06 15:26             ` Johan Hovold
  0 siblings, 2 replies; 14+ messages in thread
From: Ikjoon Jang @ 2019-12-06  3:57 UTC (permalink / raw)
  To: Johan Hovold
  Cc: linux-usb, GregKroah-Hartman, RobHerring, MarkRutland, AlanStern,
	SuwanKim, GustavoA . R . Silva, devicetree, linux-kernel,
	Nicolas Boichat

On Thu, Dec 5, 2019 at 10:26 PM Johan Hovold <johan@kernel.org> wrote:
>
> On Thu, Dec 05, 2019 at 03:32:38PM +0800, Ikjoon Jang wrote:
> > On Wed, Dec 4, 2019 at 3:55 PM Johan Hovold <johan@kernel.org> wrote:
>
> > > But related to my question above, why do you need to do this during
> > > enumeration? Why not just set the lower interval value in the hub
> > > driver?
> >
> > Because I want device tree's bInterval to be checked against the same rules
> > defined in usb_parse_endpoint(). e.g. although hardware says its maximum
> > is 255, but the practical limit is still 0 to 16, so the code can
> > print warnings when bInterval from device node is too weird.
>
> But that could be handled refactoring the code in question or similar.
>

Yes, that should be worked. I can't exactly figure out how to refactor
the code for now, but maybe parsed endpoint descriptors are being
checked with default hard wired bInterval value and after that
an overridden value should be checked again.

Actually I don't care about the details of software policies. I just want
all devices to be handled in the same manner without any further
special treatments.

> The fundamental problem here is that you're using devicetree, which is
> supposed to only describe the hardware, to encode policy which should be
> deferred to user space.

The hub hardware has a default bInterval inside which is actually
adjustable. So I can think setting bInterval is to describe the hardware
rather than policy.

>
> So I think you need to figure out an interface that allows user space to
> set the polling interval for any hub at runtime instead.

Changing the interval at runtime is an another way to solve the
power consumption problem, but it's not so easy. At least xhci needs
to restart an endpoint and no devices are changing the interval after
enumeration stage.

Thanks!

>
> Johan

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH v4 2/2] usb: overridable hub bInterval by device node
  2019-12-06  3:57           ` Ikjoon Jang
@ 2019-12-06 15:00             ` Alan Stern
  2019-12-09  3:47               ` Ikjoon Jang
  2019-12-06 15:26             ` Johan Hovold
  1 sibling, 1 reply; 14+ messages in thread
From: Alan Stern @ 2019-12-06 15:00 UTC (permalink / raw)
  To: Ikjoon Jang
  Cc: Johan Hovold, linux-usb, GregKroah-Hartman, RobHerring,
	MarkRutland, SuwanKim, GustavoA . R . Silva, devicetree,
	linux-kernel, Nicolas Boichat

On Fri, 6 Dec 2019, Ikjoon Jang wrote:

> On Thu, Dec 5, 2019 at 10:26 PM Johan Hovold <johan@kernel.org> wrote:
> >
> > On Thu, Dec 05, 2019 at 03:32:38PM +0800, Ikjoon Jang wrote:
> > > On Wed, Dec 4, 2019 at 3:55 PM Johan Hovold <johan@kernel.org> wrote:
> >
> > > > But related to my question above, why do you need to do this during
> > > > enumeration? Why not just set the lower interval value in the hub
> > > > driver?
> > >
> > > Because I want device tree's bInterval to be checked against the same rules
> > > defined in usb_parse_endpoint(). e.g. although hardware says its maximum
> > > is 255, but the practical limit is still 0 to 16, so the code can
> > > print warnings when bInterval from device node is too weird.
> >
> > But that could be handled refactoring the code in question or similar.
> >
> 
> Yes, that should be worked. I can't exactly figure out how to refactor
> the code for now, but maybe parsed endpoint descriptors are being
> checked with default hard wired bInterval value and after that
> an overridden value should be checked again.
> 
> Actually I don't care about the details of software policies. I just want
> all devices to be handled in the same manner without any further
> special treatments.
> 
> > The fundamental problem here is that you're using devicetree, which is
> > supposed to only describe the hardware, to encode policy which should be
> > deferred to user space.
> 
> The hub hardware has a default bInterval inside which is actually
> adjustable. So I can think setting bInterval is to describe the hardware
> rather than policy.

If the hardware is adjustable, why don't you adjust the hardware 
instead of changing the software?

> > So I think you need to figure out an interface that allows user space to
> > set the polling interval for any hub at runtime instead.
> 
> Changing the interval at runtime is an another way to solve the
> power consumption problem, but it's not so easy. At least xhci needs
> to restart an endpoint and no devices are changing the interval after
> enumeration stage.

Restarting endpoints is easy; just call usb_set_interface().

Alan Stern


^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH v4 2/2] usb: overridable hub bInterval by device node
  2019-12-06  3:57           ` Ikjoon Jang
  2019-12-06 15:00             ` Alan Stern
@ 2019-12-06 15:26             ` Johan Hovold
  2019-12-09  4:05               ` Ikjoon Jang
  1 sibling, 1 reply; 14+ messages in thread
From: Johan Hovold @ 2019-12-06 15:26 UTC (permalink / raw)
  To: Ikjoon Jang
  Cc: Johan Hovold, linux-usb, GregKroah-Hartman, RobHerring,
	MarkRutland, AlanStern, SuwanKim, GustavoA . R . Silva,
	devicetree, linux-kernel, Nicolas Boichat, Mathias Nyman

On Fri, Dec 06, 2019 at 11:57:30AM +0800, Ikjoon Jang wrote:
> On Thu, Dec 5, 2019 at 10:26 PM Johan Hovold <johan@kernel.org> wrote:
> >
> > On Thu, Dec 05, 2019 at 03:32:38PM +0800, Ikjoon Jang wrote:
> > > On Wed, Dec 4, 2019 at 3:55 PM Johan Hovold <johan@kernel.org> wrote:
> >
> > > > But related to my question above, why do you need to do this during
> > > > enumeration? Why not just set the lower interval value in the hub
> > > > driver?
> > >
> > > Because I want device tree's bInterval to be checked against the same rules
> > > defined in usb_parse_endpoint(). e.g. although hardware says its maximum
> > > is 255, but the practical limit is still 0 to 16, so the code can
> > > print warnings when bInterval from device node is too weird.
> >
> > But that could be handled refactoring the code in question or similar.
> 
> Yes, that should be worked. I can't exactly figure out how to refactor
> the code for now, but maybe parsed endpoint descriptors are being
> checked with default hard wired bInterval value and after that
> an overridden value should be checked again.
> 
> Actually I don't care about the details of software policies. I just want
> all devices to be handled in the same manner without any further
> special treatments.

I'd say you're indeed trying to give a specific device special
treatment. ;)

> > The fundamental problem here is that you're using devicetree, which is
> > supposed to only describe the hardware, to encode policy which should be
> > deferred to user space.
> 
> The hub hardware has a default bInterval inside which is actually
> adjustable. So I can think setting bInterval is to describe the hardware
> rather than policy.

No, the USB spec says bInterval is a maximum requested value and that
the host is free to poll more often. And that's policy.

> > So I think you need to figure out an interface that allows user space to
> > set the polling interval for any hub at runtime instead.
> 
> Changing the interval at runtime is an another way to solve the
> power consumption problem, but it's not so easy. At least xhci needs
> to restart an endpoint and no devices are changing the interval after
> enumeration stage.

The usb-hid driver actually supports configuring the polling rate
for devices like mice and keyboards after enumeration (through a module
parameter, but still).

Unfortunately, the xhci driver does not yet support this and always uses
the device maximum bInterval. A bug report for this was filed many years
ago, perhaps it's time to address that (adding Mathias on CC):

	https://bugzilla.kernel.org/show_bug.cgi?id=82571

Johan

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH v4 2/2] usb: overridable hub bInterval by device node
  2019-12-06 15:00             ` Alan Stern
@ 2019-12-09  3:47               ` Ikjoon Jang
  0 siblings, 0 replies; 14+ messages in thread
From: Ikjoon Jang @ 2019-12-09  3:47 UTC (permalink / raw)
  To: Alan Stern
  Cc: Johan Hovold, linux-usb, GregKroah-Hartman, RobHerring,
	MarkRutland, SuwanKim, GustavoA . R . Silva, devicetree,
	linux-kernel, Nicolas Boichat

On Fri, Dec 6, 2019 at 11:00 PM Alan Stern <stern@rowland.harvard.edu> wrote:
>
> On Fri, 6 Dec 2019, Ikjoon Jang wrote:
>
> > On Thu, Dec 5, 2019 at 10:26 PM Johan Hovold <johan@kernel.org> wrote:
> > >
> > > On Thu, Dec 05, 2019 at 03:32:38PM +0800, Ikjoon Jang wrote:
> > > > On Wed, Dec 4, 2019 at 3:55 PM Johan Hovold <johan@kernel.org> wrote:
> > >
> > > > > But related to my question above, why do you need to do this during
> > > > > enumeration? Why not just set the lower interval value in the hub
> > > > > driver?
> > > >
> > > > Because I want device tree's bInterval to be checked against the same rules
> > > > defined in usb_parse_endpoint(). e.g. although hardware says its maximum
> > > > is 255, but the practical limit is still 0 to 16, so the code can
> > > > print warnings when bInterval from device node is too weird.
> > >
> > > But that could be handled refactoring the code in question or similar.
> > >
> >
> > Yes, that should be worked. I can't exactly figure out how to refactor
> > the code for now, but maybe parsed endpoint descriptors are being
> > checked with default hard wired bInterval value and after that
> > an overridden value should be checked again.
> >
> > Actually I don't care about the details of software policies. I just want
> > all devices to be handled in the same manner without any further
> > special treatments.
> >
> > > The fundamental problem here is that you're using devicetree, which is
> > > supposed to only describe the hardware, to encode policy which should be
> > > deferred to user space.
> >
> > The hub hardware has a default bInterval inside which is actually
> > adjustable. So I can think setting bInterval is to describe the hardware
> > rather than policy.
>
> If the hardware is adjustable, why don't you adjust the hardware
> instead of changing the software?

sorry, I meant "hardware has a default value but it's actually
adjustable (by software)". Adjusting hardware is the best option but
our hub doesn't allow to do that, so the current approach is patching
a hardware descriptor on enumeration stage.

>
> > > So I think you need to figure out an interface that allows user space to
> > > set the polling interval for any hub at runtime instead.
> >
> > Changing the interval at runtime is an another way to solve the
> > power consumption problem, but it's not so easy. At least xhci needs
> > to restart an endpoint and no devices are changing the interval after
> > enumeration stage.
>
> Restarting endpoints is easy; just call usb_set_interface().

I thought just changing urb->interval at runtime will be more acceptable.
Maybe I'll need an another approach if this patch is unacceptable.

Thank you!

>
> Alan Stern
>

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH v4 2/2] usb: overridable hub bInterval by device node
  2019-12-06 15:26             ` Johan Hovold
@ 2019-12-09  4:05               ` Ikjoon Jang
  2019-12-10 15:02                 ` Johan Hovold
  0 siblings, 1 reply; 14+ messages in thread
From: Ikjoon Jang @ 2019-12-09  4:05 UTC (permalink / raw)
  To: Johan Hovold
  Cc: linux-usb, GregKroah-Hartman, RobHerring, MarkRutland, AlanStern,
	SuwanKim, GustavoA . R . Silva, devicetree, linux-kernel,
	Nicolas Boichat, Mathias Nyman

On Fri, Dec 6, 2019 at 11:25 PM Johan Hovold <johan@kernel.org> wrote:
>
> On Fri, Dec 06, 2019 at 11:57:30AM +0800, Ikjoon Jang wrote:
> > On Thu, Dec 5, 2019 at 10:26 PM Johan Hovold <johan@kernel.org> wrote:
> > >
> > > On Thu, Dec 05, 2019 at 03:32:38PM +0800, Ikjoon Jang wrote:
> > > > On Wed, Dec 4, 2019 at 3:55 PM Johan Hovold <johan@kernel.org> wrote:
> > >
> > > > > But related to my question above, why do you need to do this during
> > > > > enumeration? Why not just set the lower interval value in the hub
> > > > > driver?
> > > >
> > > > Because I want device tree's bInterval to be checked against the same rules
> > > > defined in usb_parse_endpoint(). e.g. although hardware says its maximum
> > > > is 255, but the practical limit is still 0 to 16, so the code can
> > > > print warnings when bInterval from device node is too weird.
> > >
> > > But that could be handled refactoring the code in question or similar.
> >
> > Yes, that should be worked. I can't exactly figure out how to refactor
> > the code for now, but maybe parsed endpoint descriptors are being
> > checked with default hard wired bInterval value and after that
> > an overridden value should be checked again.
> >
> > Actually I don't care about the details of software policies. I just want
> > all devices to be handled in the same manner without any further
> > special treatments.
>
> I'd say you're indeed trying to give a specific device special
> treatment. ;)

yeah right, I'm giving one treatment but I mean not any further.

>
> > > The fundamental problem here is that you're using devicetree, which is
> > > supposed to only describe the hardware, to encode policy which should be
> > > deferred to user space.
> >
> > The hub hardware has a default bInterval inside which is actually
> > adjustable. So I can think setting bInterval is to describe the hardware
> > rather than policy.
>
> No, the USB spec says bInterval is a maximum requested value and that
> the host is free to poll more often. And that's policy.

Honestly I'm a bit confused on the border line between hardware
and software definition. That's quite reasonable it's policy that software
can poll more often than hardware specified, but can we think it's just
overriding hardware property specifying maximum value from beginning?
Is it still policy? or 'overriding hardware property' part is already not
a hardware description? :-S

>
> > > So I think you need to figure out an interface that allows user space to
> > > set the polling interval for any hub at runtime instead.
> >
> > Changing the interval at runtime is an another way to solve the
> > power consumption problem, but it's not so easy. At least xhci needs
> > to restart an endpoint and no devices are changing the interval after
> > enumeration stage.
>
> The usb-hid driver actually supports configuring the polling rate
> for devices like mice and keyboards after enumeration (through a module
> parameter, but still).
>
> Unfortunately, the xhci driver does not yet support this and always uses
> the device maximum bInterval. A bug report for this was filed many years
> ago, perhaps it's time to address that (adding Mathias on CC):
>
>         https://bugzilla.kernel.org/show_bug.cgi?id=82571

Thanks!

>
> Johan

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH v4 2/2] usb: overridable hub bInterval by device node
  2019-12-09  4:05               ` Ikjoon Jang
@ 2019-12-10 15:02                 ` Johan Hovold
  0 siblings, 0 replies; 14+ messages in thread
From: Johan Hovold @ 2019-12-10 15:02 UTC (permalink / raw)
  To: Ikjoon Jang
  Cc: Johan Hovold, linux-usb, GregKroah-Hartman, RobHerring,
	MarkRutland, AlanStern, SuwanKim, GustavoA . R . Silva,
	devicetree, linux-kernel, Nicolas Boichat, Mathias Nyman

On Mon, Dec 09, 2019 at 12:05:53PM +0800, Ikjoon Jang wrote:
> On Fri, Dec 6, 2019 at 11:25 PM Johan Hovold <johan@kernel.org> wrote:
> >
> > On Fri, Dec 06, 2019 at 11:57:30AM +0800, Ikjoon Jang wrote:
> > > On Thu, Dec 5, 2019 at 10:26 PM Johan Hovold <johan@kernel.org> wrote:

> > > > The fundamental problem here is that you're using devicetree, which is
> > > > supposed to only describe the hardware, to encode policy which should be
> > > > deferred to user space.
> > >
> > > The hub hardware has a default bInterval inside which is actually
> > > adjustable. So I can think setting bInterval is to describe the hardware
> > > rather than policy.
> >
> > No, the USB spec says bInterval is a maximum requested value and that
> > the host is free to poll more often. And that's policy.
> 
> Honestly I'm a bit confused on the border line between hardware
> and software definition. That's quite reasonable it's policy that software
> can poll more often than hardware specified, but can we think it's just
> overriding hardware property specifying maximum value from beginning?
> Is it still policy? or 'overriding hardware property' part is already not
> a hardware description? :-S

The hardware is supposed to give you the upper limit, and then software
is allowed to poll more often if it wants to and is able to do so.

In this case that decision depends partly on what is connected to the
hub but also on how that device in turn has been configured,
specifically, whether runtime PM has been enabled or not.

Someone who doesn't use the downstream device, or who prefers to never
suspend it, may not be willing to pay the price for polling the hub more
frequently, for example. 

So this ends up being very much a policy decision which should be left
for user space.

But if you can come up with a generic interface for this, it could be
useful in other setups as well (non-DT, hot-pluggable, etc).

Johan

^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, back to index

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-12-03 10:15 [PATCH v4 2/2] usb: overridable hub bInterval by device node Ikjoon Jang
2019-12-03 15:23 ` Alan Stern
2019-12-04  7:07   ` Ikjoon Jang
2019-12-03 16:53 ` Johan Hovold
2019-12-04  7:04   ` Ikjoon Jang
2019-12-04  7:55     ` Johan Hovold
2019-12-05  7:32       ` Ikjoon Jang
2019-12-05 14:26         ` Johan Hovold
2019-12-06  3:57           ` Ikjoon Jang
2019-12-06 15:00             ` Alan Stern
2019-12-09  3:47               ` Ikjoon Jang
2019-12-06 15:26             ` Johan Hovold
2019-12-09  4:05               ` Ikjoon Jang
2019-12-10 15:02                 ` Johan Hovold

Linux-Devicetree Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-devicetree/0 linux-devicetree/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-devicetree linux-devicetree/ https://lore.kernel.org/linux-devicetree \
		devicetree@vger.kernel.org
	public-inbox-index linux-devicetree

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-devicetree


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git