mirror of
https://github.com/torvalds/linux.git
synced 2026-05-30 01:53:29 +02:00
mt76: connac: move mt76_connac_mcu_add_key in connac module
Move key configuration code shared between mt7921 and mt7915 in mt76-connac module and remove duplicated code. Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org> Signed-off-by: Felix Fietkau <nbd@nbd.name>
This commit is contained in:
parent
e6d557a78b
commit
6683d98808
|
|
@ -83,6 +83,11 @@ struct mt76_connac_coredump {
|
|||
unsigned long last_activity;
|
||||
};
|
||||
|
||||
struct mt76_connac_sta_key_conf {
|
||||
s8 keyidx;
|
||||
u8 key[16];
|
||||
};
|
||||
|
||||
extern const struct wiphy_wowlan_support mt76_connac_wowlan_support;
|
||||
|
||||
static inline bool is_mt7922(struct mt76_dev *dev)
|
||||
|
|
|
|||
|
|
@ -2482,5 +2482,93 @@ void mt76_connac_mcu_reg_wr(struct mt76_dev *dev, u32 offset, u32 val)
|
|||
}
|
||||
EXPORT_SYMBOL_GPL(mt76_connac_mcu_reg_wr);
|
||||
|
||||
static int
|
||||
mt76_connac_mcu_sta_key_tlv(struct mt76_connac_sta_key_conf *sta_key_conf,
|
||||
struct sk_buff *skb,
|
||||
struct ieee80211_key_conf *key,
|
||||
enum set_key_cmd cmd)
|
||||
{
|
||||
struct sta_rec_sec *sec;
|
||||
u32 len = sizeof(*sec);
|
||||
struct tlv *tlv;
|
||||
|
||||
tlv = mt76_connac_mcu_add_tlv(skb, STA_REC_KEY_V2, sizeof(*sec));
|
||||
sec = (struct sta_rec_sec *)tlv;
|
||||
sec->add = cmd;
|
||||
|
||||
if (cmd == SET_KEY) {
|
||||
struct sec_key *sec_key;
|
||||
u8 cipher;
|
||||
|
||||
cipher = mt76_connac_mcu_get_cipher(key->cipher);
|
||||
if (cipher == MCU_CIPHER_NONE)
|
||||
return -EOPNOTSUPP;
|
||||
|
||||
sec_key = &sec->key[0];
|
||||
sec_key->cipher_len = sizeof(*sec_key);
|
||||
|
||||
if (cipher == MCU_CIPHER_BIP_CMAC_128) {
|
||||
sec_key->cipher_id = MCU_CIPHER_AES_CCMP;
|
||||
sec_key->key_id = sta_key_conf->keyidx;
|
||||
sec_key->key_len = 16;
|
||||
memcpy(sec_key->key, sta_key_conf->key, 16);
|
||||
|
||||
sec_key = &sec->key[1];
|
||||
sec_key->cipher_id = MCU_CIPHER_BIP_CMAC_128;
|
||||
sec_key->cipher_len = sizeof(*sec_key);
|
||||
sec_key->key_len = 16;
|
||||
memcpy(sec_key->key, key->key, 16);
|
||||
sec->n_cipher = 2;
|
||||
} else {
|
||||
sec_key->cipher_id = cipher;
|
||||
sec_key->key_id = key->keyidx;
|
||||
sec_key->key_len = key->keylen;
|
||||
memcpy(sec_key->key, key->key, key->keylen);
|
||||
|
||||
if (cipher == MCU_CIPHER_TKIP) {
|
||||
/* Rx/Tx MIC keys are swapped */
|
||||
memcpy(sec_key->key + 16, key->key + 24, 8);
|
||||
memcpy(sec_key->key + 24, key->key + 16, 8);
|
||||
}
|
||||
|
||||
/* store key_conf for BIP batch update */
|
||||
if (cipher == MCU_CIPHER_AES_CCMP) {
|
||||
memcpy(sta_key_conf->key, key->key, key->keylen);
|
||||
sta_key_conf->keyidx = key->keyidx;
|
||||
}
|
||||
|
||||
len -= sizeof(*sec_key);
|
||||
sec->n_cipher = 1;
|
||||
}
|
||||
} else {
|
||||
len -= sizeof(sec->key);
|
||||
sec->n_cipher = 0;
|
||||
}
|
||||
sec->len = cpu_to_le16(len);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int mt76_connac_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_vif *mvif = (struct mt76_vif *)vif->drv_priv;
|
||||
struct sk_buff *skb;
|
||||
int ret;
|
||||
|
||||
skb = mt76_connac_mcu_alloc_sta_req(dev, mvif, wcid);
|
||||
if (IS_ERR(skb))
|
||||
return PTR_ERR(skb);
|
||||
|
||||
ret = mt76_connac_mcu_sta_key_tlv(sta_key_conf, skb, key, cmd);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
return mt76_mcu_skb_send_msg(dev, skb, mcu_cmd, true);
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(mt76_connac_mcu_add_key);
|
||||
|
||||
MODULE_AUTHOR("Lorenzo Bianconi <lorenzo@kernel.org>");
|
||||
MODULE_LICENSE("Dual BSD/GPL");
|
||||
|
|
|
|||
|
|
@ -1587,4 +1587,9 @@ const struct ieee80211_sta_he_cap *
|
|||
mt76_connac_get_he_phy_cap(struct mt76_phy *phy, struct ieee80211_vif *vif);
|
||||
u8 mt76_connac_get_phy_mode(struct mt76_phy *phy, struct ieee80211_vif *vif,
|
||||
enum nl80211_band band, struct ieee80211_sta *sta);
|
||||
|
||||
int mt76_connac_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);
|
||||
#endif /* __MT76_CONNAC_MCU_H */
|
||||
|
|
|
|||
|
|
@ -415,8 +415,9 @@ static int mt7915_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
|
|||
mt76_wcid_key_setup(&dev->mt76, wcid,
|
||||
cmd == SET_KEY ? key : NULL);
|
||||
|
||||
err = mt7915_mcu_add_key(dev, vif, msta, key, cmd);
|
||||
|
||||
err = mt76_connac_mcu_add_key(&dev->mt76, vif, &msta->bip,
|
||||
key, MCU_EXT_CMD(STA_REC_UPDATE),
|
||||
&msta->wcid, cmd);
|
||||
out:
|
||||
mutex_unlock(&dev->mt76.mutex);
|
||||
|
||||
|
|
|
|||
|
|
@ -863,95 +863,6 @@ int mt7915_mcu_add_bss_info(struct mt7915_phy *phy,
|
|||
}
|
||||
|
||||
/** starec & wtbl **/
|
||||
static int
|
||||
mt7915_mcu_sta_key_tlv(struct mt7915_sta *msta, struct sk_buff *skb,
|
||||
struct ieee80211_key_conf *key, enum set_key_cmd cmd)
|
||||
{
|
||||
struct mt7915_sta_key_conf *bip = &msta->bip;
|
||||
struct sta_rec_sec *sec;
|
||||
struct tlv *tlv;
|
||||
u32 len = sizeof(*sec);
|
||||
|
||||
tlv = mt76_connac_mcu_add_tlv(skb, STA_REC_KEY_V2, sizeof(*sec));
|
||||
|
||||
sec = (struct sta_rec_sec *)tlv;
|
||||
sec->add = cmd;
|
||||
|
||||
if (cmd == SET_KEY) {
|
||||
struct sec_key *sec_key;
|
||||
u8 cipher;
|
||||
|
||||
cipher = mt76_connac_mcu_get_cipher(key->cipher);
|
||||
if (cipher == MCU_CIPHER_NONE)
|
||||
return -EOPNOTSUPP;
|
||||
|
||||
sec_key = &sec->key[0];
|
||||
sec_key->cipher_len = sizeof(*sec_key);
|
||||
|
||||
if (cipher == MCU_CIPHER_BIP_CMAC_128) {
|
||||
sec_key->cipher_id = MCU_CIPHER_AES_CCMP;
|
||||
sec_key->key_id = bip->keyidx;
|
||||
sec_key->key_len = 16;
|
||||
memcpy(sec_key->key, bip->key, 16);
|
||||
|
||||
sec_key = &sec->key[1];
|
||||
sec_key->cipher_id = MCU_CIPHER_BIP_CMAC_128;
|
||||
sec_key->cipher_len = sizeof(*sec_key);
|
||||
sec_key->key_len = 16;
|
||||
memcpy(sec_key->key, key->key, 16);
|
||||
|
||||
sec->n_cipher = 2;
|
||||
} else {
|
||||
sec_key->cipher_id = cipher;
|
||||
sec_key->key_id = key->keyidx;
|
||||
sec_key->key_len = key->keylen;
|
||||
memcpy(sec_key->key, key->key, key->keylen);
|
||||
|
||||
if (cipher == MCU_CIPHER_TKIP) {
|
||||
/* Rx/Tx MIC keys are swapped */
|
||||
memcpy(sec_key->key + 16, key->key + 24, 8);
|
||||
memcpy(sec_key->key + 24, key->key + 16, 8);
|
||||
}
|
||||
|
||||
/* store key_conf for BIP batch update */
|
||||
if (cipher == MCU_CIPHER_AES_CCMP) {
|
||||
memcpy(bip->key, key->key, key->keylen);
|
||||
bip->keyidx = key->keyidx;
|
||||
}
|
||||
|
||||
len -= sizeof(*sec_key);
|
||||
sec->n_cipher = 1;
|
||||
}
|
||||
} else {
|
||||
len -= sizeof(sec->key);
|
||||
sec->n_cipher = 0;
|
||||
}
|
||||
sec->len = cpu_to_le16(len);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int mt7915_mcu_add_key(struct mt7915_dev *dev, struct ieee80211_vif *vif,
|
||||
struct mt7915_sta *msta, struct ieee80211_key_conf *key,
|
||||
enum set_key_cmd cmd)
|
||||
{
|
||||
struct mt7915_vif *mvif = (struct mt7915_vif *)vif->drv_priv;
|
||||
struct sk_buff *skb;
|
||||
int ret;
|
||||
|
||||
skb = mt76_connac_mcu_alloc_sta_req(&dev->mt76, &mvif->mt76,
|
||||
&msta->wcid);
|
||||
if (IS_ERR(skb))
|
||||
return PTR_ERR(skb);
|
||||
|
||||
ret = mt7915_mcu_sta_key_tlv(msta, skb, key, cmd);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
return mt76_mcu_skb_send_msg(&dev->mt76, skb,
|
||||
MCU_EXT_CMD(STA_REC_UPDATE), true);
|
||||
}
|
||||
|
||||
static void
|
||||
mt7915_mcu_sta_ba_tlv(struct sk_buff *skb,
|
||||
struct ieee80211_ampdu_params *params,
|
||||
|
|
|
|||
|
|
@ -86,11 +86,6 @@ enum mt7916_rxq_id {
|
|||
MT7916_RXQ_BAND1,
|
||||
};
|
||||
|
||||
struct mt7915_sta_key_conf {
|
||||
s8 keyidx;
|
||||
u8 key[16];
|
||||
};
|
||||
|
||||
struct mt7915_twt_flow {
|
||||
struct list_head list;
|
||||
u64 start_tsf;
|
||||
|
|
@ -122,7 +117,7 @@ struct mt7915_sta {
|
|||
|
||||
struct mt76_sta_stats stats;
|
||||
|
||||
struct mt7915_sta_key_conf bip;
|
||||
struct mt76_connac_sta_key_conf bip;
|
||||
|
||||
struct {
|
||||
u8 flowid_mask;
|
||||
|
|
@ -422,9 +417,6 @@ int mt7915_mcu_add_tx_ba(struct mt7915_dev *dev,
|
|||
int mt7915_mcu_add_rx_ba(struct mt7915_dev *dev,
|
||||
struct ieee80211_ampdu_params *params,
|
||||
bool add);
|
||||
int mt7915_mcu_add_key(struct mt7915_dev *dev, struct ieee80211_vif *vif,
|
||||
struct mt7915_sta *msta, struct ieee80211_key_conf *key,
|
||||
enum set_key_cmd cmd);
|
||||
int mt7915_mcu_update_bss_color(struct mt7915_dev *dev, struct ieee80211_vif *vif,
|
||||
struct cfg80211_he_bss_color *he_bss_color);
|
||||
int mt7915_mcu_add_beacon(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
|
||||
|
|
|
|||
|
|
@ -452,13 +452,18 @@ static int mt7921_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
|
|||
mt76_wcid_key_setup(&dev->mt76, wcid,
|
||||
cmd == SET_KEY ? key : NULL);
|
||||
|
||||
err = mt7921_mcu_add_key(dev, vif, msta, key, cmd);
|
||||
err = mt76_connac_mcu_add_key(&dev->mt76, vif, &msta->bip,
|
||||
key, MCU_UNI_CMD(STA_REC_UPDATE),
|
||||
&msta->wcid, cmd);
|
||||
if (err)
|
||||
goto out;
|
||||
|
||||
if (key->cipher == WLAN_CIPHER_SUITE_WEP104 ||
|
||||
key->cipher == WLAN_CIPHER_SUITE_WEP40)
|
||||
err = mt7921_mcu_add_key(dev, vif, mvif->wep_sta, key, cmd);
|
||||
err = mt76_connac_mcu_add_key(&dev->mt76, vif,
|
||||
&mvif->wep_sta->bip,
|
||||
key, MCU_UNI_CMD(STA_REC_UPDATE),
|
||||
&mvif->wep_sta->wcid, cmd);
|
||||
out:
|
||||
mt7921_mutex_release(dev);
|
||||
|
||||
|
|
|
|||
|
|
@ -419,95 +419,6 @@ void mt7921_mcu_rx_event(struct mt7921_dev *dev, struct sk_buff *skb)
|
|||
}
|
||||
|
||||
/** starec & wtbl **/
|
||||
static int
|
||||
mt7921_mcu_sta_key_tlv(struct mt7921_sta *msta, struct sk_buff *skb,
|
||||
struct ieee80211_key_conf *key, enum set_key_cmd cmd)
|
||||
{
|
||||
struct mt7921_sta_key_conf *bip = &msta->bip;
|
||||
struct sta_rec_sec *sec;
|
||||
struct tlv *tlv;
|
||||
u32 len = sizeof(*sec);
|
||||
|
||||
tlv = mt76_connac_mcu_add_tlv(skb, STA_REC_KEY_V2, sizeof(*sec));
|
||||
|
||||
sec = (struct sta_rec_sec *)tlv;
|
||||
sec->add = cmd;
|
||||
|
||||
if (cmd == SET_KEY) {
|
||||
struct sec_key *sec_key;
|
||||
u8 cipher;
|
||||
|
||||
cipher = mt76_connac_mcu_get_cipher(key->cipher);
|
||||
if (cipher == MCU_CIPHER_NONE)
|
||||
return -EOPNOTSUPP;
|
||||
|
||||
sec_key = &sec->key[0];
|
||||
sec_key->cipher_len = sizeof(*sec_key);
|
||||
|
||||
if (cipher == MCU_CIPHER_BIP_CMAC_128) {
|
||||
sec_key->cipher_id = MCU_CIPHER_AES_CCMP;
|
||||
sec_key->key_id = bip->keyidx;
|
||||
sec_key->key_len = 16;
|
||||
memcpy(sec_key->key, bip->key, 16);
|
||||
|
||||
sec_key = &sec->key[1];
|
||||
sec_key->cipher_id = MCU_CIPHER_BIP_CMAC_128;
|
||||
sec_key->cipher_len = sizeof(*sec_key);
|
||||
sec_key->key_len = 16;
|
||||
memcpy(sec_key->key, key->key, 16);
|
||||
|
||||
sec->n_cipher = 2;
|
||||
} else {
|
||||
sec_key->cipher_id = cipher;
|
||||
sec_key->key_id = key->keyidx;
|
||||
sec_key->key_len = key->keylen;
|
||||
memcpy(sec_key->key, key->key, key->keylen);
|
||||
|
||||
if (cipher == MCU_CIPHER_TKIP) {
|
||||
/* Rx/Tx MIC keys are swapped */
|
||||
memcpy(sec_key->key + 16, key->key + 24, 8);
|
||||
memcpy(sec_key->key + 24, key->key + 16, 8);
|
||||
}
|
||||
|
||||
/* store key_conf for BIP batch update */
|
||||
if (cipher == MCU_CIPHER_AES_CCMP) {
|
||||
memcpy(bip->key, key->key, key->keylen);
|
||||
bip->keyidx = key->keyidx;
|
||||
}
|
||||
|
||||
len -= sizeof(*sec_key);
|
||||
sec->n_cipher = 1;
|
||||
}
|
||||
} else {
|
||||
len -= sizeof(sec->key);
|
||||
sec->n_cipher = 0;
|
||||
}
|
||||
sec->len = cpu_to_le16(len);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int mt7921_mcu_add_key(struct mt7921_dev *dev, struct ieee80211_vif *vif,
|
||||
struct mt7921_sta *msta, struct ieee80211_key_conf *key,
|
||||
enum set_key_cmd cmd)
|
||||
{
|
||||
struct mt7921_vif *mvif = (struct mt7921_vif *)vif->drv_priv;
|
||||
struct sk_buff *skb;
|
||||
int ret;
|
||||
|
||||
skb = mt76_connac_mcu_alloc_sta_req(&dev->mt76, &mvif->mt76,
|
||||
&msta->wcid);
|
||||
if (IS_ERR(skb))
|
||||
return PTR_ERR(skb);
|
||||
|
||||
ret = mt7921_mcu_sta_key_tlv(msta, skb, key, cmd);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
return mt76_mcu_skb_send_msg(&dev->mt76, skb,
|
||||
MCU_UNI_CMD(STA_REC_UPDATE), true);
|
||||
}
|
||||
|
||||
int mt7921_mcu_uni_tx_ba(struct mt7921_dev *dev,
|
||||
struct ieee80211_ampdu_params *params,
|
||||
bool enable)
|
||||
|
|
|
|||
|
|
@ -89,11 +89,6 @@ enum mt7921_rxq_id {
|
|||
MT7921_RXQ_MCU_WM = 0,
|
||||
};
|
||||
|
||||
struct mt7921_sta_key_conf {
|
||||
s8 keyidx;
|
||||
u8 key[16];
|
||||
};
|
||||
|
||||
struct mt7921_sta {
|
||||
struct mt76_wcid wcid; /* must be first */
|
||||
|
||||
|
|
@ -106,7 +101,7 @@ struct mt7921_sta {
|
|||
unsigned long ampdu_state;
|
||||
struct mt76_sta_stats stats;
|
||||
|
||||
struct mt7921_sta_key_conf bip;
|
||||
struct mt76_connac_sta_key_conf bip;
|
||||
};
|
||||
|
||||
DECLARE_EWMA(rssi, 10, 8);
|
||||
|
|
@ -296,9 +291,6 @@ int mt7921_wpdma_reset(struct mt7921_dev *dev, bool force);
|
|||
int mt7921_wpdma_reinit_cond(struct mt7921_dev *dev);
|
||||
void mt7921_dma_cleanup(struct mt7921_dev *dev);
|
||||
int mt7921_run_firmware(struct mt7921_dev *dev);
|
||||
int mt7921_mcu_add_key(struct mt7921_dev *dev, struct ieee80211_vif *vif,
|
||||
struct mt7921_sta *msta, struct ieee80211_key_conf *key,
|
||||
enum set_key_cmd cmd);
|
||||
int mt7921_mcu_sta_update(struct mt7921_dev *dev, struct ieee80211_sta *sta,
|
||||
struct ieee80211_vif *vif, bool enable,
|
||||
enum mt76_sta_info_state state);
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user