Lines Matching +full:ps +full:- +full:hold
1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright 2002-2005, Instant802 Networks, Inc.
4 * Copyright 2006-2007 Jiri Benc <jbenc@suse.cz>
5 * Copyright 2013-2014 Intel Mobile Communications GmbH
6 * Copyright (C) 2015 - 2017 Intel Deutschland GmbH
7 * Copyright (C) 2018-2025 Intel Corporation
23 #include "driver-ops.h"
46 * When the insertion fails (sta_info_insert()) returns non-zero), the
93 return rhltable_remove(&local->sta_hash, &sta->hash_node,
100 lockdep_assert_wiphy(local->hw.wiphy);
102 return rhltable_insert(&local->link_sta_hash,
103 &link_sta->link_hash_node, link_sta_rht_params);
109 lockdep_assert_wiphy(local->hw.wiphy);
111 return rhltable_remove(&local->link_sta_hash,
112 &link_sta->link_hash_node, link_sta_rht_params);
117 struct ieee80211_local *local = sta->sdata->local;
120 for (i = 0; i < ARRAY_SIZE(sta->sta.txq); i++) {
123 if (!sta->sta.txq[i])
126 txqi = to_txq_info(sta->sta.txq[i]);
136 struct ieee80211_sub_if_data *sdata = sta->sdata;
137 struct ieee80211_local *local = sdata->local;
138 struct ps_data *ps;
143 if (sta->sdata->vif.type == NL80211_IFTYPE_AP ||
144 sta->sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
145 ps = &sdata->bss->ps;
146 else if (ieee80211_vif_is_mesh(&sdata->vif))
147 ps = &sdata->u.mesh.ps;
155 atomic_dec(&ps->num_sta_ps);
161 local->total_ps_buffered -= skb_queue_len(&sta->ps_tx_buf[ac]);
162 ieee80211_purge_tx_queue(&local->hw, &sta->ps_tx_buf[ac]);
163 ieee80211_purge_tx_queue(&local->hw, &sta->tx_filtered[ac]);
166 if (ieee80211_vif_is_mesh(&sdata->vif))
169 cancel_work_sync(&sta->drv_deliver_wk);
178 kfree(sta->ampdu_mlme.tid_start_tx[i]);
179 tid_tx = rcu_dereference_raw(sta->ampdu_mlme.tid_tx[i]);
182 ieee80211_purge_tx_queue(&local->hw, &tid_tx->pending);
189 struct ieee80211_sub_if_data *sdata = sta->sdata;
190 struct ieee80211_local *local = sdata->local;
199 return rhltable_lookup(&local->sta_hash, addr, sta_rht_params);
206 struct ieee80211_local *local = sdata->local;
212 if (sta->sdata == sdata) {
214 /* this is safe as the caller must already hold
231 struct ieee80211_local *local = sdata->local;
237 if (sta->sdata == sdata ||
238 (sta->sdata->bss && sta->sdata->bss == sdata->bss)) {
240 /* this is safe as the caller must already hold
253 return rhltable_lookup(&local->link_sta_hash, addr,
260 struct ieee80211_local *local = sdata->local;
266 struct sta_info *sta = link_sta->sta;
268 if (sta->sdata == sdata ||
269 (sta->sdata->bss && sta->sdata->bss == sdata->bss)) {
271 /* this is safe as the caller must already hold
292 struct sta_info *sta = link_sta->sta;
294 u8 _link_id = link_sta->link_id;
299 return &sta->sta;
302 link = rcu_dereference(sta->sdata->link[_link_id]);
306 if (memcmp(link->conf->addr, localaddr, ETH_ALEN))
311 return &sta->sta;
325 if (ether_addr_equal(vif_addr, sta->sdata->vif.addr))
335 struct ieee80211_local *local = sdata->local;
339 list_for_each_entry_rcu(sta, &local->sta_list, list,
340 lockdep_is_held(&local->hw.wiphy->mtx)) {
341 if (sdata != sta->sdata)
355 free_percpu(link_sta->pcpu_rx_stats);
360 struct link_sta_info *link_sta = wiphy_dereference(sta->local->hw.wiphy,
361 sta->link[link_id]);
367 sta->rem_link_stats.tx_packets +=
368 link_sta->tx_stats.packets[ac];
369 sta->rem_link_stats.tx_bytes += link_sta->tx_stats.bytes[ac];
372 sta->rem_link_stats.rx_packets += link_sta->rx_stats.packets;
373 sta->rem_link_stats.rx_bytes += link_sta->rx_stats.bytes;
374 sta->rem_link_stats.tx_retries += link_sta->status_stats.retry_count;
375 sta->rem_link_stats.tx_failed += link_sta->status_stats.retry_failed;
376 sta->rem_link_stats.rx_dropped_misc += link_sta->rx_stats.dropped;
380 sta->rem_link_stats.expected_throughput += thr;
383 sta->rem_link_stats.pertid_stats.rx_msdu +=
384 link_sta->rx_stats.msdu[tid];
385 sta->rem_link_stats.pertid_stats.tx_msdu +=
386 link_sta->tx_stats.msdu[tid];
387 sta->rem_link_stats.pertid_stats.tx_msdu_retries +=
388 link_sta->status_stats.msdu_retries[tid];
389 sta->rem_link_stats.pertid_stats.tx_msdu_failed +=
390 link_sta->status_stats.msdu_failed[tid];
393 if (sta->sdata->vif.type == NL80211_IFTYPE_STATION) {
394 link = wiphy_dereference(sta->sdata->local->hw.wiphy,
395 sta->sdata->link[link_id]);
397 sta->rem_link_stats.beacon_loss_count +=
398 link->u.mgd.beacon_loss_count;
408 lockdep_assert_wiphy(sta->local->hw.wiphy);
410 link_sta = rcu_access_pointer(sta->link[link_id]);
415 link_sta_info_hash_del(sta->local, link_sta);
420 if (link_sta != &sta->deflink)
423 sta->sta.valid_links &= ~BIT(link_id);
428 RCU_INIT_POINTER(sta->link[link_id], NULL);
429 RCU_INIT_POINTER(sta->sta.link[link_id], NULL);
431 sta_info_free_link(&alloc->info);
435 ieee80211_sta_recalc_aggregates(&sta->sta);
439 * sta_info_free - free STA
453 for (i = 0; i < ARRAY_SIZE(sta->link); i++) {
456 link_sta = rcu_access_pointer(sta->link[i]);
471 while (sta->sta_state > IEEE80211_STA_NONE) {
476 ret = sta_info_move_state(sta, sta->sta_state - 1);
481 if (sta->rate_ctrl)
484 sta_dbg(sta->sdata, "Destroyed STA %pM\n", sta->sta.addr);
486 kfree(to_txq_info(sta->sta.txq[0]));
487 kfree(rcu_dereference_raw(sta->sta.rates));
489 kfree(sta->mesh);
492 sta_info_free_link(&sta->deflink);
499 return rhltable_insert(&local->sta_hash, &sta->hash_node,
509 if (sta->dead)
525 if (ieee80211_hw_check(&local->hw, HAS_RATE_CONTROL))
528 sta->rate_ctrl = local->rate_ctrl;
529 sta->rate_ctrl_priv = rate_control_alloc_sta(sta->rate_ctrl,
531 if (!sta->rate_ctrl_priv)
532 return -ENOMEM;
541 struct ieee80211_hw *hw = &local->hw;
545 link_info->pcpu_rx_stats =
547 if (!link_info->pcpu_rx_stats)
548 return -ENOMEM;
551 link_info->rx_stats.last_rx = jiffies;
552 u64_stats_init(&link_info->rx_stats.syncp);
554 ewma_signal_init(&link_info->rx_stats_avg.signal);
555 ewma_avg_signal_init(&link_info->status_stats.avg_ack_signal);
556 for (i = 0; i < ARRAY_SIZE(link_info->rx_stats_avg.chain_signal); i++)
557 ewma_signal_init(&link_info->rx_stats_avg.chain_signal[i]);
559 link_info->rx_omi_bw_rx = IEEE80211_STA_RX_BW_MAX;
560 link_info->rx_omi_bw_tx = IEEE80211_STA_RX_BW_MAX;
561 link_info->rx_omi_bw_staging = IEEE80211_STA_RX_BW_MAX;
567 switch (link_info->cur_max_bandwidth) {
585 link_info->sta = sta;
586 link_info->link_id = link_id;
587 link_info->pub = link_sta;
588 link_info->pub->sta = &sta->sta;
589 link_sta->link_id = link_id;
590 rcu_assign_pointer(sta->link[link_id], link_info);
591 rcu_assign_pointer(sta->sta.link[link_id], link_sta);
593 link_sta->smps_mode = IEEE80211_SMPS_OFF;
594 link_sta->agg.max_rc_amsdu_len = IEEE80211_MAX_MPDU_LEN_HT_BA;
602 struct ieee80211_local *local = sdata->local;
603 struct ieee80211_hw *hw = &local->hw;
609 sta = kzalloc(sizeof(*sta) + hw->sta_data_size, gfp);
613 sta->local = local;
614 sta->sdata = sdata;
616 if (sta_info_alloc_link(local, &sta->deflink, gfp))
620 sta_info_add_link(sta, link_id, &sta->deflink,
621 &sta->sta.deflink);
622 sta->sta.valid_links = BIT(link_id);
624 sta_info_add_link(sta, 0, &sta->deflink, &sta->sta.deflink);
627 sta->sta.cur = &sta->sta.deflink.agg;
629 spin_lock_init(&sta->lock);
630 spin_lock_init(&sta->ps_lock);
631 INIT_WORK(&sta->drv_deliver_wk, sta_deliver_ps_frames);
632 wiphy_work_init(&sta->ampdu_mlme.work, ieee80211_ba_session_work);
634 if (ieee80211_vif_is_mesh(&sdata->vif)) {
635 sta->mesh = kzalloc(sizeof(*sta->mesh), gfp);
636 if (!sta->mesh)
638 sta->mesh->plink_sta = sta;
639 spin_lock_init(&sta->mesh->plink_lock);
640 if (!sdata->u.mesh.user_mpm)
641 timer_setup(&sta->mesh->plink_timer, mesh_plink_timer,
643 sta->mesh->nonpeer_pm = NL80211_MESH_POWER_ACTIVE;
647 memcpy(sta->addr, addr, ETH_ALEN);
648 memcpy(sta->sta.addr, addr, ETH_ALEN);
649 memcpy(sta->deflink.addr, link_addr, ETH_ALEN);
650 memcpy(sta->sta.deflink.addr, link_addr, ETH_ALEN);
651 sta->sta.max_rx_aggregation_subframes =
652 local->hw.max_rx_aggregation_subframes;
656 /* Extended Key ID needs to install keys for keyid 0 and 1 Rx-only.
658 * references to is not NULL. To not use the initial Rx-only key
662 BUILD_BUG_ON(ARRAY_SIZE(sta->ptk) <= INVALID_PTK_KEYIDX);
663 sta->ptk_idx = INVALID_PTK_KEYIDX;
666 ieee80211_init_frag_cache(&sta->frags);
668 sta->sta_state = IEEE80211_STA_NONE;
670 if (sdata->vif.type == NL80211_IFTYPE_MESH_POINT)
671 sta->amsdu_mesh_control = -1;
674 sta->reserved_tid = IEEE80211_TID_UNRESERVED;
676 sta->last_connected = ktime_get_seconds();
679 ALIGN(hw->txq_data_size, sizeof(void *));
681 txq_data = kcalloc(ARRAY_SIZE(sta->sta.txq), size, gfp);
685 for (i = 0; i < ARRAY_SIZE(sta->sta.txq); i++) {
695 sta->airtime_weight = IEEE80211_DEFAULT_AIRTIME_WEIGHT;
698 skb_queue_head_init(&sta->ps_tx_buf[i]);
699 skb_queue_head_init(&sta->tx_filtered[i]);
700 sta->airtime[i].deficit = sta->airtime_weight;
701 atomic_set(&sta->airtime[i].aql_tx_pending, 0);
702 sta->airtime[i].aql_limit_low = local->aql_txq_limit_low[i];
703 sta->airtime[i].aql_limit_high = local->aql_txq_limit_high[i];
707 sta->last_seq_ctrl[i] = cpu_to_le16(USHRT_MAX);
713 if (!hw->wiphy->bands[i])
741 for (r = 0; r < hw->wiphy->bands[i]->n_bitrates; r++) {
744 rate = &hw->wiphy->bands[i]->bitrates[r];
746 if (!(rate->flags & mandatory))
748 sta->sta.deflink.supp_rates[i] |= BIT(r);
753 sta_dbg(sdata, "Allocated STA %pM\n", sta->sta.addr);
758 kfree(to_txq_info(sta->sta.txq[0]));
760 sta_info_free_link(&sta->deflink);
762 kfree(sta->mesh);
771 return __sta_info_alloc(sdata, addr, -1, addr, gfp);
785 struct ieee80211_sub_if_data *sdata = sta->sdata;
787 lockdep_assert_wiphy(sdata->local->hw.wiphy);
795 return -ENETDOWN;
797 if (WARN_ON(ether_addr_equal(sta->sta.addr, sdata->vif.addr) ||
798 !is_valid_ether_addr(sta->sta.addr)))
799 return -EINVAL;
806 if (ieee80211_hw_check(&sdata->local->hw, NEEDS_UNIQUE_STA_ADDR) &&
807 ieee80211_find_sta_by_ifaddr(&sdata->local->hw, sta->addr, NULL)) {
809 return -ENOTUNIQ;
823 for (state = IEEE80211_STA_NOTEXIST; state < sta->sta_state; state++) {
834 if (!local->ops->sta_add)
835 sta->uploaded = true;
839 if (sdata->vif.type == NL80211_IFTYPE_ADHOC) {
841 "failed to move IBSS STA %pM to state %d (%d) - keeping it anyway\n",
842 sta->sta.addr, state + 1, err);
847 for (; state > IEEE80211_STA_NOTEXIST; state--)
848 WARN_ON(drv_sta_state(local, sdata, sta, state, state - 1));
856 struct ieee80211_local *local = sdata->local;
857 bool allow_p2p_go_ps = sdata->vif.p2p;
861 list_for_each_entry_rcu(sta, &local->sta_list, list) {
862 if (sdata != sta->sdata ||
865 if (!sta->sta.support_p2p_ps) {
872 if (allow_p2p_go_ps != sdata->vif.bss_conf.allow_p2p_go_ps) {
873 sdata->vif.bss_conf.allow_p2p_go_ps = allow_p2p_go_ps;
874 ieee80211_link_info_change_notify(sdata, &sdata->deflink,
881 struct ieee80211_local *local = sta->local;
882 struct ieee80211_sub_if_data *sdata = sta->sdata;
886 lockdep_assert_wiphy(local->hw.wiphy);
889 if (sta_info_get_bss(sdata, sta->sta.addr)) {
890 err = -EEXIST;
896 err = -ENOMEM;
900 local->num_sta++;
901 local->sta_generation++;
912 if (sta->sta.valid_links) {
913 err = link_sta_info_hash_add(local, &sta->deflink);
920 list_add_tail_rcu(&sta->list, &local->sta_list);
925 if (sta->sta_state >= IEEE80211_STA_ASSOC) {
926 ieee80211_recalc_min_chandef(sta->sdata, -1);
927 if (!sta->sta.support_p2p_ps)
928 ieee80211_recalc_p2p_go_ps_allowed(sta->sdata);
943 if (sta->sta.valid_links) {
946 for (i = 0; i < ARRAY_SIZE(sta->link); i++) {
949 link_sta = rcu_dereference_protected(sta->link[i],
950 lockdep_is_held(&local->hw.wiphy->mtx));
956 if (sdata->vif.active_links & BIT(i))
960 ieee80211_link_sta_debugfs_add(&sta->deflink);
961 ieee80211_link_sta_debugfs_drv_add(&sta->deflink);
964 sinfo->generation = local->sta_generation;
965 cfg80211_new_sta(sdata->dev, sta->sta.addr, sinfo, GFP_KERNEL);
968 sta_dbg(sdata, "Inserted STA %pM\n", sta->sta.addr);
970 /* move reference to rcu-protected */
973 if (ieee80211_vif_is_mesh(&sdata->vif))
980 if (sta->sta.valid_links)
981 link_sta_info_hash_del(local, &sta->deflink);
983 list_del_rcu(&sta->list);
985 local->num_sta--;
996 struct ieee80211_local *local = sta->local;
1000 lockdep_assert_wiphy(local->hw.wiphy);
1068 struct ieee80211_local *local = sta->local;
1069 struct ps_data *ps;
1071 u8 ignore_for_tim = sta->sta.uapsd_queues;
1073 u16 id = sta->sta.aid;
1075 if (sta->sdata->vif.type == NL80211_IFTYPE_AP ||
1076 sta->sdata->vif.type == NL80211_IFTYPE_AP_VLAN) {
1077 if (WARN_ON_ONCE(!sta->sdata->bss))
1080 ps = &sta->sdata->bss->ps;
1082 } else if (ieee80211_vif_is_mesh(&sta->sdata->vif)) {
1083 ps = &sta->sdata->u.mesh.ps;
1090 if (ieee80211_hw_check(&local->hw, AP_LINK_PS) && !local->ops->set_tim)
1093 if (sta->dead)
1097 * If all ACs are delivery-enabled then we should build
1100 * non-enabled ones.
1102 if (ignore_for_tim == BIT(IEEE80211_NUM_ACS) - 1)
1106 ignore_for_tim = BIT(IEEE80211_NUM_ACS) - 1;
1114 indicate_tim |= !skb_queue_empty(&sta->tx_filtered[ac]) ||
1115 !skb_queue_empty(&sta->ps_tx_buf[ac]);
1122 sta->driver_buffered_tids & tids;
1124 sta->txq_buffered_tids & tids;
1128 spin_lock_bh(&local->tim_lock);
1130 if (indicate_tim == __bss_tim_get(ps->tim, id))
1134 __bss_tim_set(ps->tim, id);
1136 __bss_tim_clear(ps->tim, id);
1138 if (local->ops->set_tim && !WARN_ON(sta->dead)) {
1139 local->tim_in_locked_section = true;
1140 drv_set_tim(local, &sta->sta, indicate_tim);
1141 local->tim_in_locked_section = false;
1145 spin_unlock_bh(&local->tim_lock);
1164 timeout = (sta->listen_interval *
1165 sta->sdata->vif.bss_conf.beacon_int *
1169 return time_after(jiffies, info->control.jiffies + timeout);
1182 * a separate queue to avoid reordering with normal PS-buffered
1187 spin_lock_irqsave(&sta->tx_filtered[ac].lock, flags);
1188 skb = skb_peek(&sta->tx_filtered[ac]);
1190 skb = __skb_dequeue(&sta->tx_filtered[ac]);
1193 spin_unlock_irqrestore(&sta->tx_filtered[ac].lock, flags);
1203 ieee80211_free_txskb(&local->hw, skb);
1207 * Now also check the normal PS-buffered queue, this will
1209 * since the filtered frames are all before the normal PS
1213 spin_lock_irqsave(&sta->ps_tx_buf[ac].lock, flags);
1214 skb = skb_peek(&sta->ps_tx_buf[ac]);
1216 skb = __skb_dequeue(&sta->ps_tx_buf[ac]);
1219 spin_unlock_irqrestore(&sta->ps_tx_buf[ac].lock, flags);
1229 local->total_ps_buffered--;
1230 ps_dbg(sta->sdata, "Buffered frame expired (STA %pM)\n",
1231 sta->sta.addr);
1232 ieee80211_free_txskb(&local->hw, skb);
1236 * Finally, recalculate the TIM bit for this station -- it might
1247 return !(skb_queue_empty(&sta->ps_tx_buf[ac]) &&
1248 skb_queue_empty(&sta->tx_filtered[ac]));
1258 if (!sta->sdata->bss &&
1259 !ieee80211_vif_is_mesh(&sta->sdata->vif))
1278 return -ENOENT;
1280 local = sta->local;
1281 sdata = sta->sdata;
1283 lockdep_assert_wiphy(local->hw.wiphy);
1288 * sessions -- block that to make sure the tear-down
1296 * rx frames on RSS queues sent prior to the disassociation - wait for
1301 for (i = 0; i < ARRAY_SIZE(sta->link); i++) {
1304 if (!(sta->sta.valid_links & BIT(i)))
1307 link_sta = rcu_dereference_protected(sta->link[i],
1308 lockdep_is_held(&local->hw.wiphy->mtx));
1322 drv_tdls_cancel_channel_switch(local, sdata, &sta->sta);
1326 list_del_rcu(&sta->list);
1327 sta->removed = true;
1329 if (sta->uploaded)
1330 drv_sta_pre_rcu_remove(local, sta->sdata, sta);
1332 if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
1333 rcu_access_pointer(sdata->u.vlan.sta) == sta)
1334 RCU_INIT_POINTER(sdata->u.vlan.sta, NULL);
1343 struct ieee80211_local *local = sta->local;
1347 if (sta->sta_state == new_state)
1354 if (sta->sta_state != IEEE80211_STA_AUTH)
1355 return -EINVAL;
1358 if (sta->sta_state != IEEE80211_STA_NONE &&
1359 sta->sta_state != IEEE80211_STA_ASSOC)
1360 return -EINVAL;
1363 if (sta->sta_state != IEEE80211_STA_AUTH &&
1364 sta->sta_state != IEEE80211_STA_AUTHORIZED)
1365 return -EINVAL;
1368 if (sta->sta_state != IEEE80211_STA_ASSOC)
1369 return -EINVAL;
1373 return -EINVAL;
1376 sta_dbg(sta->sdata, "moving STA %pM to state %d\n",
1377 sta->sta.addr, new_state);
1385 if (new_state > sta->sta_state &&
1387 int err = drv_sta_state(sta->local, sta->sdata, sta,
1388 sta->sta_state, new_state);
1397 if (sta->sta_state == IEEE80211_STA_AUTH)
1398 clear_bit(WLAN_STA_AUTH, &sta->_flags);
1401 if (sta->sta_state == IEEE80211_STA_NONE) {
1402 set_bit(WLAN_STA_AUTH, &sta->_flags);
1403 } else if (sta->sta_state == IEEE80211_STA_ASSOC) {
1404 clear_bit(WLAN_STA_ASSOC, &sta->_flags);
1406 ieee80211_recalc_min_chandef(sta->sdata, -1);
1407 if (!sta->sta.support_p2p_ps)
1408 ieee80211_recalc_p2p_go_ps_allowed(sta->sdata);
1413 if (sta->sta_state == IEEE80211_STA_AUTH) {
1414 set_bit(WLAN_STA_ASSOC, &sta->_flags);
1415 sta->assoc_at = ktime_get_boottime_ns();
1417 ieee80211_recalc_min_chandef(sta->sdata, -1);
1418 if (!sta->sta.support_p2p_ps)
1419 ieee80211_recalc_p2p_go_ps_allowed(sta->sdata);
1421 } else if (sta->sta_state == IEEE80211_STA_AUTHORIZED) {
1422 ieee80211_vif_dec_num_mcast(sta->sdata);
1423 clear_bit(WLAN_STA_AUTHORIZED, &sta->_flags);
1432 if (local->ops->set_key) {
1434 if (local->ops->flush_sta)
1435 drv_flush_sta(local, sta->sdata, sta);
1438 sta->sdata,
1447 if (sta->sta_state == IEEE80211_STA_ASSOC) {
1448 ieee80211_vif_inc_num_mcast(sta->sdata);
1449 set_bit(WLAN_STA_AUTHORIZED, &sta->_flags);
1453 if (sta->sdata->vif.type == NL80211_IFTYPE_AP_VLAN ||
1454 sta->sdata->vif.type == NL80211_IFTYPE_AP)
1455 cfg80211_send_layer2_update(sta->sdata->dev,
1456 sta->sta.addr);
1462 if (new_state < sta->sta_state &&
1464 int err = drv_sta_state(sta->local, sta->sdata, sta,
1465 sta->sta_state, new_state);
1472 sta->sta_state = new_state;
1485 struct ieee80211_local *local = sta->local;
1486 struct ieee80211_sub_if_data *sdata = sta->sdata;
1504 * certain that nobody can actually hold a reference to the STA and
1510 lockdep_assert_wiphy(local->hw.wiphy);
1512 if (sta->sta_state == IEEE80211_STA_AUTHORIZED) {
1520 /* disable TIM bit - last chance to tell driver */
1523 sta->dead = true;
1525 local->num_sta--;
1526 local->sta_generation++;
1528 while (sta->sta_state > IEEE80211_STA_NONE) {
1529 ret = _sta_info_move_state(sta, sta->sta_state - 1, recalc);
1536 if (sta->uploaded) {
1542 sta_dbg(sdata, "Removed STA %pM\n", sta->sta.addr);
1547 cfg80211_del_sta_sinfo(sdata->dev, sta->sta.addr, sinfo, GFP_KERNEL);
1552 ieee80211_destroy_frag_cache(&sta->frags);
1575 lockdep_assert_wiphy(sdata->local->hw.wiphy);
1586 lockdep_assert_wiphy(sdata->local->hw.wiphy);
1600 list_for_each_entry_rcu(sta, &local->sta_list, list)
1605 if (local->quiescing)
1611 mod_timer(&local->sta_cleanup,
1619 err = rhltable_init(&local->sta_hash, &sta_rht_params);
1623 err = rhltable_init(&local->link_sta_hash, &link_sta_rht_params);
1625 rhltable_destroy(&local->sta_hash);
1629 spin_lock_init(&local->tim_lock);
1630 INIT_LIST_HEAD(&local->sta_list);
1632 timer_setup(&local->sta_cleanup, sta_info_cleanup, 0);
1638 timer_delete_sync(&local->sta_cleanup);
1639 rhltable_destroy(&local->sta_hash);
1640 rhltable_destroy(&local->link_sta_hash);
1647 struct ieee80211_local *local = sdata->local;
1653 lockdep_assert_wiphy(local->hw.wiphy);
1655 WARN_ON(vlans && sdata->vif.type != NL80211_IFTYPE_AP);
1656 WARN_ON(vlans && !sdata->bss);
1658 list_for_each_entry_safe(sta, tmp, &local->sta_list, list) {
1659 if (sdata != sta->sdata &&
1660 (!vlans || sdata->bss != sta->sdata->bss))
1666 if (link_id >= 0 && sta->sta.valid_links &&
1667 !(sta->sta.valid_links & BIT(link_id)))
1671 list_add(&sta->free_list, &free_list);
1681 if (!sta->sta.support_p2p_ps)
1686 ieee80211_recalc_min_chandef(sdata, -1);
1697 struct ieee80211_local *local = sdata->local;
1700 lockdep_assert_wiphy(local->hw.wiphy);
1702 list_for_each_entry_safe(sta, tmp, &local->sta_list, list) {
1703 unsigned long last_active = ieee80211_sta_last_active(sta, -1);
1705 if (sdata != sta->sdata)
1709 sta_dbg(sta->sdata, "expiring inactive STA %pM\n",
1710 sta->sta.addr);
1712 if (ieee80211_vif_is_mesh(&sdata->vif) &&
1714 atomic_dec(&sdata->u.mesh.ps.num_sta_ps);
1735 !ether_addr_equal(sta->sdata->vif.addr, localaddr))
1737 if (!sta->uploaded)
1739 return &sta->sta;
1758 if (!sta->uploaded)
1761 return &sta->sta;
1768 struct ieee80211_sub_if_data *sdata = sta->sdata;
1769 struct ieee80211_local *local = sdata->local;
1773 struct ps_data *ps;
1775 if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
1776 sdata = container_of(sdata->bss, struct ieee80211_sub_if_data,
1779 if (sdata->vif.type == NL80211_IFTYPE_AP)
1780 ps = &sdata->bss->ps;
1781 else if (ieee80211_vif_is_mesh(&sdata->vif))
1782 ps = &sdata->u.mesh.ps;
1789 sta->driver_buffered_tids = 0;
1790 sta->txq_buffered_tids = 0;
1792 if (!ieee80211_hw_check(&local->hw, AP_LINK_PS))
1793 drv_sta_notify(local, sdata, STA_NOTIFY_AWAKE, &sta->sta);
1795 for (i = 0; i < ARRAY_SIZE(sta->sta.txq); i++) {
1796 if (!sta->sta.txq[i] || !txq_has_queue(sta->sta.txq[i]))
1799 schedule_and_wake_txq(local, to_txq_info(sta->sta.txq[i]));
1805 spin_lock_bh(&sta->ps_lock);
1810 spin_lock_irqsave(&sta->tx_filtered[ac].lock, flags);
1811 skb_queue_splice_tail_init(&sta->tx_filtered[ac], &pending);
1812 spin_unlock_irqrestore(&sta->tx_filtered[ac].lock, flags);
1814 filtered += tmp - count;
1817 spin_lock_irqsave(&sta->ps_tx_buf[ac].lock, flags);
1818 skb_queue_splice_tail_init(&sta->ps_tx_buf[ac], &pending);
1819 spin_unlock_irqrestore(&sta->ps_tx_buf[ac].lock, flags);
1821 buffered += tmp - count;
1834 spin_unlock_bh(&sta->ps_lock);
1836 atomic_dec(&ps->num_sta_ps);
1838 local->total_ps_buffered -= buffered;
1843 "STA %pM aid %d sending %d filtered/%d PS frames since STA woke up\n",
1844 sta->sta.addr, sta->sta.aid, filtered, buffered);
1853 struct ieee80211_sub_if_data *sdata = sta->sdata;
1854 struct ieee80211_local *local = sdata->local;
1859 bool qos = sta->sta.wme;
1868 size -= 2;
1874 skb = dev_alloc_skb(local->hw.extra_tx_headroom + size);
1878 skb_reserve(skb, local->hw.extra_tx_headroom);
1881 nullfunc->frame_control = fc;
1882 nullfunc->duration_id = 0;
1883 memcpy(nullfunc->addr1, sta->sta.addr, ETH_ALEN);
1884 memcpy(nullfunc->addr2, sdata->vif.addr, ETH_ALEN);
1885 memcpy(nullfunc->addr3, sdata->vif.addr, ETH_ALEN);
1886 nullfunc->seq_ctrl = 0;
1888 skb->priority = tid;
1891 nullfunc->qos_ctrl = cpu_to_le16(tid);
1894 nullfunc->qos_ctrl |=
1897 nullfunc->frame_control |=
1906 * STA may still remain is PS mode after this frame
1910 info->flags |= IEEE80211_TX_CTL_NO_PS_BUFFER |
1914 info->control.flags |= IEEE80211_TX_CTRL_PS_RESPONSE;
1920 skb->dev = sdata->dev;
1923 chanctx_conf = rcu_dereference(sdata->vif.bss_conf.chanctx_conf);
1930 info->band = chanctx_conf->def.chan->band;
1939 return fls(tids) - 1;
1943 return fls(tids) - 1;
1961 * only happen for PS-Poll.
1971 if (!skb_queue_empty(&sta->tx_filtered[ac]) ||
1972 !skb_queue_empty(&sta->ps_tx_buf[ac]))
1985 struct ieee80211_sub_if_data *sdata = sta->sdata;
1986 struct ieee80211_local *local = sdata->local;
2003 sta->driver_buffered_tids & tids;
2004 *driver_release_tids |= sta->txq_buffered_tids & tids;
2011 skb = skb_dequeue(&sta->tx_filtered[ac]);
2014 &sta->ps_tx_buf[ac]);
2016 local->total_ps_buffered--;
2020 n_frames--;
2029 if (!skb_queue_empty(&sta->tx_filtered[ac]) ||
2030 !skb_queue_empty(&sta->ps_tx_buf[ac]))
2040 struct ieee80211_sub_if_data *sdata = sta->sdata;
2041 struct ieee80211_local *local = sdata->local;
2046 /* Service or PS-Poll period starts */
2064 * For PS-Poll, this can only happen due to a race condition
2069 * At each unscheduled SP for a non-AP STA, the AP shall
2072 * in the QoS Capability element from delivery-enabled ACs,
2073 * that are destined for the non-AP STA.
2082 tid = 7 - 2 * ac;
2096 struct ieee80211_hdr *hdr = (void *) skb->data;
2103 * STA may still remain is PS mode after this frame
2106 info->flags |= IEEE80211_TX_CTL_NO_PS_BUFFER;
2107 info->control.flags |= IEEE80211_TX_CTRL_PS_RESPONSE;
2114 hdr->frame_control |=
2117 hdr->frame_control &=
2120 if (ieee80211_is_data_qos(hdr->frame_control) ||
2121 ieee80211_is_qos_nullfunc(hdr->frame_control))
2124 tids |= BIT(skb->priority);
2133 /* for PS-Poll, there's only one frame */
2134 info->flags |= IEEE80211_TX_STATUS_EOSP |
2140 * last frame has a QoS header (i.e. is a QoS-data or
2141 * QoS-nulldata frame) then just set the EOSP bit there
2145 * the EOSP bit in the QoS header; add a QoS-nulldata
2148 * Note that this code is only in the mac80211-release
2150 * anything but QoS-data frames, or if it does, will
2151 * create the QoS-nulldata frame by itself if needed.
2153 * Cf. 802.11-2012 10.2.1.10 (c).
2158 info->flags |= IEEE80211_TX_STATUS_EOSP |
2162 * as it says the more-data bit should be set
2163 * if there are more BUs. The QoS-Null frame
2167 * expect more-data=0 when eosp=1.
2169 hdr->frame_control |=
2195 * on the TIDs we're releasing from - if there are more than
2196 * n_frames it has to set the more-data bit (if we didn't ask
2214 for (tid = 0; tid < ARRAY_SIZE(sta->sta.txq); tid++) {
2215 if (!sta->sta.txq[tid] ||
2217 txq_has_queue(sta->sta.txq[tid]))
2228 u8 ignore_for_response = sta->sta.uapsd_queues;
2231 * If all ACs are delivery-enabled then we should reply
2233 * only from the non-enabled ones.
2235 if (ignore_for_response == BIT(IEEE80211_NUM_ACS) - 1)
2244 int n_frames = sta->sta.max_sp;
2245 u8 delivery_enabled = sta->sta.uapsd_queues;
2256 switch (sta->sta.max_sp) {
2281 trace_api_sta_block_awake(sta->local, pubsta, block);
2295 ieee80211_queue_work(hw, &sta->drv_deliver_wk);
2300 ieee80211_queue_work(hw, &sta->drv_deliver_wk);
2311 struct ieee80211_local *local = sta->local;
2325 trace_api_send_eosp_nullfunc(sta->local, pubsta, tid);
2328 more_data = ieee80211_sta_ps_more_data(sta, ~sta->sta.uapsd_queues,
2343 trace_api_sta_set_buffered(sta->local, pubsta, tid, buffered);
2346 set_bit(tid, &sta->driver_buffered_tids);
2348 clear_bit(tid, &sta->driver_buffered_tids);
2358 struct ieee80211_local *local = sta->sdata->local;
2362 if (sta->local->airtime_flags & AIRTIME_USE_TX)
2364 if (sta->local->airtime_flags & AIRTIME_USE_RX)
2367 spin_lock_bh(&local->active_txq_lock[ac]);
2368 sta->airtime[ac].tx_airtime += tx_airtime;
2369 sta->airtime[ac].rx_airtime += rx_airtime;
2372 sta->airtime[ac].deficit -= airtime;
2374 spin_unlock_bh(&local->active_txq_lock[ac]);
2383 if (!sta->sta.valid_links || !sta->sta.mlo) {
2384 sta->sta.cur = &sta->sta.deflink.agg;
2389 for (link_id = 0; link_id < ARRAY_SIZE((sta)->link); link_id++) {
2396 link_sta = rcu_dereference(sta->sta.link[link_id]);
2401 sta->cur = sta->sta.deflink.agg;
2406 sta->cur.max_amsdu_len =
2407 min(sta->cur.max_amsdu_len,
2408 link_sta->agg.max_amsdu_len);
2409 sta->cur.max_rc_amsdu_len =
2410 min(sta->cur.max_rc_amsdu_len,
2411 link_sta->agg.max_rc_amsdu_len);
2413 for (i = 0; i < ARRAY_SIZE(sta->cur.max_tid_amsdu_len); i++)
2414 sta->cur.max_tid_amsdu_len[i] =
2415 min(sta->cur.max_tid_amsdu_len[i],
2416 link_sta->agg.max_tid_amsdu_len[i]);
2420 sta->sta.cur = &sta->cur;
2427 __ieee80211_sta_recalc_aggregates(sta, sta->sdata->vif.active_links);
2437 if (!wiphy_ext_feature_isset(local->hw.wiphy, NL80211_EXT_FEATURE_AQL))
2443 &sta->airtime[ac].aql_tx_pending);
2445 atomic_add(tx_airtime, &local->aql_total_pending_airtime);
2446 atomic_add(tx_airtime, &local->aql_ac_pending_airtime[ac]);
2452 &sta->airtime[ac].aql_tx_pending);
2454 atomic_cmpxchg(&sta->airtime[ac].aql_tx_pending,
2458 atomic_sub(tx_airtime, &local->aql_total_pending_airtime);
2460 &local->aql_ac_pending_airtime[ac]);
2463 wiphy_name(local->hw.wiphy), ac, tx_pending,
2465 atomic_cmpxchg(&local->aql_ac_pending_airtime[ac],
2467 atomic_sub(tx_pending, &local->aql_total_pending_airtime);
2479 link_sta_info = &sta->deflink;
2481 link_sta_info = wiphy_dereference(sta->local->hw.wiphy,
2482 sta->link[link_id]);
2484 stats = &link_sta_info->rx_stats;
2486 if (!link_sta_info->pcpu_rx_stats)
2492 cpustats = per_cpu_ptr(link_sta_info->pcpu_rx_stats, cpu);
2494 if (time_after(cpustats->last_rx, stats->last_rx))
2504 rinfo->bw = STA_STATS_GET(BW, rate);
2508 rinfo->flags = RATE_INFO_FLAGS_VHT_MCS;
2509 rinfo->mcs = STA_STATS_GET(VHT_MCS, rate);
2510 rinfo->nss = STA_STATS_GET(VHT_NSS, rate);
2512 rinfo->flags |= RATE_INFO_FLAGS_SHORT_GI;
2515 rinfo->flags = RATE_INFO_FLAGS_MCS;
2516 rinfo->mcs = STA_STATS_GET(HT_MCS, rate);
2518 rinfo->flags |= RATE_INFO_FLAGS_SHORT_GI;
2527 sband = local->hw.wiphy->bands[band];
2529 if (WARN_ON_ONCE(!sband->bitrates))
2532 brate = sband->bitrates[rate_idx].bitrate;
2533 if (rinfo->bw == RATE_INFO_BW_5)
2535 else if (rinfo->bw == RATE_INFO_BW_10)
2539 rinfo->legacy = DIV_ROUND_UP(brate, 1 << shift);
2543 rinfo->flags = RATE_INFO_FLAGS_HE_MCS;
2544 rinfo->mcs = STA_STATS_GET(HE_MCS, rate);
2545 rinfo->nss = STA_STATS_GET(HE_NSS, rate);
2546 rinfo->he_gi = STA_STATS_GET(HE_GI, rate);
2547 rinfo->he_ru_alloc = STA_STATS_GET(HE_RU, rate);
2548 rinfo->he_dcm = STA_STATS_GET(HE_DCM, rate);
2551 rinfo->flags = RATE_INFO_FLAGS_EHT_MCS;
2552 rinfo->mcs = STA_STATS_GET(EHT_MCS, rate);
2553 rinfo->nss = STA_STATS_GET(EHT_NSS, rate);
2554 rinfo->eht_gi = STA_STATS_GET(EHT_GI, rate);
2555 rinfo->eht_ru_alloc = STA_STATS_GET(EHT_RU, rate);
2563 u32 rate = READ_ONCE(sta_get_last_rx_stats(sta, link_id)->last_rate);
2566 return -EINVAL;
2568 sta_stats_decode_rate(sta->local, rate, rinfo);
2579 start = u64_stats_fetch_begin(&rxstats->syncp);
2580 value = rxstats->msdu[tid];
2581 } while (u64_stats_fetch_retry(&rxstats->syncp, start));
2590 struct ieee80211_local *local = sta->local;
2595 link_sta_info = &sta->deflink;
2597 link_sta_info = wiphy_dereference(sta->local->hw.wiphy,
2598 sta->link[link_id]);
2600 if (!(tidstats->filled & BIT(NL80211_TID_STATS_RX_MSDU))) {
2601 tidstats->rx_msdu +=
2602 sta_get_tidstats_msdu(&link_sta_info->rx_stats,
2605 if (link_sta_info->pcpu_rx_stats) {
2609 cpurxs = per_cpu_ptr(link_sta_info->pcpu_rx_stats,
2611 tidstats->rx_msdu +=
2616 tidstats->filled |= BIT(NL80211_TID_STATS_RX_MSDU);
2619 if (!(tidstats->filled & BIT(NL80211_TID_STATS_TX_MSDU))) {
2620 tidstats->filled |= BIT(NL80211_TID_STATS_TX_MSDU);
2621 tidstats->tx_msdu = link_sta_info->tx_stats.msdu[tid];
2624 if (!(tidstats->filled & BIT(NL80211_TID_STATS_TX_MSDU_RETRIES)) &&
2625 ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS)) {
2626 tidstats->filled |= BIT(NL80211_TID_STATS_TX_MSDU_RETRIES);
2627 tidstats->tx_msdu_retries =
2628 link_sta_info->status_stats.msdu_retries[tid];
2631 if (!(tidstats->filled & BIT(NL80211_TID_STATS_TX_MSDU_FAILED)) &&
2632 ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS)) {
2633 tidstats->filled |= BIT(NL80211_TID_STATS_TX_MSDU_FAILED);
2634 tidstats->tx_msdu_failed =
2635 link_sta_info->status_stats.msdu_failed[tid];
2639 spin_lock_bh(&local->fq.lock);
2641 tidstats->filled |= BIT(NL80211_TID_STATS_TXQ_STATS);
2642 ieee80211_fill_txq_stats(&tidstats->txq_stats,
2643 to_txq_info(sta->sta.txq[tid]));
2645 spin_unlock_bh(&local->fq.lock);
2655 start = u64_stats_fetch_begin(&rxstats->syncp);
2656 value = rxstats->bytes;
2657 } while (u64_stats_fetch_retry(&rxstats->syncp, start));
2666 struct ieee80211_local *local = sta->sdata->local;
2668 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_LLID) |
2677 sinfo->llid = sta->mesh->llid;
2678 sinfo->plid = sta->mesh->plid;
2679 sinfo->plink_state = sta->mesh->plink_state;
2681 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_T_OFFSET);
2682 sinfo->t_offset = sta->mesh->t_offset;
2684 sinfo->local_pm = sta->mesh->local_pm;
2685 sinfo->peer_pm = sta->mesh->peer_pm;
2686 sinfo->nonpeer_pm = sta->mesh->nonpeer_pm;
2687 sinfo->connected_to_gate = sta->mesh->connected_to_gate;
2688 sinfo->connected_to_as = sta->mesh->connected_to_as;
2690 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_AIRTIME_LINK_METRIC);
2691 sinfo->airtime_link_metric = airtime_link_metric_get(local, sta);
2699 sinfo->tx_packets = sta->rem_link_stats.tx_packets;
2700 sinfo->rx_packets = sta->rem_link_stats.rx_packets;
2701 sinfo->tx_bytes = sta->rem_link_stats.tx_bytes;
2702 sinfo->rx_bytes = sta->rem_link_stats.rx_bytes;
2703 sinfo->tx_retries = sta->rem_link_stats.tx_retries;
2704 sinfo->tx_failed = sta->rem_link_stats.tx_failed;
2705 sinfo->rx_dropped_misc = sta->rem_link_stats.rx_dropped_misc;
2706 sinfo->beacon_loss_count = sta->rem_link_stats.beacon_loss_count;
2707 sinfo->expected_throughput = sta->rem_link_stats.expected_throughput;
2709 if (sinfo->pertid) {
2710 sinfo->pertid->rx_msdu =
2711 sta->rem_link_stats.pertid_stats.rx_msdu;
2712 sinfo->pertid->tx_msdu =
2713 sta->rem_link_stats.pertid_stats.tx_msdu;
2714 sinfo->pertid->tx_msdu_retries =
2715 sta->rem_link_stats.pertid_stats.tx_msdu_retries;
2716 sinfo->pertid->tx_msdu_failed =
2717 sta->rem_link_stats.pertid_stats.tx_msdu_failed;
2726 struct ieee80211_sub_if_data *sdata = sta->sdata;
2728 int i, ac, cpu, link_id = link->link_id;
2734 link_sta_info = wiphy_dereference(sta->local->hw.wiphy,
2735 sta->link[link_id]);
2741 if (sdata->vif.type == NL80211_IFTYPE_STATION)
2742 link_sinfo->rx_beacon = link->u.mgd.count_beacon_signal;
2744 ether_addr_copy(link_sinfo->addr, link_sta_info->addr);
2746 drv_link_sta_statistics(sta->local, sdata,
2747 link_sta_info->pub,
2750 link_sinfo->filled |= BIT_ULL(NL80211_STA_INFO_INACTIVE_TIME) |
2754 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
2755 link_sinfo->beacon_loss_count =
2756 link->u.mgd.beacon_loss_count;
2757 link_sinfo->filled |= BIT_ULL(NL80211_STA_INFO_BEACON_LOSS);
2760 link_sinfo->inactive_time =
2761 jiffies_to_msecs(jiffies - ieee80211_sta_last_active(sta, link_id));
2763 if (!(link_sinfo->filled & (BIT_ULL(NL80211_STA_INFO_TX_BYTES64) |
2765 link_sinfo->tx_bytes = 0;
2767 link_sinfo->tx_bytes +=
2768 link_sta_info->tx_stats.bytes[ac];
2769 link_sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_BYTES64);
2772 if (!(link_sinfo->filled & BIT_ULL(NL80211_STA_INFO_TX_PACKETS))) {
2773 link_sinfo->tx_packets = 0;
2775 link_sinfo->tx_packets +=
2776 link_sta_info->tx_stats.packets[ac];
2777 link_sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_PACKETS);
2780 if (!(link_sinfo->filled & (BIT_ULL(NL80211_STA_INFO_RX_BYTES64) |
2782 link_sinfo->rx_bytes +=
2783 sta_get_stats_bytes(&link_sta_info->rx_stats);
2785 if (link_sta_info->pcpu_rx_stats) {
2789 cpurxs = per_cpu_ptr(link_sta_info->pcpu_rx_stats,
2791 link_sinfo->rx_bytes +=
2796 link_sinfo->filled |= BIT_ULL(NL80211_STA_INFO_RX_BYTES64);
2799 if (!(link_sinfo->filled & BIT_ULL(NL80211_STA_INFO_RX_PACKETS))) {
2800 link_sinfo->rx_packets = link_sta_info->rx_stats.packets;
2801 if (link_sta_info->pcpu_rx_stats) {
2805 cpurxs = per_cpu_ptr(link_sta_info->pcpu_rx_stats,
2807 link_sinfo->rx_packets += cpurxs->packets;
2810 link_sinfo->filled |= BIT_ULL(NL80211_STA_INFO_RX_PACKETS);
2813 if (!(link_sinfo->filled & BIT_ULL(NL80211_STA_INFO_TX_RETRIES))) {
2814 link_sinfo->tx_retries =
2815 link_sta_info->status_stats.retry_count;
2816 link_sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_RETRIES);
2819 if (!(link_sinfo->filled & BIT_ULL(NL80211_STA_INFO_TX_FAILED))) {
2820 link_sinfo->tx_failed =
2821 link_sta_info->status_stats.retry_failed;
2822 link_sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_FAILED);
2825 if (!(link_sinfo->filled & BIT_ULL(NL80211_STA_INFO_RX_DURATION))) {
2827 link_sinfo->rx_duration += sta->airtime[ac].rx_airtime;
2828 link_sinfo->filled |= BIT_ULL(NL80211_STA_INFO_RX_DURATION);
2831 if (!(link_sinfo->filled & BIT_ULL(NL80211_STA_INFO_TX_DURATION))) {
2833 link_sinfo->tx_duration += sta->airtime[ac].tx_airtime;
2834 link_sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_DURATION);
2837 if (!(link_sinfo->filled & BIT_ULL(NL80211_STA_INFO_AIRTIME_WEIGHT))) {
2838 link_sinfo->airtime_weight = sta->airtime_weight;
2839 link_sinfo->filled |= BIT_ULL(NL80211_STA_INFO_AIRTIME_WEIGHT);
2842 link_sinfo->rx_dropped_misc = link_sta_info->rx_stats.dropped;
2843 if (link_sta_info->pcpu_rx_stats) {
2847 cpurxs = per_cpu_ptr(link_sta_info->pcpu_rx_stats,
2849 link_sinfo->rx_dropped_misc += cpurxs->dropped;
2853 if (sdata->vif.type == NL80211_IFTYPE_STATION &&
2854 !(sdata->vif.driver_flags & IEEE80211_VIF_BEACON_FILTER)) {
2855 link_sinfo->filled |= BIT_ULL(NL80211_STA_INFO_BEACON_RX) |
2857 link_sinfo->rx_beacon_signal_avg =
2858 ieee80211_ave_rssi(&sdata->vif, -1);
2861 if (ieee80211_hw_check(&sta->local->hw, SIGNAL_DBM) ||
2862 ieee80211_hw_check(&sta->local->hw, SIGNAL_UNSPEC)) {
2863 if (!(link_sinfo->filled & BIT_ULL(NL80211_STA_INFO_SIGNAL))) {
2864 link_sinfo->signal = (s8)last_rxstats->last_signal;
2865 link_sinfo->filled |= BIT_ULL(NL80211_STA_INFO_SIGNAL);
2868 if (!link_sta_info->pcpu_rx_stats &&
2869 !(link_sinfo->filled &
2871 link_sinfo->signal_avg =
2872 -ewma_signal_read(&link_sta_info->rx_stats_avg.signal);
2873 link_sinfo->filled |=
2878 /* for the average - if pcpu_rx_stats isn't set - rxstats must point to
2879 * the sta->rx_stats struct, so the check here is fine with and without
2882 if (last_rxstats->chains &&
2883 !(link_sinfo->filled & (BIT_ULL(NL80211_STA_INFO_CHAIN_SIGNAL) |
2885 link_sinfo->filled |= BIT_ULL(NL80211_STA_INFO_CHAIN_SIGNAL);
2886 if (!link_sta_info->pcpu_rx_stats)
2887 link_sinfo->filled |=
2890 link_sinfo->chains = last_rxstats->chains;
2892 for (i = 0; i < ARRAY_SIZE(link_sinfo->chain_signal); i++) {
2893 link_sinfo->chain_signal[i] =
2894 last_rxstats->chain_signal_last[i];
2895 link_sinfo->chain_signal_avg[i] =
2896 -ewma_signal_read(
2897 &link_sta_info->rx_stats_avg.chain_signal[i]);
2901 if (!(link_sinfo->filled & BIT_ULL(NL80211_STA_INFO_TX_BITRATE)) &&
2902 ieee80211_rate_valid(&link_sta_info->tx_stats.last_rate)) {
2903 sta_set_rate_info_tx(sta, &link_sta_info->tx_stats.last_rate,
2904 &link_sinfo->txrate);
2905 link_sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_BITRATE);
2908 if (!(link_sinfo->filled & BIT_ULL(NL80211_STA_INFO_RX_BITRATE))) {
2909 if (sta_set_rate_info_rx(sta, &link_sinfo->rxrate,
2911 link_sinfo->filled |=
2918 sta_set_tidstats(sta, &link_sinfo->pertid[i], i,
2922 link_sinfo->bss_param.flags = 0;
2923 if (sdata->vif.bss_conf.use_cts_prot)
2924 link_sinfo->bss_param.flags |= BSS_PARAM_FLAGS_CTS_PROT;
2925 if (sdata->vif.bss_conf.use_short_preamble)
2926 link_sinfo->bss_param.flags |= BSS_PARAM_FLAGS_SHORT_PREAMBLE;
2927 if (sdata->vif.bss_conf.use_short_slot)
2928 link_sinfo->bss_param.flags |= BSS_PARAM_FLAGS_SHORT_SLOT_TIME;
2929 link_sinfo->bss_param.dtim_period = link->conf->dtim_period;
2930 link_sinfo->bss_param.beacon_interval = link->conf->beacon_int;
2935 link_sinfo->filled |=
2937 link_sinfo->expected_throughput = thr;
2940 if (!(link_sinfo->filled & BIT_ULL(NL80211_STA_INFO_ACK_SIGNAL)) &&
2941 link_sta_info->status_stats.ack_signal_filled) {
2942 link_sinfo->ack_signal =
2943 link_sta_info->status_stats.last_ack_signal;
2944 link_sinfo->filled |= BIT_ULL(NL80211_STA_INFO_ACK_SIGNAL);
2947 if (!(link_sinfo->filled & BIT_ULL(NL80211_STA_INFO_ACK_SIGNAL_AVG)) &&
2948 link_sta_info->status_stats.ack_signal_filled) {
2949 link_sinfo->avg_ack_signal =
2950 -(s8)ewma_avg_signal_read(
2951 &link_sta_info->status_stats.avg_ack_signal);
2952 link_sinfo->filled |=
2960 struct ieee80211_sub_if_data *sdata = sta->sdata;
2961 struct ieee80211_local *local = sdata->local;
2966 last_rxstats = sta_get_last_rx_stats(sta, -1);
2968 sinfo->generation = sdata->local->sta_generation;
2974 if (sdata->vif.type == NL80211_IFTYPE_STATION)
2975 sinfo->rx_beacon = sdata->deflink.u.mgd.count_beacon_signal;
2977 drv_sta_statistics(local, sdata, &sta->sta, sinfo);
2978 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_INACTIVE_TIME) |
2985 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
2986 sinfo->beacon_loss_count =
2987 sdata->deflink.u.mgd.beacon_loss_count;
2988 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_BEACON_LOSS);
2991 sinfo->connected_time = ktime_get_seconds() - sta->last_connected;
2992 sinfo->assoc_at = sta->assoc_at;
2993 sinfo->inactive_time =
2994 jiffies_to_msecs(jiffies - ieee80211_sta_last_active(sta, -1));
2996 if (!(sinfo->filled & (BIT_ULL(NL80211_STA_INFO_TX_BYTES64) |
2998 sinfo->tx_bytes = 0;
3000 sinfo->tx_bytes += sta->deflink.tx_stats.bytes[ac];
3001 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_BYTES64);
3004 if (!(sinfo->filled & BIT_ULL(NL80211_STA_INFO_TX_PACKETS))) {
3005 sinfo->tx_packets = 0;
3007 sinfo->tx_packets += sta->deflink.tx_stats.packets[ac];
3008 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_PACKETS);
3011 if (!(sinfo->filled & (BIT_ULL(NL80211_STA_INFO_RX_BYTES64) |
3013 sinfo->rx_bytes += sta_get_stats_bytes(&sta->deflink.rx_stats);
3015 if (sta->deflink.pcpu_rx_stats) {
3019 cpurxs = per_cpu_ptr(sta->deflink.pcpu_rx_stats,
3021 sinfo->rx_bytes += sta_get_stats_bytes(cpurxs);
3025 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_RX_BYTES64);
3028 if (!(sinfo->filled & BIT_ULL(NL80211_STA_INFO_RX_PACKETS))) {
3029 sinfo->rx_packets = sta->deflink.rx_stats.packets;
3030 if (sta->deflink.pcpu_rx_stats) {
3034 cpurxs = per_cpu_ptr(sta->deflink.pcpu_rx_stats,
3036 sinfo->rx_packets += cpurxs->packets;
3039 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_RX_PACKETS);
3042 if (!(sinfo->filled & BIT_ULL(NL80211_STA_INFO_TX_RETRIES))) {
3043 sinfo->tx_retries = sta->deflink.status_stats.retry_count;
3044 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_RETRIES);
3047 if (!(sinfo->filled & BIT_ULL(NL80211_STA_INFO_TX_FAILED))) {
3048 sinfo->tx_failed = sta->deflink.status_stats.retry_failed;
3049 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_FAILED);
3052 if (!(sinfo->filled & BIT_ULL(NL80211_STA_INFO_RX_DURATION))) {
3054 sinfo->rx_duration += sta->airtime[ac].rx_airtime;
3055 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_RX_DURATION);
3058 if (!(sinfo->filled & BIT_ULL(NL80211_STA_INFO_TX_DURATION))) {
3060 sinfo->tx_duration += sta->airtime[ac].tx_airtime;
3061 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_DURATION);
3064 if (!(sinfo->filled & BIT_ULL(NL80211_STA_INFO_AIRTIME_WEIGHT))) {
3065 sinfo->airtime_weight = sta->airtime_weight;
3066 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_AIRTIME_WEIGHT);
3069 sinfo->rx_dropped_misc = sta->deflink.rx_stats.dropped;
3070 if (sta->deflink.pcpu_rx_stats) {
3074 cpurxs = per_cpu_ptr(sta->deflink.pcpu_rx_stats, cpu);
3075 sinfo->rx_dropped_misc += cpurxs->dropped;
3079 if (sdata->vif.type == NL80211_IFTYPE_STATION &&
3080 !(sdata->vif.driver_flags & IEEE80211_VIF_BEACON_FILTER)) {
3081 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_BEACON_RX) |
3083 sinfo->rx_beacon_signal_avg =
3084 ieee80211_ave_rssi(&sdata->vif, -1);
3087 if (ieee80211_hw_check(&sta->local->hw, SIGNAL_DBM) ||
3088 ieee80211_hw_check(&sta->local->hw, SIGNAL_UNSPEC)) {
3089 if (!(sinfo->filled & BIT_ULL(NL80211_STA_INFO_SIGNAL))) {
3090 sinfo->signal = (s8)last_rxstats->last_signal;
3091 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_SIGNAL);
3094 if (!sta->deflink.pcpu_rx_stats &&
3095 !(sinfo->filled & BIT_ULL(NL80211_STA_INFO_SIGNAL_AVG))) {
3096 sinfo->signal_avg =
3097 -ewma_signal_read(&sta->deflink.rx_stats_avg.signal);
3098 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_SIGNAL_AVG);
3102 /* for the average - if pcpu_rx_stats isn't set - rxstats must point to
3103 * the sta->rx_stats struct, so the check here is fine with and without
3106 if (last_rxstats->chains &&
3107 !(sinfo->filled & (BIT_ULL(NL80211_STA_INFO_CHAIN_SIGNAL) |
3109 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_CHAIN_SIGNAL);
3110 if (!sta->deflink.pcpu_rx_stats)
3111 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_CHAIN_SIGNAL_AVG);
3113 sinfo->chains = last_rxstats->chains;
3115 for (i = 0; i < ARRAY_SIZE(sinfo->chain_signal); i++) {
3116 sinfo->chain_signal[i] =
3117 last_rxstats->chain_signal_last[i];
3118 sinfo->chain_signal_avg[i] =
3119 -ewma_signal_read(&sta->deflink.rx_stats_avg.chain_signal[i]);
3123 if (!(sinfo->filled & BIT_ULL(NL80211_STA_INFO_TX_BITRATE)) &&
3124 !sta->sta.valid_links &&
3125 ieee80211_rate_valid(&sta->deflink.tx_stats.last_rate)) {
3126 sta_set_rate_info_tx(sta, &sta->deflink.tx_stats.last_rate,
3127 &sinfo->txrate);
3128 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_BITRATE);
3131 if (!(sinfo->filled & BIT_ULL(NL80211_STA_INFO_RX_BITRATE)) &&
3132 !sta->sta.valid_links) {
3133 if (sta_set_rate_info_rx(sta, &sinfo->rxrate, -1) == 0)
3134 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_RX_BITRATE);
3139 sta_set_tidstats(sta, &sinfo->pertid[i], i, -1);
3143 if (ieee80211_vif_is_mesh(&sdata->vif))
3147 sinfo->bss_param.flags = 0;
3148 if (sdata->vif.bss_conf.use_cts_prot)
3149 sinfo->bss_param.flags |= BSS_PARAM_FLAGS_CTS_PROT;
3150 if (sdata->vif.bss_conf.use_short_preamble)
3151 sinfo->bss_param.flags |= BSS_PARAM_FLAGS_SHORT_PREAMBLE;
3152 if (sdata->vif.bss_conf.use_short_slot)
3153 sinfo->bss_param.flags |= BSS_PARAM_FLAGS_SHORT_SLOT_TIME;
3154 sinfo->bss_param.dtim_period = sdata->vif.bss_conf.dtim_period;
3155 sinfo->bss_param.beacon_interval = sdata->vif.bss_conf.beacon_int;
3157 sinfo->sta_flags.set = 0;
3158 sinfo->sta_flags.mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
3166 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_AUTHORIZED);
3168 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_SHORT_PREAMBLE);
3169 if (sta->sta.wme)
3170 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_WME);
3172 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_MFP);
3174 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_AUTHENTICATED);
3176 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_ASSOCIATED);
3178 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_TDLS_PEER);
3183 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_EXPECTED_THROUGHPUT);
3184 sinfo->expected_throughput = thr;
3187 if (!(sinfo->filled & BIT_ULL(NL80211_STA_INFO_ACK_SIGNAL)) &&
3188 sta->deflink.status_stats.ack_signal_filled) {
3189 sinfo->ack_signal = sta->deflink.status_stats.last_ack_signal;
3190 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_ACK_SIGNAL);
3193 if (!(sinfo->filled & BIT_ULL(NL80211_STA_INFO_ACK_SIGNAL_AVG)) &&
3194 sta->deflink.status_stats.ack_signal_filled) {
3195 sinfo->avg_ack_signal =
3196 -(s8)ewma_avg_signal_read(
3197 &sta->deflink.status_stats.avg_ack_signal);
3198 sinfo->filled |=
3202 if (sta->sta.valid_links) {
3207 ether_addr_copy(sinfo->mld_addr, sta->addr);
3210 sinfo->valid_links = sta->sta.valid_links;
3213 link_sta = wiphy_dereference(sta->local->hw.wiphy,
3214 sta->link[link_id]);
3215 link = wiphy_dereference(sdata->local->hw.wiphy,
3216 sdata->link[link_id]);
3218 if (!link_sta || !sinfo->links[link_id] || !link) {
3219 sinfo->valid_links &= ~BIT(link_id);
3222 sta_set_link_sinfo(sta, sinfo->links[link_id],
3230 struct ieee80211_sub_if_data *sdata = sta->sdata;
3231 struct ieee80211_local *local = sdata->local;
3236 ref = local->rate_ctrl;
3239 if (ref && ref->ops->get_expected_throughput)
3240 thr = ref->ops->get_expected_throughput(sta->rate_ctrl_priv);
3255 link_sta_info = &sta->deflink;
3257 link_sta_info = wiphy_dereference(sta->local->hw.wiphy,
3258 sta->link[link_id]);
3260 if (!link_sta_info->status_stats.last_ack ||
3261 time_after(stats->last_rx, link_sta_info->status_stats.last_ack))
3262 return stats->last_rx;
3264 return link_sta_info->status_stats.last_ack;
3269 struct ieee80211_sub_if_data *sdata = sta->sdata;
3273 lockdep_assert_wiphy(sdata->local->hw.wiphy);
3278 if (WARN_ON(!sta->sta.valid_links))
3279 return -EINVAL;
3281 if (WARN_ON(sta->sta.valid_links & BIT(link_id) ||
3282 sta->link[link_id]))
3283 return -EBUSY;
3287 return -ENOMEM;
3289 ret = sta_info_alloc_link(sdata->local, &alloc->info, GFP_KERNEL);
3295 sta_info_add_link(sta, link_id, &alloc->info, &alloc->sta);
3297 ieee80211_link_sta_debugfs_add(&alloc->info);
3304 lockdep_assert_wiphy(sta->sdata->local->hw.wiphy);
3313 struct ieee80211_sub_if_data *sdata = sta->sdata;
3315 u16 old_links = sta->sta.valid_links;
3319 link_sta = rcu_dereference_protected(sta->link[link_id],
3320 lockdep_is_held(&sdata->local->hw.wiphy->mtx));
3323 return -EINVAL;
3326 if (link_sta_info_hash_lookup(sdata->local, link_sta->addr)) {
3328 return -EALREADY;
3333 sta->sta.valid_links = new_links;
3343 ieee80211_sta_recalc_aggregates(&sta->sta);
3345 ret = drv_change_sta_links(sdata->local, sdata, &sta->sta,
3348 sta->sta.valid_links = old_links;
3354 ret = link_sta_info_hash_add(sdata->local, link_sta);
3361 struct ieee80211_sub_if_data *sdata = sta->sdata;
3362 u16 old_links = sta->sta.valid_links;
3364 lockdep_assert_wiphy(sdata->local->hw.wiphy);
3366 sta->sta.valid_links &= ~BIT(link_id);
3369 drv_change_sta_links(sdata->local, sdata, &sta->sta,
3370 old_links, sta->sta.valid_links);
3381 sta->sta.max_amsdu_subframes = 0;
3395 sta->sta.max_amsdu_subframes = 4 << (4 - val);
3403 return lockdep_is_held(&sta->local->hw.wiphy->mtx);