Randomly loosing USB, a manual reset works

Hi guys,

Since a month or so, my computer randomly (usually once per day) looses all USB devices for no apparent reason. If I run a script that resets USB controllers, they come back (I have to ssh from another computer since my keyboard is also an USB one).

Here is the script I use (nothing special, taken from Internet):

#!/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."

and here is relevant journalctl log

14:49:46.104230 my-host kernel: xhci_hcd 0000:0a:00.0: Event TRB for slot 12 ep 0 with no TDs queued
14:49:46.104864 my-host kernel: usb 2-3: Device not responding to setup address.
14:49:46.840428 my-host kernel: xhci_hcd 0000:0a:00.0: ERROR unknown event type 4
14:52:40.088816 my-host kernel: xhci_hcd 0000:0a:00.0: Abort failed to stop command ring: -110
14:52:40.092076 my-host kernel: xhci_hcd 0000:0a:00.0: xHCI host controller not responding, assume dead
14:52:40.092279 my-host kernel: xhci_hcd 0000:0a:00.0: Timeout while waiting for setup device command
14:52:40.092407 my-host kernel: xhci_hcd 0000:0a:00.0: Timeout while waiting for configure endpoint command
14:52:40.092501 my-host kernel: usb 1-10: Not enough bandwidth for altsetting 0
14:52:40.092670 my-host kernel: usb 1-10: 3:0: usb_set_interface failed (-62)
14:52:40.092781 my-host kernel: xhci_hcd 0000:0a:00.0: HC died; cleaning up
14:52:40.092872 my-host kernel: usb 1-3: USB disconnect, device number 3
14:52:40.093004 my-host kernel: usb 1-3.2: USB disconnect, device number 6
14:52:40.200253 my-host kernel: usb 1-3.3: USB disconnect, device number 8
14:52:40.291224 my-host kernel: usb 2-3: device not accepting address 2, error -62
14:52:40.291313 my-host kernel: usb 2-3: USB disconnect, device number 2
14:52:40.291349 my-host kernel: usb 2-5: USB disconnect, device number 3
14:52:40.296221 my-host kernel: usb 1-5: USB disconnect, device number 4
14:52:40.297219 my-host kernel: usb 1-6: USB disconnect, device number 5
14:52:40.509220 my-host kernel: usb 1-7: USB disconnect, device number 7
14:52:40.509326 my-host kernel: usb 1-10: USB disconnect, device number 9
14:52:40.510220 my-host kernel: usb 1-11: USB disconnect, device number 10
14:52:40.510442 my-host kernel: usb 1-11.1: USB disconnect, device number 12
14:52:40.637299 my-host kernel: usb 1-12: USB disconnect, device number 11

where (I assume) usb 2-3 is: Bus 002 Device 003: ID 174c:3074 ASMedia Technology Inc. ASM1074 SuperSpeed hub

My motherboard is ASRock x870 Riptide Wifi, I guess that is one of the USB controllers. Now I’m confused whether this is a hardware (mobo) or a linux issue - IMO it could be one or the another.

Also I wonder why linux gives up on USB when running the script above works.

Any ideas?

1 Like

Linux kernel’s aggressive USB power-saving features has some quirks with the ASMedia ASM1074.

Since this is a desktop motherboard, you don’t need aggressive USB power savings. So run this command to never let your kernel put your usb host controllers to sleep.

sudo grubby --update-kernel=ALL --args="usbcore.autosuspend=-1"

Reboot the system it should work.

4 Likes

Done and thanks. Let’s see now.

1 Like

It’s been a week since I’ve applied the solution and it still works without problems. Therefore I declare it as a solution.

1 Like