How to Reset/Cycle Power to a PCIe Device? The 2019 Stack Overflow Developer Survey Results Are In Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) 2019 Community Moderator Election ResultsReset a PCI Device in LinuxHow can I put a PCIe device into the D3 cold power state?How to avoid powering down certain USB devices when a machine is suspendedPCI passthrough with XenPrevent USB storage from using different device on resetNVMe PCIe disk power cyclingInstalling a PCIe-to-PCI Reversible Bridge under Debian results in “unclassified device”Asus G752VS, GTX 1070 - PCI-e audio device (second function) missingPTXdist + Linux ARM - PCIe not coming upHow can I put a PCIe device into the D3 cold power state?How do I translate between qemu-system arguments and virt-install arguments so I can unify partially working commands?NVIDIA DevBox with Ubuntu 16.04 and 4.4.0-137-generic kernel randomly reboots and automatically shuts down overnight

Why can't devices on different VLANs, but on the same subnet, communicate?

How does ice melt when immersed in water?

rotate text in posterbox

How can I define good in a religion that claims no moral authority?

Is it ok to offer lower paid work as a trial period before negotiating for a full-time job?

Make it rain characters

How should I replace vector<uint8_t>::const_iterator in an API?

Who or what is the being for whom Being is a question for Heidegger?

Can a 1st-level character have an ability score above 18?

What information about me do stores get via my credit card?

Segmentation fault output is suppressed when piping stdin into a function. Why?

How did passengers keep warm on sail ships?

Mortgage adviser recommends a longer term than necessary combined with overpayments

Why does this iterative way of solving of equation work?

Semisimplicity of the category of coherent sheaves?

Would an alien lifeform be able to achieve space travel if lacking in vision?

Difference between "generating set" and free product?

Simulating Exploding Dice

Why is Captain Marvel translated as male in Portugal?

What do you call a plan that's an alternative plan in case your initial plan fails?

Sort a list of pairs representing an acyclic, partial automorphism

How are presidential pardons supposed to be used?

University's motivation for having tenure-track positions

Wolves and sheep



How to Reset/Cycle Power to a PCIe Device?



The 2019 Stack Overflow Developer Survey Results Are In
Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)
2019 Community Moderator Election ResultsReset a PCI Device in LinuxHow can I put a PCIe device into the D3 cold power state?How to avoid powering down certain USB devices when a machine is suspendedPCI passthrough with XenPrevent USB storage from using different device on resetNVMe PCIe disk power cyclingInstalling a PCIe-to-PCI Reversible Bridge under Debian results in “unclassified device”Asus G752VS, GTX 1070 - PCI-e audio device (second function) missingPTXdist + Linux ARM - PCIe not coming upHow can I put a PCIe device into the D3 cold power state?How do I translate between qemu-system arguments and virt-install arguments so I can unify partially working commands?NVIDIA DevBox with Ubuntu 16.04 and 4.4.0-137-generic kernel randomly reboots and automatically shuts down overnight



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








17















I have a PCIe device that only works correctly when the computer is fully powered off then on again. Issuing a simple reboot or reboot -p command does not appear to cycle the power to the PCIe card, which causes it not to work after the reboot.



Is there a way to, from the OS, cycle power to a device in a PCIe slot? I can find it in /sys/bus/pci/devices/0000*/, but I can't figure out how to properly reset the board. Toggling power seems to be the only way.



Barring that, can I change a setting somewhere that will cause a full power cycle on a reboot command?



I'm running Ubuntu 12.10 by the way.










share|improve this question
























  • Did you try reboot -f? This is similar to pressing the power button of the CPU.

    – ktan
    Apr 23 '15 at 7:59












  • Two years ago the OP pointed out that a soft reboot didn't work. Your reboot -f is still a soft reboot.

    – roaima
    Apr 23 '15 at 10:18

















17















I have a PCIe device that only works correctly when the computer is fully powered off then on again. Issuing a simple reboot or reboot -p command does not appear to cycle the power to the PCIe card, which causes it not to work after the reboot.



Is there a way to, from the OS, cycle power to a device in a PCIe slot? I can find it in /sys/bus/pci/devices/0000*/, but I can't figure out how to properly reset the board. Toggling power seems to be the only way.



Barring that, can I change a setting somewhere that will cause a full power cycle on a reboot command?



I'm running Ubuntu 12.10 by the way.










share|improve this question
























  • Did you try reboot -f? This is similar to pressing the power button of the CPU.

    – ktan
    Apr 23 '15 at 7:59












  • Two years ago the OP pointed out that a soft reboot didn't work. Your reboot -f is still a soft reboot.

    – roaima
    Apr 23 '15 at 10:18













17












17








17


9






I have a PCIe device that only works correctly when the computer is fully powered off then on again. Issuing a simple reboot or reboot -p command does not appear to cycle the power to the PCIe card, which causes it not to work after the reboot.



Is there a way to, from the OS, cycle power to a device in a PCIe slot? I can find it in /sys/bus/pci/devices/0000*/, but I can't figure out how to properly reset the board. Toggling power seems to be the only way.



Barring that, can I change a setting somewhere that will cause a full power cycle on a reboot command?



I'm running Ubuntu 12.10 by the way.










share|improve this question
















I have a PCIe device that only works correctly when the computer is fully powered off then on again. Issuing a simple reboot or reboot -p command does not appear to cycle the power to the PCIe card, which causes it not to work after the reboot.



