public inbox for linux-wireless@vger.kernel.org
 help / color / mirror / Atom feed
From: Lucid Duck <lucid_duck@justthetip.ca>
To: nbd@nbd.name
Cc: lorenzo@kernel.org, linux-wireless@vger.kernel.org,
	Lucid Duck <lucid_duck@justthetip.ca>
Subject: [PATCH v2] wifi: mt76: mt7921: fix txpower reporting
Date: Fri, 30 Jan 2026 13:54:58 -0800	[thread overview]
Message-ID: <20260130215458.52886-1-lucid_duck@justthetip.ca> (raw)
In-Reply-To: <20260125222235.36565-1-lucid_duck@justthetip.ca>

The mt7921 driver never updates phy->txpower_cur, causing
mt76_get_txpower() to report incorrect values via nl80211.
Users see bogus txpower readings (typically 3 dBm or 67 dBm)
regardless of actual regulatory limits.

Fix this by updating txpower_cur in mt7921_bss_info_changed()
when BSS_CHANGED_TXPOWER is set. Use bss_conf.txpower as the
primary source, with a fallback to the channel's max_reg_power
for cases where bss_conf.txpower is not populated (INT_MIN).

Tested on Alfa AWUS036AXML (MT7921AU), kernel 6.18.6:
  - 2.4GHz ch1:  33 dBm (30 dBm limit + 3 dBm path delta) - PASS
  - 5GHz ch100:  27 dBm (24 dBm limit + 3 dBm path delta) - PASS
  - 6GHz ch5:    15 dBm (12 dBm limit + 3 dBm path delta) - PASS

Signed-off-by: Lucid Duck <lucid_duck@justthetip.ca>
---
 drivers/net/wireless/mediatek/mt76/mt7921/main.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/drivers/net/wireless/mediatek/mt76/mt7921/main.c b/drivers/net/wireless/mediatek/mt76/mt7921/main.c
index f37a35b..99fe46d 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7921/main.c
+++ b/drivers/net/wireless/mediatek/mt76/mt7921/main.c
@@ -725,6 +725,25 @@ static void mt7921_bss_info_changed(struct ieee80211_hw *hw,
 	if (changed & BSS_CHANGED_CQM)
 		mt7921_mcu_set_rssimonitor(dev, vif);

+	if (changed & BSS_CHANGED_TXPOWER) {
+		int tx_power = info->txpower;
+
+		/*
+		 * Workaround for kernel 6.18+: bss_conf.txpower may not be
+		 * populated (INT_MIN) even when BSS_CHANGED_TXPOWER is set.
+		 * In this case, use the channel's max regulatory power.
+		 */
+		if (tx_power == INT_MIN || tx_power <= 0) {
+			struct ieee80211_channel *chan = phy->mt76->chandef.chan;
+			if (chan)
+				tx_power = chan->max_reg_power;
+		}
+
+		/* txpower is in dBm, txpower_cur is in 0.5dBm units */
+		if (tx_power > 0 && tx_power < 127)
+			phy->mt76->txpower_cur = tx_power * 2;
+	}
+
 	if (changed & BSS_CHANGED_ASSOC) {
 		mt7921_mcu_sta_update(dev, NULL, vif, true,
 				      MT76_STA_INFO_STATE_ASSOC);
--
2.43.0

  parent reply	other threads:[~2026-01-30 22:06 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-25 22:22 [PATCH] wifi: mt76: connac: fix txpower_cur not being updated Lucid Duck
2026-01-27  1:59 ` Nick
2026-01-27 12:21 ` Felix Fietkau
2026-01-27 16:17   ` Bitterblue Smith
2026-01-27 17:00     ` Felix Fietkau
2026-01-30 21:54 ` Lucid Duck [this message]
2026-02-10  3:02   ` [PATCH v2] wifi: mt76: mt7921: fix txpower reporting Nick
2026-02-12  2:46     ` Lucid Duck
2026-03-09 21:50   ` Lucid Duck
2026-03-12  6:38     ` Sean Wang
2026-03-17 17:30       ` [PATCH v3 0/1] wifi: mt76: mt7921: fix txpower reporting from rate power configuration Lucid Duck
2026-03-17 17:30         ` [PATCH v3 1/1] " Lucid Duck
2026-03-17 21:51           ` Lucid Duck
2026-03-19  6:00           ` Sean Wang
2026-03-19 20:38             ` [PATCH v4] " Lucid Duck
2026-03-20  1:17               ` Lucid Duck
2026-03-20  6:34                 ` Greg KH
2026-03-21  8:58               ` Sean Wang
2026-01-30 21:58 ` [PATCH v2] wifi: mt76: mt7921: fix txpower reporting Lucid Duck

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260130215458.52886-1-lucid_duck@justthetip.ca \
    --to=lucid_duck@justthetip.ca \
    --cc=linux-wireless@vger.kernel.org \
    --cc=lorenzo@kernel.org \
    --cc=nbd@nbd.name \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox