* Forcing re-enumeration of a chosen USB device from userspace?
@ 2024-08-08 6:39 Michał Pecio
2024-08-08 19:54 ` Alan Stern
0 siblings, 1 reply; 4+ messages in thread
From: Michał Pecio @ 2024-08-08 6:39 UTC (permalink / raw)
To: linux-usb
Hi,
I have a buggy USB device which works fine if connected before booting
Linux and also starts to work if I unbind and rebind the XHCI driver.
On the other hand, hot plugging the device with the driver already
running usually results in invalid descriptors being returned and
sometimes even if the descriptors are right, the device still doesn't
function entirely normally. I suspect a race between initialization of
its internal state and enumeration by the host, nothing I can fix.
Rebinding XHCI driver forces new enumeration of the device and reliably
fixes all issues every time, but it has the obvious downside of also
resetting everything else on this bus.
Can I have the same effect selectively, for one chosen device only?
Thanks,
Michal
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Forcing re-enumeration of a chosen USB device from userspace?
2024-08-08 6:39 Forcing re-enumeration of a chosen USB device from userspace? Michał Pecio
@ 2024-08-08 19:54 ` Alan Stern
2024-08-09 9:02 ` Michał Pecio
0 siblings, 1 reply; 4+ messages in thread
From: Alan Stern @ 2024-08-08 19:54 UTC (permalink / raw)
To: Michał Pecio; +Cc: linux-usb
On Thu, Aug 08, 2024 at 08:39:21AM +0200, Michał Pecio wrote:
> Hi,
>
> I have a buggy USB device which works fine if connected before booting
> Linux and also starts to work if I unbind and rebind the XHCI driver.
>
> On the other hand, hot plugging the device with the driver already
> running usually results in invalid descriptors being returned and
> sometimes even if the descriptors are right, the device still doesn't
> function entirely normally. I suspect a race between initialization of
> its internal state and enumeration by the host, nothing I can fix.
>
> Rebinding XHCI driver forces new enumeration of the device and reliably
> fixes all issues every time, but it has the obvious downside of also
> resetting everything else on this bus.
>
> Can I have the same effect selectively, for one chosen device only?
You can reset the device by using the usbreset program, which is part of
the usbutils package. Some distributions (such as Ubuntu) include it
whereas others (such as Fedora) don't. But if you don't have it, you
can get the source code from https://github.com/gregkh/usbutils/ and
build it yourself.
If the reset causes some descriptors to change, the kernel will
re-enumerate the device.
Alan Stern
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Forcing re-enumeration of a chosen USB device from userspace?
2024-08-08 19:54 ` Alan Stern
@ 2024-08-09 9:02 ` Michał Pecio
2024-08-09 13:53 ` Alan Stern
0 siblings, 1 reply; 4+ messages in thread
From: Michał Pecio @ 2024-08-09 9:02 UTC (permalink / raw)
To: Alan Stern; +Cc: linux-usb
> You can reset the device by using the usbreset program, which is part
> of the usbutils package. Some distributions (such as Ubuntu) include
> it whereas others (such as Fedora) don't. But if you don't have it,
> you can get the source code from https://github.com/gregkh/usbutils/
> and build it yourself.
>
> If the reset causes some descriptors to change, the kernel will
> re-enumerate the device.
Thanks for the suggestion. I compiled the tool fom Greg's repository
and ran it 100 times in a loop, but the descriptors remained unchanged.
I only got "reset USB device" messages in dmesg and class driver noise.
I had no luck playing with sysfs entries of the device, but I found
that the parent hub allows me to disable/enable individual ports. There
is some subtlely in USB 3.0 as the associated 2.0 port must be disabled
first to prevent downgrading to high speed, but it works.
Curiously though, it doesn't have the same effect as reloading the host
driver. My buggy device randomly comes back with good descriptors, with
the same bad descriptors, or most often it doesn't come back at all.
Regards,
Michal
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Forcing re-enumeration of a chosen USB device from userspace?
2024-08-09 9:02 ` Michał Pecio
@ 2024-08-09 13:53 ` Alan Stern
0 siblings, 0 replies; 4+ messages in thread
From: Alan Stern @ 2024-08-09 13:53 UTC (permalink / raw)
To: Michał Pecio; +Cc: linux-usb
On Fri, Aug 09, 2024 at 11:02:06AM +0200, Michał Pecio wrote:
> > You can reset the device by using the usbreset program, which is part
> > of the usbutils package. Some distributions (such as Ubuntu) include
> > it whereas others (such as Fedora) don't. But if you don't have it,
> > you can get the source code from https://github.com/gregkh/usbutils/
> > and build it yourself.
> >
> > If the reset causes some descriptors to change, the kernel will
> > re-enumerate the device.
>
> Thanks for the suggestion. I compiled the tool fom Greg's repository
> and ran it 100 times in a loop, but the descriptors remained unchanged.
>
> I only got "reset USB device" messages in dmesg and class driver noise.
>
>
> I had no luck playing with sysfs entries of the device, but I found
> that the parent hub allows me to disable/enable individual ports. There
> is some subtlely in USB 3.0 as the associated 2.0 port must be disabled
> first to prevent downgrading to high speed, but it works.
>
> Curiously though, it doesn't have the same effect as reloading the host
> driver. My buggy device randomly comes back with good descriptors, with
> the same bad descriptors, or most often it doesn't come back at all.
I would guess that the difference has to do with whether or not power to
the USB port is turned off. But that doesn't explain why the device
fails to enumerate properly the first time it gets plugged in.
Alan Stern
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2024-08-09 13:53 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-08-08 6:39 Forcing re-enumeration of a chosen USB device from userspace? Michał Pecio
2024-08-08 19:54 ` Alan Stern
2024-08-09 9:02 ` Michał Pecio
2024-08-09 13:53 ` Alan Stern
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox