Reload failed wifi module without rebooting system

We have a laptop with intel wifi onboard which sometimes failed due to overheating, or due to long-term uptime, or channel load / pps, or whatever.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
[2250886.567817] ieee80211 phy0: Hardware restart was requested
[2250886.602451] iwlwifi 0000:24:00.0: Radio type=0x1-0x2-0x0
[2250886.899471] iwlwifi 0000:24:00.0: Radio type=0x1-0x2-0x0
[2250887.042217] iwlwifi 0000:24:00.0: Microcode SW error detected.  Restarting 0x2000000.
[2250887.042225] iwlwifi 0000:24:00.0: Loaded firmware version: 18.168.6.1 6000g2a-6.ucode
[2250887.042348] iwlwifi 0000:24:00.0: Start IWL Error Log Dump:
[2250887.042349] iwlwifi 0000:24:00.0: Status: 0x0000004C, count: 6
[2250887.042482] iwlwifi 0000:24:00.0: Start IWL Event Log Dump: nothing in log
[2250887.042486] iwlwifi 0000:24:00.0: BUG_ON, Stop restarting
[2250887.128058] iwlwifi 0000:24:00.0: Command REPLY_ADD_STA failed: FW Error
[2250887.128063] wlan0: failed to remove key (0, 01:11:88:ab:2c:99) from hardware (-5)
[2250887.128112] iwlwifi 0000:24:00.0: iwl_trans_wait_tx_queues_empty bad state = 0
[2250887.128132] iwlwifi 0000:24:00.0: Command REPLY_ADD_STA failed: FW Error
[2250887.128133] wlan0: failed to remove key (1, ff:ff:ff:ff:ff:ff) from hardware (-5)
[2250887.228460] iwlwifi 0000:24:00.0: Request scan called when driver not ready.
[2250902.567848] iwlwifi 0000:24:00.0: Command REPLY_RXON failed: FW Error
[2250902.567857] iwlwifi 0000:24:00.0: Error clearing ASSOC_MSK on BSS (-5)
[2250902.587425] iwlwifi 0000:24:00.0: Radio type=0x1-0x2-0x0
[2250902.637530] iwlwifi 0000:24:00.0: Command COEX_PRIORITY_TABLE_CMD failed: FW Error
[2250902.637535] iwlwifi 0000:24:00.0: Could not complete ALIVE transition: -5
[2250902.649786] iwlwifi 0000:24:00.0: Failed to run INIT ucode: -5
[2250902.649819] iwlwifi 0000:24:00.0: Unable to initialize device.
[2250960.530138] iwlwifi 0000:24:00.0: Radio type=0x1-0x2-0x0
[2250960.665000] iwlwifi 0000:24:00.0: Unable to initialize device.


Basic or simple option just reboot system. But when (always) you have million open windows and million shell tabs with runned scripts over mounted partitions, it’s not a vary good option.

The option is simpler and more convenient - fix it without rebooting


Shutdown wifi nmcli radio wifi off or ip link set wlan0 down
Shutdown software rfkill block 12, rfkill list

1
2
3
4
5
6
11: hci0: Bluetooth
        Soft blocked: no
        Hard blocked: no
12: phy1: Wireless LAN      # <--
        Soft blocked: yes
        Hard blocked: no


Shutdown wifi physically by switching keyboard shortcut or special switch.
Unload kernel modules

1
2
3
modprobe -r iwldvm
modprobe -r iwlwifi
modprobe -r mac80211


Let’s turn everything back on

1
2
3
modprobe mac80211
modprobe iwlwifi
modprobe iwldvm

Again switch hardware wifi on.
Then rfkill list

1
2
3
4
5
6
11: hci0: Bluetooth
        Soft blocked: no
        Hard blocked: no
13: phy2: Wireless LAN      # <-- different
        Soft blocked: yes
        Hard blocked: no


After reload, HW has a new number rfkill unblock 13 and nmcli radio wifi on

Everything works

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
[2251004.921146] iwlwifi 0000:24:00.0: RF_KILL bit toggled to disable radio.
[2251004.921150] iwlwifi 0000:24:00.0: reporting RF_KILL (radio disabled)
[2251049.592289] Intel(R) Wireless WiFi driver for Linux
[2251049.592470] iwlwifi 0000:24:00.0: can't disable ASPM; OS doesn't have ASPM control
[2251049.597155] iwlwifi 0000:24:00.0: firmware: direct-loading firmware iwlwifi-6000g2a-6.ucode
[2251049.597317] iwlwifi 0000:24:00.0: loaded firmware version 18.168.6.1 6000g2a-6.ucode op_mode iwldvm
[2251049.613518] iwlwifi 0000:24:00.0: CONFIG_IWLWIFI_DEBUG disabled
[2251049.613521] iwlwifi 0000:24:00.0: CONFIG_IWLWIFI_DEBUGFS disabled
[2251049.613523] iwlwifi 0000:24:00.0: CONFIG_IWLWIFI_DEVICE_TRACING disabled
[2251049.613524] iwlwifi 0000:24:00.0: Detected Intel(R) Centrino(R) Advanced-N 6205 AGN, REV=0xB0
[2251049.619916] iwlwifi 0000:24:00.0: reporting RF_KILL (radio disabled)
[2251049.620010] iwlwifi 0000:24:00.0: RF_KILL bit toggled to disable radio.
[2251049.698095] ieee80211 phy1: Selected rate control algorithm 'iwl-agn-rs'
[2251062.371832] iwlwifi 0000:24:00.0: RF_KILL bit toggled to enable radio.
[2251062.371841] iwlwifi 0000:24:00.0: reporting RF_KILL (radio enabled)
[2251068.512369] iwlwifi 0000:24:00.0: Radio type=0x1-0x2-0x0
[2251068.804557] iwlwifi 0000:24:00.0: Radio type=0x1-0x2-0x0
[2251072.216384] iwlwifi 0000:24:00.0: Radio type=0x1-0x2-0x0
[2251072.509380] iwlwifi 0000:24:00.0: Radio type=0x1-0x2-0x0
[2251072.669973] wlan0: authenticate with 11:99:ea:25:b1:81
[2251072.673358] wlan0: send auth to 11:99:ea:25:b1:81 (try 1/3)
[2251072.717340] wlan0: authenticated
[2251072.717901] wlan0: waiting for beacon from 11:99:ea:25:b1:81
[2251072.805721] wlan0: associate with 11:99:ea:25:b1:81 (try 1/3)
[2251072.814607] wlan0: RX AssocResp from 11:99:ea:25:b1:81 (capab=0x1431 status=0 aid=2)
[2251072.835773] wlan0: associated
[2251072.910180] IPv6: ADDRCONF(NETDEV_CHANGE): wlan0: link becomes ready