Skip to contentSkip to conversation

wifi: mt76: connac: use a helper to cache txpower_cur

PATCH Superseded Sean Wang 4 participants 9 messages Mar 25 – Mar 31

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Sean Wang

author
#0 lore raw

PATCH 1/3 wifi: mt76: connac: use a helper to cache txpower_cur

From: Sean Wang <[email protected]>

The cached txpower value is derived from the bounded channel power after applying the chainmask path delta.

Use a helper for that conversion so callers do not open-code it.

---
 drivers/net/wireless/mediatek/mt76/mt76_connac.h     |  2 +-
 drivers/net/wireless/mediatek/mt76/mt76_connac_mac.c |  9 +++++++++
 drivers/net/wireless/mediatek/mt76/mt76_connac_mcu.c | 11 ++++++++---
 3 files changed, 18 insertions(+), 4 deletions(-)
drivers/net/wireless/mediatek/mt76/mt76_connac.h +1 -1
index 51423c7740bd..d0953e02810b 100644
@@ -420,7 +420,7 @@ mt76_connac_mutex_release(struct mt76_dev *dev, struct mt76_connac_pm *pm)
 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);
 void mt76_connac_write_hw_txp(struct mt76_dev *dev,
 			      struct mt76_tx_info *tx_info,
 			      void *txp_ptr, u32 id);
drivers/net/wireless/mediatek/mt76/mt76_connac_mac.c +9 -0
index 0339e2e7ab60..b2daa6c7d061 100644
@@ -275,6 +275,15 @@ int mt76_connac_init_tx_queues(struct mt76_phy *phy, int idx, int n_desc,
 }
 EXPORT_SYMBOL_GPL(mt76_connac_init_tx_queues);
 
+void mt76_connac_set_txpower_cur(struct mt76_phy *phy, s8 max_power)
+{
+	int delta;
+
+	delta = mt76_tx_power_path_delta(hweight16(phy->chainmask));
+	phy->txpower_cur = max_power - delta;
+}
+EXPORT_SYMBOL_GPL(mt76_connac_set_txpower_cur);
+
 #define __bitrate_mask_check(_mcs, _mode)				\
 ({									\
 	u8 i = 0;							\
drivers/net/wireless/mediatek/mt76/mt76_connac_mcu.c +8 -3
index 89bd52ea8bf7..897b065a2be6 100644
@@ -2223,14 +2223,19 @@ mt76_connac_mcu_rate_txpower_band(struct mt76_phy *phy,
 				.hw_value = ch_list[idx],
 				.band = band,
 			};
-			s8 reg_power, sar_power;
+			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);
 
-			mt76_get_rate_power_limits(phy, &chan, limits,
-						   sar_power);
+			max_power = mt76_get_rate_power_limits(phy, &chan, limits,
+							       sar_power);
+
+			if (phy->chandef.chan &&
+			    phy->chandef.chan->hw_value == ch_list[idx] &&
+			    phy->chandef.chan->band == band)
+				mt76_connac_set_txpower_cur(phy, max_power);
 
 			tx_power_tlv.last_msg = ch_list[idx] == last_ch;
 			sku_tlbv.channel = ch_list[idx];
Signature · 1 line
2.43.0
author
#1 lore raw

PATCH 2/3 wifi: mt76: connac: factor out rate power limit calculation

From: Sean Wang <[email protected]>

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.

---
 .../net/wireless/mediatek/mt76/mt76_connac.h  |  3 ++
 .../wireless/mediatek/mt76/mt76_connac_mcu.c  | 28 +++++++++++++------
 2 files changed, 23 insertions(+), 8 deletions(-)
drivers/net/wireless/mediatek/mt76/mt76_connac.h +3 -0
index d0953e02810b..1549a97873ee 100644
@@ -421,6 +421,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);
drivers/net/wireless/mediatek/mt76/mt76_connac_mcu.c +20 -8
index 897b065a2be6..1117a22c70ac 100644
@@ -2223,15 +2223,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)
@@ -2967,6 +2962,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,
Signature · 1 line
2.43.0
author
#2 lore raw

PATCH 3/3 wifi: mt76: mt792x: report txpower for the requested vif link

In reply to Sean Wang

From: Sean Wang <[email protected]>

mt792x currently reports txpower from the generic PHY cached state, which may not match the requested vif/link context.

Resolve the requested link channel and derive txpower from that channel instead, with fallback to the current PHY chandef if no valid chanctx is available.

---
 .../net/wireless/mediatek/mt76/mt7921/main.c  |  2 +-
 .../net/wireless/mediatek/mt76/mt7925/main.c  |  2 +-
 drivers/net/wireless/mediatek/mt76/mt792x.h   |  2 +
 .../net/wireless/mediatek/mt76/mt792x_core.c  | 41 +++++++++++++++++++
 4 files changed, 45 insertions(+), 2 deletions(-)
