Linux on the Dell XPS: Fixing AX201 Wi-Fi performance
Tags: linux
Published: 2022-04-06 11:03:39

I am very happy with Linux on my Dell XPS 13 9310. I use the latest version of Fedora (35 at the time of this writing, soon to be upgraded to 36).

However, the Wi-Fi connection gave me great difficulty for months before I learned that performance is much better with the power saving functionality turned off. With power saving on, I would often lose packets right and left. This was a typical ping session:

```
[bowmanjd@lappy386 ~]$ ping 192.168.0.1
PING 192.168.0.1 (192.168.0.1) 56(84) bytes of data.
64 bytes from 192.168.0.1: icmp_seq=3 ttl=64 time=223 ms
64 bytes from 192.168.0.1: icmp_seq=4 ttl=64 time=1.15 ms
64 bytes from 192.168.0.1: icmp_seq=5 ttl=64 time=15.3 ms
64 bytes from 192.168.0.1: icmp_seq=6 ttl=64 time=1.56 ms
^C
--- 192.168.0.1 ping statistics ---
6 packets transmitted, 4 received, 33.3333% packet loss, time 5075ms
rtt min/avg/max/mdev = 1.147/60.182/222.714/94.010 ms
```

Note the first two dropped packets. Sometimes more, sometimes less. At first, I blamed our wireless access point, yet no other client device had this problem. Finally, I booted into Windows on the XPS and noticed much better wireless performance. Clearly, this is a driver issue of some sort.

There may be a variety of solutions for this, and I suspect this will one day be fixed in the kernel, but here is how I solved it for now.

## The NetworkManager solution

For Linux distros using NetworkManager, add a new configuration file to the `/etc/NetworkManager/conf.d/` directory. Name it something like `disable_power_save.conf` with the contents:

```ini
[connection]
wifi.powersave = 2
```

Elevate to root first using `sudo` or similar.

One command can do it all:

```bash
printf "[connection]\nwifi.powersave = 2\n" | sudo tee /etc/NetworkManager/conf.d/disable_power_save.conf
```

Then restart NetworkManager with:

```bash
sudo systemctl restart NetworkManager
```

Test the performance with ping, and there should be a marked improvement.


## wifi.powersave config options

NetworkManager has several configurable options for wireless adapter settings, including `powersave`. You can [read about them in the API documentation](https://networkmanager.dev/docs/api/latest/settings-802-11-wireless.html). There, we discover the following `powersave` options:

- NM_SETTING_WIRELESS_POWERSAVE_DEFAULT (0) (use the globally configured value). 
- NM_SETTING_WIRELESS_POWERSAVE_IGNORE (1) (don't touch currently configured setting)
- NM_SETTING_WIRELESS_POWERSAVE_DISABLE (2) (disable Wi-Fi power saving)
- NM_SETTING_WIRELESS_POWERSAVE_ENABLE (3) (enable Wi-Fi power saving)

In this case, I want to disable Wi-Fi power saving, thus the value of 2 in the config file, set with 

```ini
[connection]
wifi.powersave = 2
```

## Detecting and setting the power-save setting on the wireless card

With or without NetworkManager, the power save setting of the AX201 and other Wi-Fi cards can be read with the `iw` command.

First, find the name of your wireless adapter with `iw dev` or to get just the name:

```
iw dev | grep -o 'Interface.*'
```

The wireless adapter likely starts with "wl". Mine is `wlp0s20f3`, so the following works to get the current powersave setting:

```
iw dev wlp0s20f3 get power_save
```

If you have already made the NetworkManager config changes and restarted NetworkManager, then the result should be `Power save: off`.

A similar command can be used to turn power_save back on:

```
iw dev wlp0s20f3 set power_save on
```


## Awaiting other solutions...

Of course, I hope that a driver solution comes soon with new kernel releases. Likely the above solution will not be necessary long term. If you have encountered other ways to solve this problem, please feel free to use the comments!

## Other resources

- [Jean-Christophe Berthon's gist](https://gist.github.com/jcberthon/ea8cfe278998968ba7c5a95344bc8b55) with NetworkManager scripts and notes
- [javamarket's comments in this archlinux forum topic](https://bbs.archlinux.org/viewtopic.php?pid=1690406#p1690406)