Is there a way to, from the OS, cycle power to a device in a PCIe slot? I can find it in /sys/bus/pci/devices/0000*/, but I can't figure out how to properly reset the board. Toggling power seems to be the only way.



Barring that, can I change a setting somewhere that will cause a full power cycle on a reboot command?



I'm running Ubuntu 12.10 by the way.







devices power-management pci






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Apr 27 '13 at 23:28







zachd1_618

















asked Apr 27 '13 at 22:40









zachd1_618zachd1_618

186116




186116












  • Did you try reboot -f? This is similar to pressing the power button of the CPU.

    – ktan
    Apr 23 '15 at 7:59












  • Two years ago the OP pointed out that a soft reboot didn't work. Your reboot -f is still a soft reboot.

    – roaima
    Apr 23 '15 at 10:18

















  • Did you try reboot -f? This is similar to pressing the power button of the CPU.

    – ktan
    Apr 23 '15 at 7:59












  • Two years ago the OP pointed out that a soft reboot didn't work. Your reboot -f is still a soft reboot.

    – roaima
    Apr 23 '15 at 10:18
















Did you try reboot -f? This is similar to pressing the power button of the CPU.

– ktan
Apr 23 '15 at 7:59






Did you try reboot -f? This is similar to pressing the power button of the CPU.

– ktan
Apr 23 '15 at 7:59














Two years ago the OP pointed out that a soft reboot didn't work. Your reboot -f is still a soft reboot.

– roaima
Apr 23 '15 at 10:18





Two years ago the OP pointed out that a soft reboot didn't work. Your reboot -f is still a soft reboot.

– roaima
Apr 23 '15 at 10:18










3 Answers
3






active

oldest

votes


















16














Potential Method #1



I think you can do it with these commands:



disable



echo 0 > /sys/bus/pci/slots/$NUMBER/power


enable



echo 1 > /sys/bus/pci/slots/$NUMBER/power


Where $NUMBER is the number of the PCI slot.



lspci -vv may help to identify the device. This is not very well documented...



Potential Method #2



I came across this thread on U&L, similar issue: there are some answers to that question that say you can reset with this command:



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


However, I would read the answers there! There are conditions around doing it this way! Specifically I would read this answer!



Potential Method #3



There is a Unix command, setpci, that may give you a method for resetting a device in the PCI bus.



I did not see any specific examples with this command so you'll have to google for examples and look through the man page. I would tread lightly with this command until you're confident in it's use. From what I've read about it, it's manipulating the hardware directly and so there are always risks in doing it yourself vs. using a tool that is exposing this type of functionality!






share|improve this answer




















  • 1





    Nothing shows up in slots, even though I have multiple cards plugged in. I do have a power directory in /sys/bus/pci/devices/$NUMBER/. But nothing seems to warrant setting 0 or 1

    – zachd1_618
    Apr 27 '13 at 23:30






  • 1





    I came across this thread on U&L, similar issue: there are some answers to that Q that say you can reset with this: echo "1" > /sys/bus/pci/devices/$NUMBER/reset. Read that Q though, there are conditions around doing it that way!

    – slm
    Apr 27 '13 at 23:42











  • Thanks for the link. I've tried that however and it doesn't seem to do anything. Specifically, the device doesn't power cycle and the system still knows it is there. (When the card is on and plugged in, there are devices in /dev that I can watch). They don't disappear when I echo "1" > ....

    – zachd1_618
    Apr 28 '13 at 0:06






  • 1





    Are you unloading the kernel modules for that card prior to the power cycling? I think you have to do that as well.

    – slm
    Apr 28 '13 at 0:33






  • 1





    I think I'll check the kernel source code to see if toggling power actually puts it into D3.

    – forest
    Aug 7 '18 at 0:04



















4














remove and rescan will allow the kernel to cycler-power the PCI device without reboot:



echo "1" > /sys/bus/pci/devices/DDDD:BB:DD.F//remove
sleep 1
echo "1" > /sys/bus/pci/rescan


where DDDD.BB.DD.F = Domain:Bus:Device.Function






share|improve this answer























  • echo "1" > /sys/bus/pci/rescan is worked for me in lenovo g560 mini pci slot. I plugged in USB 3.0 minipci card. System is Ubuntu 16.04 x64

    – kodmanyagha
    Mar 19 '18 at 12:26



















3














Resets in PCI express are a bit complex. There are two main types of resets - conventional reset, and function-level reset. There are also two types of conventional resets, fundamental resets and non-fundamental resets. See the PCI express specification for all of the details.



A 'cold reset' is a fundamental reset that takes place after power is applied to a PCIe device. There appears to be no standard way of triggering a cold reset, save for turning the system off and back on again. On my machines, the /sys/bus/pci/slots directory is empty.



A 'warm reset' is a fundamental reset that is triggered without disconnecting power from the device. There appears to be no standard way of triggering a warm reset.



A 'hot reset' is a conventional reset that is triggered across a PCI express link. A hot reset is triggered either when a link is forced into electrical idle or by sending TS1 and TS2 ordered sets with the hot reset bit set. Software can initiate a hot reset by setting and then clearing the secondary bus reset bit in the bridge control register in the PCI configuration space of the bridge port upstream of the device.



A 'function-level reset' (FLR) is a reset that affects only a single function of a PCI express device. It must not reset the entire PCIe device. Implementing function-level resets is not required by the PCIe specification. A function-level reset is initiated by setting the initiate function-level reset bit in the function's device control register in the PCI express capability structure in the PCI configuration space.



