Перезапуск usb портов linux

restart/power on usb port or modem?

I am using Ubuntu 12.04 . I will explain my situation first . I am using A USB modem which frequently disconnect for an hour or so. Then i will plug off it from ports and will insert again .Then it will search again and connect . My idea is , is there anything i can do else without plugoff the modem from USB ports , i mean restarting powersupply to modem or USB port . One more point: I can’t restart total USB’s power-supply because my speakers are USB and sometimes i used to work by attaching the USB devices . Help me guys , if i got this then you are going to save me from an daily exercise . Thank you .

3 Answers 3

usb-modeswitch

We can try if a reset of our USB device helps resurrecting it. We first need to find out the vendor ID, and the product ID easiest by

This will give information e.g. like follows:

Bus 003 Device 002: ID 04f9:0224 Brother Industries, Ltd 

In this example the vendor ID is 04f9 , product ID is 0224 (right, its my printer).

To reset the device we may then issue

sudo usb_modeswitch -R -v -p

For more options read the manpage or the project homepage.

Just a note — in case the modem hangs it may not even react on a reset command — but worth a try anyway.

hey , if device rstarted means again it have to ask me password of gsm sim but its not asking . i think its not doing . here is the link pastebin.com/qgDftJ8h

Sorry to read that. It did reset: OK, device was reset . If that did not help I have no really good further idea. I hope someone knows if it is possible to power-off an USB-port by software. I doubt it will work (e.g. my USB-ports here are always powered ON even when I powered my machine off).

You are probably using usbserial driver to activate the usb modem, it’s a driver used for testing

USB driver for GSM and CDMA modems (USB_SERIAL_OPTION)

CONFIG_USB_SERIAL_OPTION:

Say Y here if you have a GSM or CDMA modem that’s connected to USB.

This driver also supports several PCMCIA cards which have a built-in OHCI-USB adapter and an internally-connected GSM modem. The USB bus on these cards is not accessible externally.

Supported devices include (some of?) those made by: Option, Huawei, Audiovox, Novatel Wireless, or Anydata.

To compile this driver as a module, choose M here: the module will be called option.

If this driver doesn’t recognize your device, it might be accessible via the FTDI_SIO driver.

modprobe option echo VENDORID PRODUCTID > /sys/bus/usb-serial/drivers/option1/new_id 

Источник

planetceres / RESET_USB_KERNEL_MODULE.md

Restart USB ports after a power overdraw (error -110). Unplug all devices prior to running script.

for port in $(lspci | grep USB | cut -d' ' -f1); do echo -n "0000:$"| sudo tee /sys/bus/pci/drivers/xhci_hcd/unbind; sleep 5; echo -n "0000:$" | sudo tee /sys/bus/pci/drivers/xhci_hcd/bind; sleep 5; done 
for port in $(lspci | grep xHCI | cut -d' ' -f1); do echo -n "0000:$"| sudo tee /sys/bus/pci/drivers/xhci_hcd/unbind; sleep 5; echo -n "0000:$" | sudo tee /sys/bus/pci/drivers/xhci_hcd/bind; sleep 5; done 

Either my Dell Optiplex 990 computer or my Linux install has an issue: occasionally, when I re-plug a USB device into the system, it’ll cause a fault in the USB module in the kernel and USB goes dark. I’m unsure as to whether this is a hardware or software issue, but I’d simply like to restart my USB subsystem and continue working. When searching the web for ‘restart USB in Linux’ and ‘reload USB kernel module’, you get a plethora of results and none of which will work (seemingly due to how the Ubuntu standard kernel is compiled), at least for me within Ubuntu 12.04, Precise Pangolin. Until now, I’ve had no success and had to hard reset. No longer.

You’ll need root/sudo access to the machine to be able to run commands. In my case, without USB available, then I’ve either got to sprint for a PS/2 keyboard and mouse or login via SSH. You can do what I’ve done and prepared things into a suitable script I can run with just a Gnome launcher. Thanks to this fantastic post for the help. Either place the following into a script or run the commands directly:

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 

The hardware identifiers being passed around here can be revealed using a command like lspci | grep USB. In my case, the identifiers in the original post were exactly what I have in my system.

