]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
wifi: cfg80211: Add Support to Set RTS Threshold for each Radio
authorRoopni Devanathan <quic_rdevanat@quicinc.com>
Sun, 15 Jun 2025 08:23:10 +0000 (13:53 +0530)
committerJohannes Berg <johannes.berg@intel.com>
Tue, 24 Jun 2025 13:19:27 +0000 (15:19 +0200)
Currently, setting RTS threshold is based on per-phy basis, i.e., all the
radios present in a wiphy will take RTS threshold value to be the one sent
from userspace. But each radio in a multi-radio wiphy can have different
RTS threshold requirements.

To extend support to set RTS threshold for each radio, get the radio for
which RTS threshold needs to be changed from the user. Use the attribute
in NL - NL80211_ATTR_WIPHY_RADIO_INDEX, to identify the radio of interest.
Create a new structure - wiphy_radio_cfg and add rts_threshold in it as a
u32 value to store RTS threshold of each radio in a wiphy and allocate
memory for it during wiphy register based on the wiphy.n_radio updated by
drivers. Pass radio id received from the user to mac80211 drivers along
with its corresponding RTS threshold.

Signed-off-by: Roopni Devanathan <quic_rdevanat@quicinc.com>
Link: https://patch.msgid.link/20250615082312.619639-3-quic_rdevanat@quicinc.com
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
include/net/cfg80211.h
net/wireless/core.c
net/wireless/nl80211.c

index ffd9564fc840eacde79ade0f51e06e7a559acd2b..0003733b1e77082aa7fcaa91f052dc233e34bff6 100644 (file)
@@ -5547,6 +5547,18 @@ struct wiphy_iftype_akm_suites {
        int n_akm_suites;
 };
 
+/**
+ * struct wiphy_radio_cfg - physical radio config of a wiphy
+ * This structure describes the configurations of a physical radio in a
+ * wiphy. It is used to denote per-radio attributes belonging to a wiphy.
+ *
+ * @rts_threshold: RTS threshold (dot11RTSThreshold);
+ *     -1 (default) = RTS/CTS disabled
+ */
+struct wiphy_radio_cfg {
+       u32 rts_threshold;
+};
+
 /**
  * struct wiphy_radio_freq_range - wiphy frequency range
  * @start_freq:  start range edge frequency (kHz)
@@ -5802,6 +5814,10 @@ struct wiphy_radio {
  *     supports enabling HW timestamping for all peers (i.e. no need to
  *     specify a mac address).
  *
+ * @radio_cfg: configuration of radios belonging to a muli-radio wiphy. This
+ *     struct contains a list of all radio specific attributes and should be
+ *     used only for multi-radio wiphy.
+ *
  * @radio: radios belonging to this wiphy
  * @n_radio: number of radios
  */
@@ -5891,6 +5907,8 @@ struct wiphy {
        void (*reg_notifier)(struct wiphy *wiphy,
                             struct regulatory_request *request);
 
+       struct wiphy_radio_cfg *radio_cfg;
+
        /* fields below are read-only, assigned by cfg80211 */
 
        const struct ieee80211_regdomain __rcu *regd;
index 5c3c72df0591c6e32d64f7d4e10c07339f3f72c7..f3cd70757ef280a1ecc125eedd4c051e62663491 100644 (file)
@@ -995,6 +995,24 @@ int wiphy_register(struct wiphy *wiphy)
                 wiphy->max_num_akm_suites > CFG80211_MAX_NUM_AKM_SUITES)
                return -EINVAL;
 
+       /* Allocate radio configuration space for multi-radio wiphy */
+       if (wiphy->n_radio > 0) {
+               int idx;
+
+               wiphy->radio_cfg = kcalloc(wiphy->n_radio,
+                                          sizeof(*wiphy->radio_cfg),
+                                          GFP_KERNEL);
+               if (!wiphy->radio_cfg)
+                       return -ENOMEM;
+               /*
+                * Initialize wiphy radio parameters to IEEE 802.11
+                * MIB default values. RTS threshold is disabled by
+                * default with the special -1 value.
+                */
+               for (idx = 0; idx < wiphy->n_radio; idx++)
+                       wiphy->radio_cfg[idx].rts_threshold = (u32)-1;
+       }
+
        /* check and set up bitrates */
        ieee80211_set_bitrate_flags(wiphy);
 
@@ -1222,6 +1240,7 @@ void cfg80211_dev_free(struct cfg80211_registered_device *rdev)
 
 void wiphy_free(struct wiphy *wiphy)
 {
+       kfree(wiphy->radio_cfg);
        put_device(&wiphy->dev);
 }
 EXPORT_SYMBOL(wiphy_free);
index b409785497905892410bfec678ce09a0d2dba217..b0176090182ca090abcd3caa8119323ce0b8fb9f 100644 (file)
@@ -3609,6 +3609,33 @@ static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info)
        return __nl80211_set_channel(rdev, netdev, info, link_id);
 }
 
