Lines Matching refs:sta
52 * we support. For a regular station this mean we add the AP sta when we
54 * get to know about a peer on the same IBSS. For WDS we add the sta for
69 struct ieee80211_link_sta sta;
93 struct sta_info *sta)
95 return rhltable_remove(&local->sta_hash, &sta->hash_node,
117 static void __cleanup_single_sta(struct sta_info *sta)
121 struct ieee80211_sub_if_data *sdata = sta->sdata;
125 if (test_sta_flag(sta, WLAN_STA_PS_STA) ||
126 test_sta_flag(sta, WLAN_STA_PS_DRIVER) ||
127 test_sta_flag(sta, WLAN_STA_PS_DELIVER)) {
128 if (sta->sdata->vif.type == NL80211_IFTYPE_AP ||
129 sta->sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
136 clear_sta_flag(sta, WLAN_STA_PS_STA);
137 clear_sta_flag(sta, WLAN_STA_PS_DRIVER);
138 clear_sta_flag(sta, WLAN_STA_PS_DELIVER);
143 for (i = 0; i < ARRAY_SIZE(sta->sta.txq); i++) {
146 if (!sta->sta.txq[i])
149 txqi = to_txq_info(sta->sta.txq[i]);
155 local->total_ps_buffered -= skb_queue_len(&sta->ps_tx_buf[ac]);
156 ieee80211_purge_tx_queue(&local->hw, &sta->ps_tx_buf[ac]);
157 ieee80211_purge_tx_queue(&local->hw, &sta->tx_filtered[ac]);
161 mesh_sta_cleanup(sta);
163 cancel_work_sync(&sta->drv_deliver_wk);
172 kfree(sta->ampdu_mlme.tid_start_tx[i]);
173 tid_tx = rcu_dereference_raw(sta->ampdu_mlme.tid_tx[i]);
181 static void cleanup_single_sta(struct sta_info *sta)
183 struct ieee80211_sub_if_data *sdata = sta->sdata;
186 __cleanup_single_sta(sta);
187 sta_info_free(local, sta);
202 struct sta_info *sta;
205 for_each_sta_info(local, addr, sta, tmp) {
206 if (sta->sdata == sdata) {
211 return sta;
219 * Get sta info either from the specified interface
227 struct sta_info *sta;
230 for_each_sta_info(local, addr, sta, tmp) {
231 if (sta->sdata == sdata ||
232 (sta->sdata->bss && sta->sdata->bss == sdata->bss)) {
237 return sta;
260 struct sta_info *sta = link_sta->sta;
262 if (sta->sdata == sdata ||
263 (sta->sdata->bss && sta->sdata->bss == sdata->bss)) {
286 struct sta_info *sta = link_sta->sta;
293 return &sta->sta;
296 link = rcu_dereference(sta->sdata->link[_link_id]);
305 return &sta->sta;
316 struct sta_info *sta;
318 for_each_sta_info(local, sta_addr, sta, tmp) {
319 if (ether_addr_equal(vif_addr, sta->sdata->vif.addr))
320 return sta;
330 struct sta_info *sta;
333 list_for_each_entry_rcu(sta, &local->sta_list, list,
335 if (sdata != sta->sdata)
341 return sta;
352 static void sta_remove_link(struct sta_info *sta, unsigned int link_id,
358 link_sta = rcu_access_pointer(sta->link[link_id]);
359 if (link_sta != &sta->deflink)
360 lockdep_assert_held(&sta->local->sta_mtx);
366 link_sta_info_hash_del(sta->local, link_sta);
368 if (test_sta_flag(sta, WLAN_STA_INSERTED))
371 if (link_sta != &sta->deflink)
374 sta->sta.valid_links &= ~BIT(link_id);
375 RCU_INIT_POINTER(sta->link[link_id], NULL);
376 RCU_INIT_POINTER(sta->sta.link[link_id], NULL);
382 ieee80211_sta_recalc_aggregates(&sta->sta);
389 * @sta: STA info to free
396 void sta_info_free(struct ieee80211_local *local, struct sta_info *sta)
400 for (i = 0; i < ARRAY_SIZE(sta->link); i++) {
403 link_sta = rcu_access_pointer(sta->link[i]);
407 sta_remove_link(sta, i, false);
418 while (sta->sta_state > IEEE80211_STA_NONE) {
421 WARN_ON_ONCE(test_sta_flag(sta, WLAN_STA_INSERTED));
423 ret = sta_info_move_state(sta, sta->sta_state - 1);
428 if (sta->rate_ctrl)
429 rate_control_free_sta(sta);
431 sta_dbg(sta->sdata, "Destroyed STA %pM\n", sta->sta.addr);
433 kfree(to_txq_info(sta->sta.txq[0]));
434 kfree(rcu_dereference_raw(sta->sta.rates));
436 kfree(sta->mesh);
439 sta_info_free_link(&sta->deflink);
440 kfree(sta);
445 struct sta_info *sta)
447 return rhltable_insert(&local->sta_hash, &sta->hash_node,
453 struct sta_info *sta;
455 sta = container_of(wk, struct sta_info, drv_deliver_wk);
457 if (sta->dead)
461 if (!test_sta_flag(sta, WLAN_STA_PS_STA))
462 ieee80211_sta_ps_deliver_wakeup(sta);
463 else if (test_and_clear_sta_flag(sta, WLAN_STA_PSPOLL))
464 ieee80211_sta_ps_deliver_poll_response(sta);
465 else if (test_and_clear_sta_flag(sta, WLAN_STA_UAPSD))
466 ieee80211_sta_ps_deliver_uapsd(sta);
471 struct sta_info *sta, gfp_t gfp)
476 sta->rate_ctrl = local->rate_ctrl;
477 sta->rate_ctrl_priv = rate_control_alloc_sta(sta->rate_ctrl,
478 sta, gfp);
479 if (!sta->rate_ctrl_priv)
510 static void sta_info_add_link(struct sta_info *sta,
515 link_info->sta = sta;
518 link_info->pub->sta = &sta->sta;
520 rcu_assign_pointer(sta->link[link_id], link_info);
521 rcu_assign_pointer(sta->sta.link[link_id], link_sta);
534 struct sta_info *sta;
539 sta = kzalloc(sizeof(*sta) + hw->sta_data_size, gfp);
540 if (!sta)
543 sta->local = local;
544 sta->sdata = sdata;
546 if (sta_info_alloc_link(local, &sta->deflink, gfp))
550 sta_info_add_link(sta, link_id, &sta->deflink,
551 &sta->sta.deflink);
552 sta->sta.valid_links = BIT(link_id);
554 sta_info_add_link(sta, 0, &sta->deflink, &sta->sta.deflink);
557 sta->sta.cur = &sta->sta.deflink.agg;
559 spin_lock_init(&sta->lock);
560 spin_lock_init(&sta->ps_lock);
561 INIT_WORK(&sta->drv_deliver_wk, sta_deliver_ps_frames);
562 INIT_WORK(&sta->ampdu_mlme.work, ieee80211_ba_session_work);
563 mutex_init(&sta->ampdu_mlme.mtx);
566 sta->mesh = kzalloc(sizeof(*sta->mesh), gfp);
567 if (!sta->mesh)
569 sta->mesh->plink_sta = sta;
570 spin_lock_init(&sta->mesh->plink_lock);
572 timer_setup(&sta->mesh->plink_timer, mesh_plink_timer,
574 sta->mesh->nonpeer_pm = NL80211_MESH_POWER_ACTIVE;
578 memcpy(sta->addr, addr, ETH_ALEN);
579 memcpy(sta->sta.addr, addr, ETH_ALEN);
580 memcpy(sta->deflink.addr, link_addr, ETH_ALEN);
581 memcpy(sta->sta.deflink.addr, link_addr, ETH_ALEN);
582 sta->sta.max_rx_aggregation_subframes =
593 BUILD_BUG_ON(ARRAY_SIZE(sta->ptk) <= INVALID_PTK_KEYIDX);
594 sta->ptk_idx = INVALID_PTK_KEYIDX;
597 ieee80211_init_frag_cache(&sta->frags);
599 sta->sta_state = IEEE80211_STA_NONE;
602 sta->amsdu_mesh_control = -1;
605 sta->reserved_tid = IEEE80211_TID_UNRESERVED;
607 sta->last_connected = ktime_get_seconds();
612 txq_data = kcalloc(ARRAY_SIZE(sta->sta.txq), size, gfp);
616 for (i = 0; i < ARRAY_SIZE(sta->sta.txq); i++) {
620 ieee80211_txq_init(sdata, sta, txq, i);
623 if (sta_prepare_rate_control(local, sta, gfp))
626 sta->airtime_weight = IEEE80211_DEFAULT_AIRTIME_WEIGHT;
629 skb_queue_head_init(&sta->ps_tx_buf[i]);
630 skb_queue_head_init(&sta->tx_filtered[i]);
631 sta->airtime[i].deficit = sta->airtime_weight;
632 atomic_set(&sta->airtime[i].aql_tx_pending, 0);
633 sta->airtime[i].aql_limit_low = local->aql_txq_limit_low[i];
634 sta->airtime[i].aql_limit_high = local->aql_txq_limit_high[i];
638 sta->last_seq_ctrl[i] = cpu_to_le16(USHRT_MAX);
678 sta->sta.deflink.supp_rates[i] |= BIT(r);
682 sta->cparams.ce_threshold = CODEL_DISABLED_THRESHOLD;
683 sta->cparams.target = MS2TIME(20);
684 sta->cparams.interval = MS2TIME(100);
685 sta->cparams.ecn = true;
686 sta->cparams.ce_threshold_selector = 0;
687 sta->cparams.ce_threshold_mask = 0;
689 sta_dbg(sdata, "Allocated STA %pM\n", sta->sta.addr);
691 return sta;
694 kfree(to_txq_info(sta->sta.txq[0]));
696 sta_info_free_link(&sta->deflink);
698 kfree(sta->mesh);
700 kfree(sta);
719 static int sta_info_insert_check(struct sta_info *sta)
721 struct ieee80211_sub_if_data *sdata = sta->sdata;
731 if (WARN_ON(ether_addr_equal(sta->sta.addr, sdata->vif.addr) ||
732 !is_valid_ether_addr(sta->sta.addr)))
742 ieee80211_find_sta_by_ifaddr(&sdata->local->hw, sta->addr, NULL)) {
753 struct sta_info *sta)
758 for (state = IEEE80211_STA_NOTEXIST; state < sta->sta_state; state++) {
759 err = drv_sta_state(local, sdata, sta, state, state + 1);
770 sta->uploaded = true;
777 sta->sta.addr, state + 1, err);
783 WARN_ON(drv_sta_state(local, sdata, sta, state, state - 1));
793 struct sta_info *sta;
796 list_for_each_entry_rcu(sta, &local->sta_list, list) {
797 if (sdata != sta->sdata ||
798 !test_sta_flag(sta, WLAN_STA_ASSOC))
800 if (!sta->sta.support_p2p_ps) {
819 static int sta_info_insert_finish(struct sta_info *sta) __acquires(RCU)
821 struct ieee80211_local *local = sta->local;
822 struct ieee80211_sub_if_data *sdata = sta->sdata;
829 if (sta_info_get_bss(sdata, sta->sta.addr)) {
845 set_sta_flag(sta, WLAN_STA_BLOCK_BA);
848 err = sta_info_hash_add(local, sta);
852 if (sta->sta.valid_links) {
853 err = link_sta_info_hash_add(local, &sta->deflink);
855 sta_info_hash_del(local, sta);
860 list_add_tail_rcu(&sta->list, &local->sta_list);
865 if (sta->sta_state >= IEEE80211_STA_ASSOC) {
866 ieee80211_recalc_min_chandef(sta->sdata, -1);
867 if (!sta->sta.support_p2p_ps)
868 ieee80211_recalc_p2p_go_ps_allowed(sta->sdata);
872 err = sta_info_insert_drv_state(local, sdata, sta);
876 set_sta_flag(sta, WLAN_STA_INSERTED);
879 clear_sta_flag(sta, WLAN_STA_BLOCK_BA);
881 ieee80211_sta_debugfs_add(sta);
882 rate_control_add_sta_debugfs(sta);
883 if (sta->sta.valid_links) {
886 for (i = 0; i < ARRAY_SIZE(sta->link); i++) {
889 link_sta = rcu_dereference_protected(sta->link[i],
900 ieee80211_link_sta_debugfs_add(&sta->deflink);
901 ieee80211_link_sta_debugfs_drv_add(&sta->deflink);
905 cfg80211_new_sta(sdata->dev, sta->sta.addr, sinfo, GFP_KERNEL);
908 sta_dbg(sdata, "Inserted STA %pM\n", sta->sta.addr);
917 ieee80211_check_fast_xmit(sta);
921 if (sta->sta.valid_links)
922 link_sta_info_hash_del(local, &sta->deflink);
923 sta_info_hash_del(local, sta);
924 list_del_rcu(&sta->list);
929 cleanup_single_sta(sta);
936 int sta_info_insert_rcu(struct sta_info *sta) __acquires(RCU)
938 struct ieee80211_local *local = sta->local;
945 err = sta_info_insert_check(sta);
947 sta_info_free(local, sta);
953 return sta_info_insert_finish(sta);
956 int sta_info_insert(struct sta_info *sta)
958 int err = sta_info_insert_rcu(sta);
1010 static void __sta_info_recalc_tim(struct sta_info *sta, bool ignore_pending)
1012 struct ieee80211_local *local = sta->local;
1015 u8 ignore_for_tim = sta->sta.uapsd_queues;
1017 u16 id = sta->sta.aid;
1019 if (sta->sdata->vif.type == NL80211_IFTYPE_AP ||
1020 sta->sdata->vif.type == NL80211_IFTYPE_AP_VLAN) {
1021 if (WARN_ON_ONCE(!sta->sdata->bss))
1024 ps = &sta->sdata->bss->ps;
1026 } else if (ieee80211_vif_is_mesh(&sta->sdata->vif)) {
1027 ps = &sta->sdata->u.mesh.ps;
1037 if (sta->dead)
1058 indicate_tim |= !skb_queue_empty(&sta->tx_filtered[ac]) ||
1059 !skb_queue_empty(&sta->ps_tx_buf[ac]);
1066 sta->driver_buffered_tids & tids;
1068 sta->txq_buffered_tids & tids;
1082 if (local->ops->set_tim && !WARN_ON(sta->dead)) {
1084 drv_set_tim(local, &sta->sta, indicate_tim);
1092 void sta_info_recalc_tim(struct sta_info *sta)
1094 __sta_info_recalc_tim(sta, false);
1097 static bool sta_info_buffer_expired(struct sta_info *sta, struct sk_buff *skb)
1108 timeout = (sta->listen_interval *
1109 sta->sdata->vif.bss_conf.beacon_int *
1118 struct sta_info *sta, int ac)
1131 spin_lock_irqsave(&sta->tx_filtered[ac].lock, flags);
1132 skb = skb_peek(&sta->tx_filtered[ac]);
1133 if (sta_info_buffer_expired(sta, skb))
1134 skb = __skb_dequeue(&sta->tx_filtered[ac]);
1137 spin_unlock_irqrestore(&sta->tx_filtered[ac].lock, flags);
1157 spin_lock_irqsave(&sta->ps_tx_buf[ac].lock, flags);
1158 skb = skb_peek(&sta->ps_tx_buf[ac]);
1159 if (sta_info_buffer_expired(sta, skb))
1160 skb = __skb_dequeue(&sta->ps_tx_buf[ac]);
1163 spin_unlock_irqrestore(&sta->ps_tx_buf[ac].lock, flags);
1174 ps_dbg(sta->sdata, "Buffered frame expired (STA %pM)\n",
1175 sta->sta.addr);
1184 sta_info_recalc_tim(sta);
1191 return !(skb_queue_empty(&sta->ps_tx_buf[ac]) &&
1192 skb_queue_empty(&sta->tx_filtered[ac]));
1196 struct sta_info *sta)
1202 if (!sta->sdata->bss &&
1203 !ieee80211_vif_is_mesh(&sta->sdata->vif))
1208 sta_info_cleanup_expire_buffered_ac(local, sta, ac);
1213 static int __must_check __sta_info_destroy_part1(struct sta_info *sta)
1221 if (!sta)
1224 local = sta->local;
1225 sdata = sta->sdata;
1235 set_sta_flag(sta, WLAN_STA_BLOCK_BA);
1236 ieee80211_sta_tear_down_BA_sessions(sta, AGG_STOP_DESTROY_STA);
1243 drv_sync_rx_queues(local, sta);
1245 for (i = 0; i < ARRAY_SIZE(sta->link); i++) {
1248 if (!(sta->sta.valid_links & BIT(i)))
1251 link_sta = rcu_dereference_protected(sta->link[i],
1257 ret = sta_info_hash_del(local, sta);
1265 if (test_sta_flag(sta, WLAN_STA_TDLS_OFF_CHANNEL)) {
1266 drv_tdls_cancel_channel_switch(local, sdata, &sta->sta);
1267 clear_sta_flag(sta, WLAN_STA_TDLS_OFF_CHANNEL);
1270 list_del_rcu(&sta->list);
1271 sta->removed = true;
1273 if (sta->uploaded)
1274 drv_sta_pre_rcu_remove(local, sta->sdata, sta);
1277 rcu_access_pointer(sdata->u.vlan.sta) == sta)
1278 RCU_INIT_POINTER(sdata->u.vlan.sta, NULL);
1283 static int _sta_info_move_state(struct sta_info *sta,
1289 if (sta->sta_state == new_state)
1296 if (sta->sta_state != IEEE80211_STA_AUTH)
1300 if (sta->sta_state != IEEE80211_STA_NONE &&
1301 sta->sta_state != IEEE80211_STA_ASSOC)
1305 if (sta->sta_state != IEEE80211_STA_AUTH &&
1306 sta->sta_state != IEEE80211_STA_AUTHORIZED)
1310 if (sta->sta_state != IEEE80211_STA_ASSOC)
1318 sta_dbg(sta->sdata, "moving STA %pM to state %d\n",
1319 sta->sta.addr, new_state);
1324 if (test_sta_flag(sta, WLAN_STA_INSERTED)) {
1325 int err = drv_sta_state(sta->local, sta->sdata, sta,
1326 sta->sta_state, new_state);
1335 if (sta->sta_state == IEEE80211_STA_AUTH)
1336 clear_bit(WLAN_STA_AUTH, &sta->_flags);
1339 if (sta->sta_state == IEEE80211_STA_NONE) {
1340 set_bit(WLAN_STA_AUTH, &sta->_flags);
1341 } else if (sta->sta_state == IEEE80211_STA_ASSOC) {
1342 clear_bit(WLAN_STA_ASSOC, &sta->_flags);
1344 ieee80211_recalc_min_chandef(sta->sdata, -1);
1345 if (!sta->sta.support_p2p_ps)
1346 ieee80211_recalc_p2p_go_ps_allowed(sta->sdata);
1351 if (sta->sta_state == IEEE80211_STA_AUTH) {
1352 set_bit(WLAN_STA_ASSOC, &sta->_flags);
1353 sta->assoc_at = ktime_get_boottime_ns();
1355 ieee80211_recalc_min_chandef(sta->sdata, -1);
1356 if (!sta->sta.support_p2p_ps)
1357 ieee80211_recalc_p2p_go_ps_allowed(sta->sdata);
1359 } else if (sta->sta_state == IEEE80211_STA_AUTHORIZED) {
1360 ieee80211_vif_dec_num_mcast(sta->sdata);
1361 clear_bit(WLAN_STA_AUTHORIZED, &sta->_flags);
1362 ieee80211_clear_fast_xmit(sta);
1363 ieee80211_clear_fast_rx(sta);
1367 if (sta->sta_state == IEEE80211_STA_ASSOC) {
1368 ieee80211_vif_inc_num_mcast(sta->sdata);
1369 set_bit(WLAN_STA_AUTHORIZED, &sta->_flags);
1370 ieee80211_check_fast_xmit(sta);
1371 ieee80211_check_fast_rx(sta);
1373 if (sta->sdata->vif.type == NL80211_IFTYPE_AP_VLAN ||
1374 sta->sdata->vif.type == NL80211_IFTYPE_AP)
1375 cfg80211_send_layer2_update(sta->sdata->dev,
1376 sta->sta.addr);
1382 sta->sta_state = new_state;
1387 int sta_info_move_state(struct sta_info *sta,
1390 return _sta_info_move_state(sta, new_state, true);
1393 static void __sta_info_destroy_part2(struct sta_info *sta, bool recalc)
1395 struct ieee80211_local *local = sta->local;
1396 struct ieee80211_sub_if_data *sdata = sta->sdata;
1408 if (sta->sta_state == IEEE80211_STA_AUTHORIZED) {
1409 ret = _sta_info_move_state(sta, IEEE80211_STA_ASSOC, recalc);
1420 drv_flush_sta(local, sta->sdata, sta);
1422 ieee80211_flush_queues(local, sta->sdata, false);
1426 ieee80211_free_sta_keys(local, sta);
1429 __sta_info_recalc_tim(sta, true);
1431 sta->dead = true;
1436 while (sta->sta_state > IEEE80211_STA_NONE) {
1437 ret = _sta_info_move_state(sta, sta->sta_state - 1, recalc);
1444 if (sta->uploaded) {
1445 ret = drv_sta_state(local, sdata, sta, IEEE80211_STA_NONE,
1450 sta_dbg(sdata, "Removed STA %pM\n", sta->sta.addr);
1454 sta_set_sinfo(sta, sinfo, true);
1455 cfg80211_del_sta_sinfo(sdata->dev, sta->sta.addr, sinfo, GFP_KERNEL);
1458 ieee80211_sta_debugfs_remove(sta);
1460 ieee80211_destroy_frag_cache(&sta->frags);
1462 cleanup_single_sta(sta);
1465 int __must_check __sta_info_destroy(struct sta_info *sta)
1467 int err = __sta_info_destroy_part1(sta);
1474 __sta_info_destroy_part2(sta, true);
1481 struct sta_info *sta;
1485 sta = sta_info_get(sdata, addr);
1486 ret = __sta_info_destroy(sta);
1495 struct sta_info *sta;
1499 sta = sta_info_get_bss(sdata, addr);
1500 ret = __sta_info_destroy(sta);
1509 struct sta_info *sta;
1513 list_for_each_entry_rcu(sta, &local->sta_list, list)
1514 if (sta_info_cleanup_expire_buffered(local, sta))
1561 struct sta_info *sta, *tmp;
1571 list_for_each_entry_safe(sta, tmp, &local->sta_list, list) {
1572 if (sdata == sta->sdata ||
1573 (vlans && sdata->bss == sta->sdata->bss)) {
1574 if (!WARN_ON(__sta_info_destroy_part1(sta)))
1575 list_add(&sta->free_list, &free_list);
1584 list_for_each_entry_safe(sta, tmp, &free_list, free_list) {
1585 if (!sta->sta.support_p2p_ps)
1587 __sta_info_destroy_part2(sta, false);
1603 struct sta_info *sta, *tmp;
1607 list_for_each_entry_safe(sta, tmp, &local->sta_list, list) {
1608 unsigned long last_active = ieee80211_sta_last_active(sta);
1610 if (sdata != sta->sdata)
1614 sta_dbg(sta->sdata, "expiring inactive STA %pM\n",
1615 sta->sta.addr);
1618 test_sta_flag(sta, WLAN_STA_PS_STA))
1621 WARN_ON(__sta_info_destroy(sta));
1634 struct sta_info *sta;
1640 for_each_sta_info(local, addr, sta, tmp) {
1642 !ether_addr_equal(sta->sdata->vif.addr, localaddr))
1644 if (!sta->uploaded)
1646 return &sta->sta;
1656 struct sta_info *sta;
1661 sta = sta_info_get_bss(vif_to_sdata(vif), addr);
1662 if (!sta)
1665 if (!sta->uploaded)
1668 return &sta->sta;
1673 void ieee80211_sta_ps_deliver_wakeup(struct sta_info *sta)
1675 struct ieee80211_sub_if_data *sdata = sta->sdata;
1693 clear_sta_flag(sta, WLAN_STA_SP);
1696 sta->driver_buffered_tids = 0;
1697 sta->txq_buffered_tids = 0;
1700 drv_sta_notify(local, sdata, STA_NOTIFY_AWAKE, &sta->sta);
1702 for (i = 0; i < ARRAY_SIZE(sta->sta.txq); i++) {
1703 if (!sta->sta.txq[i] || !txq_has_queue(sta->sta.txq[i]))
1706 schedule_and_wake_txq(local, to_txq_info(sta->sta.txq[i]));
1712 spin_lock(&sta->ps_lock);
1717 spin_lock_irqsave(&sta->tx_filtered[ac].lock, flags);
1718 skb_queue_splice_tail_init(&sta->tx_filtered[ac], &pending);
1719 spin_unlock_irqrestore(&sta->tx_filtered[ac].lock, flags);
1724 spin_lock_irqsave(&sta->ps_tx_buf[ac].lock, flags);
1725 skb_queue_splice_tail_init(&sta->ps_tx_buf[ac], &pending);
1726 spin_unlock_irqrestore(&sta->ps_tx_buf[ac].lock, flags);
1734 clear_sta_flag(sta, WLAN_STA_PS_DELIVER);
1739 clear_sta_flag(sta, WLAN_STA_PSPOLL);
1740 clear_sta_flag(sta, WLAN_STA_UAPSD);
1741 spin_unlock(&sta->ps_lock);
1747 sta_info_recalc_tim(sta);
1751 sta->sta.addr, sta->sta.aid, filtered, buffered);
1753 ieee80211_check_fast_xmit(sta);
1756 static void ieee80211_send_null_response(struct sta_info *sta, int tid,
1760 struct ieee80211_sub_if_data *sdata = sta->sdata;
1766 bool qos = sta->sta.wme;
1790 memcpy(nullfunc->addr1, sta->sta.addr, ETH_ALEN);
1824 drv_allow_buffered_frames(local, sta, BIT(tid), 1,
1838 ieee80211_xmit(sdata, sta, skb);
1859 ieee80211_sta_ps_more_data(struct sta_info *sta, u8 ignored_acs,
1878 if (!skb_queue_empty(&sta->tx_filtered[ac]) ||
1879 !skb_queue_empty(&sta->ps_tx_buf[ac]))
1887 ieee80211_sta_ps_get_frames(struct sta_info *sta, int n_frames, u8 ignored_acs,
1892 struct ieee80211_sub_if_data *sdata = sta->sdata;
1910 sta->driver_buffered_tids & tids;
1911 *driver_release_tids |= sta->txq_buffered_tids & tids;
1918 skb = skb_dequeue(&sta->tx_filtered[ac]);
1921 &sta->ps_tx_buf[ac]);
1936 if (!skb_queue_empty(&sta->tx_filtered[ac]) ||
1937 !skb_queue_empty(&sta->ps_tx_buf[ac]))
1943 ieee80211_sta_ps_deliver_response(struct sta_info *sta,
1947 struct ieee80211_sub_if_data *sdata = sta->sdata;
1954 set_sta_flag(sta, WLAN_STA_SP);
1958 ieee80211_sta_ps_get_frames(sta, n_frames, ignored_acs, reason,
1961 more_data = ieee80211_sta_ps_more_data(sta, ignored_acs, reason, driver_release_tids);
1991 ieee80211_send_null_response(sta, tid, reason, true, false);
2084 drv_allow_buffered_frames(local, sta, tids, num,
2091 sta, find_highest_prio_tid(tids),
2094 sta_info_recalc_tim(sta);
2108 drv_release_buffered_frames(local, sta, driver_release_tids,
2121 for (tid = 0; tid < ARRAY_SIZE(sta->sta.txq); tid++) {
2122 if (!sta->sta.txq[tid] ||
2124 txq_has_queue(sta->sta.txq[tid]))
2127 sta_info_recalc_tim(sta);
2133 void ieee80211_sta_ps_deliver_poll_response(struct sta_info *sta)
2135 u8 ignore_for_response = sta->sta.uapsd_queues;
2145 ieee80211_sta_ps_deliver_response(sta, 1, ignore_for_response,
2149 void ieee80211_sta_ps_deliver_uapsd(struct sta_info *sta)
2151 int n_frames = sta->sta.max_sp;
2152 u8 delivery_enabled = sta->sta.uapsd_queues;
2163 switch (sta->sta.max_sp) {
2179 ieee80211_sta_ps_deliver_response(sta, n_frames, ~delivery_enabled,
2186 struct sta_info *sta = container_of(pubsta, struct sta_info, sta);
2188 trace_api_sta_block_awake(sta->local, pubsta, block);
2191 set_sta_flag(sta, WLAN_STA_PS_DRIVER);
2192 ieee80211_clear_fast_xmit(sta);
2196 if (!test_sta_flag(sta, WLAN_STA_PS_DRIVER))
2199 if (!test_sta_flag(sta, WLAN_STA_PS_STA)) {
2200 set_sta_flag(sta, WLAN_STA_PS_DELIVER);
2201 clear_sta_flag(sta, WLAN_STA_PS_DRIVER);
2202 ieee80211_queue_work(hw, &sta->drv_deliver_wk);
2203 } else if (test_sta_flag(sta, WLAN_STA_PSPOLL) ||
2204 test_sta_flag(sta, WLAN_STA_UAPSD)) {
2206 clear_sta_flag(sta, WLAN_STA_PS_DRIVER);
2207 ieee80211_queue_work(hw, &sta->drv_deliver_wk);
2209 clear_sta_flag(sta, WLAN_STA_PS_DRIVER);
2210 ieee80211_check_fast_xmit(sta);
2217 struct sta_info *sta = container_of(pubsta, struct sta_info, sta);
2218 struct ieee80211_local *local = sta->local;
2222 clear_sta_flag(sta, WLAN_STA_SP);
2228 struct sta_info *sta = container_of(pubsta, struct sta_info, sta);
2232 trace_api_send_eosp_nullfunc(sta->local, pubsta, tid);
2235 more_data = ieee80211_sta_ps_more_data(sta, ~sta->sta.uapsd_queues,
2238 ieee80211_send_null_response(sta, tid, reason, false, more_data);
2245 struct sta_info *sta = container_of(pubsta, struct sta_info, sta);
2250 trace_api_sta_set_buffered(sta->local, pubsta, tid, buffered);
2253 set_bit(tid, &sta->driver_buffered_tids);
2255 clear_bit(tid, &sta->driver_buffered_tids);
2257 sta_info_recalc_tim(sta);
2264 struct sta_info *sta = container_of(pubsta, struct sta_info, sta);
2265 struct ieee80211_local *local = sta->sdata->local;
2270 if (sta->local->airtime_flags & AIRTIME_USE_TX)
2272 if (sta->local->airtime_flags & AIRTIME_USE_RX)
2276 sta->airtime[ac].tx_airtime += tx_airtime;
2277 sta->airtime[ac].rx_airtime += rx_airtime;
2279 diff = (u32)jiffies - sta->airtime[ac].last_active;
2281 sta->airtime[ac].deficit -= airtime;
2287 void __ieee80211_sta_recalc_aggregates(struct sta_info *sta, u16 active_links)
2292 if (!sta->sta.valid_links || !sta->sta.mlo) {
2293 sta->sta.cur = &sta->sta.deflink.agg;
2298 for (link_id = 0; link_id < ARRAY_SIZE((sta)->link); link_id++) {
2305 link_sta = rcu_dereference(sta->sta.link[link_id]);
2310 sta->cur = sta->sta.deflink.agg;
2315 sta->cur.max_amsdu_len =
2316 min(sta->cur.max_amsdu_len,
2318 sta->cur.max_rc_amsdu_len =
2319 min(sta->cur.max_rc_amsdu_len,
2322 for (i = 0; i < ARRAY_SIZE(sta->cur.max_tid_amsdu_len); i++)
2323 sta->cur.max_tid_amsdu_len[i] =
2324 min(sta->cur.max_tid_amsdu_len[i],
2329 sta->sta.cur = &sta->cur;
2334 struct sta_info *sta = container_of(pubsta, struct sta_info, sta);
2336 __ieee80211_sta_recalc_aggregates(sta, sta->sdata->vif.active_links);
2341 struct sta_info *sta, u8 ac,
2350 if (sta)
2352 &sta->airtime[ac].aql_tx_pending);
2359 if (sta) {
2361 &sta->airtime[ac].aql_tx_pending);
2363 atomic_cmpxchg(&sta->airtime[ac].aql_tx_pending,
2381 sta_get_last_rx_stats(struct sta_info *sta)
2383 struct ieee80211_sta_rx_stats *stats = &sta->deflink.rx_stats;
2386 if (!sta->deflink.pcpu_rx_stats)
2392 cpustats = per_cpu_ptr(sta->deflink.pcpu_rx_stats, cpu);
2460 static int sta_set_rate_info_rx(struct sta_info *sta, struct rate_info *rinfo)
2462 u32 rate = READ_ONCE(sta_get_last_rx_stats(sta)->last_rate);
2467 sta_stats_decode_rate(sta->local, rate, rinfo);
2485 static void sta_set_tidstats(struct sta_info *sta,
2489 struct ieee80211_local *local = sta->local;
2493 tidstats->rx_msdu += sta_get_tidstats_msdu(&sta->deflink.rx_stats,
2496 if (sta->deflink.pcpu_rx_stats) {
2500 cpurxs = per_cpu_ptr(sta->deflink.pcpu_rx_stats,
2512 tidstats->tx_msdu = sta->deflink.tx_stats.msdu[tid];
2518 tidstats->tx_msdu_retries = sta->deflink.status_stats.msdu_retries[tid];
2524 tidstats->tx_msdu_failed = sta->deflink.status_stats.msdu_failed[tid];
2533 to_txq_info(sta->sta.txq[tid]));
2553 void sta_set_sinfo(struct sta_info *sta, struct station_info *sinfo,
2556 struct ieee80211_sub_if_data *sdata = sta->sdata;
2562 last_rxstats = sta_get_last_rx_stats(sta);
2573 drv_sta_statistics(local, sdata, &sta->sta, sinfo);
2587 sinfo->connected_time = ktime_get_seconds() - sta->last_connected;
2588 sinfo->assoc_at = sta->assoc_at;
2590 jiffies_to_msecs(jiffies - ieee80211_sta_last_active(sta));
2596 sinfo->tx_bytes += sta->deflink.tx_stats.bytes[ac];
2603 sinfo->tx_packets += sta->deflink.tx_stats.packets[ac];
2609 sinfo->rx_bytes += sta_get_stats_bytes(&sta->deflink.rx_stats);
2611 if (sta->deflink.pcpu_rx_stats) {
2615 cpurxs = per_cpu_ptr(sta->deflink.pcpu_rx_stats,
2625 sinfo->rx_packets = sta->deflink.rx_stats.packets;
2626 if (sta->deflink.pcpu_rx_stats) {
2630 cpurxs = per_cpu_ptr(sta->deflink.pcpu_rx_stats,
2639 sinfo->tx_retries = sta->deflink.status_stats.retry_count;
2644 sinfo->tx_failed = sta->deflink.status_stats.retry_failed;
2650 sinfo->rx_duration += sta->airtime[ac].rx_airtime;
2656 sinfo->tx_duration += sta->airtime[ac].tx_airtime;
2661 sinfo->airtime_weight = sta->airtime_weight;
2665 sinfo->rx_dropped_misc = sta->deflink.rx_stats.dropped;
2666 if (sta->deflink.pcpu_rx_stats) {
2670 cpurxs = per_cpu_ptr(sta->deflink.pcpu_rx_stats, cpu);
2682 if (ieee80211_hw_check(&sta->local->hw, SIGNAL_DBM) ||
2683 ieee80211_hw_check(&sta->local->hw, SIGNAL_UNSPEC)) {
2689 if (!sta->deflink.pcpu_rx_stats &&
2692 -ewma_signal_read(&sta->deflink.rx_stats_avg.signal);
2698 * the sta->rx_stats struct, so the check here is fine with and without
2705 if (!sta->deflink.pcpu_rx_stats)
2714 -ewma_signal_read(&sta->deflink.rx_stats_avg.chain_signal[i]);
2719 !sta->sta.valid_links) {
2720 sta_set_rate_info_tx(sta, &sta->deflink.tx_stats.last_rate,
2726 !sta->sta.valid_links) {
2727 if (sta_set_rate_info_rx(sta, &sinfo->rxrate) == 0)
2733 sta_set_tidstats(sta, &sinfo->pertid[i], i);
2747 sinfo->llid = sta->mesh->llid;
2748 sinfo->plid = sta->mesh->plid;
2749 sinfo->plink_state = sta->mesh->plink_state;
2750 if (test_sta_flag(sta, WLAN_STA_TOFFSET_KNOWN)) {
2752 sinfo->t_offset = sta->mesh->t_offset;
2754 sinfo->local_pm = sta->mesh->local_pm;
2755 sinfo->peer_pm = sta->mesh->peer_pm;
2756 sinfo->nonpeer_pm = sta->mesh->nonpeer_pm;
2757 sinfo->connected_to_gate = sta->mesh->connected_to_gate;
2758 sinfo->connected_to_as = sta->mesh->connected_to_as;
2780 if (test_sta_flag(sta, WLAN_STA_AUTHORIZED))
2782 if (test_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE))
2784 if (sta->sta.wme)
2786 if (test_sta_flag(sta, WLAN_STA_MFP))
2788 if (test_sta_flag(sta, WLAN_STA_AUTH))
2790 if (test_sta_flag(sta, WLAN_STA_ASSOC))
2792 if (test_sta_flag(sta, WLAN_STA_TDLS_PEER))
2795 thr = sta_get_expected_throughput(sta);
2803 sta->deflink.status_stats.ack_signal_filled) {
2804 sinfo->ack_signal = sta->deflink.status_stats.last_ack_signal;
2809 sta->deflink.status_stats.ack_signal_filled) {
2812 &sta->deflink.status_stats.avg_ack_signal);
2820 airtime_link_metric_get(local, sta);
2824 u32 sta_get_expected_throughput(struct sta_info *sta)
2826 struct ieee80211_sub_if_data *sdata = sta->sdata;
2831 if (test_sta_flag(sta, WLAN_STA_RATE_CONTROL))
2836 thr = ref->ops->get_expected_throughput(sta->rate_ctrl_priv);
2838 thr = drv_get_expected_throughput(local, sta);
2843 unsigned long ieee80211_sta_last_active(struct sta_info *sta)
2845 struct ieee80211_sta_rx_stats *stats = sta_get_last_rx_stats(sta);
2847 if (!sta->deflink.status_stats.last_ack ||
2848 time_after(stats->last_rx, sta->deflink.status_stats.last_ack))
2850 return sta->deflink.status_stats.last_ack;
2853 static void sta_update_codel_params(struct sta_info *sta, u32 thr)
2855 if (thr && thr < STA_SLOW_THRESHOLD * sta->local->num_sta) {
2856 sta->cparams.target = MS2TIME(50);
2857 sta->cparams.interval = MS2TIME(300);
2858 sta->cparams.ecn = false;
2860 sta->cparams.target = MS2TIME(20);
2861 sta->cparams.interval = MS2TIME(100);
2862 sta->cparams.ecn = true;
2869 struct sta_info *sta = container_of(pubsta, struct sta_info, sta);
2871 sta_update_codel_params(sta, thr);
2874 int ieee80211_sta_allocate_link(struct sta_info *sta, unsigned int link_id)
2876 struct ieee80211_sub_if_data *sdata = sta->sdata;
2883 if (WARN_ON(!sta->sta.valid_links))
2886 if (WARN_ON(sta->sta.valid_links & BIT(link_id) ||
2887 sta->link[link_id]))
2900 sta_info_add_link(sta, link_id, &alloc->info, &alloc->sta);
2907 void ieee80211_sta_free_link(struct sta_info *sta, unsigned int link_id)
2909 lockdep_assert_held(&sta->sdata->local->sta_mtx);
2911 sta_remove_link(sta, link_id, false);
2914 int ieee80211_sta_activate_link(struct sta_info *sta, unsigned int link_id)
2916 struct ieee80211_sub_if_data *sdata = sta->sdata;
2918 u16 old_links = sta->sta.valid_links;
2922 link_sta = rcu_dereference_protected(sta->link[link_id],
2936 sta->sta.valid_links = new_links;
2938 if (!test_sta_flag(sta, WLAN_STA_INSERTED))
2946 ieee80211_sta_recalc_aggregates(&sta->sta);
2948 ret = drv_change_sta_links(sdata->local, sdata, &sta->sta,
2951 sta->sta.valid_links = old_links;
2952 sta_remove_link(sta, link_id, false);
2962 void ieee80211_sta_remove_link(struct sta_info *sta, unsigned int link_id)
2964 struct ieee80211_sub_if_data *sdata = sta->sdata;
2965 u16 old_links = sta->sta.valid_links;
2969 sta->sta.valid_links &= ~BIT(link_id);
2971 if (test_sta_flag(sta, WLAN_STA_INSERTED))
2972 drv_change_sta_links(sdata->local, sdata, &sta->sta,
2973 old_links, sta->sta.valid_links);
2975 sta_remove_link(sta, link_id, true);
2978 void ieee80211_sta_set_max_amsdu_subframes(struct sta_info *sta,
2984 sta->sta.max_amsdu_subframes = 0;
2998 sta->sta.max_amsdu_subframes = 4 << (4 - val);
3004 struct sta_info *sta = container_of(pubsta, struct sta_info, sta);
3006 return lockdep_is_held(&sta->local->sta_mtx);