* [PATCH] usb: gadget: f_hid: convert polling interval from ms to bInterval units
@ 2026-07-16 14:49 Arthur Crépin Leblond
2026-07-17 10:26 ` Greg Kroah-Hartman
0 siblings, 1 reply; 3+ messages in thread
From: Arthur Crépin Leblond @ 2026-07-16 14:49 UTC (permalink / raw)
To: linux-usb; +Cc: Arthur Crépin Leblond, Ben Hoff, Greg Kroah-Hartman
The HID polling interval is different depending on the USB speed.
- Full speed: the units are milliseconds (1-255)
- High/Super speed: the units are micro-frames of 0.125ms
Exposing directly the bInterval means that the user needs to know
which speed is currently in use and has to convert it accordingly
themselves.
The solution is to expose the interval in units of milliseconds and
do the conversion in the driver.
Cc: Ben Hoff <hoff.benjamin.k@gmail.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Arthur Crépin Leblond <arthur@marmottus.net>
---
Documentation/ABI/testing/configfs-usb-gadget-hid | 10 ++++++++++
drivers/usb/gadget/function/f_hid.c | 8 ++++----
2 files changed, 14 insertions(+), 4 deletions(-)
diff --git a/Documentation/ABI/testing/configfs-usb-gadget-hid b/Documentation/ABI/testing/configfs-usb-gadget-hid
index 748705c4cb58..006d479b7428 100644
--- a/Documentation/ABI/testing/configfs-usb-gadget-hid
+++ b/Documentation/ABI/testing/configfs-usb-gadget-hid
@@ -11,3 +11,13 @@ Description:
report_length HID report length
subclass HID device subclass to use
============= ============================================
+
+What: /config/usb-gadget/gadget/functions/hid.name/interval
+Date: Jul 2026
+KernelVersion: 7.2
+Description:
+ The polling interval for the HID endpoint(s), expressed in
+ milliseconds in the range 1-255.
+
+ The value is speed-independent: the driver converts it to the
+ appropriate bInterval.
diff --git a/drivers/usb/gadget/function/f_hid.c b/drivers/usb/gadget/function/f_hid.c
index 3c6b43d06a6d..49548a96c1e8 100644
--- a/drivers/usb/gadget/function/f_hid.c
+++ b/drivers/usb/gadget/function/f_hid.c
@@ -1211,8 +1211,8 @@ static int hidg_bind(struct usb_configuration *c, struct usb_function *f)
hidg_ss_in_ep_desc.bInterval = 4;
} else {
hidg_fs_in_ep_desc.bInterval = hidg->interval;
- hidg_hs_in_ep_desc.bInterval = hidg->interval;
- hidg_ss_in_ep_desc.bInterval = hidg->interval;
+ hidg_hs_in_ep_desc.bInterval = USB_MS_TO_HS_INTERVAL(hidg->interval);
+ hidg_ss_in_ep_desc.bInterval = USB_MS_TO_HS_INTERVAL(hidg->interval);
}
hidg_ss_out_comp_desc.wBytesPerInterval =
@@ -1245,8 +1245,8 @@ static int hidg_bind(struct usb_configuration *c, struct usb_function *f)
hidg_ss_out_ep_desc.bInterval = 4;
} else {
hidg_fs_out_ep_desc.bInterval = hidg->interval;
- hidg_hs_out_ep_desc.bInterval = hidg->interval;
- hidg_ss_out_ep_desc.bInterval = hidg->interval;
+ hidg_hs_out_ep_desc.bInterval = USB_MS_TO_HS_INTERVAL(hidg->interval);
+ hidg_ss_out_ep_desc.bInterval = USB_MS_TO_HS_INTERVAL(hidg->interval);
}
status = usb_assign_descriptors(f,
hidg_fs_descriptors_intout,
--
2.55.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] usb: gadget: f_hid: convert polling interval from ms to bInterval units
2026-07-16 14:49 [PATCH] usb: gadget: f_hid: convert polling interval from ms to bInterval units Arthur Crépin Leblond
@ 2026-07-17 10:26 ` Greg Kroah-Hartman
2026-07-17 13:02 ` Arthur Crepin Leblond
0 siblings, 1 reply; 3+ messages in thread
From: Greg Kroah-Hartman @ 2026-07-17 10:26 UTC (permalink / raw)
To: Arthur Crépin Leblond; +Cc: linux-usb, Ben Hoff
On Thu, Jul 16, 2026 at 04:49:21PM +0200, Arthur Crépin Leblond wrote:
> The HID polling interval is different depending on the USB speed.
>
> - Full speed: the units are milliseconds (1-255)
> - High/Super speed: the units are micro-frames of 0.125ms
>
> Exposing directly the bInterval means that the user needs to know
> which speed is currently in use and has to convert it accordingly
> themselves.
>
> The solution is to expose the interval in units of milliseconds and
> do the conversion in the driver.
>
> Cc: Ben Hoff <hoff.benjamin.k@gmail.com>
> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> Signed-off-by: Arthur Crépin Leblond <arthur@marmottus.net>
> ---
> Documentation/ABI/testing/configfs-usb-gadget-hid | 10 ++++++++++
> drivers/usb/gadget/function/f_hid.c | 8 ++++----
> 2 files changed, 14 insertions(+), 4 deletions(-)
>
> diff --git a/Documentation/ABI/testing/configfs-usb-gadget-hid b/Documentation/ABI/testing/configfs-usb-gadget-hid
> index 748705c4cb58..006d479b7428 100644
> --- a/Documentation/ABI/testing/configfs-usb-gadget-hid
> +++ b/Documentation/ABI/testing/configfs-usb-gadget-hid
> @@ -11,3 +11,13 @@ Description:
> report_length HID report length
> subclass HID device subclass to use
> ============= ============================================
> +
> +What: /config/usb-gadget/gadget/functions/hid.name/interval
> +Date: Jul 2026
> +KernelVersion: 7.2
> +Description:
> + The polling interval for the HID endpoint(s), expressed in
> + milliseconds in the range 1-255.
> +
> + The value is speed-independent: the driver converts it to the
> + appropriate bInterval.
> diff --git a/drivers/usb/gadget/function/f_hid.c b/drivers/usb/gadget/function/f_hid.c
> index 3c6b43d06a6d..49548a96c1e8 100644
> --- a/drivers/usb/gadget/function/f_hid.c
> +++ b/drivers/usb/gadget/function/f_hid.c
> @@ -1211,8 +1211,8 @@ static int hidg_bind(struct usb_configuration *c, struct usb_function *f)
> hidg_ss_in_ep_desc.bInterval = 4;
> } else {
> hidg_fs_in_ep_desc.bInterval = hidg->interval;
> - hidg_hs_in_ep_desc.bInterval = hidg->interval;
> - hidg_ss_in_ep_desc.bInterval = hidg->interval;
> + hidg_hs_in_ep_desc.bInterval = USB_MS_TO_HS_INTERVAL(hidg->interval);
> + hidg_ss_in_ep_desc.bInterval = USB_MS_TO_HS_INTERVAL(hidg->interval);
> }
>
> hidg_ss_out_comp_desc.wBytesPerInterval =
> @@ -1245,8 +1245,8 @@ static int hidg_bind(struct usb_configuration *c, struct usb_function *f)
> hidg_ss_out_ep_desc.bInterval = 4;
> } else {
> hidg_fs_out_ep_desc.bInterval = hidg->interval;
> - hidg_hs_out_ep_desc.bInterval = hidg->interval;
> - hidg_ss_out_ep_desc.bInterval = hidg->interval;
> + hidg_hs_out_ep_desc.bInterval = USB_MS_TO_HS_INTERVAL(hidg->interval);
> + hidg_ss_out_ep_desc.bInterval = USB_MS_TO_HS_INTERVAL(hidg->interval);
So this breaks the current usage, as the value previously used now
operates differently, right?
Yes, it was never documented, but by changing this, what are you now
causing to be changed when kernels are updated and userspace isn't
modified?
thanks,
greg k-h
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] usb: gadget: f_hid: convert polling interval from ms to bInterval units
2026-07-17 10:26 ` Greg Kroah-Hartman
@ 2026-07-17 13:02 ` Arthur Crepin Leblond
0 siblings, 0 replies; 3+ messages in thread
From: Arthur Crepin Leblond @ 2026-07-17 13:02 UTC (permalink / raw)
To: Greg Kroah-Hartman; +Cc: linux-usb, Ben Hoff
On Friday 17 July 2026 12:26:19 PM (+02:00), Greg Kroah-Hartman wrote:
> On Thu, Jul 16, 2026 at 04:49:21PM +0200, Arthur Crépin Leblond wrote:
> > The HID polling interval is different depending on the USB speed.
> >
> > - Full speed: the units are milliseconds (1-255)
> > - High/Super speed: the units are micro-frames of 0.125ms
> >
> > Exposing directly the bInterval means that the user needs to know
> > which speed is currently in use and has to convert it accordingly
> > themselves.
> >
> > The solution is to expose the interval in units of milliseconds and
> > do the conversion in the driver.
> >
> > Cc: Ben Hoff <hoff.benjamin.k@gmail.com>
> > Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> > Signed-off-by: Arthur Crépin Leblond <arthur@marmottus.net>
> > ---
> > Documentation/ABI/testing/configfs-usb-gadget-hid | 10 ++++++++++
> > drivers/usb/gadget/function/f_hid.c | 8 ++++----
> > 2 files changed, 14 insertions(+), 4 deletions(-)
> >
> > diff --git a/Documentation/ABI/testing/configfs-usb-gadget-hid b/Documentation/ABI/testing/configfs-usb-gadget-hid
> > index 748705c4cb58..006d479b7428 100644
> > --- a/Documentation/ABI/testing/configfs-usb-gadget-hid
> > +++ b/Documentation/ABI/testing/configfs-usb-gadget-hid
> > @@ -11,3 +11,13 @@ Description:
> > report_length HID report length
> > subclass HID device subclass to use
> > ============= ============================================
> > +
> > +What: /config/usb-gadget/gadget/functions/hid.name/interval
> > +Date: Jul 2026
> > +KernelVersion: 7.2
> > +Description:
> > + The polling interval for the HID endpoint(s), expressed in
> > + milliseconds in the range 1-255.
> > +
> > + The value is speed-independent: the driver converts it to the
> > + appropriate bInterval.
> > diff --git a/drivers/usb/gadget/function/f_hid.c b/drivers/usb/gadget/function/f_hid.c
> > index 3c6b43d06a6d..49548a96c1e8 100644
> > --- a/drivers/usb/gadget/function/f_hid.c
> > +++ b/drivers/usb/gadget/function/f_hid.c
> > @@ -1211,8 +1211,8 @@ static int hidg_bind(struct usb_configuration *c, struct usb_function *f)
> > hidg_ss_in_ep_desc.bInterval = 4;
> > } else {
> > hidg_fs_in_ep_desc.bInterval = hidg->interval;
> > - hidg_hs_in_ep_desc.bInterval = hidg->interval;
> > - hidg_ss_in_ep_desc.bInterval = hidg->interval;
> > + hidg_hs_in_ep_desc.bInterval = USB_MS_TO_HS_INTERVAL(hidg->interval);
> > + hidg_ss_in_ep_desc.bInterval = USB_MS_TO_HS_INTERVAL(hidg->interval);
> > }
> >
> > hidg_ss_out_comp_desc.wBytesPerInterval =
> > @@ -1245,8 +1245,8 @@ static int hidg_bind(struct usb_configuration *c, struct usb_function *f)
> > hidg_ss_out_ep_desc.bInterval = 4;
> > } else {
> > hidg_fs_out_ep_desc.bInterval = hidg->interval;
> > - hidg_hs_out_ep_desc.bInterval = hidg->interval;
> > - hidg_ss_out_ep_desc.bInterval = hidg->interval;
> > + hidg_hs_out_ep_desc.bInterval = USB_MS_TO_HS_INTERVAL(hidg->interval);
> > + hidg_ss_out_ep_desc.bInterval = USB_MS_TO_HS_INTERVAL(hidg->interval);
>
> So this breaks the current usage, as the value previously used now
> operates differently, right?
>
> Yes, it was never documented, but by changing this, what are you now
> causing to be changed when kernels are updated and userspace isn't
> modified?
>
> thanks,
>
> greg k-h
>
Hi Greg,
Hmmm, agreed, this would break compatibility as the userland expects
the value to be the *real* bInterval.
But it is also not convenient as we cannot know which speed will be
negotiated and therefore set the bInterval accordingly.
Having the same bInterval for all speeds does not adapt.
One solution could be to expose 3 attributes
* interval_fs -> bInterval for full-speed
* interval_hs -> bInterval for high-speed
* interval_ss -> bInterval for super-speed
Taking precedence over the regular interval one if set. Too overkill?
--
Arthur Crépin Leblond
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-07-17 13:03 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-16 14:49 [PATCH] usb: gadget: f_hid: convert polling interval from ms to bInterval units Arthur Crépin Leblond
2026-07-17 10:26 ` Greg Kroah-Hartman
2026-07-17 13:02 ` Arthur Crepin Leblond
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox