Skip to content

Commit 022159b

Browse files
LorenzoBianconinbd168
authored andcommitted
mt76: mt7921: rely on mt76_connac_mcu module for suspend and WoW support
Rely on mt76_connac_mcu module for suspend and WoW support and remove duplicated code Signed-off-by: Lorenzo Bianconi <[email protected]> Signed-off-by: Felix Fietkau <[email protected]>
1 parent 80fc1e3 commit 022159b

File tree

5 files changed

+11
-412
lines changed

5 files changed

+11
-412
lines changed

drivers/net/wireless/mediatek/mt76/mt7921/main.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -994,9 +994,10 @@ static int mt7921_suspend(struct ieee80211_hw *hw,
994994
set_bit(MT76_STATE_SUSPEND, &phy->mt76->state);
995995
ieee80211_iterate_active_interfaces(hw,
996996
IEEE80211_IFACE_ITER_RESUME_ALL,
997-
mt7921_mcu_set_suspend_iter, phy);
997+
mt76_connac_mcu_set_suspend_iter,
998+
&dev->mphy);
998999

999-
err = mt7921_mcu_set_hif_suspend(dev, true);
1000+
err = mt76_connac_mcu_set_hif_suspend(&dev->mt76, true);
10001001

10011002
mutex_unlock(&dev->mt76.mutex);
10021003

@@ -1011,15 +1012,16 @@ static int mt7921_resume(struct ieee80211_hw *hw)
10111012

10121013
mutex_lock(&dev->mt76.mutex);
10131014

1014-
err = mt7921_mcu_set_hif_suspend(dev, false);
1015+
err = mt76_connac_mcu_set_hif_suspend(&dev->mt76, false);
10151016
if (err < 0)
10161017
goto out;
10171018

10181019
set_bit(MT76_STATE_RUNNING, &phy->mt76->state);
10191020
clear_bit(MT76_STATE_SUSPEND, &phy->mt76->state);
10201021
ieee80211_iterate_active_interfaces(hw,
10211022
IEEE80211_IFACE_ITER_RESUME_ALL,
1022-
mt7921_mcu_set_suspend_iter, phy);
1023+
mt76_connac_mcu_set_suspend_iter,
1024+
&dev->mphy);
10231025

10241026
ieee80211_queue_delayed_work(hw, &phy->mt76->mac_work,
10251027
MT7921_WATCHDOG_TIME);
@@ -1044,7 +1046,7 @@ static void mt7921_set_rekey_data(struct ieee80211_hw *hw,
10441046
struct mt7921_dev *dev = mt7921_hw_dev(hw);
10451047

10461048
mutex_lock(&dev->mt76.mutex);
1047-
mt7921_mcu_update_gtk_rekey(hw, vif, data);
1049+
mt76_connac_mcu_update_gtk_rekey(hw, vif, data);
10481050
mutex_unlock(&dev->mt76.mutex);
10491051
}
10501052
#endif /* CONFIG_PM */

drivers/net/wireless/mediatek/mt76/mt7921/mcu.c

Lines changed: 1 addition & 305 deletions
Original file line numberDiff line numberDiff line change
@@ -865,15 +865,6 @@ static int mt7921_load_ram(struct mt7921_dev *dev)
865865
return ret;
866866
}
867867

868-
static const struct wiphy_wowlan_support mt7921_wowlan_support = {
869-
.flags = WIPHY_WOWLAN_MAGIC_PKT | WIPHY_WOWLAN_DISCONNECT |
870-
WIPHY_WOWLAN_SUPPORTS_GTK_REKEY | WIPHY_WOWLAN_NET_DETECT,
871-
.n_patterns = 1,
872-
.pattern_min_len = 1,
873-
.pattern_max_len = MT7921_WOW_PATTEN_MAX_LEN,
874-
.max_nd_match_sets = 10,
875-
};
876-
877868
static int mt7921_load_firmware(struct mt7921_dev *dev)
878869
{
879870
int ret;
@@ -902,7 +893,7 @@ static int mt7921_load_firmware(struct mt7921_dev *dev)
902893
mt76_queue_tx_cleanup(dev, dev->mt76.q_mcu[MT_MCUQ_FWDL], false);
903894

904895
#ifdef CONFIG_PM
905-
dev->mt76.hw->wiphy->wowlan = &mt7921_wowlan_support;
896+
dev->mt76.hw->wiphy->wowlan = &mt76_connac_wowlan_support;
906897
#endif /* CONFIG_PM */
907898

908899
dev_err(dev->mt76.dev, "Firmware init done\n");
@@ -1241,298 +1232,3 @@ int mt7921_mcu_set_bss_pm(struct mt7921_dev *dev, struct ieee80211_vif *vif,
12411232
return mt76_mcu_send_msg(&dev->mt76, MCU_CMD_SET_BSS_CONNECTED, &req,
12421233
sizeof(req), false);
12431234
}
1244-
1245-
#ifdef CONFIG_PM
1246-
int mt7921_mcu_set_hif_suspend(struct mt7921_dev *dev, bool suspend)
1247-
{
1248-
struct {
1249-
struct {
1250-
u8 hif_type; /* 0x0: HIF_SDIO
1251-
* 0x1: HIF_USB
1252-
* 0x2: HIF_PCIE
1253-
*/
1254-
u8 pad[3];
1255-
} __packed hdr;
1256-
struct hif_suspend_tlv {
1257-
__le16 tag;
1258-
__le16 len;
1259-
u8 suspend;
1260-
} __packed hif_suspend;
1261-
} req = {
1262-
.hif_suspend = {
1263-
.tag = cpu_to_le16(0), /* 0: UNI_HIF_CTRL_BASIC */
1264-
.len = cpu_to_le16(sizeof(struct hif_suspend_tlv)),
1265-
.suspend = suspend,
1266-
},
1267-
};
1268-
1269-
if (mt76_is_mmio(&dev->mt76))
1270-
req.hdr.hif_type = 2;
1271-
else if (mt76_is_usb(&dev->mt76))
1272-
req.hdr.hif_type = 1;
1273-
else if (mt76_is_sdio(&dev->mt76))
1274-
req.hdr.hif_type = 0;
1275-
1276-
return mt76_mcu_send_msg(&dev->mt76, MCU_UNI_CMD_HIF_CTRL, &req,
1277-
sizeof(req), true);
1278-
}
1279-
EXPORT_SYMBOL_GPL(mt7921_mcu_set_hif_suspend);
1280-
1281-
static int
1282-
mt7921_mcu_set_wow_ctrl(struct mt7921_phy *phy, struct ieee80211_vif *vif,
1283-
bool suspend, struct cfg80211_wowlan *wowlan)
1284-
{
1285-
struct mt7921_vif *mvif = (struct mt7921_vif *)vif->drv_priv;
1286-
struct mt7921_dev *dev = phy->dev;
1287-
struct {
1288-
struct {
1289-
u8 bss_idx;
1290-
u8 pad[3];
1291-
} __packed hdr;
1292-
struct mt7921_wow_ctrl_tlv wow_ctrl_tlv;
1293-
struct mt7921_wow_gpio_param_tlv gpio_tlv;
1294-
} req = {
1295-
.hdr = {
1296-
.bss_idx = mvif->mt76.idx,
1297-
},
1298-
.wow_ctrl_tlv = {
1299-
.tag = cpu_to_le16(UNI_SUSPEND_WOW_CTRL),
1300-
.len = cpu_to_le16(sizeof(struct mt7921_wow_ctrl_tlv)),
1301-
.cmd = suspend ? 1 : 2,
1302-
},
1303-
.gpio_tlv = {
1304-
.tag = cpu_to_le16(UNI_SUSPEND_WOW_GPIO_PARAM),
1305-
.len = cpu_to_le16(sizeof(struct mt7921_wow_gpio_param_tlv)),
1306-
.gpio_pin = 0xff, /* follow fw about GPIO pin */
1307-
},
1308-
};
1309-
1310-
if (wowlan->magic_pkt)
1311-
req.wow_ctrl_tlv.trigger |= BIT(0);
1312-
if (wowlan->disconnect)
1313-
req.wow_ctrl_tlv.trigger |= BIT(2);
1314-
if (wowlan->nd_config) {
1315-
mt76_connac_mcu_sched_scan_req(&dev->mphy, vif,
1316-
wowlan->nd_config);
1317-
req.wow_ctrl_tlv.trigger |= BIT(5);
1318-
mt76_connac_mcu_sched_scan_enable(&dev->mphy, vif, suspend);
1319-
}
1320-
1321-
if (mt76_is_mmio(&dev->mt76))
1322-
req.wow_ctrl_tlv.wakeup_hif = WOW_PCIE;
1323-
else if (mt76_is_usb(&dev->mt76))
1324-
req.wow_ctrl_tlv.wakeup_hif = WOW_USB;
1325-
else if (mt76_is_sdio(&dev->mt76))
1326-
req.wow_ctrl_tlv.wakeup_hif = WOW_GPIO;
1327-
1328-
return mt76_mcu_send_msg(&dev->mt76, MCU_UNI_CMD_SUSPEND, &req,
1329-
sizeof(req), true);
1330-
}
1331-
1332-
static int
1333-
mt7921_mcu_set_wow_pattern(struct mt7921_dev *dev,
1334-
struct ieee80211_vif *vif,
1335-
u8 index, bool enable,
1336-
struct cfg80211_pkt_pattern *pattern)
1337-
{
1338-
struct mt7921_vif *mvif = (struct mt7921_vif *)vif->drv_priv;
1339-
struct mt7921_wow_pattern_tlv *ptlv;
1340-
struct sk_buff *skb;
1341-
struct req_hdr {
1342-
u8 bss_idx;
1343-
u8 pad[3];
1344-
} __packed hdr = {
1345-
.bss_idx = mvif->mt76.idx,
1346-
};
1347-
1348-
skb = mt76_mcu_msg_alloc(&dev->mt76, NULL,
1349-
sizeof(hdr) + sizeof(*ptlv));
1350-
if (!skb)
1351-
return -ENOMEM;
1352-
1353-
skb_put_data(skb, &hdr, sizeof(hdr));
1354-
ptlv = (struct mt7921_wow_pattern_tlv *)skb_put(skb, sizeof(*ptlv));
1355-
ptlv->tag = cpu_to_le16(UNI_SUSPEND_WOW_PATTERN);
1356-
ptlv->len = cpu_to_le16(sizeof(*ptlv));
1357-
ptlv->data_len = pattern->pattern_len;
1358-
ptlv->enable = enable;
1359-
ptlv->index = index;
1360-
1361-
memcpy(ptlv->pattern, pattern->pattern, pattern->pattern_len);
1362-
memcpy(ptlv->mask, pattern->mask, pattern->pattern_len / 8);
1363-
1364-
return mt76_mcu_skb_send_msg(&dev->mt76, skb, MCU_UNI_CMD_SUSPEND,
1365-
true);
1366-
}
1367-
1368-
static int
1369-
mt7921_mcu_set_suspend_mode(struct mt7921_dev *dev,
1370-
struct ieee80211_vif *vif,
1371-
bool enable, u8 mdtim, bool wow_suspend)
1372-
{
1373-
struct mt7921_vif *mvif = (struct mt7921_vif *)vif->drv_priv;
1374-
struct {
1375-
struct {
1376-
u8 bss_idx;
1377-
u8 pad[3];
1378-
} __packed hdr;
1379-
struct mt7921_suspend_tlv suspend_tlv;
1380-
} req = {
1381-
.hdr = {
1382-
.bss_idx = mvif->mt76.idx,
1383-
},
1384-
.suspend_tlv = {
1385-
.tag = cpu_to_le16(UNI_SUSPEND_MODE_SETTING),
1386-
.len = cpu_to_le16(sizeof(struct mt7921_suspend_tlv)),
1387-
.enable = enable,
1388-
.mdtim = mdtim,
1389-
.wow_suspend = wow_suspend,
1390-
},
1391-
};
1392-
1393-
return mt76_mcu_send_msg(&dev->mt76, MCU_UNI_CMD_SUSPEND, &req,
1394-
sizeof(req), true);
1395-
}
1396-
1397-
static int
1398-
mt7921_mcu_set_gtk_rekey(struct mt7921_dev *dev,
1399-
struct ieee80211_vif *vif,
1400-
bool suspend)
1401-
{
1402-
struct mt7921_vif *mvif = (struct mt7921_vif *)vif->drv_priv;
1403-
struct {
1404-
struct {
1405-
u8 bss_idx;
1406-
u8 pad[3];
1407-
} __packed hdr;
1408-
struct mt7921_gtk_rekey_tlv gtk_tlv;
1409-
} __packed req = {
1410-
.hdr = {
1411-
.bss_idx = mvif->mt76.idx,
1412-
},
1413-
.gtk_tlv = {
1414-
.tag = cpu_to_le16(UNI_OFFLOAD_OFFLOAD_GTK_REKEY),
1415-
.len = cpu_to_le16(sizeof(struct mt7921_gtk_rekey_tlv)),
1416-
.rekey_mode = !suspend,
1417-
},
1418-
};
1419-
1420-
return mt76_mcu_send_msg(&dev->mt76, MCU_UNI_CMD_OFFLOAD, &req,
1421-
sizeof(req), true);
1422-
}
1423-
1424-
static int
1425-
mt7921_mcu_set_arp_filter(struct mt7921_dev *dev, struct ieee80211_vif *vif,
1426-
bool suspend)
1427-
{
1428-
struct mt7921_vif *mvif = (struct mt7921_vif *)vif->drv_priv;
1429-
struct {
1430-
struct {
1431-
u8 bss_idx;
1432-
u8 pad[3];
1433-
} __packed hdr;
1434-
struct mt7921_arpns_tlv arpns;
1435-
} req = {
1436-
.hdr = {
1437-
.bss_idx = mvif->mt76.idx,
1438-
},
1439-
.arpns = {
1440-
.tag = cpu_to_le16(UNI_OFFLOAD_OFFLOAD_ARP),
1441-
.len = cpu_to_le16(sizeof(struct mt7921_arpns_tlv)),
1442-
.mode = suspend,
1443-
},
1444-
};
1445-
1446-
return mt76_mcu_send_msg(&dev->mt76, MCU_UNI_CMD_OFFLOAD, &req,
1447-
sizeof(req), true);
1448-
}
1449-
1450-
void mt7921_mcu_set_suspend_iter(void *priv, u8 *mac,
1451-
struct ieee80211_vif *vif)
1452-
{
1453-
struct mt7921_phy *phy = priv;
1454-
bool suspend = test_bit(MT76_STATE_SUSPEND, &phy->mt76->state);
1455-
struct ieee80211_hw *hw = phy->mt76->hw;
1456-
struct cfg80211_wowlan *wowlan = hw->wiphy->wowlan_config;
1457-
int i;
1458-
1459-
mt7921_mcu_set_gtk_rekey(phy->dev, vif, suspend);
1460-
mt7921_mcu_set_arp_filter(phy->dev, vif, suspend);
1461-
1462-
mt7921_mcu_set_suspend_mode(phy->dev, vif, suspend, 1, true);
1463-
1464-
for (i = 0; i < wowlan->n_patterns; i++)
1465-
mt7921_mcu_set_wow_pattern(phy->dev, vif, i, suspend,
1466-
&wowlan->patterns[i]);
1467-
mt7921_mcu_set_wow_ctrl(phy, vif, suspend, wowlan);
1468-
}
1469-
1470-
static void
1471-
mt7921_mcu_key_iter(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
1472-
struct ieee80211_sta *sta, struct ieee80211_key_conf *key,
1473-
void *data)
1474-
{
1475-
struct mt7921_gtk_rekey_tlv *gtk_tlv = data;
1476-
u32 cipher;
1477-
1478-
if (key->cipher != WLAN_CIPHER_SUITE_AES_CMAC &&
1479-
key->cipher != WLAN_CIPHER_SUITE_CCMP &&
1480-
key->cipher != WLAN_CIPHER_SUITE_TKIP)
1481-
return;
1482-
1483-
if (key->cipher == WLAN_CIPHER_SUITE_TKIP) {
1484-
gtk_tlv->proto = cpu_to_le32(NL80211_WPA_VERSION_1);
1485-
cipher = BIT(3);
1486-
} else {
1487-
gtk_tlv->proto = cpu_to_le32(NL80211_WPA_VERSION_2);
1488-
cipher = BIT(4);
1489-
}
1490-
1491-
/* we are assuming here to have a single pairwise key */
1492-
if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE) {
1493-
gtk_tlv->pairwise_cipher = cpu_to_le32(cipher);
1494-
gtk_tlv->group_cipher = cpu_to_le32(cipher);
1495-
gtk_tlv->keyid = key->keyidx;
1496-
}
1497-
}
1498-
1499-
int mt7921_mcu_update_gtk_rekey(struct ieee80211_hw *hw,
1500-
struct ieee80211_vif *vif,
1501-
struct cfg80211_gtk_rekey_data *key)
1502-
{
1503-
struct mt7921_vif *mvif = (struct mt7921_vif *)vif->drv_priv;
1504-
struct mt7921_dev *dev = mt7921_hw_dev(hw);
1505-
struct mt7921_gtk_rekey_tlv *gtk_tlv;
1506-
struct sk_buff *skb;
1507-
struct {
1508-
u8 bss_idx;
1509-
u8 pad[3];
1510-
} __packed hdr = {
1511-
.bss_idx = mvif->mt76.idx,
1512-
};
1513-
1514-
skb = mt76_mcu_msg_alloc(&dev->mt76, NULL,
1515-
sizeof(hdr) + sizeof(*gtk_tlv));
1516-
if (!skb)
1517-
return -ENOMEM;
1518-
1519-
skb_put_data(skb, &hdr, sizeof(hdr));
1520-
gtk_tlv = (struct mt7921_gtk_rekey_tlv *)skb_put(skb,
1521-
sizeof(*gtk_tlv));
1522-
gtk_tlv->tag = cpu_to_le16(UNI_OFFLOAD_OFFLOAD_GTK_REKEY);
1523-
gtk_tlv->len = cpu_to_le16(sizeof(*gtk_tlv));
1524-
gtk_tlv->rekey_mode = 2;
1525-
gtk_tlv->option = 1;
1526-
1527-
rcu_read_lock();
1528-
ieee80211_iter_keys_rcu(hw, vif, mt7921_mcu_key_iter, gtk_tlv);
1529-
rcu_read_unlock();
1530-
1531-
memcpy(gtk_tlv->kek, key->kek, NL80211_KEK_LEN);
1532-
memcpy(gtk_tlv->kck, key->kck, NL80211_KCK_LEN);
1533-
memcpy(gtk_tlv->replay_ctr, key->replay_ctr, NL80211_REPLAY_CTR_LEN);
1534-
1535-
return mt76_mcu_skb_send_msg(&dev->mt76, skb, MCU_UNI_CMD_OFFLOAD,
1536-
true);
1537-
}
1538-
#endif /* CONFIG_PM */

0 commit comments

Comments
 (0)