drivers/net/wireless/mediatek/mt76/mt7921/main.c +1 -1
index 3d74fabe7408..2e7cdf8edc12 100644
@@ -1552,7 +1552,7 @@ const struct ieee80211_ops mt7921_ops = {
 	.wake_tx_queue = mt76_wake_tx_queue,
 	.release_buffered_frames = mt76_release_buffered_frames,
 	.channel_switch_beacon = mt7921_channel_switch_beacon,
-	.get_txpower = mt76_get_txpower,
+	.get_txpower = mt792x_get_txpower,
 	.get_stats = mt792x_get_stats,
 	.get_et_sset_count = mt792x_get_et_sset_count,
 	.get_et_strings = mt792x_get_et_strings,
drivers/net/wireless/mediatek/mt76/mt7925/main.c +1 -1
index 73d3722739d0..53e1a93c6976 100644
@@ -2433,7 +2433,7 @@ const struct ieee80211_ops mt7925_ops = {
 	.wake_tx_queue = mt76_wake_tx_queue,
 	.release_buffered_frames = mt76_release_buffered_frames,
 	.channel_switch_beacon = mt7925_channel_switch_beacon,
-	.get_txpower = mt76_get_txpower,
+	.get_txpower = mt792x_get_txpower,
 	.get_stats = mt792x_get_stats,
 	.get_et_sset_count = mt792x_get_et_sset_count,
 	.get_et_strings = mt792x_get_et_strings,
drivers/net/wireless/mediatek/mt76/mt792x.h +2 -0
index 4ff93f2cd624..65eba18bc3a1 100644
@@ -397,6 +397,8 @@ void mt792x_roc_timer(struct timer_list *timer);
 void mt792x_csa_timer(struct timer_list *timer);
 void mt792x_flush(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
 		  u32 queues, bool drop);
+int mt792x_get_txpower(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
+		       unsigned int link_id, int *dbm);
 int mt792x_assign_vif_chanctx(struct ieee80211_hw *hw,
 			      struct ieee80211_vif *vif,
 			      struct ieee80211_bss_conf *link_conf,
drivers/net/wireless/mediatek/mt76/mt792x_core.c +41 -0

47 lines not on this page · raw message

Signature · 1 line
2.43.0
Tested-by on v1 1/3
#3 lore raw
In reply to Sean Wang

Sean,

Tested the full 3-patch series on MT7921AU. All three bands working correctly -- txpower reporting is fixed.

Test environment:

  Kernel:     6.19.8-200.fc43.x86_64 (Fedora 43)
  Device:     MediaTek MT7921AU USB (0e8d:7961)
  Firmware:   HW/SW 0x8a108a10, WM 20251223091148
  AP:         Tri-band (2.4/5/6 GHz)
  Regdomain:  CA (DFS-FCC), also tested US, JP, DE
  Note:       Internet maintained via separate USB ethernet

adapter during WiFi testing

Baseline (stock 6.19.8, pre-patch):

txpower 3.00 dBm on all bands

Post-patch txpower:

  2.4 GHz  ch 1   (2412 MHz, 20 MHz):   36.00 dBm
  5 GHz    ch 100 (5500 MHz, 80 MHz):    26.00 dBm
  6 GHz    ch 5   (5975 MHz, 80 MHz):    12.00 dBm

All values match expected CA regulatory limits. Connectivity verified with 0% packet loss on every band.

Stress testing (28 tests, 28 passed, 0 failed):

- Connect/disconnect: 10 cycles per band (30 total), txpower correct and ping 0% loss on every cycle
- Band switching: 30 sequential hops (2.4 -> 5 -> 6 -> repeat), txpower correct on every hop, ping 30/30
- Module reload: 15 full rmmod/insmod cycles of all mt76 modules, txpower correct after every reload
- Throughput: 100-ping per band, 0% loss on all

      2.4 GHz: avg 2.4 ms, max 23.6 ms
      5 GHz:   avg 1.9 ms, max 8.0 ms
      6 GHz:   avg 2.2 ms, max 3.3 ms
  - Soak: 20-minute continuous test per band (60 min total),
    txpower sampled every 30 seconds, never deviated
      2.4 GHz: 40/40 samples at 36.00 dBm, slab delta -4 kB
      5 GHz:   40/40 samples at 26.00 dBm, slab delta +16 kB
      6 GHz:   40/40 samples at 12.00 dBm, slab delta -16 kB
  - Memory: 50 connect/disconnect cycles, slab delta +64 kB
    (negligible, no leak)
  - Band-hop marathon: 200 random band hops, 200/200 pass,
    ping 200/200 OK, completed in 1232 seconds
  - Concurrent managed + monitor: txpower stable on all bands
    with a monitor VIF present, ping 0% loss
  - Regulatory domain switching: txpower correctly adjusts
    per country on 5 GHz
      CA: 26.00 dBm
      US: 24.00 dBm
      JP: 23.00 dBm
      DE: 26.00 dBm

Zero kernel warnings in dmesg throughout all testing.

For context, I originally reported this bug and submitted a fix in January (v1 through v4 on linux-wireless, as Lucid Duck). Patches 1 and 2 in this series address the same core issue -- capturing the rate power loop output and subtracting the path delta before caching txpower_cur. Patch 3 (the per-vif-link get_txpower callback) is a good addition that was not in my series.

author
#4 lore raw

Hi, Lucid

Quoted 59 lines · Lucid Duck

Sean,

Tested the full 3-patch series on MT7921AU. All three bands working correctly -- txpower reporting is fixed.

Test environment:

  Kernel:     6.19.8-200.fc43.x86_64 (Fedora 43)
  Device:     MediaTek MT7921AU USB (0e8d:7961)
  Firmware:   HW/SW 0x8a108a10, WM 20251223091148
  AP:         Tri-band (2.4/5/6 GHz)
  Regdomain:  CA (DFS-FCC), also tested US, JP, DE
  Note:       Internet maintained via separate USB ethernet

adapter during WiFi testing

Baseline (stock 6.19.8, pre-patch):

txpower 3.00 dBm on all bands

Post-patch txpower:

  2.4 GHz  ch 1   (2412 MHz, 20 MHz):   36.00 dBm
  5 GHz    ch 100 (5500 MHz, 80 MHz):    26.00 dBm
  6 GHz    ch 5   (5975 MHz, 80 MHz):    12.00 dBm

All values match expected CA regulatory limits. Connectivity verified with 0% packet loss on every band.

Stress testing (28 tests, 28 passed, 0 failed):

- Connect/disconnect: 10 cycles per band (30 total), txpower correct and ping 0% loss on every cycle
- Band switching: 30 sequential hops (2.4 -> 5 -> 6 -> repeat), txpower correct on every hop, ping 30/30
- Module reload: 15 full rmmod/insmod cycles of all mt76 modules, txpower correct after every reload
- Throughput: 100-ping per band, 0% loss on all

      2.4 GHz: avg 2.4 ms, max 23.6 ms
      5 GHz:   avg 1.9 ms, max 8.0 ms
      6 GHz:   avg 2.2 ms, max 3.3 ms
  - Soak: 20-minute continuous test per band (60 min total),
    txpower sampled every 30 seconds, never deviated
      2.4 GHz: 40/40 samples at 36.00 dBm, slab delta -4 kB
      5 GHz:   40/40 samples at 26.00 dBm, slab delta +16 kB
      6 GHz:   40/40 samples at 12.00 dBm, slab delta -16 kB
  - Memory: 50 connect/disconnect cycles, slab delta +64 kB
    (negligible, no leak)
  - Band-hop marathon: 200 random band hops, 200/200 pass,
    ping 200/200 OK, completed in 1232 seconds
  - Concurrent managed + monitor: txpower stable on all bands
    with a monitor VIF present, ping 0% loss
  - Regulatory domain switching: txpower correctly adjusts
    per country on 5 GHz
      CA: 26.00 dBm
      US: 24.00 dBm
      JP: 23.00 dBm
      DE: 26.00 dBm
Quoted 8 lines

Zero kernel warnings in dmesg throughout all testing.

For context, I originally reported this bug and submitted a fix in January (v1 through v4 on linux-wireless, as Lucid Duck). Patches 1 and 2 in this series address the same core issue -- capturing the rate power loop output and subtracting the path delta before caching txpower_cur. Patch 3 (the per-vif-link get_txpower callback) is a good addition that was not in my series.

Thanks a lot for the detailed testing and for confirming the fix on MT7921AU.

This was my mistake. Patches 1 and 2 do overlap with the core fix direction from your January series, and I should have credited that more clearly.

I’ll add a Co-developed-by tag for you in patches 1 and 2, along with proper attribution in the next revision.

Sean

Quoted 3 lines
#7 lore raw

Hi Felix,

Quoted 9 lines · Felix Baumann

Hi Lucid Duck,

thanks a lot for your contribution. Very much appreciated :) The kernel has a strict policy for contributions: real names only.
https://www.kernel.org/doc/html/v4.11/process/submitting-patches.html#sign-your-work-the-developer-s-certificate-of-origin

May I kindly ask whether it would be okay for Sean to use your real name?
https://github.com/Lucid-Duck

You should update your link, the real name policy was relaxed a while ago:

https://www.kernel.org/doc/html/latest/process/submitting-patches.html#developer-s-certificate-of-origin-1-1

"(...) then you just add a line saying: (...) using a known identity (sorry, no anonymous contributions.)."

See https://github.com/torvalds/linux/commit/d4563201f33a022fc0353033d9dfeb1606a88330
for details.

Having said that, I don't think the real name policy would have even applied to Tested-by / Reported-by tags. For these it really doesn't matter, as these are not code contributions.

Best regards,
Jonas

#8 lore raw
In reply to Felix Baumann

Hi Felix,

Thank you, and thanks for reaching out.
Yes, absolutely -- my real name is Devin Wittmayer. Sean is welcome to use it for the Co-developed-by tag.

Cheers,

Devin

Quoted 14 lines · Felix Baumann

Hi Lucid Duck,

thanks a lot for your contribution. Very much appreciated :) The kernel has a strict policy for contributions: real names only.
https://www.kernel.org/doc/html/v4.11/process/submitting-patches.html#sign-your-work-the-developer-s-certificate-of-origin

May I kindly ask whether it would be okay for Sean to use your real name?
https://github.com/Lucid-Duck

Signature · 2 lines
Regards
Felix Baumann