wifi: mt76: mt7925: extend mt7925_mcu_add_bss_info for per-link BSS
authorSean Wang <sean.wang@mediatek.com>
Thu, 13 Jun 2024 03:02:01 +0000 (20:02 -0700)
committerFelix Fietkau <nbd@nbd.name>
Tue, 9 Jul 2024 21:01:48 +0000 (23:01 +0200)
Extend mt7925_mcu_add_bss_info with per-link BSS configuration.

The patch we created is a prerequisite to enable the MLO function in the
driver. It is purely a refactoring patch so the functionality should
remain unchanged.

Co-developed-by: Deren Wu <deren.wu@mediatek.com>
Signed-off-by: Deren Wu <deren.wu@mediatek.com>
Signed-off-by: Sean Wang <sean.wang@mediatek.com>
Link: https://patch.msgid.link/20240613030241.5771-8-sean.wang@kernel.org
Signed-off-by: Felix Fietkau <nbd@nbd.name>
drivers/net/wireless/mediatek/mt76/mt7925/main.c
drivers/net/wireless/mediatek/mt76/mt7925/mcu.c
drivers/net/wireless/mediatek/mt76/mt7925/mcu.h
drivers/net/wireless/mediatek/mt76/mt792x.h

index d11919688bae8e92c33984efe7b8a682197b5076..7b9deb586b34209e6c9b080eefc06c297cc73b89 100644 (file)
@@ -487,9 +487,12 @@ static int mt7925_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
        struct mt792x_sta *msta = sta ? (struct mt792x_sta *)sta->drv_priv :
                                  &mvif->sta;
        struct mt76_wcid *wcid = &msta->deflink.wcid;
+       struct ieee80211_bss_conf *link_conf;
        u8 *wcid_keyidx = &wcid->hw_key_idx;
        int idx = key->keyidx, err = 0;
 
+       link_conf = mt792x_vif_to_bss_conf(vif, vif->bss_conf.link_id);
+
        /* The hardware does not support per-STA RX GTK, fallback
         * to software mode for these.
         */
@@ -528,7 +531,8 @@ static int mt7925_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
                struct mt792x_phy *phy = mt792x_hw_phy(hw);
 
                mvif->bss_conf.mt76.cipher = mt7925_mcu_get_cipher(key->cipher);
-               mt7925_mcu_add_bss_info(phy, mvif->bss_conf.mt76.ctx, vif, sta, true);
+               mt7925_mcu_add_bss_info(phy, mvif->bss_conf.mt76.ctx, link_conf,
+                                       sta, true);
        }
 
        if (cmd == SET_KEY)