+static int nl80211_set_wiphy_radio(struct genl_info *info,
+                                  struct cfg80211_registered_device *rdev,
+                                  int radio_idx)
+{
+       u32 rts_threshold = 0, old_rts, changed = 0;
+       int result;
+
+       if (!rdev->ops->set_wiphy_params)
+               return -EOPNOTSUPP;
+
+       if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) {
+               rts_threshold = nla_get_u32(
+                               info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]);
+               changed |= WIPHY_PARAM_RTS_THRESHOLD;
+       }
+
+       old_rts = rdev->wiphy.radio_cfg[radio_idx].rts_threshold;
+
+       rdev->wiphy.radio_cfg[radio_idx].rts_threshold = rts_threshold;
+
+       result = rdev_set_wiphy_params(rdev, radio_idx, changed);
+       if (result)
+               rdev->wiphy.radio_cfg[radio_idx].rts_threshold = old_rts;
+
+       return 0;
+}
+
 static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info)
 {
        struct cfg80211_registered_device *rdev = NULL;
@@ -3681,6 +3708,8 @@ static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info)
                                info->attrs[NL80211_ATTR_WIPHY_RADIO_INDEX]);
                if (radio_idx >= rdev->wiphy.n_radio)
                        return -EINVAL;
+
+               return nl80211_set_wiphy_radio(info, rdev, radio_idx);
        }
 
        if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) {
@@ -3893,16 +3922,30 @@ static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info)
        if (changed) {
                u8 old_retry_short, old_retry_long;
                u32 old_frag_threshold, old_rts_threshold;
-               u8 old_coverage_class;
+               u8 old_coverage_class, i;
                u32 old_txq_limit, old_txq_memory_limit, old_txq_quantum;
+               u32 *old_radio_rts_threshold = NULL;
 
                if (!rdev->ops->set_wiphy_params)
                        return -EOPNOTSUPP;
 
+               if (rdev->wiphy.n_radio) {
+                       old_radio_rts_threshold = kcalloc(rdev->wiphy.n_radio,
+                                                         sizeof(u32),
+                                                         GFP_KERNEL);
+                       if (!old_radio_rts_threshold)
+                               return -ENOMEM;
+               }
+
                old_retry_short = rdev->wiphy.retry_short;
                old_retry_long = rdev->wiphy.retry_long;
                old_frag_threshold = rdev->wiphy.frag_threshold;
                old_rts_threshold = rdev->wiphy.rts_threshold;
+               if (old_radio_rts_threshold) {
+                       for (i = 0 ; i < rdev->wiphy.n_radio; i++)
+                               old_radio_rts_threshold[i] =
+                                       rdev->wiphy.radio_cfg[i].rts_threshold;
+               }
                old_coverage_class = rdev->wiphy.coverage_class;
                old_txq_limit = rdev->wiphy.txq_limit;
                old_txq_memory_limit = rdev->wiphy.txq_memory_limit;
@@ -3914,8 +3957,13 @@ static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info)
                        rdev->wiphy.retry_long = retry_long;
                if (changed & WIPHY_PARAM_FRAG_THRESHOLD)
                        rdev->wiphy.frag_threshold = frag_threshold;
-               if (changed & WIPHY_PARAM_RTS_THRESHOLD)
+               if ((changed & WIPHY_PARAM_RTS_THRESHOLD) &&
+                   old_radio_rts_threshold) {
                        rdev->wiphy.rts_threshold = rts_threshold;
+                       for (i = 0 ; i < rdev->wiphy.n_radio; i++)
+                               rdev->wiphy.radio_cfg[i].rts_threshold =
+                                       rdev->wiphy.rts_threshold;
+               }
                if (changed & WIPHY_PARAM_COVERAGE_CLASS)
                        rdev->wiphy.coverage_class = coverage_class;
                if (changed & WIPHY_PARAM_TXQ_LIMIT)
@@ -3931,12 +3979,20 @@ static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info)
                        rdev->wiphy.retry_long = old_retry_long;
                        rdev->wiphy.frag_threshold = old_frag_threshold;
                        rdev->wiphy.rts_threshold = old_rts_threshold;
+                       if (old_radio_rts_threshold) {
+                               for (i = 0 ; i < rdev->wiphy.n_radio; i++)
+                                       rdev->wiphy.radio_cfg[i].rts_threshold =
+                                               old_radio_rts_threshold[i];
+                       }
                        rdev->wiphy.coverage_class = old_coverage_class;
                        rdev->wiphy.txq_limit = old_txq_limit;
                        rdev->wiphy.txq_memory_limit = old_txq_memory_limit;
                        rdev->wiphy.txq_quantum = old_txq_quantum;
-                       return result;
                }
+
+               if (old_rts_threshold)
+                       kfree(old_radio_rts_threshold);
+               return result;
        }
 
        return 0;