This site is now 100% read-only, and retired.

XML logo

wireless hardware switches (pciehp is your friend)
Posted by dkg on Thu 16 Oct 2008 at 17:43
Tags: ,
I've been playing around with an eeePC 900, which is very well-supported by debian. Kudos to the eeepc team!

I had one problem with it, after upgrading eeepc-acpi-scripts from version 1.0.4 to 1.0.9: with 1.0.4, i was able to use an ACPI hotkey to disable and re-enable the wireless. With 1.0.9, the device did not come back up for me after a toggle. The problem was resolved for me with:

echo pciehp >> /etc/modules
which i figured out from reading a brief post on the very-informative debian-eeepc-devel mailing list. The rest of this post explores why that was the answer for me.

Enabling/disabling wireless is done from a done by unloading/reloading the kernel modules, and flipping the hardware wireless switch:

## disabling:
modprobe -v -r ath_pci
echo -n 0 > /sys/devices/platform/eeepc/wlan
## enabling:
echo -n 1 > /sys/devices/platform/eeepc/wlan
modprobe -v ath_pci
The hardware switch niftiness is supported by the eeepc_laptop.ko kernel module, which is obviously specific to this device. Your own laptop might have some other method for triggering a hardware-level detachment or power-disabling of an internal device.

There are several advantages of doing a hardware-level device detachment, as opposed to just unloading the drivers:

  • If the hardware is implemented right, this is an actual full isolation of the device -- no power is drained, and it disappears entirely from the output of lspci. Just unloading the module leaves the device drawing a bit of power from the bus it's connected to (it would be good to try to measure that difference in power)
  • Unloading the modules without detaching the device also leaves open the possibility for any system utility to notice it and re-load the module, or to manipulate the device in other ways through the attached bus.
  • Often, hardware-disabling switches are bound to some external indicator on the machine (an LED, for example), which makes it easy to tell externally when a device is actually powered up.

However, there are also disadvantages with a hardware detachment: in particular, the drivers (for both the device and the hosted bus) need to be aware of the possibility for the device to disappear. You can handle dubious drivers for the device by simply unloading the modules from the kernel before unplugging and re-loading them afterwards (although this won't work if you have more than one device handled by the same module and you aren't detaching all of them). And you'll also need to handle drivers for the bus, to make sure that it knows that devices can disappear and re-appear. This is standard for drivers for some buses (like USB), which were designed pretty much from the ground up for device insertion and removal.

But PCI (of any flavor) isn't quite the same, because you never used to be able to remove or add PCI devices while the system was on. This is where pciehp comes in. This is a PCI Express hotplug module. Apparently, the wireless device in the eeepc 900 is connected via the PCI Express bus. Ensuring that the pciehp module is loaded at boot time (which is what adding the line to /etc/modules does) guarantees that the PCI subsystem in the kernel knows how to handle device insertion and removal cleanly.

Without pciehp loaded, the PCI Express bus would get into a bad state (up to and including kernel oopses) if i used the wireless switch to detach and re-attach the device. The reason it had worked with earlier versions of eeepc-acpi-scripts was that those versions were force-unloading (and force-reloading) pciehp before sending the "1" to the hardware switch. I'm not entirely sure why the current arrangement is better, though it is certainly faster at runtime to not have to wait for the module re-load. It's probably also good to not have a window in which pciehp itself is not loaded.

Note: a similar problem appears to affect ubuntu.


Comments on this Entry

Re: wireless hardware switches (pciehp is your friend)
Posted by mcortese (213.70.xx.xx) on Fri 17 Oct 2008 at 17:42
[ View Weblogs ]

I wish my Dell had a similar switch to turn on/off the wifi card!

[ Parent ]