Recently I got my USB mouse behaves very strange. Talk shortly, my mouse seems already broken partially and annoyingly it freezes the USB 2.0 port where it is plugged on. No action can be done such as reading a flash drive nor using any other USB mouse. Fortunately, there is a good hack from DavidJB and with it I successfully reset my USB 2.0 and 3.0 port without rebooting. Big thanks for DavidJB. Here I give you all commands plus one bash script example to make it easier.


Note

ehci and xhci, are USB standard interfaces for 2.0 and 3.0 respectively. ehci-pci or ehci_hcd is a Linux kernel driver for USB 2.0 handling, while xhci_hcd is the same for USB 3.0. ehci stands for Enhanced Host Controller Interface, xhci stands for eXtensible Host Controller Interface, while hcd stands for Host Controller Driver. They are low level things inside our Linux kernel.


1. For Ubuntu 14.04 until 16.04

 


There are two groups of commands, one group is for USB 2.0 port and another one is for USB 3.0. Run one group of commands either one by one or just run them at once by a bash script.

I have tested them in 14.04, 15.04, 15.10, and 16.04. I am sorry I have not tested these in 13.10, 13.04, and 12.10. Please help testing if you can.

USB 2.0
echo -n "0000:00:1a.0" | tee /sys/bus/pci/drivers/ehci-pci/unbind
echo -n "0000:00:1d.0" | tee /sys/bus/pci/drivers/ehci-pci/unbind
echo -n "0000:00:1a.0" | tee /sys/bus/pci/drivers/ehci-pci/bind
echo -n "0000:00:1d.0" | tee /sys/bus/pci/drivers/ehci-pci/bind

USB 3.0
 
echo -n "0000:03:00.0" | tee /sys/bus/pci/drivers/xhci_hcd/unbind
echo -n "0000:03:00.0" | tee /sys/bus/pci/drivers/xhci_hcd/bind

2. For Ubuntu 12.04 and Older Versions

 

There are also two groups of commands. But the only difference from the newer version’s commands is located at ehci_hcd directory. In Ubuntu 12.04, there is no ehci-pci like we find in newer Ubuntu versions. But there is ehci_hcd. Older Ubuntu versions have ehci_hcd and xhci_hcd, while newer Ubuntu versions have ehci-pci and xhci_hcd. Notice the underscore. So the difference between newer and older Ubuntu commands here is only in the USB 2.0.

USB 2.0

echo -n "0000:00:1a.0" | tee /sys/bus/pci/drivers/ehci_hcd/unbind
echo -n "0000:00:1d.0" | tee /sys/bus/pci/drivers/ehci_hcd/unbind
echo -n "0000:00:1a.0" | tee /sys/bus/pci/drivers/ehci_hcd/bind
echo -n "0000:00:1d.0" | tee /sys/bus/pci/drivers/ehci_hcd/bind

USB 3.0
 
echo -n "0000:03:00.0" | tee /sys/bus/pci/drivers/xhci_hcd/unbind
echo -n "0000:03:00.0" | tee /sys/bus/pci/drivers/xhci_hcd/bind 

As I said, you may insert a group of commands in a bash script. For those are not familiar with it, here a simple script example for you:

#!/bin/bash

# this script reset the usb 2.0 port controlled by linux kernel in Ubuntu 14.04 and later

echo -n "0000:00:1a.0" | tee /sys/bus/pci/drivers/ehci-pci/unbind
echo -n "0000:00:1d.0" | tee /sys/bus/pci/drivers/ehci-pci/unbind
echo -n "0000:00:1a.0" | tee /sys/bus/pci/drivers/ehci-pci/bind
echo -n "0000:00:1d.0" | tee /sys/bus/pci/drivers/ehci-pci/bind

Name this script anything such as `resetusb`, give it executable permission, and place this script in /usr/bin/ directory. To run it, in Terminal, switch user to root and type resetusb command.


How It Works

 


There are something you need to understand:

  • The something like `zero zero zero` (0000:00:1a.0) code number is taken from the same `zero zero zero` file name from the same directory of unbind and bind. You may check it in /sys/bus/pci/drivers/ directory.
  • The expected output is all of echo-ed `zero zero zero` code text entered to be displayed in one single line in your Terminal.
  • The not expected (the error one) output is your shell saying no such file or directory. If that happens, you should recheck your code perhaps there is an incorrect spelling there.
  • The lines of code for every USB port must be run one by one sequentially. I found that if I run it randomly, I got no such file or directory error.

Reference


, , , , ,