0

I'm having some issues with a usb device I have and I know I can solve the issue currently by unplugging and plugging back in the device.

I've tried resetting the usb port using a script from How do you reset a USB device from the command line? but that doesn't seem to go far enough.

I know previously I used udisksctl power-off to power off my usb flashdrives when I wanted to remove them, but when I use it for a generic device it fails.

Is there a way I can do a similar function for a generic usb device like a webcam?

iggy12345
  • 76
  • 3
  • 14

1 Answers1

1

spin-down

First you need to find the sysfs path to your device ( e.g. using lsusb)

If the full path to the USB device's sysfs node is:

/sys/devices/pci0000:00/0000:00:14.0/usb1/1-13/1-13.2/1-13.2.1/

udisksctl power-off -b /dev/sdz does something very much like:

hdparm -Y /dev/sdz
echo 1 >  /sys/block/sdz/device/delete
echo 1 >  /sys/devices/pci0000:00/0000:00:14.0/usb1/1-13/1-13.2/1-13.2.1/remove

( to improve the behaviour in scripts you might use /dev/disk/by-id/thingy-name01234 instead of /dev/sdz)

which then removes the:

/sys/devices/pci0000:00/0000:00:14.0/usb1/1-13/1-13.2/1-13.2.1/

directory altogether.

The parent device:

/sys/devices/pci0000:00/0000:00:14.0/usb1/1-13/1-13.2/

represents the USB port itself, and this is now in that "disabled" state.

To to reset this:

you can tell it to change which USB configuration it should use, and in order to use that configuration it needs to reset everything.

Telling it to use the same configuration it's currently in should reset it as well:

# cat /sys/devices/pci0000:00/0000:00:14.0/usb1/1-13/1-13.2/bConfigurationValue
1
# echo 1 >/sys/devices/pci0000:00/0000:00:14.0/usb1/1-13/1-13.2/bConfigurationValue

With that, the port is re-enabled just as if I'd plugged in the device again (i.e. the .../1-13.2.1 subdirectory reappears, the device on the port is probed, the kernel discovers a USB storage device there, and so on).


Rescan

And then to (re)scan, e.g. to see a newly connected device if it's not automatically found, or to again see something that was "deleted" as above, e.g.:

# (for tmp in /sys/class/scsi_host/host*/scan; do echo '- - -' >> "$tmp"; done) 

Resetting

to just reset a device:

for X in /sys/bus/usb/devices/*; do 
    echo "$X"
    cat "$X/idVendor" 2>/dev/null 
    cat "$X/idProduct" 2>/dev/null
    echo
done

to list them , then use

sudo sh -c "echo 0 > /sys/bus/usb/devices/1-4.6/authorized"
sudo sh -c "echo 1 > /sys/bus/usb/devices/1-4.6/authorized"

to reset it

Enabling smart on usb devices

if you cannot get smart values ,

  • note the vendor/prodid:
$ lsusb | grep -i seagate
Bus 003 Device 004: ID 0bd1:2027 Seagate RSS LLC Expansion HDD
  • do the following before resetting the bus configuration ( after disabling the port ):

    $ echo "0x0bd1:0x2027:u" | sudo tee /sys/module/usb_storage/parameters/quirks


https://www.reddit.com/r/linuxquestions/comments/r34j7j/running_udisksctl_poweroff_b_devsdx_disables_usb/

  • Unfortunately I'm not having the same issue I was 4 months ago, but I was able to confirm that I can power cycle my usb mouse with these instructions (I can verify that the rgb shuts off and turns back on) and that's what I was looking for, thank you! – iggy12345 Jun 10 '23 at 19:03