Resetting a PCIe Wireless Adapter

(Maybe) Reset a PCIe wireless adapter on Linux without a reboot
by

Sometimes the ath11k PCIe wireless adapter in my Thinkpad X13s breaks. I don't know why. The easiest fix is rebooting but that isn't very convenient.

Here's a workaround which is more general and should work for any PCIe wireless card that can be reset by removing and probing the device.

#!/usr/bin/env bash
set -xeu
# Find wifi remove file
remove="$(echo /sys/class/net/wl*/device/remove)"
# Remove the wireless adapter, log if can't, keep going anyway in case rescanning works
echo 1 > "$remove" || >&2 echo "$0 can't write to $remove. Wifi card not found or not running as root"
# Wait a bit
sleep 4
# Rescan PCI bus
echo 1 > /sys/bus/pci/rescan
# Restart networking services (in my case various things with NetworkManager in the name)
systemctl restart '*etwork*.service'
systemctl status '*etwork*.service'

Cite as BibTeX
@misc{reset-pcie-wireless-adapter,
    author = {Luna Nova},
    title = {Resetting a PCIe Wireless Adapter},
    year = {2023},
    url = {https://lunnova.dev/articles/reset-pcie-wireless-adapter/},
    howpublished = {https://lunnova.dev/articles/reset-pcie-wireless-adapter/},
    urldate = {2023-11-27},
    note = {lunnova.dev - (Maybe) Reset a PCIe wireless adapter on Linux without a reboot}
}

tagged linux