wifi: mac80211: add ieee80211_vif_link_active() helper
authorJohannes Berg <johannes.berg@intel.com>
Wed, 28 Feb 2024 08:48:11 +0000 (09:48 +0100)
committerJohannes Berg <johannes.berg@intel.com>
Mon, 4 Mar 2024 13:32:53 +0000 (14:32 +0100)
We sometimes need to check if a link is active, and this
is complicated by the fact that active_links has no bits
set when the vif isn't (acting as) an MLD. Add a small
new helper ieee80211_vif_link_active() to make that a bit
easier, and use it in a few places.

Reviewed-by: Ilan Peer <ilan.peer@intel.com>
Reviewed-by: Emmanuel Grumbach <emmanuel.grumbach@intel.com>
Reviewed-by: Miriam Rachel Korenblit <miriam.rachel.korenblit@intel.com>
Link: https://msgid.link/20240228094901.688760aff5f7.I06892a503f5ecb9563fbd678d35d08daf7a044b0@changeid
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
include/net/mac80211.h
net/mac80211/cfg.c
net/mac80211/chan.c
net/mac80211/driver-ops.c
net/mac80211/util.c

index 34d66d0a24b159a963d58f6e03fec8c789398cb3..6c6d8210d637482c16da980539f1743440a14b50 100644 (file)
@@ -2011,6 +2011,21 @@ static inline bool ieee80211_vif_is_mld(const struct ieee80211_vif *vif)
        return vif->valid_links != 0;
 }
 
+/**
+ * ieee80211_vif_link_active - check if a given link is active
+ * @vif: the vif
+ * @link_id: the link ID to check
+ * Return: %true if the vif is an MLD and the link is active, or if
+ *     the vif is not an MLD and the link ID is 0; %false otherwise.
+ */
+static inline bool ieee80211_vif_link_active(const struct ieee80211_vif *vif,
+                                            unsigned int link_id)
+{
+       if (!ieee80211_vif_is_mld(vif))
+               return link_id == 0;
+       return vif->active_links & BIT(link_id);
+}
+
 #define for_each_vif_active_link(vif, link, link_id)                           \
        for (link_id = 0; link_id < ARRAY_SIZE((vif)->link_conf); link_id++)    \
                if ((!(vif)->active_links ||                                    \
index b9c1ec2f9cfcc98dbdfa300106a7b707b5600947..358593eeb5000fea110579a8e3dd684c3195601b 100644 (file)
@@ -3189,8 +3189,7 @@ int __ieee80211_request_smps_mgd(struct ieee80211_sub_if_data *sdata,
        if (WARN_ON_ONCE(sdata->vif.type != NL80211_IFTYPE_STATION))
                return -EINVAL;
 
-       if (ieee80211_vif_is_mld(&sdata->vif) &&
-           !(sdata->vif.active_links & BIT(link->link_id)))
+       if (!ieee80211_vif_link_active(&sdata->vif, link->link_id))
                return 0;
 
        old_req = link->u.mgd.req_smps;
index 38acdc458c7c9aec648cecf97ac39f32350cd26f..80e4b9784131d149c6acf27f79be0b0c16edec85 100644 (file)
@@ -1701,8 +1701,7 @@ int ieee80211_link_use_channel(struct ieee80211_link_data *link,
 
        lockdep_assert_wiphy(local->hw.wiphy);
 
-       if (sdata->vif.active_links &&
-           !(sdata->vif.active_links & BIT(link->link_id))) {
+       if (!ieee80211_vif_link_active(&sdata->vif, link->link_id)) {
                ieee80211_link_update_chanreq(link, chanreq);
                return 0;
        }
index 3b7f70073fc375c6663359d84aa73aea104dcd14..dce37ba8ebe3744700e8dd83abf1ab3216957796 100644 (file)
@@ -1,7 +1,7 @@
 // SPDX-License-Identifier: GPL-2.0-only
 /*
  * Copyright 2015 Intel Deutschland GmbH
- * Copyright (C) 2022-2023 Intel Corporation
+ * Copyright (C) 2022-2024 Intel Corporation
  */
 #include <net/mac80211.h>
 #include "ieee80211_i.h"
@@ -214,8 +214,7 @@ int drv_conf_tx(struct ieee80211_local *local,
        if (!check_sdata_in_driver(sdata))
                return -EIO;
 
-       if (sdata->vif.active_links &&
-           !(sdata->vif.active_links & BIT(link->link_id)))
+       if (!ieee80211_vif_link_active(&sdata->vif, link->link_id))
                return 0;
 
        if (params->cw_min == 0 || params->cw_min > params->cw_max) {
@@ -315,8 +314,7 @@ int drv_assign_vif_chanctx(struct ieee80211_local *local,
        if (!check_sdata_in_driver(sdata))
                return -EIO;
 
-       if (sdata->vif.active_links &&
-           !(sdata->vif.active_links & BIT(link_conf->link_id)))
+       if (!ieee80211_vif_link_active(&sdata->vif, link_conf->link_id))
                return 0;
 
        trace_drv_assign_vif_chanctx(local, sdata, link_conf, ctx);
@@ -343,8 +341,7 @@ void drv_unassign_vif_chanctx(struct ieee80211_local *local,
        if (!check_sdata_in_driver(sdata))
                return;
 
-       if (sdata->vif.active_links &&
-           !(sdata->vif.active_links & BIT(link_conf->link_id)))
+       if (!ieee80211_vif_link_active(&sdata->vif, link_conf->link_id))
                return;
 
        trace_drv_unassign_vif_chanctx(local, sdata, link_conf, ctx);
@@ -461,8 +458,7 @@ void drv_link_info_changed(struct ieee80211_local *local,
        if (!check_sdata_in_driver(sdata))
                return;
 
-       if (sdata->vif.active_links &&
-           !(sdata->vif.active_links & BIT(link_id)))
+       if (!ieee80211_vif_link_active(&sdata->vif, link_id))
                return;
 
        trace_drv_link_info_changed(local, sdata, info, changed);
index f810b83a390afe9cc19067471dbcf7f5f0ceb06b..a237cbcf7b49100af8da21b54a29707ed8f7ec91 100644 (file)
@@ -1935,8 +1935,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
                for (link_id = 0;
                     link_id < ARRAY_SIZE(sdata->vif.link_conf);
                     link_id++) {
-                       if (ieee80211_vif_is_mld(&sdata->vif) &&
-                           !(sdata->vif.active_links & BIT(link_id)))
+                       if (!ieee80211_vif_link_active(&sdata->vif, link_id))
                                continue;
 
                        link = sdata_dereference(sdata->link[link_id], sdata);