[PATCH v2 4/8] wifi: ath12k: remove redundant logic for initializing arvif

Aditya Kumar Singh
2025-02-04T17:05:36Z

The current logic for initializing arvif is present in both the add
interface operation callback and ath12k_mac_assign_link_vif(). The former
handles deflink initialization, while the latter is responsible for other
links. This redundancy could be avoided by using a common helper function.

Hence, add a new helper ath12k_mac_init_arvif() which initializes a
given arvif.

Since synchronizing rcu is not required after adding a rcu pointer, remove
that now.

Tested-on: QCN9274 hw2.0 PCI WLAN.WBE.1.3.1-00173-QCAHKSWPL_SILICONZ-1

Reviewed-by: Vasanthakumar Thiagarajan <vasanthakumar.thiagarajan@oss.qualcomm.com>
Signed-off-by: Aditya Kumar Singh <aditya.kumar.singh@oss.qualcomm.com>
---
drivers/net/wireless/ath/ath12k/mac.c | 80 +++++++++++++++++++++--------------
1 file changed, 49 insertions(+), 31 deletions(-)

diff --git a/drivers/net/wireless/ath/ath12k/mac.c b/drivers/net/wireless/ath/ath12k/mac.c
index 7defc2b20fb61dcaec06d0e332c48a1b6cd2f5d6..5f0388002e16c38a834d6c7c6c020b7afa7044f0 100644
--- a/drivers/net/wireless/ath/ath12k/mac.c
+++ b/drivers/net/wireless/ath/ath12k/mac.c
@@ -3973,13 +3973,59 @@ static void ath12k_mac_op_link_info_changed(struct ieee80211_hw *hw,
ath12k_mac_bss_info_changed(ar, arvif, info, changed);
}

+static void ath12k_mac_init_arvif(struct ath12k_vif *ahvif,
+ struct ath12k_link_vif *arvif, int link_id)
+{
+ struct ath12k_hw *ah = ahvif->ah;
+ u8 _link_id;
+ int i;
+
+ lockdep_assert_wiphy(ah->hw->wiphy);
+
+ if (WARN_ON(!arvif))
+ return;
+
+ if (WARN_ON(link_id >= ATH12K_NUM_MAX_LINKS))
+ return;
+
+ if (link_id < 0)
+ _link_id = 0;
+ else
+ _link_id = link_id;
+
+ arvif->ahvif = ahvif;
+ arvif->link_id = _link_id;
+
+ INIT_LIST_HEAD(&arvif->list);
+ INIT_DELAYED_WORK(&arvif->connection_loss_work,
+ ath12k_mac_vif_sta_connection_loss_work);
+
+ for (i = 0; i < ARRAY_SIZE(arvif->bitrate_mask.control); i++) {
+ arvif->bitrate_mask.control[i].legacy = 0xffffffff;
+ memset(arvif->bitrate_mask.control[i].ht_mcs, 0xff,
+ sizeof(arvif->bitrate_mask.control[i].ht_mcs));
+ memset(arvif->bitrate_mask.control[i].vht_mcs, 0xff,
+ sizeof(arvif->bitrate_mask.control[i].vht_mcs));
+ }
+
+ /* Handle MLO related assignments */
+ if (link_id >= 0) {
+ rcu_assign_pointer(ahvif->link[arvif->link_id], arvif);
+ ahvif->links_map |= BIT(_link_id);
+ }
+
+ ath12k_generic_dbg(ATH12K_DBG_MAC,
+ "mac init link arvif (link_id %d%s) for vif %pM. links_map 0x%x",
+ _link_id, (link_id < 0) ? " deflink" : "", ahvif->vif->addr,
+ ahvif->links_map);
+}
+
static struct ath12k_link_vif *ath12k_mac_assign_link_vif(struct ath12k_hw *ah,
struct ieee80211_vif *vif,
u8 link_id)
{
struct ath12k_vif *ahvif = ath12k_vif_to_ahvif(vif);
struct ath12k_link_vif *arvif;
- int i;

lockdep_assert_wiphy(ah->hw->wiphy);

@@ -4006,25 +4052,8 @@ static struct ath12k_link_vif *ath12k_mac_assign_link_vif(struct ath12k_hw *ah,
}
}

- arvif->ahvif = ahvif;
- arvif->link_id = link_id;
- ahvif->links_map |= BIT(link_id);
-
- INIT_LIST_HEAD(&arvif->list);
- INIT_DELAYED_WORK(&arvif->connection_loss_work,
- ath12k_mac_vif_sta_connection_loss_work);
-
- for (i = 0; i < ARRAY_SIZE(arvif->bitrate_mask.control); i++) {
- arvif->bitrate_mask.control[i].legacy = 0xffffffff;
- memset(arvif->bitrate_mask.control[i].ht_mcs, 0xff,
- sizeof(arvif->bitrate_mask.control[i].ht_mcs));
- memset(arvif->bitrate_mask.control[i].vht_mcs, 0xff,
- sizeof(arvif->bitrate_mask.control[i].vht_mcs));
- }
+ ath12k_mac_init_arvif(ahvif, arvif, link_id);

- rcu_assign_pointer(ahvif->link[arvif->link_id], arvif);
- ahvif->links_map |= BIT(link_id);
- synchronize_rcu();
return arvif;
}

@@ -8312,19 +8341,8 @@ static int ath12k_mac_op_add_interface(struct ieee80211_hw *hw,
ahvif->ah = ah;
ahvif->vif = vif;
arvif = &ahvif->deflink;
- arvif->ahvif = ahvif;
-
- INIT_LIST_HEAD(&arvif->list);
- INIT_DELAYED_WORK(&arvif->connection_loss_work,
- ath12k_mac_vif_sta_connection_loss_work);

- for (i = 0; i < ARRAY_SIZE(arvif->bitrate_mask.control); i++) {
- arvif->bitrate_mask.control[i].legacy = 0xffffffff;
- memset(arvif->bitrate_mask.control[i].ht_mcs, 0xff,
- sizeof(arvif->bitrate_mask.control[i].ht_mcs));
- memset(arvif->bitrate_mask.control[i].vht_mcs, 0xff,
- sizeof(arvif->bitrate_mask.control[i].vht_mcs));
- }
+ ath12k_mac_init_arvif(ahvif, arvif, -1);

/* Allocate Default Queue now and reassign during actual vdev create */
vif->cab_queue = ATH12K_HW_DEFAULT_QUEUE;

--
2.34.1