]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
wifi: mt76: connac: factor out rate power limit calculation
authorSean Wang <sean.wang@mediatek.com>
Wed, 1 Apr 2026 18:23:21 +0000 (13:23 -0500)
committerFelix Fietkau <nbd@nbd.name>
Tue, 9 Jun 2026 10:15:22 +0000 (10:15 +0000)
Factor out the per-channel rate power limit calculation into a shared
helper.

This avoids duplicating the same regulatory, SAR and rate-limit logic in
multiple paths.

Reported-by: Devin Wittmayer <lucid_duck@justthetip.ca>
Closes: https://lore.kernel.org/linux-wireless/20260130215839.53270-1-lucid_duck@justthetip.ca/
Tested-by: Devin Wittmayer <lucid_duck@justthetip.ca>
Tested-by: Satadru Pramanik <satadru@gmail.com>
Co-developed-by: Devin Wittmayer <lucid_duck@justthetip.ca>
Signed-off-by: Devin Wittmayer <lucid_duck@justthetip.ca>
Signed-off-by: Sean Wang <sean.wang@mediatek.com>
Link: https://patch.msgid.link/20260401182322.64355-2-sean.wang@kernel.org
Signed-off-by: Felix Fietkau <nbd@nbd.name>
drivers/net/wireless/mediatek/mt76/mt76_connac.h
drivers/net/wireless/mediatek/mt76/mt76_connac_mcu.c

index 4afcc6477a99caf4f3733aefd658de901bf1944c..2aa6078993e9b7204a14479adb2e7adab75d54d6 100644 (file)
@@ -437,6 +437,9 @@ void mt76_connac_gen_ppe_thresh(u8 *he_ppet, int nss, enum nl80211_band band);
 int mt76_connac_init_tx_queues(struct mt76_phy *phy, int idx, int n_desc,
                               int ring_base, void *wed, u32 flags);
 void mt76_connac_set_txpower_cur(struct mt76_phy *phy, s8 max_power);
+s8 mt76_connac_get_rate_power_limit(struct mt76_phy *phy,
+                                   struct ieee80211_channel *chan,
+                                   struct mt76_power_limits *limits);
 void mt76_connac_write_hw_txp(struct mt76_dev *dev,
                              struct mt76_tx_info *tx_info,
                              void *txp_ptr, u32 id);
index 03348463f2db990cd225f3c43988fe6d3c9d6652..6596c9e198f425cead3bc7253b804b235fcf64c0 100644 (file)
@@ -2235,15 +2235,10 @@ mt76_connac_mcu_rate_txpower_band(struct mt76_phy *phy,
                                .hw_value = ch_list[idx],
                                .band = band,
                        };
-                       s8 reg_power, sar_power, max_power;
-
-                       reg_power = mt76_connac_get_ch_power(phy, &chan,
-                                                            tx_power);
-                       sar_power = mt76_get_sar_power(phy, &chan, reg_power);
-
-                       max_power = mt76_get_rate_power_limits(phy, &chan, limits,
-                                                              sar_power);
+                       s8 max_power;
 
+                       max_power = mt76_connac_get_rate_power_limit(phy, &chan,
+                                                                    limits);
                        if (phy->chandef.chan &&
                            phy->chandef.chan->hw_value == ch_list[idx] &&
                            phy->chandef.chan->band == band)
@@ -2979,6 +2974,23 @@ int mt76_connac_mcu_rdd_cmd(struct mt76_dev *dev, int cmd, u8 index,
 }
 EXPORT_SYMBOL_GPL(mt76_connac_mcu_rdd_cmd);
 
+s8 mt76_connac_get_rate_power_limit(struct mt76_phy *phy,
+                                   struct ieee80211_channel *chan,
+                                   struct mt76_power_limits *limits)
+{
+       s8 reg_power, sar_power;
+       int tx_power;
+
+       tx_power = 2 * phy->hw->conf.power_level;
+       if (!tx_power)
+               tx_power = 127;
+
+       reg_power = mt76_connac_get_ch_power(phy, chan, tx_power);
+       sar_power = mt76_get_sar_power(phy, chan, reg_power);
+       return mt76_get_rate_power_limits(phy, chan, limits, sar_power);
+}
+EXPORT_SYMBOL_GPL(mt76_connac_get_rate_power_limit);
+
 static int
 mt76_connac_mcu_send_ram_firmware(struct mt76_dev *dev,
                                  const struct mt76_connac2_fw_trailer *hdr,