Linux exposes the function-level reset functionality in the form of /sys/bus/pci/devices/$dev/reset. Writing a 1 to this file will initiate a function-level reset on the corresponding function. Note that this only affects that specific function of the device, not the whole device, and devices are not required to implement function-level resets as per the PCIe specification.



I am not aware of any 'nice' method for triggering a hot reset (there is no sysfs entry for that). However, it is possible to use setpci to do so:



#!/bin/bash

dev=$1

if [ -z "$dev" ]; then
echo "Error: no device specified"
exit 1
fi

if [ ! -e "/sys/bus/pci/devices/$dev" ]; then
dev="0000:$dev"
fi

if [ ! -e "/sys/bus/pci/devices/$dev" ]; then
echo "Error: device $dev not found"
exit 1
fi

port=$(basename $(dirname $(readlink "/sys/bus/pci/devices/$dev")))

if [ ! -e "/sys/bus/pci/devices/$port" ]; then
echo "Error: device $port not found"
exit 1
fi

echo "Removing $dev..."

echo 1 > "/sys/bus/pci/devices/$dev/remove"

echo "Performing hot reset of port $port..."

bc=$(setpci -s $port BRIDGE_CONTROL)

echo "Bridge control:" $bc

setpci -s $port BRIDGE_CONTROL=$(printf "%04x" $(("0x$bc" | 0x40)))
sleep 0.01
setpci -s $port BRIDGE_CONTROL=$bc
sleep 0.5

echo "Rescanning bus..."

echo 1 > "/sys/bus/pci/devices/$port/rescan"


Ensure that all attached drivers are unloaded before running this script. This script will attempt to remove the PCIe device, then command the upstream switch port to issue a hot reset, then attempt to rescan the PCIe bus. This script has also only been tested on devices with a single function, so it may need some reworking for devices with multiple functions.






share|improve this answer

























  • This script worked for my AMD RX480. Context: PCI passthrough to a Win10 guest, then shutting down or rebooting the guest. Starting the guest again (without using this script) would hang if the GPU was still attached. Running this script in between fixed the issue

    – 小太郎
    Oct 20 '18 at 7:32












Your Answer








StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f73908%2fhow-to-reset-cycle-power-to-a-pcie-device%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























3 Answers
3






active

oldest

votes








3 Answers
3






active

oldest

votes









active

oldest

votes






active

oldest

votes









16














Potential Method #1



I think you can do it with these commands:



disable



echo 0 > /sys/bus/pci/slots/$NUMBER/power


enable



echo 1 > /sys/bus/pci/slots/$NUMBER/power


Where $NUMBER is the number of the PCI slot.



lspci -vv may help to identify the device. This is not very well documented...



Potential Method #2



I came across this thread on U&L, similar issue: there are some answers to that question that say you can reset with this command:



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


However, I would read the answers there! There are conditions around doing it this way! Specifically I would read this answer!



Potential Method #3



There is a Unix command, setpci, that may give you a method for resetting a device in the PCI bus.



I did not see any specific examples with this command so you'll have to google for examples and look through the man page. I would tread lightly with this command until you're confident in it's use. From what I've read about it, it's manipulating the hardware directly and so there are always risks in doing it yourself vs. using a tool that is exposing this type of functionality!






share|improve this answer




















  • 1





    Nothing shows up in slots, even though I have multiple cards plugged in. I do have a power directory in /sys/bus/pci/devices/$NUMBER/. But nothing seems to warrant setting 0 or 1

    – zachd1_618
    Apr 27 '13 at 23:30






  • 1





    I came across this thread on U&L, similar issue: there are some answers to that Q that say you can reset with this: echo "1" > /sys/bus/pci/devices/$NUMBER/reset. Read that Q though, there are conditions around doing it that way!

    – slm
    Apr 27 '13 at 23:42











  • Thanks for the link. I've tried that however and it doesn't seem to do anything. Specifically, the device doesn't power cycle and the system still knows it is there. (When the card is on and plugged in, there are devices in /dev that I can watch). They don't disappear when I echo "1" > ....

    – zachd1_618
    Apr 28 '13 at 0:06






  • 1





    Are you unloading the kernel modules for that card prior to the power cycling? I think you have to do that as well.

    – slm
    Apr 28 '13 at 0:33






  • 1





    I think I'll check the kernel source code to see if toggling power actually puts it into D3.

    – forest
    Aug 7 '18 at 0:04
















16














Potential Method #1



I think you can do it with these commands:



disable



echo 0 > /sys/bus/pci/slots/$NUMBER/power


enable



echo 1 > /sys/bus/pci/slots/$NUMBER/power


Where $NUMBER is the number of the PCI slot.



lspci -vv may help to identify the device. This is not very well documented...



Potential Method #2



I came across this thread on U&L, similar issue: there are some answers to that question that say you can reset with this command:



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


However, I would read the answers there! There are conditions around doing it this way! Specifically I would read this answer!



Potential Method #3



There is a Unix command, setpci, that may give you a method for resetting a device in the PCI bus.



I did not see any specific examples with this command so you'll have to google for examples and look through the man page. I would tread lightly with this command until you're confident in it's use. From what I've read about it, it's manipulating the hardware directly and so there are always risks in doing it yourself vs. using a tool that is exposing this type of functionality!