I’m yet to see if my USB will correctly come back online after freezing up as it hasn’t happened yet, but I’ll try this when it does and report back. That said, the commands above definitely reload all USB devices attached to the system; that much I’ve tried.

Источник

Читайте также:  Linux ubuntu локальная сеть windows

Disconnect and reconnect USB port via cli

Does this effectively reset the power on the device and would therefore completely reset it without having to unplug and replug it in?

If a program has opened a serial USB device(say, /dev/ttyUSB0 symlinked from /dev/myserialdevice as specified in /etc/udev/rules.d/mystuff.rules), and the device gets hung for some reason, is it then necessary to reset it with an ioctl() as above, or is it sufficient to simply close() and open() it again?

@Jarryd see Alan’s explanation in the link above: Note however, that reset followed by re-enumeration is _not_ the same thing as power-cycle followed by reconnect and re-enumeration.

Save the script below as reset_usb.py or clone this repo: https://github.com/mcarans/resetusb/.

python reset_usb.py help : Show this help

sudo python reset_usb.py list : List all USB devices

sudo python reset_usb.py path /dev/bus/usb/XXX/YYY : Reset USB device using path /dev/bus/usb/XXX/YYY

sudo python reset_usb.py search «search terms» : Search for USB device using the search terms within the search string returned by list and reset matching device

sudo python reset_usb.py listpci : List all PCI USB devices

sudo python reset_usb.py pathpci /sys/bus/pci/drivers/. /XXXX:XX:XX.X : Reset PCI USB device using path /sys/bus/pci/drivers/. /XXXX:XX:XX.X

sudo python reset_usb.py searchpci «search terms» : Search for PCI USB device using the search terms within the search string returned by listpci and reset matching device

