From: Sean Wang <sean.wang@kernel.org>
To: nbd@nbd.name, lorenzo.bianconi@kernel.org
Cc: yu-ching.liu@mediatek.com, chengwei.yu@mediatek.com,
jacobs.wu@mediatek.com, posh.sun@mediatek.com,
clifford.hsu@mediatek.com, linux-wireless@vger.kernel.org,
linux-mediatek@lists.infradead.org,
Sean Wang <sean.wang@mediatek.com>
Subject: [PATCH v2 03/19] wifi: mt76: mt7925: add per-peer RX IGTK/BIGTK and RX GTK WTBLs
Date: Mon, 16 Nov 2026 17:16:14 -0600 [thread overview]
Message-ID: <20261116231630.1733906-4-sean.wang@kernel.org> (raw)
In-Reply-To: <20261116231630.1733906-1-sean.wang@kernel.org>
From: Chengwei Yu <chengwei.yu@mediatek.com>
NAN RX group keys are per-peer: each NAN peer can carry an independent
IGTK/BIGTK, and each NAN_DATA peer an independent GTK. Add
nan_rx_igtk_wcid and nan_rx_gtk_wcid to mt792x_sta to hold dedicated
WTBL entries for these keys.
WTBLs are allocated lazily: mt7925_nan_sta_wcids_init() marks both
fields MT792x_WCID_IDX_UNSET at peer-add time, and
mt7925_nan_peer_wcids_free() releases whichever slots were actually
allocated at peer-remove time. Peers that never install a NAN group
key carry zero overhead.
Co-developed-by: Sean Wang <sean.wang@mediatek.com>
Signed-off-by: Sean Wang <sean.wang@mediatek.com>
Signed-off-by: Chengwei Yu <chengwei.yu@mediatek.com>
---
.../net/wireless/mediatek/mt76/mt7925/main.c | 47 +++++++++++++++++++
drivers/net/wireless/mediatek/mt76/mt792x.h | 11 +++++
2 files changed, 58 insertions(+)
diff --git a/drivers/net/wireless/mediatek/mt76/mt7925/main.c b/drivers/net/wireless/mediatek/mt76/mt7925/main.c
index 222836699d15..490507ce97cd 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7925/main.c
+++ b/drivers/net/wireless/mediatek/mt76/mt7925/main.c
@@ -1001,6 +1001,8 @@ mt7925_get_rates_table(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
return mvif->basic_rates_idx;
}
+static void mt7925_nan_sta_wcids_init(struct mt792x_sta *msta);
+
static int mt7925_mac_link_sta_add(struct mt76_dev *mdev,
struct ieee80211_vif *vif,
struct ieee80211_link_sta *link_sta,
@@ -1123,6 +1125,9 @@ static int mt7925_mac_link_sta_add(struct mt76_dev *mdev,
goto out_pm;
}
+ if (vif->type == NL80211_IFTYPE_NAN || vif->type == NL80211_IFTYPE_NAN_DATA)
+ mt7925_nan_sta_wcids_init(msta);
+
mt76_connac_power_save_sched(&dev->mphy, &dev->pm);
return 0;
@@ -1376,6 +1381,45 @@ int mt7925_mac_sta_event(struct mt76_dev *mdev, struct ieee80211_vif *vif,
}
EXPORT_SYMBOL_GPL(mt7925_mac_sta_event);
+/* Mark per-peer NAN group key WTBLs as unallocated at station add time.
+ * Pairs with mt7925_nan_peer_wcids_free() at station remove time.
+ */
+static void mt7925_nan_sta_wcids_init(struct mt792x_sta *msta)
+{
+ msta->nan_rx_gtk_wcid.idx = MT792x_WCID_IDX_UNSET;
+ msta->nan_rx_igtk_wcid.idx = MT792x_WCID_IDX_UNSET;
+}
+
+/* Free a lazily-allocated per-peer NAN group key WTBL and reset its sentinel. */
+static void mt7925_nan_wcid_free(struct mt76_dev *mdev, struct mt76_wcid *wcid)
+{
+ u16 idx = wcid->idx;
+
+ rcu_assign_pointer(mdev->wcid[idx], NULL);
+ mt76_wcid_cleanup(mdev, wcid);
+ mt76_wcid_mask_clear(mdev->wcid_mask, idx);
+ wcid->idx = MT792x_WCID_IDX_UNSET;
+}
+
+/* Release any lazily-allocated per-peer NAN group key WTBLs for a departing
+ * station. Called from mt7925_mac_link_sta_remove() after the primary WTBL
+ * is already freed, so the NAN-specific cleanup is clearly separated from the
+ * generic STA teardown path.
+ */
+static void mt7925_nan_peer_wcids_free(struct mt76_dev *mdev,
+ struct ieee80211_vif *vif,
+ struct ieee80211_sta *sta)
+{
+ struct mt792x_sta *msta = (struct mt792x_sta *)sta->drv_priv;
+
+ if (vif->type == NL80211_IFTYPE_NAN_DATA &&
+ msta->nan_rx_gtk_wcid.idx != MT792x_WCID_IDX_UNSET)
+ mt7925_nan_wcid_free(mdev, &msta->nan_rx_gtk_wcid);
+
+ if (msta->nan_rx_igtk_wcid.idx != MT792x_WCID_IDX_UNSET)
+ mt7925_nan_wcid_free(mdev, &msta->nan_rx_igtk_wcid);
+}
+
static void mt7925_mac_link_sta_remove(struct mt76_dev *mdev,
struct ieee80211_vif *vif,
struct ieee80211_link_sta *link_sta,
@@ -1420,6 +1464,9 @@ static void mt7925_mac_link_sta_remove(struct mt76_dev *mdev,
mt76_wcid_cleanup(mdev, wcid);
mt76_wcid_mask_clear(mdev->wcid_mask, idx);
+ if (vif->type == NL80211_IFTYPE_NAN || vif->type == NL80211_IFTYPE_NAN_DATA)
+ mt7925_nan_peer_wcids_free(mdev, vif, link_sta->sta);
+
mt76_connac_power_save_sched(&dev->mphy, &dev->pm);
}
diff --git a/drivers/net/wireless/mediatek/mt76/mt792x.h b/drivers/net/wireless/mediatek/mt76/mt792x.h
index cc6eb1562b5f..07004066e666 100644
--- a/drivers/net/wireless/mediatek/mt76/mt792x.h
+++ b/drivers/net/wireless/mediatek/mt76/mt792x.h
@@ -18,6 +18,11 @@
#define MT792x_WTBL_SIZE 20
#define MT792x_WTBL_RESERVED (MT792x_WTBL_SIZE - 1)
#define MT792x_WTBL_STA (MT792x_WTBL_RESERVED - MT792x_MAX_INTERFACES)
+/* Sentinel for a lazily-allocated wcid that has not yet been assigned a slot.
+ * U16_MAX is outside every valid alloc range and matches the 0xffff value
+ * used in mt76 DMA ring entries to mark an unused wcid field.
+ */
+#define MT792x_WCID_IDX_UNSET U16_MAX
#define MT792x_CFEND_RATE_DEFAULT 0x49 /* OFDM 24M */
#define MT792x_CFEND_RATE_11B 0x03 /* 11B LP, 11M */
@@ -149,6 +154,12 @@ struct mt792x_sta {
/* NAN peer schedule */
struct mt792x_sta_nan_sched nan_sched;
+
+ /* NAN per-peer group key WTBLs (allocated lazily when keys are installed)
+ * Note: TX GTK is interface-level, see mt792x_vif->nan_tx_gtk_table
+ */
+ struct mt76_wcid nan_rx_gtk_wcid; /* NAN_DATA peer: RX GTK WTBL (per-peer) */
+ struct mt76_wcid nan_rx_igtk_wcid; /* NAN peer: RX IGTK/BIGTK WTBL (per-peer) */
};
DECLARE_EWMA(rssi, 10, 8);
--
2.43.0
next prev parent reply other threads:[~2026-11-16 23:18 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-16 23:16 [PATCH v2 00/19] wifi: mt76: mt7925: add NAN security and improve NDP reliability (part 2) Sean Wang
2026-11-16 23:16 ` [PATCH v2 01/19] wifi: mt76: mt7925: add NAN low power event control on suspend/resume Sean Wang
2026-11-16 23:16 ` [PATCH v2 02/19] wifi: mt76: mt7925: implement NAN key management MCU command Sean Wang
2026-11-16 23:16 ` Sean Wang [this message]
2026-11-16 23:16 ` [PATCH v2 04/19] wifi: mt76: mt7925: implement mt7925_nan_set_key for NAN security Sean Wang
2026-11-16 23:16 ` [PATCH v2 05/19] wifi: mt76: mt7925: install NAN BIP keys standalone in sta_key_tlv Sean Wang
2026-11-16 23:16 ` [PATCH v2 06/19] wifi: mt76: mt7925: do not disable RX NAPI twice on unload Sean Wang
2026-11-16 23:16 ` [PATCH v2 07/19] wifi: mt76: mt7925: assign the interface WTBL to the NAN management TXQ Sean Wang
2026-11-16 23:16 ` [PATCH v2 08/19] wifi: mt76: mt7925: do not deactivate shared NAN BSS on peer STA removal Sean Wang
2026-11-16 23:16 ` [PATCH v2 09/19] wifi: mt76: gate NAN unicast mgmt by peer availability via STA queues Sean Wang
2026-11-16 23:16 ` [PATCH v2 10/19] wifi: mt76: mt7925: hold NAN mgmt TX to the discovery window Sean Wang
2026-11-16 23:16 ` [PATCH v2 11/19] wifi: mt76: mt7925: double the retry budget for NAN unicast management Sean Wang
2026-11-16 23:16 ` [PATCH v2 12/19] wifi: mt76: mt7925: let TX status of DW-held NAN frames outlive the DW period Sean Wang
2026-11-16 23:16 ` [PATCH v2 13/19] wifi: mt76: mt7925: defer the NAN joined-cluster event out of NAN_START Sean Wang
2026-11-16 23:16 ` [PATCH v2 14/19] wifi: mt76: mt7925: steer NAN handshake frames by committed-bitmap state Sean Wang
2026-11-16 23:16 ` [PATCH v2 15/19] wifi: mt76: mt7925: disable only the RX NAPI instances that exist Sean Wang
2026-11-16 23:16 ` [PATCH v2 16/19] wifi: mt76: mt7925: stop queueing resets once the device is being removed Sean Wang
2026-11-16 23:16 ` [PATCH v2 17/19] wifi: mt76: mt7925: bound the lifetime of NAN unicast management frames Sean Wang
2026-11-16 23:16 ` [PATCH v2 18/19] wifi: mt76: mt7925: always deliver the joined-cluster event through the deferred work Sean Wang
2026-11-16 23:16 ` [PATCH v2 19/19] wifi: mt76: mt792x: allow three channels in the NAN combination Sean Wang
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=20261116231630.1733906-4-sean.wang@kernel.org \
--to=sean.wang@kernel.org \
--cc=chengwei.yu@mediatek.com \
--cc=clifford.hsu@mediatek.com \
--cc=jacobs.wu@mediatek.com \
--cc=linux-mediatek@lists.infradead.org \
--cc=linux-wireless@vger.kernel.org \
--cc=lorenzo.bianconi@kernel.org \
--cc=nbd@nbd.name \
--cc=posh.sun@mediatek.com \
--cc=sean.wang@mediatek.com \
--cc=yu-ching.liu@mediatek.com \
/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