]> git.ipfire.org Git - people/arne_f/kernel.git/commitdiff
mt76: unify mac_wcid_set_key
authorStanislaw Gruszka <sgruszka@redhat.com>
Wed, 29 Aug 2018 11:16:39 +0000 (13:16 +0200)
committerKalle Valo <kvalo@codeaurora.org>
Tue, 4 Sep 2018 08:02:57 +0000 (11:02 +0300)
Merge mt76x{0,2}_mac_wcid_set_key into common code.

Signed-off-by: Stanislaw Gruszka <sgruszka@redhat.com>
Signed-off-by: Kalle Valo <kvalo@codeaurora.org>
drivers/net/wireless/mediatek/mt76/mt76.h
drivers/net/wireless/mediatek/mt76/mt76x0/mac.c
drivers/net/wireless/mediatek/mt76/mt76x0/mac.h
drivers/net/wireless/mediatek/mt76/mt76x0/main.c
drivers/net/wireless/mediatek/mt76/mt76x02_mac.c
drivers/net/wireless/mediatek/mt76/mt76x02_mac.h
drivers/net/wireless/mediatek/mt76/mt76x2_common.c
drivers/net/wireless/mediatek/mt76/mt76x2_mac.h
drivers/net/wireless/mediatek/mt76/mt76x2_mac_common.c

