Skip to contentSkip to conversation

media: uvcvideo: fix the bandwdith quirk on USB 3.x

PATCH In review Michal Pecio 3 participants 3 messages Apr 14, 2024 – Jun 16, 2024

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 media: uvcvideo: fix the bandwdith quirk on USB 3.x

The bandwidth fixup quirk doesn't know that SuperSpeed exists and has the same 8 service intervals per millisecond as High Speed, hence its calculations are wrong.

Assume that all speeds from HS up use 8 intervals per millisecond.

No further changes are needed, updated code has been confirmed to work with all speeds from FS to SS.

---
 drivers/media/usb/uvc/uvc_video.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/media/usb/uvc/uvc_video.c +3 -3
index 28dde08ec6c5..4b86bef06a52 100644
@@ -214,13 +214,13 @@ static void uvc_fixup_video_ctrl(struct uvc_streaming *stream,
 		 * Compute a bandwidth estimation by multiplying the frame
 		 * size by the number of video frames per second, divide the
 		 * result by the number of USB frames (or micro-frames for
-		 * high-speed devices) per second and add the UVC header size
-		 * (assumed to be 12 bytes long).
+		 * high- and super-speed devices) per second and add the UVC
+		 * header size (assumed to be 12 bytes long).
 		 */
 		bandwidth = frame->wWidth * frame->wHeight / 8 * format->bpp;
 		bandwidth *= 10000000 / interval + 1;
 		bandwidth /= 1000;
-		if (stream->dev->udev->speed == USB_SPEED_HIGH)
+		if (stream->dev->udev->speed >= USB_SPEED_HIGH)
 			bandwidth /= 8;
 		bandwidth += 12;
 
Signature · 1 line
2.43.0
Reviewed-by on v1 1/1
#1 lore raw

Hi Michal

Quoted 11 lines · Michal Pecio

The bandwidth fixup quirk doesn't know that SuperSpeed exists and has the same 8 service intervals per millisecond as High Speed, hence its calculations are wrong.

Assume that all speeds from HS up use 8 intervals per millisecond.

No further changes are needed, updated code has been confirmed to work with all speeds from FS to SS.

Quoted 29 lines
---
 drivers/media/usb/uvc/uvc_video.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/media/usb/uvc/uvc_video.c +3 -4
index 28dde08ec6c5..4b86bef06a52 100644
@@ -214,13 +214,13 @@ static void uvc_fixup_video_ctrl(struct uvc_streaming *stream,
                 * Compute a bandwidth estimation by multiplying the frame
                 * size by the number of video frames per second, divide the
                 * result by the number of USB frames (or micro-frames for
-                * high-speed devices) per second and add the UVC header size
-                * (assumed to be 12 bytes long).
+                * high- and super-speed devices) per second and add the UVC
+                * header size (assumed to be 12 bytes long).
                 */
                bandwidth = frame->wWidth * frame->wHeight / 8 * format->bpp;
                bandwidth *= 10000000 / interval + 1;
                bandwidth /= 1000;
-               if (stream->dev->udev->speed == USB_SPEED_HIGH)
+               if (stream->dev->udev->speed >= USB_SPEED_HIGH)
                        bandwidth /= 8;
                bandwidth += 12;
 
--

2.43.0

Signature · 1 line
Ricardo Ribalda
maintainer Reviewed-by on v1 1/1
#2 lore raw
In reply to Michal Pecio

Hi Michal,

Thank you for the patch.

Quoted 10 lines · Michal Pecio

The bandwidth fixup quirk doesn't know that SuperSpeed exists and has the same 8 service intervals per millisecond as High Speed, hence its calculations are wrong.

Assume that all speeds from HS up use 8 intervals per millisecond.

No further changes are needed, updated code has been confirmed to work with all speeds from FS to SS.

Quoted 25 lines
---
 drivers/media/usb/uvc/uvc_video.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/media/usb/uvc/uvc_video.c +3 -3
index 28dde08ec6c5..4b86bef06a52 100644
@@ -214,13 +214,13 @@ static void uvc_fixup_video_ctrl(struct uvc_streaming *stream,
 		 * Compute a bandwidth estimation by multiplying the frame
 		 * size by the number of video frames per second, divide the
 		 * result by the number of USB frames (or micro-frames for
-		 * high-speed devices) per second and add the UVC header size
-		 * (assumed to be 12 bytes long).
+		 * high- and super-speed devices) per second and add the UVC
+		 * header size (assumed to be 12 bytes long).
 		 */
 		bandwidth = frame->wWidth * frame->wHeight / 8 * format->bpp;
 		bandwidth *= 10000000 / interval + 1;
 		bandwidth /= 1000;
-		if (stream->dev->udev->speed == USB_SPEED_HIGH)
+		if (stream->dev->udev->speed >= USB_SPEED_HIGH)
 			bandwidth /= 8;
 		bandwidth += 12;
 
Signature · 3 lines
Regards,

Laurent Pinchart