]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
ath9k: Differentiate between max combined and per chain power
authorSven Eckelmann <sven@narfation.org>
Wed, 20 Mar 2019 10:37:23 +0000 (11:37 +0100)
committerKalle Valo <kvalo@codeaurora.org>
Mon, 29 Apr 2019 14:53:43 +0000 (17:53 +0300)
The ath9k driver uses as maximum allowed txpower the constant
MAX_RATE_POWER. It is used to set a maximum txpower limit for the PHY
(which is combined txpower) and also the maximum txpower for per chain
rates. Its value 63 is derived from the maximum number the registers can
store for the per chain txpower.

The max txpower a user can set because of this is 31 dBm (floor(63 / 2)).
This also means that a device with multiple tx chains is even limited
further:

* 1 chain:  31 dBm per chain
* 2 chains: 28 dBm per chain
* 3 chains: 26 dBm per chain

This combined txpower limit of 31 dBm becomes even more problematic when
some extra antenna gain is set in the EEPROM. A high power device is then
no longer able to reach its potential limits.

Instead the code dealing with the combined txpower must use a higher limit
than 63 and only the code dealing with the per chain txpower have to use
the limit of 63. Since the antenna gain can be quite large and 8 bit
variables are often used in ath9k for txpower, a large, divisible by two
number like 254 is a good choice for this new limit.

Signed-off-by: Sven Eckelmann <sven@narfation.org>
Signed-off-by: Kalle Valo <kvalo@codeaurora.org>
drivers/net/wireless/ath/ath9k/eeprom.c
drivers/net/wireless/ath/ath9k/eeprom_4k.c
drivers/net/wireless/ath/ath9k/hw.c
drivers/net/wireless/ath/ath9k/hw.h
drivers/net/wireless/ath/ath9k/init.c

index 6fbd5559c0c09a79c2e6bdbba4dbdfe0976269f9..c22d457dbc54183f6006e970e284106f82eb8fef 100644 (file)
@@ -428,7 +428,7 @@ u16 ath9k_hw_get_scaled_power(struct ath_hw *ah, u16 power_limit,
        else
                power_limit = 0;
 
-       return power_limit;
+       return min_t(u16, power_limit, MAX_RATE_POWER);
 }
 
 void ath9k_hw_update_regulatory_maxpower(struct ath_hw *ah)
index b8c0a08066a010c22e4031f0254dde0f66749824..e8c2cc03be0cbef3822b7c04d9bbf81bc5f32d23 100644 (file)
@@ -424,6 +424,7 @@ static void ath9k_hw_set_4k_power_per_rate_table(struct ath_hw *ah,
        ath9k_hw_get_channel_centers(ah, chan, &centers);
 
        scaledPower = powerLimit - antenna_reduction;
+       scaledPower = min_t(u16, scaledPower, MAX_RATE_POWER);
        numCtlModes = ARRAY_SIZE(ctlModesFor11g) - SUB_NUM_CTL_MODES_AT_2G_40;
        pCtlMode = ctlModesFor11g;
 
index b6773d613f0cacffcca5773f7e7bcb3b9a31eb80..052deffb4c9d43533c026c1033ca9035c20b6bf2 100644 (file)
@@ -457,7 +457,7 @@ static void ath9k_hw_init_defaults(struct ath_hw *ah)
        struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
 
        regulatory->country_code = CTRY_DEFAULT;
-       regulatory->power_limit = MAX_RATE_POWER;
+       regulatory->power_limit = MAX_COMBINED_POWER;
 
        ah->hw_version.magic = AR5416_MAGIC;
        ah->hw_version.subvendorid = 0;
@@ -2966,7 +2966,7 @@ void ath9k_hw_apply_txpower(struct ath_hw *ah, struct ath9k_channel *chan,
                ctl = ath9k_regd_get_ctl(reg, chan);
 
        channel = chan->chan;
-       chan_pwr = min_t(int, channel->max_power * 2, MAX_RATE_POWER);
+       chan_pwr = min_t(int, channel->max_power * 2, MAX_COMBINED_POWER);
        new_pwr = min_t(int, chan_pwr, reg->power_limit);
 
        ah->eep_ops->set_txpower(ah, chan, ctl,
@@ -2979,9 +2979,9 @@ void ath9k_hw_set_txpowerlimit(struct ath_hw *ah, u32 limit, bool test)
        struct ath9k_channel *chan = ah->curchan;
        struct ieee80211_channel *channel = chan->chan;
 
-       reg->power_limit = min_t(u32, limit, MAX_RATE_POWER);
+       reg->power_limit = min_t(u32, limit, MAX_COMBINED_POWER);
        if (test)
-               channel->max_power = MAX_RATE_POWER / 2;
+               channel->max_power = MAX_COMBINED_POWER / 2;
 
        ath9k_hw_apply_txpower(ah, chan, test);
 
index 68956cdc8c9ae21c0d974466ced9c57b85294ce9..2e4489700a859722b2c54d817a91d8aea4040bcb 100644 (file)
 #define ATH9K_NUM_QUEUES            10
 
 #define MAX_RATE_POWER              63
+#define MAX_COMBINED_POWER          254 /* 128 dBm, chosen to fit in u8 */
 #define AH_WAIT_TIMEOUT             100000 /* (us) */
 #define AH_TSF_WRITE_TIMEOUT        100    /* (us) */
 #define AH_TIME_QUANTUM             10
index 98141b699c883cf327ca477cc087ae71297dbb27..043801f773b5970cfa1d50b90a3857dc60488e5c 100644 (file)
@@ -805,7 +805,7 @@ static void ath9k_init_band_txpower(struct ath_softc *sc, int band)
                ah->curchan = &ah->channels[chan->hw_value];
                cfg80211_chandef_create(&chandef, chan, NL80211_CHAN_HT20);
                ath9k_cmn_get_channel(sc->hw, ah, &chandef);
-               ath9k_hw_set_txpowerlimit(ah, MAX_RATE_POWER, true);
+               ath9k_hw_set_txpowerlimit(ah, MAX_COMBINED_POWER, true);
        }
 }