Skip to content

Commit e5d944b

Browse files
LorenzoBianconinbd168
authored andcommitted
wifi: mt76: mt7996: Add mt7996_sta_state routine
Introduce mt7996_sta_state routine in order to initialize wcid structure in mt7996 codebase. This is a preliminary patch to enable MLO support in MT7996 driver. Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org> Link: https://patch.msgid.link/20250311-mt7996-mlo-v2-6-31df6972519b@kernel.org Signed-off-by: Felix Fietkau <nbd@nbd.name>
1 parent 0a04597 commit e5d944b

File tree

5 files changed

+91
-25
lines changed

5 files changed

+91
-25
lines changed

drivers/net/wireless/mediatek/mt76/mac80211.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -816,8 +816,8 @@ void mt76_free_device(struct mt76_dev *dev)
816816
}
817817
EXPORT_SYMBOL_GPL(mt76_free_device);
818818

819-
static struct mt76_phy *
820-
mt76_vif_phy(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
819+
struct mt76_phy *mt76_vif_phy(struct ieee80211_hw *hw,
820+
struct ieee80211_vif *vif)
821821
{
822822
struct mt76_vif_link *mlink = (struct mt76_vif_link *)vif->drv_priv;
823823
struct mt76_chanctx *ctx;
@@ -831,6 +831,7 @@ mt76_vif_phy(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
831831
ctx = (struct mt76_chanctx *)mlink->ctx->drv_priv;
832832
return ctx->phy;
833833
}
834+
EXPORT_SYMBOL_GPL(mt76_vif_phy);
834835

835836
static void mt76_rx_release_amsdu(struct mt76_phy *phy, enum mt76_rxq_id q)
836837
{

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1228,6 +1228,8 @@ struct mt76_phy *mt76_alloc_phy(struct mt76_dev *dev, unsigned int size,
12281228
u8 band_idx);
12291229
int mt76_register_phy(struct mt76_phy *phy, bool vht,
12301230
struct ieee80211_rate *rates, int n_rates);
1231+
struct mt76_phy *mt76_vif_phy(struct ieee80211_hw *hw,
1232+
struct ieee80211_vif *vif);
12311233

12321234
struct dentry *mt76_register_debugfs_fops(struct mt76_phy *phy,
12331235
const struct file_operations *ops);

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

Lines changed: 86 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -815,20 +815,26 @@ mt7996_channel_switch_beacon(struct ieee80211_hw *hw,
815815
mutex_unlock(&dev->mt76.mutex);
816816
}
817817

818-
int mt7996_mac_sta_add(struct mt76_dev *mdev, struct ieee80211_vif *vif,
819-
struct ieee80211_sta *sta)
818+
static int
819+
mt7996_mac_sta_add(struct mt76_phy *mphy, struct ieee80211_vif *vif,
820+
struct ieee80211_sta *sta)
820821
{
822+
struct mt76_dev *mdev = mphy->dev;
821823
struct mt7996_dev *dev = container_of(mdev, struct mt7996_dev, mt76);
822824
struct mt7996_sta *msta = (struct mt7996_sta *)sta->drv_priv;
823825
struct mt7996_vif *mvif = (struct mt7996_vif *)vif->drv_priv;
824826
struct mt7996_sta_link *msta_link = &msta->deflink;
825827
struct mt7996_vif_link *link = &mvif->deflink;
826-
u8 band_idx = link->phy->mt76->band_idx;
827-
int idx;
828+
u8 band_idx = mphy->band_idx;
829+
int i, idx, ret = 0;
828830

829-
idx = mt76_wcid_alloc(dev->mt76.wcid_mask, MT7996_WTBL_STA);
830-
if (idx < 0)
831-
return -ENOSPC;
831+
mutex_lock(&mdev->mutex);
832+
833+
idx = mt76_wcid_alloc(mdev->wcid_mask, MT7996_WTBL_STA);
834+
if (idx < 0) {
835+
ret = -ENOSPC;
836+
goto unlock;
837+
}
832838

833839
msta->vif = mvif;
834840
INIT_LIST_HEAD(&msta_link->rc_list);
@@ -838,20 +844,37 @@ int mt7996_mac_sta_add(struct mt76_dev *mdev, struct ieee80211_vif *vif,
838844
msta_link->wcid.idx = idx;
839845
msta_link->wcid.phy_idx = band_idx;
840846

847+
for (i = 0; i < ARRAY_SIZE(sta->txq); i++) {
848+
struct mt76_txq *mtxq;
849+
850+
if (!sta->txq[i])
851+
continue;
852+
853+
mtxq = (struct mt76_txq *)sta->txq[i]->drv_priv;
854+
mtxq->wcid = idx;
855+
}
856+
841857
ewma_avg_signal_init(&msta_link->avg_ack_signal);
858+
ewma_signal_init(&msta_link->wcid.rssi);
842859

843860
mt7996_mac_wtbl_update(dev, idx,
844861
MT_WTBL_UPDATE_ADM_COUNT_CLEAR);
845862
mt7996_mcu_add_sta(dev, vif, &link->mt76, sta, CONN_STATE_DISCONNECT,
846863
true);
847864

848-
return 0;
865+
rcu_assign_pointer(mdev->wcid[idx], &msta_link->wcid);
866+
mt76_wcid_init(&msta_link->wcid, band_idx);
867+
mphy->num_sta++;
868+
unlock:
869+
mutex_unlock(&mdev->mutex);
870+
871+
return ret;
849872
}
850873

851-
int mt7996_mac_sta_event(struct mt76_dev *mdev, struct ieee80211_vif *vif,
852-
struct ieee80211_sta *sta, enum mt76_sta_event ev)
874+
static int
875+
mt7996_mac_sta_event(struct mt7996_dev *dev, struct ieee80211_vif *vif,
876+
struct ieee80211_sta *sta, enum mt76_sta_event ev)
853877
{
854-
struct mt7996_dev *dev = container_of(mdev, struct mt7996_dev, mt76);
855878
struct mt7996_sta *msta = (struct mt7996_sta *)sta->drv_priv;
856879
struct mt7996_sta_link *msta_link = &msta->deflink;
857880
struct mt7996_vif *mvif = (struct mt7996_vif *)vif->drv_priv;
@@ -893,12 +916,20 @@ int mt7996_mac_sta_event(struct mt76_dev *mdev, struct ieee80211_vif *vif,
893916
return 0;
894917
}
895918

896-
void mt7996_mac_sta_remove(struct mt76_dev *mdev, struct ieee80211_vif *vif,
897-
struct ieee80211_sta *sta)
919+
static void
920+
mt7996_mac_sta_remove(struct mt76_phy *mphy, struct ieee80211_vif *vif,
921+
struct ieee80211_sta *sta)
898922
{
923+
struct mt76_dev *mdev = mphy->dev;
899924
struct mt7996_dev *dev = container_of(mdev, struct mt7996_dev, mt76);
900925
struct mt7996_sta *msta = (struct mt7996_sta *)sta->drv_priv;
901926
struct mt7996_sta_link *msta_link = &msta->deflink;
927+
int i, idx = msta_link->wcid.idx;
928+
929+
mutex_lock(&mdev->mutex);
930+
931+
for (i = 0; i < ARRAY_SIZE(msta_link->wcid.aggr); i++)
932+
mt76_rx_aggr_stop(mdev, &msta_link->wcid, i);
902933

903934
mt7996_mac_wtbl_update(dev, msta_link->wcid.idx,
904935
MT_WTBL_UPDATE_ADM_COUNT_CLEAR);
@@ -909,6 +940,47 @@ void mt7996_mac_sta_remove(struct mt76_dev *mdev, struct ieee80211_vif *vif,
909940
if (!list_empty(&msta_link->rc_list))
910941
list_del_init(&msta_link->rc_list);
911942
spin_unlock_bh(&mdev->sta_poll_lock);
943+
944+
mt76_wcid_cleanup(mdev, &msta_link->wcid);
945+
mt76_wcid_mask_clear(mdev->wcid_mask, idx);
946+
mphy->num_sta--;
947+
948+
mutex_unlock(&mdev->mutex);
949+
}
950+
951+
static int
952+
mt7996_sta_state(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
953+
struct ieee80211_sta *sta, enum ieee80211_sta_state old_state,
954+
enum ieee80211_sta_state new_state)
955+
{
956+
struct mt76_phy *mphy = mt76_vif_phy(hw, vif);
957+
struct mt7996_dev *dev = mt7996_hw_dev(hw);
958+
enum mt76_sta_event ev;
959+
960+
if (!mphy)
961+
return -EINVAL;
962+
963+
if (old_state == IEEE80211_STA_NOTEXIST &&
964+
new_state == IEEE80211_STA_NONE)
965+
return mt7996_mac_sta_add(mphy, vif, sta);
966+
967+
if (old_state == IEEE80211_STA_NONE &&
968+
new_state == IEEE80211_STA_NOTEXIST)
969+
mt7996_mac_sta_remove(mphy, vif, sta);
970+
971+
if (old_state == IEEE80211_STA_AUTH &&
972+
new_state == IEEE80211_STA_ASSOC)
973+
ev = MT76_STA_EVENT_ASSOC;
974+
else if (old_state == IEEE80211_STA_ASSOC &&
975+
new_state == IEEE80211_STA_AUTHORIZED)
976+
ev = MT76_STA_EVENT_AUTHORIZE;
977+
else if (old_state == IEEE80211_STA_ASSOC &&
978+
new_state == IEEE80211_STA_AUTH)
979+
ev = MT76_STA_EVENT_DISASSOC;
980+
else
981+
return 0;
982+
983+
return mt7996_mac_sta_event(dev, vif, sta, ev);
912984
}
913985

914986
static void mt7996_tx(struct ieee80211_hw *hw,
@@ -1720,7 +1792,7 @@ const struct ieee80211_ops mt7996_ops = {
17201792
.configure_filter = mt7996_configure_filter,
17211793
.vif_cfg_changed = mt7996_vif_cfg_changed,
17221794
.link_info_changed = mt7996_link_info_changed,
1723-
.sta_state = mt76_sta_state,
1795+
.sta_state = mt7996_sta_state,
17241796
.sta_pre_rcu_remove = mt76_sta_pre_rcu_remove,
17251797
.link_sta_rc_update = mt7996_sta_rc_update,
17261798
.set_key = mt7996_set_key,

drivers/net/wireless/mediatek/mt76/mt7996/mmio.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -618,9 +618,6 @@ struct mt7996_dev *mt7996_mmio_probe(struct device *pdev,
618618
.rx_skb = mt7996_queue_rx_skb,
619619
.rx_check = mt7996_rx_check,
620620
.rx_poll_complete = mt7996_rx_poll_complete,
621-
.sta_add = mt7996_mac_sta_add,
622-
.sta_event = mt7996_mac_sta_event,
623-
.sta_remove = mt7996_mac_sta_remove,
624621
.update_survey = mt7996_update_channel,
625622
.set_channel = mt7996_set_channel,
626623
.vif_link_add = mt7996_vif_link_add,

drivers/net/wireless/mediatek/mt76/mt7996/mt7996.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -696,12 +696,6 @@ void mt7996_mac_write_txwi(struct mt7996_dev *dev, __le32 *txwi,
696696
struct ieee80211_key_conf *key, int pid,
697697
enum mt76_txq_id qid, u32 changed);
698698
void mt7996_mac_set_coverage_class(struct mt7996_phy *phy);
699-
int mt7996_mac_sta_add(struct mt76_dev *mdev, struct ieee80211_vif *vif,
700-
struct ieee80211_sta *sta);
701-
int mt7996_mac_sta_event(struct mt76_dev *mdev, struct ieee80211_vif *vif,
702-
struct ieee80211_sta *sta, enum mt76_sta_event ev);
703-
void mt7996_mac_sta_remove(struct mt76_dev *mdev, struct ieee80211_vif *vif,
704-
struct ieee80211_sta *sta);
705699
void mt7996_mac_work(struct work_struct *work);
706700
void mt7996_mac_reset_work(struct work_struct *work);
707701
void mt7996_mac_dump_work(struct work_struct *work);

0 commit comments

Comments
 (0)