wifi: mt76: mt7915: introduce mt7915_get_power_bound()
authorRyder Lee <ryder.lee@mediatek.com>
Wed, 23 Nov 2022 19:59:10 +0000 (03:59 +0800)
committerFelix Fietkau <nbd@nbd.name>
Thu, 1 Dec 2022 16:29:15 +0000 (17:29 +0100)
Add a helper for common boundary check. This is a preliminary patch
to add per bandwidth power control.

Signed-off-by: Ryder Lee <ryder.lee@mediatek.com>
Signed-off-by: Felix Fietkau <nbd@nbd.name>
drivers/net/wireless/mediatek/mt76/mt7915/mcu.c
drivers/net/wireless/mediatek/mt76/mt7915/mcu.h

index 718e52744994b2551c6a7076c8429733f19a67e1..b640ce9249c9e9d81beb96cd827c95982477f31e 100644 (file)
@@ -3144,14 +3144,14 @@ int mt7915_mcu_set_txpower_frame(struct mt7915_phy *phy,
                .txpower_max = DIV_ROUND_UP(mphy->txpower_cur, 2),
                .wcid = cpu_to_le16(msta->wcid.idx),
        };
-       int ret, n_chains = hweight8(mphy->antenna_mask);
+       int ret;
        s8 txpower_sku[MT7915_SKU_RATE_NUM];
 
        ret = mt7915_mcu_get_txpower_sku(phy, txpower_sku, sizeof(txpower_sku));
        if (ret)
                return ret;
 
-       txpower = txpower * 2 - mt76_tx_power_nss_delta(n_chains);
+       txpower = mt7915_get_power_bound(phy, txpower);
        if (txpower > mphy->txpower_cur || txpower < 0)
                return -EINVAL;
 
@@ -3203,12 +3203,10 @@ int mt7915_mcu_set_txpower_sku(struct mt7915_phy *phy)
        };
        struct mt76_power_limits limits_array;
        s8 *la = (s8 *)&limits_array;
-       int i, idx, n_chains = hweight8(mphy->antenna_mask);
-       int tx_power = hw->conf.power_level * 2;
+       int i, idx;
+       int tx_power;
 
-       tx_power = mt76_get_sar_power(mphy, mphy->chandef.chan,
-                                     tx_power);
-       tx_power -= mt76_tx_power_nss_delta(n_chains);
+       tx_power = mt7915_get_power_bound(phy, hw->conf.power_level);
        tx_power = mt76_get_rate_power_limits(mphy, mphy->chandef.chan,
                                              &limits_array, tx_power);
        mphy->txpower_cur = tx_power;
index 46c517e50ae4f12ff4a06f21989abef465f96947..382dcbda50bbc16317d0608272935d68c1b4cea5 100644 (file)
@@ -509,4 +509,16 @@ enum {
                                         sizeof(struct bss_info_bcn_cont) + \
                                         sizeof(struct bss_info_inband_discovery))
 
+static inline s8
+mt7915_get_power_bound(struct mt7915_phy *phy, s8 txpower)
+{
+       struct mt76_phy *mphy = phy->mt76;
+       int n_chains = hweight8(mphy->antenna_mask);
+
+       txpower = mt76_get_sar_power(mphy, mphy->chandef.chan, txpower * 2);
+       txpower -= mt76_tx_power_nss_delta(n_chains);
+
+       return txpower;
+}
+
 #endif