]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
wifi: mt76: mt7996: implement driver specific get_txpower function
authorFelix Fietkau <nbd@nbd.name>
Tue, 11 Mar 2025 10:36:44 +0000 (11:36 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 29 May 2025 09:12:32 +0000 (11:12 +0200)
[ Upstream commit 86db2c5d4ed390b97a5b455a97e2cd9c4f3eff2b ]

Fixes reporting tx power for vifs that don't have a channel context
assigned. Report the tx power of a phy that is covered by the vif's
radio mask.

Link: https://patch.msgid.link/20250311103646.43346-7-nbd@nbd.name
Signed-off-by: Felix Fietkau <nbd@nbd.name>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/net/wireless/mediatek/mt76/mt7996/main.c

index 69dd565d831900fa344e214042a74b2e5b265741..980a059b3b38fee16f3ac5b1ffab3ba0b25fb4df 100644 (file)
@@ -601,6 +601,33 @@ static void mt7996_configure_filter(struct ieee80211_hw *hw,
        mutex_unlock(&dev->mt76.mutex);
 }
 
+static int
+mt7996_get_txpower(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
+                  unsigned int link_id, int *dbm)
+{
+       struct mt7996_vif *mvif = (struct mt7996_vif *)vif->drv_priv;
+       struct mt7996_phy *phy = mt7996_vif_link_phy(&mvif->deflink);
+       struct mt7996_dev *dev = mt7996_hw_dev(hw);
+       struct wireless_dev *wdev;
+       int n_chains, delta, i;
+
+       if (!phy) {
+               wdev = ieee80211_vif_to_wdev(vif);
+               for (i = 0; i < hw->wiphy->n_radio; i++)
+                       if (wdev->radio_mask & BIT(i))
+                               phy = dev->radio_phy[i];
+
+               if (!phy)
+                       return -EINVAL;
+       }
+
+       n_chains = hweight16(phy->mt76->chainmask);
+       delta = mt76_tx_power_nss_delta(n_chains);
+       *dbm = DIV_ROUND_UP(phy->mt76->txpower_cur + delta, 2);
+
+       return 0;
+}
+
 static u8
 mt7996_get_rates_table(struct mt7996_phy *phy, struct ieee80211_bss_conf *conf,
                       bool beacon, bool mcast)
@@ -1650,7 +1677,7 @@ const struct ieee80211_ops mt7996_ops = {
        .remain_on_channel = mt76_remain_on_channel,
        .cancel_remain_on_channel = mt76_cancel_remain_on_channel,
        .release_buffered_frames = mt76_release_buffered_frames,
-       .get_txpower = mt76_get_txpower,
+       .get_txpower = mt7996_get_txpower,
        .channel_switch_beacon = mt7996_channel_switch_beacon,
        .get_stats = mt7996_get_stats,
        .get_et_sset_count = mt7996_get_et_sset_count,