[RFC PATCH 06/12] wifi: mac80211: allow drivers to install AP GTK on STA

Johannes Berg <[email protected]> Sat, 1 Aug 2026 09:58:22 +0200
Newsgroups org.kernel.vger.linux-wireless
Message-ID <20260801095822.7c8943c90250.I21a55235891576ac6a4fc303a61455e840f3f53f@changeid>
From: Johannes Berg <[email protected]>

Some drivers (e.g. iwlwifi) may want to install the GTK
on the AP station and not on the interface, so need the
station pointer. Allow them to set a flag to request it
to be passed.

Signed-off-by: Johannes Berg <[email protected]>
---
 include/net/mac80211.h |  4 ++++
 net/mac80211/debugfs.c |  3 ++-
 net/mac80211/key.c     | 19 +++++++++++++------
 3 files changed, 19 insertions(+), 7 deletions(-)

diff --git a/include/net/mac80211.h b/include/net/mac80211.h
index e9006e3a0c32..5bd080d060f4 100644
--- a/include/net/mac80211.h
+++ b/include/net/mac80211.h
@@ -3097,6 +3097,9 @@ struct ieee80211_txq {
  * @IEEE80211_HW_SUPPORTS_NDP_BLOCKACK: HW can transmit/receive S1G NDP
  *	BlockAck frames.
  *
+ * @IEEE80211_HW_PER_STA_AP_GTK: Install GTKs to the AP STA entry instead
+ *	of with %NULL sta.
+ *
  * @NUM_IEEE80211_HW_FLAGS: number of hardware flags, used for sizing arrays
  */
 enum ieee80211_hw_flags {
@@ -3158,6 +3161,7 @@ enum ieee80211_hw_flags {
 	IEEE80211_HW_HANDLES_QUIET_CSA,
 	IEEE80211_HW_STRICT,
 	IEEE80211_HW_SUPPORTS_NDP_BLOCKACK,
+	IEEE80211_HW_PER_STA_AP_GTK,
 
 	/* keep last, obviously */
 	NUM_IEEE80211_HW_FLAGS
diff --git a/net/mac80211/debugfs.c b/net/mac80211/debugfs.c
index 105653a16b68..c854d61fdf59 100644
--- a/net/mac80211/debugfs.c
+++ b/net/mac80211/debugfs.c
@@ -4,7 +4,7 @@
  *
  * Copyright 2007	Johannes Berg <[email protected]>
  * Copyright 2013-2014  Intel Mobile Communications GmbH
- * Copyright (C) 2018 - 2019, 2021-2025 Intel Corporation
+ * Copyright (C) 2018 - 2019, 2021-2026 Intel Corporation
  */
 
 #include <linux/debugfs.h>
@@ -462,6 +462,7 @@ static const char *hw_flag_names[] = {
 	FLAG(HANDLES_QUIET_CSA),
 	FLAG(STRICT),
 	FLAG(SUPPORTS_NDP_BLOCKACK),
+	FLAG(PER_STA_AP_GTK),
 #undef FLAG
 };
 
diff --git a/net/mac80211/key.c b/net/mac80211/key.c
index 0ce2ebfae578..cdc729da0c3f 100644
--- a/net/mac80211/key.c
+++ b/net/mac80211/key.c
@@ -167,8 +167,13 @@ static int ieee80211_key_enable_hw_accel(struct ieee80211_key *key)
 				goto out_unsupported;
 			break;
 		case NL80211_IFTYPE_STATION:
-			/* install group keys w/o STA as we always did */
-			sta = NULL;
+			/*
+			 * unless requested otherwise, NULL out
+			 * the STA for client group keys
+			 */
+			if (!ieee80211_hw_check(&key->local->hw,
+						PER_STA_AP_GTK))
+				sta = NULL;
 			break;
 		default:
 			goto out_unsupported;
@@ -277,9 +282,10 @@ static void ieee80211_key_disable_hw_accel(struct ieee80211_key *key)
 		increment_tailroom_need_count(sdata);
 
 	pubsta = sta ? &sta->sta : NULL;
-	/* for now override STA to NULL for client group keys as before */
+	/* unless requested otherwise, NULL out the STA for client group keys */
 	if (sdata->vif.type == NL80211_IFTYPE_STATION &&
-	    !(key->conf.flags & IEEE80211_KEY_FLAG_PAIRWISE))
+	    !(key->conf.flags & IEEE80211_KEY_FLAG_PAIRWISE) &&
+	    !ieee80211_hw_check(&key->local->hw, PER_STA_AP_GTK))
 		pubsta = NULL;
 
 	key->flags &= ~KEY_FLAG_UPLOADED_TO_HARDWARE;
@@ -1066,9 +1072,10 @@ ieee80211_key_iter(struct ieee80211_hw *hw,
 	if (!(key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE))
 		return;
 
-	/* for now override STA to NULL for client group keys as before */
+	/* unless requested otherwise, NULL out the STA for client group keys */
 	if (vif->type == NL80211_IFTYPE_STATION &&
-	    !(key->conf.flags & IEEE80211_KEY_FLAG_PAIRWISE))
+	    !(key->conf.flags & IEEE80211_KEY_FLAG_PAIRWISE) &&
+	    !ieee80211_hw_check(&key->local->hw, PER_STA_AP_GTK))
 		sta = NULL;
 
 	/* skip keys of station in removal process (if driver knew about STA) */
-- 
2.55.0