12

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.

migrated from serverfault.com Jan 23 '12 at 10:30

This question came from our site for system and network administrators.

6

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
Description:
            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.
5

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.

1

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.

  • 3
    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
  • 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
0

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. :-)

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.