From: Felix Fietkau <nbd@nbd.name>
To: linux-wireless@vger.kernel.org
Subject: [PATCH mt76-next 15/20] wifi: mt76: mt7996: keep the TWT state out of the PS flag
Date: Tue, 24 Nov 2026 09:43:04 +0100 [thread overview]
Message-ID: <20261124084309.1981968-15-nbd@nbd.name> (raw)
In-Reply-To: <20261124084309.1981968-1-nbd@nbd.name>
The UNI_PS_CLIENT_INFO entry of the PS sync event is the TWT agreement
state of a station, not its power save state. The firmware sends it at
the add of the first agreement of a station and at the delete of the
last one. It sends no event per service period.
mt7996_mcu_rx_ps_sync() writes it into MT_WCID_FLAG_PS, so the PS
throttle holds a TWT station to one frame per AC for the whole
agreement.
Do not write the entry into the flag. Only a station that is not an MLD
gets an agreement. The firmware reports no PS change of such a station
in TWT operation. It gates the air time of the station between service
periods itself.
Clear the flag at the first agreement instead. A flag set before it
would otherwise stay set for the whole agreement. Also ignore a PS enter
of a station with an agreement. The firmware can deliver an enter that
it stored before the agreement after the clear. After the last
agreement, the flag stays clear until the firmware reports the next PS
change. The host does not know the PS state of the station at that
point.
Set the flow in the mask of the station before the add command. The
firmware gates the air time from the add on, and an enter can arrive
before the command returns. If the command fails, remove the flow from
the mask again.
The PS sync event reads the flow mask of a station without the mutex
that its writers hold. Mark the accesses.
Fixes: 2d16caccd278 ("wifi: mt76: mt7996: handle UNI PS sync events")
Signed-off-by: Felix Fietkau <nbd@nbd.name>
---
drivers/net/wireless/mediatek/mt76/mt7996/mac.c | 11 ++++++++---
drivers/net/wireless/mediatek/mt76/mt7996/main.c | 2 +-
drivers/net/wireless/mediatek/mt76/mt7996/mcu.c | 9 +++++++--
3 files changed, 16 insertions(+), 6 deletions(-)
diff --git a/drivers/net/wireless/mediatek/mt76/mt7996/mac.c b/drivers/net/wireless/mediatek/mt76/mt7996/mac.c
index 1b133d74c175..6d3061c64e30 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7996/mac.c
+++ b/drivers/net/wireless/mediatek/mt76/mt7996/mac.c
@@ -2604,7 +2604,8 @@ mt7996_mac_full_reset(struct mt7996_dev *dev)
msta_link = container_of(flow, struct mt7996_sta_link,
twt.flow[flow->id]);
- msta_link->twt.flowid_mask &= ~BIT(flow->id);
+ WRITE_ONCE(msta_link->twt.flowid_mask,
+ msta_link->twt.flowid_mask & ~BIT(flow->id));
list_del_init(&flow->list);
}
dev->twt.table_mask = 0;
@@ -3413,15 +3414,18 @@ void mt7996_mac_add_twt_setup(struct ieee80211_hw *hw,
}
flow->tsf = le64_to_cpu(twt_agrt->twt);
+ WRITE_ONCE(msta_link->twt.flowid_mask,
+ msta_link->twt.flowid_mask | BIT(flowid));
if (mt7996_mcu_twt_agrt_update(dev, &msta->vif->deflink, flow,
MCU_TWT_AGRT_ADD)) {
+ WRITE_ONCE(msta_link->twt.flowid_mask,
+ msta_link->twt.flowid_mask & ~BIT(flowid));
list_del(&flow->list);
goto unlock;
}
setup_cmd = TWT_SETUP_CMD_ACCEPT;
dev->twt.table_mask |= BIT(table_id);
- msta_link->twt.flowid_mask |= BIT(flowid);
dev->twt.n_agrt++;
unlock:
@@ -3453,7 +3457,8 @@ void mt7996_mac_twt_teardown_flow(struct mt7996_dev *dev,
return;
list_del_init(&flow->list);
- msta_link->twt.flowid_mask &= ~BIT(flowid);
+ WRITE_ONCE(msta_link->twt.flowid_mask,
+ msta_link->twt.flowid_mask & ~BIT(flowid));
dev->twt.table_mask &= ~BIT(flow->table_id);
dev->twt.n_agrt--;
}
diff --git a/drivers/net/wireless/mediatek/mt76/mt7996/main.c b/drivers/net/wireless/mediatek/mt76/mt7996/main.c
index e129cd2cd73e..3486781609e3 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7996/main.c
+++ b/drivers/net/wireless/mediatek/mt76/mt7996/main.c
@@ -2025,7 +2025,7 @@ mt7996_mac_sta_remove(struct mt7996_dev *dev, struct ieee80211_vif *vif,
if (msta_link->twt.flowid_mask & BIT(i))
list_del_init(&msta_link->twt.flow[i].list);
}
- msta_link->twt.flowid_mask = 0;
+ WRITE_ONCE(msta_link->twt.flowid_mask, 0);
for (i = 0; i < ARRAY_SIZE(msta->link); i++)
mt7996_mac_sta_remove_link(dev, sta, i, true);
diff --git a/drivers/net/wireless/mediatek/mt76/mt7996/mcu.c b/drivers/net/wireless/mediatek/mt76/mt7996/mcu.c
index 599bc6735c30..91129c1f5a5e 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7996/mcu.c
+++ b/drivers/net/wireless/mediatek/mt76/mt7996/mcu.c
@@ -915,12 +915,17 @@ mt7996_mcu_wed_rro_event(struct mt7996_dev *dev, struct sk_buff *skb)
static void
mt7996_mcu_ps_transition(struct mt7996_dev *dev, u16 wcid_idx, bool ps)
{
+ struct mt7996_sta_link *msta_link;
struct mt76_wcid *wcid;
wcid = mt76_wcid_ptr(dev, wcid_idx);
if (!wcid || !wcid_to_sta(wcid))
return;
+ msta_link = container_of(wcid, struct mt7996_sta_link, wcid);
+ if (ps && READ_ONCE(msta_link->twt.flowid_mask))
+ return;
+
mt76_sta_ps_transition(&dev->mt76, wcid, ps);
}
@@ -951,12 +956,12 @@ mt7996_mcu_rx_ps_sync(struct mt7996_dev *dev, struct sk_buff *skb)
case UNI_PS_CLIENT_INFO: {
struct mt7996_mcu_ps_client_info *info = (void *)tlv;
- if (tag_len < sizeof(*info))
+ if (tag_len < sizeof(*info) || !info->ps_bit)
break;
mt7996_mcu_ps_transition(dev,
le16_to_cpu(info->wlan_idx),
- info->ps_bit);
+ false);
break;
}
case UNI_PS_MULTI_CLIENT_INFO: {
--
2.47.3
next prev parent reply other threads:[~2026-11-24 8:43 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-24 8:42 [PATCH mt76-next 01/20] wifi: mt76: mt7915: dump the firmware memory of mt7916 Felix Fietkau
2026-11-24 8:42 ` [PATCH mt76-next 02/20] wifi: mt76: mt7915: set the LED GPIO mux " Felix Fietkau
2026-11-24 8:53 ` Lorenzo Bianconi
2026-11-24 8:42 ` [PATCH mt76-next 03/20] wifi: mt76: fail an MCU command started during an MCU reset Felix Fietkau
2026-11-24 8:54 ` Lorenzo Bianconi
2026-11-24 8:42 ` [PATCH mt76-next 04/20] wifi: mt76: mark an MCU command that only reads Felix Fietkau
2026-11-24 8:42 ` [PATCH mt76-next 05/20] wifi: mt76: retry only an MCU command that reads Felix Fietkau
2026-11-24 8:42 ` [PATCH mt76-next 06/20] wifi: mt76: report an MCU command whose outcome is unknown Felix Fietkau
2026-11-24 8:42 ` [PATCH mt76-next 07/20] wifi: mt76: mt7996: mark the MCU commands that only read Felix Fietkau
2026-11-24 8:42 ` [PATCH mt76-next 08/20] wifi: mt76: mt7996: reset after an MCU reset lost a state command Felix Fietkau
2026-11-24 8:42 ` [PATCH mt76-next 09/20] wifi: mt76: mt7915: mark the MCU commands that only read Felix Fietkau
2026-11-24 8:42 ` [PATCH mt76-next 10/20] wifi: mt76: mt7915: hold the device mutex in the rate control work Felix Fietkau
2026-11-24 8:56 ` Lorenzo Bianconi
2026-11-24 8:43 ` [PATCH mt76-next 11/20] wifi: mt76: mt7915: hold the device mutex in the station and regd updates Felix Fietkau
2026-11-24 8:58 ` Lorenzo Bianconi
2026-11-24 8:43 ` [PATCH mt76-next 12/20] wifi: mt76: mt7915: reset after an MCU reset lost a state command Felix Fietkau
2026-11-24 8:43 ` [PATCH mt76-next 13/20] wifi: mt76: mt7996: clear the PS state of stations at a reset Felix Fietkau
2026-11-24 8:43 ` [PATCH mt76-next 14/20] wifi: mt76: mt7996: apply the PS sync bitmap to MLD stations alone Felix Fietkau
2026-11-24 8:43 ` Felix Fietkau [this message]
2026-11-24 8:43 ` [PATCH mt76-next 16/20] wifi: mt76: mt7996: read the TSF twice against the firmware's latch Felix Fietkau
2026-11-24 8:43 ` [PATCH mt76-next 17/20] wifi: mt76: mt7996: check a TSF write " Felix Fietkau
2026-11-24 8:43 ` [PATCH mt76-next 18/20] wifi: mt76: mt7915: keep the TWT state out of the PS flag Felix Fietkau
2026-11-24 8:43 ` [PATCH mt76-next 19/20] wifi: mt76: mt7915: clear the PS flag of a station at a reset Felix Fietkau
2026-11-24 8:43 ` [PATCH mt76-next 20/20] wifi: mt76: mt7996: set the default link again when a link is reused Felix Fietkau
2026-11-24 8:53 ` [PATCH mt76-next 01/20] wifi: mt76: mt7915: dump the firmware memory of mt7916 Lorenzo Bianconi
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=20261124084309.1981968-15-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