@@ -701,6 +705,7 @@ int mt7925_mac_sta_add(struct mt76_dev *mdev, struct ieee80211_vif *vif,
        struct mt792x_dev *dev = container_of(mdev, struct mt792x_dev, mt76);
        struct mt792x_sta *msta = (struct mt792x_sta *)sta->drv_priv;
        struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv;
+       struct ieee80211_bss_conf *link_conf;
        int ret, idx;
 
        idx = mt76_wcid_alloc(dev->mt76.wcid_mask, MT792x_WTBL_STA - 1);
@@ -725,10 +730,12 @@ int mt7925_mac_sta_add(struct mt76_dev *mdev, struct ieee80211_vif *vif,
        mt7925_mac_wtbl_update(dev, idx,
                               MT_WTBL_UPDATE_ADM_COUNT_CLEAR);
 
+       link_conf = mt792x_vif_to_bss_conf(vif, vif->bss_conf.link_id);
+
        /* should update bss info before STA add */
        if (vif->type == NL80211_IFTYPE_STATION && !sta->tdls)
-               mt7925_mcu_add_bss_info(&dev->phy, mvif->bss_conf.mt76.ctx, vif, sta,
-                                       false);
+               mt7925_mcu_add_bss_info(&dev->phy, mvif->bss_conf.mt76.ctx,
+                                       link_conf, sta, false);
 
        ret = mt7925_mcu_sta_update(dev, sta, vif, true,
                                    MT76_STA_INFO_STATE_NONE);
@@ -747,12 +754,15 @@ void mt7925_mac_sta_assoc(struct mt76_dev *mdev, struct ieee80211_vif *vif,
        struct mt792x_dev *dev = container_of(mdev, struct mt792x_dev, mt76);
        struct mt792x_sta *msta = (struct mt792x_sta *)sta->drv_priv;
        struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv;
+       struct ieee80211_bss_conf *link_conf;
 
        mt792x_mutex_acquire(dev);
 
+       link_conf = mt792x_vif_to_bss_conf(vif, vif->bss_conf.link_id);
+
        if (vif->type == NL80211_IFTYPE_STATION && !sta->tdls)
-               mt7925_mcu_add_bss_info(&dev->phy, mvif->bss_conf.mt76.ctx, vif, sta,
-                                       true);
+               mt7925_mcu_add_bss_info(&dev->phy, mvif->bss_conf.mt76.ctx,
+                                       link_conf, sta, true);
 
        ewma_avg_signal_init(&msta->deflink.avg_ack_signal);
 
@@ -771,6 +781,7 @@ void mt7925_mac_sta_remove(struct mt76_dev *mdev, struct ieee80211_vif *vif,
 {
        struct mt792x_dev *dev = container_of(mdev, struct mt792x_dev, mt76);
        struct mt792x_sta *msta = (struct mt792x_sta *)sta->drv_priv;
+       struct ieee80211_bss_conf *link_conf;
 
        mt76_connac_free_pending_tx_skbs(&dev->pm, &msta->deflink.wcid);
        mt76_connac_pm_wake(&dev->mphy, &dev->pm);
@@ -779,14 +790,16 @@ void mt7925_mac_sta_remove(struct mt76_dev *mdev, struct ieee80211_vif *vif,
        mt7925_mac_wtbl_update(dev, msta->deflink.wcid.idx,
                               MT_WTBL_UPDATE_ADM_COUNT_CLEAR);
 
+       link_conf = mt792x_vif_to_bss_conf(vif, vif->bss_conf.link_id);
+
        if (vif->type == NL80211_IFTYPE_STATION) {
                struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv;
 
                mvif->wep_sta = NULL;
                ewma_rssi_init(&mvif->bss_conf.rssi);
                if (!sta->tdls)
-                       mt7925_mcu_add_bss_info(&dev->phy, mvif->bss_conf.mt76.ctx, vif, sta,
-                                               false);
+                       mt7925_mcu_add_bss_info(&dev->phy, mvif->bss_conf.mt76.ctx,
+                                               link_conf, sta, false);
        }
 
        spin_lock_bh(&mdev->sta_poll_lock);
@@ -1244,8 +1257,8 @@ mt7925_start_ap(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
 
        mt792x_mutex_acquire(dev);
 
-       err = mt7925_mcu_add_bss_info(&dev->phy, mvif->bss_conf.mt76.ctx, vif, NULL,
-                                     true);
+       err = mt7925_mcu_add_bss_info(&dev->phy, mvif->bss_conf.mt76.ctx,
+                                     link_conf, NULL, true);
        if (err)
                goto out;
 
@@ -1275,8 +1288,8 @@ mt7925_stop_ap(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
        if (err)
                goto out;
 
-       mt7925_mcu_add_bss_info(&dev->phy, mvif->bss_conf.mt76.ctx, vif, NULL,
-                               false);
+       mt7925_mcu_add_bss_info(&dev->phy, mvif->bss_conf.mt76.ctx, link_conf,
+                               NULL, false);
 
 out:
        mt792x_mutex_release(dev);
index 1c262a024dc8edfdbcd9ae4be87d890508bb06b5..fb261ee525bef4eea4df113b446d225b2b809727 100644 (file)
@@ -2315,11 +2315,11 @@ int mt7925_mcu_set_timing(struct mt792x_phy *phy,
 
 int mt7925_mcu_add_bss_info(struct mt792x_phy *phy,
                            struct ieee80211_chanctx_conf *ctx,
-                           struct ieee80211_vif *vif,
+                           struct ieee80211_bss_conf *link_conf,
                            struct ieee80211_sta *sta,
                            int enable)
 {
-       struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv;
+       struct mt792x_vif *mvif = (struct mt792x_vif *)link_conf->vif->drv_priv;
        struct mt792x_dev *dev = phy->dev;
        struct sk_buff *skb;
        int err;
@@ -2330,18 +2330,18 @@ int mt7925_mcu_add_bss_info(struct mt792x_phy *phy,
                return PTR_ERR(skb);
 
        /* bss_basic must be first */
-       mt7925_mcu_bss_basic_tlv(skb, vif, sta, ctx, phy->mt76,
+       mt7925_mcu_bss_basic_tlv(skb, link_conf->vif, sta, ctx, phy->mt76,
                                 mvif->sta.deflink.wcid.idx, enable);
-       mt7925_mcu_bss_sec_tlv(skb, vif);
+       mt7925_mcu_bss_sec_tlv(skb, link_conf->vif);
 
-       mt7925_mcu_bss_bmc_tlv(skb, phy, ctx, vif, sta);
-       mt7925_mcu_bss_qos_tlv(skb, vif);
-       mt7925_mcu_bss_mld_tlv(skb, vif, sta);
-       mt7925_mcu_bss_ifs_tlv(skb, vif);
+       mt7925_mcu_bss_bmc_tlv(skb, phy, ctx, link_conf->vif, sta);
+       mt7925_mcu_bss_qos_tlv(skb, link_conf->vif);
+       mt7925_mcu_bss_mld_tlv(skb, link_conf->vif, sta);
+       mt7925_mcu_bss_ifs_tlv(skb, link_conf->vif);
 
-       if (vif->bss_conf.he_support) {
-               mt7925_mcu_bss_he_tlv(skb, vif, phy);
-               mt7925_mcu_bss_color_tlv(skb, vif, enable);
+       if (link_conf->he_support) {
+               mt7925_mcu_bss_he_tlv(skb, link_conf->vif, phy);
+               mt7925_mcu_bss_color_tlv(skb, link_conf->vif, enable);
        }
 
        err = mt76_mcu_skb_send_msg(&dev->mt76, skb,
index b499b1d0531a5165bbf31e9308490717f5fd7f90..c692996e057c69cd5894d3babc696c342d890609 100644 (file)
@@ -578,7 +578,7 @@ int mt7925_mcu_sched_scan_enable(struct mt76_phy *phy,
                                 bool enable);
 int mt7925_mcu_add_bss_info(struct mt792x_phy *phy,
                            struct ieee80211_chanctx_conf *ctx,
-                           struct ieee80211_vif *vif,
+                           struct ieee80211_bss_conf *link_conf,
                            struct ieee80211_sta *sta,
                            int enable);
 int mt7925_mcu_set_timing(struct mt792x_phy *phy,
index 9630514ae25f17d6a596f87f99c4ca4a0eec52c6..718c6b185d99fa1663659399e1ecb9720a201f60 100644 (file)
@@ -246,6 +246,16 @@ mt792x_link_conf_to_mconf(struct ieee80211_bss_conf *link_conf)
        return mt792x_vif_to_link(mvif, link_conf->link_id);
 }
 
+static inline struct ieee80211_bss_conf *
+mt792x_vif_to_bss_conf(struct ieee80211_vif *vif, unsigned int link_id)
+{
+       if (!ieee80211_vif_is_mld(vif) ||
+           link_id >= IEEE80211_LINK_UNSPECIFIED)
+               return &vif->bss_conf;
+
+       return link_conf_dereference_protected(vif, link_id);
+}
+
 static inline struct mt792x_dev *
 mt792x_hw_dev(struct ieee80211_hw *hw)
 {