#!/usr/bin/env python import os import sys from subprocess import Popen, PIPE import fcntl instructions = ''' Usage: python reset_usb.py help : Show this help sudo python reset_usb.py list : List all USB devices sudo python reset_usb.py path /dev/bus/usb/XXX/YYY : Reset USB device using path /dev/bus/usb/XXX/YYY sudo python reset_usb.py search "search terms" : Search for USB device using the search terms within the search string returned by list and reset matching device sudo python reset_usb.py listpci : List all PCI USB devices sudo python reset_usb.py pathpci /sys/bus/pci/drivers/. /XXXX:XX:XX.X : Reset PCI USB device using path sudo python reset_usb.py searchpci "search terms" : Search for PCI USB device using the search terms within the search string returned by listpci and reset matching device ''' if len(sys.argv) < 2: print(instructions) sys.exit(0) option = sys.argv[1].lower() if 'help' in option: print(instructions) sys.exit(0) def create_pci_list(): pci_usb_list = list() try: lspci_out = Popen('lspci -Dvmm', shell=True, bufsize=64, stdin=PIPE, stdout=PIPE, close_fds=True).stdout.read().strip().decode('utf-8') pci_devices = lspci_out.split('%s%s' % (os.linesep, os.linesep)) for pci_device in pci_devices: device_dict = dict() categories = pci_device.split(os.linesep) for category in categories: key, value = category.split('\t') device_dictПерезапуск usb портов linux] = value.strip() if 'USB' not in device_dict['Class']: continue for root, dirs, files in os.walk('/sys/bus/pci/drivers/'): slot = device_dict['Slot'] if slot in dirs: device_dict['path'] = os.path.join(root, slot) break pci_usb_list.append(device_dict) except Exception as ex: print('Failed to list pci devices! Error: %s' % ex) sys.exit(-1) return pci_usb_list def create_usb_list(): device_list = list() try: lsusb_out = Popen('lsusb -v', shell=True, bufsize=64, stdin=PIPE, stdout=PIPE, close_fds=True).stdout.read().strip().decode('utf-8') usb_devices = lsusb_out.split('%s%s' % (os.linesep, os.linesep)) for device_categories in usb_devices: if not device_categories: continue categories = device_categories.split(os.linesep) device_stuff = categories[0].strip().split() bus = device_stuff[1] device = device_stuff[3][:-1] device_dict = device_info = ' '.join(device_stuff[6:]) device_dict['description'] = device_info for category in categories: if not category: continue categoryinfo = category.strip().split() if categoryinfo[0] == 'iManufacturer': manufacturer_info = ' '.join(categoryinfo[2:]) device_dict['manufacturer'] = manufacturer_info if categoryinfo[0] == 'iProduct': device_info = ' '.join(categoryinfo[2:]) device_dict['device'] = device_info path = '/dev/bus/usb/%s/%s' % (bus, device) device_dict['path'] = path device_list.append(device_dict) except Exception as ex: print('Failed to list usb devices! Error: %s' % ex) sys.exit(-1) return device_list if 'listpci' in option: pci_usb_list = create_pci_list() for device in pci_usb_list: print('path=%s' % device['path']) print(' manufacturer=%s' % device['SVendor']) print(' device=%s' % device['SDevice']) print(' search string=%s %s' % (device['SVendor'], device['SDevice'])) sys.exit(0) if 'list' in option: usb_list = create_usb_list() for device in usb_list: print('path=%s' % device['path']) print(' description=%s' % device['description']) print(' manufacturer=%s' % device['manufacturer']) print(' device=%s' % device['device']) print(' search string=%s %s %s' % (device['description'], device['manufacturer'], device['device'])) sys.exit(0) if len(sys.argv) < 3: print(instructions) sys.exit(0) option2 = sys.argv[2] print('Resetting device: %s' % option2) # echo -n "0000:39:00.0" | tee /sys/bus/pci/drivers/xhci_hcd/unbind;echo -n "0000:39:00.0" | tee /sys/bus/pci/drivers/xhci_hcd/bind def reset_pci_usb_device(dev_path): folder, slot = os.path.split(dev_path) try: fp = open(os.path.join(folder, 'unbind'), 'wt') fp.write(slot) fp.close() fp = open(os.path.join(folder, 'bind'), 'wt') fp.write(slot) fp.close() print('Successfully reset %s' % dev_path) sys.exit(0) except Exception as ex: print('Failed to reset device! Error: %s' % ex) sys.exit(-1) if 'pathpci' in option: reset_pci_usb_device(option2) if 'searchpci' in option: pci_usb_list = create_pci_list() for device in pci_usb_list: text = '%s %s' % (device['SVendor'], device['SDevice']) if option2 in text: reset_pci_usb_device(device['path']) print('Failed to find device!') sys.exit(-1) def reset_usb_device(dev_path): USBDEVFS_RESET = 21780 try: f = open(dev_path, 'w', os.O_WRONLY) fcntl.ioctl(f, USBDEVFS_RESET, 0) print('Successfully reset %s' % dev_path) sys.exit(0) except Exception as ex: print('Failed to reset device! Error: %s' % ex) sys.exit(-1) if 'path' in option: reset_usb_device(option2) if 'search' in option: usb_list = create_usb_list() for device in usb_list: text = '%s %s %s' % (device['description'], device['manufacturer'], device['device']) if option2 in text: reset_usb_device(device['path']) print('Failed to find device!') sys.exit(-1) 

Источник

Читайте также:  Linux support amd radeon

How do I reset an USB device without unplugging it in Linux?

Every now and then there might come a need to reset a USB device, is there a way to perform the reset in software without unplugging the device itself and then pluggin it back in? More specifically I have a webcam which gets confused when playing too much with the settings in guvcapture and then needs a reset to get back on track.

5 Answers 5

usbutils includes usbreset.

Run it without any arguments to see usage and a list of devices. It requires superuser access to actually reset devices.

Usage: usbreset PPPP:VVVV - reset by product and vendor id usbreset BBB/DDD - reset by bus and device number usbreset "Product" - reset by product name 

This allows resetting individual devices which is an improvement over some answers that reset the entire bus. It might not resolve intermediary hub/bus issues, but it's a lot less disruptive to only reset the desired device.

You could try Benjamin Close's resetusb program to reset all devices — there are no binaries available, but compiling it is rather easy. Save the source code as resetusb.c , then run:

gcc -lusb resetusb.c -o resetusb 

