@@ -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
914986static 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 ,
0 commit comments