wifi: mt76: fix returned txpower for mt7921 and mt7925
Subsystems (2)
v2 cover wifi: mt76: fix returned txpower for mt7921 and mt7925
When reading the txpower with iw dev wlan1 the returned value is always 3.00 dBm, no matter what reg domain is set or if one changes the txpower manually.
This bug was discovered by me and confirmed by many people using this chipset on openwrt: https://github.com/openwrt/mt76/issues/783
I tracked the code for this and it seems that for those 2 chipsets particularly, the mt76_phy->txpower_cur is never set, in contrast to other chipsets like mt7603, mt7615, mt76x0, mt7915, etc.
Added some debug logs in the mt76_get_txpower function and I got:
[ 26.816227] mt7921u 2-1:1.3: mt76_get_txpower: phy->txpower_cur = 0 [ 26.816234] mt7921u 2-1:1.3: mt76_get_txpower: n_chains = 2 [ 26.816236] mt7921u 2-1:1.3: mt76_get_txpower: delta = 6 [ 26.816237] mt7921u 2-1:1.3: mt76_get_txpower: *dbm = 3
So the driver is correctly calculating the TX power adjustment based on the number of antennas. However, the base TX power (phy->txpower_cur) is not being properly initialized or set to a meaningful value. It's starting at 0, so the final result is just the antenna gain compensation divided by 2.
While investigating this I found commit ff94604 that adds a separate function for _get_power_bound so decided to reuse it for all 3 chipsets, might be needed in the future as well.
Tested-on: Alfa Network AWUS036AXML
... and it also reacts to manual txpower changes now.
Thank you in advance for looking into this!
R
Changes in v2:
- Fix line wrapping for commits body
- Added a new patch to apply the same cleanup fix to MT7996
Razvan Grigore (5):
wifi: mt76: add mt76_get_power_bound helper function
wifi: mt76: mt7921: fix returned txpower
wifi: mt76: mt7925: fix returned txpower
wifi: mt76: mt7915: cleanup mt7915_get_power_bound
wifi: mt76: mt7996: cleanup mt7996_get_power_bound
drivers/net/wireless/mediatek/mt76/mac80211.c | 11 +++++++++++ drivers/net/wireless/mediatek/mt76/mt76.h | 2 ++ drivers/net/wireless/mediatek/mt76/mt7915/debugfs.c | 8 ++++---- drivers/net/wireless/mediatek/mt76/mt7915/mcu.c | 4 ++-- drivers/net/wireless/mediatek/mt76/mt7915/mcu.h | 12 ------------ drivers/net/wireless/mediatek/mt76/mt7921/main.c | 7 +++++++ drivers/net/wireless/mediatek/mt76/mt7925/main.c | 7 +++++++ drivers/net/wireless/mediatek/mt76/mt7996/mcu.c | 2 +- drivers/net/wireless/mediatek/mt76/mt7996/mcu.h | 12 ------------ 9 files changed, 34 insertions(+), 31 deletions(-)
Signature · 1 line
2.34.1
PATCH v2 1/5 wifi: mt76: add mt76_get_power_bound helper function
This will replace mt7915_get_power_bound function from b/mt7915/mcu.h, since we will need it also for mt7921 and mt7925
--- drivers/net/wireless/mediatek/mt76/mac80211.c | 11 +++++++++++ drivers/net/wireless/mediatek/mt76/mt76.h | 2 ++ 2 files changed, 13 insertions(+)
drivers/net/wireless/mediatek/mt76/mac80211.c +11 -0
@@ -1697,6 +1697,17 @@ void mt76_wcid_add_poll(struct mt76_dev *dev, struct mt76_wcid *wcid) }EXPORT_SYMBOL_GPL (mt76_wcid_add_poll); +s8 mt76_get_power_bound (struct mt76_phy *phy,s8 txpower) +{ +int n_chains =hweight16 (phy->chainmask); + + txpower =mt76_get_sar_power (phy, phy->chandef.chan, txpower *2 ); + txpower -=mt76_tx_power_nss_delta (n_chains); + +return txpower; +} +EXPORT_SYMBOL_GPL (mt76_get_power_bound); +int mt76_get_txpower (struct ieee80211_hw *hw,struct ieee80211_vif *vif,unsigned int link_id,int *dbm) {
drivers/net/wireless/mediatek/mt76/mt76.h +2 -0
@@ -1482,6 +1482,8 @@ void mt76_sta_pre_rcu_remove(struct ieee80211_hw *hw, struct ieee80211_vif *vif,int mt76_get_min_avg_rssi (struct mt76_dev *dev,u8 phy_idx); +s8 mt76_get_power_bound (struct mt76_phy *phy,s8 txpower); +int mt76_get_txpower (struct ieee80211_hw *hw,struct ieee80211_vif *vif,unsigned int link_id,int *dbm); int mt76_init_sar_power(struct ieee80211_hw *hw,
Signature · 1 line
2.34.1
PATCH v2 2/5 wifi: mt76: mt7921: fix returned txpower
In reply to Razvan GrigoreThis bug was noticed by me and confirmed by many more people using this chipset with openwrt: https://github.com/openwrt/mt76/issues/783
It seems that for this particular chipset the mt76_phy->txpower_cur is never set, like in the case of other chipsets like mt7603, mt7615, etc.
The driver is correctly calculating the TX power adjustment based on the number of antennas. However, the base TX power (phy->txpower_cur) is not being properly initialized or set to a meaningful value. It's starting at 0, so the final result is just the antenna gain compensation divided by 2.
--- drivers/net/wireless/mediatek/mt76/mt7921/main.c | 7 +++++++ 1 file changed, 7 insertions(+)
drivers/net/wireless/mediatek/mt76/mt7921/main.c +7 -0
@@ -1251,6 +1251,8 @@ int mt7921_set_tx_sar_pwr(struct ieee80211_hw *hw, const struct cfg80211_sar_specs *sar) {struct mt76_phy *mphy = hw->priv; +int tx_power; +struct mt76_power_limits limits_array;if (sar) {int err =mt76_init_sar_power (hw, sar);
@@ -1260,6 +1262,11 @@ int mt7921_set_tx_sar_pwr(struct ieee80211_hw *hw, }mt792x_init_acpi_sar_power (mt792x_hw_phy (hw), !sar); + tx_power =mt76_get_power_bound (mphy, hw->conf.power_level); + tx_power =mt76_get_rate_power_limits (mphy, mphy->chandef.chan, + &limits_array, tx_power); + mphy->txpower_cur = tx_power; +return mt76_connac_mcu_set_rate_txpower (mphy); }
Signature · 1 line
2.34.1
PATCH v2 3/5 wifi: mt76: mt7925: fix returned txpower
In reply to Razvan GrigoreSimilar to the mt7921, seems the code was copy-paste from there. This bug was noticed by me and confirmed by many more people using this chipset with openwrt: https://github.com/openwrt/mt76/issues/783
It seems that for this particular chipset the mt76_phy->txpower_cur is never set, like in the case of other chipsets like mt7603, mt7615, etc.
The driver is correctly calculating the TX power adjustment based on the number of antennas. However, the base TX power (phy->txpower_cur) is not being properly initialized or set to a meaningful value. It's starting at 0, so the final result is just the antenna gain compensation divided by 2.
--- drivers/net/wireless/mediatek/mt76/mt7925/main.c | 7 +++++++ 1 file changed, 7 insertions(+)
drivers/net/wireless/mediatek/mt76/mt7925/main.c +7 -0
@@ -1656,6 +1656,8 @@ int mt7925_set_tx_sar_pwr(struct ieee80211_hw *hw, const struct cfg80211_sar_specs *sar) {struct mt76_phy *mphy = hw->priv; +int tx_power; +struct mt76_power_limits limits_array;if (sar) {int err =mt76_init_sar_power (hw, sar);
@@ -1665,6 +1667,11 @@ int mt7925_set_tx_sar_pwr(struct ieee80211_hw *hw, }mt792x_init_acpi_sar_power (mt792x_hw_phy (hw), !sar); + tx_power =mt76_get_power_bound (mphy, hw->conf.power_level); + tx_power =mt76_get_rate_power_limits (mphy, mphy->chandef.chan, + &limits_array, tx_power); + mphy->txpower_cur = tx_power; +return mt7925_mcu_set_rate_txpower (mphy); }
Signature · 1 line
2.34.1
PATCH v2 4/5 wifi: mt76: mt7915: cleanup mt7915_get_power_bound
In reply to Razvan GrigoreRefactor for making use of mt76_get_power_bound instead of the specific mt7915_get_power_bound, since we need this for other chipsets as well when calculating txpower
--- drivers/net/wireless/mediatek/mt76/mt7915/debugfs.c | 8 ++++---- drivers/net/wireless/mediatek/mt76/mt7915/mcu.c | 4 ++-- drivers/net/wireless/mediatek/mt76/mt7915/mcu.h | 12 ------------ 3 files changed, 6 insertions(+), 18 deletions(-)
drivers/net/wireless/mediatek/mt76/mt7915/debugfs.c +4 -4
@@ -1084,13 +1084,13 @@ mt7915_rate_txpower_set(struct file *file, const char __user *user_buf,return -EINVAL ;if (pwr160) - pwr160 =mt7915_get_power_bound (phy, pwr160); + pwr160 =mt76_get_power_bound (mphy, pwr160);if (pwr80) - pwr80 =mt7915_get_power_bound (phy, pwr80); + pwr80 =mt76_get_power_bound (mphy, pwr80);if (pwr40) - pwr40 =mt7915_get_power_bound (phy, pwr40); + pwr40 =mt76_get_power_bound (mphy, pwr40);if (pwr20) - pwr20 =mt7915_get_power_bound (phy, pwr20); + pwr20 =mt76_get_power_bound (mphy, pwr20);if (pwr160 <0 || pwr80 <0 || pwr40 <0 || pwr20 <0 )return -EINVAL ;
drivers/net/wireless/mediatek/mt76/mt7915/mcu.c +2 -2
@@ -3323,7 +3323,7 @@ int mt7915_mcu_set_txpower_frame(struct mt7915_phy *phy,if (ret)return ret; - txpower =mt7915_get_power_bound (phy, txpower); + txpower =mt76_get_power_bound (mphy, txpower);if (txpower > mphy->txpower_cur || txpower <0 )return -EINVAL ;
@@ -3373,7 +3373,7 @@ int mt7915_mcu_set_txpower_sku(struct mt7915_phy *phy)int i, idx;int tx_power; - tx_power =mt7915_get_power_bound (phy, hw->conf.power_level); + tx_power =mt76_get_power_bound (mphy, hw->conf.power_level); tx_power =mt76_get_rate_power_limits (mphy, mphy->chandef.chan, &limits_array, tx_power); mphy->txpower_cur = tx_power;
drivers/net/wireless/mediatek/mt76/mt7915/mcu.h +0 -12
@@ -515,16 +515,4 @@ enum { sizeof(struct bss_info_bmc_rate) +\ sizeof(struct bss_info_ext_bss)) -static inline s8 -mt7915_get_power_bound (struct mt7915_phy *phy,s8 txpower) -{ -struct mt76_phy *mphy = phy->mt76; -int n_chains =hweight16 (mphy->chainmask); - - txpower =mt76_get_sar_power (mphy, mphy->chandef.chan, txpower *2 ); - txpower -=mt76_tx_power_nss_delta (n_chains); - -return txpower; -} -#endif
Signature · 1 line
2.34.1
PATCH v2 5/5 wifi: mt76: mt7996: cleanup mt7996_get_power_bound
In reply to Razvan GrigoreRefactor for making use of mt76_get_power_bound instead of the specific mt7996_get_power_bound, since we need this for other chipsets as well when calculating txpower
--- drivers/net/wireless/mediatek/mt76/mt7996/mcu.c | 2 +- drivers/net/wireless/mediatek/mt76/mt7996/mcu.h | 12 ------------ 2 files changed, 1 insertion(+), 13 deletions(-)
drivers/net/wireless/mediatek/mt76/mt7996/mcu.c +1 -1
@@ -4579,7 +4579,7 @@ int mt7996_mcu_set_txpower_sku(struct mt7996_phy *phy)struct sk_buff *skb;int i, tx_power; - tx_power =mt7996_get_power_bound (phy, phy->txpower); + tx_power =mt76_get_power_bound (mphy, phy->txpower); tx_power =mt76_get_rate_power_limits (mphy, mphy->chandef.chan, &la, tx_power); mphy->txpower_cur = tx_power;
drivers/net/wireless/mediatek/mt76/mt7996/mcu.h +0 -12
@@ -809,18 +809,6 @@ enum {#define MT7996_MAX_BSS_OFFLOAD_SIZE (MT7996_MAX_BEACON_SIZE + \ MT7996_BEACON_UPDATE_SIZE) -static inline s8 -mt7996_get_power_bound (struct mt7996_phy *phy,s8 txpower) -{ -struct mt76_phy *mphy = phy->mt76; -int n_chains =hweight16 (mphy->chainmask); - - txpower =mt76_get_sar_power (mphy, mphy->chandef.chan, txpower *2 ); - txpower -=mt76_tx_power_nss_delta (n_chains); - -return txpower; -} -enum {UNI_BAND_CONFIG_RADIO_ENABLE ,UNI_BAND_CONFIG_RTS_THRESHOLD =0x08 ,
Signature · 1 line
2.34.1
Hello,
Seems this patch series not actually working on MT7925. Anyone could help?
https://github.com/openwrt/mt76/issues/783#issuecomment-2704349798
Best regards,
Shengyu
Quoted 56 lines · Razvan Grigore
When reading the txpower with
iw dev wlan1the returned value is always 3.00 dBm, no matter what reg domain is set or if one changes the txpower manually.This bug was discovered by me and confirmed by many people using this chipset on openwrt: https://github.com/openwrt/mt76/issues/783
I tracked the code for this and it seems that for those 2 chipsets particularly, the
mt76_phy->txpower_curis never set, in contrast to other chipsets like mt7603, mt7615, mt76x0, mt7915, etc.Added some debug logs in the
mt76_get_txpowerfunction and I got:[ 26.816227] mt7921u 2-1:1.3: mt76_get_txpower: phy->txpower_cur = 0 [ 26.816234] mt7921u 2-1:1.3: mt76_get_txpower: n_chains = 2 [ 26.816236] mt7921u 2-1:1.3: mt76_get_txpower: delta = 6 [ 26.816237] mt7921u 2-1:1.3: mt76_get_txpower: *dbm = 3So the driver is correctly calculating the TX power adjustment based on the number of antennas. However, the base TX power (
phy->txpower_cur) is not being properly initialized or set to a meaningful value. It's starting at 0, so the final result is just the antenna gain compensation divided by 2.While investigating this I found commit ff94604 that adds a separate function for
_get_power_boundso decided to reuse it for all 3 chipsets, might be needed in the future as well.Tested-on: Alfa Network AWUS036AXML
... and it also reacts to manual txpower changes now.Thank you in advance for looking into this!
RChanges in v2:
- Fix line wrapping for commits body
- Added a new patch to apply the same cleanup fix to MT7996Razvan Grigore (5):
wifi: mt76: addmt76_get_power_boundhelper function
wifi: mt76: mt7921: fix returned txpower
wifi: mt76: mt7925: fix returned txpower
wifi: mt76: mt7915: cleanupmt7915_get_power_bound
wifi: mt76: mt7996: cleanupmt7996_get_power_bounddrivers/net/wireless/mediatek/mt76/mac80211.c | 11 +++++++++++ drivers/net/wireless/mediatek/mt76/mt76.h | 2 ++ drivers/net/wireless/mediatek/mt76/mt7915/debugfs.c | 8 ++++---- drivers/net/wireless/mediatek/mt76/mt7915/mcu.c | 4 ++-- drivers/net/wireless/mediatek/mt76/mt7915/mcu.h | 12 ------------ drivers/net/wireless/mediatek/mt76/mt7921/main.c | 7 +++++++ drivers/net/wireless/mediatek/mt76/mt7925/main.c | 7 +++++++ drivers/net/wireless/mediatek/mt76/mt7996/mcu.c | 2 +- drivers/net/wireless/mediatek/mt76/mt7996/mcu.h | 12 ------------ 9 files changed, 34 insertions(+), 31 deletions(-)