diff mbox

ath9k_hw: fix channel maximum power level test

Message ID 20170322194240.1488-1-nbd@nbd.name (mailing list archive)
State Changes Requested
Delegated to: Kalle Valo
Headers show

Commit Message

Felix Fietkau March 22, 2017, 7:42 p.m. UTC
The tx power applied by set_txpower is limited by the CTL (conformance
test limit) entries in the EEPROM. These can change based on the user
configured regulatory domain.
Depending on the EEPROM data this can cause the tx power to become too
limited, if the original regdomain CTLs impose lowr limits than the CTLs
of the user configured regdomain.

To fix this issue, set the initial channel limits without any CTL
restrictions and only apply the CTL at run time when setting the channel
and the real tx power.

Cc: stable@vger.kernel.org
Signed-off-by: Felix Fietkau <nbd@nbd.name>
---
 drivers/net/wireless/ath/ath9k/hw.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

Comments

Kalle Valo April 5, 2017, 8:33 a.m. UTC | #1
Felix Fietkau <nbd@nbd.name> wrote:
> The tx power applied by set_txpower is limited by the CTL (conformance
> test limit) entries in the EEPROM. These can change based on the user
> configured regulatory domain.
> Depending on the EEPROM data this can cause the tx power to become too
> limited, if the original regdomain CTLs impose lowr limits than the CTLs
> of the user configured regdomain.
> 
> To fix this issue, set the initial channel limits without any CTL
> restrictions and only apply the CTL at run time when setting the channel
> and the real tx power.
> 
> Cc: stable@vger.kernel.org
> Signed-off-by: Felix Fietkau <nbd@nbd.name>

Failed to apply:

error: patch failed: drivers/net/wireless/ath/ath9k/hw.c:2937
error: drivers/net/wireless/ath/ath9k/hw.c: patch does not apply
stg import: Diff does not apply cleanly

Patch set to Changes Requested.
Weedy April 8, 2017, 5:12 a.m. UTC | #2
On 22 March 2017 at 15:42, Felix Fietkau <nbd@nbd.name> wrote:
> The tx power applied by set_txpower is limited by the CTL (conformance
> test limit) entries in the EEPROM. These can change based on the user
> configured regulatory domain.
> Depending on the EEPROM data this can cause the tx power to become too
> limited, if the original regdomain CTLs impose lowr limits than the CTLs
> of the user configured regdomain.

When merged, should this this fix this annoyance? Or is TP-Link just
shipping junk cal data?

root@LEDE:~# iw phy
Wiphy phy1
...
        Frequencies:
            * 5180 MHz [36] (21.0 dBm)
            * 5200 MHz [40] (21.0 dBm)
            * 5220 MHz [44] (21.0 dBm)
            * 5240 MHz [48] (21.0 dBm)
            * 5260 MHz [52] (21.0 dBm) (radar detection)
            * 5280 MHz [56] (21.0 dBm) (radar detection)
            * 5300 MHz [60] (21.0 dBm) (radar detection)
            * 5320 MHz [64] (21.0 dBm) (radar detection)
            * 5500 MHz [100] (21.0 dBm) (radar detection)
            * 5520 MHz [104] (21.0 dBm) (radar detection)
            * 5540 MHz [108] (21.0 dBm) (radar detection)
            * 5560 MHz [112] (21.0 dBm) (radar detection)
            * 5580 MHz [116] (21.0 dBm) (radar detection)
            * 5600 MHz [120] (disabled)
            * 5620 MHz [124] (disabled)
            * 5640 MHz [128] (disabled)
            * 5660 MHz [132] (21.0 dBm) (radar detection)
            * 5680 MHz [136] (21.0 dBm) (radar detection)
            * 5700 MHz [140] (21.0 dBm) (radar detection)
            * 5745 MHz [149] (21.0 dBm)
            * 5765 MHz [153] (21.0 dBm)
            * 5785 MHz [157] (21.0 dBm)
            * 5805 MHz [161] (21.0 dBm)
            * 5825 MHz [165] (21.0 dBm)
