Bug 14642

Summary: ath9k txpower configuration only takes effect after scan
Product: Drivers Reporter: Javier Cardona (javier)
Component: network-wirelessAssignee: Luis Chamberlain (mcgrof)
Status: CLOSED CODE_FIX    
Severity: low CC: ath9k-devel, linville, mcgrof, nenad, sujith, vkthiagu
Priority: P1    
Hardware: All   
OS: Linux   
Kernel Version: 2.6.32-rc7-wl Subsystem:
Regression: No Bisected commit-id:
Attachments: Force tx power change to take effect

Description Javier Cardona 2009-11-19 19:20:59 UTC
Changing the transmission power while the interface is up and associated has no effect.  The following sequence of commands will not affect the output power (verified with a sniffer):

# iwconfig wlan0 txpower 20dbm
# iwconfig wlan0
wlan0     IEEE 802.11abgn  ESSID:"cozyguest"
         Mode:Managed  Frequency:2.462 GHz  Access Point: 00:13:10:XX:XX:XX
         Bit Rate=54 Mb/s   Tx-Power=20 dBm
         ...

# iwconfig wlan0 txpower 0dbm
# iwconfig wlan0
wlan0     IEEE 802.11abgn  ESSID:"cozyguest"
         Mode:Managed  Frequency:2.462 GHz  Access Point: 00:13:10:XX:XX:XX
         Bit Rate=54 Mb/s   Tx-Power=0 dBm
         ...

The changes will take effect if the interface is brought down and up or if a scan is issued.  

Some notes that may be useful to fix this:

After mac80211 sets IEEE80211_CONF_CHANGE_POWER the driver updates
sc->config.txpowlimit.  The new value is sent to the card by
ath_update_txpow() which is only called by:

  1    364  drivers/net/wireless/ath/ath9k/main.c <<ath_set_channel>>
            ath_update_txpow(sc);
  2   1230  drivers/net/wireless/ath/ath9k/main.c <<ath_radio_enable>>
            ath_update_txpow(sc);
  3   2021  drivers/net/wireless/ath/ath9k/main.c <<ath_reset>>
            ath_update_txpow(sc);
  4   2330  drivers/net/wireless/ath/ath9k/main.c <<ath9k_start>>
            ath_update_txpow(sc);

The new power settings only take effect if one triggers one of these
functions, for instance by issuing a scan.

Don't have a fix at this time.  The obvious fix did not solve the problem:

diff --git a/drivers/net/wireless/ath/ath9k/main.c
b/drivers/net/wireless/ath/ath9k/main.c
index 16bdb1b..b62012e 100644
--- a/drivers/net/wireless/ath/ath9k/main.c
+++ b/drivers/net/wireless/ath/ath9k/main.c
@@ -2795,8 +2795,10 @@ static int ath9k_config(struct ieee80211_hw
*hw, u32 changed)
       }

 skip_chan_change:
-       if (changed & IEEE80211_CONF_CHANGE_POWER)
+       if (changed & IEEE80211_CONF_CHANGE_POWER) {
               sc->config.txpowlimit = 2 * conf->power_level;
+               ath_update_txpow(sc);
+       }

       spin_lock_bh(&sc->wiphy_lock);
       disable_radio = ath9k_all_wiphys_idle(sc);

But issuing a scan after changing the power did:

# iwconfig wlan0 txpower 10dbm; iw dev wlan0 scan

( Scanning seems to be the magic word that one must invoke to get
things done on ath9k: See also bug 14187 )
Comment 1 Luis Chamberlain 2009-12-01 07:52:49 UTC
Created attachment 23981 [details]
Force tx power change to take effect

Can you please test this patch. It is based on wireless-testing, not sure if it'll apply to 2.6.32-rcx, so may want to try either with bleeding edge compat-wireless or with wireless-testing directly.
Comment 2 Luis Chamberlain 2009-12-16 18:56:11 UTC
So .. any update on tests with the patch?
Comment 3 Luis Chamberlain 2010-01-19 19:05:24 UTC
This was tested by another users, going to close this as I just submitted the patch.