wifi: mt76: mt7925: add mt7925_set_link_key
authorSean Wang <sean.wang@mediatek.com>
Sat, 6 Jul 2024 08:27:45 +0000 (01:27 -0700)
committerFelix Fietkau <nbd@nbd.name>
Tue, 9 Jul 2024 21:02:01 +0000 (23:02 +0200)
add mt7925_set_link_key to set up the key according to the link id

Co-developed-by: Ming Yen Hsieh <mingyen.hsieh@mediatek.com>
Signed-off-by: Ming Yen Hsieh <mingyen.hsieh@mediatek.com>
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/e8cd7d37484be238a4eb9e500ef2b8aa46e43667.1720248331.git.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/mt7925.h

index 59b1e920bb4a770784cf129dab881952027245fc..7c7452729710275591b67bccdc49fe77a7a4dd60 100644 (file)
@@ -499,31 +499,28 @@ static int mt7925_cancel_remain_on_channel(struct ieee80211_hw *hw,
        return mt7925_abort_roc(phy, &mvif->bss_conf);
 }
 
-static int mt7925_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
-                         struct ieee80211_vif *vif, struct ieee80211_sta *sta,
-                         struct ieee80211_key_conf *key)
+static int mt7925_set_link_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
+                              struct ieee80211_vif *vif, struct ieee80211_sta *sta,
+                              struct ieee80211_key_conf *key, int link_id)
 {
        struct mt792x_dev *dev = mt792x_hw_dev(hw);
        struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv;
        struct mt792x_sta *msta = sta ? (struct mt792x_sta *)sta->drv_priv :
                                  &mvif->sta;
-       struct ieee80211_link_sta *link_sta = sta ? &sta->deflink : NULL;
-       struct mt76_wcid *wcid = &msta->deflink.wcid;
        struct ieee80211_bss_conf *link_conf;
-       u8 *wcid_keyidx = &wcid->hw_key_idx;
+       struct ieee80211_link_sta *link_sta;
        int idx = key->keyidx, err = 0;
+       struct mt792x_link_sta *mlink;
+       struct mt792x_bss_conf *mconf;
+       struct mt76_wcid *wcid;
+       u8 *wcid_keyidx;
 
-       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.
-        */
-       if ((vif->type == NL80211_IFTYPE_ADHOC ||
-            vif->type == NL80211_IFTYPE_MESH_POINT) &&
-           (key->cipher == WLAN_CIPHER_SUITE_TKIP ||
-            key->cipher == WLAN_CIPHER_SUITE_CCMP) &&
-           !(key->flags & IEEE80211_KEY_FLAG_PAIRWISE))
-               return -EOPNOTSUPP;
+       link_conf = mt792x_vif_to_bss_conf(vif, link_id);
+       link_sta = sta ? mt792x_sta_to_link_sta(vif, sta, link_id) : NULL;
+       mconf = mt792x_vif_to_link(mvif, link_id);
+       mlink = mt792x_sta_to_link(msta, link_id);
+       wcid = &mlink->wcid;
+       wcid_keyidx = &wcid->hw_key_idx;
 
        /* fall back to sw encryption for unsupported ciphers */
        switch (key->cipher) {
@@ -547,13 +544,11 @@ static int mt7925_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
                return -EOPNOTSUPP;
        }
 
-       mt792x_mutex_acquire(dev);
-
-       if (cmd == SET_KEY && !mvif->bss_conf.mt76.cipher) {
+       if (cmd == SET_KEY && !mconf->mt76.cipher) {
                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, link_conf,
+               mconf->mt76.cipher = mt7925_mcu_get_cipher(key->cipher);
+               mt7925_mcu_add_bss_info(phy, mconf->mt76.ctx, link_conf,
                                        link_sta, true);
        }
 
@@ -567,9 +562,9 @@ static int mt7925_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
        mt76_wcid_key_setup(&dev->mt76, wcid,
                            cmd == SET_KEY ? key : NULL);
 
-       err = mt7925_mcu_add_key(&dev->mt76, vif, &msta->deflink.bip,
+       err = mt7925_mcu_add_key(&dev->mt76, vif, &mlink->bip,
                                 key, MCU_UNI_CMD(STA_REC_UPDATE),
-                                &msta->deflink.wcid, cmd);
+                                &mlink->wcid, cmd, msta);
 
        if (err)
                goto out;
@@ -578,9 +573,32 @@ static int mt7925_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
            key->cipher == WLAN_CIPHER_SUITE_WEP40)
                err = mt7925_mcu_add_key(&dev->mt76, vif, &mvif->wep_sta->deflink.bip,
                                         key, MCU_WMWA_UNI_CMD(STA_REC_UPDATE),
-                                        &mvif->wep_sta->deflink.wcid, cmd);
-
+                                        &mvif->wep_sta->deflink.wcid, cmd, msta);
 out:
