diff mbox series

[5/7] mac80211: add support for 6 GHz channels and regulatory

Message ID 20220704102341.5692-6-quic_adisi@quicinc.com
State New
Headers show
Series [1/7] cfg80211: save Power Spectral Density (PSD) of the regulatory rule | expand

Commit Message

Aditya Kumar Singh July 4, 2022, 10:23 a.m. UTC
6 GHz introduces various power modes of operation. Currently, based
on the power mode, channel's Power Spectral Density (PSD)  value as
well as channel disabled flag can change. For single interface,
current implementation works just fine. But for multi-interfaces, for
example AP-STA concurrency, two different channel context needs to be
maintained. This is because, STA power mode also depends on the AP's
power mode it is going to associate with. Hence, PSD value and channel
disabled flag might vary. In this case, same channel context cannot be
used for both AP and STA.

Therefore, to support multiple channel space for each power mode, the
6 GHz channels needs a separate storage space in struct
ieee80211_supported_band. Because of this, the existing APIs to get the
channel/freq from freq/channel will not work for 6 GHz band.

Add support to store all possible 6 GHz channel pools according to the
power mode as well as add API support for getting chan/freq info from
the new struct ieee80211_channel_6ghz.

Signed-off-by: Aditya Kumar Singh <quic_adisi@quicinc.com>
---
 include/net/cfg80211.h   | 31 ++++++++++++++++++++++++++++
 include/net/regulatory.h |  1 +
 net/mac80211/util.c      | 40 +++++++++++++++++++++++++++++++++++-
 net/wireless/reg.c       | 44 +++++++++++++++++++++++++++++++++-------
 net/wireless/util.c      | 27 ++++++++++++++++++++++++
 5 files changed, 135 insertions(+), 8 deletions(-)
diff mbox series

Patch

diff --git a/include/net/cfg80211.h b/include/net/cfg80211.h
index 1e8852c6149f..21c058bec5fe 100644
--- a/include/net/cfg80211.h
+++ b/include/net/cfg80211.h
@@ -512,6 +512,21 @@  struct ieee80211_sta_s1g_cap {
 	u8 nss_mcs[5];
 };
 
+/**
+ * struct ieee80211_channel_6ghz - 6 GHz channel definitions
+ *
+ * This structure defines all the channels supported by the
+ * 6 GHz band.
+ *
+ * @channels: Array of channels the hardware can operate with
+ *      in 6 GHz band.
+ * @n_channels: Number of channels in @channels
+ */
+struct ieee80211_channel_6ghz {
+	struct ieee80211_channel *channels;
+	int n_channels;
+};
+
 /**
  * struct ieee80211_supported_band - frequency band definition
  *
@@ -520,6 +535,7 @@  struct ieee80211_sta_s1g_cap {
  *
  * @channels: Array of channels the hardware can operate with
  *	in this band.
+ * @channels_6ghz: Array of 6 GHz channels the hardware can operate with
  * @band: the band this structure represents
  * @n_channels: Number of channels in @channels
  * @bitrates: Array of bitrates the hardware can operate with
@@ -539,6 +555,8 @@  struct ieee80211_sta_s1g_cap {
  */
 struct ieee80211_supported_band {
 	struct ieee80211_channel *channels;
+	struct ieee80211_channel_6ghz
+			    *channels_6ghz[NL80211_REG_MAX_POWER_MODES + 1];
 	struct ieee80211_rate *bitrates;
 	enum nl80211_band band;
 	int n_channels;
@@ -5943,6 +5961,19 @@  ieee80211_get_channel(struct wiphy *wiphy, int freq)
 	return ieee80211_get_channel_khz(wiphy, MHZ_TO_KHZ(freq));
 }
 