root@LEDE:~# iw reg get
global
country CA: DFS-FCC
    (2402 - 2472 @ 40), (N/A, 30), (N/A)
    (5150 - 5250 @ 80), (N/A, 23), (N/A), AUTO-BW
    (5250 - 5350 @ 80), (N/A, 24), (0 ms), DFS, AUTO-BW
    (5470 - 5600 @ 80), (N/A, 24), (0 ms), DFS
    (5650 - 5730 @ 80), (N/A, 24), (0 ms), DFS
    (5735 - 5835 @ 80), (N/A, 30), (N/A)

phy#1
country US: DFS-FCC
    (2402 - 2472 @ 40), (N/A, 30), (N/A)
    (5170 - 5250 @ 80), (N/A, 23), (N/A), AUTO-BW
    (5250 - 5330 @ 80), (N/A, 23), (0 ms), DFS, AUTO-BW
    (5490 - 5730 @ 160), (N/A, 23), (0 ms), DFS
    (5735 - 5835 @ 80), (N/A, 30), (N/A)
    (57240 - 63720 @ 2160), (N/A, 40), (N/A)

root@LEDE:~# iw phy phy1 set txpower fixed 1500
root@LEDE:~# iwinfo
wlan1     ESSID: nah
          Access Point: still nah
          Mode: Master  Channel: 48 (5.240 GHz)
          Tx-Power: 15 dBm  Link Quality: 44/70
          Signal: -66 dBm  Noise: -90 dBm
          Bit Rate: 147.5 MBit/s
          Encryption: WPA2 PSK (CCMP)
          Type: nl80211  HW Mode(s): 802.11an
          Hardware: 168C:0033 168C:A120 [Atheros AR9580]
          TX power offset: none
          Frequency offset: none
          Supports VAPs: yes  PHY name: phy1

root@LEDE:~# iw phy phy1 set txpower fixed 2000
root@LEDE:~# iwinfo
wlan1     ESSID: nah
          Access Point: still nah
          Mode: Master  Channel: 48 (5.240 GHz)
          Tx-Power: 17 dBm  Link Quality: 45/70
          Signal: -65 dBm  Noise: -90 dBm
          Bit Rate: 177.5 MBit/s
          Encryption: WPA2 PSK (CCMP)
          Type: nl80211  HW Mode(s): 802.11an
          Hardware: 168C:0033 168C:A120 [Atheros AR9580]
          TX power offset: none
          Frequency offset: none
          Supports VAPs: yes  PHY name: phy1
diff mbox

Patch

diff --git a/drivers/net/wireless/ath/ath9k/hw.c b/drivers/net/wireless/ath/ath9k/hw.c
index 17ca60482b5f..3346cbf63b9c 100644
--- a/drivers/net/wireless/ath/ath9k/hw.c
+++ b/drivers/net/wireless/ath/ath9k/hw.c
@@ -2937,10 +2937,14 @@  void ath9k_hw_apply_txpower(struct ath_hw *ah, struct ath9k_channel *chan,
 	struct ieee80211_channel *channel;
 	int chan_pwr, new_pwr, max_gain;
 	int ant_gain, ant_reduction = 0;
+	u16 ctl = NO_CTL;
 
 	if (!chan)
 		return;
 
+	if (!test)
+		ctl = ath9k_regd_get_ctl(reg, chan);
+
 	channel = chan->chan;
 	chan_pwr = min_t(int, channel->max_power * 2, MAX_RATE_POWER);
 	new_pwr = min_t(int, chan_pwr, reg->power_limit);
@@ -2950,9 +2954,7 @@  void ath9k_hw_apply_txpower(struct ath_hw *ah, struct ath9k_channel *chan,
 	if (ant_gain > max_gain)
 		ant_reduction = ant_gain - max_gain;
 
-	ah->eep_ops->set_txpower(ah, chan,
-				 ath9k_regd_get_ctl(reg, chan),
-				 ant_reduction, new_pwr, test);
+	ah->eep_ops->set_txpower(ah, chan, ctl, ant_reduction, new_pwr, test);
 }
 
 void ath9k_hw_set_txpowerlimit(struct ath_hw *ah, u32 limit, bool test)