You can now run the tool as resetusb . Alternatively, @unhammer points to Alan Stern's single-device version (plus some hints on how to use it).

modprobe -vr ehci_hcd modprobe -v ehci_hcd 

(you could of course script this)

Some distributions may also have their own tools to restart the USB subsystem; Mandrake apparently has /etc/init.d/usb .

$ sudo modprobe -vr ehci_hcd results in modprobe: FATAL: Module ehci_hcd is builtin. on kubuntu trusty.

On my laptop with debian 8, ehci_hcd gives errors. However, rmmod ehci_pci && sleep 2 && modprobe ehci_pci works perfectly.

Let's say I want to reset /dev/sdc .

# udevadm info -q all /dev/sdc | grep DEVPATH E: DEVPATH=/devices/pci0000:00/0000:00:14.0/usb2/2-1/2-1.4/2-1.4:1.0/host2/target2:0:0/2:0:0:0/block/sdc 

I take the 2-1.4 above (yours might just be 2-1 - my device is plugged into a hub) and do:

# echo 2-1.4 > /sys/bus/usb/drivers/usb/unbind # echo 2-1.4 > /sys/bus/usb/drivers/usb/bind 

I've made a one-liner(-ish) for that: DEV="sdc"; USB=$(udevadm info -q all /dev/$DEV | grep DEVPATH | grep -o '/usb3*/[1-9,-]*' | cut -d'/' -f3); echo $USB > /sys/bus/usb/drivers/usb/unbind; echo $USB > /sys/bus/usb/drivers/usb/bind Make DEV the drive you want to reset, and run - it'll extract the USB port number and unbind/bind it (untested).

You can restart the hardware abstraction layer: sudo /etc/init.d/hal restart

i think HAL is replaced by something else in the newest version of ubuntu.. so its depend of distrib..

Читайте также:  Logging out in linux

I seriously doubt it would have worked anyway. HAL wasn't a low-level abstraction layer like the Windows component of the same name.

I've created a Python script that simplifies the whole process:

Save the script below as reset_usb.py or clone this repo.

