diff mbox series

[v3,2/9] wifi: cfg80211: save Power Spectral Density (PSD) of the regulatory rule

Message ID 20230315132904.31779-3-quic_adisi@quicinc.com
State New
Headers show
Series wifi: cfg80211/mac80211: extend 6 GHz support for all power modes | expand

Commit Message

Aditya Kumar Singh March 15, 2023, 1:28 p.m. UTC
From: Wen Gong <quic_wgong@quicinc.com>

6 GHz regulatory domains introduces Power Spectral Density (PSD).
The PSD value of the regulatory rule should be taken into effect
for the ieee80211_channels falling into that particular regulatory
rule. Save the values in the channel which has PSD value and add
nl80211 attributes accordingly to handle it.

Signed-off-by: Wen Gong <quic_wgong@quicinc.com>
Co-developed-by: Aditya Kumar Singh <quic_adisi@quicinc.com>
Signed-off-by: Aditya Kumar Singh <quic_adisi@quicinc.com>
---
 include/net/cfg80211.h       |  5 +++++
 include/net/regulatory.h     |  1 +
 include/uapi/linux/nl80211.h |  9 +++++++++
 net/wireless/nl80211.c       | 18 ++++++++++++++++++
 net/wireless/reg.c           | 17 +++++++++++++++++
 5 files changed, 50 insertions(+)

Comments

Johannes Berg Sept. 13, 2023, 2:58 p.m. UTC | #1
On Wed, 2023-03-15 at 18:58 +0530, Aditya Kumar Singh wrote:

> @@ -8650,6 +8660,14 @@ static int parse_reg_rule(struct nlattr *tb[],
>  
>  	reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]);
>  
> +	if (reg_rule->flags & NL80211_RRF_PSD) {
> +		if (!tb[NL80211_ATTR_POWER_RULE_PSD])
> +			return -EINVAL;
> +
> +		reg_rule->psd =
> +			nla_get_s8(tb[NL80211_ATTR_POWER_RULE_PSD]);
> +	}

Wait ... I'm not sure why we've been adding stuff to this recently, but
anyway, this part should only be used by CRDA which is deprecated
anyway?

So I'd say we shouldn't touch any of the code under #ifdef
CONFIG_CFG80211_CRDA_SUPPORT any more since CRDA will not continue to
developed with any updates here.

johannes
Jeff Johnson Sept. 14, 2023, 3:15 a.m. UTC | #2
On 9/13/2023 7:58 AM, Johannes Berg wrote:
> So I'd say we shouldn't touch any of the code under #ifdef
> CONFIG_CFG80211_CRDA_SUPPORT any more since CRDA will not continue to
> developed with any updates here.

On a related note, what will happen to ongoing wireless-regdb support 
now that Seth has stepped down as maintainer? Have enough vendors moved 
to self-managed such that regdb is obsolete?
Wen Gong Sept. 14, 2023, 3:45 a.m. UTC | #3
On 9/13/2023 10:58 PM, Johannes Berg wrote:
> On Wed, 2023-03-15 at 18:58 +0530, Aditya Kumar Singh wrote:
>
>> @@ -8650,6 +8660,14 @@ static int parse_reg_rule(struct nlattr *tb[],
>>   
>>   	reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]);
>>   
>> +	if (reg_rule->flags & NL80211_RRF_PSD) {
>> +		if (!tb[NL80211_ATTR_POWER_RULE_PSD])
>> +			return -EINVAL;
>> +
>> +		reg_rule->psd =
>> +			nla_get_s8(tb[NL80211_ATTR_POWER_RULE_PSD]);
>> +	}
> Wait ... I'm not sure why we've been adding stuff to this recently, but
> anyway, this part should only be used by CRDA which is deprecated
> anyway?
>
> So I'd say we shouldn't touch any of the code under #ifdef
> CONFIG_CFG80211_CRDA_SUPPORT any more since CRDA will not continue to
> developed with any updates here.
>
> johannes
Oh, I will remove the change in parse_reg_rule() in next version, because
you asked me to add change in 2 
functions(nl80211_put_regdom()/nl80211_msg_put_channel())
below, but I added change in one more function(parse_reg_rule()).

https://lore.kernel.org/linux-wireless/a4e56dbbe88771456bcf3051a0891d66d5e34fd4.camel@sipsolutions.net/
Wen Gong Sept. 14, 2023, 3:59 a.m. UTC | #4
On 9/14/2023 11:15 AM, Jeff Johnson wrote:
> On 9/13/2023 7:58 AM, Johannes Berg wrote:
>> So I'd say we shouldn't touch any of the code under #ifdef
>> CONFIG_CFG80211_CRDA_SUPPORT any more since CRDA will not continue to
>> developed with any updates here.
>
> On a related note, what will happen to ongoing wireless-regdb support 
> now that Seth has stepped down as maintainer? Have enough vendors 
> moved to self-managed such that regdb is obsolete?
currently ath10k chips are not self-managed.
Johannes Berg Sept. 14, 2023, 7:18 a.m. UTC | #5
On Thu, 2023-09-14 at 11:45 +0800, Wen Gong wrote:
> On 9/13/2023 10:58 PM, Johannes Berg wrote:
> > On Wed, 2023-03-15 at 18:58 +0530, Aditya Kumar Singh wrote:
> > 
> > > @@ -8650,6 +8660,14 @@ static int parse_reg_rule(struct nlattr *tb[],
> > >   
> > >   	reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]);
> > >   
> > > +	if (reg_rule->flags & NL80211_RRF_PSD) {
> > > +		if (!tb[NL80211_ATTR_POWER_RULE_PSD])
> > > +			return -EINVAL;
> > > +
> > > +		reg_rule->psd =
> > > +			nla_get_s8(tb[NL80211_ATTR_POWER_RULE_PSD]);
> > > +	}
> > Wait ... I'm not sure why we've been adding stuff to this recently, but
> > anyway, this part should only be used by CRDA which is deprecated
> > anyway?
> > 
> > So I'd say we shouldn't touch any of the code under #ifdef
> > CONFIG_CFG80211_CRDA_SUPPORT any more since CRDA will not continue to
> > developed with any updates here.
> > 
> > johannes
> Oh, I will remove the change in parse_reg_rule() in next version, because
> you asked me to add change in 2 
> functions(nl80211_put_regdom()/nl80211_msg_put_channel())
> below, but I added change in one more function(parse_reg_rule()).
> 

Yes, we should have visibility on the output - but I don't think we ever
expect the input to carry it this way via nl80211 since that's long
deprecated in favour of the kernel loading it as a 'firmware' file.

johannes
Chen-Yu Tsai Dec. 22, 2023, 3:57 a.m. UTC | #6
On Thu, Sep 14, 2023 at 11:15 AM Jeff Johnson <quic_jjohnson@quicinc.com> wrote:
>
> On 9/13/2023 7:58 AM, Johannes Berg wrote:
> > So I'd say we shouldn't touch any of the code under #ifdef
> > CONFIG_CFG80211_CRDA_SUPPORT any more since CRDA will not continue to
> > developed with any updates here.
>
> On a related note, what will happen to ongoing wireless-regdb support
> now that Seth has stepped down as maintainer? Have enough vendors moved
> to self-managed such that regdb is obsolete?

I've picked up maintainership for wireless-regdb.

ChenYu
Kalle Valo Dec. 22, 2023, 8:08 a.m. UTC | #7
Chen-Yu Tsai <wens@kernel.org> writes:

> On Thu, Sep 14, 2023 at 11:15 AM Jeff Johnson <quic_jjohnson@quicinc.com> wrote:
>>
>> On 9/13/2023 7:58 AM, Johannes Berg wrote:
>> > So I'd say we shouldn't touch any of the code under #ifdef
>> > CONFIG_CFG80211_CRDA_SUPPORT any more since CRDA will not continue to
>> > developed with any updates here.
>>
>> On a related note, what will happen to ongoing wireless-regdb support
>> now that Seth has stepped down as maintainer? Have enough vendors moved
>> to self-managed such that regdb is obsolete?
>
> I've picked up maintainership for wireless-regdb.

Chen-Yu, sorry that I haven't been able to comment anything earlier but
I want to thank you for taking the role. And big thanks to Seth for
maintaining regdb for all these years!
diff mbox series

Patch

diff --git a/include/net/cfg80211.h b/include/net/cfg80211.h
index 7cebba1c4135..d64481d8d871 100644
--- a/include/net/cfg80211.h
+++ b/include/net/cfg80211.h
@@ -115,6 +115,8 @@  struct wiphy;
  *	This may be due to the driver or due to regulatory bandwidth
  *	restrictions.
  * @IEEE80211_CHAN_NO_EHT: EHT operation is not permitted on this channel.