share|improve this answer




















  • 1





    Nothing shows up in slots, even though I have multiple cards plugged in. I do have a power directory in /sys/bus/pci/devices/$NUMBER/. But nothing seems to warrant setting 0 or 1

    – zachd1_618
    Apr 27 '13 at 23:30






  • 1





    I came across this thread on U&L, similar issue: there are some answers to that Q that say you can reset with this: echo "1" > /sys/bus/pci/devices/$NUMBER/reset. Read that Q though, there are conditions around doing it that way!

    – slm
    Apr 27 '13 at 23:42











  • Thanks for the link. I've tried that however and it doesn't seem to do anything. Specifically, the device doesn't power cycle and the system still knows it is there. (When the card is on and plugged in, there are devices in /dev that I can watch). They don't disappear when I echo "1" > ....

    – zachd1_618
    Apr 28 '13 at 0:06






  • 1





    Are you unloading the kernel modules for that card prior to the power cycling? I think you have to do that as well.

    – slm
    Apr 28 '13 at 0:33






  • 1





    I think I'll check the kernel source code to see if toggling power actually puts it into D3.

    – forest
    Aug 7 '18 at 0:04














16












16








16







Potential Method #1



I think you can do it with these commands:



disable



echo 0 > /sys/bus/pci/slots/$NUMBER/power


enable



echo 1 > /sys/bus/pci/slots/$NUMBER/power


Where $NUMBER is the number of the PCI slot.



lspci -vv may help to identify the device. This is not very well documented...



Potential Method #2



I came across this thread on U&L, similar issue: there are some answers to that question that say you can reset with this command:



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


However, I would read the answers there! There are conditions around doing it this way! Specifically I would read this answer!



Potential Method #3



There is a Unix command, setpci, that may give you a method for resetting a device in the PCI bus.



I did not see any specific examples with this command so you'll have to google for examples and look through the man page. I would tread lightly with this command until you're confident in it's use. From what I've read about it, it's manipulating the hardware directly and so there are always risks in doing it yourself vs. using a tool that is exposing this type of functionality!






share|improve this answer















Potential Method #1



I think you can do it with these commands:



disable



echo 0 > /sys/bus/pci/slots/$NUMBER/power


enable



echo 1 > /sys/bus/pci/slots/$NUMBER/power


Where $NUMBER is the number of the PCI slot.



lspci -vv may help to identify the device. This is not very well documented...



Potential Method #2



I came across this thread on U&L, similar issue: there are some answers to that question that say you can reset with this command:



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


However, I would read the answers there! There are conditions around doing it this way! Specifically I would read this answer!



Potential Method #3



There is a Unix command, setpci, that may give you a method for resetting a device in the PCI bus.



I did not see any specific examples with this command so you'll have to google for examples and look through the man page. I would tread lightly with this command until you're confident in it's use. From what I've read about it, it's manipulating the hardware directly and so there are always risks in doing it yourself vs. using a tool that is exposing this type of functionality!







share|improve this answer














share|improve this answer



share|improve this answer








edited Apr 13 '17 at 12:36









Community

1




1










answered Apr 27 '13 at 23:18









slmslm

256k71544689




256k71544689







  • 1





    Nothing shows up in slots, even though I have multiple cards plugged in. I do have a power directory in /sys/bus/pci/devices/$NUMBER/. But nothing seems to warrant setting 0 or 1

    – zachd1_618
    Apr 27 '13 at 23:30






  • 1





    I came across this thread on U&L, similar issue: there are some answers to that Q that say you can reset with this: echo "1" > /sys/bus/pci/devices/$NUMBER/reset. Read that Q though, there are conditions around doing it that way!

    – slm
    Apr 27 '13 at 23:42











  • Thanks for the link. I've tried that however and it doesn't seem to do anything. Specifically, the device doesn't power cycle and the system still knows it is there. (When the card is on and plugged in, there are devices in /dev that I can watch). They don't disappear when I echo "1" > ....

    – zachd1_618
    Apr 28 '13 at 0:06






  • 1





    Are you unloading the kernel modules for that card prior to the power cycling? I think you have to do that as well.

    – slm
    Apr 28 '13 at 0:33






  • 1





    I think I'll check the kernel source code to see if toggling power actually puts it into D3.

    – forest
    Aug 7 '18 at 0:04













  • 1





    Nothing shows up in slots, even though I have multiple cards plugged in. I do have a power directory in /sys/bus/pci/devices/$NUMBER/. But nothing seems to warrant setting 0 or 1

    – zachd1_618
    Apr 27 '13 at 23:30






  • 1





    I came across this thread on U&L, similar issue: there are some answers to that Q that say you can reset with this: echo "1" > /sys/bus/pci/devices/$NUMBER/reset. Read that Q though, there are conditions around doing it that way!

    – slm
    Apr 27 '13 at 23:42











  • Thanks for the link. I've tried that however and it doesn't seem to do anything. Specifically, the device doesn't power cycle and the system still knows it is there. (When the card is on and plugged in, there are devices in /dev that I can watch). They don't disappear when I echo "1" > ....

    – zachd1_618
    Apr 28 '13 at 0:06






  • 1





    Are you unloading the kernel modules for that card prior to the power cycling? I think you have to do that as well.

    – slm
    Apr 28 '13 at 0:33






  • 1





    I think I'll check the kernel source code to see if toggling power actually puts it into D3.

    – forest
    Aug 7 '18 at 0:04








1




1





Nothing shows up in slots, even though I have multiple cards plugged in. I do have a power directory in /sys/bus/pci/devices/$NUMBER/. But nothing seems to warrant setting 0 or 1

– zachd1_618
Apr 27 '13 at 23:30





