{"id":132668,"date":"2023-03-24T08:00:00","date_gmt":"2023-03-24T08:00:00","guid":{"rendered":"https:\/\/fedoramagazine.org\/?p=37873"},"modified":"2023-03-24T08:00:00","modified_gmt":"2023-03-24T08:00:00","slug":"use-sysfs-to-restart-failed-pci-devices-wifi-cards-sound-cards-etc","status":"publish","type":"post","link":"https:\/\/sickgaming.net\/blog\/2023\/03\/24\/use-sysfs-to-restart-failed-pci-devices-wifi-cards-sound-cards-etc\/","title":{"rendered":"Use sysfs to restart failed PCI devices (WiFi cards, sound cards, etc.)"},"content":{"rendered":"<p>This article describes one method of restarting PCI devices. It demonstrates restating a wireless device. But the concept should work on any device whose device driver has adequate hotplug support.<sup><a href=\"#references\">[1]<\/a><\/sup><\/p>\n<p> <span id=\"more-37873\"><\/span> <\/p>\n<p>Computers typically consist of several interconnected devices. Some devices can be physically disconnected and reconnected with ease (for example, most USB devices). Others might require a specific interaction with the operating system or specific software. And others will require a full reboot.<\/p>\n<p>Built-in laptop wireless cards are PCI devices that could fail at runtime but might not be easy to physically disconnect and reconnect without a full reboot. In many cases these devices can be restarted through Linux&#8217;s <em>sysfs<\/em> interface without having to do a full reboot of the computer.<\/p>\n<p>This article will specifically demo how to restart an Atheros wireless card which has locked up.<\/p>\n<h2>How to restart PCI devices<\/h2>\n<p>Depending on your particular desktop environment and hardware, it may be possible to switch the PCI card off and back on using a GUI or hardware switch or button. But if none of those options exist or work, the following CLI method of restarting the PCI card might prove useful.<\/p>\n<p>To restart a wireless card you will need its PCI <em>domain<\/em>, <em>bus<\/em>, <em>device<\/em> and <em>function<\/em> address. Run the <em>lspci<\/em> command, as shown below, and search its output to find your wireless card&#8217;s PCI address.<\/p>\n<pre class=\"wp-block-preformatted\">$ lspci\n&lt;snip&gt;\n<strong>3d:00.0<\/strong> Network controller: Qualcomm Atheros QCA6174 802.11ac Wireless Network Adapter (rev 32)<\/pre>\n<p>In the above example, the PCI address of the Atheros card is <strong>3d:00.0<\/strong>. If the address shown does not include a domain part (that is, the number at the start of the line contains only one colon character), then the computer has only one PCI domain and it is <strong>0000<\/strong>.<\/p>\n<p>The following commands, with the capital letters substituted with the device&#8217;s PCI address, can be used to restart a PCI device on a running system.<sup><a href=\"#references\">[2]<\/a><\/sup><\/p>\n<pre class=\"wp-block-preformatted\"># echo \"1\" &gt; \/sys\/bus\/pci\/devices\/DDDD\\:BB\\:DD.F\/remove # sleep 1 # echo \"1\" &gt; \/sys\/bus\/pci\/rescan<\/pre>\n<p>In the above example, the placeholders DDDD, BB, DD, and F are for the PCI device domain, bus, device, and function respectively.<\/p>\n<p>Substituting the values from the example output of the <em>lspci<\/em> command shown above gives the command that would need to be run to restart the Atheros wireless card on this example system.<\/p>\n<pre class=\"wp-block-preformatted\">$ sudo \/bin\/sh -c \"echo '1' &gt; \/sys\/bus\/pci\/devices\/0000\\:3d\\:00.0\/remove\"\n$ sleep 1\n$ sudo \/bin\/sh -c \"echo '1' &gt; \/sys\/bus\/pci\/rescan\"<\/pre>\n<p>If required, the above commands could be automated by putting them in a script.<\/p>\n<pre class=\"wp-block-preformatted\">$ nano restart-wireless-card.sh\n#!\/bin\/bash\necho \"1\" &gt; \/sys\/bus\/pci\/devices\/0000\\:3d\\:00.0\/remove sleep 1 echo \"1\" &gt; \/sys\/bus\/pci\/rescan<\/pre>\n<p>Enable executable permissions with, for example, <em>chmod +x restart-wireless-card.sh<\/em> and run <em>sudo .\/restart-wireless-card.sh<\/em> whenever you need to restart your PCI device.<\/p>\n<h2>Final notes<\/h2>\n<p>Not all PCI devices can be restarted using this method. But the real-life example demonstrated above does work to get the WiFi card running again without requiring a full reboot of the PC.<\/p>\n<h2 id=\"references\">References<\/h2>\n<ol>\n<li><a href=\"https:\/\/electronics.stackexchange.com\/a\/208796\" target=\"_blank\" rel=\"noreferrer noopener\">stackexchange.com: Does PCIe hotplug actually work in practice?<\/a><\/li>\n<li><a href=\"https:\/\/unix.stackexchange.com\/questions\/73908\/how-to-reset-cycle-power-to-a-pcie-device\/245184#245184\" target=\"_blank\" rel=\"noreferrer noopener\">stackexchange.com: How to Reset\/Cycle Power to a PCIe Device?<\/a><\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>This article describes one method of restarting PCI devices. It demonstrates restating a wireless device. But the concept should work on any device whose device driver has adequate hotplug support.[1] Computers typically consist of several interconnected devices. Some devices can be physically disconnected and reconnected with ease (for example, most USB devices). Others might require [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[48],"tags":[606,45,1453,46,47,1454,1455,1456,1457,1458],"class_list":["post-132668","post","type-post","status-publish","format-standard","hentry","category-fedora-os","tag-faqs-and-guides","tag-fedora","tag-lspci","tag-magazine","tag-news","tag-pci","tag-pci-address","tag-pci-device","tag-pci-slot","tag-sysfs"],"_links":{"self":[{"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/posts\/132668","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/comments?post=132668"}],"version-history":[{"count":0,"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/posts\/132668\/revisions"}],"wp:attachment":[{"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/media?parent=132668"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/categories?post=132668"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/tags?post=132668"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}