+ * @IEEE80211_CHAN_PSD: power spectral density (in dBm)
+ *	on this channel
  */
 enum ieee80211_channel_flags {
 	IEEE80211_CHAN_DISABLED		= 1<<0,
@@ -138,6 +140,7 @@  enum ieee80211_channel_flags {
 	IEEE80211_CHAN_16MHZ		= 1<<18,
 	IEEE80211_CHAN_NO_320MHZ	= 1<<19,
 	IEEE80211_CHAN_NO_EHT		= 1<<20,
+	IEEE80211_CHAN_PSD              = 1<<21,
 };
 
 #define IEEE80211_CHAN_NO_HT40 \
@@ -171,6 +174,7 @@  enum ieee80211_channel_flags {
  *	on this channel.
  * @dfs_state_entered: timestamp (jiffies) when the dfs state was entered.
  * @dfs_cac_ms: DFS CAC time in milliseconds, this is valid for DFS channels.
+ * @psd: power spectral density (in dBm)
  */
 struct ieee80211_channel {
 	enum nl80211_band band;
@@ -187,6 +191,7 @@  struct ieee80211_channel {
 	enum nl80211_dfs_state dfs_state;
 	unsigned long dfs_state_entered;
 	unsigned int dfs_cac_ms;
+	s8 psd;
 };
 
 /**
diff --git a/include/net/regulatory.h b/include/net/regulatory.h
index 896191f420d5..c2bf0b39fd1e 100644
--- a/include/net/regulatory.h
+++ b/include/net/regulatory.h
@@ -224,6 +224,7 @@  struct ieee80211_reg_rule {
 	u32 flags;
 	u32 dfs_cac_ms;
 	bool has_wmm;
+	s8 psd;
 };
 
 struct ieee80211_regdomain {
diff --git a/include/uapi/linux/nl80211.h b/include/uapi/linux/nl80211.h
index 9a0ac0363f1f..844d2000b4e1 100644
--- a/include/uapi/linux/nl80211.h
+++ b/include/uapi/linux/nl80211.h
@@ -4167,6 +4167,8 @@  enum nl80211_wmm_rule {
  *	as the primary or any of the secondary channels isn't possible
  * @NL80211_FREQUENCY_ATTR_NO_EHT: EHT operation is not allowed on this channel
  *	in current regulatory domain.
+ * @NL80211_FREQUENCY_ATTR_PSD: power spectral density (in dBm)
+ *	is allowed on this channel in current regulatory domain.
  * @NL80211_FREQUENCY_ATTR_MAX: highest frequency attribute number
  *	currently defined
  * @__NL80211_FREQUENCY_ATTR_AFTER_LAST: internal use
@@ -4205,6 +4207,7 @@  enum nl80211_frequency_attr {
 	NL80211_FREQUENCY_ATTR_16MHZ,
 	NL80211_FREQUENCY_ATTR_NO_320MHZ,
 	NL80211_FREQUENCY_ATTR_NO_EHT,
+	NL80211_FREQUENCY_ATTR_PSD,
 
 	/* keep last */
 	__NL80211_FREQUENCY_ATTR_AFTER_LAST,
@@ -4305,6 +4308,8 @@  enum nl80211_reg_type {
  * 	a given frequency range. The value is in mBm (100 * dBm).
  * @NL80211_ATTR_DFS_CAC_TIME: DFS CAC time in milliseconds.
  *	If not present or 0 default CAC time will be used.
+ * @NL80211_ATTR_POWER_RULE_PSD: power spectral density (in dBm).
+ *	This could be negative.
  * @NL80211_REG_RULE_ATTR_MAX: highest regulatory rule attribute number
  *	currently defined
  * @__NL80211_REG_RULE_ATTR_AFTER_LAST: internal use
@@ -4322,6 +4327,8 @@  enum nl80211_reg_rule_attr {
 
 	NL80211_ATTR_DFS_CAC_TIME,
 
+	NL80211_ATTR_POWER_RULE_PSD,
+
 	/* keep last */
 	__NL80211_REG_RULE_ATTR_AFTER_LAST,
 	NL80211_REG_RULE_ATTR_MAX = __NL80211_REG_RULE_ATTR_AFTER_LAST - 1
@@ -4404,6 +4411,7 @@  enum nl80211_sched_scan_match_attr {
  * @NL80211_RRF_NO_160MHZ: 160MHz operation not allowed
  * @NL80211_RRF_NO_HE: HE operation not allowed
  * @NL80211_RRF_NO_320MHZ: 320MHz operation not allowed
+ * @NL80211_RRF_PSD: channels has power spectral density value
  */
 enum nl80211_reg_rule_flags {
 	NL80211_RRF_NO_OFDM		= 1<<0,
@@ -4423,6 +4431,7 @@  enum nl80211_reg_rule_flags {
 	NL80211_RRF_NO_160MHZ		= 1<<16,
 	NL80211_RRF_NO_HE		= 1<<17,
 	NL80211_RRF_NO_320MHZ		= 1<<18,
+	NL80211_RRF_PSD                 = 1<<19,
 };
 
 #define NL80211_RRF_PASSIVE_SCAN	NL80211_RRF_NO_IR
diff --git a/net/wireless/nl80211.c b/net/wireless/nl80211.c
index 0a31b1d2845d..1e8fe560078f 100644
--- a/net/wireless/nl80211.c
+++ b/net/wireless/nl80211.c
@@ -1106,6 +1106,10 @@  static int nl80211_msg_put_channel(struct sk_buff *msg, struct wiphy *wiphy,
 	if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_OFFSET, chan->freq_offset))
 		goto nla_put_failure;
 
+	if ((chan->flags & IEEE80211_CHAN_PSD) &&
+	    nla_put_s8(msg, NL80211_FREQUENCY_ATTR_PSD, chan->psd))
+		goto nla_put_failure;
+
 	if ((chan->flags & IEEE80211_CHAN_DISABLED) &&
 	    nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED))
 		goto nla_put_failure;
@@ -8456,6 +8460,11 @@  static int nl80211_put_regdom(const struct ieee80211_regdomain *regdom,
 				reg_rule->dfs_cac_ms))
 			goto nla_put_failure;
 
+		if ((reg_rule->flags & NL80211_RRF_PSD) &&
+		    nla_put_s8(msg, NL80211_ATTR_POWER_RULE_PSD,
+			       reg_rule->psd))
+			goto nla_put_failure;
+
 		nla_nest_end(msg, nl_reg_rule);
 	}
 
@@ -8629,6 +8638,7 @@  static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] =
 	[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]	= { .type = NLA_U32 },
 	[NL80211_ATTR_POWER_RULE_MAX_EIRP]	= { .type = NLA_U32 },
 	[NL80211_ATTR_DFS_CAC_TIME]		= { .type = NLA_U32 },
+	[NL80211_ATTR_POWER_RULE_PSD]		= { .type = NLA_S8 },
 };
 
 static int parse_reg_rule(struct nlattr *tb[],
@@ -8650,6 +8660,14 @@  static int parse_reg_rule(struct nlattr *tb[],
 
 	reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]);
 
+	if (reg_rule->flags & NL80211_RRF_PSD) {
+		if (!tb[NL80211_ATTR_POWER_RULE_PSD])
+			return -EINVAL;
+
+		reg_rule->psd =
+			nla_get_s8(tb[NL80211_ATTR_POWER_RULE_PSD]);
+	}
+
 	freq_range->start_freq_khz =
 		nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]);
 	freq_range->end_freq_khz =