+/**
+ * ieee80211_get_6ghz_channel_khz - get channel struct from wiphy for specified
+ *                                  frequency in 6 GHz band
+ *
+ * @wiphy: the struct wiphy to get the channel for
+ * @freq: the center frequency (in KHz) of the channel
+ * @power_mode: the power mode in which freq is to be operated
+ * Return: The channel struct from @wiphy at @freq.
+ */
+struct ieee80211_channel *
+ieee80211_get_6ghz_channel_khz(struct wiphy *wiphy, u32 freq,
+			       enum nl80211_regulatory_power_modes power_mode);
+
 /**
  * cfg80211_channel_is_psc - Check if the channel is a 6 GHz PSC
  * @chan: control channel to check
diff --git a/include/net/regulatory.h b/include/net/regulatory.h
index ed20004fb6a9..5589c3eb8316 100644
--- a/include/net/regulatory.h
+++ b/include/net/regulatory.h
@@ -218,6 +218,7 @@  struct ieee80211_reg_rule {
 	struct ieee80211_freq_range freq_range;
 	struct ieee80211_power_rule power_rule;
 	struct ieee80211_wmm_rule wmm_rule;
+	enum nl80211_regulatory_power_modes power_mode;
 	u32 flags;
 	u32 dfs_cac_ms;
 	bool has_wmm;
diff --git a/net/mac80211/util.c b/net/mac80211/util.c
index efdea5c2f2db..6a955ef5712c 100644
--- a/net/mac80211/util.c
+++ b/net/mac80211/util.c
@@ -3464,6 +3464,9 @@  bool ieee80211_chandef_he_6ghz_oper(struct ieee80211_sub_if_data *sdata,
 	bool support_80_80, support_160, support_320;
 	u8 he_phy_cap, eht_phy_cap;
 	u32 freq;
+	enum ieee80211_ap_reg_power reg_6ghz_power_beacon, reg_6ghz_ap_power;
+	enum ieee80211_client_reg_power reg_6ghz_client_power;
+	enum nl80211_regulatory_power_modes reg_6ghz_power_final;
 
 	if (chandef->chan->band != NL80211_BAND_6GHZ)
 		return true;
@@ -3506,6 +3509,39 @@  bool ieee80211_chandef_he_6ghz_oper(struct ieee80211_sub_if_data *sdata,
 		return false;
 	}
 
+	/* 6 GHz Power mode present in the beacon */
+	reg_6ghz_power_beacon = u8_get_bits(he_6ghz_oper->control,
+					    IEEE80211_HE_6GHZ_OPER_CTRL_REG_INFO);
+	switch (reg_6ghz_power_beacon) {
+	case IEEE80211_REG_LPI_AP:
+	case IEEE80211_REG_SP_AP:
+	case IEEE80211_REG_VLP_AP:
+		break;
+	default:
+		sdata_info(sdata,
+			   "Invalid Regulatory Info subfield in HE 6 GHz operation, expect issues\n");
+		return false;
+	}
+
+	/* For AP/AP_VLAN/MESH_POINT interfaces, the 6 GHz power mode depends on the
+	 * mode configured by user (LPI/SP/VLP). For other interfaces (for ex STA)
+	 * mode depends on the power mode present in beacon as well as power mode
+	 * configured by the user for that interface
+	 */
+	if (iftype == NL80211_IFTYPE_AP || iftype == NL80211_IFTYPE_AP_VLAN ||
+	    iftype == NL80211_IFTYPE_MESH_POINT) {
+		/* 6 GHz Power mode configured by the user in the config */
+		reg_6ghz_ap_power = sdata->wdev.ap_6ghz_power;
+		reg_6ghz_power_final =
+			ieee80211_ap_reg_power_to_reg_power_mode(reg_6ghz_ap_power);
+	} else {
+		/* 6 GHz Power mode configured by the user in the config */
+		reg_6ghz_client_power = sdata->wdev.client_6ghz_power;
+		reg_6ghz_power_final =
+		     ieee80211_client_reg_power_to_reg_power_mode(reg_6ghz_client_power,
+								  reg_6ghz_power_beacon);
+	}
+
 	/*
 	 * The EHT operation IE does not contain the primary channel so the
 	 * primary channel frequency should be taken from the 6 GHz operation
@@ -3513,7 +3549,9 @@  bool ieee80211_chandef_he_6ghz_oper(struct ieee80211_sub_if_data *sdata,
 	 */
 	freq = ieee80211_channel_to_frequency(he_6ghz_oper->primary,
 					      NL80211_BAND_6GHZ);