python reset_usb.py help # Show this help sudo python reset_usb.py list # List all USB devices sudo python reset_usb.py path /dev/bus/usb/XXX/YYY # Reset USB device using path /dev/bus/usb/XXX/YYY sudo python reset_usb.py search "search terms" # Search for USB device using the search terms within the search string returned by list and reset matching device sudo python reset_usb.py listpci # List all PCI USB devices sudo python reset_usb.py pathpci /sys/bus/pci/drivers/. /XXXX:XX:XX.X # Reset PCI USB device using path /sys/bus/pci/drivers/. /XXXX:XX:XX.X sudo python reset_usb.py searchpci "search terms" # Search for PCI USB device using the search terms within the search string returned by listpci and reset matching device 
#!/usr/bin/env python import os import sys from subprocess import Popen, PIPE import fcntl instructions = ''' Usage: python reset_usb.py help : Show this help sudo python reset_usb.py list : List all USB devices sudo python reset_usb.py path /dev/bus/usb/XXX/YYY : Reset USB device using path /dev/bus/usb/XXX/YYY sudo python reset_usb.py search "search terms" : Search for USB device using the search terms within the search string returned by list and reset matching device sudo python reset_usb.py listpci : List all PCI USB devices sudo python reset_usb.py pathpci /sys/bus/pci/drivers/. /XXXX:XX:XX.X : Reset PCI USB device using path sudo python reset_usb.py searchpci "search terms" : Search for PCI USB device using the search terms within the search string returned by listpci and reset matching device ''' if len(sys.argv) < 2: print(instructions) sys.exit(0) option = sys.argv[1].lower() if 'help' in option: print(instructions) sys.exit(0) def create_pci_list(): pci_usb_list = list() try: lspci_out = Popen('lspci -Dvmm', shell=True, bufsize=64, stdin=PIPE, stdout=PIPE, close_fds=True).stdout.read().strip().decode('utf-8') pci_devices = lspci_out.split('%s%s' % (os.linesep, os.linesep)) for pci_device in pci_devices: device_dict = dict() categories = pci_device.split(os.linesep) for category in categories: key, value = category.split('\t') device_dictПерезапуск usb портов linux] = value.strip() if 'USB' not in device_dict['Class']: continue for root, dirs, files in os.walk('/sys/bus/pci/drivers/'): slot = device_dict['Slot'] if slot in dirs: device_dict['path'] = os.path.join(root, slot) break pci_usb_list.append(device_dict) except Exception as ex: print('Failed to list pci devices! Error: %s' % ex) sys.exit(-1) return pci_usb_list def create_usb_list(): device_list = list() try: lsusb_out = Popen('lsusb -v', shell=True, bufsize=64, stdin=PIPE, stdout=PIPE, close_fds=True).stdout.read().strip().decode('utf-8') usb_devices = lsusb_out.split('%s%s' % (os.linesep, os.linesep)) for device_categories in usb_devices: if not device_categories: continue categories = device_categories.split(os.linesep) device_stuff = categories[0].strip().split() bus = device_stuff[1] device = device_stuff[3][:-1] device_dict = device_info = ' '.join(device_stuff[6:]) device_dict['description'] = device_info for category in categories: if not category: continue categoryinfo = category.strip().split() if categoryinfo[0] == 'iManufacturer': manufacturer_info = ' '.join(categoryinfo[2:]) device_dict['manufacturer'] = manufacturer_info if categoryinfo[0] == 'iProduct': device_info = ' '.join(categoryinfo[2:]) device_dict['device'] = device_info path = '/dev/bus/usb/%s/%s' % (bus, device) device_dict['path'] = path device_list.append(device_dict) except Exception as ex: print('Failed to list usb devices! Error: %s' % ex) sys.exit(-1) return device_list if 'listpci' in option: pci_usb_list = create_pci_list() for device in pci_usb_list: print('path=%s' % device['path']) print(' manufacturer=%s' % device['SVendor']) print(' device=%s' % device['SDevice']) print(' search string=%s %s' % (device['SVendor'], device['SDevice'])) sys.exit(0) if 'list' in option: usb_list = create_usb_list() for device in usb_list: print('path=%s' % device['path']) print(' description=%s' % device['description']) print(' manufacturer=%s' % device['manufacturer']) print(' device=%s' % device['device']) print(' search string=%s %s %s' % (device['description'], device['manufacturer'], device['device'])) sys.exit(0) if len(sys.argv) < 3: print(instructions) sys.exit(0) option2 = sys.argv[2] print('Resetting device: %s' % option2) # echo -n "0000:39:00.0" | tee /sys/bus/pci/drivers/xhci_hcd/unbind;echo -n "0000:39:00.0" | tee /sys/bus/pci/drivers/xhci_hcd/bind def reset_pci_usb_device(dev_path): folder, slot = os.path.split(dev_path) try: fp = open(os.path.join(folder, 'unbind'), 'wt') fp.write(slot) fp.close() fp = open(os.path.join(folder, 'bind'), 'wt') fp.write(slot) fp.close() print('Successfully reset %s' % dev_path) sys.exit(0) except Exception as ex: print('Failed to reset device! Error: %s' % ex) sys.exit(-1) if 'pathpci' in option: reset_pci_usb_device(option2) if 'searchpci' in option: pci_usb_list = create_pci_list() for device in pci_usb_list: text = '%s %s' % (device['SVendor'], device['SDevice']) if option2 in text: reset_pci_usb_device(device['path']) print('Failed to find device!') sys.exit(-1) def reset_usb_device(dev_path): USBDEVFS_RESET = 21780 try: f = open(dev_path, 'w', os.O_WRONLY) fcntl.ioctl(f, USBDEVFS_RESET, 0) print('Successfully reset %s' % dev_path) sys.exit(0) except Exception as ex: print('Failed to reset device! Error: %s' % ex) sys.exit(-1) if 'path' in option: reset_usb_device(option2) if 'search' in option: usb_list = create_usb_list() for device in usb_list: text = '%s %s %s' % (device['description'], device['manufacturer'], device['device']) if option2 in text: reset_usb_device(device['path']) print('Failed to find device!') sys.exit(-1) 

Источник

Оцените статью
Adblock
detector