From: Sean Wang Date: Wed, 1 Apr 2026 18:23:21 +0000 (-0500) Subject: wifi: mt76: connac: factor out rate power limit calculation X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=317bc1a0590e15c5a47c07e61f89edffcde65098;p=thirdparty%2Flinux.git wifi: mt76: connac: factor out rate power limit calculation 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 Closes: https://lore.kernel.org/linux-wireless/20260130215839.53270-1-lucid_duck@justthetip.ca/ Tested-by: Devin Wittmayer Tested-by: Satadru Pramanik Co-developed-by: Devin Wittmayer Signed-off-by: Devin Wittmayer Signed-off-by: Sean Wang Link: https://patch.msgid.link/20260401182322.64355-2-sean.wang@kernel.org Signed-off-by: Felix Fietkau --- diff --git a/drivers/net/wireless/mediatek/mt76/mt76_connac.h b/drivers/net/wireless/mediatek/mt76/mt76_connac.h index 4afcc6477a99..2aa6078993e9 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76_connac.h +++ b/drivers/net/wireless/mediatek/mt76/mt76_connac.h @@ -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); diff --git a/drivers/net/wireless/mediatek/mt76/mt76_connac_mcu.c b/drivers/net/wireless/mediatek/mt76/mt76_connac_mcu.c index 03348463f2db..6596c9e198f4 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76_connac_mcu.c +++ b/drivers/net/wireless/mediatek/mt76/mt76_connac_mcu.c @@ -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,