Nothing shows up in slots, even though I have multiple cards plugged in. I do have a power directory in /sys/bus/pci/devices/$NUMBER/. But nothing seems to warrant setting 0 or 1

– zachd1_618
Apr 27 '13 at 23:30




1




1





I came across this thread on U&L, similar issue: there are some answers to that Q that say you can reset with this: echo "1" > /sys/bus/pci/devices/$NUMBER/reset. Read that Q though, there are conditions around doing it that way!

– slm
Apr 27 '13 at 23:42





I came across this thread on U&L, similar issue: there are some answers to that Q that say you can reset with this: echo "1" > /sys/bus/pci/devices/$NUMBER/reset. Read that Q though, there are conditions around doing it that way!

– slm
Apr 27 '13 at 23:42













Thanks for the link. I've tried that however and it doesn't seem to do anything. Specifically, the device doesn't power cycle and the system still knows it is there. (When the card is on and plugged in, there are devices in /dev that I can watch). They don't disappear when I echo "1" > ....

– zachd1_618
Apr 28 '13 at 0:06





Thanks for the link. I've tried that however and it doesn't seem to do anything. Specifically, the device doesn't power cycle and the system still knows it is there. (When the card is on and plugged in, there are devices in /dev that I can watch). They don't disappear when I echo "1" > ....

– zachd1_618
Apr 28 '13 at 0:06




1




1





Are you unloading the kernel modules for that card prior to the power cycling? I think you have to do that as well.

– slm
Apr 28 '13 at 0:33





Are you unloading the kernel modules for that card prior to the power cycling? I think you have to do that as well.

– slm
Apr 28 '13 at 0:33




1




1





I think I'll check the kernel source code to see if toggling power actually puts it into D3.

– forest
Aug 7 '18 at 0:04






I think I'll check the kernel source code to see if toggling power actually puts it into D3.

– forest
Aug 7 '18 at 0:04














4














remove and rescan will allow the kernel to cycler-power the PCI device without reboot:



echo "1" > /sys/bus/pci/devices/DDDD:BB:DD.F//remove
sleep 1
echo "1" > /sys/bus/pci/rescan


where DDDD.BB.DD.F = Domain:Bus:Device.Function






share|improve this answer























  • echo "1" > /sys/bus/pci/rescan is worked for me in lenovo g560 mini pci slot. I plugged in USB 3.0 minipci card. System is Ubuntu 16.04 x64

    – kodmanyagha
    Mar 19 '18 at 12:26
















4














remove and rescan will allow the kernel to cycler-power the PCI device without reboot:



echo "1" > /sys/bus/pci/devices/DDDD:BB:DD.F//remove
sleep 1
echo "1" > /sys/bus/pci/rescan


where DDDD.BB.DD.F = Domain:Bus:Device.Function






share|improve this answer























  • echo "1" > /sys/bus/pci/rescan is worked for me in lenovo g560 mini pci slot. I plugged in USB 3.0 minipci card. System is Ubuntu 16.04 x64

    – kodmanyagha
    Mar 19 '18 at 12:26














4












4








4







remove and rescan will allow the kernel to cycler-power the PCI device without reboot:



echo "1" > /sys/bus/pci/devices/DDDD:BB:DD.F//remove
sleep 1
echo "1" > /sys/bus/pci/rescan


where DDDD.BB.DD.F = Domain:Bus:Device.Function






share|improve this answer













remove and rescan will allow the kernel to cycler-power the PCI device without reboot:



echo "1" > /sys/bus/pci/devices/DDDD:BB:DD.F//remove
sleep 1
echo "1" > /sys/bus/pci/rescan


where DDDD.BB.DD.F = Domain:Bus:Device.Function







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 24 '15 at 16:35









cybercyber

411




411












  • echo "1" > /sys/bus/pci/rescan is worked for me in lenovo g560 mini pci slot. I plugged in USB 3.0 minipci card. System is Ubuntu 16.04 x64

    – kodmanyagha
    Mar 19 '18 at 12:26


















  • echo "1" > /sys/bus/pci/rescan is worked for me in lenovo g560 mini pci slot. I plugged in USB 3.0 minipci card. System is Ubuntu 16.04 x64

    – kodmanyagha
    Mar 19 '18 at 12:26

















echo "1" > /sys/bus/pci/rescan is worked for me in lenovo g560 mini pci slot. I plugged in USB 3.0 minipci card. System is Ubuntu 16.04 x64

– kodmanyagha
Mar 19 '18 at 12:26






echo "1" > /sys/bus/pci/rescan is worked for me in lenovo g560 mini pci slot. I plugged in USB 3.0 minipci card. System is Ubuntu 16.04 x64

– kodmanyagha
Mar 19 '18 at 12:26












3














Resets in PCI express are a bit complex. There are two main types of resets - conventional reset, and function-level reset. There are also two types of conventional resets, fundamental resets and non-fundamental resets. See the PCI express specification for all of the details.



A 'cold reset' is a fundamental reset that takes place after power is applied to a PCIe device. There appears to be no standard way of triggering a cold reset, save for turning the system off and back on again. On my machines, the /sys/bus/pci/slots directory is empty.



A 'warm reset' is a fundamental reset that is triggered without disconnecting power from the device. There appears to be no standard way of triggering a warm reset.



A 'hot reset' is a conventional reset that is triggered across a PCI express link. A hot reset is triggered either when a link is forced into electrical idle or by sending TS1 and TS2 ordered sets with the hot reset bit set. Software can initiate a hot reset by setting and then clearing the secondary bus reset bit in the bridge control register in the PCI configuration space of the bridge port upstream of the device.



A 'function-level reset' (FLR) is a reset that affects only a single function of a PCI express device. It must not reset the entire PCIe device. Implementing function-level resets is not required by the PCIe specification. A function-level reset is initiated by setting the initiate function-level reset bit in the function's device control register in the PCI express capability structure in the PCI configuration space.



Linux exposes the function-level reset functionality in the form of /sys/bus/pci/devices/$dev/reset. Writing a 1 to this file will initiate a function-level reset on the corresponding function. Note that this only affects that specific function of the device, not the whole device, and devices are not required to implement function-level resets as per the PCIe specification.



I am not aware of any 'nice' method for triggering a hot reset (there is no sysfs entry for that). However, it is possible to use setpci to do so:



#!/bin/bash

dev=$1

if [ -z "$dev" ]; then
echo "Error: no device specified"
exit 1
fi

if [ ! -e "/sys/bus/pci/devices/$dev" ]; then
dev="0000:$dev"
fi

if [ ! -e "/sys/bus/pci/devices/$dev" ]; then
echo "Error: device $dev not found"
exit 1
fi

port=$(basename $(dirname $(readlink "/sys/bus/pci/devices/$dev")))

if [ ! -e "/sys/bus/pci/devices/$port" ]; then
echo "Error: device $port not found"
exit 1
fi

echo "Removing $dev..."

echo 1 > "/sys/bus/pci/devices/$dev/remove"

echo "Performing hot reset of port $port..."

bc=$(setpci -s $port BRIDGE_CONTROL)

echo "Bridge control:" $bc

setpci -s $port BRIDGE_CONTROL=$(printf "%04x" $(("0x$bc" | 0x40)))
sleep 0.01
setpci -s $port BRIDGE_CONTROL=$bc
sleep 0.5

echo "Rescanning bus..."

echo 1 > "/sys/bus/pci/devices/$port/rescan"


Ensure that all attached drivers are unloaded before running this script. This script will attempt to remove the PCIe device, then command the upstream switch port to issue a hot reset, then attempt to rescan the PCIe bus. This script has also only been tested on devices with a single function, so it may need some reworking for devices with multiple functions.






share|improve this answer

























  • This script worked for my AMD RX480. Context: PCI passthrough to a Win10 guest, then shutting down or rebooting the guest. Starting the guest again (without using this script) would hang if the GPU was still attached. Running this script in between fixed the issue

    – 小太郎
    Oct 20 '18 at 7:32
















3














Resets in PCI express are a bit complex. There are two main types of resets - conventional reset, and function-level reset. There are also two types of conventional resets, fundamental resets and non-fundamental resets. See the PCI express specification for all of the details.



A 'cold reset' is a fundamental reset that takes place after power is applied to a PCIe device. There appears to be no standard way of triggering a cold reset, save for turning the system off and back on again. On my machines, the /sys/bus/pci/slots directory is empty.



A 'warm reset' is a fundamental reset that is triggered without disconnecting power from the device. There appears to be no standard way of triggering a warm reset.



A 'hot reset' is a conventional reset that is triggered across a PCI express link. A hot reset is triggered either when a link is forced into electrical idle or by sending TS1 and TS2 ordered sets with the hot reset bit set. Software can initiate a hot reset by setting and then clearing the secondary bus reset bit in the bridge control register in the PCI configuration space of the bridge port upstream of the device.



A 'function-level reset' (FLR) is a reset that affects only a single function of a PCI express device. It must not reset the entire PCIe device. Implementing function-level resets is not required by the PCIe specification. A function-level reset is initiated by setting the initiate function-level reset bit in the function's device control register in the PCI express capability structure in the PCI configuration space.



Linux exposes the function-level reset functionality in the form of /sys/bus/pci/devices/$dev/reset. Writing a 1 to this file will initiate a function-level reset on the corresponding function. Note that this only affects that specific function of the device, not the whole device, and devices are not required to implement function-level resets as per the PCIe specification.



I am not aware of any 'nice' method for triggering a hot reset (there is no sysfs entry for that). However, it is possible to use setpci to do so:



#!/bin/bash

dev=$1

if [ -z "$dev" ]; then
echo "Error: no device specified"
exit 1
fi

if [ ! -e "/sys/bus/pci/devices/$dev" ]; then
dev="0000:$dev"
fi

if [ ! -e "/sys/bus/pci/devices/$dev" ]; then
echo "Error: device $dev not found"
exit 1
fi

port=$(basename $(dirname $(readlink "/sys/bus/pci/devices/$dev")))

if [ ! -e "/sys/bus/pci/devices/$port" ]; then
echo "Error: device $port not found"
exit 1
fi

echo "Removing $dev..."

echo 1 > "/sys/bus/pci/devices/$dev/remove"

echo "Performing hot reset of port $port..."

bc=$(setpci -s $port BRIDGE_CONTROL)

echo "Bridge control:" $bc

setpci -s $port BRIDGE_CONTROL=$(printf "%04x" $(("0x$bc" | 0x40)))
sleep 0.01
setpci -s $port BRIDGE_CONTROL=$bc
sleep 0.5

echo "Rescanning bus..."

echo 1 > "/sys/bus/pci/devices/$port/rescan"


