Commit 294f17ae authored by Lorenzo Bianconi's avatar Lorenzo Bianconi Committed by Felix Fietkau

mt76: mt7615: rework wtbl key configuration

Remove key dependency from mt7615_mac_wtbl_update_key and export
mt7615_mac_wtbl_update_key, mt7615_mac_wtbl_update_pk and
mt7615_mac_wtbl_update_cipher in order to reuse them in usb code.
Move mt7615_mac_get_cipher in mac.h
Signed-off-by: default avatarLorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: default avatarFelix Fietkau <nbd@nbd.name>
parent 3a188056
...@@ -964,58 +964,31 @@ void mt7615_mac_set_rates(struct mt7615_phy *phy, struct mt7615_sta *sta, ...@@ -964,58 +964,31 @@ void mt7615_mac_set_rates(struct mt7615_phy *phy, struct mt7615_sta *sta,
sta->wcid.tx_info |= MT_WCID_TX_INFO_SET; sta->wcid.tx_info |= MT_WCID_TX_INFO_SET;
} }
static enum mt7615_cipher_type int mt7615_mac_wtbl_update_key(struct mt7615_dev *dev,
mt7615_mac_get_cipher(int cipher) struct mt76_wcid *wcid,
{ u8 *key, u8 keylen,
switch (cipher) { enum mt7615_cipher_type cipher,
case WLAN_CIPHER_SUITE_WEP40: enum set_key_cmd cmd)
return MT_CIPHER_WEP40;
case WLAN_CIPHER_SUITE_WEP104:
return MT_CIPHER_WEP104;
case WLAN_CIPHER_SUITE_TKIP:
return MT_CIPHER_TKIP;
case WLAN_CIPHER_SUITE_AES_CMAC:
return MT_CIPHER_BIP_CMAC_128;
case WLAN_CIPHER_SUITE_CCMP:
return MT_CIPHER_AES_CCMP;
case WLAN_CIPHER_SUITE_CCMP_256:
return MT_CIPHER_CCMP_256;
case WLAN_CIPHER_SUITE_GCMP:
return MT_CIPHER_GCMP;
case WLAN_CIPHER_SUITE_GCMP_256:
return MT_CIPHER_GCMP_256;
case WLAN_CIPHER_SUITE_SMS4:
return MT_CIPHER_WAPI;
default:
return MT_CIPHER_NONE;
}
}
static int
mt7615_mac_wtbl_update_key(struct mt7615_dev *dev, struct mt76_wcid *wcid,
struct ieee80211_key_conf *key,
enum mt7615_cipher_type cipher,
enum set_key_cmd cmd)
{ {
u32 addr = mt7615_mac_wtbl_addr(dev, wcid->idx) + 30 * 4; u32 addr = mt7615_mac_wtbl_addr(dev, wcid->idx) + 30 * 4;
u8 data[32] = {}; u8 data[32] = {};
if (key->keylen > sizeof(data)) if (keylen > sizeof(data))
return -EINVAL; return -EINVAL;
mt76_rr_copy(dev, addr, data, sizeof(data)); mt76_rr_copy(dev, addr, data, sizeof(data));
if (cmd == SET_KEY) { if (cmd == SET_KEY) {
if (cipher == MT_CIPHER_TKIP) { if (cipher == MT_CIPHER_TKIP) {
/* Rx/Tx MIC keys are swapped */ /* Rx/Tx MIC keys are swapped */
memcpy(data + 16, key->key + 24, 8); memcpy(data + 16, key + 24, 8);
memcpy(data + 24, key->key + 16, 8); memcpy(data + 24, key + 16, 8);
} }
if (cipher != MT_CIPHER_BIP_CMAC_128 && wcid->cipher) if (cipher != MT_CIPHER_BIP_CMAC_128 && wcid->cipher)
memmove(data + 16, data, 16); memmove(data + 16, data, 16);
if (cipher != MT_CIPHER_BIP_CMAC_128 || !wcid->cipher) if (cipher != MT_CIPHER_BIP_CMAC_128 || !wcid->cipher)
memcpy(data, key->key, key->keylen); memcpy(data, key, keylen);
else if (cipher == MT_CIPHER_BIP_CMAC_128) else if (cipher == MT_CIPHER_BIP_CMAC_128)
memcpy(data + 16, key->key, 16); memcpy(data + 16, key, 16);
} else { } else {
if (wcid->cipher & ~BIT(cipher)) { if (wcid->cipher & ~BIT(cipher)) {
if (cipher != MT_CIPHER_BIP_CMAC_128) if (cipher != MT_CIPHER_BIP_CMAC_128)
...@@ -1029,11 +1002,12 @@ mt7615_mac_wtbl_update_key(struct mt7615_dev *dev, struct mt76_wcid *wcid, ...@@ -1029,11 +1002,12 @@ mt7615_mac_wtbl_update_key(struct mt7615_dev *dev, struct mt76_wcid *wcid,
return 0; return 0;
} }
EXPORT_SYMBOL_GPL(mt7615_mac_wtbl_update_key);
static int int mt7615_mac_wtbl_update_pk(struct mt7615_dev *dev,
mt7615_mac_wtbl_update_pk(struct mt7615_dev *dev, struct mt76_wcid *wcid, struct mt76_wcid *wcid,
enum mt7615_cipher_type cipher, int keyidx, enum mt7615_cipher_type cipher,
enum set_key_cmd cmd) int keyidx, enum set_key_cmd cmd)
{ {
u32 addr = mt7615_mac_wtbl_addr(dev, wcid->idx), w0, w1; u32 addr = mt7615_mac_wtbl_addr(dev, wcid->idx), w0, w1;
...@@ -1065,11 +1039,12 @@ mt7615_mac_wtbl_update_pk(struct mt7615_dev *dev, struct mt76_wcid *wcid, ...@@ -1065,11 +1039,12 @@ mt7615_mac_wtbl_update_pk(struct mt7615_dev *dev, struct mt76_wcid *wcid,
return 0; return 0;
} }
EXPORT_SYMBOL_GPL(mt7615_mac_wtbl_update_pk);
static void void mt7615_mac_wtbl_update_cipher(struct mt7615_dev *dev,
mt7615_mac_wtbl_update_cipher(struct mt7615_dev *dev, struct mt76_wcid *wcid, struct mt76_wcid *wcid,
enum mt7615_cipher_type cipher, enum mt7615_cipher_type cipher,
enum set_key_cmd cmd) enum set_key_cmd cmd)
{ {
u32 addr = mt7615_mac_wtbl_addr(dev, wcid->idx); u32 addr = mt7615_mac_wtbl_addr(dev, wcid->idx);
...@@ -1087,6 +1062,7 @@ mt7615_mac_wtbl_update_cipher(struct mt7615_dev *dev, struct mt76_wcid *wcid, ...@@ -1087,6 +1062,7 @@ mt7615_mac_wtbl_update_cipher(struct mt7615_dev *dev, struct mt76_wcid *wcid,
mt76_clear(dev, addr + 2 * 4, MT_WTBL_W2_KEY_TYPE); mt76_clear(dev, addr + 2 * 4, MT_WTBL_W2_KEY_TYPE);
} }
} }
EXPORT_SYMBOL_GPL(mt7615_mac_wtbl_update_cipher);
int mt7615_mac_wtbl_set_key(struct mt7615_dev *dev, int mt7615_mac_wtbl_set_key(struct mt7615_dev *dev,
struct mt76_wcid *wcid, struct mt76_wcid *wcid,
...@@ -1103,7 +1079,8 @@ int mt7615_mac_wtbl_set_key(struct mt7615_dev *dev, ...@@ -1103,7 +1079,8 @@ int mt7615_mac_wtbl_set_key(struct mt7615_dev *dev,
spin_lock_bh(&dev->mt76.lock); spin_lock_bh(&dev->mt76.lock);
mt7615_mac_wtbl_update_cipher(dev, wcid, cipher, cmd); mt7615_mac_wtbl_update_cipher(dev, wcid, cipher, cmd);
err = mt7615_mac_wtbl_update_key(dev, wcid, key, cipher, cmd); err = mt7615_mac_wtbl_update_key(dev, wcid, key->key, key->keylen,
cipher, cmd);
if (err < 0) if (err < 0)
goto out; goto out;
......
...@@ -394,6 +394,33 @@ enum mt7615_cipher_type { ...@@ -394,6 +394,33 @@ enum mt7615_cipher_type {
MT_CIPHER_GCMP_256, MT_CIPHER_GCMP_256,
}; };
static inline enum mt7615_cipher_type
mt7615_mac_get_cipher(int cipher)
{
switch (cipher) {
case WLAN_CIPHER_SUITE_WEP40:
return MT_CIPHER_WEP40;
case WLAN_CIPHER_SUITE_WEP104:
return MT_CIPHER_WEP104;
case WLAN_CIPHER_SUITE_TKIP:
return MT_CIPHER_TKIP;
case WLAN_CIPHER_SUITE_AES_CMAC:
return MT_CIPHER_BIP_CMAC_128;
case WLAN_CIPHER_SUITE_CCMP:
return MT_CIPHER_AES_CCMP;
case WLAN_CIPHER_SUITE_CCMP_256:
return MT_CIPHER_CCMP_256;
case WLAN_CIPHER_SUITE_GCMP:
return MT_CIPHER_GCMP;
case WLAN_CIPHER_SUITE_GCMP_256:
return MT_CIPHER_GCMP_256;
case WLAN_CIPHER_SUITE_SMS4:
return MT_CIPHER_WAPI;
default:
return MT_CIPHER_NONE;
}
}
static inline struct mt7615_txp_common * static inline struct mt7615_txp_common *
mt7615_txwi_to_txp(struct mt76_dev *dev, struct mt76_txwi_cache *t) mt7615_txwi_to_txp(struct mt76_dev *dev, struct mt76_txwi_cache *t)
{ {
......
...@@ -67,6 +67,7 @@ struct mt7615_vif; ...@@ -67,6 +67,7 @@ struct mt7615_vif;
struct mt7615_sta; struct mt7615_sta;
struct mt7615_dfs_pulse; struct mt7615_dfs_pulse;
struct mt7615_dfs_pattern; struct mt7615_dfs_pattern;
enum mt7615_cipher_type;
enum mt7615_hw_txq_id { enum mt7615_hw_txq_id {
MT7615_TXQ_MAIN, MT7615_TXQ_MAIN,
...@@ -412,6 +413,19 @@ void mt7615_mac_tx_free(struct mt7615_dev *dev, struct sk_buff *skb); ...@@ -412,6 +413,19 @@ void mt7615_mac_tx_free(struct mt7615_dev *dev, struct sk_buff *skb);
int mt7615_mac_wtbl_set_key(struct mt7615_dev *dev, struct mt76_wcid *wcid, int mt7615_mac_wtbl_set_key(struct mt7615_dev *dev, struct mt76_wcid *wcid,
struct ieee80211_key_conf *key, struct ieee80211_key_conf *key,
enum set_key_cmd cmd); enum set_key_cmd cmd);
int mt7615_mac_wtbl_update_pk(struct mt7615_dev *dev,
struct mt76_wcid *wcid,
enum mt7615_cipher_type cipher,
int keyidx, enum set_key_cmd cmd);
void mt7615_mac_wtbl_update_cipher(struct mt7615_dev *dev,
struct mt76_wcid *wcid,
enum mt7615_cipher_type cipher,
enum set_key_cmd cmd);
int mt7615_mac_wtbl_update_key(struct mt7615_dev *dev,
struct mt76_wcid *wcid,
u8 *key, u8 keylen,
enum mt7615_cipher_type cipher,
enum set_key_cmd cmd);
void mt7615_mac_reset_work(struct work_struct *work); void mt7615_mac_reset_work(struct work_struct *work);
int mt7615_mcu_wait_response(struct mt7615_dev *dev, int cmd, int seq); int mt7615_mcu_wait_response(struct mt7615_dev *dev, int cmd, int seq);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment