wifi: iwlwifi: mvm: factor out iwl_mvm_sta_fw_id_mask()
authorJohannes Berg <johannes.berg@intel.com>
Sun, 16 Apr 2023 12:47:30 +0000 (15:47 +0300)
committerJohannes Berg <johannes.berg@intel.com>
Mon, 17 Apr 2023 07:53:24 +0000 (09:53 +0200)
We are going to need this in more places than just the
key code, so factor out the functionality of getting
the FW station ID mask (filtered to a specific link if
needed) to a separate function that can now be called
both under RCU and mvm->mutex protection.

Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Signed-off-by: Gregory Greenman <gregory.greenman@intel.com>
Link: https://lore.kernel.org/r/20230416154301.eff92b93025d.I2c50290a0537d5db3d3460f4d57c78a4712ffb75@changeid
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
drivers/net/wireless/intel/iwlwifi/mvm/mld-key.c
drivers/net/wireless/intel/iwlwifi/mvm/mld-sta.c
drivers/net/wireless/intel/iwlwifi/mvm/sta.h

index 7c417b39aca455f47043a748c59df38b237c0775..a8ab35473924f02b97ac472ccc976c01077d10e5 100644 (file)
@@ -15,10 +15,6 @@ static u32 iwl_mvm_get_sec_sta_mask(struct iwl_mvm *mvm,
 {
        struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
        struct iwl_mvm_vif_link_info *link_info = &mvmvif->deflink;
-       struct iwl_mvm_link_sta *link_sta;
-       struct iwl_mvm_sta *mvmsta;
-       u32 result = 0;
-       int link_id;
 
        lockdep_assert_held(&mvm->mutex);
 
@@ -49,33 +45,10 @@ static u32 iwl_mvm_get_sec_sta_mask(struct iwl_mvm *mvm,
        if (!sta && (keyconf->link_id >= 0 || !vif->valid_links))
                return BIT(link_info->ap_sta_id);
 
-       /* this shouldn't happen now */
-       if (!sta)
-               return 0;
+       /* STA should be non-NULL now, but iwl_mvm_sta_fw_id_mask() checks */
 
-       mvmsta = iwl_mvm_sta_from_mac80211(sta);
-
-       /* it's easy when the STA is not an MLD */
-       if (!sta->valid_links)
-               return BIT(mvmsta->deflink.sta_id);
-
-       /* but if it is an MLD, get the mask of all the FW STAs it has ... */
-       for (link_id = 0; link_id < ARRAY_SIZE(mvmsta->link); link_id++) {
-               /* unless we have a specific link in mind (GTK on client) */
-               if (keyconf->link_id >= 0 &&
-                   keyconf->link_id != link_id)
-                       continue;
-
-               link_sta =
-                       rcu_dereference_protected(mvmsta->link[link_id],
-                                                 lockdep_is_held(&mvm->mutex));
-               if (!link_sta)
-                       continue;
-
-               result |= BIT(link_sta->sta_id);
-       }
-
-       return result;
+       /* pass link_id to filter by it if not -1 (GTK on client) */
+       return iwl_mvm_sta_fw_id_mask(mvm, sta, keyconf->link_id);
 }
 
 static u32 iwl_mvm_get_sec_flags(struct iwl_mvm *mvm,
index ad71233a229970a1aa7a6003f63b714ab3a3af09..c5d25772159bc4ddd002506b1b39ca16ab13b5de 100644 (file)
@@ -4,6 +4,43 @@
  */
 #include "mvm.h"
 #include "time-sync.h"
+#include "sta.h"
+
+u32 iwl_mvm_sta_fw_id_mask(struct iwl_mvm *mvm, struct ieee80211_sta *sta,
+                          int filter_link_id)
+{
+       struct iwl_mvm_sta *mvmsta;
+       unsigned int link_id;
+       u32 result = 0;
+
+       if (!sta)
+               return 0;
+
+       mvmsta = iwl_mvm_sta_from_mac80211(sta);
+
+       /* it's easy when the STA is not an MLD */
+       if (!sta->valid_links)
+               return BIT(mvmsta->deflink.sta_id);
+
+       /* but if it is an MLD, get the mask of all the FW STAs it has ... */
+       for (link_id = 0; link_id < ARRAY_SIZE(mvmsta->link); link_id++) {
+               struct iwl_mvm_link_sta *link_sta;
+
+               /* unless we have a specific link in mind */
+               if (filter_link_id >= 0 && link_id != filter_link_id)
+                       continue;
+
+               link_sta =
+                       rcu_dereference_check(mvmsta->link[link_id],
+                                             lockdep_is_held(&mvm->mutex));
+               if (!link_sta)
+                       continue;
+
+               result |= BIT(link_sta->sta_id);
+       }
+
+       return result;
+}
 
 static int iwl_mvm_mld_send_sta_cmd(struct iwl_mvm *mvm,
                                    struct iwl_mvm_sta_cfg_cmd *cmd)
index 7b9e91935aa07ee44d11ef0c8a919cf8ee8c75be..698b9c014cd3e88a65ac8e73e81a8191615244a5 100644 (file)
@@ -642,6 +642,8 @@ int iwl_mvm_mld_update_sta_links(struct iwl_mvm *mvm,
                                 struct ieee80211_vif *vif,
                                 struct ieee80211_sta *sta,
                                 u16 old_links, u16 new_links);
+u32 iwl_mvm_sta_fw_id_mask(struct iwl_mvm *mvm, struct ieee80211_sta *sta,
+                          int filter_link_id);
 
 /* Queues */
 void iwl_mvm_mld_modify_all_sta_disable_tx(struct iwl_mvm *mvm,