Ensure that all attached drivers are unloaded before running this script. This script will attempt to remove the PCIe device, then command the upstream switch port to issue a hot reset, then attempt to rescan the PCIe bus. This script has also only been tested on devices with a single function, so it may need some reworking for devices with multiple functions.






share|improve this answer

























  • This script worked for my AMD RX480. Context: PCI passthrough to a Win10 guest, then shutting down or rebooting the guest. Starting the guest again (without using this script) would hang if the GPU was still attached. Running this script in between fixed the issue

    – 小太郎
    Oct 20 '18 at 7:32














3












3








3







Resets in PCI express are a bit complex. There are two main types of resets - conventional reset, and function-level reset. There are also two types of conventional resets, fundamental resets and non-fundamental resets. See the PCI express specification for all of the details.



A 'cold reset' is a fundamental reset that takes place after power is applied to a PCIe device. There appears to be no standard way of triggering a cold reset, save for turning the system off and back on again. On my machines, the /sys/bus/pci/slots directory is empty.



A 'warm reset' is a fundamental reset that is triggered without disconnecting power from the device. There appears to be no standard way of triggering a warm reset.



A 'hot reset' is a conventional reset that is triggered across a PCI express link. A hot reset is triggered either when a link is forced into electrical idle or by sending TS1 and TS2 ordered sets with the hot reset bit set. Software can initiate a hot reset by setting and then clearing the secondary bus reset bit in the bridge control register in the PCI configuration space of the bridge port upstream of the device.



A 'function-level reset' (FLR) is a reset that affects only a single function of a PCI express device. It must not reset the entire PCIe device. Implementing function-level resets is not required by the PCIe specification. A function-level reset is initiated by setting the initiate function-level reset bit in the function's device control register in the PCI express capability structure in the PCI configuration space.



Linux exposes the function-level reset functionality in the form of /sys/bus/pci/devices/$dev/reset. Writing a 1 to this file will initiate a function-level reset on the corresponding function. Note that this only affects that specific function of the device, not the whole device, and devices are not required to implement function-level resets as per the PCIe specification.



I am not aware of any 'nice' method for triggering a hot reset (there is no sysfs entry for that). However, it is possible to use setpci to do so:



#!/bin/bash

dev=$1

if [ -z "$dev" ]; then
echo "Error: no device specified"
exit 1
fi

if [ ! -e "/sys/bus/pci/devices/$dev" ]; then
dev="0000:$dev"
fi

if [ ! -e "/sys/bus/pci/devices/$dev" ]; then
echo "Error: device $dev not found"
exit 1
fi

port=$(basename $(dirname $(readlink "/sys/bus/pci/devices/$dev")))

if [ ! -e "/sys/bus/pci/devices/$port" ]; then
echo "Error: device $port not found"
exit 1
fi

echo "Removing $dev..."

echo 1 > "/sys/bus/pci/devices/$dev/remove"

echo "Performing hot reset of port $port..."

bc=$(setpci -s $port BRIDGE_CONTROL)

echo "Bridge control:" $bc

setpci -s $port BRIDGE_CONTROL=$(printf "%04x" $(("0x$bc" | 0x40)))
sleep 0.01
setpci -s $port BRIDGE_CONTROL=$bc
sleep 0.5

echo "Rescanning bus..."

echo 1 > "/sys/bus/pci/devices/$port/rescan"


Ensure that all attached drivers are unloaded before running this script. This script will attempt to remove the PCIe device, then command the upstream switch port to issue a hot reset, then attempt to rescan the PCIe bus. This script has also only been tested on devices with a single function, so it may need some reworking for devices with multiple functions.






share|improve this answer















Resets in PCI express are a bit complex. There are two main types of resets - conventional reset, and function-level reset. There are also two types of conventional resets, fundamental resets and non-fundamental resets. See the PCI express specification for all of the details.



A 'cold reset' is a fundamental reset that takes place after power is applied to a PCIe device. There appears to be no standard way of triggering a cold reset, save for turning the system off and back on again. On my machines, the /sys/bus/pci/slots directory is empty.



A 'warm reset' is a fundamental reset that is triggered without disconnecting power from the device. There appears to be no standard way of triggering a warm reset.



A 'hot reset' is a conventional reset that is triggered across a PCI express link. A hot reset is triggered either when a link is forced into electrical idle or by sending TS1 and TS2 ordered sets with the hot reset bit set. Software can initiate a hot reset by setting and then clearing the secondary bus reset bit in the bridge control register in the PCI configuration space of the bridge port upstream of the device.



A 'function-level reset' (FLR) is a reset that affects only a single function of a PCI express device. It must not reset the entire PCIe device. Implementing function-level resets is not required by the PCIe specification. A function-level reset is initiated by setting the initiate function-level reset bit in the function's device control register in the PCI express capability structure in the PCI configuration space.



Linux exposes the function-level reset functionality in the form of /sys/bus/pci/devices/$dev/reset. Writing a 1 to this file will initiate a function-level reset on the corresponding function. Note that this only affects that specific function of the device, not the whole device, and devices are not required to implement function-level resets as per the PCIe specification.



I am not aware of any 'nice' method for triggering a hot reset (there is no sysfs entry for that). However, it is possible to use setpci to do so:



#!/bin/bash

dev=$1

if [ -z "$dev" ]; then
echo "Error: no device specified"
exit 1
fi

if [ ! -e "/sys/bus/pci/devices/$dev" ]; then
dev="0000:$dev"
fi

if [ ! -e "/sys/bus/pci/devices/$dev" ]; then
echo "Error: device $dev not found"
exit 1
fi