diff --git a/net/wireless/reg.c b/net/wireless/reg.c
index 0d40d6af7e10..452e0085ed2c 100644
--- a/net/wireless/reg.c
+++ b/net/wireless/reg.c
@@ -1587,6 +1587,8 @@  static u32 map_regdom_flags(u32 rd_flags)
 		channel_flags |= IEEE80211_CHAN_NO_HE;
 	if (rd_flags & NL80211_RRF_NO_320MHZ)
 		channel_flags |= IEEE80211_CHAN_NO_320MHZ;
+	if (rd_flags & NL80211_RRF_PSD)
+		channel_flags |= IEEE80211_CHAN_PSD;
 	return channel_flags;
 }
 
@@ -1793,6 +1795,9 @@  static void handle_channel_single_rule(struct wiphy *wiphy,
 				chan->dfs_cac_ms = reg_rule->dfs_cac_ms;
 		}
 
+		if (chan->flags & IEEE80211_CHAN_PSD)
+			chan->psd = reg_rule->psd;
+
 		return;
 	}
 
@@ -1813,6 +1818,9 @@  static void handle_channel_single_rule(struct wiphy *wiphy,
 			chan->dfs_cac_ms = IEEE80211_DFS_MIN_CAC_TIME_MS;
 	}
 
+	if (chan->flags & IEEE80211_CHAN_PSD)
+		chan->psd = reg_rule->psd;
+
 	if (chan->orig_mpwr) {
 		/*
 		 * Devices that use REGULATORY_COUNTRY_IE_FOLLOW_POWER
@@ -1882,6 +1890,12 @@  static void handle_channel_adjacent_rules(struct wiphy *wiphy,
 							 rrule2->dfs_cac_ms);
 		}
 
+		if ((rrule1->flags & NL80211_RRF_PSD) &&
+		    (rrule2->flags & NL80211_RRF_PSD))
+			chan->psd = min_t(s8, rrule1->psd, rrule2->psd);
+		else
+			chan->flags &= ~NL80211_RRF_PSD;
+
 		return;
 	}
 
@@ -2572,6 +2586,9 @@  static void handle_channel_custom(struct wiphy *wiphy,
 			chan->dfs_cac_ms = IEEE80211_DFS_MIN_CAC_TIME_MS;
 	}
 
+	if (chan->flags & IEEE80211_CHAN_PSD)
+		chan->psd = reg_rule->psd;
+
 	chan->max_power = chan->max_reg_power;
 }