Cliff Hacks Things.

Sunday, November 25, 2007

eeebuntu tip: unloading/reloading the wifi drivers

The eee's wifi does not survive a suspend: the hardware and drivers get into different states, and things quit working. The wifi control scripts in ASUS's Linux distribution hold the key.

There's a particular sequence of rmmod/insmod calls that will force the system to rediscover the wifi, and (for me at least) fixes all the various b0rked states it can get into. I call it the "Magic Wifi Dance," because it's a ritual that I don't completely understand.

My control script is below. You'll need the Atheros drivers and the ASUS ACPI module.


#!/bin/sh

# The sequence here *may* be important.
# (It seems to fail intermittently if you deviate.)
unload_modules() {
rmmod wlan_scan_sta
rmmod wlan_tkip
rmmod wlan_wep
rmmod wlan_ccmp
rmmod wlan_acl
rmmod ath_pci
sleep 1
rmmod ath_rate_atheros
rmmod ath_hal
rmmod wlan
rmmod ath_dfs
}

# At least this one's straightforward.
load_modules() {
modprobe ath_pci
}

wifi_on() {
# Force PCI Express Hotplug to reinit
rmmod pciehp
sleep 1
# pciehp_force may be unnecessary; Xandros did it.
modprobe pciehp pciehp_force=1
sleep 1
# Switch on the hardware
echo 1 >/proc/acpi/asus/wlan
sleep 1
load_modules
}

wifi_off() {
unload_modules
echo 0 >/proc/acpi/asus/wlan
}

case $1 in
on)
wifi_on
;;
off)
wifi_off
;;
toggle)
STAT=`cat /proc/acpi/asus/wlan`
if [ "$STAT" = "1" ];
then wifi_off;
else wifi_on;
fi
;;
esac


When executed on an "eeebuntu" machine with ASUS's binary modules, that script should be capable of shutting down and bringing up the Atheros wifi card. The on and off arguments do what their names imply; the toggle argument checks the card's status in proc and responds appropriately. (I use toggle to make the keyboard's wifi key work, which I'll demonstrate in my upcoming post on ACPI events.)

For those playing along at home, this resulting control script is a good one to call from /etc/acpi/suspend.d and /etc/acpi/resume.d, with off and on arguments, respectively. (Just make sure it's called after the interfaces are shut down on suspend, and before they're brought up on resume. On default Ubuntu, calling the suspend script "56-eee-wifi-off" and the resume script "60-eee-wifi-on" gets the order right.)

Labels: ,

106 Comments:

Post a Comment

<< Home