RT2870 under (K)Ubuntu Natty (11.04)

The new version of (K)Ubuntu, Natty (11.04), is shipped with the new Kernel 2.6.38 but still with the old wireless driver for the RT2870. If one does not want low speed on data transfers, the driver for the RT2870 has to be compiled manually, but that does not work without compilation errors. To solve this issue follow the steps for the previous version Maverick, which I described in my article „RT2870 compile error under (K)Ubuntu Maverick (10.10)“.

Recompile all kernel modules using DKMS

With the Dynamic Kernel Module Support (DKMS) framework compiling modules is very comfortable. However, one major drawback is the lack of rebuilding all modules at once. One has to specify each module, each version and each kernel. The following lines let you recompile all modules for the current kernel:

for mod in `dkms status | cut -d, -f1 | uniq`;
do for ver in `dkms status | cut -d, -f2 | uniq`;
do dkms remove -m $mod -v $ver -k `uname -r` && dkms build -m $mod -v $ver -k `uname -r` && dkms install -m $mod -v $ver -k `uname -r`;

RT2870 compile error under (K)Ubuntu Maverick (10.10)

Yesterday the next version of Ubuntu was released. It comes with kernel 2.6.35 which can make problems if you want to compile the RT2870 driver provided by Ralink. The reason for me to compile the driver rather than using the one shipped with the kernel is that the latter reduces my WLAN speed from 130 MBit/s to 54 MBit/s.

If you start compiling the Ralink driver you will soon get the following error message:

CC [M]  2010_0709_RT2870_Linux_STA_v2.4.0.1/os/linux/../../common/cmm_mac_usb.o
2010_0709_RT2870_Linux_STA_v2.4.0.1/os/linux/../../common/cmm_mac_usb.c: In function ‘RTMPAllocUsbBulkBufStruct’:
2010_0709_RT2870_Linux_STA_v2.4.0.1/os/linux/../../common/cmm_mac_usb.c:52: error: implicit declaration of function ‘usb_buffer_alloc’
2010_0709_RT2870_Linux_STA_v2.4.0.1/os/linux/../../common/cmm_mac_usb.c:52: warning: assignment makes pointer from integer without a cast
2010_0709_RT2870_Linux_STA_v2.4.0.1/os/linux/../../common/cmm_mac_usb.c: In function ‘RTMPFreeUsbBulkBufStruct’:
2010_0709_RT2870_Linux_STA_v2.4.0.1/os/linux/../../common/cmm_mac_usb.c:78: error: implicit declaration of function ‘usb_buffer_free’
2010_0709_RT2870_Linux_STA_v2.4.0.1/os/linux/../../common/cmm_mac_usb.c: In function ‘RTMPFreeTxRxRingMemory’:
make[2]: *** [2010_0709_RT2870_Linux_STA_v2.4.0.1/os/linux/../../common/cmm_mac_usb.o] Error 1
make[1]: *** [_module_2010_0709_RT2870_Linux_STA_v2.4.0.1/os/linux] Error 2
make[1]: Leaving directory '/usr/src/linux-headers-2.6.35-22-generic'
make: *** [LINUX] Error 2

The cause for these errors is that the driver makes use of the functions usb_buffer_alloc() and usb_buffer_free() which got renamed in kernel 2.6.35. This is stated in the Changelog:

    USB: rename usb_buffer_alloc() and usb_buffer_free() users

    For more clearance what the functions actually do,

      usb_buffer_alloc() is renamed to usb_alloc_coherent()
      usb_buffer_free()  is renamed to usb_free_coherent()

So to get rid of the error messages all you have to do is to rename the function in include/os/rt_linux.h. To make it easier you can download a patch here. Just run the following command in the driver directory:

patch -ul -p0 -i path/to/patch

Or use the one-liner:

wget -qO- http://www.linuxcrew.de/wp-content/uploads/2010/10/rt2870sta_usb_kernel2635.patch | patch -ul -p0

After patching you can compile the driver without errors again.