2022-12-05 13:20:08

by Ricardo Ribalda

[permalink] [raw]
Subject: [PATCH v3] media: uvcvideo: Recover stalled ElGato devices

Elgato Cam Link 4k can be in a stalled state if the resolution of
the external source has changed while the firmware initializes.
Once in this state, the device is useless until it receives a
USB reset. It has even been observed that the stalled state will
continue even after unplugging the device.

lsusb -v

Bus 002 Device 002: ID 0fd9:0066 Elgato Systems GmbH Cam Link 4K
Device Descriptor:
bLength 18
bDescriptorType 1
bcdUSB 3.00
bDeviceClass 239 Miscellaneous Device
bDeviceSubClass 2
bDeviceProtocol 1 Interface Association
bMaxPacketSize0 9
idVendor 0x0fd9 Elgato Systems GmbH
idProduct 0x0066
bcdDevice 0.00
iManufacturer 1 Elgato
iProduct 2 Cam Link 4K
iSerial 4 0005AC52FE000
bNumConfigurations 1

Reviewed-by: Sergey Senozhatsky <[email protected]>
Signed-off-by: Ricardo Ribalda <[email protected]>
---
Recover stalled ElGato devices

Just a resend of this hw fix.

To: Laurent Pinchart <[email protected]>
To: Mauro Carvalho Chehab <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: Sergey Senozhatsky <[email protected]>
Cc: Yunke Cao <[email protected]>
---
Changes in v3:
- Add Reviewed-by: Sergey
- Improve identation (Thanks Sergey!)
- Link to v2: https://lore.kernel.org/r/[email protected]

Changes in v2:
- Remove info from lsusb
- Link to v1: https://lore.kernel.org/r/[email protected]
---
drivers/media/usb/uvc/uvc_video.c | 23 +++++++++++++++++++----
1 file changed, 19 insertions(+), 4 deletions(-)

diff --git a/drivers/media/usb/uvc/uvc_video.c b/drivers/media/usb/uvc/uvc_video.c
index 170a008f4006..a8323cf0e9f9 100644
--- a/drivers/media/usb/uvc/uvc_video.c
+++ b/drivers/media/usb/uvc/uvc_video.c
@@ -129,12 +129,13 @@ int uvc_query_ctrl(struct uvc_device *dev, u8 query, u8 unit,
return -EPIPE;
}

+static const struct usb_device_id elgato_cam_link_4k = {
+ USB_DEVICE(0x0fd9, 0x0066)
+};
+
static void uvc_fixup_video_ctrl(struct uvc_streaming *stream,
struct uvc_streaming_control *ctrl)
{
- static const struct usb_device_id elgato_cam_link_4k = {
- USB_DEVICE(0x0fd9, 0x0066)
- };
struct uvc_format *format = NULL;
struct uvc_frame *frame = NULL;
unsigned int i;
@@ -297,7 +298,7 @@ static int uvc_get_video_ctrl(struct uvc_streaming *stream,
dev_err(&stream->intf->dev,
"Failed to query (%u) UVC %s control : %d (exp. %u).\n",
query, probe ? "probe" : "commit", ret, size);
- ret = -EIO;
+ ret = (ret == -EPROTO) ? -EPROTO : -EIO;
goto out;
}

@@ -2121,6 +2122,20 @@ int uvc_video_init(struct uvc_streaming *stream)
* request on the probe control, as required by the UVC specification.
*/
ret = uvc_get_video_ctrl(stream, probe, 1, UVC_GET_CUR);
+
+ /*
+ * Elgato Cam Link 4k can be in a stalled state if the resolution of
+ * the external source has changed while the firmware initializes.
+ * Once in this state, the device is useless until it receives a
+ * USB reset. It has even been observed that the stalled state will
+ * continue even after unplugging the device.
+ */
+ if (usb_match_one_id(stream->dev->intf, &elgato_cam_link_4k) &&
+ (ret == -EPROTO)) {
+ usb_reset_device(stream->dev->udev);
+ dev_err(&stream->intf->dev, "Restarting Elgato Cam Link 4K\n");
+ }
+
if (ret < 0)
return ret;


---
base-commit: 521a547ced6477c54b4b0cc206000406c221b4d6
change-id: 20220920-resend-elgato-a845482bdd02

Best regards,
--
Ricardo Ribalda <[email protected]>


2022-12-05 23:06:03

by Laurent Pinchart

[permalink] [raw]
Subject: Re: [PATCH v3] media: uvcvideo: Recover stalled ElGato devices

Hi Ricardo,

On Mon, Dec 05, 2022 at 11:45:43PM +0100, Ricardo Ribalda wrote:
> On Mon, 5 Dec 2022 at 23:39, Laurent Pinchart wrote:
> > On Mon, Dec 05, 2022 at 01:53:01PM +0100, Ricardo Ribalda wrote:
> > > Elgato Cam Link 4k can be in a stalled state if the resolution of
> > > the external source has changed while the firmware initializes.
> > > Once in this state, the device is useless until it receives a
> > > USB reset. It has even been observed that the stalled state will
> > > continue even after unplugging the device.
> >
> > Why, ô, why :'-(
> >
> > > lsusb -v
> > >
> > > Bus 002 Device 002: ID 0fd9:0066 Elgato Systems GmbH Cam Link 4K
> > > Device Descriptor:
> > > bLength 18
> > > bDescriptorType 1
> > > bcdUSB 3.00
> > > bDeviceClass 239 Miscellaneous Device
> > > bDeviceSubClass 2
> > > bDeviceProtocol 1 Interface Association
> > > bMaxPacketSize0 9
> > > idVendor 0x0fd9 Elgato Systems GmbH
> > > idProduct 0x0066
> > > bcdDevice 0.00
> > > iManufacturer 1 Elgato
> > > iProduct 2 Cam Link 4K
> > > iSerial 4 0005AC52FE000
> > > bNumConfigurations 1
> > >
> > > Reviewed-by: Sergey Senozhatsky <[email protected]>
> > > Signed-off-by: Ricardo Ribalda <[email protected]>
> > > ---
> > > Recover stalled ElGato devices
> > >
> > > Just a resend of this hw fix.
> > >
> > > To: Laurent Pinchart <[email protected]>
> > > To: Mauro Carvalho Chehab <[email protected]>
> > > Cc: [email protected]
> > > Cc: [email protected]
> > > Cc: Sergey Senozhatsky <[email protected]>
> > > Cc: Yunke Cao <[email protected]>
> > > ---
> > > Changes in v3:
> > > - Add Reviewed-by: Sergey
> > > - Improve identation (Thanks Sergey!)
> > > - Link to v2: https://lore.kernel.org/r/[email protected]
> > >
> > > Changes in v2:
> > > - Remove info from lsusb
> > > - Link to v1: https://lore.kernel.org/r/[email protected]
> > > ---
> > > drivers/media/usb/uvc/uvc_video.c | 23 +++++++++++++++++++----
> > > 1 file changed, 19 insertions(+), 4 deletions(-)
> > >
> > > diff --git a/drivers/media/usb/uvc/uvc_video.c b/drivers/media/usb/uvc/uvc_video.c
> > > index 170a008f4006..a8323cf0e9f9 100644
> > > --- a/drivers/media/usb/uvc/uvc_video.c
> > > +++ b/drivers/media/usb/uvc/uvc_video.c
> > > @@ -129,12 +129,13 @@ int uvc_query_ctrl(struct uvc_device *dev, u8 query, u8 unit,
> > > return -EPIPE;
> > > }
> > >
> > > +static const struct usb_device_id elgato_cam_link_4k = {
> > > + USB_DEVICE(0x0fd9, 0x0066)
> > > +};
> > > +
> > > static void uvc_fixup_video_ctrl(struct uvc_streaming *stream,
> > > struct uvc_streaming_control *ctrl)
> > > {
> > > - static const struct usb_device_id elgato_cam_link_4k = {
> > > - USB_DEVICE(0x0fd9, 0x0066)
> > > - };
> > > struct uvc_format *format = NULL;
> > > struct uvc_frame *frame = NULL;
> > > unsigned int i;
> > > @@ -297,7 +298,7 @@ static int uvc_get_video_ctrl(struct uvc_streaming *stream,
> > > dev_err(&stream->intf->dev,
> > > "Failed to query (%u) UVC %s control : %d (exp. %u).\n",
> > > query, probe ? "probe" : "commit", ret, size);
> > > - ret = -EIO;
> > > + ret = (ret == -EPROTO) ? -EPROTO : -EIO;
> >
> > This will change the error returned by VIDIOC_S_FMT and VIDIOC_TRY_FMT,
> > but I don't think that will cause issues.
> >
> > > goto out;
> > > }
> > >
> > > @@ -2121,6 +2122,20 @@ int uvc_video_init(struct uvc_streaming *stream)
> > > * request on the probe control, as required by the UVC specification.
> > > */
> > > ret = uvc_get_video_ctrl(stream, probe, 1, UVC_GET_CUR);
> > > +
> > > + /*
> > > + * Elgato Cam Link 4k can be in a stalled state if the resolution of
> > > + * the external source has changed while the firmware initializes.
> > > + * Once in this state, the device is useless until it receives a
> > > + * USB reset. It has even been observed that the stalled state will
> > > + * continue even after unplugging the device.
> > > + */
> > > + if (usb_match_one_id(stream->dev->intf, &elgato_cam_link_4k) &&
> > > + (ret == -EPROTO)) {
> >
> > I'd swap the tests, as the second one is cheaper. You also don't need
> > the inner parentheses.
> >
> > > + usb_reset_device(stream->dev->udev);
> > > + dev_err(&stream->intf->dev, "Restarting Elgato Cam Link 4K\n");
> >
> > I would also swap those two lines, if an error occurs when resetting the
> > device, it's good to have the "restarting" message printed first.
> >
> > If I understand this correctly, probe will still fail, and the user will
> > have to unplug and replug the device to fix this, right ? If so I'd
> > expand the error message, maybe something along those lines:
>
> I kind of recall that it was not needed to replug the device. Will
> test on real hardware to confirm.

How does it get reprobed then ? By unloading and reloading the driver
(or unbinding and rebinding the device through sysfs) ?

> > dev_err(&stream->intf->dev, "Elgato Cam Link 4K firmware crash detected\n");
> > dev_err(&stream->intf->dev, "Resetting the device, unplug and replug to recover\n");
> >
> > Reviewed-by: Laurent Pinchart <[email protected]>
> >
> > > + }
> > > +
> > > if (ret < 0)
> > > return ret;
> > >
> > >
> > > ---
> > > base-commit: 521a547ced6477c54b4b0cc206000406c221b4d6
> > > change-id: 20220920-resend-elgato-a845482bdd02

--
Regards,

Laurent Pinchart

2022-12-05 23:06:26

by Laurent Pinchart

[permalink] [raw]
Subject: Re: [PATCH v3] media: uvcvideo: Recover stalled ElGato devices

Hi Ricardo,

Thank you for the patch.

On Mon, Dec 05, 2022 at 01:53:01PM +0100, Ricardo Ribalda wrote:
> Elgato Cam Link 4k can be in a stalled state if the resolution of
> the external source has changed while the firmware initializes.
> Once in this state, the device is useless until it receives a
> USB reset. It has even been observed that the stalled state will
> continue even after unplugging the device.

Why, ô, why :'-(

> lsusb -v
>
> Bus 002 Device 002: ID 0fd9:0066 Elgato Systems GmbH Cam Link 4K
> Device Descriptor:
> bLength 18
> bDescriptorType 1
> bcdUSB 3.00
> bDeviceClass 239 Miscellaneous Device
> bDeviceSubClass 2
> bDeviceProtocol 1 Interface Association
> bMaxPacketSize0 9
> idVendor 0x0fd9 Elgato Systems GmbH
> idProduct 0x0066
> bcdDevice 0.00
> iManufacturer 1 Elgato
> iProduct 2 Cam Link 4K
> iSerial 4 0005AC52FE000
> bNumConfigurations 1
>
> Reviewed-by: Sergey Senozhatsky <[email protected]>
> Signed-off-by: Ricardo Ribalda <[email protected]>
> ---
> Recover stalled ElGato devices
>
> Just a resend of this hw fix.
>
> To: Laurent Pinchart <[email protected]>
> To: Mauro Carvalho Chehab <[email protected]>
> Cc: [email protected]
> Cc: [email protected]
> Cc: Sergey Senozhatsky <[email protected]>
> Cc: Yunke Cao <[email protected]>
> ---
> Changes in v3:
> - Add Reviewed-by: Sergey
> - Improve identation (Thanks Sergey!)
> - Link to v2: https://lore.kernel.org/r/[email protected]
>
> Changes in v2:
> - Remove info from lsusb
> - Link to v1: https://lore.kernel.org/r/[email protected]
> ---
> drivers/media/usb/uvc/uvc_video.c | 23 +++++++++++++++++++----
> 1 file changed, 19 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/media/usb/uvc/uvc_video.c b/drivers/media/usb/uvc/uvc_video.c
> index 170a008f4006..a8323cf0e9f9 100644
> --- a/drivers/media/usb/uvc/uvc_video.c
> +++ b/drivers/media/usb/uvc/uvc_video.c
> @@ -129,12 +129,13 @@ int uvc_query_ctrl(struct uvc_device *dev, u8 query, u8 unit,
> return -EPIPE;
> }
>
> +static const struct usb_device_id elgato_cam_link_4k = {
> + USB_DEVICE(0x0fd9, 0x0066)
> +};
> +
> static void uvc_fixup_video_ctrl(struct uvc_streaming *stream,
> struct uvc_streaming_control *ctrl)
> {
> - static const struct usb_device_id elgato_cam_link_4k = {
> - USB_DEVICE(0x0fd9, 0x0066)
> - };
> struct uvc_format *format = NULL;
> struct uvc_frame *frame = NULL;
> unsigned int i;
> @@ -297,7 +298,7 @@ static int uvc_get_video_ctrl(struct uvc_streaming *stream,
> dev_err(&stream->intf->dev,
> "Failed to query (%u) UVC %s control : %d (exp. %u).\n",
> query, probe ? "probe" : "commit", ret, size);
> - ret = -EIO;
> + ret = (ret == -EPROTO) ? -EPROTO : -EIO;

This will change the error returned by VIDIOC_S_FMT and VIDIOC_TRY_FMT,
but I don't think that will cause issues.

> goto out;
> }
>
> @@ -2121,6 +2122,20 @@ int uvc_video_init(struct uvc_streaming *stream)
> * request on the probe control, as required by the UVC specification.
> */
> ret = uvc_get_video_ctrl(stream, probe, 1, UVC_GET_CUR);
> +
> + /*
> + * Elgato Cam Link 4k can be in a stalled state if the resolution of
> + * the external source has changed while the firmware initializes.
> + * Once in this state, the device is useless until it receives a
> + * USB reset. It has even been observed that the stalled state will
> + * continue even after unplugging the device.
> + */
> + if (usb_match_one_id(stream->dev->intf, &elgato_cam_link_4k) &&
> + (ret == -EPROTO)) {

I'd swap the tests, as the second one is cheaper. You also don't need
the inner parentheses.

> + usb_reset_device(stream->dev->udev);
> + dev_err(&stream->intf->dev, "Restarting Elgato Cam Link 4K\n");

I would also swap those two lines, if an error occurs when resetting the
device, it's good to have the "restarting" message printed first.

If I understand this correctly, probe will still fail, and the user will
have to unplug and replug the device to fix this, right ? If so I'd
expand the error message, maybe something along those lines:

dev_err(&stream->intf->dev, "Elgato Cam Link 4K firmware crash detected\n");
dev_err(&stream->intf->dev, "Resetting the device, unplug and replug to recover\n");

Reviewed-by: Laurent Pinchart <[email protected]>

> + }
> +
> if (ret < 0)
> return ret;
>
>
> ---
> base-commit: 521a547ced6477c54b4b0cc206000406c221b4d6
> change-id: 20220920-resend-elgato-a845482bdd02

--
Regards,

Laurent Pinchart

2022-12-05 23:06:48

by Ricardo Ribalda

[permalink] [raw]
Subject: Re: [PATCH v3] media: uvcvideo: Recover stalled ElGato devices

Hi Laurent

Thanks for your review

On Mon, 5 Dec 2022 at 23:39, Laurent Pinchart
<[email protected]> wrote:
>
> Hi Ricardo,
>
> Thank you for the patch.
>
> On Mon, Dec 05, 2022 at 01:53:01PM +0100, Ricardo Ribalda wrote:
> > Elgato Cam Link 4k can be in a stalled state if the resolution of
> > the external source has changed while the firmware initializes.
> > Once in this state, the device is useless until it receives a
> > USB reset. It has even been observed that the stalled state will
> > continue even after unplugging the device.
>
> Why, ô, why :'-(
>
> > lsusb -v
> >
> > Bus 002 Device 002: ID 0fd9:0066 Elgato Systems GmbH Cam Link 4K
> > Device Descriptor:
> > bLength 18
> > bDescriptorType 1
> > bcdUSB 3.00
> > bDeviceClass 239 Miscellaneous Device
> > bDeviceSubClass 2
> > bDeviceProtocol 1 Interface Association
> > bMaxPacketSize0 9
> > idVendor 0x0fd9 Elgato Systems GmbH
> > idProduct 0x0066
> > bcdDevice 0.00
> > iManufacturer 1 Elgato
> > iProduct 2 Cam Link 4K
> > iSerial 4 0005AC52FE000
> > bNumConfigurations 1
> >
> > Reviewed-by: Sergey Senozhatsky <[email protected]>
> > Signed-off-by: Ricardo Ribalda <[email protected]>
> > ---
> > Recover stalled ElGato devices
> >
> > Just a resend of this hw fix.
> >
> > To: Laurent Pinchart <[email protected]>
> > To: Mauro Carvalho Chehab <[email protected]>
> > Cc: [email protected]
> > Cc: [email protected]
> > Cc: Sergey Senozhatsky <[email protected]>
> > Cc: Yunke Cao <[email protected]>
> > ---
> > Changes in v3:
> > - Add Reviewed-by: Sergey
> > - Improve identation (Thanks Sergey!)
> > - Link to v2: https://lore.kernel.org/r/[email protected]
> >
> > Changes in v2:
> > - Remove info from lsusb
> > - Link to v1: https://lore.kernel.org/r/[email protected]
> > ---
> > drivers/media/usb/uvc/uvc_video.c | 23 +++++++++++++++++++----
> > 1 file changed, 19 insertions(+), 4 deletions(-)
> >
> > diff --git a/drivers/media/usb/uvc/uvc_video.c b/drivers/media/usb/uvc/uvc_video.c
> > index 170a008f4006..a8323cf0e9f9 100644
> > --- a/drivers/media/usb/uvc/uvc_video.c
> > +++ b/drivers/media/usb/uvc/uvc_video.c
> > @@ -129,12 +129,13 @@ int uvc_query_ctrl(struct uvc_device *dev, u8 query, u8 unit,
> > return -EPIPE;
> > }
> >
> > +static const struct usb_device_id elgato_cam_link_4k = {
> > + USB_DEVICE(0x0fd9, 0x0066)
> > +};
> > +
> > static void uvc_fixup_video_ctrl(struct uvc_streaming *stream,
> > struct uvc_streaming_control *ctrl)
> > {
> > - static const struct usb_device_id elgato_cam_link_4k = {
> > - USB_DEVICE(0x0fd9, 0x0066)
> > - };
> > struct uvc_format *format = NULL;
> > struct uvc_frame *frame = NULL;
> > unsigned int i;
> > @@ -297,7 +298,7 @@ static int uvc_get_video_ctrl(struct uvc_streaming *stream,
> > dev_err(&stream->intf->dev,
> > "Failed to query (%u) UVC %s control : %d (exp. %u).\n",
> > query, probe ? "probe" : "commit", ret, size);
> > - ret = -EIO;
> > + ret = (ret == -EPROTO) ? -EPROTO : -EIO;
>
> This will change the error returned by VIDIOC_S_FMT and VIDIOC_TRY_FMT,
> but I don't think that will cause issues.
>
> > goto out;
> > }
> >
> > @@ -2121,6 +2122,20 @@ int uvc_video_init(struct uvc_streaming *stream)
> > * request on the probe control, as required by the UVC specification.
> > */
> > ret = uvc_get_video_ctrl(stream, probe, 1, UVC_GET_CUR);
> > +
> > + /*
> > + * Elgato Cam Link 4k can be in a stalled state if the resolution of
> > + * the external source has changed while the firmware initializes.
> > + * Once in this state, the device is useless until it receives a
> > + * USB reset. It has even been observed that the stalled state will
> > + * continue even after unplugging the device.
> > + */
> > + if (usb_match_one_id(stream->dev->intf, &elgato_cam_link_4k) &&
> > + (ret == -EPROTO)) {
>
> I'd swap the tests, as the second one is cheaper. You also don't need
> the inner parentheses.
>
> > + usb_reset_device(stream->dev->udev);
> > + dev_err(&stream->intf->dev, "Restarting Elgato Cam Link 4K\n");
>
> I would also swap those two lines, if an error occurs when resetting the
> device, it's good to have the "restarting" message printed first.
>
> If I understand this correctly, probe will still fail, and the user will
> have to unplug and replug the device to fix this, right ? If so I'd
> expand the error message, maybe something along those lines:

I kind of recall that it was not needed to replug the device. Will
test on real hardware to confirm.


>
> dev_err(&stream->intf->dev, "Elgato Cam Link 4K firmware crash detected\n");
> dev_err(&stream->intf->dev, "Resetting the device, unplug and replug to recover\n");
>
> Reviewed-by: Laurent Pinchart <[email protected]>
>
> > + }
> > +
> > if (ret < 0)
> > return ret;
> >
> >
> > ---
> > base-commit: 521a547ced6477c54b4b0cc206000406c221b4d6
> > change-id: 20220920-resend-elgato-a845482bdd02
>
> --
> Regards,
>
> Laurent Pinchart



--
Ricardo Ribalda

2022-12-06 00:02:14

by Ricardo Ribalda

[permalink] [raw]
Subject: Re: [PATCH v3] media: uvcvideo: Recover stalled ElGato devices

On Mon, 5 Dec 2022 at 23:55, Laurent Pinchart
<[email protected]> wrote:
>
> Hi Ricardo,
>
> On Mon, Dec 05, 2022 at 11:45:43PM +0100, Ricardo Ribalda wrote:
> > On Mon, 5 Dec 2022 at 23:39, Laurent Pinchart wrote:
> > > On Mon, Dec 05, 2022 at 01:53:01PM +0100, Ricardo Ribalda wrote:
> > > > Elgato Cam Link 4k can be in a stalled state if the resolution of
> > > > the external source has changed while the firmware initializes.
> > > > Once in this state, the device is useless until it receives a
> > > > USB reset. It has even been observed that the stalled state will
> > > > continue even after unplugging the device.
> > >
> > > Why, ô, why :'-(
> > >
> > > > lsusb -v
> > > >
> > > > Bus 002 Device 002: ID 0fd9:0066 Elgato Systems GmbH Cam Link 4K
> > > > Device Descriptor:
> > > > bLength 18
> > > > bDescriptorType 1
> > > > bcdUSB 3.00
> > > > bDeviceClass 239 Miscellaneous Device
> > > > bDeviceSubClass 2
> > > > bDeviceProtocol 1 Interface Association
> > > > bMaxPacketSize0 9
> > > > idVendor 0x0fd9 Elgato Systems GmbH
> > > > idProduct 0x0066
> > > > bcdDevice 0.00
> > > > iManufacturer 1 Elgato
> > > > iProduct 2 Cam Link 4K
> > > > iSerial 4 0005AC52FE000
> > > > bNumConfigurations 1
> > > >
> > > > Reviewed-by: Sergey Senozhatsky <[email protected]>
> > > > Signed-off-by: Ricardo Ribalda <[email protected]>
> > > > ---
> > > > Recover stalled ElGato devices
> > > >
> > > > Just a resend of this hw fix.
> > > >
> > > > To: Laurent Pinchart <[email protected]>
> > > > To: Mauro Carvalho Chehab <[email protected]>
> > > > Cc: [email protected]
> > > > Cc: [email protected]
> > > > Cc: Sergey Senozhatsky <[email protected]>
> > > > Cc: Yunke Cao <[email protected]>
> > > > ---
> > > > Changes in v3:
> > > > - Add Reviewed-by: Sergey
> > > > - Improve identation (Thanks Sergey!)
> > > > - Link to v2: https://lore.kernel.org/r/[email protected]
> > > >
> > > > Changes in v2:
> > > > - Remove info from lsusb
> > > > - Link to v1: https://lore.kernel.org/r/[email protected]
> > > > ---
> > > > drivers/media/usb/uvc/uvc_video.c | 23 +++++++++++++++++++----
> > > > 1 file changed, 19 insertions(+), 4 deletions(-)
> > > >
> > > > diff --git a/drivers/media/usb/uvc/uvc_video.c b/drivers/media/usb/uvc/uvc_video.c
> > > > index 170a008f4006..a8323cf0e9f9 100644
> > > > --- a/drivers/media/usb/uvc/uvc_video.c
> > > > +++ b/drivers/media/usb/uvc/uvc_video.c
> > > > @@ -129,12 +129,13 @@ int uvc_query_ctrl(struct uvc_device *dev, u8 query, u8 unit,
> > > > return -EPIPE;
> > > > }
> > > >
> > > > +static const struct usb_device_id elgato_cam_link_4k = {
> > > > + USB_DEVICE(0x0fd9, 0x0066)
> > > > +};
> > > > +
> > > > static void uvc_fixup_video_ctrl(struct uvc_streaming *stream,
> > > > struct uvc_streaming_control *ctrl)
> > > > {
> > > > - static const struct usb_device_id elgato_cam_link_4k = {
> > > > - USB_DEVICE(0x0fd9, 0x0066)
> > > > - };
> > > > struct uvc_format *format = NULL;
> > > > struct uvc_frame *frame = NULL;
> > > > unsigned int i;
> > > > @@ -297,7 +298,7 @@ static int uvc_get_video_ctrl(struct uvc_streaming *stream,
> > > > dev_err(&stream->intf->dev,
> > > > "Failed to query (%u) UVC %s control : %d (exp. %u).\n",
> > > > query, probe ? "probe" : "commit", ret, size);
> > > > - ret = -EIO;
> > > > + ret = (ret == -EPROTO) ? -EPROTO : -EIO;
> > >
> > > This will change the error returned by VIDIOC_S_FMT and VIDIOC_TRY_FMT,
> > > but I don't think that will cause issues.
> > >
> > > > goto out;
> > > > }
> > > >
> > > > @@ -2121,6 +2122,20 @@ int uvc_video_init(struct uvc_streaming *stream)
> > > > * request on the probe control, as required by the UVC specification.
> > > > */
> > > > ret = uvc_get_video_ctrl(stream, probe, 1, UVC_GET_CUR);
> > > > +
> > > > + /*
> > > > + * Elgato Cam Link 4k can be in a stalled state if the resolution of
> > > > + * the external source has changed while the firmware initializes.
> > > > + * Once in this state, the device is useless until it receives a
> > > > + * USB reset. It has even been observed that the stalled state will
> > > > + * continue even after unplugging the device.
> > > > + */
> > > > + if (usb_match_one_id(stream->dev->intf, &elgato_cam_link_4k) &&
> > > > + (ret == -EPROTO)) {
> > >
> > > I'd swap the tests, as the second one is cheaper. You also don't need
> > > the inner parentheses.
> > >
> > > > + usb_reset_device(stream->dev->udev);
> > > > + dev_err(&stream->intf->dev, "Restarting Elgato Cam Link 4K\n");
> > >
> > > I would also swap those two lines, if an error occurs when resetting the
> > > device, it's good to have the "restarting" message printed first.
> > >
> > > If I understand this correctly, probe will still fail, and the user will
> > > have to unplug and replug the device to fix this, right ? If so I'd
> > > expand the error message, maybe something along those lines:
> >
> > I kind of recall that it was not needed to replug the device. Will
> > test on real hardware to confirm.
>
> How does it get reprobed then ? By unloading and reloading the driver
> (or unbinding and rebinding the device through sysfs) ?

Just went through the internal bug report. We were rebinding the
driver during the test.

Will add the "unplug-replug" message

Thanks!



>
> > > dev_err(&stream->intf->dev, "Elgato Cam Link 4K firmware crash detected\n");
> > > dev_err(&stream->intf->dev, "Resetting the device, unplug and replug to recover\n");
> > >
> > > Reviewed-by: Laurent Pinchart <[email protected]>
> > >
> > > > + }
> > > > +
> > > > if (ret < 0)
> > > > return ret;
> > > >
> > > >
> > > > ---
> > > > base-commit: 521a547ced6477c54b4b0cc206000406c221b4d6
> > > > change-id: 20220920-resend-elgato-a845482bdd02
>
> --
> Regards,
>
> Laurent Pinchart



--
Ricardo Ribalda