+       return err;
+}
+
+static int mt7925_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
+                         struct ieee80211_vif *vif, struct ieee80211_sta *sta,
+                         struct ieee80211_key_conf *key)
+{
+       struct mt792x_dev *dev = mt792x_hw_dev(hw);
+       int err;
+
+       /* The hardware does not support per-STA RX GTK, fallback
+        * to software mode for these.
+        */
+       if ((vif->type == NL80211_IFTYPE_ADHOC ||
+            vif->type == NL80211_IFTYPE_MESH_POINT) &&
+           (key->cipher == WLAN_CIPHER_SUITE_TKIP ||
+            key->cipher == WLAN_CIPHER_SUITE_CCMP) &&
+           !(key->flags & IEEE80211_KEY_FLAG_PAIRWISE))
+               return -EOPNOTSUPP;
+
+       mt792x_mutex_acquire(dev);
+
+       err = mt7925_set_link_key(hw, cmd, vif, sta, key, vif->bss_conf.link_id);
+
        mt792x_mutex_release(dev);
 
        return err;
index ba91c8e37dff6ae5bb1ea3f139d64d8ff5516cef..1db81cf4d71d3b15d3f3d027a650477de7f8b227 100644 (file)
@@ -961,13 +961,12 @@ mt7925_mcu_sta_key_tlv(struct mt76_wcid *wcid,
                       struct mt76_connac_sta_key_conf *sta_key_conf,
                       struct sk_buff *skb,
                       struct ieee80211_key_conf *key,
-                      enum set_key_cmd cmd)
+                      enum set_key_cmd cmd,
+                      struct mt792x_sta *msta)
 {
-       struct mt792x_link_sta *mlink = container_of(wcid, struct mt792x_link_sta, wcid);
-       struct mt792x_sta *msta = container_of(mlink, struct mt792x_sta, deflink);
-       struct sta_rec_sec_uni *sec;
        struct mt792x_vif *mvif = msta->vif;
        struct mt792x_bss_conf *mconf = mt792x_vif_to_link(mvif, wcid->link_id);
+       struct sta_rec_sec_uni *sec;
        struct ieee80211_sta *sta;
        struct ieee80211_vif *vif;
        struct tlv *tlv;
@@ -990,12 +989,16 @@ mt7925_mcu_sta_key_tlv(struct mt76_wcid *wcid,
                sec->tx_key = 1;
                sec->key_type = 1;
                link_sta = mt792x_sta_to_link_sta(vif, sta, wcid->link_id);
-               memcpy(sec->peer_addr, link_sta->addr, ETH_ALEN);
+
+               if (link_sta)
+                       memcpy(sec->peer_addr, link_sta->addr, ETH_ALEN);
        } else {
                struct ieee80211_bss_conf *link_conf;
 
                link_conf = mt792x_vif_to_bss_conf(vif, wcid->link_id);
-               memcpy(sec->peer_addr, link_conf->bssid, ETH_ALEN);
+
+               if (link_conf)
+                       memcpy(sec->peer_addr, link_conf->bssid, ETH_ALEN);
        }
 
        if (cmd == SET_KEY) {
@@ -1040,18 +1043,20 @@ mt7925_mcu_sta_key_tlv(struct mt76_wcid *wcid,
 int mt7925_mcu_add_key(struct mt76_dev *dev, struct ieee80211_vif *vif,
                       struct mt76_connac_sta_key_conf *sta_key_conf,
                       struct ieee80211_key_conf *key, int mcu_cmd,
-                      struct mt76_wcid *wcid, enum set_key_cmd cmd)
+                      struct mt76_wcid *wcid, enum set_key_cmd cmd,
+                      struct mt792x_sta *msta)
 {
-       struct mt76_vif *mvif = (struct mt76_vif *)vif->drv_priv;
+       struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv;
+       struct mt792x_bss_conf *mconf = mt792x_vif_to_link(mvif, wcid->link_id);
        struct sk_buff *skb;
        int ret;
 
-       skb = __mt76_connac_mcu_alloc_sta_req(dev, mvif, wcid,
+       skb = __mt76_connac_mcu_alloc_sta_req(dev, &mconf->mt76, wcid,
                                              MT7925_STA_UPDATE_MAX_SIZE);
        if (IS_ERR(skb))
                return PTR_ERR(skb);
 
-       ret = mt7925_mcu_sta_key_tlv(wcid, sta_key_conf, skb, key, cmd);
+       ret = mt7925_mcu_sta_key_tlv(wcid, sta_key_conf, skb, key, cmd, msta);
        if (ret)
                return ret;
 
index 8ec5a3a202028d12bc02b1c4e2091c9c334541dd..7750049c42f2c1c2a1d6c1318cc54b87d338c598 100644 (file)
@@ -304,7 +304,8 @@ int mt7925_mcu_fill_message(struct mt76_dev *mdev, struct sk_buff *skb,
 int mt7925_mcu_add_key(struct mt76_dev *dev, struct ieee80211_vif *vif,
                       struct mt76_connac_sta_key_conf *sta_key_conf,
                       struct ieee80211_key_conf *key, int mcu_cmd,
-                      struct mt76_wcid *wcid, enum set_key_cmd cmd);
+                      struct mt76_wcid *wcid, enum set_key_cmd cmd,
+                      struct mt792x_sta *msta);
 int mt7925_mcu_set_rts_thresh(struct mt792x_phy *phy, u32 val);
 int mt7925_mcu_wtbl_update_hdr_trans(struct mt792x_dev *dev,
                                     struct ieee80211_vif *vif,