Skip to content

Commit 80fc1e3

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

File tree

5 files changed

+15
-334
lines changed

5 files changed

+15
-334
lines changed

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,13 @@ mt7921_init_wiphy(struct ieee80211_hw *hw)
6969

7070
wiphy->iface_combinations = if_comb;
7171
wiphy->n_iface_combinations = ARRAY_SIZE(if_comb);
72-
wiphy->max_scan_ie_len = MT7921_SCAN_IE_LEN;
72+
wiphy->max_scan_ie_len = MT76_CONNAC_SCAN_IE_LEN;
7373
wiphy->max_scan_ssids = 4;
74-
wiphy->max_sched_scan_plan_interval = MT7921_MAX_SCHED_SCAN_INTERVAL;
74+
wiphy->max_sched_scan_plan_interval =
75+
MT76_CONNAC_MAX_SCHED_SCAN_INTERVAL;
7576
wiphy->max_sched_scan_ie_len = IEEE80211_MAX_DATA_LEN;
76-
wiphy->max_sched_scan_ssids = MT7921_MAX_SCHED_SCAN_SSID;
77-
wiphy->max_match_sets = MT7921_MAX_SCAN_MATCH;
77+
wiphy->max_sched_scan_ssids = MT76_CONNAC_MAX_SCHED_SCAN_SSID;
78+
wiphy->max_match_sets = MT76_CONNAC_MAX_SCAN_MATCH;
7879
wiphy->max_sched_scan_reqs = 1;
7980
wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH;
8081

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -864,7 +864,7 @@ mt7921_hw_scan(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
864864
int err;
865865

866866
mutex_lock(&dev->mt76.mutex);
867-
err = mt7921_mcu_hw_scan(mphy->priv, vif, req);
867+
err = mt76_connac_mcu_hw_scan(mphy, vif, req);
868868
mutex_unlock(&dev->mt76.mutex);
869869

870870
return err;
@@ -877,7 +877,7 @@ mt7921_cancel_hw_scan(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
877877
struct mt76_phy *mphy = hw->priv;
878878

879879
mutex_lock(&dev->mt76.mutex);
880-
mt7921_mcu_cancel_hw_scan(mphy->priv, vif);
880+
mt76_connac_mcu_cancel_hw_scan(mphy, vif);
881881
mutex_unlock(&dev->mt76.mutex);
882882
}
883883

@@ -892,11 +892,11 @@ mt7921_start_sched_scan(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
892892

893893
mutex_lock(&dev->mt76.mutex);
894894

895-
err = mt7921_mcu_sched_scan_req(mphy->priv, vif, req);
895+
err = mt76_connac_mcu_sched_scan_req(mphy, vif, req);
896896
if (err < 0)
897897
goto out;
898898

899-
err = mt7921_mcu_sched_scan_enable(mphy->priv, vif, true);
899+
err = mt76_connac_mcu_sched_scan_enable(mphy, vif, true);
900900
out:
901901
mutex_unlock(&dev->mt76.mutex);
902902

@@ -911,7 +911,7 @@ mt7921_stop_sched_scan(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
911911
int err;
912912

913913
mutex_lock(&dev->mt76.mutex);
914-
err = mt7921_mcu_sched_scan_enable(mphy->priv, vif, false);
914+
err = mt76_connac_mcu_sched_scan_enable(mphy, vif, false);
915915
mutex_unlock(&dev->mt76.mutex);
916916

917917
return err;

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

Lines changed: 4 additions & 193 deletions
Original file line numberDiff line numberDiff line change
@@ -1110,197 +1110,7 @@ int mt7921_mcu_get_eeprom(struct mt7921_dev *dev, u32 offset)
11101110
return 0;
11111111
}
11121112

1113-
#define MT7921_SCAN_CHANNEL_TIME 60
1114-
int mt7921_mcu_hw_scan(struct mt7921_phy *phy, struct ieee80211_vif *vif,
1115-
struct ieee80211_scan_request *scan_req)
1116-
{
1117-
struct mt7921_vif *mvif = (struct mt7921_vif *)vif->drv_priv;
1118-
struct cfg80211_scan_request *sreq = &scan_req->req;
1119-
int n_ssids = 0, err, i, duration = MT7921_SCAN_CHANNEL_TIME;
1120-
int ext_channels_num = max_t(int, sreq->n_channels - 32, 0);
1121-
struct ieee80211_channel **scan_list = sreq->channels;
1122-
struct mt7921_dev *dev = phy->dev;
1123-
struct mt7921_mcu_scan_channel *chan;
1124-
struct mt7921_hw_scan_req *req;
1125-
struct sk_buff *skb;
1126-
1127-
skb = mt76_mcu_msg_alloc(&dev->mt76, NULL, sizeof(*req));
1128-
if (!skb)
1129-
return -ENOMEM;
1130-
1131-
set_bit(MT76_HW_SCANNING, &phy->mt76->state);
1132-
mvif->mt76.scan_seq_num = (mvif->mt76.scan_seq_num + 1) & 0x7f;
1133-
1134-
req = (struct mt7921_hw_scan_req *)skb_put(skb, sizeof(*req));
1135-
1136-
req->seq_num = mvif->mt76.scan_seq_num;
1137-
req->bss_idx = mvif->mt76.idx;
1138-
req->scan_type = sreq->n_ssids ? 1 : 0;
1139-
req->probe_req_num = sreq->n_ssids ? 2 : 0;
1140-
req->version = 1;
1141-
1142-
for (i = 0; i < sreq->n_ssids; i++) {
1143-
if (!sreq->ssids[i].ssid_len)
1144-
continue;
1145-
1146-
req->ssids[i].ssid_len = cpu_to_le32(sreq->ssids[i].ssid_len);
1147-
memcpy(req->ssids[i].ssid, sreq->ssids[i].ssid,
1148-
sreq->ssids[i].ssid_len);
1149-
n_ssids++;
1150-
}
1151-
req->ssid_type = n_ssids ? BIT(2) : BIT(0);
1152-
req->ssid_type_ext = n_ssids ? BIT(0) : 0;
1153-
req->ssids_num = n_ssids;
1154-
1155-
/* increase channel time for passive scan */
1156-
if (!sreq->n_ssids)
1157-
duration *= 2;
1158-
req->timeout_value = cpu_to_le16(sreq->n_channels * duration);
1159-
req->channel_min_dwell_time = cpu_to_le16(duration);
1160-
req->channel_dwell_time = cpu_to_le16(duration);
1161-
1162-
req->channels_num = min_t(u8, sreq->n_channels, 32);
1163-
req->ext_channels_num = min_t(u8, ext_channels_num, 32);
1164-
for (i = 0; i < req->channels_num + req->ext_channels_num; i++) {
1165-
if (i >= 32)
1166-
chan = &req->ext_channels[i - 32];
1167-
else
1168-
chan = &req->channels[i];
1169-
1170-
chan->band = scan_list[i]->band == NL80211_BAND_2GHZ ? 1 : 2;
1171-
chan->channel_num = scan_list[i]->hw_value;
1172-
}
1173-
req->channel_type = sreq->n_channels ? 4 : 0;
1174-
1175-
if (sreq->ie_len > 0) {
1176-
memcpy(req->ies, sreq->ie, sreq->ie_len);
1177-
req->ies_len = cpu_to_le16(sreq->ie_len);
1178-
}
1179-
1180-
memcpy(req->bssid, sreq->bssid, ETH_ALEN);
1181-
if (sreq->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) {
1182-
get_random_mask_addr(req->random_mac, sreq->mac_addr,
1183-
sreq->mac_addr_mask);
1184-
req->scan_func = 1;
1185-
}
1186-
1187-
err = mt76_mcu_skb_send_msg(&dev->mt76, skb, MCU_CMD_START_HW_SCAN,
1188-
false);
1189-
if (err < 0)
1190-
clear_bit(MT76_HW_SCANNING, &phy->mt76->state);
1191-
1192-
return err;
1193-
}
1194-
1195-
int mt7921_mcu_cancel_hw_scan(struct mt7921_phy *phy,
1196-
struct ieee80211_vif *vif)
1197-
{
1198-
struct mt7921_vif *mvif = (struct mt7921_vif *)vif->drv_priv;
1199-
struct mt7921_dev *dev = phy->dev;
1200-
struct {
1201-
u8 seq_num;
1202-
u8 is_ext_channel;
1203-
u8 rsv[2];
1204-
} __packed req = {
1205-
.seq_num = mvif->mt76.scan_seq_num,
1206-
};
1207-
1208-
if (test_and_clear_bit(MT76_HW_SCANNING, &phy->mt76->state)) {
1209-
struct cfg80211_scan_info info = {
1210-
.aborted = true,
1211-
};
1212-
1213-
ieee80211_scan_completed(phy->mt76->hw, &info);
1214-
}
1215-
1216-
return mt76_mcu_send_msg(&dev->mt76, MCU_CMD_CANCEL_HW_SCAN, &req,
1217-
sizeof(req), false);
1218-
}
1219-
1220-
int mt7921_mcu_sched_scan_req(struct mt7921_phy *phy,
1221-
struct ieee80211_vif *vif,
1222-
struct cfg80211_sched_scan_request *sreq)
1223-
{
1224-
struct mt7921_vif *mvif = (struct mt7921_vif *)vif->drv_priv;
1225-
struct ieee80211_channel **scan_list = sreq->channels;
1226-
struct mt7921_dev *dev = phy->dev;
1227-
struct mt7921_mcu_scan_channel *chan;
1228-
struct mt7921_sched_scan_req *req;
1229-
struct cfg80211_match_set *match;
1230-
struct cfg80211_ssid *ssid;
1231-
struct sk_buff *skb;
1232-
int i;
1233-
1234-
skb = mt76_mcu_msg_alloc(&dev->mt76, NULL,
1235-
sizeof(*req) + sreq->ie_len);
1236-
if (!skb)
1237-
return -ENOMEM;
1238-
1239-
mvif->mt76.scan_seq_num = (mvif->mt76.scan_seq_num + 1) & 0x7f;
1240-
1241-
req = (struct mt7921_sched_scan_req *)skb_put(skb, sizeof(*req));
1242-
req->version = 1;
1243-
req->seq_num = mvif->mt76.scan_seq_num;
1244-
1245-
req->ssids_num = sreq->n_ssids;
1246-
for (i = 0; i < req->ssids_num; i++) {
1247-
ssid = &sreq->ssids[i];
1248-
memcpy(req->ssids[i].ssid, ssid->ssid, ssid->ssid_len);
1249-
req->ssids[i].ssid_len = cpu_to_le32(ssid->ssid_len);
1250-
}
1251-
1252-
req->match_num = sreq->n_match_sets;
1253-
for (i = 0; i < req->match_num; i++) {
1254-
match = &sreq->match_sets[i];
1255-
memcpy(req->match[i].ssid, match->ssid.ssid,
1256-
match->ssid.ssid_len);
1257-
req->match[i].rssi_th = cpu_to_le32(match->rssi_thold);
1258-
req->match[i].ssid_len = match->ssid.ssid_len;
1259-
}
1260-
1261-
req->channel_type = sreq->n_channels ? 4 : 0;
1262-
req->channels_num = min_t(u8, sreq->n_channels, 64);
1263-
for (i = 0; i < req->channels_num; i++) {
1264-
chan = &req->channels[i];
1265-
chan->band = scan_list[i]->band == NL80211_BAND_2GHZ ? 1 : 2;
1266-
chan->channel_num = scan_list[i]->hw_value;
1267-
}
1268-
1269-
req->intervals_num = sreq->n_scan_plans;
1270-
for (i = 0; i < req->intervals_num; i++)
1271-
req->intervals[i] = cpu_to_le16(sreq->scan_plans[i].interval);
1272-
1273-
if (sreq->ie_len > 0) {
1274-
req->ie_len = cpu_to_le16(sreq->ie_len);
1275-
memcpy(skb_put(skb, sreq->ie_len), sreq->ie, sreq->ie_len);
1276-
}
1277-
1278-
return mt76_mcu_skb_send_msg(&dev->mt76, skb, MCU_CMD_SCHED_SCAN_REQ,
1279-
false);
1280-
}
1281-
1282-
int mt7921_mcu_sched_scan_enable(struct mt7921_phy *phy,
1283-
struct ieee80211_vif *vif,
1284-
bool enable)
1285-
{
1286-
struct mt7921_dev *dev = phy->dev;
1287-
struct {
1288-
u8 active; /* 0: enabled 1: disabled */
1289-
u8 rsv[3];
1290-
} __packed req = {
1291-
.active = !enable,
1292-
};
1293-
1294-
if (enable)
1295-
set_bit(MT76_HW_SCHED_SCANNING, &phy->mt76->state);
1296-
else
1297-
clear_bit(MT76_HW_SCHED_SCANNING, &phy->mt76->state);
1298-
1299-
return mt76_mcu_send_msg(&dev->mt76, MCU_CMD_SCHED_SCAN_ENABLE, &req,
1300-
sizeof(req), false);
1301-
}
1302-
1303-
u32 mt7921_get_wtbl_info(struct mt7921_dev *dev, u16 wlan_idx)
1113+
u32 mt7921_get_wtbl_info(struct mt7921_dev *dev, u32 wlan_idx)
13041114
{
13051115
struct mt7921_mcu_wlan_info wtbl_info = {
13061116
.wlan_idx = cpu_to_le32(wlan_idx),
@@ -1502,9 +1312,10 @@ mt7921_mcu_set_wow_ctrl(struct mt7921_phy *phy, struct ieee80211_vif *vif,
15021312
if (wowlan->disconnect)
15031313
req.wow_ctrl_tlv.trigger |= BIT(2);
15041314
if (wowlan->nd_config) {
1505-
mt7921_mcu_sched_scan_req(phy, vif, wowlan->nd_config);
1315+
mt76_connac_mcu_sched_scan_req(&dev->mphy, vif,
1316+
wowlan->nd_config);
15061317
req.wow_ctrl_tlv.trigger |= BIT(5);
1507-
mt7921_mcu_sched_scan_enable(phy, vif, suspend);
1318+
mt76_connac_mcu_sched_scan_enable(&dev->mphy, vif, suspend);
15081319
}
15091320

15101321
if (mt76_is_mmio(&dev->mt76))

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

Lines changed: 0 additions & 116 deletions
Original file line numberDiff line numberDiff line change
@@ -386,122 +386,6 @@ struct mt7921_mcu_reg_event {
386386
__le32 val;
387387
} __packed;
388388

389-
struct mt7921_mcu_scan_ssid {
390-
__le32 ssid_len;
391-
u8 ssid[IEEE80211_MAX_SSID_LEN];
392-
} __packed;
393-
394-
struct mt7921_mcu_scan_channel {
395-
u8 band; /* 1: 2.4GHz
396-
* 2: 5.0GHz
397-
* Others: Reserved
398-
*/
399-
u8 channel_num;
400-
} __packed;
401-
402-
struct mt7921_mcu_scan_match {
403-
__le32 rssi_th;
404-
u8 ssid[IEEE80211_MAX_SSID_LEN];
405-
u8 ssid_len;
406-
u8 rsv[3];
407-
} __packed;
408-
409-
struct mt7921_hw_scan_req {
410-
u8 seq_num;
411-
u8 bss_idx;
412-
u8 scan_type; /* 0: PASSIVE SCAN
413-
* 1: ACTIVE SCAN
414-
*/
415-
u8 ssid_type; /* BIT(0) wildcard SSID
416-
* BIT(1) P2P wildcard SSID
417-
* BIT(2) specified SSID + wildcard SSID
418-
* BIT(2) + ssid_type_ext BIT(0) specified SSID only
419-
*/
420-
u8 ssids_num;
421-
u8 probe_req_num; /* Number of probe request for each SSID */
422-
u8 scan_func; /* BIT(0) Enable random MAC scan
423-
* BIT(1) Disable DBDC scan type 1~3.
424-
* BIT(2) Use DBDC scan type 3 (dedicated one RF to scan).
425-
*/
426-
u8 version; /* 0: Not support fields after ies.
427-
* 1: Support fields after ies.
428-
*/
429-
struct mt7921_mcu_scan_ssid ssids[4];
430-
__le16 probe_delay_time;
431-
__le16 channel_dwell_time; /* channel Dwell interval */
432-
__le16 timeout_value;
433-
u8 channel_type; /* 0: Full channels
434-
* 1: Only 2.4GHz channels
435-
* 2: Only 5GHz channels
436-
* 3: P2P social channel only (channel #1, #6 and #11)
437-
* 4: Specified channels
438-
* Others: Reserved
439-
*/
440-
u8 channels_num; /* valid when channel_type is 4 */
441-
/* valid when channels_num is set */
442-
struct mt7921_mcu_scan_channel channels[32];
443-
__le16 ies_len;
444-
u8 ies[MT7921_SCAN_IE_LEN];
445-
/* following fields are valid if version > 0 */
446-
u8 ext_channels_num;
447-
u8 ext_ssids_num;
448-
__le16 channel_min_dwell_time;
449-
struct mt7921_mcu_scan_channel ext_channels[32];
450-
struct mt7921_mcu_scan_ssid ext_ssids[6];
451-
u8 bssid[ETH_ALEN];
452-
u8 random_mac[ETH_ALEN]; /* valid when BIT(1) in scan_func is set. */
453-
u8 pad[63];
454-
u8 ssid_type_ext;
455-
} __packed;
456-
457-
#define SCAN_DONE_EVENT_MAX_CHANNEL_NUM 64
458-
struct mt7921_hw_scan_done {
459-
u8 seq_num;
460-
u8 sparse_channel_num;
461-
struct mt7921_mcu_scan_channel sparse_channel;
462-
u8 complete_channel_num;
463-
u8 current_state;
464-
u8 version;
465-
u8 pad;
466-
__le32 beacon_scan_num;
467-
u8 pno_enabled;
468-
u8 pad2[3];
469-
u8 sparse_channel_valid_num;
470-
u8 pad3[3];
471-
u8 channel_num[SCAN_DONE_EVENT_MAX_CHANNEL_NUM];
472-
/* idle format for channel_idle_time
473-
* 0: first bytes: idle time(ms) 2nd byte: dwell time(ms)
474-
* 1: first bytes: idle time(8ms) 2nd byte: dwell time(8ms)
475-
* 2: dwell time (16us)
476-
*/
477-
__le16 channel_idle_time[SCAN_DONE_EVENT_MAX_CHANNEL_NUM];
478-
/* beacon and probe response count */
479-
u8 beacon_probe_num[SCAN_DONE_EVENT_MAX_CHANNEL_NUM];
480-
u8 mdrdy_count[SCAN_DONE_EVENT_MAX_CHANNEL_NUM];
481-
__le32 beacon_2g_num;
482-
__le32 beacon_5g_num;
483-
} __packed;
484-
485-
struct mt7921_sched_scan_req {
486-
u8 version;
487-
u8 seq_num;
488-
u8 stop_on_match;
489-
u8 ssids_num;
490-
u8 match_num;
491-
u8 pad;
492-
__le16 ie_len;
493-
struct mt7921_mcu_scan_ssid ssids[MT7921_MAX_SCHED_SCAN_SSID];
494-
struct mt7921_mcu_scan_match match[MT7921_MAX_SCAN_MATCH];
495-
u8 channel_type;
496-
u8 channels_num;
497-
u8 intervals_num;
498-
u8 scan_func;
499-
struct mt7921_mcu_scan_channel channels[64];
500-
__le16 intervals[MT7921_MAX_SCHED_SCAN_INTERVAL];
501-
u8 bss_idx;
502-
u8 pad2[64];
503-
} __packed;
504-
505389
struct mt7921_mcu_tx_config {
506390
u8 peer_addr[ETH_ALEN];
507391
u8 sw;

0 commit comments

Comments
 (0)