7

When I plug in my no-name USB 2.0 hub with a mouse and a keyboard connected to it, that USB port on my computer stops working: Devices connected to it, whether through a hub or directly, are not detected anymore.

A restart of the system makes the port work again, but I'd rather have less harsh method, which only "resets" the USB controllers.

1 Answer 1

10

I wrote a script that works for me (on Debian 11):

#!/usr/bin/env bash
# Resets all USB host controllers of the system.
# This is useful in case one stopped working
# due to a faulty device having been connected to it.

base="/sys/bus/pci/drivers"
sleep_secs="1"

# This might find a sub-set of these:
# * 'ohci_hcd' - USB 3.0
# * 'ehci-pci' - USB 2.0
# * 'xhci_hcd' - USB 3.0
echo "Looking for USB standards ..."
for usb_std in "$base/"?hci[-_]?c*
do
    echo "* USB standard '$usb_std' ..."
    for dev_path in "$usb_std/"*:*
    do
        dev="$(basename "$dev_path")"
        echo "  - Resetting device '$dev' ..."
        printf '%s' "$dev" | sudo tee "$usb_std/unbind" > /dev/null
        sleep "$sleep_secs"
        printf '%s' "$dev" | sudo tee "$usb_std/bind" > /dev/null
        echo "    done."
    done
    echo "  done."
done
echo "done."

NOTE:

  • It requires root access to reset the controllers.

Idea taken from: https://www.linux.org/threads/resetting-the-usb-subsystem.10404/

3
  • 3
    See also the usbreset utility in usbutils that does a ioctl(fd, USBDEVFS_RESET, 0) on /dev/bus/usb/$bus/$dev. Don't know how effective it would be in your use case. Jun 1, 2022 at 13:29
  • 1
    @StéphaneChazelas AFAICT, usbreset (from usbutils) only works with devices, not controllers (root hubs). When I run usbutils with no options, I get a list of (attached) devices but no controllers or root hubs. If I run [sudo] usbreset against a controller/root hub (dev set to 001), usbreset prints No such device found and exits.
    – jaimet
    Jul 28 at 20:12
  • This worked for me (Debian trixie) my USB-A 3.x (>0) to USB-C, plugged into an SSD was recognised as Speed: 480Mb/s (high) initially, then not recognised, then after this reset as Bus: Speed: 5Gb/s (super)
    – GraemeV
    Aug 25 at 12:59

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .