Linux – disable a usb port in linux

linuxusb

I've searched a lot for an answer to this, but the closest I can get to finding a solution is this, but it doesn't work for me.

Here's my system:

# uname -a
Linux vin 4.4.0-1-amd64 #1 SMP Debian 4.4.6-1 (2016-03-17) x86_64 GNU/Linux

The problem is this: one of my USB ports appears to be dead. Any program that tries to read "/sys/bus/usb/devices/usb1/descriptors" will cause the program to hang in an unkillable state.

Unfortunately, a lot of software seems to want to access USB1, including chrome and blender, which is why this is bugging me so much. When I invoke those programs with strace, they always hang at the moment they try to open "/sys/bus/usb/devices/usb1/descriptors".

I've tried things like "echo suspend > /sys/bus/usb/devices/usb1/power/level" but it's no good – the command simply hangs like the others.

I tried using the hubpower code mentioned in the post linked above, but it likewise seems to just hang like the others.

I tried powering down the whole system and opening up the computer itself to disconnect the USB port directly, but the whole collection of USB ports (there are a lot of them) seem very tightly integrated with the motherboard, and I couldn't see a way to unplug anything. Granted, I don't have tons of experience plugging wires into and out of motherboards. If the only hope is to do it that way, I could hopefully manage it.

I tried going into the BIOS and disabling all the USB ports except one; and then disabling all except the next; and the next; and so on, to see which one was the problem. But it didn't seem to have any effect – Linux still was able to recognize the ports well enough to use my USB mouse and keyboard. Linux didn't seem to care what the BIOS configuration was.

The thing that occurs to me is that there may be some way to tell the Linux kernel to ignore USB1, but to do so without actually attempting to interact with USB1 (since that seems to cause the unkillable hang). But I don't know how to do that.

Best Answer

Partial answer: I'm not sure if you can disable only one USB port, but you can disable the controller and all its ports.

You can list the controllers with lspci: lspci -k| grep -i usb -A2 For example, I get:

03:00.0 USB controller: ASMedia Technology Inc. ASM1142 USB 3.1 Host Controller
        Subsystem: Micro-Star International Co., Ltd. [MSI] ASM1142 USB 3.1 Host Controller
        Kernel driver in use: xhci_hcd
        Kernel modules: xhci_pci

Meaning the USB controller on PCI port 03:00.0 is handled by xhcp_pci kernel module.

Now, I can ask the driver not to manage this controller with the following command:

echo "0000:03:00.0" | sudo tee /sys/bus/pci/drivers/xhci_hcd/unbind

If you don't mind losing the other USB ports of this controller, this could be a solution.

Related Question