From: Felix Fietkau <nbd@nbd.name>
To: linux-wireless@vger.kernel.org
Subject: [PATCH mt76-next 05/16] wifi: mt76: mt7915: count the WA TX statistics from an unsolicited event
Date: Thu, 26 Nov 2026 19:23:14 +0100 [thread overview]
Message-ID: <20261126182325.2516607-5-nbd@nbd.name> (raw)
In-Reply-To: <20261126182325.2516607-1-nbd@nbd.name>
The WA firmware answers the TX statistics query with seq 0, so
mt7915_mcu_parse_response() takes a WA_TX_STAT event as the answer of
any waited command. An answer that arrives after its own wait ended is
taken by the next waited command, whose caller then reads the wrong
payload. Reachable via a station dump with WED active, when the wait
ends at a timeout or an MCU reset.
Count the event as unsolicited and send the query without a wait.
TX_PACKETS of a station dump thus lags by one query. Send no query for a
station index above 255, since the event of the mt7915 chip names only
its low byte.
Fixes: 161a7528e407 ("wifi: mt76: mt7915: rework tx packets counting when WED is active")
Signed-off-by: Felix Fietkau <nbd@nbd.name>
---
.../net/wireless/mediatek/mt76/mt7915/mcu.c | 114 ++++++++----------
1 file changed, 51 insertions(+), 63 deletions(-)
diff --git a/drivers/net/wireless/mediatek/mt76/mt7915/mcu.c b/drivers/net/wireless/mediatek/mt76/mt7915/mcu.c
index 6a19f52d9932..74c632a27c12 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7915/mcu.c
+++ b/drivers/net/wireless/mediatek/mt76/mt7915/mcu.c
@@ -195,9 +195,7 @@ mt7915_mcu_parse_response(struct mt76_dev *mdev, int cmd,
return -EINVAL;
rxd = (struct mt76_connac2_mcu_rxd *)skb->data;
- if (seq != rxd->seq &&
- !(rxd->eid == MCU_CMD_EXT_CID &&
- rxd->ext_eid == MCU_EXT_EVENT_WA_TX_STAT))
+ if (seq != rxd->seq)
return -EAGAIN;
if (cmd == MCU_CMD(PATCH_SEM_CONTROL)) {
@@ -464,6 +462,41 @@ mt7915_mcu_rx_ps_sync(struct mt7915_dev *dev, struct sk_buff *skb)
mt7915_mac_sta_ps_transition(dev, wcid, ps);
}
+static void
+mt7915_mcu_rx_wa_tx_stat(struct mt7915_dev *dev, struct sk_buff *skb)
+{
+ struct mt7915_mcu_wa_tx_stat {
+ __le16 wcid;
+ u8 __rsv2[2];
+
+ /* tx_bytes is deprecated since WA byte counter uses u32,
+ * which easily leads to overflow.
+ */
+ __le32 tx_bytes;
+ __le32 tx_packets;
+ } __packed *res;
+ int offset = sizeof(struct mt76_connac2_mcu_rxd);
+ struct mt76_wcid *wcid;
+ u16 wlan_idx;
+
+ if (!is_mt7915(&dev->mt76))
+ offset += 4;
+
+ if (skb->len < offset + sizeof(*res))
+ return;
+
+ res = (struct mt7915_mcu_wa_tx_stat *)(skb->data + offset);
+ wlan_idx = le16_to_cpu(res->wcid);
+ if (is_mt7915(&dev->mt76))
+ wlan_idx &= 0xff;
+
+ rcu_read_lock();
+ wcid = mt76_wcid_ptr(dev, wlan_idx);
+ if (wcid)
+ wcid->stats.tx_packets += le32_to_cpu(res->tx_packets);
+ rcu_read_unlock();
+}
+
static void
mt7915_mcu_rx_ext_event(struct mt7915_dev *dev, struct sk_buff *skb)
{
@@ -489,6 +522,9 @@ mt7915_mcu_rx_ext_event(struct mt7915_dev *dev, struct sk_buff *skb)
case MCU_EXT_EVENT_PS_SYNC:
mt7915_mcu_rx_ps_sync(dev, skb);
break;
+ case MCU_EXT_EVENT_WA_TX_STAT:
+ mt7915_mcu_rx_wa_tx_stat(dev, skb);
+ break;
default:
break;
}
@@ -515,14 +551,12 @@ void mt7915_mcu_rx_event(struct mt7915_dev *dev, struct sk_buff *skb)
struct mt76_connac2_mcu_rxd *rxd;
rxd = (struct mt76_connac2_mcu_rxd *)skb->data;
- if ((rxd->ext_eid == MCU_EXT_EVENT_THERMAL_PROTECT ||
- rxd->ext_eid == MCU_EXT_EVENT_FW_LOG_2_HOST ||
- rxd->ext_eid == MCU_EXT_EVENT_ASSERT_DUMP ||
- rxd->ext_eid == MCU_EXT_EVENT_PS_SYNC ||
- rxd->ext_eid == MCU_EXT_EVENT_BCC_NOTIFY ||
- !rxd->seq) &&
- !(rxd->eid == MCU_CMD_EXT_CID &&
- rxd->ext_eid == MCU_EXT_EVENT_WA_TX_STAT))
+ if (rxd->ext_eid == MCU_EXT_EVENT_THERMAL_PROTECT ||
+ rxd->ext_eid == MCU_EXT_EVENT_FW_LOG_2_HOST ||
+ rxd->ext_eid == MCU_EXT_EVENT_ASSERT_DUMP ||
+ rxd->ext_eid == MCU_EXT_EVENT_PS_SYNC ||
+ rxd->ext_eid == MCU_EXT_EVENT_BCC_NOTIFY ||
+ !rxd->seq)
mt7915_mcu_rx_unsolicited_event(dev, skb);
else
mt76_mcu_rx_event(&dev->mt76, skb);
@@ -4309,22 +4343,12 @@ int mt7915_mcu_wed_wa_tx_stats(struct mt7915_dev *dev, u16 wlan_idx)
} __packed req = {
.cmd = cpu_to_le32(0x15),
};
- struct mt7915_mcu_wa_tx_stat {
- __le16 wcid;
- u8 __rsv2[2];
-
- /* tx_bytes is deprecated since WA byte counter uses u32,
- * which easily leads to overflow.
- */
- __le32 tx_bytes;
- __le32 tx_packets;
- } __packed *res;
- struct mt76_wcid *wcid;
- struct sk_buff *skb;
- int ret, len, offset;
- u16 ret_wcid;
+ int len;
if (is_mt7915(&dev->mt76)) {
+ if (wlan_idx > 0xff)
+ return -EINVAL;
+
req.arg0 = cpu_to_le32(wlan_idx);
len = sizeof(req) - sizeof(req.arg2);
} else {
@@ -4333,44 +4357,8 @@ int mt7915_mcu_wed_wa_tx_stats(struct mt7915_dev *dev, u16 wlan_idx)
len = sizeof(req);
}
- ret = mt76_mcu_send_and_get_msg(&dev->mt76, MCU_WA_PARAM_CMD(QUERY) |
- MT76_MCU_CMD_READ,
- &req, len, true, &skb);
- if (ret)
- return ret;
-
- offset = is_mt7915(&dev->mt76) ? 0 : 4;
- if (skb->len < offset + sizeof(*res)) {
- dev_kfree_skb(skb);
- return -EINVAL;
- }
-
- skb_pull(skb, offset);
-
- res = (struct mt7915_mcu_wa_tx_stat *)skb->data;
-
- ret_wcid = le16_to_cpu(res->wcid);
- if (is_mt7915(&dev->mt76))
- ret_wcid &= 0xff;
-
- if (ret_wcid != wlan_idx) {
- ret = -EINVAL;
- goto out;
- }
-
- rcu_read_lock();
-
- wcid = mt76_wcid_ptr(dev, wlan_idx);
- if (wcid)
- wcid->stats.tx_packets += le32_to_cpu(res->tx_packets);
- else
- ret = -EINVAL;
-
- rcu_read_unlock();
-out:
- dev_kfree_skb(skb);
-
- return ret;
+ return mt76_mcu_send_msg(&dev->mt76, MCU_WA_PARAM_CMD(QUERY) |
+ MT76_MCU_CMD_READ, &req, len, false);
}
int mt7915_mcu_rf_regval(struct mt7915_dev *dev, u32 regidx, u32 *val, bool set)
--
2.47.3
next prev parent reply other threads:[~2026-11-26 18:23 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-26 18:23 [PATCH mt76-next 01/16] wifi: mt76: keep the Null frame of an AP on its AC queue Felix Fietkau
2026-11-26 18:23 ` [PATCH mt76-next 02/16] wifi: mt76: mt7996: limit the HE and EHT maps of a peer to its rx_nss Felix Fietkau
2026-11-26 18:23 ` [PATCH mt76-next 03/16] wifi: mt76: mt7915: send the current SM power save mode in STA_REC_HT Felix Fietkau
2026-11-26 18:23 ` [PATCH mt76-next 04/16] wifi: mt76: mt7996: take the HE caps of the band of each link Felix Fietkau
2026-11-26 18:23 ` Felix Fietkau [this message]
2026-11-26 18:23 ` [PATCH mt76-next 06/16] wifi: mt76: keep an RX replay counter per group key id and TID Felix Fietkau
2026-11-26 18:23 ` [PATCH mt76-next 07/16] wifi: mt76: mt7996: check the RX PN of group addressed frames Felix Fietkau
2026-11-26 18:23 ` [PATCH mt76-next 08/16] wifi: mt76: mt7615: " Felix Fietkau
2026-11-26 18:23 ` [PATCH mt76-next 09/16] wifi: mt76: mt7615: reset the group RX PN counters at WoWLAN resume Felix Fietkau
2026-11-26 18:23 ` [PATCH mt76-next 10/16] wifi: mt76: mt7915: check the RX PN of group addressed frames Felix Fietkau
2026-11-26 18:23 ` [PATCH mt76-next 11/16] wifi: mt76: mt792x: " Felix Fietkau
2026-11-26 18:23 ` [PATCH mt76-next 12/16] wifi: mt76: mt792x: reset the group RX PN counters at WoWLAN resume Felix Fietkau
2026-11-26 18:23 ` [PATCH mt76-next 13/16] wifi: mt76: mt7603: check the RX PN of group addressed frames Felix Fietkau
2026-11-26 18:23 ` [PATCH mt76-next 14/16] wifi: mt76: mt76x02: find no station for the group wcid of a vif Felix Fietkau
2026-11-26 18:23 ` [PATCH mt76-next 15/16] wifi: mt76: mt7915: stop resets before the hw is unregistered Felix Fietkau
2026-11-26 18:23 ` [PATCH mt76-next 16/16] wifi: mt76: mt7996: " Felix Fietkau
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=20261126182325.2516607-5-nbd@nbd.name \
--to=nbd@nbd.name \
--cc=linux-wireless@vger.kernel.org \
/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