Linux wireless drivers development
 help / color / mirror / Atom feed
From: Josef Schlehofer <pepe.schlehofer@gmail.com>
To: Ping-Ke Shih <pkshih@realtek.com>
Cc: Zong-Zhe Yang <kevin_yang@realtek.com>, linux-wireless@vger.kernel.org
Subject: [PATCH rtw-next v3 3/3] wifi: rtw89: allow AP mode on 6 GHz
Date: Fri,  4 Dec 2026 16:31:21 +0100	[thread overview]
Message-ID: <20261204153121.55841-4-pepe.schlehofer@gmail.com> (raw)
In-Reply-To: <20261204153121.55841-1-pepe.schlehofer@gmail.com>

Since commit f6baa1d3d570 ("wifi: rtw89: process regulatory for 6 GHz
power type") rtw89 refuses to start an AP on 6 GHz. The 6 GHz power
type follows the AP that a station connects to, and nothing selects one
for an AP of its own.

mac80211 sets no power type for an AP. Read it from the HE operation
element of the beacon instead, as cfg80211 does for its regulatory
checks. Allow LPI and VLP when the AP starts, and refuse other power
types. Recalculate the 6 GHz power type when the AP starts, stops,
changes its beacon or leaves 6 GHz, and undo it when starting the AP
fails. If a later beacon has a power type that cannot be used, fall
back to the default power type.

Signed-off-by: Josef Schlehofer <pepe.schlehofer@gmail.com>
---
v3:
- do the 6 GHz recalc in start_ap right before rfk channel. A failed
  recalc and the errors before it return directly.
- fall back to the default power type at BSS_CHANGED_BEACON, which
  drops rtw89_reg_6ghz_recalc_ap() and the __rtw89_reg_6ghz_recalc()
  split

v2:
- reuse reg_6ghz_power, drop ap_reg_power
- read the AP power type in rtw89_reg_6ghz_power_recalc() and handle
  the AP in a sub-function of rtw89_reg_6ghz_recalc(), so mac80211.c
  only calls rtw89_reg_6ghz_recalc()
- return an error from the beacon parser when there is no usable power
  type. reg_6ghz_power cannot mark that case, because
  RTW89_REG_6GHZ_POWER_DFLT equals VLP
- drop the P2P GO check, patch 2 gives a GO its HE capabilities

 drivers/net/wireless/realtek/rtw89/mac80211.c | 25 +++++--
 drivers/net/wireless/realtek/rtw89/regd.c     | 68 ++++++++++++++++++-
 2 files changed, 85 insertions(+), 8 deletions(-)

diff --git a/drivers/net/wireless/realtek/rtw89/mac80211.c b/drivers/net/wireless/realtek/rtw89/mac80211.c
index 98f4b5c98f6..5ddd912577d 100644
--- a/drivers/net/wireless/realtek/rtw89/mac80211.c
+++ b/drivers/net/wireless/realtek/rtw89/mac80211.c
@@ -799,8 +799,13 @@ static void rtw89_ops_link_info_changed(struct ieee80211_hw *hw,
 		WRITE_ONCE(rtwvif_link->sync_bcn_tsf, 0);
 	}
 
-	if (changed & BSS_CHANGED_BEACON)
+	if (changed & BSS_CHANGED_BEACON) {
+		/* a beacon update cannot be refused, fall back to the default power type */
+		if (rtw89_reg_6ghz_recalc(rtwdev, rtwvif_link, true))
+			rtw89_reg_6ghz_recalc(rtwdev, rtwvif_link, false);
+
 		rtw89_chip_h2c_update_beacon(rtwdev, rtwvif_link);
+	}
 
 	if (changed & BSS_CHANGED_ERP_SLOT)
 		rtw89_conf_tx(rtwdev, rtwvif_link);
@@ -828,7 +833,6 @@ static int rtw89_ops_start_ap(struct ieee80211_hw *hw,
 	struct rtw89_dev *rtwdev = hw->priv;
 	struct rtw89_vif *rtwvif = vif_to_rtwvif(vif);
 	struct rtw89_vif_link *rtwvif_link;
-	const struct rtw89_chan *chan;
 	int ret = 0;
 
 	lockdep_assert_wiphy(hw->wiphy);
@@ -841,10 +845,6 @@ static int rtw89_ops_start_ap(struct ieee80211_hw *hw,
 		return -ENOLINK;
 	}
 
-	chan = rtw89_chan_get(rtwdev, rtwvif_link->chanctx_idx);
-	if (chan->band_type == RTW89_BAND_6G)
-		return -EOPNOTSUPP;
-
 	if (rtwdev->scanning)
 		rtw89_hw_scan_abort(rtwdev, rtwdev->scan_info.scanning_vif);
 
@@ -880,17 +880,26 @@ static int rtw89_ops_start_ap(struct ieee80211_hw *hw,
 		return ret;
 	}
 
+	/* must do rtw89_reg_6ghz_recalc() before rfk channel */
+	ret = rtw89_reg_6ghz_recalc(rtwdev, rtwvif_link, true);
+	if (ret)
+		return ret;
+
 	rtw89_chip_rfk_channel(rtwdev, rtwvif_link);
 
 	if (RTW89_CHK_FW_FEATURE(NOTIFY_AP_INFO, &rtwdev->fw)) {
 		ret = rtw89_fw_h2c_ap_info_refcount(rtwdev, true);
 		if (ret)
-			return ret;
+			goto err;
 	}
 
 	rtw89_queue_chanctx_work(rtwdev);
 
 	return 0;
+
+err:
+	rtw89_reg_6ghz_recalc(rtwdev, rtwvif_link, false);
+	return ret;
 }
 
 static
@@ -917,6 +926,8 @@ void rtw89_ops_stop_ap(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
 	rtw89_mac_stop_ap(rtwdev, rtwvif_link);
 	rtw89_chip_h2c_assoc_cmac_tbl(rtwdev, rtwvif_link, NULL);
 	rtw89_fw_h2c_join_info(rtwdev, rtwvif_link, NULL, true);
+
+	rtw89_reg_6ghz_recalc(rtwdev, rtwvif_link, false);
 }
 
 static int rtw89_ops_set_tim(struct ieee80211_hw *hw, struct ieee80211_sta *sta,
diff --git a/drivers/net/wireless/realtek/rtw89/regd.c b/drivers/net/wireless/realtek/rtw89/regd.c
index 82cf78cfc64..dfc827f9802 100644
--- a/drivers/net/wireless/realtek/rtw89/regd.c
+++ b/drivers/net/wireless/realtek/rtw89/regd.c
@@ -1381,16 +1381,73 @@ static bool __rtw89_reg_6ghz_power_recalc(struct rtw89_dev *rtwdev)
 	return true;
 }
 
+/* mac80211 sets no 6 GHz power type for an AP, read it from the beacon */
+static int rtw89_reg_6ghz_ap_power_type(struct rtw89_dev *rtwdev,
+					struct rtw89_vif_link *rtwvif_link,
+					enum ieee80211_ap_reg_power *power_type)
+{
+	const size_t ies_offset = offsetof(struct ieee80211_mgmt, u.beacon.variable);
+	struct ieee80211_vif *vif = rtwvif_link_to_vif(rtwvif_link);
+	const struct ieee80211_he_6ghz_oper *he_6ghz_oper;
+	const struct ieee80211_he_operation *he_oper;
+	enum ieee80211_ap_reg_power type;
+	const struct rtw89_chan *chan;
+	const struct element *elem;
+	struct sk_buff *skb;
+	int ret = -EOPNOTSUPP;
+
+	*power_type = IEEE80211_REG_UNSET_AP;
+
+	chan = rtw89_chan_get(rtwdev, rtwvif_link->chanctx_idx);
+	if (chan->band_type != RTW89_BAND_6G)
+		return 0;
+
+	skb = ieee80211_beacon_get_template(rtwdev->hw, vif, NULL,
+					    rtwvif_link->link_id);
+	if (!skb)
+		return ret;
+
+	if (skb->len < ies_offset)
+		goto out;
+
+	elem = cfg80211_find_ext_elem(WLAN_EID_EXT_HE_OPERATION,
+				      skb->data + ies_offset,
+				      skb->len - ies_offset);
+	if (!elem || elem->datalen < sizeof(*he_oper) + 1 ||
+	    elem->datalen < ieee80211_he_oper_size(elem->data + 1))
+		goto out;
+
+	he_oper = (const void *)&elem->data[1];
+	he_6ghz_oper = ieee80211_he_6ghz_oper(he_oper);
+	if (!he_6ghz_oper)
+		goto out;
+
+	type = cfg80211_6ghz_power_type(he_6ghz_oper->control, 0);
+
+	/* only LPI and VLP are supported for an AP */
+	if (type == IEEE80211_REG_LPI_AP || type == IEEE80211_REG_VLP_AP) {
+		*power_type = type;
+		ret = 0;
+	}
+
+out:
+	dev_kfree_skb_any(skb);
+	return ret;
+}
+
 static int rtw89_reg_6ghz_power_recalc(struct rtw89_dev *rtwdev,
 				       struct rtw89_vif_link *rtwvif_link, bool active,
 				       unsigned int *changed)
 {
 	struct rtw89_regulatory_info *regulatory = &rtwdev->regulatory;
+	struct ieee80211_vif *vif = rtwvif_link_to_vif(rtwvif_link);
 	const struct rtw89_regd *regd = regulatory->regd;
 	bool blocked[NUM_OF_RTW89_REG_6GHZ_POWER] = {};
 	u8 index = rtw89_regd_get_index(rtwdev, regd);
+	enum ieee80211_ap_reg_power power_type;
 	struct ieee80211_bss_conf *bss_conf;
 	bool dflt = false;
+	int ret = 0;
 
 	if (index == RTW89_REGD_MAX_COUNTRY_NUM ||
 	    test_bit(index, regulatory->block_6ghz_vlp))
@@ -1401,7 +1458,13 @@ static int rtw89_reg_6ghz_power_recalc(struct rtw89_dev *rtwdev,
 	bss_conf = rtw89_vif_rcu_dereference_link(rtwvif_link, true);
 
 	if (active) {
-		switch (bss_conf->power_type) {
+		if (vif->type == NL80211_IFTYPE_AP)
+			ret = rtw89_reg_6ghz_ap_power_type(rtwdev, rtwvif_link,
+							   &power_type);
+		else
+			power_type = bss_conf->power_type;
+
+		switch (power_type) {
 		case IEEE80211_REG_VLP_AP:
 			rtwvif_link->reg_6ghz_power = RTW89_REG_6GHZ_POWER_VLP;
 			break;
@@ -1423,6 +1486,9 @@ static int rtw89_reg_6ghz_power_recalc(struct rtw89_dev *rtwdev,
 
 	rcu_read_unlock();
 
+	if (ret)
+		return ret;
+
 	if (!dflt && blocked[rtwvif_link->reg_6ghz_power]) {
 		rtw89_debug(rtwdev, RTW89_DBG_REGD,
 			    "%c%c 6 GHz power type-%u is blocked by policy\n",
-- 
2.54.0 (Apple Git-157)


      parent reply	other threads:[~2026-12-04 15:31 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-04 15:31 [PATCH rtw-next v3 0/3] wifi: rtw89: allow AP mode on 6 GHz Josef Schlehofer
2026-12-04 15:31 ` [PATCH rtw-next v3 1/3] wifi: rtw89: advertise HE 6 GHz antenna pattern consistency Josef Schlehofer
2026-12-04 15:31 ` [PATCH rtw-next v3 2/3] wifi: rtw89: share HE and EHT capabilities with P2P interfaces Josef Schlehofer
2026-12-04 15:31 ` Josef Schlehofer [this message]

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=20261204153121.55841-4-pepe.schlehofer@gmail.com \
    --to=pepe.schlehofer@gmail.com \
    --cc=kevin_yang@realtek.com \
    --cc=linux-wireless@vger.kernel.org \
    --cc=pkshih@realtek.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