Power Cycling PCIe Devices from the Command Line

I hate to say this but Linux software is not perfect. I know, I know, but nothing could possibly be wrong with openSUSE, right? Well, Linux and all the open source tools are created by people and since we are flawed, so are our creations. Sometimes, things can slip through the quality assurance process at openSUSE and however rare, they do happen.

The Problem

One of my problems that has shown it’s ugly head is an issue with the wifi driver. Sometimes, for whatever reason, it cannot authenticate. Another situation is, sometimes, you may have an issue passing a device to a Virtual Machine and it doesn’t come back quite right.

The Solution

In short, if you have a device on the PCI bus that needs to be removed and added again, there are some ways to do that. To get the PCI device ID, run:

/sbin/lspci

Take note of whatever your troublesome device is from here.

Method 1

echo "1" > /sys/bus/pci/devices/$NUMBER/reset

This should reset the device and have it behave, but as you may know from your experience in having used the original Nintendo Entertainment System, sometimes, it just isn’t good enough.

Example

echo "1" > /sys/bus/pci/devices/0000\:03\:00.0/reset

In my case, that will send the wifi network module to reset. It may or may not solve your issue.

Method 2

This one absolutely works. It is a bit more… brute force but it does indeed solve any issues I have.

echo "1" > /sys/bus/pci/devices/$NUMBER/remove
sleep 2
echo "1" > /sys/bus/pci/rescan

The sleep 2 is only necessary if you are copying and pasting into the terminal or creating a script. It is just a pause before it rescans the PCI bus. How I used it and I did create a script for this that I can invoke if I have problems.

Example

echo "1" > /sys/bus/pci/devices/0000\:03\:00.0/remove
sleep 2
echo "1" > /sys/bus/pci/rescan

Final Thoughts

Software isn’t perfect, I have historically had issues on more than one distribution with PCI devices requiring a reset. This method works with openSUSE Tumbleweed in the year 2019. If this should change, I will update this post.

References

https://unix.stackexchange.com/questions/73908/how-to-reset-cycle-power-to-a-pcie-device

Advertisements

3 thoughts on “Power Cycling PCIe Devices from the Command Line

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.