hc
2024-10-22 8ac6c7a54ed1b98d142dce24b11c6de6a1e239a5
kernel/net/mac80211/sta_info.c
....@@ -1,13 +1,10 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * Copyright 2002-2005, Instant802 Networks, Inc.
34 * Copyright 2006-2007 Jiri Benc <jbenc@suse.cz>
45 * Copyright 2013-2014 Intel Mobile Communications GmbH
56 * Copyright (C) 2015 - 2017 Intel Deutschland GmbH
67 * Copyright (C) 2018-2021 Intel Corporation
7
- *
8
- * This program is free software; you can redistribute it and/or modify
9
- * it under the terms of the GNU General Public License version 2 as
10
- * published by the Free Software Foundation.
118 */
129
1310 #include <linux/module.h>
....@@ -90,7 +87,6 @@
9087 struct tid_ampdu_tx *tid_tx;
9188 struct ieee80211_sub_if_data *sdata = sta->sdata;
9289 struct ieee80211_local *local = sdata->local;
93
- struct fq *fq = &local->fq;
9490 struct ps_data *ps;
9591
9692 if (test_sta_flag(sta, WLAN_STA_PS_STA) ||
....@@ -113,11 +109,14 @@
113109
114110 if (sta->sta.txq[0]) {
115111 for (i = 0; i < ARRAY_SIZE(sta->sta.txq); i++) {
116
- struct txq_info *txqi = to_txq_info(sta->sta.txq[i]);
112
+ struct txq_info *txqi;
117113
118
- spin_lock_bh(&fq->lock);
114
+ if (!sta->sta.txq[i])
115
+ continue;
116
+
117
+ txqi = to_txq_info(sta->sta.txq[i]);
118
+
119119 ieee80211_txq_purge(local, txqi);
120
- spin_unlock_bh(&fq->lock);
121120 }
122121 }
123122
....@@ -211,6 +210,20 @@
211210 return NULL;
212211 }
213212
213
+struct sta_info *sta_info_get_by_addrs(struct ieee80211_local *local,
214
+ const u8 *sta_addr, const u8 *vif_addr)
215
+{
216
+ struct rhlist_head *tmp;
217
+ struct sta_info *sta;
218
+
219
+ for_each_sta_info(local, sta_addr, sta, tmp) {
220
+ if (ether_addr_equal(vif_addr, sta->sdata->vif.addr))
221
+ return sta;
222
+ }
223
+
224
+ return NULL;
225
+}
226
+
214227 struct sta_info *sta_info_get_by_idx(struct ieee80211_sub_if_data *sdata,
215228 int idx)
216229 {
....@@ -218,7 +231,8 @@
218231 struct sta_info *sta;
219232 int i = 0;
220233
221
- list_for_each_entry_rcu(sta, &local->sta_list, list) {
234
+ list_for_each_entry_rcu(sta, &local->sta_list, list,
235
+ lockdep_is_held(&local->sta_mtx)) {
222236 if (sdata != sta->sdata)
223237 continue;
224238 if (i < idx) {
....@@ -363,6 +377,15 @@
363377 sta->sta.max_rx_aggregation_subframes =
364378 local->hw.max_rx_aggregation_subframes;
365379
380
+ /* Extended Key ID needs to install keys for keyid 0 and 1 Rx-only.
381
+ * The Tx path starts to use a key as soon as the key slot ptk_idx
382
+ * references to is not NULL. To not use the initial Rx-only key
383
+ * prematurely for Tx initialize ptk_idx to an impossible PTK keyid
384
+ * which always will refer to a NULL key.
385
+ */
386
+ BUILD_BUG_ON(ARRAY_SIZE(sta->ptk) <= INVALID_PTK_KEYIDX);
387
+ sta->ptk_idx = INVALID_PTK_KEYIDX;
388
+
366389 sta->local = local;
367390 sta->sdata = sdata;
368391 sta->rx_stats.last_rx = jiffies;
....@@ -394,6 +417,7 @@
394417 for (i = 0; i < ARRAY_SIZE(sta->sta.txq); i++) {
395418 struct txq_info *txq = txq_data + i * size;
396419
420
+ /* might not do anything for the bufferable MMPDU TXQ */
397421 ieee80211_txq_init(sdata, sta, txq, i);
398422 }
399423 }
....@@ -401,13 +425,60 @@
401425 if (sta_prepare_rate_control(local, sta, gfp))
402426 goto free_txq;
403427
428
+ sta->airtime_weight = IEEE80211_DEFAULT_AIRTIME_WEIGHT;
429
+
404430 for (i = 0; i < IEEE80211_NUM_ACS; i++) {
405431 skb_queue_head_init(&sta->ps_tx_buf[i]);
406432 skb_queue_head_init(&sta->tx_filtered[i]);
433
+ sta->airtime[i].deficit = sta->airtime_weight;
434
+ atomic_set(&sta->airtime[i].aql_tx_pending, 0);
435
+ sta->airtime[i].aql_limit_low = local->aql_txq_limit_low[i];
436
+ sta->airtime[i].aql_limit_high = local->aql_txq_limit_high[i];
407437 }
408438
409439 for (i = 0; i < IEEE80211_NUM_TIDS; i++)
410440 sta->last_seq_ctrl[i] = cpu_to_le16(USHRT_MAX);
441
+
442
+ for (i = 0; i < NUM_NL80211_BANDS; i++) {
443
+ u32 mandatory = 0;
444
+ int r;
445
+
446
+ if (!hw->wiphy->bands[i])
447
+ continue;
448
+
449
+ switch (i) {
450
+ case NL80211_BAND_2GHZ:
451
+ /*
452
+ * We use both here, even if we cannot really know for
453
+ * sure the station will support both, but the only use
454
+ * for this is when we don't know anything yet and send
455
+ * management frames, and then we'll pick the lowest
456
+ * possible rate anyway.
457
+ * If we don't include _G here, we cannot find a rate
458
+ * in P2P, and thus trigger the WARN_ONCE() in rate.c
459
+ */
460
+ mandatory = IEEE80211_RATE_MANDATORY_B |
461
+ IEEE80211_RATE_MANDATORY_G;
462
+ break;
463
+ case NL80211_BAND_5GHZ:
464
+ mandatory = IEEE80211_RATE_MANDATORY_A;
465
+ break;
466
+ case NL80211_BAND_60GHZ:
467
+ WARN_ON(1);
468
+ mandatory = 0;
469
+ break;
470
+ }
471
+
472
+ for (r = 0; r < hw->wiphy->bands[i]->n_bitrates; r++) {
473
+ struct ieee80211_rate *rate;
474
+
475
+ rate = &hw->wiphy->bands[i]->bitrates[r];
476
+
477
+ if (!(rate->flags & mandatory))
478
+ continue;
479
+ sta->sta.supp_rates[i] |= BIT(r);
480
+ }
481
+ }
411482
412483 sta->sta.smps_mode = IEEE80211_SMPS_OFF;
413484 if (sdata->vif.type == NL80211_IFTYPE_AP ||
....@@ -574,13 +645,13 @@
574645 /* check if STA exists already */
575646 if (sta_info_get_bss(sdata, sta->sta.addr)) {
576647 err = -EEXIST;
577
- goto out_err;
648
+ goto out_cleanup;
578649 }
579650
580651 sinfo = kzalloc(sizeof(struct station_info), GFP_KERNEL);
581652 if (!sinfo) {
582653 err = -ENOMEM;
583
- goto out_err;
654
+ goto out_cleanup;
584655 }
585656
586657 local->num_sta++;
....@@ -636,8 +707,8 @@
636707 out_drop_sta:
637708 local->num_sta--;
638709 synchronize_net();
710
+ out_cleanup:
639711 cleanup_single_sta(sta);
640
- out_err:
641712 mutex_unlock(&local->sta_mtx);
642713 kfree(sinfo);
643714 rcu_read_lock();
....@@ -969,7 +1040,8 @@
9691040 list_del_rcu(&sta->list);
9701041 sta->removed = true;
9711042
972
- drv_sta_pre_rcu_remove(local, sta->sdata, sta);
1043
+ if (sta->uploaded)
1044
+ drv_sta_pre_rcu_remove(local, sta->sdata, sta);
9731045
9741046 if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
9751047 rcu_access_pointer(sdata->u.vlan.sta) == sta)
....@@ -1031,7 +1103,6 @@
10311103 cfg80211_del_sta_sinfo(sdata->dev, sta->sta.addr, sinfo, GFP_KERNEL);
10321104 kfree(sinfo);
10331105
1034
- rate_control_remove_sta_debugfs(sta);
10351106 ieee80211_sta_debugfs_remove(sta);
10361107
10371108 ieee80211_destroy_frag_cache(&sta->frags);
....@@ -1260,13 +1331,11 @@
12601331 if (!ieee80211_hw_check(&local->hw, AP_LINK_PS))
12611332 drv_sta_notify(local, sdata, STA_NOTIFY_AWAKE, &sta->sta);
12621333
1263
- if (sta->sta.txq[0]) {
1264
- for (i = 0; i < ARRAY_SIZE(sta->sta.txq); i++) {
1265
- if (!txq_has_queue(sta->sta.txq[i]))
1266
- continue;
1334
+ for (i = 0; i < ARRAY_SIZE(sta->sta.txq); i++) {
1335
+ if (!sta->sta.txq[i] || !txq_has_queue(sta->sta.txq[i]))
1336
+ continue;
12671337
1268
- drv_wake_tx_queue(local, to_txq_info(sta->sta.txq[i]));
1269
- }
1338
+ schedule_and_wake_txq(local, to_txq_info(sta->sta.txq[i]));
12701339 }
12711340
12721341 skb_queue_head_init(&pending);
....@@ -1304,20 +1373,6 @@
13041373 spin_unlock(&sta->ps_lock);
13051374
13061375 atomic_dec(&ps->num_sta_ps);
1307
-
1308
- /* This station just woke up and isn't aware of our SMPS state */
1309
- if (!ieee80211_vif_is_mesh(&sdata->vif) &&
1310
- !ieee80211_smps_is_restrictive(sta->known_smps_mode,
1311
- sdata->smps_mode) &&
1312
- sta->known_smps_mode != sdata->bss->req_smps &&
1313
- sta_info_tx_streams(sta) != 1) {
1314
- ht_dbg(sdata,
1315
- "%pM just woke up and MIMO capable - update SMPS\n",
1316
- sta->sta.addr);
1317
- ieee80211_send_smps_action(sdata, sdata->bss->req_smps,
1318
- sta->sta.addr,
1319
- sdata->vif.bss_conf.bssid);
1320
- }
13211376
13221377 local->total_ps_buffered -= buffered;
13231378
....@@ -1412,7 +1467,7 @@
14121467 }
14131468
14141469 info->band = chanctx_conf->def.chan->band;
1415
- ieee80211_xmit(sdata, sta, skb, 0);
1470
+ ieee80211_xmit(sdata, sta, skb);
14161471 rcu_read_unlock();
14171472 }
14181473
....@@ -1699,7 +1754,8 @@
16991754 return;
17001755
17011756 for (tid = 0; tid < ARRAY_SIZE(sta->sta.txq); tid++) {
1702
- if (!(driver_release_tids & BIT(tid)) ||
1757
+ if (!sta->sta.txq[tid] ||
1758
+ !(driver_release_tids & BIT(tid)) ||
17031759 txq_has_queue(sta->sta.txq[tid]))
17041760 continue;
17051761
....@@ -1837,6 +1893,63 @@
18371893 }
18381894 EXPORT_SYMBOL(ieee80211_sta_set_buffered);
18391895
1896
+void ieee80211_sta_register_airtime(struct ieee80211_sta *pubsta, u8 tid,
1897
+ u32 tx_airtime, u32 rx_airtime)
1898
+{
1899
+ struct sta_info *sta = container_of(pubsta, struct sta_info, sta);
1900
+ struct ieee80211_local *local = sta->sdata->local;
1901
+ u8 ac = ieee80211_ac_from_tid(tid);
1902
+ u32 airtime = 0;
1903
+
1904
+ if (sta->local->airtime_flags & AIRTIME_USE_TX)
1905
+ airtime += tx_airtime;
1906
+ if (sta->local->airtime_flags & AIRTIME_USE_RX)
1907
+ airtime += rx_airtime;
1908
+
1909
+ spin_lock_bh(&local->active_txq_lock[ac]);
1910
+ sta->airtime[ac].tx_airtime += tx_airtime;
1911
+ sta->airtime[ac].rx_airtime += rx_airtime;
1912
+ sta->airtime[ac].deficit -= airtime;
1913
+ spin_unlock_bh(&local->active_txq_lock[ac]);
1914
+}
1915
+EXPORT_SYMBOL(ieee80211_sta_register_airtime);
1916
+
1917
+void ieee80211_sta_update_pending_airtime(struct ieee80211_local *local,
1918
+ struct sta_info *sta, u8 ac,
1919
+ u16 tx_airtime, bool tx_completed)
1920
+{
1921
+ int tx_pending;
1922
+
1923
+ if (!wiphy_ext_feature_isset(local->hw.wiphy, NL80211_EXT_FEATURE_AQL))
1924
+ return;
1925
+
1926
+ if (!tx_completed) {
1927
+ if (sta)
1928
+ atomic_add(tx_airtime,
1929
+ &sta->airtime[ac].aql_tx_pending);
1930
+
1931
+ atomic_add(tx_airtime, &local->aql_total_pending_airtime);
1932
+ return;
1933
+ }
1934
+
1935
+ if (sta) {
1936
+ tx_pending = atomic_sub_return(tx_airtime,
1937
+ &sta->airtime[ac].aql_tx_pending);
1938
+ if (tx_pending < 0)
1939
+ atomic_cmpxchg(&sta->airtime[ac].aql_tx_pending,
1940
+ tx_pending, 0);
1941
+ }
1942
+
1943
+ tx_pending = atomic_sub_return(tx_airtime,
1944
+ &local->aql_total_pending_airtime);
1945
+ if (WARN_ONCE(tx_pending < 0,
1946
+ "Device %s AC %d pending airtime underflow: %u, %u",
1947
+ wiphy_name(local->hw.wiphy), ac, tx_pending,
1948
+ tx_airtime))
1949
+ atomic_cmpxchg(&local->aql_total_pending_airtime,
1950
+ tx_pending, 0);
1951
+}
1952
+
18401953 int sta_info_move_state(struct sta_info *sta,
18411954 enum ieee80211_sta_state new_state)
18421955 {
....@@ -1905,6 +2018,7 @@
19052018 case IEEE80211_STA_ASSOC:
19062019 if (sta->sta_state == IEEE80211_STA_AUTH) {
19072020 set_bit(WLAN_STA_ASSOC, &sta->_flags);
2021
+ sta->assoc_at = ktime_get_boottime_ns();
19082022 ieee80211_recalc_min_chandef(sta->sdata);
19092023 if (!sta->sta.support_p2p_ps)
19102024 ieee80211_recalc_p2p_go_ps_allowed(sta->sdata);
....@@ -1975,10 +2089,9 @@
19752089 sta_get_last_rx_stats(struct sta_info *sta)
19762090 {
19772091 struct ieee80211_sta_rx_stats *stats = &sta->rx_stats;
1978
- struct ieee80211_local *local = sta->local;
19792092 int cpu;
19802093
1981
- if (!ieee80211_hw_check(&local->hw, USES_RSS))
2094
+ if (!sta->pcpu_rx_stats)
19822095 return stats;
19832096
19842097 for_each_possible_cpu(cpu) {
....@@ -2047,7 +2160,7 @@
20472160
20482161 static int sta_set_rate_info_rx(struct sta_info *sta, struct rate_info *rinfo)
20492162 {
2050
- u16 rate = READ_ONCE(sta_get_last_rx_stats(sta)->last_rate);
2163
+ u32 rate = READ_ONCE(sta_get_last_rx_stats(sta)->last_rate);
20512164
20522165 if (rate == STA_STATS_RATE_INVALID)
20532166 return -EINVAL;
....@@ -2056,19 +2169,39 @@
20562169 return 0;
20572170 }
20582171
2172
+static inline u64 sta_get_tidstats_msdu(struct ieee80211_sta_rx_stats *rxstats,
2173
+ int tid)
2174
+{
2175
+ unsigned int start;
2176
+ u64 value;
2177
+
2178
+ do {
2179
+ start = u64_stats_fetch_begin_irq(&rxstats->syncp);
2180
+ value = rxstats->msdu[tid];
2181
+ } while (u64_stats_fetch_retry_irq(&rxstats->syncp, start));
2182
+
2183
+ return value;
2184
+}
2185
+
20592186 static void sta_set_tidstats(struct sta_info *sta,
20602187 struct cfg80211_tid_stats *tidstats,
20612188 int tid)
20622189 {
20632190 struct ieee80211_local *local = sta->local;
2191
+ int cpu;
20642192
20652193 if (!(tidstats->filled & BIT(NL80211_TID_STATS_RX_MSDU))) {
2066
- unsigned int start;
2194
+ tidstats->rx_msdu += sta_get_tidstats_msdu(&sta->rx_stats, tid);
20672195
2068
- do {
2069
- start = u64_stats_fetch_begin(&sta->rx_stats.syncp);
2070
- tidstats->rx_msdu = sta->rx_stats.msdu[tid];
2071
- } while (u64_stats_fetch_retry(&sta->rx_stats.syncp, start));
2196
+ if (sta->pcpu_rx_stats) {
2197
+ for_each_possible_cpu(cpu) {
2198
+ struct ieee80211_sta_rx_stats *cpurxs;
2199
+
2200
+ cpurxs = per_cpu_ptr(sta->pcpu_rx_stats, cpu);
2201
+ tidstats->rx_msdu +=
2202
+ sta_get_tidstats_msdu(cpurxs, tid);
2203
+ }
2204
+ }
20722205
20732206 tidstats->filled |= BIT(NL80211_TID_STATS_RX_MSDU);
20742207 }
....@@ -2109,9 +2242,9 @@
21092242 u64 value;
21102243
21112244 do {
2112
- start = u64_stats_fetch_begin(&rxstats->syncp);
2245
+ start = u64_stats_fetch_begin_irq(&rxstats->syncp);
21132246 value = rxstats->bytes;
2114
- } while (u64_stats_fetch_retry(&rxstats->syncp, start));
2247
+ } while (u64_stats_fetch_retry_irq(&rxstats->syncp, start));
21152248
21162249 return value;
21172250 }
....@@ -2137,11 +2270,11 @@
21372270 sinfo->rx_beacon = sdata->u.mgd.count_beacon_signal;
21382271
21392272 drv_sta_statistics(local, sdata, &sta->sta, sinfo);
2140
-
21412273 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_INACTIVE_TIME) |
21422274 BIT_ULL(NL80211_STA_INFO_STA_FLAGS) |
21432275 BIT_ULL(NL80211_STA_INFO_BSS_PARAM) |
21442276 BIT_ULL(NL80211_STA_INFO_CONNECTED_TIME) |
2277
+ BIT_ULL(NL80211_STA_INFO_ASSOC_AT_BOOTTIME) |
21452278 BIT_ULL(NL80211_STA_INFO_RX_DROP_MISC);
21462279
21472280 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
....@@ -2150,6 +2283,7 @@
21502283 }
21512284
21522285 sinfo->connected_time = ktime_get_seconds() - sta->last_connected;
2286
+ sinfo->assoc_at = sta->assoc_at;
21532287 sinfo->inactive_time =
21542288 jiffies_to_msecs(jiffies - ieee80211_sta_last_active(sta));
21552289
....@@ -2205,6 +2339,23 @@
22052339 if (!(sinfo->filled & BIT_ULL(NL80211_STA_INFO_TX_FAILED))) {
22062340 sinfo->tx_failed = sta->status_stats.retry_failed;
22072341 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_FAILED);
2342
+ }
2343
+
2344
+ if (!(sinfo->filled & BIT_ULL(NL80211_STA_INFO_RX_DURATION))) {
2345
+ for (ac = 0; ac < IEEE80211_NUM_ACS; ac++)
2346
+ sinfo->rx_duration += sta->airtime[ac].rx_airtime;
2347
+ sinfo->filled |= BIT_ULL(NL80211_STA_INFO_RX_DURATION);
2348
+ }
2349
+
2350
+ if (!(sinfo->filled & BIT_ULL(NL80211_STA_INFO_TX_DURATION))) {
2351
+ for (ac = 0; ac < IEEE80211_NUM_ACS; ac++)
2352
+ sinfo->tx_duration += sta->airtime[ac].tx_airtime;
2353
+ sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_DURATION);
2354
+ }
2355
+
2356
+ if (!(sinfo->filled & BIT_ULL(NL80211_STA_INFO_AIRTIME_WEIGHT))) {
2357
+ sinfo->airtime_weight = sta->airtime_weight;
2358
+ sinfo->filled |= BIT_ULL(NL80211_STA_INFO_AIRTIME_WEIGHT);
22082359 }
22092360
22102361 sinfo->rx_dropped_misc = sta->rx_stats.dropped;
....@@ -2272,11 +2423,8 @@
22722423 }
22732424
22742425 if (tidstats && !cfg80211_sinfo_alloc_tid_stats(sinfo, GFP_KERNEL)) {
2275
- for (i = 0; i < IEEE80211_NUM_TIDS + 1; i++) {
2276
- struct cfg80211_tid_stats *tidstats = &sinfo->pertid[i];
2277
-
2278
- sta_set_tidstats(sta, tidstats, i);
2279
- }
2426
+ for (i = 0; i < IEEE80211_NUM_TIDS + 1; i++)
2427
+ sta_set_tidstats(sta, &sinfo->pertid[i], i);
22802428 }
22812429
22822430 if (ieee80211_vif_is_mesh(&sdata->vif)) {
....@@ -2286,7 +2434,9 @@
22862434 BIT_ULL(NL80211_STA_INFO_PLINK_STATE) |
22872435 BIT_ULL(NL80211_STA_INFO_LOCAL_PM) |
22882436 BIT_ULL(NL80211_STA_INFO_PEER_PM) |
2289
- BIT_ULL(NL80211_STA_INFO_NONPEER_PM);
2437
+ BIT_ULL(NL80211_STA_INFO_NONPEER_PM) |
2438
+ BIT_ULL(NL80211_STA_INFO_CONNECTED_TO_GATE) |
2439
+ BIT_ULL(NL80211_STA_INFO_CONNECTED_TO_AS);
22902440
22912441 sinfo->llid = sta->mesh->llid;
22922442 sinfo->plid = sta->mesh->plid;
....@@ -2298,6 +2448,8 @@
22982448 sinfo->local_pm = sta->mesh->local_pm;
22992449 sinfo->peer_pm = sta->mesh->peer_pm;
23002450 sinfo->nonpeer_pm = sta->mesh->nonpeer_pm;
2451
+ sinfo->connected_to_gate = sta->mesh->connected_to_gate;
2452
+ sinfo->connected_to_as = sta->mesh->connected_to_as;
23012453 #endif
23022454 }
23032455
....@@ -2347,13 +2499,19 @@
23472499 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_ACK_SIGNAL);
23482500 }
23492501
2350
- if (ieee80211_hw_check(&sta->local->hw, REPORTS_TX_ACK_STATUS) &&
2351
- !(sinfo->filled & BIT_ULL(NL80211_STA_INFO_DATA_ACK_SIGNAL_AVG))) {
2502
+ if (!(sinfo->filled & BIT_ULL(NL80211_STA_INFO_ACK_SIGNAL_AVG)) &&
2503
+ sta->status_stats.ack_signal_filled) {
23522504 sinfo->avg_ack_signal =
23532505 -(s8)ewma_avg_signal_read(
23542506 &sta->status_stats.avg_ack_signal);
23552507 sinfo->filled |=
2356
- BIT_ULL(NL80211_STA_INFO_DATA_ACK_SIGNAL_AVG);
2508
+ BIT_ULL(NL80211_STA_INFO_ACK_SIGNAL_AVG);
2509
+ }
2510
+
2511
+ if (ieee80211_vif_is_mesh(&sdata->vif)) {
2512
+ sinfo->filled |= BIT_ULL(NL80211_STA_INFO_AIRTIME_LINK_METRIC);
2513
+ sinfo->airtime_link_metric =
2514
+ airtime_link_metric_get(local, sta);
23572515 }
23582516 }
23592517