Is there a generic way to reset a PCI device in Linux from the command line? That is, cause the PCI bus to issue a reset command.


according to http://www.kernel.org/doc/Documentation/ABI/testing/sysfs-bus-pci you can reset individual functions of the device if that's supported:

What:       /sys/bus/pci/devices/.../reset
            Some devices allow an individual function to be reset
            without affecting other functions in the same device.
            For devices that have this support, a file named reset
            will be present in sysfs.  Writing 1 to this file
            will perform reset.
| improve this answer | |

The closest thing the PCI bus has to a device level reset is changing the power state to D3 and back to D0. After unloading the driver ( it would be bad to reset the hardware out from under the driver ), you can use setpci to write to the control registers to change the power state, but I believe this happens automatically when you unload the driver.

| improve this answer | |

Since a generic PCI device is not hotpluggable there won't be a way to reset it and have the kernel re-enumerate it.

Whatever kind of problems you are trying to solve, there surely is a better way than to just reset it.

| improve this answer | |
  • 4
    I'm simulating a PCI device in QEMU and need to reset it's state as I develop. I wanted to do it from within the guest. – Jonathan Jan 24 '12 at 5:20
  • 1
    I have a buggy pci cctv card, it is working but sometimes dies with a segfault. After that, the whole system needs to be restarted, wiht a PCI reset this could be avoidable ... The system is stable, no harm, only the video input gets blank, so sometimes it is a better solution to reset the PCI than restarting the whole machine every day. (especially if you are 8000km away from that machine for 6 months) – Gipsz Jakab Jun 14 '17 at 8:41

The problem with the solutions above is that they require the cooperativity of the device; however in most scenarios the reason to reset it is exactly its non-cooperativity.

However, as it is described here, there is another, "harder" way to reset it on the PCI level: we remove it from the PCI bus and then re-insert it by a rescan.

The steps:

  1. echo 1 >/sys/bus/pci/<pci-id-of-device>/remove. We can find its PCI ID with an lspci command.
  2. echo 1 >/sys/bus/pci/rescan

I have here a buggy pci device, sometimes PCI-level reset, sometimes this removal-readd trick fixes it. I am about to write a script to do it automagically. :-)

| improve this answer | |
  • Ugh. My USB controller is still buggy, even after this reset. – Chris Feb 3 at 0:25
  • @Chris Are you sure that it is the controller, and not a device on it? – peterh - Reinstate Monica Feb 3 at 0:54
  • Yes, I'm sure it's the controller 00:14.0 USB controller: Intel Corporation 200 Series/Z370 Chipset Family USB 3.0 xHCI Controller. I pass it to VM through VFIO and after VM reboot I also have to reboot the host to make it work again, otherwise any USB plugged in is detected, but communication fails. – Chris Feb 4 at 9:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.