-	he_chandef.chan = ieee80211_get_channel(sdata->local->hw.wiphy, freq);
+	he_chandef.chan = ieee80211_get_6ghz_channel_khz(sdata->local->hw.wiphy,
+							 MHZ_TO_KHZ(freq),
+							 reg_6ghz_power_final);
 
 	switch (u8_get_bits(he_6ghz_oper->control,
 			    IEEE80211_HE_6GHZ_OPER_CTRL_REG_INFO)) {
diff --git a/net/wireless/reg.c b/net/wireless/reg.c
index 9a06aadba0d7..fae360afbd65 100644
--- a/net/wireless/reg.c
+++ b/net/wireless/reg.c
@@ -1626,7 +1626,8 @@  static u32 map_regdom_flags(u32 rd_flags)
 
 static const struct ieee80211_reg_rule *
 freq_reg_info_regd(u32 center_freq,
-		   const struct ieee80211_regdomain *regd, u32 bw)
+		   const struct ieee80211_regdomain *regd, u32 bw,
+		   enum nl80211_regulatory_power_modes power_mode)
 {
 	int i;
 	bool band_rule_found = false;
@@ -1640,7 +1641,12 @@  freq_reg_info_regd(u32 center_freq,
 		const struct ieee80211_freq_range *fr = NULL;
 
 		rr = &regd->reg_rules[i];
-		fr = &rr->freq_range;
+
+		if (rr->power_mode == power_mode)
+			fr = &rr->freq_range;
+
+		if (!fr)
+			continue;
 
 		/*
 		 * We only need to know if one frequency rule was
@@ -1672,7 +1678,8 @@  __freq_reg_info(struct wiphy *wiphy, u32 center_freq, u32 min_bw)
 	u32 bw;
 
 	for (bw = MHZ_TO_KHZ(bws[i]); bw >= min_bw; bw = MHZ_TO_KHZ(bws[i--])) {
-		reg_rule = freq_reg_info_regd(center_freq, regd, bw);
+		reg_rule = freq_reg_info_regd(center_freq, regd, bw,
+					      NL80211_REG_AP_LPI);
 		if (!IS_ERR(reg_rule))
 			return reg_rule;
 	}
@@ -2324,7 +2331,8 @@  static void reg_process_ht_flags_channel(struct wiphy *wiphy,
 	if (regd) {
 		const struct ieee80211_reg_rule *reg_rule =
 			freq_reg_info_regd(MHZ_TO_KHZ(channel->center_freq),
-					   regd, MHZ_TO_KHZ(20));
+					   regd, MHZ_TO_KHZ(20),
+					   NL80211_REG_AP_LPI);
 
 		if (!IS_ERR(reg_rule))
 			flags = reg_rule->flags;
@@ -2563,7 +2571,8 @@  static void update_all_wiphy_regulatory(enum nl80211_reg_initiator initiator)
 static void handle_channel_custom(struct wiphy *wiphy,
 				  struct ieee80211_channel *chan,
 				  const struct ieee80211_regdomain *regd,
-				  u32 min_bw)
+				  u32 min_bw,
+				  enum nl80211_regulatory_power_modes power_mode)
 {
 	u32 bw_flags = 0;
 	const struct ieee80211_reg_rule *reg_rule = NULL;
@@ -2572,7 +2581,7 @@  static void handle_channel_custom(struct wiphy *wiphy,
 
 	center_freq_khz = ieee80211_channel_to_khz(chan);
 	for (bw = MHZ_TO_KHZ(20); bw >= min_bw; bw = bw / 2) {
-		reg_rule = freq_reg_info_regd(center_freq_khz, regd, bw);
+		reg_rule = freq_reg_info_regd(center_freq_khz, regd, bw, power_mode);
 		if (!IS_ERR(reg_rule))
 			break;
 	}
@@ -2625,10 +2634,30 @@  static void handle_band_custom(struct wiphy *wiphy,
 			       const struct ieee80211_regdomain *regd)
 {
 	unsigned int i;
+	unsigned int j;
+	bool _6ghz_new_support = false;
 
 	if (!sband)
 		return;
 
+	if (sband->band == NL80211_BAND_6GHZ) {
+		for (i = 0; i < NL80211_REG_MAX_POWER_MODES + 1; i++) {
+			if (!sband->channels_6ghz[i])
+				continue;
+
+			if (!_6ghz_new_support)
+				_6ghz_new_support = true;
+
+			for (j = 0; j < sband->channels_6ghz[i]->n_channels; j++)
+				handle_channel_custom(wiphy,
+						      &sband->channels_6ghz[i]->channels[j],
+						      regd, MHZ_TO_KHZ(20), i);
+		}
+
+		if (_6ghz_new_support)
+			return;
+	}
+
 	/*
 	 * We currently assume that you always want at least 20 MHz,
 	 * otherwise channel 12 might get enabled if this rule is
@@ -2636,7 +2665,8 @@  static void handle_band_custom(struct wiphy *wiphy,
 	 */
 	for (i = 0; i < sband->n_channels; i++)
 		handle_channel_custom(wiphy, &sband->channels[i], regd,
-				      MHZ_TO_KHZ(20));
+				      MHZ_TO_KHZ(20),
+				      NL80211_REG_AP_LPI);
 }
 
 /* Used by drivers prior to wiphy registration */
diff --git a/net/wireless/util.c b/net/wireless/util.c
index cca0ee321a03..38e807e30874 100644
--- a/net/wireless/util.c
+++ b/net/wireless/util.c
@@ -165,6 +165,33 @@  int ieee80211_freq_khz_to_channel(u32 freq)
 }
 EXPORT_SYMBOL(ieee80211_freq_khz_to_channel);
 
+struct ieee80211_channel
+*ieee80211_get_6ghz_channel_khz(struct wiphy *wiphy, u32 freq,
+				enum nl80211_regulatory_power_modes power_mode)
+{
+	struct ieee80211_supported_band *sband;
+	int i;
+	struct ieee80211_channel *chan;
+
+	sband = wiphy->bands[NL80211_BAND_6GHZ];
+
+	if (!sband || power_mode >= NL80211_REG_MAX_POWER_MODES + 1)
+		return NULL;
+
+	if (!sband->channels_6ghz[power_mode])
+		return ieee80211_get_channel_khz(wiphy, freq);
+
+	for (i = 0; i < sband->channels_6ghz[power_mode]->n_channels; i++) {
+		chan = &sband->channels_6ghz[power_mode]->channels[i];
+
+		if (ieee80211_channel_to_khz(chan) == freq)
+			return chan;
+	}
+
+	return NULL;
+}
+EXPORT_SYMBOL(ieee80211_get_6ghz_channel_khz);
+
 struct ieee80211_channel *ieee80211_get_channel_khz(struct wiphy *wiphy,
 						    u32 freq)
 {