index 10959c4669bd6319b58c14aa5027d5d0275e2187..b02b4191ef37194ace7a85c6697bb23df7e389ef 100644 (file)
@@ -423,6 +423,9 @@ struct mt76_rx_status {
 #define mt76_rmw_field(_dev, _reg, _field, _val)       \
        mt76_rmw(_dev, _reg, _field, FIELD_PREP(_field, _val))
 
+#define __mt76_rmw_field(_dev, _reg, _field, _val)     \
+       __mt76_rmw(_dev, _reg, _field, FIELD_PREP(_field, _val))
+
 #define mt76_hw(dev) (dev)->mt76.hw
 
 bool __mt76_poll(struct mt76_dev *dev, u32 offset, u32 mask, u32 val,
index 6d0a6fb18be96ee807c0fc6d7c991f998674c2df..2fcdedd0cadc993382b27b75e2fb8473208d8bbb 100644 (file)
@@ -565,44 +565,3 @@ u32 mt76x0_mac_process_rx(struct mt76x0_dev *dev, struct sk_buff *skb,
 
        return len;
 }
-
-int mt76x0_mac_wcid_set_key(struct mt76x0_dev *dev, u8 idx,
-                         struct ieee80211_key_conf *key)
-{
-       enum mt76x02_cipher_type cipher;
-       u8 key_data[32];
-       u8 iv_data[8];
-       u32 val;
-
-       cipher = mt76x02_mac_get_key_info(key, key_data);
-       if (cipher == MT_CIPHER_NONE && key)
-               return -EINVAL;
-
-       trace_mt76x0_set_key(&dev->mt76, idx);
-
-       mt76_wr_copy(dev, MT_WCID_KEY(idx), key_data, sizeof(key_data));
-
-       memset(iv_data, 0, sizeof(iv_data));
-       if (key) {
-               iv_data[3] = key->keyidx << 6;
-               if (cipher >= MT_CIPHER_TKIP) {
-                       /* Note: start with 1 to comply with spec,
-                        *       (see comment on common/cmm_wpa.c:4291).
-                        */
-                       iv_data[0] |= 1;
-                       iv_data[3] |= 0x20;
-               }
-       }
-       mt76_wr_copy(dev, MT_WCID_IV(idx), iv_data, sizeof(iv_data));
-
-       val = mt76_rr(dev, MT_WCID_ATTR(idx));
-       val &= ~MT_WCID_ATTR_PKEY_MODE & ~MT_WCID_ATTR_PKEY_MODE_EXT;
-       val |= FIELD_PREP(MT_WCID_ATTR_PKEY_MODE, cipher & 7) |
-              FIELD_PREP(MT_WCID_ATTR_PKEY_MODE_EXT, cipher >> 3);
-       val &= ~MT_WCID_ATTR_PAIRWISE;
-       val |= MT_WCID_ATTR_PAIRWISE *
-               !!(key && key->flags & IEEE80211_KEY_FLAG_PAIRWISE);
-       mt76_wr(dev, MT_WCID_ATTR(idx), val);
-
-       return 0;
-}
index d44ef1e9a1dde42c1bf8e483b4347db98d90b84d..f8074c477044e07e3a06b78bf5e5fce896201ed0 100644 (file)
@@ -138,8 +138,6 @@ struct mt76_txwi {
 
 u32 mt76x0_mac_process_rx(struct mt76x0_dev *dev, struct sk_buff *skb,
                        u8 *data, void *rxi);
-int mt76x0_mac_wcid_set_key(struct mt76x0_dev *dev, u8 idx,
-                         struct ieee80211_key_conf *key);
 void mt76x0_mac_wcid_set_rate(struct mt76x0_dev *dev, struct mt76_wcid *wcid,
                            const struct ieee80211_tx_rate *rate);
 
index fb31c103aeeefb64b1a129b61c5ebcbafc7f06c5..5b39f4d280722f4db3f5fbbc468a35be2a3663df 100644 (file)
@@ -259,7 +259,7 @@ mt76x0_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
 
        if (!msta) {
                if (key || wcid->hw_key_idx == idx) {
-                       ret = mt76x0_mac_wcid_set_key(dev, wcid->idx, key);
+                       ret = mt76x02_mac_wcid_set_key(&dev->mt76, wcid->idx, key);
                        if (ret)
                                return ret;
                }
@@ -267,7 +267,7 @@ mt76x0_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
                return mt76x02_mac_shared_key_setup(&dev->mt76, mvif->idx, idx, key);
        }
 
-       return mt76x0_mac_wcid_set_key(dev, msta->wcid.idx, key);
+       return mt76x02_mac_wcid_set_key(&dev->mt76, msta->wcid.idx, key);
 }
 
 static int mt76x0_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
index 6d45adc0522fc3b761bae04be23324150e18feca..3261c510a8c83d74ccd71e4ded634b28ef55bd19 100644 (file)
@@ -67,3 +67,32 @@ int mt76x02_mac_shared_key_setup(struct mt76_dev *dev, u8 vif_idx, u8 key_idx,
        return 0;
 }
 EXPORT_SYMBOL_GPL(mt76x02_mac_shared_key_setup);
+
+int mt76x02_mac_wcid_set_key(struct mt76_dev *dev, u8 idx,
+                           struct ieee80211_key_conf *key)
+{
+       enum mt76x02_cipher_type cipher;
+       u8 key_data[32];
+       u8 iv_data[8];
+
+       cipher = mt76x02_mac_get_key_info(key, key_data);
+       if (cipher == MT_CIPHER_NONE && key)
+               return -EOPNOTSUPP;
+
+       __mt76_wr_copy(dev, MT_WCID_KEY(idx), key_data, sizeof(key_data));
+       __mt76_rmw_field(dev, MT_WCID_ATTR(idx), MT_WCID_ATTR_PKEY_MODE, cipher);
+
+       memset(iv_data, 0, sizeof(iv_data));
+       if (key) {
+               __mt76_rmw_field(dev, MT_WCID_ATTR(idx), MT_WCID_ATTR_PAIRWISE,
+                                !!(key->flags & IEEE80211_KEY_FLAG_PAIRWISE));
+               iv_data[3] = key->keyidx << 6;
+               if (cipher >= MT_CIPHER_TKIP)
+                       iv_data[3] |= 0x20;
+       }
+
+       __mt76_wr_copy(dev, MT_WCID_IV(idx), iv_data, sizeof(iv_data));
+
+       return 0;
+}
+EXPORT_SYMBOL_GPL(mt76x02_mac_wcid_set_key);
index 6f8b8a1d02cf6bbf0eb6c0060deb11544472a385..aebc7dcf7435d43eaf9884bd4d564e122f9f12a7 100644 (file)
@@ -44,4 +44,6 @@ mt76x02_mac_get_key_info(struct ieee80211_key_conf *key, u8 *key_data);
 
 int mt76x02_mac_shared_key_setup(struct mt76_dev *dev, u8 vif_idx, u8 key_idx,
                                struct ieee80211_key_conf *key);
+int mt76x02_mac_wcid_set_key(struct mt76_dev *dev, u8 idx,
+                           struct ieee80211_key_conf *key);
 #endif
index 56cceeac78d8ec0411c2a8bb4cfac4018fbaaee2..1de191c4f6a0be378801e52cf236be5df6fec38b 100644 (file)
@@ -219,7 +219,7 @@ int mt76x2_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
 
        if (!msta) {
                if (key || wcid->hw_key_idx == idx) {
-                       ret = mt76x2_mac_wcid_set_key(dev, wcid->idx, key);
+                       ret = mt76x02_mac_wcid_set_key(&dev->mt76, wcid->idx, key);
                        if (ret)
                                return ret;
                }
@@ -227,7 +227,7 @@ int mt76x2_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
                return mt76x02_mac_shared_key_setup(&dev->mt76, mvif->idx, idx, key);
        }
 
-       return mt76x2_mac_wcid_set_key(dev, msta->wcid.idx, key);
+       return mt76x02_mac_wcid_set_key(&dev->mt76, msta->wcid.idx, key);
 }
 EXPORT_SYMBOL_GPL(mt76x2_set_key);
 
index 4be2e0e64847fca5e8a86ed3d9cf01bea599062e..77dd01da9bb9bff878a5726026a8c0249d755599 100644 (file)
@@ -169,8 +169,6 @@ void mt76x2_mac_write_txwi(struct mt76x2_dev *dev, struct mt76x2_txwi *txwi,
                           struct sk_buff *skb, struct mt76_wcid *wcid,
                           struct ieee80211_sta *sta, int len);
 void mt76x2_mac_wcid_setup(struct mt76x2_dev *dev, u8 idx, u8 vif_idx, u8 *mac);
-int mt76x2_mac_wcid_set_key(struct mt76x2_dev *dev, u8 idx,
-                           struct ieee80211_key_conf *key);
 void mt76x2_mac_wcid_set_rate(struct mt76x2_dev *dev, struct mt76_wcid *wcid,
                              const struct ieee80211_tx_rate *rate);
 void mt76x2_mac_wcid_set_drop(struct mt76x2_dev *dev, u8 idx, bool drop);
index 7359ef64726819715e053234820e1e9e35318002..c218434af347c832a70693306afb966c0071f826 100644 (file)
@@ -229,35 +229,6 @@ out:
 }
 EXPORT_SYMBOL_GPL(mt76x2_send_tx_status);
 
-int mt76x2_mac_wcid_set_key(struct mt76x2_dev *dev, u8 idx,
-                           struct ieee80211_key_conf *key)
-{
-       enum mt76x02_cipher_type cipher;
-       u8 key_data[32];
-       u8 iv_data[8];
-
-       cipher = mt76x02_mac_get_key_info(key, key_data);
-       if (cipher == MT_CIPHER_NONE && key)
-               return -EOPNOTSUPP;
-
-       mt76_rmw_field(dev, MT_WCID_ATTR(idx), MT_WCID_ATTR_PKEY_MODE, cipher);
-       mt76_wr_copy(dev, MT_WCID_KEY(idx), key_data, sizeof(key_data));
-
-       memset(iv_data, 0, sizeof(iv_data));
-       if (key) {
-               mt76_rmw_field(dev, MT_WCID_ATTR(idx), MT_WCID_ATTR_PAIRWISE,
-                              !!(key->flags & IEEE80211_KEY_FLAG_PAIRWISE));
-               iv_data[3] = key->keyidx << 6;
-               if (cipher >= MT_CIPHER_TKIP)
-                       iv_data[3] |= 0x20;
-       }
-
-       mt76_wr_copy(dev, MT_WCID_IV(idx), iv_data, sizeof(iv_data));
-
-       return 0;
-}
-EXPORT_SYMBOL_GPL(mt76x2_mac_wcid_set_key);
-
 static __le16
 mt76x2_mac_tx_rate_val(struct mt76x2_dev *dev,
                       const struct ieee80211_tx_rate *rate, u8 *nss_val)