port=$(basename $(dirname $(readlink "/sys/bus/pci/devices/$dev")))

if [ ! -e "/sys/bus/pci/devices/$port" ]; then
echo "Error: device $port not found"
exit 1
fi

echo "Removing $dev..."

echo 1 > "/sys/bus/pci/devices/$dev/remove"

echo "Performing hot reset of port $port..."

bc=$(setpci -s $port BRIDGE_CONTROL)

echo "Bridge control:" $bc

setpci -s $port BRIDGE_CONTROL=$(printf "%04x" $(("0x$bc" | 0x40)))
sleep 0.01
setpci -s $port BRIDGE_CONTROL=$bc
sleep 0.5

echo "Rescanning bus..."

echo 1 > "/sys/bus/pci/devices/$port/rescan"


Ensure that all attached drivers are unloaded before running this script. This script will attempt to remove the PCIe device, then command the upstream switch port to issue a hot reset, then attempt to rescan the PCIe bus. This script has also only been tested on devices with a single function, so it may need some reworking for devices with multiple functions.







share|improve this answer














share|improve this answer



share|improve this answer








edited yesterday

























answered Oct 9 '18 at 22:35









alex.forencichalex.forencich

2701210




2701210












  • This script worked for my AMD RX480. Context: PCI passthrough to a Win10 guest, then shutting down or rebooting the guest. Starting the guest again (without using this script) would hang if the GPU was still attached. Running this script in between fixed the issue

    – 小太郎
    Oct 20 '18 at 7:32


















  • This script worked for my AMD RX480. Context: PCI passthrough to a Win10 guest, then shutting down or rebooting the guest. Starting the guest again (without using this script) would hang if the GPU was still attached. Running this script in between fixed the issue

    – 小太郎
    Oct 20 '18 at 7:32

















This script worked for my AMD RX480. Context: PCI passthrough to a Win10 guest, then shutting down or rebooting the guest. Starting the guest again (without using this script) would hang if the GPU was still attached. Running this script in between fixed the issue

– 小太郎
Oct 20 '18 at 7:32






This script worked for my AMD RX480. Context: PCI passthrough to a Win10 guest, then shutting down or rebooting the guest. Starting the guest again (without using this script) would hang if the GPU was still attached. Running this script in between fixed the issue

– 小太郎
Oct 20 '18 at 7:32


















draft saved

draft discarded
















































Thanks for contributing an answer to Unix & Linux Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f73908%2fhow-to-reset-cycle-power-to-a-pcie-device%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







-devices, pci, power-management

Popular posts from this blog

Mobil Contents History Mobil brands Former Mobil brands Lukoil transaction Mobil UK Mobil Australia Mobil New Zealand Mobil Greece Mobil in Japan Mobil in Canada Mobil Egypt See also References External links Navigation menuwww.mobil.com"Mobil Corporation"the original"Our Houston campus""Business & Finance: Socony-Vacuum Corp.""Popular Mechanics""Lubrite Technologies""Exxon Mobil campus 'clearly happening'""Toledo Blade - Google News Archive Search""The Lion and the Moose - How 2 Executives Pulled off the Biggest Merger Ever""ExxonMobil Press Release""Lubricants""Archived copy"the original"Mobil 1™ and Mobil Super™ motor oil and synthetic motor oil - Mobil™ Motor Oils""Mobil Delvac""Mobil Industrial website""The State of Competition in Gasoline Marketing: The Effects of Refiner Operations at Retail""Mobil Travel Guide to become Forbes Travel Guide""Hotel Rankings: Forbes Merges with Mobil"the original"Jamieson oil industry history""Mobil news""Caltex pumps for control""Watchdog blocks Caltex bid""Exxon Mobil sells service station network""Mobil Oil New Zealand Limited is New Zealand's oldest oil company, with predecessor companies having first established a presence in the country in 1896""ExxonMobil subsidiaries have a business history in New Zealand stretching back more than 120 years. We are involved in petroleum refining and distribution and the marketing of fuels, lubricants and chemical products""Archived copy"the original"Exxon Mobil to Sell Its Japanese Arm for $3.9 Billion""Gas station merger will end Esso and Mobil's long run in Japan""Esso moves to affiliate itself with PC Optimum, no longer Aeroplan, in loyalty point switch""Mobil brand of gas stations to launch in Canada after deal for 213 Loblaws-owned locations""Mobil Nears Completion of Rebranding 200 Loblaw Gas Stations""Learn about ExxonMobil's operations in Egypt""Petrol and Diesel Service Stations in Egypt - Mobil"Official websiteExxon Mobil corporate websiteMobil Industrial official websiteeeeeeeeDA04275022275790-40000 0001 0860 5061n82045453134887257134887257

Frič See also Navigation menuinternal link

Identify plant with long narrow paired leaves and reddish stems Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) Announcing the arrival of Valued Associate #679: Cesar Manara Unicorn Meta Zoo #1: Why another podcast?What is this plant with long sharp leaves? Is it a weed?What is this 3ft high, stalky plant, with mid sized narrow leaves?What is this young shrub with opposite ovate, crenate leaves and reddish stems?What is this plant with large broad serrated leaves?Identify this upright branching weed with long leaves and reddish stemsPlease help me identify this bulbous plant with long, broad leaves and white flowersWhat is this small annual with narrow gray/green leaves and rust colored daisy-type flowers?What is this chilli plant?Does anyone know what type of chilli plant this is?Help identify this plant