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: ,

6 Comments:

  • Just a mistake that took me some time to resolve: rename the resume.d and suspend.d scripts so that they end in .sh. Otherwise, the acpi script will just ignore them.

    Anyways, my wifi does not resume properly every time. I have to switch it off and back again using the sleep wifi key. and sometimes, if I switch it using the key, then it doesn't come back. So, it is quite unstable.

    Did you have those problems? Did you observe improvements with the new asus_acpi module?

    By Blogger Benoit, at 11:39 PM  

  • Wifi doesn't reliably come back after suspend, it's true. I have to toggle it with the wifi button.

    It comes back reliably when I do this, though.

    No functional changes in the new source modules, except that I can port them to 2.6.22 (though I'll lose wifi).

    By Blogger Cliff L. Biffle, at 12:12 PM  

  • Hello,
    As far as I know I have the asus drivers installed under Debian "lenny", but the directory /proc/acpi/asus/ doesn't exist. Do you have any ideas?

    Also, I have a blog with several eee-related articles if you are interested. So far only related to the default Xandros, but I'm eager to get Debian up and running and start posting more tutorials.

    Thanks for the great tutorials!

    -Elijah
    http://ewolf.wordpress.com/

    By Blogger c wolf, at 12:48 PM  

  • Hmm interesting. This script works every single time except the first time you turn off the wifi after rebooting.

    By Blogger Parker, at 7:27 PM  

  • I was very pleased to find this site. I wanted to thank you for this great read!! I definitely enjoying every little bit of it and I have you bookmarked to check out new stuff you post.thai girls

    By Blogger chinese girl, at 10:30 PM  

  • I have read your blog its very attractive and impressive. I like it your blog.

    Java Online Training Java EE Online Training Java EE Online Training Java 8 online training Core Java 8 online training

    Java Online Training from India Java Online Training from India Core Java Training Online Core Java Training Online Java Training InstitutesJava Training Institutes

    By Blogger Naviya Nair, at 9:28 PM  

Post a Comment

<< Home